Java String Normalize normalize(String adoc)

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

Description

Normalize with Unicode aware.

License

Open Source License

Parameter

Parameter Description
adoc a parameter

Declaration

public static String normalize(String adoc) 

Method Source Code

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

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

public class Main {
    static final Pattern NOT_PRINT = Pattern.compile(
            "([\\p{Punct}\\p{Cntrl}\\p{Sc}]|\\P{Print})+",
            Pattern.UNICODE_CHARACTER_CLASS);
    static final Pattern WHITESPACE = Pattern.compile("\\s+",
            Pattern.UNICODE_CHARACTER_CLASS);

    /**/* www.j  a  va  2s . c o  m*/
     * Normalize with Unicode aware.
     * @param adoc
     * @return
     */
    public static String normalize(String adoc) {
        String normalized = Normalizer.normalize(adoc, Normalizer.Form.NFC);
        normalized = adoc.toLowerCase(Locale.ROOT);
        normalized = NOT_PRINT.matcher(adoc).replaceAll(" ");
        normalized = WHITESPACE.matcher(adoc).replaceAll(" ");
        normalized = normalized.trim();
        return normalized;
    }
}

Related

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