2 * Copyright (C) 2009 by Aiwota Programmer
3 * aiwotaprog@tetteke.tk
5 * This file is part of Dialektos.
7 * Dialektos 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 3 of the License, or
10 * (at your option) any later version.
12 * Dialektos 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.
17 * You should have received a copy of the GNU General Public License
18 * along with Dialektos. If not, see <http://www.gnu.org/licenses/>.
21 #ifndef CP932_TABLE_HXX
22 #define CP932_TABLE_HXX
31 unsigned short to_bmp(unsigned char ch) {
32 if (ch >= 0xa1 && ch <= 0xdf)
33 return codemap_a1[index_a1(ch)];
36 unsigned short to_bmp(unsigned char ch1, unsigned char ch2) {
37 if (ch1 >= 0x81 && ch1 <= 0x9f) {
38 const int index = index_81(ch1, ch2);
39 return index == -1 ? 0 : codemap_81[index];
40 } else if (ch1 >= 0xe0 && ch1 <= 0xea) {
41 const int index = index_e0(ch1, ch2);
42 return index == -1 ? 0 : codemap_e0[index];
43 } else if (ch1 >= 0xed && ch1 <= 0xee) {
44 const int index = index_ed(ch1, ch2);
45 return index == -1 ? 0 : codemap_ed[index];
50 int index_81(unsigned char ku, unsigned char ten) {
51 if (ku >= 0x81 && ku <= 0x9f && ten >= 0x40 && ten <= 0xfc) {
52 // from 1 ku to 62 ku.
53 return (ku-0x81)*(0xfc-0x40+1) + (ten-0x40);
58 int index_e0(unsigned char ku, unsigned char ten) {
59 if (ku >= 0xe0 && ku <= 0xea && ten >= 0x40 && ten <= 0xfc) {
60 // from 63 ku to 84 ku.
61 return (ku-0xe0)*(0xfc-0x40+1) + (ten-0x40);
66 int index_ed(unsigned char ku, unsigned char ten) {
67 if (ku >= 0xed && ku <= 0xee && ten >= 0x40 && ten <= 0xfc) {
68 // from 63 ku to 84 ku.
69 return (ku-0xed)*(0xfc-0x40+1) + (ten-0x40);
74 int index_a1(unsigned char ch) {
75 if (ch >= 0xa1 && ch <= 0xdf) {
81 static const unsigned short codemap_81[(0xa0-0x81)*(0xfd-0x40)];
82 static const unsigned short codemap_e0[(0xeb-0xe0)*(0xfd-0x40)];
83 static const unsigned short codemap_ed[(0xef-0xed)*(0xfd-0x40)];
84 static const unsigned short codemap_a1[0xe0-0xa1];
88 } // namespace convert
90 } // namespace dialektos