diff --git a/src/main/java/org/apache/commons/lang3/CharSequenceUtils.java b/src/main/java/org/apache/commons/lang3/CharSequenceUtils.java index fdb91220b..0dace41e5 100644 --- a/src/main/java/org/apache/commons/lang3/CharSequenceUtils.java +++ b/src/main/java/org/apache/commons/lang3/CharSequenceUtils.java @@ -134,6 +134,13 @@ public class CharSequenceUtils { * @return the index where the search sequence was found */ static int indexOf(final CharSequence cs, final CharSequence searchChar, final int start) { + if (cs instanceof String) { + return ((String) cs).indexOf(searchChar.toString(), start); + } else if (cs instanceof StringBuilder) { + return ((StringBuilder) cs).indexOf(searchChar.toString(), start); + } else if (cs instanceof StringBuffer) { + return ((StringBuffer) cs).indexOf(searchChar.toString(), start); + } return cs.toString().indexOf(searchChar.toString(), start); // if (cs instanceof String && searchChar instanceof String) { // // TODO: Do we assume searchChar is usually relatively small; @@ -218,6 +225,13 @@ public class CharSequenceUtils { * @return the index where the search sequence was found */ static int lastIndexOf(final CharSequence cs, final CharSequence searchChar, final int start) { + if (cs instanceof String) { + return ((String) cs).lastIndexOf((String) searchChar, start); + } else if (cs instanceof StringBuilder) { + return ((StringBuilder) cs).lastIndexOf((String) searchChar, start); + } else if (cs instanceof StringBuffer) { + return ((StringBuffer) cs).lastIndexOf((String) searchChar, start); + } return cs.toString().lastIndexOf(searchChar.toString(), start); // if (cs instanceof String && searchChar instanceof String) { // // TODO: Do we assume searchChar is usually relatively small;