clean db
[platform/upstream/ibus-libpinyin.git] / src / PYHalfFullConverter.cc
1 /* vim:set et ts=4 sts=4:
2  *
3  * ibus-pinyin - The Chinese PinYin engine for IBus
4  *
5  * Copyright (c) 2008-2010 Peng Huang <shawn.p.huang@gmail.com>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  */
21
22 #include "PYHalfFullConverter.h"
23
24 namespace PY {
25
26 const guint
27 HalfFullConverter::m_table[][3] = {
28     { 0x0020, 0x3000, 1 },
29     { 0x0021, 0xFF01, 94 },
30     { 0x00A2, 0xFFE0, 2 },
31     { 0x00A5, 0xFFE5, 1 },
32     { 0x00A6, 0xFFE4, 1 },
33     { 0x00AC, 0xFFE2, 1 },
34     { 0x00AF, 0xFFE3, 1 },
35     { 0x20A9, 0xFFE6, 1 },
36     { 0xFF61, 0x3002, 1 },
37     { 0xFF62, 0x300C, 2 },
38     { 0xFF64, 0x3001, 1 },
39     { 0xFF65, 0x30FB, 1 },
40     { 0xFF66, 0x30F2, 1 },
41     { 0xFF67, 0x30A1, 1 },
42     { 0xFF68, 0x30A3, 1 },
43     { 0xFF69, 0x30A5, 1 },
44     { 0xFF6A, 0x30A7, 1 },
45     { 0xFF6B, 0x30A9, 1 },
46     { 0xFF6C, 0x30E3, 1 },
47     { 0xFF6D, 0x30E5, 1 },
48     { 0xFF6E, 0x30E7, 1 },
49     { 0xFF6F, 0x30C3, 1 },
50     { 0xFF70, 0x30FC, 1 },
51     { 0xFF71, 0x30A2, 1 },
52     { 0xFF72, 0x30A4, 1 },
53     { 0xFF73, 0x30A6, 1 },
54     { 0xFF74, 0x30A8, 1 },
55     { 0xFF75, 0x30AA, 2 },
56     { 0xFF77, 0x30AD, 1 },
57     { 0xFF78, 0x30AF, 1 },
58     { 0xFF79, 0x30B1, 1 },
59     { 0xFF7A, 0x30B3, 1 },
60     { 0xFF7B, 0x30B5, 1 },
61     { 0xFF7C, 0x30B7, 1 },
62     { 0xFF7D, 0x30B9, 1 },
63     { 0xFF7E, 0x30BB, 1 },
64     { 0xFF7F, 0x30BD, 1 },
65     { 0xFF80, 0x30BF, 1 },
66     { 0xFF81, 0x30C1, 1 },
67     { 0xFF82, 0x30C4, 1 },
68     { 0xFF83, 0x30C6, 1 },
69     { 0xFF84, 0x30C8, 1 },
70     { 0xFF85, 0x30CA, 6 },
71     { 0xFF8B, 0x30D2, 1 },
72     { 0xFF8C, 0x30D5, 1 },
73     { 0xFF8D, 0x30D8, 1 },
74     { 0xFF8E, 0x30DB, 1 },
75     { 0xFF8F, 0x30DE, 5 },
76     { 0xFF94, 0x30E4, 1 },
77     { 0xFF95, 0x30E6, 1 },
78     { 0xFF96, 0x30E8, 6 },
79     { 0xFF9C, 0x30EF, 1 },
80     { 0xFF9D, 0x30F3, 1 },
81     { 0xFFA0, 0x3164, 1 },
82     { 0xFFA1, 0x3131, 30 },
83     { 0xFFC2, 0x314F, 6 },
84     { 0xFFCA, 0x3155, 6 },
85     { 0xFFD2, 0x315B, 9 },
86     { 0xFFE9, 0x2190, 4 },
87     { 0xFFED, 0x25A0, 1 },
88     { 0xFFEE, 0x25CB, 1 },
89 };
90
91 gunichar
92 HalfFullConverter::toFull (gunichar ch)
93 {
94     for (guint i = 0; i < G_N_ELEMENTS (m_table); i++) {
95         if (G_UNLIKELY (ch < m_table[i][0]))
96             return ch;
97         if (G_UNLIKELY (ch < m_table[i][0] + m_table[i][2]))
98             return ch - m_table[i][0] + m_table[i][1];
99     }
100     return ch;
101 }
102
103 gunichar
104 HalfFullConverter::toHalf (gunichar ch)
105 {
106     for (guint i = 0; i < G_N_ELEMENTS (m_table); i++) {
107         if (G_LIKELY (ch < m_table[i][1]))
108             continue;
109         if (G_LIKELY (ch >= m_table[i][1] + m_table[i][2]))
110             continue;
111         return ch - m_table[i][1] + m_table[i][0];
112     }
113     return ch;
114 }
115
116 };
117