summaryrefslogtreecommitdiff
path: root/hangul/hangul.h
blob: bf16afde2b6dde89ed5fc60c240dfb460386fa18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/* libhangul
 * Copyright (C) 2004 - 2007 Choe Hwanjin
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

#ifndef libhangul_hangul_h
#define libhangul_hangul_h

#include <stdbool.h>
#include <inttypes.h>

#ifdef __GNUC__
#define LIBHANGUL_DEPRECATED __attribute__((deprecated));
#else
#define LIBHANGUL_DEPRECATED
#endif

#ifdef __cplusplus
extern "C" {
#endif

/* hangulctype.c */
enum {
    HANGUL_CHOSEONG_FILLER  = 0x115f,   /* hangul choseong filler */
    HANGUL_JUNGSEONG_FILLER = 0x1160    /* hangul jungseong filler */
};

typedef uint32_t ucschar;

bool hangul_is_choseong(ucschar c);
bool hangul_is_jungseong(ucschar c);
bool hangul_is_jongseong(ucschar c);
bool hangul_is_choseong_conjoinable(ucschar c);
bool hangul_is_jungseong_conjoinable(ucschar c);
bool hangul_is_jongseong_conjoinable(ucschar c);
bool hangul_is_syllable(ucschar c);
bool hangul_is_jamo(ucschar c);
bool hangul_is_cjamo(ucschar c);

ucschar hangul_jamo_to_cjamo(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);

const ucschar* hangul_syllable_iterator_prev(const ucschar* str,
					     const ucschar* begin);
const ucschar* hangul_syllable_iterator_next(const ucschar* str,
					     const ucschar* end);

int     hangul_syllable_len(const ucschar* str, int max_len);

ucschar hangul_jamo_to_syllable(ucschar choseong,
				ucschar jungseong,
				ucschar jongseong);
void    hangul_syllable_to_jamo(ucschar syllable,
				ucschar* choseong,
				ucschar* jungseong,
				ucschar* jongseong);
int     hangul_jamos_to_syllables(ucschar* dest, int destlen,
				  const ucschar* src, int srclen);

/* hangulinputcontext.c */
typedef struct _HangulKeyboard        HangulKeyboard;
typedef struct _HangulCombination     HangulCombination;
typedef struct _HangulBuffer          HangulBuffer;
typedef struct _HangulInputContext    HangulInputContext;

enum {
    HANGUL_OUTPUT_SYLLABLE,
    HANGUL_OUTPUT_JAMO
};

enum {
    HANGUL_KEYBOARD_TYPE_JAMO,
    HANGUL_KEYBOARD_TYPE_JASO,
    HANGUL_KEYBOARD_TYPE_ROMAJA
};

/* keyboard */
HangulKeyboard* hangul_keyboard_new(void);
void    hangul_keyboard_delete(HangulKeyboard *keyboard);
void    hangul_keyboard_set_value(HangulKeyboard *keyboard,
				  int key, ucschar value);
void    hangul_keyboard_set_type(HangulKeyboard *keyboard, int type);

/* combination */
HangulCombination* hangul_combination_new(void);
void hangul_combination_delete(HangulCombination *combination);
bool hangul_combination_set_data(HangulCombination* combination, 
		     ucschar* first, ucschar* second, ucschar* result, unsigned int n);

/* input context */
HangulInputContext* hangul_ic_new(const char* keyboard);
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);
bool hangul_ic_is_transliteration(HangulInputContext *hic);

void hangul_ic_set_output_mode(HangulInputContext *hic, int mode);
void hangul_ic_set_keyboard(HangulInputContext *hic,
			    const HangulKeyboard *keyboard);
void hangul_ic_select_keyboard(HangulInputContext *hic,
			       const char* id);
void hangul_ic_set_combination(HangulInputContext *hic,
			       const HangulCombination *combination);
void hangul_ic_connect_callback(HangulInputContext* hic, const char* event,
				void* callback, void* user_data);

unsigned    hangul_ic_get_n_keyboards();
const char* hangul_ic_get_keyboard_id(unsigned index_);
const char* hangul_ic_get_keyboard_name(unsigned index_);

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 */
typedef struct _Hanja Hanja;
typedef struct _HanjaList HanjaList;
typedef struct _HanjaTable HanjaTable;

HanjaTable*  hanja_table_load(const char *filename);
HanjaList*   hanja_table_match_exact(const HanjaTable* table, const char *key);
HanjaList*   hanja_table_match_prefix(const HanjaTable* table, const char *key);
HanjaList*   hanja_table_match_suffix(const HanjaTable* table, const char *key);
void         hanja_table_delete(HanjaTable *table);

int          hanja_list_get_size(const HanjaList *list);
const char*  hanja_list_get_key(const HanjaList *list);
const Hanja* hanja_list_get_nth(const HanjaList *list, unsigned int n);
const char*  hanja_list_get_nth_key(const HanjaList *list, unsigned int n);
const char*  hanja_list_get_nth_value(const HanjaList *list, unsigned int n);
const char*  hanja_list_get_nth_comment(const HanjaList *list, unsigned int n);
void         hanja_list_delete(HanjaList *list);

const char*  hanja_get_key(const Hanja* hanja);
const char*  hanja_get_value(const Hanja* hanja);
const char*  hanja_get_comment(const Hanja* hanja);

#ifdef __cplusplus
}
#endif

#undef LIBHANGUL_DEPRECATED

#endif /* libhangul_hangul_h */