Non-whitespace characters are defined as in the
* Character.isWhitespace method (that method is used).
*
* @param str The string to parse
*
* @param from The index of the first position to search from
*
* @return The index of the last character in the next word, plus 1,
* IS_NEWLINE, or IS_EOS if there are no more words.
*
*
* */
private int nextLineEnd(String str, int from) {
final int len = str.length();
char c = '\0';
// First skip all whitespace, except new line
while (from < len && (c = str.charAt(from)) != '\n' &&
Character.isWhitespace(c)) {
from++;
}
if (c == '\n') {
return IS_NEWLINE;
}
if (from >= len) {
return IS_EOS;
}
// Now skip word characters
while (from < len && !Character.isWhitespace(str.charAt(from))) {
from++;
}
return from;
}
/**
* Returns the position of the first character in the next word, starting
* from 'from', if a newline is encountered first then the index of the
* newline character plus 1 is returned. If the end of the string is
* encountered then IS_EOS is returned. Words are defined as any
* concatenation of 1 or more characters which are not
* whitespace. Whitespace characters are those for which
* Character.isWhitespace() returns true (that method is used).
*
* Non-whitespace characters are defined as in the
* Character.isWhitespace method (that method is used).
*
* @param str The string to parse
*
* @param from The index where to start parsing
*
* @return The index of the first character of the next word, or the index
* of the newline plus 1, or IS_EOS.
*
*
* */
private int nextWord(String str, int from) {
final int len = str.length();
char c = '\0';
// First skip all whitespace, but new lines
while (from < len && (c = str.charAt(from)) != '\n' &&
Character.isWhitespace(c)) {
from++;
}
if (from >= len) {
return IS_EOS;
}
else if (c == '\n') {
return from+1;
}
else {
return from;
}
}
}