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
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
|
/*
**********************************************************************
* Copyright (C) 1998-2007, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
*
* File unistr.h
*
* Modification History:
*
* Date Name Description
* 09/25/98 stephen Creation.
* 11/11/98 stephen Changed per 11/9 code review.
* 04/20/99 stephen Overhauled per 4/16 code review.
* 11/18/99 aliu Made to inherit from Replaceable. Added method
* handleReplaceBetween(); other methods unchanged.
* 06/25/01 grhoten Remove dependency on iostream.
******************************************************************************
*/
#ifndef UNISTR_H
#define UNISTR_H
/**
* \file
* \brief C++ API: Unicode String
*/
#include "unicode/rep.h"
struct UConverter; // unicode/ucnv.h
class StringThreadTest;
#ifndef U_COMPARE_CODE_POINT_ORDER
/* see also ustring.h and unorm.h */
/**
* Option bit for u_strCaseCompare, u_strcasecmp, unorm_compare, etc:
* Compare strings in code point order instead of code unit order.
* @stable ICU 2.2
*/
#define U_COMPARE_CODE_POINT_ORDER 0x8000
#endif
#ifndef USTRING_H
/**
* \ingroup ustring_ustrlen
*/
U_STABLE int32_t U_EXPORT2
u_strlen(const UChar *s);
#endif
U_NAMESPACE_BEGIN
class Locale; // unicode/locid.h
class StringCharacterIterator;
class BreakIterator; // unicode/brkiter.h
/* The <iostream> include has been moved to unicode/ustream.h */
/**
* Constant to be used in the UnicodeString(char *, int32_t, EInvariant) constructor
* which constructs a Unicode string from an invariant-character char * string.
* About invariant characters see utypes.h.
* This constructor has no runtime dependency on conversion code and is
* therefore recommended over ones taking a charset name string
* (where the empty string "" indicates invariant-character conversion).
*
* @stable ICU 3.2
*/
#define US_INV U_NAMESPACE_QUALIFIER UnicodeString::kInvariant
/**
* Unicode String literals in C++.
* Dependent on the platform properties, different UnicodeString
* constructors should be used to create a UnicodeString object from
* a string literal.
* The macros are defined for maximum performance.
* They work only for strings that contain "invariant characters", i.e.,
* only latin letters, digits, and some punctuation.
* See utypes.h for details.
*
* The string parameter must be a C string literal.
* The length of the string, not including the terminating
* <code>NUL</code>, must be specified as a constant.
* The U_STRING_DECL macro should be invoked exactly once for one
* such string variable before it is used.
* @stable ICU 2.0
*/
#if defined(U_DECLARE_UTF16)
# define UNICODE_STRING(cs, _length) U_NAMESPACE_QUALIFIER UnicodeString(TRUE, (const UChar *)U_DECLARE_UTF16(cs), _length)
#elif U_SIZEOF_WCHAR_T==U_SIZEOF_UCHAR && (U_CHARSET_FAMILY==U_ASCII_FAMILY || (U_SIZEOF_UCHAR == 2 && defined(U_WCHAR_IS_UTF16)))
# define UNICODE_STRING(cs, _length) U_NAMESPACE_QUALIFIER UnicodeString(TRUE, (const UChar *)L ## cs, _length)
#elif U_SIZEOF_UCHAR==1 && U_CHARSET_FAMILY==U_ASCII_FAMILY
# define UNICODE_STRING(cs, _length) U_NAMESPACE_QUALIFIER UnicodeString(TRUE, (const UChar *)cs, _length)
#else
# define UNICODE_STRING(cs, _length) U_NAMESPACE_QUALIFIER UnicodeString(cs, _length, US_INV)
#endif
/**
* Unicode String literals in C++.
* Dependent on the platform properties, different UnicodeString
* constructors should be used to create a UnicodeString object from
* a string literal.
* The macros are defined for improved performance.
* They work only for strings that contain "invariant characters", i.e.,
* only latin letters, digits, and some punctuation.
* See utypes.h for details.
*
* The string parameter must be a C string literal.
* @stable ICU 2.0
*/
#define UNICODE_STRING_SIMPLE(cs) UNICODE_STRING(cs, -1)
/**
* UnicodeString is a string class that stores Unicode characters directly and provides
* similar functionality as the Java String and StringBuffer classes.
* It is a concrete implementation of the abstract class Replaceable (for transliteration).
*
* The UnicodeString class is not suitable for subclassing.
*
* <p>For an overview of Unicode strings in C and C++ see the
* <a href="http://icu-project.org/userguide/strings.html">User Guide Strings chapter</a>.</p>
*
* <p>In ICU, a Unicode string consists of 16-bit Unicode <em>code units</em>.
* A Unicode character may be stored with either one code unit
* (the most common case) or with a matched pair of special code units
* ("surrogates"). The data type for code units is UChar.
* For single-character handling, a Unicode character code <em>point</em> is a value
* in the range 0..0x10ffff. ICU uses the UChar32 type for code points.</p>
*
* <p>Indexes and offsets into and lengths of strings always count code units, not code points.
* This is the same as with multi-byte char* strings in traditional string handling.
* Operations on partial strings typically do not test for code point boundaries.
* If necessary, the user needs to take care of such boundaries by testing for the code unit
* values or by using functions like
* UnicodeString::getChar32Start() and UnicodeString::getChar32Limit()
* (or, in C, the equivalent macros U16_SET_CP_START() and U16_SET_CP_LIMIT(), see utf.h).</p>
*
* UnicodeString methods are more lenient with regard to input parameter values
* than other ICU APIs. In particular:
* - If indexes are out of bounds for a UnicodeString object
* (<0 or >length()) then they are "pinned" to the nearest boundary.
* - If primitive string pointer values (e.g., const UChar * or char *)
* for input strings are NULL, then those input string parameters are treated
* as if they pointed to an empty string.
* However, this is <em>not</em> the case for char * parameters for charset names
* or other IDs.
* - Most UnicodeString methods do not take a UErrorCode parameter because
* there are usually very few opportunities for failure other than a shortage
* of memory, error codes in low-level C++ string methods would be inconvenient,
* and the error code as the last parameter (ICU convention) would prevent
* the use of default parameter values.
* Instead, such methods set the UnicodeString into a "bogus" state
* (see isBogus()) if an error occurs.
*
* In string comparisons, two UnicodeString objects that are both "bogus"
* compare equal (to be transitive and prevent endless loops in sorting),
* and a "bogus" string compares less than any non-"bogus" one.
*
* Const UnicodeString methods are thread-safe. Multiple threads can use
* const methods on the same UnicodeString object simultaneously,
* but non-const methods must not be called concurrently (in multiple threads)
* with any other (const or non-const) methods.
*
* Similarly, const UnicodeString & parameters are thread-safe.
* One object may be passed in as such a parameter concurrently in multiple threads.
* This includes the const UnicodeString & parameters for
* copy construction, assignment, and cloning.
*
* <p>UnicodeString uses several storage methods.
* String contents can be stored inside the UnicodeString object itself,
* in an allocated and shared buffer, or in an outside buffer that is "aliased".
* Most of this is done transparently, but careful aliasing in particular provides
* significant performance improvements.
* Also, the internal buffer is accessible via special functions.
* For details see the
* <a href="http://icu-project.org/userguide/strings.html">User Guide Strings chapter</a>.</p>
*
* @see utf.h
* @see CharacterIterator
* @stable ICU 2.0
*/
class U_COMMON_API UnicodeString : public Replaceable
{
public:
/**
* Constant to be used in the UnicodeString(char *, int32_t, EInvariant) constructor
* which constructs a Unicode string from an invariant-character char * string.
* Use the macro US_INV instead of the full qualification for this value.
*
* @see US_INV
* @stable ICU 3.2
*/
enum EInvariant {
/**
* @see EInvariant
* @stable ICU 3.2
*/
kInvariant
};
//========================================
// Read-only operations
//========================================
/* Comparison - bitwise only - for international comparison use collation */
/**
* Equality operator. Performs only bitwise comparison.
* @param text The UnicodeString to compare to this one.
* @return TRUE if <TT>text</TT> contains the same characters as this one,
* FALSE otherwise.
* @stable ICU 2.0
*/
inline UBool operator== (const UnicodeString& text) const;
/**
* Inequality operator. Performs only bitwise comparison.
* @param text The UnicodeString to compare to this one.
* @return FALSE if <TT>text</TT> contains the same characters as this one,
* TRUE otherwise.
* @stable ICU 2.0
*/
inline UBool operator!= (const UnicodeString& text) const;
/**
* Greater than operator. Performs only bitwise comparison.
* @param text The UnicodeString to compare to this one.
* @return TRUE if the characters in this are bitwise
* greater than the characters in <code>text</code>, FALSE otherwise
* @stable ICU 2.0
*/
inline UBool operator> (const UnicodeString& text) const;
/**
* Less than operator. Performs only bitwise comparison.
* @param text The UnicodeString to compare to this one.
* @return TRUE if the characters in this are bitwise
* less than the characters in <code>text</code>, FALSE otherwise
* @stable ICU 2.0
*/
inline UBool operator< (const UnicodeString& text) const;
/**
* Greater than or equal operator. Performs only bitwise comparison.
* @param text The UnicodeString to compare to this one.
* @return TRUE if the characters in this are bitwise
* greater than or equal to the characters in <code>text</code>, FALSE otherwise
* @stable ICU 2.0
*/
inline UBool operator>= (const UnicodeString& text) const;
/**
* Less than or equal operator. Performs only bitwise comparison.
* @param text The UnicodeString to compare to this one.
* @return TRUE if the characters in this are bitwise
* less than or equal to the characters in <code>text</code>, FALSE otherwise
* @stable ICU 2.0
*/
inline UBool operator<= (const UnicodeString& text) const;
/**
* Compare the characters bitwise in this UnicodeString to
* the characters in <code>text</code>.
* @param text The UnicodeString to compare to this one.
* @return The result of bitwise character comparison: 0 if this
* contains the same characters as <code>text</code>, -1 if the characters in
* this are bitwise less than the characters in <code>text</code>, +1 if the
* characters in this are bitwise greater than the characters
* in <code>text</code>.
* @stable ICU 2.0
*/
inline int8_t compare(const UnicodeString& text) const;
/**
* Compare the characters bitwise in the range
* [<TT>start</TT>, <TT>start + length</TT>) with the characters
* in <TT>text</TT>
* @param start the offset at which the compare operation begins
* @param length the number of characters of text to compare.
* @param text the other text to be compared against this string.
* @return The result of bitwise character comparison: 0 if this
* contains the same characters as <code>text</code>, -1 if the characters in
* this are bitwise less than the characters in <code>text</code>, +1 if the
* characters in this are bitwise greater than the characters
* in <code>text</code>.
* @stable ICU 2.0
*/
inline int8_t compare(int32_t start,
int32_t length,
const UnicodeString& text) const;
/**
* Compare the characters bitwise in the range
* [<TT>start</TT>, <TT>start + length</TT>) with the characters
* in <TT>srcText</TT> in the range
* [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
* @param start the offset at which the compare operation begins
* @param length the number of characters in this to compare.
* @param srcText the text to be compared
* @param srcStart the offset into <TT>srcText</TT> to start comparison
* @param srcLength the number of characters in <TT>src</TT> to compare
* @return The result of bitwise character comparison: 0 if this
* contains the same characters as <code>srcText</code>, -1 if the characters in
* this are bitwise less than the characters in <code>srcText</code>, +1 if the
* characters in this are bitwise greater than the characters
* in <code>srcText</code>.
* @stable ICU 2.0
*/
inline int8_t compare(int32_t start,
int32_t length,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength) const;
/**
* Compare the characters bitwise in this UnicodeString with the first
* <TT>srcLength</TT> characters in <TT>srcChars</TT>.
* @param srcChars The characters to compare to this UnicodeString.
* @param srcLength the number of characters in <TT>srcChars</TT> to compare
* @return The result of bitwise character comparison: 0 if this
* contains the same characters as <code>srcChars</code>, -1 if the characters in
* this are bitwise less than the characters in <code>srcChars</code>, +1 if the
* characters in this are bitwise greater than the characters
* in <code>srcChars</code>.
* @stable ICU 2.0
*/
inline int8_t compare(const UChar *srcChars,
int32_t srcLength) const;
/**
* Compare the characters bitwise in the range
* [<TT>start</TT>, <TT>start + length</TT>) with the first
* <TT>length</TT> characters in <TT>srcChars</TT>
* @param start the offset at which the compare operation begins
* @param length the number of characters to compare.
* @param srcChars the characters to be compared
* @return The result of bitwise character comparison: 0 if this
* contains the same characters as <code>srcChars</code>, -1 if the characters in
* this are bitwise less than the characters in <code>srcChars</code>, +1 if the
* characters in this are bitwise greater than the characters
* in <code>srcChars</code>.
* @stable ICU 2.0
*/
inline int8_t compare(int32_t start,
int32_t length,
const UChar *srcChars) const;
/**
* Compare the characters bitwise in the range
* [<TT>start</TT>, <TT>start + length</TT>) with the characters
* in <TT>srcChars</TT> in the range
* [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
* @param start the offset at which the compare operation begins
* @param length the number of characters in this to compare
* @param srcChars the characters to be compared
* @param srcStart the offset into <TT>srcChars</TT> to start comparison
* @param srcLength the number of characters in <TT>srcChars</TT> to compare
* @return The result of bitwise character comparison: 0 if this
* contains the same characters as <code>srcChars</code>, -1 if the characters in
* this are bitwise less than the characters in <code>srcChars</code>, +1 if the
* characters in this are bitwise greater than the characters
* in <code>srcChars</code>.
* @stable ICU 2.0
*/
inline int8_t compare(int32_t start,
int32_t length,
const UChar *srcChars,
int32_t srcStart,
int32_t srcLength) const;
/**
* Compare the characters bitwise in the range
* [<TT>start</TT>, <TT>limit</TT>) with the characters
* in <TT>srcText</TT> in the range
* [<TT>srcStart</TT>, <TT>srcLimit</TT>).
* @param start the offset at which the compare operation begins
* @param limit the offset immediately following the compare operation
* @param srcText the text to be compared
* @param srcStart the offset into <TT>srcText</TT> to start comparison
* @param srcLimit the offset into <TT>srcText</TT> to limit comparison
* @return The result of bitwise character comparison: 0 if this
* contains the same characters as <code>srcText</code>, -1 if the characters in
* this are bitwise less than the characters in <code>srcText</code>, +1 if the
* characters in this are bitwise greater than the characters
* in <code>srcText</code>.
* @stable ICU 2.0
*/
inline int8_t compareBetween(int32_t start,
int32_t limit,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLimit) const;
/**
* Compare two Unicode strings in code point order.
* The result may be different from the results of compare(), operator<, etc.
* if supplementary characters are present:
*
* In UTF-16, supplementary characters (with code points U+10000 and above) are
* stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff,
* which means that they compare as less than some other BMP characters like U+feff.
* This function compares Unicode strings in code point order.
* If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.
*
* @param text Another string to compare this one to.
* @return a negative/zero/positive integer corresponding to whether
* this string is less than/equal to/greater than the second one
* in code point order
* @stable ICU 2.0
*/
inline int8_t compareCodePointOrder(const UnicodeString& text) const;
/**
* Compare two Unicode strings in code point order.
* The result may be different from the results of compare(), operator<, etc.
* if supplementary characters are present:
*
* In UTF-16, supplementary characters (with code points U+10000 and above) are
* stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff,
* which means that they compare as less than some other BMP characters like U+feff.
* This function compares Unicode strings in code point order.
* If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.
*
* @param start The start offset in this string at which the compare operation begins.
* @param length The number of code units from this string to compare.
* @param srcText Another string to compare this one to.
* @return a negative/zero/positive integer corresponding to whether
* this string is less than/equal to/greater than the second one
* in code point order
* @stable ICU 2.0
*/
inline int8_t compareCodePointOrder(int32_t start,
int32_t length,
const UnicodeString& srcText) const;
/**
* Compare two Unicode strings in code point order.
* The result may be different from the results of compare(), operator<, etc.
* if supplementary characters are present:
*
* In UTF-16, supplementary characters (with code points U+10000 and above) are
* stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff,
* which means that they compare as less than some other BMP characters like U+feff.
* This function compares Unicode strings in code point order.
* If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.
*
* @param start The start offset in this string at which the compare operation begins.
* @param length The number of code units from this string to compare.
* @param srcText Another string to compare this one to.
* @param srcStart The start offset in that string at which the compare operation begins.
* @param srcLength The number of code units from that string to compare.
* @return a negative/zero/positive integer corresponding to whether
* this string is less than/equal to/greater than the second one
* in code point order
* @stable ICU 2.0
*/
inline int8_t compareCodePointOrder(int32_t start,
int32_t length,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength) const;
/**
* Compare two Unicode strings in code point order.
* The result may be different from the results of compare(), operator<, etc.
* if supplementary characters are present:
*
* In UTF-16, supplementary characters (with code points U+10000 and above) are
* stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff,
* which means that they compare as less than some other BMP characters like U+feff.
* This function compares Unicode strings in code point order.
* If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.
*
* @param srcChars A pointer to another string to compare this one to.
* @param srcLength The number of code units from that string to compare.
* @return a negative/zero/positive integer corresponding to whether
* this string is less than/equal to/greater than the second one
* in code point order
* @stable ICU 2.0
*/
inline int8_t compareCodePointOrder(const UChar *srcChars,
int32_t srcLength) const;
/**
* Compare two Unicode strings in code point order.
* The result may be different from the results of compare(), operator<, etc.
* if supplementary characters are present:
*
* In UTF-16, supplementary characters (with code points U+10000 and above) are
* stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff,
* which means that they compare as less than some other BMP characters like U+feff.
* This function compares Unicode strings in code point order.
* If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.
*
* @param start The start offset in this string at which the compare operation begins.
* @param length The number of code units from this string to compare.
* @param srcChars A pointer to another string to compare this one to.
* @return a negative/zero/positive integer corresponding to whether
* this string is less than/equal to/greater than the second one
* in code point order
* @stable ICU 2.0
*/
inline int8_t compareCodePointOrder(int32_t start,
int32_t length,
const UChar *srcChars) const;
/**
* Compare two Unicode strings in code point order.
* The result may be different from the results of compare(), operator<, etc.
* if supplementary characters are present:
*
* In UTF-16, supplementary characters (with code points U+10000 and above) are
* stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff,
* which means that they compare as less than some other BMP characters like U+feff.
* This function compares Unicode strings in code point order.
* If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.
*
* @param start The start offset in this string at which the compare operation begins.
* @param length The number of code units from this string to compare.
* @param srcChars A pointer to another string to compare this one to.
* @param srcStart The start offset in that string at which the compare operation begins.
* @param srcLength The number of code units from that string to compare.
* @return a negative/zero/positive integer corresponding to whether
* this string is less than/equal to/greater than the second one
* in code point order
* @stable ICU 2.0
*/
inline int8_t compareCodePointOrder(int32_t start,
int32_t length,
const UChar *srcChars,
int32_t srcStart,
int32_t srcLength) const;
/**
* Compare two Unicode strings in code point order.
* The result may be different from the results of compare(), operator<, etc.
* if supplementary characters are present:
*
* In UTF-16, supplementary characters (with code points U+10000 and above) are
* stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff,
* which means that they compare as less than some other BMP characters like U+feff.
* This function compares Unicode strings in code point order.
* If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.
*
* @param start The start offset in this string at which the compare operation begins.
* @param limit The offset after the last code unit from this string to compare.
* @param srcText Another string to compare this one to.
* @param srcStart The start offset in that string at which the compare operation begins.
* @param srcLimit The offset after the last code unit from that string to compare.
* @return a negative/zero/positive integer corresponding to whether
* this string is less than/equal to/greater than the second one
* in code point order
* @stable ICU 2.0
*/
inline int8_t compareCodePointOrderBetween(int32_t start,
int32_t limit,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLimit) const;
/**
* Compare two strings case-insensitively using full case folding.
* This is equivalent to this->foldCase(options).compare(text.foldCase(options)).
*
* @param text Another string to compare this one to.
* @param options A bit set of options:
* - U_FOLD_CASE_DEFAULT or 0 is used for default options:
* Comparison in code unit order with default case folding.
*
* - U_COMPARE_CODE_POINT_ORDER
* Set to choose code point order instead of code unit order
* (see u_strCompare for details).
*
* - U_FOLD_CASE_EXCLUDE_SPECIAL_I
*
* @return A negative, zero, or positive integer indicating the comparison result.
* @stable ICU 2.0
*/
inline int8_t caseCompare(const UnicodeString& text, uint32_t options) const;
/**
* Compare two strings case-insensitively using full case folding.
* This is equivalent to this->foldCase(options).compare(srcText.foldCase(options)).
*
* @param start The start offset in this string at which the compare operation begins.
* @param length The number of code units from this string to compare.
* @param srcText Another string to compare this one to.
* @param options A bit set of options:
* - U_FOLD_CASE_DEFAULT or 0 is used for default options:
* Comparison in code unit order with default case folding.
*
* - U_COMPARE_CODE_POINT_ORDER
* Set to choose code point order instead of code unit order
* (see u_strCompare for details).
*
* - U_FOLD_CASE_EXCLUDE_SPECIAL_I
*
* @return A negative, zero, or positive integer indicating the comparison result.
* @stable ICU 2.0
*/
inline int8_t caseCompare(int32_t start,
int32_t length,
const UnicodeString& srcText,
uint32_t options) const;
/**
* Compare two strings case-insensitively using full case folding.
* This is equivalent to this->foldCase(options).compare(srcText.foldCase(options)).
*
* @param start The start offset in this string at which the compare operation begins.
* @param length The number of code units from this string to compare.
* @param srcText Another string to compare this one to.
* @param srcStart The start offset in that string at which the compare operation begins.
* @param srcLength The number of code units from that string to compare.
* @param options A bit set of options:
* - U_FOLD_CASE_DEFAULT or 0 is used for default options:
* Comparison in code unit order with default case folding.
*
* - U_COMPARE_CODE_POINT_ORDER
* Set to choose code point order instead of code unit order
* (see u_strCompare for details).
*
* - U_FOLD_CASE_EXCLUDE_SPECIAL_I
*
* @return A negative, zero, or positive integer indicating the comparison result.
* @stable ICU 2.0
*/
inline int8_t caseCompare(int32_t start,
int32_t length,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength,
uint32_t options) const;
/**
* Compare two strings case-insensitively using full case folding.
* This is equivalent to this->foldCase(options).compare(srcChars.foldCase(options)).
*
* @param srcChars A pointer to another string to compare this one to.
* @param srcLength The number of code units from that string to compare.
* @param options A bit set of options:
* - U_FOLD_CASE_DEFAULT or 0 is used for default options:
* Comparison in code unit order with default case folding.
*
* - U_COMPARE_CODE_POINT_ORDER
* Set to choose code point order instead of code unit order
* (see u_strCompare for details).
*
* - U_FOLD_CASE_EXCLUDE_SPECIAL_I
*
* @return A negative, zero, or positive integer indicating the comparison result.
* @stable ICU 2.0
*/
inline int8_t caseCompare(const UChar *srcChars,
int32_t srcLength,
uint32_t options) const;
/**
* Compare two strings case-insensitively using full case folding.
* This is equivalent to this->foldCase(options).compare(srcChars.foldCase(options)).
*
* @param start The start offset in this string at which the compare operation begins.
* @param length The number of code units from this string to compare.
* @param srcChars A pointer to another string to compare this one to.
* @param options A bit set of options:
* - U_FOLD_CASE_DEFAULT or 0 is used for default options:
* Comparison in code unit order with default case folding.
*
* - U_COMPARE_CODE_POINT_ORDER
* Set to choose code point order instead of code unit order
* (see u_strCompare for details).
*
* - U_FOLD_CASE_EXCLUDE_SPECIAL_I
*
* @return A negative, zero, or positive integer indicating the comparison result.
* @stable ICU 2.0
*/
inline int8_t caseCompare(int32_t start,
int32_t length,
const UChar *srcChars,
uint32_t options) const;
/**
* Compare two strings case-insensitively using full case folding.
* This is equivalent to this->foldCase(options).compare(srcChars.foldCase(options)).
*
* @param start The start offset in this string at which the compare operation begins.
* @param length The number of code units from this string to compare.
* @param srcChars A pointer to another string to compare this one to.
* @param srcStart The start offset in that string at which the compare operation begins.
* @param srcLength The number of code units from that string to compare.
* @param options A bit set of options:
* - U_FOLD_CASE_DEFAULT or 0 is used for default options:
* Comparison in code unit order with default case folding.
*
* - U_COMPARE_CODE_POINT_ORDER
* Set to choose code point order instead of code unit order
* (see u_strCompare for details).
*
* - U_FOLD_CASE_EXCLUDE_SPECIAL_I
*
* @return A negative, zero, or positive integer indicating the comparison result.
* @stable ICU 2.0
*/
inline int8_t caseCompare(int32_t start,
int32_t length,
const UChar *srcChars,
int32_t srcStart,
int32_t srcLength,
uint32_t options) const;
/**
* Compare two strings case-insensitively using full case folding.
* This is equivalent to this->foldCase(options).compareBetween(text.foldCase(options)).
*
* @param start The start offset in this string at which the compare operation begins.
* @param limit The offset after the last code unit from this string to compare.
* @param srcText Another string to compare this one to.
* @param srcStart The start offset in that string at which the compare operation begins.
* @param srcLimit The offset after the last code unit from that string to compare.
* @param options A bit set of options:
* - U_FOLD_CASE_DEFAULT or 0 is used for default options:
* Comparison in code unit order with default case folding.
*
* - U_COMPARE_CODE_POINT_ORDER
* Set to choose code point order instead of code unit order
* (see u_strCompare for details).
*
* - U_FOLD_CASE_EXCLUDE_SPECIAL_I
*
* @return A negative, zero, or positive integer indicating the comparison result.
* @stable ICU 2.0
*/
inline int8_t caseCompareBetween(int32_t start,
int32_t limit,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLimit,
uint32_t options) const;
/**
* Determine if this starts with the characters in <TT>text</TT>
* @param text The text to match.
* @return TRUE if this starts with the characters in <TT>text</TT>,
* FALSE otherwise
* @stable ICU 2.0
*/
inline UBool startsWith(const UnicodeString& text) const;
/**
* Determine if this starts with the characters in <TT>srcText</TT>
* in the range [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
* @param srcText The text to match.
* @param srcStart the offset into <TT>srcText</TT> to start matching
* @param srcLength the number of characters in <TT>srcText</TT> to match
* @return TRUE if this starts with the characters in <TT>text</TT>,
* FALSE otherwise
* @stable ICU 2.0
*/
inline UBool startsWith(const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength) const;
/**
* Determine if this starts with the characters in <TT>srcChars</TT>
* @param srcChars The characters to match.
* @param srcLength the number of characters in <TT>srcChars</TT>
* @return TRUE if this starts with the characters in <TT>srcChars</TT>,
* FALSE otherwise
* @stable ICU 2.0
*/
inline UBool startsWith(const UChar *srcChars,
int32_t srcLength) const;
/**
* Determine if this ends with the characters in <TT>srcChars</TT>
* in the range [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
* @param srcChars The characters to match.
* @param srcStart the offset into <TT>srcText</TT> to start matching
* @param srcLength the number of characters in <TT>srcChars</TT> to match
* @return TRUE if this ends with the characters in <TT>srcChars</TT>, FALSE otherwise
* @stable ICU 2.0
*/
inline UBool startsWith(const UChar *srcChars,
int32_t srcStart,
int32_t srcLength) const;
/**
* Determine if this ends with the characters in <TT>text</TT>
* @param text The text to match.
* @return TRUE if this ends with the characters in <TT>text</TT>,
* FALSE otherwise
* @stable ICU 2.0
*/
inline UBool endsWith(const UnicodeString& text) const;
/**
* Determine if this ends with the characters in <TT>srcText</TT>
* in the range [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
* @param srcText The text to match.
* @param srcStart the offset into <TT>srcText</TT> to start matching
* @param srcLength the number of characters in <TT>srcText</TT> to match
* @return TRUE if this ends with the characters in <TT>text</TT>,
* FALSE otherwise
* @stable ICU 2.0
*/
inline UBool endsWith(const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength) const;
/**
* Determine if this ends with the characters in <TT>srcChars</TT>
* @param srcChars The characters to match.
* @param srcLength the number of characters in <TT>srcChars</TT>
* @return TRUE if this ends with the characters in <TT>srcChars</TT>,
* FALSE otherwise
* @stable ICU 2.0
*/
inline UBool endsWith(const UChar *srcChars,
int32_t srcLength) const;
/**
* Determine if this ends with the characters in <TT>srcChars</TT>
* in the range [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
* @param srcChars The characters to match.
* @param srcStart the offset into <TT>srcText</TT> to start matching
* @param srcLength the number of characters in <TT>srcChars</TT> to match
* @return TRUE if this ends with the characters in <TT>srcChars</TT>,
* FALSE otherwise
* @stable ICU 2.0
*/
inline UBool endsWith(const UChar *srcChars,
int32_t srcStart,
int32_t srcLength) const;
/* Searching - bitwise only */
/**
* Locate in this the first occurrence of the characters in <TT>text</TT>,
* using bitwise comparison.
* @param text The text to search for.
* @return The offset into this of the start of <TT>text</TT>,
* or -1 if not found.
* @stable ICU 2.0
*/
inline int32_t indexOf(const UnicodeString& text) const;
/**
* Locate in this the first occurrence of the characters in <TT>text</TT>
* starting at offset <TT>start</TT>, using bitwise comparison.
* @param text The text to search for.
* @param start The offset at which searching will start.
* @return The offset into this of the start of <TT>text</TT>,
* or -1 if not found.
* @stable ICU 2.0
*/
inline int32_t indexOf(const UnicodeString& text,
int32_t start) const;
/**
* Locate in this the first occurrence in the range
* [<TT>start</TT>, <TT>start + length</TT>) of the characters
* in <TT>text</TT>, using bitwise comparison.
* @param text The text to search for.
* @param start The offset at which searching will start.
* @param length The number of characters to search
* @return The offset into this of the start of <TT>text</TT>,
* or -1 if not found.
* @stable ICU 2.0
*/
inline int32_t indexOf(const UnicodeString& text,
int32_t start,
int32_t length) const;
/**
* Locate in this the first occurrence in the range
* [<TT>start</TT>, <TT>start + length</TT>) of the characters
* in <TT>srcText</TT> in the range
* [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>),
* using bitwise comparison.
* @param srcText The text to search for.
* @param srcStart the offset into <TT>srcText</TT> at which
* to start matching
* @param srcLength the number of characters in <TT>srcText</TT> to match
* @param start the offset into this at which to start matching
* @param length the number of characters in this to search
* @return The offset into this of the start of <TT>text</TT>,
* or -1 if not found.
* @stable ICU 2.0
*/
inline int32_t indexOf(const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength,
int32_t start,
int32_t length) const;
/**
* Locate in this the first occurrence of the characters in
* <TT>srcChars</TT>
* starting at offset <TT>start</TT>, using bitwise comparison.
* @param srcChars The text to search for.
* @param srcLength the number of characters in <TT>srcChars</TT> to match
* @param start the offset into this at which to start matching
* @return The offset into this of the start of <TT>text</TT>,
* or -1 if not found.
* @stable ICU 2.0
*/
inline int32_t indexOf(const UChar *srcChars,
int32_t srcLength,
int32_t start) const;
/**
* Locate in this the first occurrence in the range
* [<TT>start</TT>, <TT>start + length</TT>) of the characters
* in <TT>srcChars</TT>, using bitwise comparison.
* @param srcChars The text to search for.
* @param srcLength the number of characters in <TT>srcChars</TT>
* @param start The offset at which searching will start.
* @param length The number of characters to search
* @return The offset into this of the start of <TT>srcChars</TT>,
* or -1 if not found.
* @stable ICU 2.0
*/
inline int32_t indexOf(const UChar *srcChars,
int32_t srcLength,
int32_t start,
int32_t length) const;
/**
* Locate in this the first occurrence in the range
* [<TT>start</TT>, <TT>start + length</TT>) of the characters
* in <TT>srcChars</TT> in the range
* [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>),
* using bitwise comparison.
* @param srcChars The text to search for.
* @param srcStart the offset into <TT>srcChars</TT> at which
* to start matching
* @param srcLength the number of characters in <TT>srcChars</TT> to match
* @param start the offset into this at which to start matching
* @param length the number of characters in this to search
* @return The offset into this of the start of <TT>text</TT>,
* or -1 if not found.
* @stable ICU 2.0
*/
int32_t indexOf(const UChar *srcChars,
int32_t srcStart,
int32_t srcLength,
int32_t start,
int32_t length) const;
/**
* Locate in this the first occurrence of the BMP code point <code>c</code>,
* using bitwise comparison.
* @param c The code unit to search for.
* @return The offset into this of <TT>c</TT>, or -1 if not found.
* @stable ICU 2.0
*/
inline int32_t indexOf(UChar c) const;
/**
* Locate in this the first occurrence of the code point <TT>c</TT>,
* using bitwise comparison.
*
* @param c The code point to search for.
* @return The offset into this of <TT>c</TT>, or -1 if not found.
* @stable ICU 2.0
*/
inline int32_t indexOf(UChar32 c) const;
/**
* Locate in this the first occurrence of the BMP code point <code>c</code>,
* starting at offset <TT>start</TT>, using bitwise comparison.
* @param c The code unit to search for.
* @param start The offset at which searching will start.
* @return The offset into this of <TT>c</TT>, or -1 if not found.
* @stable ICU 2.0
*/
inline int32_t indexOf(UChar c,
int32_t start) const;
/**
* Locate in this the first occurrence of the code point <TT>c</TT>
* starting at offset <TT>start</TT>, using bitwise comparison.
*
* @param c The code point to search for.
* @param start The offset at which searching will start.
* @return The offset into this of <TT>c</TT>, or -1 if not found.
* @stable ICU 2.0
*/
inline int32_t indexOf(UChar32 c,
int32_t start) const;
/**
* Locate in this the first occurrence of the BMP code point <code>c</code>
* in the range [<TT>start</TT>, <TT>start + length</TT>),
* using bitwise comparison.
* @param c The code unit to search for.
* @param start the offset into this at which to start matching
* @param length the number of characters in this to search
* @return The offset into this of <TT>c</TT>, or -1 if not found.
* @stable ICU 2.0
*/
inline int32_t indexOf(UChar c,
int32_t start,
int32_t length) const;
/**
* Locate in this the first occurrence of the code point <TT>c</TT>
* in the range [<TT>start</TT>, <TT>start + length</TT>),
* using bitwise comparison.
*
* @param c The code point to search for.
* @param start the offset into this at which to start matching
* @param length the number of characters in this to search
* @return The offset into this of <TT>c</TT>, or -1 if not found.
* @stable ICU 2.0
*/
inline int32_t indexOf(UChar32 c,
int32_t start,
int32_t length) const;
/**
* Locate in this the last occurrence of the characters in <TT>text</TT>,
* using bitwise comparison.
* @param text The text to search for.
* @return The offset into this of the start of <TT>text</TT>,
* or -1 if not found.
* @stable ICU 2.0
*/
inline int32_t lastIndexOf(const UnicodeString& text) const;
/**
* Locate in this the last occurrence of the characters in <TT>text</TT>
* starting at offset <TT>start</TT>, using bitwise comparison.
* @param text The text to search for.
* @param start The offset at which searching will start.
* @return The offset into this of the start of <TT>text</TT>,
* or -1 if not found.
* @stable ICU 2.0
*/
inline int32_t lastIndexOf(const UnicodeString& text,
int32_t start) const;
/**
* Locate in this the last occurrence in the range
* [<TT>start</TT>, <TT>start + length</TT>) of the characters
* in <TT>text</TT>, using bitwise comparison.
* @param text The text to search for.
* @param start The offset at which searching will start.
* @param length The number of characters to search
* @return The offset into this of the start of <TT>text</TT>,
* or -1 if not found.
* @stable ICU 2.0
*/
inline int32_t lastIndexOf(const UnicodeString& text,
int32_t start,
int32_t length) const;
/**
* Locate in this the last occurrence in the range
* [<TT>start</TT>, <TT>start + length</TT>) of the characters
* in <TT>srcText</TT> in the range
* [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>),
* using bitwise comparison.
* @param srcText The text to search for.
* @param srcStart the offset into <TT>srcText</TT> at which
* to start matching
* @param srcLength the number of characters in <TT>srcText</TT> to match
* @param start the offset into this at which to start matching
* @param length the number of characters in this to search
* @return The offset into this of the start of <TT>text</TT>,
* or -1 if not found.
* @stable ICU 2.0
*/
inline int32_t lastIndexOf(const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength,
int32_t start,
int32_t length) const;
/**
* Locate in this the last occurrence of the characters in <TT>srcChars</TT>
* starting at offset <TT>start</TT>, using bitwise comparison.
* @param srcChars The text to search for.
* @param srcLength the number of characters in <TT>srcChars</TT> to match
* @param start the offset into this at which to start matching
* @return The offset into this of the start of <TT>text</TT>,
* or -1 if not found.
* @stable ICU 2.0
*/
inline int32_t lastIndexOf(const UChar *srcChars,
int32_t srcLength,
int32_t start) const;
/**
* Locate in this the last occurrence in the range
* [<TT>start</TT>, <TT>start + length</TT>) of the characters
* in <TT>srcChars</TT>, using bitwise comparison.
* @param srcChars The text to search for.
* @param srcLength the number of characters in <TT>srcChars</TT>
* @param start The offset at which searching will start.
* @param length The number of characters to search
* @return The offset into this of the start of <TT>srcChars</TT>,
* or -1 if not found.
* @stable ICU 2.0
*/
inline int32_t lastIndexOf(const UChar *srcChars,
int32_t srcLength,
int32_t start,
int32_t length) const;
/**
* Locate in this the last occurrence in the range
* [<TT>start</TT>, <TT>start + length</TT>) of the characters
* in <TT>srcChars</TT> in the range
* [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>),
* using bitwise comparison.
* @param srcChars The text to search for.
* @param srcStart the offset into <TT>srcChars</TT> at which
* to start matching
* @param srcLength the number of characters in <TT>srcChars</TT> to match
* @param start the offset into this at which to start matching
* @param length the number of characters in this to search
* @return The offset into this of the start of <TT>text</TT>,
* or -1 if not found.
* @stable ICU 2.0
*/
int32_t lastIndexOf(const UChar *srcChars,
int32_t srcStart,
int32_t srcLength,
int32_t start,
int32_t length) const;
/**
* Locate in this the last occurrence of the BMP code point <code>c</code>,
* using bitwise comparison.
* @param c The code unit to search for.
* @return The offset into this of <TT>c</TT>, or -1 if not found.
* @stable ICU 2.0
*/
inline int32_t lastIndexOf(UChar c) const;
/**
* Locate in this the last occurrence of the code point <TT>c</TT>,
* using bitwise comparison.
*
* @param c The code point to search for.
* @return The offset into this of <TT>c</TT>, or -1 if not found.
* @stable ICU 2.0
*/
inline int32_t lastIndexOf(UChar32 c) const;
/**
* Locate in this the last occurrence of the BMP code point <code>c</code>
* starting at offset <TT>start</TT>, using bitwise comparison.
* @param c The code unit to search for.
* @param start The offset at which searching will start.
* @return The offset into this of <TT>c</TT>, or -1 if not found.
* @stable ICU 2.0
*/
inline int32_t lastIndexOf(UChar c,
int32_t start) const;
/**
* Locate in this the last occurrence of the code point <TT>c</TT>
* starting at offset <TT>start</TT>, using bitwise comparison.
*
* @param c The code point to search for.
* @param start The offset at which searching will start.
* @return The offset into this of <TT>c</TT>, or -1 if not found.
* @stable ICU 2.0
*/
inline int32_t lastIndexOf(UChar32 c,
int32_t start) const;
/**
* Locate in this the last occurrence of the BMP code point <code>c</code>
* in the range [<TT>start</TT>, <TT>start + length</TT>),
* using bitwise comparison.
* @param c The code unit to search for.
* @param start the offset into this at which to start matching
* @param length the number of characters in this to search
* @return The offset into this of <TT>c</TT>, or -1 if not found.
* @stable ICU 2.0
*/
inline int32_t lastIndexOf(UChar c,
int32_t start,
int32_t length) const;
/**
* Locate in this the last occurrence of the code point <TT>c</TT>
* in the range [<TT>start</TT>, <TT>start + length</TT>),
* using bitwise comparison.
*
* @param c The code point to search for.
* @param start the offset into this at which to start matching
* @param length the number of characters in this to search
* @return The offset into this of <TT>c</TT>, or -1 if not found.
* @stable ICU 2.0
*/
inline int32_t lastIndexOf(UChar32 c,
int32_t start,
int32_t length) const;
/* Character access */
/**
* Return the code unit at offset <tt>offset</tt>.
* If the offset is not valid (0..length()-1) then U+ffff is returned.
* @param offset a valid offset into the text
* @return the code unit at offset <tt>offset</tt>
* or 0xffff if the offset is not valid for this string
* @stable ICU 2.0
*/
inline UChar charAt(int32_t offset) const;
/**
* Return the code unit at offset <tt>offset</tt>.
* If the offset is not valid (0..length()-1) then U+ffff is returned.
* @param offset a valid offset into the text
* @return the code unit at offset <tt>offset</tt>
* @stable ICU 2.0
*/
inline UChar operator[] (int32_t offset) const;
/**
* Return the code point that contains the code unit
* at offset <tt>offset</tt>.
* If the offset is not valid (0..length()-1) then U+ffff is returned.
* @param offset a valid offset into the text
* that indicates the text offset of any of the code units
* that will be assembled into a code point (21-bit value) and returned
* @return the code point of text at <tt>offset</tt>
* or 0xffff if the offset is not valid for this string
* @stable ICU 2.0
*/
inline UChar32 char32At(int32_t offset) const;
/**
* Adjust a random-access offset so that
* it points to the beginning of a Unicode character.
* The offset that is passed in points to
* any code unit of a code point,
* while the returned offset will point to the first code unit
* of the same code point.
* In UTF-16, if the input offset points to a second surrogate
* of a surrogate pair, then the returned offset will point
* to the first surrogate.
* @param offset a valid offset into one code point of the text
* @return offset of the first code unit of the same code point
* @see U16_SET_CP_START
* @stable ICU 2.0
*/
inline int32_t getChar32Start(int32_t offset) const;
/**
* Adjust a random-access offset so that
* it points behind a Unicode character.
* The offset that is passed in points behind
* any code unit of a code point,
* while the returned offset will point behind the last code unit
* of the same code point.
* In UTF-16, if the input offset points behind the first surrogate
* (i.e., to the second surrogate)
* of a surrogate pair, then the returned offset will point
* behind the second surrogate (i.e., to the first surrogate).
* @param offset a valid offset after any code unit of a code point of the text
* @return offset of the first code unit after the same code point
* @see U16_SET_CP_LIMIT
* @stable ICU 2.0
*/
inline int32_t getChar32Limit(int32_t offset) const;
/**
* Move the code unit index along the string by delta code points.
* Interpret the input index as a code unit-based offset into the string,
* move the index forward or backward by delta code points, and
* return the resulting index.
* The input index should point to the first code unit of a code point,
* if there is more than one.
*
* Both input and output indexes are code unit-based as for all
* string indexes/offsets in ICU (and other libraries, like MBCS char*).
* If delta<0 then the index is moved backward (toward the start of the string).
* If delta>0 then the index is moved forward (toward the end of the string).
*
* This behaves like CharacterIterator::move32(delta, kCurrent).
*
* Behavior for out-of-bounds indexes:
* <code>moveIndex32</code> pins the input index to 0..length(), i.e.,
* if the input index<0 then it is pinned to 0;
* if it is index>length() then it is pinned to length().
* Afterwards, the index is moved by <code>delta</code> code points
* forward or backward,
* but no further backward than to 0 and no further forward than to length().
* The resulting index return value will be in between 0 and length(), inclusively.
*
* Examples:
* <pre>
* // s has code points 'a' U+10000 'b' U+10ffff U+2029
* UnicodeString s=UNICODE_STRING("a\\U00010000b\\U0010ffff\\u2029", 31).unescape();
*
* // initial index: position of U+10000
* int32_t index=1;
*
* // the following examples will all result in index==4, position of U+10ffff
*
* // skip 2 code points from some position in the string
* index=s.moveIndex32(index, 2); // skips U+10000 and 'b'
*
* // go to the 3rd code point from the start of s (0-based)
* index=s.moveIndex32(0, 3); // skips 'a', U+10000, and 'b'
*
* // go to the next-to-last code point of s
* index=s.moveIndex32(s.length(), -2); // backward-skips U+2029 and U+10ffff
* </pre>
*
* @param index input code unit index
* @param delta (signed) code point count to move the index forward or backward
* in the string
* @return the resulting code unit index
* @stable ICU 2.0
*/
int32_t moveIndex32(int32_t index, int32_t delta) const;
/* Substring extraction */
/**
* Copy the characters in the range
* [<tt>start</tt>, <tt>start + length</tt>) into the array <tt>dst</tt>,
* beginning at <tt>dstStart</tt>.
* If the string aliases to <code>dst</code> itself as an external buffer,
* then extract() will not copy the contents.
*
* @param start offset of first character which will be copied into the array
* @param length the number of characters to extract
* @param dst array in which to copy characters. The length of <tt>dst</tt>
* must be at least (<tt>dstStart + length</tt>).
* @param dstStart the offset in <TT>dst</TT> where the first character
* will be extracted
* @stable ICU 2.0
*/
inline void extract(int32_t start,
int32_t length,
UChar *dst,
int32_t dstStart = 0) const;
/**
* Copy the contents of the string into dest.
* This is a convenience function that
* checks if there is enough space in dest,
* extracts the entire string if possible,
* and NUL-terminates dest if possible.
*
* If the string fits into dest but cannot be NUL-terminated
* (length()==destCapacity) then the error code is set to U_STRING_NOT_TERMINATED_WARNING.
* If the string itself does not fit into dest
* (length()>destCapacity) then the error code is set to U_BUFFER_OVERFLOW_ERROR.
*
* If the string aliases to <code>dest</code> itself as an external buffer,
* then extract() will not copy the contents.
*
* @param dest Destination string buffer.
* @param destCapacity Number of UChars available at dest.
* @param errorCode ICU error code.
* @return length()
* @stable ICU 2.0
*/
int32_t
extract(UChar *dest, int32_t destCapacity,
UErrorCode &errorCode) const;
/**
* Copy the characters in the range
* [<tt>start</tt>, <tt>start + length</tt>) into the UnicodeString
* <tt>target</tt>.
* @param start offset of first character which will be copied
* @param length the number of characters to extract
* @param target UnicodeString into which to copy characters.
* @return A reference to <TT>target</TT>
* @stable ICU 2.0
*/
inline void extract(int32_t start,
int32_t length,
UnicodeString& target) const;
/**
* Copy the characters in the range [<tt>start</tt>, <tt>limit</tt>)
* into the array <tt>dst</tt>, beginning at <tt>dstStart</tt>.
* @param start offset of first character which will be copied into the array
* @param limit offset immediately following the last character to be copied
* @param dst array in which to copy characters. The length of <tt>dst</tt>
* must be at least (<tt>dstStart + (limit - start)</tt>).
* @param dstStart the offset in <TT>dst</TT> where the first character
* will be extracted
* @stable ICU 2.0
*/
inline void extractBetween(int32_t start,
int32_t limit,
UChar *dst,
int32_t dstStart = 0) const;
/**
* Copy the characters in the range [<tt>start</tt>, <tt>limit</tt>)
* into the UnicodeString <tt>target</tt>. Replaceable API.
* @param start offset of first character which will be copied
* @param limit offset immediately following the last character to be copied
* @param target UnicodeString into which to copy characters.
* @return A reference to <TT>target</TT>
* @stable ICU 2.0
*/
virtual void extractBetween(int32_t start,
int32_t limit,
UnicodeString& target) const;
/**
* Copy the characters in the range
* [<tt>start</TT>, <tt>start + length</TT>) into an array of characters.
* All characters must be invariant (see utypes.h).
* Use US_INV as the last, signature-distinguishing parameter.
*
* This function does not write any more than <code>targetLength</code>
* characters but returns the length of the entire output string
* so that one can allocate a larger buffer and call the function again
* if necessary.
* The output string is NUL-terminated if possible.
*
* @param start offset of first character which will be copied
* @param startLength the number of characters to extract
* @param target the target buffer for extraction, can be NULL
* if targetLength is 0
* @param targetCapacity the length of the target buffer
* @param inv Signature-distinguishing paramater, use US_INV.
* @return the output string length, not including the terminating NUL
* @stable ICU 3.2
*/
int32_t extract(int32_t start,
int32_t startLength,
char *target,
int32_t targetCapacity,
enum EInvariant inv) const;
#if !UCONFIG_NO_CONVERSION
/**
* Copy the characters in the range
* [<tt>start</TT>, <tt>start + length</TT>) into an array of characters
* in a specified codepage.
* The output string is NUL-terminated.
*
* Recommendation: For invariant-character strings use
* extract(int32_t start, int32_t length, char *target, int32_t targetCapacity, enum EInvariant inv) const
* because it avoids object code dependencies of UnicodeString on
* the conversion code.
*
* @param start offset of first character which will be copied
* @param startLength the number of characters to extract
* @param target the target buffer for extraction
* @param codepage the desired codepage for the characters. 0 has
* the special meaning of the default codepage
* If <code>codepage</code> is an empty string (<code>""</code>),
* then a simple conversion is performed on the codepage-invariant
* subset ("invariant characters") of the platform encoding. See utypes.h.
* If <TT>target</TT> is NULL, then the number of bytes required for
* <TT>target</TT> is returned. It is assumed that the target is big enough
* to fit all of the characters.
* @return the output string length, not including the terminating NUL
* @stable ICU 2.0
*/
inline int32_t extract(int32_t start,
int32_t startLength,
char *target,
const char *codepage = 0) const;
/**
* Copy the characters in the range
* [<tt>start</TT>, <tt>start + length</TT>) into an array of characters
* in a specified codepage.
* This function does not write any more than <code>targetLength</code>
* characters but returns the length of the entire output string
* so that one can allocate a larger buffer and call the function again
* if necessary.
* The output string is NUL-terminated if possible.
*
* Recommendation: For invariant-character strings use
* extract(int32_t start, int32_t length, char *target, int32_t targetCapacity, enum EInvariant inv) const
* because it avoids object code dependencies of UnicodeString on
* the conversion code.
*
* @param start offset of first character which will be copied
* @param startLength the number of characters to extract
* @param target the target buffer for extraction
* @param targetLength the length of the target buffer
* @param codepage the desired codepage for the characters. 0 has
* the special meaning of the default codepage
* If <code>codepage</code> is an empty string (<code>""</code>),
* then a simple conversion is performed on the codepage-invariant
* subset ("invariant characters") of the platform encoding. See utypes.h.
* If <TT>target</TT> is NULL, then the number of bytes required for
* <TT>target</TT> is returned.
* @return the output string length, not including the terminating NUL
* @stable ICU 2.0
*/
int32_t extract(int32_t start,
int32_t startLength,
char *target,
uint32_t targetLength,
const char *codepage = 0) const;
/**
* Convert the UnicodeString into a codepage string using an existing UConverter.
* The output string is NUL-terminated if possible.
*
* This function avoids the overhead of opening and closing a converter if
* multiple strings are extracted.
*
* @param dest destination string buffer, can be NULL if destCapacity==0
* @param destCapacity the number of chars available at dest
* @param cnv the converter object to be used (ucnv_resetFromUnicode() will be called),
* or NULL for the default converter
* @param errorCode normal ICU error code
* @return the length of the output string, not counting the terminating NUL;
* if the length is greater than destCapacity, then the string will not fit
* and a buffer of the indicated length would need to be passed in
* @stable ICU 2.0
*/
int32_t extract(char *dest, int32_t destCapacity,
UConverter *cnv,
UErrorCode &errorCode) const;
#endif
/* Length operations */
/**
* Return the length of the UnicodeString object.
* The length is the number of UChar code units are in the UnicodeString.
* If you want the number of code points, please use countChar32().
* @return the length of the UnicodeString object
* @see countChar32
* @stable ICU 2.0
*/
inline int32_t length(void) const;
/**
* Count Unicode code points in the length UChar code units of the string.
* A code point may occupy either one or two UChar code units.
* Counting code points involves reading all code units.
*
* This functions is basically the inverse of moveIndex32().
*
* @param start the index of the first code unit to check
* @param length the number of UChar code units to check
* @return the number of code points in the specified code units
* @see length
* @stable ICU 2.0
*/
int32_t
countChar32(int32_t start=0, int32_t length=INT32_MAX) const;
/**
* Check if the length UChar code units of the string
* contain more Unicode code points than a certain number.
* This is more efficient than counting all code points in this part of the string
* and comparing that number with a threshold.
* This function may not need to scan the string at all if the length
* falls within a certain range, and
* never needs to count more than 'number+1' code points.
* Logically equivalent to (countChar32(start, length)>number).
* A Unicode code point may occupy either one or two UChar code units.
*
* @param start the index of the first code unit to check (0 for the entire string)
* @param length the number of UChar code units to check
* (use INT32_MAX for the entire string; remember that start/length
* values are pinned)
* @param number The number of code points in the (sub)string is compared against
* the 'number' parameter.
* @return Boolean value for whether the string contains more Unicode code points
* than 'number'. Same as (u_countChar32(s, length)>number).
* @see countChar32
* @see u_strHasMoreChar32Than
* @stable ICU 2.4
*/
UBool
hasMoreChar32Than(int32_t start, int32_t length, int32_t number) const;
/**
* Determine if this string is empty.
* @return TRUE if this string contains 0 characters, FALSE otherwise.
* @stable ICU 2.0
*/
inline UBool isEmpty(void) const;
/**
* Return the capacity of the internal buffer of the UnicodeString object.
* This is useful together with the getBuffer functions.
* See there for details.
*
* @return the number of UChars available in the internal buffer
* @see getBuffer
* @stable ICU 2.0
*/
inline int32_t getCapacity(void) const;
/* Other operations */
/**
* Generate a hash code for this object.
* @return The hash code of this UnicodeString.
* @stable ICU 2.0
*/
inline int32_t hashCode(void) const;
/**
* Determine if this object contains a valid string.
* A bogus string has no value. It is different from an empty string.
* It can be used to indicate that no string value is available.
* getBuffer() and getTerminatedBuffer() return NULL, and
* length() returns 0.
*
* @return TRUE if the string is valid, FALSE otherwise
* @see setToBogus()
* @stable ICU 2.0
*/
inline UBool isBogus(void) const;
//========================================
// Write operations
//========================================
/* Assignment operations */
/**
* Assignment operator. Replace the characters in this UnicodeString
* with the characters from <TT>srcText</TT>.
* @param srcText The text containing the characters to replace
* @return a reference to this
* @stable ICU 2.0
*/
UnicodeString &operator=(const UnicodeString &srcText);
/**
* Almost the same as the assignment operator.
* Replace the characters in this UnicodeString
* with the characters from <code>srcText</code>.
*
* This function works the same for all strings except for ones that
* are readonly aliases.
* Starting with ICU 2.4, the assignment operator and the copy constructor
* allocate a new buffer and copy the buffer contents even for readonly aliases.
* This function implements the old, more efficient but less safe behavior
* of making this string also a readonly alias to the same buffer.
* The fastCopyFrom function must be used only if it is known that the lifetime of
* this UnicodeString is at least as long as the lifetime of the aliased buffer
* including its contents, for example for strings from resource bundles
* or aliases to string contents.
*
* @param src The text containing the characters to replace.
* @return a reference to this
* @stable ICU 2.4
*/
UnicodeString &fastCopyFrom(const UnicodeString &src);
/**
* Assignment operator. Replace the characters in this UnicodeString
* with the code unit <TT>ch</TT>.
* @param ch the code unit to replace
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& operator= (UChar ch);
/**
* Assignment operator. Replace the characters in this UnicodeString
* with the code point <TT>ch</TT>.
* @param ch the code point to replace
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& operator= (UChar32 ch);
/**
* Set the text in the UnicodeString object to the characters
* in <TT>srcText</TT> in the range
* [<TT>srcStart</TT>, <TT>srcText.length()</TT>).
* <TT>srcText</TT> is not modified.
* @param srcText the source for the new characters
* @param srcStart the offset into <TT>srcText</TT> where new characters
* will be obtained
* @return a reference to this
* @stable ICU 2.2
*/
inline UnicodeString& setTo(const UnicodeString& srcText,
int32_t srcStart);
/**
* Set the text in the UnicodeString object to the characters
* in <TT>srcText</TT> in the range
* [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
* <TT>srcText</TT> is not modified.
* @param srcText the source for the new characters
* @param srcStart the offset into <TT>srcText</TT> where new characters
* will be obtained
* @param srcLength the number of characters in <TT>srcText</TT> in the
* replace string.
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& setTo(const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength);
/**
* Set the text in the UnicodeString object to the characters in
* <TT>srcText</TT>.
* <TT>srcText</TT> is not modified.
* @param srcText the source for the new characters
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& setTo(const UnicodeString& srcText);
/**
* Set the characters in the UnicodeString object to the characters
* in <TT>srcChars</TT>. <TT>srcChars</TT> is not modified.
* @param srcChars the source for the new characters
* @param srcLength the number of Unicode characters in srcChars.
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& setTo(const UChar *srcChars,
int32_t srcLength);
/**
* Set the characters in the UnicodeString object to the code unit
* <TT>srcChar</TT>.
* @param srcChar the code unit which becomes the UnicodeString's character
* content
* @return a reference to this
* @stable ICU 2.0
*/
UnicodeString& setTo(UChar srcChar);
/**
* Set the characters in the UnicodeString object to the code point
* <TT>srcChar</TT>.
* @param srcChar the code point which becomes the UnicodeString's character
* content
* @return a reference to this
* @stable ICU 2.0
*/
UnicodeString& setTo(UChar32 srcChar);
/**
* Aliasing setTo() function, analogous to the readonly-aliasing UChar* constructor.
* The text will be used for the UnicodeString object, but
* it will not be released when the UnicodeString is destroyed.
* This has copy-on-write semantics:
* When the string is modified, then the buffer is first copied into
* newly allocated memory.
* The aliased buffer is never modified.
* In an assignment to another UnicodeString, the text will be aliased again,
* so that both strings then alias the same readonly-text.
*
* @param isTerminated specifies if <code>text</code> is <code>NUL</code>-terminated.
* This must be true if <code>textLength==-1</code>.
* @param text The characters to alias for the UnicodeString.
* @param textLength The number of Unicode characters in <code>text</code> to alias.
* If -1, then this constructor will determine the length
* by calling <code>u_strlen()</code>.
* @return a reference to this
* @stable ICU 2.0
*/
UnicodeString &setTo(UBool isTerminated,
const UChar *text,
int32_t textLength);
/**
* Aliasing setTo() function, analogous to the writable-aliasing UChar* constructor.
* The text will be used for the UnicodeString object, but
* it will not be released when the UnicodeString is destroyed.
* This has write-through semantics:
* For as long as the capacity of the buffer is sufficient, write operations
* will directly affect the buffer. When more capacity is necessary, then
* a new buffer will be allocated and the contents copied as with regularly
* constructed strings.
* In an assignment to another UnicodeString, the buffer will be copied.
* The extract(UChar *dst) function detects whether the dst pointer is the same
* as the string buffer itself and will in this case not copy the contents.
*
* @param buffer The characters to alias for the UnicodeString.
* @param buffLength The number of Unicode characters in <code>buffer</code> to alias.
* @param buffCapacity The size of <code>buffer</code> in UChars.
* @return a reference to this
* @stable ICU 2.0
*/
UnicodeString &setTo(UChar *buffer,
int32_t buffLength,
int32_t buffCapacity);
/**
* Make this UnicodeString object invalid.
* The string will test TRUE with isBogus().
*
* A bogus string has no value. It is different from an empty string.
* It can be used to indicate that no string value is available.
* getBuffer() and getTerminatedBuffer() return NULL, and
* length() returns 0.
*
* This utility function is used throughout the UnicodeString
* implementation to indicate that a UnicodeString operation failed,
* and may be used in other functions,
* especially but not exclusively when such functions do not
* take a UErrorCode for simplicity.
*
* The following methods, and no others, will clear a string object's bogus flag:
* - remove()
* - remove(0, INT32_MAX)
* - truncate(0)
* - operator=() (assignment operator)
* - setTo(...)
*
* The simplest ways to turn a bogus string into an empty one
* is to use the remove() function.
* Examples for other functions that are equivalent to "set to empty string":
* \code
* if(s.isBogus()) {
* s.remove(); // set to an empty string (remove all), or
* s.remove(0, INT32_MAX); // set to an empty string (remove all), or
* s.truncate(0); // set to an empty string (complete truncation), or
* s=UnicodeString(); // assign an empty string, or
* s.setTo((UChar32)-1); // set to a pseudo code point that is out of range, or
* static const UChar nul=0;
* s.setTo(&nul, 0); // set to an empty C Unicode string
* }
* \endcode
*
* @see isBogus()
* @stable ICU 2.0
*/
void setToBogus();
/**
* Set the character at the specified offset to the specified character.
* @param offset A valid offset into the text of the character to set
* @param ch The new character
* @return A reference to this
* @stable ICU 2.0
*/
UnicodeString& setCharAt(int32_t offset,
UChar ch);
/* Append operations */
/**
* Append operator. Append the code unit <TT>ch</TT> to the UnicodeString
* object.
* @param ch the code unit to be appended
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& operator+= (UChar ch);
/**
* Append operator. Append the code point <TT>ch</TT> to the UnicodeString
* object.
* @param ch the code point to be appended
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& operator+= (UChar32 ch);
/**
* Append operator. Append the characters in <TT>srcText</TT> to the
* UnicodeString object at offset <TT>start</TT>. <TT>srcText</TT> is
* not modified.
* @param srcText the source for the new characters
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& operator+= (const UnicodeString& srcText);
/**
* Append the characters
* in <TT>srcText</TT> in the range
* [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>) to the
* UnicodeString object at offset <TT>start</TT>. <TT>srcText</TT>
* is not modified.
* @param srcText the source for the new characters
* @param srcStart the offset into <TT>srcText</TT> where new characters
* will be obtained
* @param srcLength the number of characters in <TT>srcText</TT> in
* the append string
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& append(const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength);
/**
* Append the characters in <TT>srcText</TT> to the UnicodeString object at
* offset <TT>start</TT>. <TT>srcText</TT> is not modified.
* @param srcText the source for the new characters
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& append(const UnicodeString& srcText);
/**
* Append the characters in <TT>srcChars</TT> in the range
* [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>) to the UnicodeString
* object at offset
* <TT>start</TT>. <TT>srcChars</TT> is not modified.
* @param srcChars the source for the new characters
* @param srcStart the offset into <TT>srcChars</TT> where new characters
* will be obtained
* @param srcLength the number of characters in <TT>srcChars</TT> in
* the append string
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& append(const UChar *srcChars,
int32_t srcStart,
int32_t srcLength);
/**
* Append the characters in <TT>srcChars</TT> to the UnicodeString object
* at offset <TT>start</TT>. <TT>srcChars</TT> is not modified.
* @param srcChars the source for the new characters
* @param srcLength the number of Unicode characters in <TT>srcChars</TT>
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& append(const UChar *srcChars,
int32_t srcLength);
/**
* Append the code unit <TT>srcChar</TT> to the UnicodeString object.
* @param srcChar the code unit to append
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& append(UChar srcChar);
/**
* Append the code point <TT>srcChar</TT> to the UnicodeString object.
* @param srcChar the code point to append
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& append(UChar32 srcChar);
/* Insert operations */
/**
* Insert the characters in <TT>srcText</TT> in the range
* [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>) into the UnicodeString
* object at offset <TT>start</TT>. <TT>srcText</TT> is not modified.
* @param start the offset where the insertion begins
* @param srcText the source for the new characters
* @param srcStart the offset into <TT>srcText</TT> where new characters
* will be obtained
* @param srcLength the number of characters in <TT>srcText</TT> in
* the insert string
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& insert(int32_t start,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength);
/**
* Insert the characters in <TT>srcText</TT> into the UnicodeString object
* at offset <TT>start</TT>. <TT>srcText</TT> is not modified.
* @param start the offset where the insertion begins
* @param srcText the source for the new characters
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& insert(int32_t start,
const UnicodeString& srcText);
/**
* Insert the characters in <TT>srcChars</TT> in the range
* [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>) into the UnicodeString
* object at offset <TT>start</TT>. <TT>srcChars</TT> is not modified.
* @param start the offset at which the insertion begins
* @param srcChars the source for the new characters
* @param srcStart the offset into <TT>srcChars</TT> where new characters
* will be obtained
* @param srcLength the number of characters in <TT>srcChars</TT>
* in the insert string
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& insert(int32_t start,
const UChar *srcChars,
int32_t srcStart,
int32_t srcLength);
/**
* Insert the characters in <TT>srcChars</TT> into the UnicodeString object
* at offset <TT>start</TT>. <TT>srcChars</TT> is not modified.
* @param start the offset where the insertion begins
* @param srcChars the source for the new characters
* @param srcLength the number of Unicode characters in srcChars.
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& insert(int32_t start,
const UChar *srcChars,
int32_t srcLength);
/**
* Insert the code unit <TT>srcChar</TT> into the UnicodeString object at
* offset <TT>start</TT>.
* @param start the offset at which the insertion occurs
* @param srcChar the code unit to insert
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& insert(int32_t start,
UChar srcChar);
/**
* Insert the code point <TT>srcChar</TT> into the UnicodeString object at
* offset <TT>start</TT>.
* @param start the offset at which the insertion occurs
* @param srcChar the code point to insert
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& insert(int32_t start,
UChar32 srcChar);
/* Replace operations */
/**
* Replace the characters in the range
* [<TT>start</TT>, <TT>start + length</TT>) with the characters in
* <TT>srcText</TT> in the range
* [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
* <TT>srcText</TT> is not modified.
* @param start the offset at which the replace operation begins
* @param length the number of characters to replace. The character at
* <TT>start + length</TT> is not modified.
* @param srcText the source for the new characters
* @param srcStart the offset into <TT>srcText</TT> where new characters
* will be obtained
* @param srcLength the number of characters in <TT>srcText</TT> in
* the replace string
* @return a reference to this
* @stable ICU 2.0
*/
UnicodeString& replace(int32_t start,
int32_t length,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength);
/**
* Replace the characters in the range
* [<TT>start</TT>, <TT>start + length</TT>)
* with the characters in <TT>srcText</TT>. <TT>srcText</TT> is
* not modified.
* @param start the offset at which the replace operation begins
* @param length the number of characters to replace. The character at
* <TT>start + length</TT> is not modified.
* @param srcText the source for the new characters
* @return a reference to this
* @stable ICU 2.0
*/
UnicodeString& replace(int32_t start,
int32_t length,
const UnicodeString& srcText);
/**
* Replace the characters in the range
* [<TT>start</TT>, <TT>start + length</TT>) with the characters in
* <TT>srcChars</TT> in the range
* [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>). <TT>srcChars</TT>
* is not modified.
* @param start the offset at which the replace operation begins
* @param length the number of characters to replace. The character at
* <TT>start + length</TT> is not modified.
* @param srcChars the source for the new characters
* @param srcStart the offset into <TT>srcChars</TT> where new characters
* will be obtained
* @param srcLength the number of characters in <TT>srcChars</TT>
* in the replace string
* @return a reference to this
* @stable ICU 2.0
*/
UnicodeString& replace(int32_t start,
int32_t length,
const UChar *srcChars,
int32_t srcStart,
int32_t srcLength);
/**
* Replace the characters in the range
* [<TT>start</TT>, <TT>start + length</TT>) with the characters in
* <TT>srcChars</TT>. <TT>srcChars</TT> is not modified.
* @param start the offset at which the replace operation begins
* @param length number of characters to replace. The character at
* <TT>start + length</TT> is not modified.
* @param srcChars the source for the new characters
* @param srcLength the number of Unicode characters in srcChars
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& replace(int32_t start,
int32_t length,
const UChar *srcChars,
int32_t srcLength);
/**
* Replace the characters in the range
* [<TT>start</TT>, <TT>start + length</TT>) with the code unit
* <TT>srcChar</TT>.
* @param start the offset at which the replace operation begins
* @param length the number of characters to replace. The character at
* <TT>start + length</TT> is not modified.
* @param srcChar the new code unit
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& replace(int32_t start,
int32_t length,
UChar srcChar);
/**
* Replace the characters in the range
* [<TT>start</TT>, <TT>start + length</TT>) with the code point
* <TT>srcChar</TT>.
* @param start the offset at which the replace operation begins
* @param length the number of characters to replace. The character at
* <TT>start + length</TT> is not modified.
* @param srcChar the new code point
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& replace(int32_t start,
int32_t length,
UChar32 srcChar);
/**
* Replace the characters in the range [<TT>start</TT>, <TT>limit</TT>)
* with the characters in <TT>srcText</TT>. <TT>srcText</TT> is not modified.
* @param start the offset at which the replace operation begins
* @param limit the offset immediately following the replace range
* @param srcText the source for the new characters
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& replaceBetween(int32_t start,
int32_t limit,
const UnicodeString& srcText);
/**
* Replace the characters in the range [<TT>start</TT>, <TT>limit</TT>)
* with the characters in <TT>srcText</TT> in the range
* [<TT>srcStart</TT>, <TT>srcLimit</TT>). <TT>srcText</TT> is not modified.
* @param start the offset at which the replace operation begins
* @param limit the offset immediately following the replace range
* @param srcText the source for the new characters
* @param srcStart the offset into <TT>srcChars</TT> where new characters
* will be obtained
* @param srcLimit the offset immediately following the range to copy
* in <TT>srcText</TT>
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& replaceBetween(int32_t start,
int32_t limit,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLimit);
/**
* Replace a substring of this object with the given text.
* @param start the beginning index, inclusive; <code>0 <= start
* <= limit</code>.
* @param limit the ending index, exclusive; <code>start <= limit
* <= length()</code>.
* @param text the text to replace characters <code>start</code>
* to <code>limit - 1</code>
* @stable ICU 2.0
*/
virtual void handleReplaceBetween(int32_t start,
int32_t limit,
const UnicodeString& text);
/**
* Replaceable API
* @return TRUE if it has MetaData
* @stable ICU 2.4
*/
virtual UBool hasMetaData() const;
/**
* Copy a substring of this object, retaining attribute (out-of-band)
* information. This method is used to duplicate or reorder substrings.
* The destination index must not overlap the source range.
*
* @param start the beginning index, inclusive; <code>0 <= start <=
* limit</code>.
* @param limit the ending index, exclusive; <code>start <= limit <=
* length()</code>.
* @param dest the destination index. The characters from
* <code>start..limit-1</code> will be copied to <code>dest</code>.
* Implementations of this method may assume that <code>dest <= start ||
* dest >= limit</code>.
* @stable ICU 2.0
*/
virtual void copy(int32_t start, int32_t limit, int32_t dest);
/* Search and replace operations */
/**
* Replace all occurrences of characters in oldText with the characters
* in newText
* @param oldText the text containing the search text
* @param newText the text containing the replacement text
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& findAndReplace(const UnicodeString& oldText,
const UnicodeString& newText);
/**
* Replace all occurrences of characters in oldText with characters
* in newText
* in the range [<TT>start</TT>, <TT>start + length</TT>).
* @param start the start of the range in which replace will performed
* @param length the length of the range in which replace will be performed
* @param oldText the text containing the search text
* @param newText the text containing the replacement text
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& findAndReplace(int32_t start,
int32_t length,
const UnicodeString& oldText,
const UnicodeString& newText);
/**
* Replace all occurrences of characters in oldText in the range
* [<TT>oldStart</TT>, <TT>oldStart + oldLength</TT>) with the characters
* in newText in the range
* [<TT>newStart</TT>, <TT>newStart + newLength</TT>)
* in the range [<TT>start</TT>, <TT>start + length</TT>).
* @param start the start of the range in which replace will performed
* @param length the length of the range in which replace will be performed
* @param oldText the text containing the search text
* @param oldStart the start of the search range in <TT>oldText</TT>
* @param oldLength the length of the search range in <TT>oldText</TT>
* @param newText the text containing the replacement text
* @param newStart the start of the replacement range in <TT>newText</TT>
* @param newLength the length of the replacement range in <TT>newText</TT>
* @return a reference to this
* @stable ICU 2.0
*/
UnicodeString& findAndReplace(int32_t start,
int32_t length,
const UnicodeString& oldText,
int32_t oldStart,
int32_t oldLength,
const UnicodeString& newText,
int32_t newStart,
int32_t newLength);
/* Remove operations */
/**
* Remove all characters from the UnicodeString object.
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& remove(void);
/**
* Remove the characters in the range
* [<TT>start</TT>, <TT>start + length</TT>) from the UnicodeString object.
* @param start the offset of the first character to remove
* @param length the number of characters to remove
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& remove(int32_t start,
int32_t length = (int32_t)INT32_MAX);
/**
* Remove the characters in the range
* [<TT>start</TT>, <TT>limit</TT>) from the UnicodeString object.
* @param start the offset of the first character to remove
* @param limit the offset immediately following the range to remove
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& removeBetween(int32_t start,
int32_t limit = (int32_t)INT32_MAX);
/* Length operations */
/**
* Pad the start of this UnicodeString with the character <TT>padChar</TT>.
* If the length of this UnicodeString is less than targetLength,
* length() - targetLength copies of padChar will be added to the
* beginning of this UnicodeString.
* @param targetLength the desired length of the string
* @param padChar the character to use for padding. Defaults to
* space (U+0020)
* @return TRUE if the text was padded, FALSE otherwise.
* @stable ICU 2.0
*/
UBool padLeading(int32_t targetLength,
UChar padChar = 0x0020);
/**
* Pad the end of this UnicodeString with the character <TT>padChar</TT>.
* If the length of this UnicodeString is less than targetLength,
* length() - targetLength copies of padChar will be added to the
* end of this UnicodeString.
* @param targetLength the desired length of the string
* @param padChar the character to use for padding. Defaults to
* space (U+0020)
* @return TRUE if the text was padded, FALSE otherwise.
* @stable ICU 2.0
*/
UBool padTrailing(int32_t targetLength,
UChar padChar = 0x0020);
/**
* Truncate this UnicodeString to the <TT>targetLength</TT>.
* @param targetLength the desired length of this UnicodeString.
* @return TRUE if the text was truncated, FALSE otherwise
* @stable ICU 2.0
*/
inline UBool truncate(int32_t targetLength);
/**
* Trims leading and trailing whitespace from this UnicodeString.
* @return a reference to this
* @stable ICU 2.0
*/
UnicodeString& trim(void);
/* Miscellaneous operations */
/**
* Reverse this UnicodeString in place.
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& reverse(void);
/**
* Reverse the range [<TT>start</TT>, <TT>start + length</TT>) in
* this UnicodeString.
* @param start the start of the range to reverse
* @param length the number of characters to to reverse
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& reverse(int32_t start,
int32_t length);
/**
* Convert the characters in this to UPPER CASE following the conventions of
* the default locale.
* @return A reference to this.
* @stable ICU 2.0
*/
UnicodeString& toUpper(void);
/**
* Convert the characters in this to UPPER CASE following the conventions of
* a specific locale.
* @param locale The locale containing the conventions to use.
* @return A reference to this.
* @stable ICU 2.0
*/
UnicodeString& toUpper(const Locale& locale);
/**
* Convert the characters in this to lower case following the conventions of
* the default locale.
* @return A reference to this.
* @stable ICU 2.0
*/
UnicodeString& toLower(void);
/**
* Convert the characters in this to lower case following the conventions of
* a specific locale.
* @param locale The locale containing the conventions to use.
* @return A reference to this.
* @stable ICU 2.0
*/
UnicodeString& toLower(const Locale& locale);
#if !UCONFIG_NO_BREAK_ITERATION
/**
* Titlecase this string, convenience function using the default locale.
*
* Casing is locale-dependent and context-sensitive.
* Titlecasing uses a break iterator to find the first characters of words
* that are to be titlecased. It titlecases those characters and lowercases
* all others.
*
* The titlecase break iterator can be provided to customize for arbitrary
* styles, using rules and dictionaries beyond the standard iterators.
* It may be more efficient to always provide an iterator to avoid
* opening and closing one for each string.
* The standard titlecase iterator for the root locale implements the
* algorithm of Unicode TR 21.
*
* This function uses only the setText(), first() and next() methods of the
* provided break iterator.
*
* @param titleIter A break iterator to find the first characters of words
* that are to be titlecased.
* If none is provided (0), then a standard titlecase
* break iterator is opened.
* Otherwise the provided iterator is set to the string's text.
* @return A reference to this.
* @stable ICU 2.1
*/
UnicodeString &toTitle(BreakIterator *titleIter);
/**
* Titlecase this string.
*
* Casing is locale-dependent and context-sensitive.
* Titlecasing uses a break iterator to find the first characters of words
* that are to be titlecased. It titlecases those characters and lowercases
* all others.
*
* The titlecase break iterator can be provided to customize for arbitrary
* styles, using rules and dictionaries beyond the standard iterators.
* It may be more efficient to always provide an iterator to avoid
* opening and closing one for each string.
* The standard titlecase iterator for the root locale implements the
* algorithm of Unicode TR 21.
*
* This function uses only the setText(), first() and next() methods of the
* provided break iterator.
*
* @param titleIter A break iterator to find the first characters of words
* that are to be titlecased.
* If none is provided (0), then a standard titlecase
* break iterator is opened.
* Otherwise the provided iterator is set to the string's text.
* @param locale The locale to consider.
* @return A reference to this.
* @stable ICU 2.1
*/
UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale);
/**
* Titlecase this string, with options.
*
* Casing is locale-dependent and context-sensitive.
* Titlecasing uses a break iterator to find the first characters of words
* that are to be titlecased. It titlecases those characters and lowercases
* all others. (This can be modified with options.)
*
* The titlecase break iterator can be provided to customize for arbitrary
* styles, using rules and dictionaries beyond the standard iterators.
* It may be more efficient to always provide an iterator to avoid
* opening and closing one for each string.
* The standard titlecase iterator for the root locale implements the
* algorithm of Unicode TR 21.
*
* This function uses only the setText(), first() and next() methods of the
* provided break iterator.
*
* @param titleIter A break iterator to find the first characters of words
* that are to be titlecased.
* If none is provided (0), then a standard titlecase
* break iterator is opened.
* Otherwise the provided iterator is set to the string's text.
* @param locale The locale to consider.
* @param options Options bit set, see ucasemap_open().
* @return A reference to this.
* @see U_TITLECASE_NO_LOWERCASE
* @see U_TITLECASE_NO_BREAK_ADJUSTMENT
* @see ucasemap_open
* @draft ICU 3.8
*/
UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale, uint32_t options);
#endif
/**
* Case-fold the characters in this string.
* Case-folding is locale-independent and not context-sensitive,
* but there is an option for whether to include or exclude mappings for dotted I
* and dotless i that are marked with 'I' in CaseFolding.txt.
* The result may be longer or shorter than the original.
*
* @param options Either U_FOLD_CASE_DEFAULT or U_FOLD_CASE_EXCLUDE_SPECIAL_I
* @return A reference to this.
* @stable ICU 2.0
*/
UnicodeString &foldCase(uint32_t options=0 /*U_FOLD_CASE_DEFAULT*/);
//========================================
// Access to the internal buffer
//========================================
/**
* Get a read/write pointer to the internal buffer.
* The buffer is guaranteed to be large enough for at least minCapacity UChars,
* writable, and is still owned by the UnicodeString object.
* Calls to getBuffer(minCapacity) must not be nested, and
* must be matched with calls to releaseBuffer(newLength).
* If the string buffer was read-only or shared,
* then it will be reallocated and copied.
*
* An attempted nested call will return 0, and will not further modify the
* state of the UnicodeString object.
* It also returns 0 if the string is bogus.
*
* The actual capacity of the string buffer may be larger than minCapacity.
* getCapacity() returns the actual capacity.
* For many operations, the full capacity should be used to avoid reallocations.
*
* While the buffer is "open" between getBuffer(minCapacity)
* and releaseBuffer(newLength), the following applies:
* - The string length is set to 0.
* - Any read API call on the UnicodeString object will behave like on a 0-length string.
* - Any write API call on the UnicodeString object is disallowed and will have no effect.
* - You can read from and write to the returned buffer.
* - The previous string contents will still be in the buffer;
* if you want to use it, then you need to call length() before getBuffer(minCapacity).
* If the length() was greater than minCapacity, then any contents after minCapacity
* may be lost.
* The buffer contents is not NUL-terminated by getBuffer().
* If length()<getCapacity() then you can terminate it by writing a NUL
* at index length().
* - You must call releaseBuffer(newLength) before and in order to
* return to normal UnicodeString operation.
*
* @param minCapacity the minimum number of UChars that are to be available
* in the buffer, starting at the returned pointer;
* default to the current string capacity if minCapacity==-1
* @return a writable pointer to the internal string buffer,
* or 0 if an error occurs (nested calls, out of memory)
*
* @see releaseBuffer
* @see getTerminatedBuffer()
* @stable ICU 2.0
*/
UChar *getBuffer(int32_t minCapacity);
/**
* Release a read/write buffer on a UnicodeString object with an
* "open" getBuffer(minCapacity).
* This function must be called in a matched pair with getBuffer(minCapacity).
* releaseBuffer(newLength) must be called if and only if a getBuffer(minCapacity) is "open".
*
* It will set the string length to newLength, at most to the current capacity.
* If newLength==-1 then it will set the length according to the
* first NUL in the buffer, or to the capacity if there is no NUL.
*
* After calling releaseBuffer(newLength) the UnicodeString is back to normal operation.
*
* @param newLength the new length of the UnicodeString object;
* defaults to the current capacity if newLength is greater than that;
* if newLength==-1, it defaults to u_strlen(buffer) but not more than
* the current capacity of the string
*
* @see getBuffer(int32_t minCapacity)
* @stable ICU 2.0
*/
void releaseBuffer(int32_t newLength=-1);
/**
* Get a read-only pointer to the internal buffer.
* This can be called at any time on a valid UnicodeString.
*
* It returns 0 if the string is bogus, or
* during an "open" getBuffer(minCapacity).
*
* It can be called as many times as desired.
* The pointer that it returns will remain valid until the UnicodeString object is modified,
* at which time the pointer is semantically invalidated and must not be used any more.
*
* The capacity of the buffer can be determined with getCapacity().
* The part after length() may or may not be initialized and valid,
* depending on the history of the UnicodeString object.
*
* The buffer contents is (probably) not NUL-terminated.
* You can check if it is with
* <code>(s.length()<s.getCapacity() && buffer[s.length()]==0)</code>.
* (See getTerminatedBuffer().)
*
* The buffer may reside in read-only memory. Its contents must not
* be modified.
*
* @return a read-only pointer to the internal string buffer,
* or 0 if the string is empty or bogus
*
* @see getBuffer(int32_t minCapacity)
* @see getTerminatedBuffer()
* @stable ICU 2.0
*/
inline const UChar *getBuffer() const;
/**
* Get a read-only pointer to the internal buffer,
* making sure that it is NUL-terminated.
* This can be called at any time on a valid UnicodeString.
*
* It returns 0 if the string is bogus, or
* during an "open" getBuffer(minCapacity), or if the buffer cannot
* be NUL-terminated (because memory allocation failed).
*
* It can be called as many times as desired.
* The pointer that it returns will remain valid until the UnicodeString object is modified,
* at which time the pointer is semantically invalidated and must not be used any more.
*
* The capacity of the buffer can be determined with getCapacity().
* The part after length()+1 may or may not be initialized and valid,
* depending on the history of the UnicodeString object.
*
* The buffer contents is guaranteed to be NUL-terminated.
* getTerminatedBuffer() may reallocate the buffer if a terminating NUL
* is written.
* For this reason, this function is not const, unlike getBuffer().
* Note that a UnicodeString may also contain NUL characters as part of its contents.
*
* The buffer may reside in read-only memory. Its contents must not
* be modified.
*
* @return a read-only pointer to the internal string buffer,
* or 0 if the string is empty or bogus
*
* @see getBuffer(int32_t minCapacity)
* @see getBuffer()
* @stable ICU 2.2
*/
inline const UChar *getTerminatedBuffer();
//========================================
// Constructors
//========================================
/** Construct an empty UnicodeString.
* @stable ICU 2.0
*/
UnicodeString();
/**
* Construct a UnicodeString with capacity to hold <TT>capacity</TT> UChars
* @param capacity the number of UChars this UnicodeString should hold
* before a resize is necessary; if count is greater than 0 and count
* code points c take up more space than capacity, then capacity is adjusted
* accordingly.
* @param c is used to initially fill the string
* @param count specifies how many code points c are to be written in the
* string
* @stable ICU 2.0
*/
UnicodeString(int32_t capacity, UChar32 c, int32_t count);
/**
* Single UChar (code unit) constructor.
* @param ch the character to place in the UnicodeString
* @stable ICU 2.0
*/
UnicodeString(UChar ch);
/**
* Single UChar32 (code point) constructor.
* @param ch the character to place in the UnicodeString
* @stable ICU 2.0
*/
UnicodeString(UChar32 ch);
/**
* UChar* constructor.
* @param text The characters to place in the UnicodeString. <TT>text</TT>
* must be NULL (U+0000) terminated.
* @stable ICU 2.0
*/
UnicodeString(const UChar *text);
/**
* UChar* constructor.
* @param text The characters to place in the UnicodeString.
* @param textLength The number of Unicode characters in <TT>text</TT>
* to copy.
* @stable ICU 2.0
*/
UnicodeString(const UChar *text,
int32_t textLength);
/**
* Readonly-aliasing UChar* constructor.
* The text will be used for the UnicodeString object, but
* it will not be released when the UnicodeString is destroyed.
* This has copy-on-write semantics:
* When the string is modified, then the buffer is first copied into
* newly allocated memory.
* The aliased buffer is never modified.
* In an assignment to another UnicodeString, the text will be aliased again,
* so that both strings then alias the same readonly-text.
*
* @param isTerminated specifies if <code>text</code> is <code>NUL</code>-terminated.
* This must be true if <code>textLength==-1</code>.
* @param text The characters to alias for the UnicodeString.
* @param textLength The number of Unicode characters in <code>text</code> to alias.
* If -1, then this constructor will determine the length
* by calling <code>u_strlen()</code>.
* @stable ICU 2.0
*/
UnicodeString(UBool isTerminated,
const UChar *text,
int32_t textLength);
/**
* Writable-aliasing UChar* constructor.
* The text will be used for the UnicodeString object, but
* it will not be released when the UnicodeString is destroyed.
* This has write-through semantics:
* For as long as the capacity of the buffer is sufficient, write operations
* will directly affect the buffer. When more capacity is necessary, then
* a new buffer will be allocated and the contents copied as with regularly
* constructed strings.
* In an assignment to another UnicodeString, the buffer will be copied.
* The extract(UChar *dst) function detects whether the dst pointer is the same
* as the string buffer itself and will in this case not copy the contents.
*
* @param buffer The characters to alias for the UnicodeString.
* @param buffLength The number of Unicode characters in <code>buffer</code> to alias.
* @param buffCapacity The size of <code>buffer</code> in UChars.
* @stable ICU 2.0
*/
UnicodeString(UChar *buffer, int32_t buffLength, int32_t buffCapacity);
#if !UCONFIG_NO_CONVERSION
/**
* char* constructor.
* @param codepageData an array of bytes, null-terminated
* @param codepage the encoding of <TT>codepageData</TT>. The special
* value 0 for <TT>codepage</TT> indicates that the text is in the
* platform's default codepage.
*
* If <code>codepage</code> is an empty string (<code>""</code>),
* then a simple conversion is performed on the codepage-invariant
* subset ("invariant characters") of the platform encoding. See utypes.h.
* Recommendation: For invariant-character strings use the constructor
* UnicodeString(const char *src, int32_t length, enum EInvariant inv)
* because it avoids object code dependencies of UnicodeString on
* the conversion code.
*
* @stable ICU 2.0
*/
UnicodeString(const char *codepageData,
const char *codepage = 0);
/**
* char* constructor.
* @param codepageData an array of bytes.
* @param dataLength The number of bytes in <TT>codepageData</TT>.
* @param codepage the encoding of <TT>codepageData</TT>. The special
* value 0 for <TT>codepage</TT> indicates that the text is in the
* platform's default codepage.
* If <code>codepage</code> is an empty string (<code>""</code>),
* then a simple conversion is performed on the codepage-invariant
* subset ("invariant characters") of the platform encoding. See utypes.h.
* Recommendation: For invariant-character strings use the constructor
* UnicodeString(const char *src, int32_t length, enum EInvariant inv)
* because it avoids object code dependencies of UnicodeString on
* the conversion code.
*
* @stable ICU 2.0
*/
UnicodeString(const char *codepageData,
int32_t dataLength,
const char *codepage = 0);
/**
* char * / UConverter constructor.
* This constructor uses an existing UConverter object to
* convert the codepage string to Unicode and construct a UnicodeString
* from that.
*
* The converter is reset at first.
* If the error code indicates a failure before this constructor is called,
* or if an error occurs during conversion or construction,
* then the string will be bogus.
*
* This function avoids the overhead of opening and closing a converter if
* multiple strings are constructed.
*
* @param src input codepage string
* @param srcLength length of the input string, can be -1 for NUL-terminated strings
* @param cnv converter object (ucnv_resetToUnicode() will be called),
* can be NULL for the default converter
* @param errorCode normal ICU error code
* @stable ICU 2.0
*/
UnicodeString(
const char *src, int32_t srcLength,
UConverter *cnv,
UErrorCode &errorCode);
#endif
/**
* Constructs a Unicode string from an invariant-character char * string.
* About invariant characters see utypes.h.
* This constructor has no runtime dependency on conversion code and is
* therefore recommended over ones taking a charset name string
* (where the empty string "" indicates invariant-character conversion).
*
* Use the macro US_INV as the third, signature-distinguishing parameter.
*
* For example:
* \code
* void fn(const char *s) {
* UnicodeString ustr(s, -1, US_INV);
* // use ustr ...
* }
* \endcode
*
* @param src String using only invariant characters.
* @param length Length of src, or -1 if NUL-terminated.
* @param inv Signature-distinguishing paramater, use US_INV.
*
* @see US_INV
* @stable ICU 3.2
*/
UnicodeString(const char *src, int32_t length, enum EInvariant inv);
/**
* Copy constructor.
* @param that The UnicodeString object to copy.
* @stable ICU 2.0
*/
UnicodeString(const UnicodeString& that);
/**
* 'Substring' constructor from tail of source string.
* @param src The UnicodeString object to copy.
* @param srcStart The offset into <tt>src</tt> at which to start copying.
* @stable ICU 2.2
*/
UnicodeString(const UnicodeString& src, int32_t srcStart);
/**
* 'Substring' constructor from subrange of source string.
* @param src The UnicodeString object to copy.
* @param srcStart The offset into <tt>src</tt> at which to start copying.
* @param srcLength The number of characters from <tt>src</tt> to copy.
* @stable ICU 2.2
*/
UnicodeString(const UnicodeString& src, int32_t srcStart, int32_t srcLength);
/**
* Clone this object, an instance of a subclass of Replaceable.
* Clones can be used concurrently in multiple threads.
* If a subclass does not implement clone(), or if an error occurs,
* then NULL is returned.
* The clone functions in all subclasses return a pointer to a Replaceable
* because some compilers do not support covariant (same-as-this)
* return types; cast to the appropriate subclass if necessary.
* The caller must delete the clone.
*
* @return a clone of this object
*
* @see Replaceable::clone
* @see getDynamicClassID
* @stable ICU 2.6
*/
virtual Replaceable *clone() const;
/** Destructor.
* @stable ICU 2.0
*/
virtual ~UnicodeString();
/* Miscellaneous operations */
/**
* Unescape a string of characters and return a string containing
* the result. The following escape sequences are recognized:
*
* \\uhhhh 4 hex digits; h in [0-9A-Fa-f]
* \\Uhhhhhhhh 8 hex digits
* \\xhh 1-2 hex digits
* \\ooo 1-3 octal digits; o in [0-7]
* \\cX control-X; X is masked with 0x1F
*
* as well as the standard ANSI C escapes:
*
* \\a => U+0007, \\b => U+0008, \\t => U+0009, \\n => U+000A,
* \\v => U+000B, \\f => U+000C, \\r => U+000D, \\e => U+001B,
* \\" => U+0022, \\' => U+0027, \\? => U+003F, \\\\ => U+005C
*
* Anything else following a backslash is generically escaped. For
* example, "[a\\-z]" returns "[a-z]".
*
* If an escape sequence is ill-formed, this method returns an empty
* string. An example of an ill-formed sequence is "\\u" followed by
* fewer than 4 hex digits.
*
* This function is similar to u_unescape() but not identical to it.
* The latter takes a source char*, so it does escape recognition
* and also invariant conversion.
*
* @return a string with backslash escapes interpreted, or an
* empty string on error.
* @see UnicodeString#unescapeAt()
* @see u_unescape()
* @see u_unescapeAt()
* @stable ICU 2.0
*/
UnicodeString unescape() const;
/**
* Unescape a single escape sequence and return the represented
* character. See unescape() for a listing of the recognized escape
* sequences. The character at offset-1 is assumed (without
* checking) to be a backslash. If the escape sequence is
* ill-formed, or the offset is out of range, (UChar32)0xFFFFFFFF is
* returned.
*
* @param offset an input output parameter. On input, it is the
* offset into this string where the escape sequence is located,
* after the initial backslash. On output, it is advanced after the
* last character parsed. On error, it is not advanced at all.
* @return the character represented by the escape sequence at
* offset, or (UChar32)0xFFFFFFFF on error.
* @see UnicodeString#unescape()
* @see u_unescape()
* @see u_unescapeAt()
* @stable ICU 2.0
*/
UChar32 unescapeAt(int32_t &offset) const;
/**
* ICU "poor man's RTTI", returns a UClassID for this class.
*
* @stable ICU 2.2
*/
static UClassID U_EXPORT2 getStaticClassID();
/**
* ICU "poor man's RTTI", returns a UClassID for the actual class.
*
* @stable ICU 2.2
*/
virtual UClassID getDynamicClassID() const;
//========================================
// Implementation methods
//========================================
protected:
/**
* Implement Replaceable::getLength() (see jitterbug 1027).
* @stable ICU 2.4
*/
virtual int32_t getLength() const;
/**
* The change in Replaceable to use virtual getCharAt() allows
* UnicodeString::charAt() to be inline again (see jitterbug 709).
* @stable ICU 2.4
*/
virtual UChar getCharAt(int32_t offset) const;
/**
* The change in Replaceable to use virtual getChar32At() allows
* UnicodeString::char32At() to be inline again (see jitterbug 709).
* @stable ICU 2.4
*/
virtual UChar32 getChar32At(int32_t offset) const;
private:
inline int8_t
doCompare(int32_t start,
int32_t length,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength) const;
int8_t doCompare(int32_t start,
int32_t length,
const UChar *srcChars,
int32_t srcStart,
int32_t srcLength) const;
inline int8_t
doCompareCodePointOrder(int32_t start,
int32_t length,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength) const;
int8_t doCompareCodePointOrder(int32_t start,
int32_t length,
const UChar *srcChars,
int32_t srcStart,
int32_t srcLength) const;
inline int8_t
doCaseCompare(int32_t start,
int32_t length,
const UnicodeString &srcText,
int32_t srcStart,
int32_t srcLength,
uint32_t options) const;
int8_t
doCaseCompare(int32_t start,
int32_t length,
const UChar *srcChars,
int32_t srcStart,
int32_t srcLength,
uint32_t options) const;
int32_t doIndexOf(UChar c,
int32_t start,
int32_t length) const;
int32_t doIndexOf(UChar32 c,
int32_t start,
int32_t length) const;
int32_t doLastIndexOf(UChar c,
int32_t start,
int32_t length) const;
int32_t doLastIndexOf(UChar32 c,
int32_t start,
int32_t length) const;
void doExtract(int32_t start,
int32_t length,
UChar *dst,
int32_t dstStart) const;
inline void doExtract(int32_t start,
int32_t length,
UnicodeString& target) const;
inline UChar doCharAt(int32_t offset) const;
UnicodeString& doReplace(int32_t start,
int32_t length,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength);
UnicodeString& doReplace(int32_t start,
int32_t length,
const UChar *srcChars,
int32_t srcStart,
int32_t srcLength);
UnicodeString& doReverse(int32_t start,
int32_t length);
// calculate hash code
int32_t doHashCode(void) const;
// get pointer to start of array
inline UChar* getArrayStart(void);
inline const UChar* getArrayStart(void) const;
// allocate the array; result may be fStackBuffer
// sets refCount to 1 if appropriate
// sets fArray, fCapacity, and fFlags
// returns boolean for success or failure
UBool allocate(int32_t capacity);
// release the array if owned
void releaseArray(void);
// turn a bogus string into an empty one
void unBogus();
// implements assigment operator, copy constructor, and fastCopyFrom()
UnicodeString ©From(const UnicodeString &src, UBool fastCopy=FALSE);
// Pin start and limit to acceptable values.
inline void pinIndex(int32_t& start) const;
inline void pinIndices(int32_t& start,
int32_t& length) const;
#if !UCONFIG_NO_CONVERSION
/* Internal extract() using UConverter. */
int32_t doExtract(int32_t start, int32_t length,
char *dest, int32_t destCapacity,
UConverter *cnv,
UErrorCode &errorCode) const;
/*
* Real constructor for converting from codepage data.
* It assumes that it is called with !fRefCounted.
*
* If <code>codepage==0</code>, then the default converter
* is used for the platform encoding.
* If <code>codepage</code> is an empty string (<code>""</code>),
* then a simple conversion is performed on the codepage-invariant
* subset ("invariant characters") of the platform encoding. See utypes.h.
*/
void doCodepageCreate(const char *codepageData,
int32_t dataLength,
const char *codepage);
/*
* Worker function for creating a UnicodeString from
* a codepage string using a UConverter.
*/
void
doCodepageCreate(const char *codepageData,
int32_t dataLength,
UConverter *converter,
UErrorCode &status);
#endif
/*
* This function is called when write access to the array
* is necessary.
*
* We need to make a copy of the array if
* the buffer is read-only, or
* the buffer is refCounted (shared), and refCount>1, or
* the buffer is too small.
*
* Return FALSE if memory could not be allocated.
*/
UBool cloneArrayIfNeeded(int32_t newCapacity = -1,
int32_t growCapacity = -1,
UBool doCopyArray = TRUE,
int32_t **pBufferToDelete = 0,
UBool forceClone = FALSE);
// common function for case mappings
UnicodeString &
caseMap(BreakIterator *titleIter,
const char *locale,
uint32_t options,
int32_t toWhichCase);
// ref counting
void addRef(void);
int32_t removeRef(void);
int32_t refCount(void) const;
// constants
enum {
US_STACKBUF_SIZE=7, // Size of stack buffer for small strings
kInvalidUChar=0xffff, // invalid UChar index
kGrowSize=128, // grow size for this buffer
kInvalidHashCode=0, // invalid hash code
kEmptyHashCode=1, // hash code for empty string
// bit flag values for fFlags
kIsBogus=1, // this string is bogus, i.e., not valid or NULL
kUsingStackBuffer=2,// fArray==fStackBuffer
kRefCounted=4, // there is a refCount field before the characters in fArray
kBufferIsReadonly=8,// do not write to this buffer
kOpenGetBuffer=16, // getBuffer(minCapacity) was called (is "open"),
// and releaseBuffer(newLength) must be called
// combined values for convenience
kShortString=kUsingStackBuffer,
kLongString=kRefCounted,
kReadonlyAlias=kBufferIsReadonly,
kWritableAlias=0
};
friend class StringCharacterIterator;
friend class StringThreadTest;
/*
* The following are all the class fields that are stored
* in each UnicodeString object.
* Note that UnicodeString has virtual functions,
* therefore there is an implicit vtable pointer
* as the first real field.
* The fields should be aligned such that no padding is
* necessary, mostly by having larger types first.
* On 32-bit machines, the size should be 32 bytes,
* on 64-bit machines (8-byte pointers), it should be 40 bytes.
*/
// (implicit) *vtable;
int32_t fLength; // number of characters in fArray
int32_t fCapacity; // sizeof fArray
UChar *fArray; // the Unicode data
uint16_t fFlags; // bit flags: see constants above
UChar fStackBuffer [ US_STACKBUF_SIZE ]; // buffer for small strings
};
/**
* Create a new UnicodeString with the concatenation of two others.
*
* @param s1 The first string to be copied to the new one.
* @param s2 The second string to be copied to the new one, after s1.
* @return UnicodeString(s1).append(s2)
* @stable ICU 2.8
*/
U_COMMON_API UnicodeString U_EXPORT2
operator+ (const UnicodeString &s1, const UnicodeString &s2);
//========================================
// Inline members
//========================================
//========================================
// Privates
//========================================
inline void
UnicodeString::pinIndex(int32_t& start) const
{
// pin index
if(start < 0) {
start = 0;
} else if(start > fLength) {
start = fLength;
}
}
inline void
UnicodeString::pinIndices(int32_t& start,
int32_t& _length) const
{
// pin indices
if(start < 0) {
start = 0;
} else if(start > fLength) {
start = fLength;
}
if(_length < 0) {
_length = 0;
} else if(_length > (fLength - start)) {
_length = (fLength - start);
}
}
inline UChar*
UnicodeString::getArrayStart()
{ return fArray; }
inline const UChar*
UnicodeString::getArrayStart() const
{ return fArray; }
//========================================
// Read-only implementation methods
//========================================
inline int32_t
UnicodeString::length() const
{ return fLength; }
inline int32_t
UnicodeString::getCapacity() const
{ return fCapacity; }
inline int32_t
UnicodeString::hashCode() const
{ return doHashCode(); }
inline UBool
UnicodeString::isBogus() const
{ return (UBool)(fFlags & kIsBogus); }
inline const UChar *
UnicodeString::getBuffer() const {
if(!(fFlags&(kIsBogus|kOpenGetBuffer))) {
return fArray;
} else {
return 0;
}
}
//========================================
// Read-only alias methods
//========================================
inline int8_t
UnicodeString::doCompare(int32_t start,
int32_t length,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength) const
{
if(srcText.isBogus()) {
return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
} else {
srcText.pinIndices(srcStart, srcLength);
return doCompare(start, length, srcText.fArray, srcStart, srcLength);
}
}
inline UBool
UnicodeString::operator== (const UnicodeString& text) const
{
if(isBogus()) {
return text.isBogus();
} else {
return
!text.isBogus() &&
fLength == text.fLength &&
doCompare(0, fLength, text, 0, text.fLength) == 0;
}
}
inline UBool
UnicodeString::operator!= (const UnicodeString& text) const
{ return (! operator==(text)); }
inline UBool
UnicodeString::operator> (const UnicodeString& text) const
{ return doCompare(0, fLength, text, 0, text.fLength) == 1; }
inline UBool
UnicodeString::operator< (const UnicodeString& text) const
{ return doCompare(0, fLength, text, 0, text.fLength) == -1; }
inline UBool
UnicodeString::operator>= (const UnicodeString& text) const
{ return doCompare(0, fLength, text, 0, text.fLength) != -1; }
inline UBool
UnicodeString::operator<= (const UnicodeString& text) const
{ return doCompare(0, fLength, text, 0, text.fLength) != 1; }
inline int8_t
UnicodeString::compare(const UnicodeString& text) const
{ return doCompare(0, fLength, text, 0, text.fLength); }
inline int8_t
UnicodeString::compare(int32_t start,
int32_t _length,
const UnicodeString& srcText) const
{ return doCompare(start, _length, srcText, 0, srcText.fLength); }
inline int8_t
UnicodeString::compare(const UChar *srcChars,
int32_t srcLength) const
{ return doCompare(0, fLength, srcChars, 0, srcLength); }
inline int8_t
UnicodeString::compare(int32_t start,
int32_t _length,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength) const
{ return doCompare(start, _length, srcText, srcStart, srcLength); }
inline int8_t
UnicodeString::compare(int32_t start,
int32_t _length,
const UChar *srcChars) const
{ return doCompare(start, _length, srcChars, 0, _length); }
inline int8_t
UnicodeString::compare(int32_t start,
int32_t _length,
const UChar *srcChars,
int32_t srcStart,
int32_t srcLength) const
{ return doCompare(start, _length, srcChars, srcStart, srcLength); }
inline int8_t
UnicodeString::compareBetween(int32_t start,
int32_t limit,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLimit) const
{ return doCompare(start, limit - start,
srcText, srcStart, srcLimit - srcStart); }
inline int8_t
UnicodeString::doCompareCodePointOrder(int32_t start,
int32_t length,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength) const
{
if(srcText.isBogus()) {
return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
} else {
srcText.pinIndices(srcStart, srcLength);
return doCompareCodePointOrder(start, length, srcText.fArray, srcStart, srcLength);
}
}
inline int8_t
UnicodeString::compareCodePointOrder(const UnicodeString& text) const
{ return doCompareCodePointOrder(0, fLength, text, 0, text.fLength); }
inline int8_t
UnicodeString::compareCodePointOrder(int32_t start,
int32_t _length,
const UnicodeString& srcText) const
{ return doCompareCodePointOrder(start, _length, srcText, 0, srcText.fLength); }
inline int8_t
UnicodeString::compareCodePointOrder(const UChar *srcChars,
int32_t srcLength) const
{ return doCompareCodePointOrder(0, fLength, srcChars, 0, srcLength); }
inline int8_t
UnicodeString::compareCodePointOrder(int32_t start,
int32_t _length,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength) const
{ return doCompareCodePointOrder(start, _length, srcText, srcStart, srcLength); }
inline int8_t
UnicodeString::compareCodePointOrder(int32_t start,
int32_t _length,
const UChar *srcChars) const
{ return doCompareCodePointOrder(start, _length, srcChars, 0, _length); }
inline int8_t
UnicodeString::compareCodePointOrder(int32_t start,
int32_t _length,
const UChar *srcChars,
int32_t srcStart,
int32_t srcLength) const
{ return doCompareCodePointOrder(start, _length, srcChars, srcStart, srcLength); }
inline int8_t
UnicodeString::compareCodePointOrderBetween(int32_t start,
int32_t limit,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLimit) const
{ return doCompareCodePointOrder(start, limit - start,
srcText, srcStart, srcLimit - srcStart); }
inline int8_t
UnicodeString::doCaseCompare(int32_t start,
int32_t length,
const UnicodeString &srcText,
int32_t srcStart,
int32_t srcLength,
uint32_t options) const
{
if(srcText.isBogus()) {
return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
} else {
srcText.pinIndices(srcStart, srcLength);
return doCaseCompare(start, length, srcText.fArray, srcStart, srcLength, options);
}
}
inline int8_t
UnicodeString::caseCompare(const UnicodeString &text, uint32_t options) const {
return doCaseCompare(0, fLength, text, 0, text.fLength, options);
}
inline int8_t
UnicodeString::caseCompare(int32_t start,
int32_t _length,
const UnicodeString &srcText,
uint32_t options) const {
return doCaseCompare(start, _length, srcText, 0, srcText.fLength, options);
}
inline int8_t
UnicodeString::caseCompare(const UChar *srcChars,
int32_t srcLength,
uint32_t options) const {
return doCaseCompare(0, fLength, srcChars, 0, srcLength, options);
}
inline int8_t
UnicodeString::caseCompare(int32_t start,
int32_t _length,
const UnicodeString &srcText,
int32_t srcStart,
int32_t srcLength,
uint32_t options) const {
return doCaseCompare(start, _length, srcText, srcStart, srcLength, options);
}
inline int8_t
UnicodeString::caseCompare(int32_t start,
int32_t _length,
const UChar *srcChars,
uint32_t options) const {
return doCaseCompare(start, _length, srcChars, 0, _length, options);
}
inline int8_t
UnicodeString::caseCompare(int32_t start,
int32_t _length,
const UChar *srcChars,
int32_t srcStart,
int32_t srcLength,
uint32_t options) const {
return doCaseCompare(start, _length, srcChars, srcStart, srcLength, options);
}
inline int8_t
UnicodeString::caseCompareBetween(int32_t start,
int32_t limit,
const UnicodeString &srcText,
int32_t srcStart,
int32_t srcLimit,
uint32_t options) const {
return doCaseCompare(start, limit - start, srcText, srcStart, srcLimit - srcStart, options);
}
inline int32_t
UnicodeString::indexOf(const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength,
int32_t start,
int32_t _length) const
{
if(!srcText.isBogus()) {
srcText.pinIndices(srcStart, srcLength);
if(srcLength > 0) {
return indexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
}
}
return -1;
}
inline int32_t
UnicodeString::indexOf(const UnicodeString& text) const
{ return indexOf(text, 0, text.fLength, 0, fLength); }
inline int32_t
UnicodeString::indexOf(const UnicodeString& text,
int32_t start) const {
pinIndex(start);
return indexOf(text, 0, text.fLength, start, fLength - start);
}
inline int32_t
UnicodeString::indexOf(const UnicodeString& text,
int32_t start,
int32_t _length) const
{ return indexOf(text, 0, text.fLength, start, _length); }
inline int32_t
UnicodeString::indexOf(const UChar *srcChars,
int32_t srcLength,
int32_t start) const {
pinIndex(start);
return indexOf(srcChars, 0, srcLength, start, fLength - start);
}
inline int32_t
UnicodeString::indexOf(const UChar *srcChars,
int32_t srcLength,
int32_t start,
int32_t _length) const
{ return indexOf(srcChars, 0, srcLength, start, _length); }
inline int32_t
UnicodeString::indexOf(UChar c,
int32_t start,
int32_t _length) const
{ return doIndexOf(c, start, _length); }
inline int32_t
UnicodeString::indexOf(UChar32 c,
int32_t start,
int32_t _length) const
{ return doIndexOf(c, start, _length); }
inline int32_t
UnicodeString::indexOf(UChar c) const
{ return doIndexOf(c, 0, fLength); }
inline int32_t
UnicodeString::indexOf(UChar32 c) const
{ return indexOf(c, 0, fLength); }
inline int32_t
UnicodeString::indexOf(UChar c,
int32_t start) const {
pinIndex(start);
return doIndexOf(c, start, fLength - start);
}
inline int32_t
UnicodeString::indexOf(UChar32 c,
int32_t start) const {
pinIndex(start);
return indexOf(c, start, fLength - start);
}
inline int32_t
UnicodeString::lastIndexOf(const UChar *srcChars,
int32_t srcLength,
int32_t start,
int32_t _length) const
{ return lastIndexOf(srcChars, 0, srcLength, start, _length); }
inline int32_t
UnicodeString::lastIndexOf(const UChar *srcChars,
int32_t srcLength,
int32_t start) const {
pinIndex(start);
return lastIndexOf(srcChars, 0, srcLength, start, fLength - start);
}
inline int32_t
UnicodeString::lastIndexOf(const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength,
int32_t start,
int32_t _length) const
{
if(!srcText.isBogus()) {
srcText.pinIndices(srcStart, srcLength);
if(srcLength > 0) {
return lastIndexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
}
}
return -1;
}
inline int32_t
UnicodeString::lastIndexOf(const UnicodeString& text,
int32_t start,
int32_t _length) const
{ return lastIndexOf(text, 0, text.fLength, start, _length); }
inline int32_t
UnicodeString::lastIndexOf(const UnicodeString& text,
int32_t start) const {
pinIndex(start);
return lastIndexOf(text, 0, text.fLength, start, fLength - start);
}
inline int32_t
UnicodeString::lastIndexOf(const UnicodeString& text) const
{ return lastIndexOf(text, 0, text.fLength, 0, fLength); }
inline int32_t
UnicodeString::lastIndexOf(UChar c,
int32_t start,
int32_t _length) const
{ return doLastIndexOf(c, start, _length); }
inline int32_t
UnicodeString::lastIndexOf(UChar32 c,
int32_t start,
int32_t _length) const {
return doLastIndexOf(c, start, _length);
}
inline int32_t
UnicodeString::lastIndexOf(UChar c) const
{ return doLastIndexOf(c, 0, fLength); }
inline int32_t
UnicodeString::lastIndexOf(UChar32 c) const {
return lastIndexOf(c, 0, fLength);
}
inline int32_t
UnicodeString::lastIndexOf(UChar c,
int32_t start) const {
pinIndex(start);
return doLastIndexOf(c, start, fLength - start);
}
inline int32_t
UnicodeString::lastIndexOf(UChar32 c,
int32_t start) const {
pinIndex(start);
return lastIndexOf(c, start, fLength - start);
}
inline UBool
UnicodeString::startsWith(const UnicodeString& text) const
{ return compare(0, text.fLength, text, 0, text.fLength) == 0; }
inline UBool
UnicodeString::startsWith(const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength) const
{ return doCompare(0, srcLength, srcText, srcStart, srcLength) == 0; }
inline UBool
UnicodeString::startsWith(const UChar *srcChars,
int32_t srcLength) const
{ return doCompare(0, srcLength, srcChars, 0, srcLength) == 0; }
inline UBool
UnicodeString::startsWith(const UChar *srcChars,
int32_t srcStart,
int32_t srcLength) const
{ return doCompare(0, srcLength, srcChars, srcStart, srcLength) == 0;}
inline UBool
UnicodeString::endsWith(const UnicodeString& text) const
{ return doCompare(fLength - text.fLength, text.fLength,
text, 0, text.fLength) == 0; }
inline UBool
UnicodeString::endsWith(const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength) const {
srcText.pinIndices(srcStart, srcLength);
return doCompare(fLength - srcLength, srcLength,
srcText, srcStart, srcLength) == 0;
}
inline UBool
UnicodeString::endsWith(const UChar *srcChars,
int32_t srcLength) const {
if(srcLength < 0) {
srcLength = u_strlen(srcChars);
}
return doCompare(fLength - srcLength, srcLength,
srcChars, 0, srcLength) == 0;
}
inline UBool
UnicodeString::endsWith(const UChar *srcChars,
int32_t srcStart,
int32_t srcLength) const {
if(srcLength < 0) {
srcLength = u_strlen(srcChars + srcStart);
}
return doCompare(fLength - srcLength, srcLength,
srcChars, srcStart, srcLength) == 0;
}
//========================================
// replace
//========================================
inline UnicodeString&
UnicodeString::replace(int32_t start,
int32_t _length,
const UnicodeString& srcText)
{ return doReplace(start, _length, srcText, 0, srcText.fLength); }
inline UnicodeString&
UnicodeString::replace(int32_t start,
int32_t _length,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength)
{ return doReplace(start, _length, srcText, srcStart, srcLength); }
inline UnicodeString&
UnicodeString::replace(int32_t start,
int32_t _length,
const UChar *srcChars,
int32_t srcLength)
{ return doReplace(start, _length, srcChars, 0, srcLength); }
inline UnicodeString&
UnicodeString::replace(int32_t start,
int32_t _length,
const UChar *srcChars,
int32_t srcStart,
int32_t srcLength)
{ return doReplace(start, _length, srcChars, srcStart, srcLength); }
inline UnicodeString&
UnicodeString::replace(int32_t start,
int32_t _length,
UChar srcChar)
{ return doReplace(start, _length, &srcChar, 0, 1); }
inline UnicodeString&
UnicodeString::replace(int32_t start,
int32_t _length,
UChar32 srcChar) {
UChar buffer[U16_MAX_LENGTH];
int32_t count = 0;
UBool isError = FALSE;
U16_APPEND(buffer, count, U16_MAX_LENGTH, srcChar, isError);
return doReplace(start, _length, buffer, 0, count);
}
inline UnicodeString&
UnicodeString::replaceBetween(int32_t start,
int32_t limit,
const UnicodeString& srcText)
{ return doReplace(start, limit - start, srcText, 0, srcText.fLength); }
inline UnicodeString&
UnicodeString::replaceBetween(int32_t start,
int32_t limit,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLimit)
{ return doReplace(start, limit - start, srcText, srcStart, srcLimit - srcStart); }
inline UnicodeString&
UnicodeString::findAndReplace(const UnicodeString& oldText,
const UnicodeString& newText)
{ return findAndReplace(0, fLength, oldText, 0, oldText.fLength,
newText, 0, newText.fLength); }
inline UnicodeString&
UnicodeString::findAndReplace(int32_t start,
int32_t _length,
const UnicodeString& oldText,
const UnicodeString& newText)
{ return findAndReplace(start, _length, oldText, 0, oldText.fLength,
newText, 0, newText.fLength); }
// ============================
// extract
// ============================
inline void
UnicodeString::doExtract(int32_t start,
int32_t _length,
UnicodeString& target) const
{ target.replace(0, target.fLength, *this, start, _length); }
inline void
UnicodeString::extract(int32_t start,
int32_t _length,
UChar *target,
int32_t targetStart) const
{ doExtract(start, _length, target, targetStart); }
inline void
UnicodeString::extract(int32_t start,
int32_t _length,
UnicodeString& target) const
{ doExtract(start, _length, target); }
#if !UCONFIG_NO_CONVERSION
inline int32_t
UnicodeString::extract(int32_t start,
int32_t _length,
char *dst,
const char *codepage) const
{
// This dstSize value will be checked explicitly
return extract(start, _length, dst, dst!=0 ? 0xffffffff : 0, codepage);
}
#endif
inline void
UnicodeString::extractBetween(int32_t start,
int32_t limit,
UChar *dst,
int32_t dstStart) const {
pinIndex(start);
pinIndex(limit);
doExtract(start, limit - start, dst, dstStart);
}
inline UChar
UnicodeString::doCharAt(int32_t offset) const
{
if((uint32_t)offset < (uint32_t)fLength) {
return fArray[offset];
} else {
return kInvalidUChar;
}
}
inline UChar
UnicodeString::charAt(int32_t offset) const
{ return doCharAt(offset); }
inline UChar
UnicodeString::operator[] (int32_t offset) const
{ return doCharAt(offset); }
inline UChar32
UnicodeString::char32At(int32_t offset) const
{
if((uint32_t)offset < (uint32_t)fLength) {
UChar32 c;
U16_GET(fArray, 0, offset, fLength, c);
return c;
} else {
return kInvalidUChar;
}
}
inline int32_t
UnicodeString::getChar32Start(int32_t offset) const {
if((uint32_t)offset < (uint32_t)fLength) {
U16_SET_CP_START(fArray, 0, offset);
return offset;
} else {
return 0;
}
}
inline int32_t
UnicodeString::getChar32Limit(int32_t offset) const {
if((uint32_t)offset < (uint32_t)fLength) {
U16_SET_CP_LIMIT(fArray, 0, offset, fLength);
return offset;
} else {
return fLength;
}
}
inline UBool
UnicodeString::isEmpty() const {
return fLength == 0;
}
//========================================
// Write implementation methods
//========================================
inline const UChar *
UnicodeString::getTerminatedBuffer() {
if(fFlags&(kIsBogus|kOpenGetBuffer)) {
return 0;
} else if(fLength<fCapacity && fArray[fLength]==0) {
return fArray;
} else if(cloneArrayIfNeeded(fLength+1)) {
fArray[fLength]=0;
return fArray;
} else {
return 0;
}
}
inline UnicodeString&
UnicodeString::operator= (UChar ch)
{ return doReplace(0, fLength, &ch, 0, 1); }
inline UnicodeString&
UnicodeString::operator= (UChar32 ch)
{ return replace(0, fLength, ch); }
inline UnicodeString&
UnicodeString::setTo(const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength)
{
unBogus();
return doReplace(0, fLength, srcText, srcStart, srcLength);
}
inline UnicodeString&
UnicodeString::setTo(const UnicodeString& srcText,
int32_t srcStart)
{
unBogus();
srcText.pinIndex(srcStart);
return doReplace(0, fLength, srcText, srcStart, srcText.fLength - srcStart);
}
inline UnicodeString&
UnicodeString::setTo(const UnicodeString& srcText)
{
unBogus();
return doReplace(0, fLength, srcText, 0, srcText.fLength);
}
inline UnicodeString&
UnicodeString::setTo(const UChar *srcChars,
int32_t srcLength)
{
unBogus();
return doReplace(0, fLength, srcChars, 0, srcLength);
}
inline UnicodeString&
UnicodeString::setTo(UChar srcChar)
{
unBogus();
return doReplace(0, fLength, &srcChar, 0, 1);
}
inline UnicodeString&
UnicodeString::setTo(UChar32 srcChar)
{
unBogus();
return replace(0, fLength, srcChar);
}
inline UnicodeString&
UnicodeString::append(const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength)
{ return doReplace(fLength, 0, srcText, srcStart, srcLength); }
inline UnicodeString&
UnicodeString::append(const UnicodeString& srcText)
{ return doReplace(fLength, 0, srcText, 0, srcText.fLength); }
inline UnicodeString&
UnicodeString::append(const UChar *srcChars,
int32_t srcStart,
int32_t srcLength)
{ return doReplace(fLength, 0, srcChars, srcStart, srcLength); }
inline UnicodeString&
UnicodeString::append(const UChar *srcChars,
int32_t srcLength)
{ return doReplace(fLength, 0, srcChars, 0, srcLength); }
inline UnicodeString&
UnicodeString::append(UChar srcChar)
{ return doReplace(fLength, 0, &srcChar, 0, 1); }
inline UnicodeString&
UnicodeString::append(UChar32 srcChar) {
UChar buffer[U16_MAX_LENGTH];
int32_t _length = 0;
UBool isError = FALSE;
U16_APPEND(buffer, _length, U16_MAX_LENGTH, srcChar, isError);
return doReplace(fLength, 0, buffer, 0, _length);
}
inline UnicodeString&
UnicodeString::operator+= (UChar ch)
{ return doReplace(fLength, 0, &ch, 0, 1); }
inline UnicodeString&
UnicodeString::operator+= (UChar32 ch) {
return append(ch);
}
inline UnicodeString&
UnicodeString::operator+= (const UnicodeString& srcText)
{ return doReplace(fLength, 0, srcText, 0, srcText.fLength); }
inline UnicodeString&
UnicodeString::insert(int32_t start,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength)
{ return doReplace(start, 0, srcText, srcStart, srcLength); }
inline UnicodeString&
UnicodeString::insert(int32_t start,
const UnicodeString& srcText)
{ return doReplace(start, 0, srcText, 0, srcText.fLength); }
inline UnicodeString&
UnicodeString::insert(int32_t start,
const UChar *srcChars,
int32_t srcStart,
int32_t srcLength)
{ return doReplace(start, 0, srcChars, srcStart, srcLength); }
inline UnicodeString&
UnicodeString::insert(int32_t start,
const UChar *srcChars,
int32_t srcLength)
{ return doReplace(start, 0, srcChars, 0, srcLength); }
inline UnicodeString&
UnicodeString::insert(int32_t start,
UChar srcChar)
{ return doReplace(start, 0, &srcChar, 0, 1); }
inline UnicodeString&
UnicodeString::insert(int32_t start,
UChar32 srcChar)
{ return replace(start, 0, srcChar); }
inline UnicodeString&
UnicodeString::remove()
{
// remove() of a bogus string makes the string empty and non-bogus
if(isBogus()) {
unBogus();
} else {
fLength = 0;
}
return *this;
}
inline UnicodeString&
UnicodeString::remove(int32_t start,
int32_t _length)
{
if(start <= 0 && _length == INT32_MAX) {
// remove(guaranteed everything) of a bogus string makes the string empty and non-bogus
return remove();
}
return doReplace(start, _length, NULL, 0, 0);
}
inline UnicodeString&
UnicodeString::removeBetween(int32_t start,
int32_t limit)
{ return doReplace(start, limit - start, NULL, 0, 0); }
inline UBool
UnicodeString::truncate(int32_t targetLength)
{
if(isBogus() && targetLength == 0) {
// truncate(0) of a bogus string makes the string empty and non-bogus
unBogus();
return FALSE;
} else if((uint32_t)targetLength < (uint32_t)fLength) {
fLength = targetLength;
return TRUE;
} else {
return FALSE;
}
}
inline UnicodeString&
UnicodeString::reverse()
{ return doReverse(0, fLength); }
inline UnicodeString&
UnicodeString::reverse(int32_t start,
int32_t _length)
{ return doReverse(start, _length); }
U_NAMESPACE_END
#endif
|