MCPcopy Index your code
hub / github.com/NativeScript/NativeScript / consumeAURLToken

Method consumeAURLToken

packages/core/css/CSS3Parser.ts:369–431  ·  view source on GitHub ↗

* 4.3.5. Consume a url token * https://www.w3.org/TR/css-syntax-3/#consume-a-url-token

()

Source from the content-addressed store, hash-verified

367 * https://www.w3.org/TR/css-syntax-3/#consume-a-url-token
368 */
369 private consumeAURLToken(): InputToken {
370 const start = this.nextInputCodePointIndex - 3 /* url */ - 1; /* ( */
371 const urlToken: InputToken = {
372 type: TokenObjectType.url,
373 text: undefined,
374 };
375 this.consumeAWhitespace();
376 if (this.nextInputCodePointIndex >= this.text.length) {
377 return urlToken;
378 }
379 const nextInputCodePoint = this.text[this.nextInputCodePointIndex];
380 if (nextInputCodePoint === '"' || nextInputCodePoint === "'") {
381 const stringToken = this.consumeAStringToken();
382 // TODO: Handle bad-string.
383 // TODO: Set value instead.
384 urlToken.text = stringToken.text;
385 this.consumeAWhitespace();
386 if (this.text[this.nextInputCodePointIndex] === ')' || this.nextInputCodePointIndex >= this.text.length) {
387 this.nextInputCodePointIndex++;
388 const end = this.nextInputCodePointIndex;
389 urlToken.text = this.text.substring(start, end);
390
391 return urlToken;
392 } else {
393 // TODO: Handle bad-url.
394 return null;
395 }
396 }
397
398 while (this.nextInputCodePointIndex < this.text.length) {
399 const char = this.text[this.nextInputCodePointIndex++];
400 switch (char) {
401 case ')':
402 return urlToken;
403 case ' ':
404 case '\t':
405 case '\n':
406 case '\r':
407 case '\f':
408 this.consumeAWhitespace();
409 if (this.text[this.nextInputCodePointIndex] === ')') {
410 this.nextInputCodePointIndex++;
411
412 return urlToken;
413 } else {
414 // TODO: Bar url! Consume remnants.
415 return null;
416 }
417 case '"':
418 case "'":
419 // TODO: Parse error! Bar url! Consume remnants.
420 return null;
421 case '\\':
422 // TODO: Escape!
423 throw new Error('Escaping not yet supported!');
424 default:
425 // TODO: Non-printable chars - error.
426 urlToken.text += char;

Callers 1

Calls 2

consumeAWhitespaceMethod · 0.95
consumeAStringTokenMethod · 0.95

Tested by

no test coverage detected