| @@ 8163-8176 (lines=14) @@ | ||
| 8160 | ||
| 8161 | // Counts the column offset in a string, taking tabs into account. |
|
| 8162 | // Used mostly to find indentation. |
|
| 8163 | var countColumn = CodeMirror.countColumn = function(string, end, tabSize, startIndex, startValue) { |
|
| 8164 | if (end == null) { |
|
| 8165 | end = string.search(/[^\s\u00a0]/); |
|
| 8166 | if (end == -1) end = string.length; |
|
| 8167 | } |
|
| 8168 | for (var i = startIndex || 0, n = startValue || 0;;) { |
|
| 8169 | var nextTab = string.indexOf("\t", i); |
|
| 8170 | if (nextTab < 0 || nextTab >= end) |
|
| 8171 | return n + (end - i); |
|
| 8172 | n += nextTab - i; |
|
| 8173 | n += tabSize - (n % tabSize); |
|
| 8174 | i = nextTab + 1; |
|
| 8175 | } |
|
| 8176 | }; |
|
| 8177 | ||
| 8178 | // The inverse of countColumn -- find the offset that corresponds to |
|
| 8179 | // a particular column. |
|
| @@ 10-23 (lines=14) @@ | ||
| 7 | ||
| 8 | // Counts the column offset in a string, taking tabs into account. |
|
| 9 | // Used mostly to find indentation. |
|
| 10 | var countColumn = function(string, end, tabSize, startIndex, startValue) { |
|
| 11 | if (end == null) { |
|
| 12 | end = string.search(/[^\s\u00a0]/); |
|
| 13 | if (end == -1) end = string.length; |
|
| 14 | } |
|
| 15 | for (var i = startIndex || 0, n = startValue || 0;;) { |
|
| 16 | var nextTab = string.indexOf("\t", i); |
|
| 17 | if (nextTab < 0 || nextTab >= end) |
|
| 18 | return n + (end - i); |
|
| 19 | n += nextTab - i; |
|
| 20 | n += tabSize - (n % tabSize); |
|
| 21 | i = nextTab + 1; |
|
| 22 | } |
|
| 23 | }; |
|
| 24 | ||
| 25 | function StringStream(string, tabSize) { |
|
| 26 | this.pos = this.start = 0; |
|