You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2020/12/05 17:16:44 UTC
[commons-lang] branch master updated: LANG-1620 - refine
StringUtils.lastIndexOfIgnoreCase (#664)
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git
The following commit(s) were added to refs/heads/master by this push:
new 76443d7 LANG-1620 - refine StringUtils.lastIndexOfIgnoreCase (#664)
76443d7 is described below
commit 76443d7f1d430f3708f5be7f3aa3cd6565dba433
Author: Arturo Bernal <ar...@gmail.com>
AuthorDate: Sat Dec 5 18:16:31 2020 +0100
LANG-1620 - refine StringUtils.lastIndexOfIgnoreCase (#664)
---
src/main/java/org/apache/commons/lang3/StringUtils.java | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java b/src/main/java/org/apache/commons/lang3/StringUtils.java
index 75c414c..93e8407 100644
--- a/src/main/java/org/apache/commons/lang3/StringUtils.java
+++ b/src/main/java/org/apache/commons/lang3/StringUtils.java
@@ -5135,18 +5135,20 @@ public class StringUtils {
if (str == null || searchStr == null) {
return INDEX_NOT_FOUND;
}
- if (startPos > str.length() - searchStr.length()) {
- startPos = str.length() - searchStr.length();
+ final int searchStrLength = searchStr.length();
+ final int strLength = str.length();
+ if (startPos > strLength - searchStrLength) {
+ startPos = strLength - searchStrLength;
}
if (startPos < 0) {
return INDEX_NOT_FOUND;
}
- if (searchStr.length() == 0) {
+ if (searchStrLength == 0) {
return startPos;
}
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;
}
}