* Update position tracking for a region of text using indexOf for newlines. * This is more efficient than char-by-char for regions with sparse newlines.
(buffer: string, start: number, end: number)
| 634 | * This is more efficient than char-by-char for regions with sparse newlines. |
| 635 | */ |
| 636 | #updatePositionForRegion(buffer: string, start: number, end: number): void { |
| 637 | if (!this.#trackPosition) return; |
| 638 | |
| 639 | let pos = start; |
| 640 | while (pos < end) { |
| 641 | const nlIdx = buffer.indexOf("\n", pos); |
| 642 | if (nlIdx === -1 || nlIdx >= end) { |
| 643 | // No more newlines in region |
| 644 | this.#column += end - pos; |
| 645 | break; |
| 646 | } |
| 647 | // Found a newline |
| 648 | this.#line++; |
| 649 | this.#column = 1; |
| 650 | pos = nlIdx + 1; |
| 651 | } |
| 652 | this.#offset += end - start; |
| 653 | } |
| 654 | |
| 655 | #normalizeLineEndings(chunk: string): string { |
| 656 | const version = this.#xml11 ? "1.1" : "1.0"; |
no outgoing calls
no test coverage detected