From c01f6ce7f6c70b72ceef439996c146f7b4744f98 Mon Sep 17 00:00:00 2001 From: "David A. Madore" Date: Thu, 29 Apr 2010 00:20:54 +0200 Subject: More proper handling of CJK and Hangul. --- .../android/unicodeMap/UnicodeCharacter.java | 71 +++++++++++++++------- 1 file changed, 49 insertions(+), 22 deletions(-) (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 166229f..f3ff6d1 100644 --- a/src/org/madore/android/unicodeMap/UnicodeCharacter.java +++ b/src/org/madore/android/unicodeMap/UnicodeCharacter.java @@ -226,18 +226,42 @@ public class UnicodeCharacter implements UnicodeDisplayable { } 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); + CJK_IDEOGRAPH_EXTENSION_A(0x3400, 0x4DB5, Category.OTHER_LETTER) { + public String getName(int codePoint) { + return cjkIdeographName(codePoint); + } + }, + CJK_IDEOGRAPH(0x4E00, 0x9FCB, Category.OTHER_LETTER) { + public String getName(int codePoint) { + return cjkIdeographName(codePoint); + } + }, + HANGUL_SYLLABLE(0xAC00, 0xD7A3, Category.OTHER_LETTER) { + public String getName(int codePoint) { + return hangulSyllableName(codePoint); + } + }, + CJK_IDEOGRAPH_EXTENSION_B(0x20000, 0x2A6D6, Category.OTHER_LETTER) { + public String getName(int codePoint) { + return cjkIdeographName(codePoint); + } + }, + CJK_IDEOGRAPH_EXTENSION_C(0x2A700, 0x2B734, Category.OTHER_LETTER) { + public String getName(int codePoint) { + return cjkIdeographName(codePoint); + } + }; protected final int from; protected final int to; - SpecialRange(int from, int last) { + protected Category category; + SpecialRange(int from, int last, Category category) { this.from = from; this.to = last+1; + this.category = category; } public int getFrom() { return this.from; } public int getTo() { return this.to; } + public Category getCategory() { return this.category; } + public String getName(int codePoint) { return null; } public boolean belongs(int codePoint) { return ( codePoint>=this.from && codePoint= this.from && to <= this.to ); } - public static boolean isCjkUnifiedIdeograph(int codePoint) { + public static boolean isCjkIdeograph(int codePoint) { return ( CJK_IDEOGRAPH.belongs(codePoint) || CJK_IDEOGRAPH_EXTENSION_A.belongs(codePoint) || CJK_IDEOGRAPH_EXTENSION_B.belongs(codePoint) @@ -258,28 +282,31 @@ public class UnicodeCharacter implements UnicodeDisplayable { public static boolean isHangulSyllable(int codePoint) { return HANGUL_SYLLABLE.belongs(codePoint); } - public static String cjkUnifiedIdeographName(int codePoint) { - if ( ! isCjkUnifiedIdeograph(codePoint) ) - return null; + protected static String cjkIdeographName(int codePoint) { return String.format("CJK UNIFIED IDEOGRAPH-%04X", codePoint); } - public static String hangulSyllableName(int codePoint) { - if ( ! isHangulSyllable(codePoint) ) - return null; + protected static String hangulSyllableName(int codePoint) { 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]); + 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]); } } -- cgit v1.2.3