* 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)
| 797 | * regex pre-check in {@link #flushText} for the no-position-tracking path. |
| 798 | */ |
| 799 | #captureText(buffer: string, bufferLen: number): boolean { |
| 800 | // Initialize text tracking if this is the start of a new text node |
| 801 | if (this.#textStartIdx === -1) { |
| 802 | if (this.#trackPosition) { |
| 803 | this.#textStartLine = this.#line; |
| 804 | this.#textStartColumn = this.#column; |
| 805 | this.#textStartOffset = this.#offset; |
| 806 | } |
| 807 | this.#textStartIdx = this.#bufferIndex; |
| 808 | } |
| 809 | |
| 810 | if (this.#trackPosition) { |
| 811 | // Scan for '<' while tracking line/column positions. |
| 812 | // Illegal C0 chars are checked here (we're already per-char). |
| 813 | let idx = this.#bufferIndex; |
| 814 | let line = this.#line; |
| 815 | let column = this.#column; |
| 816 | let offset = this.#offset; |
| 817 | |
| 818 | while (idx < bufferLen) { |
| 819 | const code = buffer.charCodeAt(idx); |
| 820 | if (code === CC_LT) { |
| 821 | this.#bufferIndex = idx; |
| 822 | this.#line = line; |
| 823 | this.#column = column; |
| 824 | this.#offset = offset; |
| 825 | return true; |
| 826 | } |
| 827 | |
| 828 | if (this.#isIllegalLiteralChar(code)) { |
| 829 | this.#bufferIndex = idx; |
| 830 | this.#line = line; |
| 831 | this.#column = column; |
| 832 | this.#offset = offset; |
| 833 | this.#error( |
| 834 | `Illegal XML character U+${ |
| 835 | code.toString(16).toUpperCase().padStart(4, "0") |
| 836 | }`, |
| 837 | ); |
| 838 | } |
| 839 | |
| 840 | if (code === CC_LF) { |
| 841 | line++; |
| 842 | column = 1; |
| 843 | } else { |
| 844 | column++; |
| 845 | } |
| 846 | offset++; |
| 847 | idx++; |
| 848 | } |
| 849 | |
| 850 | this.#bufferIndex = idx; |
| 851 | this.#line = line; |
| 852 | this.#column = column; |
| 853 | this.#offset = offset; |
| 854 | } else { |
| 855 | // Fast path: native indexOf is SIMD-optimized in V8. |
| 856 | // Illegal C0 chars are checked in #flushText via regex. |
no test coverage detected