MCPcopy Create free account
hub / github.com/ReadyTalk/avian / compile

Method compile

classpath/java/util/regex/Compiler.java:372–532  ·  view source on GitHub ↗
(String regex)

Source from the content-addressed store, hash-verified

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;

Callers

nothing calls this directly

Calls 15

pushMethod · 0.95
parseEscapedCharacterMethod · 0.95
getEndOffsetMethod · 0.95
parseClassMethod · 0.95
popMethod · 0.95
digitsMethod · 0.95
parseIntMethod · 0.95
startAlternativeMethod · 0.95
isPlainStringMethod · 0.95
toCharArrayMethod · 0.80
toVMMethod · 0.80
peekMethod · 0.65

Tested by

no test coverage detected