Handle JDK1.2/JDK1.3 bug in String.indexOf

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@137512 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Stephen Colebourne 2003-07-26 14:34:49 +00:00
parent 9345b31d15
commit 89e735ed4e

View File

@ -146,7 +146,7 @@
* @author <a href="mailto:ggregory@seagullsw.com">Gary Gregory</a>
* @author Phil Steitz
* @since 1.0
* @version $Id: StringUtils.java,v 1.79 2003/07/25 22:22:30 scolebourne Exp $
* @version $Id: StringUtils.java,v 1.80 2003/07/26 14:34:49 scolebourne Exp $
*/
public class StringUtils {
// Performance testing notes (JDK 1.4, Jul03, scolebourne)
@ -822,6 +822,7 @@ public static int indexOf(String str, String searchStr) {
* StringUtils.indexOf("aabaabaa", "b", 9) = -1
* StringUtils.indexOf("aabaabaa", "b", -1) = 2
* StringUtils.indexOf("aabaabaa", "", 2) = 2
* StringUtils.indexOf("abc", "", 9) = 3
* </pre>
*
* @param str the String to check, may be null
@ -834,6 +835,10 @@ public static int indexOf(String str, String searchStr, int startPos) {
if (str == null || searchStr == null) {
return -1;
}
// JDK1.2/JDK1.3 have a bug, when startPos > str.length for "", hence
if (searchStr.length() == 0 && startPos >= str.length()) {
return str.length();
}
return str.indexOf(searchStr, startPos);
}