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

Method decodeUri

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

Returns a URI-decoded token. @param token encoded token @return decoded token

(final byte[] token)

Source from the content-addressed store, hash-verified

412 * @return decoded token
413 */
414 public static byte[] decodeUri(final byte[] token) {
415 final int tl = token.length;
416 final TokenBuilder tb = new TokenBuilder(tl);
417 for(int t = 0; t < tl; t++) {
418 int b = token[t];
419 if(b == '+') {
420 b = ' ';
421 } else if(b == '%') {
422 final int b1 = ++t < tl ? dec(token[t]) : -1, b2 = ++t < tl ? dec(token[t]) : -1;
423 b = b1 != -1 && b2 != -1 ? b1 << 4 | b2 : -1;
424 }
425 if(b == -1) tb.add(Token.REPLACEMENT);
426 else tb.addByte((byte) b);
427 }
428
429 Token.string(tb.next()).codePoints().forEach(cp ->
430 tb.add(XMLToken.valid(cp) ? cp : Token.REPLACEMENT)
431 );
432 return tb.finish();
433 }
434
435 /**
436 * URI-decodes a string.

Callers 6

addParamsMethod · 0.95
decodeAndEscapeMethod · 0.95
itemMethod · 0.95
itemMethod · 0.95
itemMethod · 0.95
valueMethod · 0.95

Calls 9

addMethod · 0.95
addByteMethod · 0.95
stringMethod · 0.95
nextMethod · 0.95
validMethod · 0.95
finishMethod · 0.95
tokenMethod · 0.95
decMethod · 0.45
forEachMethod · 0.45

Tested by

no test coverage detected