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

Method loadGroup

java/com/google/re2j/Matcher.java:279–310  ·  view source on GitHub ↗

Helper: finds subgroup information if needed for group.

(int group)

Source from the content-addressed store, hash-verified

277
278 /** Helper: finds subgroup information if needed for group. */
279 private void loadGroup(int group) {
280 if (group < 0 || group > groupCount) {
281 throw new IndexOutOfBoundsException("Group index out of bounds: " + group);
282 }
283 if (!hasMatch) {
284 throw new IllegalStateException("perhaps no match attempted");
285 }
286 if (group == 0 || hasGroups) {
287 return;
288 }
289
290 // Include the character after the matched text (if there is one).
291 // This is necessary in the case of inputSequence abc and pattern
292 // (a)(b$)?(b)? . If we do pass in the trailing c,
293 // the groups evaluate to new String[] {"ab", "a", null, "b" }
294 // If we don't, they evaluate to new String[] {"ab", "a", "b", null}
295 // We know it won't affect the total matched because the previous call
296 // to match included the extra character, and it was not matched then.
297 int end = groups[1] + 1;
298 if (end > inputLength) {
299 end = inputLength;
300 }
301
302 boolean ok =
303 pattern.re2().match(matcherInput, groups[0], end, anchorFlag, groups, 1 + groupCount);
304 // Must match - hasMatch says that the last call with these
305 // parameters worked just fine.
306 if (!ok) {
307 throw new IllegalStateException("inconsistency in matching group data");
308 }
309 hasGroups = true;
310 }
311
312 /**
313 * Matches the entire input against the pattern (anchored start and end). If there is a match,

Callers 2

startMethod · 0.95
endMethod · 0.95

Calls 2

re2Method · 0.80
matchMethod · 0.45

Tested by

no test coverage detected