Java String Normalize normalizeWord(String word)

Here you can find the source of normalizeWord(String word)

Description

normalize Word

License

Open Source License

Declaration

public static String normalizeWord(String word) 

Method Source Code


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

import java.lang.reflect.Method;

public class Main {
    public static String normalizeWord(String word) {
        try {/* w w  w  . j  ava 2s. c om*/
            int i;
            Class<?> normalizerClass = Class.forName("java.text.Normalizer");
            Class<?> normalizerFormClass = null;
            Class<?>[] nestedClasses = normalizerClass.getDeclaredClasses();
            for (i = 0; i < nestedClasses.length; i++) {
                Class<?> nestedClass = nestedClasses[i];
                if (nestedClass.getName().equals("java.text.Normalizer$Form")) {
                    normalizerFormClass = nestedClass;
                }
            }
            assert normalizerFormClass.isEnum();
            Method methodNormalize = normalizerClass.getDeclaredMethod("normalize", CharSequence.class,
                    normalizerFormClass);
            Object nfcNormalization = null;
            Object[] constants = normalizerFormClass.getEnumConstants();
            for (i = 0; i < constants.length; i++) {
                Object constant = constants[i];
                if (constant.toString().equals("NFC")) {
                    nfcNormalization = constant;
                }
            }
            return (String) methodNormalize.invoke(null, word, nfcNormalization);
        } catch (Exception ex) {
            return null;
        }
    }
}

Related

  1. normalizeUnicode(String str)
  2. normalizeUnicodeDiacritics(String text)
  3. normalizeWhitespace(final String str)
  4. normalizeWhiteSpace(String str)
  5. normalizeWidth(String text)