classlib: fix StringBuilder.indexOf

Fix #615
This commit is contained in:
Alexey Andreev 2022-10-05 10:16:54 +02:00
parent fcb13b24ad
commit a40c955d39
2 changed files with 11 additions and 1 deletions

View File

@ -674,7 +674,7 @@ class TAbstractStringBuilder extends TObject implements TSerializable, TCharSequ
public int indexOf(TString str, int fromIndex) {
int sz = length - str.length();
outer: for (int i = fromIndex; i < sz; ++i) {
outer: for (int i = fromIndex; i <= sz; ++i) {
for (int j = 0; j < str.length(); ++j) {
if (buffer[i + j] != str.charAt(j)) {
continue outer;

View File

@ -407,4 +407,14 @@ public class StringBuilderTest {
public void substringWithUpperBoundAtEndWorks() {
assertEquals("23", "123".substring(1, 3));
}
@Test
public void indexOf() {
StringBuilder sb = new StringBuilder();
sb.append("12345");
assertEquals(3, sb.indexOf("45"));
assertEquals(-1, sb.indexOf("56"));
assertEquals(0, sb.indexOf("12345"));
assertEquals(0, sb.indexOf("123"));
}
}