getWord method

String getWord()

Consume and return the next word in buffer, disregarding quotes.

Developers should use getQuotedWord instead unless they specifically want the behavior described below, as getWord can leave remaining with unbalanced quotes.

A word is a sequence of non-whitespace characters, themselves surrounded by whitespace. The whitespace preceding the word is consumed but not returned, and the whitespace after the word is left untouched.

The word 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 getWord() {
  skipWhitespace();

  int start = index;

  while (!eof && !isWhitespace) {
    index++;
  }

  return escape(start, index);
}