forked from unicode-org/icu
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcbiditst.c
More file actions
4982 lines (4545 loc) · 211 KB
/
cbiditst.c
File metadata and controls
4982 lines (4545 loc) · 211 KB
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
// © 2016 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
/********************************************************************
* COPYRIGHT:
* Copyright (c) 1997-2014, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************/
/* file name: cbiditst.c
* encoding: UTF-8
* tab size: 8 (not used)
* indentation:4
*
* created on: 1999sep27
* created by: Markus W. Scherer, updated by Matitiahu Allouche
*/
#include "cintltst.h"
#include "unicode/utypes.h"
#include "unicode/uchar.h"
#include "unicode/ustring.h"
#include "unicode/ubidi.h"
#include "unicode/ushape.h"
#include "cbiditst.h"
#include "cstring.h"
#include <stdbool.h>
/* the following include is needed for snprintf */
#include <stdio.h>
#define MAXLEN MAX_STRING_LENGTH
/* prototypes ---------------------------------------------------------------*/
void addComplexTest(TestNode** root);
static void testCharFromDirProp(void);
static void testBidi(void);
static void doTests(UBiDi *pBiDi, UBiDi *pLine, UBool countRunsFirst);
static void doMisc(void);
static void doTest(UBiDi *pBiDi, int testNumber, const BiDiTestData *test,
int32_t lineStart, UBool countRunsFirst);
static void _testReordering(UBiDi *pBiDi, int testNumber);
static void testInverse(void);
static void _testManyInverseBidi(UBiDi *pBiDi, UBiDiLevel direction);
static void _testInverseBidi(UBiDi *pBiDi, const UChar *src, int32_t srcLength,
UBiDiLevel direction, UErrorCode *pErrorCode);
static void _testWriteReverse(void);
static void _testManyAddedPoints(void);
static void _testMisc(void);
static void doArabicShapingTest(void);
static void doLamAlefSpecialVLTRArabicShapingTest(void);
static void doTashkeelSpecialVLTRArabicShapingTest(void);
static void doLOGICALArabicDeShapingTest(void);
static void doArabicShapingTestForBug5421(void);
static void doArabicShapingTestForBug8703(void);
static void doArabicShapingTestForBug9024(void);
static void _testPresentationForms(const UChar *in);
static void doArabicShapingTestForNewCharacters(void);
static void testReorder(void);
static void testReorderArabicMathSymbols(void);
static void testFailureRecovery(void);
static void testMultipleParagraphs(void);
static void testGetBaseDirection(void);
static void testContext(void);
static void doTailTest(void);
static void testBracketOverflow(void);
static void TestExplicitLevel0(void);
static void testUBidiWriteReorderedBufferOverflow(void);
/* new BIDI API */
static void testReorderingMode(void);
static void testReorderRunsOnly(void);
static void testStreaming(void);
static void testClassOverride(void);
static const char* inverseBasic(UBiDi *pBiDi, const char *src, int32_t srcLen,
uint32_t option, UBiDiLevel level, char *result);
static UBool assertRoundTrip(UBiDi *pBiDi, int32_t tc, int32_t outIndex,
const char *srcChars, const char *destChars,
const UChar *dest, int32_t destLen, int mode,
int option, UBiDiLevel level);
static UBool checkResultLength(UBiDi *pBiDi, const char *srcChars,
const char *destChars,
int32_t destLen, const char *mode,
const char *option, UBiDiLevel level);
static UBool checkMaps(UBiDi *pBiDi, int32_t stringIndex, const char *src,
const char *dest, const char *mode, const char* option,
UBiDiLevel level, UBool forward);
/* helpers ------------------------------------------------------------------ */
static const char *levelString="...............................................................";
static void initCharFromDirProps(void);
static UChar *
getStringFromDirProps(const uint8_t *dirProps, int32_t length, UChar *buffer);
static void printUnicode(const UChar *s, int32_t length, const UBiDiLevel *levels);
/* regression tests ---------------------------------------------------------*/
void
addComplexTest(TestNode** root) {
addTest(root, testCharFromDirProp, "complex/bidi/TestCharFromDirProp");
addTest(root, testBidi, "complex/bidi/TestBidi");
addTest(root, testInverse, "complex/bidi/TestInverse");
addTest(root, testReorder,"complex/bidi/TestReorder");
addTest(root, testFailureRecovery,"complex/bidi/TestFailureRecovery");
addTest(root, testMultipleParagraphs,"complex/bidi/TestMultipleParagraphs");
addTest(root, testReorderingMode, "complex/bidi/TestReorderingMode");
addTest(root, testReorderRunsOnly, "complex/bidi/TestReorderRunsOnly");
addTest(root, testStreaming, "complex/bidi/TestStreaming");
addTest(root, testClassOverride, "complex/bidi/TestClassOverride");
addTest(root, testGetBaseDirection, "complex/bidi/testGetBaseDirection");
addTest(root, testContext, "complex/bidi/testContext");
addTest(root, testBracketOverflow, "complex/bidi/TestBracketOverflow");
addTest(root, TestExplicitLevel0, "complex/bidi/TestExplicitLevel0");
addTest(root, testUBidiWriteReorderedBufferOverflow, "complex/bidi/writeReorderedBufferOverflow");
addTest(root, doArabicShapingTest, "complex/arabic-shaping/ArabicShapingTest");
addTest(root, doLamAlefSpecialVLTRArabicShapingTest, "complex/arabic-shaping/lamalef");
addTest(root, doTashkeelSpecialVLTRArabicShapingTest, "complex/arabic-shaping/tashkeel");
addTest(root, doLOGICALArabicDeShapingTest, "complex/arabic-shaping/unshaping");
addTest(root, doArabicShapingTestForBug5421, "complex/arabic-shaping/bug-5421");
addTest(root, doTailTest, "complex/arabic-shaping/tailtest");
addTest(root, doArabicShapingTestForBug8703, "complex/arabic-shaping/bug-8703");
addTest(root, testReorderArabicMathSymbols, "complex/bidi/bug-9024");
addTest(root, doArabicShapingTestForBug9024, "complex/arabic-shaping/bug-9024");
addTest(root, doArabicShapingTestForNewCharacters, "complex/arabic-shaping/shaping2");
}
static void
testCharFromDirProp(void) {
/* verify that the exemplar characters have the expected bidi classes */
int32_t i;
log_verbose("\nEntering TestCharFromDirProp\n\n");
initCharFromDirProps();
for(i=0; i<U_CHAR_DIRECTION_COUNT; ++i) {
if(u_charDirection(charFromDirProp[i])!=(UCharDirection)i) {
log_err("\nu_charDirection(charFromDirProp[%d]=U+%04x)==%d!=%d\n",
i, charFromDirProp[i], u_charDirection(charFromDirProp[i]), i);
}
}
log_verbose("\nExiting TestCharFromDirProp\n\n");
}
static void
testBidi(void) {
UBiDi *pBiDi, *pLine=NULL;
UErrorCode errorCode=U_ZERO_ERROR;
log_verbose("\nEntering TestBidi\n\n");
pBiDi=ubidi_openSized(MAXLEN, 0, &errorCode);
if(pBiDi!=NULL) {
pLine=ubidi_open();
if(pLine!=NULL) {
doTests(pBiDi, pLine, false);
doTests(pBiDi, pLine, true);
} else {
log_err("ubidi_open() returned NULL, out of memory\n");
}
} else {
log_err("ubidi_openSized() returned NULL, errorCode %s\n", myErrorName(errorCode));
}
doMisc();
if(pLine!=NULL) {
ubidi_close(pLine);
}
if(pBiDi!=NULL) {
ubidi_close(pBiDi);
}
log_verbose("\nExiting TestBidi\n\n");
}
static void
doTests(UBiDi *pBiDi, UBiDi *pLine, UBool countRunsFirst) {
int testNumber;
UChar string[MAXLEN];
UErrorCode errorCode;
int32_t lineStart;
UBiDiLevel paraLevel;
for(testNumber=0; testNumber<bidiTestCount; ++testNumber) {
errorCode=U_ZERO_ERROR;
getStringFromDirProps(tests[testNumber].text, tests[testNumber].length, string);
paraLevel=tests[testNumber].paraLevel;
ubidi_setPara(pBiDi, string, -1, paraLevel, NULL, &errorCode);
if(U_SUCCESS(errorCode)) {
log_verbose("ubidi_setPara(tests[%d], paraLevel %d) ok, direction %d paraLevel=%d\n",
testNumber, paraLevel, ubidi_getDirection(pBiDi), paraLevel);
lineStart=tests[testNumber].lineStart;
if(lineStart==-1) {
doTest(pBiDi, testNumber, tests+testNumber, 0, countRunsFirst);
} else {
ubidi_setLine(pBiDi, lineStart, tests[testNumber].lineLimit, pLine, &errorCode);
if(U_SUCCESS(errorCode)) {
log_verbose("ubidi_setLine(%d, %d) ok, direction %d paraLevel=%d\n",
lineStart, tests[testNumber].lineLimit, ubidi_getDirection(pLine), ubidi_getParaLevel(pLine));
doTest(pLine, testNumber, tests+testNumber, lineStart, countRunsFirst);
} else {
log_err("ubidi_setLine(tests[%d], %d, %d) failed with errorCode %s\n",
testNumber, lineStart, tests[testNumber].lineLimit, myErrorName(errorCode));
}
}
} else {
log_err("ubidi_setPara(tests[%d], paraLevel %d) failed with errorCode %s\n",
testNumber, paraLevel, myErrorName(errorCode));
}
}
}
static const char columns[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
#define TABLE_SIZE 256
static UBool tablesInitialized = false;
static UChar pseudoToUChar[TABLE_SIZE];
static uint8_t UCharToPseudo[TABLE_SIZE]; /* used for Unicode chars < 0x0100 */
static uint8_t UCharToPseud2[TABLE_SIZE]; /* used for Unicode chars >=0x0100 */
static void buildPseudoTables(void)
/*
The rules for pseudo-Bidi are as follows:
- [ == LRE
- ] == RLE
- { == LRO
- } == RLO
- ^ == PDF
- @ == LRM
- & == RLM
- A-F == Arabic Letters 0631-0636
- G-V == Hebrew letters 05d7-05e6
- W-Z == Unassigned RTL 05CC..05CF
originally 08D0..08D3
Unicode 6.1 changes U+08A0..U+08FF from R to AL which works ok.
Unicode 11 adds U+08D3 ARABIC SMALL LOW WAW which has bc=NSM
so we stop using Z in this test.
Unicode 14 assigns 08D0..08D2 to diacritics (bc=NSM) so we switch to 05CC..05CF.
- 0-5 == western digits 0030-0035
- 6-9 == Arabic-Indic digits 0666-0669
- ` == Combining Grave Accent 0300 (NSM)
- ~ == Delete 007f (BN)
- | == Paragraph Separator 2029 (B)
- _ == Info Separator 1 001f (S)
All other characters represent themselves as Latin-1, with the corresponding
Bidi properties.
*/
{
int i;
UChar uchar;
uint8_t c;
/* initialize all tables to unknown */
for (i=0; i < TABLE_SIZE; i++) {
pseudoToUChar[i] = 0xFFFD;
UCharToPseudo[i] = '?';
UCharToPseud2[i] = '?';
}
/* initialize non letters or digits */
pseudoToUChar[(uint8_t) 0 ] = 0x0000; UCharToPseudo[0x00] = (uint8_t) 0 ;
pseudoToUChar[(uint8_t)' '] = 0x0020; UCharToPseudo[0x20] = (uint8_t)' ';
pseudoToUChar[(uint8_t)'!'] = 0x0021; UCharToPseudo[0x21] = (uint8_t)'!';
pseudoToUChar[(uint8_t)'"'] = 0x0022; UCharToPseudo[0x22] = (uint8_t)'"';
pseudoToUChar[(uint8_t)'#'] = 0x0023; UCharToPseudo[0x23] = (uint8_t)'#';
pseudoToUChar[(uint8_t)'$'] = 0x0024; UCharToPseudo[0x24] = (uint8_t)'$';
pseudoToUChar[(uint8_t)'%'] = 0x0025; UCharToPseudo[0x25] = (uint8_t)'%';
pseudoToUChar[(uint8_t)'\'']= 0x0027; UCharToPseudo[0x27] = (uint8_t)'\'';
pseudoToUChar[(uint8_t)'('] = 0x0028; UCharToPseudo[0x28] = (uint8_t)'(';
pseudoToUChar[(uint8_t)')'] = 0x0029; UCharToPseudo[0x29] = (uint8_t)')';
pseudoToUChar[(uint8_t)'*'] = 0x002A; UCharToPseudo[0x2A] = (uint8_t)'*';
pseudoToUChar[(uint8_t)'+'] = 0x002B; UCharToPseudo[0x2B] = (uint8_t)'+';
pseudoToUChar[(uint8_t)','] = 0x002C; UCharToPseudo[0x2C] = (uint8_t)',';
pseudoToUChar[(uint8_t)'-'] = 0x002D; UCharToPseudo[0x2D] = (uint8_t)'-';
pseudoToUChar[(uint8_t)'.'] = 0x002E; UCharToPseudo[0x2E] = (uint8_t)'.';
pseudoToUChar[(uint8_t)'/'] = 0x002F; UCharToPseudo[0x2F] = (uint8_t)'/';
pseudoToUChar[(uint8_t)':'] = 0x003A; UCharToPseudo[0x3A] = (uint8_t)':';
pseudoToUChar[(uint8_t)';'] = 0x003B; UCharToPseudo[0x3B] = (uint8_t)';';
pseudoToUChar[(uint8_t)'<'] = 0x003C; UCharToPseudo[0x3C] = (uint8_t)'<';
pseudoToUChar[(uint8_t)'='] = 0x003D; UCharToPseudo[0x3D] = (uint8_t)'=';
pseudoToUChar[(uint8_t)'>'] = 0x003E; UCharToPseudo[0x3E] = (uint8_t)'>';
pseudoToUChar[(uint8_t)'?'] = 0x003F; UCharToPseudo[0x3F] = (uint8_t)'?';
pseudoToUChar[(uint8_t)'\\']= 0x005C; UCharToPseudo[0x5C] = (uint8_t)'\\';
/* initialize specially used characters */
pseudoToUChar[(uint8_t)'`'] = 0x0300; UCharToPseud2[0x00] = (uint8_t)'`'; /* NSM */
pseudoToUChar[(uint8_t)'@'] = 0x200E; UCharToPseud2[0x0E] = (uint8_t)'@'; /* LRM */
pseudoToUChar[(uint8_t)'&'] = 0x200F; UCharToPseud2[0x0F] = (uint8_t)'&'; /* RLM */
pseudoToUChar[(uint8_t)'_'] = 0x001F; UCharToPseudo[0x1F] = (uint8_t)'_'; /* S */
pseudoToUChar[(uint8_t)'|'] = 0x2029; UCharToPseud2[0x29] = (uint8_t)'|'; /* B */
pseudoToUChar[(uint8_t)'['] = 0x202A; UCharToPseud2[0x2A] = (uint8_t)'['; /* LRE */
pseudoToUChar[(uint8_t)']'] = 0x202B; UCharToPseud2[0x2B] = (uint8_t)']'; /* RLE */
pseudoToUChar[(uint8_t)'^'] = 0x202C; UCharToPseud2[0x2C] = (uint8_t)'^'; /* PDF */
pseudoToUChar[(uint8_t)'{'] = 0x202D; UCharToPseud2[0x2D] = (uint8_t)'{'; /* LRO */
pseudoToUChar[(uint8_t)'}'] = 0x202E; UCharToPseud2[0x2E] = (uint8_t)'}'; /* RLO */
pseudoToUChar[(uint8_t)'~'] = 0x007F; UCharToPseudo[0x7F] = (uint8_t)'~'; /* BN */
/* initialize western digits */
for (i = 0, uchar = 0x0030; i < 6; i++, uchar++) {
c = (uint8_t)columns[i];
pseudoToUChar[c] = uchar;
UCharToPseudo[uchar & 0x00ff] = c;
}
/* initialize Hindi digits */
for (i = 6, uchar = 0x0666; i < 10; i++, uchar++) {
c = (uint8_t)columns[i];
pseudoToUChar[c] = uchar;
UCharToPseud2[uchar & 0x00ff] = c;
}
/* initialize Arabic letters */
for (i = 10, uchar = 0x0631; i < 16; i++, uchar++) {
c = (uint8_t)columns[i];
pseudoToUChar[c] = uchar;
UCharToPseud2[uchar & 0x00ff] = c;
}
/* initialize Hebrew letters */
for (i = 16, uchar = 0x05D7; i < 32; i++, uchar++) {
c = (uint8_t)columns[i];
pseudoToUChar[c] = uchar;
UCharToPseud2[uchar & 0x00ff] = c;
}
/* initialize Unassigned code points */
for (i = 32, uchar=0x05CC; i < 36; i++, uchar++) {
c = (uint8_t)columns[i];
pseudoToUChar[c] = uchar;
UCharToPseud2[uchar & 0x00ff] = c;
}
/* initialize Latin lower case letters */
for (i = 36, uchar = 0x0061; i < 62; i++, uchar++) {
c = (uint8_t)columns[i];
pseudoToUChar[c] = uchar;
UCharToPseudo[uchar & 0x00ff] = c;
}
tablesInitialized = true;
}
/*----------------------------------------------------------------------*/
static int pseudoToU16(const int length, const char * input, UChar * output)
/* This function converts a pseudo-Bidi string into a UChar string.
It returns the length of the UChar string.
*/
{
int i;
if (!tablesInitialized) {
buildPseudoTables();
}
for (i = 0; i < length; i++)
output[i] = pseudoToUChar[(uint8_t)input[i]];
output[length] = 0;
return length;
}
/*----------------------------------------------------------------------*/
static int u16ToPseudo(const int length, const UChar * input, char * output)
/* This function converts a UChar string into a pseudo-Bidi string.
It returns the length of the pseudo-Bidi string.
*/
{
int i;
UChar uchar;
if (!tablesInitialized) {
buildPseudoTables();
}
for (i = 0; i < length; i++)
{
uchar = input[i];
output[i] = uchar < 0x0100 ? UCharToPseudo[uchar] :
UCharToPseud2[uchar & 0x00ff];
}
output[length] = '\0';
return length;
}
static char * formatLevels(UBiDi *bidi, char *buffer) {
UErrorCode ec = U_ZERO_ERROR;
const UBiDiLevel* gotLevels = ubidi_getLevels(bidi, &ec);
int32_t len = ubidi_getLength(bidi);
char c;
int32_t i, k;
if(U_FAILURE(ec)) {
strcpy(buffer, "BAD LEVELS");
return buffer;
}
for (i=0; i<len; i++) {
k = gotLevels[i];
if (k >= (int32_t)sizeof(columns))
c = '+';
else
c = columns[k];
buffer[i] = c;
}
buffer[len] = '\0';
return buffer;
}
static const char *reorderingModeNames[] = {
"UBIDI_REORDER_DEFAULT",
"UBIDI_REORDER_NUMBERS_SPECIAL",
"UBIDI_REORDER_GROUP_NUMBERS_WITH_R",
"UBIDI_REORDER_RUNS_ONLY",
"UBIDI_REORDER_INVERSE_NUMBERS_AS_L",
"UBIDI_REORDER_INVERSE_LIKE_DIRECT",
"UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL"};
static char *reorderingOptionNames(char *buffer, int options) {
buffer[0] = 0;
if (options & UBIDI_OPTION_INSERT_MARKS) {
strcat(buffer, " UBIDI_OPTION_INSERT_MARKS");
}
if (options & UBIDI_OPTION_REMOVE_CONTROLS) {
strcat(buffer, " UBIDI_OPTION_REMOVE_CONTROLS");
}
if (options & UBIDI_OPTION_STREAMING) {
strcat(buffer, " UBIDI_OPTION_STREAMING");
}
return buffer;
}
static void printCaseInfo(UBiDi *bidi, const char *src, const char *dst)
/* src and dst are char arrays encoded as pseudo Bidi */
{
/* Since calls to log_err with a \n within the pattern increment the
* error count, new lines are issued via fputs, except when we want the
* increment to happen.
*/
UErrorCode errorCode=U_ZERO_ERROR;
int32_t i, length = ubidi_getProcessedLength(bidi);
const UBiDiLevel *levels;
char levelChars[MAXLEN];
UBiDiLevel lev;
int32_t runCount;
char buffer[100];
log_err("========================================"); fputs("\n", stderr);
levels = ubidi_getLevels(bidi, &errorCode);
if (U_FAILURE(errorCode)) {
strcpy(levelChars, "BAD LEVELS");
} else {
log_err("Processed length: %d", length); fputs("\n", stderr);
for (i = 0; i < length; i++) {
lev = levels[i];
if (lev < sizeof(columns)) {
levelChars[i] = columns[lev];
} else {
levelChars[i] = '+';
}
}
levelChars[length] = 0;
}
log_err("Levels: %s", levelChars); fputs("\n", stderr);
log_err("Source: %s", src); fputs("\n", stderr);
log_err("Result: %s", dst); fputs("\n", stderr);
log_err("Direction: %d", ubidi_getDirection(bidi)); fputs("\n", stderr);
log_err("paraLevel: %d", ubidi_getParaLevel(bidi)); fputs("\n", stderr);
i = ubidi_getReorderingMode(bidi);
log_err("reorderingMode: %d = %s", i, reorderingModeNames[i]);
fputs("\n", stderr);
i = ubidi_getReorderingOptions(bidi);
log_err("reorderingOptions: %d = %s", i, reorderingOptionNames(buffer, i));
fputs("\n", stderr);
runCount = ubidi_countRuns(bidi, &errorCode);
if (U_FAILURE(errorCode)) {
log_err( "BAD RUNS");
} else {
log_err("Runs: %d => logicalStart.length/level: ", runCount);
for (i = 0; i < runCount; i++) {
UBiDiDirection dir;
int32_t start, len;
dir = ubidi_getVisualRun(bidi, i, &start, &len);
log_err(" %d.%d/%d", start, len, dir);
}
}
fputs("\n", stderr);
}
static UBool matchingPair(UBiDi *bidi, int32_t i, char c1, char c2)
{
/* No test for []{} since they have special meaning for pseudo Bidi */
static char mates1Chars[] = "<>()";
static char mates2Chars[] = "><)(";
UBiDiLevel level;
int k, len;
if (c1 == c2) {
return true;
}
/* For UBIDI_REORDER_RUNS_ONLY, it would not be correct to check levels[i],
so we use the appropriate run's level, which is good for all cases.
*/
ubidi_getLogicalRun(bidi, i, NULL, &level);
if ((level & 1) == 0) {
return false;
}
len = (int)strlen(mates1Chars);
for (k = 0; k < len; k++) {
if ((c1 == mates1Chars[k]) && (c2 == mates2Chars[k])) {
return true;
}
}
return false;
}
static UBool checkWhatYouCan(UBiDi *bidi, const char *srcChars, const char *dstChars)
/* srcChars and dstChars are char arrays encoded as pseudo Bidi */
{
int32_t i, idx, logLimit, visLimit;
UBool testOK, errMap, errDst;
UErrorCode errorCode=U_ZERO_ERROR;
int32_t visMap[MAXLEN];
int32_t logMap[MAXLEN];
char accumSrc[MAXLEN];
char accumDst[MAXLEN];
ubidi_getVisualMap(bidi, visMap, &errorCode);
ubidi_getLogicalMap(bidi, logMap, &errorCode);
if (U_FAILURE(errorCode)) {
log_err("Error #1 invoking ICU within checkWhatYouCan\n");
return false;
}
testOK = true;
errMap = errDst = false;
logLimit = ubidi_getProcessedLength(bidi);
visLimit = ubidi_getResultLength(bidi);
memset(accumSrc, '?', logLimit);
memset(accumDst, '?', visLimit);
for (i = 0; i < logLimit; i++) {
idx = ubidi_getVisualIndex(bidi, i, &errorCode);
if (idx != logMap[i]) {
errMap = true;
}
if (idx == UBIDI_MAP_NOWHERE) {
continue;
}
if (idx >= visLimit) {
continue;
}
accumDst[idx] = srcChars[i];
if (!matchingPair(bidi, i, srcChars[i], dstChars[idx])) {
errDst = true;
}
}
accumDst[visLimit] = 0;
if (U_FAILURE(errorCode)) {
log_err("Error #2 invoking ICU within checkWhatYouCan\n");
return false;
}
if (errMap) {
if (testOK) {
printCaseInfo(bidi, srcChars, dstChars);
testOK = false;
}
log_err("Mismatch between getLogicalMap() and getVisualIndex()\n");
log_err("Map :");
for (i = 0; i < logLimit; i++) {
log_err(" %d", logMap[i]);
}
fputs("\n", stderr);
log_err("Indexes:");
for (i = 0; i < logLimit; i++) {
log_err(" %d", ubidi_getVisualIndex(bidi, i, &errorCode));
}
fputs("\n", stderr);
}
if (errDst) {
if (testOK) {
printCaseInfo(bidi, srcChars, dstChars);
testOK = false;
}
log_err("Source does not map to Result\n");
log_err("We got: %s", accumDst); fputs("\n", stderr);
}
errMap = errDst = false;
for (i = 0; i < visLimit; i++) {
idx = ubidi_getLogicalIndex(bidi, i, &errorCode);
if (idx != visMap[i]) {
errMap = true;
}
if (idx == UBIDI_MAP_NOWHERE) {
continue;
}
if (idx >= logLimit) {
continue;
}
accumSrc[idx] = dstChars[i];
if (!matchingPair(bidi, idx, srcChars[idx], dstChars[i])) {
errDst = true;
}
}
accumSrc[logLimit] = 0;
if (U_FAILURE(errorCode)) {
log_err("Error #3 invoking ICU within checkWhatYouCan\n");
return false;
}
if (errMap) {
if (testOK) {
printCaseInfo(bidi, srcChars, dstChars);
testOK = false;
}
log_err("Mismatch between getVisualMap() and getLogicalIndex()\n");
log_err("Map :");
for (i = 0; i < visLimit; i++) {
log_err(" %d", visMap[i]);
}
fputs("\n", stderr);
log_err("Indexes:");
for (i = 0; i < visLimit; i++) {
log_err(" %d", ubidi_getLogicalIndex(bidi, i, &errorCode));
}
fputs("\n", stderr);
}
if (errDst) {
if (testOK) {
printCaseInfo(bidi, srcChars, dstChars);
testOK = false;
}
log_err("Result does not map to Source\n");
log_err("We got: %s", accumSrc);
fputs("\n", stderr);
}
return testOK;
}
static void
testReorder(void) {
static const char* const logicalOrder[] ={
"del(KC)add(K.C.&)",
"del(QDVT) add(BVDL)",
"del(PQ)add(R.S.)T)U.&",
"del(LV)add(L.V.) L.V.&",
"day 0 R DPDHRVR dayabbr",
"day 1 H DPHPDHDA dayabbr",
"day 2 L DPBLENDA dayabbr",
"day 3 J DPJQVM dayabbr",
"day 4 I DPIQNF dayabbr",
"day 5 M DPMEG dayabbr",
"helloDPMEG",
"hello WXY"
};
static const char* const visualOrder[]={
"del(CK)add(&.C.K)",
"del(TVDQ) add(LDVB)",
"del(QP)add(S.R.)&.U(T", /* updated for Unicode 6.3 matching brackets */
"del(VL)add(V.L.) &.V.L", /* updated for Unicode 6.3 matching brackets */
"day 0 RVRHDPD R dayabbr",
"day 1 ADHDPHPD H dayabbr",
"day 2 ADNELBPD L dayabbr",
"day 3 MVQJPD J dayabbr",
"day 4 FNQIPD I dayabbr",
"day 5 GEMPD M dayabbr",
"helloGEMPD",
"hello YXW"
};
static const char* const visualOrder1[]={
")K.C.&(dda)KC(led",
")BVDL(dda )QDVT(led",
"T(U.&).R.S(dda)PQ(led", /* updated for Unicode 6.3 matching brackets */
"L.V.& ).L.V(dda)LV(led", /* updated for Unicode 6.3 matching brackets */
"rbbayad R DPDHRVR 0 yad",
"rbbayad H DPHPDHDA 1 yad",
"rbbayad L DPBLENDA 2 yad",
"rbbayad J DPJQVM 3 yad",
"rbbayad I DPIQNF 4 yad",
"rbbayad M DPMEG 5 yad",
"DPMEGolleh",
"WXY olleh"
};
static const char* const visualOrder2[]={
"@)@K.C.&@(dda)@KC@(led",
"@)@BVDL@(dda )@QDVT@(led",
"R.S.)T)U.&@(dda)@PQ@(led",
"L.V.) L.V.&@(dda)@LV@(led",
"rbbayad @R DPDHRVR@ 0 yad",
"rbbayad @H DPHPDHDA@ 1 yad",
"rbbayad @L DPBLENDA@ 2 yad",
"rbbayad @J DPJQVM@ 3 yad",
"rbbayad @I DPIQNF@ 4 yad",
"rbbayad @M DPMEG@ 5 yad",
"DPMEGolleh",
"WXY@ olleh"
};
static const char* const visualOrder3[]={
")K.C.&(KC)dda(led",
")BVDL(ddaQDVT) (led",
"R.S.)T)U.&(PQ)dda(led",
"L.V.) L.V.&(LV)dda(led",
"rbbayad DPDHRVR R 0 yad",
"rbbayad DPHPDHDA H 1 yad",
"rbbayad DPBLENDA L 2 yad",
"rbbayad DPJQVM J 3 yad",
"rbbayad DPIQNF I 4 yad",
"rbbayad DPMEG M 5 yad",
"DPMEGolleh",
"WXY olleh"
};
static const char* const visualOrder4[]={
"del(add(CK(.C.K)",
"del( (TVDQadd(LDVB)",
"del(add(QP(.U(T(.S.R",
"del(add(VL(.V.L (.V.L",
"day 0 R RVRHDPD dayabbr",
"day 1 H ADHDPHPD dayabbr",
"day 2 L ADNELBPD dayabbr",
"day 3 J MVQJPD dayabbr",
"day 4 I FNQIPD dayabbr",
"day 5 M GEMPD dayabbr",
"helloGEMPD",
"hello YXW"
};
char formatChars[MAXLEN];
UErrorCode ec = U_ZERO_ERROR;
UBiDi* bidi = ubidi_open();
int i;
log_verbose("\nEntering TestReorder\n\n");
for(i=0;i<UPRV_LENGTHOF(logicalOrder);i++){
int32_t srcSize = (int32_t)strlen(logicalOrder[i]);
int32_t destSize = srcSize*2;
UChar src[MAXLEN];
UChar dest[MAXLEN];
char chars[MAXLEN];
log_verbose("Testing L2V #1 for case %d\n", i);
pseudoToU16(srcSize,logicalOrder[i],src);
ec = U_ZERO_ERROR;
ubidi_setPara(bidi,src,srcSize,UBIDI_DEFAULT_LTR ,NULL,&ec);
if(U_FAILURE(ec)){
log_err("ubidi_setPara(tests[%d], paraLevel %d) failed with errorCode %s\n",
i, UBIDI_DEFAULT_LTR, u_errorName(ec));
}
/* try pre-flighting */
destSize = ubidi_writeReordered(bidi,dest,0,UBIDI_DO_MIRRORING,&ec);
if(ec!=U_BUFFER_OVERFLOW_ERROR){
log_err("Pre-flighting did not give expected error: Expected: U_BUFFER_OVERFLOW_ERROR. Got: %s \n",u_errorName(ec));
}else if(destSize!=srcSize){
log_err("Pre-flighting did not give expected size: Expected: %d. Got: %d \n",srcSize,destSize);
}else{
ec= U_ZERO_ERROR;
}
destSize=ubidi_writeReordered(bidi,dest,destSize+1,UBIDI_DO_MIRRORING,&ec);
u16ToPseudo(destSize,dest,chars);
if(destSize!=srcSize){
log_err("ubidi_writeReordered() destSize and srcSize do not match\n");
}else if(strcmp(visualOrder[i],chars)!=0){
log_err("ubidi_writeReordered() did not give expected results for UBIDI_DO_MIRRORING.\n"
"Input : %s\nExpected: %s\nGot : %s\nLevels : %s\nAt Index: %d\n",
logicalOrder[i],visualOrder[i],chars,formatLevels(bidi, formatChars),i);
}
checkWhatYouCan(bidi, logicalOrder[i], chars);
}
for(i=0;i<UPRV_LENGTHOF(logicalOrder);i++){
int32_t srcSize = (int32_t)strlen(logicalOrder[i]);
int32_t destSize = srcSize*2;
UChar src[MAXLEN];
UChar dest[MAXLEN];
char chars[MAXLEN];
log_verbose("Testing L2V #2 for case %d\n", i);
pseudoToU16(srcSize,logicalOrder[i],src);
ec = U_ZERO_ERROR;
ubidi_setPara(bidi,src,srcSize,UBIDI_DEFAULT_LTR ,NULL,&ec);
if(U_FAILURE(ec)){
log_err("ubidi_setPara(tests[%d], paraLevel %d) failed with errorCode %s\n",
i, UBIDI_DEFAULT_LTR, u_errorName(ec));
}
/* try pre-flighting */
destSize = ubidi_writeReordered(bidi,dest,0,UBIDI_DO_MIRRORING+UBIDI_OUTPUT_REVERSE,&ec);
if(ec!=U_BUFFER_OVERFLOW_ERROR){
log_err("Pre-flighting did not give expected error: Expected: U_BUFFER_OVERFLOW_ERROR. Got: %s \n",u_errorName(ec));
}else if(destSize!=srcSize){
log_err("Pre-flighting did not give expected size: Expected: %d. Got: %d \n",srcSize,destSize);
}else{
ec= U_ZERO_ERROR;
}
destSize=ubidi_writeReordered(bidi,dest,destSize+1,UBIDI_DO_MIRRORING+UBIDI_OUTPUT_REVERSE,&ec);
u16ToPseudo(destSize,dest,chars);
if(destSize!=srcSize){
log_err("ubidi_writeReordered() destSize and srcSize do not match\n");
}else if(strcmp(visualOrder1[i],chars)!=0){
log_err("ubidi_writeReordered() did not give expected results for UBIDI_DO_MIRRORING+UBIDI_OUTPUT_REVERSE.\n"
"Input : %s\nExpected: %s\nGot : %s\nLevels : %s\nAt Index: %d\n",
logicalOrder[i],visualOrder1[i],chars,formatLevels(bidi, formatChars),i);
}
}
for(i=0;i<UPRV_LENGTHOF(logicalOrder);i++){
int32_t srcSize = (int32_t)strlen(logicalOrder[i]);
int32_t destSize = srcSize*2;
UChar src[MAXLEN];
UChar dest[MAXLEN];
char chars[MAXLEN];
log_verbose("Testing V2L #3 for case %d\n", i);
pseudoToU16(srcSize,logicalOrder[i],src);
ec = U_ZERO_ERROR;
ubidi_setInverse(bidi,true);
ubidi_setPara(bidi,src,srcSize,UBIDI_DEFAULT_LTR ,NULL,&ec);
if(U_FAILURE(ec)){
log_err("ubidi_setPara(tests[%d], paraLevel %d) failed with errorCode %s\n",
i, UBIDI_DEFAULT_LTR, u_errorName(ec));
}
/* try pre-flighting */
destSize = ubidi_writeReordered(bidi,dest,0,UBIDI_INSERT_LRM_FOR_NUMERIC+UBIDI_OUTPUT_REVERSE,&ec);
if(ec!=U_BUFFER_OVERFLOW_ERROR){
log_err("Pre-flighting did not give expected error: Expected: U_BUFFER_OVERFLOW_ERROR. Got: %s \n",u_errorName(ec));
}else{
ec= U_ZERO_ERROR;
}
destSize=ubidi_writeReordered(bidi,dest,destSize+1,UBIDI_INSERT_LRM_FOR_NUMERIC+UBIDI_OUTPUT_REVERSE,&ec);
u16ToPseudo(destSize,dest,chars);
if(strcmp(visualOrder2[i],chars)!=0){
log_err("ubidi_writeReordered() did not give expected results for UBIDI_INSERT_LRM_FOR_NUMERIC+UBIDI_OUTPUT_REVERSE.\n"
"Input : %s\nExpected: %s\nGot : %s\nLevels : %s\nAt Index: %d\n",
logicalOrder[i],visualOrder2[i],chars,formatLevels(bidi, formatChars),i);
}
}
/* Max Explicit level */
for(i=0;i<UPRV_LENGTHOF(logicalOrder);i++){
int32_t srcSize = (int32_t)strlen(logicalOrder[i]);
int32_t destSize = srcSize*2;
UChar src[MAXLEN];
UChar dest[MAXLEN];
char chars[MAXLEN];
UBiDiLevel levels[UBIDI_MAX_EXPLICIT_LEVEL]={1,2,3,4,5,6,7,8,9,10};
log_verbose("Testing V2L #4 for case %d\n", i);
pseudoToU16(srcSize,logicalOrder[i],src);
ec = U_ZERO_ERROR;
ubidi_setPara(bidi,src,srcSize,UBIDI_DEFAULT_LTR,levels,&ec);
if(U_FAILURE(ec)){
log_err("ubidi_setPara(tests[%d], paraLevel %d) failed with errorCode %s\n",
i, UBIDI_MAX_EXPLICIT_LEVEL, u_errorName(ec));
}
/* try pre-flighting */
destSize = ubidi_writeReordered(bidi,dest,0,UBIDI_OUTPUT_REVERSE,&ec);
if(ec!=U_BUFFER_OVERFLOW_ERROR){
log_err("Pre-flighting did not give expected error: Expected: U_BUFFER_OVERFLOW_ERROR. Got: %s \n",u_errorName(ec));
}else if(destSize!=srcSize){
log_err("Pre-flighting did not give expected size: Expected: %d. Got: %d \n",srcSize,destSize);
}else{
ec = U_ZERO_ERROR;
}
destSize=ubidi_writeReordered(bidi,dest,destSize+1,UBIDI_OUTPUT_REVERSE,&ec);
u16ToPseudo(destSize,dest,chars);
if(destSize!=srcSize){
log_err("ubidi_writeReordered() destSize and srcSize do not match. Dest Size = %d Source Size = %d\n",destSize,srcSize );
}else if(strcmp(visualOrder3[i],chars)!=0){
log_err("ubidi_writeReordered() did not give expected results for UBIDI_OUTPUT_REVERSE.\n"
"Input : %s\nExpected: %s\nGot : %s\nLevels : %s\nAt Index: %d\n",
logicalOrder[i],visualOrder3[i],chars,formatLevels(bidi, formatChars),i);
}
}
for(i=0;i<UPRV_LENGTHOF(logicalOrder);i++){
int32_t srcSize = (int32_t)strlen(logicalOrder[i]);
int32_t destSize = srcSize*2;
UChar src[MAXLEN];
UChar dest[MAXLEN];
char chars[MAXLEN];
UBiDiLevel levels[UBIDI_MAX_EXPLICIT_LEVEL]={1,2,3,4,5,6,7,8,9,10};
log_verbose("Testing V2L #5 for case %d\n", i);
pseudoToU16(srcSize,logicalOrder[i],src);
ec = U_ZERO_ERROR;
ubidi_setPara(bidi,src,srcSize,UBIDI_DEFAULT_LTR,levels,&ec);
if(U_FAILURE(ec)){
log_err("ubidi_setPara(tests[%d], paraLevel %d) failed with errorCode %s\n",
i, UBIDI_MAX_EXPLICIT_LEVEL, u_errorName(ec));
}
/* try pre-flighting */
destSize = ubidi_writeReordered(bidi,dest,0,UBIDI_DO_MIRRORING+UBIDI_REMOVE_BIDI_CONTROLS,&ec);
if(ec!=U_BUFFER_OVERFLOW_ERROR){
log_err("Pre-flighting did not give expected error: Expected: U_BUFFER_OVERFLOW_ERROR. Got: %s \n",u_errorName(ec));
}else{
ec= U_ZERO_ERROR;
}
destSize=ubidi_writeReordered(bidi,dest,destSize+1,UBIDI_DO_MIRRORING+UBIDI_REMOVE_BIDI_CONTROLS,&ec);
u16ToPseudo(destSize,dest,chars);
if(strcmp(visualOrder4[i],chars)!=0){
log_err("ubidi_writeReordered() did not give expected results for UBIDI_DO_MIRRORING+UBIDI_REMOVE_BIDI_CONTROLS.\n"
"Input : %s\nExpected: %s\nGot : %s\nLevels : %s\nAt Index: %d\n",
logicalOrder[i],visualOrder4[i],chars,formatLevels(bidi, formatChars),i);
}
}
ubidi_close(bidi);
log_verbose("\nExiting TestReorder\n\n");
}
static void
testReorderArabicMathSymbols(void) {
static const UChar logicalOrder[][MAXLEN]={
/* Arabic mathematical Symbols 0x1EE00 - 0x1EE1B */
{0xD83B, 0xDE00, 0xD83B, 0xDE01, 0xD83B, 0xDE02, 0xD83B, 0xDE03, 0x20,
0xD83B, 0xDE24, 0xD83B, 0xDE05, 0xD83B, 0xDE06, 0x20,
0xD83B, 0xDE07, 0xD83B, 0xDE08, 0xD83B, 0xDE09, 0x20,
0xD83B, 0xDE0A, 0xD83B, 0xDE0B, 0xD83B, 0xDE0C, 0xD83B, 0xDE0D, 0x20,
0xD83B, 0xDE0E, 0xD83B, 0xDE0F, 0xD83B, 0xDE10, 0xD83B, 0xDE11, 0x20,
0xD83B, 0xDE12, 0xD83B, 0xDE13, 0xD83B, 0xDE14, 0xD83B, 0xDE15, 0x20,
0xD83B, 0xDE16, 0xD83B, 0xDE17, 0xD83B, 0xDE18, 0x20,
0xD83B, 0xDE19, 0xD83B, 0xDE1A, 0xD83B, 0xDE1B},
/* Arabic mathematical Symbols - Looped Symbols, 0x1EE80 - 0x1EE9B */
{0xD83B, 0xDE80, 0xD83B, 0xDE81, 0xD83B, 0xDE82, 0xD83B, 0xDE83, 0x20,
0xD83B, 0xDE84, 0xD83B, 0xDE85, 0xD83B, 0xDE86, 0x20,
0xD83B, 0xDE87, 0xD83B, 0xDE88, 0xD83B, 0xDE89, 0x20,
0xD83B, 0xDE8B, 0xD83B, 0xDE8C, 0xD83B, 0xDE8D, 0x20,
0xD83B, 0xDE8E, 0xD83B, 0xDE8F, 0xD83B, 0xDE90, 0xD83B, 0xDE91, 0x20,
0xD83B, 0xDE92, 0xD83B, 0xDE93, 0xD83B, 0xDE94, 0xD83B, 0xDE95, 0x20,
0xD83B, 0xDE96, 0xD83B, 0xDE97, 0xD83B, 0xDE98, 0x20,
0xD83B, 0xDE99, 0xD83B, 0xDE9A, 0xD83B, 0xDE9B},
/* Arabic mathematical Symbols - Double-struck Symbols, 0x1EEA1 - 0x1EEBB */
{0xD83B, 0xDEA1, 0xD83B, 0xDEA2, 0xD83B, 0xDEA3, 0x20,
0xD83B, 0xDEA5, 0xD83B, 0xDEA6, 0x20,
0xD83B, 0xDEA7, 0xD83B, 0xDEA8, 0xD83B, 0xDEA9, 0x20,
0xD83B, 0xDEAB, 0xD83B, 0xDEAC, 0xD83B, 0xDEAD, 0x20,
0xD83B, 0xDEAE, 0xD83B, 0xDEAF, 0xD83B, 0xDEB0, 0xD83B, 0xDEB1, 0x20,
0xD83B, 0xDEB2, 0xD83B, 0xDEB3, 0xD83B, 0xDEB4, 0xD83B, 0xDEB5, 0x20,
0xD83B, 0xDEB6, 0xD83B, 0xDEB7, 0xD83B, 0xDEB8, 0x20,
0xD83B, 0xDEB9, 0xD83B, 0xDEBA, 0xD83B, 0xDEBB},
/* Arabic mathematical Symbols - Initial Symbols, 0x1EE21 - 0x1EE3B */
{0xD83B, 0xDE21, 0xD83B, 0xDE22, 0x20,
0xD83B, 0xDE27, 0xD83B, 0xDE29, 0x20,
0xD83B, 0xDE2A, 0xD83B, 0xDE2B, 0xD83B, 0xDE2C, 0xD83B, 0xDE2D, 0x20,
0xD83B, 0xDE2E, 0xD83B, 0xDE2F, 0xD83B, 0xDE30, 0xD83B, 0xDE31, 0x20,
0xD83B, 0xDE32, 0xD83B, 0xDE34, 0xD83B, 0xDE35, 0x20,
0xD83B, 0xDE36, 0xD83B, 0xDE37, 0x20,
0xD83B, 0xDE39, 0xD83B, 0xDE3B},
/* Arabic mathematical Symbols - Tailed Symbols */
{0xD83B, 0xDE42, 0xD83B, 0xDE47, 0xD83B, 0xDE49, 0xD83B, 0xDE4B, 0x20,
0xD83B, 0xDE4D, 0xD83B, 0xDE4E, 0xD83B, 0xDE4F, 0x20,
0xD83B, 0xDE51, 0xD83B, 0xDE52, 0xD83B, 0xDE54, 0xD83B, 0xDE57, 0x20,
0xD83B, 0xDE59, 0xD83B, 0xDE5B, 0xD83B, 0xDE5D, 0xD83B, 0xDE5F}
};
static const UChar visualOrder[][MAXLEN]={
/* Arabic mathematical Symbols 0x1EE00 - 0x1EE1B */
{0xD83B, 0xDE1B, 0xD83B, 0xDE1A, 0xD83B, 0xDE19, 0x20,
0xD83B, 0xDE18, 0xD83B, 0xDE17, 0xD83B, 0xDE16, 0x20,
0xD83B, 0xDE15, 0xD83B, 0xDE14, 0xD83B, 0xDE13, 0xD83B, 0xDE12, 0x20,
0xD83B, 0xDE11, 0xD83B, 0xDE10, 0xD83B, 0xDE0F, 0xD83B, 0xDE0E, 0x20,
0xD83B, 0xDE0D, 0xD83B, 0xDE0C, 0xD83B, 0xDE0B, 0xD83B, 0xDE0A, 0x20,
0xD83B, 0xDE09, 0xD83B, 0xDE08, 0xD83B, 0xDE07, 0x20,
0xD83B, 0xDE06, 0xD83B, 0xDE05, 0xD83B, 0xDE24, 0x20,
0xD83B, 0xDE03, 0xD83B, 0xDE02, 0xD83B, 0xDE01, 0xD83B, 0xDE00},
/* Arabic mathematical Symbols - Looped Symbols, 0x1EE80 - 0x1EE9B */
{0xD83B, 0xDE9B, 0xD83B, 0xDE9A, 0xD83B, 0xDE99, 0x20,
0xD83B, 0xDE98, 0xD83B, 0xDE97, 0xD83B, 0xDE96, 0x20,
0xD83B, 0xDE95, 0xD83B, 0xDE94, 0xD83B, 0xDE93, 0xD83B, 0xDE92, 0x20,
0xD83B, 0xDE91, 0xD83B, 0xDE90, 0xD83B, 0xDE8F, 0xD83B, 0xDE8E, 0x20,
0xD83B, 0xDE8D, 0xD83B, 0xDE8C, 0xD83B, 0xDE8B, 0x20,
0xD83B, 0xDE89, 0xD83B, 0xDE88, 0xD83B, 0xDE87, 0x20,
0xD83B, 0xDE86, 0xD83B, 0xDE85, 0xD83B, 0xDE84, 0x20,
0xD83B, 0xDE83, 0xD83B, 0xDE82, 0xD83B, 0xDE81, 0xD83B, 0xDE80},
/* Arabic mathematical Symbols - Double-struck Symbols, 0x1EEA1 - 0x1EEBB */
{0xD83B, 0xDEBB, 0xD83B, 0xDEBA, 0xD83B, 0xDEB9, 0x20,
0xD83B, 0xDEB8, 0xD83B, 0xDEB7, 0xD83B, 0xDEB6, 0x20,
0xD83B, 0xDEB5, 0xD83B, 0xDEB4, 0xD83B, 0xDEB3, 0xD83B, 0xDEB2, 0x20,
0xD83B, 0xDEB1, 0xD83B, 0xDEB0, 0xD83B, 0xDEAF, 0xD83B, 0xDEAE, 0x20,
0xD83B, 0xDEAD, 0xD83B, 0xDEAC, 0xD83B, 0xDEAB, 0x20,
0xD83B, 0xDEA9, 0xD83B, 0xDEA8, 0xD83B, 0xDEA7, 0x20,
0xD83B, 0xDEA6, 0xD83B, 0xDEA5, 0x20,
0xD83B, 0xDEA3, 0xD83B, 0xDEA2, 0xD83B, 0xDEA1},
/* Arabic mathematical Symbols - Initial Symbols, 0x1EE21 - 0x1EE3B */
{0xD83B, 0xDE3B, 0xD83B, 0xDE39, 0x20,
0xD83B, 0xDE37, 0xD83B, 0xDE36, 0x20,
0xD83B, 0xDE35, 0xD83B, 0xDE34, 0xD83B, 0xDE32, 0x20,
0xD83B, 0xDE31, 0xD83B, 0xDE30, 0xD83B, 0xDE2F, 0xD83B, 0xDE2E, 0x20,
0xD83B, 0xDE2D, 0xD83B, 0xDE2C, 0xD83B, 0xDE2B, 0xD83B, 0xDE2A, 0x20,
0xD83B, 0xDE29, 0xD83B, 0xDE27, 0x20,
0xD83B, 0xDE22, 0xD83B, 0xDE21},
/* Arabic mathematical Symbols - Tailed Symbols */
{0xD83B, 0xDE5F, 0xD83B, 0xDE5D, 0xD83B, 0xDE5B, 0xD83B, 0xDE59, 0x20,
0xD83B, 0xDE57, 0xD83B, 0xDE54, 0xD83B, 0xDE52, 0xD83B, 0xDE51, 0x20,
0xD83B, 0xDE4F, 0xD83B, 0xDE4E, 0xD83B, 0xDE4D, 0x20,
0xD83B, 0xDE4B, 0xD83B, 0xDE49, 0xD83B, 0xDE47, 0xD83B, 0xDE42}