internal CachedCodeEntry(string key, Hashtable capnames, string[] capslist, RegexCode code, Hashtable caps, int capsize, ExclusiveReference runner, SharedReference repl)
 {
     this._key = key;
     this._capnames = capnames;
     this._capslist = capslist;
     this._code = code;
     this._caps = caps;
     this._capsize = capsize;
     this._runnerref = runner;
     this._replref = repl;
 }
コード例 #2
0
 private Regex(string pattern, RegexOptions options, bool useCache)
 {
     CachedCodeEntry cachedAndUpdate = null;
     string str = null;
     if (pattern == null)
     {
         throw new ArgumentNullException("pattern");
     }
     if ((options < RegexOptions.None) || ((((int) options) >> 10) != 0))
     {
         throw new ArgumentOutOfRangeException("options");
     }
     if (((options & RegexOptions.ECMAScript) != RegexOptions.None) && ((options & ~(RegexOptions.CultureInvariant | RegexOptions.ECMAScript | RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.IgnoreCase)) != RegexOptions.None))
     {
         throw new ArgumentOutOfRangeException("options");
     }
     if ((options & RegexOptions.CultureInvariant) != RegexOptions.None)
     {
         str = CultureInfo.InvariantCulture.ToString();
     }
     else
     {
         str = CultureInfo.CurrentCulture.ToString();
     }
     string[] strArray = new string[] { ((int) options).ToString(NumberFormatInfo.InvariantInfo), ":", str, ":", pattern };
     string key = string.Concat(strArray);
     cachedAndUpdate = LookupCachedAndUpdate(key);
     this.pattern = pattern;
     this.roptions = options;
     if (cachedAndUpdate == null)
     {
         RegexTree t = RegexParser.Parse(pattern, this.roptions);
         this.capnames = t._capnames;
         this.capslist = t._capslist;
         this.code = RegexWriter.Write(t);
         this.caps = this.code._caps;
         this.capsize = this.code._capsize;
         this.InitializeReferences();
         t = null;
         if (useCache)
         {
             cachedAndUpdate = this.CacheCode(key);
         }
     }
     else
     {
         this.caps = cachedAndUpdate._caps;
         this.capnames = cachedAndUpdate._capnames;
         this.capslist = cachedAndUpdate._capslist;
         this.capsize = cachedAndUpdate._capsize;
         this.code = cachedAndUpdate._code;
         this.factory = cachedAndUpdate._factory;
         this.runnerref = cachedAndUpdate._runnerref;
         this.replref = cachedAndUpdate._replref;
         this.refsInitialized = true;
     }
     if (this.UseOptionC() && (this.factory == null))
     {
         this.factory = this.Compile(this.code, this.roptions);
         if (useCache && (cachedAndUpdate != null))
         {
             cachedAndUpdate.AddCompiled(this.factory);
         }
         this.code = null;
     }
 }
コード例 #3
0
        private Regex(String pattern, RegexOptions options, bool useCache) {
            RegexTree tree;
            CachedCodeEntry cached = null;
            string cultureKey = null;

            if (pattern == null) 
                throw new ArgumentNullException("pattern");
            if (options < RegexOptions.None || ( ((int) options) >> MaxOptionShift) != 0)
                throw new ArgumentOutOfRangeException("options");
            if ((options &   RegexOptions.ECMAScript) != 0
             && (options & ~(RegexOptions.ECMAScript | 
                             RegexOptions.IgnoreCase | 
                             RegexOptions.Multiline | 
                             RegexOptions.Compiled | 
                             RegexOptions.CultureInvariant
#if DBG
                           | RegexOptions.Debug
#endif
                                               )) != 0)
                throw new ArgumentOutOfRangeException("options");

            // Try to look up this regex in the cache.  We do this regardless of whether useCache is true since there's
            // really no reason not to. 
            if ((options & RegexOptions.CultureInvariant) != 0)
                cultureKey = CultureInfo.InvariantCulture.ThreeLetterWindowsLanguageName;
            else
                cultureKey = CultureInfo.CurrentCulture.ThreeLetterWindowsLanguageName;
            
            String key = ((int) options).ToString(NumberFormatInfo.InvariantInfo) + ":" + cultureKey + ":" + pattern;
            cached = LookupCachedAndUpdate(key);

            this.pattern = pattern;
            this.roptions = options;

            if (cached == null) {
                // Parse the input
                tree = RegexParser.Parse(pattern, roptions);

                // Extract the relevant information
                capnames   = tree._capnames;
                capslist   = tree._capslist;
                code       = RegexWriter.Write(tree);
                caps       = code._caps;
                capsize    = code._capsize;

                InitializeReferences();

                tree = null;
                if (useCache)
                    cached = CacheCode(key);
            }
            else {
                caps       = cached._caps;
                capnames   = cached._capnames;
                capslist   = cached._capslist;
                capsize    = cached._capsize;
                code       = cached._code;
                factory    = cached._factory;
                runnerref  = cached._runnerref;
                replref    = cached._replref;
                refsInitialized = true;
            }

            // if the compile option is set, then compile the code if it's not already
            if (UseOptionC() && factory == null) {
                factory = Compile(code, roptions);

                if (useCache && cached != null)
                    cached.AddCompiled(factory);
                code = null;
            }
        }
コード例 #4
0
 protected void InitializeReferences()
 {
     if (this.refsInitialized)
     {
         throw new NotSupportedException(SR.GetString("OnlyAllowedOnce"));
     }
     this.refsInitialized = true;
     this.runnerref = new ExclusiveReference();
     this.replref = new SharedReference();
 }
コード例 #5
0
ファイル: Regex.cs プロジェクト: kkurni-icloud/corefx-old
        internal CachedCodeEntry(CachedCodeEntryKey key, Dictionary <String, Int32> capnames, String[] capslist, RegexCode code, Dictionary <Int32, Int32> caps, int capsize, ExclusiveReference runner, SharedReference repl)
        {
            _key      = key;
            _capnames = capnames;
            _capslist = capslist;

            _code    = code;
            _caps    = caps;
            _capsize = capsize;

            _runnerref = runner;
            _replref   = repl;
        }
コード例 #6
0
 /// <devdoc>
 /// </devdoc>
 protected void InitializeReferences() {
     if (refsInitialized)
         throw new NotSupportedException(SR.GetString(SR.OnlyAllowedOnce));
     
     refsInitialized = true;
     runnerref  = new ExclusiveReference();
     replref    = new SharedReference();
 }
コード例 #7
0
 internal CachedCodeEntry(string key, Hashtable capnames, string[] capslist, RegexCode code, Hashtable caps, int capsize, ExclusiveReference runner, SharedReference repl)
 {
     this._key       = key;
     this._capnames  = capnames;
     this._capslist  = capslist;
     this._code      = code;
     this._caps      = caps;
     this._capsize   = capsize;
     this._runnerref = runner;
     this._replref   = repl;
 }
コード例 #8
0
ファイル: Regex.cs プロジェクト: kazuk/corefx
        private Regex(String pattern, RegexOptions options, TimeSpan matchTimeout, bool useCache)
        {
            RegexTree       tree;
            CachedCodeEntry cached     = null;
            string          cultureKey = null;

            if (pattern == null)
            {
                throw new ArgumentNullException("pattern");
            }
            if (options < RegexOptions.None || (((int)options) >> MaxOptionShift) != 0)
            {
                throw new ArgumentOutOfRangeException("options");
            }
            if ((options & RegexOptions.ECMAScript) != 0 &&
                (options & ~(RegexOptions.ECMAScript |
                             RegexOptions.IgnoreCase |
                             RegexOptions.Multiline |
                             RegexOptions.CultureInvariant
#if DEBUG
                             | RegexOptions.Debug
#endif
                             )) != 0)
            {
                throw new ArgumentOutOfRangeException("options");
            }

            ValidateMatchTimeout(matchTimeout);

            // Try to look up this regex in the cache.  We do this regardless of whether useCache is true since there's
            // really no reason not to.
            if ((options & RegexOptions.CultureInvariant) != 0)
            {
                cultureKey = CultureInfo.InvariantCulture.ToString(); // "English (United States)"
            }
            else
            {
                cultureKey = CultureInfo.CurrentCulture.ToString();
            }

            var key = new CachedCodeEntryKey(options, cultureKey, pattern);
            cached = LookupCachedAndUpdate(key);

            _pattern  = pattern;
            _roptions = options;

            _internalMatchTimeout = matchTimeout;

            if (cached == null)
            {
                // Parse the input
                tree = RegexParser.Parse(pattern, _roptions);

                // Extract the relevant information
                _capnames = tree._capnames;
                _capslist = tree._capslist;
                _code     = RegexWriter.Write(tree);
                _caps     = _code._caps;
                _capsize  = _code._capsize;

                InitializeReferences();

                tree = null;
                if (useCache)
                {
                    cached = CacheCode(key);
                }
            }
            else
            {
                _caps            = cached._caps;
                _capnames        = cached._capnames;
                _capslist        = cached._capslist;
                _capsize         = cached._capsize;
                _code            = cached._code;
                _runnerref       = cached._runnerref;
                _replref         = cached._replref;
                _refsInitialized = true;
            }
        }
コード例 #9
0
        private Regex(String pattern, RegexOptions options, bool useCache)
        {
            RegexTree       tree;
            CachedCodeEntry cached     = null;
            string          cultureKey = null;

            if (pattern == null)
            {
                throw new ArgumentNullException("pattern");
            }
            if (options < RegexOptions.None || (((int)options) >> MaxOptionShift) != 0)
            {
                throw new ArgumentOutOfRangeException("options");
            }
            if ((options & RegexOptions.ECMAScript) != 0 &&
                (options & ~(RegexOptions.ECMAScript |
                             RegexOptions.IgnoreCase |
                             RegexOptions.Multiline |
                             RegexOptions.Compiled |
                             RegexOptions.CultureInvariant
#if DBG
                             | RegexOptions.Debug
#endif
                             )) != 0)
            {
                throw new ArgumentOutOfRangeException("options");
            }

            // Try to look up this regex in the cache.  We do this regardless of whether useCache is true since there's
            // really no reason not to.
            if ((options & RegexOptions.CultureInvariant) != 0)
            {
                cultureKey = CultureInfo.InvariantCulture.ThreeLetterWindowsLanguageName;
            }
            else
            {
                cultureKey = CultureInfo.CurrentCulture.ThreeLetterWindowsLanguageName;
            }

            String key = ((int)options).ToString(NumberFormatInfo.InvariantInfo) + ":" + cultureKey + ":" + pattern;
            cached = LookupCachedAndUpdate(key);

            this.pattern  = pattern;
            this.roptions = options;

            if (cached == null)
            {
                // Parse the input
                tree = RegexParser.Parse(pattern, roptions);

                // Extract the relevant information
                capnames = tree._capnames;
                capslist = tree._capslist;
                code     = RegexWriter.Write(tree);
                caps     = code._caps;
                capsize  = code._capsize;

                InitializeReferences();

                tree = null;
                if (useCache)
                {
                    cached = CacheCode(key);
                }
            }
            else
            {
                caps            = cached._caps;
                capnames        = cached._capnames;
                capslist        = cached._capslist;
                capsize         = cached._capsize;
                code            = cached._code;
                factory         = cached._factory;
                runnerref       = cached._runnerref;
                replref         = cached._replref;
                refsInitialized = true;
            }

            // if the compile option is set, then compile the code if it's not already
            if (UseOptionC() && factory == null)
            {
                factory = Compile(code, roptions);

                if (useCache && cached != null)
                {
                    cached.AddCompiled(factory);
                }
                code = null;
            }
        }
コード例 #10
0
ファイル: regex.cs プロジェクト: ArildF/masters
        // Returns a Regex object corresponding to the given pattern, compiled with
        // the specified options.
        /// <include file='doc\Regex.uex' path='docs/doc[@for="Regex.Regex1"]/*' />
        /// <devdoc>
        ///    <para>
        ///       Creates and compiles a regular expression object for the
        ///       specified regular expression
        ///       with options that modify the pattern.
        ///    </para>
        /// </devdoc>
        public Regex(String pattern, RegexOptions options) {
            RegexTree tree;
            CachedCodeEntry cached;

            if (pattern == null) 
                throw new ArgumentNullException("pattern");


            if (options < RegexOptions.None || ( ((int) options) >> MaxOptionShift) != 0)
                throw new ArgumentOutOfRangeException("options");
            if ((options &   RegexOptions.ECMAScript) != 0
             && (options & ~(RegexOptions.ECMAScript | RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.Compiled
#if DBG
                           | RegexOptions.Debug
#endif
                                               )) != 0)
                throw new ArgumentOutOfRangeException("options");

            String key = ((int) options).ToString(NumberFormatInfo.InvariantInfo) + ":" + pattern;

            cached = LookupCached(key);

            this.pattern = pattern;
            this.roptions = options;

            if (cached == null) {
                // Parse the input
                tree = RegexParser.Parse(pattern, roptions);

                // Extract the relevant information
                capnames   = tree._capnames;
                capslist   = tree._capslist;
                code       = RegexWriter.Write(tree);
                caps       = code._caps;
                capsize    = code._capsize;

                InitializeReferences();

                tree = null;
                cachedentry= CacheCode(key);
            }
            else {
                caps       = cached._caps;
                capnames   = cached._capnames;
                capslist   = cached._capslist;
                capsize    = cached._capsize;
                code       = cached._code;
                factory    = cached._factory;
                runnerref  = cached._runnerref;
                replref    = cached._replref;
                refsInitialized = true;

                cachedentry     = cached;
            }

            // if the compile option is set, then compile the code if it's not already
            if (UseOptionC() && factory == null) {
                factory = Compile(code, roptions);
                cachedentry.AddCompiled(factory);
                code = null;
            }
        }
コード例 #11
0
ファイル: regex.cs プロジェクト: ArildF/masters
        internal CachedCodeEntry(RegexOptions options, Hashtable capnames, String[] capslist, RegexCode code, Hashtable caps, int capsize, ExclusiveReference runner, SharedReference repl) {

            _options    = options;
            _capnames   = capnames;
            _capslist   = capslist;

            _code       = code;
            _caps       = caps;
            _capsize    = capsize;

            _runnerref     = runner;
            _replref       = repl;

            _references = 1;
        }