MCPcopy Create free account
hub / github.com/google/re2j / parseRepeat

Method parseRepeat

java/com/google/re2j/Parser.java:998–1034  ·  view source on GitHub ↗
(StringIterator t)

Source from the content-addressed store, hash-verified

996 // On success, advances |t| beyond the repeat; otherwise |t.pos()| is
997 // undefined.
998 private static int parseRepeat(StringIterator t) throws PatternSyntaxException {
999 int start = t.pos();
1000 if (!t.more() || !t.lookingAt('{')) {
1001 return -1;
1002 }
1003 t.skip(1); // '{'
1004 int min = parseInt(t); // (can be -2)
1005 if (min == -1) {
1006 return -1;
1007 }
1008 if (!t.more()) {
1009 return -1;
1010 }
1011 int max;
1012 if (!t.lookingAt(',')) {
1013 max = min;
1014 } else {
1015 t.skip(1); // ','
1016 if (!t.more()) {
1017 return -1;
1018 }
1019 if (t.lookingAt('}')) {
1020 max = -1;
1021 } else if ((max = parseInt(t)) == -1) { // (can be -2)
1022 return -1;
1023 }
1024 }
1025 if (!t.more() || !t.lookingAt('}')) {
1026 return -1;
1027 }
1028 t.skip(1); // '}'
1029 if (min < 0 || min > 1000 || max == -2 || max > 1000 || (max >= 0 && min > max)) {
1030 // Numbers were negative or too big, or max is present and min > max.
1031 throw new PatternSyntaxException(ERR_INVALID_REPEAT_SIZE, t.from(start));
1032 }
1033 return (min << 16) | (max & 0xffff); // success
1034 }
1035
1036 // parsePerlFlags parses a Perl flag setting or non-capturing group or both,
1037 // like (?i) or (?: or (?i:.

Callers 1

parseInternalMethod · 0.95

Calls 6

parseIntMethod · 0.95
posMethod · 0.80
moreMethod · 0.80
fromMethod · 0.80
lookingAtMethod · 0.45
skipMethod · 0.45

Tested by

no test coverage detected