Example #1
0
        RegExpDfaWave GetWave(string text)
        {
            RegExpStringKey next   = null;
            int             length = text.Length;

            do
            {
                if (text != this._lastText)
                {
                    next = this._stringsToStatesCache[(text.Length == length) ? text : text.Substring(0, length)];
                }
                else
                {
                    next = this._lastState;
                }
                length--;
            }while ((length >= 0) && (next == null));
            if (next == null)
            {
                next = this.CacheWave(string.Empty, null, '\0', this.GetInitialStates());
            }
            length++;
            while (length < text.Length)
            {
                next = this.CacheWave((text.Length == (length + 1)) ? text : text.Substring(0, length + 1), next, text[length], next._Wave.GetNextWave(text[length]));
                length++;
            }
            this._lastState = next;
            this._lastText  = text;
            return(next._Wave);
        }
Example #2
0
            bool IEqualityComparer <object> .Equals(object x, object y)
            {
                RegExpStringKey item = x as RegExpStringKey;

                if (item == null)
                {
                    return(IsEqual((string)x, (RegExpStringKey)y));
                }
                RegExpStringKey key = y as RegExpStringKey;

                if (key != null)
                {
                    return(IsEqual(item, key));
                }
                return(IsEqual((string)y, item));
            }
Example #3
0
        RegExpStringKey CacheWave(string str, RegExpStringKey next, char symbol, RegExpDfaWave candidateWave)
        {
            RegExpDfaWave wave;

            if (candidateWave.Count == 0)
            {
                return(new RegExpStringKey(str, candidateWave, next, symbol));
            }
            if (!this._statesCache.TryGetValue(candidateWave, out wave))
            {
                wave = candidateWave;
                this._statesCache.Add(wave, wave);
            }
            RegExpStringKey key = new RegExpStringKey(str, wave, next, symbol);

            this._stringsToStatesCache.Add(key);
            return(key);
        }
Example #4
0
            static bool IsEqual(string str, RegExpStringKey key)
            {
                int length = str.Length;

                if (key._Length != length)
                {
                    return(false);
                }
                for (RegExpStringKey key2 = key; key2._Next != null; key2 = key2._Next)
                {
                    length--;
                    if (str[length] != key2._Symbol)
                    {
                        return(false);
                    }
                }
                return(true);
            }
Example #5
0
            static bool IsEqual(RegExpStringKey item, RegExpStringKey key)
            {
                if (item._Length != key._Length)
                {
                    return(false);
                }
                RegExpStringKey next = key;

                for (RegExpStringKey key3 = item; next._Next != null; key3 = key3._Next)
                {
                    if (key3._Symbol != next._Symbol)
                    {
                        return(false);
                    }
                    next = next._Next;
                }
                return(true);
            }
Example #6
0
 public void Add(RegExpStringKey key)
 {
     this.inner.Add(key, key);
 }