MCPcopy Create free account
hub / github.com/IIIIQIIII/claude-code / tokenize

Function tokenize

src/native-ts/color-diff/index.ts:552–576  ·  view source on GitHub ↗
(text: string)

Source from the content-addressed store, hash-verified

550// Tokenize into word runs, whitespace runs, and single punctuation chars —
551// matches the Rust tokenize() which mirrors diffWordsWithSpace's splitting.
552function tokenize(text: string): string[] {
553 const tokens: string[] = []
554 let i = 0
555 while (i < text.length) {
556 const ch = text[i]!
557 if (/[\p{L}\p{N}_]/u.test(ch)) {
558 let j = i + 1
559 while (j < text.length && /[\p{L}\p{N}_]/u.test(text[j]!)) j++
560 tokens.push(text.slice(i, j))
561 i = j
562 } else if (/\s/.test(ch)) {
563 let j = i + 1
564 while (j < text.length && /\s/.test(text[j]!)) j++
565 tokens.push(text.slice(i, j))
566 i = j
567 } else {
568 // advance one codepoint (handle surrogate pairs)
569 const cp = text.codePointAt(i)!
570 const len = cp > 0xffff ? 2 : 1
571 tokens.push(text.slice(i, i + len))
572 i += len
573 }
574 }
575 return tokens
576}
577
578function findAdjacentPairs(markers: Marker[]): [number, number][] {
579 const pairs: [number, number][] = []

Callers 1

wordDiffStringsFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected