2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4 * Copyright (c) 2007 Sun Microsystems, Inc. All Rights Reserved.
6 * The contents of this file are subject to the terms of either the GNU Lesser
7 * General Public License Version 2.1 only ("LGPL") or the Common Development and
8 * Distribution License ("CDDL")(collectively, the "License"). You may not use this
9 * file except in compliance with the License. You can obtain a copy of the CDDL at
10 * http://www.opensource.org/licenses/cddl1.php and a copy of the LGPLv2.1 at
11 * http://www.opensource.org/licenses/lgpl-license.php. See the License for the
12 * specific language governing permissions and limitations under the License. When
13 * distributing the software, include this License Header Notice in each file and
14 * include the full text of the License in the License file as well as the
17 * NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND DISTRIBUTION LICENSE
19 * For Covered Software in this distribution, this License shall be governed by the
20 * laws of the State of California (excluding conflict-of-law provisions).
21 * Any litigation relating to this License shall be subject to the jurisdiction of
22 * the Federal Courts of the Northern District of California and the state courts
23 * of the State of California, with venue lying in Santa Clara County, California.
27 * If you wish your version of this file to be governed by only the CDDL or only
28 * the LGPL Version 2.1, indicate your decision by adding "[Contributor]" elects to
29 * include this software in this distribution under the [CDDL or LGPL Version 2.1]
30 * license." If you don't indicate a single choice of license, a recipient has the
31 * option to distribute your version of this file under either the CDDL or the LGPL
32 * Version 2.1, or to extend the choice of license to its licensees as provided
33 * above. However, if you add LGPL Version 2.1 code and therefore, elected the LGPL
34 * Version 2 license, then the option applies only if the new code is made subject
35 * to such option by the copyright holder.
45 #include "pinyin_data.h"
46 #include "shuangpin_data.h"
48 #define INITIAL_NUM 26
50 #define ZEROINITIAL_NUM 12
52 static const char *initials[INITIAL_NUM] =
53 { "", "", "", "b", "p", "m", "f", "d", "t", "n", "l",
54 "g", "k", "h", "j", "q", "x", "zh",
55 "ch", "sh", "r", "z", "c", "s", "y", "w", };
57 static const char *finals[FINAL_NUM] = { "", "a", "o", "e", "ai", "ei", "ao",
58 "ou", "an", "en", "ang", "eng", "er",
59 "i", "ia", "ie", "iao", "iu", "ian",
60 "in", "iang", "ing", "u",
61 "ua", "uo", "uai", "ui", "uan", "un",
62 "uang", "ong", "v", "ue", "iong", };
65 //MS2003 shuangpin plan map table
66 static const char ms2003_mapinitials[INITIAL_NUM] =
67 { '\0', '\0', 'o', 'b', 'p', 'm', 'f', 'd',
68 't', 'n', 'l', 'g', 'k',
69 'h', 'j', 'q', 'x', 'v', 'i', 'u', 'r', 'z', 'c', 's',
72 static const char ms2003_mapfinals[FINAL_NUM] =
73 { '\0', 'a', 'o', 'e', 'l', 'z', 'k',
74 'b', 'j', 'f', 'h', 'g', 'r',
75 'i', 'w', 'x', 'c', 'q', 'm', 'n', 'd', ';', 'u',
76 'w', 'o', 'y', 'v', 'r', 'p',
77 'd', 's', 'v', 't', 's', };
79 static TZeroInitial ms2003_zeroinitials[] = {
95 //ZhiNengABC shuangpin plan map table
96 static const char abc_mapinitials[INITIAL_NUM] =
97 { '\0', '\0', 'o', 'b', 'p', 'm', 'f', 'd',
98 't', 'n', 'l', 'g', 'k', 'h',
99 'j', 'q', 'x', 'a', 'e', 'v', 'r', 'z', 'c', 's',
102 static const char abc_mapfinals[FINAL_NUM] =
103 { '\0', 'a', 'o', 'e', 'l', 'q', 'k',
104 'b', 'j', 'f', 'h', 'g', 'r',
105 'i', 'd', 'x', 'z', 'r', 'w', 'c', 't', 'y', 'u',
106 'd', 'o', 'c', 'm', 'p', 'n',
107 't', 's', 'v', 'm', 's', };
109 static TZeroInitial abc_zeroinitials[] = {
124 //ZiGuang shuangpin plan map table
125 static const char ziguang_mapinitials[INITIAL_NUM] =
126 { '\0', '\0', 'o', 'b', 'p', 'm', 'f', 'd',
127 't', 'n', 'l', 'g', 'k',
128 'h', 'j', 'q', 'x', 'u', 'a', 'i', 'r', 'z', 'c', 's',
131 static const char ziguang_mapfinals[FINAL_NUM] =
132 { '\0', 'a', 'o', 'e', 'p', 'k', 'q',
133 'z', 'r', 'w', 's', 't', 'j',
134 'i', 'x', 'd', 'b', 'j', 'f', 'y', 'g', ';', 'u',
135 'x', 'o', 'y', 'n', 'l', 'm',
136 'g', 'h', 'v', 'n', 'h', };
138 static TZeroInitial ziguang_zeroinitials[] = {
153 //PinYinJiaJia shuangpin plan map table
154 static const char pyjiajia_mapinitials[INITIAL_NUM] =
155 { '\0', '\0', 'o', 'b', 'p', 'm', 'f', 'd',
156 't', 'n', 'l', 'g', 'k',
157 'h', 'j', 'q', 'x', 'v', 'u', 'i', 'r', 'z', 'c', 's',
160 static const char pyjiajia_mapfinals[FINAL_NUM] =
161 { '\0', 'a', 'o', 'e', 's', 'w', 'd',
162 'p', 'f', 'r', 'g', 't',
163 'q', 'i', 'b', 'm', 'k', 'n', 'j', 'l', 'h', 'q', 'u',
164 'b', 'o', 'x', 'v', 'c',
165 'z', 'h', 'y', 'v', 'x', 'y', };
167 static TZeroInitial pyjiajia_zeroinitials[] = {
182 //Ziranma shuangpin plan map table
183 static const char ziranma_mapinitials[INITIAL_NUM] =
184 { 'a', 'e', 'o', 'b', 'p', 'm', 'f', 'd',
185 't', 'n', 'l', 'g', 'k',
186 'h', 'j', 'q', 'x', 'v', 'i', 'u', 'r', 'z', 'c', 's',
189 static const char ziranma_mapfinals[FINAL_NUM] =
190 { '\0', 'a', 'o', 'e', 'l', 'z', 'k',
191 'b', 'j', 'f', 'h', 'g',
192 '\0', 'i', 'w', 'x', 'c', 'q', 'm', 'n', 'd', 'y', 'u',
193 'w', 'o', 'y', 'v', 'r', 'p',
194 'd', 's', 'v', 't', 's', };
196 static TZeroInitial ziranma_zeroinitials[] = {
211 //Ziranma shuangpin plan map table
212 static const char xiaohe_mapinitials[INITIAL_NUM] =
213 { 'a', 'e', 'o', 'b', 'p', 'm', 'f', 'd',
214 't', 'n', 'l', 'g', 'k',
215 'h', 'j', 'q', 'x', 'v', 'i', 'u', 'r', 'z', 'c', 's',
218 static const char xiaohe_mapfinals[FINAL_NUM] =
219 { '\0', 'a', 'o', 'e', 'd', 'w', 'c',
220 'z', 'j', 'f', 'h', 'g', '\0',
221 'i', 'x', 'p', 'n', 'q', 'm', 'b', 'l', 'k', 'u',
222 'x', 'o', 'k', 'v', 'r', 'y',
223 'l', 's', 'v', 't', 's', };
225 static TZeroInitial xiaohe_zeroinitials[] = {
240 CShuangpinData::CShuangpinData (EShuangpinType shpPlan) : m_shuangpinPlan(NULL)
243 _genKeyboardMap(shpPlan);
246 CShuangpinData::~CShuangpinData()
248 delete m_shuangpinPlan;
252 CShuangpinData::encodeSyllable(const char *pinyin)
254 std::map<std::string, TSyllable>::iterator iter;
255 iter = m_codingmap.find(pinyin);
256 if (iter != m_codingmap.end()) {
263 CShuangpinData::decodeSyllable(TSyllable s, const char **i, const char **f)
269 CShuangpinData::getMapString(const char *shpstr, CMappedYin &syls)
271 assert(shpstr != NULL);
272 assert(m_shuangpinPlan->mapinitials != NULL);
274 const char *ch = shpstr;
275 int len = strlen(shpstr);
281 for (int i = 0; i < INITIAL_NUM; i++) {
282 if (*ch == m_shuangpinPlan->mapinitials[i]) {
283 syls.push_back(std::string(initials[i]));
289 if (m_shuangpinPlan->zeroinitals != NULL) {
290 for (int i = 0; i < ZEROINITIAL_NUM; i++) {
291 if (!strcmp(shpstr, m_shuangpinPlan->zeroinitals[i].mapshp)) {
292 syls.push_back(std::string(m_shuangpinPlan->zeroinitals[i].
299 for (int i = 0; i < INITIAL_NUM; i++) {
300 if (*ch == m_shuangpinPlan->mapinitials[i]) {
301 for (int j = 0; j < FINAL_NUM; j++) {
302 if (*(ch + 1) == m_shuangpinPlan->mapfinals[j]) {
303 sprintf(buf, "%s%s", initials[i], finals[j]);
304 std::map<std::string, TSyllable>::iterator iter;
305 iter = m_codingmap.find(buf);
306 if (iter != m_codingmap.end()) {
307 syls.push_back(std::string(buf));
315 //Invalid shuangpin input character number, return 0;
323 CShuangpinData::setShuangpinType(EShuangpinType shpType)
325 if (shpType == getShuangpinType()) {
328 _genKeyboardMap(shpType);
333 CShuangpinData::_genCodingMap()
336 const TPyTabEntry *pinyin_table = CPinyinData::getPinyinTable(len);
338 for (size_t i = 0; i < len; ++i) {
339 m_codingmap.insert(CEncodingMap::value_type(pinyin_table[i].pystr,
340 pinyin_table[i].id));
345 CShuangpinData::_genKeyboardMap(EShuangpinType shyType)
347 if (m_shuangpinPlan == NULL) {
348 m_shuangpinPlan = new TShuangpinPlan;
349 memset(m_shuangpinPlan, 0, sizeof(TShuangpinPlan));
351 m_shuangpinPlan->type = shyType;
354 m_shuangpinPlan->mapinitials = (char*)ms2003_mapinitials;
355 m_shuangpinPlan->mapfinals = (char*)ms2003_mapfinals;
356 m_shuangpinPlan->zeroinitals = ms2003_zeroinitials;
359 m_shuangpinPlan->mapinitials = (char*)abc_mapinitials;
360 m_shuangpinPlan->mapfinals = (char*)abc_mapfinals;
361 m_shuangpinPlan->zeroinitals = abc_zeroinitials;
364 m_shuangpinPlan->mapinitials = (char*)ziguang_mapinitials;
365 m_shuangpinPlan->mapfinals = (char*)ziguang_mapfinals;
366 m_shuangpinPlan->zeroinitals = ziguang_zeroinitials;
369 m_shuangpinPlan->mapinitials = (char*)pyjiajia_mapinitials;
370 m_shuangpinPlan->mapfinals = (char*)pyjiajia_mapfinals;
371 m_shuangpinPlan->zeroinitals = pyjiajia_zeroinitials;
374 m_shuangpinPlan->mapinitials = (char*)ziranma_mapinitials;
375 m_shuangpinPlan->mapfinals = (char*)ziranma_mapfinals;
376 m_shuangpinPlan->zeroinitals = ziranma_zeroinitials;
379 m_shuangpinPlan->mapinitials = (char*)xiaohe_mapinitials;
380 m_shuangpinPlan->mapfinals = (char*)xiaohe_mapfinals;
381 m_shuangpinPlan->zeroinitals = xiaohe_zeroinitials;