* Given a group of RegExps, returns a RegExp that globally * matches the union of the sets of strings matched by the input RegExp. * Since it matches globally, if the input strings have a start-of-input * anchor (/^.../), it is ignored for the purposes of unioning. * @par
(regexs)
| 238 | * @return {RegExp} a global regex. |
| 239 | */ |
| 240 | function combinePrefixPatterns(regexs) { |
| 241 | var capturedGroupIndex = 0; |
| 242 | |
| 243 | var needToFoldCase = false; |
| 244 | var ignoreCase = false; |
| 245 | for (var i = 0, n = regexs.length; i < n; ++i) { |
| 246 | var regex = regexs[i]; |
| 247 | if (regex.ignoreCase) { |
| 248 | ignoreCase = true; |
| 249 | } else if (/[a-z]/i.test(regex.source.replace( |
| 250 | /\\u[0-9a-f]{4}|\\x[0-9a-f]{2}|\\[^ux]/gi, ''))) { |
| 251 | needToFoldCase = true; |
| 252 | ignoreCase = false; |
| 253 | break; |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | var escapeCharToCodeUnit = { |
| 258 | 'b': 8, |
| 259 | 't': 9, |
| 260 | 'n': 0xa, |
| 261 | 'v': 0xb, |
| 262 | 'f': 0xc, |
| 263 | 'r': 0xd |
| 264 | }; |
| 265 | |
| 266 | function decodeEscape(charsetPart) { |
| 267 | var cc0 = charsetPart.charCodeAt(0); |
| 268 | if (cc0 !== 92 /* \\ */) { |
| 269 | return cc0; |
| 270 | } |
| 271 | var c1 = charsetPart.charAt(1); |
| 272 | cc0 = escapeCharToCodeUnit[c1]; |
| 273 | if (cc0) { |
| 274 | return cc0; |
| 275 | } else if ('0' <= c1 && c1 <= '7') { |
| 276 | return parseInt(charsetPart.substring(1), 8); |
| 277 | } else if (c1 === 'u' || c1 === 'x') { |
| 278 | return parseInt(charsetPart.substring(2), 16); |
| 279 | } else { |
| 280 | return charsetPart.charCodeAt(1); |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | function encodeEscape(charCode) { |
| 285 | if (charCode < 0x20) { |
| 286 | return (charCode < 0x10 ? '\\x0' : '\\x') + charCode.toString(16); |
| 287 | } |
| 288 | var ch = String.fromCharCode(charCode); |
| 289 | return (ch === '\\' || ch === '-' || ch === ']' || ch === '^') |
| 290 | ? "\\" + ch : ch; |
| 291 | } |
| 292 | |
| 293 | function caseFoldCharset(charSet) { |
| 294 | var charsetParts = charSet.substring(1, charSet.length - 1).match( |
| 295 | new RegExp( |
| 296 | '\\\\u[0-9A-Fa-f]{4}' |
| 297 | + '|\\\\x[0-9A-Fa-f]{2}' |
no test coverage detected