From 7108dafb73f4c06261a56b819f4530ffd17bf6e7 Mon Sep 17 00:00:00 2001 From: "David A. Madore" Date: Tue, 27 Apr 2010 20:55:58 +0200 Subject: Preliminary implementation of CJK and Hangul. --- .../android/unicodeMap/UnicodeCharacter.java | 58 ++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'src/org/madore/android/unicodeMap/UnicodeCharacter.java') diff --git a/src/org/madore/android/unicodeMap/UnicodeCharacter.java b/src/org/madore/android/unicodeMap/UnicodeCharacter.java index 552b43c..166229f 100644 --- a/src/org/madore/android/unicodeMap/UnicodeCharacter.java +++ b/src/org/madore/android/unicodeMap/UnicodeCharacter.java @@ -225,6 +225,64 @@ public class UnicodeCharacter implements UnicodeDisplayable { public String toString() { return this.descr; } } + public static enum SpecialRange { + CJK_IDEOGRAPH_EXTENSION_A(0x3400, 0x4DB5), + CJK_IDEOGRAPH(0x4E00, 0x9FCB), + HANGUL_SYLLABLE(0xAC00, 0xD7A3), + CJK_IDEOGRAPH_EXTENSION_B(0x20000, 0x2A6D6), + CJK_IDEOGRAPH_EXTENSION_C(0x2A700, 0x2B734); + protected final int from; protected final int to; + SpecialRange(int from, int last) { + this.from = from; + this.to = last+1; + } + public int getFrom() { return this.from; } + public int getTo() { return this.to; } + public boolean belongs(int codePoint) { + return ( codePoint>=this.from && codePointthis.to)?this.to:to; + return (to0-from0>0) ? to0-from0 : 0; + } + public boolean inside(int from, int to) { + return ( from >= this.from && to <= this.to ); + } + public static boolean isCjkUnifiedIdeograph(int codePoint) { + return ( CJK_IDEOGRAPH.belongs(codePoint) + || CJK_IDEOGRAPH_EXTENSION_A.belongs(codePoint) + || CJK_IDEOGRAPH_EXTENSION_B.belongs(codePoint) + || CJK_IDEOGRAPH_EXTENSION_C.belongs(codePoint) ); + } + public static boolean isHangulSyllable(int codePoint) { + return HANGUL_SYLLABLE.belongs(codePoint); + } + public static String cjkUnifiedIdeographName(int codePoint) { + if ( ! isCjkUnifiedIdeograph(codePoint) ) + return null; + return String.format("CJK UNIFIED IDEOGRAPH-%04X", codePoint); + } + public static String hangulSyllableName(int codePoint) { + if ( ! isHangulSyllable(codePoint) ) + return null; + int index = codePoint - HANGUL_SYLLABLE.getFrom(); + final int tCount = 28; final int nCount = 21*tCount; + int l = index/nCount; + int v = (index%nCount)/tCount; + int t = index%tCount; + final String[] partL = { "G", "GG", "N", "D", "DD", "R", "M", "B", "BB", "S", + "SS", "", "J", "JJ", "C", "K", "T", "P", "H" }; + final String[] partV = { "A", "AE", "YA", "YAE", "EO", "E", "YEO", "YE", "O", "WA", + "WAE", "OE", "YO", "U", "WEO", "WE", "WI", "YU", "EU", "YI", + "I" }; + final String[] partT = { "", "G", "GG", "GS", "N", "NJ", "NH", "D", "L", "LG", + "LM", "LB", "LS", "LT", "LP", "LH", "M", "B", "BS", "S", + "SS", "NG", "J", "C", "K", "T", "P", "H" }; + return String.format("HANGUL SYLLABLE %s%s%s", partL[l], partV[v], partT[t]); + } + } + public static enum Category { UPPERCASE_LETTER("Lu", Character.UPPERCASE_LETTER), LOWERCASE_LETTER("Ll", Character.LOWERCASE_LETTER), -- cgit v1.2.3