ICU 64.2 64.2

unistr.h
Go to the documentation of this file.
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 **********************************************************************
5 * Copyright (C) 1998-2016, International Business Machines
6 * Corporation and others. All Rights Reserved.
7 **********************************************************************
8 *
9 * File unistr.h
10 *
11 * Modification History:
12 *
13 * Date Name Description
14 * 09/25/98 stephen Creation.
15 * 11/11/98 stephen Changed per 11/9 code review.
16 * 04/20/99 stephen Overhauled per 4/16 code review.
17 * 11/18/99 aliu Made to inherit from Replaceable. Added method
18 * handleReplaceBetween(); other methods unchanged.
19 * 06/25/01 grhoten Remove dependency on iostream.
20 ******************************************************************************
21 */
22
23 #ifndef UNISTR_H
24 #define UNISTR_H
25
31 #include <cstddef>
32 #include "unicode/utypes.h"
33 #include "unicode/char16ptr.h"
34 #include "unicode/rep.h"
35 #include "unicode/std_string.h"
36 #include "unicode/stringpiece.h"
37 #include "unicode/bytestream.h"
38
39 struct UConverter; // unicode/ucnv.h
40
41 #ifndef USTRING_H
42
45 U_STABLE int32_t U_EXPORT2
46 u_strlen(const UChar *s);
47 #endif
48
49 U_NAMESPACE_BEGIN
50
51 #if !UCONFIG_NO_BREAK_ITERATION
52 class BreakIterator; // unicode/brkiter.h
53 #endif
54 class Edits;
55
56 U_NAMESPACE_END
57
58 // Not #ifndef U_HIDE_INTERNAL_API because UnicodeString needs the UStringCaseMapper.
65 typedef int32_t U_CALLCONV
66 UStringCaseMapper(int32_t caseLocale, uint32_t options,
67 #if !UCONFIG_NO_BREAK_ITERATION
68 icu::BreakIterator *iter,
69 #endif
70 char16_t *dest, int32_t destCapacity,
71 const char16_t *src, int32_t srcLength,
72 icu::Edits *edits,
73 UErrorCode &errorCode);
74
75 U_NAMESPACE_BEGIN
76
77 class Locale; // unicode/locid.h
78 class StringCharacterIterator;
79 class UnicodeStringAppendable; // unicode/appendable.h
80
81 /* The <iostream> include has been moved to unicode/ustream.h */
82
93 #define US_INV icu::UnicodeString::kInvariant
94
112 #if !U_CHAR16_IS_TYPEDEF
113 # define UNICODE_STRING(cs, _length) icu::UnicodeString(TRUE, u ## cs, _length)
114 #else
115 # define UNICODE_STRING(cs, _length) icu::UnicodeString(TRUE, (const char16_t*)u ## cs, _length)
116 #endif
117
131 #define UNICODE_STRING_SIMPLE(cs) UNICODE_STRING(cs, -1)
132
140 #ifndef UNISTR_FROM_CHAR_EXPLICIT
141 # if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION)
142 // Auto-"explicit" in ICU library code.
143 # define UNISTR_FROM_CHAR_EXPLICIT explicit
144 # else
145 // Empty by default for source code compatibility.
146 # define UNISTR_FROM_CHAR_EXPLICIT
147 # endif
148 #endif
149
160 #ifndef UNISTR_FROM_STRING_EXPLICIT
161 # if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION)
162 // Auto-"explicit" in ICU library code.
163 # define UNISTR_FROM_STRING_EXPLICIT explicit
164 # else
165 // Empty by default for source code compatibility.
166 # define UNISTR_FROM_STRING_EXPLICIT
167 # endif
168 #endif
169
203 #ifndef UNISTR_OBJECT_SIZE
204 # define UNISTR_OBJECT_SIZE 64
205 #endif
206
289 class U_COMMON_API UnicodeString : public Replaceable
290 {
291 public:
292
301 enum EInvariant {
306 kInvariant
307 };
308
309 //========================================
310 // Read-only operations
311 //========================================
312
313 /* Comparison - bitwise only - for international comparison use collation */
314
322 inline UBool operator== (const UnicodeString& text) const;
323
331 inline UBool operator!= (const UnicodeString& text) const;
332
340 inline UBool operator> (const UnicodeString& text) const;
341
349 inline UBool operator< (const UnicodeString& text) const;
350
358 inline UBool operator>= (const UnicodeString& text) const;
359
367 inline UBool operator<= (const UnicodeString& text) const;
368
380 inline int8_t compare(const UnicodeString& text) const;
381
397 inline int8_t compare(int32_t start,
398 int32_t length,
399 const UnicodeString& text) const;
400
418 inline int8_t compare(int32_t start,
419 int32_t length,
420 const UnicodeString& srcText,
421 int32_t srcStart,
422 int32_t srcLength) const;
423
436 inline int8_t compare(ConstChar16Ptr srcChars,
437 int32_t srcLength) const;
438
453 inline int8_t compare(int32_t start,
454 int32_t length,
455 const char16_t *srcChars) const;
456
474 inline int8_t compare(int32_t start,
475 int32_t length,
476 const char16_t *srcChars,
477 int32_t srcStart,
478 int32_t srcLength) const;
479
497 inline int8_t compareBetween(int32_t start,
498 int32_t limit,
499 const UnicodeString& srcText,
500 int32_t srcStart,
501 int32_t srcLimit) const;
502
520 inline int8_t compareCodePointOrder(const UnicodeString& text) const;
521
541 inline int8_t compareCodePointOrder(int32_t start,
542 int32_t length,
543 const UnicodeString& srcText) const;
544
566 inline int8_t compareCodePointOrder(int32_t start,
567 int32_t length,
568 const UnicodeString& srcText,
569 int32_t srcStart,
570 int32_t srcLength) const;
571
590 inline int8_t compareCodePointOrder(ConstChar16Ptr srcChars,
591 int32_t srcLength) const;
592
612 inline int8_t compareCodePointOrder(int32_t start,
613 int32_t length,
614 const char16_t *srcChars) const;
615
637 inline int8_t compareCodePointOrder(int32_t start,
638 int32_t length,
639 const char16_t *srcChars,
640 int32_t srcStart,
641 int32_t srcLength) const;
642
664 inline int8_t compareCodePointOrderBetween(int32_t start,
665 int32_t limit,
666 const UnicodeString& srcText,
667 int32_t srcStart,
668 int32_t srcLimit) const;
669
688 inline int8_t caseCompare(const UnicodeString& text, uint32_t options) const;
689
710 inline int8_t caseCompare(int32_t start,
711 int32_t length,
712 const UnicodeString& srcText,
713 uint32_t options) const;
714
737 inline int8_t caseCompare(int32_t start,
738 int32_t length,
739 const UnicodeString& srcText,
740 int32_t srcStart,
741 int32_t srcLength,
742 uint32_t options) const;
743
763 inline int8_t caseCompare(ConstChar16Ptr srcChars,
764 int32_t srcLength,
765 uint32_t options) const;
766
787 inline int8_t caseCompare(int32_t start,
788 int32_t length,
789 const char16_t *srcChars,
790 uint32_t options) const;
791
814 inline int8_t caseCompare(int32_t start,
815 int32_t length,
816 const char16_t *srcChars,
817 int32_t srcStart,
818 int32_t srcLength,
819 uint32_t options) const;
820
843 inline int8_t caseCompareBetween(int32_t start,
844 int32_t limit,
845 const UnicodeString& srcText,
846 int32_t srcStart,
847 int32_t srcLimit,
848 uint32_t options) const;
849
857 inline UBool startsWith(const UnicodeString& text) const;
858
869 inline UBool startsWith(const UnicodeString& srcText,
870 int32_t srcStart,
871 int32_t srcLength) const;
872
881 inline UBool startsWith(ConstChar16Ptr srcChars,
882 int32_t srcLength) const;
883
893 inline UBool startsWith(const char16_t *srcChars,
894 int32_t srcStart,
895 int32_t srcLength) const;
896
904 inline UBool endsWith(const UnicodeString& text) const;
905
916 inline UBool endsWith(const UnicodeString& srcText,
917 int32_t srcStart,
918 int32_t srcLength) const;
919
928 inline UBool endsWith(ConstChar16Ptr srcChars,
929 int32_t srcLength) const;
930
941 inline UBool endsWith(const char16_t *srcChars,
942 int32_t srcStart,
943 int32_t srcLength) const;
944
945
946 /* Searching - bitwise only */
947
956 inline int32_t indexOf(const UnicodeString& text) const;
957
967 inline int32_t indexOf(const UnicodeString& text,
968 int32_t start) const;
969
981 inline int32_t indexOf(const UnicodeString& text,
982 int32_t start,
983 int32_t length) const;
984
1001 inline int32_t indexOf(const UnicodeString& srcText,
1002 int32_t srcStart,
1003 int32_t srcLength,
1004 int32_t start,
1005 int32_t length) const;
1006
1018 inline int32_t indexOf(const char16_t *srcChars,
1019 int32_t srcLength,
1020 int32_t start) const;
1021
1034 inline int32_t indexOf(ConstChar16Ptr srcChars,
1035 int32_t srcLength,
1036 int32_t start,
1037 int32_t length) const;
1038
1055 int32_t indexOf(const char16_t *srcChars,
1056 int32_t srcStart,
1057 int32_t srcLength,
1058 int32_t start,
1059 int32_t length) const;
1060
1068 inline int32_t indexOf(char16_t c) const;
1069
1078 inline int32_t indexOf(UChar32 c) const;
1079
1088 inline int32_t indexOf(char16_t c,
1089 int32_t start) const;
1090
1100 inline int32_t indexOf(UChar32 c,
1101 int32_t start) const;
1102
1113 inline int32_t indexOf(char16_t c,
1114 int32_t start,
1115 int32_t length) const;
1116
1128 inline int32_t indexOf(UChar32 c,
1129 int32_t start,
1130 int32_t length) const;
1131
1140 inline int32_t lastIndexOf(const UnicodeString& text) const;
1141
1151 inline int32_t lastIndexOf(const UnicodeString& text,
1152 int32_t start) const;
1153
1165 inline int32_t lastIndexOf(const UnicodeString& text,
1166 int32_t start,
1167 int32_t length) const;
1168
1185 inline int32_t lastIndexOf(const UnicodeString& srcText,
1186 int32_t srcStart,
1187 int32_t srcLength,
1188 int32_t start,
1189 int32_t length) const;
1190
1201 inline int32_t lastIndexOf(const char16_t *srcChars,
1202 int32_t srcLength,
1203 int32_t start) const;
1204
1217 inline int32_t lastIndexOf(ConstChar16Ptr srcChars,
1218 int32_t srcLength,
1219 int32_t start,
1220 int32_t length) const;
1221
1238 int32_t lastIndexOf(const char16_t *srcChars,
1239 int32_t srcStart,
1240 int32_t srcLength,
1241 int32_t start,
1242 int32_t length) const;
1243
1251 inline int32_t lastIndexOf(char16_t c) const;
1252
1261 inline int32_t lastIndexOf(UChar32 c) const;
1262
1271 inline int32_t lastIndexOf(char16_t c,
1272 int32_t start) const;
1273
1283 inline int32_t lastIndexOf(UChar32 c,
1284 int32_t start) const;
1285
1296 inline int32_t lastIndexOf(char16_t c,
1297 int32_t start,
1298 int32_t length) const;
1299
1311 inline int32_t lastIndexOf(UChar32 c,
1312 int32_t start,
1313 int32_t length) const;
1314
1315
1316 /* Character access */
1317
1326 inline char16_t charAt(int32_t offset) const;
1327
1335 inline char16_t operator[] (int32_t offset) const;
1336
1348 UChar32 char32At(int32_t offset) const;
1349
1365 int32_t getChar32Start(int32_t offset) const;
1366
1383 int32_t getChar32Limit(int32_t offset) const;
1384
1435 int32_t moveIndex32(int32_t index, int32_t delta) const;
1436
1437 /* Substring extraction */
1438
1454 inline void extract(int32_t start,
1455 int32_t length,
1456 Char16Ptr dst,
1457 int32_t dstStart = 0) const;
1458
1480 int32_t
1481 extract(Char16Ptr dest, int32_t destCapacity,
1482 UErrorCode &errorCode) const;
1483
1493 inline void extract(int32_t start,
1494 int32_t length,
1495 UnicodeString& target) const;
1496
1508 inline void extractBetween(int32_t start,
1509 int32_t limit,
1510 char16_t *dst,
1511 int32_t dstStart = 0) const;
1512
1521 virtual void extractBetween(int32_t start,
1522 int32_t limit,
1523 UnicodeString& target) const;
1524
1546 int32_t extract(int32_t start,
1547 int32_t startLength,
1548 char *target,
1549 int32_t targetCapacity,
1550 enum EInvariant inv) const;
1551
1552 #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
1553
1573 int32_t extract(int32_t start,
1574 int32_t startLength,
1575 char *target,
1576 uint32_t targetLength) const;
1577
1578 #endif
1579
1580 #if !UCONFIG_NO_CONVERSION
1581
1607 inline int32_t extract(int32_t start,
1608 int32_t startLength,
1609 char *target,
1610 const char *codepage = 0) const;
1611
1641 int32_t extract(int32_t start,
1642 int32_t startLength,
1643 char *target,
1644 uint32_t targetLength,
1645 const char *codepage) const;
1646
1664 int32_t extract(char *dest, int32_t destCapacity,
1665 UConverter *cnv,
1666 UErrorCode &errorCode) const;
1667
1668 #endif
1669
1683 UnicodeString tempSubString(int32_t start=0, int32_t length=INT32_MAX) const;
1684
1695 inline UnicodeString tempSubStringBetween(int32_t start, int32_t limit=INT32_MAX) const;
1696
1708 void toUTF8(ByteSink &sink) const;
1709
1722 template<typename StringClass>
1723 StringClass &toUTF8String(StringClass &result) const {
1724 StringByteSink<StringClass> sbs(&result, length());
1725 toUTF8(sbs);
1726 return result;
1727 }
1728
1744 int32_t toUTF32(UChar32 *utf32, int32_t capacity, UErrorCode &errorCode) const;
1745
1746 /* Length operations */
1747
1756 inline int32_t length(void) const;
1757
1771 int32_t
1772 countChar32(int32_t start=0, int32_t length=INT32_MAX) const;
1773
1797 UBool
1798 hasMoreChar32Than(int32_t start, int32_t length, int32_t number) const;
1799
1805 inline UBool isEmpty(void) const;
1806
1816 inline int32_t getCapacity(void) const;
1817
1818 /* Other operations */
1819
1825 inline int32_t hashCode(void) const;
1826
1839 inline UBool isBogus(void) const;
1840
1841
1842 //========================================
1843 // Write operations
1844 //========================================
1845
1846 /* Assignment operations */
1847
1866 UnicodeString &operator=(const UnicodeString &srcText);
1867
1893 UnicodeString &fastCopyFrom(const UnicodeString &src);
1894
1903 UnicodeString &operator=(UnicodeString &&src) U_NOEXCEPT;
1904
1910 void swap(UnicodeString &other) U_NOEXCEPT;
1911
1918 friend inline void U_EXPORT2
1919 swap(UnicodeString &s1, UnicodeString &s2) U_NOEXCEPT {
1920 s1.swap(s2);
1921 }
1922
1930 inline UnicodeString& operator= (char16_t ch);
1931
1939 inline UnicodeString& operator= (UChar32 ch);
1940
1952 inline UnicodeString& setTo(const UnicodeString& srcText,
1953 int32_t srcStart);
1954
1968 inline UnicodeString& setTo(const UnicodeString& srcText,
1969 int32_t srcStart,
1970 int32_t srcLength);
1971
1980 inline UnicodeString& setTo(const UnicodeString& srcText);
1981
1990 inline UnicodeString& setTo(const char16_t *srcChars,
1991 int32_t srcLength);
1992
2001 inline UnicodeString& setTo(char16_t srcChar);
2002
2011 inline UnicodeString& setTo(UChar32 srcChar);
2012
2036 UnicodeString &setTo(UBool isTerminated,
2037 ConstChar16Ptr text,
2038 int32_t textLength);
2039
2059 UnicodeString &setTo(char16_t *buffer,
2060 int32_t buffLength,
2061 int32_t buffCapacity);
2062
2103 void setToBogus();
2104
2112 UnicodeString& setCharAt(int32_t offset,
2113 char16_t ch);
2114
2115
2116 /* Append operations */
2117
2125 inline UnicodeString& operator+= (char16_t ch);
2126
2134 inline UnicodeString& operator+= (UChar32 ch);
2135
2143 inline UnicodeString& operator+= (const UnicodeString& srcText);
2144
2159 inline UnicodeString& append(const UnicodeString& srcText,
2160 int32_t srcStart,
2161 int32_t srcLength);
2162
2170 inline UnicodeString& append(const UnicodeString& srcText);
2171
2185 inline UnicodeString& append(const char16_t *srcChars,
2186 int32_t srcStart,
2187 int32_t srcLength);
2188
2198 inline UnicodeString& append(ConstChar16Ptr srcChars,
2199 int32_t srcLength);
2200
2207 inline UnicodeString& append(char16_t srcChar);
2208
2215 UnicodeString& append(UChar32 srcChar);
2216
2217
2218 /* Insert operations */
2219
2233 inline UnicodeString& insert(int32_t start,
2234 const UnicodeString& srcText,
2235 int32_t srcStart,
2236 int32_t srcLength);
2237
2246 inline UnicodeString& insert(int32_t start,
2247 const UnicodeString& srcText);
2248
2262 inline UnicodeString& insert(int32_t start,
2263 const char16_t *srcChars,
2264 int32_t srcStart,
2265 int32_t srcLength);
2266
2276 inline UnicodeString& insert(int32_t start,
2277 ConstChar16Ptr srcChars,
2278 int32_t srcLength);
2279
2288 inline UnicodeString& insert(int32_t start,
2289 char16_t srcChar);
2290
2299 inline UnicodeString& insert(int32_t start,
2300 UChar32 srcChar);
2301
2302
2303 /* Replace operations */
2304
2322 inline UnicodeString& replace(int32_t start,
2323 int32_t length,
2324 const UnicodeString& srcText,
2325 int32_t srcStart,
2326 int32_t srcLength);
2327
2340 inline UnicodeString& replace(int32_t start,
2341 int32_t length,
2342 const UnicodeString& srcText);
2343
2361 inline UnicodeString& replace(int32_t start,
2362 int32_t length,
2363 const char16_t *srcChars,
2364 int32_t srcStart,
2365 int32_t srcLength);
2366
2379 inline UnicodeString& replace(int32_t start,
2380 int32_t length,
2381 ConstChar16Ptr srcChars,
2382 int32_t srcLength);
2383
2395 inline UnicodeString& replace(int32_t start,
2396 int32_t length,
2397 char16_t srcChar);
2398
2410 UnicodeString& replace(int32_t start, int32_t length, UChar32 srcChar);
2411
2421 inline UnicodeString& replaceBetween(int32_t start,
2422 int32_t limit,
2423 const UnicodeString& srcText);
2424
2439 inline UnicodeString& replaceBetween(int32_t start,
2440 int32_t limit,
2441 const UnicodeString& srcText,
2442 int32_t srcStart,
2443 int32_t srcLimit);
2444
2452 virtual void handleReplaceBetween(int32_t start,
2453 int32_t limit,
2454 const UnicodeString& text);
2455
2461 virtual UBool hasMetaData() const;
2462
2476 virtual void copy(int32_t start, int32_t limit, int32_t dest);
2477
2478 /* Search and replace operations */
2479
2488 inline UnicodeString& findAndReplace(const UnicodeString& oldText,
2489 const UnicodeString& newText);
2490
2502 inline UnicodeString& findAndReplace(int32_t start,
2503 int32_t length,
2504 const UnicodeString& oldText,
2505 const UnicodeString& newText);
2506
2524 UnicodeString& findAndReplace(int32_t start,
2525 int32_t length,
2526 const UnicodeString& oldText,
2527 int32_t oldStart,
2528 int32_t oldLength,
2529 const UnicodeString& newText,
2530 int32_t newStart,
2531 int32_t newLength);
2532
2533
2534 /* Remove operations */
2535
2541 inline UnicodeString& remove(void);
2542
2551 inline UnicodeString& remove(int32_t start,
2552 int32_t length = (int32_t)INT32_MAX);
2553
2562 inline UnicodeString& removeBetween(int32_t start,
2563 int32_t limit = (int32_t)INT32_MAX);
2564
2574 inline UnicodeString &retainBetween(int32_t start, int32_t limit = INT32_MAX);
2575
2576 /* Length operations */
2577
2589 UBool padLeading(int32_t targetLength,
2590 char16_t padChar = 0x0020);
2591
2603 UBool padTrailing(int32_t targetLength,
2604 char16_t padChar = 0x0020);
2605
2612 inline UBool truncate(int32_t targetLength);
2613
2619 UnicodeString& trim(void);
2620
2621
2622 /* Miscellaneous operations */
2623
2629 inline UnicodeString& reverse(void);
2630
2639 inline UnicodeString& reverse(int32_t start,
2640 int32_t length);
2641
2648 UnicodeString& toUpper(void);
2649
2657 UnicodeString& toUpper(const Locale& locale);
2658
2665 UnicodeString& toLower(void);
2666
2674 UnicodeString& toLower(const Locale& locale);
2675
2676 #if !UCONFIG_NO_BREAK_ITERATION
2677
2704 UnicodeString &toTitle(BreakIterator *titleIter);
2705
2733 UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale);
2734
2766 UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale, uint32_t options);
2767
2768 #endif
2769
2783 UnicodeString &foldCase(uint32_t options=0 /*U_FOLD_CASE_DEFAULT*/);
2784
2785 //========================================
2786 // Access to the internal buffer
2787 //========================================
2788
2832 char16_t *getBuffer(int32_t minCapacity);
2833
2854 void releaseBuffer(int32_t newLength=-1);
2855
2886 inline const char16_t *getBuffer() const;
2887
2921 const char16_t *getTerminatedBuffer();
2922
2923 //========================================
2924 // Constructors
2925 //========================================
2926
2930 inline UnicodeString();
2931
2943 UnicodeString(int32_t capacity, UChar32 c, int32_t count);
2944
2954 UNISTR_FROM_CHAR_EXPLICIT UnicodeString(char16_t ch);
2955
2965 UNISTR_FROM_CHAR_EXPLICIT UnicodeString(UChar32 ch);
2966
2977 UNISTR_FROM_STRING_EXPLICIT UnicodeString(const char16_t *text);
2978
2979 #if !U_CHAR16_IS_TYPEDEF
2980
2990 UNISTR_FROM_STRING_EXPLICIT UnicodeString(const uint16_t *text) :
2991 UnicodeString(ConstChar16Ptr(text)) {}
2992 #endif
2993
2994 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
2995
3006 UNISTR_FROM_STRING_EXPLICIT UnicodeString(const wchar_t *text) :
3007 UnicodeString(ConstChar16Ptr(text)) {}
3008 #endif
3009
3020 UNISTR_FROM_STRING_EXPLICIT inline UnicodeString(const std::nullptr_t text);
3021
3029 UnicodeString(const char16_t *text,
3030 int32_t textLength);
3031
3032 #if !U_CHAR16_IS_TYPEDEF
3033
3040 UnicodeString(const uint16_t *text, int32_t length) :
3041 UnicodeString(ConstChar16Ptr(text), length) {}
3042 #endif
3043
3044 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
3045
3053 UnicodeString(const wchar_t *text, int32_t length) :
3054 UnicodeString(ConstChar16Ptr(text), length) {}
3055 #endif
3056
3064 inline UnicodeString(const std::nullptr_t text, int32_t length);
3065
3088 UnicodeString(UBool isTerminated,
3089 ConstChar16Ptr text,
3090 int32_t textLength);
3091
3110 UnicodeString(char16_t *buffer, int32_t buffLength, int32_t buffCapacity);
3111
3112 #if !U_CHAR16_IS_TYPEDEF
3113
3121 UnicodeString(uint16_t *buffer, int32_t buffLength, int32_t buffCapacity) :
3122 UnicodeString(Char16Ptr(buffer), buffLength, buffCapacity) {}
3123 #endif
3124
3125 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
3126
3135 UnicodeString(wchar_t *buffer, int32_t buffLength, int32_t buffCapacity) :
3136 UnicodeString(Char16Ptr(buffer), buffLength, buffCapacity) {}
3137 #endif
3138
3147 inline UnicodeString(std::nullptr_t buffer, int32_t buffLength, int32_t buffCapacity);
3148
3149 #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
3150
3170 UNISTR_FROM_STRING_EXPLICIT UnicodeString(const char *codepageData);
3171
3180 UnicodeString(const char *codepageData, int32_t dataLength);
3181
3182 #endif
3183
3184 #if !UCONFIG_NO_CONVERSION
3185
3203 UnicodeString(const char *codepageData, const char *codepage);
3204
3222 UnicodeString(const char *codepageData, int32_t dataLength, const char *codepage);
3223
3245 UnicodeString(
3246 const char *src, int32_t srcLength,
3247 UConverter *cnv,
3248 UErrorCode &errorCode);
3249
3250 #endif
3251
3275 UnicodeString(const char *src, int32_t length, enum EInvariant inv);
3276
3277
3294 UnicodeString(const UnicodeString& that);
3295
3302 UnicodeString(UnicodeString &&src) U_NOEXCEPT;
3303
3310 UnicodeString(const UnicodeString& src, int32_t srcStart);
3311
3319 UnicodeString(const UnicodeString& src, int32_t srcStart, int32_t srcLength);
3320
3337 virtual Replaceable *clone() const;
3338
3342 virtual ~UnicodeString();
3343
3357 static UnicodeString fromUTF8(StringPiece utf8);
3358
3370 static UnicodeString fromUTF32(const UChar32 *utf32, int32_t length);
3371
3372 /* Miscellaneous operations */
3373
3408 UnicodeString unescape() const;
3409
3429 UChar32 unescapeAt(int32_t &offset) const;
3430
3436 static UClassID U_EXPORT2 getStaticClassID();
3437
3443 virtual UClassID getDynamicClassID() const;
3444
3445 //========================================
3446 // Implementation methods
3447 //========================================
3448
3449 protected:
3454 virtual int32_t getLength() const;
3455
3461 virtual char16_t getCharAt(int32_t offset) const;
3462
3468 virtual UChar32 getChar32At(int32_t offset) const;
3469
3470 private:
3471 // For char* constructors. Could be made public.
3472 UnicodeString &setToUTF8(StringPiece utf8);
3473 // For extract(char*).
3474 // We could make a toUTF8(target, capacity, errorCode) public but not
3475 // this version: New API will be cleaner if we make callers create substrings
3476 // rather than having start+length on every method,
3477 // and it should take a UErrorCode&.
3478 int32_t
3479 toUTF8(int32_t start, int32_t len,
3480 char *target, int32_t capacity) const;
3481
3486 UBool doEquals(const UnicodeString &text, int32_t len) const;
3487
3488 inline int8_t
3489 doCompare(int32_t start,
3490 int32_t length,
3491 const UnicodeString& srcText,
3492 int32_t srcStart,
3493 int32_t srcLength) const;
3494
3495 int8_t doCompare(int32_t start,
3496 int32_t length,
3497 const char16_t *srcChars,
3498 int32_t srcStart,
3499 int32_t srcLength) const;
3500
3501 inline int8_t
3502 doCompareCodePointOrder(int32_t start,
3503 int32_t length,
3504 const UnicodeString& srcText,
3505 int32_t srcStart,
3506 int32_t srcLength) const;
3507
3508 int8_t doCompareCodePointOrder(int32_t start,
3509 int32_t length,
3510 const char16_t *srcChars,
3511 int32_t srcStart,
3512 int32_t srcLength) const;
3513
3514 inline int8_t
3515 doCaseCompare(int32_t start,
3516 int32_t length,
3517 const UnicodeString &srcText,
3518 int32_t srcStart,
3519 int32_t srcLength,
3520 uint32_t options) const;
3521
3522 int8_t
3523 doCaseCompare(int32_t start,
3524 int32_t length,
3525 const char16_t *srcChars,
3526 int32_t srcStart,
3527 int32_t srcLength,
3528 uint32_t options) const;
3529
3530 int32_t doIndexOf(char16_t c,
3531 int32_t start,
3532 int32_t length) const;
3533
3534 int32_t doIndexOf(UChar32 c,
3535 int32_t start,
3536 int32_t length) const;
3537
3538 int32_t doLastIndexOf(char16_t c,
3539 int32_t start,
3540 int32_t length) const;
3541
3542 int32_t doLastIndexOf(UChar32 c,
3543 int32_t start,
3544 int32_t length) const;
3545
3546 void doExtract(int32_t start,
3547 int32_t length,
3548 char16_t *dst,
3549 int32_t dstStart) const;
3550
3551 inline void doExtract(int32_t start,
3552 int32_t length,
3553 UnicodeString& target) const;
3554
3555 inline char16_t doCharAt(int32_t offset) const;
3556
3557 UnicodeString& doReplace(int32_t start,
3558 int32_t length,
3559 const UnicodeString& srcText,
3560 int32_t srcStart,
3561 int32_t srcLength);
3562
3563 UnicodeString& doReplace(int32_t start,
3564 int32_t length,
3565 const char16_t *srcChars,
3566 int32_t srcStart,
3567 int32_t srcLength);
3568
3569 UnicodeString& doAppend(const UnicodeString& src, int32_t srcStart, int32_t srcLength);
3570 UnicodeString& doAppend(const char16_t *srcChars, int32_t srcStart, int32_t srcLength);
3571
3572 UnicodeString& doReverse(int32_t start,
3573 int32_t length);
3574
3575 // calculate hash code
3576 int32_t doHashCode(void) const;
3577
3578 // get pointer to start of array
3579 // these do not check for kOpenGetBuffer, unlike the public getBuffer() function
3580 inline char16_t* getArrayStart(void);
3581 inline const char16_t* getArrayStart(void) const;
3582
3583 inline UBool hasShortLength() const;
3584 inline int32_t getShortLength() const;
3585
3586 // A UnicodeString object (not necessarily its current buffer)
3587 // is writable unless it isBogus() or it has an "open" getBuffer(minCapacity).
3588 inline UBool isWritable() const;
3589
3590 // Is the current buffer writable?
3591 inline UBool isBufferWritable() const;
3592
3593 // None of the following does releaseArray().
3594 inline void setZeroLength();
3595 inline void setShortLength(int32_t len);
3596 inline void setLength(int32_t len);
3597 inline void setToEmpty();
3598 inline void setArray(char16_t *array, int32_t len, int32_t capacity); // sets length but not flags
3599
3600 // allocate the array; result may be the stack buffer
3601 // sets refCount to 1 if appropriate
3602 // sets fArray, fCapacity, and flags
3603 // sets length to 0
3604 // returns boolean for success or failure
3605 UBool allocate(int32_t capacity);
3606
3607 // release the array if owned
3608 void releaseArray(void);
3609
3610 // turn a bogus string into an empty one
3611 void unBogus();
3612
3613 // implements assigment operator, copy constructor, and fastCopyFrom()
3614 UnicodeString &copyFrom(const UnicodeString &src, UBool fastCopy=FALSE);
3615
3616 // Copies just the fields without memory management.
3617 void copyFieldsFrom(UnicodeString &src, UBool setSrcToBogus) U_NOEXCEPT;
3618
3619 // Pin start and limit to acceptable values.
3620 inline void pinIndex(int32_t& start) const;
3621 inline void pinIndices(int32_t& start,
3622 int32_t& length) const;
3623
3624 #if !UCONFIG_NO_CONVERSION
3625
3626 /* Internal extract() using UConverter. */
3627 int32_t doExtract(int32_t start, int32_t length,
3628 char *dest, int32_t destCapacity,
3629 UConverter *cnv,
3630 UErrorCode &errorCode) const;
3631
3632 /*
3633 * Real constructor for converting from codepage data.
3634 * It assumes that it is called with !fRefCounted.
3635 *
3636 * If `codepage==0`, then the default converter
3637 * is used for the platform encoding.
3638 * If `codepage` is an empty string (`""`),
3639 * then a simple conversion is performed on the codepage-invariant
3640 * subset ("invariant characters") of the platform encoding. See utypes.h.
3641 */
3642 void doCodepageCreate(const char *codepageData,
3643 int32_t dataLength,
3644 const char *codepage);
3645
3646 /*
3647 * Worker function for creating a UnicodeString from
3648 * a codepage string using a UConverter.
3649 */
3650 void
3651 doCodepageCreate(const char *codepageData,
3652 int32_t dataLength,
3653 UConverter *converter,
3654 UErrorCode &status);
3655
3656 #endif
3657
3658 /*
3659 * This function is called when write access to the array
3660 * is necessary.
3661 *
3662 * We need to make a copy of the array if
3663 * the buffer is read-only, or
3664 * the buffer is refCounted (shared), and refCount>1, or
3665 * the buffer is too small.
3666 *
3667 * Return FALSE if memory could not be allocated.
3668 */
3669 UBool cloneArrayIfNeeded(int32_t newCapacity = -1,
3670 int32_t growCapacity = -1,
3671 UBool doCopyArray = TRUE,
3672 int32_t **pBufferToDelete = 0,
3673 UBool forceClone = FALSE);
3674
3680 UnicodeString &
3681 caseMap(int32_t caseLocale, uint32_t options,
3682 #if !UCONFIG_NO_BREAK_ITERATION
3683 BreakIterator *iter,
3684 #endif
3685 UStringCaseMapper *stringCaseMapper);
3686
3687 // ref counting
3688 void addRef(void);
3689 int32_t removeRef(void);
3690 int32_t refCount(void) const;
3691
3692 // constants
3693 enum {
3699 US_STACKBUF_SIZE=(int32_t)(UNISTR_OBJECT_SIZE-sizeof(void *)-2)/U_SIZEOF_UCHAR,
3700 kInvalidUChar=0xffff, // U+FFFF returned by charAt(invalid index)
3701 kInvalidHashCode=0, // invalid hash code
3702 kEmptyHashCode=1, // hash code for empty string
3703
3704 // bit flag values for fLengthAndFlags
3705 kIsBogus=1, // this string is bogus, i.e., not valid or NULL
3706 kUsingStackBuffer=2,// using fUnion.fStackFields instead of fUnion.fFields
3707 kRefCounted=4, // there is a refCount field before the characters in fArray
3708 kBufferIsReadonly=8,// do not write to this buffer
3709 kOpenGetBuffer=16, // getBuffer(minCapacity) was called (is "open"),
3710 // and releaseBuffer(newLength) must be called
3711 kAllStorageFlags=0x1f,
3712
3713 kLengthShift=5, // remaining 11 bits for non-negative short length, or negative if long
3714 kLength1=1<<kLengthShift,
3715 kMaxShortLength=0x3ff, // max non-negative short length (leaves top bit 0)
3716 kLengthIsLarge=0xffe0, // short length < 0, real length is in fUnion.fFields.fLength
3717
3718 // combined values for convenience
3719 kShortString=kUsingStackBuffer,
3720 kLongString=kRefCounted,
3721 kReadonlyAlias=kBufferIsReadonly,
3722 kWritableAlias=0
3723 };
3724
3725 friend class UnicodeStringAppendable;
3726
3727 union StackBufferOrFields; // forward declaration necessary before friend declaration
3728 friend union StackBufferOrFields; // make US_STACKBUF_SIZE visible inside fUnion
3729
3730 /*
3731 * The following are all the class fields that are stored
3732 * in each UnicodeString object.
3733 * Note that UnicodeString has virtual functions,
3734 * therefore there is an implicit vtable pointer
3735 * as the first real field.
3736 * The fields should be aligned such that no padding is necessary.
3737 * On 32-bit machines, the size should be 32 bytes,
3738 * on 64-bit machines (8-byte pointers), it should be 40 bytes.
3739 *
3740 * We use a hack to achieve this.
3741 *
3742 * With at least some compilers, each of the following is forced to
3743 * a multiple of sizeof(pointer) [the largest field base unit here is a data pointer],
3744 * rounded up with additional padding if the fields do not already fit that requirement:
3745 * - sizeof(class UnicodeString)
3746 * - offsetof(UnicodeString, fUnion)
3747 * - sizeof(fUnion)
3748 * - sizeof(fStackFields)
3749 *
3750 * We optimize for the longest possible internal buffer for short strings.
3751 * fUnion.fStackFields begins with 2 bytes for storage flags
3752 * and the length of relatively short strings,
3753 * followed by the buffer for short string contents.
3754 * There is no padding inside fStackFields.
3755 *
3756 * Heap-allocated and aliased strings use fUnion.fFields.
3757 * Both fStackFields and fFields must begin with the same fields for flags and short length,
3758 * that is, those must have the same memory offsets inside the object,
3759 * because the flags must be inspected in order to decide which half of fUnion is being used.
3760 * We assume that the compiler does not reorder the fields.
3761 *
3762 * (Padding at the end of fFields is ok:
3763 * As long as it is no larger than fStackFields, it is not wasted space.)
3764 *
3765 * For some of the history of the UnicodeString class fields layout, see
3766 * - ICU ticket #11551 "longer UnicodeString contents in stack buffer"
3767 * - ICU ticket #11336 "UnicodeString: recombine stack buffer arrays"
3768 * - ICU ticket #8322 "why is sizeof(UnicodeString)==48?"
3769 */
3770 // (implicit) *vtable;
3771 union StackBufferOrFields {
3772 // fStackFields is used iff (fLengthAndFlags&kUsingStackBuffer) else fFields is used.
3773 // Each struct of the union must begin with fLengthAndFlags.
3774 struct {
3775 int16_t fLengthAndFlags; // bit fields: see constants above
3776 char16_t fBuffer[US_STACKBUF_SIZE]; // buffer for short strings
3777 } fStackFields;
3778 struct {
3779 int16_t fLengthAndFlags; // bit fields: see constants above
3780 int32_t fLength; // number of characters in fArray if >127; else undefined
3781 int32_t fCapacity; // capacity of fArray (in char16_ts)
3782 // array pointer last to minimize padding for machines with P128 data model
3783 // or pointer sizes that are not a power of 2
3784 char16_t *fArray; // the Unicode data
3785 } fFields;
3786 } fUnion;
3787 };
3788
3797 U_COMMON_API UnicodeString U_EXPORT2
3798 operator+ (const UnicodeString &s1, const UnicodeString &s2);
3799
3800 //========================================
3801 // Inline members
3802 //========================================
3803
3804 //========================================
3805 // Privates
3806 //========================================
3807
3808 inline void
3809 UnicodeString::pinIndex(int32_t& start) const
3810 {
3811 // pin index
3812 if(start < 0) {
3813 start = 0;
3814 } else if(start > length()) {
3815 start = length();
3816 }
3817 }
3818
3819 inline void
3820 UnicodeString::pinIndices(int32_t& start,
3821 int32_t& _length) const
3822 {
3823 // pin indices
3824 int32_t len = length();
3825 if(start < 0) {
3826 start = 0;
3827 } else if(start > len) {
3828 start = len;
3829 }
3830 if(_length < 0) {
3831 _length = 0;
3832 } else if(_length > (len - start)) {
3833 _length = (len - start);
3834 }
3835 }
3836
3837 inline char16_t*
3838 UnicodeString::getArrayStart() {
3839 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3840 fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
3841 }
3842
3843 inline const char16_t*
3844 UnicodeString::getArrayStart() const {
3845 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3846 fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
3847 }
3848
3849 //========================================
3850 // Default constructor
3851 //========================================
3852
3853 inline
3854 UnicodeString::UnicodeString() {
3855 fUnion.fStackFields.fLengthAndFlags=kShortString;
3856 }
3857
3858 inline UnicodeString::UnicodeString(const std::nullptr_t /*text*/) {
3859 fUnion.fStackFields.fLengthAndFlags=kShortString;
3860 }
3861
3862 inline UnicodeString::UnicodeString(const std::nullptr_t /*text*/, int32_t /*length*/) {
3863 fUnion.fStackFields.fLengthAndFlags=kShortString;
3864 }
3865
3866 inline UnicodeString::UnicodeString(std::nullptr_t /*buffer*/, int32_t /*buffLength*/, int32_t /*buffCapacity*/) {
3867 fUnion.fStackFields.fLengthAndFlags=kShortString;
3868 }
3869
3870 //========================================
3871 // Read-only implementation methods
3872 //========================================
3873 inline UBool
3874 UnicodeString::hasShortLength() const {
3875 return fUnion.fFields.fLengthAndFlags>=0;
3876 }
3877
3878 inline int32_t
3879 UnicodeString::getShortLength() const {
3880 // fLengthAndFlags must be non-negative -> short length >= 0
3881 // and arithmetic or logical shift does not matter.
3882 return fUnion.fFields.fLengthAndFlags>>kLengthShift;
3883 }
3884
3885 inline int32_t
3886 UnicodeString::length() const {
3887 return hasShortLength() ? getShortLength() : fUnion.fFields.fLength;
3888 }
3889
3890 inline int32_t
3891 UnicodeString::getCapacity() const {
3892 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3893 US_STACKBUF_SIZE : fUnion.fFields.fCapacity;
3894 }
3895
3896 inline int32_t
3897 UnicodeString::hashCode() const
3898 { return doHashCode(); }
3899
3900 inline UBool
3901 UnicodeString::isBogus() const
3902 { return (UBool)(fUnion.fFields.fLengthAndFlags & kIsBogus); }
3903
3904 inline UBool
3905 UnicodeString::isWritable() const
3906 { return (UBool)!(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus)); }
3907
3908 inline UBool
3909 UnicodeString::isBufferWritable() const
3910 {
3911 return (UBool)(
3912 !(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus|kBufferIsReadonly)) &&
3913 (!(fUnion.fFields.fLengthAndFlags&kRefCounted) || refCount()==1));
3914 }
3915
3916 inline const char16_t *
3917 UnicodeString::getBuffer() const {
3918 if(fUnion.fFields.fLengthAndFlags&(kIsBogus|kOpenGetBuffer)) {
3919 return nullptr;
3920 } else if(fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) {
3921 return fUnion.fStackFields.fBuffer;
3922 } else {
3923 return fUnion.fFields.fArray;
3924 }
3925 }
3926
3927 //========================================
3928 // Read-only alias methods
3929 //========================================
3930 inline int8_t
3931 UnicodeString::doCompare(int32_t start,
3932 int32_t thisLength,
3933 const UnicodeString& srcText,
3934 int32_t srcStart,
3935 int32_t srcLength) const
3936 {
3937 if(srcText.isBogus()) {
3938 return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
3939 } else {
3940 srcText.pinIndices(srcStart, srcLength);
3941 return doCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
3942 }
3943 }
3944
3945 inline UBool
3946 UnicodeString::operator== (const UnicodeString& text) const
3947 {
3948 if(isBogus()) {
3949 return text.isBogus();
3950 } else {
3951 int32_t len = length(), textLength = text.length();
3952 return !text.isBogus() && len == textLength && doEquals(text, len);
3953 }
3954 }
3955
3956 inline UBool
3957 UnicodeString::operator!= (const UnicodeString& text) const
3958 { return (! operator==(text)); }
3959
3960 inline UBool
3961 UnicodeString::operator> (const UnicodeString& text) const
3962 { return doCompare(0, length(), text, 0, text.length()) == 1; }
3963
3964 inline UBool
3965 UnicodeString::operator< (const UnicodeString& text) const
3966 { return doCompare(0, length(), text, 0, text.length()) == -1; }
3967
3968 inline UBool
3969 UnicodeString::operator>= (const UnicodeString& text) const
3970 { return doCompare(0, length(), text, 0, text.length()) != -1; }
3971
3972 inline UBool
3973 UnicodeString::operator<= (const UnicodeString& text) const
3974 { return doCompare(0, length(), text, 0, text.length()) != 1; }
3975
3976 inline int8_t
3977 UnicodeString::compare(const UnicodeString& text) const
3978 { return doCompare(0, length(), text, 0, text.length()); }
3979
3980 inline int8_t
3981 UnicodeString::compare(int32_t start,
3982 int32_t _length,
3983 const UnicodeString& srcText) const
3984 { return doCompare(start, _length, srcText, 0, srcText.length()); }
3985
3986 inline int8_t
3987 UnicodeString::compare(ConstChar16Ptr srcChars,
3988 int32_t srcLength) const
3989 { return doCompare(0, length(), srcChars, 0, srcLength); }
3990
3991 inline int8_t
3992 UnicodeString::compare(int32_t start,
3993 int32_t _length,
3994 const UnicodeString& srcText,
3995 int32_t srcStart,
3996 int32_t srcLength) const
3997 { return doCompare(start, _length, srcText, srcStart, srcLength); }
3998
3999 inline int8_t
4000 UnicodeString::compare(int32_t start,
4001 int32_t _length,
4002 const char16_t *srcChars) const
4003 { return doCompare(start, _length, srcChars, 0, _length); }
4004
4005 inline int8_t
4006 UnicodeString::compare(int32_t start,
4007 int32_t _length,
4008 const char16_t *srcChars,
4009 int32_t srcStart,
4010 int32_t srcLength) const
4011 { return doCompare(start, _length, srcChars, srcStart, srcLength); }
4012
4013 inline int8_t
4014 UnicodeString::compareBetween(int32_t start,
4015 int32_t limit,
4016 const UnicodeString& srcText,
4017 int32_t srcStart,
4018 int32_t srcLimit) const
4019 { return doCompare(start, limit - start,
4020 srcText, srcStart, srcLimit - srcStart); }
4021
4022 inline int8_t
4023 UnicodeString::doCompareCodePointOrder(int32_t start,
4024 int32_t thisLength,
4025 const UnicodeString& srcText,
4026 int32_t srcStart,
4027 int32_t srcLength) const
4028 {
4029 if(srcText.isBogus()) {
4030 return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
4031 } else {
4032 srcText.pinIndices(srcStart, srcLength);
4033 return doCompareCodePointOrder(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
4034 }
4035 }
4036
4037 inline int8_t
4038 UnicodeString::compareCodePointOrder(const UnicodeString& text) const
4039 { return doCompareCodePointOrder(0, length(), text, 0, text.length()); }
4040
4041 inline int8_t
4042 UnicodeString::compareCodePointOrder(int32_t start,
4043 int32_t _length,
4044 const UnicodeString& srcText) const
4045 { return doCompareCodePointOrder(start, _length, srcText, 0, srcText.length()); }
4046
4047 inline int8_t
4048 UnicodeString::compareCodePointOrder(ConstChar16Ptr srcChars,
4049 int32_t srcLength) const
4050 { return doCompareCodePointOrder(0, length(), srcChars, 0, srcLength); }
4051
4052 inline int8_t
4053 UnicodeString::compareCodePointOrder(int32_t start,
4054 int32_t _length,
4055 const UnicodeString& srcText,
4056 int32_t srcStart,
4057 int32_t srcLength) const
4058 { return doCompareCodePointOrder(start, _length, srcText, srcStart, srcLength); }
4059
4060 inline int8_t
4061 UnicodeString::compareCodePointOrder(int32_t start,
4062 int32_t _length,
4063 const char16_t *srcChars) const
4064 { return doCompareCodePointOrder(start, _length, srcChars, 0, _length); }
4065
4066 inline int8_t
4067 UnicodeString::compareCodePointOrder(int32_t start,
4068 int32_t _length,
4069 const char16_t *srcChars,
4070 int32_t srcStart,
4071 int32_t srcLength) const
4072 { return doCompareCodePointOrder(start, _length, srcChars, srcStart, srcLength); }
4073
4074 inline int8_t
4075 UnicodeString::compareCodePointOrderBetween(int32_t start,
4076 int32_t limit,
4077 const UnicodeString& srcText,
4078 int32_t srcStart,
4079 int32_t srcLimit) const
4080 { return doCompareCodePointOrder(start, limit - start,
4081 srcText, srcStart, srcLimit - srcStart); }
4082
4083 inline int8_t
4084 UnicodeString::doCaseCompare(int32_t start,
4085 int32_t thisLength,
4086 const UnicodeString &srcText,
4087 int32_t srcStart,
4088 int32_t srcLength,
4089 uint32_t options) const
4090 {
4091 if(srcText.isBogus()) {
4092 return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
4093 } else {
4094 srcText.pinIndices(srcStart, srcLength);
4095 return doCaseCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength, options);
4096 }
4097 }
4098
4099 inline int8_t
4100 UnicodeString::caseCompare(const UnicodeString &text, uint32_t options) const {
4101 return doCaseCompare(0, length(), text, 0, text.length(), options);
4102 }
4103
4104 inline int8_t
4105 UnicodeString::caseCompare(int32_t start,
4106 int32_t _length,
4107 const UnicodeString &srcText,
4108 uint32_t options) const {
4109 return doCaseCompare(start, _length, srcText, 0, srcText.length(), options);
4110 }
4111
4112 inline int8_t
4113 UnicodeString::caseCompare(ConstChar16Ptr srcChars,
4114 int32_t srcLength,
4115 uint32_t options) const {
4116 return doCaseCompare(0, length(), srcChars, 0, srcLength, options);
4117 }
4118
4119 inline int8_t
4120 UnicodeString::caseCompare(int32_t start,
4121 int32_t _length,
4122 const UnicodeString &srcText,
4123 int32_t srcStart,
4124 int32_t srcLength,
4125 uint32_t options) const {
4126 return doCaseCompare(start, _length, srcText, srcStart, srcLength, options);
4127 }
4128
4129 inline int8_t
4130 UnicodeString::caseCompare(int32_t start,
4131 int32_t _length,
4132 const char16_t *srcChars,
4133 uint32_t options) const {
4134 return doCaseCompare(start, _length, srcChars, 0, _length, options);
4135 }
4136
4137 inline int8_t
4138 UnicodeString::caseCompare(int32_t start,
4139 int32_t _length,
4140 const char16_t *srcChars,
4141 int32_t srcStart,
4142 int32_t srcLength,
4143 uint32_t options) const {
4144 return doCaseCompare(start, _length, srcChars, srcStart, srcLength, options);
4145 }
4146
4147 inline int8_t
4148 UnicodeString::caseCompareBetween(int32_t start,
4149 int32_t limit,
4150 const UnicodeString &srcText,
4151 int32_t srcStart,
4152 int32_t srcLimit,
4153 uint32_t options) const {
4154 return doCaseCompare(start, limit - start, srcText, srcStart, srcLimit - srcStart, options);
4155 }
4156
4157 inline int32_t
4158 UnicodeString::indexOf(const UnicodeString& srcText,
4159 int32_t srcStart,
4160 int32_t srcLength,
4161 int32_t start,
4162 int32_t _length) const
4163 {
4164 if(!srcText.isBogus()) {
4165 srcText.pinIndices(srcStart, srcLength);
4166 if(srcLength > 0) {
4167 return indexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
4168 }
4169 }
4170 return -1;
4171 }
4172
4173 inline int32_t
4174 UnicodeString::indexOf(const UnicodeString& text) const
4175 { return indexOf(text, 0, text.length(), 0, length()); }
4176
4177 inline int32_t
4178 UnicodeString::indexOf(const UnicodeString& text,
4179 int32_t start) const {
4180 pinIndex(start);
4181 return indexOf(text, 0, text.length(), start, length() - start);
4182 }
4183
4184 inline int32_t
4185 UnicodeString::indexOf(const UnicodeString& text,
4186 int32_t start,
4187 int32_t _length) const
4188 { return indexOf(text, 0, text.length(), start, _length); }
4189
4190 inline int32_t
4191 UnicodeString::indexOf(const char16_t *srcChars,
4192 int32_t srcLength,
4193 int32_t start) const {
4194 pinIndex(start);
4195 return indexOf(srcChars, 0, srcLength, start, length() - start);
4196 }
4197
4198 inline int32_t
4199 UnicodeString::indexOf(ConstChar16Ptr srcChars,
4200 int32_t srcLength,
4201 int32_t start,
4202 int32_t _length) const
4203 { return indexOf(srcChars, 0, srcLength, start, _length); }
4204
4205 inline int32_t
4206 UnicodeString::indexOf(char16_t c,
4207 int32_t start,
4208 int32_t _length) const
4209 { return doIndexOf(c, start, _length); }
4210
4211 inline int32_t
4212 UnicodeString::indexOf(UChar32 c,
4213 int32_t start,
4214 int32_t _length) const
4215 { return doIndexOf(c, start, _length); }
4216
4217 inline int32_t
4218 UnicodeString::indexOf(char16_t c) const
4219 { return doIndexOf(c, 0, length()); }
4220
4221 inline int32_t
4222 UnicodeString::indexOf(UChar32 c) const
4223 { return indexOf(c, 0, length()); }
4224
4225 inline int32_t
4226 UnicodeString::indexOf(char16_t c,
4227 int32_t start) const {
4228 pinIndex(start);
4229 return doIndexOf(c, start, length() - start);
4230 }
4231
4232 inline int32_t
4233 UnicodeString::indexOf(UChar32 c,
4234 int32_t start) const {
4235 pinIndex(start);
4236 return indexOf(c, start, length() - start);
4237 }
4238
4239 inline int32_t
4240 UnicodeString::lastIndexOf(ConstChar16Ptr srcChars,
4241 int32_t srcLength,
4242 int32_t start,
4243 int32_t _length) const
4244 { return lastIndexOf(srcChars, 0, srcLength, start, _length); }
4245
4246 inline int32_t
4247 UnicodeString::lastIndexOf(const char16_t *srcChars,
4248 int32_t srcLength,
4249 int32_t start) const {
4250 pinIndex(start);
4251 return lastIndexOf(srcChars, 0, srcLength, start, length() - start);
4252 }
4253
4254 inline int32_t
4255 UnicodeString::lastIndexOf(const UnicodeString& srcText,
4256 int32_t srcStart,
4257 int32_t srcLength,
4258 int32_t start,
4259 int32_t _length) const
4260 {
4261 if(!srcText.isBogus()) {
4262 srcText.pinIndices(srcStart, srcLength);
4263 if(srcLength > 0) {
4264 return lastIndexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
4265 }
4266 }
4267 return -1;
4268 }
4269
4270 inline int32_t
4271 UnicodeString::lastIndexOf(const UnicodeString& text,
4272 int32_t start,
4273 int32_t _length) const
4274 { return lastIndexOf(text, 0, text.length(), start, _length); }
4275
4276 inline int32_t
4277 UnicodeString::lastIndexOf(const UnicodeString& text,
4278 int32_t start) const {
4279 pinIndex(start);
4280 return lastIndexOf(text, 0, text.length(), start, length() - start);
4281 }
4282
4283 inline int32_t
4284 UnicodeString::lastIndexOf(const UnicodeString& text) const
4285 { return lastIndexOf(text, 0, text.length(), 0, length()); }
4286
4287 inline int32_t
4288 UnicodeString::lastIndexOf(char16_t c,
4289 int32_t start,
4290 int32_t _length) const
4291 { return doLastIndexOf(c, start, _length); }
4292
4293 inline int32_t
4294 UnicodeString::lastIndexOf(UChar32 c,
4295 int32_t start,
4296 int32_t _length) const {
4297 return doLastIndexOf(c, start, _length);
4298 }
4299
4300 inline int32_t
4301 UnicodeString::lastIndexOf(char16_t c) const
4302 { return doLastIndexOf(c, 0, length()); }
4303
4304 inline int32_t
4305 UnicodeString::lastIndexOf(UChar32 c) const {
4306 return lastIndexOf(c, 0, length());
4307 }
4308
4309 inline int32_t
4310 UnicodeString::lastIndexOf(char16_t c,
4311 int32_t start) const {
4312 pinIndex(start);
4313 return doLastIndexOf(c, start, length() - start);
4314 }
4315
4316 inline int32_t
4317 UnicodeString::lastIndexOf(UChar32 c,
4318 int32_t start) const {
4319 pinIndex(start);
4320 return lastIndexOf(c, start, length() - start);
4321 }
4322
4323 inline UBool
4324 UnicodeString::startsWith(const UnicodeString& text) const
4325 { return compare(0, text.length(), text, 0, text.length()) == 0; }
4326
4327 inline UBool
4328 UnicodeString::startsWith(const UnicodeString& srcText,
4329 int32_t srcStart,
4330 int32_t srcLength) const
4331 { return doCompare(0, srcLength, srcText, srcStart, srcLength) == 0; }
4332
4333 inline UBool
4334 UnicodeString::startsWith(ConstChar16Ptr srcChars, int32_t srcLength) const {
4335 if(srcLength < 0) {
4336 srcLength = u_strlen(toUCharPtr(srcChars));
4337 }
4338 return doCompare(0, srcLength, srcChars, 0, srcLength) == 0;
4339 }
4340
4341 inline UBool
4342 UnicodeString::startsWith(const char16_t *srcChars, int32_t srcStart, int32_t srcLength) const {
4343 if(srcLength < 0) {
4344 srcLength = u_strlen(toUCharPtr(srcChars));
4345 }
4346 return doCompare(0, srcLength, srcChars, srcStart, srcLength) == 0;
4347 }
4348
4349 inline UBool
4350 UnicodeString::endsWith(const UnicodeString& text) const
4351 { return doCompare(length() - text.length(), text.length(),
4352 text, 0, text.length()) == 0; }
4353
4354 inline UBool
4355 UnicodeString::endsWith(const UnicodeString& srcText,
4356 int32_t srcStart,
4357 int32_t srcLength) const {
4358 srcText.pinIndices(srcStart, srcLength);
4359 return doCompare(length() - srcLength, srcLength,
4360 srcText, srcStart, srcLength) == 0;
4361 }
4362
4363 inline UBool
4364 UnicodeString::endsWith(ConstChar16Ptr srcChars,
4365 int32_t srcLength) const {
4366 if(srcLength < 0) {
4367 srcLength = u_strlen(toUCharPtr(srcChars));
4368 }
4369 return doCompare(length() - srcLength, srcLength,
4370 srcChars, 0, srcLength) == 0;
4371 }
4372
4373 inline UBool
4374 UnicodeString::endsWith(const char16_t *srcChars,
4375 int32_t srcStart,
4376 int32_t srcLength) const {
4377 if(srcLength < 0) {
4378 srcLength = u_strlen(toUCharPtr(srcChars + srcStart));
4379 }
4380 return doCompare(length() - srcLength, srcLength,
4381 srcChars, srcStart, srcLength) == 0;
4382 }
4383
4384 //========================================
4385 // replace
4386 //========================================
4387 inline UnicodeString&
4388 UnicodeString::replace(int32_t start,
4389 int32_t _length,
4390 const UnicodeString& srcText)
4391 { return doReplace(start, _length, srcText, 0, srcText.length()); }
4392
4393 inline UnicodeString&
4394 UnicodeString::replace(int32_t start,
4395 int32_t _length,
4396 const UnicodeString& srcText,
4397 int32_t srcStart,
4398 int32_t srcLength)
4399 { return doReplace(start, _length, srcText, srcStart, srcLength); }
4400
4401 inline UnicodeString&
4402 UnicodeString::replace(int32_t start,
4403 int32_t _length,
4404 ConstChar16Ptr srcChars,
4405 int32_t srcLength)
4406 { return doReplace(start, _length, srcChars, 0, srcLength); }
4407
4408 inline UnicodeString&
4409 UnicodeString::replace(int32_t start,
4410 int32_t _length,
4411 const char16_t *srcChars,
4412 int32_t srcStart,
4413 int32_t srcLength)
4414 { return doReplace(start, _length, srcChars, srcStart, srcLength); }
4415
4416 inline UnicodeString&
4417 UnicodeString::replace(int32_t start,
4418 int32_t _length,
4419 char16_t srcChar)
4420 { return doReplace(start, _length, &srcChar, 0, 1); }
4421
4422 inline UnicodeString&
4423 UnicodeString::replaceBetween(int32_t start,
4424 int32_t limit,
4425 const UnicodeString& srcText)
4426 { return doReplace(start, limit - start, srcText, 0, srcText.length()); }
4427
4428 inline UnicodeString&
4429 UnicodeString::replaceBetween(int32_t start,
4430 int32_t limit,
4431 const UnicodeString& srcText,
4432 int32_t srcStart,
4433 int32_t srcLimit)
4434 { return doReplace(start, limit - start, srcText, srcStart, srcLimit - srcStart); }
4435
4436 inline UnicodeString&
4437 UnicodeString::findAndReplace(const UnicodeString& oldText,
4438 const UnicodeString& newText)
4439 { return findAndReplace(0, length(), oldText, 0, oldText.length(),
4440 newText, 0, newText.length()); }
4441
4442 inline UnicodeString&
4443 UnicodeString::findAndReplace(int32_t start,
4444 int32_t _length,
4445 const UnicodeString& oldText,
4446 const UnicodeString& newText)
4447 { return findAndReplace(start, _length, oldText, 0, oldText.length(),
4448 newText, 0, newText.length()); }
4449
4450 // ============================
4451 // extract
4452 // ============================
4453 inline void
4454 UnicodeString::doExtract(int32_t start,
4455 int32_t _length,
4456 UnicodeString& target) const
4457 { target.replace(0, target.length(), *this, start, _length); }
4458
4459 inline void
4460 UnicodeString::extract(int32_t start,
4461 int32_t _length,
4462 Char16Ptr target,
4463 int32_t targetStart) const
4464 { doExtract(start, _length, target, targetStart); }
4465
4466 inline void
4467 UnicodeString::extract(int32_t start,
4468 int32_t _length,
4469 UnicodeString& target) const
4470 { doExtract(start, _length, target); }
4471
4472 #if !UCONFIG_NO_CONVERSION
4473
4474 inline int32_t
4475 UnicodeString::extract(int32_t start,
4476 int32_t _length,
4477 char *dst,
4478 const char *codepage) const
4479
4480 {
4481 // This dstSize value will be checked explicitly
4482 return extract(start, _length, dst, dst!=0 ? 0xffffffff : 0, codepage);
4483 }
4484
4485 #endif
4486
4487 inline void
4488 UnicodeString::extractBetween(int32_t start,
4489 int32_t limit,
4490 char16_t *dst,
4491 int32_t dstStart) const {
4492 pinIndex(start);
4493 pinIndex(limit);
4494 doExtract(start, limit - start, dst, dstStart);
4495 }
4496
4497 inline UnicodeString
4498 UnicodeString::tempSubStringBetween(int32_t start, int32_t limit) const {
4499 return tempSubString(start, limit - start);
4500 }
4501
4502 inline char16_t
4503 UnicodeString::doCharAt(int32_t offset) const
4504 {
4505 if((uint32_t)offset < (uint32_t)length()) {
4506 return getArrayStart()[offset];
4507 } else {
4508 return kInvalidUChar;
4509 }
4510 }
4511
4512 inline char16_t
4513 UnicodeString::charAt(int32_t offset) const
4514 { return doCharAt(offset); }
4515
4516 inline char16_t
4517 UnicodeString::operator[] (int32_t offset) const
4518 { return doCharAt(offset); }
4519
4520 inline UBool
4521 UnicodeString::isEmpty() const {
4522 // Arithmetic or logical right shift does not matter: only testing for 0.
4523 return (fUnion.fFields.fLengthAndFlags>>kLengthShift) == 0;
4524 }
4525
4526 //========================================
4527 // Write implementation methods
4528 //========================================
4529 inline void
4530 UnicodeString::setZeroLength() {
4531 fUnion.fFields.fLengthAndFlags &= kAllStorageFlags;
4532 }
4533
4534 inline void
4535 UnicodeString::setShortLength(int32_t len) {
4536 // requires 0 <= len <= kMaxShortLength
4537 fUnion.fFields.fLengthAndFlags =
4538 (int16_t)((fUnion.fFields.fLengthAndFlags & kAllStorageFlags) | (len << kLengthShift));
4539 }
4540
4541 inline void
4542 UnicodeString::setLength(int32_t len) {
4543 if(len <= kMaxShortLength) {
4544 setShortLength(len);
4545 } else {
4546 fUnion.fFields.fLengthAndFlags |= kLengthIsLarge;
4547 fUnion.fFields.fLength = len;
4548 }
4549 }
4550
4551 inline void
4552 UnicodeString::setToEmpty() {
4553 fUnion.fFields.fLengthAndFlags = kShortString;
4554 }
4555
4556 inline void
4557 UnicodeString::setArray(char16_t *array, int32_t len, int32_t capacity) {
4558 setLength(len);
4559 fUnion.fFields.fArray = array;
4560 fUnion.fFields.fCapacity = capacity;
4561 }
4562
4563 inline UnicodeString&
4564 UnicodeString::operator= (char16_t ch)
4565 { return doReplace(0, length(), &ch, 0, 1); }
4566
4567 inline UnicodeString&
4568 UnicodeString::operator= (UChar32 ch)
4569 { return replace(0, length(), ch); }
4570
4571 inline UnicodeString&
4572 UnicodeString::setTo(const UnicodeString& srcText,
4573 int32_t srcStart,
4574 int32_t srcLength)
4575 {
4576 unBogus();
4577 return doReplace(0, length(), srcText, srcStart, srcLength);
4578 }
4579
4580 inline UnicodeString&
4581 UnicodeString::setTo(const UnicodeString& srcText,
4582 int32_t srcStart)
4583 {
4584 unBogus();
4585 srcText.pinIndex(srcStart);
4586 return doReplace(0, length(), srcText, srcStart, srcText.length() - srcStart);
4587 }
4588
4589 inline UnicodeString&
4590 UnicodeString::setTo(const UnicodeString& srcText)
4591 {
4592 return copyFrom(srcText);
4593 }
4594
4595 inline UnicodeString&
4596 UnicodeString::setTo(const char16_t *srcChars,
4597 int32_t srcLength)
4598 {
4599 unBogus();
4600 return doReplace(0, length(), srcChars, 0, srcLength);
4601 }
4602
4603 inline UnicodeString&
4604 UnicodeString::setTo(char16_t srcChar)
4605 {
4606 unBogus();
4607 return doReplace(0, length(), &srcChar, 0, 1);
4608 }
4609
4610 inline UnicodeString&
4611 UnicodeString::setTo(UChar32 srcChar)
4612 {
4613 unBogus();
4614 return replace(0, length(), srcChar);
4615 }
4616
4617 inline UnicodeString&
4618 UnicodeString::append(const UnicodeString& srcText,
4619 int32_t srcStart,
4620 int32_t srcLength)
4621 { return doAppend(srcText, srcStart, srcLength); }
4622
4623 inline UnicodeString&
4624 UnicodeString::append(const UnicodeString& srcText)
4625 { return doAppend(srcText, 0, srcText.length()); }
4626
4627 inline UnicodeString&
4628 UnicodeString::append(const char16_t *srcChars,
4629 int32_t srcStart,
4630 int32_t srcLength)
4631 { return doAppend(srcChars, srcStart, srcLength); }
4632
4633 inline UnicodeString&
4634 UnicodeString::append(ConstChar16Ptr srcChars,
4635 int32_t srcLength)
4636 { return doAppend(srcChars, 0, srcLength); }
4637
4638 inline UnicodeString&
4639 UnicodeString::append(char16_t srcChar)
4640 { return doAppend(&srcChar, 0, 1); }
4641
4642 inline UnicodeString&
4643 UnicodeString::operator+= (char16_t ch)
4644 { return doAppend(&ch, 0, 1); }
4645
4646 inline UnicodeString&
4647 UnicodeString::operator+= (UChar32 ch) {
4648 return append(ch);
4649 }
4650
4651 inline UnicodeString&
4652 UnicodeString::operator+= (const UnicodeString& srcText)
4653 { return doAppend(srcText, 0, srcText.length()); }
4654
4655 inline UnicodeString&
4656 UnicodeString::insert(int32_t start,
4657 const UnicodeString& srcText,
4658 int32_t srcStart,
4659 int32_t srcLength)
4660 { return doReplace(start, 0, srcText, srcStart, srcLength); }
4661
4662 inline UnicodeString&
4663 UnicodeString::insert(int32_t start,
4664 const UnicodeString& srcText)
4665 { return doReplace(start, 0, srcText, 0, srcText.length()); }
4666
4667 inline UnicodeString&
4668 UnicodeString::insert(int32_t start,
4669 const char16_t *srcChars,
4670 int32_t srcStart,
4671 int32_t srcLength)
4672 { return doReplace(start, 0, srcChars, srcStart, srcLength); }
4673
4674 inline UnicodeString&
4675 UnicodeString::insert(int32_t start,
4676 ConstChar16Ptr srcChars,
4677 int32_t srcLength)
4678 { return doReplace(start, 0, srcChars, 0, srcLength); }
4679
4680 inline UnicodeString&
4681 UnicodeString::insert(int32_t start,
4682 char16_t srcChar)
4683 { return doReplace(start, 0, &srcChar, 0, 1); }
4684
4685 inline UnicodeString&
4686 UnicodeString::insert(int32_t start,
4687 UChar32 srcChar)
4688 { return replace(start, 0, srcChar); }
4689
4690
4691 inline UnicodeString&
4692 UnicodeString::remove()
4693 {
4694 // remove() of a bogus string makes the string empty and non-bogus
4695 if(isBogus()) {
4696 setToEmpty();
4697 } else {
4698 setZeroLength();
4699 }
4700 return *this;
4701 }
4702
4703 inline UnicodeString&
4704 UnicodeString::remove(int32_t start,
4705 int32_t _length)
4706 {
4707 if(start <= 0 && _length == INT32_MAX) {
4708 // remove(guaranteed everything) of a bogus string makes the string empty and non-bogus
4709 return remove();
4710 }
4711 return doReplace(start, _length, NULL, 0, 0);
4712 }
4713
4714 inline UnicodeString&
4715 UnicodeString::removeBetween(int32_t start,
4716 int32_t limit)
4717 { return doReplace(start, limit - start, NULL, 0, 0); }
4718
4719 inline UnicodeString &
4720 UnicodeString::retainBetween(int32_t start, int32_t limit) {
4721 truncate(limit);
4722 return doReplace(0, start, NULL, 0, 0);
4723 }
4724
4725 inline UBool
4726 UnicodeString::truncate(int32_t targetLength)
4727 {
4728 if(isBogus() && targetLength == 0) {
4729 // truncate(0) of a bogus string makes the string empty and non-bogus
4730 unBogus();
4731 return FALSE;
4732 } else if((uint32_t)targetLength < (uint32_t)length()) {
4733 setLength(targetLength);
4734 return TRUE;
4735 } else {
4736 return FALSE;
4737 }
4738 }
4739
4740 inline UnicodeString&
4741 UnicodeString::reverse()
4742 { return doReverse(0, length()); }
4743
4744 inline UnicodeString&
4745 UnicodeString::reverse(int32_t start,
4746 int32_t _length)
4747 { return doReverse(start, _length); }
4748
4749 U_NAMESPACE_END
4750
4751 #endif
UNISTR_OBJECT_SIZE
#define UNISTR_OBJECT_SIZE
Desired sizeof(UnicodeString) in bytes.
Definition: unistr.h:204
icu::UnicodeString::EInvariant
EInvariant
Constant to be used in the UnicodeString(char *, int32_t, EInvariant) constructor which constructs a ...
Definition: unistr.h:301
icu::UnicodeString::UnicodeString
UnicodeString(wchar_t *buffer, int32_t buffLength, int32_t buffCapacity)
Writable-aliasing wchar_t * constructor.
Definition: unistr.h:3135
icu::Replaceable::copy
virtual void copy(int32_t start, int32_t limit, int32_t dest)=0
Copies a substring of this object, retaining metadata.
icu::operator==
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
U_CALLCONV
#define U_CALLCONV
Similar to U_CDECL_BEGIN/U_CDECL_END, this qualifier is necessary in callback function typedefs to ma...
Definition: platform.h:840
icu::UnicodeString::UnicodeString
UNISTR_FROM_STRING_EXPLICIT UnicodeString(const uint16_t *text)
uint16_t * constructor.
Definition: unistr.h:2990
icu::UnicodeString::UnicodeString
UNISTR_FROM_STRING_EXPLICIT UnicodeString(const wchar_t *text)
wchar_t * constructor.
Definition: unistr.h:3006
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:93
icu::UnicodeString::UnicodeString
UnicodeString(const wchar_t *text, int32_t length)
wchar_t * constructor.
Definition: unistr.h:3053
U_SIZEOF_UCHAR
#define U_SIZEOF_UCHAR
Number of bytes in a UChar.
Definition: umachine.h:280
icu::UnicodeString::UnicodeString
UnicodeString(const uint16_t *text, int32_t length)
uint16_t * constructor.
Definition: unistr.h:3040
icu::Replaceable::extractBetween
virtual void extractBetween(int32_t start, int32_t limit, UnicodeString &target) const =0
Copies characters in the range [start, limit) into the UnicodeString target.
icu::ByteSink
A ByteSink can be filled with bytes.
Definition: bytestream.h:50
icu::Replaceable::getChar32At
virtual UChar32 getChar32At(int32_t offset) const =0
Virtual version of char32At().
UStringCaseMapper
int32_t UStringCaseMapper(int32_t caseLocale, uint32_t options, icu::BreakIterator *iter, char16_t *dest, int32_t destCapacity, const char16_t *src, int32_t srcLength, icu::Edits *edits, UErrorCode &errorCode)
Internal string case mapping function type.
Definition: unistr.h:66
UCONFIG_NO_BREAK_ITERATION
#define UCONFIG_NO_BREAK_ITERATION
This switch turns off break iteration.
Definition: uconfig.h:348
icu::UnicodeString::isBogus
UBool isBogus(void) const
Determine if this object contains a valid string.
Definition: unistr.h:3901
icu::Edits
Records lengths of string edits but not replacement text.
Definition: edits.h:77
stringpiece.h
C++ API: StringPiece: Read-only byte string wrapper class.
icu::Replaceable
Replaceable is an abstract base class representing a string of characters that supports the replaceme...
Definition: rep.h:73
UNISTR_FROM_CHAR_EXPLICIT
#define UNISTR_FROM_CHAR_EXPLICIT
This can be defined to be empty or "explicit".
Definition: unistr.h:146
U_NAMESPACE_BEGIN
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:137
icu::UnicodeString::swap
friend void swap(UnicodeString &s1, UnicodeString &s2) U_NOEXCEPT
Non-member UnicodeString swap function.
Definition: unistr.h:1919
icu::UnicodeString::toUTF8String
StringClass & toUTF8String(StringClass &result) const
Convert the UnicodeString to UTF-8 and append the result to a standard string.
Definition: unistr.h:1723
icu::Replaceable::length
int32_t length() const
Returns the number of 16-bit code units in the text.
Definition: rep.h:245
bytestream.h
C++ API: Interface for writing bytes, and implementation classes.
icu::operator+
U_COMMON_API UnicodeString operator+(const UnicodeString &s1, const UnicodeString &s2)
Create a new UnicodeString with the concatenation of two others.
icu::Replaceable::getLength
virtual int32_t getLength() const =0
Virtual version of length().
icu::BreakIterator
The BreakIterator class implements methods for finding the location of boundaries in text.
Definition: brkiter.h:102
icu::operator!=
UBool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
Definition: stringpiece.h:218
icu::Replaceable::char32At
UChar32 char32At(int32_t offset) const
Returns the 32-bit code point at the given 16-bit offset into the text.
Definition: rep.h:255
UChar32
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
Definition: umachine.h:389
NULL
#define NULL
Define NULL if necessary, to nullptr for C++ and to ((void *)0) for C.
Definition: utypes.h:188
icu::UObject::getDynamicClassID
virtual UClassID getDynamicClassID() const
ICU4C "poor man's RTTI", returns a UClassID for the actual ICU class.
std_string.h
C++ API: Central ICU header for including the C++ standard <string> header and for related definition...
icu::toUCharPtr
const UChar * toUCharPtr(const char16_t *p)
Converts from const char16_t * to const UChar *.
Definition: char16ptr.h:257
icu::Replaceable::getCharAt
virtual char16_t getCharAt(int32_t offset) const =0
Virtual version of charAt().
TRUE
#define TRUE
The TRUE value of a UBool.
Definition: umachine.h:229
U_NOEXCEPT
#define U_NOEXCEPT
"noexcept" if supported, otherwise empty.
Definition: platform.h:503
UChar
uint16_t UChar
The base type for UTF-16 code units and pointers.
Definition: umachine.h:342
icu::UnicodeString::UnicodeString
UnicodeString(uint16_t *buffer, int32_t buffLength, int32_t buffCapacity)
Writable-aliasing uint16_t * constructor.
Definition: unistr.h:3121
U_NAMESPACE_END
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:138
UConverter
struct UConverter UConverter
Definition: ucnv_err.h:96
INT32_MAX
#define INT32_MAX
The largest value a 32 bit signed integer can hold.
Definition: umachine.h:171
UErrorCode
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers,...
Definition: utypes.h:401
icu::Replaceable::charAt
char16_t charAt(int32_t offset) const
Returns the 16-bit code unit at the given offset into the text.
Definition: rep.h:250
icu::UnicodeString::length
int32_t length(void) const
Return the length of the UnicodeString object.
Definition: unistr.h:3886
icu::Char16Ptr
char16_t * wrapper with implicit conversion from distinct but bit-compatible pointer types.
Definition: char16ptr.h:39
icu::ConstChar16Ptr
const char16_t * wrapper with implicit conversion from distinct but bit-compatible pointer types.
Definition: char16ptr.h:146
icu::Replaceable::handleReplaceBetween
virtual void handleReplaceBetween(int32_t start, int32_t limit, const UnicodeString &text)=0
Replaces a substring of this object with the given text.
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
icu::StringByteSink
Implementation of ByteSink that writes to a "string".
Definition: bytestream.h:232
u_strlen
int32_t u_strlen(const UChar *s)
Determine the length of an array of UChar.
icu::Replaceable::clone
virtual Replaceable * clone() const
Clone this object, an instance of a subclass of Replaceable.
FALSE
#define FALSE
The FALSE value of a UBool.
Definition: umachine.h:233
U_COMMON_API
#define U_COMMON_API
Set to export library symbols from inside the common library, and to import them from outside.
Definition: utypes.h:300
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:289
icu::Replaceable::hasMetaData
virtual UBool hasMetaData() const
Returns true if this object contains metadata.
UNISTR_FROM_STRING_EXPLICIT
#define UNISTR_FROM_STRING_EXPLICIT
This can be defined to be empty or "explicit".
Definition: unistr.h:166
icu::StringPiece
A string-like object that points to a sized piece of memory.
Definition: stringpiece.h:54
icu::UnicodeString::replace
UnicodeString & replace(int32_t start, int32_t length, const UnicodeString &srcText, int32_t srcStart, int32_t srcLength)
Replace the characters in the range [start, start + length) with the characters in srcText in the ran...
Definition: unistr.h:4394
U_STABLE
#define U_STABLE
This is used to declare a function as a stable public ICU C API.
Definition: umachine.h:111
UBool
int8_t UBool
The ICU boolean type.
Definition: umachine.h:225
char16ptr.h
C++ API: char16_t pointer wrappers with implicit conversion from bit-compatible raw pointer types.
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:192
rep.h
C++ API: Replaceable String.