File: utf8lib.c

package info (click to toggle)
darkplaces 0~20180412~beta1-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 18,200 kB
  • sloc: ansic: 176,886; makefile: 485; pascal: 455; perl: 372; objc: 245; sh: 102
file content (3055 lines) | stat: -rw-r--r-- 88,120 bytes parent folder | download | duplicates (3)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
#include "quakedef.h"
#include "utf8lib.h"

/*
================================================================================
Initialization of UTF-8 support and new cvars.
================================================================================
*/
// for compatibility this defaults to 0
cvar_t    utf8_enable = {CVAR_SAVE, "utf8_enable", "0", "Enable UTF-8 support. For compatibility, this is disabled by default in most games."};

void   u8_Init(void)
{
	Cvar_RegisterVariable(&utf8_enable);
}

/*
================================================================================
UTF-8 encoding and decoding functions follow.
================================================================================
*/

unsigned char utf8_lengths[256] = { // 0 = invalid
	1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // ascii characters
	1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
	1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
	1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
	1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
	1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
	1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
	1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0x80 - 0xBF are within multibyte sequences
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // they could be interpreted as 2-byte starts but
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // the codepoint would be < 127
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
	0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // C0 and C1 would also result in overlong encodings
	2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
	3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
	4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
	// with F5 the codepoint is above 0x10FFFF,
	// F8-FB would start 5-byte sequences
	// FC-FD would start 6-byte sequences
	// ...
};
Uchar utf8_range[5] = {
	1,       // invalid - let's not allow the creation of 0-bytes :P
	1,       // ascii minimum
	0x80,    // 2-byte minimum
	0x800,   // 3-byte minimum
	0x10000, // 4-byte minimum
};

/** Analyze the next character and return various information if requested.
 * @param _s      An utf-8 string.
 * @param _start  Filled with the start byte-offset of the next valid character
 * @param _len    Fileed with the length of the next valid character
 * @param _ch     Filled with the unicode value of the next character
 * @param _maxlen Maximum number of bytes to read from _s
 * @return        Whether or not another valid character is in the string
 */
#define U8_ANALYZE_INFINITY 7
static qboolean u8_analyze(const char *_s, size_t *_start, size_t *_len, Uchar *_ch, size_t _maxlen)
{
	const unsigned char *s = (const unsigned char*)_s;
	size_t i, j;
	size_t bits = 0;
	Uchar ch;

	i = 0;
findchar:
	while (i < _maxlen && s[i] && (bits = utf8_lengths[s[i]]) == 0)
		++i;

	if (i >= _maxlen || !s[i]) {
		if (_start) *_start = i;
		if (_len) *_len = 0;
		return false;
	}
	
	if (bits == 1) { // ascii
		if (_start) *_start = i;
		if (_len) *_len = 1;
		if (_ch) *_ch = (Uchar)s[i];
		return true;
	}

	ch = (s[i] & (0xFF >> bits));
	for (j = 1; j < bits; ++j)
	{
		if ( (s[i+j] & 0xC0) != 0x80 )
		{
			i += j;
			goto findchar;
		}
		ch = (ch << 6) | (s[i+j] & 0x3F);
	}
	if (ch < utf8_range[bits] || ch >= 0x10FFFF)
	{
		i += bits;
		goto findchar;
	}
#if 0
	// <0xC2 is always an overlong encoding, they're invalid, thus skipped
	while (i < _maxlen && s[i] && s[i] >= 0x80 && s[i] < 0xC2) {
		//fprintf(stderr, "skipping\n");
		++i;
	}

	// If we hit the end, well, we're out and invalid
	if(i >= _maxlen || !s[i]) {
		if (_start) *_start = i;
		if (_len) *_len = 0;
		return false;
	}

	// I'll leave that in - if you remove it, also change the part below
	// to support 1-byte chars correctly
	if (s[i] < 0x80)
	{
		if (_start) *_start = i;
		if (_len) *_len = 1;
		if (_ch) *_ch = (Uchar)s[i];
		//fprintf(stderr, "valid ascii\n");
		return true;
	}

	// Figure out the next char's length
	bc = s[i];
	bits = 1;
	// count the 1 bits, they're the # of bytes
	for (bt = 0x40; bt && (bc & bt); bt >>= 1, ++bits);
	if (!bt)
	{
		//fprintf(stderr, "superlong\n");
		++i;
		goto findchar;
	}
	if(i + bits > _maxlen) {
		/*
		if (_start) *_start = i;
		if (_len) *_len = 0;
		return false;
		*/
		++i;
		goto findchar;
	}
	// turn bt into a mask and give ch a starting value
	--bt;
	ch = (s[i] & bt);
	// check the byte sequence for invalid bytes
	for (j = 1; j < bits; ++j)
	{
		// valid bit value: 10xx xxxx
		//if (s[i+j] < 0x80 || s[i+j] >= 0xC0)
		if ( (s[i+j] & 0xC0) != 0x80 )
		{
			//fprintf(stderr, "sequence of %i f'd at %i by %x\n", bits, j, (unsigned int)s[i+j]);
			// this byte sequence is invalid, skip it
			i += j;
			// find a character after it
			goto findchar;
		}
		// at the same time, decode the character
		ch = (ch << 6) | (s[i+j] & 0x3F);
	}

	// Now check the decoded byte for an overlong encoding
	if ( (bits >= 2 && ch < 0x80) ||
	     (bits >= 3 && ch < 0x800) ||
	     (bits >= 4 && ch < 0x10000) ||
	     ch >= 0x10FFFF // RFC 3629
		)
	{
		i += bits;
		//fprintf(stderr, "overlong: %i bytes for %x\n", bits, ch);
		goto findchar;
	}
#endif

	if (_start)
		*_start = i;
	if (_len)
		*_len = bits;
	if (_ch)
		*_ch = ch;
	//fprintf(stderr, "valid utf8\n");
	return true;
}

/** Get the number of characters in an UTF-8 string.
 * @param _s    An utf-8 encoded null-terminated string.
 * @return      The number of unicode characters in the string.
 */
size_t u8_strlen(const char *_s)
{
	size_t st, ln;
	size_t len = 0;
	const unsigned char *s = (const unsigned char*)_s;

	if (!utf8_enable.integer)
		return strlen(_s);

	while (*s)
	{
		// ascii char, skip u8_analyze
		if (*s < 0x80)
		{
			++len;
			++s;
			continue;
		}

		// invalid, skip u8_analyze
		if (*s < 0xC2)
		{
			++s;
			continue;
		}

		if (!u8_analyze((const char*)s, &st, &ln, NULL, U8_ANALYZE_INFINITY))
			break;
		// valid character, skip after it
		s += st + ln;
		++len;
	}
	return len;
}

static int colorcode_skipwidth(const unsigned char *s)
{
	if(*s == STRING_COLOR_TAG)
	{
		if(s[1] <= '9' && s[1] >= '0') // ^[0-9] found
		{
			return 2;
		}
		else if(s[1] == STRING_COLOR_RGB_TAG_CHAR &&
			((s[2] >= '0' && s[2] <= '9') || (s[2] >= 'a' && s[2] <= 'f') || (s[2] >= 'A' && s[2] <= 'F')) &&
			((s[3] >= '0' && s[3] <= '9') || (s[3] >= 'a' && s[3] <= 'f') || (s[3] >= 'A' && s[3] <= 'F')) &&
			((s[4] >= '0' && s[4] <= '9') || (s[4] >= 'a' && s[4] <= 'f') || (s[4] >= 'A' && s[4] <= 'F')))
		{
			return 5;
		}
		else if(s[1] == STRING_COLOR_TAG)
		{
			return 1; // special case, do NOT call colorcode_skipwidth for next char
		}
	}
	return 0;
}

/** Get the number of characters in a part of an UTF-8 string.
 * @param _s    An utf-8 encoded null-terminated string.
 * @param n     The maximum number of bytes.
 * @return      The number of unicode characters in the string.
 */
size_t u8_strnlen(const char *_s, size_t n)
{
	size_t st, ln;
	size_t len = 0;
	const unsigned char *s = (const unsigned char*)_s;

	if (!utf8_enable.integer)
	{
		len = strlen(_s);
		return (len < n) ? len : n;
	}

	while (*s && n)
	{
		// ascii char, skip u8_analyze
		if (*s < 0x80)
		{
			++len;
			++s;
			--n;
			continue;
		}

		// invalid, skip u8_analyze
		if (*s < 0xC2)
		{
			++s;
			--n;
			continue;
		}

		if (!u8_analyze((const char*)s, &st, &ln, NULL, n))
			break;
		// valid character, see if it's still inside the range specified by n:
		if (n < st + ln)
			return len;
		++len;
		n -= st + ln;
		s += st + ln;
	}
	return len;
}

static size_t u8_strnlen_colorcodes(const char *_s, size_t n)
{
	size_t st, ln;
	size_t len = 0;
	const unsigned char *s = (const unsigned char*)_s;

	while (*s && n)
	{
		int w = colorcode_skipwidth(s);
		n -= w;
		s += w;
		if(w > 1) // == 1 means single caret
			continue;

		// ascii char, skip u8_analyze
		if (*s < 0x80 || !utf8_enable.integer)
		{
			++len;
			++s;
			--n;
			continue;
		}

		// invalid, skip u8_analyze
		if (*s < 0xC2)
		{
			++s;
			--n;
			continue;
		}

		if (!u8_analyze((const char*)s, &st, &ln, NULL, n))
			break;
		// valid character, see if it's still inside the range specified by n:
		if (n < st + ln)
			return len;
		++len;
		n -= st + ln;
		s += st + ln;
	}
	return len;
}

/** Get the number of bytes used in a string to represent an amount of characters.
 * @param _s    An utf-8 encoded null-terminated string.
 * @param n     The number of characters we want to know the byte-size for.
 * @return      The number of bytes used to represent n characters.
 */
size_t u8_bytelen(const char *_s, size_t n)
{
	size_t st, ln;
	size_t len = 0;
	const unsigned char *s = (const unsigned char*)_s;

	if (!utf8_enable.integer) {
		len = strlen(_s);
		return (len < n) ? len : n;
	}

	while (*s && n)
	{
		// ascii char, skip u8_analyze
		if (*s < 0x80)
		{
			++len;
			++s;
			--n;
			continue;
		}

		// invalid, skip u8_analyze
		if (*s < 0xC2)
		{
			++s;
			++len;
			continue;
		}

		if (!u8_analyze((const char*)s, &st, &ln, NULL, U8_ANALYZE_INFINITY))
			break;
		--n;
		s += st + ln;
		len += st + ln;
	}
	return len;
}

static size_t u8_bytelen_colorcodes(const char *_s, size_t n)
{
	size_t st, ln;
	size_t len = 0;
	const unsigned char *s = (const unsigned char*)_s;

	while (*s && n)
	{
		int w = colorcode_skipwidth(s);
		len += w;
		s += w;
		if(w > 1) // == 1 means single caret
			continue;

		// ascii char, skip u8_analyze
		if (*s < 0x80 || !utf8_enable.integer)
		{
			++len;
			++s;
			--n;
			continue;
		}

		// invalid, skip u8_analyze
		if (*s < 0xC2)
		{
			++s;
			++len;
			continue;
		}

		if (!u8_analyze((const char*)s, &st, &ln, NULL, U8_ANALYZE_INFINITY))
			break;
		--n;
		s += st + ln;
		len += st + ln;
	}
	return len;
}

/** Get the byte-index for a character-index.
 * @param _s      An utf-8 encoded string.
 * @param i       The character-index for which you want the byte offset.
 * @param len     If not null, character's length will be stored in there.
 * @return        The byte-index at which the character begins, or -1 if the string is too short.
 */
int u8_byteofs(const char *_s, size_t i, size_t *len)
{
	size_t st, ln;
	size_t ofs = 0;
	const unsigned char *s = (const unsigned char*)_s;

	if (!utf8_enable.integer)
	{
		if (strlen(_s) < i)
		{
			if (len) *len = 0;
			return -1;
		}

		if (len) *len = 1;
		return (int)i;
	}

	st = ln = 0;
	do
	{
		ofs += ln;
		if (!u8_analyze((const char*)s + ofs, &st, &ln, NULL, U8_ANALYZE_INFINITY))
			return -1;
		ofs += st;
	} while(i-- > 0);
	if (len)
		*len = ln;
	return (int)ofs;
}

/** Get the char-index for a byte-index.
 * @param _s      An utf-8 encoded string.
 * @param i       The byte offset for which you want the character index.
 * @param len     If not null, the offset within the character is stored here.
 * @return        The character-index, or -1 if the string is too short.
 */
int u8_charidx(const char *_s, size_t i, size_t *len)
{
	size_t st, ln;
	size_t ofs = 0;
	size_t pofs = 0;
	int idx = 0;
	const unsigned char *s = (const unsigned char*)_s;

	if (!utf8_enable.integer)
	{
		if (len) *len = 0;
		return (int)i;
	}

	while (ofs < i && s[ofs])
	{
		// ascii character, skip u8_analyze
		if (s[ofs] < 0x80)
		{
			pofs = ofs;
			++idx;
			++ofs;
			continue;
		}

		// invalid, skip u8_analyze
		if (s[ofs] < 0xC2)
		{
			++ofs;
			continue;
		}

		if (!u8_analyze((const char*)s+ofs, &st, &ln, NULL, U8_ANALYZE_INFINITY))
			return -1;
		// see if next char is after the bytemark
		if (ofs + st > i)
		{
			if (len)
				*len = i - pofs;
			return idx;
		}
		++idx;
		pofs = ofs + st;
		ofs += st + ln;
		// see if bytemark is within the char
		if (ofs > i)
		{
			if (len)
				*len = i - pofs;
			return idx;
		}
	}
	if (len) *len = 0;
	return idx;
}

/** Get the byte offset of the previous byte.
 * The result equals:
 * prevchar_pos = u8_byteofs(text, u8_charidx(text, thischar_pos, NULL) - 1, NULL)
 * @param _s      An utf-8 encoded string.
 * @param i       The current byte offset.
 * @return        The byte offset of the previous character
 */
size_t u8_prevbyte(const char *_s, size_t i)
{
	size_t st, ln;
	const unsigned char *s = (const unsigned char*)_s;
	size_t lastofs = 0;
	size_t ofs = 0;

	if (!utf8_enable.integer)
	{
		if (i > 0)
			return i-1;
		return 0;
	}

	while (ofs < i && s[ofs])
	{
		// ascii character, skip u8_analyze
		if (s[ofs] < 0x80)
		{
			lastofs = ofs++;
			continue;
		}

		// invalid, skip u8_analyze
		if (s[ofs] < 0xC2)
		{
			++ofs;
			continue;
		}

		if (!u8_analyze((const char*)s+ofs, &st, &ln, NULL, U8_ANALYZE_INFINITY))
			return lastofs;
		if (ofs + st > i)
			return lastofs;
		if (ofs + st + ln >= i)
			return ofs + st;

		lastofs = ofs;
		ofs += st + ln;
	}
	return lastofs;
}

Uchar u8_quake2utf8map[256] = {
	0xE000, 0xE001, 0xE002, 0xE003, 0xE004, 0xE005, 0xE006, 0xE007, 0xE008, 0xE009, 0xE00A, 0xE00B, 0xE00C, 0xE00D, 0xE00E, 0xE00F, // specials
	0xE010, 0xE011, 0xE012, 0xE013, 0xE014, 0xE015, 0xE016, 0xE017, 0xE018, 0xE019, 0xE01A, 0xE01B, 0xE01C, 0xE01D, 0xE01E, 0xE01F, // specials
	0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F, // shift+digit line
	0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F, // digits
	0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F, // caps
	0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005A, 0x005B, 0x005C, 0x005D, 0x005E, 0x005F, // caps
	0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F, // small
	0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 0x007A, 0x007B, 0x007C, 0x007D, 0x007E, 0x007F, // small
	0xE080, 0xE081, 0xE082, 0xE083, 0xE084, 0xE085, 0xE086, 0xE087, 0xE088, 0xE089, 0xE08A, 0xE08B, 0xE08C, 0xE08D, 0xE08E, 0xE08F, // specials
	0xE090, 0xE091, 0xE092, 0xE093, 0xE094, 0xE095, 0xE096, 0xE097, 0xE098, 0xE099, 0xE09A, 0xE09B, 0xE09C, 0xE09D, 0xE09E, 0xE09F, // faces
	0xE0A0, 0xE0A1, 0xE0A2, 0xE0A3, 0xE0A4, 0xE0A5, 0xE0A6, 0xE0A7, 0xE0A8, 0xE0A9, 0xE0AA, 0xE0AB, 0xE0AC, 0xE0AD, 0xE0AE, 0xE0AF,
	0xE0B0, 0xE0B1, 0xE0B2, 0xE0B3, 0xE0B4, 0xE0B5, 0xE0B6, 0xE0B7, 0xE0B8, 0xE0B9, 0xE0BA, 0xE0BB, 0xE0BC, 0xE0BD, 0xE0BE, 0xE0BF,
	0xE0C0, 0xE0C1, 0xE0C2, 0xE0C3, 0xE0C4, 0xE0C5, 0xE0C6, 0xE0C7, 0xE0C8, 0xE0C9, 0xE0CA, 0xE0CB, 0xE0CC, 0xE0CD, 0xE0CE, 0xE0CF,
	0xE0D0, 0xE0D1, 0xE0D2, 0xE0D3, 0xE0D4, 0xE0D5, 0xE0D6, 0xE0D7, 0xE0D8, 0xE0D9, 0xE0DA, 0xE0DB, 0xE0DC, 0xE0DD, 0xE0DE, 0xE0DF,
	0xE0E0, 0xE0E1, 0xE0E2, 0xE0E3, 0xE0E4, 0xE0E5, 0xE0E6, 0xE0E7, 0xE0E8, 0xE0E9, 0xE0EA, 0xE0EB, 0xE0EC, 0xE0ED, 0xE0EE, 0xE0EF,
	0xE0F0, 0xE0F1, 0xE0F2, 0xE0F3, 0xE0F4, 0xE0F5, 0xE0F6, 0xE0F7, 0xE0F8, 0xE0F9, 0xE0FA, 0xE0FB, 0xE0FC, 0xE0FD, 0xE0FE, 0xE0FF,
};

/** Fetch a character from an utf-8 encoded string.
 * @param _s      The start of an utf-8 encoded multi-byte character.
 * @param _end    Will point to after the first multi-byte character.
 * @return        The 32-bit integer representation of the first multi-byte character or 0 for invalid characters.
 */
Uchar u8_getchar_utf8_enabled(const char *_s, const char **_end)
{
	size_t st, ln;
	Uchar ch;

	if (!u8_analyze(_s, &st, &ln, &ch, U8_ANALYZE_INFINITY))
		ch = 0;
	if (_end)
		*_end = _s + st + ln;
	return ch;
}

/** Fetch a character from an utf-8 encoded string.
 * @param _s      The start of an utf-8 encoded multi-byte character.
 * @param _end    Will point to after the first multi-byte character.
 * @return        The 32-bit integer representation of the first multi-byte character or 0 for invalid characters.
 */
Uchar u8_getnchar_utf8_enabled(const char *_s, const char **_end, size_t _maxlen)
{
	size_t st, ln;
	Uchar ch;

	if (!u8_analyze(_s, &st, &ln, &ch, _maxlen))
		ch = 0;
	if (_end)
		*_end = _s + st + ln;
	return ch;
}

/** Encode a wide-character into utf-8.
 * @param w        The wide character to encode.
 * @param to       The target buffer the utf-8 encoded string is stored to.
 * @param maxlen   The maximum number of bytes that fit into the target buffer.
 * @return         Number of bytes written to the buffer not including the terminating null.
 *                 Less or equal to 0 if the buffer is too small.
 */
int u8_fromchar(Uchar w, char *to, size_t maxlen)
{
	if (maxlen < 1)
		return 0;

	if (!w)
		return 0;

	if (w >= 0xE000 && !utf8_enable.integer)
		w -= 0xE000;

	if (w < 0x80 || !utf8_enable.integer)
	{
		to[0] = (char)w;
		if (maxlen < 2)
			return -1;
		to[1] = 0;
		return 1;
	}
	// for a little speedup
	if (w < 0x800)
	{
		if (maxlen < 3)
		{
			to[0] = 0;
			return -1;
		}
		to[2] = 0;
		to[1] = 0x80 | (w & 0x3F); w >>= 6;
		to[0] = 0xC0 | w;
		return 2;
	}
	if (w < 0x10000)
	{
		if (maxlen < 4)
		{
			to[0] = 0;
			return -1;
		}
		to[3] = 0;
		to[2] = 0x80 | (w & 0x3F); w >>= 6;
		to[1] = 0x80 | (w & 0x3F); w >>= 6;
		to[0] = 0xE0 | w;
		return 3;
	}

	// RFC 3629
	if (w <= 0x10FFFF)
	{
		if (maxlen < 5)
		{
			to[0] = 0;
			return -1;
		}
		to[4] = 0;
		to[3] = 0x80 | (w & 0x3F); w >>= 6;
		to[2] = 0x80 | (w & 0x3F); w >>= 6;
		to[1] = 0x80 | (w & 0x3F); w >>= 6;
		to[0] = 0xF0 | w;
		return 4;
	}
	return 0;
}

/** uses u8_fromchar on a static buffer
 * @param ch        The unicode character to convert to encode
 * @param l         The number of bytes without the terminating null.
 * @return          A statically allocated buffer containing the character's utf8 representation, or NULL if it fails.
 */
char *u8_encodech(Uchar ch, size_t *l, char *buf16)
{
	size_t len;
	len = u8_fromchar(ch, buf16, 16);
	if (len > 0)
	{
		if (l) *l = len;
		return buf16;
	}
	return NULL;
}

/** Convert a utf-8 multibyte string to a wide character string.
 * @param wcs       The target wide-character buffer.
 * @param mb        The utf-8 encoded multibyte string to convert.
 * @param maxlen    The maximum number of wide-characters that fit into the target buffer.
 * @return          The number of characters written to the target buffer.
 */
size_t u8_mbstowcs(Uchar *wcs, const char *mb, size_t maxlen)
{
	size_t i;
	Uchar ch;
	if (maxlen < 1)
		return 0;
	for (i = 0; *mb && i < maxlen-1; ++i)
	{
		ch = u8_getchar(mb, &mb);
		if (!ch)
			break;
		wcs[i] = ch;
	}
	wcs[i] = 0;
	return i;
}

/** Convert a wide-character string to a utf-8 multibyte string.
 * @param mb      The target buffer the utf-8 string is written to.
 * @param wcs     The wide-character string to convert.
 * @param maxlen  The number bytes that fit into the multibyte target buffer.
 * @return        The number of bytes written, not including the terminating \0
 */
size_t u8_wcstombs(char *mb, const Uchar *wcs, size_t maxlen)
{
	size_t i;
	const char *start = mb;
	if (maxlen < 2)
		return 0;
	for (i = 0; wcs[i] && i < maxlen-1; ++i)
	{
		/*
		int len;
		if ( (len = u8_fromchar(wcs[i], mb, maxlen - i)) < 0)
			return (mb - start);
		mb += len;
		*/
		mb += u8_fromchar(wcs[i], mb, maxlen - i);
	}
	*mb = 0;
	return (mb - start);
}

/*
============
UTF-8 aware COM_StringLengthNoColors

calculates the visible width of a color coded string.

*valid is filled with TRUE if the string is a valid colored string (that is, if
it does not end with an unfinished color code). If it gets filled with FALSE, a
fix would be adding a STRING_COLOR_TAG at the end of the string.

valid can be set to NULL if the caller doesn't care.

For size_s, specify the maximum number of characters from s to use, or 0 to use
all characters until the zero terminator.
============
*/
size_t
COM_StringLengthNoColors(const char *s, size_t size_s, qboolean *valid);
size_t
u8_COM_StringLengthNoColors(const char *_s, size_t size_s, qboolean *valid)
{
	const unsigned char *s = (const unsigned char*)_s;
	const unsigned char *end;
	size_t len = 0;
	size_t st, ln;

	if (!utf8_enable.integer)
		return COM_StringLengthNoColors(_s, size_s, valid);

	end = size_s ? (s + size_s) : NULL;

	for(;;)
	{
		switch((s == end) ? 0 : *s)
		{
			case 0:
				if(valid)
					*valid = TRUE;
				return len;
			case STRING_COLOR_TAG:
				++s;
				switch((s == end) ? 0 : *s)
				{
					case STRING_COLOR_RGB_TAG_CHAR:
						if (s+1 != end && isxdigit(s[1]) &&
							s+2 != end && isxdigit(s[2]) &&
							s+3 != end && isxdigit(s[3]) )
						{
							s+=3;
							break;
						}
						++len; // STRING_COLOR_TAG
						++len; // STRING_COLOR_RGB_TAG_CHAR
						break;
					case 0: // ends with unfinished color code!
						++len;
						if(valid)
							*valid = FALSE;
						return len;
					case STRING_COLOR_TAG: // escaped ^
						++len;
						break;
					case '0': case '1': case '2': case '3': case '4':
					case '5': case '6': case '7': case '8': case '9': // color code
						break;
					default: // not a color code
						++len; // STRING_COLOR_TAG
						++len; // the character
						break;
				}
				++s;
				continue;
			default:
				break;
		}

		// ascii char, skip u8_analyze
		if (*s < 0x80)
		{
			++len;
			++s;
			continue;
		}

		// invalid, skip u8_analyze
		if (*s < 0xC2)
		{
			++s;
			continue;
		}

		if (!u8_analyze((const char*)s, &st, &ln, NULL, U8_ANALYZE_INFINITY))
		{
			// we CAN end up here, if an invalid char is between this one and the end of the string
			if(valid)
				*valid = TRUE;
			return len;
		}

		if(end && s + st + ln > end)
		{
			// string length exceeded by new character
			if(valid)
				*valid = TRUE;
			return len;
		}

		// valid character, skip after it
		s += st + ln;
		++len;
	}
	// never get here
}

/** Pads a utf-8 string
 * @param out     The target buffer the utf-8 string is written to.
 * @param outsize The size of the target buffer, including the final NUL
 * @param in      The input utf-8 buffer
 * @param leftalign Left align the output string (by default right alignment is done)
 * @param minwidth The minimum output width
 * @param maxwidth The maximum output width
 * @return        The number of bytes written, not including the terminating \0
 */
size_t u8_strpad(char *out, size_t outsize, const char *in, qboolean leftalign, size_t minwidth, size_t maxwidth)
{
	if(!utf8_enable.integer)
	{
		return dpsnprintf(out, outsize, "%*.*s", leftalign ? -(int) minwidth : (int) minwidth, (int) maxwidth, in);
	}
	else
	{
		size_t l = u8_bytelen(in, maxwidth);
		size_t actual_width = u8_strnlen(in, l);
		int pad = (int)((actual_width >= minwidth) ? 0 : (minwidth - actual_width));
		int prec = (int)l;
		int lpad = leftalign ? 0 : pad;
		int rpad = leftalign ? pad : 0;
		return dpsnprintf(out, outsize, "%*s%.*s%*s", lpad, "", prec, in, rpad, "");
	}
}

size_t u8_strpad_colorcodes(char *out, size_t outsize, const char *in, qboolean leftalign, size_t minwidth, size_t maxwidth)
{
	size_t l = u8_bytelen_colorcodes(in, maxwidth);
	size_t actual_width = u8_strnlen_colorcodes(in, l);
	int pad = (int)((actual_width >= minwidth) ? 0 : (minwidth - actual_width));
	int prec = (int)l;
	int lpad = leftalign ? 0 : pad;
	int rpad = leftalign ? pad : 0;
	return dpsnprintf(out, outsize, "%*s%.*s%*s", lpad, "", prec, in, rpad, "");
}


/*
The two following functions (u8_toupper, u8_tolower) are derived from
ftp://ftp.unicode.org/Public/UNIDATA/UnicodeData.txt and the following license
holds for these:

Copyright © 1991-2011 Unicode, Inc. All rights reserved. Distributed under the
Terms of Use in http://www.unicode.org/copyright.html.

Permission is hereby granted, free of charge, to any person obtaining a copy of
the Unicode data files and any associated documentation (the "Data Files") or
Unicode software and any associated documentation (the "Software") to deal in
the Data Files or Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, and/or sell copies
of the Data Files or Software, and to permit persons to whom the Data Files or
Software are furnished to do so, provided that (a) the above copyright
notice(s) and this permission notice appear with all copies of the Data Files
or Software, (b) both the above copyright notice(s) and this permission notice
appear in associated documentation, and (c) there is clear notice in each
modified Data File or in the Software as well as in the documentation
associated with the Data File(s) or Software that the data or software has been
modified.

THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD
PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN
THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL
DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THE DATA FILES OR
SOFTWARE.

Except as contained in this notice, the name of a copyright holder shall not be
used in advertising or otherwise to promote the sale, use or other dealings in
these Data Files or Software without prior written authorization of the
copyright holder.
*/

Uchar u8_toupper(Uchar ch)
{
	switch(ch)
	{
		case 0x0061: return 0x0041;
		case 0x0062: return 0x0042;
		case 0x0063: return 0x0043;
		case 0x0064: return 0x0044;
		case 0x0065: return 0x0045;
		case 0x0066: return 0x0046;
		case 0x0067: return 0x0047;
		case 0x0068: return 0x0048;
		case 0x0069: return 0x0049;
		case 0x006A: return 0x004A;
		case 0x006B: return 0x004B;
		case 0x006C: return 0x004C;
		case 0x006D: return 0x004D;
		case 0x006E: return 0x004E;
		case 0x006F: return 0x004F;
		case 0x0070: return 0x0050;
		case 0x0071: return 0x0051;
		case 0x0072: return 0x0052;
		case 0x0073: return 0x0053;
		case 0x0074: return 0x0054;
		case 0x0075: return 0x0055;
		case 0x0076: return 0x0056;
		case 0x0077: return 0x0057;
		case 0x0078: return 0x0058;
		case 0x0079: return 0x0059;
		case 0x007A: return 0x005A;
		case 0x00B5: return 0x039C;
		case 0x00E0: return 0x00C0;
		case 0x00E1: return 0x00C1;
		case 0x00E2: return 0x00C2;
		case 0x00E3: return 0x00C3;
		case 0x00E4: return 0x00C4;
		case 0x00E5: return 0x00C5;
		case 0x00E6: return 0x00C6;
		case 0x00E7: return 0x00C7;
		case 0x00E8: return 0x00C8;
		case 0x00E9: return 0x00C9;
		case 0x00EA: return 0x00CA;
		case 0x00EB: return 0x00CB;
		case 0x00EC: return 0x00CC;
		case 0x00ED: return 0x00CD;
		case 0x00EE: return 0x00CE;
		case 0x00EF: return 0x00CF;
		case 0x00F0: return 0x00D0;
		case 0x00F1: return 0x00D1;
		case 0x00F2: return 0x00D2;
		case 0x00F3: return 0x00D3;
		case 0x00F4: return 0x00D4;
		case 0x00F5: return 0x00D5;
		case 0x00F6: return 0x00D6;
		case 0x00F8: return 0x00D8;
		case 0x00F9: return 0x00D9;
		case 0x00FA: return 0x00DA;
		case 0x00FB: return 0x00DB;
		case 0x00FC: return 0x00DC;
		case 0x00FD: return 0x00DD;
		case 0x00FE: return 0x00DE;
		case 0x00FF: return 0x0178;
		case 0x0101: return 0x0100;
		case 0x0103: return 0x0102;
		case 0x0105: return 0x0104;
		case 0x0107: return 0x0106;
		case 0x0109: return 0x0108;
		case 0x010B: return 0x010A;
		case 0x010D: return 0x010C;
		case 0x010F: return 0x010E;
		case 0x0111: return 0x0110;
		case 0x0113: return 0x0112;
		case 0x0115: return 0x0114;
		case 0x0117: return 0x0116;
		case 0x0119: return 0x0118;
		case 0x011B: return 0x011A;
		case 0x011D: return 0x011C;
		case 0x011F: return 0x011E;
		case 0x0121: return 0x0120;
		case 0x0123: return 0x0122;
		case 0x0125: return 0x0124;
		case 0x0127: return 0x0126;
		case 0x0129: return 0x0128;
		case 0x012B: return 0x012A;
		case 0x012D: return 0x012C;
		case 0x012F: return 0x012E;
		case 0x0131: return 0x0049;
		case 0x0133: return 0x0132;
		case 0x0135: return 0x0134;
		case 0x0137: return 0x0136;
		case 0x013A: return 0x0139;
		case 0x013C: return 0x013B;
		case 0x013E: return 0x013D;
		case 0x0140: return 0x013F;
		case 0x0142: return 0x0141;
		case 0x0144: return 0x0143;
		case 0x0146: return 0x0145;
		case 0x0148: return 0x0147;
		case 0x014B: return 0x014A;
		case 0x014D: return 0x014C;
		case 0x014F: return 0x014E;
		case 0x0151: return 0x0150;
		case 0x0153: return 0x0152;
		case 0x0155: return 0x0154;
		case 0x0157: return 0x0156;
		case 0x0159: return 0x0158;
		case 0x015B: return 0x015A;
		case 0x015D: return 0x015C;
		case 0x015F: return 0x015E;
		case 0x0161: return 0x0160;
		case 0x0163: return 0x0162;
		case 0x0165: return 0x0164;
		case 0x0167: return 0x0166;
		case 0x0169: return 0x0168;
		case 0x016B: return 0x016A;
		case 0x016D: return 0x016C;
		case 0x016F: return 0x016E;
		case 0x0171: return 0x0170;
		case 0x0173: return 0x0172;
		case 0x0175: return 0x0174;
		case 0x0177: return 0x0176;
		case 0x017A: return 0x0179;
		case 0x017C: return 0x017B;
		case 0x017E: return 0x017D;
		case 0x017F: return 0x0053;
		case 0x0180: return 0x0243;
		case 0x0183: return 0x0182;
		case 0x0185: return 0x0184;
		case 0x0188: return 0x0187;
		case 0x018C: return 0x018B;
		case 0x0192: return 0x0191;
		case 0x0195: return 0x01F6;
		case 0x0199: return 0x0198;
		case 0x019A: return 0x023D;
		case 0x019E: return 0x0220;
		case 0x01A1: return 0x01A0;
		case 0x01A3: return 0x01A2;
		case 0x01A5: return 0x01A4;
		case 0x01A8: return 0x01A7;
		case 0x01AD: return 0x01AC;
		case 0x01B0: return 0x01AF;
		case 0x01B4: return 0x01B3;
		case 0x01B6: return 0x01B5;
		case 0x01B9: return 0x01B8;
		case 0x01BD: return 0x01BC;
		case 0x01BF: return 0x01F7;
		case 0x01C5: return 0x01C4;
		case 0x01C6: return 0x01C4;
		case 0x01C8: return 0x01C7;
		case 0x01C9: return 0x01C7;
		case 0x01CB: return 0x01CA;
		case 0x01CC: return 0x01CA;
		case 0x01CE: return 0x01CD;
		case 0x01D0: return 0x01CF;
		case 0x01D2: return 0x01D1;
		case 0x01D4: return 0x01D3;
		case 0x01D6: return 0x01D5;
		case 0x01D8: return 0x01D7;
		case 0x01DA: return 0x01D9;
		case 0x01DC: return 0x01DB;
		case 0x01DD: return 0x018E;
		case 0x01DF: return 0x01DE;
		case 0x01E1: return 0x01E0;
		case 0x01E3: return 0x01E2;
		case 0x01E5: return 0x01E4;
		case 0x01E7: return 0x01E6;
		case 0x01E9: return 0x01E8;
		case 0x01EB: return 0x01EA;
		case 0x01ED: return 0x01EC;
		case 0x01EF: return 0x01EE;
		case 0x01F2: return 0x01F1;
		case 0x01F3: return 0x01F1;
		case 0x01F5: return 0x01F4;
		case 0x01F9: return 0x01F8;
		case 0x01FB: return 0x01FA;
		case 0x01FD: return 0x01FC;
		case 0x01FF: return 0x01FE;
		case 0x0201: return 0x0200;
		case 0x0203: return 0x0202;
		case 0x0205: return 0x0204;
		case 0x0207: return 0x0206;
		case 0x0209: return 0x0208;
		case 0x020B: return 0x020A;
		case 0x020D: return 0x020C;
		case 0x020F: return 0x020E;
		case 0x0211: return 0x0210;
		case 0x0213: return 0x0212;
		case 0x0215: return 0x0214;
		case 0x0217: return 0x0216;
		case 0x0219: return 0x0218;
		case 0x021B: return 0x021A;
		case 0x021D: return 0x021C;
		case 0x021F: return 0x021E;
		case 0x0223: return 0x0222;
		case 0x0225: return 0x0224;
		case 0x0227: return 0x0226;
		case 0x0229: return 0x0228;
		case 0x022B: return 0x022A;
		case 0x022D: return 0x022C;
		case 0x022F: return 0x022E;
		case 0x0231: return 0x0230;
		case 0x0233: return 0x0232;
		case 0x023C: return 0x023B;
		case 0x023F: return 0x2C7E;
		case 0x0240: return 0x2C7F;
		case 0x0242: return 0x0241;
		case 0x0247: return 0x0246;
		case 0x0249: return 0x0248;
		case 0x024B: return 0x024A;
		case 0x024D: return 0x024C;
		case 0x024F: return 0x024E;
		case 0x0250: return 0x2C6F;
		case 0x0251: return 0x2C6D;
		case 0x0252: return 0x2C70;
		case 0x0253: return 0x0181;
		case 0x0254: return 0x0186;
		case 0x0256: return 0x0189;
		case 0x0257: return 0x018A;
		case 0x0259: return 0x018F;
		case 0x025B: return 0x0190;
		case 0x0260: return 0x0193;
		case 0x0263: return 0x0194;
		case 0x0265: return 0xA78D;
		case 0x0268: return 0x0197;
		case 0x0269: return 0x0196;
		case 0x026B: return 0x2C62;
		case 0x026F: return 0x019C;
		case 0x0271: return 0x2C6E;
		case 0x0272: return 0x019D;
		case 0x0275: return 0x019F;
		case 0x027D: return 0x2C64;
		case 0x0280: return 0x01A6;
		case 0x0283: return 0x01A9;
		case 0x0288: return 0x01AE;
		case 0x0289: return 0x0244;
		case 0x028A: return 0x01B1;
		case 0x028B: return 0x01B2;
		case 0x028C: return 0x0245;
		case 0x0292: return 0x01B7;
		case 0x0345: return 0x0399;
		case 0x0371: return 0x0370;
		case 0x0373: return 0x0372;
		case 0x0377: return 0x0376;
		case 0x037B: return 0x03FD;
		case 0x037C: return 0x03FE;
		case 0x037D: return 0x03FF;
		case 0x03AC: return 0x0386;
		case 0x03AD: return 0x0388;
		case 0x03AE: return 0x0389;
		case 0x03AF: return 0x038A;
		case 0x03B1: return 0x0391;
		case 0x03B2: return 0x0392;
		case 0x03B3: return 0x0393;
		case 0x03B4: return 0x0394;
		case 0x03B5: return 0x0395;
		case 0x03B6: return 0x0396;
		case 0x03B7: return 0x0397;
		case 0x03B8: return 0x0398;
		case 0x03B9: return 0x0399;
		case 0x03BA: return 0x039A;
		case 0x03BB: return 0x039B;
		case 0x03BC: return 0x039C;
		case 0x03BD: return 0x039D;
		case 0x03BE: return 0x039E;
		case 0x03BF: return 0x039F;
		case 0x03C0: return 0x03A0;
		case 0x03C1: return 0x03A1;
		case 0x03C2: return 0x03A3;
		case 0x03C3: return 0x03A3;
		case 0x03C4: return 0x03A4;
		case 0x03C5: return 0x03A5;
		case 0x03C6: return 0x03A6;
		case 0x03C7: return 0x03A7;
		case 0x03C8: return 0x03A8;
		case 0x03C9: return 0x03A9;
		case 0x03CA: return 0x03AA;
		case 0x03CB: return 0x03AB;
		case 0x03CC: return 0x038C;
		case 0x03CD: return 0x038E;
		case 0x03CE: return 0x038F;
		case 0x03D0: return 0x0392;
		case 0x03D1: return 0x0398;
		case 0x03D5: return 0x03A6;
		case 0x03D6: return 0x03A0;
		case 0x03D7: return 0x03CF;
		case 0x03D9: return 0x03D8;
		case 0x03DB: return 0x03DA;
		case 0x03DD: return 0x03DC;
		case 0x03DF: return 0x03DE;
		case 0x03E1: return 0x03E0;
		case 0x03E3: return 0x03E2;
		case 0x03E5: return 0x03E4;
		case 0x03E7: return 0x03E6;
		case 0x03E9: return 0x03E8;
		case 0x03EB: return 0x03EA;
		case 0x03ED: return 0x03EC;
		case 0x03EF: return 0x03EE;
		case 0x03F0: return 0x039A;
		case 0x03F1: return 0x03A1;
		case 0x03F2: return 0x03F9;
		case 0x03F5: return 0x0395;
		case 0x03F8: return 0x03F7;
		case 0x03FB: return 0x03FA;
		case 0x0430: return 0x0410;
		case 0x0431: return 0x0411;
		case 0x0432: return 0x0412;
		case 0x0433: return 0x0413;
		case 0x0434: return 0x0414;
		case 0x0435: return 0x0415;
		case 0x0436: return 0x0416;
		case 0x0437: return 0x0417;
		case 0x0438: return 0x0418;
		case 0x0439: return 0x0419;
		case 0x043A: return 0x041A;
		case 0x043B: return 0x041B;
		case 0x043C: return 0x041C;
		case 0x043D: return 0x041D;
		case 0x043E: return 0x041E;
		case 0x043F: return 0x041F;
		case 0x0440: return 0x0420;
		case 0x0441: return 0x0421;
		case 0x0442: return 0x0422;
		case 0x0443: return 0x0423;
		case 0x0444: return 0x0424;
		case 0x0445: return 0x0425;
		case 0x0446: return 0x0426;
		case 0x0447: return 0x0427;
		case 0x0448: return 0x0428;
		case 0x0449: return 0x0429;
		case 0x044A: return 0x042A;
		case 0x044B: return 0x042B;
		case 0x044C: return 0x042C;
		case 0x044D: return 0x042D;
		case 0x044E: return 0x042E;
		case 0x044F: return 0x042F;
		case 0x0450: return 0x0400;
		case 0x0451: return 0x0401;
		case 0x0452: return 0x0402;
		case 0x0453: return 0x0403;
		case 0x0454: return 0x0404;
		case 0x0455: return 0x0405;
		case 0x0456: return 0x0406;
		case 0x0457: return 0x0407;
		case 0x0458: return 0x0408;
		case 0x0459: return 0x0409;
		case 0x045A: return 0x040A;
		case 0x045B: return 0x040B;
		case 0x045C: return 0x040C;
		case 0x045D: return 0x040D;
		case 0x045E: return 0x040E;
		case 0x045F: return 0x040F;
		case 0x0461: return 0x0460;
		case 0x0463: return 0x0462;
		case 0x0465: return 0x0464;
		case 0x0467: return 0x0466;
		case 0x0469: return 0x0468;
		case 0x046B: return 0x046A;
		case 0x046D: return 0x046C;
		case 0x046F: return 0x046E;
		case 0x0471: return 0x0470;
		case 0x0473: return 0x0472;
		case 0x0475: return 0x0474;
		case 0x0477: return 0x0476;
		case 0x0479: return 0x0478;
		case 0x047B: return 0x047A;
		case 0x047D: return 0x047C;
		case 0x047F: return 0x047E;
		case 0x0481: return 0x0480;
		case 0x048B: return 0x048A;
		case 0x048D: return 0x048C;
		case 0x048F: return 0x048E;
		case 0x0491: return 0x0490;
		case 0x0493: return 0x0492;
		case 0x0495: return 0x0494;
		case 0x0497: return 0x0496;
		case 0x0499: return 0x0498;
		case 0x049B: return 0x049A;
		case 0x049D: return 0x049C;
		case 0x049F: return 0x049E;
		case 0x04A1: return 0x04A0;
		case 0x04A3: return 0x04A2;
		case 0x04A5: return 0x04A4;
		case 0x04A7: return 0x04A6;
		case 0x04A9: return 0x04A8;
		case 0x04AB: return 0x04AA;
		case 0x04AD: return 0x04AC;
		case 0x04AF: return 0x04AE;
		case 0x04B1: return 0x04B0;
		case 0x04B3: return 0x04B2;
		case 0x04B5: return 0x04B4;
		case 0x04B7: return 0x04B6;
		case 0x04B9: return 0x04B8;
		case 0x04BB: return 0x04BA;
		case 0x04BD: return 0x04BC;
		case 0x04BF: return 0x04BE;
		case 0x04C2: return 0x04C1;
		case 0x04C4: return 0x04C3;
		case 0x04C6: return 0x04C5;
		case 0x04C8: return 0x04C7;
		case 0x04CA: return 0x04C9;
		case 0x04CC: return 0x04CB;
		case 0x04CE: return 0x04CD;
		case 0x04CF: return 0x04C0;
		case 0x04D1: return 0x04D0;
		case 0x04D3: return 0x04D2;
		case 0x04D5: return 0x04D4;
		case 0x04D7: return 0x04D6;
		case 0x04D9: return 0x04D8;
		case 0x04DB: return 0x04DA;
		case 0x04DD: return 0x04DC;
		case 0x04DF: return 0x04DE;
		case 0x04E1: return 0x04E0;
		case 0x04E3: return 0x04E2;
		case 0x04E5: return 0x04E4;
		case 0x04E7: return 0x04E6;
		case 0x04E9: return 0x04E8;
		case 0x04EB: return 0x04EA;
		case 0x04ED: return 0x04EC;
		case 0x04EF: return 0x04EE;
		case 0x04F1: return 0x04F0;
		case 0x04F3: return 0x04F2;
		case 0x04F5: return 0x04F4;
		case 0x04F7: return 0x04F6;
		case 0x04F9: return 0x04F8;
		case 0x04FB: return 0x04FA;
		case 0x04FD: return 0x04FC;
		case 0x04FF: return 0x04FE;
		case 0x0501: return 0x0500;
		case 0x0503: return 0x0502;
		case 0x0505: return 0x0504;
		case 0x0507: return 0x0506;
		case 0x0509: return 0x0508;
		case 0x050B: return 0x050A;
		case 0x050D: return 0x050C;
		case 0x050F: return 0x050E;
		case 0x0511: return 0x0510;
		case 0x0513: return 0x0512;
		case 0x0515: return 0x0514;
		case 0x0517: return 0x0516;
		case 0x0519: return 0x0518;
		case 0x051B: return 0x051A;
		case 0x051D: return 0x051C;
		case 0x051F: return 0x051E;
		case 0x0521: return 0x0520;
		case 0x0523: return 0x0522;
		case 0x0525: return 0x0524;
		case 0x0527: return 0x0526;
		case 0x0561: return 0x0531;
		case 0x0562: return 0x0532;
		case 0x0563: return 0x0533;
		case 0x0564: return 0x0534;
		case 0x0565: return 0x0535;
		case 0x0566: return 0x0536;
		case 0x0567: return 0x0537;
		case 0x0568: return 0x0538;
		case 0x0569: return 0x0539;
		case 0x056A: return 0x053A;
		case 0x056B: return 0x053B;
		case 0x056C: return 0x053C;
		case 0x056D: return 0x053D;
		case 0x056E: return 0x053E;
		case 0x056F: return 0x053F;
		case 0x0570: return 0x0540;
		case 0x0571: return 0x0541;
		case 0x0572: return 0x0542;
		case 0x0573: return 0x0543;
		case 0x0574: return 0x0544;
		case 0x0575: return 0x0545;
		case 0x0576: return 0x0546;
		case 0x0577: return 0x0547;
		case 0x0578: return 0x0548;
		case 0x0579: return 0x0549;
		case 0x057A: return 0x054A;
		case 0x057B: return 0x054B;
		case 0x057C: return 0x054C;
		case 0x057D: return 0x054D;
		case 0x057E: return 0x054E;
		case 0x057F: return 0x054F;
		case 0x0580: return 0x0550;
		case 0x0581: return 0x0551;
		case 0x0582: return 0x0552;
		case 0x0583: return 0x0553;
		case 0x0584: return 0x0554;
		case 0x0585: return 0x0555;
		case 0x0586: return 0x0556;
		case 0x1D79: return 0xA77D;
		case 0x1D7D: return 0x2C63;
		case 0x1E01: return 0x1E00;
		case 0x1E03: return 0x1E02;
		case 0x1E05: return 0x1E04;
		case 0x1E07: return 0x1E06;
		case 0x1E09: return 0x1E08;
		case 0x1E0B: return 0x1E0A;
		case 0x1E0D: return 0x1E0C;
		case 0x1E0F: return 0x1E0E;
		case 0x1E11: return 0x1E10;
		case 0x1E13: return 0x1E12;
		case 0x1E15: return 0x1E14;
		case 0x1E17: return 0x1E16;
		case 0x1E19: return 0x1E18;
		case 0x1E1B: return 0x1E1A;
		case 0x1E1D: return 0x1E1C;
		case 0x1E1F: return 0x1E1E;
		case 0x1E21: return 0x1E20;
		case 0x1E23: return 0x1E22;
		case 0x1E25: return 0x1E24;
		case 0x1E27: return 0x1E26;
		case 0x1E29: return 0x1E28;
		case 0x1E2B: return 0x1E2A;
		case 0x1E2D: return 0x1E2C;
		case 0x1E2F: return 0x1E2E;
		case 0x1E31: return 0x1E30;
		case 0x1E33: return 0x1E32;
		case 0x1E35: return 0x1E34;
		case 0x1E37: return 0x1E36;
		case 0x1E39: return 0x1E38;
		case 0x1E3B: return 0x1E3A;
		case 0x1E3D: return 0x1E3C;
		case 0x1E3F: return 0x1E3E;
		case 0x1E41: return 0x1E40;
		case 0x1E43: return 0x1E42;
		case 0x1E45: return 0x1E44;
		case 0x1E47: return 0x1E46;
		case 0x1E49: return 0x1E48;
		case 0x1E4B: return 0x1E4A;
		case 0x1E4D: return 0x1E4C;
		case 0x1E4F: return 0x1E4E;
		case 0x1E51: return 0x1E50;
		case 0x1E53: return 0x1E52;
		case 0x1E55: return 0x1E54;
		case 0x1E57: return 0x1E56;
		case 0x1E59: return 0x1E58;
		case 0x1E5B: return 0x1E5A;
		case 0x1E5D: return 0x1E5C;
		case 0x1E5F: return 0x1E5E;
		case 0x1E61: return 0x1E60;
		case 0x1E63: return 0x1E62;
		case 0x1E65: return 0x1E64;
		case 0x1E67: return 0x1E66;
		case 0x1E69: return 0x1E68;
		case 0x1E6B: return 0x1E6A;
		case 0x1E6D: return 0x1E6C;
		case 0x1E6F: return 0x1E6E;
		case 0x1E71: return 0x1E70;
		case 0x1E73: return 0x1E72;
		case 0x1E75: return 0x1E74;
		case 0x1E77: return 0x1E76;
		case 0x1E79: return 0x1E78;
		case 0x1E7B: return 0x1E7A;
		case 0x1E7D: return 0x1E7C;
		case 0x1E7F: return 0x1E7E;
		case 0x1E81: return 0x1E80;
		case 0x1E83: return 0x1E82;
		case 0x1E85: return 0x1E84;
		case 0x1E87: return 0x1E86;
		case 0x1E89: return 0x1E88;
		case 0x1E8B: return 0x1E8A;
		case 0x1E8D: return 0x1E8C;
		case 0x1E8F: return 0x1E8E;
		case 0x1E91: return 0x1E90;
		case 0x1E93: return 0x1E92;
		case 0x1E95: return 0x1E94;
		case 0x1E9B: return 0x1E60;
		case 0x1EA1: return 0x1EA0;
		case 0x1EA3: return 0x1EA2;
		case 0x1EA5: return 0x1EA4;
		case 0x1EA7: return 0x1EA6;
		case 0x1EA9: return 0x1EA8;
		case 0x1EAB: return 0x1EAA;
		case 0x1EAD: return 0x1EAC;
		case 0x1EAF: return 0x1EAE;
		case 0x1EB1: return 0x1EB0;
		case 0x1EB3: return 0x1EB2;
		case 0x1EB5: return 0x1EB4;
		case 0x1EB7: return 0x1EB6;
		case 0x1EB9: return 0x1EB8;
		case 0x1EBB: return 0x1EBA;
		case 0x1EBD: return 0x1EBC;
		case 0x1EBF: return 0x1EBE;
		case 0x1EC1: return 0x1EC0;
		case 0x1EC3: return 0x1EC2;
		case 0x1EC5: return 0x1EC4;
		case 0x1EC7: return 0x1EC6;
		case 0x1EC9: return 0x1EC8;
		case 0x1ECB: return 0x1ECA;
		case 0x1ECD: return 0x1ECC;
		case 0x1ECF: return 0x1ECE;
		case 0x1ED1: return 0x1ED0;
		case 0x1ED3: return 0x1ED2;
		case 0x1ED5: return 0x1ED4;
		case 0x1ED7: return 0x1ED6;
		case 0x1ED9: return 0x1ED8;
		case 0x1EDB: return 0x1EDA;
		case 0x1EDD: return 0x1EDC;
		case 0x1EDF: return 0x1EDE;
		case 0x1EE1: return 0x1EE0;
		case 0x1EE3: return 0x1EE2;
		case 0x1EE5: return 0x1EE4;
		case 0x1EE7: return 0x1EE6;
		case 0x1EE9: return 0x1EE8;
		case 0x1EEB: return 0x1EEA;
		case 0x1EED: return 0x1EEC;
		case 0x1EEF: return 0x1EEE;
		case 0x1EF1: return 0x1EF0;
		case 0x1EF3: return 0x1EF2;
		case 0x1EF5: return 0x1EF4;
		case 0x1EF7: return 0x1EF6;
		case 0x1EF9: return 0x1EF8;
		case 0x1EFB: return 0x1EFA;
		case 0x1EFD: return 0x1EFC;
		case 0x1EFF: return 0x1EFE;
		case 0x1F00: return 0x1F08;
		case 0x1F01: return 0x1F09;
		case 0x1F02: return 0x1F0A;
		case 0x1F03: return 0x1F0B;
		case 0x1F04: return 0x1F0C;
		case 0x1F05: return 0x1F0D;
		case 0x1F06: return 0x1F0E;
		case 0x1F07: return 0x1F0F;
		case 0x1F10: return 0x1F18;
		case 0x1F11: return 0x1F19;
		case 0x1F12: return 0x1F1A;
		case 0x1F13: return 0x1F1B;
		case 0x1F14: return 0x1F1C;
		case 0x1F15: return 0x1F1D;
		case 0x1F20: return 0x1F28;
		case 0x1F21: return 0x1F29;
		case 0x1F22: return 0x1F2A;
		case 0x1F23: return 0x1F2B;
		case 0x1F24: return 0x1F2C;
		case 0x1F25: return 0x1F2D;
		case 0x1F26: return 0x1F2E;
		case 0x1F27: return 0x1F2F;
		case 0x1F30: return 0x1F38;
		case 0x1F31: return 0x1F39;
		case 0x1F32: return 0x1F3A;
		case 0x1F33: return 0x1F3B;
		case 0x1F34: return 0x1F3C;
		case 0x1F35: return 0x1F3D;
		case 0x1F36: return 0x1F3E;
		case 0x1F37: return 0x1F3F;
		case 0x1F40: return 0x1F48;
		case 0x1F41: return 0x1F49;
		case 0x1F42: return 0x1F4A;
		case 0x1F43: return 0x1F4B;
		case 0x1F44: return 0x1F4C;
		case 0x1F45: return 0x1F4D;
		case 0x1F51: return 0x1F59;
		case 0x1F53: return 0x1F5B;
		case 0x1F55: return 0x1F5D;
		case 0x1F57: return 0x1F5F;
		case 0x1F60: return 0x1F68;
		case 0x1F61: return 0x1F69;
		case 0x1F62: return 0x1F6A;
		case 0x1F63: return 0x1F6B;
		case 0x1F64: return 0x1F6C;
		case 0x1F65: return 0x1F6D;
		case 0x1F66: return 0x1F6E;
		case 0x1F67: return 0x1F6F;
		case 0x1F70: return 0x1FBA;
		case 0x1F71: return 0x1FBB;
		case 0x1F72: return 0x1FC8;
		case 0x1F73: return 0x1FC9;
		case 0x1F74: return 0x1FCA;
		case 0x1F75: return 0x1FCB;
		case 0x1F76: return 0x1FDA;
		case 0x1F77: return 0x1FDB;
		case 0x1F78: return 0x1FF8;
		case 0x1F79: return 0x1FF9;
		case 0x1F7A: return 0x1FEA;
		case 0x1F7B: return 0x1FEB;
		case 0x1F7C: return 0x1FFA;
		case 0x1F7D: return 0x1FFB;
		case 0x1F80: return 0x1F88;
		case 0x1F81: return 0x1F89;
		case 0x1F82: return 0x1F8A;
		case 0x1F83: return 0x1F8B;
		case 0x1F84: return 0x1F8C;
		case 0x1F85: return 0x1F8D;
		case 0x1F86: return 0x1F8E;
		case 0x1F87: return 0x1F8F;
		case 0x1F90: return 0x1F98;
		case 0x1F91: return 0x1F99;
		case 0x1F92: return 0x1F9A;
		case 0x1F93: return 0x1F9B;
		case 0x1F94: return 0x1F9C;
		case 0x1F95: return 0x1F9D;
		case 0x1F96: return 0x1F9E;
		case 0x1F97: return 0x1F9F;
		case 0x1FA0: return 0x1FA8;
		case 0x1FA1: return 0x1FA9;
		case 0x1FA2: return 0x1FAA;
		case 0x1FA3: return 0x1FAB;
		case 0x1FA4: return 0x1FAC;
		case 0x1FA5: return 0x1FAD;
		case 0x1FA6: return 0x1FAE;
		case 0x1FA7: return 0x1FAF;
		case 0x1FB0: return 0x1FB8;
		case 0x1FB1: return 0x1FB9;
		case 0x1FB3: return 0x1FBC;
		case 0x1FBE: return 0x0399;
		case 0x1FC3: return 0x1FCC;
		case 0x1FD0: return 0x1FD8;
		case 0x1FD1: return 0x1FD9;
		case 0x1FE0: return 0x1FE8;
		case 0x1FE1: return 0x1FE9;
		case 0x1FE5: return 0x1FEC;
		case 0x1FF3: return 0x1FFC;
		case 0x214E: return 0x2132;
		case 0x2170: return 0x2160;
		case 0x2171: return 0x2161;
		case 0x2172: return 0x2162;
		case 0x2173: return 0x2163;
		case 0x2174: return 0x2164;
		case 0x2175: return 0x2165;
		case 0x2176: return 0x2166;
		case 0x2177: return 0x2167;
		case 0x2178: return 0x2168;
		case 0x2179: return 0x2169;
		case 0x217A: return 0x216A;
		case 0x217B: return 0x216B;
		case 0x217C: return 0x216C;
		case 0x217D: return 0x216D;
		case 0x217E: return 0x216E;
		case 0x217F: return 0x216F;
		case 0x2184: return 0x2183;
		case 0x24D0: return 0x24B6;
		case 0x24D1: return 0x24B7;
		case 0x24D2: return 0x24B8;
		case 0x24D3: return 0x24B9;
		case 0x24D4: return 0x24BA;
		case 0x24D5: return 0x24BB;
		case 0x24D6: return 0x24BC;
		case 0x24D7: return 0x24BD;
		case 0x24D8: return 0x24BE;
		case 0x24D9: return 0x24BF;
		case 0x24DA: return 0x24C0;
		case 0x24DB: return 0x24C1;
		case 0x24DC: return 0x24C2;
		case 0x24DD: return 0x24C3;
		case 0x24DE: return 0x24C4;
		case 0x24DF: return 0x24C5;
		case 0x24E0: return 0x24C6;
		case 0x24E1: return 0x24C7;
		case 0x24E2: return 0x24C8;
		case 0x24E3: return 0x24C9;
		case 0x24E4: return 0x24CA;
		case 0x24E5: return 0x24CB;
		case 0x24E6: return 0x24CC;
		case 0x24E7: return 0x24CD;
		case 0x24E8: return 0x24CE;
		case 0x24E9: return 0x24CF;
		case 0x2C30: return 0x2C00;
		case 0x2C31: return 0x2C01;
		case 0x2C32: return 0x2C02;
		case 0x2C33: return 0x2C03;
		case 0x2C34: return 0x2C04;
		case 0x2C35: return 0x2C05;
		case 0x2C36: return 0x2C06;
		case 0x2C37: return 0x2C07;
		case 0x2C38: return 0x2C08;
		case 0x2C39: return 0x2C09;
		case 0x2C3A: return 0x2C0A;
		case 0x2C3B: return 0x2C0B;
		case 0x2C3C: return 0x2C0C;
		case 0x2C3D: return 0x2C0D;
		case 0x2C3E: return 0x2C0E;
		case 0x2C3F: return 0x2C0F;
		case 0x2C40: return 0x2C10;
		case 0x2C41: return 0x2C11;
		case 0x2C42: return 0x2C12;
		case 0x2C43: return 0x2C13;
		case 0x2C44: return 0x2C14;
		case 0x2C45: return 0x2C15;
		case 0x2C46: return 0x2C16;
		case 0x2C47: return 0x2C17;
		case 0x2C48: return 0x2C18;
		case 0x2C49: return 0x2C19;
		case 0x2C4A: return 0x2C1A;
		case 0x2C4B: return 0x2C1B;
		case 0x2C4C: return 0x2C1C;
		case 0x2C4D: return 0x2C1D;
		case 0x2C4E: return 0x2C1E;
		case 0x2C4F: return 0x2C1F;
		case 0x2C50: return 0x2C20;
		case 0x2C51: return 0x2C21;
		case 0x2C52: return 0x2C22;
		case 0x2C53: return 0x2C23;
		case 0x2C54: return 0x2C24;
		case 0x2C55: return 0x2C25;
		case 0x2C56: return 0x2C26;
		case 0x2C57: return 0x2C27;
		case 0x2C58: return 0x2C28;
		case 0x2C59: return 0x2C29;
		case 0x2C5A: return 0x2C2A;
		case 0x2C5B: return 0x2C2B;
		case 0x2C5C: return 0x2C2C;
		case 0x2C5D: return 0x2C2D;
		case 0x2C5E: return 0x2C2E;
		case 0x2C61: return 0x2C60;
		case 0x2C65: return 0x023A;
		case 0x2C66: return 0x023E;
		case 0x2C68: return 0x2C67;
		case 0x2C6A: return 0x2C69;
		case 0x2C6C: return 0x2C6B;
		case 0x2C73: return 0x2C72;
		case 0x2C76: return 0x2C75;
		case 0x2C81: return 0x2C80;
		case 0x2C83: return 0x2C82;
		case 0x2C85: return 0x2C84;
		case 0x2C87: return 0x2C86;
		case 0x2C89: return 0x2C88;
		case 0x2C8B: return 0x2C8A;
		case 0x2C8D: return 0x2C8C;
		case 0x2C8F: return 0x2C8E;
		case 0x2C91: return 0x2C90;
		case 0x2C93: return 0x2C92;
		case 0x2C95: return 0x2C94;
		case 0x2C97: return 0x2C96;
		case 0x2C99: return 0x2C98;
		case 0x2C9B: return 0x2C9A;
		case 0x2C9D: return 0x2C9C;
		case 0x2C9F: return 0x2C9E;
		case 0x2CA1: return 0x2CA0;
		case 0x2CA3: return 0x2CA2;
		case 0x2CA5: return 0x2CA4;
		case 0x2CA7: return 0x2CA6;
		case 0x2CA9: return 0x2CA8;
		case 0x2CAB: return 0x2CAA;
		case 0x2CAD: return 0x2CAC;
		case 0x2CAF: return 0x2CAE;
		case 0x2CB1: return 0x2CB0;
		case 0x2CB3: return 0x2CB2;
		case 0x2CB5: return 0x2CB4;
		case 0x2CB7: return 0x2CB6;
		case 0x2CB9: return 0x2CB8;
		case 0x2CBB: return 0x2CBA;
		case 0x2CBD: return 0x2CBC;
		case 0x2CBF: return 0x2CBE;
		case 0x2CC1: return 0x2CC0;
		case 0x2CC3: return 0x2CC2;
		case 0x2CC5: return 0x2CC4;
		case 0x2CC7: return 0x2CC6;
		case 0x2CC9: return 0x2CC8;
		case 0x2CCB: return 0x2CCA;
		case 0x2CCD: return 0x2CCC;
		case 0x2CCF: return 0x2CCE;
		case 0x2CD1: return 0x2CD0;
		case 0x2CD3: return 0x2CD2;
		case 0x2CD5: return 0x2CD4;
		case 0x2CD7: return 0x2CD6;
		case 0x2CD9: return 0x2CD8;
		case 0x2CDB: return 0x2CDA;
		case 0x2CDD: return 0x2CDC;
		case 0x2CDF: return 0x2CDE;
		case 0x2CE1: return 0x2CE0;
		case 0x2CE3: return 0x2CE2;
		case 0x2CEC: return 0x2CEB;
		case 0x2CEE: return 0x2CED;
		case 0x2D00: return 0x10A0;
		case 0x2D01: return 0x10A1;
		case 0x2D02: return 0x10A2;
		case 0x2D03: return 0x10A3;
		case 0x2D04: return 0x10A4;
		case 0x2D05: return 0x10A5;
		case 0x2D06: return 0x10A6;
		case 0x2D07: return 0x10A7;
		case 0x2D08: return 0x10A8;
		case 0x2D09: return 0x10A9;
		case 0x2D0A: return 0x10AA;
		case 0x2D0B: return 0x10AB;
		case 0x2D0C: return 0x10AC;
		case 0x2D0D: return 0x10AD;
		case 0x2D0E: return 0x10AE;
		case 0x2D0F: return 0x10AF;
		case 0x2D10: return 0x10B0;
		case 0x2D11: return 0x10B1;
		case 0x2D12: return 0x10B2;
		case 0x2D13: return 0x10B3;
		case 0x2D14: return 0x10B4;
		case 0x2D15: return 0x10B5;
		case 0x2D16: return 0x10B6;
		case 0x2D17: return 0x10B7;
		case 0x2D18: return 0x10B8;
		case 0x2D19: return 0x10B9;
		case 0x2D1A: return 0x10BA;
		case 0x2D1B: return 0x10BB;
		case 0x2D1C: return 0x10BC;
		case 0x2D1D: return 0x10BD;
		case 0x2D1E: return 0x10BE;
		case 0x2D1F: return 0x10BF;
		case 0x2D20: return 0x10C0;
		case 0x2D21: return 0x10C1;
		case 0x2D22: return 0x10C2;
		case 0x2D23: return 0x10C3;
		case 0x2D24: return 0x10C4;
		case 0x2D25: return 0x10C5;
		case 0xA641: return 0xA640;
		case 0xA643: return 0xA642;
		case 0xA645: return 0xA644;
		case 0xA647: return 0xA646;
		case 0xA649: return 0xA648;
		case 0xA64B: return 0xA64A;
		case 0xA64D: return 0xA64C;
		case 0xA64F: return 0xA64E;
		case 0xA651: return 0xA650;
		case 0xA653: return 0xA652;
		case 0xA655: return 0xA654;
		case 0xA657: return 0xA656;
		case 0xA659: return 0xA658;
		case 0xA65B: return 0xA65A;
		case 0xA65D: return 0xA65C;
		case 0xA65F: return 0xA65E;
		case 0xA661: return 0xA660;
		case 0xA663: return 0xA662;
		case 0xA665: return 0xA664;
		case 0xA667: return 0xA666;
		case 0xA669: return 0xA668;
		case 0xA66B: return 0xA66A;
		case 0xA66D: return 0xA66C;
		case 0xA681: return 0xA680;
		case 0xA683: return 0xA682;
		case 0xA685: return 0xA684;
		case 0xA687: return 0xA686;
		case 0xA689: return 0xA688;
		case 0xA68B: return 0xA68A;
		case 0xA68D: return 0xA68C;
		case 0xA68F: return 0xA68E;
		case 0xA691: return 0xA690;
		case 0xA693: return 0xA692;
		case 0xA695: return 0xA694;
		case 0xA697: return 0xA696;
		case 0xA723: return 0xA722;
		case 0xA725: return 0xA724;
		case 0xA727: return 0xA726;
		case 0xA729: return 0xA728;
		case 0xA72B: return 0xA72A;
		case 0xA72D: return 0xA72C;
		case 0xA72F: return 0xA72E;
		case 0xA733: return 0xA732;
		case 0xA735: return 0xA734;
		case 0xA737: return 0xA736;
		case 0xA739: return 0xA738;
		case 0xA73B: return 0xA73A;
		case 0xA73D: return 0xA73C;
		case 0xA73F: return 0xA73E;
		case 0xA741: return 0xA740;
		case 0xA743: return 0xA742;
		case 0xA745: return 0xA744;
		case 0xA747: return 0xA746;
		case 0xA749: return 0xA748;
		case 0xA74B: return 0xA74A;
		case 0xA74D: return 0xA74C;
		case 0xA74F: return 0xA74E;
		case 0xA751: return 0xA750;
		case 0xA753: return 0xA752;
		case 0xA755: return 0xA754;
		case 0xA757: return 0xA756;
		case 0xA759: return 0xA758;
		case 0xA75B: return 0xA75A;
		case 0xA75D: return 0xA75C;
		case 0xA75F: return 0xA75E;
		case 0xA761: return 0xA760;
		case 0xA763: return 0xA762;
		case 0xA765: return 0xA764;
		case 0xA767: return 0xA766;
		case 0xA769: return 0xA768;
		case 0xA76B: return 0xA76A;
		case 0xA76D: return 0xA76C;
		case 0xA76F: return 0xA76E;
		case 0xA77A: return 0xA779;
		case 0xA77C: return 0xA77B;
		case 0xA77F: return 0xA77E;
		case 0xA781: return 0xA780;
		case 0xA783: return 0xA782;
		case 0xA785: return 0xA784;
		case 0xA787: return 0xA786;
		case 0xA78C: return 0xA78B;
		case 0xA791: return 0xA790;
		case 0xA7A1: return 0xA7A0;
		case 0xA7A3: return 0xA7A2;
		case 0xA7A5: return 0xA7A4;
		case 0xA7A7: return 0xA7A6;
		case 0xA7A9: return 0xA7A8;
		case 0xFF41: return 0xFF21;
		case 0xFF42: return 0xFF22;
		case 0xFF43: return 0xFF23;
		case 0xFF44: return 0xFF24;
		case 0xFF45: return 0xFF25;
		case 0xFF46: return 0xFF26;
		case 0xFF47: return 0xFF27;
		case 0xFF48: return 0xFF28;
		case 0xFF49: return 0xFF29;
		case 0xFF4A: return 0xFF2A;
		case 0xFF4B: return 0xFF2B;
		case 0xFF4C: return 0xFF2C;
		case 0xFF4D: return 0xFF2D;
		case 0xFF4E: return 0xFF2E;
		case 0xFF4F: return 0xFF2F;
		case 0xFF50: return 0xFF30;
		case 0xFF51: return 0xFF31;
		case 0xFF52: return 0xFF32;
		case 0xFF53: return 0xFF33;
		case 0xFF54: return 0xFF34;
		case 0xFF55: return 0xFF35;
		case 0xFF56: return 0xFF36;
		case 0xFF57: return 0xFF37;
		case 0xFF58: return 0xFF38;
		case 0xFF59: return 0xFF39;
		case 0xFF5A: return 0xFF3A;
		case 0x10428: return 0x10400;
		case 0x10429: return 0x10401;
		case 0x1042A: return 0x10402;
		case 0x1042B: return 0x10403;
		case 0x1042C: return 0x10404;
		case 0x1042D: return 0x10405;
		case 0x1042E: return 0x10406;
		case 0x1042F: return 0x10407;
		case 0x10430: return 0x10408;
		case 0x10431: return 0x10409;
		case 0x10432: return 0x1040A;
		case 0x10433: return 0x1040B;
		case 0x10434: return 0x1040C;
		case 0x10435: return 0x1040D;
		case 0x10436: return 0x1040E;
		case 0x10437: return 0x1040F;
		case 0x10438: return 0x10410;
		case 0x10439: return 0x10411;
		case 0x1043A: return 0x10412;
		case 0x1043B: return 0x10413;
		case 0x1043C: return 0x10414;
		case 0x1043D: return 0x10415;
		case 0x1043E: return 0x10416;
		case 0x1043F: return 0x10417;
		case 0x10440: return 0x10418;
		case 0x10441: return 0x10419;
		case 0x10442: return 0x1041A;
		case 0x10443: return 0x1041B;
		case 0x10444: return 0x1041C;
		case 0x10445: return 0x1041D;
		case 0x10446: return 0x1041E;
		case 0x10447: return 0x1041F;
		case 0x10448: return 0x10420;
		case 0x10449: return 0x10421;
		case 0x1044A: return 0x10422;
		case 0x1044B: return 0x10423;
		case 0x1044C: return 0x10424;
		case 0x1044D: return 0x10425;
		case 0x1044E: return 0x10426;
		case 0x1044F: return 0x10427;
		default: return ch;
	}
}

Uchar u8_tolower(Uchar ch)
{
	switch(ch)
	{
		case 0x0041: return 0x0061;
		case 0x0042: return 0x0062;
		case 0x0043: return 0x0063;
		case 0x0044: return 0x0064;
		case 0x0045: return 0x0065;
		case 0x0046: return 0x0066;
		case 0x0047: return 0x0067;
		case 0x0048: return 0x0068;
		case 0x0049: return 0x0069;
		case 0x004A: return 0x006A;
		case 0x004B: return 0x006B;
		case 0x004C: return 0x006C;
		case 0x004D: return 0x006D;
		case 0x004E: return 0x006E;
		case 0x004F: return 0x006F;
		case 0x0050: return 0x0070;
		case 0x0051: return 0x0071;
		case 0x0052: return 0x0072;
		case 0x0053: return 0x0073;
		case 0x0054: return 0x0074;
		case 0x0055: return 0x0075;
		case 0x0056: return 0x0076;
		case 0x0057: return 0x0077;
		case 0x0058: return 0x0078;
		case 0x0059: return 0x0079;
		case 0x005A: return 0x007A;
		case 0x00C0: return 0x00E0;
		case 0x00C1: return 0x00E1;
		case 0x00C2: return 0x00E2;
		case 0x00C3: return 0x00E3;
		case 0x00C4: return 0x00E4;
		case 0x00C5: return 0x00E5;
		case 0x00C6: return 0x00E6;
		case 0x00C7: return 0x00E7;
		case 0x00C8: return 0x00E8;
		case 0x00C9: return 0x00E9;
		case 0x00CA: return 0x00EA;
		case 0x00CB: return 0x00EB;
		case 0x00CC: return 0x00EC;
		case 0x00CD: return 0x00ED;
		case 0x00CE: return 0x00EE;
		case 0x00CF: return 0x00EF;
		case 0x00D0: return 0x00F0;
		case 0x00D1: return 0x00F1;
		case 0x00D2: return 0x00F2;
		case 0x00D3: return 0x00F3;
		case 0x00D4: return 0x00F4;
		case 0x00D5: return 0x00F5;
		case 0x00D6: return 0x00F6;
		case 0x00D8: return 0x00F8;
		case 0x00D9: return 0x00F9;
		case 0x00DA: return 0x00FA;
		case 0x00DB: return 0x00FB;
		case 0x00DC: return 0x00FC;
		case 0x00DD: return 0x00FD;
		case 0x00DE: return 0x00FE;
		case 0x0100: return 0x0101;
		case 0x0102: return 0x0103;
		case 0x0104: return 0x0105;
		case 0x0106: return 0x0107;
		case 0x0108: return 0x0109;
		case 0x010A: return 0x010B;
		case 0x010C: return 0x010D;
		case 0x010E: return 0x010F;
		case 0x0110: return 0x0111;
		case 0x0112: return 0x0113;
		case 0x0114: return 0x0115;
		case 0x0116: return 0x0117;
		case 0x0118: return 0x0119;
		case 0x011A: return 0x011B;
		case 0x011C: return 0x011D;
		case 0x011E: return 0x011F;
		case 0x0120: return 0x0121;
		case 0x0122: return 0x0123;
		case 0x0124: return 0x0125;
		case 0x0126: return 0x0127;
		case 0x0128: return 0x0129;
		case 0x012A: return 0x012B;
		case 0x012C: return 0x012D;
		case 0x012E: return 0x012F;
		case 0x0130: return 0x0069;
		case 0x0132: return 0x0133;
		case 0x0134: return 0x0135;
		case 0x0136: return 0x0137;
		case 0x0139: return 0x013A;
		case 0x013B: return 0x013C;
		case 0x013D: return 0x013E;
		case 0x013F: return 0x0140;
		case 0x0141: return 0x0142;
		case 0x0143: return 0x0144;
		case 0x0145: return 0x0146;
		case 0x0147: return 0x0148;
		case 0x014A: return 0x014B;
		case 0x014C: return 0x014D;
		case 0x014E: return 0x014F;
		case 0x0150: return 0x0151;
		case 0x0152: return 0x0153;
		case 0x0154: return 0x0155;
		case 0x0156: return 0x0157;
		case 0x0158: return 0x0159;
		case 0x015A: return 0x015B;
		case 0x015C: return 0x015D;
		case 0x015E: return 0x015F;
		case 0x0160: return 0x0161;
		case 0x0162: return 0x0163;
		case 0x0164: return 0x0165;
		case 0x0166: return 0x0167;
		case 0x0168: return 0x0169;
		case 0x016A: return 0x016B;
		case 0x016C: return 0x016D;
		case 0x016E: return 0x016F;
		case 0x0170: return 0x0171;
		case 0x0172: return 0x0173;
		case 0x0174: return 0x0175;
		case 0x0176: return 0x0177;
		case 0x0178: return 0x00FF;
		case 0x0179: return 0x017A;
		case 0x017B: return 0x017C;
		case 0x017D: return 0x017E;
		case 0x0181: return 0x0253;
		case 0x0182: return 0x0183;
		case 0x0184: return 0x0185;
		case 0x0186: return 0x0254;
		case 0x0187: return 0x0188;
		case 0x0189: return 0x0256;
		case 0x018A: return 0x0257;
		case 0x018B: return 0x018C;
		case 0x018E: return 0x01DD;
		case 0x018F: return 0x0259;
		case 0x0190: return 0x025B;
		case 0x0191: return 0x0192;
		case 0x0193: return 0x0260;
		case 0x0194: return 0x0263;
		case 0x0196: return 0x0269;
		case 0x0197: return 0x0268;
		case 0x0198: return 0x0199;
		case 0x019C: return 0x026F;
		case 0x019D: return 0x0272;
		case 0x019F: return 0x0275;
		case 0x01A0: return 0x01A1;
		case 0x01A2: return 0x01A3;
		case 0x01A4: return 0x01A5;
		case 0x01A6: return 0x0280;
		case 0x01A7: return 0x01A8;
		case 0x01A9: return 0x0283;
		case 0x01AC: return 0x01AD;
		case 0x01AE: return 0x0288;
		case 0x01AF: return 0x01B0;
		case 0x01B1: return 0x028A;
		case 0x01B2: return 0x028B;
		case 0x01B3: return 0x01B4;
		case 0x01B5: return 0x01B6;
		case 0x01B7: return 0x0292;
		case 0x01B8: return 0x01B9;
		case 0x01BC: return 0x01BD;
		case 0x01C4: return 0x01C6;
		case 0x01C5: return 0x01C6;
		case 0x01C7: return 0x01C9;
		case 0x01C8: return 0x01C9;
		case 0x01CA: return 0x01CC;
		case 0x01CB: return 0x01CC;
		case 0x01CD: return 0x01CE;
		case 0x01CF: return 0x01D0;
		case 0x01D1: return 0x01D2;
		case 0x01D3: return 0x01D4;
		case 0x01D5: return 0x01D6;
		case 0x01D7: return 0x01D8;
		case 0x01D9: return 0x01DA;
		case 0x01DB: return 0x01DC;
		case 0x01DE: return 0x01DF;
		case 0x01E0: return 0x01E1;
		case 0x01E2: return 0x01E3;
		case 0x01E4: return 0x01E5;
		case 0x01E6: return 0x01E7;
		case 0x01E8: return 0x01E9;
		case 0x01EA: return 0x01EB;
		case 0x01EC: return 0x01ED;
		case 0x01EE: return 0x01EF;
		case 0x01F1: return 0x01F3;
		case 0x01F2: return 0x01F3;
		case 0x01F4: return 0x01F5;
		case 0x01F6: return 0x0195;
		case 0x01F7: return 0x01BF;
		case 0x01F8: return 0x01F9;
		case 0x01FA: return 0x01FB;
		case 0x01FC: return 0x01FD;
		case 0x01FE: return 0x01FF;
		case 0x0200: return 0x0201;
		case 0x0202: return 0x0203;
		case 0x0204: return 0x0205;
		case 0x0206: return 0x0207;
		case 0x0208: return 0x0209;
		case 0x020A: return 0x020B;
		case 0x020C: return 0x020D;
		case 0x020E: return 0x020F;
		case 0x0210: return 0x0211;
		case 0x0212: return 0x0213;
		case 0x0214: return 0x0215;
		case 0x0216: return 0x0217;
		case 0x0218: return 0x0219;
		case 0x021A: return 0x021B;
		case 0x021C: return 0x021D;
		case 0x021E: return 0x021F;
		case 0x0220: return 0x019E;
		case 0x0222: return 0x0223;
		case 0x0224: return 0x0225;
		case 0x0226: return 0x0227;
		case 0x0228: return 0x0229;
		case 0x022A: return 0x022B;
		case 0x022C: return 0x022D;
		case 0x022E: return 0x022F;
		case 0x0230: return 0x0231;
		case 0x0232: return 0x0233;
		case 0x023A: return 0x2C65;
		case 0x023B: return 0x023C;
		case 0x023D: return 0x019A;
		case 0x023E: return 0x2C66;
		case 0x0241: return 0x0242;
		case 0x0243: return 0x0180;
		case 0x0244: return 0x0289;
		case 0x0245: return 0x028C;
		case 0x0246: return 0x0247;
		case 0x0248: return 0x0249;
		case 0x024A: return 0x024B;
		case 0x024C: return 0x024D;
		case 0x024E: return 0x024F;
		case 0x0370: return 0x0371;
		case 0x0372: return 0x0373;
		case 0x0376: return 0x0377;
		case 0x0386: return 0x03AC;
		case 0x0388: return 0x03AD;
		case 0x0389: return 0x03AE;
		case 0x038A: return 0x03AF;
		case 0x038C: return 0x03CC;
		case 0x038E: return 0x03CD;
		case 0x038F: return 0x03CE;
		case 0x0391: return 0x03B1;
		case 0x0392: return 0x03B2;
		case 0x0393: return 0x03B3;
		case 0x0394: return 0x03B4;
		case 0x0395: return 0x03B5;
		case 0x0396: return 0x03B6;
		case 0x0397: return 0x03B7;
		case 0x0398: return 0x03B8;
		case 0x0399: return 0x03B9;
		case 0x039A: return 0x03BA;
		case 0x039B: return 0x03BB;
		case 0x039C: return 0x03BC;
		case 0x039D: return 0x03BD;
		case 0x039E: return 0x03BE;
		case 0x039F: return 0x03BF;
		case 0x03A0: return 0x03C0;
		case 0x03A1: return 0x03C1;
		case 0x03A3: return 0x03C3;
		case 0x03A4: return 0x03C4;
		case 0x03A5: return 0x03C5;
		case 0x03A6: return 0x03C6;
		case 0x03A7: return 0x03C7;
		case 0x03A8: return 0x03C8;
		case 0x03A9: return 0x03C9;
		case 0x03AA: return 0x03CA;
		case 0x03AB: return 0x03CB;
		case 0x03CF: return 0x03D7;
		case 0x03D8: return 0x03D9;
		case 0x03DA: return 0x03DB;
		case 0x03DC: return 0x03DD;
		case 0x03DE: return 0x03DF;
		case 0x03E0: return 0x03E1;
		case 0x03E2: return 0x03E3;
		case 0x03E4: return 0x03E5;
		case 0x03E6: return 0x03E7;
		case 0x03E8: return 0x03E9;
		case 0x03EA: return 0x03EB;
		case 0x03EC: return 0x03ED;
		case 0x03EE: return 0x03EF;
		case 0x03F4: return 0x03B8;
		case 0x03F7: return 0x03F8;
		case 0x03F9: return 0x03F2;
		case 0x03FA: return 0x03FB;
		case 0x03FD: return 0x037B;
		case 0x03FE: return 0x037C;
		case 0x03FF: return 0x037D;
		case 0x0400: return 0x0450;
		case 0x0401: return 0x0451;
		case 0x0402: return 0x0452;
		case 0x0403: return 0x0453;
		case 0x0404: return 0x0454;
		case 0x0405: return 0x0455;
		case 0x0406: return 0x0456;
		case 0x0407: return 0x0457;
		case 0x0408: return 0x0458;
		case 0x0409: return 0x0459;
		case 0x040A: return 0x045A;
		case 0x040B: return 0x045B;
		case 0x040C: return 0x045C;
		case 0x040D: return 0x045D;
		case 0x040E: return 0x045E;
		case 0x040F: return 0x045F;
		case 0x0410: return 0x0430;
		case 0x0411: return 0x0431;
		case 0x0412: return 0x0432;
		case 0x0413: return 0x0433;
		case 0x0414: return 0x0434;
		case 0x0415: return 0x0435;
		case 0x0416: return 0x0436;
		case 0x0417: return 0x0437;
		case 0x0418: return 0x0438;
		case 0x0419: return 0x0439;
		case 0x041A: return 0x043A;
		case 0x041B: return 0x043B;
		case 0x041C: return 0x043C;
		case 0x041D: return 0x043D;
		case 0x041E: return 0x043E;
		case 0x041F: return 0x043F;
		case 0x0420: return 0x0440;
		case 0x0421: return 0x0441;
		case 0x0422: return 0x0442;
		case 0x0423: return 0x0443;
		case 0x0424: return 0x0444;
		case 0x0425: return 0x0445;
		case 0x0426: return 0x0446;
		case 0x0427: return 0x0447;
		case 0x0428: return 0x0448;
		case 0x0429: return 0x0449;
		case 0x042A: return 0x044A;
		case 0x042B: return 0x044B;
		case 0x042C: return 0x044C;
		case 0x042D: return 0x044D;
		case 0x042E: return 0x044E;
		case 0x042F: return 0x044F;
		case 0x0460: return 0x0461;
		case 0x0462: return 0x0463;
		case 0x0464: return 0x0465;
		case 0x0466: return 0x0467;
		case 0x0468: return 0x0469;
		case 0x046A: return 0x046B;
		case 0x046C: return 0x046D;
		case 0x046E: return 0x046F;
		case 0x0470: return 0x0471;
		case 0x0472: return 0x0473;
		case 0x0474: return 0x0475;
		case 0x0476: return 0x0477;
		case 0x0478: return 0x0479;
		case 0x047A: return 0x047B;
		case 0x047C: return 0x047D;
		case 0x047E: return 0x047F;
		case 0x0480: return 0x0481;
		case 0x048A: return 0x048B;
		case 0x048C: return 0x048D;
		case 0x048E: return 0x048F;
		case 0x0490: return 0x0491;
		case 0x0492: return 0x0493;
		case 0x0494: return 0x0495;
		case 0x0496: return 0x0497;
		case 0x0498: return 0x0499;
		case 0x049A: return 0x049B;
		case 0x049C: return 0x049D;
		case 0x049E: return 0x049F;
		case 0x04A0: return 0x04A1;
		case 0x04A2: return 0x04A3;
		case 0x04A4: return 0x04A5;
		case 0x04A6: return 0x04A7;
		case 0x04A8: return 0x04A9;
		case 0x04AA: return 0x04AB;
		case 0x04AC: return 0x04AD;
		case 0x04AE: return 0x04AF;
		case 0x04B0: return 0x04B1;
		case 0x04B2: return 0x04B3;
		case 0x04B4: return 0x04B5;
		case 0x04B6: return 0x04B7;
		case 0x04B8: return 0x04B9;
		case 0x04BA: return 0x04BB;
		case 0x04BC: return 0x04BD;
		case 0x04BE: return 0x04BF;
		case 0x04C0: return 0x04CF;
		case 0x04C1: return 0x04C2;
		case 0x04C3: return 0x04C4;
		case 0x04C5: return 0x04C6;
		case 0x04C7: return 0x04C8;
		case 0x04C9: return 0x04CA;
		case 0x04CB: return 0x04CC;
		case 0x04CD: return 0x04CE;
		case 0x04D0: return 0x04D1;
		case 0x04D2: return 0x04D3;
		case 0x04D4: return 0x04D5;
		case 0x04D6: return 0x04D7;
		case 0x04D8: return 0x04D9;
		case 0x04DA: return 0x04DB;
		case 0x04DC: return 0x04DD;
		case 0x04DE: return 0x04DF;
		case 0x04E0: return 0x04E1;
		case 0x04E2: return 0x04E3;
		case 0x04E4: return 0x04E5;
		case 0x04E6: return 0x04E7;
		case 0x04E8: return 0x04E9;
		case 0x04EA: return 0x04EB;
		case 0x04EC: return 0x04ED;
		case 0x04EE: return 0x04EF;
		case 0x04F0: return 0x04F1;
		case 0x04F2: return 0x04F3;
		case 0x04F4: return 0x04F5;
		case 0x04F6: return 0x04F7;
		case 0x04F8: return 0x04F9;
		case 0x04FA: return 0x04FB;
		case 0x04FC: return 0x04FD;
		case 0x04FE: return 0x04FF;
		case 0x0500: return 0x0501;
		case 0x0502: return 0x0503;
		case 0x0504: return 0x0505;
		case 0x0506: return 0x0507;
		case 0x0508: return 0x0509;
		case 0x050A: return 0x050B;
		case 0x050C: return 0x050D;
		case 0x050E: return 0x050F;
		case 0x0510: return 0x0511;
		case 0x0512: return 0x0513;
		case 0x0514: return 0x0515;
		case 0x0516: return 0x0517;
		case 0x0518: return 0x0519;
		case 0x051A: return 0x051B;
		case 0x051C: return 0x051D;
		case 0x051E: return 0x051F;
		case 0x0520: return 0x0521;
		case 0x0522: return 0x0523;
		case 0x0524: return 0x0525;
		case 0x0526: return 0x0527;
		case 0x0531: return 0x0561;
		case 0x0532: return 0x0562;
		case 0x0533: return 0x0563;
		case 0x0534: return 0x0564;
		case 0x0535: return 0x0565;
		case 0x0536: return 0x0566;
		case 0x0537: return 0x0567;
		case 0x0538: return 0x0568;
		case 0x0539: return 0x0569;
		case 0x053A: return 0x056A;
		case 0x053B: return 0x056B;
		case 0x053C: return 0x056C;
		case 0x053D: return 0x056D;
		case 0x053E: return 0x056E;
		case 0x053F: return 0x056F;
		case 0x0540: return 0x0570;
		case 0x0541: return 0x0571;
		case 0x0542: return 0x0572;
		case 0x0543: return 0x0573;
		case 0x0544: return 0x0574;
		case 0x0545: return 0x0575;
		case 0x0546: return 0x0576;
		case 0x0547: return 0x0577;
		case 0x0548: return 0x0578;
		case 0x0549: return 0x0579;
		case 0x054A: return 0x057A;
		case 0x054B: return 0x057B;
		case 0x054C: return 0x057C;
		case 0x054D: return 0x057D;
		case 0x054E: return 0x057E;
		case 0x054F: return 0x057F;
		case 0x0550: return 0x0580;
		case 0x0551: return 0x0581;
		case 0x0552: return 0x0582;
		case 0x0553: return 0x0583;
		case 0x0554: return 0x0584;
		case 0x0555: return 0x0585;
		case 0x0556: return 0x0586;
		case 0x10A0: return 0x2D00;
		case 0x10A1: return 0x2D01;
		case 0x10A2: return 0x2D02;
		case 0x10A3: return 0x2D03;
		case 0x10A4: return 0x2D04;
		case 0x10A5: return 0x2D05;
		case 0x10A6: return 0x2D06;
		case 0x10A7: return 0x2D07;
		case 0x10A8: return 0x2D08;
		case 0x10A9: return 0x2D09;
		case 0x10AA: return 0x2D0A;
		case 0x10AB: return 0x2D0B;
		case 0x10AC: return 0x2D0C;
		case 0x10AD: return 0x2D0D;
		case 0x10AE: return 0x2D0E;
		case 0x10AF: return 0x2D0F;
		case 0x10B0: return 0x2D10;
		case 0x10B1: return 0x2D11;
		case 0x10B2: return 0x2D12;
		case 0x10B3: return 0x2D13;
		case 0x10B4: return 0x2D14;
		case 0x10B5: return 0x2D15;
		case 0x10B6: return 0x2D16;
		case 0x10B7: return 0x2D17;
		case 0x10B8: return 0x2D18;
		case 0x10B9: return 0x2D19;
		case 0x10BA: return 0x2D1A;
		case 0x10BB: return 0x2D1B;
		case 0x10BC: return 0x2D1C;
		case 0x10BD: return 0x2D1D;
		case 0x10BE: return 0x2D1E;
		case 0x10BF: return 0x2D1F;
		case 0x10C0: return 0x2D20;
		case 0x10C1: return 0x2D21;
		case 0x10C2: return 0x2D22;
		case 0x10C3: return 0x2D23;
		case 0x10C4: return 0x2D24;
		case 0x10C5: return 0x2D25;
		case 0x1E00: return 0x1E01;
		case 0x1E02: return 0x1E03;
		case 0x1E04: return 0x1E05;
		case 0x1E06: return 0x1E07;
		case 0x1E08: return 0x1E09;
		case 0x1E0A: return 0x1E0B;
		case 0x1E0C: return 0x1E0D;
		case 0x1E0E: return 0x1E0F;
		case 0x1E10: return 0x1E11;
		case 0x1E12: return 0x1E13;
		case 0x1E14: return 0x1E15;
		case 0x1E16: return 0x1E17;
		case 0x1E18: return 0x1E19;
		case 0x1E1A: return 0x1E1B;
		case 0x1E1C: return 0x1E1D;
		case 0x1E1E: return 0x1E1F;
		case 0x1E20: return 0x1E21;
		case 0x1E22: return 0x1E23;
		case 0x1E24: return 0x1E25;
		case 0x1E26: return 0x1E27;
		case 0x1E28: return 0x1E29;
		case 0x1E2A: return 0x1E2B;
		case 0x1E2C: return 0x1E2D;
		case 0x1E2E: return 0x1E2F;
		case 0x1E30: return 0x1E31;
		case 0x1E32: return 0x1E33;
		case 0x1E34: return 0x1E35;
		case 0x1E36: return 0x1E37;
		case 0x1E38: return 0x1E39;
		case 0x1E3A: return 0x1E3B;
		case 0x1E3C: return 0x1E3D;
		case 0x1E3E: return 0x1E3F;
		case 0x1E40: return 0x1E41;
		case 0x1E42: return 0x1E43;
		case 0x1E44: return 0x1E45;
		case 0x1E46: return 0x1E47;
		case 0x1E48: return 0x1E49;
		case 0x1E4A: return 0x1E4B;
		case 0x1E4C: return 0x1E4D;
		case 0x1E4E: return 0x1E4F;
		case 0x1E50: return 0x1E51;
		case 0x1E52: return 0x1E53;
		case 0x1E54: return 0x1E55;
		case 0x1E56: return 0x1E57;
		case 0x1E58: return 0x1E59;
		case 0x1E5A: return 0x1E5B;
		case 0x1E5C: return 0x1E5D;
		case 0x1E5E: return 0x1E5F;
		case 0x1E60: return 0x1E61;
		case 0x1E62: return 0x1E63;
		case 0x1E64: return 0x1E65;
		case 0x1E66: return 0x1E67;
		case 0x1E68: return 0x1E69;
		case 0x1E6A: return 0x1E6B;
		case 0x1E6C: return 0x1E6D;
		case 0x1E6E: return 0x1E6F;
		case 0x1E70: return 0x1E71;
		case 0x1E72: return 0x1E73;
		case 0x1E74: return 0x1E75;
		case 0x1E76: return 0x1E77;
		case 0x1E78: return 0x1E79;
		case 0x1E7A: return 0x1E7B;
		case 0x1E7C: return 0x1E7D;
		case 0x1E7E: return 0x1E7F;
		case 0x1E80: return 0x1E81;
		case 0x1E82: return 0x1E83;
		case 0x1E84: return 0x1E85;
		case 0x1E86: return 0x1E87;
		case 0x1E88: return 0x1E89;
		case 0x1E8A: return 0x1E8B;
		case 0x1E8C: return 0x1E8D;
		case 0x1E8E: return 0x1E8F;
		case 0x1E90: return 0x1E91;
		case 0x1E92: return 0x1E93;
		case 0x1E94: return 0x1E95;
		case 0x1E9E: return 0x00DF;
		case 0x1EA0: return 0x1EA1;
		case 0x1EA2: return 0x1EA3;
		case 0x1EA4: return 0x1EA5;
		case 0x1EA6: return 0x1EA7;
		case 0x1EA8: return 0x1EA9;
		case 0x1EAA: return 0x1EAB;
		case 0x1EAC: return 0x1EAD;
		case 0x1EAE: return 0x1EAF;
		case 0x1EB0: return 0x1EB1;
		case 0x1EB2: return 0x1EB3;
		case 0x1EB4: return 0x1EB5;
		case 0x1EB6: return 0x1EB7;
		case 0x1EB8: return 0x1EB9;
		case 0x1EBA: return 0x1EBB;
		case 0x1EBC: return 0x1EBD;
		case 0x1EBE: return 0x1EBF;
		case 0x1EC0: return 0x1EC1;
		case 0x1EC2: return 0x1EC3;
		case 0x1EC4: return 0x1EC5;
		case 0x1EC6: return 0x1EC7;
		case 0x1EC8: return 0x1EC9;
		case 0x1ECA: return 0x1ECB;
		case 0x1ECC: return 0x1ECD;
		case 0x1ECE: return 0x1ECF;
		case 0x1ED0: return 0x1ED1;
		case 0x1ED2: return 0x1ED3;
		case 0x1ED4: return 0x1ED5;
		case 0x1ED6: return 0x1ED7;
		case 0x1ED8: return 0x1ED9;
		case 0x1EDA: return 0x1EDB;
		case 0x1EDC: return 0x1EDD;
		case 0x1EDE: return 0x1EDF;
		case 0x1EE0: return 0x1EE1;
		case 0x1EE2: return 0x1EE3;
		case 0x1EE4: return 0x1EE5;
		case 0x1EE6: return 0x1EE7;
		case 0x1EE8: return 0x1EE9;
		case 0x1EEA: return 0x1EEB;
		case 0x1EEC: return 0x1EED;
		case 0x1EEE: return 0x1EEF;
		case 0x1EF0: return 0x1EF1;
		case 0x1EF2: return 0x1EF3;
		case 0x1EF4: return 0x1EF5;
		case 0x1EF6: return 0x1EF7;
		case 0x1EF8: return 0x1EF9;
		case 0x1EFA: return 0x1EFB;
		case 0x1EFC: return 0x1EFD;
		case 0x1EFE: return 0x1EFF;
		case 0x1F08: return 0x1F00;
		case 0x1F09: return 0x1F01;
		case 0x1F0A: return 0x1F02;
		case 0x1F0B: return 0x1F03;
		case 0x1F0C: return 0x1F04;
		case 0x1F0D: return 0x1F05;
		case 0x1F0E: return 0x1F06;
		case 0x1F0F: return 0x1F07;
		case 0x1F18: return 0x1F10;
		case 0x1F19: return 0x1F11;
		case 0x1F1A: return 0x1F12;
		case 0x1F1B: return 0x1F13;
		case 0x1F1C: return 0x1F14;
		case 0x1F1D: return 0x1F15;
		case 0x1F28: return 0x1F20;
		case 0x1F29: return 0x1F21;
		case 0x1F2A: return 0x1F22;
		case 0x1F2B: return 0x1F23;
		case 0x1F2C: return 0x1F24;
		case 0x1F2D: return 0x1F25;
		case 0x1F2E: return 0x1F26;
		case 0x1F2F: return 0x1F27;
		case 0x1F38: return 0x1F30;
		case 0x1F39: return 0x1F31;
		case 0x1F3A: return 0x1F32;
		case 0x1F3B: return 0x1F33;
		case 0x1F3C: return 0x1F34;
		case 0x1F3D: return 0x1F35;
		case 0x1F3E: return 0x1F36;
		case 0x1F3F: return 0x1F37;
		case 0x1F48: return 0x1F40;
		case 0x1F49: return 0x1F41;
		case 0x1F4A: return 0x1F42;
		case 0x1F4B: return 0x1F43;
		case 0x1F4C: return 0x1F44;
		case 0x1F4D: return 0x1F45;
		case 0x1F59: return 0x1F51;
		case 0x1F5B: return 0x1F53;
		case 0x1F5D: return 0x1F55;
		case 0x1F5F: return 0x1F57;
		case 0x1F68: return 0x1F60;
		case 0x1F69: return 0x1F61;
		case 0x1F6A: return 0x1F62;
		case 0x1F6B: return 0x1F63;
		case 0x1F6C: return 0x1F64;
		case 0x1F6D: return 0x1F65;
		case 0x1F6E: return 0x1F66;
		case 0x1F6F: return 0x1F67;
		case 0x1F88: return 0x1F80;
		case 0x1F89: return 0x1F81;
		case 0x1F8A: return 0x1F82;
		case 0x1F8B: return 0x1F83;
		case 0x1F8C: return 0x1F84;
		case 0x1F8D: return 0x1F85;
		case 0x1F8E: return 0x1F86;
		case 0x1F8F: return 0x1F87;
		case 0x1F98: return 0x1F90;
		case 0x1F99: return 0x1F91;
		case 0x1F9A: return 0x1F92;
		case 0x1F9B: return 0x1F93;
		case 0x1F9C: return 0x1F94;
		case 0x1F9D: return 0x1F95;
		case 0x1F9E: return 0x1F96;
		case 0x1F9F: return 0x1F97;
		case 0x1FA8: return 0x1FA0;
		case 0x1FA9: return 0x1FA1;
		case 0x1FAA: return 0x1FA2;
		case 0x1FAB: return 0x1FA3;
		case 0x1FAC: return 0x1FA4;
		case 0x1FAD: return 0x1FA5;
		case 0x1FAE: return 0x1FA6;
		case 0x1FAF: return 0x1FA7;
		case 0x1FB8: return 0x1FB0;
		case 0x1FB9: return 0x1FB1;
		case 0x1FBA: return 0x1F70;
		case 0x1FBB: return 0x1F71;
		case 0x1FBC: return 0x1FB3;
		case 0x1FC8: return 0x1F72;
		case 0x1FC9: return 0x1F73;
		case 0x1FCA: return 0x1F74;
		case 0x1FCB: return 0x1F75;
		case 0x1FCC: return 0x1FC3;
		case 0x1FD8: return 0x1FD0;
		case 0x1FD9: return 0x1FD1;
		case 0x1FDA: return 0x1F76;
		case 0x1FDB: return 0x1F77;
		case 0x1FE8: return 0x1FE0;
		case 0x1FE9: return 0x1FE1;
		case 0x1FEA: return 0x1F7A;
		case 0x1FEB: return 0x1F7B;
		case 0x1FEC: return 0x1FE5;
		case 0x1FF8: return 0x1F78;
		case 0x1FF9: return 0x1F79;
		case 0x1FFA: return 0x1F7C;
		case 0x1FFB: return 0x1F7D;
		case 0x1FFC: return 0x1FF3;
		case 0x2126: return 0x03C9;
		case 0x212A: return 0x006B;
		case 0x212B: return 0x00E5;
		case 0x2132: return 0x214E;
		case 0x2160: return 0x2170;
		case 0x2161: return 0x2171;
		case 0x2162: return 0x2172;
		case 0x2163: return 0x2173;
		case 0x2164: return 0x2174;
		case 0x2165: return 0x2175;
		case 0x2166: return 0x2176;
		case 0x2167: return 0x2177;
		case 0x2168: return 0x2178;
		case 0x2169: return 0x2179;
		case 0x216A: return 0x217A;
		case 0x216B: return 0x217B;
		case 0x216C: return 0x217C;
		case 0x216D: return 0x217D;
		case 0x216E: return 0x217E;
		case 0x216F: return 0x217F;
		case 0x2183: return 0x2184;
		case 0x24B6: return 0x24D0;
		case 0x24B7: return 0x24D1;
		case 0x24B8: return 0x24D2;
		case 0x24B9: return 0x24D3;
		case 0x24BA: return 0x24D4;
		case 0x24BB: return 0x24D5;
		case 0x24BC: return 0x24D6;
		case 0x24BD: return 0x24D7;
		case 0x24BE: return 0x24D8;
		case 0x24BF: return 0x24D9;
		case 0x24C0: return 0x24DA;
		case 0x24C1: return 0x24DB;
		case 0x24C2: return 0x24DC;
		case 0x24C3: return 0x24DD;
		case 0x24C4: return 0x24DE;
		case 0x24C5: return 0x24DF;
		case 0x24C6: return 0x24E0;
		case 0x24C7: return 0x24E1;
		case 0x24C8: return 0x24E2;
		case 0x24C9: return 0x24E3;
		case 0x24CA: return 0x24E4;
		case 0x24CB: return 0x24E5;
		case 0x24CC: return 0x24E6;
		case 0x24CD: return 0x24E7;
		case 0x24CE: return 0x24E8;
		case 0x24CF: return 0x24E9;
		case 0x2C00: return 0x2C30;
		case 0x2C01: return 0x2C31;
		case 0x2C02: return 0x2C32;
		case 0x2C03: return 0x2C33;
		case 0x2C04: return 0x2C34;
		case 0x2C05: return 0x2C35;
		case 0x2C06: return 0x2C36;
		case 0x2C07: return 0x2C37;
		case 0x2C08: return 0x2C38;
		case 0x2C09: return 0x2C39;
		case 0x2C0A: return 0x2C3A;
		case 0x2C0B: return 0x2C3B;
		case 0x2C0C: return 0x2C3C;
		case 0x2C0D: return 0x2C3D;
		case 0x2C0E: return 0x2C3E;
		case 0x2C0F: return 0x2C3F;
		case 0x2C10: return 0x2C40;
		case 0x2C11: return 0x2C41;
		case 0x2C12: return 0x2C42;
		case 0x2C13: return 0x2C43;
		case 0x2C14: return 0x2C44;
		case 0x2C15: return 0x2C45;
		case 0x2C16: return 0x2C46;
		case 0x2C17: return 0x2C47;
		case 0x2C18: return 0x2C48;
		case 0x2C19: return 0x2C49;
		case 0x2C1A: return 0x2C4A;
		case 0x2C1B: return 0x2C4B;
		case 0x2C1C: return 0x2C4C;
		case 0x2C1D: return 0x2C4D;
		case 0x2C1E: return 0x2C4E;
		case 0x2C1F: return 0x2C4F;
		case 0x2C20: return 0x2C50;
		case 0x2C21: return 0x2C51;
		case 0x2C22: return 0x2C52;
		case 0x2C23: return 0x2C53;
		case 0x2C24: return 0x2C54;
		case 0x2C25: return 0x2C55;
		case 0x2C26: return 0x2C56;
		case 0x2C27: return 0x2C57;
		case 0x2C28: return 0x2C58;
		case 0x2C29: return 0x2C59;
		case 0x2C2A: return 0x2C5A;
		case 0x2C2B: return 0x2C5B;
		case 0x2C2C: return 0x2C5C;
		case 0x2C2D: return 0x2C5D;
		case 0x2C2E: return 0x2C5E;
		case 0x2C60: return 0x2C61;
		case 0x2C62: return 0x026B;
		case 0x2C63: return 0x1D7D;
		case 0x2C64: return 0x027D;
		case 0x2C67: return 0x2C68;
		case 0x2C69: return 0x2C6A;
		case 0x2C6B: return 0x2C6C;
		case 0x2C6D: return 0x0251;
		case 0x2C6E: return 0x0271;
		case 0x2C6F: return 0x0250;
		case 0x2C70: return 0x0252;
		case 0x2C72: return 0x2C73;
		case 0x2C75: return 0x2C76;
		case 0x2C7E: return 0x023F;
		case 0x2C7F: return 0x0240;
		case 0x2C80: return 0x2C81;
		case 0x2C82: return 0x2C83;
		case 0x2C84: return 0x2C85;
		case 0x2C86: return 0x2C87;
		case 0x2C88: return 0x2C89;
		case 0x2C8A: return 0x2C8B;
		case 0x2C8C: return 0x2C8D;
		case 0x2C8E: return 0x2C8F;
		case 0x2C90: return 0x2C91;
		case 0x2C92: return 0x2C93;
		case 0x2C94: return 0x2C95;
		case 0x2C96: return 0x2C97;
		case 0x2C98: return 0x2C99;
		case 0x2C9A: return 0x2C9B;
		case 0x2C9C: return 0x2C9D;
		case 0x2C9E: return 0x2C9F;
		case 0x2CA0: return 0x2CA1;
		case 0x2CA2: return 0x2CA3;
		case 0x2CA4: return 0x2CA5;
		case 0x2CA6: return 0x2CA7;
		case 0x2CA8: return 0x2CA9;
		case 0x2CAA: return 0x2CAB;
		case 0x2CAC: return 0x2CAD;
		case 0x2CAE: return 0x2CAF;
		case 0x2CB0: return 0x2CB1;
		case 0x2CB2: return 0x2CB3;
		case 0x2CB4: return 0x2CB5;
		case 0x2CB6: return 0x2CB7;
		case 0x2CB8: return 0x2CB9;
		case 0x2CBA: return 0x2CBB;
		case 0x2CBC: return 0x2CBD;
		case 0x2CBE: return 0x2CBF;
		case 0x2CC0: return 0x2CC1;
		case 0x2CC2: return 0x2CC3;
		case 0x2CC4: return 0x2CC5;
		case 0x2CC6: return 0x2CC7;
		case 0x2CC8: return 0x2CC9;
		case 0x2CCA: return 0x2CCB;
		case 0x2CCC: return 0x2CCD;
		case 0x2CCE: return 0x2CCF;
		case 0x2CD0: return 0x2CD1;
		case 0x2CD2: return 0x2CD3;
		case 0x2CD4: return 0x2CD5;
		case 0x2CD6: return 0x2CD7;
		case 0x2CD8: return 0x2CD9;
		case 0x2CDA: return 0x2CDB;
		case 0x2CDC: return 0x2CDD;
		case 0x2CDE: return 0x2CDF;
		case 0x2CE0: return 0x2CE1;
		case 0x2CE2: return 0x2CE3;
		case 0x2CEB: return 0x2CEC;
		case 0x2CED: return 0x2CEE;
		case 0xA640: return 0xA641;
		case 0xA642: return 0xA643;
		case 0xA644: return 0xA645;
		case 0xA646: return 0xA647;
		case 0xA648: return 0xA649;
		case 0xA64A: return 0xA64B;
		case 0xA64C: return 0xA64D;
		case 0xA64E: return 0xA64F;
		case 0xA650: return 0xA651;
		case 0xA652: return 0xA653;
		case 0xA654: return 0xA655;
		case 0xA656: return 0xA657;
		case 0xA658: return 0xA659;
		case 0xA65A: return 0xA65B;
		case 0xA65C: return 0xA65D;
		case 0xA65E: return 0xA65F;
		case 0xA660: return 0xA661;
		case 0xA662: return 0xA663;
		case 0xA664: return 0xA665;
		case 0xA666: return 0xA667;
		case 0xA668: return 0xA669;
		case 0xA66A: return 0xA66B;
		case 0xA66C: return 0xA66D;
		case 0xA680: return 0xA681;
		case 0xA682: return 0xA683;
		case 0xA684: return 0xA685;
		case 0xA686: return 0xA687;
		case 0xA688: return 0xA689;
		case 0xA68A: return 0xA68B;
		case 0xA68C: return 0xA68D;
		case 0xA68E: return 0xA68F;
		case 0xA690: return 0xA691;
		case 0xA692: return 0xA693;
		case 0xA694: return 0xA695;
		case 0xA696: return 0xA697;
		case 0xA722: return 0xA723;
		case 0xA724: return 0xA725;
		case 0xA726: return 0xA727;
		case 0xA728: return 0xA729;
		case 0xA72A: return 0xA72B;
		case 0xA72C: return 0xA72D;
		case 0xA72E: return 0xA72F;
		case 0xA732: return 0xA733;
		case 0xA734: return 0xA735;
		case 0xA736: return 0xA737;
		case 0xA738: return 0xA739;
		case 0xA73A: return 0xA73B;
		case 0xA73C: return 0xA73D;
		case 0xA73E: return 0xA73F;
		case 0xA740: return 0xA741;
		case 0xA742: return 0xA743;
		case 0xA744: return 0xA745;
		case 0xA746: return 0xA747;
		case 0xA748: return 0xA749;
		case 0xA74A: return 0xA74B;
		case 0xA74C: return 0xA74D;
		case 0xA74E: return 0xA74F;
		case 0xA750: return 0xA751;
		case 0xA752: return 0xA753;
		case 0xA754: return 0xA755;
		case 0xA756: return 0xA757;
		case 0xA758: return 0xA759;
		case 0xA75A: return 0xA75B;
		case 0xA75C: return 0xA75D;
		case 0xA75E: return 0xA75F;
		case 0xA760: return 0xA761;
		case 0xA762: return 0xA763;
		case 0xA764: return 0xA765;
		case 0xA766: return 0xA767;
		case 0xA768: return 0xA769;
		case 0xA76A: return 0xA76B;
		case 0xA76C: return 0xA76D;
		case 0xA76E: return 0xA76F;
		case 0xA779: return 0xA77A;
		case 0xA77B: return 0xA77C;
		case 0xA77D: return 0x1D79;
		case 0xA77E: return 0xA77F;
		case 0xA780: return 0xA781;
		case 0xA782: return 0xA783;
		case 0xA784: return 0xA785;
		case 0xA786: return 0xA787;
		case 0xA78B: return 0xA78C;
		case 0xA78D: return 0x0265;
		case 0xA790: return 0xA791;
		case 0xA7A0: return 0xA7A1;
		case 0xA7A2: return 0xA7A3;
		case 0xA7A4: return 0xA7A5;
		case 0xA7A6: return 0xA7A7;
		case 0xA7A8: return 0xA7A9;
		case 0xFF21: return 0xFF41;
		case 0xFF22: return 0xFF42;
		case 0xFF23: return 0xFF43;
		case 0xFF24: return 0xFF44;
		case 0xFF25: return 0xFF45;
		case 0xFF26: return 0xFF46;
		case 0xFF27: return 0xFF47;
		case 0xFF28: return 0xFF48;
		case 0xFF29: return 0xFF49;
		case 0xFF2A: return 0xFF4A;
		case 0xFF2B: return 0xFF4B;
		case 0xFF2C: return 0xFF4C;
		case 0xFF2D: return 0xFF4D;
		case 0xFF2E: return 0xFF4E;
		case 0xFF2F: return 0xFF4F;
		case 0xFF30: return 0xFF50;
		case 0xFF31: return 0xFF51;
		case 0xFF32: return 0xFF52;
		case 0xFF33: return 0xFF53;
		case 0xFF34: return 0xFF54;
		case 0xFF35: return 0xFF55;
		case 0xFF36: return 0xFF56;
		case 0xFF37: return 0xFF57;
		case 0xFF38: return 0xFF58;
		case 0xFF39: return 0xFF59;
		case 0xFF3A: return 0xFF5A;
		case 0x10400: return 0x10428;
		case 0x10401: return 0x10429;
		case 0x10402: return 0x1042A;
		case 0x10403: return 0x1042B;
		case 0x10404: return 0x1042C;
		case 0x10405: return 0x1042D;
		case 0x10406: return 0x1042E;
		case 0x10407: return 0x1042F;
		case 0x10408: return 0x10430;
		case 0x10409: return 0x10431;
		case 0x1040A: return 0x10432;
		case 0x1040B: return 0x10433;
		case 0x1040C: return 0x10434;
		case 0x1040D: return 0x10435;
		case 0x1040E: return 0x10436;
		case 0x1040F: return 0x10437;
		case 0x10410: return 0x10438;
		case 0x10411: return 0x10439;
		case 0x10412: return 0x1043A;
		case 0x10413: return 0x1043B;
		case 0x10414: return 0x1043C;
		case 0x10415: return 0x1043D;
		case 0x10416: return 0x1043E;
		case 0x10417: return 0x1043F;
		case 0x10418: return 0x10440;
		case 0x10419: return 0x10441;
		case 0x1041A: return 0x10442;
		case 0x1041B: return 0x10443;
		case 0x1041C: return 0x10444;
		case 0x1041D: return 0x10445;
		case 0x1041E: return 0x10446;
		case 0x1041F: return 0x10447;
		case 0x10420: return 0x10448;
		case 0x10421: return 0x10449;
		case 0x10422: return 0x1044A;
		case 0x10423: return 0x1044B;
		case 0x10424: return 0x1044C;
		case 0x10425: return 0x1044D;
		case 0x10426: return 0x1044E;
		case 0x10427: return 0x1044F;
		default: return ch;
	}
}