| 149 | // a word) |
| 150 | // TODO: `prefix` and `suffix` might be useful in richer word-relevancy scoring. |
| 151 | get(string, prefix, suffix) { |
| 152 | if (prefix == null) prefix = ""; |
| 153 | if (suffix == null) suffix = ""; |
| 154 | if (!this.initialized) this.init(); |
| 155 | let regexpString = Utils.escapeRegexSpecialCharacters(string); |
| 156 | // Avoid cost of constructing new strings if prefix/suffix are empty (which is expected to be a |
| 157 | // common case). |
| 158 | if (prefix) regexpString = prefix + regexpString; |
| 159 | if (suffix) regexpString = regexpString + suffix; |
| 160 | // Smartcase: Regexp is case insensitive, unless `string` contains a capital letter (testing |
| 161 | // `string`, not `regexpString`). |
| 162 | return this.cache[regexpString] || |
| 163 | (this.cache[regexpString] = new RegExp(regexpString, Utils.hasUpperCase(string) ? "" : "i")); |
| 164 | }, |
| 165 | }; |