Java String Normalize normalize(String name)

Here you can find the source of normalize(String name)

Description

normalize

License

Open Source License

Declaration

public static String normalize(String name) 

Method Source Code


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

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

public class Main {
    public static String normalize(String name) {
        return normalize(name, -1);
    }//from w ww  . j  ava  2 s. c o  m

    public static String normalize(String name, int limit) {
        String normalized = deAccent(name).replaceAll("[^0-9a-zA-Z\\$_]", "");
        return limit > 0 && normalized.length() > limit ? normalized.substring(0, limit - 1) : normalized;
    }

    private static String deAccent(String str) {
        String nfdNormalizedString = Normalizer.normalize(str, Normalizer.Form.NFD);
        Pattern pattern = Pattern.compile("\\p{InCombiningDiacriticalMarks}+");
        return pattern.matcher(nfdNormalizedString).replaceAll("");
    }
}

Related

  1. normalize(final String string)
  2. normalize(final String string)
  3. normalize(Object o, StringBuffer sb)
  4. normalize(String adoc)
  5. normalize(String in)
  6. normalize(String s)
  7. normalize(String s)
  8. normalize(String s)
  9. normalize(String s)