Fixes String.indexOf(String) issue

This commit is contained in:
konsoletyper 2014-04-25 14:35:14 +04:00
parent 3b2ec91d20
commit abc6c83827
2 changed files with 2 additions and 1 deletions

View File

@ -307,7 +307,7 @@ public class TString extends TObject implements TSerializable, TComparable<TStri
public int indexOf(TString str, int fromIndex) { public int indexOf(TString str, int fromIndex) {
int toIndex = length() - str.length(); int toIndex = length() - str.length();
outer: outer:
for (int i = fromIndex; i < toIndex; ++i) { for (int i = fromIndex; i <= toIndex; ++i) {
for (int j = 0; j < str.length(); ++j) { for (int j = 0; j < str.length(); ++j) {
if (charAt(i + j) != str.charAt(j)) { if (charAt(i + j) != str.charAt(j)) {
continue outer; continue outer;

View File

@ -160,6 +160,7 @@ public class StringTest {
@Test @Test
public void findsString() { public void findsString() {
assertEquals(1, "abcdbcd".indexOf("bc")); assertEquals(1, "abcdbcd".indexOf("bc"));
assertEquals(3, "abcdbcd".indexOf("dbcd"));
assertEquals(-1, "abcdbcd".indexOf("bb")); assertEquals(-1, "abcdbcd".indexOf("bb"));
} }