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

Method #updatePositionForRegion

xml/_tokenizer.ts:636–653  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

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";

Callers 4

#captureCommentMethod · 0.95
#capturePIMethod · 0.95
#captureCDATAMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected