Ejemplo n.º 1
0
        /// <summary>Initializes the instance.</summary>
        /// <remarks>
        /// This is separated out of the constructor so that an app only using 'new Regex(pattern)'
        /// rather than 'new Regex(pattern, options)' can avoid statically referencing the Regex
        /// compiler, such that a tree shaker / linker can trim it away if it's not otherwise used.
        /// </remarks>
        private void Init(string pattern, RegexOptions options, TimeSpan matchTimeout, CultureInfo?culture)
        {
            ValidatePattern(pattern);
            ValidateOptions(options);
            ValidateMatchTimeout(matchTimeout);

            this.pattern         = pattern;
            roptions             = options;
            internalMatchTimeout = matchTimeout;

#if DEBUG
            if (IsDebug)
            {
                Debug.WriteLine($"Pattern: {pattern}    Options: {options & ~RegexOptions.Debug}    Timeout: {(matchTimeout == InfiniteMatchTimeout ? "infinite" : matchTimeout.ToString())}");
            }
#endif

            // Parse the input
            RegexTree tree = RegexParser.Parse(pattern, roptions, culture ?? ((options & RegexOptions.CultureInvariant) != 0 ? CultureInfo.InvariantCulture : CultureInfo.CurrentCulture));

            // Extract the relevant information
            capnames = tree.CapNames;
            capslist = tree.CapsList;
            _code    = RegexWriter.Write(tree);
            caps     = _code.Caps;
            capsize  = _code.CapSize;

            InitializeReferences();
        }
Ejemplo n.º 2
0
        private void Init(string pattern, RegexOptions options, TimeSpan matchTimeout, CultureInfo culture)
        {
            ValidatePattern(pattern);
            ValidateOptions(options);
            ValidateMatchTimeout(matchTimeout);

            this.pattern         = pattern;
            internalMatchTimeout = matchTimeout;
            roptions             = options;

            // Parse the input
            RegexTree tree = RegexParser.Parse(pattern, roptions, culture);

            // Generate the RegexCode from the node tree.  This is required for interpreting,
            // and is used as input into RegexOptions.Compiled and RegexOptions.NonBacktracking.
            _code = RegexWriter.Write(tree, culture);

            if ((options & RegexOptions.NonBacktracking) != 0)
            {
                // NonBacktracking doesn't support captures (other than the implicit top-level capture).
                capnames = null;
                capslist = null;
                caps     = null;
                capsize  = 1;
            }
            else
            {
                capnames = tree.CapNames;
                capslist = tree.CapsList;
                caps     = _code.Caps;
                capsize  = _code.CapSize;
            }
        }
Ejemplo n.º 3
0
        internal Regex(string pattern, RegexOptions options, TimeSpan matchTimeout, CultureInfo?culture)
        {
            Init(pattern, options, matchTimeout, culture);

            // if the compile option is set, then compile the code
            if (RuntimeFeature.IsDynamicCodeCompiled && UseOptionC())
            {
                factory = Compile(pattern, _code !, options, matchTimeout != InfiniteMatchTimeout);
                _code   = null;
            }
        }
Ejemplo n.º 4
0
 public CachedCodeEntry(CachedCodeEntryKey key, Hashtable capnames, string[] capslist, RegexCode code,
                        Hashtable caps, int capsize, ExclusiveReference runner, WeakReference <RegexReplacement?> replref)
 {
     Key       = key;
     Capnames  = capnames;
     Capslist  = capslist;
     Code      = code;
     Caps      = caps;
     Capsize   = capsize;
     Runnerref = runner;
     ReplRef   = replref;
 }
Ejemplo n.º 5
0
        internal Regex(string pattern, RegexOptions options, TimeSpan matchTimeout, CultureInfo?culture)
        {
            Init(pattern, options, matchTimeout, culture);

#if FEATURE_COMPILED
            // if the compile option is set, then compile the code
            if (UseOptionC())
            {
                // Storing into this Regex's factory will also implicitly update the cache
                factory = Compile(_code !, options, matchTimeout != InfiniteMatchTimeout);
                _code   = null;
            }
#endif
        }
Ejemplo n.º 6
0
        internal Regex(string pattern, RegexOptions options, TimeSpan matchTimeout, CultureInfo?culture)
        {
            culture ??= GetTargetCulture(options);
            Init(pattern, options, matchTimeout, culture);

            if ((options & RegexOptions.NonBacktracking) != 0)
            {
                // If we're in non-backtracking mode, create the appropriate factory.
                factory = SymbolicRegexRunner.CreateFactory(_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;
            }
        }
Ejemplo n.º 7
0
        private void Init(string pattern, RegexOptions options, TimeSpan matchTimeout, CultureInfo?culture)
        {
            ValidatePattern(pattern);
            ValidateOptions(options);
            ValidateMatchTimeout(matchTimeout);

            this.pattern         = pattern;
            internalMatchTimeout = matchTimeout;
            roptions             = options;
            culture ??= GetTargetCulture(options);

#if DEBUG
            if (IsDebug)
            {
                Debug.WriteLine($"Pattern: {pattern}    Options: {options & ~RegexOptions.Debug}    Timeout: {(matchTimeout == InfiniteMatchTimeout ? "infinite" : matchTimeout.ToString())}");
            }
#endif

            // Parse the input
            RegexTree tree = RegexParser.Parse(pattern, roptions, culture);

            // Generate the RegexCode from the node tree.  This is required for interpreting,
            // and is used as input into RegexOptions.Compiled and RegexOptions.NonBacktracking.
            _code = RegexWriter.Write(tree);

            if ((options & RegexOptions.NonBacktracking) != 0)
            {
                // NonBacktracking doesn't support captures (other than the implicit top-level capture).
                capnames = null;
                capslist = null;
                caps     = null;
                capsize  = 1;
            }
            else
            {
                capnames = tree.CapNames;
                capslist = tree.CapsList;
                caps     = _code.Caps;
                capsize  = _code.CapSize;
            }
        }
Ejemplo n.º 8
0
        /// <summary>Initializes the instance.</summary>
        /// <remarks>
        /// This is separated out of the constructor to allow the Regex ctor that doesn't
        /// take a RegexOptions to avoid rooting the regex compiler, such that it can be trimmed away.
        /// </remarks>
        private void Init(string pattern, RegexOptions options, TimeSpan matchTimeout, CultureInfo?culture)
        {
            ValidatePattern(pattern);
            ValidateOptions(options);
            ValidateMatchTimeout(matchTimeout);

            this.pattern         = pattern;
            roptions             = options;
            internalMatchTimeout = matchTimeout;

            // Parse the input
            RegexTree tree = RegexParser.Parse(pattern, roptions, culture ?? ((options & RegexOptions.CultureInvariant) != 0 ? CultureInfo.InvariantCulture : CultureInfo.CurrentCulture));

            // Extract the relevant information
            capnames = tree.CapNames;
            capslist = tree.CapsList;
            _code    = RegexWriter.Write(tree);
            caps     = _code.Caps;
            capsize  = _code.CapSize;

            InitializeReferences();
        }
Ejemplo n.º 9
0
        private void Init(string pattern, RegexOptions options, TimeSpan matchTimeout, CultureInfo culture)
        {
            ValidatePattern(pattern);
            ValidateOptions(options);
            ValidateMatchTimeout(matchTimeout);

            this.pattern         = pattern;
            internalMatchTimeout = matchTimeout;
            roptions             = options;

            // Parse the input
            RegexTree tree = RegexParser.Parse(pattern, roptions, culture);

            // Generate the RegexCode from the node tree.  This is required for interpreting,
            // and is used as input into RegexOptions.Compiled and RegexOptions.NonBacktracking.
            _code = RegexWriter.Write(tree, culture);

            capnames = tree.CapNames;
            capslist = tree.CapsList;
            caps     = _code.Caps;
            capsize  = _code.CapSize;
        }
Ejemplo n.º 10
0
        /// <summary>Initializes the instance.</summary>
        /// <remarks>
        /// This is separated out of the constructor so that an app only using 'new Regex(pattern)'
        /// rather than 'new Regex(pattern, options)' can avoid statically referencing the Regex
        /// compiler, such that a tree shaker / linker can trim it away if it's not otherwise used.
        /// </remarks>
        private void Init(string pattern, RegexOptions options, TimeSpan matchTimeout, CultureInfo?culture)
        {
            ValidatePattern(pattern);
            ValidateOptions(options);
            ValidateMatchTimeout(matchTimeout);

            this.pattern         = pattern;
            roptions             = options;
            internalMatchTimeout = matchTimeout;

#if DEBUG
            if (Debug)
            {
                System.Diagnostics.Debug.Write($"Pattern:     {pattern}");
                RegexOptions displayOptions = options & ~RegexOptions.Debug;
                if (displayOptions != RegexOptions.None)
                {
                    System.Diagnostics.Debug.Write($"Options:     {displayOptions}");
                }
                if (matchTimeout != Regex.InfiniteMatchTimeout)
                {
                    System.Diagnostics.Debug.Write($"Timeout:     {matchTimeout}");
                }
            }
#endif

            // Parse the input
            RegexTree tree = RegexParser.Parse(pattern, roptions, culture ?? ((options & RegexOptions.CultureInvariant) != 0 ? CultureInfo.InvariantCulture : CultureInfo.CurrentCulture));

            // Extract the relevant information
            capnames = tree.CapNames;
            capslist = tree.CapsList;
            _code    = RegexWriter.Write(tree);
            caps     = _code.Caps;
            capsize  = _code.CapSize;

            InitializeReferences();
        }
Ejemplo n.º 11
0
        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.
                // If the compiler can't compile this regex, it'll return null, and we'll fall back
                // to the interpreter.
                factory = Compile(pattern, _code, options, matchTimeout != InfiniteMatchTimeout);
                if (factory is not null)
                {
                    _code = null;
                }
            }
        }
Ejemplo n.º 12
0
 public void AddCompiled(RegexRunnerFactory factory)
 {
     Factory = factory;
     Code    = null;
 }