* 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
(cm, query, ignoreCase, smartCase)
| 1965 | * through to the Regex object. |
| 1966 | */ |
| 1967 | function parseQuery(cm, query, ignoreCase, smartCase) { |
| 1968 | // First try to extract regex + flags from the input. If no flags found, |
| 1969 | // extract just the regex. IE does not accept flags directly defined in |
| 1970 | // the regex string in the form /regex/flags |
| 1971 | var slashes = findUnescapedSlashes(query); |
| 1972 | var regexPart; |
| 1973 | var forceIgnoreCase; |
| 1974 | if (!slashes.length) { |
| 1975 | // Query looks like 'regexp' |
| 1976 | regexPart = query; |
| 1977 | } else { |
| 1978 | // Query looks like 'regexp/...' |
| 1979 | regexPart = query.substring(0, slashes[0]); |
| 1980 | var flagsPart = query.substring(slashes[0]); |
| 1981 | forceIgnoreCase = (flagsPart.indexOf('i') != -1); |
| 1982 | } |
| 1983 | if (!regexPart) { |
| 1984 | return null; |
| 1985 | } |
| 1986 | if (smartCase) { |
| 1987 | ignoreCase = (/^[^A-Z]*$/).test(regexPart); |
| 1988 | } |
| 1989 | try { |
| 1990 | var regexp = new RegExp(regexPart, |
| 1991 | (ignoreCase || forceIgnoreCase) ? 'i' : undefined); |
| 1992 | return regexp; |
| 1993 | } catch (e) { |
| 1994 | showConfirm(cm, 'Invalid regex: ' + regexPart); |
| 1995 | } |
| 1996 | } |
| 1997 | function showConfirm(cm, text) { |
| 1998 | if (cm.openConfirm) { |
| 1999 | cm.openConfirm('<span style="color: red">' + text + |
no test coverage detected