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

Class Matcher

java/com/google/re2j/Matcher.java:41–608  ·  view source on GitHub ↗

A stateful iterator that interprets a regex Pattern on a specific input. Its interface mimics the JDK 1.4.2 java.util.regex.Matcher. Conceptually, a Matcher consists of four parts: A compiled regular expression Pattern, set at construction and fixed for the life

Source from the content-addressed store, hash-verified

39 * @author rsc@google.com (Russ Cox)
40 */
41public final class Matcher {
42 // The pattern being matched.
43 private final Pattern pattern;
44
45 // The group indexes, in [start, end) pairs. Zeroth pair is overall match.
46 private final int[] groups;
47
48 private final Map<String, Integer> namedGroups;
49
50 // The number of submatches (groups) in the pattern.
51 private final int groupCount;
52
53 // The number of instructions in the pattern.
54 private final int numberOfInstructions;
55
56 private MatcherInput matcherInput;
57
58 // The input length in UTF16 codes.
59 private int inputLength;
60
61 // The append position: where the next append should start.
62 private int appendPos;
63
64 // Is there a current match?
65 private boolean hasMatch;
66
67 // Have we found the submatches (groups) of the current match?
68 // group[0], group[1] are set regardless.
69 private boolean hasGroups;
70
71 // The anchor flag to use when repeating the match to find subgroups.
72 private int anchorFlag;
73
74 private Matcher(Pattern pattern) {
75 if (pattern == null) {
76 throw new NullPointerException("pattern is null");
77 }
78 this.pattern = pattern;
79 RE2 re2 = pattern.re2();
80 groupCount = re2.numberOfCapturingGroups();
81 groups = new int[2 + 2 * groupCount];
82 namedGroups = re2.namedGroups;
83 numberOfInstructions = re2.numberOfInstructions();
84 }
85
86 /** Creates a new {@code Matcher} with the given pattern and input. */
87 Matcher(Pattern pattern, CharSequence input) {
88 this(pattern);
89 reset(input);
90 }
91
92 Matcher(Pattern pattern, MatcherInput input) {
93 this(pattern);
94 reset(input);
95 }
96
97 /** Returns the {@code Pattern} associated with this {@code Matcher}. */
98 public Pattern pattern() {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…