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