Java String Accent equalsIgnoreCaseAndAccent(String string1, String string2, Locale locale)

Here you can find the source of equalsIgnoreCaseAndAccent(String string1, String string2, Locale locale)

Description

equals Ignore Case And Accent

License

Open Source License

Declaration

public static boolean equalsIgnoreCaseAndAccent(String string1, String string2, Locale locale) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.text.Collator;

import java.util.Locale;

public class Main {
    public static boolean equalsIgnoreCaseAndAccent(String string1, String string2) {
        return compareIgnoreCaseAndAccent(string1, string2) == 0;
    }/*from   w  w  w. j  a  va 2s  . co m*/

    public static boolean equalsIgnoreCaseAndAccent(String string1, String string2, Locale locale) {
        return compareIgnoreCaseAndAccent(string1, string2, locale) == 0;
    }

    /**
     * Performs a string comparison ignoring case and accent. Beginning and ending spaces are trimmed.
     * 
     * @param string1
     *          string to be compared.
     * @param string2
     *          string to be compared.
     * @param locale
     *          The locale to perform the comparison.
     * @return a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the
     *         second.
     */
    public static int compareIgnoreCaseAndAccent(String string1, String string2, Locale locale) {
        if (string1 == null || string2 == null) {
            if (string1 == null && string2 == null)
                return 0;
            if (string1 == null)
                return -1;
            return 1;
        }

        Collator collator = Collator.getInstance(locale);
        collator.setStrength(Collator.PRIMARY);
        collator.setDecomposition(Collator.FULL_DECOMPOSITION);

        return collator.compare(string1, string2);
    }

    /**
     * Performs a string comparison ignoring case and accent. Beginning and ending spaces are trimmed.
     * 
     * @param string1
     *          string to be compared.
     * @param string2
     *          string to be compared.
     * @return a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the
     *         second.
     */
    public static int compareIgnoreCaseAndAccent(String string1, String string2) {
        return compareIgnoreCaseAndAccent(string1, string2, Locale.getDefault());
    }
}

Related

  1. deAccent(String str)
  2. deAccent(String str)
  3. deleteAccents(String text)
  4. equalsIgnoreAccents(String lhs, String rhs, Locale locale)
  5. equalsIgnoreAccentsAndCase(String s1, String s2)
  6. equalsStringIgnoringAccents(String str1, String str2)
  7. getDeAccentLoweredChars(String word)
  8. normalizeByRemovingAccent(final String string)
  9. removeAccent(String s)