validator/parse-css.js
/**
 * Parses a CSS function token named 'url', including the string and closing
 * paren. Typically takes the form "url('http://foo')".
 * Returns the token_idx past the closing paren, or -1 if parsing fails.
 * Preconditions: tokens[token_idx] is a URL token
 *                and tokens[token_idx]->StringValue() == "url"
 * @param {!Array<!parse_css.Token>} tokens
 * @param {number} tokenIdx
 * @param {!parse_css.ParsedCssUrl} parsed
 * @return {number}
 */
Parses a CSS function token named 'url', including the string and closing
paren.
Parses a CSS function token named ' url ' including the string and closing paren .
function parseUrlFunction(tokens, tokenIdx, parsed) {
  const token = tokens[tokenIdx];
  goog.asserts.assert(token.tokenType == parse_css.TokenType.FUNCTION_TOKEN);
  goog.asserts.assert(
       (token).value === 'url');
  goog.asserts.assert(
      tokens[tokens.length - 1].tokenType === parse_css.TokenType.EOF_TOKEN);
  token.copyPosTo(parsed);
  ++tokenIdx;  
  goog.asserts.assert(tokenIdx < tokens.length);
  while (tokens[tokenIdx].tokenType === parse_css.TokenType.WHITESPACE) {
    ++tokenIdx;
    goog.asserts.assert(tokenIdx < tokens.length);
  }
  if (tokens[tokenIdx].tokenType !== parse_css.TokenType.STRING) {
    return -1;
  }
  parsed.utf8Url =
       (tokens[tokenIdx]).value;
  ++tokenIdx;
  goog.asserts.assert(tokenIdx < tokens.length);
  while (tokens[tokenIdx].tokenType === parse_css.TokenType.WHITESPACE) {
    ++tokenIdx;
    goog.asserts.assert(tokenIdx < tokens.length);
  }
  if (tokens[tokenIdx].tokenType !== parse_css.TokenType.CLOSE_PAREN) {
    return -1;
  }
  return tokenIdx + 1;
}
function parseUrlFunction ( tokens , tokenIdx , parsed ) { const token = tokens [ tokenIdx ] ; goog . asserts . assert ( token . tokenType == parse_css . TokenType . FUNCTION_TOKEN ) ; goog . asserts . assert ( ( token ) . value === 'url' ) ; goog . asserts . assert ( tokens [ tokens . length - 1 ] . tokenType === parse_css . TokenType . EOF_TOKEN ) ; token . copyPosTo ( parsed ) ; ++ tokenIdx ; goog . asserts . assert ( tokenIdx < tokens . length ) ; while ( tokens [ tokenIdx ] . tokenType === parse_css . TokenType . WHITESPACE ) { ++ tokenIdx ; goog . asserts . assert ( tokenIdx < tokens . length ) ; } if ( tokens [ tokenIdx ] . tokenType !== parse_css . TokenType . STRING ) { return - 1 ; } parsed . utf8Url = ( tokens [ tokenIdx ] ) . value ; ++ tokenIdx ; goog . asserts . assert ( tokenIdx < tokens . length ) ; while ( tokens [ tokenIdx ] . tokenType === parse_css . TokenType . WHITESPACE ) { ++ tokenIdx ; goog . asserts . assert ( tokenIdx < tokens . length ) ; } if ( tokens [ tokenIdx ] . tokenType !== parse_css . TokenType . CLOSE_PAREN ) { return - 1 ; } return tokenIdx + 1 ; }
Parses a CSS function token named 'url', including the string and closing
 paren.
Parses a CSS function token named ' url ' including the string and closing paren .
/** @type {parse_css.FunctionToken} */ // We've digested the function token above. // Safe: tokens ends w/ EOF_TOKEN. // Consume optional whitespace. // Safe: tokens ends w/ EOF_TOKEN. // Consume URL. /** @type {parse_css.StringToken} */ // Safe: tokens ends w/ EOF_TOKEN. // Consume optional whitespace. // Safe: tokens ends w/ EOF_TOKEN. // Consume ')'