Java String Accent stripAccents(String input)

Here you can find the source of stripAccents(String input)

Description

strip Accents

License

Open Source License

Declaration

public static String stripAccents(String input) 

Method Source Code


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

import java.text.Normalizer;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;

public class Main {
    private static Pattern findAccentsPattern = Pattern.compile("\\p{InCombiningDiacriticalMarks}+");
    private static Map<Character, Character> visualEquivalents = new HashMap<>();

    public static String stripAccents(String input) {
        if (input == null) {
            return null;
        }//from   w  w w.j a v a 2  s .c o  m
        final String decomposed = Normalizer.normalize(input, Normalizer.Form.NFD);
        // Note that this doesn't correctly remove ligatures...
        String stripped = findAccentsPattern.matcher(decomposed).replaceAll("");
        for (Map.Entry<Character, Character> e : visualEquivalents.entrySet()) {
            stripped = stripped.replace(e.getKey(), e.getValue());
        }
        return stripped;
    }
}

Related

  1. replaceAccents(String string)
  2. stripAccents(final String input)
  3. stripAccents(final String input)
  4. stripAccents(final String s)
  5. stripAccents(String input)
  6. stripAccents(String input)
  7. stripAccents(String v)
  8. stripAccentsToLowerCase(String str)
  9. toLatinUnaccented(String s)