/** * <p>Case in-sensitive find of the last index within a CharSequence.</p> * * <p>A {@code null} CharSequence will return {@code -1}. * A negative start position returns {@code -1}. * An empty ("") search CharSequence always matches unless the start position is negative. * A start position greater than the string length searches the whole string.</p> * * <pre> * StringUtils.lastIndexOfIgnoreCase(null, *) = -1 * StringUtils.lastIndexOfIgnoreCase(*, null) = -1 * StringUtils.lastIndexOfIgnoreCase("aabaabaa", "A") = 7 * StringUtils.lastIndexOfIgnoreCase("aabaabaa", "B") = 5 * StringUtils.lastIndexOfIgnoreCase("aabaabaa", "AB") = 4 * </pre> * * @param str the CharSequence to check, may be null * @param searchStr the CharSequence to find, may be null * @return the first index of the search CharSequence, * -1 if no match or {@code null} string input * @since 2.5 * @since 3.0 Changed signature from lastIndexOfIgnoreCase(String, String) to lastIndexOfIgnoreCase(CharSequence, CharSequence) */ public static int lastIndexOfIgnoreCase(final CharSequence str, final CharSequence searchStr) { if (str == null || searchStr == null) { return INDEX_NOT_FOUND; } return lastIndexOfIgnoreCase(str, searchStr, str.length()); }
@Test public void testLastIndexOfIgnoreCase_String() { assertEquals(-1, StringUtils.lastIndexOfIgnoreCase(null, null)); assertEquals(-1, StringUtils.lastIndexOfIgnoreCase("", null)); assertEquals(-1, StringUtils.lastIndexOfIgnoreCase(null, "")); assertEquals(-1, StringUtils.lastIndexOfIgnoreCase("", "a")); assertEquals(0, StringUtils.lastIndexOfIgnoreCase("", "")); assertEquals(8, StringUtils.lastIndexOfIgnoreCase("aabaabaa", "")); assertEquals(7, StringUtils.lastIndexOfIgnoreCase("aabaabaa", "a")); assertEquals(7, StringUtils.lastIndexOfIgnoreCase("aabaabaa", "A")); assertEquals(5, StringUtils.lastIndexOfIgnoreCase("aabaabaa", "b")); assertEquals(5, StringUtils.lastIndexOfIgnoreCase("aabaabaa", "B")); assertEquals(4, StringUtils.lastIndexOfIgnoreCase("aabaabaa", "ab")); assertEquals(4, StringUtils.lastIndexOfIgnoreCase("aabaabaa", "AB")); assertEquals(-1, StringUtils.lastIndexOfIgnoreCase("ab", "AAB")); assertEquals(0, StringUtils.lastIndexOfIgnoreCase("aab", "AAB")); }
@Test public void testLastIndexOfIgnoreCase_StringInt() { assertEquals(-1, StringUtils.lastIndexOfIgnoreCase(null, null, 0)); assertEquals(-1, StringUtils.lastIndexOfIgnoreCase(null, null, -1)); assertEquals(-1, StringUtils.lastIndexOfIgnoreCase(null, "", 0)); assertEquals(-1, StringUtils.lastIndexOfIgnoreCase(null, "", -1)); assertEquals(-1, StringUtils.lastIndexOfIgnoreCase("", null, 0)); assertEquals(-1, StringUtils.lastIndexOfIgnoreCase("", null, -1)); assertEquals(0, StringUtils.lastIndexOfIgnoreCase("", "", 0)); assertEquals(-1, StringUtils.lastIndexOfIgnoreCase("", "", -1)); assertEquals(0, StringUtils.lastIndexOfIgnoreCase("", "", 9)); assertEquals(0, StringUtils.lastIndexOfIgnoreCase("abc", "", 0)); assertEquals(-1, StringUtils.lastIndexOfIgnoreCase("abc", "", -1)); assertEquals(3, StringUtils.lastIndexOfIgnoreCase("abc", "", 9)); assertEquals(7, StringUtils.lastIndexOfIgnoreCase("aabaabaa", "A", 8)); assertEquals(5, StringUtils.lastIndexOfIgnoreCase("aabaabaa", "B", 8)); assertEquals(4, StringUtils.lastIndexOfIgnoreCase("aabaabaa", "AB", 8)); assertEquals(2, StringUtils.lastIndexOfIgnoreCase("aabaabaa", "B", 3)); assertEquals(5, StringUtils.lastIndexOfIgnoreCase("aabaabaa", "B", 9)); assertEquals(-1, StringUtils.lastIndexOfIgnoreCase("aabaabaa", "B", -1)); assertEquals(-1, StringUtils.lastIndexOfIgnoreCase("aabaabaa", "B", 0)); assertEquals(0, StringUtils.lastIndexOfIgnoreCase("aabaabaa", "A", 0)); assertEquals(1, StringUtils.lastIndexOfIgnoreCase("aab", "AB", 1)); }
@Override protected int handleIndex(CharSequence str, CharSequence searchStr, int startPos) { return StringUtils.lastIndexOfIgnoreCase(str, searchStr, startPos); }
/** * <p>Case in-sensitive find of the last index within a CharSequence.</p> * * <p>A {@code null} CharSequence will return {@code -1}. * A negative start position returns {@code -1}. * An empty ("") search CharSequence always matches unless the start position is negative. * A start position greater than the string length searches the whole string.</p> * * <pre> * StringUtils.lastIndexOfIgnoreCase(null, *) = -1 * StringUtils.lastIndexOfIgnoreCase(*, null) = -1 * StringUtils.lastIndexOfIgnoreCase("aabaabaa", "A") = 7 * StringUtils.lastIndexOfIgnoreCase("aabaabaa", "B") = 5 * StringUtils.lastIndexOfIgnoreCase("aabaabaa", "AB") = 4 * </pre> * * @param str the CharSequence to check, may be null * @param searchStr the CharSequence to find, may be null * @return the first index of the search CharSequence, * -1 if no match or {@code null} string input * @since 2.5 * @since 3.0 Changed signature from lastIndexOfIgnoreCase(String, String) to lastIndexOfIgnoreCase(CharSequence, CharSequence) */ public static int lastIndexOfIgnoreCase(final CharSequence str, final CharSequence searchStr) { if (str == null || searchStr == null) { return INDEX_NOT_FOUND; } return lastIndexOfIgnoreCase(str, searchStr, str.length()); }
/** * <p>Case in-sensitive find of the last index within a CharSequence.</p> * * <p>A {@code null} CharSequence will return {@code -1}. * A negative start position returns {@code -1}. * An empty ("") search CharSequence always matches unless the start position is negative. * A start position greater than the string length searches the whole string.</p> * * <pre> * StringUtils.lastIndexOfIgnoreCase(null, *) = -1 * StringUtils.lastIndexOfIgnoreCase(*, null) = -1 * StringUtils.lastIndexOfIgnoreCase("aabaabaa", "A") = 7 * StringUtils.lastIndexOfIgnoreCase("aabaabaa", "B") = 5 * StringUtils.lastIndexOfIgnoreCase("aabaabaa", "AB") = 4 * </pre> * * @param str the CharSequence to check, may be null * @param searchStr the CharSequence to find, may be null * @return the first index of the search CharSequence, * -1 if no match or {@code null} string input * @since 2.5 * @since 3.0 Changed signature from lastIndexOfIgnoreCase(String, String) to lastIndexOfIgnoreCase(CharSequence, CharSequence) */ public static int lastIndexOfIgnoreCase(final CharSequence str, final CharSequence searchStr) { if (str == null || searchStr == null) { return INDEX_NOT_FOUND; } return lastIndexOfIgnoreCase(str, searchStr, str.length()); }
/** * <p>Case in-sensitive find of the last index within a CharSequence.</p> * * <p>A {@code null} CharSequence will return {@code -1}. * A negative start position returns {@code -1}. * An empty ("") search CharSequence always matches unless the start position is negative. * A start position greater than the string length searches the whole string.</p> * * <pre> * StringUtils.lastIndexOfIgnoreCase(null, *) = -1 * StringUtils.lastIndexOfIgnoreCase(*, null) = -1 * StringUtils.lastIndexOfIgnoreCase("aabaabaa", "A") = 7 * StringUtils.lastIndexOfIgnoreCase("aabaabaa", "B") = 5 * StringUtils.lastIndexOfIgnoreCase("aabaabaa", "AB") = 4 * </pre> * * @param str the CharSequence to check, may be null * @param searchStr the CharSequence to find, may be null * @return the first index of the search CharSequence, * -1 if no match or {@code null} string input * @since 2.5 * @since 3.0 Changed signature from lastIndexOfIgnoreCase(String, String) to lastIndexOfIgnoreCase(CharSequence, CharSequence) */ public static int lastIndexOfIgnoreCase(final CharSequence str, final CharSequence searchStr) { if (str == null || searchStr == null) { return INDEX_NOT_FOUND; } return lastIndexOfIgnoreCase(str, searchStr, str.length()); }
public static int lastIndexOfIgnoreCase(ActionContext actionContext){ Thing self = actionContext.getObject("self"); CharSequence cs1 = (CharSequence) self.doAction("getCs1", actionContext); CharSequence cs2 = (CharSequence) self.doAction("getCs2", actionContext); Integer startPos = (Integer) self.doAction("getStartPos", actionContext); return StringUtils.lastIndexOfIgnoreCase(cs1, cs2, startPos); }