(
column: number,
wordDefinition: RegExp,
text: string,
textOffset: number
)
| 123 | } |
| 124 | |
| 125 | export function getWordAtText( |
| 126 | column: number, |
| 127 | wordDefinition: RegExp, |
| 128 | text: string, |
| 129 | textOffset: number |
| 130 | ): IWordAtPosition | null { |
| 131 | // if `words` can contain whitespace character we have to use the slow variant |
| 132 | // otherwise we use the fast variant of finding a word |
| 133 | wordDefinition.lastIndex = 0; |
| 134 | const match = wordDefinition.exec(text); |
| 135 | if (!match) { |
| 136 | return null; |
| 137 | } |
| 138 | // todo@joh the `match` could already be the (first) word |
| 139 | const ret = |
| 140 | match[0].indexOf(' ') >= 0 |
| 141 | ? // did match a word which contains a space character -> use slow word find |
| 142 | getWordAtPosSlow(column, wordDefinition, text, textOffset) |
| 143 | : // sane word definition -> use fast word find |
| 144 | getWordAtPosFast(column, wordDefinition, text, textOffset); |
| 145 | |
| 146 | // both (getWordAtPosFast and getWordAtPosSlow) leave the wordDefinition-RegExp |
| 147 | // in an undefined state and to not confuse other users of the wordDefinition |
| 148 | // we reset the lastIndex |
| 149 | wordDefinition.lastIndex = 0; |
| 150 | |
| 151 | return ret; |
| 152 | } |
| 153 | |
| 154 | export function regExpLeadsToEndlessLoop(regexp: RegExp): boolean { |
| 155 | // Exit early if it's one of these special cases which are meant to match |
no test coverage detected