MCPcopy Create free account
hub / github.com/denoland/std / parseEntityDeclaration

Function parseEntityDeclaration

xml/_parse_sync.ts:369–512  ·  view source on GitHub ↗

* Parse and validate an ENTITY declaration syntax. * * We do NOT expand custom entities from DTD * We only support the 5 predefined XML entities (lt, gt, amp, apos, quot). * External entities (SYSTEM/PUBLIC) are also not supported. * * This function validates syntax but does not st

()

Source from the content-addressed store, hash-verified

367 * NDataDecl ::= S 'NDATA' S Name
368 */
369 function parseEntityDeclaration(): void {
370 // Skip whitespace after ENTITY keyword (already validated by caller)
371 skipWhitespace();
372
373 // Check for parameter entity marker '%'
374 const isParameterEntity = input.charCodeAt(pos) === CC_PERCENT;
375 if (isParameterEntity) {
376 pos++;
377 // Must have whitespace after '%'
378 if (pos >= len || !isWhitespace(input.charCodeAt(pos))) {
379 error("Missing whitespace after '%' in parameter entity declaration");
380 }
381 skipWhitespace();
382 }
383
384 // Read entity name
385 const name = readName();
386 if (name === "") {
387 error("Missing entity name in ENTITY declaration");
388 }
389
390 // Must have whitespace after name
391 if (pos >= len || !isWhitespace(input.charCodeAt(pos))) {
392 error("Missing whitespace after entity name");
393 }
394 skipWhitespace();
395
396 // Determine entity definition type
397 const code = input.charCodeAt(pos);
398 if (code === CC_DQUOTE || code === CC_SQUOTE) {
399 // EntityValue - internal entity
400 parseQuotedLiteral();
401
402 // Check for SGML-style comment (-- after quoted value)
403 skipWhitespace();
404 if (
405 pos + 1 < len &&
406 input.charCodeAt(pos) === CC_DASH &&
407 input.charCodeAt(pos + 1) === CC_DASH
408 ) {
409 error(
410 "SGML-style comments (--) are not allowed in XML declarations",
411 );
412 }
413 } else {
414 // ExternalID - SYSTEM or PUBLIC
415 const kwStart = pos;
416 while (
417 pos < len &&
418 ((input.charCodeAt(pos) >= 65 && input.charCodeAt(pos) <= 90) || // A-Z
419 (input.charCodeAt(pos) >= 97 && input.charCodeAt(pos) <= 122)) // a-z
420 ) {
421 pos++;
422 }
423 const keyword = input.slice(kwStart, pos);
424 const keywordUpper = keyword.toUpperCase();
425
426 // Check for case-sensitivity - must be uppercase

Callers 1

Calls 9

skipWhitespaceFunction · 0.85
isWhitespaceFunction · 0.85
errorFunction · 0.85
readNameFunction · 0.85
parseQuotedLiteralFunction · 0.85
startsWithMethod · 0.80
minMethod · 0.80
includesMethod · 0.80
sliceMethod · 0.45

Tested by

no test coverage detected