| 73 | // The inverse of countColumn -- find the offset that corresponds to |
| 74 | // a particular column. |
| 75 | export function findColumn(string, goal, tabSize) { |
| 76 | for (let pos = 0, col = 0;;) { |
| 77 | let nextTab = string.indexOf("\t", pos) |
| 78 | if (nextTab == -1) nextTab = string.length |
| 79 | let skipped = nextTab - pos |
| 80 | if (nextTab == string.length || col + skipped >= goal) |
| 81 | return pos + Math.min(skipped, goal - col) |
| 82 | col += nextTab - pos |
| 83 | col += tabSize - (col % tabSize) |
| 84 | pos = nextTab + 1 |
| 85 | if (col >= goal) return pos |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | let spaceStrs = [""] |
| 90 | export function spaceStr(n) { |