Ejemplo n.º 1
0
        private void ProcessWildCard(TransitionState state, string sSearchIn, ref int nCurrIndex, int nSearchUpTo)
        {
            TransitionState toState = null;
            int             nIndex  = nCurrIndex;

            while (nIndex <= nSearchUpTo)
            {
                char ch = sSearchIn[nIndex];

                toState = state.GetSingleTransition(ch.ToString());

                if (toState != null)
                {
                    nCurrIndex = nIndex;
                }
                nIndex++;
            }
        }
Ejemplo n.º 2
0
        public bool FindMatch(string sSearchIn, int nSearchStartAt,
                              int nSearchEndAt, ref int nFoundBeginAt, ref int nFoundEndAt)
        {
            if (_startingDFAState == null || nSearchStartAt < 0)
            {
                return(false);
            }

            TransitionState stateStart = _startingDFAState;

            nFoundBeginAt = -1;
            nFoundEndAt   = -1;
            bool            accepted     = false;
            TransitionState toState      = null;
            TransitionState currentState = stateStart;
            int             nIndex       = nSearchStartAt;
            int             nSearchUpTo  = nSearchEndAt;

            while (nIndex <= nSearchUpTo)
            {
                if (_useGreedy && IsWildCard(currentState) == true)
                {
                    if (nFoundBeginAt == -1)
                    {
                        nFoundBeginAt = nIndex;
                    }
                    ProcessWildCard(currentState, sSearchIn, ref nIndex, nSearchUpTo);
                }

                char chInputSymbol = sSearchIn[nIndex];

                toState = currentState.GetSingleTransition(chInputSymbol.ToString());

                if (toState == null)
                {
                    toState = currentState.GetSingleTransition(MetaSymbol.ANY_ONE_CHAR_TRANS);
                }

                if (toState != null)
                {
                    if (nFoundBeginAt == -1)
                    {
                        nFoundBeginAt = nIndex;
                    }

                    if (toState.AcceptingState)
                    {
                        if (_matchAtEnd && nIndex != nSearchUpTo)
                        {
                        }
                        else
                        {
                            accepted    = true;
                            nFoundEndAt = nIndex;
                            if (_useGreedy == false)
                            {
                                break;
                            }
                        }
                    }

                    currentState = toState;
                    nIndex++;
                }
                else
                {
                    if (!_matchAtStart && !accepted)
                    {
                        nIndex = (nFoundBeginAt != -1 ? nFoundBeginAt + 1 : nIndex + 1);

                        nFoundBeginAt = -1;
                        nFoundEndAt   = -1;

                        currentState = stateStart;
                    }
                    else
                    {
                        break;
                    }
                }
            }

            if (!accepted)
            {
                if (stateStart.AcceptingState == false)
                {
                    return(false);
                }
                else
                {
                    nFoundBeginAt = nSearchStartAt;
                    nFoundEndAt   = nFoundBeginAt - 1;
                    return(true);
                }
            }

            return(true);
        }
Ejemplo n.º 3
0
 private bool IsWildCard(TransitionState state)
 {
     return(state == state.GetSingleTransition(MetaSymbol.ANY_ONE_CHAR_TRANS));
 }