| 30 | const namePattern = /(?:^|\s)name=(?:"([^"]+)"|'([^']+)'|([^\s]+))/ |
| 31 | |
| 32 | const lineNumberAt = (source: string): (offset: number) => number => { |
| 33 | const starts = [0] |
| 34 | for (let index = 0; index < source.length; index++) { |
| 35 | if (source.charCodeAt(index) === 10) starts.push(index + 1) |
| 36 | } |
| 37 | |
| 38 | return (offset) => { |
| 39 | let low = 0 |
| 40 | let high = starts.length |
| 41 | while (low < high) { |
| 42 | const middle = (low + high) >>> 1 |
| 43 | if (starts[middle] <= offset) low = middle + 1 |
| 44 | else high = middle |
| 45 | } |
| 46 | return low |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | const snippets = ( |
| 51 | text: string, |