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 | package Torello.CSS; import java.util.Vector; import Torello.Java.Additional.ByRef; import java.util.stream.IntStream; import java.util.function.Consumer; /** * It has been patently decided that neither {@code 'BadStr'} nor {@code 'BadURL'} will have * constructors. */ @Torello.JavaDoc.JDHeaderBackgroundImg(EmbedTagFileID="CSS_TOK") public class BadURL extends CSSToken implements CharSequence, java.io.Serializable, Comparable<CharSequence> { /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */ protected static final long serialVersionUID = 1; // ******************************************************************************************** // ******************************************************************************************** // Private Constructor, API "is" and "if" Methods // ******************************************************************************************** // ******************************************************************************************** BadURL(final int[] css, final int sPos, final int ePos) { super(css, sPos, ePos); } @Override public final boolean isBadURL () { return true; } @Override public final BadURL ifBadURL () { return this; } // ******************************************************************************************** // ******************************************************************************************** // CONSUME // ******************************************************************************************** // ******************************************************************************************** // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** // Copied from: // https://drafts.csswg.org/css-syntax-3/#consume-the-remnants-of-a-bad-url // April 2024 // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** // // 4.3.15. Consume the remnants of a bad url // // This section describes how to consume the remnants of a bad url from a stream of code // points, "cleaning up" after the tokenizer realizes that it’s in the middle of a // <bad-url-token> rather than a <url-token>. It returns nothing; its sole use is to consume // enough of the input stream to reach a recovery point where normal tokenizing can resume. // // Repeatedly consume the next input code point from the stream: // // ** U+0029 RIGHT PARENTHESIS ()) // EOF // ==> Return. // // ** the input stream starts with a valid escape // ==> Consume an escaped code point. This allows an escaped right parenthesis ("\)") to // be encountered without ending the <bad-url-token>. This is otherwise identical to // the "anything else" clause. // // ** anything else // Do nothing. /** * This is a tokenizer method which <B>"consumes"</B> the next {@code BadURL}-Token from the * input Code-Point Array. * * <EMBED CLASS=defs DATA-TOK=BadURL-Token DATA-URL=consume-the-remnants-of-a-bad-url * DATA-OP=Consume> * <EMBED CLASS=external-html DATA-FILE-ID=COPIED_CSS_WG> * <EMBED CLASS=external-html DATA-FILE-ID=BAD_URL_TOKEN> */ protected static void consume( // When invoked from 'CSSTokenizer' final int[] css, // C, int[] css final ByRef<Integer> POS, // P, array-pos loop-variable final Consumer<CSSToken> returnParsedToken, // T, Vector<CSSToken>.add final int sPos ) { int pos; for (pos=sPos; pos < css.length; pos++) if (css[pos] == ')') { pos++; break; } else if ((css[pos] == '\\') && ((pos+1) < css.length) && (css[pos+1] == ')')) pos++; returnParsedToken.accept(new BadURL(css, sPos, pos)); POS.f = pos; } } |