コード例 #1
0
        internal System.Text.RegularExpressions.Match Run(bool quick, int prevlen, string input, int beginning, int length, int startat)
        {
            RegexRunner runner = null;

            if ((startat < 0) || (startat > input.Length))
            {
                throw new ArgumentOutOfRangeException("start", SR.GetString("BeginIndexNotNegative"));
            }
            if ((length < 0) || (length > input.Length))
            {
                throw new ArgumentOutOfRangeException("length", SR.GetString("LengthNotNegative"));
            }
            runner = (RegexRunner)this.runnerref.Get();
            if (runner == null)
            {
                if (this.factory != null)
                {
                    runner = this.factory.CreateInstance();
                }
                else
                {
                    runner = new RegexInterpreter(this.code, this.UseOptionInvariant() ? CultureInfo.InvariantCulture : CultureInfo.CurrentCulture);
                }
            }
            System.Text.RegularExpressions.Match match = runner.Scan(this, input, beginning, beginning + length, startat, prevlen, quick);
            this.runnerref.Release(runner);
            return(match);
        }
コード例 #2
0
ファイル: Reference.cs プロジェクト: rsumner31/corefx2
        /// <summary>
        /// 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.
        /// </summary>
        public void Release(object obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException(nameof(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;
                }
            }
        }
コード例 #3
0
ファイル: Reference.cs プロジェクト: 939481896/dotnet-corefx
        /// <summary>
        /// Return an object and grab an exclusive lock.
        ///
        /// If the exclusive lock can't be obtained, null is returned;
        /// if the object can't be returned, the lock is released.
        /// </summary>
        public RegexRunner Get()
        {
            // try to obtain the lock

            if (0 == Interlocked.Exchange(ref _locked, 1))
            {
                // grab reference
                RegexRunner obj = _ref;

                // release the lock and return null if no reference
                if (obj == null)
                {
                    _locked = 0;

                    return(null);
                }

                // remember the reference and keep the lock
                _obj = obj;

                return(obj);
            }

            return(null);
        }
コード例 #4
0
ファイル: Regex.cs プロジェクト: bkeys/linux-packaging-mono
        /*
         * Internal worker called by all the public APIs
         */
        internal Match Run(bool quick, int prevlen, string input, int beginning, int length, int startat)
        {
            Match       match;
            RegexRunner runner = null;

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

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

            // 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);
                }
            }

            try
            {
                // Do the scan starting at the requested position
                match = runner.Scan(this, input, beginning, beginning + length, startat, prevlen, quick, internalMatchTimeout);
            }
            finally
            {
                // Release or fill the cache slot
                _runnerref.Release(runner);
            }

#if DEBUG
            if (Debug && match != null)
            {
                match.Dump();
            }
#endif
            return(match);
        }
コード例 #5
0
        internal System.Text.RegularExpressions.Match Run(bool quick, int prevlen, string input, int beginning, int length, int startat)
        {
            RegexRunner runner = null;

            if ((startat < 0) || (startat > input.Length))
            {
                throw new ArgumentOutOfRangeException();
            }
            if ((length < 0) || (length > input.Length))
            {
                throw new ArgumentOutOfRangeException();
            }
            runner = new RegexInterpreter(this.code, this.UseOptionInvariant() ? CultureInfo.InvariantCulture : CultureInfo.CurrentCulture);
            return(runner.Scan(this, input, beginning, beginning + length, startat, prevlen, quick));
        }
コード例 #6
0
ファイル: regex.cs プロジェクト: Paul1nh0/Singularity
        // Internal worker called by all the public APIs
        internal Match Run(bool quick, int prevlen, String input, int beginning, int length, int startat)
        {
            Match       match;
            RegexRunner runner = null;

            if (startat < 0 || startat > input.Length)
            {
                throw new ArgumentOutOfRangeException("start", ""); //XXX: SR.GetString(SR.BeginIndexNotNegative));
            }
            if (length < 0 || length > input.Length)
            {
                throw new ArgumentOutOfRangeException("length", ""); //XXX: SR.GetString(SR.LengthNotNegative));
            }
            // 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);
            }

            // Do the scan starting at the requested position

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

            // Release or fill the cache slot

            runnerref.Release(runner);

#if DBG
            if (UseOptionDebug())
            {
                match.Dump();
            }
#endif
            return(match);
        }
コード例 #7
0
 internal void Release(object obj)
 {
     if (obj == null)
     {
         throw new ArgumentNullException("obj");
     }
     if (this._obj == obj)
     {
         this._obj    = null;
         this._locked = 0;
     }
     else if ((this._obj == null) && (Interlocked.Exchange(ref this._locked, 1) == 0))
     {
         if (this._ref == null)
         {
             this._ref = (RegexRunner)obj;
         }
         this._locked = 0;
     }
 }
 internal void Release(object obj)
 {
     if (obj == null)
     {
         throw new ArgumentNullException("obj");
     }
     if (this._obj == obj)
     {
         this._obj = null;
         this._locked = 0;
     }
     else if ((this._obj == null) && (Interlocked.Exchange(ref this._locked, 1) == 0))
     {
         if (this._ref == null)
         {
             this._ref = (RegexRunner) obj;
         }
         this._locked = 0;
     }
 }
コード例 #9
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;
                }
            }
        }