/usr/include/unicode/unistr.h is in libicu-dev 60.2-3ubuntu3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 | // © 2016 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
/*
**********************************************************************
* Copyright (C) 1998-2016, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
*
* File unistr.h
*
* Modification History:
*
* Date Name Description
* 09/25/98 stephen Creation.
* 11/11/98 stephen Changed per 11/9 code review.
* 04/20/99 stephen Overhauled per 4/16 code review.
* 11/18/99 aliu Made to inherit from Replaceable. Added method
* handleReplaceBetween(); other methods unchanged.
* 06/25/01 grhoten Remove dependency on iostream.
******************************************************************************
*/
#ifndef UNISTR_H
#define UNISTR_H
/**
* \file
* \brief C++ API: Unicode String
*/
#include <cstddef>
#include "unicode/utypes.h"
#include "unicode/char16ptr.h"
#include "unicode/rep.h"
#include "unicode/std_string.h"
#include "unicode/stringpiece.h"
#include "unicode/bytestream.h"
struct UConverter; // unicode/ucnv.h
#ifndef USTRING_H
/**
* \ingroup ustring_ustrlen
*/
U_STABLE int32_t U_EXPORT2
u_strlen(const UChar *s);
#endif
U_NAMESPACE_BEGIN
#if !UCONFIG_NO_BREAK_ITERATION
class BreakIterator; // unicode/brkiter.h
#endif
class Edits;
U_NAMESPACE_END
// Not #ifndef U_HIDE_INTERNAL_API because UnicodeString needs the UStringCaseMapper.
/**
* Internal string case mapping function type.
* All error checking must be done.
* src and dest must not overlap.
* @internal
*/
typedef int32_t U_CALLCONV
UStringCaseMapper(int32_t caseLocale, uint32_t options,
#if !UCONFIG_NO_BREAK_ITERATION
icu::BreakIterator *iter,
#endif
char16_t *dest, int32_t destCapacity,
const char16_t *src, int32_t srcLength,
icu::Edits *edits,
UErrorCode &errorCode);
U_NAMESPACE_BEGIN
class Locale; // unicode/locid.h
class StringCharacterIterator;
class UnicodeStringAppendable; // unicode/appendable.h
/* The <iostream> include has been moved to unicode/ustream.h */
/**
* Constant to be used in the UnicodeString(char *, int32_t, EInvariant) constructor
* which constructs a Unicode string from an invariant-character char * string.
* About invariant characters see utypes.h.
* This constructor has no runtime dependency on conversion code and is
* therefore recommended over ones taking a charset name string
* (where the empty string "" indicates invariant-character conversion).
*
* @stable ICU 3.2
*/
#define US_INV icu::UnicodeString::kInvariant
/**
* Unicode String literals in C++.
*
* Note: these macros are not recommended for new code.
* Prior to the availability of C++11 and u"unicode string literals",
* these macros were provided for portability and efficiency when
* initializing UnicodeStrings from literals.
*
* They work only for strings that contain "invariant characters", i.e.,
* only latin letters, digits, and some punctuation.
* See utypes.h for details.
*
* The string parameter must be a C string literal.
* The length of the string, not including the terminating
* <code>NUL</code>, must be specified as a constant.
* @stable ICU 2.0
*/
#if !U_CHAR16_IS_TYPEDEF
# define UNICODE_STRING(cs, _length) icu::UnicodeString(TRUE, u ## cs, _length)
#else
# define UNICODE_STRING(cs, _length) icu::UnicodeString(TRUE, (const char16_t*)u ## cs, _length)
#endif
/**
* Unicode String literals in C++.
* Dependent on the platform properties, different UnicodeString
* constructors should be used to create a UnicodeString object from
* a string literal.
* The macros are defined for improved performance.
* They work only for strings that contain "invariant characters", i.e.,
* only latin letters, digits, and some punctuation.
* See utypes.h for details.
*
* The string parameter must be a C string literal.
* @stable ICU 2.0
*/
#define UNICODE_STRING_SIMPLE(cs) UNICODE_STRING(cs, -1)
/**
* \def UNISTR_FROM_CHAR_EXPLICIT
* This can be defined to be empty or "explicit".
* If explicit, then the UnicodeString(char16_t) and UnicodeString(UChar32)
* constructors are marked as explicit, preventing their inadvertent use.
* @stable ICU 49
*/
#ifndef UNISTR_FROM_CHAR_EXPLICIT
# if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION)
// Auto-"explicit" in ICU library code.
# define UNISTR_FROM_CHAR_EXPLICIT explicit
# else
// Empty by default for source code compatibility.
# define UNISTR_FROM_CHAR_EXPLICIT
# endif
#endif
/**
* \def UNISTR_FROM_STRING_EXPLICIT
* This can be defined to be empty or "explicit".
* If explicit, then the UnicodeString(const char *) and UnicodeString(const char16_t *)
* constructors are marked as explicit, preventing their inadvertent use.
*
* In particular, this helps prevent accidentally depending on ICU conversion code
* by passing a string literal into an API with a const UnicodeString & parameter.
* @stable ICU 49
*/
#ifndef UNISTR_FROM_STRING_EXPLICIT
# if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION)
// Auto-"explicit" in ICU library code.
# define UNISTR_FROM_STRING_EXPLICIT explicit
# else
// Empty by default for source code compatibility.
# define UNISTR_FROM_STRING_EXPLICIT
# endif
#endif
/**
* \def UNISTR_OBJECT_SIZE
* Desired sizeof(UnicodeString) in bytes.
* It should be a multiple of sizeof(pointer) to avoid unusable space for padding.
* The object size may want to be a multiple of 16 bytes,
* which is a common granularity for heap allocation.
*
* Any space inside the object beyond sizeof(vtable pointer) + 2
* is available for storing short strings inside the object.
* The bigger the object, the longer a string that can be stored inside the object,
* without additional heap allocation.
*
* Depending on a platform's pointer size, pointer alignment requirements,
* and struct padding, the compiler will usually round up sizeof(UnicodeString)
* to 4 * sizeof(pointer) (or 3 * sizeof(pointer) for P128 data models),
* to hold the fields for heap-allocated strings.
* Such a minimum size also ensures that the object is easily large enough
* to hold at least 2 char16_ts, for one supplementary code point (U16_MAX_LENGTH).
*
* sizeof(UnicodeString) >= 48 should work for all known platforms.
*
* For example, on a 64-bit machine where sizeof(vtable pointer) is 8,
* sizeof(UnicodeString) = 64 would leave space for
* (64 - sizeof(vtable pointer) - 2) / U_SIZEOF_UCHAR = (64 - 8 - 2) / 2 = 27
* char16_ts stored inside the object.
*
* The minimum object size on a 64-bit machine would be
* 4 * sizeof(pointer) = 4 * 8 = 32 bytes,
* and the internal buffer would hold up to 11 char16_ts in that case.
*
* @see U16_MAX_LENGTH
* @stable ICU 56
*/
#ifndef UNISTR_OBJECT_SIZE
# define UNISTR_OBJECT_SIZE 64
#endif
/**
* UnicodeString is a string class that stores Unicode characters directly and provides
* similar functionality as the Java String and StringBuffer/StringBuilder classes.
* It is a concrete implementation of the abstract class Replaceable (for transliteration).
*
* A UnicodeString may also "alias" an external array of characters
* (that is, point to it, rather than own the array)
* whose lifetime must then at least match the lifetime of the aliasing object.
* This aliasing may be preserved when returning a UnicodeString by value,
* depending on the compiler and the function implementation,
* via Return Value Optimization (RVO) or the move assignment operator.
* (However, the copy assignment operator does not preserve aliasing.)
* For details see the description of storage models at the end of the class API docs
* and in the User Guide chapter linked from there.
*
* The UnicodeString class is not suitable for subclassing.
*
* <p>For an overview of Unicode strings in C and C++ see the
* <a href="http://userguide.icu-project.org/strings#TOC-Strings-in-C-C-">User Guide Strings chapter</a>.</p>
*
* <p>In ICU, a Unicode string consists of 16-bit Unicode <em>code units</em>.
* A Unicode character may be stored with either one code unit
* (the most common case) or with a matched pair of special code units
* ("surrogates"). The data type for code units is char16_t.
* For single-character handling, a Unicode character code <em>point</em> is a value
* in the range 0..0x10ffff. ICU uses the UChar32 type for code points.</p>
*
* <p>Indexes and offsets into and lengths of strings always count code units, not code points.
* This is the same as with multi-byte char* strings in traditional string handling.
* Operations on partial strings typically do not test for code point boundaries.
* If necessary, the user needs to take care of such boundaries by testing for the code unit
* values or by using functions like
* UnicodeString::getChar32Start() and UnicodeString::getChar32Limit()
* (or, in C, the equivalent macros U16_SET_CP_START() and U16_SET_CP_LIMIT(), see utf.h).</p>
*
* UnicodeString methods are more lenient with regard to input parameter values
* than other ICU APIs. In particular:
* - If indexes are out of bounds for a UnicodeString object
* (<0 or >length()) then they are "pinned" to the nearest boundary.
* - If primitive string pointer values (e.g., const char16_t * or char *)
* for input strings are NULL, then those input string parameters are treated
* as if they pointed to an empty string.
* However, this is <em>not</em> the case for char * parameters for charset names
* or other IDs.
* - Most UnicodeString methods do not take a UErrorCode parameter because
* there are usually very few opportunities for failure other than a shortage
* of memory, error codes in low-level C++ string methods would be inconvenient,
* and the error code as the last parameter (ICU convention) would prevent
* the use of default parameter values.
* Instead, such methods set the UnicodeString into a "bogus" state
* (see isBogus()) if an error occurs.
*
* In string comparisons, two UnicodeString objects that are both "bogus"
* compare equal (to be transitive and prevent endless loops in sorting),
* and a "bogus" string compares less than any non-"bogus" one.
*
* Const UnicodeString methods are thread-safe. Multiple threads can use
* const methods on the same UnicodeString object simultaneously,
* but non-const methods must not be called concurrently (in multiple threads)
* with any other (const or non-const) methods.
*
* Similarly, const UnicodeString & parameters are thread-safe.
* One object may be passed in as such a parameter concurrently in multiple threads.
* This includes the const UnicodeString & parameters for
* copy construction, assignment, and cloning.
*
* <p>UnicodeString uses several storage methods.
* String contents can be stored inside the UnicodeString object itself,
* in an allocated and shared buffer, or in an outside buffer that is "aliased".
* Most of this is done transparently, but careful aliasing in particular provides
* significant performance improvements.
* Also, the internal buffer is accessible via special functions.
* For details see the
* <a href="http://userguide.icu-project.org/strings#TOC-Maximizing-Performance-with-the-UnicodeString-Storage-Model">User Guide Strings chapter</a>.</p>
*
* @see utf.h
* @see CharacterIterator
* @stable ICU 2.0
*/
class U_COMMON_API UnicodeString : public Replaceable
{
public:
/**
* Constant to be used in the UnicodeString(char *, int32_t, EInvariant) constructor
* which constructs a Unicode string from an invariant-character char * string.
* Use the macro US_INV instead of the full qualification for this value.
*
* @see US_INV
* @stable ICU 3.2
*/
enum EInvariant {
/**
* @see EInvariant
* @stable ICU 3.2
*/
kInvariant
};
//========================================
// Read-only operations
//========================================
/* Comparison - bitwise only - for international comparison use collation */
/**
* Equality operator. Performs only bitwise comparison.
* @param text The UnicodeString to compare to this one.
* @return TRUE if <TT>text</TT> contains the same characters as this one,
* FALSE otherwise.
* @stable ICU 2.0
*/
inline UBool operator== (const UnicodeString& text) const;
/**
* Inequality operator. Performs only bitwise comparison.
* @param text The UnicodeString to compare to this one.
* @return FALSE if <TT>text</TT> contains the same characters as this one,
* TRUE otherwise.
* @stable ICU 2.0
*/
inline UBool operator!= (const UnicodeString& text) const;
/**
* Greater than operator. Performs only bitwise comparison.
* @param text The UnicodeString to compare to this one.
* @return TRUE if the characters in this are bitwise
* greater than the characters in <code>text</code>, FALSE otherwise
* @stable ICU 2.0
*/
inline UBool operator> (const UnicodeString& text) const;
/**
* Less than operator. Performs only bitwise comparison.
* @param text The UnicodeString to compare to this one.
* @return TRUE if the characters in this are bitwise
* less than the characters in <code>text</code>, FALSE otherwise
* @stable ICU 2.0
*/
inline UBool operator< (const UnicodeString& text) const;
/**
* Greater than or equal operator. Performs only bitwise comparison.
* @param text The UnicodeString to compare to this one.
* @return TRUE if the characters in this are bitwise
* greater than or equal to the characters in <code>text</code>, FALSE otherwise
* @stable ICU 2.0
*/
inline UBool operator>= (const UnicodeString& text) const;
/**
* Less than or equal operator. Performs only bitwise comparison.
* @param text The UnicodeString to compare to this one.
* @return TRUE if the characters in this are bitwise
* less than or equal to the characters in <code>text</code>, FALSE otherwise
* @stable ICU 2.0
*/
inline UBool operator<= (const UnicodeString& text) const;
/**
* Compare the characters bitwise in this UnicodeString to
* the characters in <code>text</code>.
* @param text The UnicodeString to compare to this one.
* @return The result of bitwise character comparison: 0 if this
* contains the same characters as <code>text</code>, -1 if the characters in
* this are bitwise less than the characters in <code>text</code>, +1 if the
* characters in this are bitwise greater than the characters
* in <code>text</code>.
* @stable ICU 2.0
*/
inline int8_t compare(const UnicodeString& text) const;
/**
* Compare the characters bitwise in the range
* [<TT>start</TT>, <TT>start + length</TT>) with the characters
* in the <b>entire string</b> <TT>text</TT>.
* (The parameters "start" and "length" are not applied to the other text "text".)
* @param start the offset at which the compare operation begins
* @param length the number of characters of text to compare.
* @param text the other text to be compared against this string.
* @return The result of bitwise character comparison: 0 if this
* contains the same characters as <code>text</code>, -1 if the characters in
* this are bitwise less than the characters in <code>text</code>, +1 if the
* characters in this are bitwise greater than the characters
* in <code>text</code>.
* @stable ICU 2.0
*/
inline int8_t compare(int32_t start,
int32_t length,
const UnicodeString& text) const;
/**
* Compare the characters bitwise in the range
* [<TT>start</TT>, <TT>start + length</TT>) with the characters
* in <TT>srcText</TT> in the range
* [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
* @param start the offset at which the compare operation begins
* @param length the number of characters in this to compare.
* @param srcText the text to be compared
* @param srcStart the offset into <TT>srcText</TT> to start comparison
* @param srcLength the number of characters in <TT>src</TT> to compare
* @return The result of bitwise character comparison: 0 if this
* contains the same characters as <code>srcText</code>, -1 if the characters in
* this are bitwise less than the characters in <code>srcText</code>, +1 if the
* characters in this are bitwise greater than the characters
* in <code>srcText</code>.
* @stable ICU 2.0
*/
inline int8_t compare(int32_t start,
int32_t length,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength) const;
/**
* Compare the characters bitwise in this UnicodeString with the first
* <TT>srcLength</TT> characters in <TT>srcChars</TT>.
* @param srcChars The characters to compare to this UnicodeString.
* @param srcLength the number of characters in <TT>srcChars</TT> to compare
* @return The result of bitwise character comparison: 0 if this
* contains the same characters as <code>srcChars</code>, -1 if the characters in
* this are bitwise less than the characters in <code>srcChars</code>, +1 if the
* characters in this are bitwise greater than the characters
* in <code>srcChars</code>.
* @stable ICU 2.0
*/
inline int8_t compare(ConstChar16Ptr srcChars,
int32_t srcLength) const;
/**
* Compare the characters bitwise in the range
* [<TT>start</TT>, <TT>start + length</TT>) with the first
* <TT>length</TT> characters in <TT>srcChars</TT>
* @param start the offset at which the compare operation begins
* @param length the number of characters to compare.
* @param srcChars the characters to be compared
* @return The result of bitwise character comparison: 0 if this
* contains the same characters as <code>srcChars</code>, -1 if the characters in
* this are bitwise less than the characters in <code>srcChars</code>, +1 if the
* characters in this are bitwise greater than the characters
* in <code>srcChars</code>.
* @stable ICU 2.0
*/
inline int8_t compare(int32_t start,
int32_t length,
const char16_t *srcChars) const;
/**
* Compare the characters bitwise in the range
* [<TT>start</TT>, <TT>start + length</TT>) with the characters
* in <TT>srcChars</TT> in the range
* [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
* @param start the offset at which the compare operation begins
* @param length the number of characters in this to compare
* @param srcChars the characters to be compared
* @param srcStart the offset into <TT>srcChars</TT> to start comparison
* @param srcLength the number of characters in <TT>srcChars</TT> to compare
* @return The result of bitwise character comparison: 0 if this
* contains the same characters as <code>srcChars</code>, -1 if the characters in
* this are bitwise less than the characters in <code>srcChars</code>, +1 if the
* characters in this are bitwise greater than the characters
* in <code>srcChars</code>.
* @stable ICU 2.0
*/
inline int8_t compare(int32_t start,
int32_t length,
const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength) const;
/**
* Compare the characters bitwise in the range
* [<TT>start</TT>, <TT>limit</TT>) with the characters
* in <TT>srcText</TT> in the range
* [<TT>srcStart</TT>, <TT>srcLimit</TT>).
* @param start the offset at which the compare operation begins
* @param limit the offset immediately following the compare operation
* @param srcText the text to be compared
* @param srcStart the offset into <TT>srcText</TT> to start comparison
* @param srcLimit the offset into <TT>srcText</TT> to limit comparison
* @return The result of bitwise character comparison: 0 if this
* contains the same characters as <code>srcText</code>, -1 if the characters in
* this are bitwise less than the characters in <code>srcText</code>, +1 if the
* characters in this are bitwise greater than the characters
* in <code>srcText</code>.
* @stable ICU 2.0
*/
inline int8_t compareBetween(int32_t start,
int32_t limit,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLimit) const;
/**
* Compare two Unicode strings in code point order.
* The result may be different from the results of compare(), operator<, etc.
* if supplementary characters are present:
*
* In UTF-16, supplementary characters (with code points U+10000 and above) are
* stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff,
* which means that they compare as less than some other BMP characters like U+feff.
* This function compares Unicode strings in code point order.
* If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.
*
* @param text Another string to compare this one to.
* @return a negative/zero/positive integer corresponding to whether
* this string is less than/equal to/greater than the second one
* in code point order
* @stable ICU 2.0
*/
inline int8_t compareCodePointOrder(const UnicodeString& text) const;
/**
* Compare two Unicode strings in code point order.
* The result may be different from the results of compare(), operator<, etc.
* if supplementary characters are present:
*
* In UTF-16, supplementary characters (with code points U+10000 and above) are
* stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff,
* which means that they compare as less than some other BMP characters like U+feff.
* This function compares Unicode strings in code point order.
* If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.
*
* @param start The start offset in this string at which the compare operation begins.
* @param length The number of code units from this string to compare.
* @param srcText Another string to compare this one to.
* @return a negative/zero/positive integer corresponding to whether
* this string is less than/equal to/greater than the second one
* in code point order
* @stable ICU 2.0
*/
inline int8_t compareCodePointOrder(int32_t start,
int32_t length,
const UnicodeString& srcText) const;
/**
* Compare two Unicode strings in code point order.
* The result may be different from the results of compare(), operator<, etc.
* if supplementary characters are present:
*
* In UTF-16, supplementary characters (with code points U+10000 and above) are
* stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff,
* which means that they compare as less than some other BMP characters like U+feff.
* This function compares Unicode strings in code point order.
* If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.
*
* @param start The start offset in this string at which the compare operation begins.
* @param length The number of code units from this string to compare.
* @param srcText Another string to compare this one to.
* @param srcStart The start offset in that string at which the compare operation begins.
* @param srcLength The number of code units from that string to compare.
* @return a negative/zero/positive integer corresponding to whether
* this string is less than/equal to/greater than the second one
* in code point order
* @stable ICU 2.0
*/
inline int8_t compareCodePointOrder(int32_t start,
int32_t length,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength) const;
/**
* Compare two Unicode strings in code point order.
* The result may be different from the results of compare(), operator<, etc.
* if supplementary characters are present:
*
* In UTF-16, supplementary characters (with code points U+10000 and above) are
* stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff,
* which means that they compare as less than some other BMP characters like U+feff.
* This function compares Unicode strings in code point order.
* If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.
*
* @param srcChars A pointer to another string to compare this one to.
* @param srcLength The number of code units from that string to compare.
* @return a negative/zero/positive integer corresponding to whether
* this string is less than/equal to/greater than the second one
* in code point order
* @stable ICU 2.0
*/
inline int8_t compareCodePointOrder(ConstChar16Ptr srcChars,
int32_t srcLength) const;
/**
* Compare two Unicode strings in code point order.
* The result may be different from the results of compare(), operator<, etc.
* if supplementary characters are present:
*
* In UTF-16, supplementary characters (with code points U+10000 and above) are
* stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff,
* which means that they compare as less than some other BMP characters like U+feff.
* This function compares Unicode strings in code point order.
* If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.
*
* @param start The start offset in this string at which the compare operation begins.
* @param length The number of code units from this string to compare.
* @param srcChars A pointer to another string to compare this one to.
* @return a negative/zero/positive integer corresponding to whether
* this string is less than/equal to/greater than the second one
* in code point order
* @stable ICU 2.0
*/
inline int8_t compareCodePointOrder(int32_t start,
int32_t length,
const char16_t *srcChars) const;
/**
* Compare two Unicode strings in code point order.
* The result may be different from the results of compare(), operator<, etc.
* if supplementary characters are present:
*
* In UTF-16, supplementary characters (with code points U+10000 and above) are
* stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff,
* which means that they compare as less than some other BMP characters like U+feff.
* This function compares Unicode strings in code point order.
* If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.
*
* @param start The start offset in this string at which the compare operation begins.
* @param length The number of code units from this string to compare.
* @param srcChars A pointer to another string to compare this one to.
* @param srcStart The start offset in that string at which the compare operation begins.
* @param srcLength The number of code units from that string to compare.
* @return a negative/zero/positive integer corresponding to whether
* this string is less than/equal to/greater than the second one
* in code point order
* @stable ICU 2.0
*/
inline int8_t compareCodePointOrder(int32_t start,
int32_t length,
const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength) const;
/**
* Compare two Unicode strings in code point order.
* The result may be different from the results of compare(), operator<, etc.
* if supplementary characters are present:
*
* In UTF-16, supplementary characters (with code points U+10000 and above) are
* stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff,
* which means that they compare as less than some other BMP characters like U+feff.
* This function compares Unicode strings in code point order.
* If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.
*
* @param start The start offset in this string at which the compare operation begins.
* @param limit The offset after the last code unit from this string to compare.
* @param srcText Another string to compare this one to.
* @param srcStart The start offset in that string at which the compare operation begins.
* @param srcLimit The offset after the last code unit from that string to compare.
* @return a negative/zero/positive integer corresponding to whether
* this string is less than/equal to/greater than the second one
* in code point order
* @stable ICU 2.0
*/
inline int8_t compareCodePointOrderBetween(int32_t start,
int32_t limit,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLimit) const;
/**
* Compare two strings case-insensitively using full case folding.
* This is equivalent to this->foldCase(options).compare(text.foldCase(options)).
*
* @param text Another string to compare this one to.
* @param options A bit set of options:
* - U_FOLD_CASE_DEFAULT or 0 is used for default options:
* Comparison in code unit order with default case folding.
*
* - U_COMPARE_CODE_POINT_ORDER
* Set to choose code point order instead of code unit order
* (see u_strCompare for details).
*
* - U_FOLD_CASE_EXCLUDE_SPECIAL_I
*
* @return A negative, zero, or positive integer indicating the comparison result.
* @stable ICU 2.0
*/
inline int8_t caseCompare(const UnicodeString& text, uint32_t options) const;
/**
* Compare two strings case-insensitively using full case folding.
* This is equivalent to this->foldCase(options).compare(srcText.foldCase(options)).
*
* @param start The start offset in this string at which the compare operation begins.
* @param length The number of code units from this string to compare.
* @param srcText Another string to compare this one to.
* @param options A bit set of options:
* - U_FOLD_CASE_DEFAULT or 0 is used for default options:
* Comparison in code unit order with default case folding.
*
* - U_COMPARE_CODE_POINT_ORDER
* Set to choose code point order instead of code unit order
* (see u_strCompare for details).
*
* - U_FOLD_CASE_EXCLUDE_SPECIAL_I
*
* @return A negative, zero, or positive integer indicating the comparison result.
* @stable ICU 2.0
*/
inline int8_t caseCompare(int32_t start,
int32_t length,
const UnicodeString& srcText,
uint32_t options) const;
/**
* Compare two strings case-insensitively using full case folding.
* This is equivalent to this->foldCase(options).compare(srcText.foldCase(options)).
*
* @param start The start offset in this string at which the compare operation begins.
* @param length The number of code units from this string to compare.
* @param srcText Another string to compare this one to.
* @param srcStart The start offset in that string at which the compare operation begins.
* @param srcLength The number of code units from that string to compare.
* @param options A bit set of options:
* - U_FOLD_CASE_DEFAULT or 0 is used for default options:
* Comparison in code unit order with default case folding.
*
* - U_COMPARE_CODE_POINT_ORDER
* Set to choose code point order instead of code unit order
* (see u_strCompare for details).
*
* - U_FOLD_CASE_EXCLUDE_SPECIAL_I
*
* @return A negative, zero, or positive integer indicating the comparison result.
* @stable ICU 2.0
*/
inline int8_t caseCompare(int32_t start,
int32_t length,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength,
uint32_t options) const;
/**
* Compare two strings case-insensitively using full case folding.
* This is equivalent to this->foldCase(options).compare(srcChars.foldCase(options)).
*
* @param srcChars A pointer to another string to compare this one to.
* @param srcLength The number of code units from that string to compare.
* @param options A bit set of options:
* - U_FOLD_CASE_DEFAULT or 0 is used for default options:
* Comparison in code unit order with default case folding.
*
* - U_COMPARE_CODE_POINT_ORDER
* Set to choose code point order instead of code unit order
* (see u_strCompare for details).
*
* - U_FOLD_CASE_EXCLUDE_SPECIAL_I
*
* @return A negative, zero, or positive integer indicating the comparison result.
* @stable ICU 2.0
*/
inline int8_t caseCompare(ConstChar16Ptr srcChars,
int32_t srcLength,
uint32_t options) const;
/**
* Compare two strings case-insensitively using full case folding.
* This is equivalent to this->foldCase(options).compare(srcChars.foldCase(options)).
*
* @param start The start offset in this string at which the compare operation begins.
* @param length The number of code units from this string to compare.
* @param srcChars A pointer to another string to compare this one to.
* @param options A bit set of options:
* - U_FOLD_CASE_DEFAULT or 0 is used for default options:
* Comparison in code unit order with default case folding.
*
* - U_COMPARE_CODE_POINT_ORDER
* Set to choose code point order instead of code unit order
* (see u_strCompare for details).
*
* - U_FOLD_CASE_EXCLUDE_SPECIAL_I
*
* @return A negative, zero, or positive integer indicating the comparison result.
* @stable ICU 2.0
*/
inline int8_t caseCompare(int32_t start,
int32_t length,
const char16_t *srcChars,
uint32_t options) const;
/**
* Compare two strings case-insensitively using full case folding.
* This is equivalent to this->foldCase(options).compare(srcChars.foldCase(options)).
*
* @param start The start offset in this string at which the compare operation begins.
* @param length The number of code units from this string to compare.
* @param srcChars A pointer to another string to compare this one to.
* @param srcStart The start offset in that string at which the compare operation begins.
* @param srcLength The number of code units from that string to compare.
* @param options A bit set of options:
* - U_FOLD_CASE_DEFAULT or 0 is used for default options:
* Comparison in code unit order with default case folding.
*
* - U_COMPARE_CODE_POINT_ORDER
* Set to choose code point order instead of code unit order
* (see u_strCompare for details).
*
* - U_FOLD_CASE_EXCLUDE_SPECIAL_I
*
* @return A negative, zero, or positive integer indicating the comparison result.
* @stable ICU 2.0
*/
inline int8_t caseCompare(int32_t start,
int32_t length,
const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength,
uint32_t options) const;
/**
* Compare two strings case-insensitively using full case folding.
* This is equivalent to this->foldCase(options).compareBetween(text.foldCase(options)).
*
* @param start The start offset in this string at which the compare operation begins.
* @param limit The offset after the last code unit from this string to compare.
* @param srcText Another string to compare this one to.
* @param srcStart The start offset in that string at which the compare operation begins.
* @param srcLimit The offset after the last code unit from that string to compare.
* @param options A bit set of options:
* - U_FOLD_CASE_DEFAULT or 0 is used for default options:
* Comparison in code unit order with default case folding.
*
* - U_COMPARE_CODE_POINT_ORDER
* Set to choose code point order instead of code unit order
* (see u_strCompare for details).
*
* - U_FOLD_CASE_EXCLUDE_SPECIAL_I
*
* @return A negative, zero, or positive integer indicating the comparison result.
* @stable ICU 2.0
*/
inline int8_t caseCompareBetween(int32_t start,
int32_t limit,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLimit,
uint32_t options) const;
/**
* Determine if this starts with the characters in <TT>text</TT>
* @param text The text to match.
* @return TRUE if this starts with the characters in <TT>text</TT>,
* FALSE otherwise
* @stable ICU 2.0
*/
inline UBool startsWith(const UnicodeString& text) const;
/**
* Determine if this starts with the characters in <TT>srcText</TT>
* in the range [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
* @param srcText The text to match.
* @param srcStart the offset into <TT>srcText</TT> to start matching
* @param srcLength the number of characters in <TT>srcText</TT> to match
* @return TRUE if this starts with the characters in <TT>text</TT>,
* FALSE otherwise
* @stable ICU 2.0
*/
inline UBool startsWith(const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength) const;
/**
* Determine if this starts with the characters in <TT>srcChars</TT>
* @param srcChars The characters to match.
* @param srcLength the number of characters in <TT>srcChars</TT>
* @return TRUE if this starts with the characters in <TT>srcChars</TT>,
* FALSE otherwise
* @stable ICU 2.0
*/
inline UBool startsWith(ConstChar16Ptr srcChars,
int32_t srcLength) const;
/**
* Determine if this ends with the characters in <TT>srcChars</TT>
* in the range [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
* @param srcChars The characters to match.
* @param srcStart the offset into <TT>srcText</TT> to start matching
* @param srcLength the number of characters in <TT>srcChars</TT> to match
* @return TRUE if this ends with the characters in <TT>srcChars</TT>, FALSE otherwise
* @stable ICU 2.0
*/
inline UBool startsWith(const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength) const;
/**
* Determine if this ends with the characters in <TT>text</TT>
* @param text The text to match.
* @return TRUE if this ends with the characters in <TT>text</TT>,
* FALSE otherwise
* @stable ICU 2.0
*/
inline UBool endsWith(const UnicodeString& text) const;
/**
* Determine if this ends with the characters in <TT>srcText</TT>
* in the range [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
* @param srcText The text to match.
* @param srcStart the offset into <TT>srcText</TT> to start matching
* @param srcLength the number of characters in <TT>srcText</TT> to match
* @return TRUE if this ends with the characters in <TT>text</TT>,
* FALSE otherwise
* @stable ICU 2.0
*/
inline UBool endsWith(const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength) const;
/**
* Determine if this ends with the characters in <TT>srcChars</TT>
* @param srcChars The characters to match.
* @param srcLength the number of characters in <TT>srcChars</TT>
* @return TRUE if this ends with the characters in <TT>srcChars</TT>,
* FALSE otherwise
* @stable ICU 2.0
*/
inline UBool endsWith(ConstChar16Ptr srcChars,
int32_t srcLength) const;
/**
* Determine if this ends with the characters in <TT>srcChars</TT>
* in the range [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
* @param srcChars The characters to match.
* @param srcStart the offset into <TT>srcText</TT> to start matching
* @param srcLength the number of characters in <TT>srcChars</TT> to match
* @return TRUE if this ends with the characters in <TT>srcChars</TT>,
* FALSE otherwise
* @stable ICU 2.0
*/
inline UBool endsWith(const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength) const;
/* Searching - bitwise only */
/**
* Locate in this the first occurrence of the characters in <TT>text</TT>,
* using bitwise comparison.
* @param text The text to search for.
* @return The offset into this of the start of <TT>text</TT>,
* or -1 if not found.
* @stable ICU 2.0
*/
inline int32_t indexOf(const UnicodeString& text) const;
/**
* Locate in this the first occurrence of the characters in <TT>text</TT>
* starting at offset <TT>start</TT>, using bitwise comparison.
* @param text The text to search for.
* @param start The offset at which searching will start.
* @return The offset into this of the start of <TT>text</TT>,
* or -1 if not found.
* @stable ICU 2.0
*/
inline int32_t indexOf(const UnicodeString& text,
int32_t start) const;
/**
* Locate in this the first occurrence in the range
* [<TT>start</TT>, <TT>start + length</TT>) of the characters
* in <TT>text</TT>, using bitwise comparison.
* @param text The text to search for.
* @param start The offset at which searching will start.
* @param length The number of characters to search
* @return The offset into this of the start of <TT>text</TT>,
* or -1 if not found.
* @stable ICU 2.0
*/
inline int32_t indexOf(const UnicodeString& text,
int32_t start,
int32_t length) const;
/**
* Locate in this the first occurrence in the range
* [<TT>start</TT>, <TT>start + length</TT>) of the characters
* in <TT>srcText</TT> in the range
* [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>),
* using bitwise comparison.
* @param srcText The text to search for.
* @param srcStart the offset into <TT>srcText</TT> at which
* to start matching
* @param srcLength the number of characters in <TT>srcText</TT> to match
* @param start the offset into this at which to start matching
* @param length the number of characters in this to search
* @return The offset into this of the start of <TT>text</TT>,
* or -1 if not found.
* @stable ICU 2.0
*/
inline int32_t indexOf(const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength,
int32_t start,
int32_t length) const;
/**
* Locate in this the first occurrence of the characters in
* <TT>srcChars</TT>
* starting at offset <TT>start</TT>, using bitwise comparison.
* @param srcChars The text to search for.
* @param srcLength the number of characters in <TT>srcChars</TT> to match
* @param start the offset into this at which to start matching
* @return The offset into this of the start of <TT>text</TT>,
* or -1 if not found.
* @stable ICU 2.0
*/
inline int32_t indexOf(const char16_t *srcChars,
int32_t srcLength,
int32_t start) const;
/**
* Locate in this the first occurrence in the range
* [<TT>start</TT>, <TT>start + length</TT>) of the characters
* in <TT>srcChars</TT>, using bitwise comparison.
* @param srcChars The text to search for.
* @param srcLength the number of characters in <TT>srcChars</TT>
* @param start The offset at which searching will start.
* @param length The number of characters to search
* @return The offset into this of the start of <TT>srcChars</TT>,
* or -1 if not found.
* @stable ICU 2.0
*/
inline int32_t indexOf(ConstChar16Ptr srcChars,
int32_t srcLength,
int32_t start,
int32_t length) const;
/**
* Locate in this the first occurrence in the range
* [<TT>start</TT>, <TT>start + length</TT>) of the characters
* in <TT>srcChars</TT> in the range
* [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>),
* using bitwise comparison.
* @param srcChars The text to search for.
* @param srcStart the offset into <TT>srcChars</TT> at which
* to start matching
* @param srcLength the number of characters in <TT>srcChars</TT> to match
* @param start the offset into this at which to start matching
* @param length the number of characters in this to search
* @return The offset into this of the start of <TT>text</TT>,
* or -1 if not found.
* @stable ICU 2.0
*/
int32_t indexOf(const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength,
int32_t start,
int32_t length) const;
/**
* Locate in this the first occurrence of the BMP code point <code>c</code>,
* using bitwise comparison.
* @param c The code unit to search for.
* @return The offset into this of <TT>c</TT>, or -1 if not found.
* @stable ICU 2.0
*/
inline int32_t indexOf(char16_t c) const;
/**
* Locate in this the first occurrence of the code point <TT>c</TT>,
* using bitwise comparison.
*
* @param c The code point to search for.
* @return The offset into this of <TT>c</TT>, or -1 if not found.
* @stable ICU 2.0
*/
inline int32_t indexOf(UChar32 c) const;
/**
* Locate in this the first occurrence of the BMP code point <code>c</code>,
* starting at offset <TT>start</TT>, using bitwise comparison.
* @param c The code unit to search for.
* @param start The offset at which searching will start.
* @return The offset into this of <TT>c</TT>, or -1 if not found.
* @stable ICU 2.0
*/
inline int32_t indexOf(char16_t c,
int32_t start) const;
/**
* Locate in this the first occurrence of the code point <TT>c</TT>
* starting at offset <TT>start</TT>, using bitwise comparison.
*
* @param c The code point to search for.
* @param start The offset at which searching will start.
* @return The offset into this of <TT>c</TT>, or -1 if not found.
* @stable ICU 2.0
*/
inline int32_t indexOf(UChar32 c,
int32_t start) const;
/**
* Locate in this the first occurrence of the BMP code point <code>c</code>
* in the range [<TT>start</TT>, <TT>start + length</TT>),
* using bitwise comparison.
* @param c The code unit to search for.
* @param start the offset into this at which to start matching
* @param length the number of characters in this to search
* @return The offset into this of <TT>c</TT>, or -1 if not found.
* @stable ICU 2.0
*/
inline int32_t indexOf(char16_t c,
int32_t start,
int32_t length) const;
/**
* Locate in this the first occurrence of the code point <TT>c</TT>
* in the range [<TT>start</TT>, <TT>start + length</TT>),
* using bitwise comparison.
*
* @param c The code point to search for.
* @param start the offset into this at which to start matching
* @param length the number of characters in this to search
* @return The offset into this of <TT>c</TT>, or -1 if not found.
* @stable ICU 2.0
*/
inline int32_t indexOf(UChar32 c,
int32_t start,
int32_t length) const;
/**
* Locate in this the last occurrence of the characters in <TT>text</TT>,
* using bitwise comparison.
* @param text The text to search for.
* @return The offset into this of the start of <TT>text</TT>,
* or -1 if not found.
* @stable ICU 2.0
*/
inline int32_t lastIndexOf(const UnicodeString& text) const;
/**
* Locate in this the last occurrence of the characters in <TT>text</TT>
* starting at offset <TT>start</TT>, using bitwise comparison.
* @param text The text to search for.
* @param start The offset at which searching will start.
* @return The offset into this of the start of <TT>text</TT>,
* or -1 if not found.
* @stable ICU 2.0
*/
inline int32_t lastIndexOf(const UnicodeString& text,
int32_t start) const;
/**
* Locate in this the last occurrence in the range
* [<TT>start</TT>, <TT>start + length</TT>) of the characters
* in <TT>text</TT>, using bitwise comparison.
* @param text The text to search for.
* @param start The offset at which searching will start.
* @param length The number of characters to search
* @return The offset into this of the start of <TT>text</TT>,
* or -1 if not found.
* @stable ICU 2.0
*/
inline int32_t lastIndexOf(const UnicodeString& text,
int32_t start,
int32_t length) const;
/**
* Locate in this the last occurrence in the range
* [<TT>start</TT>, <TT>start + length</TT>) of the characters
* in <TT>srcText</TT> in the range
* [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>),
* using bitwise comparison.
* @param srcText The text to search for.
* @param srcStart the offset into <TT>srcText</TT> at which
* to start matching
* @param srcLength the number of characters in <TT>srcText</TT> to match
* @param start the offset into this at which to start matching
* @param length the number of characters in this to search
* @return The offset into this of the start of <TT>text</TT>,
* or -1 if not found.
* @stable ICU 2.0
*/
inline int32_t lastIndexOf(const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength,
int32_t start,
int32_t length) const;
/**
* Locate in this the last occurrence of the characters in <TT>srcChars</TT>
* starting at offset <TT>start</TT>, using bitwise comparison.
* @param srcChars The text to search for.
* @param srcLength the number of characters in <TT>srcChars</TT> to match
* @param start the offset into this at which to start matching
* @return The offset into this of the start of <TT>text</TT>,
* or -1 if not found.
* @stable ICU 2.0
*/
inline int32_t lastIndexOf(const char16_t *srcChars,
int32_t srcLength,
int32_t start) const;
/**
* Locate in this the last occurrence in the range
* [<TT>start</TT>, <TT>start + length</TT>) of the characters
* in <TT>srcChars</TT>, using bitwise comparison.
* @param srcChars The text to search for.
* @param srcLength the number of characters in <TT>srcChars</TT>
* @param start The offset at which searching will start.
* @param length The number of characters to search
* @return The offset into this of the start of <TT>srcChars</TT>,
* or -1 if not found.
* @stable ICU 2.0
*/
inline int32_t lastIndexOf(ConstChar16Ptr srcChars,
int32_t srcLength,
int32_t start,
int32_t length) const;
/**
* Locate in this the last occurrence in the range
* [<TT>start</TT>, <TT>start + length</TT>) of the characters
* in <TT>srcChars</TT> in the range
* [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>),
* using bitwise comparison.
* @param srcChars The text to search for.
* @param srcStart the offset into <TT>srcChars</TT> at which
* to start matching
* @param srcLength the number of characters in <TT>srcChars</TT> to match
* @param start the offset into this at which to start matching
* @param length the number of characters in this to search
* @return The offset into this of the start of <TT>text</TT>,
* or -1 if not found.
* @stable ICU 2.0
*/
int32_t lastIndexOf(const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength,
int32_t start,
int32_t length) const;
/**
* Locate in this the last occurrence of the BMP code point <code>c</code>,
* using bitwise comparison.
* @param c The code unit to search for.
* @return The offset into this of <TT>c</TT>, or -1 if not found.
* @stable ICU 2.0
*/
inline int32_t lastIndexOf(char16_t c) const;
/**
* Locate in this the last occurrence of the code point <TT>c</TT>,
* using bitwise comparison.
*
* @param c The code point to search for.
* @return The offset into this of <TT>c</TT>, or -1 if not found.
* @stable ICU 2.0
*/
inline int32_t lastIndexOf(UChar32 c) const;
/**
* Locate in this the last occurrence of the BMP code point <code>c</code>
* starting at offset <TT>start</TT>, using bitwise comparison.
* @param c The code unit to search for.
* @param start The offset at which searching will start.
* @return The offset into this of <TT>c</TT>, or -1 if not found.
* @stable ICU 2.0
*/
inline int32_t lastIndexOf(char16_t c,
int32_t start) const;
/**
* Locate in this the last occurrence of the code point <TT>c</TT>
* starting at offset <TT>start</TT>, using bitwise comparison.
*
* @param c The code point to search for.
* @param start The offset at which searching will start.
* @return The offset into this of <TT>c</TT>, or -1 if not found.
* @stable ICU 2.0
*/
inline int32_t lastIndexOf(UChar32 c,
int32_t start) const;
/**
* Locate in this the last occurrence of the BMP code point <code>c</code>
* in the range [<TT>start</TT>, <TT>start + length</TT>),
* using bitwise comparison.
* @param c The code unit to search for.
* @param start the offset into this at which to start matching
* @param length the number of characters in this to search
* @return The offset into this of <TT>c</TT>, or -1 if not found.
* @stable ICU 2.0
*/
inline int32_t lastIndexOf(char16_t c,
int32_t start,
int32_t length) const;
/**
* Locate in this the last occurrence of the code point <TT>c</TT>
* in the range [<TT>start</TT>, <TT>start + length</TT>),
* using bitwise comparison.
*
* @param c The code point to search for.
* @param start the offset into this at which to start matching
* @param length the number of characters in this to search
* @return The offset into this of <TT>c</TT>, or -1 if not found.
* @stable ICU 2.0
*/
inline int32_t lastIndexOf(UChar32 c,
int32_t start,
int32_t length) const;
/* Character access */
/**
* Return the code unit at offset <tt>offset</tt>.
* If the offset is not valid (0..length()-1) then U+ffff is returned.
* @param offset a valid offset into the text
* @return the code unit at offset <tt>offset</tt>
* or 0xffff if the offset is not valid for this string
* @stable ICU 2.0
*/
inline char16_t charAt(int32_t offset) const;
/**
* Return the code unit at offset <tt>offset</tt>.
* If the offset is not valid (0..length()-1) then U+ffff is returned.
* @param offset a valid offset into the text
* @return the code unit at offset <tt>offset</tt>
* @stable ICU 2.0
*/
inline char16_t operator[] (int32_t offset) const;
/**
* Return the code point that contains the code unit
* at offset <tt>offset</tt>.
* If the offset is not valid (0..length()-1) then U+ffff is returned.
* @param offset a valid offset into the text
* that indicates the text offset of any of the code units
* that will be assembled into a code point (21-bit value) and returned
* @return the code point of text at <tt>offset</tt>
* or 0xffff if the offset is not valid for this string
* @stable ICU 2.0
*/
UChar32 char32At(int32_t offset) const;
/**
* Adjust a random-access offset so that
* it points to the beginning of a Unicode character.
* The offset that is passed in points to
* any code unit of a code point,
* while the returned offset will point to the first code unit
* of the same code point.
* In UTF-16, if the input offset points to a second surrogate
* of a surrogate pair, then the returned offset will point
* to the first surrogate.
* @param offset a valid offset into one code point of the text
* @return offset of the first code unit of the same code point
* @see U16_SET_CP_START
* @stable ICU 2.0
*/
int32_t getChar32Start(int32_t offset) const;
/**
* Adjust a random-access offset so that
* it points behind a Unicode character.
* The offset that is passed in points behind
* any code unit of a code point,
* while the returned offset will point behind the last code unit
* of the same code point.
* In UTF-16, if the input offset points behind the first surrogate
* (i.e., to the second surrogate)
* of a surrogate pair, then the returned offset will point
* behind the second surrogate (i.e., to the first surrogate).
* @param offset a valid offset after any code unit of a code point of the text
* @return offset of the first code unit after the same code point
* @see U16_SET_CP_LIMIT
* @stable ICU 2.0
*/
int32_t getChar32Limit(int32_t offset) const;
/**
* Move the code unit index along the string by delta code points.
* Interpret the input index as a code unit-based offset into the string,
* move the index forward or backward by delta code points, and
* return the resulting index.
* The input index should point to the first code unit of a code point,
* if there is more than one.
*
* Both input and output indexes are code unit-based as for all
* string indexes/offsets in ICU (and other libraries, like MBCS char*).
* If delta<0 then the index is moved backward (toward the start of the string).
* If delta>0 then the index is moved forward (toward the end of the string).
*
* This behaves like CharacterIterator::move32(delta, kCurrent).
*
* Behavior for out-of-bounds indexes:
* <code>moveIndex32</code> pins the input index to 0..length(), i.e.,
* if the input index<0 then it is pinned to 0;
* if it is index>length() then it is pinned to length().
* Afterwards, the index is moved by <code>delta</code> code points
* forward or backward,
* but no further backward than to 0 and no further forward than to length().
* The resulting index return value will be in between 0 and length(), inclusively.
*
* Examples:
* <pre>
* // s has code points 'a' U+10000 'b' U+10ffff U+2029
* UnicodeString s=UNICODE_STRING("a\\U00010000b\\U0010ffff\\u2029", 31).unescape();
*
* // initial index: position of U+10000
* int32_t index=1;
*
* // the following examples will all result in index==4, position of U+10ffff
*
* // skip 2 code points from some position in the string
* index=s.moveIndex32(index, 2); // skips U+10000 and 'b'
*
* // go to the 3rd code point from the start of s (0-based)
* index=s.moveIndex32(0, 3); // skips 'a', U+10000, and 'b'
*
* // go to the next-to-last code point of s
* index=s.moveIndex32(s.length(), -2); // backward-skips U+2029 and U+10ffff
* </pre>
*
* @param index input code unit index
* @param delta (signed) code point count to move the index forward or backward
* in the string
* @return the resulting code unit index
* @stable ICU 2.0
*/
int32_t moveIndex32(int32_t index, int32_t delta) const;
/* Substring extraction */
/**
* Copy the characters in the range
* [<tt>start</tt>, <tt>start + length</tt>) into the array <tt>dst</tt>,
* beginning at <tt>dstStart</tt>.
* If the string aliases to <code>dst</code> itself as an external buffer,
* then extract() will not copy the contents.
*
* @param start offset of first character which will be copied into the array
* @param length the number of characters to extract
* @param dst array in which to copy characters. The length of <tt>dst</tt>
* must be at least (<tt>dstStart + length</tt>).
* @param dstStart the offset in <TT>dst</TT> where the first character
* will be extracted
* @stable ICU 2.0
*/
inline void extract(int32_t start,
int32_t length,
Char16Ptr dst,
int32_t dstStart = 0) const;
/**
* Copy the contents of the string into dest.
* This is a convenience function that
* checks if there is enough space in dest,
* extracts the entire string if possible,
* and NUL-terminates dest if possible.
*
* If the string fits into dest but cannot be NUL-terminated
* (length()==destCapacity) then the error code is set to U_STRING_NOT_TERMINATED_WARNING.
* If the string itself does not fit into dest
* (length()>destCapacity) then the error code is set to U_BUFFER_OVERFLOW_ERROR.
*
* If the string aliases to <code>dest</code> itself as an external buffer,
* then extract() will not copy the contents.
*
* @param dest Destination string buffer.
* @param destCapacity Number of char16_ts available at dest.
* @param errorCode ICU error code.
* @return length()
* @stable ICU 2.0
*/
int32_t
extract(Char16Ptr dest, int32_t destCapacity,
UErrorCode &errorCode) const;
/**
* Copy the characters in the range
* [<tt>start</tt>, <tt>start + length</tt>) into the UnicodeString
* <tt>target</tt>.
* @param start offset of first character which will be copied
* @param length the number of characters to extract
* @param target UnicodeString into which to copy characters.
* @return A reference to <TT>target</TT>
* @stable ICU 2.0
*/
inline void extract(int32_t start,
int32_t length,
UnicodeString& target) const;
/**
* Copy the characters in the range [<tt>start</tt>, <tt>limit</tt>)
* into the array <tt>dst</tt>, beginning at <tt>dstStart</tt>.
* @param start offset of first character which will be copied into the array
* @param limit offset immediately following the last character to be copied
* @param dst array in which to copy characters. The length of <tt>dst</tt>
* must be at least (<tt>dstStart + (limit - start)</tt>).
* @param dstStart the offset in <TT>dst</TT> where the first character
* will be extracted
* @stable ICU 2.0
*/
inline void extractBetween(int32_t start,
int32_t limit,
char16_t *dst,
int32_t dstStart = 0) const;
/**
* Copy the characters in the range [<tt>start</tt>, <tt>limit</tt>)
* into the UnicodeString <tt>target</tt>. Replaceable API.
* @param start offset of first character which will be copied
* @param limit offset immediately following the last character to be copied
* @param target UnicodeString into which to copy characters.
* @return A reference to <TT>target</TT>
* @stable ICU 2.0
*/
virtual void extractBetween(int32_t start,
int32_t limit,
UnicodeString& target) const;
/**
* Copy the characters in the range
* [<tt>start</TT>, <tt>start + startLength</TT>) into an array of characters.
* All characters must be invariant (see utypes.h).
* Use US_INV as the last, signature-distinguishing parameter.
*
* This function does not write any more than <code>targetCapacity</code>
* characters but returns the length of the entire output string
* so that one can allocate a larger buffer and call the function again
* if necessary.
* The output string is NUL-terminated if possible.
*
* @param start offset of first character which will be copied
* @param startLength the number of characters to extract
* @param target the target buffer for extraction, can be NULL
* if targetLength is 0
* @param targetCapacity the length of the target buffer
* @param inv Signature-distinguishing paramater, use US_INV.
* @return the output string length, not including the terminating NUL
* @stable ICU 3.2
*/
int32_t extract(int32_t start,
int32_t startLength,
char *target,
int32_t targetCapacity,
enum EInvariant inv) const;
#if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
/**
* Copy the characters in the range
* [<tt>start</TT>, <tt>start + length</TT>) into an array of characters
* in the platform's default codepage.
* This function does not write any more than <code>targetLength</code>
* characters but returns the length of the entire output string
* so that one can allocate a larger buffer and call the function again
* if necessary.
* The output string is NUL-terminated if possible.
*
* @param start offset of first character which will be copied
* @param startLength the number of characters to extract
* @param target the target buffer for extraction
* @param targetLength the length of the target buffer
* If <TT>target</TT> is NULL, then the number of bytes required for
* <TT>target</TT> is returned.
* @return the output string length, not including the terminating NUL
* @stable ICU 2.0
*/
int32_t extract(int32_t start,
int32_t startLength,
char *target,
uint32_t targetLength) const;
#endif
#if !UCONFIG_NO_CONVERSION
/**
* Copy the characters in the range
* [<tt>start</TT>, <tt>start + length</TT>) into an array of characters
* in a specified codepage.
* The output string is NUL-terminated.
*
* Recommendation: For invariant-character strings use
* extract(int32_t start, int32_t length, char *target, int32_t targetCapacity, enum EInvariant inv) const
* because it avoids object code dependencies of UnicodeString on
* the conversion code.
*
* @param start offset of first character which will be copied
* @param startLength the number of characters to extract
* @param target the target buffer for extraction
* @param codepage the desired codepage for the characters. 0 has
* the special meaning of the default codepage
* If <code>codepage</code> is an empty string (<code>""</code>),
* then a simple conversion is performed on the codepage-invariant
* subset ("invariant characters") of the platform encoding. See utypes.h.
* If <TT>target</TT> is NULL, then the number of bytes required for
* <TT>target</TT> is returned. It is assumed that the target is big enough
* to fit all of the characters.
* @return the output string length, not including the terminating NUL
* @stable ICU 2.0
*/
inline int32_t extract(int32_t start,
int32_t startLength,
char *target,
const char *codepage = 0) const;
/**
* Copy the characters in the range
* [<tt>start</TT>, <tt>start + length</TT>) into an array of characters
* in a specified codepage.
* This function does not write any more than <code>targetLength</code>
* characters but returns the length of the entire output string
* so that one can allocate a larger buffer and call the function again
* if necessary.
* The output string is NUL-terminated if possible.
*
* Recommendation: For invariant-character strings use
* extract(int32_t start, int32_t length, char *target, int32_t targetCapacity, enum EInvariant inv) const
* because it avoids object code dependencies of UnicodeString on
* the conversion code.
*
* @param start offset of first character which will be copied
* @param startLength the number of characters to extract
* @param target the target buffer for extraction
* @param targetLength the length of the target buffer
* @param codepage the desired codepage for the characters. 0 has
* the special meaning of the default codepage
* If <code>codepage</code> is an empty string (<code>""</code>),
* then a simple conversion is performed on the codepage-invariant
* subset ("invariant characters") of the platform encoding. See utypes.h.
* If <TT>target</TT> is NULL, then the number of bytes required for
* <TT>target</TT> is returned.
* @return the output string length, not including the terminating NUL
* @stable ICU 2.0
*/
int32_t extract(int32_t start,
int32_t startLength,
char *target,
uint32_t targetLength,
const char *codepage) const;
/**
* Convert the UnicodeString into a codepage string using an existing UConverter.
* The output string is NUL-terminated if possible.
*
* This function avoids the overhead of opening and closing a converter if
* multiple strings are extracted.
*
* @param dest destination string buffer, can be NULL if destCapacity==0
* @param destCapacity the number of chars available at dest
* @param cnv the converter object to be used (ucnv_resetFromUnicode() will be called),
* or NULL for the default converter
* @param errorCode normal ICU error code
* @return the length of the output string, not counting the terminating NUL;
* if the length is greater than destCapacity, then the string will not fit
* and a buffer of the indicated length would need to be passed in
* @stable ICU 2.0
*/
int32_t extract(char *dest, int32_t destCapacity,
UConverter *cnv,
UErrorCode &errorCode) const;
#endif
/**
* Create a temporary substring for the specified range.
* Unlike the substring constructor and setTo() functions,
* the object returned here will be a read-only alias (using getBuffer())
* rather than copying the text.
* As a result, this substring operation is much faster but requires
* that the original string not be modified or deleted during the lifetime
* of the returned substring object.
* @param start offset of the first character visible in the substring
* @param length length of the substring
* @return a read-only alias UnicodeString object for the substring
* @stable ICU 4.4
*/
UnicodeString tempSubString(int32_t start=0, int32_t length=INT32_MAX) const;
/**
* Create a temporary substring for the specified range.
* Same as tempSubString(start, length) except that the substring range
* is specified as a (start, limit) pair (with an exclusive limit index)
* rather than a (start, length) pair.
* @param start offset of the first character visible in the substring
* @param limit offset immediately following the last character visible in the substring
* @return a read-only alias UnicodeString object for the substring
* @stable ICU 4.4
*/
inline UnicodeString tempSubStringBetween(int32_t start, int32_t limit=INT32_MAX) const;
/**
* Convert the UnicodeString to UTF-8 and write the result
* to a ByteSink. This is called by toUTF8String().
* Unpaired surrogates are replaced with U+FFFD.
* Calls u_strToUTF8WithSub().
*
* @param sink A ByteSink to which the UTF-8 version of the string is written.
* sink.Flush() is called at the end.
* @stable ICU 4.2
* @see toUTF8String
*/
void toUTF8(ByteSink &sink) const;
/**
* Convert the UnicodeString to UTF-8 and append the result
* to a standard string.
* Unpaired surrogates are replaced with U+FFFD.
* Calls toUTF8().
*
* @param result A standard string (or a compatible object)
* to which the UTF-8 version of the string is appended.
* @return The string object.
* @stable ICU 4.2
* @see toUTF8
*/
template<typename StringClass>
StringClass &toUTF8String(StringClass &result) const {
StringByteSink<StringClass> sbs(&result, length());
toUTF8(sbs);
return result;
}
/**
* Convert the UnicodeString to UTF-32.
* Unpaired surrogates are replaced with U+FFFD.
* Calls u_strToUTF32WithSub().
*
* @param utf32 destination string buffer, can be NULL if capacity==0
* @param capacity the number of UChar32s available at utf32
* @param errorCode Standard ICU error code. Its input value must
* pass the U_SUCCESS() test, or else the function returns
* immediately. Check for U_FAILURE() on output or use with
* function chaining. (See User Guide for details.)
* @return The length of the UTF-32 string.
* @see fromUTF32
* @stable ICU 4.2
*/
int32_t toUTF32(UChar32 *utf32, int32_t capacity, UErrorCode &errorCode) const;
/* Length operations */
/**
* Return the length of the UnicodeString object.
* The length is the number of char16_t code units are in the UnicodeString.
* If you want the number of code points, please use countChar32().
* @return the length of the UnicodeString object
* @see countChar32
* @stable ICU 2.0
*/
inline int32_t length(void) const;
/**
* Count Unicode code points in the length char16_t code units of the string.
* A code point may occupy either one or two char16_t code units.
* Counting code points involves reading all code units.
*
* This functions is basically the inverse of moveIndex32().
*
* @param start the index of the first code unit to check
* @param length the number of char16_t code units to check
* @return the number of code points in the specified code units
* @see length
* @stable ICU 2.0
*/
int32_t
countChar32(int32_t start=0, int32_t length=INT32_MAX) const;
/**
* Check if the length char16_t code units of the string
* contain more Unicode code points than a certain number.
* This is more efficient than counting all code points in this part of the string
* and comparing that number with a threshold.
* This function may not need to scan the string at all if the length
* falls within a certain range, and
* never needs to count more than 'number+1' code points.
* Logically equivalent to (countChar32(start, length)>number).
* A Unicode code point may occupy either one or two char16_t code units.
*
* @param start the index of the first code unit to check (0 for the entire string)
* @param length the number of char16_t code units to check
* (use INT32_MAX for the entire string; remember that start/length
* values are pinned)
* @param number The number of code points in the (sub)string is compared against
* the 'number' parameter.
* @return Boolean value for whether the string contains more Unicode code points
* than 'number'. Same as (u_countChar32(s, length)>number).
* @see countChar32
* @see u_strHasMoreChar32Than
* @stable ICU 2.4
*/
UBool
hasMoreChar32Than(int32_t start, int32_t length, int32_t number) const;
/**
* Determine if this string is empty.
* @return TRUE if this string contains 0 characters, FALSE otherwise.
* @stable ICU 2.0
*/
inline UBool isEmpty(void) const;
/**
* Return the capacity of the internal buffer of the UnicodeString object.
* This is useful together with the getBuffer functions.
* See there for details.
*
* @return the number of char16_ts available in the internal buffer
* @see getBuffer
* @stable ICU 2.0
*/
inline int32_t getCapacity(void) const;
/* Other operations */
/**
* Generate a hash code for this object.
* @return The hash code of this UnicodeString.
* @stable ICU 2.0
*/
inline int32_t hashCode(void) const;
/**
* Determine if this object contains a valid string.
* A bogus string has no value. It is different from an empty string,
* although in both cases isEmpty() returns TRUE and length() returns 0.
* setToBogus() and isBogus() can be used to indicate that no string value is available.
* For a bogus string, getBuffer() and getTerminatedBuffer() return NULL, and
* length() returns 0.
*
* @return TRUE if the string is bogus/invalid, FALSE otherwise
* @see setToBogus()
* @stable ICU 2.0
*/
inline UBool isBogus(void) const;
//========================================
// Write operations
//========================================
/* Assignment operations */
/**
* Assignment operator. Replace the characters in this UnicodeString
* with the characters from <TT>srcText</TT>.
*
* Starting with ICU 2.4, the assignment operator and the copy constructor
* allocate a new buffer and copy the buffer contents even for readonly aliases.
* By contrast, the fastCopyFrom() function implements the old,
* more efficient but less safe behavior
* of making this string also a readonly alias to the same buffer.
*
* If the source object has an "open" buffer from getBuffer(minCapacity),
* then the copy is an empty string.
*
* @param srcText The text containing the characters to replace
* @return a reference to this
* @stable ICU 2.0
* @see fastCopyFrom
*/
UnicodeString &operator=(const UnicodeString &srcText);
/**
* Almost the same as the assignment operator.
* Replace the characters in this UnicodeString
* with the characters from <code>srcText</code>.
*
* This function works the same as the assignment operator
* for all strings except for ones that are readonly aliases.
*
* Starting with ICU 2.4, the assignment operator and the copy constructor
* allocate a new buffer and copy the buffer contents even for readonly aliases.
* This function implements the old, more efficient but less safe behavior
* of making this string also a readonly alias to the same buffer.
*
* The fastCopyFrom function must be used only if it is known that the lifetime of
* this UnicodeString does not exceed the lifetime of the aliased buffer
* including its contents, for example for strings from resource bundles
* or aliases to string constants.
*
* If the source object has an "open" buffer from getBuffer(minCapacity),
* then the copy is an empty string.
*
* @param src The text containing the characters to replace.
* @return a reference to this
* @stable ICU 2.4
*/
UnicodeString &fastCopyFrom(const UnicodeString &src);
#if U_HAVE_RVALUE_REFERENCES
/**
* Move assignment operator, might leave src in bogus state.
* This string will have the same contents and state that the source string had.
* The behavior is undefined if *this and src are the same object.
* @param src source string
* @return *this
* @stable ICU 56
*/
UnicodeString &operator=(UnicodeString &&src) U_NOEXCEPT {
return moveFrom(src);
}
#endif
// do not use #ifndef U_HIDE_DRAFT_API for moveFrom, needed by non-draft API
/**
* Move assignment, might leave src in bogus state.
* This string will have the same contents and state that the source string had.
* The behavior is undefined if *this and src are the same object.
*
* Can be called explicitly, does not need C++11 support.
* @param src source string
* @return *this
* @draft ICU 56
*/
UnicodeString &moveFrom(UnicodeString &src) U_NOEXCEPT;
/**
* Swap strings.
* @param other other string
* @stable ICU 56
*/
void swap(UnicodeString &other) U_NOEXCEPT;
/**
* Non-member UnicodeString swap function.
* @param s1 will get s2's contents and state
* @param s2 will get s1's contents and state
* @stable ICU 56
*/
friend U_COMMON_API inline void U_EXPORT2
swap(UnicodeString &s1, UnicodeString &s2) U_NOEXCEPT {
s1.swap(s2);
}
/**
* Assignment operator. Replace the characters in this UnicodeString
* with the code unit <TT>ch</TT>.
* @param ch the code unit to replace
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& operator= (char16_t ch);
/**
* Assignment operator. Replace the characters in this UnicodeString
* with the code point <TT>ch</TT>.
* @param ch the code point to replace
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& operator= (UChar32 ch);
/**
* Set the text in the UnicodeString object to the characters
* in <TT>srcText</TT> in the range
* [<TT>srcStart</TT>, <TT>srcText.length()</TT>).
* <TT>srcText</TT> is not modified.
* @param srcText the source for the new characters
* @param srcStart the offset into <TT>srcText</TT> where new characters
* will be obtained
* @return a reference to this
* @stable ICU 2.2
*/
inline UnicodeString& setTo(const UnicodeString& srcText,
int32_t srcStart);
/**
* Set the text in the UnicodeString object to the characters
* in <TT>srcText</TT> in the range
* [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
* <TT>srcText</TT> is not modified.
* @param srcText the source for the new characters
* @param srcStart the offset into <TT>srcText</TT> where new characters
* will be obtained
* @param srcLength the number of characters in <TT>srcText</TT> in the
* replace string.
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& setTo(const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength);
/**
* Set the text in the UnicodeString object to the characters in
* <TT>srcText</TT>.
* <TT>srcText</TT> is not modified.
* @param srcText the source for the new characters
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& setTo(const UnicodeString& srcText);
/**
* Set the characters in the UnicodeString object to the characters
* in <TT>srcChars</TT>. <TT>srcChars</TT> is not modified.
* @param srcChars the source for the new characters
* @param srcLength the number of Unicode characters in srcChars.
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& setTo(const char16_t *srcChars,
int32_t srcLength);
/**
* Set the characters in the UnicodeString object to the code unit
* <TT>srcChar</TT>.
* @param srcChar the code unit which becomes the UnicodeString's character
* content
* @return a reference to this
* @stable ICU 2.0
*/
UnicodeString& setTo(char16_t srcChar);
/**
* Set the characters in the UnicodeString object to the code point
* <TT>srcChar</TT>.
* @param srcChar the code point which becomes the UnicodeString's character
* content
* @return a reference to this
* @stable ICU 2.0
*/
UnicodeString& setTo(UChar32 srcChar);
/**
* Aliasing setTo() function, analogous to the readonly-aliasing char16_t* constructor.
* The text will be used for the UnicodeString object, but
* it will not be released when the UnicodeString is destroyed.
* This has copy-on-write semantics:
* When the string is modified, then the buffer is first copied into
* newly allocated memory.
* The aliased buffer is never modified.
*
* In an assignment to another UnicodeString, when using the copy constructor
* or the assignment operator, the text will be copied.
* When using fastCopyFrom(), the text will be aliased again,
* so that both strings then alias the same readonly-text.
*
* @param isTerminated specifies if <code>text</code> is <code>NUL</code>-terminated.
* This must be true if <code>textLength==-1</code>.
* @param text The characters to alias for the UnicodeString.
* @param textLength The number of Unicode characters in <code>text</code> to alias.
* If -1, then this constructor will determine the length
* by calling <code>u_strlen()</code>.
* @return a reference to this
* @stable ICU 2.0
*/
UnicodeString &setTo(UBool isTerminated,
ConstChar16Ptr text,
int32_t textLength);
/**
* Aliasing setTo() function, analogous to the writable-aliasing char16_t* constructor.
* The text will be used for the UnicodeString object, but
* it will not be released when the UnicodeString is destroyed.
* This has write-through semantics:
* For as long as the capacity of the buffer is sufficient, write operations
* will directly affect the buffer. When more capacity is necessary, then
* a new buffer will be allocated and the contents copied as with regularly
* constructed strings.
* In an assignment to another UnicodeString, the buffer will be copied.
* The extract(Char16Ptr dst) function detects whether the dst pointer is the same
* as the string buffer itself and will in this case not copy the contents.
*
* @param buffer The characters to alias for the UnicodeString.
* @param buffLength The number of Unicode characters in <code>buffer</code> to alias.
* @param buffCapacity The size of <code>buffer</code> in char16_ts.
* @return a reference to this
* @stable ICU 2.0
*/
UnicodeString &setTo(char16_t *buffer,
int32_t buffLength,
int32_t buffCapacity);
/**
* Make this UnicodeString object invalid.
* The string will test TRUE with isBogus().
*
* A bogus string has no value. It is different from an empty string.
* It can be used to indicate that no string value is available.
* getBuffer() and getTerminatedBuffer() return NULL, and
* length() returns 0.
*
* This utility function is used throughout the UnicodeString
* implementation to indicate that a UnicodeString operation failed,
* and may be used in other functions,
* especially but not exclusively when such functions do not
* take a UErrorCode for simplicity.
*
* The following methods, and no others, will clear a string object's bogus flag:
* - remove()
* - remove(0, INT32_MAX)
* - truncate(0)
* - operator=() (assignment operator)
* - setTo(...)
*
* The simplest ways to turn a bogus string into an empty one
* is to use the remove() function.
* Examples for other functions that are equivalent to "set to empty string":
* \code
* if(s.isBogus()) {
* s.remove(); // set to an empty string (remove all), or
* s.remove(0, INT32_MAX); // set to an empty string (remove all), or
* s.truncate(0); // set to an empty string (complete truncation), or
* s=UnicodeString(); // assign an empty string, or
* s.setTo((UChar32)-1); // set to a pseudo code point that is out of range, or
* static const char16_t nul=0;
* s.setTo(&nul, 0); // set to an empty C Unicode string
* }
* \endcode
*
* @see isBogus()
* @stable ICU 2.0
*/
void setToBogus();
/**
* Set the character at the specified offset to the specified character.
* @param offset A valid offset into the text of the character to set
* @param ch The new character
* @return A reference to this
* @stable ICU 2.0
*/
UnicodeString& setCharAt(int32_t offset,
char16_t ch);
/* Append operations */
/**
* Append operator. Append the code unit <TT>ch</TT> to the UnicodeString
* object.
* @param ch the code unit to be appended
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& operator+= (char16_t ch);
/**
* Append operator. Append the code point <TT>ch</TT> to the UnicodeString
* object.
* @param ch the code point to be appended
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& operator+= (UChar32 ch);
/**
* Append operator. Append the characters in <TT>srcText</TT> to the
* UnicodeString object. <TT>srcText</TT> is not modified.
* @param srcText the source for the new characters
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& operator+= (const UnicodeString& srcText);
/**
* Append the characters
* in <TT>srcText</TT> in the range
* [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>) to the
* UnicodeString object at offset <TT>start</TT>. <TT>srcText</TT>
* is not modified.
* @param srcText the source for the new characters
* @param srcStart the offset into <TT>srcText</TT> where new characters
* will be obtained
* @param srcLength the number of characters in <TT>srcText</TT> in
* the append string
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& append(const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength);
/**
* Append the characters in <TT>srcText</TT> to the UnicodeString object.
* <TT>srcText</TT> is not modified.
* @param srcText the source for the new characters
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& append(const UnicodeString& srcText);
/**
* Append the characters in <TT>srcChars</TT> in the range
* [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>) to the UnicodeString
* object at offset
* <TT>start</TT>. <TT>srcChars</TT> is not modified.
* @param srcChars the source for the new characters
* @param srcStart the offset into <TT>srcChars</TT> where new characters
* will be obtained
* @param srcLength the number of characters in <TT>srcChars</TT> in
* the append string; can be -1 if <TT>srcChars</TT> is NUL-terminated
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& append(const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength);
/**
* Append the characters in <TT>srcChars</TT> to the UnicodeString object
* at offset <TT>start</TT>. <TT>srcChars</TT> is not modified.
* @param srcChars the source for the new characters
* @param srcLength the number of Unicode characters in <TT>srcChars</TT>;
* can be -1 if <TT>srcChars</TT> is NUL-terminated
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& append(ConstChar16Ptr srcChars,
int32_t srcLength);
/**
* Append the code unit <TT>srcChar</TT> to the UnicodeString object.
* @param srcChar the code unit to append
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& append(char16_t srcChar);
/**
* Append the code point <TT>srcChar</TT> to the UnicodeString object.
* @param srcChar the code point to append
* @return a reference to this
* @stable ICU 2.0
*/
UnicodeString& append(UChar32 srcChar);
/* Insert operations */
/**
* Insert the characters in <TT>srcText</TT> in the range
* [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>) into the UnicodeString
* object at offset <TT>start</TT>. <TT>srcText</TT> is not modified.
* @param start the offset where the insertion begins
* @param srcText the source for the new characters
* @param srcStart the offset into <TT>srcText</TT> where new characters
* will be obtained
* @param srcLength the number of characters in <TT>srcText</TT> in
* the insert string
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& insert(int32_t start,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength);
/**
* Insert the characters in <TT>srcText</TT> into the UnicodeString object
* at offset <TT>start</TT>. <TT>srcText</TT> is not modified.
* @param start the offset where the insertion begins
* @param srcText the source for the new characters
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& insert(int32_t start,
const UnicodeString& srcText);
/**
* Insert the characters in <TT>srcChars</TT> in the range
* [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>) into the UnicodeString
* object at offset <TT>start</TT>. <TT>srcChars</TT> is not modified.
* @param start the offset at which the insertion begins
* @param srcChars the source for the new characters
* @param srcStart the offset into <TT>srcChars</TT> where new characters
* will be obtained
* @param srcLength the number of characters in <TT>srcChars</TT>
* in the insert string
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& insert(int32_t start,
const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength);
/**
* Insert the characters in <TT>srcChars</TT> into the UnicodeString object
* at offset <TT>start</TT>. <TT>srcChars</TT> is not modified.
* @param start the offset where the insertion begins
* @param srcChars the source for the new characters
* @param srcLength the number of Unicode characters in srcChars.
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& insert(int32_t start,
ConstChar16Ptr srcChars,
int32_t srcLength);
/**
* Insert the code unit <TT>srcChar</TT> into the UnicodeString object at
* offset <TT>start</TT>.
* @param start the offset at which the insertion occurs
* @param srcChar the code unit to insert
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& insert(int32_t start,
char16_t srcChar);
/**
* Insert the code point <TT>srcChar</TT> into the UnicodeString object at
* offset <TT>start</TT>.
* @param start the offset at which the insertion occurs
* @param srcChar the code point to insert
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& insert(int32_t start,
UChar32 srcChar);
/* Replace operations */
/**
* Replace the characters in the range
* [<TT>start</TT>, <TT>start + length</TT>) with the characters in
* <TT>srcText</TT> in the range
* [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
* <TT>srcText</TT> is not modified.
* @param start the offset at which the replace operation begins
* @param length the number of characters to replace. The character at
* <TT>start + length</TT> is not modified.
* @param srcText the source for the new characters
* @param srcStart the offset into <TT>srcText</TT> where new characters
* will be obtained
* @param srcLength the number of characters in <TT>srcText</TT> in
* the replace string
* @return a reference to this
* @stable ICU 2.0
*/
UnicodeString& replace(int32_t start,
int32_t length,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength);
/**
* Replace the characters in the range
* [<TT>start</TT>, <TT>start + length</TT>)
* with the characters in <TT>srcText</TT>. <TT>srcText</TT> is
* not modified.
* @param start the offset at which the replace operation begins
* @param length the number of characters to replace. The character at
* <TT>start + length</TT> is not modified.
* @param srcText the source for the new characters
* @return a reference to this
* @stable ICU 2.0
*/
UnicodeString& replace(int32_t start,
int32_t length,
const UnicodeString& srcText);
/**
* Replace the characters in the range
* [<TT>start</TT>, <TT>start + length</TT>) with the characters in
* <TT>srcChars</TT> in the range
* [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>). <TT>srcChars</TT>
* is not modified.
* @param start the offset at which the replace operation begins
* @param length the number of characters to replace. The character at
* <TT>start + length</TT> is not modified.
* @param srcChars the source for the new characters
* @param srcStart the offset into <TT>srcChars</TT> where new characters
* will be obtained
* @param srcLength the number of characters in <TT>srcChars</TT>
* in the replace string
* @return a reference to this
* @stable ICU 2.0
*/
UnicodeString& replace(int32_t start,
int32_t length,
const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength);
/**
* Replace the characters in the range
* [<TT>start</TT>, <TT>start + length</TT>) with the characters in
* <TT>srcChars</TT>. <TT>srcChars</TT> is not modified.
* @param start the offset at which the replace operation begins
* @param length number of characters to replace. The character at
* <TT>start + length</TT> is not modified.
* @param srcChars the source for the new characters
* @param srcLength the number of Unicode characters in srcChars
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& replace(int32_t start,
int32_t length,
ConstChar16Ptr srcChars,
int32_t srcLength);
/**
* Replace the characters in the range
* [<TT>start</TT>, <TT>start + length</TT>) with the code unit
* <TT>srcChar</TT>.
* @param start the offset at which the replace operation begins
* @param length the number of characters to replace. The character at
* <TT>start + length</TT> is not modified.
* @param srcChar the new code unit
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& replace(int32_t start,
int32_t length,
char16_t srcChar);
/**
* Replace the characters in the range
* [<TT>start</TT>, <TT>start + length</TT>) with the code point
* <TT>srcChar</TT>.
* @param start the offset at which the replace operation begins
* @param length the number of characters to replace. The character at
* <TT>start + length</TT> is not modified.
* @param srcChar the new code point
* @return a reference to this
* @stable ICU 2.0
*/
UnicodeString& replace(int32_t start, int32_t length, UChar32 srcChar);
/**
* Replace the characters in the range [<TT>start</TT>, <TT>limit</TT>)
* with the characters in <TT>srcText</TT>. <TT>srcText</TT> is not modified.
* @param start the offset at which the replace operation begins
* @param limit the offset immediately following the replace range
* @param srcText the source for the new characters
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& replaceBetween(int32_t start,
int32_t limit,
const UnicodeString& srcText);
/**
* Replace the characters in the range [<TT>start</TT>, <TT>limit</TT>)
* with the characters in <TT>srcText</TT> in the range
* [<TT>srcStart</TT>, <TT>srcLimit</TT>). <TT>srcText</TT> is not modified.
* @param start the offset at which the replace operation begins
* @param limit the offset immediately following the replace range
* @param srcText the source for the new characters
* @param srcStart the offset into <TT>srcChars</TT> where new characters
* will be obtained
* @param srcLimit the offset immediately following the range to copy
* in <TT>srcText</TT>
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& replaceBetween(int32_t start,
int32_t limit,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLimit);
/**
* Replace a substring of this object with the given text.
* @param start the beginning index, inclusive; <code>0 <= start
* <= limit</code>.
* @param limit the ending index, exclusive; <code>start <= limit
* <= length()</code>.
* @param text the text to replace characters <code>start</code>
* to <code>limit - 1</code>
* @stable ICU 2.0
*/
virtual void handleReplaceBetween(int32_t start,
int32_t limit,
const UnicodeString& text);
/**
* Replaceable API
* @return TRUE if it has MetaData
* @stable ICU 2.4
*/
virtual UBool hasMetaData() const;
/**
* Copy a substring of this object, retaining attribute (out-of-band)
* information. This method is used to duplicate or reorder substrings.
* The destination index must not overlap the source range.
*
* @param start the beginning index, inclusive; <code>0 <= start <=
* limit</code>.
* @param limit the ending index, exclusive; <code>start <= limit <=
* length()</code>.
* @param dest the destination index. The characters from
* <code>start..limit-1</code> will be copied to <code>dest</code>.
* Implementations of this method may assume that <code>dest <= start ||
* dest >= limit</code>.
* @stable ICU 2.0
*/
virtual void copy(int32_t start, int32_t limit, int32_t dest);
/* Search and replace operations */
/**
* Replace all occurrences of characters in oldText with the characters
* in newText
* @param oldText the text containing the search text
* @param newText the text containing the replacement text
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& findAndReplace(const UnicodeString& oldText,
const UnicodeString& newText);
/**
* Replace all occurrences of characters in oldText with characters
* in newText
* in the range [<TT>start</TT>, <TT>start + length</TT>).
* @param start the start of the range in which replace will performed
* @param length the length of the range in which replace will be performed
* @param oldText the text containing the search text
* @param newText the text containing the replacement text
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& findAndReplace(int32_t start,
int32_t length,
const UnicodeString& oldText,
const UnicodeString& newText);
/**
* Replace all occurrences of characters in oldText in the range
* [<TT>oldStart</TT>, <TT>oldStart + oldLength</TT>) with the characters
* in newText in the range
* [<TT>newStart</TT>, <TT>newStart + newLength</TT>)
* in the range [<TT>start</TT>, <TT>start + length</TT>).
* @param start the start of the range in which replace will performed
* @param length the length of the range in which replace will be performed
* @param oldText the text containing the search text
* @param oldStart the start of the search range in <TT>oldText</TT>
* @param oldLength the length of the search range in <TT>oldText</TT>
* @param newText the text containing the replacement text
* @param newStart the start of the replacement range in <TT>newText</TT>
* @param newLength the length of the replacement range in <TT>newText</TT>
* @return a reference to this
* @stable ICU 2.0
*/
UnicodeString& findAndReplace(int32_t start,
int32_t length,
const UnicodeString& oldText,
int32_t oldStart,
int32_t oldLength,
const UnicodeString& newText,
int32_t newStart,
int32_t newLength);
/* Remove operations */
/**
* Remove all characters from the UnicodeString object.
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& remove(void);
/**
* Remove the characters in the range
* [<TT>start</TT>, <TT>start + length</TT>) from the UnicodeString object.
* @param start the offset of the first character to remove
* @param length the number of characters to remove
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& remove(int32_t start,
int32_t length = (int32_t)INT32_MAX);
/**
* Remove the characters in the range
* [<TT>start</TT>, <TT>limit</TT>) from the UnicodeString object.
* @param start the offset of the first character to remove
* @param limit the offset immediately following the range to remove
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& removeBetween(int32_t start,
int32_t limit = (int32_t)INT32_MAX);
/**
* Retain only the characters in the range
* [<code>start</code>, <code>limit</code>) from the UnicodeString object.
* Removes characters before <code>start</code> and at and after <code>limit</code>.
* @param start the offset of the first character to retain
* @param limit the offset immediately following the range to retain
* @return a reference to this
* @stable ICU 4.4
*/
inline UnicodeString &retainBetween(int32_t start, int32_t limit = INT32_MAX);
/* Length operations */
/**
* Pad the start of this UnicodeString with the character <TT>padChar</TT>.
* If the length of this UnicodeString is less than targetLength,
* length() - targetLength copies of padChar will be added to the
* beginning of this UnicodeString.
* @param targetLength the desired length of the string
* @param padChar the character to use for padding. Defaults to
* space (U+0020)
* @return TRUE if the text was padded, FALSE otherwise.
* @stable ICU 2.0
*/
UBool padLeading(int32_t targetLength,
char16_t padChar = 0x0020);
/**
* Pad the end of this UnicodeString with the character <TT>padChar</TT>.
* If the length of this UnicodeString is less than targetLength,
* length() - targetLength copies of padChar will be added to the
* end of this UnicodeString.
* @param targetLength the desired length of the string
* @param padChar the character to use for padding. Defaults to
* space (U+0020)
* @return TRUE if the text was padded, FALSE otherwise.
* @stable ICU 2.0
*/
UBool padTrailing(int32_t targetLength,
char16_t padChar = 0x0020);
/**
* Truncate this UnicodeString to the <TT>targetLength</TT>.
* @param targetLength the desired length of this UnicodeString.
* @return TRUE if the text was truncated, FALSE otherwise
* @stable ICU 2.0
*/
inline UBool truncate(int32_t targetLength);
/**
* Trims leading and trailing whitespace from this UnicodeString.
* @return a reference to this
* @stable ICU 2.0
*/
UnicodeString& trim(void);
/* Miscellaneous operations */
/**
* Reverse this UnicodeString in place.
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& reverse(void);
/**
* Reverse the range [<TT>start</TT>, <TT>start + length</TT>) in
* this UnicodeString.
* @param start the start of the range to reverse
* @param length the number of characters to to reverse
* @return a reference to this
* @stable ICU 2.0
*/
inline UnicodeString& reverse(int32_t start,
int32_t length);
/**
* Convert the characters in this to UPPER CASE following the conventions of
* the default locale.
* @return A reference to this.
* @stable ICU 2.0
*/
UnicodeString& toUpper(void);
/**
* Convert the characters in this to UPPER CASE following the conventions of
* a specific locale.
* @param locale The locale containing the conventions to use.
* @return A reference to this.
* @stable ICU 2.0
*/
UnicodeString& toUpper(const Locale& locale);
/**
* Convert the characters in this to lower case following the conventions of
* the default locale.
* @return A reference to this.
* @stable ICU 2.0
*/
UnicodeString& toLower(void);
/**
* Convert the characters in this to lower case following the conventions of
* a specific locale.
* @param locale The locale containing the conventions to use.
* @return A reference to this.
* @stable ICU 2.0
*/
UnicodeString& toLower(const Locale& locale);
#if !UCONFIG_NO_BREAK_ITERATION
/**
* Titlecase this string, convenience function using the default locale.
*
* Casing is locale-dependent and context-sensitive.
* Titlecasing uses a break iterator to find the first characters of words
* that are to be titlecased. It titlecases those characters and lowercases
* all others.
*
* The titlecase break iterator can be provided to customize for arbitrary
* styles, using rules and dictionaries beyond the standard iterators.
* It may be more efficient to always provide an iterator to avoid
* opening and closing one for each string.
* The standard titlecase iterator for the root locale implements the
* algorithm of Unicode TR 21.
*
* This function uses only the setText(), first() and next() methods of the
* provided break iterator.
*
* @param titleIter A break iterator to find the first characters of words
* that are to be titlecased.
* If none is provided (0), then a standard titlecase
* break iterator is opened.
* Otherwise the provided iterator is set to the string's text.
* @return A reference to this.
* @stable ICU 2.1
*/
UnicodeString &toTitle(BreakIterator *titleIter);
/**
* Titlecase this string.
*
* Casing is locale-dependent and context-sensitive.
* Titlecasing uses a break iterator to find the first characters of words
* that are to be titlecased. It titlecases those characters and lowercases
* all others.
*
* The titlecase break iterator can be provided to customize for arbitrary
* styles, using rules and dictionaries beyond the standard iterators.
* It may be more efficient to always provide an iterator to avoid
* opening and closing one for each string.
* The standard titlecase iterator for the root locale implements the
* algorithm of Unicode TR 21.
*
* This function uses only the setText(), first() and next() methods of the
* provided break iterator.
*
* @param titleIter A break iterator to find the first characters of words
* that are to be titlecased.
* If none is provided (0), then a standard titlecase
* break iterator is opened.
* Otherwise the provided iterator is set to the string's text.
* @param locale The locale to consider.
* @return A reference to this.
* @stable ICU 2.1
*/
UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale);
/**
* Titlecase this string, with options.
*
* Casing is locale-dependent and context-sensitive.
* Titlecasing uses a break iterator to find the first characters of words
* that are to be titlecased. It titlecases those characters and lowercases
* all others. (This can be modified with options.)
*
* The titlecase break iterator can be provided to customize for arbitrary
* styles, using rules and dictionaries beyond the standard iterators.
* It may be more efficient to always provide an iterator to avoid
* opening and closing one for each string.
* The standard titlecase iterator for the root locale implements the
* algorithm of Unicode TR 21.
*
* This function uses only the setText(), first() and next() methods of the
* provided break iterator.
*
* @param titleIter A break iterator to find the first characters of words
* that are to be titlecased.
* If none is provided (0), then a standard titlecase
* break iterator is opened.
* Otherwise the provided iterator is set to the string's text.
* @param locale The locale to consider.
* @param options Options bit set, usually 0. See U_TITLECASE_NO_LOWERCASE,
* U_TITLECASE_NO_BREAK_ADJUSTMENT, U_TITLECASE_ADJUST_TO_CASED,
* U_TITLECASE_WHOLE_STRING, U_TITLECASE_SENTENCES.
* @param options Options bit set, see ucasemap_open().
* @return A reference to this.
* @stable ICU 3.8
*/
UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale, uint32_t options);
#endif
/**
* Case-folds the characters in this string.
*
* Case-folding is locale-independent and not context-sensitive,
* but there is an option for whether to include or exclude mappings for dotted I
* and dotless i that are marked with 'T' in CaseFolding.txt.
*
* The result may be longer or shorter than the original.
*
* @param options Either U_FOLD_CASE_DEFAULT or U_FOLD_CASE_EXCLUDE_SPECIAL_I
* @return A reference to this.
* @stable ICU 2.0
*/
UnicodeString &foldCase(uint32_t options=0 /*U_FOLD_CASE_DEFAULT*/);
//========================================
// Access to the internal buffer
//========================================
/**
* Get a read/write pointer to the internal buffer.
* The buffer is guaranteed to be large enough for at least minCapacity char16_ts,
* writable, and is still owned by the UnicodeString object.
* Calls to getBuffer(minCapacity) must not be nested, and
* must be matched with calls to releaseBuffer(newLength).
* If the string buffer was read-only or shared,
* then it will be reallocated and copied.
*
* An attempted nested call will return 0, and will not further modify the
* state of the UnicodeString object.
* It also returns 0 if the string is bogus.
*
* The actual capacity of the string buffer may be larger than minCapacity.
* getCapacity() returns the actual capacity.
* For many operations, the full capacity should be used to avoid reallocations.
*
* While the buffer is "open" between getBuffer(minCapacity)
* and releaseBuffer(newLength), the following applies:
* - The string length is set to 0.
* - Any read API call on the UnicodeString object will behave like on a 0-length string.
* - Any write API call on the UnicodeString object is disallowed and will have no effect.
* - You can read from and write to the returned buffer.
* - The previous string contents will still be in the buffer;
* if you want to use it, then you need to call length() before getBuffer(minCapacity).
* If the length() was greater than minCapacity, then any contents after minCapacity
* may be lost.
* The buffer contents is not NUL-terminated by getBuffer().
* If length()<getCapacity() then you can terminate it by writing a NUL
* at index length().
* - You must call releaseBuffer(newLength) before and in order to
* return to normal UnicodeString operation.
*
* @param minCapacity the minimum number of char16_ts that are to be available
* in the buffer, starting at the returned pointer;
* default to the current string capacity if minCapacity==-1
* @return a writable pointer to the internal string buffer,
* or nullptr if an error occurs (nested calls, out of memory)
*
* @see releaseBuffer
* @see getTerminatedBuffer()
* @stable ICU 2.0
*/
char16_t *getBuffer(int32_t minCapacity);
/**
* Release a read/write buffer on a UnicodeString object with an
* "open" getBuffer(minCapacity).
* This function must be called in a matched pair with getBuffer(minCapacity).
* releaseBuffer(newLength) must be called if and only if a getBuffer(minCapacity) is "open".
*
* It will set the string length to newLength, at most to the current capacity.
* If newLength==-1 then it will set the length according to the
* first NUL in the buffer, or to the capacity if there is no NUL.
*
* After calling releaseBuffer(newLength) the UnicodeString is back to normal operation.
*
* @param newLength the new length of the UnicodeString object;
* defaults to the current capacity if newLength is greater than that;
* if newLength==-1, it defaults to u_strlen(buffer) but not more than
* the current capacity of the string
*
* @see getBuffer(int32_t minCapacity)
* @stable ICU 2.0
*/
void releaseBuffer(int32_t newLength=-1);
/**
* Get a read-only pointer to the internal buffer.
* This can be called at any time on a valid UnicodeString.
*
* It returns 0 if the string is bogus, or
* during an "open" getBuffer(minCapacity).
*
* It can be called as many times as desired.
* The pointer that it returns will remain valid until the UnicodeString object is modified,
* at which time the pointer is semantically invalidated and must not be used any more.
*
* The capacity of the buffer can be determined with getCapacity().
* The part after length() may or may not be initialized and valid,
* depending on the history of the UnicodeString object.
*
* The buffer contents is (probably) not NUL-terminated.
* You can check if it is with
* <code>(s.length()<s.getCapacity() && buffer[s.length()]==0)</code>.
* (See getTerminatedBuffer().)
*
* The buffer may reside in read-only memory. Its contents must not
* be modified.
*
* @return a read-only pointer to the internal string buffer,
* or nullptr if the string is empty or bogus
*
* @see getBuffer(int32_t minCapacity)
* @see getTerminatedBuffer()
* @stable ICU 2.0
*/
inline const char16_t *getBuffer() const;
/**
* Get a read-only pointer to the internal buffer,
* making sure that it is NUL-terminated.
* This can be called at any time on a valid UnicodeString.
*
* It returns 0 if the string is bogus, or
* during an "open" getBuffer(minCapacity), or if the buffer cannot
* be NUL-terminated (because memory allocation failed).
*
* It can be called as many times as desired.
* The pointer that it returns will remain valid until the UnicodeString object is modified,
* at which time the pointer is semantically invalidated and must not be used any more.
*
* The capacity of the buffer can be determined with getCapacity().
* The part after length()+1 may or may not be initialized and valid,
* depending on the history of the UnicodeString object.
*
* The buffer contents is guaranteed to be NUL-terminated.
* getTerminatedBuffer() may reallocate the buffer if a terminating NUL
* is written.
* For this reason, this function is not const, unlike getBuffer().
* Note that a UnicodeString may also contain NUL characters as part of its contents.
*
* The buffer may reside in read-only memory. Its contents must not
* be modified.
*
* @return a read-only pointer to the internal string buffer,
* or 0 if the string is empty or bogus
*
* @see getBuffer(int32_t minCapacity)
* @see getBuffer()
* @stable ICU 2.2
*/
const char16_t *getTerminatedBuffer();
//========================================
// Constructors
//========================================
/** Construct an empty UnicodeString.
* @stable ICU 2.0
*/
inline UnicodeString();
/**
* Construct a UnicodeString with capacity to hold <TT>capacity</TT> char16_ts
* @param capacity the number of char16_ts this UnicodeString should hold
* before a resize is necessary; if count is greater than 0 and count
* code points c take up more space than capacity, then capacity is adjusted
* accordingly.
* @param c is used to initially fill the string
* @param count specifies how many code points c are to be written in the
* string
* @stable ICU 2.0
*/
UnicodeString(int32_t capacity, UChar32 c, int32_t count);
/**
* Single char16_t (code unit) constructor.
*
* It is recommended to mark this constructor "explicit" by
* <code>-DUNISTR_FROM_CHAR_EXPLICIT=explicit</code>
* on the compiler command line or similar.
* @param ch the character to place in the UnicodeString
* @stable ICU 2.0
*/
UNISTR_FROM_CHAR_EXPLICIT UnicodeString(char16_t ch);
/**
* Single UChar32 (code point) constructor.
*
* It is recommended to mark this constructor "explicit" by
* <code>-DUNISTR_FROM_CHAR_EXPLICIT=explicit</code>
* on the compiler command line or similar.
* @param ch the character to place in the UnicodeString
* @stable ICU 2.0
*/
UNISTR_FROM_CHAR_EXPLICIT UnicodeString(UChar32 ch);
/**
* char16_t* constructor.
*
* It is recommended to mark this constructor "explicit" by
* <code>-DUNISTR_FROM_STRING_EXPLICIT=explicit</code>
* on the compiler command line or similar.
* @param text The characters to place in the UnicodeString. <TT>text</TT>
* must be NULL (U+0000) terminated.
* @stable ICU 2.0
*/
UNISTR_FROM_STRING_EXPLICIT UnicodeString(const char16_t *text);
/*
* Do not use #ifndef U_HIDE_DRAFT_API for the following constructor,
* it should always be available regardless of U_HIDE_DRAFT_API status
*/
#if !U_CHAR16_IS_TYPEDEF
/**
* uint16_t * constructor.
* Delegates to UnicodeString(const char16_t *).
*
* It is recommended to mark this constructor "explicit" by
* <code>-DUNISTR_FROM_STRING_EXPLICIT=explicit</code>
* on the compiler command line or similar.
* @param text NUL-terminated UTF-16 string
* @draft ICU 59
*/
UNISTR_FROM_STRING_EXPLICIT UnicodeString(const uint16_t *text) :
UnicodeString(ConstChar16Ptr(text)) {}
#endif
/*
* Do not use #ifndef U_HIDE_DRAFT_API for the following constructor,
* it should always be available regardless of U_HIDE_DRAFT_API status
*/
#if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
/**
* wchar_t * constructor.
* (Only defined if U_SIZEOF_WCHAR_T==2.)
* Delegates to UnicodeString(const char16_t *).
*
* It is recommended to mark this constructor "explicit" by
* <code>-DUNISTR_FROM_STRING_EXPLICIT=explicit</code>
* on the compiler command line or similar.
* @param text NUL-terminated UTF-16 string
* @draft ICU 59
*/
UNISTR_FROM_STRING_EXPLICIT UnicodeString(const wchar_t *text) :
UnicodeString(ConstChar16Ptr(text)) {}
#endif
/*
* Do not use #ifndef U_HIDE_DRAFT_API for the following constructor,
* it should always be available regardless of U_HIDE_DRAFT_API status
*/
/**
* nullptr_t constructor.
* Effectively the same as the default constructor, makes an empty string object.
*
* It is recommended to mark this constructor "explicit" by
* <code>-DUNISTR_FROM_STRING_EXPLICIT=explicit</code>
* on the compiler command line or similar.
* @param text nullptr
* @draft ICU 59
*/
UNISTR_FROM_STRING_EXPLICIT inline UnicodeString(const std::nullptr_t text);
/**
* char16_t* constructor.
* @param text The characters to place in the UnicodeString.
* @param textLength The number of Unicode characters in <TT>text</TT>
* to copy.
* @stable ICU 2.0
*/
UnicodeString(const char16_t *text,
int32_t textLength);
/*
* Do not use #ifndef U_HIDE_DRAFT_API for the following constructor,
* it should always be available regardless of U_HIDE_DRAFT_API status
*/
#if !U_CHAR16_IS_TYPEDEF
/**
* uint16_t * constructor.
* Delegates to UnicodeString(const char16_t *, int32_t).
* @param text UTF-16 string
* @param length string length
* @draft ICU 59
*/
UnicodeString(const uint16_t *text, int32_t length) :
UnicodeString(ConstChar16Ptr(text), length) {}
#endif
/*
* Do not use #ifndef U_HIDE_DRAFT_API for the following constructor,
* it should always be available regardless of U_HIDE_DRAFT_API status
*/
#if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
/**
* wchar_t * constructor.
* (Only defined if U_SIZEOF_WCHAR_T==2.)
* Delegates to UnicodeString(const char16_t *, int32_t).
* @param text NUL-terminated UTF-16 string
* @param length string length
* @draft ICU 59
*/
UnicodeString(const wchar_t *text, int32_t length) :
UnicodeString(ConstChar16Ptr(text), length) {}
#endif
/*
* Do not use #ifndef U_HIDE_DRAFT_API for the following constructor,
* it should always be available regardless of U_HIDE_DRAFT_API status
*/
/**
* nullptr_t constructor.
* Effectively the same as the default constructor, makes an empty string object.
* @param text nullptr
* @param length ignored
* @draft ICU 59
*/
inline UnicodeString(const std::nullptr_t text, int32_t length);
/**
* Readonly-aliasing char16_t* constructor.
* The text will be used for the UnicodeString object, but
* it will not be released when the UnicodeString is destroyed.
* This has copy-on-write semantics:
* When the string is modified, then the buffer is first copied into
* newly allocated memory.
* The aliased buffer is never modified.
*
* In an assignment to another UnicodeString, when using the copy constructor
* or the assignment operator, the text will be copied.
* When using fastCopyFrom(), the text will be aliased again,
* so that both strings then alias the same readonly-text.
*
* @param isTerminated specifies if <code>text</code> is <code>NUL</code>-terminated.
* This must be true if <code>textLength==-1</code>.
* @param text The characters to alias for the UnicodeString.
* @param textLength The number of Unicode characters in <code>text</code> to alias.
* If -1, then this constructor will determine the length
* by calling <code>u_strlen()</code>.
* @stable ICU 2.0
*/
UnicodeString(UBool isTerminated,
ConstChar16Ptr text,
int32_t textLength);
/**
* Writable-aliasing char16_t* constructor.
* The text will be used for the UnicodeString object, but
* it will not be released when the UnicodeString is destroyed.
* This has write-through semantics:
* For as long as the capacity of the buffer is sufficient, write operations
* will directly affect the buffer. When more capacity is necessary, then
* a new buffer will be allocated and the contents copied as with regularly
* constructed strings.
* In an assignment to another UnicodeString, the buffer will be copied.
* The extract(Char16Ptr dst) function detects whether the dst pointer is the same
* as the string buffer itself and will in this case not copy the contents.
*
* @param buffer The characters to alias for the UnicodeString.
* @param buffLength The number of Unicode characters in <code>buffer</code> to alias.
* @param buffCapacity The size of <code>buffer</code> in char16_ts.
* @stable ICU 2.0
*/
UnicodeString(char16_t *buffer, int32_t buffLength, int32_t buffCapacity);
/*
* Do not use #ifndef U_HIDE_DRAFT_API for the following constructor,
* it should always be available regardless of U_HIDE_DRAFT_API status
*/
#if !U_CHAR16_IS_TYPEDEF
/**
* Writable-aliasing uint16_t * constructor.
* Delegates to UnicodeString(const char16_t *, int32_t, int32_t).
* @param buffer writable buffer of/for UTF-16 text
* @param buffLength length of the current buffer contents
* @param buffCapacity buffer capacity
* @draft ICU 59
*/
UnicodeString(uint16_t *buffer, int32_t buffLength, int32_t buffCapacity) :
UnicodeString(Char16Ptr(buffer), buffLength, buffCapacity) {}
#endif
/*
* Do not use #ifndef U_HIDE_DRAFT_API for the following constructor,
* it should always be available regardless of U_HIDE_DRAFT_API status
*/
#if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
/**
* Writable-aliasing wchar_t * constructor.
* (Only defined if U_SIZEOF_WCHAR_T==2.)
* Delegates to UnicodeString(const char16_t *, int32_t, int32_t).
* @param buffer writable buffer of/for UTF-16 text
* @param buffLength length of the current buffer contents
* @param buffCapacity buffer capacity
* @draft ICU 59
*/
UnicodeString(wchar_t *buffer, int32_t buffLength, int32_t buffCapacity) :
UnicodeString(Char16Ptr(buffer), buffLength, buffCapacity) {}
#endif
/*
* Do not use #ifndef U_HIDE_DRAFT_API for the following constructor,
* it should always be available regardless of U_HIDE_DRAFT_API status
*/
/**
* Writable-aliasing nullptr_t constructor.
* Effectively the same as the default constructor, makes an empty string object.
* @param buffer nullptr
* @param buffLength ignored
* @param buffCapacity ignored
* @draft ICU 59
*/
inline UnicodeString(std::nullptr_t buffer, int32_t buffLength, int32_t buffCapacity);
#if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
/**
* char* constructor.
* Uses the default converter (and thus depends on the ICU conversion code)
* unless U_CHARSET_IS_UTF8 is set to 1.
*
* For ASCII (really "invariant character") strings it is more efficient to use
* the constructor that takes a US_INV (for its enum EInvariant).
* For ASCII (invariant-character) string literals, see UNICODE_STRING and
* UNICODE_STRING_SIMPLE.
*
* It is recommended to mark this constructor "explicit" by
* <code>-DUNISTR_FROM_STRING_EXPLICIT=explicit</code>
* on the compiler command line or similar.
* @param codepageData an array of bytes, null-terminated,
* in the platform's default codepage.
* @stable ICU 2.0
* @see UNICODE_STRING
* @see UNICODE_STRING_SIMPLE
*/
UNISTR_FROM_STRING_EXPLICIT UnicodeString(const char *codepageData);
/**
* char* constructor.
* Uses the default converter (and thus depends on the ICU conversion code)
* unless U_CHARSET_IS_UTF8 is set to 1.
* @param codepageData an array of bytes in the platform's default codepage.
* @param dataLength The number of bytes in <TT>codepageData</TT>.
* @stable ICU 2.0
*/
UnicodeString(const char *codepageData, int32_t dataLength);
#endif
#if !UCONFIG_NO_CONVERSION
/**
* char* constructor.
* @param codepageData an array of bytes, null-terminated
* @param codepage the encoding of <TT>codepageData</TT>. The special
* value 0 for <TT>codepage</TT> indicates that the text is in the
* platform's default codepage.
*
* If <code>codepage</code> is an empty string (<code>""</code>),
* then a simple conversion is performed on the codepage-invariant
* subset ("invariant characters") of the platform encoding. See utypes.h.
* Recommendation: For invariant-character strings use the constructor
* UnicodeString(const char *src, int32_t length, enum EInvariant inv)
* because it avoids object code dependencies of UnicodeString on
* the conversion code.
*
* @stable ICU 2.0
*/
UnicodeString(const char *codepageData, const char *codepage);
/**
* char* constructor.
* @param codepageData an array of bytes.
* @param dataLength The number of bytes in <TT>codepageData</TT>.
* @param codepage the encoding of <TT>codepageData</TT>. The special
* value 0 for <TT>codepage</TT> indicates that the text is in the
* platform's default codepage.
* If <code>codepage</code> is an empty string (<code>""</code>),
* then a simple conversion is performed on the codepage-invariant
* subset ("invariant characters") of the platform encoding. See utypes.h.
* Recommendation: For invariant-character strings use the constructor
* UnicodeString(const char *src, int32_t length, enum EInvariant inv)
* because it avoids object code dependencies of UnicodeString on
* the conversion code.
*
* @stable ICU 2.0
*/
UnicodeString(const char *codepageData, int32_t dataLength, const char *codepage);
/**
* char * / UConverter constructor.
* This constructor uses an existing UConverter object to
* convert the codepage string to Unicode and construct a UnicodeString
* from that.
*
* The converter is reset at first.
* If the error code indicates a failure before this constructor is called,
* or if an error occurs during conversion or construction,
* then the string will be bogus.
*
* This function avoids the overhead of opening and closing a converter if
* multiple strings are constructed.
*
* @param src input codepage string
* @param srcLength length of the input string, can be -1 for NUL-terminated strings
* @param cnv converter object (ucnv_resetToUnicode() will be called),
* can be NULL for the default converter
* @param errorCode normal ICU error code
* @stable ICU 2.0
*/
UnicodeString(
const char *src, int32_t srcLength,
UConverter *cnv,
UErrorCode &errorCode);
#endif
/**
* Constructs a Unicode string from an invariant-character char * string.
* About invariant characters see utypes.h.
* This constructor has no runtime dependency on conversion code and is
* therefore recommended over ones taking a charset name string
* (where the empty string "" indicates invariant-character conversion).
*
* Use the macro US_INV as the third, signature-distinguishing parameter.
*
* For example:
* \code
* void fn(const char *s) {
* UnicodeString ustr(s, -1, US_INV);
* // use ustr ...
* }
* \endcode
*
* @param src String using only invariant characters.
* @param length Length of src, or -1 if NUL-terminated.
* @param inv Signature-distinguishing paramater, use US_INV.
*
* @see US_INV
* @stable ICU 3.2
*/
UnicodeString(const char *src, int32_t length, enum EInvariant inv);
/**
* Copy constructor.
*
* Starting with ICU 2.4, the assignment operator and the copy constructor
* allocate a new buffer and copy the buffer contents even for readonly aliases.
* By contrast, the fastCopyFrom() function implements the old,
* more efficient but less safe behavior
* of making this string also a readonly alias to the same buffer.
*
* If the source object has an "open" buffer from getBuffer(minCapacity),
* then the copy is an empty string.
*
* @param that The UnicodeString object to copy.
* @stable ICU 2.0
* @see fastCopyFrom
*/
UnicodeString(const UnicodeString& that);
#if U_HAVE_RVALUE_REFERENCES
/**
* Move constructor, might leave src in bogus state.
* This string will have the same contents and state that the source string had.
* @param src source string
* @stable ICU 56
*/
UnicodeString(UnicodeString &&src) U_NOEXCEPT;
#endif
/**
* 'Substring' constructor from tail of source string.
* @param src The UnicodeString object to copy.
* @param srcStart The offset into <tt>src</tt> at which to start copying.
* @stable ICU 2.2
*/
UnicodeString(const UnicodeString& src, int32_t srcStart);
/**
* 'Substring' constructor from subrange of source string.
* @param src The UnicodeString object to copy.
* @param srcStart The offset into <tt>src</tt> at which to start copying.
* @param srcLength The number of characters from <tt>src</tt> to copy.
* @stable ICU 2.2
*/
UnicodeString(const UnicodeString& src, int32_t srcStart, int32_t srcLength);
/**
* Clone this object, an instance of a subclass of Replaceable.
* Clones can be used concurrently in multiple threads.
* If a subclass does not implement clone(), or if an error occurs,
* then NULL is returned.
* The clone functions in all subclasses return a pointer to a Replaceable
* because some compilers do not support covariant (same-as-this)
* return types; cast to the appropriate subclass if necessary.
* The caller must delete the clone.
*
* @return a clone of this object
*
* @see Replaceable::clone
* @see getDynamicClassID
* @stable ICU 2.6
*/
virtual Replaceable *clone() const;
/** Destructor.
* @stable ICU 2.0
*/
virtual ~UnicodeString();
/**
* Create a UnicodeString from a UTF-8 string.
* Illegal input is replaced with U+FFFD. Otherwise, errors result in a bogus string.
* Calls u_strFromUTF8WithSub().
*
* @param utf8 UTF-8 input string.
* Note that a StringPiece can be implicitly constructed
* from a std::string or a NUL-terminated const char * string.
* @return A UnicodeString with equivalent UTF-16 contents.
* @see toUTF8
* @see toUTF8String
* @stable ICU 4.2
*/
static UnicodeString fromUTF8(StringPiece utf8);
/**
* Create a UnicodeString from a UTF-32 string.
* Illegal input is replaced with U+FFFD. Otherwise, errors result in a bogus string.
* Calls u_strFromUTF32WithSub().
*
* @param utf32 UTF-32 input string. Must not be NULL.
* @param length Length of the input string, or -1 if NUL-terminated.
* @return A UnicodeString with equivalent UTF-16 contents.
* @see toUTF32
* @stable ICU 4.2
*/
static UnicodeString fromUTF32(const UChar32 *utf32, int32_t length);
/* Miscellaneous operations */
/**
* Unescape a string of characters and return a string containing
* the result. The following escape sequences are recognized:
*
* \\uhhhh 4 hex digits; h in [0-9A-Fa-f]
* \\Uhhhhhhhh 8 hex digits
* \\xhh 1-2 hex digits
* \\ooo 1-3 octal digits; o in [0-7]
* \\cX control-X; X is masked with 0x1F
*
* as well as the standard ANSI C escapes:
*
* \\a => U+0007, \\b => U+0008, \\t => U+0009, \\n => U+000A,
* \\v => U+000B, \\f => U+000C, \\r => U+000D, \\e => U+001B,
* \\" => U+0022, \\' => U+0027, \\? => U+003F, \\\\ => U+005C
*
* Anything else following a backslash is generically escaped. For
* example, "[a\\-z]" returns "[a-z]".
*
* If an escape sequence is ill-formed, this method returns an empty
* string. An example of an ill-formed sequence is "\\u" followed by
* fewer than 4 hex digits.
*
* This function is similar to u_unescape() but not identical to it.
* The latter takes a source char*, so it does escape recognition
* and also invariant conversion.
*
* @return a string with backslash escapes interpreted, or an
* empty string on error.
* @see UnicodeString#unescapeAt()
* @see u_unescape()
* @see u_unescapeAt()
* @stable ICU 2.0
*/
UnicodeString unescape() const;
/**
* Unescape a single escape sequence and return the represented
* character. See unescape() for a listing of the recognized escape
* sequences. The character at offset-1 is assumed (without
* checking) to be a backslash. If the escape sequence is
* ill-formed, or the offset is out of range, U_SENTINEL=-1 is
* returned.
*
* @param offset an input output parameter. On input, it is the
* offset into this string where the escape sequence is located,
* after the initial backslash. On output, it is advanced after the
* last character parsed. On error, it is not advanced at all.
* @return the character represented by the escape sequence at
* offset, or U_SENTINEL=-1 on error.
* @see UnicodeString#unescape()
* @see u_unescape()
* @see u_unescapeAt()
* @stable ICU 2.0
*/
UChar32 unescapeAt(int32_t &offset) const;
/**
* ICU "poor man's RTTI", returns a UClassID for this class.
*
* @stable ICU 2.2
*/
static UClassID U_EXPORT2 getStaticClassID();
/**
* ICU "poor man's RTTI", returns a UClassID for the actual class.
*
* @stable ICU 2.2
*/
virtual UClassID getDynamicClassID() const;
//========================================
// Implementation methods
//========================================
protected:
/**
* Implement Replaceable::getLength() (see jitterbug 1027).
* @stable ICU 2.4
*/
virtual int32_t getLength() const;
/**
* The change in Replaceable to use virtual getCharAt() allows
* UnicodeString::charAt() to be inline again (see jitterbug 709).
* @stable ICU 2.4
*/
virtual char16_t getCharAt(int32_t offset) const;
/**
* The change in Replaceable to use virtual getChar32At() allows
* UnicodeString::char32At() to be inline again (see jitterbug 709).
* @stable ICU 2.4
*/
virtual UChar32 getChar32At(int32_t offset) const;
private:
// For char* constructors. Could be made public.
UnicodeString &setToUTF8(StringPiece utf8);
// For extract(char*).
// We could make a toUTF8(target, capacity, errorCode) public but not
// this version: New API will be cleaner if we make callers create substrings
// rather than having start+length on every method,
// and it should take a UErrorCode&.
int32_t
toUTF8(int32_t start, int32_t len,
char *target, int32_t capacity) const;
/**
* Internal string contents comparison, called by operator==.
* Requires: this & text not bogus and have same lengths.
*/
UBool doEquals(const UnicodeString &text, int32_t len) const;
inline int8_t
doCompare(int32_t start,
int32_t length,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength) const;
int8_t doCompare(int32_t start,
int32_t length,
const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength) const;
inline int8_t
doCompareCodePointOrder(int32_t start,
int32_t length,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength) const;
int8_t doCompareCodePointOrder(int32_t start,
int32_t length,
const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength) const;
inline int8_t
doCaseCompare(int32_t start,
int32_t length,
const UnicodeString &srcText,
int32_t srcStart,
int32_t srcLength,
uint32_t options) const;
int8_t
doCaseCompare(int32_t start,
int32_t length,
const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength,
uint32_t options) const;
int32_t doIndexOf(char16_t c,
int32_t start,
int32_t length) const;
int32_t doIndexOf(UChar32 c,
int32_t start,
int32_t length) const;
int32_t doLastIndexOf(char16_t c,
int32_t start,
int32_t length) const;
int32_t doLastIndexOf(UChar32 c,
int32_t start,
int32_t length) const;
void doExtract(int32_t start,
int32_t length,
char16_t *dst,
int32_t dstStart) const;
inline void doExtract(int32_t start,
int32_t length,
UnicodeString& target) const;
inline char16_t doCharAt(int32_t offset) const;
UnicodeString& doReplace(int32_t start,
int32_t length,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength);
UnicodeString& doReplace(int32_t start,
int32_t length,
const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength);
UnicodeString& doAppend(const UnicodeString& src, int32_t srcStart, int32_t srcLength);
UnicodeString& doAppend(const char16_t *srcChars, int32_t srcStart, int32_t srcLength);
UnicodeString& doReverse(int32_t start,
int32_t length);
// calculate hash code
int32_t doHashCode(void) const;
// get pointer to start of array
// these do not check for kOpenGetBuffer, unlike the public getBuffer() function
inline char16_t* getArrayStart(void);
inline const char16_t* getArrayStart(void) const;
inline UBool hasShortLength() const;
inline int32_t getShortLength() const;
// A UnicodeString object (not necessarily its current buffer)
// is writable unless it isBogus() or it has an "open" getBuffer(minCapacity).
inline UBool isWritable() const;
// Is the current buffer writable?
inline UBool isBufferWritable() const;
// None of the following does releaseArray().
inline void setZeroLength();
inline void setShortLength(int32_t len);
inline void setLength(int32_t len);
inline void setToEmpty();
inline void setArray(char16_t *array, int32_t len, int32_t capacity); // sets length but not flags
// allocate the array; result may be the stack buffer
// sets refCount to 1 if appropriate
// sets fArray, fCapacity, and flags
// sets length to 0
// returns boolean for success or failure
UBool allocate(int32_t capacity);
// release the array if owned
void releaseArray(void);
// turn a bogus string into an empty one
void unBogus();
// implements assigment operator, copy constructor, and fastCopyFrom()
UnicodeString ©From(const UnicodeString &src, UBool fastCopy=FALSE);
// Copies just the fields without memory management.
void copyFieldsFrom(UnicodeString &src, UBool setSrcToBogus) U_NOEXCEPT;
// Pin start and limit to acceptable values.
inline void pinIndex(int32_t& start) const;
inline void pinIndices(int32_t& start,
int32_t& length) const;
#if !UCONFIG_NO_CONVERSION
/* Internal extract() using UConverter. */
int32_t doExtract(int32_t start, int32_t length,
char *dest, int32_t destCapacity,
UConverter *cnv,
UErrorCode &errorCode) const;
/*
* Real constructor for converting from codepage data.
* It assumes that it is called with !fRefCounted.
*
* If <code>codepage==0</code>, then the default converter
* is used for the platform encoding.
* If <code>codepage</code> is an empty string (<code>""</code>),
* then a simple conversion is performed on the codepage-invariant
* subset ("invariant characters") of the platform encoding. See utypes.h.
*/
void doCodepageCreate(const char *codepageData,
int32_t dataLength,
const char *codepage);
/*
* Worker function for creating a UnicodeString from
* a codepage string using a UConverter.
*/
void
doCodepageCreate(const char *codepageData,
int32_t dataLength,
UConverter *converter,
UErrorCode &status);
#endif
/*
* This function is called when write access to the array
* is necessary.
*
* We need to make a copy of the array if
* the buffer is read-only, or
* the buffer is refCounted (shared), and refCount>1, or
* the buffer is too small.
*
* Return FALSE if memory could not be allocated.
*/
UBool cloneArrayIfNeeded(int32_t newCapacity = -1,
int32_t growCapacity = -1,
UBool doCopyArray = TRUE,
int32_t **pBufferToDelete = 0,
UBool forceClone = FALSE);
/**
* Common function for UnicodeString case mappings.
* The stringCaseMapper has the same type UStringCaseMapper
* as in ustr_imp.h for ustrcase_map().
*/
UnicodeString &
caseMap(int32_t caseLocale, uint32_t options,
#if !UCONFIG_NO_BREAK_ITERATION
BreakIterator *iter,
#endif
UStringCaseMapper *stringCaseMapper);
// ref counting
void addRef(void);
int32_t removeRef(void);
int32_t refCount(void) const;
// constants
enum {
/**
* Size of stack buffer for short strings.
* Must be at least U16_MAX_LENGTH for the single-code point constructor to work.
* @see UNISTR_OBJECT_SIZE
*/
US_STACKBUF_SIZE=(int32_t)(UNISTR_OBJECT_SIZE-sizeof(void *)-2)/U_SIZEOF_UCHAR,
kInvalidUChar=0xffff, // U+FFFF returned by charAt(invalid index)
kInvalidHashCode=0, // invalid hash code
kEmptyHashCode=1, // hash code for empty string
// bit flag values for fLengthAndFlags
kIsBogus=1, // this string is bogus, i.e., not valid or NULL
kUsingStackBuffer=2,// using fUnion.fStackFields instead of fUnion.fFields
kRefCounted=4, // there is a refCount field before the characters in fArray
kBufferIsReadonly=8,// do not write to this buffer
kOpenGetBuffer=16, // getBuffer(minCapacity) was called (is "open"),
// and releaseBuffer(newLength) must be called
kAllStorageFlags=0x1f,
kLengthShift=5, // remaining 11 bits for non-negative short length, or negative if long
kLength1=1<<kLengthShift,
kMaxShortLength=0x3ff, // max non-negative short length (leaves top bit 0)
kLengthIsLarge=0xffe0, // short length < 0, real length is in fUnion.fFields.fLength
// combined values for convenience
kShortString=kUsingStackBuffer,
kLongString=kRefCounted,
kReadonlyAlias=kBufferIsReadonly,
kWritableAlias=0
};
friend class UnicodeStringAppendable;
union StackBufferOrFields; // forward declaration necessary before friend declaration
friend union StackBufferOrFields; // make US_STACKBUF_SIZE visible inside fUnion
/*
* The following are all the class fields that are stored
* in each UnicodeString object.
* Note that UnicodeString has virtual functions,
* therefore there is an implicit vtable pointer
* as the first real field.
* The fields should be aligned such that no padding is necessary.
* On 32-bit machines, the size should be 32 bytes,
* on 64-bit machines (8-byte pointers), it should be 40 bytes.
*
* We use a hack to achieve this.
*
* With at least some compilers, each of the following is forced to
* a multiple of sizeof(pointer) [the largest field base unit here is a data pointer],
* rounded up with additional padding if the fields do not already fit that requirement:
* - sizeof(class UnicodeString)
* - offsetof(UnicodeString, fUnion)
* - sizeof(fUnion)
* - sizeof(fStackFields)
*
* We optimize for the longest possible internal buffer for short strings.
* fUnion.fStackFields begins with 2 bytes for storage flags
* and the length of relatively short strings,
* followed by the buffer for short string contents.
* There is no padding inside fStackFields.
*
* Heap-allocated and aliased strings use fUnion.fFields.
* Both fStackFields and fFields must begin with the same fields for flags and short length,
* that is, those must have the same memory offsets inside the object,
* because the flags must be inspected in order to decide which half of fUnion is being used.
* We assume that the compiler does not reorder the fields.
*
* (Padding at the end of fFields is ok:
* As long as it is no larger than fStackFields, it is not wasted space.)
*
* For some of the history of the UnicodeString class fields layout, see
* - ICU ticket #11551 "longer UnicodeString contents in stack buffer"
* - ICU ticket #11336 "UnicodeString: recombine stack buffer arrays"
* - ICU ticket #8322 "why is sizeof(UnicodeString)==48?"
*/
// (implicit) *vtable;
union StackBufferOrFields {
// fStackFields is used iff (fLengthAndFlags&kUsingStackBuffer) else fFields is used.
// Each struct of the union must begin with fLengthAndFlags.
struct {
int16_t fLengthAndFlags; // bit fields: see constants above
char16_t fBuffer[US_STACKBUF_SIZE]; // buffer for short strings
} fStackFields;
struct {
int16_t fLengthAndFlags; // bit fields: see constants above
int32_t fLength; // number of characters in fArray if >127; else undefined
int32_t fCapacity; // capacity of fArray (in char16_ts)
// array pointer last to minimize padding for machines with P128 data model
// or pointer sizes that are not a power of 2
char16_t *fArray; // the Unicode data
} fFields;
} fUnion;
};
/**
* Create a new UnicodeString with the concatenation of two others.
*
* @param s1 The first string to be copied to the new one.
* @param s2 The second string to be copied to the new one, after s1.
* @return UnicodeString(s1).append(s2)
* @stable ICU 2.8
*/
U_COMMON_API UnicodeString U_EXPORT2
operator+ (const UnicodeString &s1, const UnicodeString &s2);
//========================================
// Inline members
//========================================
//========================================
// Privates
//========================================
inline void
UnicodeString::pinIndex(int32_t& start) const
{
// pin index
if(start < 0) {
start = 0;
} else if(start > length()) {
start = length();
}
}
inline void
UnicodeString::pinIndices(int32_t& start,
int32_t& _length) const
{
// pin indices
int32_t len = length();
if(start < 0) {
start = 0;
} else if(start > len) {
start = len;
}
if(_length < 0) {
_length = 0;
} else if(_length > (len - start)) {
_length = (len - start);
}
}
inline char16_t*
UnicodeString::getArrayStart() {
return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
}
inline const char16_t*
UnicodeString::getArrayStart() const {
return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
}
//========================================
// Default constructor
//========================================
inline
UnicodeString::UnicodeString() {
fUnion.fStackFields.fLengthAndFlags=kShortString;
}
inline UnicodeString::UnicodeString(const std::nullptr_t /*text*/) {
fUnion.fStackFields.fLengthAndFlags=kShortString;
}
inline UnicodeString::UnicodeString(const std::nullptr_t /*text*/, int32_t /*length*/) {
fUnion.fStackFields.fLengthAndFlags=kShortString;
}
inline UnicodeString::UnicodeString(std::nullptr_t /*buffer*/, int32_t /*buffLength*/, int32_t /*buffCapacity*/) {
fUnion.fStackFields.fLengthAndFlags=kShortString;
}
//========================================
// Read-only implementation methods
//========================================
inline UBool
UnicodeString::hasShortLength() const {
return fUnion.fFields.fLengthAndFlags>=0;
}
inline int32_t
UnicodeString::getShortLength() const {
// fLengthAndFlags must be non-negative -> short length >= 0
// and arithmetic or logical shift does not matter.
return fUnion.fFields.fLengthAndFlags>>kLengthShift;
}
inline int32_t
UnicodeString::length() const {
return hasShortLength() ? getShortLength() : fUnion.fFields.fLength;
}
inline int32_t
UnicodeString::getCapacity() const {
return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
US_STACKBUF_SIZE : fUnion.fFields.fCapacity;
}
inline int32_t
UnicodeString::hashCode() const
{ return doHashCode(); }
inline UBool
UnicodeString::isBogus() const
{ return (UBool)(fUnion.fFields.fLengthAndFlags & kIsBogus); }
inline UBool
UnicodeString::isWritable() const
{ return (UBool)!(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus)); }
inline UBool
UnicodeString::isBufferWritable() const
{
return (UBool)(
!(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus|kBufferIsReadonly)) &&
(!(fUnion.fFields.fLengthAndFlags&kRefCounted) || refCount()==1));
}
inline const char16_t *
UnicodeString::getBuffer() const {
if(fUnion.fFields.fLengthAndFlags&(kIsBogus|kOpenGetBuffer)) {
return nullptr;
} else if(fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) {
return fUnion.fStackFields.fBuffer;
} else {
return fUnion.fFields.fArray;
}
}
//========================================
// Read-only alias methods
//========================================
inline int8_t
UnicodeString::doCompare(int32_t start,
int32_t thisLength,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength) const
{
if(srcText.isBogus()) {
return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
} else {
srcText.pinIndices(srcStart, srcLength);
return doCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
}
}
inline UBool
UnicodeString::operator== (const UnicodeString& text) const
{
if(isBogus()) {
return text.isBogus();
} else {
int32_t len = length(), textLength = text.length();
return !text.isBogus() && len == textLength && doEquals(text, len);
}
}
inline UBool
UnicodeString::operator!= (const UnicodeString& text) const
{ return (! operator==(text)); }
inline UBool
UnicodeString::operator> (const UnicodeString& text) const
{ return doCompare(0, length(), text, 0, text.length()) == 1; }
inline UBool
UnicodeString::operator< (const UnicodeString& text) const
{ return doCompare(0, length(), text, 0, text.length()) == -1; }
inline UBool
UnicodeString::operator>= (const UnicodeString& text) const
{ return doCompare(0, length(), text, 0, text.length()) != -1; }
inline UBool
UnicodeString::operator<= (const UnicodeString& text) const
{ return doCompare(0, length(), text, 0, text.length()) != 1; }
inline int8_t
UnicodeString::compare(const UnicodeString& text) const
{ return doCompare(0, length(), text, 0, text.length()); }
inline int8_t
UnicodeString::compare(int32_t start,
int32_t _length,
const UnicodeString& srcText) const
{ return doCompare(start, _length, srcText, 0, srcText.length()); }
inline int8_t
UnicodeString::compare(ConstChar16Ptr srcChars,
int32_t srcLength) const
{ return doCompare(0, length(), srcChars, 0, srcLength); }
inline int8_t
UnicodeString::compare(int32_t start,
int32_t _length,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength) const
{ return doCompare(start, _length, srcText, srcStart, srcLength); }
inline int8_t
UnicodeString::compare(int32_t start,
int32_t _length,
const char16_t *srcChars) const
{ return doCompare(start, _length, srcChars, 0, _length); }
inline int8_t
UnicodeString::compare(int32_t start,
int32_t _length,
const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength) const
{ return doCompare(start, _length, srcChars, srcStart, srcLength); }
inline int8_t
UnicodeString::compareBetween(int32_t start,
int32_t limit,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLimit) const
{ return doCompare(start, limit - start,
srcText, srcStart, srcLimit - srcStart); }
inline int8_t
UnicodeString::doCompareCodePointOrder(int32_t start,
int32_t thisLength,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength) const
{
if(srcText.isBogus()) {
return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
} else {
srcText.pinIndices(srcStart, srcLength);
return doCompareCodePointOrder(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
}
}
inline int8_t
UnicodeString::compareCodePointOrder(const UnicodeString& text) const
{ return doCompareCodePointOrder(0, length(), text, 0, text.length()); }
inline int8_t
UnicodeString::compareCodePointOrder(int32_t start,
int32_t _length,
const UnicodeString& srcText) const
{ return doCompareCodePointOrder(start, _length, srcText, 0, srcText.length()); }
inline int8_t
UnicodeString::compareCodePointOrder(ConstChar16Ptr srcChars,
int32_t srcLength) const
{ return doCompareCodePointOrder(0, length(), srcChars, 0, srcLength); }
inline int8_t
UnicodeString::compareCodePointOrder(int32_t start,
int32_t _length,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength) const
{ return doCompareCodePointOrder(start, _length, srcText, srcStart, srcLength); }
inline int8_t
UnicodeString::compareCodePointOrder(int32_t start,
int32_t _length,
const char16_t *srcChars) const
{ return doCompareCodePointOrder(start, _length, srcChars, 0, _length); }
inline int8_t
UnicodeString::compareCodePointOrder(int32_t start,
int32_t _length,
const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength) const
{ return doCompareCodePointOrder(start, _length, srcChars, srcStart, srcLength); }
inline int8_t
UnicodeString::compareCodePointOrderBetween(int32_t start,
int32_t limit,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLimit) const
{ return doCompareCodePointOrder(start, limit - start,
srcText, srcStart, srcLimit - srcStart); }
inline int8_t
UnicodeString::doCaseCompare(int32_t start,
int32_t thisLength,
const UnicodeString &srcText,
int32_t srcStart,
int32_t srcLength,
uint32_t options) const
{
if(srcText.isBogus()) {
return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
} else {
srcText.pinIndices(srcStart, srcLength);
return doCaseCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength, options);
}
}
inline int8_t
UnicodeString::caseCompare(const UnicodeString &text, uint32_t options) const {
return doCaseCompare(0, length(), text, 0, text.length(), options);
}
inline int8_t
UnicodeString::caseCompare(int32_t start,
int32_t _length,
const UnicodeString &srcText,
uint32_t options) const {
return doCaseCompare(start, _length, srcText, 0, srcText.length(), options);
}
inline int8_t
UnicodeString::caseCompare(ConstChar16Ptr srcChars,
int32_t srcLength,
uint32_t options) const {
return doCaseCompare(0, length(), srcChars, 0, srcLength, options);
}
inline int8_t
UnicodeString::caseCompare(int32_t start,
int32_t _length,
const UnicodeString &srcText,
int32_t srcStart,
int32_t srcLength,
uint32_t options) const {
return doCaseCompare(start, _length, srcText, srcStart, srcLength, options);
}
inline int8_t
UnicodeString::caseCompare(int32_t start,
int32_t _length,
const char16_t *srcChars,
uint32_t options) const {
return doCaseCompare(start, _length, srcChars, 0, _length, options);
}
inline int8_t
UnicodeString::caseCompare(int32_t start,
int32_t _length,
const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength,
uint32_t options) const {
return doCaseCompare(start, _length, srcChars, srcStart, srcLength, options);
}
inline int8_t
UnicodeString::caseCompareBetween(int32_t start,
int32_t limit,
const UnicodeString &srcText,
int32_t srcStart,
int32_t srcLimit,
uint32_t options) const {
return doCaseCompare(start, limit - start, srcText, srcStart, srcLimit - srcStart, options);
}
inline int32_t
UnicodeString::indexOf(const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength,
int32_t start,
int32_t _length) const
{
if(!srcText.isBogus()) {
srcText.pinIndices(srcStart, srcLength);
if(srcLength > 0) {
return indexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
}
}
return -1;
}
inline int32_t
UnicodeString::indexOf(const UnicodeString& text) const
{ return indexOf(text, 0, text.length(), 0, length()); }
inline int32_t
UnicodeString::indexOf(const UnicodeString& text,
int32_t start) const {
pinIndex(start);
return indexOf(text, 0, text.length(), start, length() - start);
}
inline int32_t
UnicodeString::indexOf(const UnicodeString& text,
int32_t start,
int32_t _length) const
{ return indexOf(text, 0, text.length(), start, _length); }
inline int32_t
UnicodeString::indexOf(const char16_t *srcChars,
int32_t srcLength,
int32_t start) const {
pinIndex(start);
return indexOf(srcChars, 0, srcLength, start, length() - start);
}
inline int32_t
UnicodeString::indexOf(ConstChar16Ptr srcChars,
int32_t srcLength,
int32_t start,
int32_t _length) const
{ return indexOf(srcChars, 0, srcLength, start, _length); }
inline int32_t
UnicodeString::indexOf(char16_t c,
int32_t start,
int32_t _length) const
{ return doIndexOf(c, start, _length); }
inline int32_t
UnicodeString::indexOf(UChar32 c,
int32_t start,
int32_t _length) const
{ return doIndexOf(c, start, _length); }
inline int32_t
UnicodeString::indexOf(char16_t c) const
{ return doIndexOf(c, 0, length()); }
inline int32_t
UnicodeString::indexOf(UChar32 c) const
{ return indexOf(c, 0, length()); }
inline int32_t
UnicodeString::indexOf(char16_t c,
int32_t start) const {
pinIndex(start);
return doIndexOf(c, start, length() - start);
}
inline int32_t
UnicodeString::indexOf(UChar32 c,
int32_t start) const {
pinIndex(start);
return indexOf(c, start, length() - start);
}
inline int32_t
UnicodeString::lastIndexOf(ConstChar16Ptr srcChars,
int32_t srcLength,
int32_t start,
int32_t _length) const
{ return lastIndexOf(srcChars, 0, srcLength, start, _length); }
inline int32_t
UnicodeString::lastIndexOf(const char16_t *srcChars,
int32_t srcLength,
int32_t start) const {
pinIndex(start);
return lastIndexOf(srcChars, 0, srcLength, start, length() - start);
}
inline int32_t
UnicodeString::lastIndexOf(const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength,
int32_t start,
int32_t _length) const
{
if(!srcText.isBogus()) {
srcText.pinIndices(srcStart, srcLength);
if(srcLength > 0) {
return lastIndexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
}
}
return -1;
}
inline int32_t
UnicodeString::lastIndexOf(const UnicodeString& text,
int32_t start,
int32_t _length) const
{ return lastIndexOf(text, 0, text.length(), start, _length); }
inline int32_t
UnicodeString::lastIndexOf(const UnicodeString& text,
int32_t start) const {
pinIndex(start);
return lastIndexOf(text, 0, text.length(), start, length() - start);
}
inline int32_t
UnicodeString::lastIndexOf(const UnicodeString& text) const
{ return lastIndexOf(text, 0, text.length(), 0, length()); }
inline int32_t
UnicodeString::lastIndexOf(char16_t c,
int32_t start,
int32_t _length) const
{ return doLastIndexOf(c, start, _length); }
inline int32_t
UnicodeString::lastIndexOf(UChar32 c,
int32_t start,
int32_t _length) const {
return doLastIndexOf(c, start, _length);
}
inline int32_t
UnicodeString::lastIndexOf(char16_t c) const
{ return doLastIndexOf(c, 0, length()); }
inline int32_t
UnicodeString::lastIndexOf(UChar32 c) const {
return lastIndexOf(c, 0, length());
}
inline int32_t
UnicodeString::lastIndexOf(char16_t c,
int32_t start) const {
pinIndex(start);
return doLastIndexOf(c, start, length() - start);
}
inline int32_t
UnicodeString::lastIndexOf(UChar32 c,
int32_t start) const {
pinIndex(start);
return lastIndexOf(c, start, length() - start);
}
inline UBool
UnicodeString::startsWith(const UnicodeString& text) const
{ return compare(0, text.length(), text, 0, text.length()) == 0; }
inline UBool
UnicodeString::startsWith(const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength) const
{ return doCompare(0, srcLength, srcText, srcStart, srcLength) == 0; }
inline UBool
UnicodeString::startsWith(ConstChar16Ptr srcChars, int32_t srcLength) const {
if(srcLength < 0) {
srcLength = u_strlen(toUCharPtr(srcChars));
}
return doCompare(0, srcLength, srcChars, 0, srcLength) == 0;
}
inline UBool
UnicodeString::startsWith(const char16_t *srcChars, int32_t srcStart, int32_t srcLength) const {
if(srcLength < 0) {
srcLength = u_strlen(toUCharPtr(srcChars));
}
return doCompare(0, srcLength, srcChars, srcStart, srcLength) == 0;
}
inline UBool
UnicodeString::endsWith(const UnicodeString& text) const
{ return doCompare(length() - text.length(), text.length(),
text, 0, text.length()) == 0; }
inline UBool
UnicodeString::endsWith(const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength) const {
srcText.pinIndices(srcStart, srcLength);
return doCompare(length() - srcLength, srcLength,
srcText, srcStart, srcLength) == 0;
}
inline UBool
UnicodeString::endsWith(ConstChar16Ptr srcChars,
int32_t srcLength) const {
if(srcLength < 0) {
srcLength = u_strlen(toUCharPtr(srcChars));
}
return doCompare(length() - srcLength, srcLength,
srcChars, 0, srcLength) == 0;
}
inline UBool
UnicodeString::endsWith(const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength) const {
if(srcLength < 0) {
srcLength = u_strlen(toUCharPtr(srcChars + srcStart));
}
return doCompare(length() - srcLength, srcLength,
srcChars, srcStart, srcLength) == 0;
}
//========================================
// replace
//========================================
inline UnicodeString&
UnicodeString::replace(int32_t start,
int32_t _length,
const UnicodeString& srcText)
{ return doReplace(start, _length, srcText, 0, srcText.length()); }
inline UnicodeString&
UnicodeString::replace(int32_t start,
int32_t _length,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength)
{ return doReplace(start, _length, srcText, srcStart, srcLength); }
inline UnicodeString&
UnicodeString::replace(int32_t start,
int32_t _length,
ConstChar16Ptr srcChars,
int32_t srcLength)
{ return doReplace(start, _length, srcChars, 0, srcLength); }
inline UnicodeString&
UnicodeString::replace(int32_t start,
int32_t _length,
const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength)
{ return doReplace(start, _length, srcChars, srcStart, srcLength); }
inline UnicodeString&
UnicodeString::replace(int32_t start,
int32_t _length,
char16_t srcChar)
{ return doReplace(start, _length, &srcChar, 0, 1); }
inline UnicodeString&
UnicodeString::replaceBetween(int32_t start,
int32_t limit,
const UnicodeString& srcText)
{ return doReplace(start, limit - start, srcText, 0, srcText.length()); }
inline UnicodeString&
UnicodeString::replaceBetween(int32_t start,
int32_t limit,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLimit)
{ return doReplace(start, limit - start, srcText, srcStart, srcLimit - srcStart); }
inline UnicodeString&
UnicodeString::findAndReplace(const UnicodeString& oldText,
const UnicodeString& newText)
{ return findAndReplace(0, length(), oldText, 0, oldText.length(),
newText, 0, newText.length()); }
inline UnicodeString&
UnicodeString::findAndReplace(int32_t start,
int32_t _length,
const UnicodeString& oldText,
const UnicodeString& newText)
{ return findAndReplace(start, _length, oldText, 0, oldText.length(),
newText, 0, newText.length()); }
// ============================
// extract
// ============================
inline void
UnicodeString::doExtract(int32_t start,
int32_t _length,
UnicodeString& target) const
{ target.replace(0, target.length(), *this, start, _length); }
inline void
UnicodeString::extract(int32_t start,
int32_t _length,
Char16Ptr target,
int32_t targetStart) const
{ doExtract(start, _length, target, targetStart); }
inline void
UnicodeString::extract(int32_t start,
int32_t _length,
UnicodeString& target) const
{ doExtract(start, _length, target); }
#if !UCONFIG_NO_CONVERSION
inline int32_t
UnicodeString::extract(int32_t start,
int32_t _length,
char *dst,
const char *codepage) const
{
// This dstSize value will be checked explicitly
return extract(start, _length, dst, dst!=0 ? 0xffffffff : 0, codepage);
}
#endif
inline void
UnicodeString::extractBetween(int32_t start,
int32_t limit,
char16_t *dst,
int32_t dstStart) const {
pinIndex(start);
pinIndex(limit);
doExtract(start, limit - start, dst, dstStart);
}
inline UnicodeString
UnicodeString::tempSubStringBetween(int32_t start, int32_t limit) const {
return tempSubString(start, limit - start);
}
inline char16_t
UnicodeString::doCharAt(int32_t offset) const
{
if((uint32_t)offset < (uint32_t)length()) {
return getArrayStart()[offset];
} else {
return kInvalidUChar;
}
}
inline char16_t
UnicodeString::charAt(int32_t offset) const
{ return doCharAt(offset); }
inline char16_t
UnicodeString::operator[] (int32_t offset) const
{ return doCharAt(offset); }
inline UBool
UnicodeString::isEmpty() const {
// Arithmetic or logical right shift does not matter: only testing for 0.
return (fUnion.fFields.fLengthAndFlags>>kLengthShift) == 0;
}
//========================================
// Write implementation methods
//========================================
inline void
UnicodeString::setZeroLength() {
fUnion.fFields.fLengthAndFlags &= kAllStorageFlags;
}
inline void
UnicodeString::setShortLength(int32_t len) {
// requires 0 <= len <= kMaxShortLength
fUnion.fFields.fLengthAndFlags =
(int16_t)((fUnion.fFields.fLengthAndFlags & kAllStorageFlags) | (len << kLengthShift));
}
inline void
UnicodeString::setLength(int32_t len) {
if(len <= kMaxShortLength) {
setShortLength(len);
} else {
fUnion.fFields.fLengthAndFlags |= kLengthIsLarge;
fUnion.fFields.fLength = len;
}
}
inline void
UnicodeString::setToEmpty() {
fUnion.fFields.fLengthAndFlags = kShortString;
}
inline void
UnicodeString::setArray(char16_t *array, int32_t len, int32_t capacity) {
setLength(len);
fUnion.fFields.fArray = array;
fUnion.fFields.fCapacity = capacity;
}
inline UnicodeString&
UnicodeString::operator= (char16_t ch)
{ return doReplace(0, length(), &ch, 0, 1); }
inline UnicodeString&
UnicodeString::operator= (UChar32 ch)
{ return replace(0, length(), ch); }
inline UnicodeString&
UnicodeString::setTo(const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength)
{
unBogus();
return doReplace(0, length(), srcText, srcStart, srcLength);
}
inline UnicodeString&
UnicodeString::setTo(const UnicodeString& srcText,
int32_t srcStart)
{
unBogus();
srcText.pinIndex(srcStart);
return doReplace(0, length(), srcText, srcStart, srcText.length() - srcStart);
}
inline UnicodeString&
UnicodeString::setTo(const UnicodeString& srcText)
{
return copyFrom(srcText);
}
inline UnicodeString&
UnicodeString::setTo(const char16_t *srcChars,
int32_t srcLength)
{
unBogus();
return doReplace(0, length(), srcChars, 0, srcLength);
}
inline UnicodeString&
UnicodeString::setTo(char16_t srcChar)
{
unBogus();
return doReplace(0, length(), &srcChar, 0, 1);
}
inline UnicodeString&
UnicodeString::setTo(UChar32 srcChar)
{
unBogus();
return replace(0, length(), srcChar);
}
inline UnicodeString&
UnicodeString::append(const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength)
{ return doAppend(srcText, srcStart, srcLength); }
inline UnicodeString&
UnicodeString::append(const UnicodeString& srcText)
{ return doAppend(srcText, 0, srcText.length()); }
inline UnicodeString&
UnicodeString::append(const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength)
{ return doAppend(srcChars, srcStart, srcLength); }
inline UnicodeString&
UnicodeString::append(ConstChar16Ptr srcChars,
int32_t srcLength)
{ return doAppend(srcChars, 0, srcLength); }
inline UnicodeString&
UnicodeString::append(char16_t srcChar)
{ return doAppend(&srcChar, 0, 1); }
inline UnicodeString&
UnicodeString::operator+= (char16_t ch)
{ return doAppend(&ch, 0, 1); }
inline UnicodeString&
UnicodeString::operator+= (UChar32 ch) {
return append(ch);
}
inline UnicodeString&
UnicodeString::operator+= (const UnicodeString& srcText)
{ return doAppend(srcText, 0, srcText.length()); }
inline UnicodeString&
UnicodeString::insert(int32_t start,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength)
{ return doReplace(start, 0, srcText, srcStart, srcLength); }
inline UnicodeString&
UnicodeString::insert(int32_t start,
const UnicodeString& srcText)
{ return doReplace(start, 0, srcText, 0, srcText.length()); }
inline UnicodeString&
UnicodeString::insert(int32_t start,
const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength)
{ return doReplace(start, 0, srcChars, srcStart, srcLength); }
inline UnicodeString&
UnicodeString::insert(int32_t start,
ConstChar16Ptr srcChars,
int32_t srcLength)
{ return doReplace(start, 0, srcChars, 0, srcLength); }
inline UnicodeString&
UnicodeString::insert(int32_t start,
char16_t srcChar)
{ return doReplace(start, 0, &srcChar, 0, 1); }
inline UnicodeString&
UnicodeString::insert(int32_t start,
UChar32 srcChar)
{ return replace(start, 0, srcChar); }
inline UnicodeString&
UnicodeString::remove()
{
// remove() of a bogus string makes the string empty and non-bogus
if(isBogus()) {
setToEmpty();
} else {
setZeroLength();
}
return *this;
}
inline UnicodeString&
UnicodeString::remove(int32_t start,
int32_t _length)
{
if(start <= 0 && _length == INT32_MAX) {
// remove(guaranteed everything) of a bogus string makes the string empty and non-bogus
return remove();
}
return doReplace(start, _length, NULL, 0, 0);
}
inline UnicodeString&
UnicodeString::removeBetween(int32_t start,
int32_t limit)
{ return doReplace(start, limit - start, NULL, 0, 0); }
inline UnicodeString &
UnicodeString::retainBetween(int32_t start, int32_t limit) {
truncate(limit);
return doReplace(0, start, NULL, 0, 0);
}
inline UBool
UnicodeString::truncate(int32_t targetLength)
{
if(isBogus() && targetLength == 0) {
// truncate(0) of a bogus string makes the string empty and non-bogus
unBogus();
return FALSE;
} else if((uint32_t)targetLength < (uint32_t)length()) {
setLength(targetLength);
return TRUE;
} else {
return FALSE;
}
}
inline UnicodeString&
UnicodeString::reverse()
{ return doReverse(0, length()); }
inline UnicodeString&
UnicodeString::reverse(int32_t start,
int32_t _length)
{ return doReverse(start, _length); }
U_NAMESPACE_END
#endif
|