summaryrefslogtreecommitdiffstats
path: root/src/org/madore/android/unicodeMap/UnicodeCharacter.java
diff options
context:
space:
mode:
authorDavid A. Madore <david@procyon.(none)>2010-04-27 20:55:58 +0200
committerDavid A. Madore <david@procyon.(none)>2010-04-27 20:55:58 +0200
commit7108dafb73f4c06261a56b819f4530ffd17bf6e7 (patch)
tree22bf852a5e4dcc7c511ee6422fe253bd8dbc0cfc /src/org/madore/android/unicodeMap/UnicodeCharacter.java
parent9df4bb4fa30a0c05ccd484d6b59521bfca665854 (diff)
downloadUnicodeMap-7108dafb73f4c06261a56b819f4530ffd17bf6e7.tar.gz
UnicodeMap-7108dafb73f4c06261a56b819f4530ffd17bf6e7.tar.bz2
UnicodeMap-7108dafb73f4c06261a56b819f4530ffd17bf6e7.zip
Preliminary implementation of CJK and Hangul.
Diffstat (limited to 'src/org/madore/android/unicodeMap/UnicodeCharacter.java')
-rw-r--r--src/org/madore/android/unicodeMap/UnicodeCharacter.java58
1 files changed, 58 insertions, 0 deletions
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 && codePoint<this.to );
+ }
+ public int interCount(int from, int to) {
+ int from0 = (from<this.from)?this.from:from;
+ int to0 = (to>this.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),