Skip to content

Commit

Permalink
Merge pull request usnistgov#52 from andrey-vorobiev/check-bounds
Browse files Browse the repository at this point in the history
Do not use exceptions for control flow in StringTokenizer.lookAhead
  • Loading branch information
vladimirralev authored Jan 1, 2020
2 parents 31d96d6 + b20d7db commit b1a5142
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/gov/nist/core/StringTokenizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,8 @@ public char lookAhead() throws ParseException {

public char lookAhead(int k) throws ParseException {
// Debug.out.println("ptr = " + ptr);
try {
return buffer[ptr + k];
}
catch (IndexOutOfBoundsException e) {
return '\0';
}
int index = ptr + k;
return index < buffer.length ? buffer[index] : '\0';
}

public char getNextChar() throws ParseException {
Expand Down

0 comments on commit b1a5142

Please sign in to comment.