MCPcopy Create free account
hub / github.com/denoland/std / #captureText

Method #captureText

xml/_tokenizer.ts:750–817  ·  view source on GitHub ↗

* Capture text content in a tight loop until '<' is found. * Returns true if '<' was found, false if end of buffer reached. * * The "]]>" check (XML 1.0 §2.4) is deferred to #flushText where * a single native `includes` covers both within-chunk and cross-chunk cases. * * Il

(buffer: string, bufferLen: number)

Source from the content-addressed store, hash-verified

748 * regex pre-check in {@link #flushText} for the no-position-tracking path.
749 */
750 #captureText(buffer: string, bufferLen: number): boolean {
751 // Initialize text tracking if this is the start of a new text node
752 if (this.#textStartIdx === -1) {
753 if (this.#trackPosition) {
754 this.#textStartLine = this.#line;
755 this.#textStartColumn = this.#column;
756 this.#textStartOffset = this.#offset;
757 }
758 this.#textStartIdx = this.#bufferIndex;
759 }
760
761 if (this.#trackPosition) {
762 // Scan for '<' while tracking line/column positions.
763 // Illegal C0 chars are checked here (we're already per-char).
764 let idx = this.#bufferIndex;
765 let line = this.#line;
766 let column = this.#column;
767 let offset = this.#offset;
768
769 while (idx < bufferLen) {
770 const code = buffer.charCodeAt(idx);
771 if (code === CC_LT) {
772 this.#bufferIndex = idx;
773 this.#line = line;
774 this.#column = column;
775 this.#offset = offset;
776 return true;
777 }
778
779 if (this.#isIllegalLiteralChar(code)) {
780 this.#bufferIndex = idx;
781 this.#line = line;
782 this.#column = column;
783 this.#offset = offset;
784 this.#error(
785 `Illegal XML character U+${
786 code.toString(16).toUpperCase().padStart(4, "0")
787 }`,
788 );
789 }
790
791 if (code === CC_LF) {
792 line++;
793 column = 1;
794 } else {
795 column++;
796 }
797 offset++;
798 idx++;
799 }
800
801 this.#bufferIndex = idx;
802 this.#line = line;
803 this.#column = column;
804 this.#offset = offset;
805 } else {
806 // Fast path: native indexOf is SIMD-optimized in V8.
807 // Illegal C0 chars are checked in #flushText via regex.

Callers 1

processMethod · 0.95

Calls 3

#isIllegalLiteralCharMethod · 0.95
#errorMethod · 0.95
toStringMethod · 0.45

Tested by

no test coverage detected