Package Torello.CSS

Class Str

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.CharSequence, java.lang.Comparable<java.lang.CharSequence>

    public class Str
    extends CSSToken
    implements java.lang.CharSequence, java.io.Serializable, java.lang.Comparable<java.lang.CharSequence>
    This is a Token Data-Class. It is a descendant of the root CSSToken-Class: CSSToken. Instances of the class are usually are produced by the CSSTokenizer class. Many (but not all) of these subclasses maintain a static-method for building instances of this class named 'build'. Any CSSToken-subclass that is neither a singleton-instance, nor an "Error-Subtype" should have such a builder. Singeton instances do not need builders, and the two Error-Subtype Classes can only be generated by the tokenizer.

    All CSSToken subclasses have a CSSToken.str field which contains the exact character data that was extracted and used to construct instances of this class. All sub-casses also have several "Loop Optimization" methods. These are methods that may or may not be useful in light of some of the newer additions to JDK 17 & 21 including the 'instanceof varName' conditional-expression variable-naming features.

    The algorithms used to write this tokenizer were generated based solely on the CSS Working-Group's Syntax-Documentation. This document may be viewed here: CSS Working-Group CSS-Syntax. There is an external site that maintain all thing CSS located at drafts.csswg.org
    CSS-Tokenizer Class for String-Literals.
    See Also:
    Serialized Form


    • Field Detail

      • serialVersionUID

        🡇     🗕  🗗  🗖
        protected static final long serialVersionUID
        This fulfils the SerialVersion UID requirement for all classes that implement Java's interface java.io.Serializable. Using the Serializable Implementation offered by java is very easy, and can make saving program state when debugging a lot easier. It can also be used in place of more complicated systems like "hibernate" to store data as well.
        See Also:
        Constant Field Values
        Code:
        Exact Field Declaration Expression:
         protected static final long serialVersionUID = 1;
        
      • quote

        🡅  🡇     🗕  🗗  🗖
        public final char quote
        The quotation mark type used to quote this String-Literal. The value placed in this Java char primitive may only be a Single-Quotation Mark, or a Double-Quotation. No other types of quotations are included in this class parser.
      • unescaped

        🡅  🡇     🗕  🗗  🗖
        public final java.lang.String unescaped
        This is the actual String-Literal that this CSSToken represents. This Java String will never actually contain the opening and closing quotation marks that were used to create this String.

        Unescaped String:
        if this String utilized any Escape-Sequences representing Unicode Characters, the Unescaped-Characters are used within this String to replace the original, escaped, sequences.

        ChatGPT Provided Exmaple:
        There is a quoted, String below, provided by AI. Note that ChatGPT initially gave me a slightly different answer written as "✓ Checkmark" (which you may or may not notice has a 'u' character between the Reverse-Solidus Backslash character and the Hexadecimal Characters '2713').

        After further research, ChatGPT apologized for it's mistake saying:

        "You're correct, and I apologize for the oversight. In CSS, Unicode escape sequences within string literals do not start with the u character. Instead, they consist of a backslash followed by up to six hexadecimal digits, representing the Unicode code point."

        This crap sort of amazes me. I really can't believe it. Anything that Stack Overflow is busy condemning, with a very high likelihood is bound to be pretty good.

        Cascading Style Sheet (CSS):
         .selector::before
         {
             content: "\2713 Checkmark";
             font-family: Arial, sans-serif;
         }
        

        The above CSS-String (which is inside the 'content' Property-Value) would be stored in the field 'unescaped' as: ✓ Checkmark.
    • Method Detail

      • isStr

        🡅  🡇     🗕  🗗  🗖
        public final boolean isStr()
        Description copied from class: CSSToken
        Loop Optimization: This method only returns TRUE if this is an actual instance of Str.
        Overrides:
        isStr in class CSSToken
        Returns:
        This method returns FALSE for all instances of CSSToken, except when 'this' instance is actually the Str Subclass.

        That class has overridden this method, and returns TRUE.
        See Also:
        isStr()
      • ifStr

        🡅  🡇     🗕  🗗  🗖
        public final Str ifStr()
        Description copied from class: CSSToken
        Loop Optimization: When this method is invoked on an instance of sub-class Str this method produces 'this' instance.
        Overrides:
        ifStr in class CSSToken
        Returns:
        This method shall return null, always, except when 'this' is an actual instance of Str. When so, this method simply returns 'this'. All other sub-classes of (abstract) class CSSToken inherit this method, and therefore return null.
        See Also:
        ifStr()
      • build

        🡅  🡇     🗕  🗗  🗖
        public static Str build​(java.lang.String stringLiteral)
        Static-Builder Method for creating an instance of this class. This Static-Method is a substitute for an actual Constructor. Because many of the 'consume(...)' methods in the Token Classe for Torello.CSS actually generate / spit-out more than CSSToken instance, writing publicly available constructors is largely impossible.

        The upside to this approach is that the build methods and the consume methods share identical code. Furthermore this code is (nearly) perfectly based on the Pseudo-Code on the CSS Working-Group Website.
        Parameters:
        stringLiteral - Any Java-String that can be parsed into an instance of Str
        Returns:
        An instance of Str.

        If the contents of the Input-String parameter 'stringLiteral' cannot be consumed, exactly, by this class' 'consume' method, then an exception shall throw.
        Throws:
        TokenizeException - This exception may be thrown for any number of reasons involving the inability to parse input parameter 'stringLiteral'.