package com.mindprod.example;
import java.text.Normalizer;
import static java.lang.System.*;
/**
* Exercise Normalizer class, JDK 1.8+.
*
* @author Roedy Green, Canadian Mind Products
* @version 1.0 2009-01-01 initial version
* @since 2009-01-01
*/
public final class TestNormalizer
{
/**
* Convert accented letters to the equivalent unaccented letter.
*
* @param accented string to convert
*
* @return string with accented letters converted to equivalent unaccented letters
*/
private static String removeAccents( String accented )
{
final String normalized = Normalizer.normalize( accented, Normalizer.Form.NFD );
StringBuilder sb = new StringBuilder( accented.length() );
for ( int i = 0; i < normalized.length(); i++ )
{
char c = normalized.charAt( i );
if ( Character.getType( c ) != Character.NON_SPACING_MARK )
{
sb.append( c );
}
}
return sb.toString();
}
/**
* Test harness
*
* @param args not used
*/
public static void main( String[] args )
{
String godel = "Kurt Gödel";
out.println( "godel = " + godel );
out.println( "removeAccents( godel ) = " + removeAccents( godel ) );
}
}