char[] chars = s.toCharArray();
int tokenPos = 0;
boolean lastLetter = false;
for (int i = 0; i < chars.length; i++) {
if (tokenPos >= TOKEN_SEQUENCE.length()) {
throw new CalendricalParseException("Period could not be parsed, characters after last 'S': " + text, text, i);
}
char c = chars[i];
if ((c < '0' || c > '9') && c != '-' && c != '.') {
tokenPos = TOKEN_SEQUENCE.indexOf(c, tokenPos);
if (tokenPos < 0) {
throw new CalendricalParseException("Period could not be parsed, invalid character '" + c + "': " + text, text, i);
}
tokenPos++;
lastLetter = true;
} else {
lastLetter = false;
}
}
if (lastLetter == false) {
throw new CalendricalParseException("Period could not be parsed, invalid last character: " + text, text, s.length() - 1);
}
}