Precompute the char offset at which each line begins.
(content: string)
| 87 | |
| 88 | /** Precompute the char offset at which each line begins. */ |
| 89 | function computeLineStarts(content: string): number[] { |
| 90 | const starts = [0]; |
| 91 | for (let i = 0; i < content.length; i++) { |
| 92 | if (content[i] === '\n') starts.push(i + 1); |
| 93 | } |
| 94 | return starts; |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Find `search` in `content`, tolerating whitespace and small drift. |