/// <summary>Stores the supplied arguments and capture information, returning the parsed expression.</summary> private RegexTree Init(string pattern, RegexOptions options, TimeSpan matchTimeout, [NotNull] ref CultureInfo?culture) { this.pattern = pattern; roptions = options; internalMatchTimeout = matchTimeout; culture ??= RegexParser.GetTargetCulture(options); // Parse the pattern. RegexTree tree = RegexParser.Parse(pattern, options, culture); // Store the relevant information, constructing the appropriate factory. capnames = tree.CaptureNameToNumberMapping; capslist = tree.CaptureNames; caps = tree.CaptureNumberSparseMapping; capsize = tree.CaptureCount; return(tree); }
internal Regex(string pattern, RegexOptions options, TimeSpan matchTimeout, CultureInfo?culture) { culture ??= RegexParser.GetTargetCulture(options); Init(pattern, options, matchTimeout, culture); if ((options & RegexOptions.NonBacktracking) != 0) { // If we're in non-backtracking mode, create the appropriate factory. factory = new SymbolicRegexRunnerFactory(_code, options, matchTimeout, culture); _code = null; } else if (RuntimeFeature.IsDynamicCodeCompiled && UseOptionC()) { // If the compile option is set and compilation is supported, then compile the code. factory = Compile(pattern, _code, options, matchTimeout != InfiniteMatchTimeout); _code = null; } }
protected internal override RegexRunner CreateInstance() => // Create a new interpreter instance. new RegexInterpreter(_code, RegexParser.GetTargetCulture(_code.Options));