getQuotedWord method

String getQuotedWord()

Consume and return the next word or quoted portion in buffer.

See getWord for a description of what is considered a word.

In addition to the behavior of getWord, getQuotedWord will return the portion of buffer between an opening quote and a corresponding, non-escaped closing quote if the next word begins with a quote. The quotes are consumed but not returned.

If isRestBlock is true, remaining is returned.

The word or quoted sequence is escaped before it is returned.

You might also be interested in:

  • escape, for escaping arbitrary portions of buffer;
  • isWhitespace, for checking if the current character is considered whitespace.

Implementation

String getQuotedWord() {
  skipWhitespace();

  if (isRestBlock) {
    String content = remaining;

    index = end;

    return content;
  } else if (_quotes.containsKey(current)) {
    String closingQuote = _quotes[current]!;

    index++;
    int start = index;

    while (!eof && (current != closingQuote || isEscaped(index))) {
      index++;
    }

    if (eof) {
      throw ParsingException('Unclosed quote at position $start');
    }

    String escaped = escape(start, index);

    index++; // Skip closing quote

    return escaped;
  } else {
    return getWord();
  }
}