]>
Commit | Line | Data |
---|---|---|
b75a7d8f A |
1 | /* |
2 | ********************************************************************** | |
374ca955 | 3 | * Copyright (C) 2000-2004, International Business Machines |
b75a7d8f A |
4 | * Corporation and others. All Rights Reserved. |
5 | ********************************************************************** | |
6 | * file name: ucnvisci.c | |
7 | * encoding: US-ASCII | |
8 | * tab size: 8 (not used) | |
9 | * indentation:4 | |
10 | * | |
11 | * created on: 2001JUN26 | |
12 | * created by: Ram Viswanadha | |
13 | * | |
14 | * Date Name Description | |
15 | * 24/7/2001 Ram Added support for EXT character handling | |
16 | */ | |
17 | ||
18 | #include "unicode/utypes.h" | |
19 | ||
374ca955 | 20 | #if !UCONFIG_NO_CONVERSION && !UCONFIG_NO_LEGACY_CONVERSION |
b75a7d8f A |
21 | |
22 | #include "cmemory.h" | |
b75a7d8f A |
23 | #include "ucnv_bld.h" |
24 | #include "unicode/ucnv.h" | |
25 | #include "ucnv_cnv.h" | |
26 | #include "unicode/ucnv_cb.h" | |
27 | #include "unicode/uset.h" | |
28 | #include "cstring.h" | |
29 | ||
30 | #define UCNV_OPTIONS_VERSION_MASK 0xf | |
31 | #define NUKTA 0x093c | |
32 | #define HALANT 0x094d | |
33 | #define ZWNJ 0x200c /* Zero Width Non Joiner */ | |
34 | #define ZWJ 0x200d /* Zero width Joiner */ | |
35 | #define INVALID_CHAR 0xffff | |
36 | #define ATR 0xEF /* Attribute code */ | |
37 | #define EXT 0xF0 /* Extension code */ | |
38 | #define DANDA 0x0964 | |
39 | #define DOUBLE_DANDA 0x0965 | |
40 | #define ISCII_NUKTA 0xE9 | |
41 | #define ISCII_HALANT 0xE8 | |
42 | #define ISCII_DANDA 0xEA | |
43 | #define ISCII_INV 0xD9 | |
44 | #define INDIC_BLOCK_BEGIN 0x0900 | |
45 | #define INDIC_BLOCK_END 0x0D7F | |
46 | #define INDIC_RANGE (INDIC_BLOCK_END - INDIC_BLOCK_BEGIN) | |
47 | #define VOCALLIC_RR 0x0931 | |
48 | #define LF 0x0A | |
49 | #define ASCII_END 0xA0 | |
50 | #define NO_CHAR_MARKER 0xFFFE | |
51 | #define TELUGU_DELTA DELTA * TELUGU | |
52 | #define DEV_ABBR_SIGN 0x0970 | |
53 | #define DEV_ANUDATTA 0x0952 | |
54 | #define EXT_RANGE_BEGIN 0xA1 | |
55 | #define EXT_RANGE_END 0xEE | |
56 | ||
57 | ||
58 | typedef enum { | |
59 | DEVANAGARI =0, | |
60 | BENGALI, | |
61 | GURMUKHI, | |
62 | GUJARATI, | |
63 | ORIYA, | |
64 | TAMIL, | |
65 | TELUGU, | |
66 | KANNADA, | |
67 | MALAYALAM, | |
68 | DELTA=0x80 | |
69 | }UniLang; | |
70 | ||
71 | ||
72 | /** | |
73 | * Enumeration for switching code pages if <ATX>+<one of below values> | |
74 | * is encountered | |
75 | */ | |
76 | typedef enum { | |
77 | DEF =0x40, | |
78 | RMN =0x41, | |
79 | DEV =0x42, | |
80 | BNG =0x43, | |
81 | TML =0x44, | |
82 | TLG =0x45, | |
83 | ASM =0x46, | |
84 | ORI =0x47, | |
85 | KND =0x48, | |
86 | MLM =0x49, | |
87 | GJR =0x4A, | |
88 | PNJ =0x4B, | |
89 | ARB =0x71, | |
90 | PES =0x72, | |
91 | URD =0x73, | |
92 | SND =0x74, | |
93 | KSM =0x75, | |
94 | PST =0x76 | |
95 | }ISCIILang; | |
96 | ||
97 | typedef enum{ | |
98 | DEV_MASK =0x80, | |
99 | PNJ_MASK =0x40, | |
100 | GJR_MASK =0x20, | |
101 | ORI_MASK =0x10, | |
102 | BNG_MASK =0x08, | |
103 | KND_MASK =0x04, | |
104 | MLM_MASK =0x02, | |
105 | TML_MASK =0x01, | |
106 | ZERO =0x00 | |
107 | }MaskEnum; | |
108 | ||
109 | typedef struct{ | |
110 | UChar contextCharToUnicode; /* previous Unicode codepoint for contextual analysis */ | |
111 | UChar contextCharFromUnicode; /* previous Unicode codepoint for contextual analysis */ | |
112 | uint16_t defDeltaToUnicode; /* delta for switching to default state when DEF is encountered */ | |
113 | uint16_t currentDeltaFromUnicode;/* current delta in Indic block */ | |
114 | uint16_t currentDeltaToUnicode; /* current delta in Indic block */ | |
115 | MaskEnum currentMaskFromUnicode; /* mask for current state in toUnicode */ | |
116 | MaskEnum currentMaskToUnicode; /* mask for current state in toUnicode */ | |
117 | MaskEnum defMaskToUnicode; /* mask for default state in toUnicode */ | |
374ca955 | 118 | UBool isFirstBuffer; /* boolean for fromUnicode to see if we need to announce the first script */ |
b75a7d8f A |
119 | char name[30]; |
120 | }UConverterDataISCII; | |
121 | ||
122 | static const uint16_t lookupInitialData[][3]={ | |
123 | { DEVANAGARI, DEV_MASK, DEV }, | |
124 | { BENGALI, BNG_MASK, BNG }, | |
125 | { GURMUKHI, PNJ_MASK, PNJ }, | |
126 | { GUJARATI, GJR_MASK, GJR }, | |
127 | { ORIYA, ORI_MASK, ORI }, | |
128 | { TAMIL, TML_MASK, TML }, | |
129 | { TELUGU, KND_MASK, TLG }, | |
130 | { KANNADA, KND_MASK, KND }, | |
131 | { MALAYALAM, MLM_MASK, MLM } | |
132 | }; | |
133 | ||
134 | static void | |
135 | _ISCIIOpen(UConverter *cnv, const char *name,const char *locale,uint32_t options, UErrorCode *errorCode){ | |
136 | cnv->extraInfo = uprv_malloc (sizeof (UConverterDataISCII)); | |
137 | ||
138 | if(cnv->extraInfo != NULL) { | |
139 | int32_t len=0; | |
140 | UConverterDataISCII *converterData=(UConverterDataISCII *) cnv->extraInfo; | |
141 | converterData->contextCharToUnicode=NO_CHAR_MARKER; | |
142 | cnv->toUnicodeStatus = missingCharMarker; | |
143 | converterData->contextCharFromUnicode=0x0000; | |
144 | /* check if the version requested is supported */ | |
145 | if((options & UCNV_OPTIONS_VERSION_MASK) < 9){ | |
146 | /* initialize state variables */ | |
147 | converterData->currentDeltaFromUnicode=converterData->currentDeltaToUnicode= | |
148 | converterData->defDeltaToUnicode= | |
149 | (uint16_t)(lookupInitialData[options & UCNV_OPTIONS_VERSION_MASK][0] * DELTA); | |
150 | ||
151 | converterData->currentMaskFromUnicode = converterData->currentMaskToUnicode = | |
152 | converterData->defMaskToUnicode=lookupInitialData[options & UCNV_OPTIONS_VERSION_MASK][1]; | |
153 | ||
154 | converterData->isFirstBuffer=TRUE; | |
155 | uprv_strcpy(converterData->name,"ISCII,version="); | |
156 | len = (int32_t)uprv_strlen(converterData->name); | |
157 | converterData->name[len]= (char)((options & UCNV_OPTIONS_VERSION_MASK) + '0'); | |
158 | converterData->name[len+1]=0; | |
159 | }else{ | |
160 | uprv_free(cnv->extraInfo); | |
161 | cnv->extraInfo = NULL; | |
162 | *errorCode = U_ILLEGAL_ARGUMENT_ERROR; | |
163 | } | |
164 | ||
165 | }else{ | |
166 | *errorCode =U_MEMORY_ALLOCATION_ERROR; | |
167 | } | |
168 | } | |
169 | static void | |
170 | _ISCIIClose(UConverter *cnv){ | |
171 | if(cnv->extraInfo!=NULL) { | |
172 | if(!cnv->isExtraLocal) { | |
173 | uprv_free(cnv->extraInfo); | |
174 | } | |
175 | cnv->extraInfo=NULL; | |
176 | } | |
177 | } | |
178 | ||
179 | static const char* | |
180 | _ISCIIgetName(const UConverter* cnv){ | |
181 | if(cnv->extraInfo){ | |
182 | UConverterDataISCII* myData= (UConverterDataISCII*)cnv->extraInfo; | |
183 | return myData->name; | |
184 | } | |
185 | return NULL; | |
186 | } | |
187 | ||
188 | static void | |
189 | _ISCIIReset(UConverter *cnv, UConverterResetChoice choice){ | |
190 | UConverterDataISCII* data =(UConverterDataISCII *) (cnv->extraInfo); | |
191 | if(choice<=UCNV_RESET_TO_UNICODE) { | |
192 | cnv->toUnicodeStatus = missingCharMarker; | |
193 | cnv->mode=0; | |
194 | data->currentDeltaToUnicode=data->defDeltaToUnicode; | |
195 | data->currentMaskToUnicode = data->defMaskToUnicode; | |
196 | data->contextCharToUnicode=NO_CHAR_MARKER; | |
197 | } | |
198 | if(choice!=UCNV_RESET_TO_UNICODE) { | |
374ca955 | 199 | cnv->fromUChar32=0x0000; |
b75a7d8f A |
200 | data->contextCharFromUnicode=0x00; |
201 | data->currentMaskFromUnicode=data->defDeltaToUnicode; | |
202 | data->currentDeltaFromUnicode=data->defDeltaToUnicode; | |
374ca955 | 203 | data->isFirstBuffer=TRUE; |
b75a7d8f | 204 | } |
b75a7d8f A |
205 | } |
206 | ||
207 | /** | |
208 | * The values in validity table are indexed by the lower bits of Unicode | |
209 | * range 0x0900 - 0x09ff. The values have a structure like: | |
210 | * --------------------------------------------------------------- | |
211 | * | DEV | PNJ | GJR | ORI | BNG | TLG | MLM | TML | | |
212 | * | | | | | ASM | KND | | | | |
213 | * --------------------------------------------------------------- | |
214 | * If a code point is valid in a particular script | |
215 | * then that bit is turned on | |
216 | * | |
217 | * Unicode does not distinguish between Bengali and Assamese so we use 1 bit for | |
218 | * to represent these languages | |
219 | * | |
220 | * Telugu and Kannada have same codepoints except for Vocallic_RR which we special case | |
221 | * and combine and use 1 bit to represent these languages. | |
222 | * | |
223 | * TODO: It is probably easier to understand and maintain to change this | |
224 | * to use uint16_t and give each of the 9 Unicode/script blocks its own bit. | |
225 | */ | |
226 | ||
227 | static const uint8_t validityTable[128] = { | |
228 | /* This state table is tool generated please donot edit unless you know exactly what you are doing */ | |
229 | /*ISCII:Valid:Unicode */ | |
230 | /*0xa0 : 0x00: 0x900 */ ZERO + ZERO + ZERO + ZERO + ZERO + ZERO + ZERO + ZERO , | |
231 | /*0xa1 : 0xb8: 0x901 */ DEV_MASK + ZERO + GJR_MASK + ORI_MASK + BNG_MASK + ZERO + ZERO + ZERO , | |
232 | /*0xa2 : 0xfe: 0x902 */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + ZERO , | |
233 | /*0xa3 : 0xbf: 0x903 */ DEV_MASK + ZERO + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + TML_MASK , | |
234 | /*0x00 : 0x00: 0x904 */ ZERO + ZERO + ZERO + ZERO + ZERO + ZERO + ZERO + ZERO , | |
235 | /*0xa4 : 0xff: 0x905 */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + TML_MASK , | |
236 | /*0xa5 : 0xff: 0x906 */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + TML_MASK , | |
237 | /*0xa6 : 0xff: 0x907 */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + TML_MASK , | |
238 | /*0xa7 : 0xff: 0x908 */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + TML_MASK , | |
239 | /*0xa8 : 0xff: 0x909 */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + TML_MASK , | |
240 | /*0xa9 : 0xff: 0x90a */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + TML_MASK , | |
241 | /*0xaa : 0xfe: 0x90b */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + ZERO , | |
242 | /*0x00 : 0x00: 0x90c */ DEV_MASK + ZERO + ZERO + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + ZERO , | |
243 | /*0xae : 0x80: 0x90d */ DEV_MASK + ZERO + ZERO + ZERO + ZERO + ZERO + ZERO + ZERO , | |
244 | /*0xab : 0x87: 0x90e */ DEV_MASK + ZERO + ZERO + ZERO + ZERO + KND_MASK + MLM_MASK + TML_MASK , | |
245 | /*0xac : 0xff: 0x90f */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + TML_MASK , | |
246 | /*0xad : 0xff: 0x910 */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + TML_MASK , | |
247 | /*0xb2 : 0x80: 0x911 */ DEV_MASK + ZERO + ZERO + ZERO + ZERO + ZERO + ZERO + ZERO , | |
248 | /*0xaf : 0x87: 0x912 */ DEV_MASK + ZERO + ZERO + ZERO + ZERO + KND_MASK + MLM_MASK + TML_MASK , | |
249 | /*0xb0 : 0xff: 0x913 */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + TML_MASK , | |
250 | /*0xb1 : 0xff: 0x914 */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + TML_MASK , | |
251 | /*0xb3 : 0xff: 0x915 */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + TML_MASK , | |
252 | /*0xb4 : 0xfe: 0x916 */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + ZERO , | |
253 | /*0xb5 : 0xfe: 0x917 */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + ZERO , | |
254 | /*0xb6 : 0xfe: 0x918 */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + ZERO , | |
255 | /*0xb7 : 0xff: 0x919 */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + TML_MASK , | |
256 | /*0xb8 : 0xff: 0x91a */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + TML_MASK , | |
257 | /*0xb9 : 0xfe: 0x91b */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + ZERO , | |
258 | /*0xba : 0xff: 0x91c */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + TML_MASK , | |
259 | /*0xbb : 0xfe: 0x91d */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + ZERO , | |
260 | /*0xbc : 0xff: 0x91e */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + TML_MASK , | |
261 | /*0xbd : 0xff: 0x91f */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + TML_MASK , | |
262 | /*0xbe : 0xfe: 0x920 */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + ZERO , | |
263 | /*0xbf : 0xfe: 0x921 */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + ZERO , | |
264 | /*0xc0 : 0xfe: 0x922 */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + ZERO , | |
265 | /*0xc1 : 0xff: 0x923 */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + TML_MASK , | |
266 | /*0xc2 : 0xff: 0x924 */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + TML_MASK , | |
267 | /*0xc3 : 0xfe: 0x925 */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + ZERO , | |
268 | /*0xc4 : 0xfe: 0x926 */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + ZERO , | |
269 | /*0xc5 : 0xfe: 0x927 */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + ZERO , | |
270 | /*0xc6 : 0xff: 0x928 */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + TML_MASK , | |
271 | /*0xc7 : 0x81: 0x929 */ DEV_MASK + ZERO + ZERO + ZERO + ZERO + ZERO + ZERO + TML_MASK , | |
272 | /*0xc8 : 0xff: 0x92a */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + TML_MASK , | |
273 | /*0xc9 : 0xfe: 0x92b */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + ZERO , | |
274 | /*0xca : 0xfe: 0x92c */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + ZERO , | |
275 | /*0xcb : 0xfe: 0x92d */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + ZERO , | |
276 | /*0xcc : 0xfe: 0x92e */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + ZERO , | |
277 | /*0xcd : 0xff: 0x92f */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + TML_MASK , | |
278 | /*0xcf : 0xff: 0x930 */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + TML_MASK , | |
279 | /*0xd0 : 0x87: 0x931 */ DEV_MASK + ZERO + ZERO + ZERO + ZERO + ZERO + MLM_MASK + TML_MASK , | |
280 | /*0xd1 : 0xff: 0x932 */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + TML_MASK , | |
281 | /*0xd2 : 0xb7: 0x933 */ DEV_MASK + ZERO + GJR_MASK + ORI_MASK + ZERO + KND_MASK + MLM_MASK + TML_MASK , | |
282 | /*0xd3 : 0x83: 0x934 */ DEV_MASK + ZERO + ZERO + ZERO + ZERO + ZERO + MLM_MASK + TML_MASK , | |
283 | /*0xd4 : 0xff: 0x935 */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + TML_MASK , | |
284 | /*0xd5 : 0xfe: 0x936 */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + ZERO , | |
285 | /*0xd6 : 0xbf: 0x937 */ DEV_MASK + ZERO + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + TML_MASK , | |
286 | /*0xd7 : 0xff: 0x938 */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + TML_MASK , | |
287 | /*0xd8 : 0xff: 0x939 */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + TML_MASK , | |
288 | /*0x00 : 0x00: 0x93A */ ZERO + ZERO + ZERO + ZERO + ZERO + ZERO + ZERO + ZERO , | |
289 | /*0x00 : 0x00: 0x93B */ ZERO + ZERO + ZERO + ZERO + ZERO + ZERO + ZERO + ZERO , | |
290 | /*0xe9 : 0xda: 0x93c */ DEV_MASK + PNJ_MASK + ZERO + ORI_MASK + BNG_MASK + ZERO + MLM_MASK + ZERO , | |
291 | /*0x00 : 0x00: 0x93d */ DEV_MASK + ZERO + ZERO + ZERO + ZERO + ZERO + ZERO + ZERO , | |
292 | /*0xda : 0xff: 0x93e */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + TML_MASK , | |
293 | /*0xdb : 0xff: 0x93f */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + TML_MASK , | |
294 | /*0xdc : 0xff: 0x940 */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + TML_MASK , | |
295 | /*0xdd : 0xff: 0x941 */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + TML_MASK , | |
296 | /*0xde : 0xff: 0x942 */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + TML_MASK , | |
297 | /*0xdf : 0xbe: 0x943 */ DEV_MASK + ZERO + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + ZERO , | |
298 | /*0x00 : 0x00: 0x944 */ DEV_MASK + ZERO + ZERO + ZERO + ZERO + ZERO + ZERO + ZERO , | |
299 | /*0xe3 : 0x80: 0x945 */ DEV_MASK + ZERO + ZERO + ZERO + ZERO + ZERO + ZERO + ZERO , | |
300 | /*0xe0 : 0x87: 0x946 */ DEV_MASK + ZERO + ZERO + ZERO + ZERO + KND_MASK + MLM_MASK + TML_MASK , | |
301 | /*0xe1 : 0xff: 0x947 */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + TML_MASK , | |
302 | /*0xe2 : 0xff: 0x948 */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + TML_MASK , | |
303 | /*0xe7 : 0x80: 0x949 */ DEV_MASK + ZERO + ZERO + ZERO + ZERO + ZERO + ZERO + ZERO , | |
304 | /*0xe4 : 0x87: 0x94a */ DEV_MASK + ZERO + ZERO + ZERO + ZERO + KND_MASK + MLM_MASK + TML_MASK , | |
305 | /*0xe5 : 0xff: 0x94b */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + TML_MASK , | |
306 | /*0xe6 : 0xff: 0x94c */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + TML_MASK , | |
307 | /*0xe8 : 0xff: 0x94d */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + TML_MASK , | |
308 | /*0xec : 0x00: 0x94e */ ZERO + ZERO + ZERO + ZERO + ZERO + ZERO + ZERO + ZERO , | |
309 | /*0xed : 0x00: 0x94f */ ZERO + ZERO + ZERO + ZERO + ZERO + ZERO + ZERO + ZERO , | |
310 | /*0x00 : 0x00: 0x950 */ DEV_MASK + ZERO + GJR_MASK + ZERO + ZERO + ZERO + ZERO + ZERO , | |
311 | /*0x00 : 0x00: 0x951 */ DEV_MASK + ZERO + ZERO + ZERO + ZERO + ZERO + ZERO + ZERO , | |
312 | /*0x00 : 0x00: 0x952 */ DEV_MASK + ZERO + ZERO + ZERO + ZERO + ZERO + ZERO + ZERO , | |
313 | /*0x00 : 0x00: 0x953 */ DEV_MASK + ZERO + ZERO + ZERO + ZERO + ZERO + ZERO + ZERO , | |
314 | /*0x00 : 0x00: 0x954 */ DEV_MASK + ZERO + ZERO + ZERO + ZERO + ZERO + ZERO + ZERO , | |
315 | /*0x00 : 0x00: 0x955 */ ZERO + ZERO + ZERO + ZERO + ZERO + KND_MASK + ZERO + ZERO , | |
316 | /*0x00 : 0x00: 0x956 */ ZERO + ZERO + ZERO + ORI_MASK + ZERO + KND_MASK + ZERO + ZERO , | |
317 | /*0x00 : 0x00: 0x957 */ ZERO + ZERO + ZERO + ORI_MASK + ZERO + ZERO + MLM_MASK + ZERO , | |
318 | /*0x00 : 0x00: 0x958 */ DEV_MASK + ZERO + ZERO + ZERO + ZERO + ZERO + ZERO + ZERO , | |
319 | /*0x00 : 0x00: 0x959 */ DEV_MASK + PNJ_MASK + ZERO + ZERO + ZERO + ZERO + ZERO + ZERO , | |
320 | /*0x00 : 0x00: 0x95a */ DEV_MASK + PNJ_MASK + ZERO + ZERO + ZERO + ZERO + ZERO + ZERO , | |
321 | /*0x00 : 0x00: 0x95b */ DEV_MASK + PNJ_MASK + ZERO + ORI_MASK + ZERO + ZERO + ZERO + ZERO , | |
322 | /*0x00 : 0x00: 0x95c */ DEV_MASK + PNJ_MASK + ZERO + ZERO + BNG_MASK + ZERO + ZERO + ZERO , | |
323 | /*0x00 : 0x00: 0x95d */ DEV_MASK + ZERO + ZERO + ORI_MASK + BNG_MASK + ZERO + ZERO + ZERO , | |
324 | /*0x00 : 0x00: 0x95e */ DEV_MASK + PNJ_MASK + ZERO + ZERO + ZERO + ZERO + ZERO + ZERO , | |
325 | /*0xce : 0x98: 0x95f */ DEV_MASK + ZERO + ZERO + ORI_MASK + BNG_MASK + ZERO + ZERO + ZERO , | |
326 | /*0x00 : 0x00: 0x960 */ DEV_MASK + ZERO + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + ZERO , | |
327 | /*0x00 : 0x00: 0x961 */ DEV_MASK + ZERO + ZERO + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + ZERO , | |
328 | /*0x00 : 0x00: 0x962 */ DEV_MASK + ZERO + ZERO + ZERO + BNG_MASK + ZERO + ZERO + ZERO , | |
329 | /*0x00 : 0x00: 0x963 */ DEV_MASK + ZERO + ZERO + ZERO + BNG_MASK + ZERO + ZERO + ZERO , | |
330 | /*0xea : 0xf8: 0x964 */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + ZERO + ZERO + ZERO , | |
331 | /*0xeaea : 0x00: 0x965*/ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + ZERO + ZERO + ZERO , | |
332 | /*0xf1 : 0xff: 0x966 */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + TML_MASK , | |
333 | /*0xf2 : 0xff: 0x967 */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + TML_MASK , | |
334 | /*0xf3 : 0xff: 0x968 */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + TML_MASK , | |
335 | /*0xf4 : 0xff: 0x969 */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + TML_MASK , | |
336 | /*0xf5 : 0xff: 0x96a */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + TML_MASK , | |
337 | /*0xf6 : 0xff: 0x96b */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + TML_MASK , | |
338 | /*0xf7 : 0xff: 0x96c */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + TML_MASK , | |
339 | /*0xf8 : 0xff: 0x96d */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + TML_MASK , | |
340 | /*0xf9 : 0xff: 0x96e */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + TML_MASK , | |
341 | /*0xfa : 0xff: 0x96f */ DEV_MASK + PNJ_MASK + GJR_MASK + ORI_MASK + BNG_MASK + KND_MASK + MLM_MASK + TML_MASK , | |
342 | /*0x00 : 0x80: 0x970 */ DEV_MASK + ZERO + ZERO + ZERO + ZERO + ZERO + ZERO + ZERO , | |
343 | ||
344 | /* | |
345 | * The length of the array is 128 to provide values for 0x900..0x97f. | |
346 | * The last 15 entries for 0x971..0x97f of the validity table are all zero | |
347 | * because no Indic script uses such Unicode code points. | |
348 | */ | |
349 | /*0x00 : 0x00: 0x9yz */ ZERO + ZERO + ZERO + ZERO + ZERO + ZERO + ZERO + ZERO | |
350 | }; | |
351 | ||
352 | static const uint16_t fromUnicodeTable[128]={ | |
353 | 0x00a0 ,/* 0x0900 */ | |
354 | 0x00a1 ,/* 0x0901 */ | |
355 | 0x00a2 ,/* 0x0902 */ | |
356 | 0x00a3 ,/* 0x0903 */ | |
357 | 0xFFFF ,/* 0x0904 */ | |
358 | 0x00a4 ,/* 0x0905 */ | |
359 | 0x00a5 ,/* 0x0906 */ | |
360 | 0x00a6 ,/* 0x0907 */ | |
361 | 0x00a7 ,/* 0x0908 */ | |
362 | 0x00a8 ,/* 0x0909 */ | |
363 | 0x00a9 ,/* 0x090a */ | |
364 | 0x00aa ,/* 0x090b */ | |
365 | 0xA6E9 ,/* 0x090c */ | |
366 | 0x00ae ,/* 0x090d */ | |
367 | 0x00ab ,/* 0x090e */ | |
368 | 0x00ac ,/* 0x090f */ | |
369 | 0x00ad ,/* 0x0910 */ | |
370 | 0x00b2 ,/* 0x0911 */ | |
371 | 0x00af ,/* 0x0912 */ | |
372 | 0x00b0 ,/* 0x0913 */ | |
373 | 0x00b1 ,/* 0x0914 */ | |
374 | 0x00b3 ,/* 0x0915 */ | |
375 | 0x00b4 ,/* 0x0916 */ | |
376 | 0x00b5 ,/* 0x0917 */ | |
377 | 0x00b6 ,/* 0x0918 */ | |
378 | 0x00b7 ,/* 0x0919 */ | |
379 | 0x00b8 ,/* 0x091a */ | |
380 | 0x00b9 ,/* 0x091b */ | |
381 | 0x00ba ,/* 0x091c */ | |
382 | 0x00bb ,/* 0x091d */ | |
383 | 0x00bc ,/* 0x091e */ | |
384 | 0x00bd ,/* 0x091f */ | |
385 | 0x00be ,/* 0x0920 */ | |
386 | 0x00bf ,/* 0x0921 */ | |
387 | 0x00c0 ,/* 0x0922 */ | |
388 | 0x00c1 ,/* 0x0923 */ | |
389 | 0x00c2 ,/* 0x0924 */ | |
390 | 0x00c3 ,/* 0x0925 */ | |
391 | 0x00c4 ,/* 0x0926 */ | |
392 | 0x00c5 ,/* 0x0927 */ | |
393 | 0x00c6 ,/* 0x0928 */ | |
394 | 0x00c7 ,/* 0x0929 */ | |
395 | 0x00c8 ,/* 0x092a */ | |
396 | 0x00c9 ,/* 0x092b */ | |
397 | 0x00ca ,/* 0x092c */ | |
398 | 0x00cb ,/* 0x092d */ | |
399 | 0x00cc ,/* 0x092e */ | |
400 | 0x00cd ,/* 0x092f */ | |
401 | 0x00cf ,/* 0x0930 */ | |
402 | 0x00d0 ,/* 0x0931 */ | |
403 | 0x00d1 ,/* 0x0932 */ | |
404 | 0x00d2 ,/* 0x0933 */ | |
405 | 0x00d3 ,/* 0x0934 */ | |
406 | 0x00d4 ,/* 0x0935 */ | |
407 | 0x00d5 ,/* 0x0936 */ | |
408 | 0x00d6 ,/* 0x0937 */ | |
409 | 0x00d7 ,/* 0x0938 */ | |
410 | 0x00d8 ,/* 0x0939 */ | |
411 | 0xFFFF ,/* 0x093A */ | |
412 | 0xFFFF ,/* 0x093B */ | |
413 | 0x00e9 ,/* 0x093c */ | |
414 | 0xEAE9 ,/* 0x093d */ | |
415 | 0x00da ,/* 0x093e */ | |
416 | 0x00db ,/* 0x093f */ | |
417 | 0x00dc ,/* 0x0940 */ | |
418 | 0x00dd ,/* 0x0941 */ | |
419 | 0x00de ,/* 0x0942 */ | |
420 | 0x00df ,/* 0x0943 */ | |
421 | 0xDFE9 ,/* 0x0944 */ | |
422 | 0x00e3 ,/* 0x0945 */ | |
423 | 0x00e0 ,/* 0x0946 */ | |
424 | 0x00e1 ,/* 0x0947 */ | |
425 | 0x00e2 ,/* 0x0948 */ | |
426 | 0x00e7 ,/* 0x0949 */ | |
427 | 0x00e4 ,/* 0x094a */ | |
428 | 0x00e5 ,/* 0x094b */ | |
429 | 0x00e6 ,/* 0x094c */ | |
430 | 0x00e8 ,/* 0x094d */ | |
431 | 0x00ec ,/* 0x094e */ | |
432 | 0x00ed ,/* 0x094f */ | |
433 | 0xA1E9 ,/* 0x0950 */ /* OM Symbol */ | |
434 | 0xFFFF ,/* 0x0951 */ | |
435 | 0xF0B8 ,/* 0x0952 */ | |
436 | 0xFFFF ,/* 0x0953 */ | |
437 | 0xFFFF ,/* 0x0954 */ | |
438 | 0xFFFF ,/* 0x0955 */ | |
439 | 0xFFFF ,/* 0x0956 */ | |
440 | 0xFFFF ,/* 0x0957 */ | |
441 | 0xb3e9 ,/* 0x0958 */ | |
442 | 0xb4e9 ,/* 0x0959 */ | |
443 | 0xb5e9 ,/* 0x095a */ | |
444 | 0xbae9 ,/* 0x095b */ | |
445 | 0xbfe9 ,/* 0x095c */ | |
446 | 0xC0E9 ,/* 0x095d */ | |
447 | 0xc9e9 ,/* 0x095e */ | |
448 | 0x00ce ,/* 0x095f */ | |
449 | 0xAAe9 ,/* 0x0960 */ | |
450 | 0xA7E9 ,/* 0x0961 */ | |
451 | 0xDBE9 ,/* 0x0962 */ | |
452 | 0xDCE9 ,/* 0x0963 */ | |
453 | 0x00ea ,/* 0x0964 */ | |
454 | 0xeaea ,/* 0x0965 */ | |
455 | 0x00f1 ,/* 0x0966 */ | |
456 | 0x00f2 ,/* 0x0967 */ | |
457 | 0x00f3 ,/* 0x0968 */ | |
458 | 0x00f4 ,/* 0x0969 */ | |
459 | 0x00f5 ,/* 0x096a */ | |
460 | 0x00f6 ,/* 0x096b */ | |
461 | 0x00f7 ,/* 0x096c */ | |
462 | 0x00f8 ,/* 0x096d */ | |
463 | 0x00f9 ,/* 0x096e */ | |
464 | 0x00fa ,/* 0x096f */ | |
465 | 0xF0BF ,/* 0x0970 */ | |
466 | 0xFFFF ,/* 0x0971 */ | |
467 | 0xFFFF ,/* 0x0972 */ | |
468 | 0xFFFF ,/* 0x0973 */ | |
469 | 0xFFFF ,/* 0x0974 */ | |
470 | 0xFFFF ,/* 0x0975 */ | |
471 | 0xFFFF ,/* 0x0976 */ | |
472 | 0xFFFF ,/* 0x0977 */ | |
473 | 0xFFFF ,/* 0x0978 */ | |
474 | 0xFFFF ,/* 0x0979 */ | |
475 | 0xFFFF ,/* 0x097a */ | |
476 | 0xFFFF ,/* 0x097b */ | |
477 | 0xFFFF ,/* 0x097c */ | |
478 | 0xFFFF ,/* 0x097d */ | |
479 | 0xFFFF ,/* 0x097e */ | |
480 | 0xFFFF ,/* 0x097f */ | |
481 | }; | |
482 | static const uint16_t toUnicodeTable[256]={ | |
483 | 0x0000,/* 0x00 */ | |
484 | 0x0001,/* 0x01 */ | |
485 | 0x0002,/* 0x02 */ | |
486 | 0x0003,/* 0x03 */ | |
487 | 0x0004,/* 0x04 */ | |
488 | 0x0005,/* 0x05 */ | |
489 | 0x0006,/* 0x06 */ | |
490 | 0x0007,/* 0x07 */ | |
491 | 0x0008,/* 0x08 */ | |
492 | 0x0009,/* 0x09 */ | |
493 | 0x000a,/* 0x0a */ | |
494 | 0x000b,/* 0x0b */ | |
495 | 0x000c,/* 0x0c */ | |
496 | 0x000d,/* 0x0d */ | |
497 | 0x000e,/* 0x0e */ | |
498 | 0x000f,/* 0x0f */ | |
499 | 0x0010,/* 0x10 */ | |
500 | 0x0011,/* 0x11 */ | |
501 | 0x0012,/* 0x12 */ | |
502 | 0x0013,/* 0x13 */ | |
503 | 0x0014,/* 0x14 */ | |
504 | 0x0015,/* 0x15 */ | |
505 | 0x0016,/* 0x16 */ | |
506 | 0x0017,/* 0x17 */ | |
507 | 0x0018,/* 0x18 */ | |
508 | 0x0019,/* 0x19 */ | |
509 | 0x001a,/* 0x1a */ | |
510 | 0x001b,/* 0x1b */ | |
511 | 0x001c,/* 0x1c */ | |
512 | 0x001d,/* 0x1d */ | |
513 | 0x001e,/* 0x1e */ | |
514 | 0x001f,/* 0x1f */ | |
515 | 0x0020,/* 0x20 */ | |
516 | 0x0021,/* 0x21 */ | |
517 | 0x0022,/* 0x22 */ | |
518 | 0x0023,/* 0x23 */ | |
519 | 0x0024,/* 0x24 */ | |
520 | 0x0025,/* 0x25 */ | |
521 | 0x0026,/* 0x26 */ | |
522 | 0x0027,/* 0x27 */ | |
523 | 0x0028,/* 0x28 */ | |
524 | 0x0029,/* 0x29 */ | |
525 | 0x002a,/* 0x2a */ | |
526 | 0x002b,/* 0x2b */ | |
527 | 0x002c,/* 0x2c */ | |
528 | 0x002d,/* 0x2d */ | |
529 | 0x002e,/* 0x2e */ | |
530 | 0x002f,/* 0x2f */ | |
531 | 0x0030,/* 0x30 */ | |
532 | 0x0031,/* 0x31 */ | |
533 | 0x0032,/* 0x32 */ | |
534 | 0x0033,/* 0x33 */ | |
535 | 0x0034,/* 0x34 */ | |
536 | 0x0035,/* 0x35 */ | |
537 | 0x0036,/* 0x36 */ | |
538 | 0x0037,/* 0x37 */ | |
539 | 0x0038,/* 0x38 */ | |
540 | 0x0039,/* 0x39 */ | |
541 | 0x003A,/* 0x3A */ | |
542 | 0x003B,/* 0x3B */ | |
543 | 0x003c,/* 0x3c */ | |
544 | 0x003d,/* 0x3d */ | |
545 | 0x003e,/* 0x3e */ | |
546 | 0x003f,/* 0x3f */ | |
547 | 0x0040,/* 0x40 */ | |
548 | 0x0041,/* 0x41 */ | |
549 | 0x0042,/* 0x42 */ | |
550 | 0x0043,/* 0x43 */ | |
551 | 0x0044,/* 0x44 */ | |
552 | 0x0045,/* 0x45 */ | |
553 | 0x0046,/* 0x46 */ | |
554 | 0x0047,/* 0x47 */ | |
555 | 0x0048,/* 0x48 */ | |
556 | 0x0049,/* 0x49 */ | |
557 | 0x004a,/* 0x4a */ | |
558 | 0x004b,/* 0x4b */ | |
559 | 0x004c,/* 0x4c */ | |
560 | 0x004d,/* 0x4d */ | |
561 | 0x004e,/* 0x4e */ | |
562 | 0x004f,/* 0x4f */ | |
563 | 0x0050,/* 0x50 */ | |
564 | 0x0051,/* 0x51 */ | |
565 | 0x0052,/* 0x52 */ | |
566 | 0x0053,/* 0x53 */ | |
567 | 0x0054,/* 0x54 */ | |
568 | 0x0055,/* 0x55 */ | |
569 | 0x0056,/* 0x56 */ | |
570 | 0x0057,/* 0x57 */ | |
571 | 0x0058,/* 0x58 */ | |
572 | 0x0059,/* 0x59 */ | |
573 | 0x005a,/* 0x5a */ | |
574 | 0x005b,/* 0x5b */ | |
575 | 0x005c,/* 0x5c */ | |
576 | 0x005d,/* 0x5d */ | |
577 | 0x005e,/* 0x5e */ | |
578 | 0x005f,/* 0x5f */ | |
579 | 0x0060,/* 0x60 */ | |
580 | 0x0061,/* 0x61 */ | |
581 | 0x0062,/* 0x62 */ | |
582 | 0x0063,/* 0x63 */ | |
583 | 0x0064,/* 0x64 */ | |
584 | 0x0065,/* 0x65 */ | |
585 | 0x0066,/* 0x66 */ | |
586 | 0x0067,/* 0x67 */ | |
587 | 0x0068,/* 0x68 */ | |
588 | 0x0069,/* 0x69 */ | |
589 | 0x006a,/* 0x6a */ | |
590 | 0x006b,/* 0x6b */ | |
591 | 0x006c,/* 0x6c */ | |
592 | 0x006d,/* 0x6d */ | |
593 | 0x006e,/* 0x6e */ | |
594 | 0x006f,/* 0x6f */ | |
595 | 0x0070,/* 0x70 */ | |
596 | 0x0071,/* 0x71 */ | |
597 | 0x0072,/* 0x72 */ | |
598 | 0x0073,/* 0x73 */ | |
599 | 0x0074,/* 0x74 */ | |
600 | 0x0075,/* 0x75 */ | |
601 | 0x0076,/* 0x76 */ | |
602 | 0x0077,/* 0x77 */ | |
603 | 0x0078,/* 0x78 */ | |
604 | 0x0079,/* 0x79 */ | |
605 | 0x007a,/* 0x7a */ | |
606 | 0x007b,/* 0x7b */ | |
607 | 0x007c,/* 0x7c */ | |
608 | 0x007d,/* 0x7d */ | |
609 | 0x007e,/* 0x7e */ | |
610 | 0x007f,/* 0x7f */ | |
611 | 0x0080,/* 0x80 */ | |
612 | 0x0081,/* 0x81 */ | |
613 | 0x0082,/* 0x82 */ | |
614 | 0x0083,/* 0x83 */ | |
615 | 0x0084,/* 0x84 */ | |
616 | 0x0085,/* 0x85 */ | |
617 | 0x0086,/* 0x86 */ | |
618 | 0x0087,/* 0x87 */ | |
619 | 0x0088,/* 0x88 */ | |
620 | 0x0089,/* 0x89 */ | |
621 | 0x008a,/* 0x8a */ | |
622 | 0x008b,/* 0x8b */ | |
623 | 0x008c,/* 0x8c */ | |
624 | 0x008d,/* 0x8d */ | |
625 | 0x008e,/* 0x8e */ | |
626 | 0x008f,/* 0x8f */ | |
627 | 0x0090,/* 0x90 */ | |
628 | 0x0091,/* 0x91 */ | |
629 | 0x0092,/* 0x92 */ | |
630 | 0x0093,/* 0x93 */ | |
631 | 0x0094,/* 0x94 */ | |
632 | 0x0095,/* 0x95 */ | |
633 | 0x0096,/* 0x96 */ | |
634 | 0x0097,/* 0x97 */ | |
635 | 0x0098,/* 0x98 */ | |
636 | 0x0099,/* 0x99 */ | |
637 | 0x009a,/* 0x9a */ | |
638 | 0x009b,/* 0x9b */ | |
639 | 0x009c,/* 0x9c */ | |
640 | 0x009d,/* 0x9d */ | |
641 | 0x009e,/* 0x9e */ | |
642 | 0x009f,/* 0x9f */ | |
643 | 0x00A0,/* 0xa0 */ | |
644 | 0x0901,/* 0xa1 */ | |
645 | 0x0902,/* 0xa2 */ | |
646 | 0x0903,/* 0xa3 */ | |
647 | 0x0905,/* 0xa4 */ | |
648 | 0x0906,/* 0xa5 */ | |
649 | 0x0907,/* 0xa6 */ | |
650 | 0x0908,/* 0xa7 */ | |
651 | 0x0909,/* 0xa8 */ | |
652 | 0x090a,/* 0xa9 */ | |
653 | 0x090b,/* 0xaa */ | |
654 | 0x090e,/* 0xab */ | |
655 | 0x090f,/* 0xac */ | |
656 | 0x0910,/* 0xad */ | |
657 | 0x090d,/* 0xae */ | |
658 | 0x0912,/* 0xaf */ | |
659 | 0x0913,/* 0xb0 */ | |
660 | 0x0914,/* 0xb1 */ | |
661 | 0x0911,/* 0xb2 */ | |
662 | 0x0915,/* 0xb3 */ | |
663 | 0x0916,/* 0xb4 */ | |
664 | 0x0917,/* 0xb5 */ | |
665 | 0x0918,/* 0xb6 */ | |
666 | 0x0919,/* 0xb7 */ | |
667 | 0x091a,/* 0xb8 */ | |
668 | 0x091b,/* 0xb9 */ | |
669 | 0x091c,/* 0xba */ | |
670 | 0x091d,/* 0xbb */ | |
671 | 0x091e,/* 0xbc */ | |
672 | 0x091f,/* 0xbd */ | |
673 | 0x0920,/* 0xbe */ | |
674 | 0x0921,/* 0xbf */ | |
675 | 0x0922,/* 0xc0 */ | |
676 | 0x0923,/* 0xc1 */ | |
677 | 0x0924,/* 0xc2 */ | |
678 | 0x0925,/* 0xc3 */ | |
679 | 0x0926,/* 0xc4 */ | |
680 | 0x0927,/* 0xc5 */ | |
681 | 0x0928,/* 0xc6 */ | |
682 | 0x0929,/* 0xc7 */ | |
683 | 0x092a,/* 0xc8 */ | |
684 | 0x092b,/* 0xc9 */ | |
685 | 0x092c,/* 0xca */ | |
686 | 0x092d,/* 0xcb */ | |
687 | 0x092e,/* 0xcc */ | |
688 | 0x092f,/* 0xcd */ | |
689 | 0x095f,/* 0xce */ | |
690 | 0x0930,/* 0xcf */ | |
691 | 0x0931,/* 0xd0 */ | |
692 | 0x0932,/* 0xd1 */ | |
693 | 0x0933,/* 0xd2 */ | |
694 | 0x0934,/* 0xd3 */ | |
695 | 0x0935,/* 0xd4 */ | |
696 | 0x0936,/* 0xd5 */ | |
697 | 0x0937,/* 0xd6 */ | |
698 | 0x0938,/* 0xd7 */ | |
699 | 0x0939,/* 0xd8 */ | |
700 | 0x200D,/* 0xd9 */ | |
701 | 0x093e,/* 0xda */ | |
702 | 0x093f,/* 0xdb */ | |
703 | 0x0940,/* 0xdc */ | |
704 | 0x0941,/* 0xdd */ | |
705 | 0x0942,/* 0xde */ | |
706 | 0x0943,/* 0xdf */ | |
707 | 0x0946,/* 0xe0 */ | |
708 | 0x0947,/* 0xe1 */ | |
709 | 0x0948,/* 0xe2 */ | |
710 | 0x0945,/* 0xe3 */ | |
711 | 0x094a,/* 0xe4 */ | |
712 | 0x094b,/* 0xe5 */ | |
713 | 0x094c,/* 0xe6 */ | |
714 | 0x0949,/* 0xe7 */ | |
715 | 0x094d,/* 0xe8 */ | |
716 | 0x093c,/* 0xe9 */ | |
717 | 0x0964,/* 0xea */ | |
718 | 0xFFFF,/* 0xeb */ | |
719 | 0xFFFF,/* 0xec */ | |
720 | 0xFFFF,/* 0xed */ | |
721 | 0xFFFF,/* 0xee */ | |
722 | 0xFFFF,/* 0xef */ | |
723 | 0xFFFF,/* 0xf0 */ | |
724 | 0x0966,/* 0xf1 */ | |
725 | 0x0967,/* 0xf2 */ | |
726 | 0x0968,/* 0xf3 */ | |
727 | 0x0969,/* 0xf4 */ | |
728 | 0x096a,/* 0xf5 */ | |
729 | 0x096b,/* 0xf6 */ | |
730 | 0x096c,/* 0xf7 */ | |
731 | 0x096d,/* 0xf8 */ | |
732 | 0x096e,/* 0xf9 */ | |
733 | 0x096f,/* 0xfa */ | |
734 | 0xFFFF,/* 0xfb */ | |
735 | 0xFFFF,/* 0xfc */ | |
736 | 0xFFFF,/* 0xfd */ | |
737 | 0xFFFF,/* 0xfe */ | |
738 | 0xFFFF /* 0xff */ | |
739 | }; | |
740 | ||
741 | static const uint16_t nuktaSpecialCases[][2]={ | |
742 | { 16 /*length of array*/ , 0 }, | |
743 | { 0xA6 , 0x090c }, | |
744 | { 0xEA , 0x093D }, | |
745 | { 0xDF , 0x0944 }, | |
746 | { 0xA1 , 0x0950 }, | |
747 | { 0xb3 , 0x0958 }, | |
748 | { 0xb4 , 0x0959 }, | |
749 | { 0xb5 , 0x095a }, | |
750 | { 0xba , 0x095b }, | |
751 | { 0xbf , 0x095c }, | |
752 | { 0xC0 , 0x095d }, | |
753 | { 0xc9 , 0x095e }, | |
754 | { 0xAA , 0x0960 }, | |
755 | { 0xA7 , 0x0961 }, | |
756 | { 0xDB , 0x0962 }, | |
757 | { 0xDC , 0x0963 }, | |
758 | }; | |
759 | ||
760 | #define WRITE_TO_TARGET_FROM_U(args,offsets,source,target,targetLimit,targetByteUnit,err){ \ | |
761 | /* write the targetUniChar to target */ \ | |
762 | if(target <targetLimit){ \ | |
763 | if(targetByteUnit <= 0xFF){ \ | |
764 | *(target)++ = (uint8_t)(targetByteUnit); \ | |
765 | if(offsets){ \ | |
766 | *(offsets++) = (int32_t)(source - args->source-1); \ | |
767 | } \ | |
768 | }else{ \ | |
769 | *(target)++ = (uint8_t)(targetByteUnit>>8); \ | |
770 | if(offsets){ \ | |
771 | *(offsets++) = (int32_t)(source - args->source-1); \ | |
772 | } \ | |
773 | if(target < targetLimit){ \ | |
774 | *(target)++ = (uint8_t) targetByteUnit; \ | |
775 | if(offsets){ \ | |
776 | *(offsets++) = (int32_t)(source - args->source-1); \ | |
777 | } \ | |
778 | }else{ \ | |
779 | args->converter->charErrorBuffer[args->converter->charErrorBufferLength++] = \ | |
780 | (uint8_t) (targetByteUnit); \ | |
781 | *err = U_BUFFER_OVERFLOW_ERROR; \ | |
782 | } \ | |
783 | } \ | |
784 | }else{ \ | |
785 | if(targetByteUnit & 0xFF00){ \ | |
786 | args->converter->charErrorBuffer[args->converter->charErrorBufferLength++] = \ | |
787 | (uint8_t) (targetByteUnit >>8); \ | |
788 | } \ | |
789 | args->converter->charErrorBuffer[args->converter->charErrorBufferLength++] = \ | |
790 | (uint8_t) (targetByteUnit); \ | |
791 | *err = U_BUFFER_OVERFLOW_ERROR; \ | |
792 | } \ | |
793 | } | |
794 | ||
795 | /* Rules: | |
796 | * Explicit Halant : | |
797 | * <HALANT> + <ZWNJ> | |
798 | * Soft Halant : | |
799 | * <HALANT> + <ZWJ> | |
800 | */ | |
801 | ||
802 | static void | |
803 | UConverter_fromUnicode_ISCII_OFFSETS_LOGIC (UConverterFromUnicodeArgs * args, | |
804 | UErrorCode * err){ | |
805 | const UChar *source = args->source; | |
806 | const UChar *sourceLimit = args->sourceLimit; | |
807 | unsigned char *target = (unsigned char *) args->target; | |
808 | unsigned char *targetLimit = (unsigned char *) args->targetLimit; | |
809 | int32_t* offsets = args->offsets; | |
810 | uint32_t targetByteUnit = 0x0000; | |
811 | UChar32 sourceChar = 0x0000; | |
b75a7d8f A |
812 | UBool useFallback; |
813 | UConverterDataISCII *converterData; | |
814 | uint16_t newDelta=0; | |
815 | uint16_t range = 0; | |
816 | UBool deltaChanged = FALSE; | |
817 | ||
818 | if ((args->converter == NULL) || (args->targetLimit < args->target) || (args->sourceLimit < args->source)){ | |
819 | *err = U_ILLEGAL_ARGUMENT_ERROR; | |
820 | return; | |
821 | } | |
822 | /* initialize data */ | |
823 | converterData=(UConverterDataISCII*)args->converter->extraInfo; | |
824 | useFallback = args->converter->useFallback; | |
825 | newDelta=converterData->currentDeltaFromUnicode; | |
826 | range = (uint16_t)(newDelta/DELTA); | |
827 | ||
374ca955 | 828 | if((sourceChar = args->converter->fromUChar32)!=0) { |
b75a7d8f A |
829 | goto getTrail; |
830 | } | |
831 | ||
832 | /*writing the char to the output stream */ | |
833 | while(source < sourceLimit){ | |
834 | ||
835 | targetByteUnit = missingCharMarker; | |
836 | ||
837 | sourceChar = *source++; | |
838 | ||
839 | /*check if input is in ASCII and C0 control codes range*/ | |
840 | if (sourceChar <= ASCII_END) { | |
841 | WRITE_TO_TARGET_FROM_U(args,offsets,source,target,targetLimit,sourceChar,err); | |
842 | if(U_FAILURE(*err)){ | |
843 | break; | |
844 | } | |
845 | if(sourceChar == LF){ | |
846 | targetByteUnit = ATR<<8; | |
847 | targetByteUnit += (uint8_t) lookupInitialData[range][2]; | |
848 | args->converter->fromUnicodeStatus=sourceChar; | |
849 | /* now append ATR and language code */ | |
850 | WRITE_TO_TARGET_FROM_U(args,offsets,source,target,targetLimit,targetByteUnit,err); | |
851 | if(U_FAILURE(*err)){ | |
852 | break; | |
853 | } | |
854 | } | |
855 | continue; | |
856 | } | |
857 | switch(sourceChar){ | |
858 | case ZWNJ: | |
859 | /* contextChar has HALANT */ | |
860 | if(converterData->contextCharFromUnicode){ | |
861 | converterData->contextCharFromUnicode = 0x00; | |
862 | targetByteUnit = ISCII_HALANT; | |
863 | }else{ | |
864 | /* consume ZWNJ and continue */ | |
865 | converterData->contextCharFromUnicode = 0x00; | |
866 | continue; | |
867 | } | |
868 | break; | |
869 | case ZWJ: | |
870 | /* contextChar has HALANT */ | |
871 | if(converterData->contextCharFromUnicode){ | |
872 | targetByteUnit = ISCII_NUKTA; | |
873 | }else{ | |
874 | targetByteUnit =ISCII_INV; | |
875 | } | |
876 | converterData->contextCharFromUnicode = 0x00; | |
877 | break; | |
878 | default: | |
879 | /* is the sourceChar in the INDIC_RANGE? */ | |
880 | if((uint16_t)(INDIC_BLOCK_END-sourceChar) <= INDIC_RANGE){ | |
881 | /* Danda and Double Danda are valid in Northern scripts.. since Unicode | |
882 | * does not include these codepoints in all Northern scrips we need to | |
883 | * filter them out | |
884 | */ | |
885 | if(sourceChar!= DANDA && sourceChar != DOUBLE_DANDA){ | |
886 | /* find out to which block the souceChar belongs*/ | |
887 | range =(uint16_t)((sourceChar-INDIC_BLOCK_BEGIN)/DELTA); | |
888 | newDelta =(uint16_t)(range*DELTA); | |
889 | ||
890 | /* Now are we in the same block as the previous? */ | |
891 | if(newDelta!= converterData->currentDeltaFromUnicode || converterData->isFirstBuffer){ | |
892 | converterData->currentDeltaFromUnicode = newDelta; | |
893 | converterData->currentMaskFromUnicode = lookupInitialData[range][1]; | |
894 | deltaChanged =TRUE; | |
895 | converterData->isFirstBuffer=FALSE; | |
896 | } | |
897 | /* Normalize all Indic codepoints to Devanagari and map them to ISCII */ | |
898 | /* now subtract the new delta from sourceChar*/ | |
899 | sourceChar -= converterData->currentDeltaFromUnicode ; | |
900 | } | |
901 | ||
902 | /* get the target byte unit */ | |
903 | targetByteUnit=fromUnicodeTable[(uint8_t)sourceChar]; | |
904 | ||
905 | /* is the code point valid in current script? */ | |
906 | if((validityTable[(uint8_t)sourceChar] & converterData->currentMaskFromUnicode)==0){ | |
907 | /* Vocallic RR is assigne in ISCII Telugu and Unicode */ | |
908 | if(converterData->currentDeltaFromUnicode!=(TELUGU_DELTA) && sourceChar!=VOCALLIC_RR){ | |
909 | targetByteUnit=missingCharMarker; | |
910 | } | |
911 | } | |
912 | ||
913 | if(deltaChanged){ | |
914 | /* we are in a script block which is different than | |
915 | * previous sourceChar's script block write ATR and language codes | |
916 | */ | |
917 | uint16_t temp=0; | |
918 | temp =(uint16_t)(ATR<<8); | |
919 | temp += (uint16_t)((uint8_t) lookupInitialData[range][2]); | |
920 | /* reset */ | |
921 | deltaChanged=FALSE; | |
922 | /* now append ATR and language code */ | |
923 | WRITE_TO_TARGET_FROM_U(args,offsets,source,target,targetLimit,temp,err); | |
924 | if(U_FAILURE(*err)){ | |
925 | break; | |
926 | } | |
927 | } | |
928 | } | |
929 | /* reset context char */ | |
930 | converterData->contextCharFromUnicode = 0x00; | |
931 | break; | |
932 | } | |
933 | ||
934 | ||
935 | if(targetByteUnit != missingCharMarker){ | |
936 | if(targetByteUnit==ISCII_HALANT){ | |
937 | converterData->contextCharFromUnicode = (UChar)targetByteUnit; | |
938 | } | |
939 | /* write targetByteUnit to target*/ | |
940 | WRITE_TO_TARGET_FROM_U(args,offsets,source,target,targetLimit,targetByteUnit,err); | |
941 | if(U_FAILURE(*err)){ | |
942 | break; | |
943 | } | |
944 | } | |
945 | else{ | |
374ca955 | 946 | /* oops.. the code point is unassigned */ |
b75a7d8f A |
947 | /*check if the char is a First surrogate*/ |
948 | if(UTF_IS_SURROGATE(sourceChar)) { | |
949 | if(UTF_IS_SURROGATE_FIRST(sourceChar)) { | |
b75a7d8f A |
950 | getTrail: |
951 | /*look ahead to find the trail surrogate*/ | |
952 | if(source < sourceLimit) { | |
953 | /* test the following code unit */ | |
954 | UChar trail= (*source); | |
955 | if(UTF_IS_SECOND_SURROGATE(trail)) { | |
956 | source++; | |
374ca955 | 957 | sourceChar=UTF16_GET_PAIR_VALUE(sourceChar, trail); |
b75a7d8f A |
958 | *err =U_INVALID_CHAR_FOUND; |
959 | /* convert this surrogate code point */ | |
960 | /* exit this condition tree */ | |
961 | } else { | |
962 | /* this is an unmatched lead code unit (1st surrogate) */ | |
963 | /* callback(illegal) */ | |
b75a7d8f A |
964 | *err=U_ILLEGAL_CHAR_FOUND; |
965 | } | |
966 | } else { | |
967 | /* no more input */ | |
968 | *err = U_ZERO_ERROR; | |
b75a7d8f A |
969 | } |
970 | } else { | |
971 | /* this is an unmatched trail code unit (2nd surrogate) */ | |
972 | /* callback(illegal) */ | |
b75a7d8f A |
973 | *err=U_ILLEGAL_CHAR_FOUND; |
974 | } | |
374ca955 A |
975 | } else { |
976 | /* callback(unassigned) for a BMP code point */ | |
977 | *err = U_INVALID_CHAR_FOUND; | |
b75a7d8f | 978 | } |
b75a7d8f | 979 | |
374ca955 A |
980 | args->converter->fromUChar32=sourceChar; |
981 | break; | |
b75a7d8f | 982 | } |
b75a7d8f A |
983 | }/* end while(mySourceIndex<mySourceLength) */ |
984 | ||
b75a7d8f A |
985 | /*save the state and return */ |
986 | args->source = source; | |
987 | args->target = (char*)target; | |
988 | } | |
989 | ||
990 | static const int32_t lookupTable[][2]={ | |
991 | { ZERO, ZERO }, /*DEFALT*/ | |
992 | { ZERO, ZERO }, /*ROMAN*/ | |
993 | { DEVANAGARI, DEV_MASK }, | |
994 | { BENGALI, BNG_MASK }, | |
995 | { TAMIL, TML_MASK }, | |
996 | { TELUGU, KND_MASK }, | |
997 | { BENGALI, BNG_MASK }, | |
998 | { ORIYA, ORI_MASK }, | |
999 | { KANNADA, KND_MASK }, | |
1000 | { GUJARATI, GJR_MASK }, | |
1001 | { GURMUKHI, PNJ_MASK }, | |
1002 | }; | |
1003 | ||
1004 | #define WRITE_TO_TARGET_TO_U(args,source,target,offsets,offset,targetUniChar,delta, err){\ | |
1005 | /* add offset to current Indic Block */ \ | |
1006 | if(targetUniChar>ASCII_END && \ | |
1007 | targetUniChar != ZWJ && \ | |
1008 | targetUniChar != ZWNJ && \ | |
1009 | targetUniChar != DANDA && \ | |
1010 | targetUniChar != DOUBLE_DANDA){ \ | |
1011 | \ | |
1012 | targetUniChar+=(uint16_t)(delta); \ | |
1013 | } \ | |
1014 | /* now write the targetUniChar */ \ | |
1015 | if(target<args->targetLimit){ \ | |
1016 | *(target)++ = (UChar)targetUniChar; \ | |
1017 | if(offsets){ \ | |
1018 | *(offsets)++ = (int32_t)(offset); \ | |
1019 | } \ | |
1020 | }else{ \ | |
1021 | args->converter->UCharErrorBuffer[args->converter->UCharErrorBufferLength++] = \ | |
1022 | (UChar)targetUniChar; \ | |
1023 | *err = U_BUFFER_OVERFLOW_ERROR; \ | |
1024 | } \ | |
1025 | } | |
1026 | ||
1027 | #define GET_MAPPING(sourceChar,targetUniChar,data){ \ | |
1028 | targetUniChar = toUnicodeTable[(sourceChar)] ; \ | |
1029 | /* is the code point valid in current script? */ \ | |
1030 | if(sourceChar> ASCII_END && \ | |
1031 | (validityTable[(uint8_t)targetUniChar] & data->currentMaskToUnicode)==0){ \ | |
1032 | /* Vocallic RR is assigne in ISCII Telugu and Unicode */ \ | |
1033 | if(data->currentDeltaToUnicode!=(TELUGU_DELTA) && \ | |
1034 | targetUniChar!=VOCALLIC_RR){ \ | |
1035 | targetUniChar=missingCharMarker; \ | |
1036 | } \ | |
1037 | } \ | |
1038 | } | |
1039 | ||
1040 | /*********** | |
1041 | * Rules for ISCII to Unicode converter | |
1042 | * ISCII is stateful encoding. To convert ISCII bytes to Unicode, | |
1043 | * which has both precomposed and decomposed forms characters | |
1044 | * pre-context and post-context need to be considered. | |
1045 | * | |
1046 | * Post context | |
1047 | * i) ATR : Attribute code is used to declare the font and script switching. | |
1048 | * Currently we only switch scripts and font codes consumed without generating an error | |
1049 | * ii) EXT : Extention code is used to declare switching to Sanskrit and for obscure, | |
1050 | * obsolete characters | |
1051 | * Pre context | |
1052 | * i) Halant: if preceeded by a halant then it is a explicit halant | |
1053 | * ii) Nukta : | |
1054 | * a) if preceeded by a halant then it is a soft halant | |
1055 | * b) if preceeded by specific consonants and the ligatures have pre-composed | |
1056 | * characters in Unicode then convert to pre-composed characters | |
1057 | * iii) Danda: If Danda is preceeded by a Danda then convert to Double Danda | |
1058 | * | |
1059 | */ | |
1060 | ||
1061 | static void | |
1062 | UConverter_toUnicode_ISCII_OFFSETS_LOGIC(UConverterToUnicodeArgs *args, | |
1063 | UErrorCode* err){ | |
1064 | const char *source = ( char *) args->source; | |
1065 | UChar *target = args->target; | |
1066 | const char *sourceLimit = args->sourceLimit; | |
1067 | const UChar* targetLimit = args->targetLimit; | |
1068 | uint32_t targetUniChar = 0x0000; | |
1069 | uint8_t sourceChar = 0x0000; | |
1070 | UConverterDataISCII* data; | |
b75a7d8f A |
1071 | UChar32* toUnicodeStatus=NULL; |
1072 | UChar* contextCharToUnicode = NULL; | |
1073 | ||
1074 | if ((args->converter == NULL) || (target < args->target) || (source < args->source)){ | |
1075 | *err = U_ILLEGAL_ARGUMENT_ERROR; | |
1076 | return; | |
1077 | } | |
1078 | ||
1079 | data = (UConverterDataISCII*)(args->converter->extraInfo); | |
1080 | contextCharToUnicode = &data->contextCharToUnicode; /* contains previous ISCII codepoint visited */ | |
1081 | toUnicodeStatus = (UChar32*)&args->converter->toUnicodeStatus;/* contains the mapping to Unicode of the above codepoint*/ | |
1082 | ||
1083 | while(source<sourceLimit){ | |
1084 | ||
1085 | targetUniChar = missingCharMarker; | |
1086 | ||
1087 | if(target < targetLimit){ | |
1088 | sourceChar = (unsigned char)*(source)++; | |
1089 | ||
1090 | /* look at the post-context preform special processing */ | |
1091 | if(*contextCharToUnicode==ATR){ | |
1092 | ||
1093 | /* If we have ATR in *contextCharToUnicode then we need to change our | |
1094 | * state to the Indic Script specified by sourceChar | |
1095 | */ | |
1096 | ||
1097 | /* check if the sourceChar is supported script range*/ | |
1098 | if((uint8_t)(PNJ-sourceChar)<=PNJ-DEV){ | |
1099 | data->currentDeltaToUnicode = | |
1100 | (uint16_t)(lookupTable[sourceChar & 0x0F][0] * DELTA); | |
1101 | data->currentMaskToUnicode = | |
1102 | lookupTable[sourceChar & 0x0F][1] ; | |
1103 | } | |
1104 | else if(sourceChar==DEF){ | |
1105 | /* switch back to default */ | |
1106 | data->currentDeltaToUnicode = data->defDeltaToUnicode; | |
1107 | data->currentMaskToUnicode = data->defMaskToUnicode; | |
1108 | }else{ | |
b75a7d8f A |
1109 | if((sourceChar >= 0x21 && sourceChar <= 0x3F)){ |
1110 | /* these are display codes consume and continue */ | |
1111 | }else{ | |
1112 | *err =U_ILLEGAL_CHAR_FOUND; | |
1113 | /* reset */ | |
1114 | *contextCharToUnicode=NO_CHAR_MARKER; | |
b75a7d8f A |
1115 | goto CALLBACK; |
1116 | } | |
b75a7d8f A |
1117 | } |
1118 | ||
1119 | /* reset */ | |
1120 | *contextCharToUnicode=NO_CHAR_MARKER; | |
1121 | ||
1122 | continue; | |
1123 | ||
1124 | }else if(*contextCharToUnicode==EXT){ | |
1125 | /* check if sourceChar is in 0xA1-0xEE range */ | |
1126 | if((uint8_t) (EXT_RANGE_END - sourceChar) <= (EXT_RANGE_END - EXT_RANGE_BEGIN)){ | |
1127 | /* We currently support only Anudatta and Devanagari abbreviation sign */ | |
1128 | if(sourceChar==0xBF || sourceChar == 0xB8){ | |
1129 | targetUniChar = (sourceChar==0xBF) ? DEV_ABBR_SIGN : DEV_ANUDATTA; | |
1130 | ||
1131 | /* find out if the mapping is valid in this state */ | |
1132 | if(validityTable[(uint8_t)targetUniChar] & data->currentMaskToUnicode){ | |
1133 | ||
1134 | *contextCharToUnicode= NO_CHAR_MARKER; | |
1135 | ||
1136 | /* write to target */ | |
1137 | WRITE_TO_TARGET_TO_U(args,source,target,args->offsets,(source-args->source -2), | |
1138 | targetUniChar,data->currentDeltaToUnicode,err); | |
1139 | ||
1140 | continue; | |
1141 | } | |
1142 | } | |
1143 | /* byte unit is unassigned */ | |
1144 | targetUniChar = missingCharMarker; | |
1145 | *err= U_INVALID_CHAR_FOUND; | |
b75a7d8f A |
1146 | }else{ |
1147 | /* only 0xA1 - 0xEE are legal after EXT char */ | |
1148 | *contextCharToUnicode= NO_CHAR_MARKER; | |
b75a7d8f A |
1149 | *err = U_ILLEGAL_CHAR_FOUND; |
1150 | } | |
1151 | goto CALLBACK; | |
1152 | }else if(*contextCharToUnicode==ISCII_INV){ | |
1153 | if(sourceChar==ISCII_HALANT){ | |
1154 | targetUniChar = 0x0020; /* replace with space accoding to Indic FAQ */ | |
1155 | }else{ | |
1156 | targetUniChar = ZWJ; | |
1157 | } | |
1158 | ||
1159 | /* write to target */ | |
1160 | WRITE_TO_TARGET_TO_U(args,source,target,args->offsets,(source-args->source -2), | |
1161 | targetUniChar,data->currentDeltaToUnicode,err); | |
1162 | /* reset */ | |
1163 | *contextCharToUnicode=NO_CHAR_MARKER; | |
1164 | } | |
1165 | ||
1166 | /* look at the pre-context and perform special processing */ | |
1167 | switch(sourceChar){ | |
1168 | case ISCII_INV: | |
1169 | case EXT: /*falls through*/ | |
1170 | case ATR: | |
1171 | *contextCharToUnicode = (UChar)sourceChar; | |
1172 | ||
1173 | if(*toUnicodeStatus != missingCharMarker){ | |
1174 | ||
1175 | WRITE_TO_TARGET_TO_U(args,source,target,args->offsets,(source-args->source -2), | |
1176 | *toUnicodeStatus,data->currentDeltaToUnicode,err); | |
1177 | *toUnicodeStatus = missingCharMarker; | |
1178 | } | |
1179 | continue; | |
1180 | case ISCII_DANDA: | |
1181 | /* handle double danda*/ | |
1182 | if(*contextCharToUnicode== ISCII_DANDA){ | |
1183 | targetUniChar = DOUBLE_DANDA; | |
1184 | /* clear the context */ | |
1185 | *contextCharToUnicode = NO_CHAR_MARKER; | |
1186 | *toUnicodeStatus = missingCharMarker; | |
1187 | }else{ | |
1188 | GET_MAPPING(sourceChar,targetUniChar,data); | |
1189 | *contextCharToUnicode = sourceChar; | |
1190 | } | |
1191 | break; | |
1192 | case ISCII_HALANT: | |
1193 | /* handle explicit halant */ | |
1194 | if(*contextCharToUnicode == ISCII_HALANT){ | |
1195 | targetUniChar = ZWNJ; | |
1196 | /* clear the context */ | |
1197 | *contextCharToUnicode = NO_CHAR_MARKER; | |
1198 | }else{ | |
1199 | GET_MAPPING(sourceChar,targetUniChar,data); | |
1200 | *contextCharToUnicode = sourceChar; | |
1201 | } | |
1202 | break; | |
1203 | case ISCII_NUKTA: | |
1204 | /* handle soft halant */ | |
1205 | if(*contextCharToUnicode == ISCII_HALANT){ | |
1206 | targetUniChar = ZWJ; | |
1207 | /* clear the context */ | |
1208 | *contextCharToUnicode = NO_CHAR_MARKER; | |
1209 | break; | |
1210 | }else{ | |
1211 | /* try to handle <CHAR> + ISCII_NUKTA special mappings */ | |
1212 | int i=1; | |
1213 | UBool found =FALSE; | |
1214 | for( ;i<nuktaSpecialCases[0][0];i++){ | |
1215 | if(nuktaSpecialCases[i][0]==(uint8_t)*contextCharToUnicode){ | |
1216 | targetUniChar=nuktaSpecialCases[i][1]; | |
1217 | found =TRUE; | |
1218 | break; | |
1219 | } | |
1220 | } | |
1221 | if(found){ | |
1222 | /* find out if the mapping is valid in this state */ | |
1223 | if(validityTable[(uint8_t)targetUniChar] & data->currentMaskToUnicode){ | |
1224 | targetUniChar += data->currentDeltaToUnicode ; | |
1225 | *contextCharToUnicode= NO_CHAR_MARKER; | |
1226 | *toUnicodeStatus = missingCharMarker; | |
1227 | break; | |
1228 | } | |
1229 | /* else fall through to default */ | |
1230 | } | |
1231 | /* else fall through to default */ | |
1232 | } | |
1233 | default: | |
1234 | GET_MAPPING(sourceChar,targetUniChar,data); | |
1235 | *contextCharToUnicode = sourceChar; | |
1236 | break; | |
1237 | } | |
1238 | ||
1239 | ||
1240 | if(*toUnicodeStatus != missingCharMarker){ | |
1241 | /* write the previously mapped codepoint */ | |
1242 | WRITE_TO_TARGET_TO_U(args,source,target,args->offsets,(source-args->source -2), | |
1243 | *toUnicodeStatus,data->currentDeltaToUnicode,err); | |
1244 | *toUnicodeStatus = missingCharMarker; | |
1245 | } | |
1246 | ||
1247 | ||
1248 | if(targetUniChar != missingCharMarker ){ | |
1249 | /* now save the targetUniChar for delayed write */ | |
1250 | *toUnicodeStatus = (UChar) targetUniChar; | |
1251 | }else{ | |
1252 | ||
1253 | /* we reach here only if targetUniChar == missingCharMarker | |
1254 | * so assign codes to reason and err | |
1255 | */ | |
b75a7d8f A |
1256 | *err = U_INVALID_CHAR_FOUND; |
1257 | CALLBACK: | |
374ca955 A |
1258 | args->converter->toUBytes[0] = (uint8_t) sourceChar; |
1259 | args->converter->toULength = 1; | |
1260 | break; | |
b75a7d8f A |
1261 | } |
1262 | ||
1263 | } | |
1264 | else{ | |
1265 | *err =U_BUFFER_OVERFLOW_ERROR; | |
1266 | break; | |
1267 | } | |
1268 | } | |
374ca955 A |
1269 | |
1270 | if(U_SUCCESS(*err) && args->flush && source == sourceLimit) { | |
1271 | /* end of the input stream */ | |
1272 | UConverter *cnv = args->converter; | |
1273 | ||
1274 | if(*contextCharToUnicode==ATR || *contextCharToUnicode==EXT || *contextCharToUnicode==ISCII_INV){ | |
1275 | /* set toUBytes[] */ | |
1276 | cnv->toUBytes[0] = (uint8_t)*contextCharToUnicode; | |
1277 | cnv->toULength = 1; | |
1278 | ||
1279 | /* avoid looping on truncated sequences */ | |
1280 | *contextCharToUnicode = NO_CHAR_MARKER; | |
b75a7d8f | 1281 | }else{ |
374ca955 A |
1282 | cnv->toULength = 0; |
1283 | } | |
1284 | ||
1285 | if(*toUnicodeStatus != missingCharMarker) { | |
1286 | /* output a remaining target character */ | |
b75a7d8f A |
1287 | WRITE_TO_TARGET_TO_U(args,source,target,args->offsets,(source - args->source -1), |
1288 | *toUnicodeStatus,data->currentDeltaToUnicode,err); | |
374ca955 | 1289 | *toUnicodeStatus = missingCharMarker; |
b75a7d8f | 1290 | } |
b75a7d8f | 1291 | } |
374ca955 | 1292 | |
b75a7d8f A |
1293 | args->target = target; |
1294 | args->source = source; | |
1295 | } | |
1296 | ||
1297 | /* structure for SafeClone calculations */ | |
374ca955 | 1298 | struct cloneISCIIStruct |
b75a7d8f A |
1299 | { |
1300 | UConverter cnv; | |
1301 | UConverterDataISCII mydata; | |
1302 | }; | |
1303 | ||
1304 | ||
1305 | static UConverter * | |
1306 | _ISCII_SafeClone(const UConverter *cnv, | |
1307 | void *stackBuffer, | |
1308 | int32_t *pBufferSize, | |
1309 | UErrorCode *status) | |
1310 | { | |
374ca955 A |
1311 | struct cloneISCIIStruct * localClone; |
1312 | int32_t bufferSizeNeeded = sizeof(struct cloneISCIIStruct); | |
b75a7d8f A |
1313 | |
1314 | if (U_FAILURE(*status)){ | |
1315 | return 0; | |
1316 | } | |
1317 | ||
1318 | if (*pBufferSize == 0){ /* 'preflighting' request - set needed size into *pBufferSize */ | |
1319 | *pBufferSize = bufferSizeNeeded; | |
1320 | return 0; | |
1321 | } | |
1322 | ||
374ca955 | 1323 | localClone = (struct cloneISCIIStruct *)stackBuffer; |
b75a7d8f | 1324 | uprv_memcpy(&localClone->cnv, cnv, sizeof(UConverter)); |
b75a7d8f A |
1325 | |
1326 | uprv_memcpy(&localClone->mydata, cnv->extraInfo, sizeof(UConverterDataISCII)); | |
1327 | localClone->cnv.extraInfo = &localClone->mydata; | |
1328 | localClone->cnv.isExtraLocal = TRUE; | |
1329 | ||
1330 | return &localClone->cnv; | |
1331 | } | |
1332 | ||
1333 | static void | |
1334 | _ISCIIGetUnicodeSet(const UConverter *cnv, | |
374ca955 | 1335 | USetAdder *sa, |
b75a7d8f A |
1336 | UConverterUnicodeSet which, |
1337 | UErrorCode *pErrorCode) | |
1338 | { | |
1339 | int32_t idx, script; | |
1340 | uint8_t mask; | |
1341 | ||
1342 | /* Since all ISCII versions allow switching to other ISCII | |
1343 | scripts, we add all roundtrippable characters to this set. */ | |
374ca955 | 1344 | sa->addRange(sa->set, 0, ASCII_END); |
b75a7d8f A |
1345 | for (script = DEVANAGARI; script <= MALAYALAM; script++) { |
1346 | mask = (uint8_t)(lookupInitialData[script][1]); | |
1347 | for (idx = 0; idx < DELTA; idx++) { | |
1348 | if (validityTable[idx] & mask) { | |
374ca955 | 1349 | sa->add(sa->set, idx + (script * DELTA) + INDIC_BLOCK_BEGIN); |
b75a7d8f A |
1350 | } |
1351 | } | |
1352 | } | |
374ca955 A |
1353 | sa->add(sa->set, DANDA); |
1354 | sa->add(sa->set, DOUBLE_DANDA); | |
1355 | sa->add(sa->set, ZWNJ); | |
1356 | sa->add(sa->set, ZWJ); | |
b75a7d8f A |
1357 | } |
1358 | ||
1359 | static const UConverterImpl _ISCIIImpl={ | |
1360 | ||
1361 | UCNV_ISCII, | |
1362 | ||
1363 | NULL, | |
1364 | NULL, | |
1365 | ||
1366 | _ISCIIOpen, | |
1367 | _ISCIIClose, | |
1368 | _ISCIIReset, | |
1369 | ||
1370 | UConverter_toUnicode_ISCII_OFFSETS_LOGIC, | |
1371 | UConverter_toUnicode_ISCII_OFFSETS_LOGIC, | |
1372 | UConverter_fromUnicode_ISCII_OFFSETS_LOGIC, | |
1373 | UConverter_fromUnicode_ISCII_OFFSETS_LOGIC, | |
1374 | NULL, | |
1375 | ||
1376 | NULL, | |
1377 | _ISCIIgetName, | |
1378 | NULL, | |
1379 | _ISCII_SafeClone, | |
1380 | _ISCIIGetUnicodeSet | |
1381 | }; | |
1382 | ||
1383 | static const UConverterStaticData _ISCIIStaticData={ | |
1384 | sizeof(UConverterStaticData), | |
1385 | "ISCII", | |
1386 | 0, | |
1387 | UCNV_IBM, | |
1388 | UCNV_ISCII, | |
1389 | 1, | |
1390 | 4, | |
1391 | { 0x1a, 0, 0, 0 }, | |
1392 | 0x1, | |
1393 | FALSE, | |
1394 | FALSE, | |
1395 | 0x0, | |
1396 | 0x0, | |
1397 | { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, /* reserved */ | |
1398 | ||
1399 | }; | |
1400 | ||
1401 | const UConverterSharedData _ISCIIData={ | |
1402 | sizeof(UConverterSharedData), | |
1403 | ~((uint32_t) 0), | |
1404 | NULL, | |
1405 | NULL, | |
1406 | &_ISCIIStaticData, | |
1407 | FALSE, | |
1408 | &_ISCIIImpl, | |
1409 | 0 | |
1410 | }; | |
1411 | ||
1412 | #endif /* #if !UCONFIG_NO_LEGACY_CONVERSION */ |