processQuotedString method

String processQuotedString([
  1. bool urlString = false
])

Implementation

String processQuotedString([bool urlString = false]) {
  var start = _peekToken.span;

  // URI term sucks up everything inside of quotes(' or ") or between parens
  var stopToken = urlString ? TokenKind.RPAREN : -1;

  // Note: disable skipping whitespace tokens inside a string.
  // TODO(jmesserly): the layering here feels wrong.
  var inString = tokenizer._inString;
  tokenizer._inString = false;

  switch (_peek()) {
    case TokenKind.SINGLE_QUOTE:
      stopToken = TokenKind.SINGLE_QUOTE;
      _next(); // Skip the SINGLE_QUOTE.
      start = _peekToken.span;
      break;
    case TokenKind.DOUBLE_QUOTE:
      stopToken = TokenKind.DOUBLE_QUOTE;
      _next(); // Skip the DOUBLE_QUOTE.
      start = _peekToken.span;
      break;
    default:
      if (urlString) {
        if (_peek() == TokenKind.LPAREN) {
          _next(); // Skip the LPAREN.
          start = _peekToken.span;
        }
        stopToken = TokenKind.RPAREN;
      } else {
        _error('unexpected string', location: _makeSpan(start));
      }
      break;
  }

  // Gobble up everything until we hit our stop token.
  var stringValue = StringBuffer();
  while (_peek() != stopToken && _peek() != TokenKind.END_OF_FILE) {
    stringValue.write(_next().text);
  }

  tokenizer._inString = inString;

  // All characters between quotes is the string.
  if (stopToken != TokenKind.RPAREN) {
    _next(); // Skip the SINGLE_QUOTE or DOUBLE_QUOTE;
  }

  return stringValue.toString();
}