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

Method entity

basex-core/src/main/java/org/basex/query/QueryParser.java:4505–4546  ·  view source on GitHub ↗

Parses and converts entities. @param tb token builder @return true if an entity was found @throws QueryException query exception

(final TokenBuilder tb)

Source from the content-addressed store, hash-verified

4503 * @throws QueryException query exception
4504 */
4505 private boolean entity(final TokenBuilder tb) throws QueryException {
4506 final int p = pos;
4507 final boolean entity = consume('&');
4508 if(entity) {
4509 if(consume('#')) {
4510 final int b = consume('x') ? 0x10 : 10;
4511 boolean ok = true;
4512 int n = 0;
4513 do {
4514 final int cp = current();
4515 final boolean m = digit(cp);
4516 final boolean h = b == 0x10 && (cp >= 'a' && cp <= 'f' || cp >= 'A' && cp <= 'F');
4517 if(!m && !h) entityError(p, INVENTITY_X);
4518 final long nn = n;
4519 n = n * b + (consume() & 0xF);
4520 if(n < nn) ok = false;
4521 if(!m) n += 9;
4522 } while(!consume(';'));
4523 if(!ok) entityError(p, INVCHARREF_X);
4524 if(!XMLToken.valid(n)) entityError(p, INVCHARREF_X);
4525 tb.add(n);
4526 } else {
4527 if(consume("lt")) {
4528 tb.add('<');
4529 } else if(consume("gt")) {
4530 tb.add('>');
4531 } else if(consume("amp")) {
4532 tb.add('&');
4533 } else if(consume("quot")) {
4534 tb.add('"');
4535 } else if(consume("apos")) {
4536 tb.add('\'');
4537 } else {
4538 entityError(p, INVENTITY_X);
4539 }
4540 if(!consume(';')) entityError(p, INVENTITY_X);
4541 }
4542 } else {
4543 tb.add(consume());
4544 }
4545 return entity;
4546 }
4547
4548 /**
4549 * Raises an entity error.

Callers 4

stringLiteralMethod · 0.95
bracedURILiteralMethod · 0.95
dirElementMethod · 0.95
dirElemContentMethod · 0.95

Calls 6

entityErrorMethod · 0.95
validMethod · 0.95
addMethod · 0.65
consumeMethod · 0.45
currentMethod · 0.45
digitMethod · 0.45

Tested by

no test coverage detected