* 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)
| 13089 | * through to the Regex object. |
| 13090 | */ |
| 13091 | function parseQuery(query, ignoreCase, smartCase) { |
| 13092 | // First update the last search register |
| 13093 | var lastSearchRegister = vimGlobalState.registerController.getRegister('/'); |
| 13094 | lastSearchRegister.setText(query); |
| 13095 | // Check if the query is already a regex. |
| 13096 | if (query instanceof RegExp) { return query; } |
| 13097 | // First try to extract regex + flags from the input. If no flags found, |
| 13098 | // extract just the regex. IE does not accept flags directly defined in |
| 13099 | // the regex string in the form /regex/flags |
| 13100 | var slashes = findUnescapedSlashes(query); |
| 13101 | var regexPart; |
| 13102 | var forceIgnoreCase; |
| 13103 | if (!slashes.length) { |
| 13104 | // Query looks like 'regexp' |
| 13105 | regexPart = query; |
| 13106 | } else { |
| 13107 | // Query looks like 'regexp/...' |
| 13108 | regexPart = query.substring(0, slashes[0]); |
| 13109 | var flagsPart = query.substring(slashes[0]); |
| 13110 | forceIgnoreCase = (flagsPart.indexOf('i') != -1); |
| 13111 | } |
| 13112 | if (!regexPart) { |
| 13113 | return null; |
| 13114 | } |
| 13115 | if (!getOption('pcre')) { |
| 13116 | regexPart = translateRegex(regexPart); |
| 13117 | } |
| 13118 | if (smartCase) { |
| 13119 | ignoreCase = (/^[^A-Z]*$/).test(regexPart); |
| 13120 | } |
| 13121 | var regexp = new RegExp(regexPart, |
| 13122 | (ignoreCase || forceIgnoreCase) ? 'i' : undefined); |
| 13123 | return regexp; |
| 13124 | } |
| 13125 | function showConfirm(cm, text) { |
| 13126 | if (cm.openNotification) { |
| 13127 | cm.openNotification('<span style="color: red">' + text + '</span>', |
no test coverage detected