Package jflex

Class CharClasses


  • public class CharClasses
    extends java.lang.Object
    Character Classes.
    Version:
    JFlex 1.7.0
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.List<IntCharSet> classes
      the char classes
      private static boolean DEBUG
      debug flag (for char classes only)
      static int maxChar
      the largest character that can be used in char classes
      private int maxCharUsed
      the largest character actually used in a specification
      LexScan scanner  
    • Constructor Summary

      Constructors 
      Constructor Description
      CharClasses()
      Constructs a new CharClasses object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void check()
      Check consistency of the stored classes [debug].
      void dump()
      Dumps charclasses to the dump output stream.
      int getClassCode​(int codePoint)
      Returns the code of the character class the specified character belongs to.
      int[] getClassCodes​(java.util.List<Interval> intervalList)
      Returns an array that contains the character class codes of all characters in the specified set of input characters.
      private int[] getClassCodes​(IntCharSet set, boolean negate)
      Returns an array that contains the character class codes of all characters in the specified set of input characters.
      CharClassInterval[] getIntervals()
      Returns an array of all CharClassIntervals in this char class collection.
      int getMaxCharCode()
      Returns the greatest Unicode value of the current input character set.
      int[] getNotClassCodes​(java.util.List<Interval> intervalList)
      Returns an array that contains the character class codes of all characters that are not in the specified set of input characters.
      int getNumClasses()
      Returns the current number of character classes.
      void init​(int maxCharCode, LexScan scanner)
      Provides space for classes of characters from 0 to maxCharCode.
      void makeClass​(int singleChar, boolean caseless)
      Creates a new character class for the single character singleChar.
      void makeClass​(java.lang.String str, boolean caseless)
      Creates a new character class for each character of the specified String.
      void makeClass​(java.util.List<Interval> l, boolean caseless)
      Updates the current partition, so that the specified set of characters gets a new character class.
      void makeClass​(IntCharSet set, boolean caseless)
      Updates the current partition, so that the specified set of characters gets a new character class.
      void makeClassNot​(java.util.List<Interval> l, boolean caseless)
      Updates the current partition, so that the set of all characters not contained in the specified set of characters gets a new character class.
      void setMaxCharCode​(int maxCharCode)
      Sets the largest Unicode value of the current input character set.
      java.lang.String toString()
      Returns a string representation of the char classes stored in this class.
      java.lang.String toString​(int theClass)
      Returns a string representation of one char class
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • DEBUG

        private static final boolean DEBUG
        debug flag (for char classes only)
        See Also:
        Constant Field Values
      • maxChar

        public static final int maxChar
        the largest character that can be used in char classes
        See Also:
        Constant Field Values
      • classes

        private java.util.List<IntCharSet> classes
        the char classes
      • maxCharUsed

        private int maxCharUsed
        the largest character actually used in a specification
    • Constructor Detail

      • CharClasses

        public CharClasses()
        Constructs a new CharClasses object.

        CharClasses.init() is delayed until UnicodeProperties.init() has been called, since the max char code won't be known until then.

    • Method Detail

      • init

        public void init​(int maxCharCode,
                         LexScan scanner)
        Provides space for classes of characters from 0 to maxCharCode.

        Initially all characters are in class 0.

        Parameters:
        maxCharCode - the last character code to be considered. (127 for 7bit Lexers, 255 for 8bit Lexers and UnicodeProperties.getMaximumCodePoint() for Unicode Lexers).
        scanner - the scanner containing the UnicodeProperties instance from which caseless partitions are obtained.
      • getMaxCharCode

        public int getMaxCharCode()
        Returns the greatest Unicode value of the current input character set.
        Returns:
        unicode value.
      • setMaxCharCode

        public void setMaxCharCode​(int maxCharCode)
        Sets the largest Unicode value of the current input character set.
        Parameters:
        maxCharCode - the largest character code, used for the scanner (i.e. %7bit, %8bit, %16bit etc.)
      • getNumClasses

        public int getNumClasses()
        Returns the current number of character classes.
        Returns:
        number of character classes.
      • makeClass

        public void makeClass​(IntCharSet set,
                              boolean caseless)
        Updates the current partition, so that the specified set of characters gets a new character class.

        Characters that are elements of set are not in the same equivalence class with characters that are not elements of set.

        Parameters:
        set - the set of characters to distinguish from the rest
        caseless - if true upper/lower/title case are considered equivalent
      • getClassCode

        public int getClassCode​(int codePoint)
        Returns the code of the character class the specified character belongs to.
        Parameters:
        codePoint - code point.
        Returns:
        code of the character class.
      • dump

        public void dump()
        Dumps charclasses to the dump output stream.
      • toString

        public java.lang.String toString​(int theClass)
        Returns a string representation of one char class
        Parameters:
        theClass - the index of the class to
        Returns:
        a String object.
      • toString

        public java.lang.String toString()
        Returns a string representation of the char classes stored in this class.

        Enumerates the classes by index.

        Overrides:
        toString in class java.lang.Object
        Returns:
        representation of this char class.
      • makeClass

        public void makeClass​(int singleChar,
                              boolean caseless)
        Creates a new character class for the single character singleChar.
        Parameters:
        caseless - if true upper/lower/title case are considered equivalent
        singleChar - character.
      • makeClass

        public void makeClass​(java.lang.String str,
                              boolean caseless)
        Creates a new character class for each character of the specified String.
        Parameters:
        caseless - if true upper/lower/title case are considered equivalent
        str - set of characters.
      • makeClass

        public void makeClass​(java.util.List<Interval> l,
                              boolean caseless)
        Updates the current partition, so that the specified set of characters gets a new character class.

        Characters that are elements of the set l are not in the same equivalence class with characters that are not elements of the set l.

        Parameters:
        l - a List of Interval objects. This List represents a set of characters. The set of characters is the union of all intervals in the List.
        caseless - if true upper/lower/title case are considered equivalent
      • makeClassNot

        public void makeClassNot​(java.util.List<Interval> l,
                                 boolean caseless)
        Updates the current partition, so that the set of all characters not contained in the specified set of characters gets a new character class.

        Characters that are elements of the set v are not in the same equivalence class with characters that are not elements of the set v.

        This method is equivalent to makeClass(v)

        Parameters:
        l - a List of Interval objects. This List represents a set of characters. The set of characters is the union of all intervals in the List.
        caseless - if true upper/lower/title case are considered equivalent
      • getClassCodes

        private int[] getClassCodes​(IntCharSet set,
                                    boolean negate)
        Returns an array that contains the character class codes of all characters in the specified set of input characters.
      • getClassCodes

        public int[] getClassCodes​(java.util.List<Interval> intervalList)
        Returns an array that contains the character class codes of all characters in the specified set of input characters.
        Parameters:
        intervalList - a List of Intervals, the set of characters to get the class codes for
        Returns:
        an array with the class codes for intervalList
      • getNotClassCodes

        public int[] getNotClassCodes​(java.util.List<Interval> intervalList)
        Returns an array that contains the character class codes of all characters that are not in the specified set of input characters.
        Parameters:
        intervalList - a List of Intervals, the complement of the set of characters to get the class codes for
        Returns:
        an array with the class codes for the complement of intervalList
      • check

        public void check()
        Check consistency of the stored classes [debug].

        all classes must be disjoint, checks if all characters have a class assigned.

      • getIntervals

        public CharClassInterval[] getIntervals()
        Returns an array of all CharClassIntervals in this char class collection.

        The array is ordered by char code, i.e. result[i+1].start = result[i].end+1 Each CharClassInterval contains the number of the char class it belongs to.

        Returns:
        an array of all CharClassInterval in this char class collection.