summaryrefslogtreecommitdiffstats
path: root/include/rtl/ustring.hxx
blob: 5f0c1032c6035ff3e1970cf36b5929b920138e7e (plain)
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
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#ifndef INCLUDED_RTL_USTRING_HXX
#define INCLUDED_RTL_USTRING_HXX

#include "sal/config.h"

#include <cassert>
#include <cstddef>
#include <limits>
#include <new>
#include <ostream>
#include <utility>

#if defined LIBO_INTERNAL_ONLY
#include <string_view>
#endif

#include "rtl/ustring.h"
#include "rtl/string.hxx"
#include "rtl/stringutils.hxx"
#include "rtl/textenc.h"

#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
#include "rtl/stringconcat.hxx"
#endif

#ifdef RTL_STRING_UNITTEST
extern bool rtl_string_unittest_invalid_conversion;
#endif

// The unittest uses slightly different code to help check that the proper
// calls are made. The class is put into a different namespace to make
// sure the compiler generates a different (if generating also non-inline)
// copy of the function and does not merge them together. The class
// is "brought" into the proper rtl namespace by a typedef below.
#ifdef RTL_STRING_UNITTEST
#define rtl rtlunittest
#endif

namespace rtl
{

class OUStringBuffer;

#ifdef RTL_STRING_UNITTEST
#undef rtl
#endif

#if defined LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
/// @cond INTERNAL

/**
A simple wrapper around string literal.

This class is not part of public API and is meant to be used only in LibreOffice code.
@since LibreOffice 4.0
*/
struct SAL_WARN_UNUSED OUStringLiteral
{
    template<typename T> constexpr OUStringLiteral(
        T & literal,
        typename libreoffice_internal::ConstCharArrayDetector<
                T, libreoffice_internal::Dummy>::Type
            = libreoffice_internal::Dummy()):
        size(libreoffice_internal::ConstCharArrayDetector<T>::length),
        data(
            libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal))
    {
        assert(
            libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
    }

    int size;
    const char* data;

    // So we can use this struct in some places interchangeably with OUString
    constexpr sal_Int32 getLength() const { return size; }
};

/// @endcond
#endif

/* ======================================================================= */

/**
  This String class provides base functionality for C++ like Unicode
  character array handling. The advantage of this class is that it
  handles all the memory management for you - and it does it
  more efficiently. If you assign a string to another string, the
  data of both strings are shared (without any copy operation or
  memory allocation) as long as you do not change the string. This class
  also stores the length of the string, so that many operations are
  faster than the C-str-functions.

  This class provides only readonly string handling. So you could create
  a string and you could only query the content from this string.
  It provides also functionality to change the string, but this results
  in every case in a new string instance (in the most cases with a
  memory allocation). You don't have functionality to change the
  content of the string. If you want to change the string content, then
  you should use the OStringBuffer class, which provides these
  functionalities and avoids too much memory allocation.

  The design of this class is similar to the string classes in Java so
  less people should have understanding problems when they use this class.
*/

class SAL_WARN_UNUSED SAL_DLLPUBLIC_RTTI OUString
{
public:
    /// @cond INTERNAL
    rtl_uString * pData;
    /// @endcond

    /**
      New string containing no characters.
    */
    OUString()
    {
        pData = NULL;
        rtl_uString_new( &pData );
    }

    /**
      New string from OUString.

      @param    str         an OUString.
    */
    OUString( const OUString & str )
    {
        pData = str.pData;
        rtl_uString_acquire( pData );
    }

#if defined LIBO_INTERNAL_ONLY
    /**
      Move constructor.

      @param    str         an OUString.
      @since LibreOffice 5.2
    */
    OUString( OUString && str ) noexcept
    {
        pData = str.pData;
        str.pData = nullptr;
        rtl_uString_new( &str.pData );
    }
#endif

    /**
      New string from OUString data.

      @param    str         an OUString data.
    */
    OUString( rtl_uString * str )
    {
        pData = str;
        rtl_uString_acquire( pData );
    }

    /** New OUString from OUString data without acquiring it.  Takeover of ownership.

        The SAL_NO_ACQUIRE dummy parameter is only there to distinguish this
        from other constructors.

        @param str
               OUString data
    */
    OUString( rtl_uString * str, __sal_NoAcquire )
        { pData = str; }

    /**
      New string from a single Unicode character.

      @param    value       a Unicode character.
    */
    explicit OUString( sal_Unicode value )
        : pData (NULL)
    {
        rtl_uString_newFromStr_WithLength( &pData, &value, 1 );
    }

#if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST_CONCAT
    /// @cond INTERNAL
    // Catch inadvertent conversions to the above ctor (but still allow
    // construction from char literals):
    OUString(int) = delete;
    explicit OUString(char c):
        OUString(sal_Unicode(static_cast<unsigned char>(c)))
    {}
    /// @endcond
#endif

    /**
      New string from a Unicode character buffer array.

      @param    value       a NULL-terminated Unicode character array.
    */
    OUString( const sal_Unicode * value )
    {
        pData = NULL;
        rtl_uString_newFromStr( &pData, value );
    }

    /**
      New string from a Unicode character buffer array.

      @param    value       a Unicode character array.
      @param    length      the number of character which should be copied.
                            The character array length must be greater than
                            or equal to this value.
    */
    OUString( const sal_Unicode * value, sal_Int32 length )
    {
        pData = NULL;
        rtl_uString_newFromStr_WithLength( &pData, value, length );
    }

    /**
      New string from an 8-Bit string literal that is expected to contain only
      characters in the ASCII set (i.e. first 128 characters). This constructor
      allows an efficient and convenient way to create OUString
      instances from ASCII literals. When creating strings from data that
      is not pure ASCII, it needs to be converted to OUString by explicitly
      providing the encoding to use for the conversion.

      If there are any embedded \0's in the string literal, the result is undefined.
      Use the overload that explicitly accepts length.

      @param    literal         the 8-bit ASCII string literal

      @since LibreOffice 3.6
    */
    template< typename T >
    OUString( T& literal, typename libreoffice_internal::ConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type = libreoffice_internal::Dummy() )
    {
        assert(
            libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
        pData = NULL;
        if (libreoffice_internal::ConstCharArrayDetector<T>::length == 0) {
            rtl_uString_new(&pData);
        } else {
            rtl_uString_newFromLiteral(
                &pData,
                libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
                    literal),
                libreoffice_internal::ConstCharArrayDetector<T>::length, 0);
        }
#ifdef RTL_STRING_UNITTEST
        rtl_string_unittest_const_literal = true;
#endif
    }

#if defined LIBO_INTERNAL_ONLY
    /** @overload @since LibreOffice 5.3 */
    template<typename T> OUString(
        T & literal,
        typename libreoffice_internal::ConstCharArrayDetector<
            T, libreoffice_internal::Dummy>::TypeUtf16
                = libreoffice_internal::Dummy()):
        pData(nullptr)
    {
        if (libreoffice_internal::ConstCharArrayDetector<T>::length == 0) {
            rtl_uString_new(&pData);
        } else {
            rtl_uString_newFromStr_WithLength(
                &pData,
                libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
                    literal),
                libreoffice_internal::ConstCharArrayDetector<T>::length);
        }
    }
#endif

#ifdef RTL_STRING_UNITTEST
    /**
     * Only used by unittests to detect incorrect conversions.
     * @internal
     */
    template< typename T >
    OUString( T&, typename libreoffice_internal::ExceptConstCharArrayDetector< T >::Type = libreoffice_internal::Dummy() )
    {
        pData = NULL;
        rtl_uString_newFromLiteral( &pData, "!!br0ken!!", 10, 0 ); // set to garbage
        rtl_string_unittest_invalid_conversion = true;
    }
    /**
     * Only used by unittests to detect incorrect conversions.
     * @internal
     */
    template< typename T >
    OUString( const T&, typename libreoffice_internal::ExceptCharArrayDetector< T >::Type = libreoffice_internal::Dummy() )
    {
        pData = NULL;
        rtl_uString_newFromLiteral( &pData, "!!br0ken!!", 10, 0 ); // set to garbage
        rtl_string_unittest_invalid_conversion = true;
    }
#endif

#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
    /// @cond INTERNAL
    /**
      New string from an 8-Bit string literal that is expected to contain only
      characters in the ASCII set (i.e. first 128 characters).

      This constructor is similar to the "direct template" one, but can be
      useful in cases where the latter does not work, like in

        OUString(flag ? "a" : "bb")

      written as

        OUString(flag ? OUStringLiteral("a") : OUStringLiteral("bb"))

      @since LibreOffice 5.0
    */
    OUString(OUStringLiteral literal): pData(NULL) {
        rtl_uString_newFromLiteral(&pData, literal.data, literal.size, 0);
    }
    /// @endcond
#endif

    /**
      New string from an 8-Bit character buffer array.

      @param    value           An 8-Bit character array.
      @param    length          The number of character which should be converted.
                                The 8-Bit character array length must be
                                greater than or equal to this value.
      @param    encoding        The text encoding from which the 8-Bit character
                                sequence should be converted.
      @param    convertFlags    Flags which control the conversion.
                                see RTL_TEXTTOUNICODE_FLAGS_...

      @exception std::bad_alloc is thrown if an out-of-memory condition occurs
    */
    OUString( const sal_Char * value, sal_Int32 length,
              rtl_TextEncoding encoding,
              sal_uInt32 convertFlags = OSTRING_TO_OUSTRING_CVTFLAGS )
    {
        pData = NULL;
        rtl_string2UString( &pData, value, length, encoding, convertFlags );
        if (pData == NULL) {
            throw std::bad_alloc();
        }
    }

    /** Create a new string from an array of Unicode code points.

        @param codePoints
        an array of at least codePointCount code points, which each must be in
        the range from 0 to 0x10FFFF, inclusive.  May be null if codePointCount
        is zero.

        @param codePointCount
        the non-negative number of code points.

        @exception std::bad_alloc
        is thrown if either an out-of-memory condition occurs or the resulting
        number of UTF-16 code units would have been larger than SAL_MAX_INT32.

        @since UDK 3.2.7
    */
    explicit OUString(
        sal_uInt32 const * codePoints, sal_Int32 codePointCount):
        pData(NULL)
    {
        rtl_uString_newFromCodePoints(&pData, codePoints, codePointCount);
        if (pData == NULL) {
            throw std::bad_alloc();
        }
    }

#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
    /**
     @overload
     @internal
    */
    template< typename T1, typename T2 >
    OUString( OUStringConcat< T1, T2 >&& c )
    {
        const sal_Int32 l = c.length();
        pData = rtl_uString_alloc( l );
        if (l != 0)
        {
            sal_Unicode* end = c.addData( pData->buffer );
            pData->length = l;
            *end = '\0';
            // TODO realloc in case pData->length is noticeably smaller than l?
        }
    }

    /**
     @overload
     @internal
    */
    template< typename T >
    OUString( OUStringNumber< T >&& n )
        : OUString( n.buf, n.length )
    {}
#endif

#if defined LIBO_INTERNAL_ONLY
    OUString(std::u16string_view sv) {
        if (sv.size() > sal_uInt32(std::numeric_limits<sal_Int32>::max())) {
            throw std::bad_alloc();
        }
        pData = nullptr;
        rtl_uString_newFromStr_WithLength(&pData, sv.data(), sv.size());
    }
#endif

    /**
      Release the string data.
    */
    ~OUString()
    {
        rtl_uString_release( pData );
    }

    /** Provides an OUString const & passing a storage pointer of an
        rtl_uString * handle.
        It is more convenient to use C++ OUString member functions when dealing
        with rtl_uString * handles.  Using this function avoids unnecessary
        acquire()/release() calls for a temporary OUString object.

        @param ppHandle
               pointer to storage
        @return
               OUString const & based on given storage
    */
    static OUString const & unacquired( rtl_uString * const * ppHandle )
        { return * reinterpret_cast< OUString const * >( ppHandle ); }

    /**
      Assign a new string.

      @param    str         an OUString.
    */
    OUString & operator=( const OUString & str )
    {
        rtl_uString_assign( &pData, str.pData );
        return *this;
    }

#if defined LIBO_INTERNAL_ONLY
    /**
      Move assign a new string.

      @param    str         an OUString.
      @since LibreOffice 5.2
    */
    OUString & operator=( OUString && str ) noexcept
    {
        rtl_uString_release( pData );
        pData = str.pData;
        str.pData = nullptr;
        rtl_uString_new( &str.pData );
        return *this;
    }
#endif

    /**
      Assign a new string from an 8-Bit string literal that is expected to contain only
      characters in the ASCII set (i.e. first 128 characters). This operator
      allows an efficient and convenient way to assign OUString
      instances from ASCII literals. When assigning strings from data that
      is not pure ASCII, it needs to be converted to OUString by explicitly
      providing the encoding to use for the conversion.

      @param    literal         the 8-bit ASCII string literal

      @since LibreOffice 3.6
    */
    template< typename T >
    typename libreoffice_internal::ConstCharArrayDetector< T, OUString& >::Type operator=( T& literal )
    {
        assert(
            libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
        if (libreoffice_internal::ConstCharArrayDetector<T>::length == 0) {
            rtl_uString_new(&pData);
        } else {
            rtl_uString_newFromLiteral(
                &pData,
                libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
                    literal),
                libreoffice_internal::ConstCharArrayDetector<T>::length, 0);
        }
        return *this;
    }

#if defined LIBO_INTERNAL_ONLY
    /** @overload @since LibreOffice 5.3 */
    template<typename T>
    typename
        libreoffice_internal::ConstCharArrayDetector<T, OUString &>::TypeUtf16
    operator =(T & literal) {
        if (libreoffice_internal::ConstCharArrayDetector<T>::length == 0) {
            rtl_uString_new(&pData);
        } else {
            rtl_uString_newFromStr_WithLength(
                &pData,
                libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
                    literal),
                libreoffice_internal::ConstCharArrayDetector<T>::length);
        }
        return *this;
    }

    /** @overload @since LibreOffice 5.4 */
    OUString & operator =(OUStringLiteral const & literal) {
        if (literal.size == 0) {
            rtl_uString_new(&pData);
        } else {
            rtl_uString_newFromLiteral(&pData, literal.data, literal.size, 0);
        }
        return *this;
    }
#endif

#if defined LIBO_INTERNAL_ONLY
    /**
      Append the contents of an OUStringBuffer to this string.

      @param    str         an OUStringBuffer.

      @exception std::bad_alloc is thrown if an out-of-memory condition occurs
      @since LibreOffice 6.2
    */
    inline OUString & operator+=( const OUStringBuffer & str ) &;
#endif

    /**
      Append a string to this string.

      @param    str         an OUString.

      @exception std::bad_alloc is thrown if an out-of-memory condition occurs
    */
    OUString & operator+=( const OUString & str )
#if defined LIBO_INTERNAL_ONLY
        &
#endif
    {
        return internalAppend(str.pData);
    }
#if defined LIBO_INTERNAL_ONLY
    void operator+=(OUString const &) && = delete;
#endif

    /** Append an ASCII string literal to this string.

        @param literal  an 8-bit ASCII-only string literal

        @since LibreOffice 5.1
    */
    template<typename T>
    typename libreoffice_internal::ConstCharArrayDetector<T, OUString &>::Type
    operator +=(T & literal)
#if defined LIBO_INTERNAL_ONLY
        &
#endif
    {
        assert(
            libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
        rtl_uString_newConcatAsciiL(
            &pData, pData,
            libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
            libreoffice_internal::ConstCharArrayDetector<T>::length);
        return *this;
    }
#if defined LIBO_INTERNAL_ONLY
    template<typename T>
    typename libreoffice_internal::ConstCharArrayDetector<T, OUString &>::Type
    operator +=(T &) && = delete;
#endif

#if defined LIBO_INTERNAL_ONLY
    /** @overload @since LibreOffice 5.3 */
    template<typename T>
    typename
        libreoffice_internal::ConstCharArrayDetector<T, OUString &>::TypeUtf16
    operator +=(T & literal) & {
        rtl_uString_newConcatUtf16L(
            &pData, pData,
            libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
            libreoffice_internal::ConstCharArrayDetector<T>::length);
        return *this;
    }
    template<typename T>
    typename
        libreoffice_internal::ConstCharArrayDetector<T, OUString &>::TypeUtf16
    operator +=(T &) && = delete;

    /** @overload @since LibreOffice 5.4 */
    OUString & operator +=(OUStringLiteral const & literal) & {
        rtl_uString_newConcatAsciiL(&pData, pData, literal.data, literal.size);
        return *this;
    }
    void operator +=(OUStringLiteral const &) && = delete;
#endif

#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
    /**
     @overload
     @internal
    */
    template< typename T1, typename T2 >
    OUString& operator+=( OUStringConcat< T1, T2 >&& c ) & {
        sal_Int32 l = c.length();
        if( l == 0 )
            return *this;
        l += pData->length;
        rtl_uString_ensureCapacity( &pData, l );
        sal_Unicode* end = c.addData( pData->buffer + pData->length );
        *end = '\0';
        pData->length = l;
        return *this;
    }
    template<typename T1, typename T2> void operator +=(
        OUStringConcat<T1, T2> &&) && = delete;

    /**
     @overload
     @internal
    */
    template< typename T >
    OUString& operator+=( OUStringNumber< T >&& n ) & {
        sal_Int32 l = n.length;
        if( l == 0 )
            return *this;
        l += pData->length;
        rtl_uString_ensureCapacity( &pData, l );
        sal_Unicode* end = addDataHelper( pData->buffer + pData->length, n.buf, n.length );
        *end = '\0';
        pData->length = l;
        return *this;
    }
    template<typename T> void operator +=(
        OUStringNumber<T> &&) && = delete;
#endif

    /**
      Clears the string, i.e, makes a zero-character string
      @since LibreOffice 4.4
    */
    void clear()
    {
        rtl_uString_new( &pData );
    }

    /**
      Returns the length of this string.

      The length is equal to the number of Unicode characters in this string.

      @return   the length of the sequence of characters represented by this
                object.
    */
    sal_Int32 getLength() const { return pData->length; }

    /**
      Checks if a string is empty.

      @return   true if the string is empty;
                false, otherwise.

      @since LibreOffice 3.4
    */
    bool isEmpty() const
    {
        return pData->length == 0;
    }

    /**
      Returns a pointer to the Unicode character buffer for this string.

      It isn't necessarily NULL terminated.

      @return   a pointer to the Unicode characters buffer for this object.
    */
    const sal_Unicode * getStr() const SAL_RETURNS_NONNULL { return pData->buffer; }

    /**
      Access to individual characters.

      @param index must be non-negative and less than length.

      @return the character at the given index.

      @since LibreOffice 3.5
    */
    sal_Unicode operator [](sal_Int32 index) const {
        // silence spurious -Werror=strict-overflow warnings from GCC 4.8.2
        assert(index >= 0 && static_cast<sal_uInt32>(index) < static_cast<sal_uInt32>(getLength()));
        return getStr()[index];
    }

    /**
      Compares two strings.

      The comparison is based on the numeric value of each character in
      the strings and return a value indicating their relationship.
      This function can't be used for language specific sorting.

      @param    str         the object to be compared.
      @return   0 - if both strings are equal
                < 0 - if this string is less than the string argument
                > 0 - if this string is greater than the string argument
    */
    sal_Int32 compareTo( const OUString & str ) const
    {
        return rtl_ustr_compare_WithLength( pData->buffer, pData->length,
                                            str.pData->buffer, str.pData->length );
    }

    /**
      Compares two strings with a maximum count of characters.

      The comparison is based on the numeric value of each character in
      the strings and return a value indicating their relationship.
      This function can't be used for language specific sorting.

      @param    str         the object to be compared.
      @param    maxLength   the maximum count of characters to be compared.
      @return   0 - if both strings are equal
                < 0 - if this string is less than the string argument
                > 0 - if this string is greater than the string argument

      @since UDK 3.2.7
    */
    sal_Int32 compareTo( const OUString & str, sal_Int32 maxLength ) const
    {
        return rtl_ustr_shortenedCompare_WithLength( pData->buffer, pData->length,
                                                     str.pData->buffer, str.pData->length, maxLength );
    }

    /**
      Compares two strings in reverse order.

      The comparison is based on the numeric value of each character in
      the strings and return a value indicating their relationship.
      This function can't be used for language specific sorting.

      @param    str         the object to be compared.
      @return   0 - if both strings are equal
                < 0 - if this string is less than the string argument
                > 0 - if this string is greater than the string argument
    */
    sal_Int32 reverseCompareTo( const OUString & str ) const
    {
        return rtl_ustr_reverseCompare_WithLength( pData->buffer, pData->length,
                                                   str.pData->buffer, str.pData->length );
    }

    /**
     @overload
     This function accepts an ASCII string literal as its argument.
     @since LibreOffice 4.1
    */
    template< typename T >
    typename libreoffice_internal::ConstCharArrayDetector< T, sal_Int32 >::Type reverseCompareTo( T& literal ) const
    {
        assert(
            libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
        return rtl_ustr_asciil_reverseCompare_WithLength(
            pData->buffer, pData->length,
            libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
            libreoffice_internal::ConstCharArrayDetector<T>::length);
    }

#if defined LIBO_INTERNAL_ONLY
    /** @overload @since LibreOffice 5.3 */
    template<typename T>
    typename
        libreoffice_internal::ConstCharArrayDetector<T, sal_Int32>::TypeUtf16
    reverseCompareTo(T & literal) const {
        return rtl_ustr_reverseCompare_WithLength(
            pData->buffer, pData->length,
            libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
            libreoffice_internal::ConstCharArrayDetector<T>::length);
    }

    /** @overload @since LibreOffice 5.4 */
    sal_Int32 reverseCompareTo(OUStringLiteral const & literal) const {
        return rtl_ustr_asciil_reverseCompare_WithLength(
            pData->buffer, pData->length, literal.data, literal.size);
    }
#endif

    /**
      Perform a comparison of two strings.

      The result is true if and only if second string
      represents the same sequence of characters as the first string.
      This function can't be used for language specific comparison.

      @param    str         the object to be compared.
      @return   true if the strings are equal;
                false, otherwise.
    */
    bool equals( const OUString & str ) const
    {
        if ( pData->length != str.pData->length )
            return false;
        if ( pData == str.pData )
            return true;
        return rtl_ustr_reverseCompare_WithLength( pData->buffer, pData->length,
                                                   str.pData->buffer, str.pData->length ) == 0;
    }

    /**
      Perform an ASCII lowercase comparison of two strings.

      The result is true if and only if second string
      represents the same sequence of characters as the first string,
      ignoring the case.
      Character values between 65 and 90 (ASCII A-Z) are interpreted as
      values between 97 and 122 (ASCII a-z).
      This function can't be used for language specific comparison.

      @param    str         the object to be compared.
      @return   true if the strings are equal;
                false, otherwise.
    */
    bool equalsIgnoreAsciiCase( const OUString & str ) const
    {
        if ( pData->length != str.pData->length )
            return false;
        if ( pData == str.pData )
            return true;
        return rtl_ustr_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
                                                           str.pData->buffer, str.pData->length ) == 0;
    }

    /**
      Perform an ASCII lowercase comparison of two strings.

      Compare the two strings with uppercase ASCII
      character values between 65 and 90 (ASCII A-Z) interpreted as
      values between 97 and 122 (ASCII a-z).
      This function can't be used for language specific comparison.

      @param    str         the object to be compared.
      @return   0 - if both strings are equal
                < 0 - if this string is less than the string argument
                > 0 - if this string is greater than the string argument

      @since LibreOffice 4.0
    */
    sal_Int32 compareToIgnoreAsciiCase( const OUString & str ) const
    {
        return rtl_ustr_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
                                                           str.pData->buffer, str.pData->length );
    }


    /**
     @overload
     This function accepts an ASCII string literal as its argument.
     @since LibreOffice 3.6
    */
    template< typename T >
    typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type equalsIgnoreAsciiCase( T& literal ) const
    {
        assert(
            libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
        return
            (pData->length
             == libreoffice_internal::ConstCharArrayDetector<T>::length)
            && (rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength(
                    pData->buffer, pData->length,
                    libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
                        literal))
                == 0);
    }

#if defined LIBO_INTERNAL_ONLY
    /** @overload @since LibreOffice 5.3 */
    template<typename T>
    typename libreoffice_internal::ConstCharArrayDetector<T, bool>::TypeUtf16
    equalsIgnoreAsciiCase(T & literal) const {
        return
            rtl_ustr_compareIgnoreAsciiCase_WithLength(
                pData->buffer, pData->length,
                libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
                    literal),
                libreoffice_internal::ConstCharArrayDetector<T>::length)
            == 0;
    }

    /** @overload @since LibreOffice 5.4 */
    bool equalsIgnoreAsciiCase(OUStringLiteral const & literal) const {
        return pData->length == literal.size
            && (rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength(
                    pData->buffer, pData->length, literal.data)
                == 0);
    }
#endif

   /**
      Match against a substring appearing in this string.

      The result is true if and only if the second string appears as a substring
      of this string, at the given position.
      This function can't be used for language specific comparison.

      @param    str         the object (substring) to be compared.
      @param    fromIndex   the index to start the comparison from.
                            The index must be greater than or equal to 0
                            and less or equal as the string length.
      @return   true if str match with the characters in the string
                at the given position;
                false, otherwise.
    */
    bool match( const OUString & str, sal_Int32 fromIndex = 0 ) const
    {
        return rtl_ustr_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
                                                     str.pData->buffer, str.pData->length, str.pData->length ) == 0;
    }

    /**
     @overload
     This function accepts an ASCII string literal as its argument.
     @since LibreOffice 3.6
    */
    template< typename T >
    typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type match( T& literal, sal_Int32 fromIndex = 0 ) const
    {
        assert(
            libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
        return
            rtl_ustr_ascii_shortenedCompare_WithLength(
                pData->buffer+fromIndex, pData->length-fromIndex,
                libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
                    literal),
                libreoffice_internal::ConstCharArrayDetector<T>::length)
            == 0;
    }

#if defined LIBO_INTERNAL_ONLY
    /** @overload @since LibreOffice 5.3 */
    template<typename T>
    typename libreoffice_internal::ConstCharArrayDetector<T, bool>::TypeUtf16
    match(T & literal, sal_Int32 fromIndex = 0) const {
        assert(fromIndex >= 0);
        return
            rtl_ustr_shortenedCompare_WithLength(
                pData->buffer + fromIndex, pData->length - fromIndex,
                libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
                    literal),
                libreoffice_internal::ConstCharArrayDetector<T>::length,
                libreoffice_internal::ConstCharArrayDetector<T>::length)
            == 0;
    }

    /** @overload @since LibreOffice 5.4 */
    bool match(OUStringLiteral const & literal, sal_Int32 fromIndex = 0) const {
        return
            rtl_ustr_ascii_shortenedCompare_WithLength(
                pData->buffer + fromIndex, pData->length - fromIndex,
                literal.data, literal.size)
            == 0;
    }
#endif

    /**
      Match against a substring appearing in this string, ignoring the case of
      ASCII letters.

      The result is true if and only if the second string appears as a substring
      of this string, at the given position.
      Character values between 65 and 90 (ASCII A-Z) are interpreted as
      values between 97 and 122 (ASCII a-z).
      This function can't be used for language specific comparison.

      @param    str         the object (substring) to be compared.
      @param    fromIndex   the index to start the comparison from.
                            The index must be greater than or equal to 0
                            and less than or equal to the string length.
      @return   true if str match with the characters in the string
                at the given position;
                false, otherwise.
    */
    bool matchIgnoreAsciiCase( const OUString & str, sal_Int32 fromIndex = 0 ) const
    {
        return rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
                                                                    str.pData->buffer, str.pData->length,
                                                                    str.pData->length ) == 0;
    }

    /**
     @overload
     This function accepts an ASCII string literal as its argument.
     @since LibreOffice 3.6
    */
    template< typename T >
    typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type matchIgnoreAsciiCase( T& literal, sal_Int32 fromIndex = 0 ) const
    {
        assert(
            libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
        return
            rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength(
                pData->buffer+fromIndex, pData->length-fromIndex,
                libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
                    literal),
                libreoffice_internal::ConstCharArrayDetector<T>::length)
            == 0;
    }

#if defined LIBO_INTERNAL_ONLY
    /** @overload @since LibreOffice 5.3 */
    template<typename T>
    typename libreoffice_internal::ConstCharArrayDetector<T, bool>::TypeUtf16
    matchIgnoreAsciiCase(T & literal, sal_Int32 fromIndex = 0) const {
        assert(fromIndex >= 0);
        return
            rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength(
                pData->buffer + fromIndex, pData->length - fromIndex,
                libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
                    literal),
                libreoffice_internal::ConstCharArrayDetector<T>::length,
                libreoffice_internal::ConstCharArrayDetector<T>::length)
            == 0;
    }

    /** @overload @since LibreOffice 5.4 */
    bool matchIgnoreAsciiCase(
        OUStringLiteral const & literal, sal_Int32 fromIndex = 0) const
    {
        return
            rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength(
                pData->buffer+fromIndex, pData->length-fromIndex, literal.data,
                literal.size)
            == 0;
    }
#endif

    /**
      Compares two strings.

      The comparison is based on the numeric value of each character in
      the strings and return a value indicating their relationship.
      Since this method is optimized for performance, the ASCII character
      values are not converted in any way. The caller has to make sure that
      all ASCII characters are in the allowed range between 0 and 127.
      The ASCII string must be NULL-terminated.
      This function can't be used for language specific sorting.

      @param  asciiStr      the 8-Bit ASCII character string to be compared.
      @return   0 - if both strings are equal
                < 0 - if this string is less than the string argument
                > 0 - if this string is greater than the string argument
    */
    sal_Int32 compareToAscii( const sal_Char* asciiStr ) const
    {
        return rtl_ustr_ascii_compare_WithLength( pData->buffer, pData->length, asciiStr );
    }

    /**
      Compares two strings with a maximum count of characters.

      The comparison is based on the numeric value of each character in
      the strings and return a value indicating their relationship.
      Since this method is optimized for performance, the ASCII character
      values are not converted in any way. The caller has to make sure that
      all ASCII characters are in the allowed range between 0 and 127.
      The ASCII string must be NULL-terminated.
      This function can't be used for language specific sorting.

      @deprecated  This is a confusing overload with unexpectedly different
      semantics from the one-parameter form, so it is marked as deprecated.
      Practically all uses compare the return value against zero and can thus
      be replaced with uses of startsWith.

      @param  asciiStr          the 8-Bit ASCII character string to be compared.
      @param  maxLength         the maximum count of characters to be compared.
      @return   0 - if both strings are equal
                < 0 - if this string is less than the string argument
                > 0 - if this string is greater than the string argument
    */
    SAL_DEPRECATED(
        "replace s1.compareToAscii(s2, strlen(s2)) == 0 with s1.startsWith(s2)")
    sal_Int32 compareToAscii( const sal_Char * asciiStr, sal_Int32 maxLength ) const
    {
        return rtl_ustr_ascii_shortenedCompare_WithLength( pData->buffer, pData->length,
                                                           asciiStr, maxLength );
    }

    /**
      Compares two strings in reverse order.

      This could be useful, if normally both strings start with the same
      content. The comparison is based on the numeric value of each character
      in the strings and return a value indicating their relationship.
      Since this method is optimized for performance, the ASCII character
      values are not converted in any way. The caller has to make sure that
      all ASCII characters are in the allowed range between 0 and 127.
      The ASCII string must be NULL-terminated and must be greater than
      or equal to asciiStrLength.
      This function can't be used for language specific sorting.

      @param    asciiStr        the 8-Bit ASCII character string to be compared.
      @param    asciiStrLength  the length of the ascii string
      @return   0 - if both strings are equal
                < 0 - if this string is less than the string argument
                > 0 - if this string is greater than the string argument
    */
    sal_Int32 reverseCompareToAsciiL( const sal_Char * asciiStr, sal_Int32 asciiStrLength ) const
    {
        return rtl_ustr_asciil_reverseCompare_WithLength( pData->buffer, pData->length,
                                                          asciiStr, asciiStrLength );
    }

    /**
      Perform a comparison of two strings.

      The result is true if and only if second string
      represents the same sequence of characters as the first string.
      Since this method is optimized for performance, the ASCII character
      values are not converted in any way. The caller has to make sure that
      all ASCII characters are in the allowed range between 0 and 127.
      The ASCII string must be NULL-terminated.
      This function can't be used for language specific comparison.

      @param    asciiStr        the 8-Bit ASCII character string to be compared.
      @return   true if the strings are equal;
                false, otherwise.
    */
    bool equalsAscii( const sal_Char* asciiStr ) const
    {
        return rtl_ustr_ascii_compare_WithLength( pData->buffer, pData->length,
                                                  asciiStr ) == 0;
    }

    /**
      Perform a comparison of two strings.

      The result is true if and only if second string
      represents the same sequence of characters as the first string.
      Since this method is optimized for performance, the ASCII character
      values are not converted in any way. The caller has to make sure that
      all ASCII characters are in the allowed range between 0 and 127.
      The ASCII string must be NULL-terminated and must be greater than
      or equal to asciiStrLength.
      This function can't be used for language specific comparison.

      @param    asciiStr         the 8-Bit ASCII character string to be compared.
      @param    asciiStrLength   the length of the ascii string
      @return   true if the strings are equal;
                false, otherwise.
    */
    bool equalsAsciiL( const sal_Char* asciiStr, sal_Int32 asciiStrLength ) const
    {
        if ( pData->length != asciiStrLength )
            return false;

        return rtl_ustr_asciil_reverseEquals_WithLength(
                    pData->buffer, asciiStr, asciiStrLength );
    }

    /**
      Perform an ASCII lowercase comparison of two strings.

      The result is true if and only if second string
      represents the same sequence of characters as the first string,
      ignoring the case.
      Character values between 65 and 90 (ASCII A-Z) are interpreted as
      values between 97 and 122 (ASCII a-z).
      Since this method is optimized for performance, the ASCII character
      values are not converted in any way. The caller has to make sure that
      all ASCII characters are in the allowed range between 0 and 127.
      The ASCII string must be NULL-terminated.
      This function can't be used for language specific comparison.

      @param    asciiStr        the 8-Bit ASCII character string to be compared.
      @return   true if the strings are equal;
                false, otherwise.
    */
    bool equalsIgnoreAsciiCaseAscii( const sal_Char * asciiStr ) const
    {
        return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, asciiStr ) == 0;
    }

    /**
      Compares two ASCII strings ignoring case

      The comparison is based on the numeric value of each character in
      the strings and return a value indicating their relationship.
      Since this method is optimized for performance, the ASCII character
      values are not converted in any way. The caller has to make sure that
      all ASCII characters are in the allowed range between 0 and 127.
      The ASCII string must be NULL-terminated.
      This function can't be used for language specific sorting.

      @param  asciiStr      the 8-Bit ASCII character string to be compared.
      @return   0 - if both strings are equal
                < 0 - if this string is less than the string argument
                > 0 - if this string is greater than the string argument

      @since LibreOffice 3.5
    */
    sal_Int32 compareToIgnoreAsciiCaseAscii( const sal_Char * asciiStr ) const
    {
        return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, asciiStr );
    }

    /**
      Perform an ASCII lowercase comparison of two strings.

      The result is true if and only if second string
      represents the same sequence of characters as the first string,
      ignoring the case.
      Character values between 65 and 90 (ASCII A-Z) are interpreted as
      values between 97 and 122 (ASCII a-z).
      Since this method is optimized for performance, the ASCII character
      values are not converted in any way. The caller has to make sure that
      all ASCII characters are in the allowed range between 0 and 127.
      The ASCII string must be NULL-terminated and must be greater than
      or equal to asciiStrLength.
      This function can't be used for language specific comparison.

      @param    asciiStr        the 8-Bit ASCII character string to be compared.
      @param    asciiStrLength  the length of the ascii string
      @return   true if the strings are equal;
                false, otherwise.
    */
    bool equalsIgnoreAsciiCaseAsciiL( const sal_Char * asciiStr, sal_Int32 asciiStrLength ) const
    {
        if ( pData->length != asciiStrLength )
            return false;

        return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, asciiStr ) == 0;
    }

    /**
      Match against a substring appearing in this string.

      The result is true if and only if the second string appears as a substring
      of this string, at the given position.
      Since this method is optimized for performance, the ASCII character
      values are not converted in any way. The caller has to make sure that
      all ASCII characters are in the allowed range between 0 and 127.
      The ASCII string must be NULL-terminated and must be greater than or
      equal to asciiStrLength.
      This function can't be used for language specific comparison.

      @param    asciiStr    the object (substring) to be compared.
      @param    asciiStrLength the length of asciiStr.
      @param    fromIndex   the index to start the comparison from.
                            The index must be greater than or equal to 0
                            and less than or equal to the string length.
      @return   true if str match with the characters in the string
                at the given position;
                false, otherwise.
    */
    bool matchAsciiL( const sal_Char* asciiStr, sal_Int32 asciiStrLength, sal_Int32 fromIndex = 0 ) const
    {
        return rtl_ustr_ascii_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
                                                           asciiStr, asciiStrLength ) == 0;
    }

    // This overload is left undefined, to detect calls of matchAsciiL that
    // erroneously use RTL_CONSTASCII_USTRINGPARAM instead of
    // RTL_CONSTASCII_STRINGPARAM (but would lead to ambiguities on 32 bit
    // platforms):
#if SAL_TYPES_SIZEOFLONG == 8
    void matchAsciiL(char const *, sal_Int32, rtl_TextEncoding) const;
#endif

    /**
      Match against a substring appearing in this string, ignoring the case of
      ASCII letters.

      The result is true if and only if the second string appears as a substring
      of this string, at the given position.
      Character values between 65 and 90 (ASCII A-Z) are interpreted as
      values between 97 and 122 (ASCII a-z).
      Since this method is optimized for performance, the ASCII character
      values are not converted in any way. The caller has to make sure that
      all ASCII characters are in the allowed range between 0 and 127.
      The ASCII string must be NULL-terminated and must be greater than or
      equal to asciiStrLength.
      This function can't be used for language specific comparison.

      @param    asciiStr        the 8-Bit ASCII character string to be compared.
      @param    asciiStrLength  the length of the ascii string
      @param    fromIndex       the index to start the comparison from.
                                The index must be greater than or equal to 0
                                and less than or equal to the string length.
      @return   true if str match with the characters in the string
                at the given position;
                false, otherwise.
    */
    bool matchIgnoreAsciiCaseAsciiL( const sal_Char* asciiStr, sal_Int32 asciiStrLength, sal_Int32 fromIndex = 0 ) const
    {
        return rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
                                                                          asciiStr, asciiStrLength ) == 0;
    }

    // This overload is left undefined, to detect calls of
    // matchIgnoreAsciiCaseAsciiL that erroneously use
    // RTL_CONSTASCII_USTRINGPARAM instead of RTL_CONSTASCII_STRINGPARAM (but
    // would lead to ambiguities on 32 bit platforms):
#if SAL_TYPES_SIZEOFLONG == 8
    void matchIgnoreAsciiCaseAsciiL(char const *, sal_Int32, rtl_TextEncoding)
        const;
#endif

    /**
      Check whether this string starts with a given substring.

      @param str the substring to be compared

      @param rest if non-null, and this function returns true, then assign a
      copy of the remainder of this string to *rest. Available since
      LibreOffice 4.2

      @return true if and only if the given str appears as a substring at the
      start of this string

      @since LibreOffice 4.0
    */
    bool startsWith(OUString const & str, OUString * rest = NULL) const {
        bool b = match(str);
        if (b && rest != NULL) {
            *rest = copy(str.getLength());
        }
        return b;
    }

    /**
     @overload
     This function accepts an ASCII string literal as its argument.
     @since LibreOffice 4.0
    */
    template< typename T >
    typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type startsWith(
        T & literal, OUString * rest = NULL) const
    {
        assert(
            libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
        bool b
            = (libreoffice_internal::ConstCharArrayDetector<T>::length
               <= sal_uInt32(pData->length))
            && rtl_ustr_asciil_reverseEquals_WithLength(
                pData->buffer,
                libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
                    literal),
                libreoffice_internal::ConstCharArrayDetector<T>::length);
        if (b && rest != NULL) {
            *rest = copy(
                libreoffice_internal::ConstCharArrayDetector<T>::length);
        }
        return b;
    }

#if defined LIBO_INTERNAL_ONLY
    /** @overload @since LibreOffice 5.3 */
    template<typename T>
    typename libreoffice_internal::ConstCharArrayDetector<T, bool>::TypeUtf16
    startsWith(T & literal, OUString * rest = nullptr) const {
        bool b
            = (libreoffice_internal::ConstCharArrayDetector<T>::length
               <= sal_uInt32(pData->length))
            && (rtl_ustr_reverseCompare_WithLength(
                    pData->buffer,
                    libreoffice_internal::ConstCharArrayDetector<T>::length,
                    libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
                        literal),
                    libreoffice_internal::ConstCharArrayDetector<T>::length)
                == 0);
        if (b && rest != nullptr) {
            *rest = copy(
                libreoffice_internal::ConstCharArrayDetector<T>::length);
        }
        return b;
    }

    /** @overload @since LibreOffice 5.4 */
    bool startsWith(OUStringLiteral const & literal, OUString * rest = nullptr)
        const
    {
        bool b = literal.size <= pData->length
            && rtl_ustr_asciil_reverseEquals_WithLength(
                pData->buffer, literal.data, literal.size);
        if (b && rest != nullptr) {
            *rest = copy(literal.size);
        }
        return b;
    }
#endif

    /**
      Check whether this string starts with a given string, ignoring the case of
      ASCII letters.

      Character values between 65 and 90 (ASCII A-Z) are interpreted as
      values between 97 and 122 (ASCII a-z).
      This function can't be used for language specific comparison.

      @param str the substring to be compared

      @param rest if non-null, and this function returns true, then assign a
      copy of the remainder of this string to *rest. Available since
      LibreOffice 4.2

      @return true if and only if the given str appears as a substring at the
      start of this string, ignoring the case of ASCII letters ("A"--"Z" and
      "a"--"z")

      @since LibreOffice 4.0
    */
    bool startsWithIgnoreAsciiCase(OUString const & str, OUString * rest = NULL)
        const
    {
        bool b = matchIgnoreAsciiCase(str);
        if (b && rest != NULL) {
            *rest = copy(str.getLength());
        }
        return b;
    }

    /**
     @overload
     This function accepts an ASCII string literal as its argument.
     @since LibreOffice 4.0
    */
    template< typename T >
    typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
    startsWithIgnoreAsciiCase(T & literal, OUString * rest = NULL) const
    {
        assert(
            libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
        bool b
            = (rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths(
                   pData->buffer,
                   libreoffice_internal::ConstCharArrayDetector<T>::length,
                   libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
                       literal),
                   libreoffice_internal::ConstCharArrayDetector<T>::length)
               == 0);
        if (b && rest != NULL) {
            *rest = copy(
                libreoffice_internal::ConstCharArrayDetector<T>::length);
        }
        return b;
    }

#if defined LIBO_INTERNAL_ONLY
    /** @overload @since LibreOffice 5.3 */
    template<typename T>
    typename libreoffice_internal::ConstCharArrayDetector<T, bool>::TypeUtf16
    startsWithIgnoreAsciiCase(T & literal, OUString * rest = nullptr) const {
        bool b
            = (libreoffice_internal::ConstCharArrayDetector<T>::length
               <= sal_uInt32(pData->length))
            && (rtl_ustr_compareIgnoreAsciiCase_WithLength(
                    pData->buffer,
                    libreoffice_internal::ConstCharArrayDetector<T>::length,
                    libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
                        literal),
                    libreoffice_internal::ConstCharArrayDetector<T>::length)
                == 0);
        if (b && rest != nullptr) {
            *rest = copy(
                libreoffice_internal::ConstCharArrayDetector<T>::length);
        }
        return b;
    }

    /** @overload @since LibreOffice 5.4 */
    bool startsWithIgnoreAsciiCase(
        OUStringLiteral const & literal, OUString * rest = nullptr) const
    {
        bool b
            = (rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths(
                   pData->buffer, literal.size, literal.data, literal.size)
               == 0);
        if (b && rest != nullptr) {
            *rest = copy(literal.size);
        }
        return b;
    }
#endif

    /**
      Check whether this string ends with a given substring.

      @param str the substring to be compared

      @param rest if non-null, and this function returns true, then assign a
      copy of the remainder of this string to *rest. Available since
      LibreOffice 4.2

      @return true if and only if the given str appears as a substring at the
      end of this string

      @since LibreOffice 3.6
    */
    bool endsWith(OUString const & str, OUString * rest = NULL) const {
        bool b = str.getLength() <= getLength()
            && match(str, getLength() - str.getLength());
        if (b && rest != NULL) {
            *rest = copy(0, getLength() - str.getLength());
        }
        return b;
    }

    /**
     @overload
     This function accepts an ASCII string literal as its argument.
     @since LibreOffice 3.6
    */
    template< typename T >
    typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
    endsWith(T & literal, OUString * rest = NULL) const
    {
        assert(
            libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
        bool b
            = (libreoffice_internal::ConstCharArrayDetector<T>::length
               <= sal_uInt32(pData->length))
            && rtl_ustr_asciil_reverseEquals_WithLength(
                (pData->buffer + pData->length
                 - libreoffice_internal::ConstCharArrayDetector<T>::length),
                libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
                    literal),
                libreoffice_internal::ConstCharArrayDetector<T>::length);
        if (b && rest != NULL) {
            *rest = copy(
                0,
                (getLength()
                 - libreoffice_internal::ConstCharArrayDetector<T>::length));
        }
        return b;
    }

#if defined LIBO_INTERNAL_ONLY
    /** @overload @since LibreOffice 5.3 */
    template<typename T>
    typename libreoffice_internal::ConstCharArrayDetector<T, bool>::TypeUtf16
    endsWith(T & literal, OUString * rest = nullptr) const {
        bool b
            = (libreoffice_internal::ConstCharArrayDetector<T>::length
               <= sal_uInt32(pData->length))
            && (rtl_ustr_reverseCompare_WithLength(
                    (pData->buffer + pData->length
                     - libreoffice_internal::ConstCharArrayDetector<T>::length),
                    libreoffice_internal::ConstCharArrayDetector<T>::length,
                    libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
                        literal),
                    libreoffice_internal::ConstCharArrayDetector<T>::length)
                == 0);
        if (b && rest != nullptr) {
            *rest = copy(
                0,
                (getLength()
                 - libreoffice_internal::ConstCharArrayDetector<T>::length));
        }
        return b;
    }

    /** @overload @since LibreOffice 5.4 */
    bool endsWith(OUStringLiteral const & literal, OUString * rest = nullptr)
        const
    {
        bool b = literal.size <= pData->length
            && rtl_ustr_asciil_reverseEquals_WithLength(
                pData->buffer + pData->length - literal.size,
                literal.data, literal.size);
        if (b && rest != nullptr) {
            *rest = copy(0, (getLength() - literal.size));
        }
        return b;
    }
#endif

    /**
      Check whether this string ends with a given ASCII string.

      @param asciiStr a sequence of at least asciiStrLength ASCII characters
          (bytes in the range 0x00--0x7F)
      @param asciiStrLength the length of asciiStr; must be non-negative
      @return true if this string ends with asciiStr; otherwise, false is
      returned

      @since UDK 3.2.7
     */
    bool endsWithAsciiL(char const * asciiStr, sal_Int32 asciiStrLength)
        const
    {
        return asciiStrLength <= pData->length
            && rtl_ustr_asciil_reverseEquals_WithLength(
                pData->buffer + pData->length - asciiStrLength, asciiStr,
                asciiStrLength);
    }

    /**
      Check whether this string ends with a given string, ignoring the case of
      ASCII letters.

      Character values between 65 and 90 (ASCII A-Z) are interpreted as
      values between 97 and 122 (ASCII a-z).
      This function can't be used for language specific comparison.

      @param str the substring to be compared

      @param rest if non-null, and this function returns true, then assign a
      copy of the remainder of this string to *rest. Available since
      LibreOffice 4.2

      @return true if and only if the given str appears as a substring at the
      end of this string, ignoring the case of ASCII letters ("A"--"Z" and
      "a"--"z")

      @since LibreOffice 3.6
    */
    bool endsWithIgnoreAsciiCase(OUString const & str, OUString * rest = NULL) const
    {
        bool b =  str.getLength() <= getLength()
            && matchIgnoreAsciiCase(str, getLength() - str.getLength());
        if (b && rest != NULL) {
            *rest = copy(0, getLength() - str.getLength());
        }
        return b;
    }

    /**
     @overload
     This function accepts an ASCII string literal as its argument.
     @since LibreOffice 3.6
    */
    template< typename T >
    typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
    endsWithIgnoreAsciiCase(T & literal, OUString * rest = NULL) const
    {
        assert(
            libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
        bool b
            = (libreoffice_internal::ConstCharArrayDetector<T>::length
               <= sal_uInt32(pData->length))
            && (rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths(
                    (pData->buffer + pData->length
                     - libreoffice_internal::ConstCharArrayDetector<T>::length),
                    libreoffice_internal::ConstCharArrayDetector<T>::length,
                    libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
                        literal),
                    libreoffice_internal::ConstCharArrayDetector<T>::length)
                == 0);
        if (b && rest != NULL) {
            *rest = copy(
                0,
                (getLength()
                 - libreoffice_internal::ConstCharArrayDetector<T>::length));
        }
        return b;
    }

#if defined LIBO_INTERNAL_ONLY
    /** @overload @since LibreOffice 5.3 */
    template<typename T>
    typename libreoffice_internal::ConstCharArrayDetector<T, bool>::TypeUtf16
    endsWithIgnoreAsciiCase(T & literal, OUString * rest = nullptr) const {
        bool b
            = (libreoffice_internal::ConstCharArrayDetector<T>::length
               <= sal_uInt32(pData->length))
            && (rtl_ustr_compareIgnoreAsciiCase_WithLength(
                    (pData->buffer + pData->length
                     - libreoffice_internal::ConstCharArrayDetector<T>::length),
                    libreoffice_internal::ConstCharArrayDetector<T>::length,
                    libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
                        literal),
                    libreoffice_internal::ConstCharArrayDetector<T>::length)
                == 0);
        if (b && rest != nullptr) {
            *rest = copy(
                0,
                (getLength()
                 - libreoffice_internal::ConstCharArrayDetector<T>::length));
        }
        return b;
    }

    /** @overload @since LibreOffice 5.4 */
    bool endsWithIgnoreAsciiCase(
        OUStringLiteral const & literal, OUString * rest = nullptr) const
    {
        bool b = literal.size <= pData->length
            && (rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths(
                    pData->buffer + pData->length - literal.size,
                    literal.size, literal.data, literal.size)
                == 0);
        if (b && rest != nullptr) {
            *rest = copy(0, getLength() - literal.size);
        }
        return b;
    }
#endif

    /**
      Check whether this string ends with a given ASCII string, ignoring the
      case of ASCII letters.

      @param asciiStr a sequence of at least asciiStrLength ASCII characters
          (bytes in the range 0x00--0x7F)
      @param asciiStrLength the length of asciiStr; must be non-negative
      @return true if this string ends with asciiStr, ignoring the case of ASCII
      letters ("A"--"Z" and "a"--"z"); otherwise, false is returned
     */
    bool endsWithIgnoreAsciiCaseAsciiL(
        char const * asciiStr, sal_Int32 asciiStrLength) const
    {
        return asciiStrLength <= pData->length
            && (rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths(
                    pData->buffer + pData->length - asciiStrLength,
                    asciiStrLength, asciiStr, asciiStrLength)
                == 0);
    }

    friend bool     operator == ( const OUString& rStr1,    const OUString& rStr2 )
                        { return rStr1.equals(rStr2); }
    friend bool     operator == ( const OUString& rStr1,    const sal_Unicode * pStr2 )
                        { return rStr1.compareTo( pStr2 ) == 0; }
    friend bool     operator == ( const sal_Unicode * pStr1,    const OUString& rStr2 )
                        { return OUString( pStr1 ).compareTo( rStr2 ) == 0; }

    friend bool     operator != ( const OUString& rStr1,        const OUString& rStr2 )
                        { return !(operator == ( rStr1, rStr2 )); }
    friend bool     operator != ( const OUString& rStr1,    const sal_Unicode * pStr2 )
                        { return !(operator == ( rStr1, pStr2 )); }
    friend bool     operator != ( const sal_Unicode * pStr1,    const OUString& rStr2 )
                        { return !(operator == ( pStr1, rStr2 )); }

    friend bool     operator <  ( const OUString& rStr1,    const OUString& rStr2 )
                        { return rStr1.compareTo( rStr2 ) < 0; }
    friend bool     operator >  ( const OUString& rStr1,    const OUString& rStr2 )
                        { return rStr1.compareTo( rStr2 ) > 0; }
    friend bool     operator <= ( const OUString& rStr1,    const OUString& rStr2 )
                        { return rStr1.compareTo( rStr2 ) <= 0; }
    friend bool     operator >= ( const OUString& rStr1,    const OUString& rStr2 )
                        { return rStr1.compareTo( rStr2 ) >= 0; }

    /**
     * Compare string to an ASCII string literal.
     *
     * This operator is equal to calling equalsAsciiL().
     *
     * @since LibreOffice 3.6
     */
    template< typename T >
    friend typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator==( const OUString& rString, T& literal )
    {
        assert(
            libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
        return rString.equalsAsciiL(
            libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
            libreoffice_internal::ConstCharArrayDetector<T>::length);
    }
    /**
     * Compare string to an ASCII string literal.
     *
     * This operator is equal to calling equalsAsciiL().
     *
     * @since LibreOffice 3.6
     */
    template< typename T >
    friend typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator==( T& literal, const OUString& rString )
    {
        assert(
            libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
        return rString.equalsAsciiL(
            libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
            libreoffice_internal::ConstCharArrayDetector<T>::length);
    }
    /**
     * Compare string to an ASCII string literal.
     *
     * This operator is equal to calling !equalsAsciiL().
     *
     * @since LibreOffice 3.6
     */
    template< typename T >
    friend typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator!=( const OUString& rString, T& literal )
    {
        assert(
            libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
        return !rString.equalsAsciiL(
            libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
            libreoffice_internal::ConstCharArrayDetector<T>::length);
    }
    /**
     * Compare string to an ASCII string literal.
     *
     * This operator is equal to calling !equalsAsciiL().
     *
     * @since LibreOffice 3.6
     */
    template< typename T >
    friend typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator!=( T& literal, const OUString& rString )
    {
        assert(
            libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
        return !rString.equalsAsciiL(
            libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
            libreoffice_internal::ConstCharArrayDetector<T>::length);
    }

#if defined LIBO_INTERNAL_ONLY
    /** @overload @since LibreOffice 5.3 */
    template<typename T> friend typename libreoffice_internal::ConstCharArrayDetector<T, bool>::TypeUtf16
    operator ==(OUString & string, T & literal) {
        return
            rtl_ustr_reverseCompare_WithLength(
                string.pData->buffer, string.pData->length,
                libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
                    literal),
                libreoffice_internal::ConstCharArrayDetector<T>::length)
            == 0;
    }
    /** @overload @since LibreOffice 5.3 */
    template<typename T> friend typename libreoffice_internal::ConstCharArrayDetector<T, bool>::TypeUtf16
    operator ==(T & literal, OUString & string) {
        return
            rtl_ustr_reverseCompare_WithLength(
                libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
                    literal),
                libreoffice_internal::ConstCharArrayDetector<T>::length,
                string.pData->buffer, string.pData->length)
            == 0;
    }
    /** @overload @since LibreOffice 5.3 */
    template<typename T> friend typename libreoffice_internal::ConstCharArrayDetector<T, bool>::TypeUtf16
    operator !=(OUString & string, T & literal) {
        return
            rtl_ustr_reverseCompare_WithLength(
                string.pData->buffer, string.pData->length,
                libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
                    literal),
                libreoffice_internal::ConstCharArrayDetector<T>::length)
            != 0;
    }
    /** @overload @since LibreOffice 5.3 */
    template<typename T> friend typename libreoffice_internal::ConstCharArrayDetector<T, bool>::TypeUtf16
    operator !=(T & literal, OUString & string) {
        return
            rtl_ustr_reverseCompare_WithLength(
                libreoffice_internal::ConstCharArrayDetector<T>::toPointer(
                    literal),
                libreoffice_internal::ConstCharArrayDetector<T>::length,
                string.pData->buffer, string.pData->length)
            != 0;
    }
#endif

#if defined LIBO_INTERNAL_ONLY
    /// @cond INTERNAL

    /* Comparison between OUString and OUStringLiteral.

       @since LibreOffice 5.0
    */

    friend bool operator ==(OUString const & lhs, OUStringLiteral const & rhs) {
        return lhs.equalsAsciiL(rhs.data, rhs.size);
    }

    friend bool operator !=(OUString const & lhs, OUStringLiteral const & rhs) {
        return !lhs.equalsAsciiL(rhs.data, rhs.size);
    }

    friend bool operator <(OUString const & lhs, OUStringLiteral const & rhs) {
        return
            (rtl_ustr_ascii_compare_WithLength(
                lhs.pData->buffer, lhs.pData->length, rhs.data))
            < 0;
    }

    friend bool operator <=(OUString const & lhs, OUStringLiteral const & rhs) {
        return
            (rtl_ustr_ascii_compare_WithLength(
                lhs.pData->buffer, lhs.pData->length, rhs.data))
            <= 0;
    }

    friend bool operator >(OUString const & lhs, OUStringLiteral const & rhs) {
        return
            (rtl_ustr_ascii_compare_WithLength(
                lhs.pData->buffer, lhs.pData->length, rhs.data))
            > 0;
    }

    friend bool operator >=(OUString const & lhs, OUStringLiteral const & rhs) {
        return
            (rtl_ustr_ascii_compare_WithLength(
                lhs.pData->buffer, lhs.pData->length, rhs.data))
            >= 0;
    }

    friend bool operator ==(OUStringLiteral const & lhs, OUString const & rhs) {
        return rhs.equalsAsciiL(lhs.data, lhs.size);
    }

    friend bool operator !=(OUStringLiteral const & lhs, OUString const & rhs) {
        return !rhs.equalsAsciiL(lhs.data, lhs.size);
    }

    friend bool operator <(OUStringLiteral const & lhs, OUString const & rhs) {
        return
            (rtl_ustr_ascii_compare_WithLength(
                rhs.pData->buffer, rhs.pData->length, lhs.data))
            >= 0;
    }

    friend bool operator <=(OUStringLiteral const & lhs, OUString const & rhs) {
        return
            (rtl_ustr_ascii_compare_WithLength(
                rhs.pData->buffer, rhs.pData->length, lhs.data))
            > 0;
    }

    friend bool operator >(OUStringLiteral const & lhs, OUString const & rhs) {
        return
            (rtl_ustr_ascii_compare_WithLength(
                rhs.pData->buffer, rhs.pData->length, lhs.data))
            <= 0;
    }

    friend bool operator >=(OUStringLiteral const & lhs, OUString const & rhs) {
        return
            (rtl_ustr_ascii_compare_WithLength(
                rhs.pData->buffer, rhs.pData->length, lhs.data))
            < 0;
    }

    /// @endcond
#endif

    /**
      Returns a hashcode for this string.

      @return   a hash code value for this object.

      @see rtl::OUStringHash for convenient use of std::unordered_map
    */
    sal_Int32 hashCode() const
    {
        return rtl_ustr_hashCode_WithLength( pData->buffer, pData->length );
    }

    /**
      Returns the index within this string of the first occurrence of the
      specified character, starting the search at the specified index.

      @param    ch          character to be located.
      @param    fromIndex   the index to start the search from.
                            The index must be greater than or equal to 0
                            and less than or equal to the string length.
      @return   the index of the first occurrence of the character in the
                character sequence represented by this string that is
                greater than or equal to fromIndex, or
                -1 if the character does not occur.
    */
    sal_Int32 indexOf( sal_Unicode ch, sal_Int32 fromIndex = 0 ) const
    {
        sal_Int32 ret = rtl_ustr_indexOfChar_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, ch );
        return (ret < 0 ? ret : ret+fromIndex);
    }

    /**
      Returns the index within this string of the last occurrence of the
      specified character, searching backward starting at the end.

      @param    ch          character to be located.
      @return   the index of the last occurrence of the character in the
                character sequence represented by this string, or
                -1 if the character does not occur.
    */
    sal_Int32 lastIndexOf( sal_Unicode ch ) const
    {
        return rtl_ustr_lastIndexOfChar_WithLength( pData->buffer, pData->length, ch );
    }

    /**
      Returns the index within this string of the last occurrence of the
      specified character, searching backward starting before the specified
      index.

      @param    ch          character to be located.
      @param    fromIndex   the index before which to start the search.
      @return   the index of the last occurrence of the character in the
                character sequence represented by this string that
                is less than fromIndex, or -1
                if the character does not occur before that point.
    */
    sal_Int32 lastIndexOf( sal_Unicode ch, sal_Int32 fromIndex ) const
    {
        return rtl_ustr_lastIndexOfChar_WithLength( pData->buffer, fromIndex, ch );
    }

    /**
      Returns the index within this string of the first occurrence of the
      specified substring, starting at the specified index.

      If str doesn't include any character, always -1 is
      returned. This is also the case, if both strings are empty.

      @param    str         the substring to search for.
      @param    fromIndex   the index to start the search from.
      @return   If the string argument occurs one or more times as a substring
                within this string at the starting index, then the index
                of the first character of the first such substring is
                returned. If it does not occur as a substring starting
                at fromIndex or beyond, -1 is returned.
    */
    sal_Int32 indexOf( const OUString & str, sal_Int32 fromIndex = 0 ) const
    {
        sal_Int32 ret = rtl_ustr_indexOfStr_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
                                                        str.pData->buffer, str.pData->length );
        return (ret < 0 ? ret : ret+fromIndex);
    }

    /**
     @overload
     This function accepts an ASCII string literal as its argument.
     @since LibreOffice 3.6
    */
    template< typename T >
    typename libreoffice_internal::ConstCharArrayDetector< T, sal_Int32 >::Type indexOf( T& literal, sal_Int32 fromIndex = 0 ) const
    {
        assert(
            libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
        sal_Int32 n = rtl_ustr_indexOfAscii_WithLength(
            pData->buffer + fromIndex, pData->length - fromIndex,
            libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
            libreoffice_internal::ConstCharArrayDetector<T>::length);
        return n < 0 ? n : n + fromIndex;
    }

#if defined LIBO_INTERNAL_ONLY
    /** @overload @since LibreOffice 5.3 */
    template<typename T>
    typename
        libreoffice_internal::ConstCharArrayDetector<T, sal_Int32>::TypeUtf16
    indexOf(T & literal, sal_Int32 fromIndex = 0) const {
        assert(fromIndex >= 0);
        auto n = rtl_ustr_indexOfStr_WithLength(
            pData->buffer + fromIndex, pData->length - fromIndex,
            libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
            libreoffice_internal::ConstCharArrayDetector<T>::length);
        return n < 0 ? n : n + fromIndex;
    }

    /** @overload @since LibreOffice 5.4 */
    sal_Int32 indexOf(OUStringLiteral const & literal, sal_Int32 fromIndex = 0)
        const
    {
        sal_Int32 n = rtl_ustr_indexOfAscii_WithLength(
            pData->buffer + fromIndex, pData->length - fromIndex, literal.data,
            literal.size);
        return n < 0 ? n : n + fromIndex;
    }
#endif

    /**
       Returns the index within this string of the first occurrence of the
       specified ASCII substring, starting at the specified index.

       @param str
       the substring to be searched for.  Need not be null-terminated, but must
       be at least as long as the specified len.  Must only contain characters
       in the ASCII range 0x00--7F.

       @param len
       the length of the substring; must be non-negative.

       @param fromIndex
       the index to start the search from.  Must be in the range from zero to
       the length of this string, inclusive.

       @return
       the index (starting at 0) of the first character of the first occurrence
       of the substring within this string starting at the given fromIndex, or
       -1 if the substring does not occur.  If len is zero, -1 is returned.

       @since UDK 3.2.7
    */
    sal_Int32 indexOfAsciiL(
        char const * str, sal_Int32 len, sal_Int32 fromIndex = 0) const
    {
        sal_Int32 ret = rtl_ustr_indexOfAscii_WithLength(
            pData->buffer + fromIndex, pData->length - fromIndex, str, len);
        return ret < 0 ? ret : ret + fromIndex;
    }

    // This overload is left undefined, to detect calls of indexOfAsciiL that
    // erroneously use RTL_CONSTASCII_USTRINGPARAM instead of
    // RTL_CONSTASCII_STRINGPARAM (but would lead to ambiguities on 32 bit
    // platforms):
#if SAL_TYPES_SIZEOFLONG == 8
    void indexOfAsciiL(char const *, sal_Int32 len, rtl_TextEncoding) const;
#endif

    /**
      Returns the index within this string of the last occurrence of
      the specified substring, searching backward starting at the end.

      The returned index indicates the starting index of the substring
      in this string.
      If str doesn't include any character, always -1 is
      returned. This is also the case, if both strings are empty.

      @param    str         the substring to search for.
      @return   If the string argument occurs one or more times as a substring
                within this string, then the index of the first character of
                the last such substring is returned. If it does not occur as
                a substring, -1 is returned.
    */
    sal_Int32 lastIndexOf( const OUString & str ) const
    {
        return rtl_ustr_lastIndexOfStr_WithLength( pData->buffer, pData->length,
                                                   str.pData->buffer, str.pData->length );
    }

    /**
      Returns the index within this string of the last occurrence of
      the specified substring, searching backward starting before the specified
      index.

      The returned index indicates the starting index of the substring
      in this string.
      If str doesn't include any character, always -1 is
      returned. This is also the case, if both strings are empty.

      @param    str         the substring to search for.
      @param    fromIndex   the index before which to start the search.
      @return   If the string argument occurs one or more times as a substring
                within this string before the starting index, then the index
                of the first character of the last such substring is
                returned. Otherwise, -1 is returned.
    */
    sal_Int32 lastIndexOf( const OUString & str, sal_Int32 fromIndex ) const
    {
        return rtl_ustr_lastIndexOfStr_WithLength( pData->buffer, fromIndex,
                                                   str.pData->buffer, str.pData->length );
    }

    /**
     @overload
     This function accepts an ASCII string literal as its argument.
     @since LibreOffice 3.6
    */
    template< typename T >
    typename libreoffice_internal::ConstCharArrayDetector< T, sal_Int32 >::Type lastIndexOf( T& literal ) const
    {
        assert(
            libreoffice_internal::ConstCharArrayDetector<T>::isValid(literal));
        return rtl_ustr_lastIndexOfAscii_WithLength(
            pData->buffer, pData->length,
            libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
            libreoffice_internal::ConstCharArrayDetector<T>::length);
    }

#if defined LIBO_INTERNAL_ONLY
    /** @overload @since LibreOffice 5.3 */
    template<typename T>
    typename
        libreoffice_internal::ConstCharArrayDetector<T, sal_Int32>::TypeUtf16
    lastIndexOf(T & literal) const {
        return rtl_ustr_lastIndexOfStr_WithLength(
            pData->buffer, pData->length,
            libreoffice_internal::ConstCharArrayDetector<T>::toPointer(literal),
            libreoffice_internal::ConstCharArrayDetector<T>::length);
    }

    /** @overload @since LibreOffice 5.4 */
    sal_Int32 lastIndexOf(OUStringLiteral const & literal) const {
        return rtl_ustr_lastIndexOfAscii_WithLength(
            pData->buffer, pData->length, literal.data, literal.size);
    }
#endif

    /**
       Returns the index within this string of the last occurrence of the
       specified ASCII substring.

       @param str
       the substring to be searched for.  Need not be null-terminated, but must
       be at least as long as the specified len.  Must only contain characters
       in the ASCII range 0x00--7F.

       @param len
       the length of the substring; must be non-negative.

       @return
       the index (starting at 0) of the first character of the last occurrence
       of the substring within this string, or -1 if the substring does not
       occur.  If len is zero, -1 is returned.

       @since UDK 3.2.7
    */
    sal_Int32 lastIndexOfAsciiL(char const * str, sal_Int32 len) const
    {
        return rtl_ustr_lastIndexOfAscii_WithLength(
            pData->buffer, pData->length, str, len);
    }

    /**
      Returns a new string that is a substring of this string.

      The substring begins at the specified beginIndex. If
      beginIndex is negative or be greater than the length of
      this string, behaviour is undefined.

      @param     beginIndex   the beginning index, inclusive.
      @return    the specified substring.
    */
    SAL_WARN_UNUSED_RESULT OUString copy( sal_Int32 beginIndex ) const
    {
        return copy(beginIndex, getLength() - beginIndex);
    }

    /**
      Returns a new string that is a substring of this string.

      The substring begins at the specified beginIndex and contains count
      characters.  If either beginIndex or count are negative,
      or beginIndex + count are greater than the length of this string
      then behaviour is undefined.

      @param     beginIndex   the beginning index, inclusive.
      @param     count        the number of characters.
      @return    the specified substring.
    */
    SAL_WARN_UNUSED_RESULT OUString copy( sal_Int32 beginIndex, sal_Int32 count ) const
    {
        rtl_uString *pNew = NULL;
        rtl_uString_newFromSubString( &pNew, pData, beginIndex, count );
        return OUString( pNew, SAL_NO_ACQUIRE );
    }

    /**
      Concatenates the specified string to the end of this string.

      @param    str   the string that is concatenated to the end
                      of this string.
      @return   a string that represents the concatenation of this string
                followed by the string argument.
    */
    SAL_WARN_UNUSED_RESULT OUString concat( const OUString & str ) const
    {
        rtl_uString* pNew = NULL;
        rtl_uString_newConcat( &pNew, pData, str.pData );
        return OUString( pNew, SAL_NO_ACQUIRE );
    }

#ifndef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
    friend OUString operator+( const OUString& rStr1, const OUString& rStr2  )
    {
        return rStr1.concat( rStr2 );
    }
#endif

    /**
      Returns a new string resulting from replacing n = count characters
      from position index in this string with newStr.

      @param  index   the replacing index in str.
                      The index must be greater than or equal to 0 and
                      less than or equal to the length of the string.
      @param  count   the count of characters that will be replaced
                      The count must be greater than or equal to 0 and
                      less than or equal to the length of the string minus index.
      @param  newStr  the new substring.
      @return the new string.
    */
    SAL_WARN_UNUSED_RESULT OUString replaceAt( sal_Int32 index, sal_Int32 count, const OUString& newStr ) const
    {
        rtl_uString* pNew = NULL;
        rtl_uString_newReplaceStrAt( &pNew, pData, index, count, newStr.pData );
        return OUString( pNew, SAL_NO_ACQUIRE );
    }

    /**
      Returns a new string resulting from replacing all occurrences of
      oldChar in this string with newChar.

      If the character oldChar does not occur in the character sequence
      represented by this object, then the string is assigned with
      str.

      @param    oldChar     the old character.
      @param    newChar     the new character.
      @return   a string derived from this string by replacing every
                occurrence of oldChar with newChar.
    */
    SAL_WARN_UNUSED_RESULT OUString replace( sal_Unicode oldChar, sal_Unicode newChar ) const
    {
        rtl_uString* pNew = NULL;
        rtl_uString_newReplace( &pNew, pData, oldChar, newChar );
        return OUString( pNew, SAL_NO_ACQUIRE );
    }

    /**
      Returns a new string resulting from replacing the first occurrence of a
      given substring with another substring.

      @param from  the substring to be replaced

      @param to  the replacing substring

      @param[in,out] index  pointer to a start index; if the pointer is
      non-null: upon entry to the function, its value is the index into this
      string at which to start searching for the \p from substring, the value
      must be non-negative and not greater than this string's length; upon exiting
      the function its value is the index into this string at which the
      replacement took place or -1 if no replacement took place; if the pointer
      is null, searching always starts at index 0

      @since LibreOffice 3.6
    */
    SAL_WARN_UNUSED_RESULT OUString replaceFirst(
        OUString const & from, OUString const & to, sal_Int32 * index = NULL) const
    {
        rtl_uString * s = NULL;
        sal_Int32 i = 0;
        rtl_uString_newReplaceFirst(
            &s, pData, from.pData, to.pData, index == NULL ? &i : index);
        return OUString(s, SAL_NO_ACQUIRE);
    }

    /**
      Returns a new string resulting from replacing the first occurrence of a
      given substring with another substring.

      @param from  ASCII string literal, the substring to be replaced

      @param to  the replacing substring

      @param[in,out] index  pointer to a start index; if the pointer is
      non-null: upon entry to the function, its value is the index into the this
      string at which to start searching for the \p from substring, the value
      must be non-negative and not greater than this string's length; upon exiting
      the function its value is the index into this string at which the
      replacement took place or -1 if no replacement took place; if the pointer
      is null, searching always starts at index 0

      @since LibreOffice 3.6
    */
    template< typename T >
    SAL_WARN_UNUSED_RESULT typename libreoffice_internal::ConstCharArrayDetector< T, OUString >::Type replaceFirst( T& from, OUString const & to,
                                                                                                        sal_Int32 * index = NULL) const
    {
        assert(libreoffice_internal::ConstCharArrayDetector<T>::isValid(from));
        rtl_uString * s = NULL;
        sal_Int32 i = 0;
        rtl_uString_newReplaceFirstAsciiL(
            &s, pData,
            libreoffice_internal::ConstCharArrayDetector<T>::toPointer(from),
            libreoffice_internal::ConstCharArrayDetector<T>::length, to.pData,
            index == NULL ? &i : index);
        return OUString(s, SAL_NO_ACQUIRE);
    }

    /**
      Returns a new string resulting from replacing the first occurrence of a
      given substring with another substring.

      @param from  the substring to be replaced

      @param to  ASCII string literal, the replacing substring

      @param[in,out] index  pointer to a start index; if the pointer is
      non-null: upon entry to the function, its value is the index into the this
      string at which to start searching for the \p from substring, the value
      must be non-negative and not greater than this string's length; upon exiting
      the function its value is the index into this string at which the
      replacement took place or -1 if no replacement took place; if the pointer
      is null, searching always starts at index 0

      @since LibreOffice 5.1
    */
    template< typename T >
    SAL_WARN_UNUSED_RESULT typename libreoffice_internal::ConstCharArrayDetector< T, OUString >::Type replaceFirst( OUString const & from, T& to,
                                                                                                        sal_Int32 * index = NULL) const
    {
        assert(libreoffice_internal::ConstCharArrayDetector<T>::isValid(to));
        rtl_uString * s = NULL;
        sal_Int32 i = 0;
        rtl_uString_newReplaceFirstToAsciiL(
            &s, pData, from.pData,
            libreoffice_internal::ConstCharArrayDetector<T>::toPointer(to),
            libreoffice_internal::ConstCharArrayDetector<T>::length,
            index == NULL ? &i : index);
        return OUString(s, SAL_NO_ACQUIRE);
    }

    /**
      Returns a new string resulting from replacing the first occurrence of a
      given substring with another substring.

      @param from  ASCII string literal, the substring to be replaced

      @param to  ASCII string literal, the substring to be replaced

      @param[in,out] index  pointer to a start index; if the pointer is
      non-null: upon entry to the function, its value is the index into the this
      string at which to start searching for the \p from substring, the value
      must be non-negative and not greater than this string's length; upon exiting
      the function its value is the index into this string at which the
      replacement took place or -1 if no replacement took place; if the pointer
      is null, searching always starts at index 0

      @since LibreOffice 3.6
    */
    template< typename T1, typename T2 >
        SAL_WARN_UNUSED_RESULT typename libreoffice_internal::ConstCharArrayDetector< T1, typename libreoffice_internal::ConstCharArrayDetector< T2, OUString >::Type >::Type
        replaceFirst( T1& from, T2& to, sal_Int32 * index = NULL) const
    {
        assert(libreoffice_internal::ConstCharArrayDetector<T1>::isValid(from));
        assert(libreoffice_internal::ConstCharArrayDetector<T2>::isValid(to));
        rtl_uString * s = NULL;
        sal_Int32 i = 0;
        rtl_uString_newReplaceFirstAsciiLAsciiL(
            &s, pData,
            libreoffice_internal::ConstCharArrayDetector<T1>::toPointer(from),
            libreoffice_internal::ConstCharArrayDetector<T1>::length,
            libreoffice_internal::ConstCharArrayDetector<T2>::toPointer(to),
            libreoffice_internal::ConstCharArrayDetector<T2>::length,
            index == NULL ? &i : index);
        return OUString(s, SAL_NO_ACQUIRE);
    }

#if defined LIBO_INTERNAL_ONLY
    /** @overload @since LibreOffice 5.3 */
    template<typename T> [[nodiscard]]
    typename
        libreoffice_internal::ConstCharArrayDetector<T, OUString>::TypeUtf16
    replaceFirst(T & from, OUString const & to, sal_Int32 * index = nullptr)
        const
    {
        rtl_uString * s = nullptr;
        sal_Int32 i = 0;
        rtl_uString_newReplaceFirstUtf16LUtf16L(
            &s, pData,
            libreoffice_internal::ConstCharArrayDetector<T>::toPointer(from),
            libreoffice_internal::ConstCharArrayDetector<T>::length,
            to.pData->buffer, to.pData->length, index == nullptr ? &i : index);
        if (s == nullptr) {
            throw std::bad_alloc();
                // should be std::length_error if resulting would be too large
        }
        return OUString(s, SAL_NO_ACQUIRE);
    }
    /** @overload @since LibreOffice 5.3 */
    template<typename T> [[nodiscard]]
    typename
        libreoffice_internal::ConstCharArrayDetector<T, OUString>::TypeUtf16
    replaceFirst(OUString const & from, T & to, sal_Int32 * index = nullptr)
        const
    {
        rtl_uString * s = nullptr;
        sal_Int32 i = 0;
        rtl_uString_newReplaceFirstUtf16LUtf16L(
            &s, pData, from.pData->buffer, from.pData->length,
            libreoffice_internal::ConstCharArrayDetector<T>::toPointer(to),
            libreoffice_internal::ConstCharArrayDetector<T>::length,
            index == nullptr ? &i : index);
        if (s == nullptr) {
            throw std::bad_alloc();
                // should be std::length_error if resulting would be too large
        }
        return OUString(s, SAL_NO_ACQUIRE);
    }
    /** @overload @since LibreOffice 5.3 */
    template<typename T1, typename T2> [[nodiscard]]
    typename
        libreoffice_internal::ConstCharArrayDetector<
            T1,
            typename libreoffice_internal::ConstCharArrayDetector<
                T2, OUString>::TypeUtf16
        >::TypeUtf16
    replaceFirst(T1 & from, T2 & to, sal_Int32 * index = nullptr) const {
        rtl_uString * s = nullptr;
        sal_Int32 i = 0;
        rtl_uString_newReplaceFirstUtf16LUtf16L(
            &s, pData,
            libreoffice_internal::ConstCharArrayDetector<T1>::toPointer(from),
            libreoffice_internal::ConstCharArrayDetector<T1>::length,
            libreoffice_internal::ConstCharArrayDetector<T2>::toPointer(to),
            libreoffice_internal::ConstCharArrayDetector<T2>::length,
            index == nullptr ? &i : index);
        if (s == nullptr) {
            throw std::bad_alloc();
                // should be std::length_error if resulting would be too large
        }
        return OUString(s, SAL_NO_ACQUIRE);
    }
    /** @overload @since LibreOffice 5.3 */
    template<typename T1, typename T2> [[nodiscard]]
    typename
        libreoffice_internal::ConstCharArrayDetector<
            T1,
            typename libreoffice_internal::ConstCharArrayDetector<
                T2, OUString>::Type
        >::TypeUtf16
    replaceFirst(T1 & from, T2 & to, sal_Int32 * index = nullptr) const {
        rtl_uString * s = nullptr;
        sal_Int32 i = 0;
        rtl_uString_newReplaceFirstUtf16LAsciiL(
            &s, pData,
            libreoffice_internal::ConstCharArrayDetector<T1>::toPointer(from),
            libreoffice_internal::ConstCharArrayDetector<T1>::length,
            libreoffice_internal::ConstCharArrayDetector<T2>::toPointer(to),
            libreoffice_internal::ConstCharArrayDetector<T2>::length,
            index == nullptr ? &i : index);
        if (s == nullptr) {
            throw std::bad_alloc();
                // should be std::length_error if resulting would be too large
        }
        return OUString(s, SAL_NO_ACQUIRE);
    }
    /** @overload @since LibreOffice 5.3 */
    template<typename T1, typename T2> [[nodiscard]]
    typename
        libreoffice_internal::ConstCharArrayDetector<
            T1,
            typename libreoffice_internal::ConstCharArrayDetector<
                T2, OUString>::TypeUtf16
        >::Type
    replaceFirst(T1 & from, T2 & to, sal_Int32 * index = nullptr) const {
        rtl_uString * s = nullptr;
        sal_Int32 i = 0;
        rtl_uString_newReplaceFirstAsciiLUtf16L(
            &s, pData,
            libreoffice_internal::ConstCharArrayDetector<T1>::toPointer(from),
            libreoffice_internal::ConstCharArrayDetector<T1>::length,
            libreoffice_internal::ConstCharArrayDetector<T2>::toPointer(to),
            libreoffice_internal::ConstCharArrayDetector<T2>::length,
            index == nullptr ? &i : index);
        if (s == nullptr) {
            throw std::bad_alloc();
                // should be std::length_error if resulting would be too large
        }
        return OUString(s, SAL_NO_ACQUIRE);
    }

    /** @overload @since LibreOffice 5.4 */
    [[nodiscard]] OUString replaceFirst(
        OUStringLiteral const & from, OUString const & to,
        sal_Int32 * index = nullptr) const
    {
        rtl_uString * s = nullptr;
        sal_Int32 i = 0;
        rtl_uString_newReplaceFirstAsciiL(
            &s, pData, from.data, from.size, to.pData,
            index == nullptr ? &i : index);
        return OUString(s, SAL_NO_ACQUIRE);
    }
    /** @overload @since LibreOffice 5.4 */
    [[nodiscard]] OUString replaceFirst(
        OUString const & from, OUStringLiteral const & to,
        sal_Int32 * index = nullptr) const
    {
        rtl_uString * s = nullptr;
        sal_Int32 i = 0;
        rtl_uString_newReplaceFirstToAsciiL(
            &s, pData, from.pData, to.data, to.size,
            index == nullptr ? &i : index);
        return OUString(s, SAL_NO_ACQUIRE);
    }
    /** @overload @since LibreOffice 5.4 */
    [[nodiscard]] OUString replaceFirst(
        OUStringLiteral const & from, OUStringLiteral const & to,
        sal_Int32 * index = nullptr) const
    {
        rtl_uString * s = nullptr;
        sal_Int32 i = 0;
        rtl_uString_newReplaceFirstAsciiLAsciiL(
            &s, pData, from.data, from.size, to.data, to.size,
            index == nullptr ? &i : index);
        return OUString(s, SAL_NO_ACQUIRE);
    }
    /** @overload @since LibreOffice 5.4 */
    template<typename T> [[nodiscard]]
    typename libreoffice_internal::ConstCharArrayDetector<T, OUString >::Type
    replaceFirst(
        OUStringLiteral const & from, T & to, sal_Int32 * index = nullptr) const
    {
        assert(libreoffice_internal::ConstCharArrayDetector<T>::isValid(to));
        rtl_uString * s = nullptr;
        sal_Int32 i = 0;
        rtl_uString_newReplaceFirstAsciiLAsciiL(
            &s, pData, from.data, from.size,
            libreoffice_internal::ConstCharArrayDetector<T>::toPointer(to),
            libreoffice_internal::ConstCharArrayDetector<T>::length,
            index == nullptr ? &i : index);
        return OUString(s, SAL_NO_ACQUIRE);
    }
    /** @overload @since LibreOffice 5.4 */
    template<typename T> [[nodiscard]]
    typename libreoffice_internal::ConstCharArrayDetector<T, OUString >::Type
    replaceFirst(
        T & from, OUStringLiteral const & to, sal_Int32 * index = nullptr) const
    {
        assert(libreoffice_internal::ConstCharArrayDetector<T>::isValid(from));
        rtl_uString * s = nullptr;
        sal_Int32 i = 0;
        rtl_uString_newReplaceFirstAsciiLAsciiL(
            &s, pData,
            libreoffice_internal::ConstCharArrayDetector<T>::toPointer(from),
            libreoffice_internal::ConstCharArrayDetector<T>::length, to.data,
            to.size, index == nullptr ? &i : index);
        return OUString(s, SAL_NO_ACQUIRE);
    }
    /** @overload @since LibreOffice 5.4 */
    template<typename T> [[nodiscard]]
    typename
        libreoffice_internal::ConstCharArrayDetector<T, OUString >::TypeUtf16
    replaceFirst(
        OUStringLiteral const & from, T & to, sal_Int32 * index = nullptr) const
    {
        assert(libreoffice_internal::ConstCharArrayDetector<T>::isValid(to));
        rtl_uString * s = nullptr;
        sal_Int32 i = 0;
        rtl_uString_newReplaceFirstAsciiLUtf16L(
            &s, pData, from.data, from.size,
            libreoffice_internal::ConstCharArrayDetector<T>::toPointer(to),
            libreoffice_internal::ConstCharArrayDetector<T>::length,
            index == nullptr ? &i : index);
        return OUString(s, SAL_NO_ACQUIRE);
    }
    /** @overload @since LibreOffice 5.4 */
    template<typename T> [[nodiscard]]
    typename
        libreoffice_internal::ConstCharArrayDetector<T, OUString >::TypeUtf16
    replaceFirst(
        T & from, OUStringLiteral const & to, sal_Int32 * index = nullptr) const
    {
        assert(libreoffice_internal::ConstCharArrayDetector<T>::isValid(from));
        rtl_uString * s = nullptr;
        sal_Int32 i = 0;
        rtl_uString_newReplaceFirstUtf16LAsciiL(
            &s, pData,
            libreoffice_internal::ConstCharArrayDetector<T>::toPointer(from),
            libreoffice_internal::ConstCharArrayDetector<T>::length, to.data,
            to.size, index == nullptr ? &i : index);
        return OUString(s, SAL_NO_ACQUIRE);
    }
#endif

    /**
      Returns a new string resulting from replacing all occurrences of a given
      substring with another substring.

      Replacing subsequent occurrences picks up only after a given replacement.
      That is, replacing from "xa" to "xx" in "xaa" results in "xxa", not "xxx".

      @param from  the substring to be replaced

      @param to  the replacing substring

      @param fromIndex  the position in the string where we will begin searching

      @since LibreOffice 4.0
    */
    SAL_WARN_UNUSED_RESULT OUString replaceAll(
        OUString const & from, OUString const & to, sal_Int32 fromIndex = 0) const
    {
        rtl_uString * s = NULL;
        rtl_uString_newReplaceAllFromIndex(&s, pData, from.pData, to.pData, fromIndex);
        return OUString(s, SAL_NO_ACQUIRE);
    }

    /**
      Returns a new string resulting from replacing all occurrences of a given
      substring with another substring.

      Replacing subsequent occurrences picks up only after a given replacement.
      That is, replacing from "xa" to "xx" in "xaa" results in "xxa", not "xxx".

      @param from ASCII string literal, the substring to be replaced

      @param to  the replacing substring

      @since LibreOffice 3.6
    */
    template< typename T >
    SAL_WARN_UNUSED_RESULT typename libreoffice_internal::ConstCharArrayDetector< T, OUString >::Type replaceAll( T& from, OUString const & to) const
    {
        assert(libreoffice_internal::ConstCharArrayDetector<T>::isValid(from));
        rtl_uString * s = NULL;
        rtl_uString_newReplaceAllAsciiL(
            &s, pData,
            libreoffice_internal::ConstCharArrayDetector<T>::toPointer(from),
            libreoffice_internal::ConstCharArrayDetector<T>::length, to.pData);
        return OUString(s, SAL_NO_ACQUIRE);
    }

    /**
      Returns a new string resulting from replacing all occurrences of a given
      substring with another substring.

      Replacing subsequent occurrences picks up only after a given replacement.
      That is, replacing from "xa" to "xx" in "xaa" results in "xxa", not "xxx".

      @param from  the substring to be replaced

      @param to  ASCII string literal, the replacing substring

      @since LibreOffice 5.1
    */
    template< typename T >
    SAL_WARN_UNUSED_RESULT typename libreoffice_internal::ConstCharArrayDetector< T, OUString >::Type replaceAll( OUString const & from, T& to) const
    {
        assert(libreoffice_internal::ConstCharArrayDetector<T>::isValid(to));
        rtl_uString * s = NULL;
        rtl_uString_newReplaceAllToAsciiL(
            &s, pData, from.pData,
            libreoffice_internal::ConstCharArrayDetector<T>::toPointer(to),
            libreoffice_internal::ConstCharArrayDetector<T>::length);
        return OUString(s, SAL_NO_ACQUIRE);
    }

    /**
      Returns a new string resulting from replacing all occurrences of a given
      substring with another substring.

      Replacing subsequent occurrences picks up only after a given replacement.
      That is, replacing from "xa" to "xx" in "xaa" results in "xxa", not "xxx".

      @param from  ASCII string literal, the substring to be replaced

      @param to  ASCII string literal, the substring to be replaced

      @since LibreOffice 3.6
    */
    template< typename T1, typename T2 >
    SAL_WARN_UNUSED_RESULT typename libreoffice_internal::ConstCharArrayDetector< T1, typename libreoffice_internal::ConstCharArrayDetector< T2, OUString >::Type >::Type
        replaceAll( T1& from, T2& to ) const
    {
        assert(libreoffice_internal::ConstCharArrayDetector<T1>::isValid(from));
        assert(libreoffice_internal::ConstCharArrayDetector<T2>::isValid(to));
        rtl_uString * s = NULL;
        rtl_uString_newReplaceAllAsciiLAsciiL(
            &s, pData,
            libreoffice_internal::ConstCharArrayDetector<T1>::toPointer(from),
            libreoffice_internal::ConstCharArrayDetector<T1>::length,
            libreoffice_internal::ConstCharArrayDetector<T2>::toPointer(to),
            libreoffice_internal::ConstCharArrayDetector<T2>::length);
        return OUString(s, SAL_NO_ACQUIRE);
    }

#if defined LIBO_INTERNAL_ONLY
    /** @overload @since LibreOffice 5.3 */
    template<typename T> [[nodiscard]]
    typename
        libreoffice_internal::ConstCharArrayDetector<T, OUString>::TypeUtf16
    replaceAll(T & from, OUString const & to) const {
        rtl_uString * s = nullptr;
        rtl_uString_newReplaceAllUtf16LUtf16L(
            &s, pData,
            libreoffice_internal::ConstCharArrayDetector<T>::toPointer(from),
            libreoffice_internal::ConstCharArrayDetector<T>::length,
            to.pData->buffer, to.pData->length);
        if (s == nullptr) {
            throw std::bad_alloc();
                // should be std::length_error if resulting would be too large
        }
        return OUString(s, SAL_NO_ACQUIRE);
    }
    /** @overload @since LibreOffice 5.3 */
    template<typename T> [[nodiscard]]
    typename
        libreoffice_internal::ConstCharArrayDetector<T, OUString>::TypeUtf16
    replaceAll(OUString const & from, T & to) const {
        rtl_uString * s = nullptr;
        rtl_uString_newReplaceAllUtf16LUtf16L(
            &s, pData, from.pData->buffer, from.pData->length,
            libreoffice_internal::ConstCharArrayDetector<T>::toPointer(to),
            libreoffice_internal::ConstCharArrayDetector<T>::length);
        if (s == nullptr) {
            throw std::bad_alloc();
                // should be std::length_error if resulting would be too large
        }
        return OUString(s, SAL_NO_ACQUIRE);
    }
    /** @overload @since LibreOffice 5.3 */
    template<typename T1, typename T2> [[nodiscard]]
    typename
        libreoffice_internal::ConstCharArrayDetector<
            T1,
            typename libreoffice_internal::ConstCharArrayDetector<
                T2, OUString>::TypeUtf16
        >::TypeUtf16
    replaceAll(T1 & from, T2 & to) const {
        rtl_uString * s = nullptr;
        rtl_uString_newReplaceAllUtf16LUtf16L(
            &s, pData,
            libreoffice_internal::ConstCharArrayDetector<T1>::toPointer(from),
            libreoffice_internal::ConstCharArrayDetector<T1>::length,
            libreoffice_internal::ConstCharArrayDetector<T2>::toPointer(to),
            libreoffice_internal::ConstCharArrayDetector<T2>::length);
        if (s == nullptr) {
            throw std::bad_alloc();
                // should be std::length_error if resulting would be too large
        }
        return OUString(s, SAL_NO_ACQUIRE);
    }
    /** @overload @since LibreOffice 5.3 */
    template<typename T1, typename T2> [[nodiscard]]
    typename
        libreoffice_internal::ConstCharArrayDetector<
            T1,
            typename libreoffice_internal::ConstCharArrayDetector<
                T2, OUString>::Type
        >::TypeUtf16
    replaceAll(T1 & from, T2 & to) const {
        rtl_uString * s = nullptr;
        rtl_uString_newReplaceAllUtf16LAsciiL(
            &s, pData,
            libreoffice_internal::ConstCharArrayDetector<T1>::toPointer(from),
            libreoffice_internal::ConstCharArrayDetector<T1>::length,
            libreoffice_internal::ConstCharArrayDetector<T2>::toPointer(to),
            libreoffice_internal::ConstCharArrayDetector<T2>::length);
        if (s == nullptr) {
            throw std::bad_alloc();
                // should be std::length_error if resulting would be too large
        }
        return OUString(s, SAL_NO_ACQUIRE);
    }
    /** @overload @since LibreOffice 5.3 */
    template<typename T1, typename T2> [[nodiscard]]
    typename
        libreoffice_internal::ConstCharArrayDetector<
            T1,
            typename libreoffice_internal::ConstCharArrayDetector<
                T2, OUString>::TypeUtf16
        >::Type
    replaceAll(T1 & from, T2 & to) const {
        rtl_uString * s = nullptr;
        rtl_uString_newReplaceAllAsciiLUtf16L(
            &s, pData,
            libreoffice_internal::ConstCharArrayDetector<T1>::toPointer(from),
            libreoffice_internal::ConstCharArrayDetector<T1>::length,
            libreoffice_internal::ConstCharArrayDetector<T2>::toPointer(to),
            libreoffice_internal::ConstCharArrayDetector<T2>::length);
        if (s == nullptr) {
            throw std::bad_alloc();
                // should be std::length_error if resulting would be too large
        }
        return OUString(s, SAL_NO_ACQUIRE);
    }

    /** @overload @since LibreOffice 5.4 */
    [[nodiscard]] OUString replaceAll(
        OUStringLiteral const & from, OUString const & to) const
    {
        rtl_uString * s = nullptr;
        rtl_uString_newReplaceAllAsciiL(
            &s, pData, from.data, from.size, to.pData);
        return OUString(s, SAL_NO_ACQUIRE);
    }
    /** @overload @since LibreOffice 5.4 */
    [[nodiscard]] OUString replaceAll(
        OUString const & from, OUStringLiteral const & to) const
    {
        rtl_uString * s = nullptr;
        rtl_uString_newReplaceAllToAsciiL(
            &s, pData, from.pData, to.data, to.size);
        return OUString(s, SAL_NO_ACQUIRE);
    }
    /** @overload @since LibreOffice 5.4 */
    [[nodiscard]] OUString replaceAll(
        OUStringLiteral const & from, OUStringLiteral const & to) const
    {
        rtl_uString * s = nullptr;
        rtl_uString_newReplaceAllAsciiLAsciiL(
            &s, pData, from.data, from.size, to.data, to.size);
        return OUString(s, SAL_NO_ACQUIRE);
    }
    /** @overload @since LibreOffice 5.4 */
    template<typename T> [[nodiscard]]
    typename libreoffice_internal::ConstCharArrayDetector<T, OUString >::Type
    replaceAll(OUStringLiteral const & from, T & to) const {
        assert(libreoffice_internal::ConstCharArrayDetector<T>::isValid(to));
        rtl_uString * s = nullptr;
        rtl_uString_newReplaceAllAsciiLAsciiL(
            &s, pData, from.data, from.size,
            libreoffice_internal::ConstCharArrayDetector<T>::toPointer(to),
            libreoffice_internal::ConstCharArrayDetector<T>::length);
        return OUString(s, SAL_NO_ACQUIRE);
    }
    /** @overload @since LibreOffice 5.4 */
    template<typename T> [[nodiscard]]
    typename libreoffice_internal::ConstCharArrayDetector<T, OUString >::Type
    replaceAll(T & from, OUStringLiteral const & to) const {
        assert(libreoffice_internal::ConstCharArrayDetector<T>::isValid(from));
        rtl_uString * s = nullptr;
        rtl_uString_newReplaceAllAsciiLAsciiL(
            &s, pData,
            libreoffice_internal::ConstCharArrayDetector<T>::toPointer(from),
            libreoffice_internal::ConstCharArrayDetector<T>::length, to.data,
            to.size);
        return OUString(s, SAL_NO_ACQUIRE);
    }
    /** @overload @since LibreOffice 5.4 */
    template<typename T> [[nodiscard]]
    typename
        libreoffice_internal::ConstCharArrayDetector<T, OUString >::TypeUtf16
    replaceAll(OUStringLiteral const & from, T & to) const {
        assert(libreoffice_internal::ConstCharArrayDetector<T>::isValid(to));
        rtl_uString * s = nullptr;
        rtl_uString_newReplaceAllAsciiLUtf16L(
            &s, pData, from.data, from.size,
            libreoffice_internal::ConstCharArrayDetector<T>::toPointer(to),
            libreoffice_internal::ConstCharArrayDetector<T>::length);
        return OUString(s, SAL_NO_ACQUIRE);
    }
    /** @overload @since LibreOffice 5.4 */
    template<typename T> [[nodiscard]]
    typename
        libreoffice_internal::ConstCharArrayDetector<T, OUString >::TypeUtf16
    replaceAll(T & from, OUStringLiteral const & to) const {
        assert(libreoffice_internal::ConstCharArrayDetector<T>::isValid(from));
        rtl_uString * s = nullptr;
        rtl_uString_newReplaceAllUtf16LAsciiL(
            &s, pData,
            libreoffice_internal::ConstCharArrayDetector<T>::toPointer(from),
            libreoffice_internal::ConstCharArrayDetector<T>::length, to.data,
            to.size);
        return OUString(s, SAL_NO_ACQUIRE);
    }
#endif

    /**
      Converts from this string all ASCII uppercase characters (65-90)
      to ASCII lowercase characters (97-122).

      This function can't be used for language specific conversion.
      If the string doesn't contain characters which must be converted,
      then the new string is assigned with str.

      @return   the string, converted to ASCII lowercase.
    */
    SAL_WARN_UNUSED_RESULT OUString toAsciiLowerCase() const
    {
        rtl_uString* pNew = NULL;
        rtl_uString_newToAsciiLowerCase( &pNew, pData );
        return OUString( pNew, SAL_NO_ACQUIRE );
    }

    /**
      Converts from this string all ASCII lowercase characters (97-122)
      to ASCII uppercase characters (65-90).

      This function can't be used for language specific conversion.
      If the string doesn't contain characters which must be converted,
      then the new string is assigned with str.

      @return   the string, converted to ASCII uppercase.
    */
    SAL_WARN_UNUSED_RESULT OUString toAsciiUpperCase() const
    {
        rtl_uString* pNew = NULL;
        rtl_uString_newToAsciiUpperCase( &pNew, pData );
        return OUString( pNew, SAL_NO_ACQUIRE );
    }

    /**
      Returns a new string resulting from removing white space from both ends
      of the string.

      All characters that have codes less than or equal to
      32 (the space character), and Unicode General Punctuation area Space
      and some Control characters are considered to be white space (see
      rtl_ImplIsWhitespace).
      If the string doesn't contain white spaces at both ends,
      then the new string is assigned with str.

      @return   the string, with white space removed from the front and end.
    */
    SAL_WARN_UNUSED_RESULT OUString trim() const
    {
        rtl_uString* pNew = NULL;
        rtl_uString_newTrim( &pNew, pData );
        return OUString( pNew, SAL_NO_ACQUIRE );
    }

    /**
      Returns a token in the string.

      Example:
        sal_Int32 nIndex = 0;
        do
        {
            ...
            OUString aToken = aStr.getToken( 0, ';', nIndex );
            ...
        }
        while ( nIndex >= 0 );

      @param    token       the number of the token to return
      @param    cTok        the character which separate the tokens.
      @param    index       the position at which the token is searched in the
                            string.
                            The index must not be greater than the length of the
                            string.
                            This param is set to the position of the
                            next token or to -1, if it is the last token.
      @return   the token; if either token or index is negative, an empty token
                is returned (and index is set to -1)
    */
    OUString getToken( sal_Int32 token, sal_Unicode cTok, sal_Int32& index ) const
    {
        rtl_uString * pNew = NULL;
        index = rtl_uString_getToken( &pNew, pData, token, cTok, index );
        return OUString( pNew, SAL_NO_ACQUIRE );
    }

    /**
      Returns a token from the string.

      The same as getToken(sal_Int32, sal_Unicode, sal_Int32 &), but always
      passing in 0 as the start index in the third argument.

      @param count  the number of the token to return, starting with 0
      @param separator  the character which separates the tokens

      @return  the given token, or an empty string

      @since LibreOffice 3.6
     */
    OUString getToken(sal_Int32 count, sal_Unicode separator) const {
        sal_Int32 n = 0;
        return getToken(count, separator, n);
    }

    /**
      Returns the Boolean value from this string.

      This function can't be used for language specific conversion.

      @return   true, if the string is 1 or "True" in any ASCII case.
                false in any other case.
    */
    bool toBoolean() const
    {
        return rtl_ustr_toBoolean( pData->buffer );
    }

    /**
      Returns the first character from this string.

      @return   the first character from this string or 0, if this string
                is empty.
    */
    sal_Unicode toChar() const
    {
        return pData->buffer[0];
    }

    /**
      Returns the int32 value from this string.

      This function can't be used for language specific conversion.

      @param    radix       the radix (between 2 and 36)
      @return   the int32 represented from this string.
                0 if this string represents no number or one of too large
                magnitude.
    */
    sal_Int32 toInt32( sal_Int16 radix = 10 ) const
    {
        return rtl_ustr_toInt32( pData->buffer, radix );
    }

    /**
      Returns the uint32 value from this string.

      This function can't be used for language specific conversion.

      @param    radix       the radix (between 2 and 36)
      @return   the uint32 represented from this string.
                0 if this string represents no number or one of too large
                magnitude.

      @since LibreOffice 4.2
    */
    sal_uInt32 toUInt32( sal_Int16 radix = 10 ) const
    {
        return rtl_ustr_toUInt32( pData->buffer, radix );
    }

    /**
      Returns the int64 value from this string.

      This function can't be used for language specific conversion.

      @param    radix       the radix (between 2 and 36)
      @return   the int64 represented from this string.
                0 if this string represents no number or one of too large
                magnitude.
    */
    sal_Int64 toInt64( sal_Int16 radix = 10 ) const
    {
        return rtl_ustr_toInt64( pData->buffer, radix );
    }

    /**
      Returns the uint64 value from this string.

      This function can't be used for language specific conversion.

      @param    radix       the radix (between 2 and 36)
      @return   the uint64 represented from this string.
                0 if this string represents no number or one of too large
                magnitude.

      @since LibreOffice 4.1
    */
    sal_uInt64 toUInt64( sal_Int16 radix = 10 ) const
    {
        return rtl_ustr_toUInt64( pData->buffer, radix );
    }

    /**
      Returns the float value from this string.

      This function can't be used for language specific conversion.

      @return   the float represented from this string.
                0.0 if this string represents no number.
    */
    float toFloat() const
    {
        return rtl_ustr_toFloat( pData->buffer );
    }

    /**
      Returns the double value from this string.

      This function can't be used for language specific conversion.

      @return   the double represented from this string.
                0.0 if this string represents no number.
    */
    double toDouble() const
    {
        return rtl_ustr_toDouble( pData->buffer );
    }


    /**
       Return a canonical representation for a string.

       A pool of strings, initially empty is maintained privately
       by the string class. On invocation, if present in the pool
       the original string will be returned. Otherwise this string,
       or a copy thereof will be added to the pool and returned.

       @return
       a version of the string from the pool.

       @exception std::bad_alloc is thrown if an out-of-memory condition occurs

       @since UDK 3.2.7
    */
    OUString intern() const
    {
        rtl_uString * pNew = NULL;
        rtl_uString_intern( &pNew, pData );
        if (pNew == NULL) {
            throw std::bad_alloc();
        }
        return OUString( pNew, SAL_NO_ACQUIRE );
    }

    /**
       Return a canonical representation for a converted string.

       A pool of strings, initially empty is maintained privately
       by the string class. On invocation, if present in the pool
       the original string will be returned. Otherwise this string,
       or a copy thereof will be added to the pool and returned.

       @param    value           a 8-Bit character array.
       @param    length          the number of character which should be converted.
                                 The 8-Bit character array length must be
                                 greater than or equal to this value.
       @param    encoding        the text encoding from which the 8-Bit character
                                 sequence should be converted.
       @param    convertFlags    flags which controls the conversion.
                                 see RTL_TEXTTOUNICODE_FLAGS_...
       @param    pInfo           pointer to return conversion status or NULL.

       @return
       a version of the converted string from the pool.

       @exception std::bad_alloc is thrown if an out-of-memory condition occurs

       @since UDK 3.2.7
    */
    static OUString intern( const sal_Char * value, sal_Int32 length,
                            rtl_TextEncoding encoding,
                            sal_uInt32 convertFlags = OSTRING_TO_OUSTRING_CVTFLAGS,
                            sal_uInt32 *pInfo = NULL )
    {
        rtl_uString * pNew = NULL;
        rtl_uString_internConvert( &pNew, value, length, encoding,
                                   convertFlags, pInfo );
        if (pNew == NULL) {
            throw std::bad_alloc();
        }
        return OUString( pNew, SAL_NO_ACQUIRE );
    }

    /**
      Converts to an OString, signalling failure.

      @param pTarget
      An out parameter receiving the converted OString.  Must not be null; the
      contents are not modified if conversion fails (convertToOString returns
      false).

      @param nEncoding
      The text encoding to convert into.  Must be an octet encoding (i.e.,
      rtl_isOctetTextEncoding(nEncoding) must return true).

      @param nFlags
      A combination of RTL_UNICODETOTEXT_FLAGS that detail how to do the
      conversion (see rtl_convertUnicodeToText).  RTL_UNICODETOTEXT_FLAGS_FLUSH
      need not be included, it is implicitly assumed.  Typical uses are either
      RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR |
      RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR (fail if a Unicode character cannot
      be converted to the target nEncoding) or OUSTRING_TO_OSTRING_CVTFLAGS
      (make a best efforts conversion).

      @return
      True if the conversion succeeded, false otherwise.
     */
    bool convertToString(OString * pTarget, rtl_TextEncoding nEncoding,
                                sal_uInt32 nFlags) const
    {
        return rtl_convertUStringToString(&pTarget->pData, pData->buffer,
                                            pData->length, nEncoding, nFlags);
    }

    /** Iterate through this string based on code points instead of UTF-16 code
        units.

        See Chapter 3 of The Unicode Standard 5.0 (Addison--Wesley, 2006) for
        definitions of the various terms used in this description.

        This string is interpreted as a sequence of zero or more UTF-16 code
        units.  For each index into this sequence (from zero to one less than
        the length of the sequence, inclusive), a code point represented
        starting at the given index is computed as follows:

        - If the UTF-16 code unit addressed by the index constitutes a
        well-formed UTF-16 code unit sequence, the computed code point is the
        scalar value encoded by that UTF-16 code unit sequence.

        - Otherwise, if the index is at least two UTF-16 code units away from
        the end of the sequence, and the sequence of two UTF-16 code units
        addressed by the index constitutes a well-formed UTF-16 code unit
        sequence, the computed code point is the scalar value encoded by that
        UTF-16 code unit sequence.

        - Otherwise, the computed code point is the UTF-16 code unit addressed
        by the index.  (This last case catches unmatched surrogates as well as
        indices pointing into the middle of surrogate pairs.)

        @param indexUtf16
        pointer to a UTF-16 based index into this string; must not be null.  On
        entry, the index must be in the range from zero to the length of this
        string (in UTF-16 code units), inclusive.  Upon successful return, the
        index will be updated to address the UTF-16 code unit that is the given
        incrementCodePoints away from the initial index.

        @param incrementCodePoints
        the number of code points to move the given *indexUtf16.  If
        non-negative, moving is done after determining the code point at the
        index.  If negative, moving is done before determining the code point
        at the (then updated) index.  The value must be such that the resulting
        UTF-16 based index is in the range from zero to the length of this
        string (in UTF-16 code units), inclusive.

        @return
        the code point (an integer in the range from 0 to 0x10FFFF, inclusive)
        that is represented within this string starting at the index computed as
        follows:  If incrementCodePoints is non-negative, the index is the
        initial value of *indexUtf16; if incrementCodePoints is negative, the
        index is the updated value of *indexUtf16.  In either case, the computed
        index must be in the range from zero to one less than the length of this
        string (in UTF-16 code units), inclusive.

        @since UDK 3.2.7
    */
    sal_uInt32 iterateCodePoints(
        sal_Int32 * indexUtf16, sal_Int32 incrementCodePoints = 1) const
    {
        return rtl_uString_iterateCodePoints(
            pData, indexUtf16, incrementCodePoints);
    }

    /**
     * Convert an OString to an OUString, assuming that the OString is
     * UTF-8-encoded.
     *
     * @param rSource
     * an OString to convert
     *
     * @since LibreOffice 4.4
     */
    static OUString fromUtf8(const OString& rSource)
    {
        OUString aTarget;
        bool bSuccess = rtl_convertStringToUString(&aTarget.pData,
                                                   rSource.getStr(),
                                                   rSource.getLength(),
                                                   RTL_TEXTENCODING_UTF8,
                                                   RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR|RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR|RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR);
        (void) bSuccess;
        assert(bSuccess);
        return aTarget;
    }

    /**
     * Convert this string to an OString, assuming that the string can be
     * UTF-8-encoded successfully.
     *
     * In other words, you must not use this method on a random sequence of
     * UTF-16 code units, but only at places where it is assumed that the
     * content is a proper string.
     *
     * @since LibreOffice 4.4
     */
    OString toUtf8() const
    {
        OString aTarget;
        bool bSuccess = rtl_convertUStringToString(&aTarget.pData,
                                                   getStr(),
                                                   getLength(),
                                                   RTL_TEXTENCODING_UTF8,
                                                   RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR|RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR);
        (void) bSuccess;
        assert(bSuccess);
        return aTarget;
    }

#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"

    static OUStringNumber< int > number( int i, sal_Int16 radix = 10 )
    {
        return OUStringNumber< int >( i, radix );
    }
    static OUStringNumber< long long > number( long long ll, sal_Int16 radix = 10 )
    {
        return OUStringNumber< long long >( ll, radix );
    }
    static OUStringNumber< unsigned long long > number( unsigned long long ll, sal_Int16 radix = 10 )
    {
        return OUStringNumber< unsigned long long >( ll, radix );
    }
    static OUStringNumber< unsigned long long > number( unsigned int i, sal_Int16 radix = 10 )
    {
        return number( static_cast< unsigned long long >( i ), radix );
    }
    static OUStringNumber< long long > number( long i, sal_Int16 radix = 10)
    {
        return number( static_cast< long long >( i ), radix );
    }
    static OUStringNumber< unsigned long long > number( unsigned long i, sal_Int16 radix = 10 )
    {
        return number( static_cast< unsigned long long >( i ), radix );
    }
    static OUStringNumber< float > number( float f )
    {
        return OUStringNumber< float >( f );
    }
    static OUStringNumber< double > number( double d )
    {
        return OUStringNumber< double >( d );
    }
#else
    /**
      Returns the string representation of the integer argument.

      This function can't be used for language specific conversion.

      @param    i           an integer value
      @param    radix       the radix (between 2 and 36)
      @return   a string with the string representation of the argument.
      @since LibreOffice 4.1
    */
    static OUString number( int i, sal_Int16 radix = 10 )
    {
        sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFINT32];
        return OUString(aBuf, rtl_ustr_valueOfInt32(aBuf, i, radix));
    }
    /// @overload
    /// @since LibreOffice 4.1
    static OUString number( unsigned int i, sal_Int16 radix = 10 )
    {
        return number( static_cast< unsigned long long >( i ), radix );
    }
    /// @overload
    /// @since LibreOffice 4.1
    static OUString number( long i, sal_Int16 radix = 10)
    {
        return number( static_cast< long long >( i ), radix );
    }
    /// @overload
    /// @since LibreOffice 4.1
    static OUString number( unsigned long i, sal_Int16 radix = 10 )
    {
        return number( static_cast< unsigned long long >( i ), radix );
    }
    /// @overload
    /// @since LibreOffice 4.1
    static OUString number( long long ll, sal_Int16 radix = 10 )
    {
        sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFINT64];
        return OUString(aBuf, rtl_ustr_valueOfInt64(aBuf, ll, radix));
    }
    /// @overload
    /// @since LibreOffice 4.1
    static OUString number( unsigned long long ll, sal_Int16 radix = 10 )
    {
        sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFUINT64];
        return OUString(aBuf, rtl_ustr_valueOfUInt64(aBuf, ll, radix));
    }

    /**
      Returns the string representation of the float argument.

      This function can't be used for language specific conversion.

      @param    f           a float.
      @return   a string with the decimal representation of the argument.
      @since LibreOffice 4.1
    */
    static OUString number( float f )
    {
        sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFFLOAT];
        return OUString(aBuf, rtl_ustr_valueOfFloat(aBuf, f));
    }

    /**
      Returns the string representation of the double argument.

      This function can't be used for language specific conversion.

      @param    d           a double.
      @return   a string with the decimal representation of the argument.
      @since LibreOffice 4.1
    */
    static OUString number( double d )
    {
        sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFDOUBLE];
        return OUString(aBuf, rtl_ustr_valueOfDouble(aBuf, d));
    }
#endif

    /**
      Returns the string representation of the sal_Bool argument.

      If the sal_Bool is true, the string "true" is returned.
      If the sal_Bool is false, the string "false" is returned.
      This function can't be used for language specific conversion.

      @param    b   a sal_Bool.
      @return   a string with the string representation of the argument.
      @deprecated use boolean()
    */
    SAL_DEPRECATED("use boolean()") static OUString valueOf( sal_Bool b )
    {
        return boolean(b);
    }

    /**
      Returns the string representation of the boolean argument.

      If the argument is true, the string "true" is returned.
      If the argument is false, the string "false" is returned.
      This function can't be used for language specific conversion.

      @param    b   a bool.
      @return   a string with the string representation of the argument.
      @since LibreOffice 4.1
    */
    static OUString boolean( bool b )
    {
        sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFBOOLEAN];
        return OUString(aBuf, rtl_ustr_valueOfBoolean(aBuf, b));
    }

    /**
      Returns the string representation of the char argument.

      @param    c   a character.
      @return   a string with the string representation of the argument.
      @deprecated use operator, function or constructor taking char or sal_Unicode argument
    */
    SAL_DEPRECATED("convert to OUString or use directly") static OUString valueOf( sal_Unicode c )
    {
        return OUString( &c, 1 );
    }

    /**
      Returns the string representation of the int argument.

      This function can't be used for language specific conversion.

      @param    i           a int32.
      @param    radix       the radix (between 2 and 36)
      @return   a string with the string representation of the argument.
      @deprecated use number()
    */
    SAL_DEPRECATED("use number()") static OUString valueOf( sal_Int32 i, sal_Int16 radix = 10 )
    {
        return number( i, radix );
    }

    /**
      Returns the string representation of the long argument.

      This function can't be used for language specific conversion.

      @param    ll          a int64.
      @param    radix       the radix (between 2 and 36)
      @return   a string with the string representation of the argument.
      @deprecated use number()
    */
    SAL_DEPRECATED("use number()") static OUString valueOf( sal_Int64 ll, sal_Int16 radix = 10 )
    {
        return number( ll, radix );
    }

    /**
      Returns the string representation of the float argument.

      This function can't be used for language specific conversion.

      @param    f           a float.
      @return   a string with the string representation of the argument.
      @deprecated use number()
    */
    SAL_DEPRECATED("use number()") static OUString valueOf( float f )
    {
        return number(f);
    }

    /**
      Returns the string representation of the double argument.

      This function can't be used for language specific conversion.

      @param    d           a double.
      @return   a string with the string representation of the argument.
      @deprecated use number()
    */
    SAL_DEPRECATED("use number()") static OUString valueOf( double d )
    {
        return number(d);
    }

    /**
      Returns an OUString copied without conversion from an ASCII
      character string.

      Since this method is optimized for performance, the ASCII character
      values are not converted in any way. The caller has to make sure that
      all ASCII characters are in the allowed range between 0 and 127.
      The ASCII string must be NULL-terminated.

      Note that for string literals it is simpler and more efficient
      to directly use the OUString constructor.

      @param    value       the 8-Bit ASCII character string
      @return   a string with the string representation of the argument.
     */
    static OUString createFromAscii( const sal_Char * value )
    {
        rtl_uString* pNew = NULL;
        rtl_uString_newFromAscii( &pNew, value );
        return OUString( pNew, SAL_NO_ACQUIRE );
    }

#if defined LIBO_INTERNAL_ONLY
    operator std::u16string_view() const { return {getStr(), sal_uInt32(getLength())}; }
#endif

private:
    OUString & internalAppend( rtl_uString* pOtherData )
    {
        rtl_uString* pNewData = NULL;
        rtl_uString_newConcat( &pNewData, pData, pOtherData );
        if (pNewData == NULL) {
            throw std::bad_alloc();
        }
        rtl_uString_assign(&pData, pNewData);
        rtl_uString_release(pNewData);
        return *this;
    }

};

#if defined LIBO_INTERNAL_ONLY
// Prevent the operator ==/!= overloads with 'sal_Unicode const *' parameter from
// being selected for nonsensical code like
//
//   if (ouIdAttr == nullptr)
//
void operator ==(OUString const &, std::nullptr_t) = delete;
void operator ==(std::nullptr_t, OUString const &) = delete;
void operator !=(OUString const &, std::nullptr_t) = delete;
void operator !=(std::nullptr_t, OUString const &) = delete;
#endif

#if defined LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
/// @cond INTERNAL

/**
 @internal
*/
template<>
struct ToStringHelper< OUString >
    {
    static std::size_t length( const OUString& s ) { return s.getLength(); }
    static sal_Unicode* addData( sal_Unicode* buffer, const OUString& s ) { return addDataHelper( buffer, s.getStr(), s.getLength()); }
    static const bool allowOStringConcat = false;
    static const bool allowOUStringConcat = true;
    };

/**
 @internal
*/
template<>
struct ToStringHelper< OUStringLiteral >
    {
    static std::size_t length( const OUStringLiteral& str ) { return str.size; }
    static sal_Unicode* addData( sal_Unicode* buffer, const OUStringLiteral& str ) { return addDataLiteral( buffer, str.data, str.size ); }
    static const bool allowOStringConcat = false;
    static const bool allowOUStringConcat = true;
    };

/**
 @internal
*/
template< typename charT, typename traits, typename T1, typename T2 >
inline std::basic_ostream<charT, traits> & operator <<(
    std::basic_ostream<charT, traits> & stream, OUStringConcat< T1, T2 >&& concat)
{
    return stream << OUString( std::move(concat) );
}

/// @endcond
#endif

/** A helper to use OUStrings with hash maps.

    Instances of this class are unary function objects that can be used as
    hash function arguments to std::unordered_map and similar constructs.
 */
struct OUStringHash
{
    /** Compute a hash code for a string.

        @param rString
        a string.

        @return
        a hash code for the string.  This hash code should not be stored
        persistently, as its computation may change in later revisions.
     */
    size_t operator()(const OUString& rString) const
        { return static_cast<size_t>(rString.hashCode()); }
};

/* ======================================================================= */

/** Convert an OString to an OUString, using a specific text encoding.

    The lengths of the two strings may differ (e.g., for double-byte
    encodings, UTF-7, UTF-8).

    @param rStr
    an OString to convert.

    @param encoding
    the text encoding to use for conversion.

    @param convertFlags
    flags which control the conversion.  Either use
    OSTRING_TO_OUSTRING_CVTFLAGS, or see
    <http://udk.openoffice.org/cpp/man/spec/textconversion.html> for more
    details.
 */
inline OUString OStringToOUString( const OString & rStr,
                                   rtl_TextEncoding encoding,
                                   sal_uInt32 convertFlags = OSTRING_TO_OUSTRING_CVTFLAGS )
{
    return OUString( rStr.getStr(), rStr.getLength(), encoding, convertFlags );
}

/** Convert an OUString to an OString, using a specific text encoding.

    The lengths of the two strings may differ (e.g., for double-byte
    encodings, UTF-7, UTF-8).

    @param rUnicode
    an OUString to convert.

    @param encoding
    the text encoding to use for conversion.

    @param convertFlags
    flags which control the conversion.  Either use
    OUSTRING_TO_OSTRING_CVTFLAGS, or see
    <http://udk.openoffice.org/cpp/man/spec/textconversion.html> for more
    details.
 */
inline OString OUStringToOString( const OUString & rUnicode,
                                  rtl_TextEncoding encoding,
                                  sal_uInt32 convertFlags = OUSTRING_TO_OSTRING_CVTFLAGS )
{
    return OString( rUnicode.getStr(), rUnicode.getLength(), encoding, convertFlags );
}

/* ======================================================================= */

/**
    Support for rtl::OUString in std::ostream (and thus in
    CPPUNIT_ASSERT or SAL_INFO macros, for example).

    The rtl::OUString is converted to UTF-8.

    @since LibreOffice 3.5.
*/
template< typename charT, typename traits >
inline std::basic_ostream<charT, traits> & operator <<(
    std::basic_ostream<charT, traits> & stream, OUString const & rString)
{
    return stream <<
        OUStringToOString(rString, RTL_TEXTENCODING_UTF8);
        // best effort; potentially loses data due to conversion failures
        // (stray surrogate halves) and embedded null characters
}

} // namespace

#ifdef RTL_STRING_UNITTEST
namespace rtl
{
typedef rtlunittest::OUString OUString;
}
#endif

// In internal code, allow to use classes like OUString without having to
// explicitly refer to the rtl namespace, which is kind of superfluous given
// that OUString itself is namespaced by its OU prefix:
#if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST
using ::rtl::OUString;
using ::rtl::OUStringHash;
using ::rtl::OStringToOUString;
using ::rtl::OUStringToOString;
using ::rtl::OUStringLiteral;
using ::rtl::OUStringChar;
#endif

/// @cond INTERNAL
/**
  Make OUString hashable by default for use in STL containers.

  @since LibreOffice 6.0
*/
#if defined LIBO_INTERNAL_ONLY
namespace std {

template<>
struct hash<::rtl::OUString>
{
    std::size_t operator()(::rtl::OUString const & s) const
    { return std::size_t(s.hashCode()); }
};

}

#endif
/// @endcond

#endif /* _RTL_USTRING_HXX */

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */