MCPcopy Create free account
hub / github.com/BaseXdb/basex / decode

Method decode

basex-core/src/main/java/org/basex/util/XMLToken.java:350–407  ·  view source on GitHub ↗

Decodes an NCName to a token. @param name name @param lax lax decoding @return token

(final byte[] name, final boolean lax)

Source from the content-addressed store, hash-verified

348 * @return token
349 */
350 public static byte[] decode(final byte[] name, final boolean lax) {
351 final int nl = name.length;
352 if(nl == 0) return null;
353 if(lax) return name;
354
355 // mode: 0=normal, 1=unicode, 2=underscore, 3=building unicode
356 final TokenBuilder tb = new TokenBuilder();
357 int mode = 0, uc = 0;
358 for(int n = 0; n < nl;) {
359 final int cp = cp(name, n);
360 if(mode >= 3) {
361 uc <<= 4;
362 if(cp >= '0' && cp <= '9') {
363 uc += cp - '0';
364 } else if(cp >= 'A' && cp <= 'F') {
365 uc += cp - 0x37;
366 } else if(cp >= 'a' && cp <= 'f') {
367 uc += cp - 0x57;
368 } else {
369 return null;
370 }
371 if(++mode == 7) {
372 tb.add(uc);
373 mode = 0;
374 uc = 0;
375 }
376 } else if(cp == '_') {
377 // limit underscore counter
378 if(++mode == 3) {
379 tb.add('_');
380 mode = 0;
381 continue;
382 }
383 } else if(mode == 1) {
384 // unicode
385 mode = 3;
386 continue;
387 } else if(mode == 2) {
388 // underscore
389 tb.add('_');
390 mode = 0;
391 continue;
392 } else {
393 // normal character
394 if(!(tb.isEmpty() ? isNCStartChar(cp) : isNCChar(cp))) return null;
395 tb.add(cp);
396 mode = 0;
397 }
398 n += cl(name, n);
399 }
400
401 if(mode == 2) {
402 tb.add('_');
403 } else if(mode == 1 && !tb.isEmpty() || mode >= 3) {
404 return null;
405 }
406 return tb.finish();
407 }

Callers 3

finishOpenMethod · 0.95
cacheMethod · 0.95
itemMethod · 0.95

Calls 7

addMethod · 0.95
isEmptyMethod · 0.95
isNCStartCharMethod · 0.95
isNCCharMethod · 0.95
finishMethod · 0.95
cpMethod · 0.45
clMethod · 0.45

Tested by

no test coverage detected