(String regex)
| 370 | } |
| 371 | |
| 372 | public Pattern compile(String regex) { |
| 373 | char[] array = regex.toCharArray(); |
| 374 | CharacterMatcher.Parser characterClassParser = |
| 375 | new CharacterMatcher.Parser(array); |
| 376 | for (int index = 0; index < array.length; ++ index) { |
| 377 | char c = array[index]; |
| 378 | Group current = groups.peek(); |
| 379 | if (regularCharacter.matches(c)) { |
| 380 | current.push(c); |
| 381 | continue; |
| 382 | } |
| 383 | switch (c) { |
| 384 | case '.': |
| 385 | current.push(DOT); |
| 386 | continue; |
| 387 | case '\\': |
| 388 | int unescaped = characterClassParser.parseEscapedCharacter(index + 1); |
| 389 | if (unescaped >= 0) { |
| 390 | index = characterClassParser.getEndOffset() - 1; |
| 391 | current.push((char)unescaped); |
| 392 | continue; |
| 393 | } |
| 394 | CharacterMatcher characterClass = characterClassParser.parseClass(index); |
| 395 | if (characterClass != null) { |
| 396 | index = characterClassParser.getEndOffset() - 1; |
| 397 | current.push(new CharacterRange(characterClass)); |
| 398 | continue; |
| 399 | } |
| 400 | switch (array[index + 1]) { |
| 401 | case 'b': |
| 402 | index++; |
| 403 | current.push(WORD_BOUNDARY); |
| 404 | continue; |
| 405 | case 'B': |
| 406 | index++; |
| 407 | current.push(NON_WORD_BOUNDARY); |
| 408 | continue; |
| 409 | } |
| 410 | throw new RuntimeException("Parse error @" + index + ": " + regex); |
| 411 | case '?': |
| 412 | case '*': |
| 413 | case '+': { |
| 414 | boolean greedy = true; |
| 415 | if (index + 1 < array.length && array[index + 1] == '?') { |
| 416 | greedy = false; |
| 417 | ++ index; |
| 418 | } |
| 419 | current.push(new Repeat(current.pop(), |
| 420 | c == '+' ? 1 : 0, c == '?' ? 1 : -1, greedy)); |
| 421 | continue; |
| 422 | } |
| 423 | case '{': { |
| 424 | ++ index; |
| 425 | int length = characterClassParser.digits(index, 8, 10); |
| 426 | int min = Integer.parseInt(regex.substring(index, index + length)); |
| 427 | int max = min; |
| 428 | index += length - 1; |
| 429 | c = index + 1 < array.length ? array[index + 1] : 0; |
nothing calls this directly
no test coverage detected