forked from gigablast/open-source-search-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Unicode.cpp
1747 lines (1615 loc) · 38.9 KB
/
Unicode.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "gb-include.h"
#include "UCNormalizer.h"
#include "Mem.h"
#include "HashTable.h"
#include "iana_charset.h"
#include "Titledb.h"
static HashTableX s_convTable;
// JAB: warning abatement
//static bool verifyIconvFiles();
static bool openIconvDescriptors() ;
// alias iconv_open and close to keep count of usage
// and prevent leaks..
// now just cache all iconvs in a hash table
// static iconv_t gbiconv_open(const char *tocode, const char *fromcode) ;
// static int gbiconv_close(iconv_t cd) ;
iconv_t gbiconv_open( char *tocode, char *fromcode) {
// get hash for to/from
uint32_t hash1 = hash32Lower_a(tocode, gbstrlen(tocode), 0);
uint32_t hash2 = hash32Lower_a(fromcode, gbstrlen(fromcode),0);
uint32_t hash = hash32h(hash1, hash2);
g_errno = 0;
iconv_t *convp = (iconv_t *)s_convTable.getValue(&hash);
iconv_t conv = NULL;
if ( convp ) conv = *convp;
//log(LOG_DEBUG, "uni: convertor %s -> %s from hash 0x%"XINT32": 0x%"XINT32"",
// fromcode, tocode,
// hash, conv);
if (!conv){
//log(LOG_DEBUG, "uni: Allocating new convertor for "
// "%s to %s (hash: 0x%"XINT32")",
// fromcode, tocode,hash);
conv = iconv_open(tocode, fromcode);
if (conv == (iconv_t) -1) {
log(LOG_WARN, "uni: failed to open converter for "
"%s to %s: %s (%d)", fromcode, tocode,
strerror(errno), errno);
// need to stop if necessary converters don't open
//char *xx=NULL; *xx = 0;
g_errno = errno;
if (errno == EINVAL)
g_errno = EBADCHARSET;
return conv;
}
// add mem to table to keep track
g_mem.addMem((void*)conv, 52, "iconv", 1);
// cache convertor
s_convTable.addKey(&hash, &conv);
//log(LOG_DEBUG, "uni: Saved convertor 0x%"INT32" under hash 0x%"XINT32"",
// conv, hash);
}
else{
// reset convertor
char *dummy = NULL;
size_t dummy2 = 0;
// JAB: warning abatement
//size_t res = iconv(conv,NULL,NULL,&dummy,&dummy2);
iconv(conv,NULL,NULL,&dummy,&dummy2);
}
return conv;
}
int gbiconv_close(iconv_t cd) {
//int val = iconv_close(cd);
//if (val == 0) g_mem.rmMem((void*)cd, 1, "iconv", 1);
//return val;
return 0;
}
void gbiconv_reset(){
for (int32_t i=0;i<s_convTable.getNumSlots();i++){
//int32_t key = *(int32_t *)s_convTable.getKey(i);
//if (!key) continue;
if ( ! s_convTable.m_flags[i] ) continue;
iconv_t *pconv = (iconv_t *)s_convTable.getValueFromSlot(i);
if (! pconv) continue;
iconv_t iconv = *pconv;
//logf(LOG_DEBUG, "iconv: freeing iconv: 0x%x", (int)iconv);
g_mem.rmMem((void*)iconv, 52, "iconv");
libiconv_close(iconv);
}
s_convTable.reset();
}
#undef iconv_open
#define iconv_open(to, from) ((iconv_t)coreme(0))
#undef iconv_close
#define iconv_close(cd) ((int)coreme(0))
#define MAX_BAD_CHARS 500
#define VERIFY_UNICODE_CHECKSUMS 1
#define CHKSUM_UPPERMAP 1241336150
#define CHKSUM_LOWERMAP 1023166806
#define CHKSUM_PROPERTIES 33375957
#define CHKSUM_COMBININGCLASS 526097805
#define CHKSUM_SCRIPTS 1826246000
#define CHKSUM_KDMAP 1920116453
bool ucInit(char *path, bool verifyFiles){
char file[384];
if (path == NULL) path = "./";
// Might want to move this out of ucInit someday
// but right now it's the only thing that uses .so files (?)
char gbLibDir[512];
snprintf(gbLibDir, 512, "%s/lib",path);
// i don't think this is used any more because we don't have it!
//log(LOG_INIT, "ucinit: Setting LD_RUN_PATH to \"%s\"",gbLibDir);
if (setenv("LD_RUN_PATH", gbLibDir, 1)){
log(LOG_INIT, "Failed to set LD_RUN_PATH");
}
//char *ldpath = getenv("LD_RUN_PATH");
// i don't think this is used any more because we don't have it!
//log(LOG_DEBUG, "ucinit: LD_RUN_PATH: %s\n", ldpath);
strcpy(file, path);
strcat(file, "/ucdata/uppermap.dat");
if (!loadUnicodeTable(&g_ucUpperMap,file,
VERIFY_UNICODE_CHECKSUMS,
CHKSUM_UPPERMAP))
goto failed;
strcpy(file, path);
strcat(file, "/ucdata/lowermap.dat");
if (!loadUnicodeTable(&g_ucLowerMap,file,
VERIFY_UNICODE_CHECKSUMS,
CHKSUM_LOWERMAP))
goto failed;
strcpy(file, path);
strcat(file, "/ucdata/properties.dat");
if (!loadUnicodeTable(&g_ucProps, file,
VERIFY_UNICODE_CHECKSUMS,
CHKSUM_PROPERTIES))
goto failed;
strcpy(file, path);
strcat(file, "/ucdata/combiningclass.dat");
if (!loadUnicodeTable(&g_ucCombiningClass, file,
VERIFY_UNICODE_CHECKSUMS,
CHKSUM_COMBININGCLASS))
goto failed;
strcpy(file, path);
strcat(file, "/ucdata/scripts.dat");
if (!loadUnicodeTable(&g_ucScripts, file,
VERIFY_UNICODE_CHECKSUMS,
CHKSUM_SCRIPTS))
goto failed;
// MDW: do we need this for converting from X to utf8? or for
// the is_alnum(), etc. functions?
if (!loadDecompTables(path) ||
!initCompositionTable())
goto failed;
//s_convTable.set(1024);
if ( ! s_convTable.set(4,sizeof(iconv_t),1024,NULL,0,false,0,"cnvtbl"))
goto failed;
// dont use these files anymore
if (verifyFiles){
if (!openIconvDescriptors())
return log(LOG_WARN,
"uni: unable to open all iconv descriptors");
}
return true;
failed:
return log(LOG_WARN,
"uni: unable to load all property tables");
}
char *ucDetectBOM(char *buf, int32_t bufsize){
if (bufsize < 4) return NULL;
// copied from ICU
if(buf[0] == '\xFE' && buf[1] == '\xFF') {
return "UTF-16BE";
} else if(buf[0] == '\xFF' && buf[1] == '\xFE') {
if(buf[2] == '\x00' && buf[3] =='\x00') {
return "UTF-32LE";
} else {
return "UTF-16LE";
}
} else if(buf[0] == '\xEF' && buf[1] == '\xBB' && buf[2] == '\xBF') {
return "UTF-8";
} else if(buf[0] == '\x00' && buf[1] == '\x00' &&
buf[2] == '\xFE' && buf[3]=='\xFF') {
return "UTF-32BE";
}
return NULL;
}
/*
int32_t ucToUnicode(UChar *outbuf, int32_t outbufsize,
char *inbuf, int32_t inbuflen,
const char *charset, int32_t ignoreBadChars,
int32_t titleRecVersion){
g_errno = 0;
if (inbuflen == 0) return 0;
// alias for iconv
const char *csAlias = charset;
if (!strncmp(charset, "x-windows-949", 13)){
if (titleRecVersion >= 64 && titleRecVersion <= 65)
csAlias = "WINDOWS-1252";
else csAlias = "CP949";
}
if (!strncmp(charset, "Windows-31J", 13)){
if (titleRecVersion >= 67 || titleRecVersion < 64)
csAlias = "CP932";
}
// Treat all latin1 as windows-1252 extended charset
if (titleRecVersion < 64){
if (!strncmp(charset, "ISO-8859-1", 10) )
csAlias = "WINDOWS-1252";
}
else {
// oops, what about ISO-8859-10?
if (!strcmp(charset, "ISO-8859-1") )
csAlias = "WINDOWS-1252";
}
iconv_t cd = gbiconv_open("UTF-16LE", csAlias);
int32_t numBadChars = 0;
if (cd == (iconv_t)-1) {
log("uni: Error opening input conversion"
" descriptor for %s: %s (%d)\n",
charset,
strerror(errno),errno);
return 0;
}
//if (normalized) *normalized = false;
char *pin = (char*)inbuf;
size_t inRemaining = inbuflen;
char *pout = (char*)outbuf;
size_t outRemaining = outbufsize;
int res = 0;
if (outbuf == NULL || outbufsize == 0) {
// just find the size needed for conversion
#define TMP_SIZE 32
char buf[TMP_SIZE];
int32_t len = 0;
while (inRemaining) {
pout = buf;
outRemaining = TMP_SIZE;
res = iconv(cd, &pin, &inRemaining,
&pout, &outRemaining);
if (res < 0 && errno){
// convert the next TMP_SIZE block
if (errno == E2BIG) {
len += TMP_SIZE;
continue;
}
gbiconv_close(cd);
return 0; // other error
}
len += TMP_SIZE-outRemaining;
len >>= 1; // sizeof UChar
len += 2; // NULL terminated
gbiconv_close(cd);
return len;
}
}
while (inRemaining && outRemaining) {
//printf("Before - in: %d, out: %d\n", inRemaining, outRemaining);
again:
res = iconv(cd,&pin, &inRemaining,
&pout, &outRemaining);
//printf("After - in: %d, out: %d\n", inRemaining, outRemaining);
//printf("res: %d\n", res);
if (res < 0 && errno){
//printf("errno: %s (%d)\n", strerror(errno), errno);
switch(errno) {
case EILSEQ:
numBadChars++;
if (ignoreBadChars >= 0 &&
numBadChars > ignoreBadChars) {
g_errno = errno;
goto done;
}
utf16Encode('?', (UChar*)pout);
pout+=2;outRemaining -= 2;
pin++; inRemaining--;
continue;
case EINVAL:
numBadChars++;
utf16Encode('?', (UChar*)pout);
pout+=2;outRemaining -= 2;
pin++; inRemaining--;
continue;
// go ahead and flag an error now
// if there is a bad character, we've
// probably misguessed the charset
case E2BIG:
g_errno = errno;
//log("uni: error converting to UTF-16: %s",
// strerror(errno));
goto done;
default:
//g_errno = errno;
log("uni: unknown error occurred "
"converting to UTF-16: %s (%d)",
strerror(errno), errno);
// clear it and try again
errno = 0;
// i saw this happening a lot when rebuilding
// spiderdb and doing the titledb scan...
// it was "Resource temporarily unavailable
// (11)"
goto again;
char *xx=NULL;*xx=0;
goto done;
}
}
}
done:
gbiconv_close(cd);
int32_t len = (outbufsize - outRemaining) ;
len = len>=outbufsize-1?outbufsize-2:len;
len >>= 1;
//len = outbuf[len]=='\0'?len-1:len;
outbuf[len] = '\0';
static char eflag = 1;
if (numBadChars) {
if ( eflag )
log(LOG_DEBUG, "uni: ucToUnicode: got %"INT32" bad chars "
"in conversion. Only reported once.", numBadChars);
// this flag makes it so no bad characters are reported
// from now on
//eflag = 0;
// hmm, we were returning EBADCHARSET, but not aborting
// the conversion...this was confusing pageparser -partap
if (ignoreBadChars > 0 && numBadChars > ignoreBadChars){
g_errno = EBADCHARSET;
// needs versioning for old titlerecs which may have
// aborted after 10 bad chars
if (titleRecVersion >= 76)
return 0;
}
}
if (res < 0 && g_errno) return 0;
return len ;
}
*/
int32_t ucToAny(char *outbuf, int32_t outbufsize, char *charset_out,
char *inbuf, int32_t inbuflen, char *charset_in,
int32_t ignoreBadChars , int32_t niceness ){
if (inbuflen == 0) return 0;
// alias for iconv
char *csAlias = charset_in;
if (!strncmp(charset_in, "x-windows-949", 13))
csAlias = "CP949";
// Treat all latin1 as windows-1252 extended charset
if (!strncmp(charset_in, "ISO-8859-1", 10) )
csAlias = "WINDOWS-1252";
iconv_t cd = gbiconv_open(charset_out, csAlias);
int32_t numBadChars = 0;
if (cd == (iconv_t)-1) {
log("uni: Error opening input conversion"
" descriptor for %s: %s (%d)\n",
charset_in,
strerror(errno),errno);
return 0;
}
//if (normalized) *normalized = false;
char *pin = (char*)inbuf;
size_t inRemaining = inbuflen;
char *pout = (char*)outbuf;
size_t outRemaining = outbufsize;
int res = 0;
if (outbuf == NULL || outbufsize == 0) {
// just find the size needed for conversion
#define TMP_SIZE 32
char buf[TMP_SIZE];
int32_t len = 0;
while (inRemaining) {
QUICKPOLL(niceness);
pout = buf;
outRemaining = TMP_SIZE;
res = iconv(cd, &pin, &inRemaining,
&pout, &outRemaining);
if (res < 0 && errno){
// convert the next TMP_SIZE block
if (errno == E2BIG) {
len += TMP_SIZE;
continue;
}
gbiconv_close(cd);
return 0; // other error
}
len += TMP_SIZE-outRemaining;
//len >>= 1; // sizeof UChar
len += 1; // NULL terminated
gbiconv_close(cd);
return len;
}
}
while (inRemaining && outRemaining) {
QUICKPOLL(niceness);
//printf("Before - in: %d, out: %d\n",
//inRemaining, outRemaining);
res = iconv(cd,&pin, &inRemaining,
&pout, &outRemaining);
if (res < 0 && errno){
//printf("errno: %s (%d)\n", strerror(errno), errno);
g_errno = errno;
switch(errno) {
case EILSEQ:
numBadChars++;
if (ignoreBadChars >= 0 &&
numBadChars > ignoreBadChars) goto done;
utf8Encode('?', pout);
pout++;outRemaining --;
pin++; inRemaining--;
g_errno = 0;
continue;
case EINVAL:
numBadChars++;
utf8Encode('?', pout);
pout++;outRemaining --;
pin++; inRemaining--;
g_errno=0;
continue;
// go ahead and flag an error now
// if there is a bad character, we've
// probably misguessed the charset
case E2BIG:
//log("uni: error converting to UTF-8: %s",
// strerror(errno));
goto done;
default:
log("uni: unknown error occurred "
"converting to UTF-8: %s (%d)",
strerror(errno), errno);
goto done;
}
}
}
done:
gbiconv_close(cd);
int32_t len = (outbufsize - outRemaining) ;
len = len>=outbufsize-1?outbufsize-2:len;
//len >>= 1;
//len = outbuf[len]=='\0'?len-1:len;
outbuf[len] = '\0';
static char eflag = 1;
if (numBadChars) {
if ( eflag )
log(LOG_DEBUG, "uni: ucToAny: got %"INT32" bad chars "
"in conversion 2. Only reported once.",
numBadChars);
// this flag makes it so no bad characters are reported
// in subsequent conversions
//eflag = 0;
}
if (res < 0 && g_errno) return 0;
return len ;
}
// produces a canonical decomposition of UTF-8 input
/*
int32_t utf8CDecompose( char* outBuf, int32_t outBufSize,
const char* inBuf, int32_t inBufSize,
bool decodeEntities) {
const char *p = inBuf;
const char *pend = inBuf + inBufSize;
char *q = outBuf;
char *qend = outBuf + outBufSize;
while (p < pend) {
UChar32 c;
if (decodeEntities)
c = utf8EntityDecode(p, &p, pend - p);
else
c = utf8Decode(p, (char**) &p);
UChar32 decomp[32];
int32_t decompLen = recursiveCDExpand(c, decomp, 32);
for (int i = 0; i < decompLen && (q < qend); i++) {
UChar32 d = decomp[i];
unsigned char cc = ucCombiningClass(d);
// fix out-of-order combining chars
// Gah...this shouldn't happen too often
if (cc) {
char *qq = q; //insert point
UChar32 c2;
while (qq > outBuf){
char *qprev;
c2 = utf8Prev(qq, &qprev);
if (ucCombiningClass(c2) <= cc) break;
qq = qprev;
}
if (qq < q){ // move chars out of the way
int32_t cSize = utf8Size(c);
memmove(qq+cSize, qq, (q-qq));
}
q += utf8Encode(d, qq);
}
else
q += utf8Encode(d, q);
}
}
return q - outBuf;
}
*/
/*
int32_t ucFromUnicode( char *outbuf, int32_t outbufSize,
const UChar *inbuf, int32_t inbufSize,
const char *charset){
// alias for iconv
const char *csAlias = charset;
if (!strncmp(charset, "x-windows-949", 13) )
csAlias = "CP949";
// Treat all latin1 as windows-1252 extended charset
if (!strncmp(charset, "ISO-8859-1", 10) )
csAlias = "WINDOWS-1252";
iconv_t cd = gbiconv_open(charset,"UTF-16LE");
if (cd == (iconv_t)-1) {
log("uni: Error opening input conversion"
" descriptor for %s: %s (%d)\n",
charset,
strerror(errno),errno);
return 0;
}
char *pin = (char*)inbuf;
size_t inRemaining = inbufSize<<1;
char *pout = (char*)outbuf;
size_t outRemaining = outbufSize;
if (outbuf == NULL || outbufSize == 0) {
// just find the size needed for conversion
#define TMP_SIZE 32
char buf[TMP_SIZE];
int32_t len = 0;
while (inRemaining) {
pout = buf;
outRemaining = TMP_SIZE;
int res = iconv(cd, &pin, &inRemaining,
&pout, &outRemaining);
if (res < 0 && errno){
// convert the next TMP_SIZE block
if (errno == E2BIG) {
len += TMP_SIZE;
continue;
}
gbiconv_close(cd);
// other error
// shouldn't ever get here
// maybe we can handle this better...
// shouldn't take a version change
// because this function is only used for
// output
log(LOG_WARN, "uni: error determining space "
"to convert from UTF-16 to %s: %s",
charset,
strerror(errno));
return 0;
}
len += TMP_SIZE-outRemaining;
gbiconv_close(cd);
return len;
}
}
while (inRemaining && outRemaining) {
int res = iconv(cd,&pin, &inRemaining,
&pout, &outRemaining);
if (res < 0 && errno){
switch(errno) {
case EILSEQ:
case EINVAL:
log(LOG_DEBUG,
"uni: Bad character in conversion from "
"UTF-16 to %s", charset);
*pout++ = '?';outRemaining--;
pin++; inRemaining--;
continue;
case E2BIG:
log("uni: error converting from UTF-16 "
"to %s: %s", charset,
strerror(errno));
goto done;
default:
log("uni: unknown error occurred "
"converting from UTF-16 to %s: %s (%d)",
charset,
strerror(errno), errno);
goto done;
}
}
}
done:
gbiconv_close(cd);
int32_t len = outbufSize - outRemaining;
//len = len>=outbufsize?outbufsize-1:len;
//len = outbuf[len]=='\0'?len-1:len;
//outbuf[len] = '\0';
return len;
}
*/
// Read one UTF-8 character...optionally return the position of the next
// JAB: const-ness for the optimizer...
/*
UChar32 utf8Decode2(const char *p, const char **next){
int num_bytes = bytes_in_utf8_code[*(unsigned char*)p];
if (!num_bytes){
// ill-formed byte sequence
// lets just return an invalid character and go on to the next
if (next) *next = p+1;
return (UChar32)0xffffffff;
}
if (next){
*next = p + num_bytes;
}
switch(num_bytes){
case 1:
return (UChar32)*p;
case 2:
return (UChar32)((*p & 0x1f)<<6 |
(*(p+1) & 0x3f));
case 3:
return (UChar32)((*p & 0x0f)<<12 |
(*(p+1) & 0x3f)<<6 |
(*(p+2) & 0x3f));
case 4:
return (UChar32)((*p & 0x07)<<18 |
(*(p+1) & 0x3f)<<12 |
(*(p+2) & 0x3f)<<6 |
(*(p+3) & 0x3f));
default:
return (UChar32) -1;
};
}
*/
/*
// starting at 0xc3 0x80 ending at 0xc3 0xbf
static char ascii_c3[] = {
'A', // 80
'A', // 81
'A', // 82
'A', // 83
'A', // 84
'A', // 85
'A', // 86
'C', // 87
'E', // 88
'E', // 89
'E', // 8a
'E', // 8b
'I', // 8c
'I', // 8d
'I', // 8e
'I', // 8f
'D', // 90
'N', // 91
'O', // 92
'O', // 93
'O', // 94
'O', // 95
'O', // 96
'X', // 97 multiplication sign
'O', // 98
'U', // 99
'U', // 9a
'U', // 9b
'U', // 9c
'Y', // 9d
'P', // 9e thorn
's', // 9f sharp s
'a', // a0
'a', // a1
'a', // a2
'a', // a3
'a', // a4
'a', // a5
'a', // a6
'c', // a7
'e', // a8
'e', // a9
'e', // aa
'e', // ab
'i', // ac
'i', // ad
'i', // ae
'i', // af
'd', // b0
'n', // b1
'o', // b2
'o', // b3
'o', // b4
'o', // b5
'o', // b6
'X', // b7 division sign
'o', // b8
'u', // b9
'u', // ba
'u', // bb
'u', // bc
'y', // bd
'p', // be thorn
'y' // bf
};
// starting at 0xc4 0x80 ending at 0xc4 0xbf
static char ascii_c4[] = {
'A', // c4 80
'a', // c4 81
'A', // c4 82
'a', // c4 83
'A', // c4 84
'a', // c4 85
'C', // c4 86
'c', // c4 87
'C', // c4 88
'c', // c4 89
'C', // c4 8a
'c',
'C',
'c', // c4 8d
'D', // c4 8e
'd', // c4 8f
'D', // c4 90
'd', // c4 91
'E', // c4 92
'e', // 93
'E', // 94
'e', // 95
'E', // 96
'e', // 97
'E', // 98
'e', // 99
'E', // 9a
'e', // 9b
'G', // 9c
'g', // 9d
'G', // 9e
'g', // 9f
'G', // a0
'g', // a1
'G', // a2
'g', // a3
'H', // a4
'h', // a5
'H', // a6
'h', // a7
'I', // a8
'i', // a9
'I', // aa
'i', // ab
'I', // ac
'i', // ad
'I', // ae
'i', // af
'I', // b0
'i', // b1
'I', // b2 IJ
'i', // b3 ij
'J', // b4
'j', // b5
'K', // b6
'k', // b7
'K', // b8
'L', // b9
'l', // ba
'L', // bb
'l', // bc
'L', // bd
'l', // be
'L' // bf
};
// starting at 0xc5 0x80 ending at 0xc5 0xbf
static char ascii_c5[] = {
'l', // 80
'L', // 81
'l', // 82
'N', // 83
'n', // 84
'N', // 85
'n', // 86
'N', // 87
'n', // 88
'n', // 89
'N', // 8a
'n', // 8b
'O', // 8c
'o', // 8d
'O', // 8e
'o', // 8f
'O', // 90
'o', // 91
'O', // 92 OE
'o', // 93 oe
'R', // 94
'r', // 95
'R', // 96
'r', // 97
'R', // 98
'r', // 99
'S', // 9a
's', // 9b
'S', // 9c
's', // 9d
'S', // 9e
's', // 9f
'S', // a0
's', // a1
'T', // a2
't', // a3
'T', // a4
't', // a5
'T', // a6
't', // a7
'U', // a8
'u', // a9
'U', // aa
'u', // ab
'U', // ac
'u', // ad
'U', // ae
'u', // af
'U', // b0
'u', // b1
'U', // b2
'u', // b3
'W', // b4
'w', // b5
'Y', // b6
'y', // b7
'Y', // b8
'Z', // b9
'z', // ba
'Z', // bb
'z', // bc
'Z', // bd
'z', // be
's' // bf (int32_t s)
};
// starting at 0xc6 0x80 ending at 0xc6 0xbf
static char ascii_c6[] = {
'b', // 80
'B', // 81
'B', // 82
'b', // 83
'B', // 84
'b', // 85
'C', // 86
'C', // 87
'c', // 88
'D', // 89
'D', // 8a
'D', // 8b
'd', // 8c
'd', // 8d
'E', // 8e
'E', // 8f
'E', // 90
'F', // 91
'f', // 92
'G', // 93
'G', // 94
'h', // 95 hv
'I', // 96
'I', // 97
'K', // 98
'k', // 99
'l', // 9a
'l', // 9b
'M', // 9c
'N', // 9d
'n', // ie
'O', // 9f
'O', // a0
'o', // a1
'O', // a2 OI
'o', // a3 oi
'P', // a4
'p', // a5
'R', // a6 YR
'S', // a7
's', // a8
'S', // a9
'S', // aa
't', // ab
'T', // ac
't', // ad
'T', // ae
'U', // af
'u', // b0
'U', // b1
'V', // b2
'Y', // b3
'y', // b4
'Z', // b5
'z', // b6
'z', // b7
'z', // b8
'z', // b9
'z', // ba
'z', // bb
'z', // bc
'z', // bd
'z', // be
'p' // bf
};
class bichar {
public:
char m_c0;
char m_c1;
};
// maps utf8 chars starting with 0xce into utf8 char w/o the accent mark
static bichar utf_ce[] = {
{0xce,0x00}, // 80
{0xce,0x00}, // 81
{0xce,0x00}, // 82
{0xce,0x00}, // 83
{0xce,0x00}, // 84
{0xce,0x00}, // 85
{0xce,0x91}, // 86 Ά to Α
{0xce,0x00}, // 87
{0xce,0x95}, // 88 Έ to Ε
{0xce,0x00}, // 89 Ή to Η
{0xce,0x99}, // 8a Ί to I
{0xce,0x00}, // 8b
{0xce,0x9f}, // 8c Ό to O
{0xce,0x00}, // 8d
{0xce,0xa5}, // 8e Ύ to Y
{0xce,0xa9}, // 8f Ώ to Ω
{0xce,0xb9}, // 90 ΐ to ι
{0xce,0x91}, // 91 A to A
{0xce,0x92}, // 92 B to B
{0xce,0x93}, // 93 Γ to Γ
{0xce,0x94}, // 94 Δ to Δ
{0xce,0x95}, // 95 hv
{0xce,0x96}, // 96
{0xce,0x97}, // 97
{0xce,0x98}, // 98
{0xce,0x99}, // 99
{0xce,0x9a}, // 9a
{0xce,0x9b}, // 9b
{0xce,0x9c}, // 9c
{0xce,0x9d}, // 9d
{0xce,0x9e}, // 9e
{0xce,0x9f}, // 9f
{0xce,0xa0}, // a0
{0xce,0xa1}, // a1
{0xce,0x00}, // a2
{0xce,0xa3}, // a3
{0xce,0xa4}, // a4
{0xce,0xa5}, // a5
{0xce,0xa6}, // a6 YR
{0xce,0xa7}, // a7
{0xce,0xa8}, // a8
{0xce,0xa9}, // a9
{0xce,0x99}, // aa Ϊ to I
{0xce,0xa5}, // ab Ϋ to Y
{0xce,0xb1}, // ac ά to α
{0xce,0xb5}, // ad έ to ε
{0xce,0xb7}, // ae ή
{0xce,0xb9}, // af ί
{0xcf,0x85}, // b0 ΰ
{0xce,0xb1}, // b1