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

Method match

java/com/google/re2j/Machine.java:215–301  ·  view source on GitHub ↗
(MachineInput in, int pos, int anchor)

Source from the content-addressed store, hash-verified

213 // It reports whether a match was found.
214 // If so, matchcap holds the submatch information.
215 boolean match(MachineInput in, int pos, int anchor) {
216 int startCond = re2.cond;
217 if (startCond == Utils.EMPTY_ALL) { // impossible
218 return false;
219 }
220 if ((anchor == RE2.ANCHOR_START || anchor == RE2.ANCHOR_BOTH) && pos != 0) {
221 return false;
222 }
223 matched = false;
224 Arrays.fill(matchcap, 0, prog.numCap, -1);
225 Queue runq = q0, nextq = q1;
226 int r = in.step(pos);
227 int rune = r >> 3;
228 int width = r & 7;
229 int rune1 = -1;
230 int width1 = 0;
231 if (r != MachineInput.EOF) {
232 r = in.step(pos + width);
233 rune1 = r >> 3;
234 width1 = r & 7;
235 }
236 int flag; // bitmask of EMPTY_* flags
237 if (pos == 0) {
238 flag = Utils.emptyOpContext(-1, rune);
239 } else {
240 flag = in.context(pos);
241 }
242 for (; ; ) {
243
244 if (runq.isEmpty()) {
245 if ((startCond & Utils.EMPTY_BEGIN_TEXT) != 0 && pos != 0) {
246 // Anchored match, past beginning of text.
247 break;
248 }
249 if (matched) {
250 // Have match; finished exploring alternatives.
251 break;
252 }
253 if (!re2.prefix.isEmpty() && rune1 != re2.prefixRune && in.canCheckPrefix()) {
254 // Match requires literal prefix; fast search for it.
255 int advance = in.index(re2, pos);
256 if (advance < 0) {
257 break;
258 }
259 pos += advance;
260 r = in.step(pos);
261 rune = r >> 3;
262 width = r & 7;
263 r = in.step(pos + width);
264 rune1 = r >> 3;
265 width1 = r & 7;
266 }
267 }
268 if (!matched && (pos == 0 || anchor == RE2.UNANCHORED)) {
269 // If we are anchoring at begin then only add threads that begin
270 // at |pos| = 0.
271 if (ncap > 0) {
272 matchcap[0] = pos;

Callers 1

doExecuteMethod · 0.95

Calls 9

stepMethod · 0.95
emptyOpContextMethod · 0.95
isEmptyMethod · 0.95
addMethod · 0.95
freeMethod · 0.95
contextMethod · 0.45
canCheckPrefixMethod · 0.45
indexMethod · 0.45
endPosMethod · 0.45

Tested by

no test coverage detected