Skip to content

Commit

Permalink
fix StringUtil::indexOfIgnoreCase
Browse files Browse the repository at this point in the history
  • Loading branch information
ahadas committed Jul 25, 2020
1 parent 77f1847 commit 9c644f0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Expand Up @@ -428,15 +428,11 @@ private static int indexOfIgnoreCase(String source, String target,
final int sourceCount = source.length();
final int targetCount = target.length();
final char first = target.charAt(0);
int max = Math.min(maxIndex, sourceCount - targetCount);
final int max = Math.min(maxIndex, sourceCount - targetCount);

for (int i = 0; i <= max; i++) {
final char ch = source.charAt(i);
/* Look for first character. */
if (!equalsIgnoreCase(ch, first)) {
while (++i <= max && !equalsIgnoreCase(ch, first))
;
}
while (!equalsIgnoreCase(source.charAt(i), first) && ++i <= max);

/* Found first character, now look at the rest of v2 */
if (i <= max) {
Expand Down
Expand Up @@ -122,4 +122,10 @@ public void findWhitespace() {
Assert.assertEquals(expected, StringUtil.findWhitespace(s, i));
}
}
@Test
public void indexOfIgnoreCase() {
String source = "abc ade";
String target = "adE";
Assert.assertEquals(4, StringUtil.indexOfIgnoreCase(source, target));
}
}

0 comments on commit 9c644f0

Please sign in to comment.