* Extract the regular expression from the query and return a Regexp object. * Returns null if the query is blank. * If ignoreCase is passed in, the Regexp object will have the 'i' flag set. * If smartCase is passed in, and the query contains upper case letters, * then ignoreCas
(query, ignoreCase, smartCase)
| 4273 | * through to the Regex object. |
| 4274 | */ |
| 4275 | function parseQuery(query, ignoreCase, smartCase) { |
| 4276 | // First update the last search register |
| 4277 | var lastSearchRegister = vimGlobalState.registerController.getRegister('/'); |
| 4278 | lastSearchRegister.setText(query); |
| 4279 | // Check if the query is already a regex. |
| 4280 | if (query instanceof RegExp) { return query; } |
| 4281 | // First try to extract regex + flags from the input. If no flags found, |
| 4282 | // extract just the regex. IE does not accept flags directly defined in |
| 4283 | // the regex string in the form /regex/flags |
| 4284 | var slashes = findUnescapedSlashes(query); |
| 4285 | var regexPart; |
| 4286 | var forceIgnoreCase; |
| 4287 | if (!slashes.length) { |
| 4288 | // Query looks like 'regexp' |
| 4289 | regexPart = query; |
| 4290 | } else { |
| 4291 | // Query looks like 'regexp/...' |
| 4292 | regexPart = query.substring(0, slashes[0]); |
| 4293 | var flagsPart = query.substring(slashes[0]); |
| 4294 | forceIgnoreCase = (flagsPart.indexOf('i') != -1); |
| 4295 | } |
| 4296 | if (!regexPart) { |
| 4297 | return null; |
| 4298 | } |
| 4299 | if (!getOption('pcre')) { |
| 4300 | regexPart = translateRegex(regexPart); |
| 4301 | } |
| 4302 | if (smartCase) { |
| 4303 | ignoreCase = (/^[^A-Z]*$/).test(regexPart); |
| 4304 | } |
| 4305 | var regexp = new RegExp(regexPart, |
| 4306 | (ignoreCase || forceIgnoreCase) ? 'i' : undefined); |
| 4307 | return regexp; |
| 4308 | } |
| 4309 | function showConfirm(cm, text) { |
| 4310 | if (cm.openNotification) { |
| 4311 | cm.openNotification('<span style="color: red">' + text + '</span>', |
no test coverage detected