Check if a character is Traditional Chinese in Big-5 (Java)?
Asked Answered
B

1

3

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;
}
Bron answered 11/12, 2014 at 2:40 Comment(1)
What code have you tried to solve this? Editing in something, anything helps us help you.Razor
L
1

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

Lesbian answered 1/2, 2017 at 15:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.