Package Torello.CSS
Class URLToken
- java.lang.Object
-
- Torello.CSS.CSSToken
-
- Torello.CSS.URLToken
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.CharSequence
,java.lang.Comparable<java.lang.CharSequence>
public class URLToken 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
AnyURL
- See Also:
- Serialized Form
Hi-Lited Source-Code:- View Here: Torello/CSS/URLToken.java
- Open New Browser-Tab: Torello/CSS/URLToken.java
File Size: 15,134 Bytes Line Count: 369 '\n' Characters Found
-
-
Field Summary
Serializable ID Modifier and Type Field protected static long
serialVersionUID
This Data-Class' Instance-Fields Modifier and Type Field String
unescapedURL
-
Method Summary
Static Builders: Build an Instance of this class Modifier and Type Method static URLToken
build(String urlStr)
Tokenize CSS: CSS Working-Group Implementation Modifier and Type Method protected static void
consume(int[] css, ByRef<Integer> POS, Consumer<CSSToken> returnParsedToken, Consumer<TokenizeError> errorEncountered, boolean fromBuildMethod)
Loop-Optimization Methods: 'is' & 'if' Modifier and Type Method URLToken
ifURL()
boolean
isURL()
-
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, ifStr, ifUnicodeRange, ifWhitespace, isAtKeyword, isBadStr, isBadURL, isCDC, isCDO, isComment, isDelimiter, isDelimiter, isDimension, isFunc, isHash, isIdentifier, isNum, isPercentage, isPunct, isPunct, isStr, isUnicodeRange, 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;
-
unescapedURL
public final java.lang.String unescapedURL
The unescaped text that constitutes thisURL
.
-
-
Method Detail
-
isURL
-
ifURL
-
build
public static URLToken build(java.lang.String urlStr)
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:
urlStr
- Any Java-String
that can be parsed into an instance ofStr
- Returns:
- An instance of
Str
.
If the contents of the Input-String
parameter'urlStr'
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'urlStr'
.
-
consume
protected static void consume (int[] css, ByRef<java.lang.Integer> POS, java.util.function.Consumer<CSSToken> returnParsedToken, java.util.function.Consumer<TokenizeError> errorEncountered, boolean fromBuildMethod)
This is a tokenizer method which "consumes" the nextURLToken
from the input Code-Point Array.Tokenizer: URLToken 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 URLToken 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-url-token
Consume a url token
This section describes how to consume a url token from a stream of code points. It returns either a <url-token> or a <bad-url-token>.
Note: This algorithm assumes that the initial "url(" has already been consumed. This algorithm also assumes that it’s being called to consume an "unquoted" value, like url(foo). A quoted value, like url("foo"), is parsed as a <function-token>. Consume an ident-like token automatically handles this distinction; this algorithm shouldn’t be called directly otherwise.
- Initially create a <url-token> with its value set to the empty string.
- Consume as much whitespace as possible.
- Repeatedly consume the next input code point from the
stream:
- U+0029 RIGHT PARENTHESIS ())
- Return the <url-token>.
- EOF
- This is a parse error. Return the <url-token>.
- whitespace
- Consume as much whitespace as possible. If the next input code point is U+0029 RIGHT PARENTHESIS ()) or EOF, consume it and return the <url-token> (if EOF was encountered, this is a parse error); otherwise, consume the remnants of a bad url, create a <bad-url-token>, and return it.
- U+0022 QUOTATION MARK (")
- U+0027 APOSTROPHE (')
- U+0028 LEFT PARENTHESIS (()
- non-printable code point
- This is a parse error. Consume the remnants of a bad url, create a <bad-url-token>, and return it.
- U+005C REVERSE SOLIDUS (\)
- If the stream starts with a
valid escape, consume an escaped code
point and append the returned
code point to the <url-token>’s
value.
Otherwise, this is a parse error. Consume the remnants of a bad url, create a <bad-url-token>, and return it.
- anything else
- Append the current input code point to the <url-token>’s value.
-
-