/** * Returns <code>true</code> if <code>a</code> ends with <code>b</code> regardless of the case. * <p> * This method has a known bug under some alphabets with peculiar capitalisation rules such as the Georgian one, * where <code>Character.toUpperCase(a) == Character.toUpperCase(b)</code> doesn't necessarily imply that * <code>Character.toLowerCase(a) == Character.toLowerCase(b)</code>. The performance hit of testing for this * exceptions is so huge that it was deemed an acceptable issue. * </p> * <p> * Note that this method will return <code>true</code> if <code>b</code> is an emptry string. * </p> * @param a string to test. * @param b suffix to test for. * @return <code>true</code> if <code>a</code> ends with <code>b</code> regardless of the case, <code>false</code> otherwise. */ public static boolean endsWithIgnoreCase(String a, char[] b) {return matchesIgnoreCase(a, b, a.length());}
/** * Returns <code>true</code> if <code>a</code> ends with <code>b</code> regardless of the case. * <p> * This method has a known bug under some alphabets with peculiar capitalisation rules such as the Georgian one, * where <code>Character.toUpperCase(a) == Character.toUpperCase(b)</code> doesn't necessarily imply that * <code>Character.toLowerCase(a) == Character.toLowerCase(b)</code>. The performance hit of testing for this * exceptions is so huge that it was deemed an acceptable issue. * </p> * <p> * Note that this method will return <code>true</code> if <code>b</code> is an emptry string. * </p> * @param a string to test. * @param b suffix to test for. * @return <code>true</code> if <code>a</code> ends with <code>b</code> regardless of the case, <code>false</code> otherwise. */ public static boolean endsWithIgnoreCase(String a, String b) { return matchesIgnoreCase(a, b, a.length()); }
@Test(dataProvider = "matchesIgnoreCase") public void testMatchesIgnoreCase(String a, String b, int pos, boolean expected) { assert StringUtils.matchesIgnoreCase(a, b, pos) == expected; }
@Test(dataProvider = "matchesIgnoreCase") public void testMatchesIgnoreCaseCharArray(String a, String b, int pos, boolean expected) { assert StringUtils.matchesIgnoreCase(a, b.toCharArray(), pos) == expected; }
public boolean accept(String value) { int len = value.length(); // If case isn't important, a simple String.endsWith is enough. if (isCaseSensitive()) { for (int i = 0; i < extensions.length; i++) if(StringUtils.matches(value, extensions[i], len)) return true; } // If case is important, we have to be a bit more creative and // use String.regionMatches. else { // Matches the value to each extension. for (int i = 0; i < extensions.length; i++) if(StringUtils.matchesIgnoreCase(value, extensions[i], len)) return true; } return false; } }