2
votes

I have a thermal printer, which supports only Traditional Chinese characters other than Latin. Is there any way to check, that given a CJK character in Unicode, whether it is a valid Traditional Chinese character under Big-5 encoding?

UPDATE

Here is the method I'm using to check if a String has Unicode CJK.

public static boolean isChineseText(String s) {
    for (int i = 0; s != null && s.length() > 0 && i < s.length(); i++) {
        char ch = s.charAt(i);
        Character.UnicodeBlock block = Character.UnicodeBlock.of(ch);
        if (Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS.equals(block)
                || Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS
                        .equals(block)
                || Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A
                        .equals(block)) {
            //Here, I want to check if its a Traditional Chinese character under Big-5
            return true;
        }
    }
    return false;
}
1
What code have you tried to solve this? Editing in something, anything helps us help you.bmike
Updated Question, thanks in advanceDivyansh Goenka

1 Answers

0
votes

The checks you were doing in your code (and Java itself) uses Unicode (not Big-5) encoding to encode traditional Chinese text. See this page for a conversion list between the encodings, or this site for a lookup.

There is no easy way that I know of to test that Chinese text is Traditional. You could check if the characters fall between 0xA140 and 0xF9D5 (apparently the Big 5 range from the link I gave above), but Unicode also has overlapping encoding in this range.

See also Differentiating CJK languages (Chinese, Japanese, Korean) in Android