hangul/hangul.h,hangul/hangulinputcontext.c:
authorChoe Hwanjin <choe.hwanjin@gmail.com>
Sun, 1 Oct 2006 08:08:19 +0000 (17:08 +0900)
committerChoe Hwanjin <choe.hwanjin@gmail.com>
Sun, 1 Oct 2006 08:08:19 +0000 (17:08 +0900)
    * add hangul_ic_flush() function which flushes the current buffer and
      return it. returned pointer is not need to freed, but it is available
      until other HangulInputContext function is called.

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

hangul/hangul.h
hangul/hangulinputcontext.c
test/test.c

index 3007fe3..5d9bc97 100644 (file)
@@ -87,7 +87,6 @@ HangulInputContext* hangul_ic_new(HangulKeyboardType keyboard);
 void hangul_ic_delete(HangulInputContext *hic);
 bool hangul_ic_process(HangulInputContext *hic, int ascii);
 void hangul_ic_reset(HangulInputContext *hic);
-void hangul_ic_flush(HangulInputContext *hic);
 bool hangul_ic_backspace(HangulInputContext *hic);
 bool hangul_ic_is_empty(HangulInputContext *hic);
 int  hangul_ic_dvorak_to_qwerty(int qwerty);
@@ -100,6 +99,7 @@ void hangul_ic_set_filter(HangulInputContext *hic,
 
 const ucschar* hangul_ic_get_preedit_string(HangulInputContext *hic);
 const ucschar* hangul_ic_get_commit_string(HangulInputContext *hic);
+const ucschar* hangul_ic_flush(HangulInputContext *hic);
 
 /* hanja.c */
 enum {
index d42100d..04c3924 100644 (file)
@@ -53,6 +53,7 @@ struct _HangulInputContext {
 
     ucschar preedit_string[64];
     ucschar commit_string[64];
+    ucschar flushed_string[64];
 };
 
 #include "hangulkeyboard.h"
@@ -646,11 +647,13 @@ hangul_ic_reset(HangulInputContext *hic)
 
     hic->preedit_string[0] = 0;
     hic->commit_string[0] = 0;
+    hic->flushed_string[0] = 0;
 
     hangul_buffer_clear(&hic->buffer);
 }
 
-/* this function does not clear previously made commit string */
+/* append current preedit to the commit buffer.
+ * this function does not clear previously made commit string. */
 static void
 hangul_ic_flush_internal(HangulInputContext *hic)
 {
@@ -660,14 +663,22 @@ hangul_ic_flush_internal(HangulInputContext *hic)
     hangul_buffer_clear(&hic->buffer);
 }
 
-void
+const ucschar*
 hangul_ic_flush(HangulInputContext *hic)
 {
     if (hic == NULL)
-       return;
+       return NULL;
 
+    // get the remaining string and clear the buffer
+    hic->preedit_string[0] = 0;
     hic->commit_string[0] = 0;
-    hangul_ic_flush_internal(hic);
+    hic->flushed_string[0] = 0;
+    hangul_buffer_get_string(&hic->buffer, hic->flushed_string,
+                            N_ELEMENTS(hic->flushed_string));
+
+    hangul_buffer_clear(&hic->buffer);
+
+    return hic->flushed_string;
 }
 
 bool
@@ -884,6 +895,10 @@ hangul_ic_new(HangulKeyboardType keyboard)
 
     hangul_buffer_clear(&hic->buffer);
 
+    hic->preedit_string[0] = 0;
+    hic->commit_string[0] = 0;
+    hic->flushed_string[0] = 0;
+
     return hic;
 }
 
index c39b5bb..1e9d879 100644 (file)
@@ -48,10 +48,10 @@ main(int argc, char *argv[])
            printf("%c", ascii);
        }
     } 
+
     if (!hangul_ic_is_empty(hic)) {
-       hangul_ic_flush(hic);
-       commit_string = (wchar_t*)hangul_ic_get_commit_string(hic);
-       n = wcstombs(commit, commit_string, sizeof(commit));
+       const wchar_t *flushed = (wchar_t*)hangul_ic_flush(hic);
+       n = wcstombs(commit, flushed, sizeof(commit));
        commit[n] = '\0';
        if (strlen(commit) > 0) {
            printf("%s", commit);