com.softicar.platform.common.string.normalizer.DiacriticNormalizer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of platform-common Show documentation
Show all versions of platform-common Show documentation
The SoftiCAR Platform is a lightweight, Java-based library to create interactive business web applications.
package com.softicar.platform.common.string.normalizer;
import java.text.Normalizer;
import java.util.regex.Pattern;
/**
* Removes diacritics (aka. diacritical marks) from text.
*
* @author Alexander Schmidt
*/
public class DiacriticNormalizer {
private static final Pattern ACCENTS_PATTERN = Pattern.compile("\\p{M}");
/**
* Removes diacritics from the characters in the given text.
*
* Relies on Unicode decomposition mappings.
*
* @param text
* the text to strip of diacritical marks (never null)
* @return the given text, stripped of diacritical marks (never null)
*/
public String normalize(String text) {
return ACCENTS_PATTERN//
.matcher(Normalizer.normalize(text, Normalizer.Form.NFKD))
.replaceAll("");
}
}