Beispiel #1
0
        /*
         * Release an object back to the cache
         *
         * If the object is the one that's under lock, the lock
         * is released.
         *
         * If there is no cached object, then the lock is obtained
         * and the object is placed in the cache.
         *
         */
        internal void Release(Object obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }

            // if this reference owns the lock, release it

            if (_obj == obj)
            {
                _obj    = null;
                _locked = 0;
                return;
            }

            // if no reference owns the lock, try to cache this reference

            if (_obj == null)
            {
                // try to obtain the lock

                if (0 == Interlocked.Exchange(ref _locked, 1))
                {
                    // if there's really no reference, cache this reference

                    if (_ref == null)
                    {
                        _ref = (RegexRunner)obj;
                    }

                    // release the lock

                    _locked = 0;
                    return;
                }
            }
        }
Beispiel #2
0
 protected static bool CharInClass(char ch, String charClass, RegexRunner runner)
 {
     return(RegexCharClass.CharInClass(ch, charClass, runner.charInClassOptimize));
 }
Beispiel #3
0
        /*
         * Internal worker called by all the public APIs
         */
        internal Match Run(bool quick, int prevlen, String input, int beginning, int length, int startat, ref Match resultMatch, bool createResultMatchIfNotProvided)
        {
            Match       match;
            RegexRunner runner = null;

            if (startat < 0 || startat > input.Length)
            {
                throw new ArgumentOutOfRangeException("start", SR.GetString(SR.BeginIndexNotNegative));
            }

            if (length < 0 || length > input.Length)
            {
                throw new ArgumentOutOfRangeException("length", SR.GetString(SR.LengthNotNegative));
            }

            if (resultMatch != null && resultMatch._regex != this)
            {
                throw new ArgumentException(SR.GetString(SR.BadResultMatch), "resultMatch");
            }

            // There may be a cached runner; grab ownership of it if we can.

            runner = (RegexRunner)runnerref.Get();

            // Create a RegexRunner instance if we need to

            if (runner == null)
            {
                // Use the compiled RegexRunner factory if the code was compiled to MSIL

                if (factory != null)
                {
                    runner = factory.CreateInstance();
                }
                else
                {
                    runner = new RegexInterpreter(code, UseOptionInvariant() ? CultureInfo.InvariantCulture : CultureInfo.CurrentCulture);
                }
            }

            if (resultMatch == null && createResultMatchIfNotProvided)
            {
                resultMatch = CreateNewMatch(String.Empty, 0, 0, 0);
            }

            // Do the scan starting at the requested position

            match = runner.Scan(this, input, beginning, beginning + length, startat, prevlen, quick, resultMatch);

            // Release or fill the cache slot

            runnerref.Release(runner);

#if DBG
            if (Debug && match != null)
            {
                match.Dump();
            }
#endif
            return(match);
        }
Beispiel #4
0
        protected static bool CharInSet(char ch, String set, String category, RegexRunner runner)
        {
            string charClass = RegexCharClass.ConvertOldStringsToClass(set, category);

            return(RegexCharClass.CharInClass(ch, charClass, runner.charInClassOptimize));
        }