1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | package Torello.CSS; import Torello.Java.Additional.ByRef; import java.util.Vector; import java.util.function.Consumer; @Torello.JavaDoc.JDHeaderBackgroundImg(EmbedTagFileID="CSS_TOK") public class Dimension extends Num implements CharSequence, java.io.Serializable, Comparable<CharSequence> { /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */ protected static final long serialVersionUID = 1; // ******************************************************************************************** // ******************************************************************************************** // Public & Final Fields // ******************************************************************************************** // ******************************************************************************************** /** * The text / {@code String} that was appended to the end of the number that begin this * {@code Dimension}-Token */ public final String dimension; // ******************************************************************************************** // ******************************************************************************************** // Private Constructor, API "is" and "if" Methods // ******************************************************************************************** // ******************************************************************************************** Dimension( final int[] css, final int sPos, final int ePos, final Num n, final String dimension ) { super(css, sPos, ePos, n); this.dimension = dimension; } @Override public final boolean isDimension() { return true; } @Override public final Dimension ifDimension() { return this; } // ******************************************************************************************** // ******************************************************************************************** // User's Constructor: a static "build" method // ******************************************************************************************** // ******************************************************************************************** /** * <EMBED CLASS=defs DATA-TOK=Dimension DATA-P=dimensionStr> * <EMBED CLASS='external-html' DATA-FILE-ID=BUILD_DESC> * @param dimensionStr <EMBED CLASS='external-html' DATA-FILE-ID=BUILD_PARAM> * @return <EMBED CLASS='external-html' DATA-FILE-ID=BUILD_RET> * @throws TokenizeException <EMBED CLASS='external-html' DATA-FILE-ID=BUILD_TOK_EX> */ public static Dimension build(final String dimensionStr) { CSSToken ret = CSSToken.build(dimensionStr, INPUT_CHECKER, Num::consume); if (ret instanceof Dimension) return (Dimension) ret; throw new TokenizeException( "Your String could not be converted to a Dimension-Instance. The Number Parser " + "has returned an instance of class '" + ret.getClass().getSimpleName() + "' instead." ); } private static final CSSToken.InputChecker INPUT_CHECKER = (int[] css) -> { if (css.length < 2) throw new TokenizeException(Dimension.class); if (! Num.is(css, 0)) throw new TokenizeException ("String-text beginning does not constitute a valid CSS Number-Token"); }; // ******************************************************************************************** // ******************************************************************************************** // CONSUME // ******************************************************************************************** // ******************************************************************************************** /** * This is a tokenizer method which <B>"consumes"</B> the next Dimension-Token from the * input Code-Point Array. * * <EMBED CLASS=defs DATA-TOK=Dimension DATA-URL=dimension-token-diagram DATA-OP=Consume> * <EMBED CLASS=external-html DATA-FILE-ID=COPIED_CSS_WG_RR> * <EMBED CLASS=external-html DATA-FILE-ID=COMMENT_SVG> */ protected static void consume( final int[] css, final ByRef<Integer> POS, final Consumer<CSSToken> returnParsedToken, final int identifierStartPos, final Num num ) { /* Please, be merciful, this isn't as fun and as exciting as it looks on first-glance. These System.out's are for debugging, and to make this parser more clear when running test code. My Test-Code Directory is very, very big and has tests for a lot of things in Java-HTML. It helps TO NO END when debugging code. These PrintF's were all written while debugging the Torello.CSS Package All of the "Edge Cases" are difficult to find until you run tests on all of your Edge-Cases System.out.println( "Dimension.consume:\n" + "\tPOS.f: " + POS.f + '\n' + "\tcss[POS.f]: " + '\'' + ((char) css[POS.f]) + "'\n" + "\tidentifierStartPos: " + identifierStartPos + '\n' + "\tcss[identifierStartPos]: " + '\'' + ((char) css[identifierStartPos]) + "'\n" + "\tnum.integerOrNumber: " + num.integerOrNumber + "\n" + "\tnum.signChar: " + '\'' + num.signChar + "'\n" + "\tnum.toString(): " + '"' + num.toString() + "\"\n" + "\tnum.number.toString(): " + '"' + num.number.toString() + "\"\n" + "\tnum.number.intValue(): " + num.number.intValue() + "\n" + "\tnum.number.floatValue(): " + num.number.floatValue() ); */ // Create a <dimension-token> with the same value, type flag, and sign character as // number, and a unit set initially to the empty string. // // Consume an ident sequence. final ByRef<String> identifier = new ByRef<>(); // Consume an Identifier final int identifierEndPos = Identifier.consumeIdentSequence(css, identifierStartPos, identifier); /* System.out.println( "\tidentifier.f: " + identifier.f + '\n' + "\tidentifierEndPos: " + identifierEndPos + '\n' + "\tcss[identifierEndPos]: " + ((identifierEndPos < css.length) ? ((char) css[identifierEndPos]) : ((char) 0)) ); */ // Set the <dimension-token>’s unit to the returned ident-sequence value // Return the <dimension-token>. returnParsedToken.accept(new Dimension(css, POS.f, identifierEndPos, num, identifier.f)); POS.f = identifierEndPos; } } |