Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/jdk.charsets/share/classes/sun/nio/cs/ext/ISCII91.java
41161 views
1
/*
2
* Copyright (c) 2002, 2021, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
/*
27
*/
28
29
30
package sun.nio.cs.ext;
31
32
import java.nio.charset.Charset;
33
import java.nio.CharBuffer;
34
import java.nio.ByteBuffer;
35
import java.nio.charset.CharsetDecoder;
36
import java.nio.charset.CharsetEncoder;
37
import java.nio.charset.CoderResult;
38
import sun.nio.cs.Surrogate;
39
import sun.nio.cs.HistoricallyNamedCharset;
40
41
public class ISCII91 extends Charset implements HistoricallyNamedCharset
42
{
43
private static final char NUKTA_CHAR = '\u093c';
44
private static final char HALANT_CHAR = '\u094d';
45
private static final byte NO_CHAR = (byte)255;
46
47
public ISCII91() {
48
super("x-ISCII91", ExtendedCharsets.aliasesFor("x-ISCII91"));
49
}
50
51
public String historicalName() {
52
return "ISCII91";
53
}
54
55
public boolean contains(Charset cs) {
56
return ((cs.name().equals("US-ASCII"))
57
|| (cs instanceof ISCII91));
58
}
59
60
public CharsetDecoder newDecoder() {
61
return new Decoder(this);
62
}
63
64
public CharsetEncoder newEncoder() {
65
return new Encoder(this);
66
}
67
68
private static final char[] directMapTable = {
69
'\u0000', // ascii character
70
'\u0001', // ascii character
71
'\u0002', // ascii character
72
'\u0003', // ascii character
73
'\u0004', // ascii character
74
'\u0005', // ascii character
75
'\u0006', // ascii character
76
'\u0007', // ascii character
77
'\u0008', // ascii character
78
'\u0009', // ascii character
79
'\012', // ascii character
80
'\u000b', // ascii character
81
'\u000c', // ascii character
82
'\015', // ascii character
83
'\u000e', // ascii character
84
'\u000f', // ascii character
85
'\u0010', // ascii character
86
'\u0011', // ascii character
87
'\u0012', // ascii character
88
'\u0013', // ascii character
89
'\u0014', // ascii character
90
'\u0015', // ascii character
91
'\u0016', // ascii character
92
'\u0017', // ascii character
93
'\u0018', // ascii character
94
'\u0019', // ascii character
95
'\u001a', // ascii character
96
'\u001b', // ascii character
97
'\u001c', // ascii character
98
'\u001d', // ascii character
99
'\u001e', // ascii character
100
'\u001f', // ascii character
101
'\u0020', // ascii character
102
'\u0021', // ascii character
103
'\u0022', // ascii character
104
'\u0023', // ascii character
105
'\u0024', // ascii character
106
'\u0025', // ascii character
107
'\u0026', // ascii character
108
(char)0x0027, // '\u0027' control -- ascii character
109
'\u0028', // ascii character
110
'\u0029', // ascii character
111
'\u002a', // ascii character
112
'\u002b', // ascii character
113
'\u002c', // ascii character
114
'\u002d', // ascii character
115
'\u002e', // ascii character
116
'\u002f', // ascii character
117
'\u0030', // ascii character
118
'\u0031', // ascii character
119
'\u0032', // ascii character
120
'\u0033', // ascii character
121
'\u0034', // ascii character
122
'\u0035', // ascii character
123
'\u0036', // ascii character
124
'\u0037', // ascii character
125
'\u0038', // ascii character
126
'\u0039', // ascii character
127
'\u003a', // ascii character
128
'\u003b', // ascii character
129
'\u003c', // ascii character
130
'\u003d', // ascii character
131
'\u003e', // ascii character
132
'\u003f', // ascii character
133
'\u0040', // ascii character
134
'\u0041', // ascii character
135
'\u0042', // ascii character
136
'\u0043', // ascii character
137
'\u0044', // ascii character
138
'\u0045', // ascii character
139
'\u0046', // ascii character
140
'\u0047', // ascii character
141
'\u0048', // ascii character
142
'\u0049', // ascii character
143
'\u004a', // ascii character
144
'\u004b', // ascii character
145
'\u004c', // ascii character
146
'\u004d', // ascii character
147
'\u004e', // ascii character
148
'\u004f', // ascii character
149
'\u0050', // ascii character
150
'\u0051', // ascii character
151
'\u0052', // ascii character
152
'\u0053', // ascii character
153
'\u0054', // ascii character
154
'\u0055', // ascii character
155
'\u0056', // ascii character
156
'\u0057', // ascii character
157
'\u0058', // ascii character
158
'\u0059', // ascii character
159
'\u005a', // ascii character
160
'\u005b', // ascii character
161
'\\',// '\u005c' -- ascii character
162
'\u005d', // ascii character
163
'\u005e', // ascii character
164
'\u005f', // ascii character
165
'\u0060', // ascii character
166
'\u0061', // ascii character
167
'\u0062', // ascii character
168
'\u0063', // ascii character
169
'\u0064', // ascii character
170
'\u0065', // ascii character
171
'\u0066', // ascii character
172
'\u0067', // ascii character
173
'\u0068', // ascii character
174
'\u0069', // ascii character
175
'\u006a', // ascii character
176
'\u006b', // ascii character
177
'\u006c', // ascii character
178
'\u006d', // ascii character
179
'\u006e', // ascii character
180
'\u006f', // ascii character
181
'\u0070', // ascii character
182
'\u0071', // ascii character
183
'\u0072', // ascii character
184
'\u0073', // ascii character
185
'\u0074', // ascii character
186
'\u0075', // ascii character
187
'\u0076', // ascii character
188
'\u0077', // ascii character
189
'\u0078', // ascii character
190
'\u0079', // ascii character
191
'\u007a', // ascii character
192
'\u007b', // ascii character
193
'\u007c', // ascii character
194
'\u007d', // ascii character
195
'\u007e', // ascii character
196
'\u007f', // ascii character
197
'\uffff', // unknown character
198
'\uffff', // unknown character
199
'\uffff', // unknown character
200
'\uffff', // unknown character
201
'\uffff', // unknown character
202
'\uffff', // unknown character
203
'\uffff', // unknown character
204
'\uffff', // unknown character
205
'\uffff', // unknown character
206
'\uffff', // unknown character
207
'\uffff', // unknown character
208
'\uffff', // unknown character
209
'\uffff', // unknown character
210
'\uffff', // unknown character
211
'\uffff', // unknown character
212
'\uffff', // unknown character
213
'\uffff', // unknown character
214
'\uffff', // unknown character
215
'\uffff', // unknown character
216
'\uffff', // unknown character
217
'\uffff', // unknown character
218
'\uffff', // unknown character
219
'\uffff', // unknown character
220
'\uffff', // unknown character
221
'\uffff', // unknown character
222
'\uffff', // unknown character
223
'\uffff', // unknown character
224
'\uffff', // unknown character
225
'\uffff', // unknown character
226
'\uffff', // unknown character
227
'\uffff', // unknown character
228
'\uffff', // unknown character
229
'\u0901', // a1 -- Vowel-modifier CHANDRABINDU
230
'\u0902', // a2 -- Vowel-modifier ANUSWAR
231
'\u0903', // a3 -- Vowel-modifier VISARG
232
233
'\u0905', // a4 -- Vowel A
234
'\u0906', // a5 -- Vowel AA
235
'\u0907', // a6 -- Vowel I
236
'\u0908', // a7 -- Vowel II
237
'\u0909', // a8 -- Vowel U
238
'\u090a', // a9 -- Vowel UU
239
'\u090b', // aa -- Vowel RI
240
'\u090e', // ab -- Vowel E ( Southern Scripts )
241
'\u090f', // ac -- Vowel EY
242
'\u0910', // ad -- Vowel AI
243
'\u090d', // ae -- Vowel AYE ( Devanagari Script )
244
'\u0912', // af -- Vowel O ( Southern Scripts )
245
'\u0913', // b0 -- Vowel OW
246
'\u0914', // b1 -- Vowel AU
247
'\u0911', // b2 -- Vowel AWE ( Devanagari Script )
248
'\u0915', // b3 -- Consonant KA
249
'\u0916', // b4 -- Consonant KHA
250
'\u0917', // b5 -- Consonant GA
251
'\u0918', // b6 -- Consonant GHA
252
'\u0919', // b7 -- Consonant NGA
253
'\u091a', // b8 -- Consonant CHA
254
'\u091b', // b9 -- Consonant CHHA
255
'\u091c', // ba -- Consonant JA
256
'\u091d', // bb -- Consonant JHA
257
'\u091e', // bc -- Consonant JNA
258
'\u091f', // bd -- Consonant Hard TA
259
'\u0920', // be -- Consonant Hard THA
260
'\u0921', // bf -- Consonant Hard DA
261
'\u0922', // c0 -- Consonant Hard DHA
262
'\u0923', // c1 -- Consonant Hard NA
263
'\u0924', // c2 -- Consonant Soft TA
264
'\u0925', // c3 -- Consonant Soft THA
265
'\u0926', // c4 -- Consonant Soft DA
266
'\u0927', // c5 -- Consonant Soft DHA
267
'\u0928', // c6 -- Consonant Soft NA
268
'\u0929', // c7 -- Consonant NA ( Tamil )
269
'\u092a', // c8 -- Consonant PA
270
'\u092b', // c9 -- Consonant PHA
271
'\u092c', // ca -- Consonant BA
272
'\u092d', // cb -- Consonant BHA
273
'\u092e', // cc -- Consonant MA
274
'\u092f', // cd -- Consonant YA
275
'\u095f', // ce -- Consonant JYA ( Bengali, Assamese & Oriya )
276
'\u0930', // cf -- Consonant RA
277
'\u0931', // d0 -- Consonant Hard RA ( Southern Scripts )
278
'\u0932', // d1 -- Consonant LA
279
'\u0933', // d2 -- Consonant Hard LA
280
'\u0934', // d3 -- Consonant ZHA ( Tamil & Malayalam )
281
'\u0935', // d4 -- Consonant VA
282
'\u0936', // d5 -- Consonant SHA
283
'\u0937', // d6 -- Consonant Hard SHA
284
'\u0938', // d7 -- Consonant SA
285
'\u0939', // d8 -- Consonant HA
286
287
'\u200d', // d9 -- Consonant INVISIBLE
288
'\u093e', // da -- Vowel Sign AA
289
290
'\u093f', // db -- Vowel Sign I
291
'\u0940', // dc -- Vowel Sign II
292
'\u0941', // dd -- Vowel Sign U
293
'\u0942', // de -- Vowel Sign UU
294
'\u0943', // df -- Vowel Sign RI
295
'\u0946', // e0 -- Vowel Sign E ( Southern Scripts )
296
'\u0947', // e1 -- Vowel Sign EY
297
'\u0948', // e2 -- Vowel Sign AI
298
'\u0945', // e3 -- Vowel Sign AYE ( Devanagari Script )
299
'\u094a', // e4 -- Vowel Sign O ( Southern Scripts )
300
'\u094b', // e5 -- Vowel Sign OW
301
'\u094c', // e6 -- Vowel Sign AU
302
'\u0949', // e7 -- Vowel Sign AWE ( Devanagari Script )
303
304
'\u094d', // e8 -- Vowel Omission Sign ( Halant )
305
'\u093c', // e9 -- Diacritic Sign ( Nukta )
306
'\u0964', // ea -- Full Stop ( Viram, Northern Scripts )
307
308
'\uffff', // eb -- This position shall not be used
309
'\uffff', // ec -- This position shall not be used
310
'\uffff', // ed -- This position shall not be used
311
'\uffff', // ee -- This position shall not be used
312
313
'\ufffd', // ef -- Attribute Code ( ATR )
314
'\ufffd', // f0 -- Extension Code ( EXT )
315
316
'\u0966', // f1 -- Digit 0
317
'\u0967', // f2 -- Digit 1
318
'\u0968', // f3 -- Digit 2
319
'\u0969', // f4 -- Digit 3
320
'\u096a', // f5 -- Digit 4
321
'\u096b', // f6 -- Digit 5
322
'\u096c', // f7 -- Digit 6
323
'\u096d', // f8 -- Digit 7
324
'\u096e', // f9 -- Digit 8
325
'\u096f', // fa -- Digit 9
326
327
'\uffff', // fb -- This position shall not be used
328
'\uffff', // fc -- This position shall not be used
329
'\uffff', // fd -- This position shall not be used
330
'\uffff', // fe -- This position shall not be used
331
'\uffff' // ff -- This position shall not be used
332
}; //end of table definition
333
334
private static final byte[] encoderMappingTable = {
335
NO_CHAR,NO_CHAR, //0900 <reserved>
336
(byte)161,NO_CHAR, //0901 -- DEVANAGARI SIGN CANDRABINDU = anunasika
337
(byte)162,NO_CHAR, //0902 -- DEVANAGARI SIGN ANUSVARA = bindu
338
(byte)163,NO_CHAR, //0903 -- DEVANAGARI SIGN VISARGA
339
NO_CHAR,NO_CHAR, //0904 <reserved>
340
(byte)164,NO_CHAR, //0905 -- DEVANAGARI LETTER A
341
(byte)165,NO_CHAR, //0906 -- DEVANAGARI LETTER AA
342
(byte)166,NO_CHAR, //0907 -- DEVANAGARI LETTER I
343
(byte)167,NO_CHAR, //0908 -- DEVANAGARI LETTER II
344
(byte)168,NO_CHAR, //0909 -- DEVANAGARI LETTER U
345
(byte)169,NO_CHAR, //090a -- DEVANAGARI LETTER UU
346
(byte)170,NO_CHAR, //090b -- DEVANAGARI LETTER VOCALIC R
347
(byte)166,(byte)233, //090c -- DEVANAGARI LETTER VOVALIC L
348
(byte)174,NO_CHAR, //090d -- DEVANAGARI LETTER CANDRA E
349
(byte)171,NO_CHAR, //090e -- DEVANAGARI LETTER SHORT E
350
(byte)172,NO_CHAR, //090f -- DEVANAGARI LETTER E
351
(byte)173,NO_CHAR, //0910 -- DEVANAGARI LETTER AI
352
(byte)178,NO_CHAR, //0911 -- DEVANAGARI LETTER CANDRA O
353
(byte)175,NO_CHAR, //0912 -- DEVANAGARI LETTER SHORT O
354
(byte)176,NO_CHAR, //0913 -- DEVANAGARI LETTER O
355
(byte)177,NO_CHAR, //0914 -- DEVANAGARI LETTER AU
356
(byte)179,NO_CHAR, //0915 -- DEVANAGARI LETTER KA
357
(byte)180,NO_CHAR, //0916 -- DEVANAGARI LETTER KHA
358
(byte)181,NO_CHAR, //0917 -- DEVANAGARI LETTER GA
359
(byte)182,NO_CHAR, //0918 -- DEVANAGARI LETTER GHA
360
(byte)183,NO_CHAR, //0919 -- DEVANAGARI LETTER NGA
361
(byte)184,NO_CHAR, //091a -- DEVANAGARI LETTER CA
362
(byte)185,NO_CHAR, //091b -- DEVANAGARI LETTER CHA
363
(byte)186,NO_CHAR, //091c -- DEVANAGARI LETTER JA
364
(byte)187,NO_CHAR, //091d -- DEVANAGARI LETTER JHA
365
(byte)188,NO_CHAR, //091e -- DEVANAGARI LETTER NYA
366
(byte)189,NO_CHAR, //091f -- DEVANAGARI LETTER TTA
367
(byte)190,NO_CHAR, //0920 -- DEVANAGARI LETTER TTHA
368
(byte)191,NO_CHAR, //0921 -- DEVANAGARI LETTER DDA
369
(byte)192,NO_CHAR, //0922 -- DEVANAGARI LETTER DDHA
370
(byte)193,NO_CHAR, //0923 -- DEVANAGARI LETTER NNA
371
(byte)194,NO_CHAR, //0924 -- DEVANAGARI LETTER TA
372
(byte)195,NO_CHAR, //0925 -- DEVANAGARI LETTER THA
373
(byte)196,NO_CHAR, //0926 -- DEVANAGARI LETTER DA
374
(byte)197,NO_CHAR, //0927 -- DEVANAGARI LETTER DHA
375
(byte)198,NO_CHAR, //0928 -- DEVANAGARI LETTER NA
376
(byte)199,NO_CHAR, //0929 -- DEVANAGARI LETTER NNNA <=> 0928 + 093C
377
(byte)200,NO_CHAR, //092a -- DEVANAGARI LETTER PA
378
(byte)201,NO_CHAR, //092b -- DEVANAGARI LETTER PHA
379
(byte)202,NO_CHAR, //092c -- DEVANAGARI LETTER BA
380
(byte)203,NO_CHAR, //092d -- DEVANAGARI LETTER BHA
381
(byte)204,NO_CHAR, //092e -- DEVANAGARI LETTER MA
382
(byte)205,NO_CHAR, //092f -- DEVANAGARI LETTER YA
383
(byte)207,NO_CHAR, //0930 -- DEVANAGARI LETTER RA
384
(byte)208,NO_CHAR, //0931 -- DEVANAGARI LETTER RRA <=> 0930 + 093C
385
(byte)209,NO_CHAR, //0932 -- DEVANAGARI LETTER LA
386
(byte)210,NO_CHAR, //0933 -- DEVANAGARI LETTER LLA
387
(byte)211,NO_CHAR, //0934 -- DEVANAGARI LETTER LLLA <=> 0933 + 093C
388
(byte)212,NO_CHAR, //0935 -- DEVANAGARI LETTER VA
389
(byte)213,NO_CHAR, //0936 -- DEVANAGARI LETTER SHA
390
(byte)214,NO_CHAR, //0937 -- DEVANAGARI LETTER SSA
391
(byte)215,NO_CHAR, //0938 -- DEVANAGARI LETTER SA
392
(byte)216,NO_CHAR, //0939 -- DEVANAGARI LETTER HA
393
NO_CHAR,NO_CHAR, //093a <reserved>
394
NO_CHAR,NO_CHAR, //093b <reserved>
395
(byte)233,NO_CHAR, //093c -- DEVANAGARI SIGN NUKTA
396
(byte)234,(byte)233, //093d -- DEVANAGARI SIGN AVAGRAHA
397
(byte)218,NO_CHAR, //093e -- DEVANAGARI VOWEL SIGN AA
398
(byte)219,NO_CHAR, //093f -- DEVANAGARI VOWEL SIGN I
399
(byte)220,NO_CHAR, //0940 -- DEVANAGARI VOWEL SIGN II
400
(byte)221,NO_CHAR, //0941 -- DEVANAGARI VOWEL SIGN U
401
(byte)222,NO_CHAR, //0942 -- DEVANAGARI VOWEL SIGN UU
402
(byte)223,NO_CHAR, //0943 -- DEVANAGARI VOWEL SIGN VOCALIC R
403
(byte)223,(byte)233, //0944 -- DEVANAGARI VOWEL SIGN VOCALIC RR
404
(byte)227,NO_CHAR, //0945 -- DEVANAGARI VOWEL SIGN CANDRA E
405
(byte)224,NO_CHAR, //0946 -- DEVANAGARI VOWEL SIGN SHORT E
406
(byte)225,NO_CHAR, //0947 -- DEVANAGARI VOWEL SIGN E
407
(byte)226,NO_CHAR, //0948 -- DEVANAGARI VOWEL SIGN AI
408
(byte)231,NO_CHAR, //0949 -- DEVANAGARI VOWEL SIGN CANDRA O
409
(byte)228,NO_CHAR, //094a -- DEVANAGARI VOWEL SIGN SHORT O
410
(byte)229,NO_CHAR, //094b -- DEVANAGARI VOWEL SIGN O
411
(byte)230,NO_CHAR, //094c -- DEVANAGARI VOWEL SIGN AU
412
(byte)232,NO_CHAR, //094d -- DEVANAGARI SIGN VIRAMA ( halant )
413
NO_CHAR,NO_CHAR, //094e <reserved>
414
NO_CHAR,NO_CHAR, //094f <reserved>
415
(byte)161,(byte)233, //0950 -- DEVANAGARI OM
416
(byte)240,(byte)181, //0951 -- DEVANAGARI STRESS SIGN UDATTA
417
(byte)240,(byte)184, //0952 -- DEVANAGARI STRESS SIGN ANUDATTA
418
(byte)254,NO_CHAR, //0953 -- DEVANAGARI GRAVE ACCENT || MISSING
419
(byte)254,NO_CHAR, //0954 -- DEVANAGARI ACUTE ACCENT || MISSING
420
NO_CHAR,NO_CHAR, //0955 <reserved>
421
NO_CHAR,NO_CHAR, //0956 <reserved>
422
NO_CHAR,NO_CHAR, //0957 <reserved>
423
(byte)179,(byte)233, //0958 -- DEVANAGARI LETTER QA <=> 0915 + 093C
424
(byte)180,(byte)233, //0959 -- DEVANAGARI LETTER KHHA <=> 0916 + 093C
425
(byte)181,(byte)233, //095a -- DEVANAGARI LETTER GHHA <=> 0917 + 093C
426
(byte)186,(byte)233, //095b -- DEVANAGARI LETTER ZA <=> 091C + 093C
427
(byte)191,(byte)233, //095c -- DEVANAGARI LETTER DDDHA <=> 0921 + 093C
428
(byte)192,(byte)233, //095d -- DEVANAGARI LETTER RHA <=> 0922 + 093C
429
(byte)201,(byte)233, //095e -- DEVANAGARI LETTER FA <=> 092B + 093C
430
(byte)206,NO_CHAR, //095f -- DEVANAGARI LETTER YYA <=> 092F + 093C
431
(byte)170,(byte)233, //0960 -- DEVANAGARI LETTER VOCALIC RR
432
(byte)167,(byte)233, //0961 -- DEVANAGARI LETTER VOCALIC LL
433
(byte)219,(byte)233, //0962 -- DEVANAGARI VOWEL SIGN VOCALIC L
434
(byte)220,(byte)233, //0963 -- DEVANAGARI VOWEL SIGN VOCALIC LL
435
(byte)234,NO_CHAR, //0964 -- DEVANAGARI DANDA ( phrase separator )
436
(byte)234,(byte)234, //0965 -- DEVANAGARI DOUBLE DANDA
437
(byte)241,NO_CHAR, //0966 -- DEVANAGARI DIGIT ZERO
438
(byte)242,NO_CHAR, //0967 -- DEVANAGARI DIGIT ONE
439
(byte)243,NO_CHAR, //0968 -- DEVANAGARI DIGIT TWO
440
(byte)244,NO_CHAR, //0969 -- DEVANAGARI DIGIT THREE
441
(byte)245,NO_CHAR, //096a -- DEVANAGARI DIGIT FOUR
442
(byte)246,NO_CHAR, //096b -- DEVANAGARI DIGIT FIVE
443
(byte)247,NO_CHAR, //096c -- DEVANAGARI DIGIT SIX
444
(byte)248,NO_CHAR, //096d -- DEVANAGARI DIGIT SEVEN
445
(byte)249,NO_CHAR, //096e -- DEVANAGARI DIGIT EIGHT
446
(byte)250,NO_CHAR, //096f -- DEVANAGARI DIGIT NINE
447
(byte)240,(byte)191, //0970 -- DEVANAGARI ABBREVIATION SIGN
448
NO_CHAR,NO_CHAR, //0971 -- reserved
449
NO_CHAR,NO_CHAR, //0972 -- reserved
450
NO_CHAR,NO_CHAR, //0973 -- reserved
451
NO_CHAR,NO_CHAR, //0974 -- reserved
452
NO_CHAR,NO_CHAR, //0975 -- reserved
453
NO_CHAR,NO_CHAR, //0976 -- reserved
454
NO_CHAR,NO_CHAR, //0977 -- reserved
455
NO_CHAR,NO_CHAR, //0978 -- reserved
456
NO_CHAR,NO_CHAR, //0979 -- reserved
457
NO_CHAR,NO_CHAR, //097a -- reserved
458
NO_CHAR,NO_CHAR, //097b -- reserved
459
NO_CHAR,NO_CHAR, //097c -- reserved
460
NO_CHAR,NO_CHAR, //097d -- reserved
461
NO_CHAR,NO_CHAR, //097e -- reserved
462
NO_CHAR,NO_CHAR //097f -- reserved
463
}; //end of table definition
464
465
private static class Decoder extends CharsetDecoder {
466
467
private static final char ZWNJ_CHAR = '\u200c';
468
private static final char ZWJ_CHAR = '\u200d';
469
private static final char INVALID_CHAR = '\uffff';
470
471
private char contextChar = INVALID_CHAR;
472
private boolean needFlushing = false;
473
474
475
private Decoder(Charset cs) {
476
super(cs, 1.0f, 1.0f);
477
}
478
479
protected CoderResult implFlush(CharBuffer out) {
480
if(needFlushing) {
481
if (out.remaining() < 1) {
482
return CoderResult.OVERFLOW;
483
} else {
484
out.put(contextChar);
485
}
486
}
487
contextChar = INVALID_CHAR;
488
needFlushing = false;
489
return CoderResult.UNDERFLOW;
490
}
491
492
/* Rules:
493
* 1) ATR,EXT,following character to be replaced with '\ufffd'
494
* 2) Halant + Halant => '\u094d' (Virama) + '\u200c'(ZWNJ)
495
* 3) Halant + Nukta => '\u094d' (Virama) + '\u200d'(ZWJ)
496
*/
497
private CoderResult decodeArrayLoop(ByteBuffer src,
498
CharBuffer dst)
499
{
500
byte[] sa = src.array();
501
int sp = src.arrayOffset() + src.position();
502
int sl = src.arrayOffset() + src.limit();
503
504
char[] da = dst.array();
505
int dp = dst.arrayOffset() + dst.position();
506
int dl = dst.arrayOffset() + dst.limit();
507
508
try {
509
while (sp < sl) {
510
int index = sa[sp];
511
index = ( index < 0 )? ( index + 255 ):index;
512
char currentChar = directMapTable[index];
513
514
// if the contextChar is either ATR || EXT
515
// set the output to '\ufffd'
516
if(contextChar == '\ufffd') {
517
if (dl - dp < 1)
518
return CoderResult.OVERFLOW;
519
da[dp++] = '\ufffd';
520
contextChar = INVALID_CHAR;
521
needFlushing = false;
522
sp++;
523
continue;
524
}
525
526
switch(currentChar) {
527
case '\u0901':
528
case '\u0907':
529
case '\u0908':
530
case '\u090b':
531
case '\u093f':
532
case '\u0940':
533
case '\u0943':
534
case '\u0964':
535
if(needFlushing) {
536
if (dl - dp < 1)
537
return CoderResult.OVERFLOW;
538
da[dp++] = contextChar;
539
contextChar = currentChar;
540
sp++;
541
continue;
542
}
543
contextChar = currentChar;
544
needFlushing = true;
545
sp++;
546
continue;
547
case NUKTA_CHAR:
548
if (dl - dp < 1)
549
return CoderResult.OVERFLOW;
550
switch(contextChar) {
551
case '\u0901':
552
da[dp++] = '\u0950';
553
break;
554
case '\u0907':
555
da[dp++] = '\u090c';
556
break;
557
case '\u0908':
558
da[dp++] = '\u0961';
559
break;
560
case '\u090b':
561
da[dp++] = '\u0960';
562
break;
563
case '\u093f':
564
da[dp++] = '\u0962';
565
break;
566
case '\u0940':
567
da[dp++] = '\u0963';
568
break;
569
case '\u0943':
570
da[dp++] = '\u0944';
571
break;
572
case '\u0964':
573
da[dp++] = '\u093d';
574
break;
575
case HALANT_CHAR:
576
if(needFlushing) {
577
da[dp++] = contextChar;
578
contextChar = currentChar;
579
sp++;
580
continue;
581
}
582
da[dp++] = ZWJ_CHAR;
583
break;
584
default:
585
if(needFlushing) {
586
da[dp++] = contextChar;
587
contextChar = currentChar;
588
sp++;
589
continue;
590
}
591
da[dp++] = NUKTA_CHAR;
592
}
593
break;
594
case HALANT_CHAR:
595
if (dl - dp < 1)
596
return CoderResult.OVERFLOW;
597
if(needFlushing) {
598
da[dp++] = contextChar;
599
contextChar = currentChar;
600
sp++;
601
continue;
602
}
603
if(contextChar == HALANT_CHAR) {
604
da[dp++] = ZWNJ_CHAR;
605
break;
606
}
607
da[dp++] = HALANT_CHAR;
608
break;
609
case INVALID_CHAR:
610
if(needFlushing) {
611
if (dl - dp < 1)
612
return CoderResult.OVERFLOW;
613
da[dp++] = contextChar;
614
contextChar = currentChar;
615
sp++;
616
continue;
617
}
618
return CoderResult.unmappableForLength(1);
619
default:
620
if (dl - dp < 1)
621
return CoderResult.OVERFLOW;
622
if(needFlushing) {
623
da[dp++] = contextChar;
624
contextChar = currentChar;
625
sp++;
626
continue;
627
}
628
da[dp++] = currentChar;
629
break;
630
}//end switch
631
632
contextChar = currentChar;
633
needFlushing = false;
634
sp++;
635
}
636
return CoderResult.UNDERFLOW;
637
} finally {
638
src.position(sp - src.arrayOffset());
639
dst.position(dp - dst.arrayOffset());
640
}
641
}
642
643
private CoderResult decodeBufferLoop(ByteBuffer src,
644
CharBuffer dst)
645
{
646
int mark = src.position();
647
648
try {
649
while (src.hasRemaining()) {
650
int index = src.get();
651
index = ( index < 0 )? ( index + 255 ):index;
652
char currentChar = directMapTable[index];
653
654
// if the contextChar is either ATR || EXT
655
// set the output to '\ufffd'
656
if(contextChar == '\ufffd') {
657
if (dst.remaining() < 1)
658
return CoderResult.OVERFLOW;
659
dst.put('\ufffd');
660
contextChar = INVALID_CHAR;
661
needFlushing = false;
662
mark++;
663
continue;
664
}
665
666
switch(currentChar) {
667
case '\u0901':
668
case '\u0907':
669
case '\u0908':
670
case '\u090b':
671
case '\u093f':
672
case '\u0940':
673
case '\u0943':
674
case '\u0964':
675
if(needFlushing) {
676
if (dst.remaining() < 1)
677
return CoderResult.OVERFLOW;
678
dst.put(contextChar);
679
contextChar = currentChar;
680
mark++;
681
continue;
682
}
683
contextChar = currentChar;
684
needFlushing = true;
685
mark++;
686
continue;
687
case NUKTA_CHAR:
688
if (dst.remaining() < 1)
689
return CoderResult.OVERFLOW;
690
switch(contextChar) {
691
case '\u0901':
692
dst.put('\u0950');
693
break;
694
case '\u0907':
695
dst.put('\u090c');
696
break;
697
case '\u0908':
698
dst.put('\u0961');
699
break;
700
case '\u090b':
701
dst.put('\u0960');
702
break;
703
case '\u093f':
704
dst.put('\u0962');
705
break;
706
case '\u0940':
707
dst.put('\u0963');
708
break;
709
case '\u0943':
710
dst.put('\u0944');
711
break;
712
case '\u0964':
713
dst.put('\u093d');
714
break;
715
case HALANT_CHAR:
716
if(needFlushing) {
717
dst.put(contextChar);
718
contextChar = currentChar;
719
mark++;
720
continue;
721
}
722
dst.put(ZWJ_CHAR);
723
break;
724
default:
725
if(needFlushing) {
726
dst.put(contextChar);
727
contextChar = currentChar;
728
mark++;
729
continue;
730
}
731
dst.put(NUKTA_CHAR);
732
}
733
break;
734
case HALANT_CHAR:
735
if (dst.remaining() < 1)
736
return CoderResult.OVERFLOW;
737
if(needFlushing) {
738
dst.put(contextChar);
739
contextChar = currentChar;
740
mark++;
741
continue;
742
}
743
if(contextChar == HALANT_CHAR) {
744
dst.put(ZWNJ_CHAR);
745
break;
746
}
747
dst.put(HALANT_CHAR);
748
break;
749
case INVALID_CHAR:
750
if(needFlushing) {
751
if (dst.remaining() < 1)
752
return CoderResult.OVERFLOW;
753
dst.put(contextChar);
754
contextChar = currentChar;
755
mark++;
756
continue;
757
}
758
return CoderResult.unmappableForLength(1);
759
default:
760
if (dst.remaining() < 1)
761
return CoderResult.OVERFLOW;
762
if(needFlushing) {
763
dst.put(contextChar);
764
contextChar = currentChar;
765
mark++;
766
continue;
767
}
768
dst.put(currentChar);
769
break;
770
}//end switch
771
contextChar = currentChar;
772
needFlushing = false;
773
mark++;
774
}
775
return CoderResult.UNDERFLOW;
776
} finally {
777
src.position(mark);
778
}
779
}
780
781
protected CoderResult decodeLoop(ByteBuffer src,
782
CharBuffer dst)
783
{
784
if (src.hasArray() && dst.hasArray())
785
return decodeArrayLoop(src, dst);
786
else
787
return decodeBufferLoop(src, dst);
788
}
789
}
790
791
private static class Encoder extends CharsetEncoder {
792
793
private static final byte NO_CHAR = (byte)255;
794
795
//private static CharToByteISCII91 c2b = new CharToByteISCII91();
796
//private static final byte[] directMapTable = c2b.getISCIIEncoderMap();
797
798
private final Surrogate.Parser sgp = new Surrogate.Parser();
799
800
private Encoder(Charset cs) {
801
super(cs, 2.0f, 2.0f);
802
}
803
804
public boolean canEncode(char ch) {
805
//check for Devanagari range,ZWJ,ZWNJ and ASCII range.
806
return ((ch >= '\u0900' && ch <= '\u097f' &&
807
encoderMappingTable[2*(ch-'\u0900')] != NO_CHAR) ||
808
(ch == '\u200d') ||
809
(ch == '\u200c') ||
810
(ch <= '\u007f'));
811
}
812
813
814
private CoderResult encodeArrayLoop(CharBuffer src,
815
ByteBuffer dst)
816
{
817
char[] sa = src.array();
818
int sp = src.arrayOffset() + src.position();
819
int sl = src.arrayOffset() + src.limit();
820
821
byte[] da = dst.array();
822
int dp = dst.arrayOffset() + dst.position();
823
int dl = dst.arrayOffset() + dst.limit();
824
825
try {
826
char inputChar;
827
while (sp < sl) {
828
int index = Integer.MIN_VALUE;
829
inputChar = sa[sp];
830
831
if (inputChar >= 0x0000 && inputChar <= 0x007f) {
832
if (dl - dp < 1)
833
return CoderResult.OVERFLOW;
834
da[dp++] = (byte) inputChar;
835
sp++;
836
continue;
837
}
838
839
// if inputChar == ZWJ replace it with halant
840
// if inputChar == ZWNJ replace it with Nukta
841
842
if (inputChar == 0x200c) {
843
inputChar = HALANT_CHAR;
844
}
845
else if (inputChar == 0x200d) {
846
inputChar = NUKTA_CHAR;
847
}
848
849
if (inputChar >= 0x0900 && inputChar <= 0x097f) {
850
index = ((int)(inputChar) - 0x0900)*2;
851
}
852
853
if (Character.isSurrogate(inputChar)) {
854
if (sgp.parse(inputChar, sa, sp, sl) < 0)
855
return sgp.error();
856
return sgp.unmappableResult();
857
}
858
859
if (index == Integer.MIN_VALUE ||
860
encoderMappingTable[index] == NO_CHAR) {
861
return CoderResult.unmappableForLength(1);
862
} else {
863
if(encoderMappingTable[index + 1] == NO_CHAR) {
864
if(dl - dp < 1)
865
return CoderResult.OVERFLOW;
866
da[dp++] = encoderMappingTable[index];
867
} else {
868
if(dl - dp < 2)
869
return CoderResult.OVERFLOW;
870
da[dp++] = encoderMappingTable[index];
871
da[dp++] = encoderMappingTable[index + 1];
872
}
873
sp++;
874
}
875
}
876
return CoderResult.UNDERFLOW;
877
} finally {
878
src.position(sp - src.arrayOffset());
879
dst.position(dp - dst.arrayOffset());
880
}
881
}
882
883
private CoderResult encodeBufferLoop(CharBuffer src,
884
ByteBuffer dst)
885
{
886
int mark = src.position();
887
888
try {
889
char inputChar;
890
while (src.hasRemaining()) {
891
int index = Integer.MIN_VALUE;
892
inputChar = src.get();
893
894
if (inputChar >= 0x0000 && inputChar <= 0x007f) {
895
if (dst.remaining() < 1)
896
return CoderResult.OVERFLOW;
897
dst.put((byte) inputChar);
898
mark++;
899
continue;
900
}
901
902
// if inputChar == ZWJ replace it with halant
903
// if inputChar == ZWNJ replace it with Nukta
904
905
if (inputChar == 0x200c) {
906
inputChar = HALANT_CHAR;
907
}
908
else if (inputChar == 0x200d) {
909
inputChar = NUKTA_CHAR;
910
}
911
912
if (inputChar >= 0x0900 && inputChar <= 0x097f) {
913
index = ((int)(inputChar) - 0x0900)*2;
914
}
915
916
if (Character.isSurrogate(inputChar)) {
917
if (sgp.parse(inputChar, src) < 0)
918
return sgp.error();
919
return sgp.unmappableResult();
920
}
921
922
if (index == Integer.MIN_VALUE ||
923
encoderMappingTable[index] == NO_CHAR) {
924
return CoderResult.unmappableForLength(1);
925
} else {
926
if(encoderMappingTable[index + 1] == NO_CHAR) {
927
if(dst.remaining() < 1)
928
return CoderResult.OVERFLOW;
929
dst.put(encoderMappingTable[index]);
930
} else {
931
if(dst.remaining() < 2)
932
return CoderResult.OVERFLOW;
933
dst.put(encoderMappingTable[index]);
934
dst.put(encoderMappingTable[index + 1]);
935
}
936
}
937
mark++;
938
}
939
return CoderResult.UNDERFLOW;
940
} finally {
941
src.position(mark);
942
}
943
}
944
945
protected CoderResult encodeLoop(CharBuffer src,
946
ByteBuffer dst)
947
{
948
if (src.hasArray() && dst.hasArray())
949
return encodeArrayLoop(src, dst);
950
else
951
return encodeBufferLoop(src, dst);
952
}
953
}
954
}
955
956