// Counts the column offset in a string, taking tabs into account. // Used mostly to find indentation. export function countColumn(string: string, end: number | null, tabSize: number, startIndex?: number, startValue?: number): number { if (end == null) { end = string.search(/[^\s\u00a0]/) if (end == -1) end = string.length } for (let i = startIndex || 0, n = startValue || 0;;) { let nextTab = string.indexOf("\t", i) if (nextTab < 0 || nextTab >= end) return n + (end - i) n += nextTab - i n += tabSize - (n % tabSize) i = nextTab + 1 } }