From b65f635b99a67f6e55aa1a14aaf98e1d53ef9cbc Mon Sep 17 00:00:00 2001 From: Huang Peng Date: Fri, 15 Aug 2008 18:44:24 +0800 Subject: [PATCH] Update test.py --- engine/hangul.i | 12 +++++++++++- engine/test.py | 35 +++++++++++++++++++---------------- 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/engine/hangul.i b/engine/hangul.i index 16ecebe..f852a5a 100644 --- a/engine/hangul.i +++ b/engine/hangul.i @@ -31,7 +31,10 @@ %typemap (in) ucschar * { if (PyUnicode_Check ($input)) { - $1 = (ucschar *)PyUnicode_AsUnicode ($input); + Py_ssize_t size = PyUnicode_GetSize ($input); + $1 = (ucschar *)malloc ((size + 1) * sizeof (ucschar)); + PyUnicode_AsWideChar ((PyUnicodeObject *)$input, (wchar_t *)$1, size); + $1[size] = 0; } else { PyErr_SetString (PyExc_TypeError, @@ -40,6 +43,10 @@ } } +%typemap(freearg) ucschar * { + free ($1); +} + %typemap (out) ucschar * { if ($1 != NULL) { $result = PyUnicode_FromWideChar ((const wchar_t *)$1, @@ -233,13 +240,16 @@ bool hangul_is_syllable(ucschar c); bool hangul_is_jaso(ucschar c); bool hangul_is_jamo(ucschar c); +/* ucschar hangul_jaso_to_jamo(ucschar ch); ucschar hangul_choseong_to_jamo(ucschar ch); ucschar hangul_jungseong_to_jamo(ucschar ch); ucschar hangul_jongseong_to_jamo(ucschar ch); +*/ ucschar hangul_choseong_to_jongseong(ucschar ch); ucschar hangul_jongseong_to_choseong(ucschar ch); + /* void hangul_jongseong_dicompose(ucschar ch, ucschar* jong, ucschar* cho); */ diff --git a/engine/test.py b/engine/test.py index cd67997..8d35beb 100644 --- a/engine/test.py +++ b/engine/test.py @@ -1,21 +1,24 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -import anthy +import hangul import sys -ctx = anthy.anthy_context () -ctx._set_encoding (2) -if len(sys.argv) >= 2: - ctx.set_string (sys.argv[1]) -else: - ctx.set_string ("かまぁく") -conv_stat = anthy.anthy_conv_stat () -seg_stat = anthy.anthy_segment_stat () -ctx.get_stat (conv_stat) -for i in range (0, conv_stat.nr_segment): - ctx.get_segment_stat (i, seg_stat) - buf = " " - i = ctx.get_segment (i, 0, buf, 10) - print buf[:i] -# anthy.anthy_release_context (ctx) +ctx = hangul.HangulInputContext("2") +ctx.process(ord('a')) +ctx.process(ord('b')) +ctx.process(ord('c')) +print ctx.get_preedit_string() +print ctx.get_commit_string() +print ctx.flush() +print ctx.get_preedit_string() +print ctx.get_commit_string() +print ctx.flush() ctx = None + +table = hangul.HanjaTable("/usr/share/libhangul/hanja/hanja.txt") +v = table.match_prefix("가례") +if v: + k, l = v + print k + for v, c in l: + print v, c -- 2.7.4