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
//! # okpyeon (옥편)
//!
//! Korean IME candidate data as static tables, for the two conversions every
//! Korean input method needs when the 한자(hanja) key is pressed:
//!
//! - **Hanja lookup** ([`hanja`]): a hangul syllable reading (독음) to its
//! hanja candidates, each with a hun-eum gloss (훈음, e.g. `"배울 학"`).
//! Like flipping through a paper 옥편.
//! - **Special symbols** ([`symbols`], [`symbols_revised`]): the MS-IME-style
//! consonant tables (press `ㅁ` then the 한자 key to pick `※ ☆ ★ …`).
//!
//! Word-level (multi-syllable) conversion is deliberately out of scope; every
//! lookup key is a single `char`.
//!
//! ```
//! let candidates = okpyeon::hanja('학').unwrap();
//! assert_eq!(candidates[0], ('學', "배울 학"));
//!
//! let shapes = okpyeon::symbols('ㅁ').unwrap();
//! assert!(shapes.contains(&'※'));
//! ```
//!
//! ## Data
//!
//! The tables are compiled in from two [libhangul] data files (vendored in
//! `data/`, BSD-3-Clause, see the crate README for provenance):
//!
//! - `hanja.txt`, filtered to entries whose key and value are each a single
//! character (multi-syllable word entries, plus two anomalous entries with
//! multi-character values, are removed). Candidate order preserves the file
//! order, which libhangul curates common-first (`학` starts with
//! `學 鶴 虐 …`), so it is directly usable as an IME candidate list.
//! Glosses may be empty for rare hanja.
//! - `mssymbol.txt`, the consonant-to-symbol tables replicating the Windows
//! MS IME behavior. 18 keys exist (`ㄱ`-`ㅎ` plus `ㄲ ㄸ ㅃ ㅆ`; `ㅉ` has no
//! assignment, faithful to MS IME). Keys are compatibility jamo (U+3131..).
//!
//! No allocation, no `std`, no dependencies; lookups are binary searches over
//! sorted static slices.
//!
//! [libhangul]: https://github.com/libhangul/libhangul
include!;
/// Looks up hanja candidates for a hangul syllable reading (독음).
///
/// Returns `(hanja, hun-eum gloss)` pairs in libhangul's curated
/// common-first order. The gloss is empty for many rare hanja. Returns
/// `None` when the reading has no entry.
///
/// ```
/// assert_eq!(okpyeon::hanja('국').unwrap()[0], ('國', "나라 국"));
/// assert_eq!(okpyeon::hanja('A'), None);
/// ```
/// Looks up the MS-IME-style special symbol candidates for a consonant.
///
/// This is the table behind the Windows habit of composing a lone consonant
/// and pressing the 한자 key: `ㄱ` punctuation, `ㄴ` brackets, `ㄷ` math,
/// `ㄹ` units, `ㅁ` general symbols (`※ ☆ ★ …`), `ㅂ` box drawing, and so
/// on. The key must be a compatibility jamo (U+3131..); 18 keys are defined
/// (`ㅉ` intentionally absent, as in MS IME).
///
/// Faithful to libhangul's `mssymbol.txt`, including its two known quirks
/// inherited from old MS IME: `ㄹ`'s 4th slot is a fullwidth `F` (a
/// duplicate of the one in the `ㅍ` fullwidth-latin table) where `°` is
/// expected, and `㉾` is missing. See [`symbols_revised`] for the corrected
/// table.
///
/// ```
/// assert!(okpyeon::symbols('ㅁ').unwrap().contains(&'★'));
/// assert_eq!(okpyeon::symbols('ㅉ'), None);
/// ```
/// Like [`symbols`], with the two known `mssymbol.txt` quirks corrected.
///
/// - `ㄹ`'s 4th candidate is `°` (degree sign) instead of a fullwidth `F`
/// duplicated from the `ㅍ` table, matching the 날개셋 input method.
/// - `ㅁ` gains `㉾` as its last candidate, matching current Windows MS IME.
///
/// Everything else is identical to [`symbols`].
///
/// ```
/// assert_eq!(okpyeon::symbols_revised('ㄹ').unwrap()[3], '°');
/// assert_eq!(okpyeon::symbols_revised('ㅁ').unwrap().last(), Some(&'㉾'));
/// ```