-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwtswidth.c
More file actions
1078 lines (1011 loc) · 62.4 KB
/
wtswidth.c
File metadata and controls
1078 lines (1011 loc) · 62.4 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
// Copyright (c) 2024-2026 Steffen Illhardt,
// Licensed under the MIT license ( https://opensource.org/license/mit/ ).
//
// However, I don't claim any credits because the essential components of this
// code are not my intellectual properties.
//
// *** 1. ***
// The C code of this library is substantially a copy of C++ code authored and
// published by Microsoft under the MIT license.
// Copyright (c) Microsoft Corporation. All rights reserved.
// ( refer to https://github.com/microsoft/terminal/blob/main/LICENSE )
//
// Source files used:
// https://github.com/microsoft/terminal/blob/main/src/types/inc/CodepointWidthDetector.hpp
// https://github.com/microsoft/terminal/blob/main/src/types/CodepointWidthDetector.cpp
//
// The aforementioned source code was retrieved and modified in September 2024.
// Modifications done:
// - Code removed that is not needed for the purpose of this library.
// - Transcriptions that are necessary and/or reasonable to meet the C syntax.
// The original trie data as well as the algorithms and structures used to
// process the string data are preserved to maintain the original string width
// measurement as used by Windows Terminal and Conhost by default.
//
// For additional information about the implementation and preprocessed Unicode
// data in the trie tables refer to:
// https://github.com/microsoft/terminal/pull/16916
// https://github.com/microsoft/terminal/blob/main/src/tools/GraphemeTableGen/Program.cs
//
// *** 2. ***
// Furthermore, code to convert UTF-8 to a code point is taken from or derived
// from Björn Höhrmann's "Flexible and Economical UTF-8 Decoder".
// Copyright (c) 2008-2010 Bjoern Hoehrmann <bjoern@hoehrmann.de>
// See https://bjoern.hoehrmann.de/utf-8/decoder/dfa/ for details.
// The main difference compared with the original implementation is that ASCII
// is handled separately in the modified code. The transition values are moved
// to the beginning of the lookup table and replace the character class (zero
// values) for ASCII bytes.
#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 202311L
# include <stdbool.h>
#endif
#include <stdint.h>
#include "wtswidth.h"
#if !defined(HEADER_WTSWIDTH_3BD91CCF_2635_44D1_9D88_5114B59F8255_1_3)
# error "wtswidth version mismatch source <=> header"
#elif defined(__GNUC__) || defined(__clang__)
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wdeclaration-after-statement" // C11 is required anyway, no issue here
# if defined(__clang__)
# pragma clang diagnostic ignored "-Wc++-keyword" // uchar.h for char16_t and char32_t is only conditionally included anyway
# pragma clang diagnostic ignored "-Wpre-c23-compat" // bool is a type since C23, it was a macro before
# pragma clang diagnostic ignored "-Wunsafe-buffer-usage" // tons of pointer stuff in this code because it's C, not C++; so ... shh clang!
# endif
#elif defined(_MSC_VER)
# pragma warning(push)
# pragma warning(disable : 4710) // function not inline
# pragma warning(disable : 5045) // spectre mitigation possibly inserted
#endif
// Significant parts of this piece of code are taken from or derived from Björn
// Höhrmann's "Flexible and Economical UTF-8 Decoder".
/* *** begin of Höhrmann's UTF-8 Decoder derived code *** */
typedef struct
{
char32_t codePointCache;
int transitionState;
} U8State;
enum decoderSuccessStates
{
utf8Accept = 0, // transition state indicating that code point creation has been successfully finished
utf8Reject = 12 // transition state indicating that invalid UTF-8 has been found (values >12 are transition states for incomplete code points)
};
static inline void U8NonAsciiDecode(U8State *const pState, const uint8_t codeUnit) // relies on NEVER getting an ASCII value passed to codeUnit
{
// clang-format off
static const uint8_t transitionStatesAndCharClasses[] = {
// The first table is a transition table that maps a combination of a state
// of the automation and a character class to one out of of 108 state values.
0, 12, 24, 36, 60, 96, 84, 12, 12, 12, 48, 72, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
12, 0, 12, 12, 12, 12, 12, 0, 12, 0, 12, 12, 12, 24, 12, 12, 12, 12, 12, 24, 12, 24, 12, 12,
12, 12, 12, 12, 12, 12, 12, 24, 12, 12, 12, 12, 12, 24, 12, 12, 12, 12, 12, 12, 12, 24, 12, 12,
12, 12, 12, 12, 12, 12, 12, 36, 12, 36, 12, 12, 12, 36, 12, 12, 12, 12, 12, 36, 12, 36, 12, 12,
12, 36, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
// 20 bytes filler to avoid additional calculations for index adjustments.
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
// The second table maps the 128 non-ASCII bytes to character classes
// to reduce the size of the transition table and create bit masks.
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
8, 8, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
10, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 3, 3, 11, 6, 6, 6, 5, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8
};
// clang-format on
static const uint32_t continuationBitCnt = 6; // left-shifts the transitional code point value to make room for the next 6 relevant bits of a continuation byte
static const uint8_t continuationMask = 0x3F; // 00'111111, leaves the 6 relevant low order bits of a continuation byte
static const uint8_t fullByteMask = 0xFF; // 11111111, later on right-shifted to get a bit mask that removes the marker bits of a lead byte
const uint8_t charClass = transitionStatesAndCharClasses[codeUnit];
pState->codePointCache = (pState->transitionState > utf8Reject) ?
((pState->codePointCache << continuationBitCnt) | (codeUnit & continuationMask)) : // continuation bytes
(char32_t)(codeUnit & (fullByteMask >> charClass)); // lead bytes
pState->transitionState = transitionStatesAndCharClasses[pState->transitionState + charClass];
}
/* *** end of Höhrmann's UTF-8 Decoder derived code *** */
// Decodes the next codepoint from the given UTF-8 string.
// Returns the start of the next codepoint.
static inline const uint8_t *utf8NextOrFFFD(const uint8_t *it, const uint8_t *const end, char32_t *const pOut)
{
static const uint8_t asciiEnd = 0x7F; // upper bound of the ASCII range
static const char32_t unicodeReplChar = 0xFFFD; // Unicode Replacement Character '�', inserted for invalid UTF-8 sequences
U8State u8State = { 0 };
int prevTransState = utf8Accept;
while (it < end)
{
if (*it <= asciiEnd) // U8NonAsciiDecode() relies on ASCII being handled elsewhere
{
if (u8State.transitionState == utf8Accept) // nothing in the cache -> OK
{
*pOut = *it;
return it + 1;
}
// still an incomplete code point in the cache -> ill-formed UTF-8
*pOut = unicodeReplChar;
return it;
}
prevTransState = u8State.transitionState; // used to synchronize/recover after ill-formed UTF-8 has been found
U8NonAsciiDecode(&u8State, *it); // decode the current UTF-8 code unit, update the transition state
if (u8State.transitionState != utf8Reject) // valid
{
++it;
if (u8State.transitionState > utf8Reject) // still incomplete code point
continue;
*pOut = u8State.codePointCache; // complete code point
return it;
}
break;
}
// ill-formed
if (prevTransState == utf8Accept)
++it;
*pOut = unicodeReplChar;
return it;
}
enum charSizes
{
char8size = sizeof(uint8_t),
char16size = sizeof(char16_t)
};
static inline bool *AmbiguousIsWide(void)
{
// only a bool (unlike wtsambw_t elsewhere) makes some compilers finally consider that there are only 2 states: narrow or wide
static bool _ambiguousIsWide = false;
return &_ambiguousIsWide;
}
// NOTE: Comments in the Terminal derived code are those of the original author of the C++ code that this is based on.
/* *** begin of Windows Terminal derived code *** */
typedef struct
{
// These are the [out] parameters for GraphemeNext/Prev.
//
// If a previous call returned false (= reached the end of the string), then on the first call with
// the next string, beg/len will contain the parts of the grapheme cluster that are found in that
// new string argument. That's true even if the two strings don't join to form a single cluster.
// In that case beg/len will simply be an empty string. It basically tells you
// "Yup, that cluster in the last string was complete after all".
//
// However, width will always be updated to represent the width of the current cluster.
//
// For instance, if the first string is a narrow emoji and the second one is U+FE0F, the first call will return
// the emoji with a width of 1, and the second call will return U+FE0F with a width of 2.
// You know these two belong together because the first call returned false.
// The total width is not 1+2 but rather just 2.
const void *beg;
int len;
// width will always be between 0 or 2.
int width;
// If GraphemeNext/Prev return false (= reached the end of the string), they'll fill these struct
// members with some info so that we can check if it joins with the start of the next string argument.
// _state is stored ~flipped, so that we can differentiate between it being unset (0) and it being set to 0 (~0 = 255).
int _state;
int _last;
} GraphemeState;
// s_stage1/2/3/4 represents a multi-stage table, aka trie.
// The highest bits of the codepoint are an index into s_stage1, which selects a row in s_stage2.
// The next couple bits of the codepoint then select the column in that row.
// This continues until the last stage which contains the final value.
//
// Fundamentally, the trie is generated by taking all 1114112 codepoints and their assigned values and deduplicating
// chunks of e.g. 16 values each. Each deduplicated chunk is assigned its offset in the list of all deduplicated chunks.
// This results in two lists: 1114112/16=7132 IDs and however many deduplicated chunks you have accumulated.
// This is often called a two-stage table.
//
// If you want to look up the value now, you'll first find the deduplicated chunk offset via `offsets[codepoint / 16]`.
// This gives you the location of your chunk. Now you just look up the value with `values[offset + (codepoint & 15)]`.
//
// Since the 7132 offsets take up a lot more space than the deduplicated values (at least in case of the Unicode database),
// this process can be repeated by compressing the offset array the exact same way the values got compressed and so on.
// s_joinRules represents the UAX #29 extended grapheme cluster rules, however slightly modified to fit our needs.
// Specifically, UAX #29 states:
// > Note: Testing two adjacent characters is insufficient for determining a boundary.
//
// I completely agree, but I really hate it. So this code trades off correctness for simplicity
// by using a simple lookup table anyway. Under most circumstances users won't notice,
// because as far as I can see this only behaves different for degenerate ("invalid") Unicode.
// It reduces our code complexity significantly and is way *way* faster.
//
// This is a great reference for the s_joinRules table:
// https://www.unicode.org/Public/UCD/latest/ucd/auxiliary/GraphemeBreakTest.html
// Generated by GraphemeTableGen
// on 2024-12-04T15:47:45Z, from Unicode 16.0.0, 9224 bytes
// clang-format off
static const uint16_t s_stage0[] = {
0x0000, 0x0020, 0x0040, 0x0060, 0x0080, 0x009f, 0x00bf, 0x00ca, 0x00ca, 0x00ca, 0x00ca, 0x00ca, 0x00ca, 0x00ca, 0x00ca, 0x00ca,
0x00ca, 0x00ca, 0x00ca, 0x00ca, 0x00d8, 0x00f8, 0x010a, 0x010e, 0x010b, 0x0108, 0x0113, 0x0133, 0x0153, 0x0153, 0x0153, 0x016f,
0x018f, 0x01a7, 0x01c7, 0x01e7, 0x0133, 0x0133, 0x0205, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0221, 0x0236, 0x00ca, 0x00ca,
0x0256, 0x0276, 0x0133, 0x0133, 0x0133, 0x028b, 0x02ab, 0x02b9, 0x0133, 0x02cc, 0x02ea, 0x0302, 0x0322, 0x033f, 0x035f, 0x037f,
0x00ca, 0x00ca, 0x00ca, 0x00ca, 0x00ca, 0x00ca, 0x00ca, 0x00ca, 0x00ca, 0x00ca, 0x00ca, 0x00ca, 0x00ca, 0x00ca, 0x00ca, 0x00ca,
0x00ca, 0x00ca, 0x00ca, 0x00ca, 0x00ca, 0x00ca, 0x00ca, 0x00ca, 0x00ca, 0x00ca, 0x00ca, 0x00ca, 0x00ca, 0x00ca, 0x00ca, 0x039f,
0x00ca, 0x00ca, 0x00ca, 0x00ca, 0x00ca, 0x00ca, 0x00ca, 0x00ca, 0x00ca, 0x00ca, 0x00ca, 0x00ca, 0x00ca, 0x00ca, 0x00ca, 0x00ca,
0x00ca, 0x00ca, 0x00ca, 0x00ca, 0x00ca, 0x00ca, 0x00ca, 0x00ca, 0x00ca, 0x00ca, 0x00ca, 0x00ca, 0x00ca, 0x00ca, 0x00ca, 0x039f,
0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133,
0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133,
0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133,
0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133,
0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133,
0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133,
0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133,
0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133,
0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133,
0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133,
0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133,
0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133,
0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133,
0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133,
0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133,
0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133,
0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133,
0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133,
0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133,
0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133,
0x03bf, 0x03c7, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133,
0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133, 0x0133,
0x0153, 0x0153, 0x0153, 0x0153, 0x0153, 0x0153, 0x0153, 0x0153, 0x0153, 0x0153, 0x0153, 0x0153, 0x0153, 0x0153, 0x0153, 0x0153,
0x0153, 0x0153, 0x0153, 0x0153, 0x0153, 0x0153, 0x0153, 0x0153, 0x0153, 0x0153, 0x0153, 0x0153, 0x0153, 0x0153, 0x0153, 0x03e7,
0x0153, 0x0153, 0x0153, 0x0153, 0x0153, 0x0153, 0x0153, 0x0153, 0x0153, 0x0153, 0x0153, 0x0153, 0x0153, 0x0153, 0x0153, 0x0153,
0x0153, 0x0153, 0x0153, 0x0153, 0x0153, 0x0153, 0x0153, 0x0153, 0x0153, 0x0153, 0x0153, 0x0153, 0x0153, 0x0153, 0x0153, 0x03e7,
};
static const uint16_t s_stage1[] = {
0x0000, 0x0004, 0x000c, 0x0014, 0x001c, 0x0024, 0x002a, 0x0031, 0x002a, 0x0037, 0x002a, 0x003f, 0x0047, 0x0049, 0x004f, 0x0057, 0x005f, 0x0065, 0x006d, 0x002a, 0x002a, 0x002a, 0x0073, 0x007b, 0x0083, 0x008a, 0x002a, 0x0091, 0x0098, 0x009f, 0x00a3, 0x00aa,
0x00b2, 0x00b8, 0x00be, 0x00c5, 0x00cd, 0x00d5, 0x00dd, 0x00e5, 0x00ed, 0x00f5, 0x00fd, 0x0105, 0x010d, 0x0115, 0x011d, 0x0125, 0x012d, 0x0135, 0x013d, 0x0145, 0x014d, 0x0155, 0x015d, 0x0164, 0x016b, 0x0173, 0x0175, 0x017d, 0x0182, 0x018a, 0x0192, 0x019a,
0x019d, 0x01a5, 0x01ad, 0x002a, 0x01b5, 0x01b9, 0x01bd, 0x01c2, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x01ca, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x01d0, 0x01d7, 0x01de, 0x01e6,
0x01ed, 0x002a, 0x01f5, 0x002a, 0x01fb, 0x002a, 0x002a, 0x002a, 0x0203, 0x0209, 0x0211, 0x0218, 0x0220, 0x0228, 0x0230, 0x0236, 0x023d, 0x002a, 0x002a, 0x0244, 0x002a, 0x002a, 0x002a, 0x0047, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a,
0x024c, 0x0254, 0x025c, 0x0262, 0x026a, 0x0272, 0x027a, 0x0282, 0x028a, 0x0292, 0x029a, 0x002a, 0x02a2, 0x002a, 0x02a9, 0x02b0, 0x002a, 0x02b8, 0x02bc, 0x02c4, 0x002a, 0x002a, 0x02cc, 0x02d4, 0x02dc, 0x02e4, 0x02ec, 0x02f4, 0x02fc, 0x0304, 0x030c, 0x002a,
0x002a, 0x002a, 0x002a, 0x0314, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x031c, 0x0322, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x0326, 0x002a, 0x032d, 0x002a, 0x0043, 0x002a, 0x002a, 0x0335, 0x0339, 0x0341, 0x0341, 0x0341, 0x0347, 0x034d,
0x0355, 0x035b, 0x0341, 0x0363, 0x0341, 0x036a, 0x036e, 0x0374, 0x037b, 0x0381, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341,
0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0388, 0x0390, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x0393, 0x039b, 0x017f, 0x002a, 0x002a, 0x002a, 0x002a, 0x03a3, 0x002a, 0x03ab, 0x03b3, 0x03bb, 0x03c3, 0x03cb, 0x03d3,
0x03d8, 0x03e0, 0x03e8, 0x03f0, 0x002a, 0x002a, 0x002a, 0x03f7, 0x03ff, 0x0400, 0x0401, 0x0402, 0x0403, 0x0404, 0x0405, 0x03ff, 0x0400, 0x0401, 0x0402, 0x0403, 0x0404, 0x0405, 0x03ff, 0x0400, 0x0401, 0x0402, 0x0403, 0x0404, 0x0405, 0x03ff, 0x0400, 0x0401,
0x0402, 0x0403, 0x0404, 0x0405, 0x03ff, 0x0400, 0x0401, 0x0402, 0x0403, 0x0404, 0x0405, 0x03ff, 0x0400, 0x0401, 0x0402, 0x0403, 0x0404, 0x040c, 0x0414, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a,
0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x02bc, 0x02bc, 0x02bc, 0x02bc, 0x02bc, 0x02bc, 0x02bc, 0x02bc, 0x02bc, 0x02bc, 0x02bc, 0x02bc, 0x02bc,
0x02bc, 0x02bc, 0x02bc, 0x02bc, 0x02bc, 0x02bc, 0x02bc, 0x02bc, 0x02bc, 0x02bc, 0x02bc, 0x02bc, 0x02bc, 0x02bc, 0x02bc, 0x02bc, 0x02bc, 0x02bc, 0x02bc, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x041c, 0x002a, 0x002a, 0x002a, 0x002a,
0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x0424, 0x042a, 0x002a, 0x032d, 0x0355, 0x0432, 0x0437, 0x043b, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x0443, 0x002a, 0x002a, 0x002a, 0x044b, 0x002a, 0x0450, 0x002a, 0x002a, 0x002a,
0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x0458, 0x002a, 0x002a, 0x01f1, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x0460, 0x0465, 0x002a, 0x002a, 0x002a,
0x002a, 0x046b, 0x0471, 0x002a, 0x00a7, 0x0479, 0x002a, 0x0481, 0x0489, 0x0491, 0x0499, 0x04a1, 0x04a9, 0x04b1, 0x04b9, 0x04bc, 0x04c4, 0x002a, 0x04c9, 0x04d1, 0x04d9, 0x04e0, 0x04e8, 0x04ed, 0x04f5, 0x04f9, 0x0501, 0x002a, 0x002a, 0x0504, 0x050c, 0x0510,
0x0518, 0x051b, 0x002a, 0x0522, 0x002a, 0x002a, 0x002a, 0x0528, 0x002a, 0x002a, 0x002a, 0x0530, 0x0538, 0x002a, 0x053e, 0x0546, 0x054e, 0x0556, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x055a, 0x002a, 0x0562, 0x002a, 0x0569, 0x0571, 0x0578, 0x002a, 0x002a,
0x002a, 0x002a, 0x057b, 0x0583, 0x058b, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x0211, 0x0593, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a,
0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x0598, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a,
0x002a, 0x059e, 0x05a5, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x05ac, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x05b3, 0x05ba, 0x05be, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341,
0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x05c6, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341,
0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x05ce, 0x05d6, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a,
0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x05d8, 0x0341, 0x0341, 0x0341, 0x0341, 0x05e0, 0x05e7, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x05ed, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a,
0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x05f5, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a,
0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x05fd, 0x0605, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x0609, 0x0611, 0x002a, 0x002a, 0x0619, 0x002a, 0x002a, 0x0341, 0x0621, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a,
0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x0629, 0x0631, 0x0639, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a,
0x002a, 0x002a, 0x0641, 0x002a, 0x0648, 0x002a, 0x05a5, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x064b, 0x0651, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x0651, 0x002a, 0x002a, 0x002a, 0x0657, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a,
0x002a, 0x002a, 0x065d, 0x002a, 0x0665, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x002a, 0x066d,
0x066e, 0x066e, 0x0675, 0x067d, 0x0683, 0x068b, 0x0691, 0x0699, 0x06a1, 0x066e, 0x066e, 0x06a9, 0x06b0, 0x06b8, 0x06bf, 0x06c7, 0x06cf, 0x06d0, 0x06d1, 0x06d9, 0x06e1, 0x06e9, 0x06ee, 0x06d0, 0x06f6, 0x06d0, 0x06fe, 0x002a, 0x0706, 0x002a, 0x070e, 0x0716,
0x071d, 0x0724, 0x066e, 0x072c, 0x0734, 0x06d0, 0x06d0, 0x066e, 0x073c, 0x0744, 0x074c, 0x002a, 0x002a, 0x002a, 0x002a, 0x066e, 0x066e, 0x066e, 0x066e, 0x066e, 0x066e, 0x066e, 0x066e, 0x066e, 0x066e, 0x066e, 0x066e, 0x066e, 0x066e, 0x066e, 0x0754, 0x0341,
0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0341, 0x0342, 0x075c,
0x0047, 0x0764, 0x0764, 0x0047, 0x0047, 0x0047, 0x076c, 0x0764, 0x0764, 0x0764, 0x0764, 0x0764, 0x0764, 0x0764, 0x0764, 0x0764, 0x0764, 0x0764, 0x0764, 0x0764, 0x0764, 0x0764, 0x0764, 0x0764, 0x0764, 0x0764, 0x0764, 0x0764, 0x0764, 0x0764, 0x0764, 0x0764,
0x0764, 0x0764, 0x0764, 0x0764, 0x0764, 0x0764, 0x0764, 0x02bc, 0x02bc, 0x02bc, 0x02bc, 0x02bc, 0x02bc, 0x02bc, 0x02bc, 0x02bc, 0x02bc, 0x02bc, 0x02bc, 0x02bc, 0x02bc, 0x02bc, 0x02bc, 0x02bc, 0x02bc, 0x02bc, 0x02bc, 0x02bc, 0x02bc, 0x02bc, 0x02bc, 0x02bc,
0x02bc, 0x02bc, 0x02bc, 0x02bc, 0x02bc, 0x02bc, 0x0774,
};
static const uint16_t s_stage2[] = {
0x0000, 0x0000, 0x0000, 0x0000, 0x0008, 0x0008, 0x0008, 0x0008,
0x0008, 0x0008, 0x0008, 0x0009, 0x0000, 0x0000, 0x0000, 0x0000,
0x0011, 0x0018, 0x0020, 0x0022, 0x002a, 0x0008, 0x0029, 0x0030,
0x0036, 0x003e, 0x0040, 0x0047, 0x004c, 0x0008, 0x004a, 0x002d,
0x004e, 0x002d, 0x0053, 0x0029, 0x005b, 0x0063, 0x0034, 0x0008,
0x004e, 0x002d, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008,
0x0008, 0x0008, 0x002a, 0x006b, 0x0049, 0x0008, 0x0008, 0x0008,
0x0008, 0x004c, 0x0008, 0x004c, 0x0008, 0x0008, 0x0008, 0x0072,
0x005a, 0x0079, 0x0081, 0x0008, 0x0008, 0x0008, 0x0008, 0x0089,
0x0089, 0x0089, 0x0089, 0x0089, 0x0089, 0x0089, 0x0089, 0x0008,
0x0008, 0x0091, 0x0092, 0x0098, 0x0028, 0x0091, 0x0092, 0x0098,
0x0028, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x004c,
0x0008, 0x0092, 0x0092, 0x0092, 0x0092, 0x0092, 0x0092, 0x004c,
0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x00a0, 0x00a6, 0x0008,
0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x00ad, 0x0089, 0x0089,
0x0089, 0x0089, 0x00af, 0x00b5, 0x0008, 0x0008, 0x0008, 0x0008,
0x0008, 0x0008, 0x0008, 0x00bd, 0x0008, 0x0089, 0x00c5, 0x0008,
0x0008, 0x0008, 0x0008, 0x00a0, 0x0089, 0x0089, 0x0008, 0x0008,
0x00c9, 0x0008, 0x0008, 0x00a8, 0x00d1, 0x00d8, 0x00df, 0x0008,
0x0008, 0x00e5, 0x00c8, 0x0008, 0x0008, 0x0008, 0x0089, 0x0089,
0x00a5, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x00a8,
0x0089, 0x00c9, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x00a0,
0x00a4, 0x00ed, 0x0008, 0x0008, 0x00a8, 0x00f5, 0x00f9, 0x00a2,
0x0008, 0x0008, 0x0008, 0x00fd, 0x0008, 0x0008, 0x0008, 0x0008,
0x0105, 0x0089, 0x0008, 0x0008, 0x0008, 0x0008, 0x00ac, 0x0089,
0x0089, 0x010c, 0x0089, 0x0089, 0x0089, 0x0111, 0x0008, 0x0115,
0x011a, 0x011a, 0x011a, 0x011a, 0x0120, 0x0127, 0x012e, 0x00ad,
0x011a, 0x0136, 0x0008, 0x0008, 0x011a, 0x013d, 0x0008, 0x0115,
0x011a, 0x011a, 0x0145, 0x014c, 0x0152, 0x0159, 0x0160, 0x0166,
0x016e, 0x0136, 0x0008, 0x0175, 0x0177, 0x017e, 0x0008, 0x0008,
0x0008, 0x0008, 0x0008, 0x0008, 0x0182, 0x0189, 0x0190, 0x00c8,
0x0008, 0x0008, 0x0008, 0x0194, 0x0008, 0x017e, 0x0008, 0x0115,
0x011a, 0x011a, 0x0145, 0x019c, 0x0152, 0x01a4, 0x01ab, 0x0008,
0x0008, 0x0136, 0x0008, 0x0008, 0x01b2, 0x013d, 0x0008, 0x0115,
0x011a, 0x011a, 0x0145, 0x019c, 0x01ba, 0x0159, 0x0160, 0x01c2,
0x016e, 0x0136, 0x0008, 0x01ca, 0x0008, 0x01d0, 0x0008, 0x0008,
0x0008, 0x0008, 0x0008, 0x0008, 0x01d3, 0x01db, 0x01e2, 0x0166,
0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x01ea, 0x0008, 0x0115,
0x011a, 0x011a, 0x0145, 0x011a, 0x01f2, 0x01f9, 0x0200, 0x0206,
0x020e, 0x0136, 0x0008, 0x0008, 0x0008, 0x013d, 0x0008, 0x0008,
0x0008, 0x0008, 0x0008, 0x0008, 0x0212, 0x021a, 0x0221, 0x0227,
0x0008, 0x0136, 0x0008, 0x016a, 0x0008, 0x022f, 0x0008, 0x0115,
0x011a, 0x011a, 0x011a, 0x011a, 0x0237, 0x023e, 0x0245, 0x0166,
0x0008, 0x0136, 0x0008, 0x0008, 0x0008, 0x013d, 0x0008, 0x0008,
0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x024c, 0x0253, 0x025b,
0x0008, 0x0008, 0x0263, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008,
0x0008, 0x026a, 0x00a5, 0x00ca, 0x008a, 0x0008, 0x0008, 0x0008,
0x0008, 0x0008, 0x0008, 0x026a, 0x00a3, 0x0008, 0x008a, 0x0008,
0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x00a6, 0x0008, 0x0008,
0x0178, 0x024d, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008,
0x00ad, 0x0128, 0x00b0, 0x00a9, 0x0089, 0x00ad, 0x0089, 0x0089,
0x0089, 0x00a3, 0x0177, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008,
0x0008, 0x0008, 0x00a9, 0x0271, 0x0279, 0x0008, 0x0008, 0x01d3,
0x027e, 0x00c9, 0x0008, 0x00e0, 0x0008, 0x0286, 0x00ed, 0x0008,
0x00ed, 0x0008, 0x0008, 0x0008, 0x0008, 0x028e, 0x028e, 0x028e,
0x028e, 0x028e, 0x028e, 0x028e, 0x028e, 0x0296, 0x0296, 0x0296,
0x0296, 0x0296, 0x029e, 0x029e, 0x029e, 0x029e, 0x029e, 0x029e,
0x029e, 0x029e, 0x0008, 0x0008, 0x0008, 0x00a9, 0x0008, 0x0008,
0x0008, 0x0008, 0x02a6, 0x0008, 0x0008, 0x0008, 0x02ac, 0x0008,
0x0008, 0x0136, 0x0008, 0x0008, 0x0008, 0x0136, 0x0008, 0x0008,
0x0008, 0x0008, 0x0008, 0x0008, 0x02b1, 0x0129, 0x02b9, 0x0127,
0x00a4, 0x00ed, 0x0008, 0x0008, 0x0008, 0x0008, 0x00a0, 0x0008,
0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0206, 0x0008, 0x0008,
0x0008, 0x0008, 0x00c8, 0x0008, 0x0008, 0x0008, 0x0008, 0x02c1,
0x02c8, 0x02d0, 0x02d7, 0x0008, 0x0008, 0x00ca, 0x02df, 0x0008,
0x0008, 0x0008, 0x0008, 0x02e3, 0x008a, 0x02eb, 0x012a, 0x02f3,
0x00d8, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0089,
0x0089, 0x008a, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008,
0x0110, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x02fb, 0x0301,
0x01d9, 0x0008, 0x0008, 0x0008, 0x0008, 0x00a0, 0x00a4, 0x0008,
0x0112, 0x0008, 0x0008, 0x0008, 0x0309, 0x0311, 0x0008, 0x0008,
0x0008, 0x0008, 0x0317, 0x031f, 0x022f, 0x0008, 0x0008, 0x0008,
0x0008, 0x0327, 0x032b, 0x030b, 0x0008, 0x0008, 0x0330, 0x0089,
0x0271, 0x018b, 0x0338, 0x00a6, 0x0008, 0x0340, 0x0348, 0x034d,
0x0022, 0x0355, 0x035d, 0x0363, 0x0008, 0x036a, 0x0008, 0x0008,
0x0372, 0x0089, 0x002c, 0x007a, 0x0025, 0x0008, 0x0008, 0x0008,
0x0008, 0x002c, 0x0008, 0x0008, 0x0089, 0x0089, 0x0089, 0x0089,
0x00c9, 0x0008, 0x037a, 0x004c, 0x0073, 0x0008, 0x0381, 0x002d,
0x0008, 0x036a, 0x0008, 0x0008, 0x0033, 0x0060, 0x0092, 0x0026,
0x0092, 0x0028, 0x0008, 0x004c, 0x0389, 0x038f, 0x0008, 0x0396,
0x0008, 0x0028, 0x0008, 0x0008, 0x039c, 0x0008, 0x007a, 0x0008,
0x0008, 0x0008, 0x0040, 0x03a4, 0x039f, 0x03a9, 0x0068, 0x03ae,
0x007d, 0x0032, 0x0008, 0x03b4, 0x002e, 0x0008, 0x03bc, 0x03ba,
0x0008, 0x0008, 0x03ba, 0x0008, 0x002b, 0x004c, 0x002b, 0x0008,
0x0008, 0x007a, 0x0008, 0x0008, 0x002e, 0x03c4, 0x0008, 0x03cc,
0x0008, 0x0008, 0x03d4, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008,
0x0008, 0x03d5, 0x0008, 0x0008, 0x0008, 0x03dd, 0x03e5, 0x03ed,
0x0008, 0x0008, 0x0008, 0x0008, 0x0092, 0x0092, 0x0092, 0x0092,
0x0092, 0x0092, 0x0092, 0x0092, 0x03f5, 0x0092, 0x0092, 0x0092,
0x0092, 0x0098, 0x0092, 0x0092, 0x0008, 0x0008, 0x0008, 0x0008,
0x0098, 0x03fb, 0x0401, 0x0032, 0x0407, 0x040e, 0x0028, 0x0008,
0x0349, 0x007a, 0x0008, 0x0416, 0x041e, 0x0425, 0x042d, 0x0433,
0x043a, 0x043a, 0x0442, 0x043a, 0x0437, 0x0442, 0x0446, 0x043a,
0x044e, 0x0451, 0x043a, 0x043b, 0x0459, 0x045f, 0x0467, 0x046b,
0x0469, 0x0473, 0x043a, 0x0477, 0x0478, 0x047e, 0x0480, 0x0485,
0x0455, 0x0482, 0x048b, 0x0491, 0x0499, 0x0473, 0x04a1, 0x03cf,
0x036a, 0x04a9, 0x0394, 0x002b, 0x04ad, 0x04b5, 0x04bc, 0x0008,
0x04c4, 0x0008, 0x004e, 0x0092, 0x0008, 0x0008, 0x04cc, 0x0008,
0x036a, 0x0008, 0x04a9, 0x04d4, 0x0008, 0x0008, 0x0008, 0x0008,
0x0008, 0x0008, 0x0393, 0x0008, 0x04dc, 0x0008, 0x0008, 0x04e4,
0x0008, 0x0008, 0x0008, 0x0008, 0x04e8, 0x0028, 0x0008, 0x0008,
0x0008, 0x0008, 0x0008, 0x00ca, 0x00a6, 0x0008, 0x0008, 0x0008,
0x0008, 0x0008, 0x0008, 0x0008, 0x00ca, 0x04f0, 0x04f0, 0x04f0,
0x04f6, 0x04f0, 0x04f0, 0x04f0, 0x04f0, 0x04f0, 0x04f0, 0x04fa,
0x0008, 0x04f0, 0x04f0, 0x04f0, 0x04f0, 0x04f0, 0x04f0, 0x04f0,
0x04f0, 0x0502, 0x0008, 0x0008, 0x0008, 0x04f0, 0x04f0, 0x04f0,
0x04f0, 0x04f0, 0x050a, 0x0512, 0x0515, 0x051c, 0x04f0, 0x04f0,
0x04f0, 0x04f0, 0x04f0, 0x04f0, 0x04f0, 0x04f1, 0x0524, 0x04f0,
0x04f0, 0x04f0, 0x04f0, 0x052c, 0x04f0, 0x04f0, 0x04f0, 0x04f0,
0x04f0, 0x051c, 0x04f0, 0x04f1, 0x04f0, 0x04f0, 0x04f0, 0x04f0,
0x04f0, 0x04f0, 0x0502, 0x0534, 0x04f0, 0x04f0, 0x04f0, 0x04f1,
0x04f0, 0x04f0, 0x04f0, 0x04f0, 0x0092, 0x04f0, 0x04f0, 0x04f0,
0x04f0, 0x04f0, 0x04f0, 0x0513, 0x053b, 0x04f0, 0x04f0, 0x04f0,
0x04f0, 0x04f9, 0x04f0, 0x04f0, 0x04f0, 0x04f0, 0x04f0, 0x04f0,
0x04f1, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008,
0x00ca, 0x0330, 0x0543, 0x0008, 0x0008, 0x0008, 0x00a8, 0x0008,
0x0008, 0x0008, 0x0008, 0x0549, 0x01cf, 0x0008, 0x0008, 0x0550,
0x01ce, 0x0008, 0x0008, 0x0557, 0x0008, 0x0008, 0x0008, 0x0008,
0x0008, 0x0327, 0x025b, 0x055f, 0x0008, 0x0008, 0x0008, 0x0089,
0x0089, 0x00a6, 0x00ca, 0x0008, 0x0008, 0x0008, 0x0008, 0x00a8,
0x0543, 0x0008, 0x0008, 0x00ca, 0x0089, 0x022f, 0x0008, 0x028e,
0x028e, 0x028e, 0x0567, 0x0111, 0x0008, 0x0008, 0x0008, 0x0008,
0x0008, 0x056c, 0x0572, 0x0579, 0x0008, 0x0008, 0x0008, 0x00ed,
0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0580, 0x0587, 0x0008,
0x01cf, 0x058e, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x01ce,
0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0596, 0x01c1,
0x00c8, 0x0008, 0x0008, 0x0008, 0x0008, 0x059e, 0x05a6, 0x0008,
0x0008, 0x0008, 0x0008, 0x01d6, 0x05ae, 0x0008, 0x0008, 0x05b6,
0x05b7, 0x05b7, 0x05bb, 0x05b7, 0x05b7, 0x05b7, 0x05b6, 0x05b7,
0x05b7, 0x05bb, 0x05b7, 0x05b7, 0x05b7, 0x05b6, 0x05b7, 0x05b7,
0x05c0, 0x0008, 0x0296, 0x0296, 0x05c8, 0x05cf, 0x029e, 0x029e,
0x029e, 0x029e, 0x029e, 0x05d3, 0x0008, 0x0008, 0x0008, 0x0177,
0x0008, 0x0008, 0x0008, 0x0008, 0x0089, 0x0089, 0x04f0, 0x0532,
0x0089, 0x0089, 0x04f0, 0x04f0, 0x04f5, 0x04f0, 0x04f1, 0x04fa,
0x0008, 0x0008, 0x04f0, 0x04f0, 0x04f0, 0x04f0, 0x0533, 0x0008,
0x0008, 0x0008, 0x01d3, 0x0008, 0x0008, 0x0008, 0x0008, 0x04f1,
0x0008, 0x0000, 0x05db, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008,
0x0008, 0x0008, 0x00ed, 0x0008, 0x0008, 0x0008, 0x0008, 0x00c9,
0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x00a8, 0x00a5,
0x05e2, 0x00aa, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x02d8,
0x0008, 0x0008, 0x0008, 0x0008, 0x00aa, 0x0008, 0x0008, 0x0008,
0x0008, 0x0008, 0x00a2, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008,
0x05e9, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008,
0x00aa, 0x05ef, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008,
0x0008, 0x05f7, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008,
0x0089, 0x008a, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x05ff,
0x00ca, 0x0112, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0607,
0x060e, 0x01d0, 0x00e7, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008,
0x0008, 0x00a5, 0x0008, 0x0008, 0x0008, 0x00ca, 0x026e, 0x00a3,
0x0008, 0x0227, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x01cf,
0x0008, 0x0112, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0604,
0x0128, 0x0616, 0x061d, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008,
0x0008, 0x0625, 0x062c, 0x0177, 0x00c8, 0x0008, 0x0008, 0x0008,
0x0008, 0x0008, 0x0008, 0x0008, 0x00ca, 0x02f3, 0x00a5, 0x0008,
0x0008, 0x022f, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008,
0x0634, 0x063c, 0x0640, 0x0166, 0x0008, 0x0646, 0x00a3, 0x00a3,
0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x02f3,
0x064d, 0x0654, 0x065c, 0x0008, 0x0663, 0x0008, 0x0008, 0x0008,
0x0008, 0x0008, 0x0008, 0x055a, 0x0089, 0x066b, 0x0008, 0x0008,
0x0177, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x02f3,
0x0673, 0x067a, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008,
0x0008, 0x0166, 0x0158, 0x0682, 0x00c9, 0x0008, 0x0008, 0x0280,
0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x02f3, 0x0689,
0x00c9, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008,
0x0691, 0x0581, 0x0008, 0x0008, 0x0008, 0x0318, 0x0699, 0x00a4,
0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0625, 0x0089, 0x0224,
0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x06a1, 0x06a8,
0x06b0, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008,
0x0606, 0x06b6, 0x06be, 0x0008, 0x0008, 0x0008, 0x00ad, 0x00a5,
0x0008, 0x0008, 0x0008, 0x0008, 0x00a0, 0x06c6, 0x00ca, 0x0008,
0x0580, 0x02d7, 0x0008, 0x0008, 0x0008, 0x0008, 0x06cd, 0x06d3,
0x0128, 0x00a6, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0166,
0x008a, 0x0581, 0x0008, 0x0008, 0x00ac, 0x0089, 0x0089, 0x06db,
0x06e2, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x06e9,
0x06f0, 0x06f7, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008,
0x0008, 0x06ff, 0x0707, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008,
0x0008, 0x070f, 0x0008, 0x0717, 0x0008, 0x0008, 0x0008, 0x0008,
0x0008, 0x024f, 0x071f, 0x0727, 0x0008, 0x0008, 0x01d0, 0x0008,
0x0008, 0x0008, 0x0008, 0x00a7, 0x0089, 0x0543, 0x0008, 0x0008,
0x0008, 0x0008, 0x0008, 0x00a8, 0x0089, 0x02f1, 0x0008, 0x0008,
0x0008, 0x0008, 0x0008, 0x0008, 0x00a3, 0x0008, 0x0008, 0x0008,
0x0008, 0x0008, 0x0008, 0x008a, 0x0008, 0x0008, 0x0008, 0x0008,
0x072c, 0x0733, 0x0008, 0x0008, 0x00ca, 0x025a, 0x025b, 0x025b,
0x025b, 0x025b, 0x025b, 0x00ca, 0x00a5, 0x0008, 0x0008, 0x0008,
0x0008, 0x0008, 0x073b, 0x0008, 0x0743, 0x0008, 0x04f0, 0x04f0,
0x04f0, 0x04f0, 0x04f0, 0x04f0, 0x04f0, 0x0008, 0x04f0, 0x04f0,
0x0502, 0x0008, 0x0008, 0x0008, 0x0008, 0x0534, 0x04f0, 0x0533,
0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x04f4, 0x074b,
0x04f0, 0x04f0, 0x04f0, 0x04f0, 0x0529, 0x0008, 0x0752, 0x0008,
0x0008, 0x075a, 0x0008, 0x04fe, 0x0008, 0x04f0, 0x04f0, 0x04f0,
0x04f0, 0x04f0, 0x04f0, 0x04f0, 0x04fa, 0x0008, 0x0008, 0x0008,
0x0206, 0x00a4, 0x0008, 0x0008, 0x0008, 0x0089, 0x0089, 0x0089,
0x0089, 0x0089, 0x0543, 0x0089, 0x0089, 0x008a, 0x0008, 0x0008,
0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x01d4, 0x0602, 0x02f3,
0x0089, 0x0762, 0x00a4, 0x0008, 0x0008, 0x0008, 0x05ef, 0x0008,
0x0008, 0x0191, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008,
0x0008, 0x04f0, 0x04f0, 0x04f1, 0x0008, 0x04f0, 0x04f0, 0x04f1,
0x0008, 0x0089, 0x0089, 0x0089, 0x0089, 0x0089, 0x0089, 0x008a,
0x00a0, 0x0089, 0x0089, 0x0089, 0x0089, 0x0089, 0x00a3, 0x00ed,
0x0008, 0x01ce, 0x0008, 0x0008, 0x00a0, 0x00ad, 0x0089, 0x0008,
0x0008, 0x008a, 0x0089, 0x0089, 0x0764, 0x00b3, 0x00a5, 0x0008,
0x0008, 0x00ca, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008,
0x0177, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x00aa, 0x0008,
0x0008, 0x0008, 0x0008, 0x0008, 0x00a8, 0x0008, 0x0008, 0x008a,
0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x00aa, 0x00a5, 0x0008,
0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x076c, 0x043a, 0x043a,
0x043a, 0x043a, 0x043a, 0x043a, 0x043a, 0x043a, 0x043b, 0x043a,
0x043a, 0x043a, 0x043a, 0x043a, 0x043a, 0x0092, 0x0774, 0x0092,
0x0092, 0x0092, 0x077c, 0x0092, 0x0092, 0x0092, 0x0092, 0x0092,
0x0784, 0x078c, 0x078e, 0x0092, 0x0796, 0x079d, 0x07a2, 0x0092,
0x07a5, 0x043a, 0x043a, 0x043a, 0x043a, 0x07aa, 0x07b0, 0x07b0,
0x07b0, 0x07b8, 0x043a, 0x04f0, 0x07c0, 0x04f0, 0x0513, 0x07c6,
0x07cb, 0x04f0, 0x07ce, 0x07d6, 0x043a, 0x0444, 0x043a, 0x043a,
0x043a, 0x0442, 0x0442, 0x0442, 0x0442, 0x07d7, 0x043d, 0x07df,
0x0442, 0x0442, 0x0442, 0x0442, 0x0442, 0x0442, 0x0442, 0x07e0,
0x0442, 0x0442, 0x0446, 0x043a, 0x0442, 0x0442, 0x0442, 0x0442,
0x07e6, 0x0446, 0x043a, 0x0442, 0x0442, 0x07ed, 0x07f5, 0x0442,
0x0442, 0x0442, 0x0442, 0x0442, 0x0442, 0x0442, 0x0443, 0x07fd,
0x0442, 0x0442, 0x0442, 0x0442, 0x0442, 0x0442, 0x0442, 0x0442,
0x0800, 0x0442, 0x0442, 0x0442, 0x0442, 0x0442, 0x0442, 0x0442,
0x0807, 0x0391, 0x080f, 0x0442, 0x0442, 0x0442, 0x043a, 0x043a,
0x0468, 0x043a, 0x043a, 0x07d1, 0x043a, 0x076c, 0x043a, 0x043a,
0x043a, 0x043a, 0x043a, 0x043a, 0x043a, 0x043f, 0x0442, 0x0442,
0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0444, 0x076c,
0x0802, 0x043e, 0x043a, 0x07d3, 0x043e, 0x0445, 0x0008, 0x0008,
0x0008, 0x0008, 0x0008, 0x0008, 0x0817, 0x043a, 0x0008, 0x0008,
0x04dc, 0x043a, 0x0442, 0x0446, 0x07d7, 0x043a, 0x0008, 0x0817,
0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x043a, 0x0008,
0x0819, 0x0008, 0x0008, 0x0008, 0x0008, 0x043a, 0x0008, 0x0008,
0x0008, 0x0391, 0x043a, 0x043a, 0x0008, 0x0821, 0x0442, 0x0442,
0x0442, 0x0442, 0x0442, 0x0826, 0x082a, 0x0442, 0x0442, 0x0442,
0x0442, 0x0442, 0x0442, 0x0442, 0x043a, 0x043a, 0x043a, 0x043a,
0x043a, 0x043a, 0x0442, 0x0445, 0x0442, 0x0475, 0x0442, 0x0442,
0x0442, 0x0442, 0x0442, 0x0442, 0x0443, 0x043c, 0x0442, 0x0800,
0x0442, 0x07d6, 0x0442, 0x07d7, 0x043a, 0x043a, 0x043a, 0x043a,
0x043a, 0x043a, 0x043a, 0x0459, 0x0832, 0x0000, 0x0000, 0x0000,
0x0089, 0x0089, 0x0089, 0x0089, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0089, 0x0089, 0x0089, 0x0089,
0x0089, 0x0089, 0x0000, 0x0000, 0x0092, 0x0092, 0x0092, 0x0092,
0x0092, 0x0092, 0x0092, 0x083a,
};
static const uint8_t s_stage3[] = {
0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
0x41, 0x40, 0xc0, 0x40, 0x40, 0xc0, 0x40, 0x40,
0xc0, 0x4c, 0xc0, 0x40, 0x40, 0x41, 0xcc, 0x40,
0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x40, 0xc0, 0xc0,
0xc0, 0xc0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
0xc0, 0x40, 0x40, 0x40, 0x40, 0x40, 0xc0, 0xc0,
0x40, 0x40, 0x40, 0x40, 0xc0, 0x40, 0xc0, 0xc0,
0xc0, 0x40, 0xc0, 0xc0, 0x40, 0x40, 0x40, 0xc0,
0xc0, 0xc0, 0x40, 0xc0, 0x40, 0xc0, 0x40, 0x40,
0x40, 0x40, 0x40, 0x40, 0xc0, 0xc0, 0xc0, 0x40,
0x40, 0x40, 0x40, 0xc0, 0xc0, 0xc0, 0x40, 0xc0,
0x40, 0x40, 0x40, 0xc0, 0xc0, 0xc0, 0xc0, 0x40,
0xc0, 0x40, 0x40, 0xc0, 0x40, 0xc0, 0x40, 0xc0,
0x40, 0xc0, 0x40, 0x40, 0x40, 0x40, 0xc0, 0x40,
0x40, 0xc0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
0x40, 0xc0, 0xc0, 0xc0, 0xc0, 0x40, 0xc0, 0x40,
0xc0, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
0x02, 0x40, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0,
0xc0, 0xc0, 0x40, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0,
0x40, 0x40, 0x40, 0x02, 0x02, 0x02, 0x02, 0x02,
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x02, 0x02,
0x02, 0x02, 0x02, 0x02, 0x02, 0x40, 0x02, 0x02,
0x40, 0x02, 0x02, 0x40, 0x02, 0x04, 0x04, 0x04,
0x04, 0x04, 0x04, 0x40, 0x40, 0x02, 0x02, 0x02,
0x40, 0x02, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
0x40, 0x02, 0x02, 0x02, 0x02, 0x02, 0x04, 0x40,
0x02, 0x02, 0x02, 0x02, 0x02, 0x40, 0x40, 0x02,
0x40, 0x02, 0x02, 0x02, 0x02, 0x40, 0x40, 0x40,
0x40, 0x40, 0x40, 0x40, 0x04, 0x40, 0x40, 0x40,
0x40, 0x40, 0x02, 0x40, 0x40, 0x02, 0x02, 0x40,
0x02, 0x02, 0x02, 0x02, 0x02, 0x40, 0x02, 0x02,
0x02, 0x40, 0x40, 0x40, 0x40, 0x04, 0x04, 0x40,
0x40, 0x40, 0x40, 0x40, 0x02, 0x02, 0x04, 0x02,
0x02, 0x02, 0x02, 0x02, 0x42, 0x40, 0x40, 0x40,
0x40, 0x40, 0x4b, 0x4b, 0x4b, 0x4b, 0x4b, 0x4b,
0x4b, 0x4b, 0x02, 0x42, 0x02, 0x40, 0x42, 0x42,
0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x42,
0x42, 0x42, 0x42, 0x0a, 0x42, 0x42, 0x40, 0x40,
0x02, 0x02, 0x40, 0x40, 0x40, 0x40, 0x02, 0x42,
0x42, 0x40, 0x40, 0x40, 0x40, 0x4b, 0x40, 0x4b,
0x4b, 0x4b, 0x4b, 0x4b, 0x4b, 0x40, 0x4b, 0x40,
0x40, 0x40, 0x4b, 0x4b, 0x40, 0x40, 0x02, 0x40,
0x42, 0x42, 0x02, 0x02, 0x02, 0x02, 0x40, 0x40,
0x42, 0x40, 0x40, 0x42, 0x42, 0x0a, 0x40, 0x40,
0x40, 0x40, 0x40, 0x40, 0x40, 0x42, 0x40, 0x40,
0x40, 0x40, 0x4b, 0x4b, 0x40, 0x4b, 0x4b, 0x40,
0x40, 0x40, 0x40, 0x40, 0x40, 0x02, 0x40, 0x02,
0x02, 0x42, 0x40, 0x40, 0x40, 0x40, 0x02, 0x40,
0x42, 0x42, 0x02, 0x02, 0x40, 0x40, 0x40, 0x40,
0x02, 0x40, 0x40, 0x02, 0x02, 0x02, 0x40, 0x40,
0x40, 0x02, 0x40, 0x40, 0x4b, 0x40, 0x4b, 0x4b,
0x40, 0x4b, 0x4b, 0x4b, 0x42, 0x02, 0x02, 0x02,
0x02, 0x02, 0x40, 0x02, 0x42, 0x40, 0x42, 0x42,
0x0a, 0x40, 0x40, 0x4b, 0x02, 0x02, 0x02, 0x02,
0x02, 0x02, 0x4b, 0x4b, 0x40, 0x40, 0x02, 0x40,
0x42, 0x02, 0x40, 0x40, 0x40, 0x40, 0x40, 0x02,
0x02, 0x42, 0x40, 0x4b, 0x40, 0x40, 0x40, 0x40,
0x40, 0x40, 0x02, 0x40, 0x40, 0x40, 0x40, 0x40,
0x40, 0x42, 0x42, 0x02, 0x42, 0x42, 0x40, 0x40,
0x40, 0x42, 0x42, 0x40, 0x42, 0x42, 0x42, 0x02,
0x40, 0x40, 0x02, 0x42, 0x42, 0x42, 0x02, 0x40,
0x40, 0x40, 0x4b, 0x4b, 0x40, 0x40, 0x02, 0x40,
0x02, 0x02, 0x42, 0x42, 0x42, 0x42, 0x40, 0x02,
0x02, 0x40, 0x02, 0x02, 0x02, 0x0a, 0x40, 0x40,
0x40, 0x40, 0x40, 0x02, 0x02, 0x40, 0x4b, 0x4b,
0x4b, 0x40, 0x40, 0x40, 0x40, 0x40, 0x02, 0x40,
0x42, 0x02, 0x42, 0x42, 0x42, 0x42, 0x42, 0x40,
0x02, 0x42, 0x40, 0x42, 0x42, 0x02, 0x02, 0x40,
0x40, 0x40, 0x40, 0x40, 0x42, 0x42, 0x40, 0x02,
0x02, 0x42, 0x42, 0x40, 0x40, 0x40, 0x40, 0x4b,
0x4b, 0x4b, 0x02, 0x02, 0x40, 0x42, 0x42, 0x02,
0x02, 0x02, 0x02, 0x40, 0x42, 0x42, 0x40, 0x42,
0x42, 0x42, 0x0a, 0x44, 0x40, 0x40, 0x02, 0x40,
0x40, 0x40, 0x40, 0x42, 0x42, 0x02, 0x02, 0x02,
0x40, 0x02, 0x40, 0x42, 0x42, 0x42, 0x42, 0x42,
0x42, 0x42, 0x42, 0x40, 0x40, 0x42, 0x42, 0x40,
0x40, 0x40, 0x40, 0x02, 0x40, 0x42, 0x02, 0x02,
0x02, 0x02, 0x42, 0x02, 0x02, 0x02, 0x02, 0x02,
0x02, 0x40, 0x02, 0x02, 0x42, 0x42, 0x02, 0x02,
0x40, 0x40, 0x40, 0x40, 0x02, 0x02, 0x40, 0x40,
0x02, 0x40, 0x42, 0x02, 0x02, 0x40, 0x85, 0x85,
0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 0x46, 0x46,
0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x47, 0x47,
0x47, 0x47, 0x47, 0x47, 0x47, 0x47, 0x40, 0x40,
0x02, 0x02, 0x02, 0x42, 0x40, 0x40, 0x02, 0x02,
0x42, 0x40, 0x40, 0x40, 0x40, 0x02, 0x02, 0x42,
0x02, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x02,
0x42, 0x02, 0x02, 0x02, 0x42, 0x42, 0x42, 0x42,
0x02, 0x42, 0x42, 0x42, 0x40, 0x40, 0x40, 0x40,
0x42, 0x42, 0x02, 0x42, 0x42, 0x42, 0x42, 0x42,
0x02, 0x02, 0x02, 0x40, 0x40, 0x40, 0x40, 0x02,
0x42, 0x42, 0x02, 0x40, 0x40, 0x40, 0x40, 0x40,
0x42, 0x02, 0x42, 0x02, 0x40, 0x02, 0x40, 0x40,
0x02, 0x02, 0x02, 0x42, 0x42, 0x42, 0x02, 0x02,
0x02, 0x02, 0x02, 0x40, 0x40, 0x40, 0x40, 0x02,
0x42, 0x02, 0x02, 0x02, 0x42, 0x02, 0x42, 0x42,
0x42, 0x40, 0x42, 0x02, 0x02, 0x02, 0x02, 0x42,
0x42, 0x02, 0x02, 0x42, 0x02, 0x02, 0x02, 0x40,
0x40, 0x40, 0x40, 0x40, 0x40, 0x02, 0x42, 0x02,
0x02, 0x42, 0x42, 0x42, 0x02, 0x42, 0x02, 0x40,
0x40, 0x40, 0x40, 0x42, 0x42, 0x42, 0x42, 0x02,
0x02, 0x02, 0x02, 0x40, 0x02, 0x02, 0x02, 0x02,
0x40, 0x40, 0x40, 0x40, 0x02, 0x40, 0x40, 0x42,
0x40, 0x40, 0x40, 0x02, 0x02, 0x0d, 0x02, 0x02,
0xc0, 0x40, 0x40, 0xc0, 0xc0, 0xc0, 0xc0, 0x40,
0x40, 0xc0, 0xc0, 0x40, 0x40, 0x41, 0x41, 0x02,
0x02, 0x02, 0x02, 0x02, 0x40, 0xc0, 0x40, 0xc0,
0xc0, 0x40, 0xc0, 0x40, 0x40, 0x40, 0xc0, 0x4c,
0x40, 0xc0, 0x40, 0x4c, 0x40, 0x40, 0x40, 0x40,
0x40, 0x40, 0x02, 0x02, 0x02, 0x02, 0x02, 0x41,
0x02, 0x02, 0x40, 0x40, 0x40, 0xc0, 0x40, 0xc0,
0x40, 0x40, 0xc0, 0xcc, 0x40, 0x40, 0x40, 0xc0,
0x40, 0xc0, 0xc0, 0xc0, 0xc0, 0xcc, 0xcc, 0xcc,
0xcc, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x4c,
0x4c, 0x40, 0x40, 0x40, 0x40, 0x40, 0xc0, 0x40,
0xc0, 0x40, 0x40, 0x40, 0xc0, 0x40, 0x40, 0xc0,
0x40, 0x40, 0x40, 0xc0, 0x40, 0x40, 0xc0, 0xc0,
0xc0, 0xc0, 0xc0, 0x40, 0xc0, 0x40, 0x40, 0x40,
0xc0, 0x40, 0x40, 0x40, 0xc0, 0xc0, 0x40, 0x40,
0xc0, 0xc0, 0xc0, 0xc0, 0x40, 0x40, 0x8c, 0x8c,
0x40, 0x40, 0x40, 0x40, 0x4c, 0x80, 0x80, 0x40,
0x40, 0x40, 0x40, 0x40, 0x4c, 0x40, 0x40, 0x40,
0x40, 0x40, 0x40, 0x40, 0x4c, 0x40, 0x8c, 0x8c,
0x8c, 0x8c, 0x4c, 0x4c, 0x4c, 0x8c, 0x4c, 0x4c,
0x8c, 0x40, 0x40, 0x40, 0x40, 0x4c, 0x4c, 0x4c,
0x40, 0x40, 0x40, 0x40, 0x40, 0xc0, 0xc0, 0xcc,
0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x4c, 0x4c, 0x40,
0x40, 0x40, 0x40, 0xc0, 0xc0, 0x40, 0x40, 0xcc,
0xc0, 0x40, 0x40, 0x40, 0x40, 0xc0, 0xc0, 0x40,
0x40, 0xc0, 0x40, 0x40, 0xc0, 0xc0, 0x40, 0x40,
0x40, 0x4c, 0x4c, 0x8c, 0x8c, 0x40, 0x4c, 0x4c,
0x4c, 0x4c, 0x4c, 0xcc, 0xc0, 0x4c, 0xcc, 0x4c,
0x4c, 0x4c, 0x4c, 0xcc, 0xcc, 0x4c, 0x4c, 0x4c,
0x40, 0x8c, 0x8c, 0x4c, 0x4c, 0x4c, 0x4c, 0xcc,
0x4c, 0xcc, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c,
0x4c, 0x4c, 0x8c, 0x8c, 0x8c, 0x8c, 0x8c, 0x8c,
0x8c, 0x8c, 0x4c, 0x4c, 0x4c, 0x4c, 0xcc, 0xcc,
0x4c, 0xcc, 0xcc, 0xcc, 0x4c, 0xcc, 0xcc, 0x4c,
0xcc, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x40,
0x40, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x4c,
0x4c, 0x4c, 0x8c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c,
0x4c, 0xcc, 0xcc, 0x4c, 0x4c, 0x8c, 0x8c, 0x4c,
0x4c, 0x4c, 0x4c, 0x4c, 0x8c, 0x8c, 0xcc, 0xcc,
0xcc, 0xcc, 0xcc, 0xcc, 0x8c, 0xcc, 0xcc, 0xcc,
0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x8c, 0x8c, 0xcc,
0x8c, 0xcc, 0xcc, 0x8c, 0xcc, 0xcc, 0x8c, 0xcc,
0xcc, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x8c, 0x40,
0x40, 0x4c, 0x4c, 0x4c, 0x40, 0x4c, 0x40, 0x4c,
0x40, 0x8c, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
0x40, 0x4c, 0x40, 0x40, 0x4c, 0x40, 0x40, 0x40,
0x40, 0x8c, 0x40, 0x8c, 0x40, 0x40, 0x40, 0x8c,
0x8c, 0x8c, 0x40, 0x8c, 0x40, 0x40, 0x40, 0x4c,
0x4c, 0x4c, 0x4c, 0x4c, 0x40, 0x40, 0x40, 0x40,
0x40, 0x8c, 0x8c, 0x8c, 0x40, 0x40, 0x40, 0x40,
0x40, 0x40, 0x40, 0x8c, 0x40, 0x40, 0x40, 0x40,
0x40, 0x4c, 0x4c, 0x4c, 0x40, 0x40, 0x40, 0x8c,
0x8c, 0x40, 0x40, 0x40, 0x40, 0x8c, 0xc0, 0xc0,
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
0x40, 0x80, 0x80, 0x80, 0x80, 0x80, 0x40, 0x40,
0x40, 0x40, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
0x40, 0x40, 0x80, 0x80, 0x02, 0x02, 0x02, 0x02,
0x82, 0x82, 0x8c, 0x80, 0x80, 0x80, 0x80, 0x80,
0x80, 0x80, 0x8c, 0x80, 0x40, 0x80, 0x80, 0x80,
0x80, 0x80, 0x80, 0x80, 0x40, 0x02, 0x02, 0x80,
0x80, 0x80, 0x80, 0x80, 0x40, 0x40, 0x40, 0x40,
0x40, 0x80, 0x80, 0x80, 0x40, 0x40, 0x40, 0x40,
0x40, 0x40, 0x40, 0x80, 0x8c, 0x80, 0x80, 0x80,
0x80, 0x80, 0x80, 0x02, 0x02, 0x02, 0x02, 0x02,
0x02, 0x40, 0x40, 0x02, 0x40, 0x40, 0x40, 0x02,
0x40, 0x40, 0x40, 0x42, 0x42, 0x02, 0x02, 0x42,
0x42, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x42,
0x42, 0x42, 0x42, 0x02, 0x02, 0x40, 0x40, 0x85,
0x85, 0x85, 0x85, 0x85, 0x40, 0x40, 0x40, 0x02,
0x42, 0x42, 0x02, 0x02, 0x42, 0x42, 0x02, 0x02,
0x42, 0x42, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
0x40, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x42,
0x02, 0x02, 0x42, 0x42, 0x02, 0x02, 0x40, 0x40,
0x40, 0x40, 0x02, 0x42, 0x40, 0x40, 0x02, 0x40,
0x02, 0x02, 0x02, 0x40, 0x40, 0x02, 0x40, 0x40,
0x40, 0x42, 0x02, 0x02, 0x42, 0x42, 0x40, 0x40,
0x40, 0x40, 0x40, 0x42, 0x02, 0x40, 0x02, 0x42,
0x42, 0x40, 0x42, 0x02, 0x40, 0x40, 0x88, 0x89,
0x89, 0x89, 0x89, 0x89, 0x89, 0x89, 0x89, 0x88,
0x89, 0x89, 0x89, 0x89, 0x40, 0x40, 0x40, 0x40,
0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x40,
0x40, 0x40, 0x47, 0x47, 0x47, 0x47, 0x47, 0x40,
0x40, 0x40, 0x40, 0x41, 0x02, 0x02, 0x02, 0x40,
0xc0, 0x40, 0x40, 0x02, 0x02, 0x02, 0x40, 0x02,
0x02, 0x40, 0x40, 0x40, 0x02, 0x02, 0x40, 0x40,
0x40, 0x02, 0x02, 0x02, 0x02, 0x40, 0x40, 0x42,
0x02, 0x42, 0x40, 0x40, 0x40, 0x40, 0x40, 0x02,
0x40, 0x40, 0x02, 0x02, 0x40, 0x40, 0x40, 0x42,
0x42, 0x42, 0x02, 0x02, 0x02, 0x02, 0x42, 0x02,
0x02, 0x40, 0x40, 0x04, 0x40, 0x40, 0x42, 0x40,
0x44, 0x44, 0x40, 0x40, 0x40, 0x40, 0x02, 0x02,
0x02, 0x02, 0x40, 0x42, 0x02, 0x40, 0x40, 0x40,
0x40, 0x42, 0x42, 0x42, 0x02, 0x02, 0x42, 0x42,
0x02, 0x42, 0x02, 0x02, 0x40, 0x40, 0x40, 0x02,
0x02, 0x40, 0x42, 0x42, 0x02, 0x42, 0x42, 0x42,
0x42, 0x40, 0x40, 0x42, 0x42, 0x42, 0x40, 0x40,
0x42, 0x42, 0x40, 0x40, 0x02, 0x02, 0x40, 0x42,
0x40, 0x40, 0x42, 0x40, 0x42, 0x42, 0x42, 0x40,
0x42, 0x42, 0x02, 0x42, 0x02, 0x44, 0x02, 0x40,
0x40, 0x40, 0x40, 0x40, 0x02, 0x02, 0x40, 0x40,
0x40, 0x40, 0x40, 0x42, 0x42, 0x02, 0x02, 0x02,
0x42, 0x02, 0x40, 0x02, 0x42, 0x02, 0x42, 0x42,
0x42, 0x42, 0x02, 0x42, 0x02, 0x02, 0x40, 0x40,
0x40, 0x40, 0x42, 0x42, 0x42, 0x42, 0x02, 0x02,
0x42, 0x02, 0x02, 0x02, 0x42, 0x42, 0x02, 0x42,
0x02, 0x40, 0x40, 0x40, 0x02, 0x42, 0x02, 0x42,
0x42, 0x40, 0x40, 0x02, 0x02, 0x02, 0x02, 0x42,
0x02, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x40,
0x42, 0x40, 0x40, 0x02, 0x02, 0x42, 0x02, 0x44,
0x42, 0x44, 0x42, 0x02, 0x40, 0x40, 0x40, 0x40,
0x02, 0x02, 0x42, 0x42, 0x42, 0x42, 0x02, 0x40,
0x40, 0x40, 0x42, 0x40, 0x40, 0x40, 0x02, 0x42,
0x44, 0x02, 0x02, 0x02, 0x02, 0x40, 0x40, 0x40,
0x40, 0x44, 0x44, 0x44, 0x44, 0x02, 0x02, 0x02,
0x02, 0x02, 0x02, 0x40, 0x42, 0x02, 0x02, 0x02,
0x02, 0x02, 0x02, 0x42, 0x02, 0x02, 0x42, 0x02,
0x02, 0x40, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
0x40, 0x40, 0x02, 0x40, 0x02, 0x02, 0x40, 0x02,
0x02, 0x02, 0x02, 0x02, 0x02, 0x44, 0x02, 0x40,
0x40, 0x42, 0x42, 0x42, 0x42, 0x42, 0x40, 0x02,
0x02, 0x40, 0x42, 0x42, 0x02, 0x42, 0x02, 0x40,
0x40, 0x40, 0x02, 0x02, 0x42, 0x42, 0x40, 0x02,
0x02, 0x44, 0x42, 0x40, 0x40, 0x40, 0x40, 0x02,
0x02, 0x02, 0x40, 0x40, 0x40, 0x42, 0x42, 0x02,
0x42, 0x02, 0x40, 0x40, 0x40, 0x40, 0x40, 0x46,
0x40, 0x40, 0x40, 0x46, 0x46, 0x46, 0x40, 0x40,
0x40, 0x40, 0x40, 0x80, 0x80, 0x80, 0x80, 0x02,
0x40, 0x40, 0x40, 0x82, 0x82, 0x40, 0x40, 0x40,
0x40, 0x40, 0x40, 0x80, 0x80, 0x80, 0x80, 0x40,
0x80, 0x80, 0x40, 0x40, 0x80, 0x40, 0x40, 0x40,
0x40, 0x40, 0x80, 0x80, 0x80, 0x40, 0x40, 0x80,
0x40, 0x40, 0x02, 0x02, 0x02, 0x40, 0x40, 0x02,
0x02, 0x02, 0x02, 0x02, 0x4c, 0x4c, 0x4c, 0x4c,
0x8c, 0x4c, 0x4c, 0x4c, 0xc0, 0xc0, 0xc0, 0x40,
0x40, 0x4c, 0x4c, 0x4c, 0xc0, 0xc0, 0xc0, 0xc0,
0xc0, 0xc0, 0x40, 0x4c, 0xc0, 0xc0, 0x40, 0x40,
0x4c, 0x4c, 0x4c, 0x4c, 0xcc, 0xcc, 0xc0, 0xc0,
0xc0, 0xc0, 0xc0, 0xc0, 0xcc, 0xcc, 0xc0, 0xc0,
0xc0, 0xc0, 0xc0, 0xc0, 0x8c, 0xc0, 0x8c, 0x8c,
0x8c, 0x8c, 0x8c, 0x8c, 0x8c, 0xc0, 0xc0, 0xc0,
0xc0, 0xc0, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c,
0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43,
0x80, 0x8c, 0x8c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c,
0x80, 0x80, 0x8c, 0x80, 0x80, 0x80, 0x80, 0x80,
0x8c, 0x8c, 0x8c, 0x8c, 0x8c, 0x8c, 0x80, 0x4c,
0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x8c, 0x8c,
0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x8c,
0x8c, 0x8c, 0x8c, 0x8c, 0x8c, 0x4c, 0x8c, 0x8c,
0x8c, 0x4c, 0x4c, 0x4c, 0x4c, 0x8c, 0x4c, 0x4c,
0x4c, 0x8c, 0x4c, 0x4c, 0x4c, 0x8c, 0x8c, 0x8c,
0x82, 0x82, 0x82, 0x82, 0x82, 0x8c, 0x4c, 0x8c,
0x8c, 0x8c, 0x8c, 0x8c, 0x8c, 0x4c, 0x4c, 0x8c,
0x8c, 0x8c, 0x8c, 0x8c, 0x8c, 0x40, 0x40, 0x4c,
0x4c, 0x4c, 0x8c, 0x8c, 0x8c, 0x8c, 0x4c, 0x40,
0x40, 0x40, 0x40, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c,
0x4c, 0x40, 0x40, 0x40, 0x40, 0x8c, 0x8c, 0x8c,
0x8c, 0x40, 0x8c, 0x8c, 0x8c, 0x8c, 0x8c, 0x8c,
0x40, 0x8c, 0x41, 0x02, 0x41, 0x41, 0x41, 0x41,
0x41, 0x41, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0,
0x40, 0x40,
};
static const uint32_t s_joinRules[2][16] = {
{
/* 0b00000011110011111111111111001111 */ 0x03CFFFCF,
/* 0b00001111111111111111111111111111 */ 0x0FFFFFFF,
/* 0b00000011110011111111111111001111 */ 0x03CFFFCF,
/* 0b00000011110011111111111101001111 */ 0x03CFFF4F,
/* 0b00000000000000000000000000001100 */ 0x0000000C,
/* 0b00000011110000001100001111001111 */ 0x03C0C3CF,
/* 0b00000011110011110000111111001111 */ 0x03CF0FCF,
/* 0b00000011110011110011111111001111 */ 0x03CF3FCF,
/* 0b00000011110011110000111111001111 */ 0x03CF0FCF,
/* 0b00000011110011110011111111001111 */ 0x03CF3FCF,
/* 0b00000011000011111111111111001111 */ 0x030FFFCF,
/* 0b00000011110011111111111111001111 */ 0x03CFFFCF,
/* 0b00000011110011111111111111001111 */ 0x03CFFFCF,
/* 0b00000000110011111111111111001111 */ 0x00CFFFCF,
/* 0b00000000000000000000000000000000 */ 0x00000000,
/* 0b00000000000000000000000000000000 */ 0x00000000,
},
{
/* 0b00000011110011111111111111001111 */ 0x03CFFFCF,
/* 0b00001111111111111111111111111111 */ 0x0FFFFFFF,
/* 0b00000011110011111111111111001111 */ 0x03CFFFCF,
/* 0b00000011110011111111111111001111 */ 0x03CFFFCF,
/* 0b00000000000000000000000000001100 */ 0x0000000C,
/* 0b00000011110000001100001111001111 */ 0x03C0C3CF,
/* 0b00000011110011110000111111001111 */ 0x03CF0FCF,
/* 0b00000011110011110011111111001111 */ 0x03CF3FCF,
/* 0b00000011110011110000111111001111 */ 0x03CF0FCF,
/* 0b00000011110011110011111111001111 */ 0x03CF3FCF,
/* 0b00000011000011111111111111001111 */ 0x030FFFCF,
/* 0b00000011110011111111111111001111 */ 0x03CFFFCF,
/* 0b00000011110011111111111111001111 */ 0x03CFFFCF,
/* 0b00000000110011111111111111001111 */ 0x00CFFFCF,
/* 0b00000000000000000000000000000000 */ 0x00000000,
/* 0b00000000000000000000000000000000 */ 0x00000000,
},
};
// clang-format on
static inline int ucdLookup(const char32_t cp)
{
const uint16_t s0 = s_stage0[cp >> 11];
const uint16_t s1 = s_stage1[s0 + ((cp >> 6) & 31)];
const uint16_t s2 = s_stage2[s1 + ((cp >> 3) & 7)];
const uint8_t s3 = s_stage3[s2 + ((cp >> 0) & 7)];
return s3;
}
static inline int ucdGraphemeJoins(const int state, const int lead, const int trail)
{
const int l = lead & 15;
const int t = trail & 15;
return (s_joinRules[state][l] >> (t * 2)) & 3;
}
static inline bool ucdGraphemeDone(const int state)
{
return state == 3;
}
static inline int ucdToCharacterWidth(const int val)
{
return val >> 6;
}
// Decodes the next codepoint from the given UTF-16 string.
// Returns the start of the next codepoint. Assumes `it < end`.
static inline const char16_t *utf16NextOrFFFD(const char16_t *it, const char16_t *const end, char32_t *const pOut)
{
char32_t c = *it++;
// Is any surrogate?
if ((c & 0xF800) == 0xD800)
{
const char32_t c1 = c;
c = 0xfffd;
// Is leading surrogate and not at end?
if ((c1 & 0x400) == 0 && it != end)
{
const char32_t c2 = *it;
// Is also trailing surrogate!
if ((c2 & 0xFC00) == 0xDC00)
{
c = (c1 << 10) - 0x35FDC00 + c2;
++it;
}
}
}
*pOut = c;
return it;
}
// Parses the next grapheme cluster from the given string. The algorithm largely follows "UAX #29: Unicode Text Segmentation",
// but takes some mild liberties. Returns false if the end of the string was reached. Updates `s` with the cluster.
static inline bool GraphemeNext(GraphemeState *const s, const void *const str, const void *const end, const int charSize)
{
const void *clusterBeg = (const uint8_t *)(s->beg) + s->len * charSize;
int width = s->width;
int state = s->_state;
int lead = s->_last;
// If it's a new string argument, we'll restart at the new string's beginning.
if (clusterBeg < str)
clusterBeg = str;
const void *clusterEnd = clusterBeg;
// Skip if we're already at the end.
if (clusterEnd < end)
{
char32_t cp;
const void *clusterEndNext;
// If a previous parsing of a grapheme cluster got interrupted because we reached the end of the string,
// we'll have stored the parser state in `s._state` so that we can continue parsing within the new string.
// The problem is that a `state` of zero is also a valid state parameter for `ucdGraphemeJoins`.
// Thus, we're storing `s._state` bit-flipped so that we can differentiate between it being unset (0) and
// storing a previous state of 0 (0xffff...).
const bool gotState = state != 0;
state = ~state;
if (gotState)
goto fetchNext;
if (charSize == char8size)
clusterEnd = utf8NextOrFFFD((const uint8_t *)clusterEnd, (const uint8_t *)end, &cp);
else
clusterEnd = utf16NextOrFFFD((const char16_t *)clusterEnd, (const char16_t *)end, &cp);
lead = ucdLookup(cp);
width = 0;
state = 0;
for (;;)
{
{
int w = ucdToCharacterWidth(lead);
if (w == 3)
w = *AmbiguousIsWide() ? 2 : 1;
// U+FE0F Variation Selector-16 is used to turn unqualified Emojis into qualified ones.
// By convention, this turns them from being ambiguous width (= narrow) into wide ones.
// We achieve this here by explicitly giving this codepoint a wide width.
// Later down below we'll clamp width back to <= 2.
if (cp == 0xFE0F)
w = 2;
width += w;
}
// If we're at the end of the string, we'll break out of the loop, but leave
// `state` and `lead` as-is, so that we can continue parsing in the next string.
if (clusterEnd >= end)
break;
fetchNext:
if (charSize == char8size)
clusterEndNext = utf8NextOrFFFD((const uint8_t *)clusterEnd, (const uint8_t *)end, &cp);
else
clusterEndNext = utf16NextOrFFFD((const char16_t *)clusterEnd, (const char16_t *)end, &cp);
const int trail = ucdLookup(cp);
state = ucdGraphemeJoins(state, lead, trail);
if (ucdGraphemeDone(state))
{
// We'll later do `state = ~state` which will result in `state == 0`.
state = ~0;
lead = 0;
break;
}
clusterEnd = clusterEndNext;
lead = trail;
}
state = ~state;
width = width > 2 ? 2 : width;
s->beg = clusterBeg;