// Exposed to ExecTests. public static RE2 compileImpl(String expr, int mode, bool longest) { Regexp re = Parser.parse(expr, mode); int maxCap = re.maxCap(); // (may shrink during simplify) re = Simplify.simplify(re); Prog prog = Compiler.compileRegexp(re); RE2 re2 = new RE2(expr, prog, maxCap, longest); StringBuilder prefixBuilder = new StringBuilder(); re2.prefixComplete = prog.prefix(prefixBuilder); re2.prefix = prefixBuilder.ToString(); try { re2.prefixUTF8 = Encoding.UTF8.GetBytes(re2.prefix); } catch (Exception e) { throw new IllegalStateException("can't happen"); } if (re2.prefix.Length > 0) { re2.prefixRune = Char.ConvertToUtf32(re2.prefix, 0); } return(re2); }
/** * Constructs a matching Machine for the specified {@code RE2}. */ public Machine(RE2 re2) { this.prog = re2.prog; this.re2 = re2; this.q0 = new Queue(prog.numInst()); this.q1 = new Queue(prog.numInst()); this.matchcap = new int[prog.numCap < 2 ? 2 : prog.numCap]; }
private RE2(String expr, Prog prog, int numSubexp, bool longest) { this.expr = expr; this.prog = prog; this.numSubexp = numSubexp; this.cond = prog.startCond(); this.longest = longest; }
// This is visible for testing. RE2(String expr) { RE2 re2 = RE2.compile(expr); // Copy everything. this.expr = re2.expr; this.prog = re2.prog; this.cond = re2.cond; this.numSubexp = re2.numSubexp; this.longest = re2.longest; this.prefix = re2.prefix; this.prefixUTF8 = re2.prefixUTF8; this.prefixComplete = re2.prefixComplete; this.prefixRune = re2.prefixRune; }