@@ -1946,9 +1946,9 @@ public int indexOf(final String str) {
19461946 * @return The first index of the string, or -1 if not found
19471947 */
19481948 public int indexOf (final String str , int startIndex ) {
1949- startIndex = Math .max (startIndex , 0 );
1949+ startIndex = Math .max (0 , startIndex );
19501950 if (str == null || startIndex >= size ) {
1951- return - 1 ;
1951+ return StringUtils . INDEX_NOT_FOUND ;
19521952 }
19531953 final int strLen = str .length ();
19541954 if (strLen == 1 ) {
@@ -1958,19 +1958,20 @@ public int indexOf(final String str, int startIndex) {
19581958 return startIndex ;
19591959 }
19601960 if (strLen > size ) {
1961- return - 1 ;
1961+ return StringUtils . INDEX_NOT_FOUND ;
19621962 }
19631963 final char [] thisBuf = buffer ;
1964- final int len = size - strLen + 1 ;
1965- outer : for (int i = startIndex ; i < len ; i ++) {
1966- for (int j = 0 ; j < strLen ; j ++) {
1967- if (str .charAt (j ) != thisBuf [i + j ]) {
1968- continue outer ;
1969- }
1964+ final int searchLen = size - strLen + 1 ;
1965+ for (int i = startIndex ; i < searchLen ; i ++) {
1966+ boolean found = true ;
1967+ for (int j = 0 ; j < strLen && found ; j ++) {
1968+ found = str .charAt (j ) == thisBuf [i + j ];
1969+ }
1970+ if (found ) {
1971+ return i ;
19701972 }
1971- return i ;
19721973 }
1973- return - 1 ;
1974+ return StringUtils . INDEX_NOT_FOUND ;
19741975 }
19751976
19761977 /**
@@ -2282,27 +2283,28 @@ public int lastIndexOf(final String str) {
22822283 public int lastIndexOf (final String str , int startIndex ) {
22832284 startIndex = startIndex >= size ? size - 1 : startIndex ;
22842285 if (str == null || startIndex < 0 ) {
2285- return - 1 ;
2286+ return StringUtils . INDEX_NOT_FOUND ;
22862287 }
22872288 final int strLen = str .length ();
2288- if (strLen > 0 && strLen <= size ) {
2289- if (strLen == 1 ) {
2290- return lastIndexOf (str .charAt (0 ), startIndex );
2289+ if (strLen == 0 ) {
2290+ return startIndex ;
2291+ }
2292+ if (strLen > size ) {
2293+ return StringUtils .INDEX_NOT_FOUND ;
2294+ }
2295+ if (strLen == 1 ) {
2296+ return lastIndexOf (str .charAt (0 ), startIndex );
2297+ }
2298+ for (int i = startIndex - strLen + 1 ; i >= 0 ; i --) {
2299+ boolean found = true ;
2300+ for (int j = 0 ; j < strLen && found ; j ++) {
2301+ found = str .charAt (j ) == buffer [i + j ];
22912302 }
2292-
2293- outer : for (int i = startIndex - strLen + 1 ; i >= 0 ; i --) {
2294- for (int j = 0 ; j < strLen ; j ++) {
2295- if (str .charAt (j ) != buffer [i + j ]) {
2296- continue outer ;
2297- }
2298- }
2303+ if (found ) {
22992304 return i ;
23002305 }
2301-
2302- } else if (strLen == 0 ) {
2303- return startIndex ;
23042306 }
2305- return - 1 ;
2307+ return StringUtils . INDEX_NOT_FOUND ;
23062308 }
23072309
23082310 /**
0 commit comments