Package io.github.connellite.util
Class ConvertToAscii
java.lang.Object
io.github.connellite.util.ConvertToAscii
Escapes non-ASCII text to
\\uXXXX sequences and decodes those sequences back to Unicode,
similar in spirit to the JDK native2ascii tool.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Stringascii2native(String text) Replaces each\\uXXXXsubstring (four hex digits, case-insensitive) with the corresponding UTF-16 code unit.static Stringnative2ascii(String text) Escapes characters above U+007F as\\uXXXX.static Stringnative2ascii(String text, boolean ignoreLatinCharacters) Escapes characters to\\uXXXXform.
-
Constructor Details
-
ConvertToAscii
public ConvertToAscii()
-
-
Method Details
-
native2ascii
Escapes characters above U+007F as\\uXXXX. ASCII letters, digits, and punctuation stay as-is.- Parameters:
text- source text;nulland empty are returned unchanged- Returns:
- escaped text, or
nulliftextwasnull
-
native2ascii
Escapes characters to\\uXXXXform.If
ignoreLatinCharactersisfalse, only code points> 0x7Fare escaped. Iftrue, every character (including ASCII) is written as a\\uXXXXescape.- Parameters:
text- source text;nulland empty are returned unchangedignoreLatinCharacters- whentrue, escape all characters; whenfalse, only non-ASCII- Returns:
- escaped text, or
nulliftextwasnull
-
ascii2native
Replaces each\\uXXXXsubstring (four hex digits, case-insensitive) with the corresponding UTF-16 code unit. Unmatched parts of the input are copied unchanged.- Parameters:
text- text possibly containing\\uXXXXescapes;nulland empty are returned unchanged- Returns:
- decoded text, or
nulliftextwasnull
-