예제 #1
0
 /**
  * Adds a transition to this tree. If the lower-case flag is
  * set, the character will be converted to lower-case before
  * being added.
  *
  * @param c              the character to transition for
  * @param lowerCase      the lower-case conversion flag
  * @param state          the state to transition to
  */
 public void Add(char c, bool lowerCase, DFAState state)
 {
     if (lowerCase)
     {
         c = Char.ToLower(c);
     }
     if (value == '\0')
     {
         this.value = c;
         this.state = state;
         this.left  = new TransitionTree();
         this.right = new TransitionTree();
     }
     else if (value > c)
     {
         left.Add(c, false, state);
     }
     else
     {
         right.Add(c, false, state);
     }
 }
예제 #2
0
        /**
         * Adds a string match to this automaton. New states and
         * transitions will be added to extend this automaton to
         * support the specified string.
         *
         * @param str              the string to match
         * @param caseInsensitive  the case-insensitive flag
         * @param value            the match value
         */
        public void AddMatch(string str, bool caseInsensitive, TokenPattern value)
        {
            DFAState state;
            DFAState next;
            char     c     = str[0];
            int      start = 0;

            if (caseInsensitive)
            {
                c = Char.ToLower(c);
            }
            if (c < 128)
            {
                state = ascii[c];
                if (state == null)
                {
                    state = ascii[c] = new DFAState();
                }
                start++;
            }
            else
            {
                state = nonAscii;
            }
            for (int i = start; i < str.Length; i++)
            {
                next = state.tree.Find(str[i], caseInsensitive);
                if (next == null)
                {
                    next = new DFAState();
                    state.tree.Add(str[i], caseInsensitive, next);
                }
                state = next;
            }
            state.value = value;
        }