HangulInputContext의 상태를 알 수 있는 함수 추가:
authorChoe Hwanjin <choe.hwanjin@gmail.com>
Sun, 14 Jan 2007 12:14:07 +0000 (21:14 +0900)
committerChoe Hwanjin <choe.hwanjin@gmail.com>
Sun, 14 Jan 2007 12:14:07 +0000 (21:14 +0900)
 * hangul_buffer_has_choseong(), hangul_buffer_has_jungseong(),
   hangul_buffer_has_jongseong() 추가

git-svn-id: http://kldp.net/svn/hangul/libhangul/trunk@114 8f00fcd2-89fc-0310-932e-b01be5b65e01

hangul/hangul.h
hangul/hangulctype.c
hangul/hangulinputcontext.c

index 6529443..a981709 100644 (file)
@@ -93,7 +93,12 @@ void hangul_ic_delete(HangulInputContext *hic);
 bool hangul_ic_process(HangulInputContext *hic, int ascii);
 void hangul_ic_reset(HangulInputContext *hic);
 bool hangul_ic_backspace(HangulInputContext *hic);
+
 bool hangul_ic_is_empty(HangulInputContext *hic);
+bool hangul_ic_has_choseong(HangulInputContext *hic);
+bool hangul_ic_has_jungseong(HangulInputContext *hic);
+bool hangul_ic_has_jongseong(HangulInputContext *hic);
+
 int  hangul_ic_dvorak_to_qwerty(int qwerty);
 
 void hangul_ic_set_output_mode(HangulInputContext *hic, int mode);
index 0035f90..104c83a 100644 (file)
@@ -25,6 +25,8 @@
 #include <config.h>
 #endif
 
+#include <stdlib.h>
+
 #include "hangul.h"
 
 /**
@@ -373,4 +375,43 @@ hangul_jaso_to_syllable(ucschar choseong, ucschar jungseong, ucschar jongseong)
     return c;
 }
 
+void
+hangul_syllable_to_jaso(ucschar syllable,
+                       ucschar* choseong,
+                       ucschar* jungseong,
+                       ucschar* jongseong)
+{
+    static const ucschar hangul_base    = 0xac00;
+    static const ucschar choseong_base  = 0x1100;
+    static const ucschar jungseong_base = 0x1161;
+    static const ucschar jongseong_base = 0x11a7;
+    static const int njungseong = 21;
+    static const int njongseong = 28;
+
+    if (!hangul_is_syllable(syllable)) {
+       if (jongseong != NULL)
+           *jongseong = 0;
+       if (jungseong != NULL)
+           *jungseong = 0;
+       if (choseong != NULL)
+           *choseong = 0;
 
+       return;
+    }
+
+    syllable -= hangul_base;
+
+    if (jongseong != NULL) {
+       *jongseong = jongseong_base + syllable % njongseong;
+    }
+    syllable /= njongseong;
+
+    if (jungseong != NULL) {
+       *jungseong = jungseong_base + syllable % njungseong;
+    }
+    syllable /= njungseong;
+
+    if (choseong != NULL) {
+       *choseong = choseong_base + syllable;
+    }
+}
index e304c63..adf4599 100644 (file)
@@ -274,6 +274,24 @@ hangul_buffer_is_empty(HangulBuffer *buffer)
           buffer->jongseong == 0;
 }
 
+static bool
+hangul_buffer_has_choseong(HangulBuffer *buffer)
+{
+    return buffer->choseong != 0;
+}
+
+static bool
+hangul_buffer_has_jungseong(HangulBuffer *buffer)
+{
+    return buffer->jungseong != 0;
+}
+
+static bool
+hangul_buffer_has_jongseong(HangulBuffer *buffer)
+{
+    return buffer->jongseong != 0;
+}
+
 static void
 hangul_buffer_push(HangulBuffer *buffer, ucschar ch)
 {
@@ -969,6 +987,24 @@ hangul_ic_is_empty(HangulInputContext *hic)
     return hangul_buffer_is_empty(&hic->buffer);
 }
 
+bool
+hangul_ic_has_choseong(HangulInputContext *hic)
+{
+    return hangul_buffer_has_choseong(&hic->buffer);
+}
+
+bool
+hangul_ic_has_jungseong(HangulInputContext *hic)
+{
+    return hangul_buffer_has_jungseong(&hic->buffer);
+}
+
+bool
+hangul_ic_has_jongseong(HangulInputContext *hic)
+{
+    return hangul_buffer_has_jongseong(&hic->buffer);
+}
+
 void
 hangul_ic_set_output_mode(HangulInputContext *hic, int mode)
 {