1*91e1e26aSAlexander Pyhalov /*
2*91e1e26aSAlexander Pyhalov * CDDL HEADER START
3*91e1e26aSAlexander Pyhalov *
4*91e1e26aSAlexander Pyhalov * The contents of this file are subject to the terms of the
5*91e1e26aSAlexander Pyhalov * Common Development and Distribution License (the "License").
6*91e1e26aSAlexander Pyhalov * You may not use this file except in compliance with the License.
7*91e1e26aSAlexander Pyhalov *
8*91e1e26aSAlexander Pyhalov * You can obtain a copy of the license at src/OPENSOLARIS.LICENSE
9*91e1e26aSAlexander Pyhalov * or http://www.opensolaris.org/os/licensing.
10*91e1e26aSAlexander Pyhalov * See the License for the specific language governing permissions
11*91e1e26aSAlexander Pyhalov * and limitations under the License.
12*91e1e26aSAlexander Pyhalov *
13*91e1e26aSAlexander Pyhalov * When distributing Covered Code, include this CDDL HEADER in each
14*91e1e26aSAlexander Pyhalov * file and include the License file at src/OPENSOLARIS.LICENSE.
15*91e1e26aSAlexander Pyhalov * If applicable, add the following below this CDDL HEADER, with the
16*91e1e26aSAlexander Pyhalov * fields enclosed by brackets "[]" replaced with your own identifying
17*91e1e26aSAlexander Pyhalov * information: Portions Copyright [yyyy] [name of copyright owner]
18*91e1e26aSAlexander Pyhalov *
19*91e1e26aSAlexander Pyhalov * CDDL HEADER END
20*91e1e26aSAlexander Pyhalov */
21*91e1e26aSAlexander Pyhalov /*
22*91e1e26aSAlexander Pyhalov * COPYRIGHT AND PERMISSION NOTICE
23*91e1e26aSAlexander Pyhalov *
24*91e1e26aSAlexander Pyhalov * Copyright (c) 1991-2005 Unicode, Inc. All rights reserved. Distributed
25*91e1e26aSAlexander Pyhalov * under the Terms of Use in http://www.unicode.org/copyright.html.
26*91e1e26aSAlexander Pyhalov *
27*91e1e26aSAlexander Pyhalov * This file has been modified by Sun Microsystems, Inc.
28*91e1e26aSAlexander Pyhalov *
29*91e1e26aSAlexander Pyhalov */
30*91e1e26aSAlexander Pyhalov /*
31*91e1e26aSAlexander Pyhalov * Copyright(c) 2008 Sun Microsystems, Inc.
32*91e1e26aSAlexander Pyhalov * All rights reserved.
33*91e1e26aSAlexander Pyhalov */
34*91e1e26aSAlexander Pyhalov
35*91e1e26aSAlexander Pyhalov #ifndef _UNICODE_TCVN_H_
36*91e1e26aSAlexander Pyhalov #define _UNICODE_TCVN_H_
37*91e1e26aSAlexander Pyhalov
38*91e1e26aSAlexander Pyhalov
39*91e1e26aSAlexander Pyhalov static const unsigned long tcvn2uni_1[32] = {
40*91e1e26aSAlexander Pyhalov /*
41*91e1e26aSAlexander Pyhalov * 0x00 - Ox17
42*91e1e26aSAlexander Pyhalov */
43*91e1e26aSAlexander Pyhalov 0x0000, 0x00DA, 0x1EE4, 0x0003, 0x1EEA, 0x1EEC, 0x1EEE, 0x0007,
44*91e1e26aSAlexander Pyhalov 0x0008, 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x000E, 0x000F,
45*91e1e26aSAlexander Pyhalov 0x0010, 0x1EE8, 0x1EF0, 0x1EF2, 0x1EF6, 0x1EF8, 0x00DD, 0x1EF4,
46*91e1e26aSAlexander Pyhalov };
47*91e1e26aSAlexander Pyhalov
48*91e1e26aSAlexander Pyhalov
49*91e1e26aSAlexander Pyhalov static const unsigned long tcvn2uni_2[128] = {
50*91e1e26aSAlexander Pyhalov /*
51*91e1e26aSAlexander Pyhalov * 0x80 - Oxff
52*91e1e26aSAlexander Pyhalov */
53*91e1e26aSAlexander Pyhalov 0x00C0, 0x1EA2, 0x00C3, 0x00C1, 0x1EA0, 0x1EB6, 0x1EAC, 0x00C8,
54*91e1e26aSAlexander Pyhalov 0x1EBA, 0x1EBC, 0x00C9, 0x1EB8, 0x1EC6, 0x00CC, 0x1EC8, 0x0128,
55*91e1e26aSAlexander Pyhalov 0x00CD, 0x1ECA, 0x00D2, 0x1ECE, 0x00D5, 0x00D3, 0x1ECC, 0x1ED8,
56*91e1e26aSAlexander Pyhalov 0x1EDC, 0x1EDE, 0x1EE0, 0x1EDA, 0x1EE2, 0x00D9, 0x1EE6, 0x0168,
57*91e1e26aSAlexander Pyhalov 0x00A0, 0x0102, 0x00C2, 0x00CA, 0x00D4, 0x01A0, 0x01AF, 0x0110,
58*91e1e26aSAlexander Pyhalov 0x0103, 0x00E2, 0x00EA, 0x00F4, 0x01A1, 0x01B0, 0x0111, 0x1EB0,
59*91e1e26aSAlexander Pyhalov 0x0300, 0x0309, 0x0303, 0x0301, 0x0323, 0x00E0, 0x1EA3, 0x00E3,
60*91e1e26aSAlexander Pyhalov 0x00E1, 0x1EA1, 0x1EB2, 0x1EB1, 0x1EB3, 0x1EB5, 0x1EAF, 0x1EB4,
61*91e1e26aSAlexander Pyhalov 0x1EAE, 0x1EA6, 0x1EA8, 0x1EAA, 0x1EA4, 0x1EC0, 0x1EB7, 0x1EA7,
62*91e1e26aSAlexander Pyhalov 0x1EA9, 0x1EAB, 0x1EA5, 0x1EAD, 0x00E8, 0x1EC2, 0x1EBB, 0x1EBD,
63*91e1e26aSAlexander Pyhalov 0x00E9, 0x1EB9, 0x1EC1, 0x1EC3, 0x1EC5, 0x1EBF, 0x1EC7, 0x00EC,
64*91e1e26aSAlexander Pyhalov 0x1EC9, 0x1EC4, 0x1EBE, 0x1ED2, 0x0129, 0x00ED, 0x1ECB, 0x00F2,
65*91e1e26aSAlexander Pyhalov 0x1ED4, 0x1ECF, 0x00F5, 0x00F3, 0x1ECD, 0x1ED3, 0x1ED5, 0x1ED7,
66*91e1e26aSAlexander Pyhalov 0x1ED1, 0x1ED9, 0x1EDD, 0x1EDF, 0x1EE1, 0x1EDB, 0x1EE3, 0x00F9,
67*91e1e26aSAlexander Pyhalov 0x1ED6, 0x1EE7, 0x0169, 0x00FA, 0x1EE5, 0x1EEB, 0x1EED, 0x1EEF,
68*91e1e26aSAlexander Pyhalov 0x1EE9, 0x1EF1, 0x1EF3, 0x1EF7, 0x1EF9, 0x00FD, 0x1EF5, 0x1ED0,
69*91e1e26aSAlexander Pyhalov };
70*91e1e26aSAlexander Pyhalov
71*91e1e26aSAlexander Pyhalov #ifdef __NEED_TCVN_2_UNI__
tcvn_2_uni(const unsigned char * in,unsigned long * out)72*91e1e26aSAlexander Pyhalov static int tcvn_2_uni(const unsigned char *in, unsigned long *out )
73*91e1e26aSAlexander Pyhalov {
74*91e1e26aSAlexander Pyhalov unsigned char c = *in;
75*91e1e26aSAlexander Pyhalov
76*91e1e26aSAlexander Pyhalov if (c < 0x18)
77*91e1e26aSAlexander Pyhalov *out = tcvn2uni_1[c];
78*91e1e26aSAlexander Pyhalov else if (c < 0x80)
79*91e1e26aSAlexander Pyhalov *out = c;
80*91e1e26aSAlexander Pyhalov else
81*91e1e26aSAlexander Pyhalov *out = tcvn2uni_2[c-0x80];
82*91e1e26aSAlexander Pyhalov
83*91e1e26aSAlexander Pyhalov return 1;
84*91e1e26aSAlexander Pyhalov }
85*91e1e26aSAlexander Pyhalov #endif /* __NEED_TCVN_2_UNI__ */
86*91e1e26aSAlexander Pyhalov
87*91e1e26aSAlexander Pyhalov static const unsigned char uni2tcvn_1[280] = {
88*91e1e26aSAlexander Pyhalov 0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
89*91e1e26aSAlexander Pyhalov 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
90*91e1e26aSAlexander Pyhalov 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
91*91e1e26aSAlexander Pyhalov 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
92*91e1e26aSAlexander Pyhalov 0x80, 0x83, 0xa2, 0x82, 0x00, 0x00, 0x00, 0x00,
93*91e1e26aSAlexander Pyhalov 0x87, 0x8a, 0xa3, 0x00, 0x8d, 0x90, 0x00, 0x00,
94*91e1e26aSAlexander Pyhalov 0x00, 0x00, 0x92, 0x95, 0xa4, 0x94, 0x00, 0x00,
95*91e1e26aSAlexander Pyhalov 0x00, 0x9d, 0x01, 0x00, 0x00, 0x16, 0x00, 0x00,
96*91e1e26aSAlexander Pyhalov 0xb5, 0xb8, 0xa9, 0xb7, 0x00, 0x00, 0x00, 0x00,
97*91e1e26aSAlexander Pyhalov 0xcc, 0xd0, 0xaa, 0x00, 0xd7, 0xdd, 0x00, 0x00,
98*91e1e26aSAlexander Pyhalov 0x00, 0x00, 0xdf, 0xe3, 0xab, 0xe2, 0x00, 0x00,
99*91e1e26aSAlexander Pyhalov 0x00, 0xef, 0xf3, 0x00, 0x00, 0xfd, 0x00, 0x00,
100*91e1e26aSAlexander Pyhalov 0x00, 0x00, 0xa1, 0xa8, 0x00, 0x00, 0x00, 0x00,
101*91e1e26aSAlexander Pyhalov 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
102*91e1e26aSAlexander Pyhalov 0xa7, 0xae, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
103*91e1e26aSAlexander Pyhalov 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
104*91e1e26aSAlexander Pyhalov 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
105*91e1e26aSAlexander Pyhalov 0x8f, 0xdc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
106*91e1e26aSAlexander Pyhalov 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
107*91e1e26aSAlexander Pyhalov 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
108*91e1e26aSAlexander Pyhalov 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
109*91e1e26aSAlexander Pyhalov 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
110*91e1e26aSAlexander Pyhalov 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
111*91e1e26aSAlexander Pyhalov 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
112*91e1e26aSAlexander Pyhalov 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
113*91e1e26aSAlexander Pyhalov 0x9f, 0xf2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
114*91e1e26aSAlexander Pyhalov 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
115*91e1e26aSAlexander Pyhalov 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
116*91e1e26aSAlexander Pyhalov 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
117*91e1e26aSAlexander Pyhalov 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
118*91e1e26aSAlexander Pyhalov 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
119*91e1e26aSAlexander Pyhalov 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
120*91e1e26aSAlexander Pyhalov 0xa5, 0xac, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
121*91e1e26aSAlexander Pyhalov 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa6,
122*91e1e26aSAlexander Pyhalov 0xad, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
123*91e1e26aSAlexander Pyhalov };
124*91e1e26aSAlexander Pyhalov
125*91e1e26aSAlexander Pyhalov static const unsigned char uni2tcvn_2[40] = {
126*91e1e26aSAlexander Pyhalov 0xb0, 0xb3, 0x00, 0xb2, 0x00, 0x00, 0x00, 0x00,
127*91e1e26aSAlexander Pyhalov 0x00, 0xb1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
128*91e1e26aSAlexander Pyhalov 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
129*91e1e26aSAlexander Pyhalov 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
130*91e1e26aSAlexander Pyhalov 0x00, 0x00, 0x00, 0xb4, 0x00, 0x00, 0x00, 0x00,
131*91e1e26aSAlexander Pyhalov };
132*91e1e26aSAlexander Pyhalov static const unsigned char uni2tcvn_3[96] = {
133*91e1e26aSAlexander Pyhalov 0x84, 0xb9, 0x81, 0xb6, 0xc4, 0xca, 0xc1, 0xc7,
134*91e1e26aSAlexander Pyhalov 0xc2, 0xc8, 0xc3, 0xc9, 0x86, 0xcb, 0xc0, 0xbe,
135*91e1e26aSAlexander Pyhalov 0xaf, 0xbb, 0xba, 0xbc, 0xbf, 0xbd, 0x85, 0xc6,
136*91e1e26aSAlexander Pyhalov 0x8b, 0xd1, 0x88, 0xce, 0x89, 0xcf, 0xda, 0xd5,
137*91e1e26aSAlexander Pyhalov 0xc5, 0xd2, 0xcd, 0xd3, 0xd9, 0xd4, 0x8c, 0xd6,
138*91e1e26aSAlexander Pyhalov 0x8e, 0xd8, 0x91, 0xde, 0x96, 0xe4, 0x93, 0xe1,
139*91e1e26aSAlexander Pyhalov 0xff, 0xe8, 0xdb, 0xe5, 0xe0, 0xe6, 0xf0, 0xe7,
140*91e1e26aSAlexander Pyhalov 0x97, 0xe9, 0x9b, 0xed, 0x98, 0xea, 0x99, 0xeb,
141*91e1e26aSAlexander Pyhalov 0x9a, 0xec, 0x9c, 0xee, 0x02, 0xf4, 0x9e, 0xf1,
142*91e1e26aSAlexander Pyhalov 0x11, 0xf8, 0x04, 0xf5, 0x05, 0xf6, 0x06, 0xf7,
143*91e1e26aSAlexander Pyhalov 0x12, 0xf9, 0x13, 0xfa, 0x17, 0xfe, 0x14, 0xfb,
144*91e1e26aSAlexander Pyhalov 0x15, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
145*91e1e26aSAlexander Pyhalov };
146*91e1e26aSAlexander Pyhalov
147*91e1e26aSAlexander Pyhalov #ifdef __NEED_UNI_2_TCVN__
uni_2_tcvn(unsigned long in,unsigned char * out)148*91e1e26aSAlexander Pyhalov static int uni_2_tcvn (unsigned long in, unsigned char *out)
149*91e1e26aSAlexander Pyhalov {
150*91e1e26aSAlexander Pyhalov unsigned char c = 0;
151*91e1e26aSAlexander Pyhalov
152*91e1e26aSAlexander Pyhalov if (in < 0x0080 && (in >= 0x0020 || (0xFF01FF89 & (1 << in)) )) {
153*91e1e26aSAlexander Pyhalov /* Bit mask, bit 1 means there have valid unicode value.
154*91e1e26aSAlexander Pyhalov * 0xFF01FF89 = 1111 1111 0000 0001 1111 1111 1000 1001
155*91e1e26aSAlexander Pyhalov */
156*91e1e26aSAlexander Pyhalov *out = in;
157*91e1e26aSAlexander Pyhalov return 1;
158*91e1e26aSAlexander Pyhalov } else if (in >= 0x00a0 && in < 0x01b8)
159*91e1e26aSAlexander Pyhalov c = uni2tcvn_1[in-0x00a0];
160*91e1e26aSAlexander Pyhalov else if (in >= 0x0300 && in < 0x0328)
161*91e1e26aSAlexander Pyhalov c = uni2tcvn_2[in-0x0300];
162*91e1e26aSAlexander Pyhalov else if (in >= 0x1ea0 && in < 0x1f00)
163*91e1e26aSAlexander Pyhalov c = uni2tcvn_3[in-0x1ea0];
164*91e1e26aSAlexander Pyhalov
165*91e1e26aSAlexander Pyhalov if (c != 0) {
166*91e1e26aSAlexander Pyhalov *out = c;
167*91e1e26aSAlexander Pyhalov return 1;
168*91e1e26aSAlexander Pyhalov }
169*91e1e26aSAlexander Pyhalov
170*91e1e26aSAlexander Pyhalov return 0;
171*91e1e26aSAlexander Pyhalov }
172*91e1e26aSAlexander Pyhalov #endif /* __NEED_UNI_2_TCVN__ */
173*91e1e26aSAlexander Pyhalov
174*91e1e26aSAlexander Pyhalov #endif
175