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
|
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
|
-
+
-
+
-
+
-
+
-
+
-
+
-
+
|
OFHTTPRequest *request;
[of_stdout writeString: @"Parsing UnicodeData.txt…"];
while ((line = [response readLine]) != nil) {
void *pool2;
OFArray OF_GENERIC(OFString *) *components;
of_unichar_t codePoint;
OFUnichar codePoint;
if (line.length == 0)
continue;
pool2 = objc_autoreleasePoolPush();
components = [line componentsSeparatedByString: @";"];
if (components.count != 15) {
of_log(@"Invalid line: %@\n", line);
[OFApplication terminateWithStatus: 1];
}
codePoint = (of_unichar_t)[[components objectAtIndex: 0]
codePoint = (OFUnichar)[[components objectAtIndex: 0]
unsignedLongLongValueWithBase: 16];
if (codePoint > 0x10FFFF)
@throw [OFOutOfRangeException exception];
_uppercaseTable[codePoint] = (of_unichar_t)[[components
_uppercaseTable[codePoint] = (OFUnichar)[[components
objectAtIndex: 12] unsignedLongLongValueWithBase: 16];
_lowercaseTable[codePoint] = (of_unichar_t)[[components
_lowercaseTable[codePoint] = (OFUnichar)[[components
objectAtIndex: 13] unsignedLongLongValueWithBase: 16];
_titlecaseTable[codePoint] = (of_unichar_t)[[components
_titlecaseTable[codePoint] = (OFUnichar)[[components
objectAtIndex: 14] unsignedLongLongValueWithBase: 16];
if ([[components objectAtIndex: 5] length] > 0) {
OFArray *decomposed = [[components objectAtIndex: 5]
componentsSeparatedByString: @" "];
bool compat = false;
OFMutableString *string;
if ([decomposed.firstObject hasPrefix: @"<"]) {
decomposed = [decomposed objectsInRange:
of_range(1, decomposed.count - 1)];
OFMakeRange(1, decomposed.count - 1)];
compat = true;
}
string = [OFMutableString string];
for (OFString *character in decomposed) {
of_unichar_t unichar = (of_unichar_t)[character
OFUnichar unichar = (OFUnichar)[character
unsignedLongLongValueWithBase: 16];
[string appendCharacters: &unichar
length: 1];
}
[string makeImmutable];
|
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
|
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
|
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
|
OFFile *file = [OFFile fileWithPath: path
mode: @"w"];
[file writeString: COPYRIGHT
@"#include \"config.h\"\n"
@"\n"
@"#import \"OFString.h\"\n\n"
@"static const of_unichar_t emptyPage[0x100] = { 0 };\n"
@"static const OFUnichar emptyPage[0x100] = { 0 };\n"
@"static const char *emptyDecompositionPage[0x100] = { NULL };\n"
@"\n"];
/* Write uppercasePage%u */
for (of_unichar_t i = 0; i < 0x110000; i += 0x100) {
for (OFUnichar i = 0; i < 0x110000; i += 0x100) {
bool isEmpty = true;
for (of_unichar_t j = i; j < i + 0x100; j++) {
for (OFUnichar j = i; j < i + 0x100; j++) {
if (_uppercaseTable[j] != 0) {
isEmpty = false;
_uppercaseTableSize = i >> 8;
_uppercaseTableUsed[_uppercaseTableSize] = 1;
break;
}
}
if (!isEmpty) {
void *pool2 = objc_autoreleasePoolPush();
[file writeFormat: @"static const of_unichar_t "
[file writeFormat: @"static const OFUnichar "
@"uppercasePage%u[0x100] = {\n",
i >> 8];
for (of_unichar_t j = i; j < i + 0x100; j += 8)
for (OFUnichar j = i; j < i + 0x100; j += 8)
[file writeFormat:
@"\t%u, %u, %u, %u, %u, %u, %u, %u,\n",
_uppercaseTable[j],
_uppercaseTable[j + 1],
_uppercaseTable[j + 2],
_uppercaseTable[j + 3],
_uppercaseTable[j + 4],
_uppercaseTable[j + 5],
_uppercaseTable[j + 6],
_uppercaseTable[j + 7]];
[file writeString: @"};\n\n"];
objc_autoreleasePoolPop(pool2);
}
}
/* Write lowercasePage%u */
for (of_unichar_t i = 0; i < 0x110000; i += 0x100) {
for (OFUnichar i = 0; i < 0x110000; i += 0x100) {
bool isEmpty = true;
for (of_unichar_t j = i; j < i + 0x100; j++) {
for (OFUnichar j = i; j < i + 0x100; j++) {
if (_lowercaseTable[j] != 0) {
isEmpty = false;
_lowercaseTableSize = i >> 8;
_lowercaseTableUsed[_lowercaseTableSize] = 1;
break;
}
}
if (!isEmpty) {
void *pool2 = objc_autoreleasePoolPush();
[file writeFormat: @"static const of_unichar_t "
[file writeFormat: @"static const OFUnichar "
@"lowercasePage%u[0x100] = {\n",
i >> 8];
for (of_unichar_t j = i; j < i + 0x100; j += 8)
for (OFUnichar j = i; j < i + 0x100; j += 8)
[file writeFormat:
@"\t%u, %u, %u, %u, %u, %u, %u, %u,\n",
_lowercaseTable[j],
_lowercaseTable[j + 1],
_lowercaseTable[j + 2],
_lowercaseTable[j + 3],
_lowercaseTable[j + 4],
_lowercaseTable[j + 5],
_lowercaseTable[j + 6],
_lowercaseTable[j + 7]];
[file writeString: @"};\n\n"];
objc_autoreleasePoolPop(pool2);
}
}
/* Write titlecasePage%u if it does NOT match uppercasePage%u */
for (of_unichar_t i = 0; i < 0x110000; i += 0x100) {
for (OFUnichar i = 0; i < 0x110000; i += 0x100) {
bool isEmpty = true;
for (of_unichar_t j = i; j < i + 0x100; j++) {
for (OFUnichar j = i; j < i + 0x100; j++) {
if (_titlecaseTable[j] != 0) {
isEmpty = !memcmp(_uppercaseTable + i,
_titlecaseTable + i,
256 * sizeof(of_unichar_t));
256 * sizeof(OFUnichar));
_titlecaseTableSize = i >> 8;
_titlecaseTableUsed[_titlecaseTableSize] =
(isEmpty ? 2 : 1);
break;
}
}
if (!isEmpty) {
void *pool2 = objc_autoreleasePoolPush();
[file writeFormat: @"static const of_unichar_t "
[file writeFormat: @"static const OFUnichar "
@"titlecasePage%u[0x100] = {\n",
i >> 8];
for (of_unichar_t j = i; j < i + 0x100; j += 8)
for (OFUnichar j = i; j < i + 0x100; j += 8)
[file writeFormat:
@"\t%u, %u, %u, %u, %u, %u, %u, %u,\n",
_titlecaseTable[j],
_titlecaseTable[j + 1],
_titlecaseTable[j + 2],
_titlecaseTable[j + 3],
_titlecaseTable[j + 4],
_titlecaseTable[j + 5],
_titlecaseTable[j + 6],
_titlecaseTable[j + 7]];
[file writeString: @"};\n\n"];
objc_autoreleasePoolPop(pool2);
}
}
/* Write casefoldingPage%u if it does NOT match lowercasePage%u */
for (of_unichar_t i = 0; i < 0x110000; i += 0x100) {
for (OFUnichar i = 0; i < 0x110000; i += 0x100) {
bool isEmpty = true;
for (of_unichar_t j = i; j < i + 0x100; j++) {
for (OFUnichar j = i; j < i + 0x100; j++) {
if (_casefoldingTable[j] != 0) {
isEmpty = !memcmp(_lowercaseTable + i,
_casefoldingTable + i,
256 * sizeof(of_unichar_t));
256 * sizeof(OFUnichar));
_casefoldingTableSize = i >> 8;
_casefoldingTableUsed[_casefoldingTableSize] =
(isEmpty ? 2 : 1);
break;
}
}
if (!isEmpty) {
void *pool2 = objc_autoreleasePoolPush();
[file writeFormat: @"static const of_unichar_t "
[file writeFormat: @"static const OFUnichar "
@"casefoldingPage%u[0x100] = {\n",
i >> 8];
for (of_unichar_t j = i; j < i + 0x100; j += 8)
for (OFUnichar j = i; j < i + 0x100; j += 8)
[file writeFormat:
@"\t%u, %u, %u, %u, %u, %u, %u, %u,\n",
_casefoldingTable[j],
_casefoldingTable[j + 1],
_casefoldingTable[j + 2],
_casefoldingTable[j + 3],
_casefoldingTable[j + 4],
_casefoldingTable[j + 5],
_casefoldingTable[j + 6],
_casefoldingTable[j + 7]];
[file writeString: @"};\n\n"];
objc_autoreleasePoolPop(pool2);
}
}
/* Write decompositionPage%u */
for (of_unichar_t i = 0; i < 0x110000; i += 0x100) {
for (OFUnichar i = 0; i < 0x110000; i += 0x100) {
bool isEmpty = true;
for (of_unichar_t j = i; j < i + 0x100; j++) {
for (OFUnichar j = i; j < i + 0x100; j++) {
if (_decompositionTable[j] != nil) {
isEmpty = false;
_decompositionTableSize = i >> 8;
_decompositionTableUsed[
_decompositionTableSize] = 1;
break;
}
}
if (!isEmpty) {
void *pool2 = objc_autoreleasePoolPush();
[file writeFormat: @"static const char *const "
@"decompositionPage%u[0x100] = {\n",
i >> 8];
for (of_unichar_t j = i; j < i + 0x100; j++) {
for (OFUnichar j = i; j < i + 0x100; j++) {
if ((j - i) % 2 == 0)
[file writeString: @"\t"];
else
[file writeString: @" "];
if (_decompositionTable[j] != nil) {
const char *UTF8String =
|
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
|
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
|
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
|
_lowercaseTableSize++;
_titlecaseTableSize++;
_casefoldingTableSize++;
_decompositionTableSize++;
_decompositionCompatTableSize++;
/* Write of_unicode_uppercase_table */
[file writeFormat: @"const of_unichar_t *const "
[file writeFormat: @"const OFUnichar *const "
@"of_unicode_uppercase_table[0x%X] = {\n\t",
_uppercaseTableSize];
for (of_unichar_t i = 0; i < _uppercaseTableSize; i++) {
for (OFUnichar i = 0; i < _uppercaseTableSize; i++) {
if (_uppercaseTableUsed[i])
[file writeFormat: @"uppercasePage%u", i];
else
[file writeString: @"emptyPage"];
if (i + 1 < _uppercaseTableSize) {
if ((i + 1) % 4 == 0)
[file writeString: @",\n\t"];
else
[file writeString: @", "];
}
}
[file writeString: @"\n};\n\n"];
/* Write of_unicode_lowercase_table */
[file writeFormat: @"const of_unichar_t *const "
[file writeFormat: @"const OFUnichar *const "
@"of_unicode_lowercase_table[0x%X] = {\n\t",
_lowercaseTableSize];
for (of_unichar_t i = 0; i < _lowercaseTableSize; i++) {
for (OFUnichar i = 0; i < _lowercaseTableSize; i++) {
if (_lowercaseTableUsed[i])
[file writeFormat: @"lowercasePage%u", i];
else
[file writeString: @"emptyPage"];
if (i + 1 < _lowercaseTableSize) {
if ((i + 1) % 4 == 0)
[file writeString: @",\n\t"];
else
[file writeString: @", "];
}
}
[file writeString: @"\n};\n\n"];
/* Write of_unicode_titlecase_table */
[file writeFormat: @"const of_unichar_t *const "
[file writeFormat: @"const OFUnichar *const "
@"of_unicode_titlecase_table[0x%X] = {\n\t",
_titlecaseTableSize];
for (of_unichar_t i = 0; i < _titlecaseTableSize; i++) {
for (OFUnichar i = 0; i < _titlecaseTableSize; i++) {
if (_titlecaseTableUsed[i] == 1)
[file writeFormat: @"titlecasePage%u", i];
else if (_titlecaseTableUsed[i] == 2)
[file writeFormat: @"uppercasePage%u", i];
else
[file writeString: @"emptyPage"];
if (i + 1 < _titlecaseTableSize) {
if ((i + 1) % 4 == 0)
[file writeString: @",\n\t"];
else
[file writeString: @", "];
}
}
[file writeString: @"\n};\n\n"];
/* Write of_unicode_casefolding_table */
[file writeFormat: @"const of_unichar_t *const "
[file writeFormat: @"const OFUnichar *const "
@"of_unicode_casefolding_table[0x%X] = {\n\t",
_casefoldingTableSize];
for (of_unichar_t i = 0; i < _casefoldingTableSize; i++) {
for (OFUnichar i = 0; i < _casefoldingTableSize; i++) {
if (_casefoldingTableUsed[i] == 1)
[file writeFormat: @"casefoldingPage%u", i];
else if (_casefoldingTableUsed[i] == 2)
[file writeFormat: @"lowercasePage%u", i];
else
[file writeString: @"emptyPage"];
|