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

Function readText

xml/_parse_sync.ts:772–801  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

770 }
771
772 function readText(): string {
773 const start = pos;
774 const idx = input.indexOf("<", pos);
775 const end = idx === -1 ? len : idx;
776
777 for (let i = start; i < end; i++) {
778 const code = input.charCodeAt(i);
779 if (isIllegalLiteralChar(code)) {
780 pos = i;
781 error(
782 `Illegal XML character U+${
783 code.toString(16).toUpperCase().padStart(4, "0")
784 }`,
785 );
786 }
787 }
788
789 pos = end;
790
791 // Slice text once (reused for ]]> check and entity decoding)
792 const text = input.slice(start, end);
793
794 // XML 1.0 §2.4: "]]>" is not allowed in text content
795 if (text.includes("]]>")) {
796 pos = start + text.indexOf("]]>");
797 error("Cannot use ']]>' in text content (XML 1.0 §2.4)");
798 }
799
800 return decodeEntities(text, xml11);
801 }
802
803 function addNode(node: XmlTextNode | XmlCDataNode | XmlCommentNode): void {
804 if (stack.length > 0) {

Callers 1

parseSyncFunction · 0.85

Calls 6

decodeEntitiesFunction · 0.90
isIllegalLiteralCharFunction · 0.85
errorFunction · 0.85
includesMethod · 0.80
toStringMethod · 0.45
sliceMethod · 0.45

Tested by

no test coverage detected