Adjust fromIndex in String#lastIndexOf if necessary

If fromIndex 'is greater than or equal to the length of this string,
it has the same effect as if it were equal to one less than the length
of the string':

http://docs.oracle.com/javase/6/docs/api/java/lang/String.html#lastIndexOf%28int,%20int%29

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This commit is contained in:
Johannes Schindelin 2013-10-25 10:51:14 -05:00
parent 6f64e3aaab
commit 2ff0178da4

View File

@ -602,6 +602,9 @@ public final class String
}
public int lastIndexOf(int ch, int lastIndex) {
if (lastIndex >= length) {
lastIndex = length - 1;
}
for (int i = lastIndex ; i >= 0; --i) {
if (charAt(i) == ch) {
return i;