Ejemplo n.º 1
0
 public PatternState(PatternState other)
 {
     _state = other.State;
     _startIndex = other.StateIndex;
 }
Ejemplo n.º 2
0
        private bool Find()
        {
            _matchedPatterns.Clear();
            _matchedPatternPositions.Clear();

            for (int j = 0; j < _pattern.Length; ++j)
            {
                char c = _pattern[j];
                for (int i = 0; i < _patternList.Count; i++)
                {
                    var patternState = _patternList[i];
                    var s = patternState.State.GetStates(c);
                    if (s != null && s.Count > 0)
                    {
                        patternState.State = s[0];
                        if (s[0].AcceptState)
                        {
                            _matchedPatternPositions.Add(patternState.StateIndex);
                            _matchedPatterns.Add(_pattern.Substring(patternState.StateIndex, j - patternState.StateIndex + 1));
                        }
                    }
                    else
                    {
                        _patternList.RemoveAt(i);
                        --i;
                    }
                }

                var startState = _DFA.GetFirstState();
                var transition = startState.GetStates(c);
                if (transition != null && transition.Count > 0)
                {
                    var patternState = new PatternState();
                    patternState.StateIndex = j;
                    patternState.State = transition[0];
                    _patternList.Add(patternState);

                    if (transition[0].AcceptState)
                    {
                        _matchedPatternPositions.Add(j);
                        _matchedPatterns.Add(c.ToString());
                    }
                }
                else
                {
                    //then entry state is already accepting state, like a*
                    if (startState.AcceptState)
                    {
                        _matchedPatternPositions.Add(j);
                        _matchedPatterns.Add(c.ToString());
                    }
                }
            }
            return _matchedPatternPositions.Count > 0;
        }