LANG-1620 - refine StringUtils.lastIndexOfIgnoreCase (#664)

This commit is contained in:
Arturo Bernal 2020-12-05 18:16:31 +01:00 committed by GitHub
parent edcf9344e6
commit 76443d7f1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 4 deletions

View File

@ -5135,18 +5135,20 @@ public class StringUtils {
if (str == null || searchStr == null) { if (str == null || searchStr == null) {
return INDEX_NOT_FOUND; return INDEX_NOT_FOUND;
} }
if (startPos > str.length() - searchStr.length()) { final int searchStrLength = searchStr.length();
startPos = str.length() - searchStr.length(); final int strLength = str.length();
if (startPos > strLength - searchStrLength) {
startPos = strLength - searchStrLength;
} }
if (startPos < 0) { if (startPos < 0) {
return INDEX_NOT_FOUND; return INDEX_NOT_FOUND;
} }
if (searchStr.length() == 0) { if (searchStrLength == 0) {
return startPos; return startPos;
} }
for (int i = startPos; i >= 0; i--) { for (int i = startPos; i >= 0; i--) {
if (CharSequenceUtils.regionMatches(str, true, i, searchStr, 0, searchStr.length())) { if (CharSequenceUtils.regionMatches(str, true, i, searchStr, 0, searchStrLength)) {
return i; return i;
} }
} }