(searchString: string, isRegex: boolean, options: RegExpOptions = {})
| 188 | } |
| 189 | |
| 190 | export function createRegExp(searchString: string, isRegex: boolean, options: RegExpOptions = {}): RegExp { |
| 191 | if (!searchString) { |
| 192 | throw new Error('Cannot create regex from empty string'); |
| 193 | } |
| 194 | if (!isRegex) { |
| 195 | searchString = escapeRegExpCharacters(searchString); |
| 196 | } |
| 197 | if (options.wholeWord) { |
| 198 | if (!/\B/.test(searchString.charAt(0))) { |
| 199 | searchString = '\\b' + searchString; |
| 200 | } |
| 201 | if (!/\B/.test(searchString.charAt(searchString.length - 1))) { |
| 202 | searchString = searchString + '\\b'; |
| 203 | } |
| 204 | } |
| 205 | let modifiers = ''; |
| 206 | if (options.global) { |
| 207 | modifiers += 'g'; |
| 208 | } |
| 209 | if (!options.matchCase) { |
| 210 | modifiers += 'i'; |
| 211 | } |
| 212 | if (options.multiline) { |
| 213 | modifiers += 'm'; |
| 214 | } |
| 215 | if (options.unicode) { |
| 216 | modifiers += 'u'; |
| 217 | } |
| 218 | |
| 219 | return new RegExp(searchString, modifiers); |
| 220 | } |
| 221 | |
| 222 | export function regExpLeadsToEndlessLoop(regexp: RegExp): boolean { |
| 223 | // Exit early if it's one of these special cases which are meant to match |
nothing calls this directly
no test coverage detected