Class Str
- java.lang.Object
-
- Torello.CSS.CSSToken
-
- Torello.CSS.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 theCSSTokenizer
class. Many (but not all) of these subclasses maintain astatic
-method for building instances of this class named'build'
. AnyCSSToken
-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.
AllCSSToken
subclasses have aCSSToken.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 atdrafts.csswg.org
CSS-Tokenizer Class forString
-Literals.- See Also:
- Serialized Form
Hi-Lited Source-Code:- View Here: Torello/CSS/Str.java
- Open New Browser-Tab: Torello/CSS/Str.java
File Size: 16,809 Bytes Line Count: 368 '\n' Characters Found
-
-
Field Summary
Serializable ID Modifier and Type Field protected static long
serialVersionUID
This Data-Class' Instance-Fields Modifier and Type Field char
quote
String
unescaped
-
Method Summary
Static Builders: Build an Instance of this class Modifier and Type Method static Str
build(String stringLiteral)
Tokenize CSS: CSS Working-Group Implementation Modifier and Type Method static void
consume(int[] css, ByRef<Integer> POS, Consumer<CSSToken> returnParsedToken, Consumer<TokenizeError> errorEncountered)
Loop-Optimization Methods: 'is' & 'if' Modifier and Type Method Str
ifStr()
boolean
isStr()
-
Methods inherited from class Torello.CSS.CSSToken
asAtKeyword, asBadStr, asBadURL, asCDC, asCDO, asComment, asDelimiter, asDimension, asFunc, asHash, asIdentifier, asNum, asPercentage, asPunct, asStr, asUnicodeRange, asURL, asWhitespace, charAt, compareTo, equals, ifAtKeyword, ifBadStr, ifBadURL, ifCDC, ifCDO, ifComment, ifDelimiter, ifDelimiter, ifDimension, ifFunc, ifHash, ifIdentifier, ifNum, ifPercentage, ifPunct, ifPunct, ifUnicodeRange, ifURL, ifWhitespace, isAtKeyword, isBadStr, isBadURL, isCDC, isCDO, isComment, isDelimiter, isDelimiter, isDimension, isFunc, isHash, isIdentifier, isNum, isPercentage, isPunct, isPunct, isUnicodeRange, isURL, isWhitespace, length, subSequence, toString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
-
-
-
Field Detail
-
serialVersionUID
protected static final long serialVersionUID
This fulfils the SerialVersion UID requirement for all classes that implement Java'sinterface java.io.Serializable
. Using theSerializable
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 thisString
-Literal. The value placed in this Javachar
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 actualString
-Literal that thisCSSToken
represents. This JavaString
will never actually contain the opening and closing quotation marks that were used to create thisString
.
Unescaped String:
if thisString
utilized any Escape-Sequences representing Unicode Characters, the Unescaped-Characters are used within thisString
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
-
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 forTorello.CSS
actually generate / spit-out more thanCSSToken
instance, writing publicly available constructors is largely impossible.
The upside to this approach is that thebuild
methods and theconsume
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 ofStr
- 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'
.
-
consume
public static void consume (int[] css, ByRef<java.lang.Integer> POS, java.util.function.Consumer<CSSToken> returnParsedToken, java.util.function.Consumer<TokenizeError> errorEncountered)
This is a tokenizer method which "consumes" the nextString
-Literal from the input Code-Point Array.Tokenizer: String-Literal Consume Method, Pseudo-Code
Making use of the CSS Parser DOES NOT require any knowledge of how the underlying Pass 1 Tokenizer actually works. Browser-War people are usually pretty convincing that parsing CSS is a "Moving Target" type of operation, not to be engaged by mere mortals.
Below is the CSS Working Group's String-Literal Pseudo-Code. You may review it if you are at wit's end, and have nothing better to do. There is no need to actually invoke this method, it is here solely for informational purposes.
These Parsing Pseudo-Code Instructions and Rail-Road Diagrams have been copied from the CSS-Working-Group Web-Site:
https://drafts.csswg.org/css-syntax/#consume-string-token
Consume a string token
This section describes how to consume a string token from a stream of code points. It returns either a <string-token> or <bad-string-token>.
This algorithm may be called with an ending code point, which denotes the code point that ends the string. If an ending code point is not specified, the current input code point is used.
Initially create a <string-token> with its value set to the empty string.
Repeatedly consume the next input code point from the stream:
- ending code point
- Return the <string-token>.
- EOF
- This is a parse error. Return the <string-token>.
- newline
- This is a parse error. Reconsume the current input code point, create a <bad-string-token>, and return it.
- U+005C REVERSE SOLIDUS (\)
-
If the next input code point is EOF,
do nothing.
Otherwise, if the next input code point is a newline, consume it.
Otherwise, (the stream starts with a valid escape) consume an escaped code point and append the returned code point to the <string-token>’s value.
- anything else
- Append the current input code point to the <string-token>’s value.
-
-