/// <summary>
 /// Checks if the specified character matches this character
 /// set.This method takes the inverted flag into account.
 /// </summary>
 /// <param name="c">The character to check</param>
 /// <returns>True if the character is in the set, false if not</returns>
 private bool InSet(char c)
 {
     if (this == CharacterSetElement.DOT)
     {
         return(CharacterSetElement.InDotSet(c));
     }
     else if (this == CharacterSetElement.DIGIT ||
              this == CharacterSetElement.NONDIGIT)
     {
         return(CharacterSetElement.InDigitSet(c) != this.inverted);
     }
     else if (this == CharacterSetElement.WHITESPACE ||
              this == CharacterSetElement.NONWHITESPACE)
     {
         return(CharacterSetElement.InWhitespaceSet(c) != this.inverted);
     }
     else if (this == CharacterSetElement.WORD ||
              this == CharacterSetElement.NONWORD)
     {
         return(CharacterSetElement.InWordSet(c) != this.inverted);
     }
     else
     {
         return(this.InUserSet(c) != this.inverted);
     }
 }
Example #2
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);
        }
Example #3
0
 /**
  * Adds a character subset to this character set.
  *
  * @param elem           the character set to add
  */
 public void AddCharacterSet(CharacterSetElement elem)
 {
     contents.Add(elem);
 }
Example #4
0
 /**
  * Adds a character subset to this character set.
  *
  * @param elem           the character set to add
  */
 public void AddCharacterSet(CharacterSetElement elem) {
     contents.Add(elem);
 }
Example #5
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;
        }
 /// <summary>
 /// Adds a character subset to this character set.
 /// </summary>
 /// <param name="elem">The character set to add</param>
 public void AddCharacterSet(CharacterSetElement elem)
 {
     this.charSetContents.Add(elem);
 }