Package com.anyascii

Class AnyAscii


  • public final class AnyAscii
    extends Object
    Unicode to ASCII transliteration

    Converts Unicode characters to their best ASCII representation

    AnyAscii provides ASCII-only replacement strings for practically all Unicode characters. Text is converted character-by-character without considering the context. The mappings for each script are based on popular existing romanization systems. Symbolic characters are converted based on their meaning or appearance. All ASCII characters in the input are left unchanged, every other character is replaced with printable ASCII characters. Unknown characters and some known characters are replaced with an empty string and removed.

    • Method Detail

      • transliterate

        public static String transliterate​(String s)
        Transliterates a string into ASCII.
        Parameters:
        s - a string
        Returns:
        an ASCII-only string
        Throws:
        NullPointerException - if s == null
      • isAscii

        public static boolean isAscii​(CharSequence s)
        Determines whether a string is ASCII-only.
        Parameters:
        s - a string
        Returns:
        true if the string is ASCII-only, false otherwise
        Throws:
        NullPointerException - if s == null
      • isAscii

        public static boolean isAscii​(char c)
        Determines whether a character is in ASCII.
        Parameters:
        c - a character
        Returns:
        true if the character is in ASCII, false otherwise
      • isAscii

        public static boolean isAscii​(int codePoint)
        Determines whether a character is in ASCII.
        Parameters:
        codePoint - a character
        Returns:
        true if the character is in ASCII, false otherwise
      • transliterate

        public static void transliterate​(CharSequence s,
                                         StringBuilder dst)
        Transliterates a string into ASCII.
        Parameters:
        s - a string
        dst - the destination buffer
        Throws:
        NullPointerException - if s == null or dst == null
      • transliterate

        public static void transliterate​(int codePoint,
                                         StringBuilder dst)
        Transliterates a character into ASCII.
        Parameters:
        codePoint - a character
        dst - the destination buffer
        Throws:
        NullPointerException - if dst == null
      • transliterate

        public static String transliterate​(int codePoint)
        Transliterates a character into ASCII.
        Parameters:
        codePoint - a character
        Returns:
        an ASCII-only string