Ejemplo n.º 1
0
        int IEqualityComparer.GetHashCode(object obj)
        {
            RegExCacheIndex ri  = (RegExCacheIndex)obj;
            string          pat = (ri.CaseSensitive ? "T:" : "F:") + ri.Pattern;

            return(pat.GetHashCode());
        }
Ejemplo n.º 2
0
        private static Regex getCachedRegEx(string pattern, RegexOptions opt)
        {
            Context.CheckCancelled(); // Check if the user has cancelled

            Boolean         caseSensitive = (opt & RegexOptions.IgnoreCase) == RegexOptions.IgnoreCase;
            RegExCacheIndex ri            = new RegExCacheIndex(pattern, caseSensitive);

            if (regExCache.ContainsKey(ri))
            {
                Context.TraceEvent(100, 0, "RegExFilter: Returning Cached RegEx");
                Regex cachedRegEx;
                lock (regExCache.SyncRoot)
                {
                    cachedRegEx = (Regex)regExCache[ri];
                }
                return(cachedRegEx);
            }
            else
            {
                Context.TraceEvent(100, 0, "RegExFilter: Adding RegEx to Cache");
                Regex newRegEx = new Regex(pattern, opt);
                lock (regExCache.SyncRoot)
                {
                    regExCache.Add(ri, newRegEx);
                }
                return(newRegEx);
            }
        }
Ejemplo n.º 3
0
        bool IEqualityComparer.Equals(object x, object y)
        {
            RegExCacheIndex left  = (RegExCacheIndex)x;
            RegExCacheIndex right = (RegExCacheIndex)y;

            if (left.CaseSensitive == right.CaseSensitive)
            {
                if (left.CaseSensitive == true)
                {
                    return(string.Compare(left.Pattern, right.Pattern, false) == 0);
                }
                else
                {
                    return(string.Compare(left.Pattern, right.Pattern, true) == 0);
                }
            }
            else
            {
                return(false);
            }
        }
        private static Regex getCachedRegEx(string pattern, RegexOptions opt)
        {
            Context.CheckCancelled(); // Check if the user has cancelled

            Boolean caseSensitive = (opt & RegexOptions.IgnoreCase) == RegexOptions.IgnoreCase;
            RegExCacheIndex ri = new RegExCacheIndex(pattern, caseSensitive);

            if (regExCache.ContainsKey(ri))
            {
                Context.TraceEvent(100, 0, "RegExFilter: Returning Cached RegEx");
                Regex cachedRegEx;
                lock (regExCache.SyncRoot)
                {
                    cachedRegEx = (Regex)regExCache[ri];
                }
                return cachedRegEx;
            }
            else
            {
                Context.TraceEvent(100, 0, "RegExFilter: Adding RegEx to Cache");
                Regex newRegEx = new Regex(pattern, opt);
                lock(regExCache.SyncRoot)
                {
                    regExCache.Add(ri, newRegEx);
                }
                return newRegEx;
            }
        }