Пример #1
0
        /**
         * Parses a regular expression character set. This method handles
         * the contents of the '[...]' construct in a regular expression.
         *
         * @return the element representing this character set
         *
         * @throws RegExpException if an error was encountered in the
         *             pattern string
         */
        private Element ParseCharSet()
        {
            CharacterSetElement charset;
            Element             elem;
            bool repeat = true;
            char start;
            char end;

            if (PeekChar(0) == '^')
            {
                ReadChar('^');
                charset = new CharacterSetElement(true);
            }
            else
            {
                charset = new CharacterSetElement(false);
            }

            while (PeekChar(0) > 0 && repeat)
            {
                start = (char)PeekChar(0);
                switch (start)
                {
                case ']':
                    repeat = false;
                    break;

                case '\\':
                    elem = ParseEscapeChar();
                    if (elem is StringElement)
                    {
                        charset.AddCharacters((StringElement)elem);
                    }
                    else
                    {
                        charset.AddCharacterSet((CharacterSetElement)elem);
                    }
                    break;

                default:
                    ReadChar(start);
                    if (PeekChar(0) == '-' &&
                        PeekChar(1) > 0 &&
                        PeekChar(1) != ']')
                    {
                        ReadChar('-');
                        end = ReadChar();
                        charset.AddRange(FixChar(start), FixChar(end));
                    }
                    else
                    {
                        charset.AddCharacter(FixChar(start));
                    }
                    break;
                }
            }

            return(charset);
        }
Пример #2
0
 /**
  * Adds a character subset to this character set.
  *
  * @param elem           the character set to add
  */
 public void AddCharacterSet(CharacterSetElement elem)
 {
     contents.Add(elem);
 }