ICU 75.1  75.1
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 "unicode/utypes.h"
32 
33 #if U_SHOW_CPLUSPLUS_API
34 
35 #include <cstddef>
36 #include "unicode/char16ptr.h"
37 #include "unicode/rep.h"
38 #include "unicode/std_string.h"
39 #include "unicode/stringpiece.h"
40 #include "unicode/bytestream.h"
41 
42 struct UConverter; // unicode/ucnv.h
43 
44 #ifndef USTRING_H
50 U_CAPI int32_t U_EXPORT2 u_strlen(const UChar *s);
51 #endif
52 
53 U_NAMESPACE_BEGIN
54 
55 #if !UCONFIG_NO_BREAK_ITERATION
56 class BreakIterator; // unicode/brkiter.h
57 #endif
58 class Edits;
59 
60 U_NAMESPACE_END
61 
62 // Not #ifndef U_HIDE_INTERNAL_API because UnicodeString needs the UStringCaseMapper.
69 typedef int32_t U_CALLCONV
70 UStringCaseMapper(int32_t caseLocale, uint32_t options,
72  icu::BreakIterator *iter,
73 #endif
74  char16_t *dest, int32_t destCapacity,
75  const char16_t *src, int32_t srcLength,
76  icu::Edits *edits,
77  UErrorCode &errorCode);
78 
79 U_NAMESPACE_BEGIN
80 
81 class Locale; // unicode/locid.h
82 class StringCharacterIterator;
83 class UnicodeStringAppendable; // unicode/appendable.h
84 
85 /* The <iostream> include has been moved to unicode/ustream.h */
86 
97 #define US_INV icu::UnicodeString::kInvariant
98 
116 #if !U_CHAR16_IS_TYPEDEF
117 # define UNICODE_STRING(cs, _length) icu::UnicodeString(true, u ## cs, _length)
118 #else
119 # define UNICODE_STRING(cs, _length) icu::UnicodeString(true, (const char16_t*)u ## cs, _length)
120 #endif
121 
135 #define UNICODE_STRING_SIMPLE(cs) UNICODE_STRING(cs, -1)
136 
144 #ifndef UNISTR_FROM_CHAR_EXPLICIT
145 # if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION)
146  // Auto-"explicit" in ICU library code.
147 # define UNISTR_FROM_CHAR_EXPLICIT explicit
148 # else
149  // Empty by default for source code compatibility.
150 # define UNISTR_FROM_CHAR_EXPLICIT
151 # endif
152 #endif
153 
164 #ifndef UNISTR_FROM_STRING_EXPLICIT
165 # if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION)
166  // Auto-"explicit" in ICU library code.
167 # define UNISTR_FROM_STRING_EXPLICIT explicit
168 # else
169  // Empty by default for source code compatibility.
170 # define UNISTR_FROM_STRING_EXPLICIT
171 # endif
172 #endif
173 
207 #ifndef UNISTR_OBJECT_SIZE
208 # define UNISTR_OBJECT_SIZE 64
209 #endif
210 
296 {
297 public:
298 
307  enum EInvariant {
312  kInvariant
313  };
314 
315  //========================================
316  // Read-only operations
317  //========================================
318 
319  /* Comparison - bitwise only - for international comparison use collation */
320 
328  inline bool operator== (const UnicodeString& text) const;
329 
337  inline bool operator!= (const UnicodeString& text) const;
338 
346  inline UBool operator> (const UnicodeString& text) const;
347 
355  inline UBool operator< (const UnicodeString& text) const;
356 
364  inline UBool operator>= (const UnicodeString& text) const;
365 
373  inline UBool operator<= (const UnicodeString& text) const;
374 
386  inline int8_t compare(const UnicodeString& text) const;
387 
403  inline int8_t compare(int32_t start,
404  int32_t length,
405  const UnicodeString& text) const;
406 
424  inline int8_t compare(int32_t start,
425  int32_t length,
426  const UnicodeString& srcText,
427  int32_t srcStart,
428  int32_t srcLength) const;
429 
442  inline int8_t compare(ConstChar16Ptr srcChars,
443  int32_t srcLength) const;
444 
459  inline int8_t compare(int32_t start,
460  int32_t length,
461  const char16_t *srcChars) const;
462 
480  inline int8_t compare(int32_t start,
481  int32_t length,
482  const char16_t *srcChars,
483  int32_t srcStart,
484  int32_t srcLength) const;
485 
503  inline int8_t compareBetween(int32_t start,
504  int32_t limit,
505  const UnicodeString& srcText,
506  int32_t srcStart,
507  int32_t srcLimit) const;
508 
526  inline int8_t compareCodePointOrder(const UnicodeString& text) const;
527 
547  inline int8_t compareCodePointOrder(int32_t start,
548  int32_t length,
549  const UnicodeString& srcText) const;
550 
572  inline int8_t compareCodePointOrder(int32_t start,
573  int32_t length,
574  const UnicodeString& srcText,
575  int32_t srcStart,
576  int32_t srcLength) const;
577 
596  inline int8_t compareCodePointOrder(ConstChar16Ptr srcChars,
597  int32_t srcLength) const;
598 
618  inline int8_t compareCodePointOrder(int32_t start,
619  int32_t length,
620  const char16_t *srcChars) const;
621 
643  inline int8_t compareCodePointOrder(int32_t start,
644  int32_t length,
645  const char16_t *srcChars,
646  int32_t srcStart,
647  int32_t srcLength) const;
648 
670  inline int8_t compareCodePointOrderBetween(int32_t start,
671  int32_t limit,
672  const UnicodeString& srcText,
673  int32_t srcStart,
674  int32_t srcLimit) const;
675 
694  inline int8_t caseCompare(const UnicodeString& text, uint32_t options) const;
695 
716  inline int8_t caseCompare(int32_t start,
717  int32_t length,
718  const UnicodeString& srcText,
719  uint32_t options) const;
720 
743  inline int8_t caseCompare(int32_t start,
744  int32_t length,
745  const UnicodeString& srcText,
746  int32_t srcStart,
747  int32_t srcLength,
748  uint32_t options) const;
749 
769  inline int8_t caseCompare(ConstChar16Ptr srcChars,
770  int32_t srcLength,
771  uint32_t options) const;
772 
793  inline int8_t caseCompare(int32_t start,
794  int32_t length,
795  const char16_t *srcChars,
796  uint32_t options) const;
797 
820  inline int8_t caseCompare(int32_t start,
821  int32_t length,
822  const char16_t *srcChars,
823  int32_t srcStart,
824  int32_t srcLength,
825  uint32_t options) const;
826 
849  inline int8_t caseCompareBetween(int32_t start,
850  int32_t limit,
851  const UnicodeString& srcText,
852  int32_t srcStart,
853  int32_t srcLimit,
854  uint32_t options) const;
855 
863  inline UBool startsWith(const UnicodeString& text) const;
864 
875  inline UBool startsWith(const UnicodeString& srcText,
876  int32_t srcStart,
877  int32_t srcLength) const;
878 
887  inline UBool startsWith(ConstChar16Ptr srcChars,
888  int32_t srcLength) const;
889 
899  inline UBool startsWith(const char16_t *srcChars,
900  int32_t srcStart,
901  int32_t srcLength) const;
902 
910  inline UBool endsWith(const UnicodeString& text) const;
911 
922  inline UBool endsWith(const UnicodeString& srcText,
923  int32_t srcStart,
924  int32_t srcLength) const;
925 
934  inline UBool endsWith(ConstChar16Ptr srcChars,
935  int32_t srcLength) const;
936 
947  inline UBool endsWith(const char16_t *srcChars,
948  int32_t srcStart,
949  int32_t srcLength) const;
950 
951 
952  /* Searching - bitwise only */
953 
962  inline int32_t indexOf(const UnicodeString& text) const;
963 
973  inline int32_t indexOf(const UnicodeString& text,
974  int32_t start) const;
975 
987  inline int32_t indexOf(const UnicodeString& text,
988  int32_t start,
989  int32_t length) const;
990 
1007  inline int32_t indexOf(const UnicodeString& srcText,
1008  int32_t srcStart,
1009  int32_t srcLength,
1010  int32_t start,
1011  int32_t length) const;
1012 
1024  inline int32_t indexOf(const char16_t *srcChars,
1025  int32_t srcLength,
1026  int32_t start) const;
1027 
1040  inline int32_t indexOf(ConstChar16Ptr srcChars,
1041  int32_t srcLength,
1042  int32_t start,
1043  int32_t length) const;
1044 
1061  int32_t indexOf(const char16_t *srcChars,
1062  int32_t srcStart,
1063  int32_t srcLength,
1064  int32_t start,
1065  int32_t length) const;
1066 
1074  inline int32_t indexOf(char16_t c) const;
1075 
1084  inline int32_t indexOf(UChar32 c) const;
1085 
1094  inline int32_t indexOf(char16_t c,
1095  int32_t start) const;
1096 
1106  inline int32_t indexOf(UChar32 c,
1107  int32_t start) const;
1108 
1119  inline int32_t indexOf(char16_t c,
1120  int32_t start,
1121  int32_t length) const;
1122 
1134  inline int32_t indexOf(UChar32 c,
1135  int32_t start,
1136  int32_t length) const;
1137 
1146  inline int32_t lastIndexOf(const UnicodeString& text) const;
1147 
1157  inline int32_t lastIndexOf(const UnicodeString& text,
1158  int32_t start) const;
1159 
1171  inline int32_t lastIndexOf(const UnicodeString& text,
1172  int32_t start,
1173  int32_t length) const;
1174 
1191  inline int32_t lastIndexOf(const UnicodeString& srcText,
1192  int32_t srcStart,
1193  int32_t srcLength,
1194  int32_t start,
1195  int32_t length) const;
1196 
1207  inline int32_t lastIndexOf(const char16_t *srcChars,
1208  int32_t srcLength,
1209  int32_t start) const;
1210 
1223  inline int32_t lastIndexOf(ConstChar16Ptr srcChars,
1224  int32_t srcLength,
1225  int32_t start,
1226  int32_t length) const;
1227 
1244  int32_t lastIndexOf(const char16_t *srcChars,
1245  int32_t srcStart,
1246  int32_t srcLength,
1247  int32_t start,
1248  int32_t length) const;
1249 
1257  inline int32_t lastIndexOf(char16_t c) const;
1258 
1267  inline int32_t lastIndexOf(UChar32 c) const;
1268 
1277  inline int32_t lastIndexOf(char16_t c,
1278  int32_t start) const;
1279 
1289  inline int32_t lastIndexOf(UChar32 c,
1290  int32_t start) const;
1291 
1302  inline int32_t lastIndexOf(char16_t c,
1303  int32_t start,
1304  int32_t length) const;
1305 
1317  inline int32_t lastIndexOf(UChar32 c,
1318  int32_t start,
1319  int32_t length) const;
1320 
1321 
1322  /* Character access */
1323 
1332  inline char16_t charAt(int32_t offset) const;
1333 
1341  inline char16_t operator[] (int32_t offset) const;
1342 
1354  UChar32 char32At(int32_t offset) const;
1355 
1371  int32_t getChar32Start(int32_t offset) const;
1372 
1389  int32_t getChar32Limit(int32_t offset) const;
1390 
1441  int32_t moveIndex32(int32_t index, int32_t delta) const;
1442 
1443  /* Substring extraction */
1444 
1460  inline void extract(int32_t start,
1461  int32_t length,
1462  Char16Ptr dst,
1463  int32_t dstStart = 0) const;
1464 
1486  int32_t
1487  extract(Char16Ptr dest, int32_t destCapacity,
1488  UErrorCode &errorCode) const;
1489 
1499  inline void extract(int32_t start,
1500  int32_t length,
1501  UnicodeString& target) const;
1502 
1514  inline void extractBetween(int32_t start,
1515  int32_t limit,
1516  char16_t *dst,
1517  int32_t dstStart = 0) const;
1518 
1527  virtual void extractBetween(int32_t start,
1528  int32_t limit,
1529  UnicodeString& target) const override;
1530 
1552  int32_t extract(int32_t start,
1553  int32_t startLength,
1554  char *target,
1555  int32_t targetCapacity,
1556  enum EInvariant inv) const;
1557 
1558 #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
1559 
1579  int32_t extract(int32_t start,
1580  int32_t startLength,
1581  char *target,
1582  uint32_t targetLength) const;
1583 
1584 #endif
1585 
1586 #if !UCONFIG_NO_CONVERSION
1587 
1613  inline int32_t extract(int32_t start,
1614  int32_t startLength,
1615  char* target,
1616  const char* codepage = nullptr) const;
1617 
1647  int32_t extract(int32_t start,
1648  int32_t startLength,
1649  char *target,
1650  uint32_t targetLength,
1651  const char *codepage) const;
1652 
1670  int32_t extract(char *dest, int32_t destCapacity,
1671  UConverter *cnv,
1672  UErrorCode &errorCode) const;
1673 
1674 #endif
1675 
1689  UnicodeString tempSubString(int32_t start=0, int32_t length=INT32_MAX) const;
1690 
1701  inline UnicodeString tempSubStringBetween(int32_t start, int32_t limit=INT32_MAX) const;
1702 
1714  void toUTF8(ByteSink &sink) const;
1715 
1728  template<typename StringClass>
1729  StringClass &toUTF8String(StringClass &result) const {
1730  StringByteSink<StringClass> sbs(&result, length());
1731  toUTF8(sbs);
1732  return result;
1733  }
1734 
1750  int32_t toUTF32(UChar32 *utf32, int32_t capacity, UErrorCode &errorCode) const;
1751 
1752  /* Length operations */
1753 
1762  inline int32_t length() const;
1763 
1777  int32_t
1778  countChar32(int32_t start=0, int32_t length=INT32_MAX) const;
1779 
1803  UBool
1804  hasMoreChar32Than(int32_t start, int32_t length, int32_t number) const;
1805 
1811  inline UBool isEmpty() const;
1812 
1822  inline int32_t getCapacity() const;
1823 
1824  /* Other operations */
1825 
1831  inline int32_t hashCode() const;
1832 
1845  inline UBool isBogus() const;
1846 
1847  //========================================
1848  // Write operations
1849  //========================================
1850 
1851  /* Assignment operations */
1852 
1872 
1899 
1909 
1915  void swap(UnicodeString &other) noexcept;
1916 
1923  friend inline void U_EXPORT2
1924  swap(UnicodeString &s1, UnicodeString &s2) noexcept {
1925  s1.swap(s2);
1926  }
1927 
1935  inline UnicodeString& operator= (char16_t ch);
1936 
1944  inline UnicodeString& operator= (UChar32 ch);
1945 
1957  inline UnicodeString& setTo(const UnicodeString& srcText,
1958  int32_t srcStart);
1959 
1973  inline UnicodeString& setTo(const UnicodeString& srcText,
1974  int32_t srcStart,
1975  int32_t srcLength);
1976 
1985  inline UnicodeString& setTo(const UnicodeString& srcText);
1986 
1995  inline UnicodeString& setTo(const char16_t *srcChars,
1996  int32_t srcLength);
1997 
2006  inline UnicodeString& setTo(char16_t srcChar);
2007 
2016  inline UnicodeString& setTo(UChar32 srcChar);
2017 
2041  UnicodeString &setTo(UBool isTerminated,
2042  ConstChar16Ptr text,
2043  int32_t textLength);
2044 
2064  UnicodeString &setTo(char16_t *buffer,
2065  int32_t buffLength,
2066  int32_t buffCapacity);
2067 
2107  void setToBogus();
2108 
2116  UnicodeString& setCharAt(int32_t offset,
2117  char16_t ch);
2118 
2119 
2120  /* Append operations */
2121 
2129  inline UnicodeString& operator+= (char16_t ch);
2130 
2138  inline UnicodeString& operator+= (UChar32 ch);
2139 
2147  inline UnicodeString& operator+= (const UnicodeString& srcText);
2148 
2163  inline UnicodeString& append(const UnicodeString& srcText,
2164  int32_t srcStart,
2165  int32_t srcLength);
2166 
2174  inline UnicodeString& append(const UnicodeString& srcText);
2175 
2189  inline UnicodeString& append(const char16_t *srcChars,
2190  int32_t srcStart,
2191  int32_t srcLength);
2192 
2202  inline UnicodeString& append(ConstChar16Ptr srcChars,
2203  int32_t srcLength);
2204 
2211  inline UnicodeString& append(char16_t srcChar);
2212 
2220 
2221 
2222  /* Insert operations */
2223 
2237  inline UnicodeString& insert(int32_t start,
2238  const UnicodeString& srcText,
2239  int32_t srcStart,
2240  int32_t srcLength);
2241 
2250  inline UnicodeString& insert(int32_t start,
2251  const UnicodeString& srcText);
2252 
2266  inline UnicodeString& insert(int32_t start,
2267  const char16_t *srcChars,
2268  int32_t srcStart,
2269  int32_t srcLength);
2270 
2280  inline UnicodeString& insert(int32_t start,
2281  ConstChar16Ptr srcChars,
2282  int32_t srcLength);
2283 
2292  inline UnicodeString& insert(int32_t start,
2293  char16_t srcChar);
2294 
2303  inline UnicodeString& insert(int32_t start,
2304  UChar32 srcChar);
2305 
2306 
2307  /* Replace operations */
2308 
2326  inline UnicodeString& replace(int32_t start,
2327  int32_t length,
2328  const UnicodeString& srcText,
2329  int32_t srcStart,
2330  int32_t srcLength);
2331 
2344  inline UnicodeString& replace(int32_t start,
2345  int32_t length,
2346  const UnicodeString& srcText);
2347 
2365  inline UnicodeString& replace(int32_t start,
2366  int32_t length,
2367  const char16_t *srcChars,
2368  int32_t srcStart,
2369  int32_t srcLength);
2370 
2383  inline UnicodeString& replace(int32_t start,
2384  int32_t length,
2385  ConstChar16Ptr srcChars,
2386  int32_t srcLength);
2387 
2399  inline UnicodeString& replace(int32_t start,
2400  int32_t length,
2401  char16_t srcChar);
2402 
2414  UnicodeString& replace(int32_t start, int32_t length, UChar32 srcChar);
2415 
2425  inline UnicodeString& replaceBetween(int32_t start,
2426  int32_t limit,
2427  const UnicodeString& srcText);
2428 
2443  inline UnicodeString& replaceBetween(int32_t start,
2444  int32_t limit,
2445  const UnicodeString& srcText,
2446  int32_t srcStart,
2447  int32_t srcLimit);
2448 
2456  virtual void handleReplaceBetween(int32_t start,
2457  int32_t limit,
2458  const UnicodeString& text) override;
2459 
2465  virtual UBool hasMetaData() const override;
2466 
2480  virtual void copy(int32_t start, int32_t limit, int32_t dest) override;
2481 
2482  /* Search and replace operations */
2483 
2492  inline UnicodeString& findAndReplace(const UnicodeString& oldText,
2493  const UnicodeString& newText);
2494 
2506  inline UnicodeString& findAndReplace(int32_t start,
2507  int32_t length,
2508  const UnicodeString& oldText,
2509  const UnicodeString& newText);
2510 
2529  int32_t length,
2530  const UnicodeString& oldText,
2531  int32_t oldStart,
2532  int32_t oldLength,
2533  const UnicodeString& newText,
2534  int32_t newStart,
2535  int32_t newLength);
2536 
2537 
2538  /* Remove operations */
2539 
2548  inline UnicodeString& remove();
2549 
2558  inline UnicodeString& remove(int32_t start,
2559  int32_t length = (int32_t)INT32_MAX);
2560 
2569  inline UnicodeString& removeBetween(int32_t start,
2570  int32_t limit = (int32_t)INT32_MAX);
2571 
2581  inline UnicodeString &retainBetween(int32_t start, int32_t limit = INT32_MAX);
2582 
2583  /* Length operations */
2584 
2596  UBool padLeading(int32_t targetLength,
2597  char16_t padChar = 0x0020);
2598 
2610  UBool padTrailing(int32_t targetLength,
2611  char16_t padChar = 0x0020);
2612 
2619  inline UBool truncate(int32_t targetLength);
2620 
2627 
2628  /* Miscellaneous operations */
2629 
2635  inline UnicodeString& reverse();
2636 
2645  inline UnicodeString& reverse(int32_t start,
2646  int32_t length);
2647 
2655 
2663  UnicodeString& toUpper(const Locale& locale);
2664 
2672 
2680  UnicodeString& toLower(const Locale& locale);
2681 
2682 #if !UCONFIG_NO_BREAK_ITERATION
2683 
2711 
2739  UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale);
2740 
2771  UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale, uint32_t options);
2772 
2773 #endif
2774 
2788  UnicodeString &foldCase(uint32_t options=0 /*U_FOLD_CASE_DEFAULT*/);
2789 
2790  //========================================
2791  // Access to the internal buffer
2792  //========================================
2793 
2837  char16_t *getBuffer(int32_t minCapacity);
2838 
2859  void releaseBuffer(int32_t newLength=-1);
2860 
2891  inline const char16_t *getBuffer() const;
2892 
2926  const char16_t *getTerminatedBuffer();
2927 
2928  //========================================
2929  // Constructors
2930  //========================================
2931 
2935  inline UnicodeString();
2936 
2948  UnicodeString(int32_t capacity, UChar32 c, int32_t count);
2949 
2960 
2971 
2983 
2984 #if !U_CHAR16_IS_TYPEDEF
2996  UnicodeString(ConstChar16Ptr(text)) {}
2997 #endif
2998 
2999 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
3012  UnicodeString(ConstChar16Ptr(text)) {}
3013 #endif
3014 
3025  UNISTR_FROM_STRING_EXPLICIT inline UnicodeString(const std::nullptr_t text);
3026 
3034  UnicodeString(const char16_t *text,
3035  int32_t textLength);
3036 
3037 #if !U_CHAR16_IS_TYPEDEF
3045  UnicodeString(const uint16_t *text, int32_t textLength) :
3046  UnicodeString(ConstChar16Ptr(text), textLength) {}
3047 #endif
3048 
3049 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
3058  UnicodeString(const wchar_t *text, int32_t textLength) :
3059  UnicodeString(ConstChar16Ptr(text), textLength) {}
3060 #endif
3061 
3069  inline UnicodeString(const std::nullptr_t text, int32_t textLength);
3070 
3093  UnicodeString(UBool isTerminated,
3094  ConstChar16Ptr text,
3095  int32_t textLength);
3096 
3115  UnicodeString(char16_t *buffer, int32_t buffLength, int32_t buffCapacity);
3116 
3117 #if !U_CHAR16_IS_TYPEDEF
3126  UnicodeString(uint16_t *buffer, int32_t buffLength, int32_t buffCapacity) :
3127  UnicodeString(Char16Ptr(buffer), buffLength, buffCapacity) {}
3128 #endif
3129 
3130 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
3140  UnicodeString(wchar_t *buffer, int32_t buffLength, int32_t buffCapacity) :
3141  UnicodeString(Char16Ptr(buffer), buffLength, buffCapacity) {}
3142 #endif
3143 
3152  inline UnicodeString(std::nullptr_t buffer, int32_t buffLength, int32_t buffCapacity);
3153 
3154 #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
3155 
3175  UNISTR_FROM_STRING_EXPLICIT UnicodeString(const char *codepageData);
3176 
3185  UnicodeString(const char *codepageData, int32_t dataLength);
3186 
3187 #endif
3188 
3189 #if !UCONFIG_NO_CONVERSION
3190 
3208  UnicodeString(const char *codepageData, const char *codepage);
3209 
3227  UnicodeString(const char *codepageData, int32_t dataLength, const char *codepage);
3228 
3251  const char *src, int32_t srcLength,
3252  UConverter *cnv,
3253  UErrorCode &errorCode);
3254 
3255 #endif
3256 
3280  UnicodeString(const char *src, int32_t textLength, enum EInvariant inv);
3281 
3282 
3300 
3307  UnicodeString(UnicodeString &&src) noexcept;
3308 
3315  UnicodeString(const UnicodeString& src, int32_t srcStart);
3316 
3324  UnicodeString(const UnicodeString& src, int32_t srcStart, int32_t srcLength);
3325 
3339  virtual UnicodeString *clone() const override;
3340 
3344  virtual ~UnicodeString();
3345 
3360 
3372  static UnicodeString fromUTF32(const UChar32 *utf32, int32_t length);
3373 
3374  /* Miscellaneous operations */
3375 
3411 
3431  UChar32 unescapeAt(int32_t &offset) const;
3432 
3438  static UClassID U_EXPORT2 getStaticClassID();
3439 
3445  virtual UClassID getDynamicClassID() const override;
3446 
3447  //========================================
3448  // Implementation methods
3449  //========================================
3450 
3451 protected:
3456  virtual int32_t getLength() const override;
3457 
3463  virtual char16_t getCharAt(int32_t offset) const override;
3464 
3470  virtual UChar32 getChar32At(int32_t offset) const override;
3471 
3472 private:
3473  // For char* constructors. Could be made public.
3474  UnicodeString &setToUTF8(StringPiece utf8);
3475  // For extract(char*).
3476  // We could make a toUTF8(target, capacity, errorCode) public but not
3477  // this version: New API will be cleaner if we make callers create substrings
3478  // rather than having start+length on every method,
3479  // and it should take a UErrorCode&.
3480  int32_t
3481  toUTF8(int32_t start, int32_t len,
3482  char *target, int32_t capacity) const;
3483 
3488  UBool doEquals(const UnicodeString &text, int32_t len) const;
3489 
3490  inline UBool
3491  doEqualsSubstring(int32_t start,
3492  int32_t length,
3493  const UnicodeString& srcText,
3494  int32_t srcStart,
3495  int32_t srcLength) const;
3496 
3497  UBool doEqualsSubstring(int32_t start,
3498  int32_t length,
3499  const char16_t *srcChars,
3500  int32_t srcStart,
3501  int32_t srcLength) const;
3502 
3503  inline int8_t
3504  doCompare(int32_t start,
3505  int32_t length,
3506  const UnicodeString& srcText,
3507  int32_t srcStart,
3508  int32_t srcLength) const;
3509 
3510  int8_t doCompare(int32_t start,
3511  int32_t length,
3512  const char16_t *srcChars,
3513  int32_t srcStart,
3514  int32_t srcLength) const;
3515 
3516  inline int8_t
3517  doCompareCodePointOrder(int32_t start,
3518  int32_t length,
3519  const UnicodeString& srcText,
3520  int32_t srcStart,
3521  int32_t srcLength) const;
3522 
3523  int8_t doCompareCodePointOrder(int32_t start,
3524  int32_t length,
3525  const char16_t *srcChars,
3526  int32_t srcStart,
3527  int32_t srcLength) const;
3528 
3529  inline int8_t
3530  doCaseCompare(int32_t start,
3531  int32_t length,
3532  const UnicodeString &srcText,
3533  int32_t srcStart,
3534  int32_t srcLength,
3535  uint32_t options) const;
3536 
3537  int8_t
3538  doCaseCompare(int32_t start,
3539  int32_t length,
3540  const char16_t *srcChars,
3541  int32_t srcStart,
3542  int32_t srcLength,
3543  uint32_t options) const;
3544 
3545  int32_t doIndexOf(char16_t c,
3546  int32_t start,
3547  int32_t length) const;
3548 
3549  int32_t doIndexOf(UChar32 c,
3550  int32_t start,
3551  int32_t length) const;
3552 
3553  int32_t doLastIndexOf(char16_t c,
3554  int32_t start,
3555  int32_t length) const;
3556 
3557  int32_t doLastIndexOf(UChar32 c,
3558  int32_t start,
3559  int32_t length) const;
3560 
3561  void doExtract(int32_t start,
3562  int32_t length,
3563  char16_t *dst,
3564  int32_t dstStart) const;
3565 
3566  inline void doExtract(int32_t start,
3567  int32_t length,
3568  UnicodeString& target) const;
3569 
3570  inline char16_t doCharAt(int32_t offset) const;
3571 
3572  UnicodeString& doReplace(int32_t start,
3573  int32_t length,
3574  const UnicodeString& srcText,
3575  int32_t srcStart,
3576  int32_t srcLength);
3577 
3578  UnicodeString& doReplace(int32_t start,
3579  int32_t length,
3580  const char16_t *srcChars,
3581  int32_t srcStart,
3582  int32_t srcLength);
3583 
3584  UnicodeString& doAppend(const UnicodeString& src, int32_t srcStart, int32_t srcLength);
3585  UnicodeString& doAppend(const char16_t *srcChars, int32_t srcStart, int32_t srcLength);
3586 
3587  UnicodeString& doReverse(int32_t start,
3588  int32_t length);
3589 
3590  // calculate hash code
3591  int32_t doHashCode() const;
3592 
3593  // get pointer to start of array
3594  // these do not check for kOpenGetBuffer, unlike the public getBuffer() function
3595  inline char16_t* getArrayStart();
3596  inline const char16_t* getArrayStart() const;
3597 
3598  inline UBool hasShortLength() const;
3599  inline int32_t getShortLength() const;
3600 
3601  // A UnicodeString object (not necessarily its current buffer)
3602  // is writable unless it isBogus() or it has an "open" getBuffer(minCapacity).
3603  inline UBool isWritable() const;
3604 
3605  // Is the current buffer writable?
3606  inline UBool isBufferWritable() const;
3607 
3608  // None of the following does releaseArray().
3609  inline void setZeroLength();
3610  inline void setShortLength(int32_t len);
3611  inline void setLength(int32_t len);
3612  inline void setToEmpty();
3613  inline void setArray(char16_t *array, int32_t len, int32_t capacity); // sets length but not flags
3614 
3615  // allocate the array; result may be the stack buffer
3616  // sets refCount to 1 if appropriate
3617  // sets fArray, fCapacity, and flags
3618  // sets length to 0
3619  // returns boolean for success or failure
3620  UBool allocate(int32_t capacity);
3621 
3622  // release the array if owned
3623  void releaseArray();
3624 
3625  // turn a bogus string into an empty one
3626  void unBogus();
3627 
3628  // implements assignment operator, copy constructor, and fastCopyFrom()
3629  UnicodeString &copyFrom(const UnicodeString &src, UBool fastCopy=false);
3630 
3631  // Copies just the fields without memory management.
3632  void copyFieldsFrom(UnicodeString &src, UBool setSrcToBogus) noexcept;
3633 
3634  // Pin start and limit to acceptable values.
3635  inline void pinIndex(int32_t& start) const;
3636  inline void pinIndices(int32_t& start,
3637  int32_t& length) const;
3638 
3639 #if !UCONFIG_NO_CONVERSION
3640 
3641  /* Internal extract() using UConverter. */
3642  int32_t doExtract(int32_t start, int32_t length,
3643  char *dest, int32_t destCapacity,
3644  UConverter *cnv,
3645  UErrorCode &errorCode) const;
3646 
3647  /*
3648  * Real constructor for converting from codepage data.
3649  * It assumes that it is called with !fRefCounted.
3650  *
3651  * If `codepage==0`, then the default converter
3652  * is used for the platform encoding.
3653  * If `codepage` is an empty string (`""`),
3654  * then a simple conversion is performed on the codepage-invariant
3655  * subset ("invariant characters") of the platform encoding. See utypes.h.
3656  */
3657  void doCodepageCreate(const char *codepageData,
3658  int32_t dataLength,
3659  const char *codepage);
3660 
3661  /*
3662  * Worker function for creating a UnicodeString from
3663  * a codepage string using a UConverter.
3664  */
3665  void
3666  doCodepageCreate(const char *codepageData,
3667  int32_t dataLength,
3668  UConverter *converter,
3669  UErrorCode &status);
3670 
3671 #endif
3672 
3673  /*
3674  * This function is called when write access to the array
3675  * is necessary.
3676  *
3677  * We need to make a copy of the array if
3678  * the buffer is read-only, or
3679  * the buffer is refCounted (shared), and refCount>1, or
3680  * the buffer is too small.
3681  *
3682  * Return false if memory could not be allocated.
3683  */
3684  UBool cloneArrayIfNeeded(int32_t newCapacity = -1,
3685  int32_t growCapacity = -1,
3686  UBool doCopyArray = true,
3687  int32_t** pBufferToDelete = nullptr,
3688  UBool forceClone = false);
3689 
3695  UnicodeString &
3696  caseMap(int32_t caseLocale, uint32_t options,
3698  BreakIterator *iter,
3699 #endif
3700  UStringCaseMapper *stringCaseMapper);
3701 
3702  // ref counting
3703  void addRef();
3704  int32_t removeRef();
3705  int32_t refCount() const;
3706 
3707  // constants
3708  enum {
3714  US_STACKBUF_SIZE=(int32_t)(UNISTR_OBJECT_SIZE-sizeof(void *)-2)/U_SIZEOF_UCHAR,
3715  kInvalidUChar=0xffff, // U+FFFF returned by charAt(invalid index)
3716  kInvalidHashCode=0, // invalid hash code
3717  kEmptyHashCode=1, // hash code for empty string
3718 
3719  // bit flag values for fLengthAndFlags
3720  kIsBogus=1, // this string is bogus, i.e., not valid or nullptr
3721  kUsingStackBuffer=2,// using fUnion.fStackFields instead of fUnion.fFields
3722  kRefCounted=4, // there is a refCount field before the characters in fArray
3723  kBufferIsReadonly=8,// do not write to this buffer
3724  kOpenGetBuffer=16, // getBuffer(minCapacity) was called (is "open"),
3725  // and releaseBuffer(newLength) must be called
3726  kAllStorageFlags=0x1f,
3727 
3728  kLengthShift=5, // remaining 11 bits for non-negative short length, or negative if long
3729  kLength1=1<<kLengthShift,
3730  kMaxShortLength=0x3ff, // max non-negative short length (leaves top bit 0)
3731  kLengthIsLarge=0xffe0, // short length < 0, real length is in fUnion.fFields.fLength
3732 
3733  // combined values for convenience
3734  kShortString=kUsingStackBuffer,
3735  kLongString=kRefCounted,
3736  kReadonlyAlias=kBufferIsReadonly,
3737  kWritableAlias=0
3738  };
3739 
3740  friend class UnicodeStringAppendable;
3741 
3742  union StackBufferOrFields; // forward declaration necessary before friend declaration
3743  friend union StackBufferOrFields; // make US_STACKBUF_SIZE visible inside fUnion
3744 
3745  /*
3746  * The following are all the class fields that are stored
3747  * in each UnicodeString object.
3748  * Note that UnicodeString has virtual functions,
3749  * therefore there is an implicit vtable pointer
3750  * as the first real field.
3751  * The fields should be aligned such that no padding is necessary.
3752  * On 32-bit machines, the size should be 32 bytes,
3753  * on 64-bit machines (8-byte pointers), it should be 40 bytes.
3754  *
3755  * We use a hack to achieve this.
3756  *
3757  * With at least some compilers, each of the following is forced to
3758  * a multiple of sizeof(pointer) [the largest field base unit here is a data pointer],
3759  * rounded up with additional padding if the fields do not already fit that requirement:
3760  * - sizeof(class UnicodeString)
3761  * - offsetof(UnicodeString, fUnion)
3762  * - sizeof(fUnion)
3763  * - sizeof(fStackFields)
3764  *
3765  * We optimize for the longest possible internal buffer for short strings.
3766  * fUnion.fStackFields begins with 2 bytes for storage flags
3767  * and the length of relatively short strings,
3768  * followed by the buffer for short string contents.
3769  * There is no padding inside fStackFields.
3770  *
3771  * Heap-allocated and aliased strings use fUnion.fFields.
3772  * Both fStackFields and fFields must begin with the same fields for flags and short length,
3773  * that is, those must have the same memory offsets inside the object,
3774  * because the flags must be inspected in order to decide which half of fUnion is being used.
3775  * We assume that the compiler does not reorder the fields.
3776  *
3777  * (Padding at the end of fFields is ok:
3778  * As long as it is no larger than fStackFields, it is not wasted space.)
3779  *
3780  * For some of the history of the UnicodeString class fields layout, see
3781  * - ICU ticket #11551 "longer UnicodeString contents in stack buffer"
3782  * - ICU ticket #11336 "UnicodeString: recombine stack buffer arrays"
3783  * - ICU ticket #8322 "why is sizeof(UnicodeString)==48?"
3784  */
3785  // (implicit) *vtable;
3786  union StackBufferOrFields {
3787  // fStackFields is used iff (fLengthAndFlags&kUsingStackBuffer) else fFields is used.
3788  // Each struct of the union must begin with fLengthAndFlags.
3789  struct {
3790  int16_t fLengthAndFlags; // bit fields: see constants above
3791  char16_t fBuffer[US_STACKBUF_SIZE]; // buffer for short strings
3792  } fStackFields;
3793  struct {
3794  int16_t fLengthAndFlags; // bit fields: see constants above
3795  int32_t fLength; // number of characters in fArray if >127; else undefined
3796  int32_t fCapacity; // capacity of fArray (in char16_ts)
3797  // array pointer last to minimize padding for machines with P128 data model
3798  // or pointer sizes that are not a power of 2
3799  char16_t *fArray; // the Unicode data
3800  } fFields;
3801  } fUnion;
3802 };
3803 
3812 U_COMMON_API UnicodeString U_EXPORT2
3814 
3815 //========================================
3816 // Inline members
3817 //========================================
3818 
3819 //========================================
3820 // Privates
3821 //========================================
3822 
3823 inline void
3824 UnicodeString::pinIndex(int32_t& start) const
3825 {
3826  // pin index
3827  if(start < 0) {
3828  start = 0;
3829  } else if(start > length()) {
3830  start = length();
3831  }
3832 }
3833 
3834 inline void
3835 UnicodeString::pinIndices(int32_t& start,
3836  int32_t& _length) const
3837 {
3838  // pin indices
3839  int32_t len = length();
3840  if(start < 0) {
3841  start = 0;
3842  } else if(start > len) {
3843  start = len;
3844  }
3845  if(_length < 0) {
3846  _length = 0;
3847  } else if(_length > (len - start)) {
3848  _length = (len - start);
3849  }
3850 }
3851 
3852 inline char16_t*
3853 UnicodeString::getArrayStart() {
3854  return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3855  fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
3856 }
3857 
3858 inline const char16_t*
3859 UnicodeString::getArrayStart() const {
3860  return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3861  fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
3862 }
3863 
3864 //========================================
3865 // Default constructor
3866 //========================================
3867 
3868 inline
3869 UnicodeString::UnicodeString() {
3870  fUnion.fStackFields.fLengthAndFlags=kShortString;
3871 }
3872 
3873 inline UnicodeString::UnicodeString(const std::nullptr_t /*text*/) {
3874  fUnion.fStackFields.fLengthAndFlags=kShortString;
3875 }
3876 
3877 inline UnicodeString::UnicodeString(const std::nullptr_t /*text*/, int32_t /*length*/) {
3878  fUnion.fStackFields.fLengthAndFlags=kShortString;
3879 }
3880 
3881 inline UnicodeString::UnicodeString(std::nullptr_t /*buffer*/, int32_t /*buffLength*/, int32_t /*buffCapacity*/) {
3882  fUnion.fStackFields.fLengthAndFlags=kShortString;
3883 }
3884 
3885 //========================================
3886 // Read-only implementation methods
3887 //========================================
3888 inline UBool
3889 UnicodeString::hasShortLength() const {
3890  return fUnion.fFields.fLengthAndFlags>=0;
3891 }
3892 
3893 inline int32_t
3894 UnicodeString::getShortLength() const {
3895  // fLengthAndFlags must be non-negative -> short length >= 0
3896  // and arithmetic or logical shift does not matter.
3897  return fUnion.fFields.fLengthAndFlags>>kLengthShift;
3898 }
3899 
3900 inline int32_t
3901 UnicodeString::length() const {
3902  return hasShortLength() ? getShortLength() : fUnion.fFields.fLength;
3903 }
3904 
3905 inline int32_t
3906 UnicodeString::getCapacity() const {
3907  return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3908  US_STACKBUF_SIZE : fUnion.fFields.fCapacity;
3909 }
3910 
3911 inline int32_t
3912 UnicodeString::hashCode() const
3913 { return doHashCode(); }
3914 
3915 inline UBool
3916 UnicodeString::isBogus() const
3917 { return (UBool)(fUnion.fFields.fLengthAndFlags & kIsBogus); }
3918 
3919 inline UBool
3920 UnicodeString::isWritable() const
3921 { return (UBool)!(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus)); }
3922 
3923 inline UBool
3924 UnicodeString::isBufferWritable() const
3925 {
3926  return (UBool)(
3927  !(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus|kBufferIsReadonly)) &&
3928  (!(fUnion.fFields.fLengthAndFlags&kRefCounted) || refCount()==1));
3929 }
3930 
3931 inline const char16_t *
3932 UnicodeString::getBuffer() const {
3933  if(fUnion.fFields.fLengthAndFlags&(kIsBogus|kOpenGetBuffer)) {
3934  return nullptr;
3935  } else if(fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) {
3936  return fUnion.fStackFields.fBuffer;
3937  } else {
3938  return fUnion.fFields.fArray;
3939  }
3940 }
3941 
3942 //========================================
3943 // Read-only alias methods
3944 //========================================
3945 inline int8_t
3946 UnicodeString::doCompare(int32_t start,
3947  int32_t thisLength,
3948  const UnicodeString& srcText,
3949  int32_t srcStart,
3950  int32_t srcLength) const
3951 {
3952  if(srcText.isBogus()) {
3953  return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
3954  } else {
3955  srcText.pinIndices(srcStart, srcLength);
3956  return doCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
3957  }
3958 }
3959 
3960 inline UBool
3961 UnicodeString::doEqualsSubstring(int32_t start,
3962  int32_t thisLength,
3963  const UnicodeString& srcText,
3964  int32_t srcStart,
3965  int32_t srcLength) const
3966 {
3967  if(srcText.isBogus()) {
3968  return isBogus();
3969  } else {
3970  srcText.pinIndices(srcStart, srcLength);
3971  return !isBogus() && doEqualsSubstring(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
3972  }
3973 }
3974 
3975 inline bool
3977 {
3978  if(isBogus()) {
3979  return text.isBogus();
3980  } else {
3981  int32_t len = length(), textLength = text.length();
3982  return !text.isBogus() && len == textLength && doEquals(text, len);
3983  }
3984 }
3985 
3986 inline bool
3988 { return (! operator==(text)); }
3989 
3990 inline UBool
3991 UnicodeString::operator> (const UnicodeString& text) const
3992 { return doCompare(0, length(), text, 0, text.length()) == 1; }
3993 
3994 inline UBool
3995 UnicodeString::operator< (const UnicodeString& text) const
3996 { return doCompare(0, length(), text, 0, text.length()) == -1; }
3997 
3998 inline UBool
3999 UnicodeString::operator>= (const UnicodeString& text) const
4000 { return doCompare(0, length(), text, 0, text.length()) != -1; }
4001 
4002 inline UBool
4003 UnicodeString::operator<= (const UnicodeString& text) const
4004 { return doCompare(0, length(), text, 0, text.length()) != 1; }
4005 
4006 inline int8_t
4007 UnicodeString::compare(const UnicodeString& text) const
4008 { return doCompare(0, length(), text, 0, text.length()); }
4009 
4010 inline int8_t
4011 UnicodeString::compare(int32_t start,
4012  int32_t _length,
4013  const UnicodeString& srcText) const
4014 { return doCompare(start, _length, srcText, 0, srcText.length()); }
4015 
4016 inline int8_t
4017 UnicodeString::compare(ConstChar16Ptr srcChars,
4018  int32_t srcLength) const
4019 { return doCompare(0, length(), srcChars, 0, srcLength); }
4020 
4021 inline int8_t
4022 UnicodeString::compare(int32_t start,
4023  int32_t _length,
4024  const UnicodeString& srcText,
4025  int32_t srcStart,
4026  int32_t srcLength) const
4027 { return doCompare(start, _length, srcText, srcStart, srcLength); }
4028 
4029 inline int8_t
4030 UnicodeString::compare(int32_t start,
4031  int32_t _length,
4032  const char16_t *srcChars) const
4033 { return doCompare(start, _length, srcChars, 0, _length); }
4034 
4035 inline int8_t
4036 UnicodeString::compare(int32_t start,
4037  int32_t _length,
4038  const char16_t *srcChars,
4039  int32_t srcStart,
4040  int32_t srcLength) const
4041 { return doCompare(start, _length, srcChars, srcStart, srcLength); }
4042 
4043 inline int8_t
4044 UnicodeString::compareBetween(int32_t start,
4045  int32_t limit,
4046  const UnicodeString& srcText,
4047  int32_t srcStart,
4048  int32_t srcLimit) const
4049 { return doCompare(start, limit - start,
4050  srcText, srcStart, srcLimit - srcStart); }
4051 
4052 inline int8_t
4053 UnicodeString::doCompareCodePointOrder(int32_t start,
4054  int32_t thisLength,
4055  const UnicodeString& srcText,
4056  int32_t srcStart,
4057  int32_t srcLength) const
4058 {
4059  if(srcText.isBogus()) {
4060  return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
4061  } else {
4062  srcText.pinIndices(srcStart, srcLength);
4063  return doCompareCodePointOrder(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
4064  }
4065 }
4066 
4067 inline int8_t
4068 UnicodeString::compareCodePointOrder(const UnicodeString& text) const
4069 { return doCompareCodePointOrder(0, length(), text, 0, text.length()); }
4070 
4071 inline int8_t
4072 UnicodeString::compareCodePointOrder(int32_t start,
4073  int32_t _length,
4074  const UnicodeString& srcText) const
4075 { return doCompareCodePointOrder(start, _length, srcText, 0, srcText.length()); }
4076 
4077 inline int8_t
4078 UnicodeString::compareCodePointOrder(ConstChar16Ptr srcChars,
4079  int32_t srcLength) const
4080 { return doCompareCodePointOrder(0, length(), srcChars, 0, srcLength); }
4081 
4082 inline int8_t
4083 UnicodeString::compareCodePointOrder(int32_t start,
4084  int32_t _length,
4085  const UnicodeString& srcText,
4086  int32_t srcStart,
4087  int32_t srcLength) const
4088 { return doCompareCodePointOrder(start, _length, srcText, srcStart, srcLength); }
4089 
4090 inline int8_t
4091 UnicodeString::compareCodePointOrder(int32_t start,
4092  int32_t _length,
4093  const char16_t *srcChars) const
4094 { return doCompareCodePointOrder(start, _length, srcChars, 0, _length); }
4095 
4096 inline int8_t
4097 UnicodeString::compareCodePointOrder(int32_t start,
4098  int32_t _length,
4099  const char16_t *srcChars,
4100  int32_t srcStart,
4101  int32_t srcLength) const
4102 { return doCompareCodePointOrder(start, _length, srcChars, srcStart, srcLength); }
4103 
4104 inline int8_t
4105 UnicodeString::compareCodePointOrderBetween(int32_t start,
4106  int32_t limit,
4107  const UnicodeString& srcText,
4108  int32_t srcStart,
4109  int32_t srcLimit) const
4110 { return doCompareCodePointOrder(start, limit - start,
4111  srcText, srcStart, srcLimit - srcStart); }
4112 
4113 inline int8_t
4114 UnicodeString::doCaseCompare(int32_t start,
4115  int32_t thisLength,
4116  const UnicodeString &srcText,
4117  int32_t srcStart,
4118  int32_t srcLength,
4119  uint32_t options) const
4120 {
4121  if(srcText.isBogus()) {
4122  return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
4123  } else {
4124  srcText.pinIndices(srcStart, srcLength);
4125  return doCaseCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength, options);
4126  }
4127 }
4128 
4129 inline int8_t
4130 UnicodeString::caseCompare(const UnicodeString &text, uint32_t options) const {
4131  return doCaseCompare(0, length(), text, 0, text.length(), options);
4132 }
4133 
4134 inline int8_t
4135 UnicodeString::caseCompare(int32_t start,
4136  int32_t _length,
4137  const UnicodeString &srcText,
4138  uint32_t options) const {
4139  return doCaseCompare(start, _length, srcText, 0, srcText.length(), options);
4140 }
4141 
4142 inline int8_t
4143 UnicodeString::caseCompare(ConstChar16Ptr srcChars,
4144  int32_t srcLength,
4145  uint32_t options) const {
4146  return doCaseCompare(0, length(), srcChars, 0, srcLength, options);
4147 }
4148 
4149 inline int8_t
4150 UnicodeString::caseCompare(int32_t start,
4151  int32_t _length,
4152  const UnicodeString &srcText,
4153  int32_t srcStart,
4154  int32_t srcLength,
4155  uint32_t options) const {
4156  return doCaseCompare(start, _length, srcText, srcStart, srcLength, options);
4157 }
4158 
4159 inline int8_t
4160 UnicodeString::caseCompare(int32_t start,
4161  int32_t _length,
4162  const char16_t *srcChars,
4163  uint32_t options) const {
4164  return doCaseCompare(start, _length, srcChars, 0, _length, options);
4165 }
4166 
4167 inline int8_t
4168 UnicodeString::caseCompare(int32_t start,
4169  int32_t _length,
4170  const char16_t *srcChars,
4171  int32_t srcStart,
4172  int32_t srcLength,
4173  uint32_t options) const {
4174  return doCaseCompare(start, _length, srcChars, srcStart, srcLength, options);
4175 }
4176 
4177 inline int8_t
4178 UnicodeString::caseCompareBetween(int32_t start,
4179  int32_t limit,
4180  const UnicodeString &srcText,
4181  int32_t srcStart,
4182  int32_t srcLimit,
4183  uint32_t options) const {
4184  return doCaseCompare(start, limit - start, srcText, srcStart, srcLimit - srcStart, options);
4185 }
4186 
4187 inline int32_t
4188 UnicodeString::indexOf(const UnicodeString& srcText,
4189  int32_t srcStart,
4190  int32_t srcLength,
4191  int32_t start,
4192  int32_t _length) const
4193 {
4194  if(!srcText.isBogus()) {
4195  srcText.pinIndices(srcStart, srcLength);
4196  if(srcLength > 0) {
4197  return indexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
4198  }
4199  }
4200  return -1;
4201 }
4202 
4203 inline int32_t
4204 UnicodeString::indexOf(const UnicodeString& text) const
4205 { return indexOf(text, 0, text.length(), 0, length()); }
4206 
4207 inline int32_t
4208 UnicodeString::indexOf(const UnicodeString& text,
4209  int32_t start) const {
4210  pinIndex(start);
4211  return indexOf(text, 0, text.length(), start, length() - start);
4212 }
4213 
4214 inline int32_t
4215 UnicodeString::indexOf(const UnicodeString& text,
4216  int32_t start,
4217  int32_t _length) const
4218 { return indexOf(text, 0, text.length(), start, _length); }
4219 
4220 inline int32_t
4221 UnicodeString::indexOf(const char16_t *srcChars,
4222  int32_t srcLength,
4223  int32_t start) const {
4224  pinIndex(start);
4225  return indexOf(srcChars, 0, srcLength, start, length() - start);
4226 }
4227 
4228 inline int32_t
4229 UnicodeString::indexOf(ConstChar16Ptr srcChars,
4230  int32_t srcLength,
4231  int32_t start,
4232  int32_t _length) const
4233 { return indexOf(srcChars, 0, srcLength, start, _length); }
4234 
4235 inline int32_t
4236 UnicodeString::indexOf(char16_t c,
4237  int32_t start,
4238  int32_t _length) const
4239 { return doIndexOf(c, start, _length); }
4240 
4241 inline int32_t
4242 UnicodeString::indexOf(UChar32 c,
4243  int32_t start,
4244  int32_t _length) const
4245 { return doIndexOf(c, start, _length); }
4246 
4247 inline int32_t
4248 UnicodeString::indexOf(char16_t c) const
4249 { return doIndexOf(c, 0, length()); }
4250 
4251 inline int32_t
4252 UnicodeString::indexOf(UChar32 c) const
4253 { return indexOf(c, 0, length()); }
4254 
4255 inline int32_t
4256 UnicodeString::indexOf(char16_t c,
4257  int32_t start) const {
4258  pinIndex(start);
4259  return doIndexOf(c, start, length() - start);
4260 }
4261 
4262 inline int32_t
4263 UnicodeString::indexOf(UChar32 c,
4264  int32_t start) const {
4265  pinIndex(start);
4266  return indexOf(c, start, length() - start);
4267 }
4268 
4269 inline int32_t
4270 UnicodeString::lastIndexOf(ConstChar16Ptr srcChars,
4271  int32_t srcLength,
4272  int32_t start,
4273  int32_t _length) const
4274 { return lastIndexOf(srcChars, 0, srcLength, start, _length); }
4275 
4276 inline int32_t
4277 UnicodeString::lastIndexOf(const char16_t *srcChars,
4278  int32_t srcLength,
4279  int32_t start) const {
4280  pinIndex(start);
4281  return lastIndexOf(srcChars, 0, srcLength, start, length() - start);
4282 }
4283 
4284 inline int32_t
4285 UnicodeString::lastIndexOf(const UnicodeString& srcText,
4286  int32_t srcStart,
4287  int32_t srcLength,
4288  int32_t start,
4289  int32_t _length) const
4290 {
4291  if(!srcText.isBogus()) {
4292  srcText.pinIndices(srcStart, srcLength);
4293  if(srcLength > 0) {
4294  return lastIndexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
4295  }
4296  }
4297  return -1;
4298 }
4299 
4300 inline int32_t
4301 UnicodeString::lastIndexOf(const UnicodeString& text,
4302  int32_t start,
4303  int32_t _length) const
4304 { return lastIndexOf(text, 0, text.length(), start, _length); }
4305 
4306 inline int32_t
4307 UnicodeString::lastIndexOf(const UnicodeString& text,
4308  int32_t start) const {
4309  pinIndex(start);
4310  return lastIndexOf(text, 0, text.length(), start, length() - start);
4311 }
4312 
4313 inline int32_t
4314 UnicodeString::lastIndexOf(const UnicodeString& text) const
4315 { return lastIndexOf(text, 0, text.length(), 0, length()); }
4316 
4317 inline int32_t
4318 UnicodeString::lastIndexOf(char16_t c,
4319  int32_t start,
4320  int32_t _length) const
4321 { return doLastIndexOf(c, start, _length); }
4322 
4323 inline int32_t
4324 UnicodeString::lastIndexOf(UChar32 c,
4325  int32_t start,
4326  int32_t _length) const {
4327  return doLastIndexOf(c, start, _length);
4328 }
4329 
4330 inline int32_t
4331 UnicodeString::lastIndexOf(char16_t c) const
4332 { return doLastIndexOf(c, 0, length()); }
4333 
4334 inline int32_t
4335 UnicodeString::lastIndexOf(UChar32 c) const {
4336  return lastIndexOf(c, 0, length());
4337 }
4338 
4339 inline int32_t
4340 UnicodeString::lastIndexOf(char16_t c,
4341  int32_t start) const {
4342  pinIndex(start);
4343  return doLastIndexOf(c, start, length() - start);
4344 }
4345 
4346 inline int32_t
4347 UnicodeString::lastIndexOf(UChar32 c,
4348  int32_t start) const {
4349  pinIndex(start);
4350  return lastIndexOf(c, start, length() - start);
4351 }
4352 
4353 inline UBool
4354 UnicodeString::startsWith(const UnicodeString& text) const
4355 { return doEqualsSubstring(0, text.length(), text, 0, text.length()); }
4356 
4357 inline UBool
4358 UnicodeString::startsWith(const UnicodeString& srcText,
4359  int32_t srcStart,
4360  int32_t srcLength) const
4361 { return doEqualsSubstring(0, srcLength, srcText, srcStart, srcLength); }
4362 
4363 inline UBool
4364 UnicodeString::startsWith(ConstChar16Ptr srcChars, int32_t srcLength) const {
4365  if(srcLength < 0) {
4366  srcLength = u_strlen(toUCharPtr(srcChars));
4367  }
4368  return doEqualsSubstring(0, srcLength, srcChars, 0, srcLength);
4369 }
4370 
4371 inline UBool
4372 UnicodeString::startsWith(const char16_t *srcChars, int32_t srcStart, int32_t srcLength) const {
4373  if(srcLength < 0) {
4374  srcLength = u_strlen(toUCharPtr(srcChars));
4375  }
4376  return doEqualsSubstring(0, srcLength, srcChars, srcStart, srcLength);
4377 }
4378 
4379 inline UBool
4380 UnicodeString::endsWith(const UnicodeString& text) const
4381 { return doEqualsSubstring(length() - text.length(), text.length(),
4382  text, 0, text.length()); }
4383 
4384 inline UBool
4385 UnicodeString::endsWith(const UnicodeString& srcText,
4386  int32_t srcStart,
4387  int32_t srcLength) const {
4388  srcText.pinIndices(srcStart, srcLength);
4389  return doEqualsSubstring(length() - srcLength, srcLength,
4390  srcText, srcStart, srcLength);
4391 }
4392 
4393 inline UBool
4394 UnicodeString::endsWith(ConstChar16Ptr srcChars,
4395  int32_t srcLength) const {
4396  if(srcLength < 0) {
4397  srcLength = u_strlen(toUCharPtr(srcChars));
4398  }
4399  return doEqualsSubstring(length() - srcLength, srcLength, srcChars, 0, srcLength);
4400 }
4401 
4402 inline UBool
4403 UnicodeString::endsWith(const char16_t *srcChars,
4404  int32_t srcStart,
4405  int32_t srcLength) const {
4406  if(srcLength < 0) {
4407  srcLength = u_strlen(toUCharPtr(srcChars + srcStart));
4408  }
4409  return doEqualsSubstring(length() - srcLength, srcLength,
4410  srcChars, srcStart, srcLength);
4411 }
4412 
4413 //========================================
4414 // replace
4415 //========================================
4416 inline UnicodeString&
4417 UnicodeString::replace(int32_t start,
4418  int32_t _length,
4419  const UnicodeString& srcText)
4420 { return doReplace(start, _length, srcText, 0, srcText.length()); }
4421 
4422 inline UnicodeString&
4423 UnicodeString::replace(int32_t start,
4424  int32_t _length,
4425  const UnicodeString& srcText,
4426  int32_t srcStart,
4427  int32_t srcLength)
4428 { return doReplace(start, _length, srcText, srcStart, srcLength); }
4429 
4430 inline UnicodeString&
4431 UnicodeString::replace(int32_t start,
4432  int32_t _length,
4433  ConstChar16Ptr srcChars,
4434  int32_t srcLength)
4435 { return doReplace(start, _length, srcChars, 0, srcLength); }
4436 
4437 inline UnicodeString&
4438 UnicodeString::replace(int32_t start,
4439  int32_t _length,
4440  const char16_t *srcChars,
4441  int32_t srcStart,
4442  int32_t srcLength)
4443 { return doReplace(start, _length, srcChars, srcStart, srcLength); }
4444 
4445 inline UnicodeString&
4446 UnicodeString::replace(int32_t start,
4447  int32_t _length,
4448  char16_t srcChar)
4449 { return doReplace(start, _length, &srcChar, 0, 1); }
4450 
4451 inline UnicodeString&
4452 UnicodeString::replaceBetween(int32_t start,
4453  int32_t limit,
4454  const UnicodeString& srcText)
4455 { return doReplace(start, limit - start, srcText, 0, srcText.length()); }
4456 
4457 inline UnicodeString&
4458 UnicodeString::replaceBetween(int32_t start,
4459  int32_t limit,
4460  const UnicodeString& srcText,
4461  int32_t srcStart,
4462  int32_t srcLimit)
4463 { return doReplace(start, limit - start, srcText, srcStart, srcLimit - srcStart); }
4464 
4465 inline UnicodeString&
4466 UnicodeString::findAndReplace(const UnicodeString& oldText,
4467  const UnicodeString& newText)
4468 { return findAndReplace(0, length(), oldText, 0, oldText.length(),
4469  newText, 0, newText.length()); }
4470 
4471 inline UnicodeString&
4472 UnicodeString::findAndReplace(int32_t start,
4473  int32_t _length,
4474  const UnicodeString& oldText,
4475  const UnicodeString& newText)
4476 { return findAndReplace(start, _length, oldText, 0, oldText.length(),
4477  newText, 0, newText.length()); }
4478 
4479 // ============================
4480 // extract
4481 // ============================
4482 inline void
4483 UnicodeString::doExtract(int32_t start,
4484  int32_t _length,
4485  UnicodeString& target) const
4486 { target.replace(0, target.length(), *this, start, _length); }
4487 
4488 inline void
4489 UnicodeString::extract(int32_t start,
4490  int32_t _length,
4491  Char16Ptr target,
4492  int32_t targetStart) const
4493 { doExtract(start, _length, target, targetStart); }
4494 
4495 inline void
4496 UnicodeString::extract(int32_t start,
4497  int32_t _length,
4498  UnicodeString& target) const
4499 { doExtract(start, _length, target); }
4500 
4501 #if !UCONFIG_NO_CONVERSION
4502 
4503 inline int32_t
4504 UnicodeString::extract(int32_t start,
4505  int32_t _length,
4506  char *dst,
4507  const char *codepage) const
4508 
4509 {
4510  // This dstSize value will be checked explicitly
4511  return extract(start, _length, dst, dst != nullptr ? 0xffffffff : 0, codepage);
4512 }
4513 
4514 #endif
4515 
4516 inline void
4517 UnicodeString::extractBetween(int32_t start,
4518  int32_t limit,
4519  char16_t *dst,
4520  int32_t dstStart) const {
4521  pinIndex(start);
4522  pinIndex(limit);
4523  doExtract(start, limit - start, dst, dstStart);
4524 }
4525 
4526 inline UnicodeString
4527 UnicodeString::tempSubStringBetween(int32_t start, int32_t limit) const {
4528  return tempSubString(start, limit - start);
4529 }
4530 
4531 inline char16_t
4532 UnicodeString::doCharAt(int32_t offset) const
4533 {
4534  if((uint32_t)offset < (uint32_t)length()) {
4535  return getArrayStart()[offset];
4536  } else {
4537  return kInvalidUChar;
4538  }
4539 }
4540 
4541 inline char16_t
4542 UnicodeString::charAt(int32_t offset) const
4543 { return doCharAt(offset); }
4544 
4545 inline char16_t
4546 UnicodeString::operator[] (int32_t offset) const
4547 { return doCharAt(offset); }
4548 
4549 inline UBool
4550 UnicodeString::isEmpty() const {
4551  // Arithmetic or logical right shift does not matter: only testing for 0.
4552  return (fUnion.fFields.fLengthAndFlags>>kLengthShift) == 0;
4553 }
4554 
4555 //========================================
4556 // Write implementation methods
4557 //========================================
4558 inline void
4559 UnicodeString::setZeroLength() {
4560  fUnion.fFields.fLengthAndFlags &= kAllStorageFlags;
4561 }
4562 
4563 inline void
4564 UnicodeString::setShortLength(int32_t len) {
4565  // requires 0 <= len <= kMaxShortLength
4566  fUnion.fFields.fLengthAndFlags =
4567  (int16_t)((fUnion.fFields.fLengthAndFlags & kAllStorageFlags) | (len << kLengthShift));
4568 }
4569 
4570 inline void
4571 UnicodeString::setLength(int32_t len) {
4572  if(len <= kMaxShortLength) {
4573  setShortLength(len);
4574  } else {
4575  fUnion.fFields.fLengthAndFlags |= kLengthIsLarge;
4576  fUnion.fFields.fLength = len;
4577  }
4578 }
4579 
4580 inline void
4581 UnicodeString::setToEmpty() {
4582  fUnion.fFields.fLengthAndFlags = kShortString;
4583 }
4584 
4585 inline void
4586 UnicodeString::setArray(char16_t *array, int32_t len, int32_t capacity) {
4587  setLength(len);
4588  fUnion.fFields.fArray = array;
4589  fUnion.fFields.fCapacity = capacity;
4590 }
4591 
4592 inline UnicodeString&
4593 UnicodeString::operator= (char16_t ch)
4594 { return doReplace(0, length(), &ch, 0, 1); }
4595 
4596 inline UnicodeString&
4597 UnicodeString::operator= (UChar32 ch)
4598 { return replace(0, length(), ch); }
4599 
4600 inline UnicodeString&
4601 UnicodeString::setTo(const UnicodeString& srcText,
4602  int32_t srcStart,
4603  int32_t srcLength)
4604 {
4605  unBogus();
4606  return doReplace(0, length(), srcText, srcStart, srcLength);
4607 }
4608 
4609 inline UnicodeString&
4610 UnicodeString::setTo(const UnicodeString& srcText,
4611  int32_t srcStart)
4612 {
4613  unBogus();
4614  srcText.pinIndex(srcStart);
4615  return doReplace(0, length(), srcText, srcStart, srcText.length() - srcStart);
4616 }
4617 
4618 inline UnicodeString&
4619 UnicodeString::setTo(const UnicodeString& srcText)
4620 {
4621  return copyFrom(srcText);
4622 }
4623 
4624 inline UnicodeString&
4625 UnicodeString::setTo(const char16_t *srcChars,
4626  int32_t srcLength)
4627 {
4628  unBogus();
4629  return doReplace(0, length(), srcChars, 0, srcLength);
4630 }
4631 
4632 inline UnicodeString&
4633 UnicodeString::setTo(char16_t srcChar)
4634 {
4635  unBogus();
4636  return doReplace(0, length(), &srcChar, 0, 1);
4637 }
4638 
4639 inline UnicodeString&
4640 UnicodeString::setTo(UChar32 srcChar)
4641 {
4642  unBogus();
4643  return replace(0, length(), srcChar);
4644 }
4645 
4646 inline UnicodeString&
4647 UnicodeString::append(const UnicodeString& srcText,
4648  int32_t srcStart,
4649  int32_t srcLength)
4650 { return doAppend(srcText, srcStart, srcLength); }
4651 
4652 inline UnicodeString&
4653 UnicodeString::append(const UnicodeString& srcText)
4654 { return doAppend(srcText, 0, srcText.length()); }
4655 
4656 inline UnicodeString&
4657 UnicodeString::append(const char16_t *srcChars,
4658  int32_t srcStart,
4659  int32_t srcLength)
4660 { return doAppend(srcChars, srcStart, srcLength); }
4661 
4662 inline UnicodeString&
4663 UnicodeString::append(ConstChar16Ptr srcChars,
4664  int32_t srcLength)
4665 { return doAppend(srcChars, 0, srcLength); }
4666 
4667 inline UnicodeString&
4668 UnicodeString::append(char16_t srcChar)
4669 { return doAppend(&srcChar, 0, 1); }
4670 
4671 inline UnicodeString&
4672 UnicodeString::operator+= (char16_t ch)
4673 { return doAppend(&ch, 0, 1); }
4674 
4675 inline UnicodeString&
4676 UnicodeString::operator+= (UChar32 ch) {
4677  return append(ch);
4678 }
4679 
4680 inline UnicodeString&
4681 UnicodeString::operator+= (const UnicodeString& srcText)
4682 { return doAppend(srcText, 0, srcText.length()); }
4683 
4684 inline UnicodeString&
4685 UnicodeString::insert(int32_t start,
4686  const UnicodeString& srcText,
4687  int32_t srcStart,
4688  int32_t srcLength)
4689 { return doReplace(start, 0, srcText, srcStart, srcLength); }
4690 
4691 inline UnicodeString&
4692 UnicodeString::insert(int32_t start,
4693  const UnicodeString& srcText)
4694 { return doReplace(start, 0, srcText, 0, srcText.length()); }
4695 
4696 inline UnicodeString&
4697 UnicodeString::insert(int32_t start,
4698  const char16_t *srcChars,
4699  int32_t srcStart,
4700  int32_t srcLength)
4701 { return doReplace(start, 0, srcChars, srcStart, srcLength); }
4702 
4703 inline UnicodeString&
4704 UnicodeString::insert(int32_t start,
4705  ConstChar16Ptr srcChars,
4706  int32_t srcLength)
4707 { return doReplace(start, 0, srcChars, 0, srcLength); }
4708 
4709 inline UnicodeString&
4710 UnicodeString::insert(int32_t start,
4711  char16_t srcChar)
4712 { return doReplace(start, 0, &srcChar, 0, 1); }
4713 
4714 inline UnicodeString&
4715 UnicodeString::insert(int32_t start,
4716  UChar32 srcChar)
4717 { return replace(start, 0, srcChar); }
4718 
4719 
4720 inline UnicodeString&
4721 UnicodeString::remove()
4722 {
4723  // remove() of a bogus string makes the string empty and non-bogus
4724  if(isBogus()) {
4725  setToEmpty();
4726  } else {
4727  setZeroLength();
4728  }
4729  return *this;
4730 }
4731 
4732 inline UnicodeString&
4733 UnicodeString::remove(int32_t start,
4734  int32_t _length)
4735 {
4736  if(start <= 0 && _length == INT32_MAX) {
4737  // remove(guaranteed everything) of a bogus string makes the string empty and non-bogus
4738  return remove();
4739  }
4740  return doReplace(start, _length, nullptr, 0, 0);
4741 }
4742 
4743 inline UnicodeString&
4744 UnicodeString::removeBetween(int32_t start,
4745  int32_t limit)
4746 { return doReplace(start, limit - start, nullptr, 0, 0); }
4747 
4748 inline UnicodeString &
4749 UnicodeString::retainBetween(int32_t start, int32_t limit) {
4750  truncate(limit);
4751  return doReplace(0, start, nullptr, 0, 0);
4752 }
4753 
4754 inline UBool
4755 UnicodeString::truncate(int32_t targetLength)
4756 {
4757  if(isBogus() && targetLength == 0) {
4758  // truncate(0) of a bogus string makes the string empty and non-bogus
4759  unBogus();
4760  return false;
4761  } else if((uint32_t)targetLength < (uint32_t)length()) {
4762  setLength(targetLength);
4763  return true;
4764  } else {
4765  return false;
4766  }
4767 }
4768 
4769 inline UnicodeString&
4770 UnicodeString::reverse()
4771 { return doReverse(0, length()); }
4772 
4773 inline UnicodeString&
4774 UnicodeString::reverse(int32_t start,
4775  int32_t _length)
4776 { return doReverse(start, _length); }
4777 
4778 U_NAMESPACE_END
4779 
4780 #endif /* U_SHOW_CPLUSPLUS_API */
4781 
4782 #endif
C++ API: Interface for writing bytes, and implementation classes.
C++ API: char16_t pointer wrappers with implicit conversion from bit-compatible raw pointer types.
The BreakIterator class implements methods for finding the location of boundaries in text.
Definition: brkiter.h:106
A ByteSink can be filled with bytes.
Definition: bytestream.h:53
char16_t * wrapper with implicit conversion from distinct but bit-compatible pointer types.
Definition: char16ptr.h:42
const char16_t * wrapper with implicit conversion from distinct but bit-compatible pointer types.
Definition: char16ptr.h:149
Records lengths of string edits but not replacement text.
Definition: edits.h:80
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:195
Replaceable is an abstract base class representing a string of characters that supports the replaceme...
Definition: rep.h:77
virtual void extractBetween(int32_t start, int32_t limit, UnicodeString &target) const =0
Copies characters in the range [start, limit) into the UnicodeString target.
char16_t charAt(int32_t offset) const
Returns the 16-bit code unit at the given offset into the text.
Definition: rep.h:251
int32_t length() const
Returns the number of 16-bit code units in the text.
Definition: rep.h:246
Implementation of ByteSink that writes to a "string".
Definition: bytestream.h:267
A string-like object that points to a sized piece of memory.
Definition: stringpiece.h:60
An Appendable implementation which writes to a UnicodeString.
Definition: appendable.h:156
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:296
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 in the range [start, start + length) of the characters in srcChar...
UnicodeString(const UnicodeString &that)
Copy constructor.
void swap(UnicodeString &other) noexcept
Swap strings.
virtual char16_t getCharAt(int32_t offset) const override
The change in Replaceable to use virtual getCharAt() allows UnicodeString::charAt() to be inline agai...
virtual int32_t getLength() const override
Implement Replaceable::getLength() (see jitterbug 1027).
UnicodeString & foldCase(uint32_t options=0)
Case-folds the characters in this string.
UChar32 unescapeAt(int32_t &offset) const
Unescape a single escape sequence and return the represented character.
UnicodeString(const wchar_t *text, int32_t textLength)
wchar_t * constructor.
Definition: unistr.h:3058
virtual void handleReplaceBetween(int32_t start, int32_t limit, const UnicodeString &text) override
Replace a substring of this object with the given text.
UBool hasMoreChar32Than(int32_t start, int32_t length, int32_t number) const
Check if the length char16_t code units of the string contain more Unicode code points than a certain...
UnicodeString(const UnicodeString &src, int32_t srcStart, int32_t srcLength)
'Substring' constructor from subrange of source string.
UnicodeString & operator=(UnicodeString &&src) noexcept
Move assignment operator; might leave src in bogus state.
virtual ~UnicodeString()
Destructor.
UnicodeString(const char *codepageData, int32_t dataLength, const char *codepage)
char* constructor.
UnicodeString & toLower()
Convert the characters in this to lower case following the conventions of the default locale.
UnicodeString(const char *codepageData, const char *codepage)
char* constructor.
UnicodeString(UBool isTerminated, ConstChar16Ptr text, int32_t textLength)
Readonly-aliasing char16_t* constructor.
UnicodeString & fastCopyFrom(const UnicodeString &src)
Almost the same as the assignment operator.
UnicodeString & toTitle(BreakIterator *titleIter)
Titlecase this string, convenience function using the default locale.
EInvariant
Constant to be used in the UnicodeString(char *, int32_t, EInvariant) constructor which constructs a ...
Definition: unistr.h:307
UnicodeString unescape() const
Unescape a string of characters and return a string containing the result.
UnicodeString(const UnicodeString &src, int32_t srcStart)
'Substring' constructor from tail of source string.
int32_t getChar32Limit(int32_t offset) const
Adjust a random-access offset so that it points behind a Unicode character.
UnicodeString(char16_t *buffer, int32_t buffLength, int32_t buffCapacity)
Writable-aliasing char16_t* constructor.
UnicodeString(int32_t capacity, UChar32 c, int32_t count)
Construct a UnicodeString with capacity to hold capacity char16_ts.
UNISTR_FROM_STRING_EXPLICIT UnicodeString(const uint16_t *text)
uint16_t * constructor.
Definition: unistr.h:2995
int32_t extract(int32_t start, int32_t startLength, char *target, uint32_t targetLength, const char *codepage) const
Copy the characters in the range [start, start + length) into an array of characters in a specified c...
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)
Replace all occurrences of characters in oldText in the range [oldStart, oldStart + oldLength) with t...
virtual void copy(int32_t start, int32_t limit, int32_t dest) override
Copy a substring of this object, retaining attribute (out-of-band) information.
virtual void extractBetween(int32_t start, int32_t limit, UnicodeString &target) const override
Copy the characters in the range [start, limit) into the UnicodeString target.
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:4423
UBool padLeading(int32_t targetLength, char16_t padChar=0x0020)
Pad the start of this UnicodeString with the character padChar.
int32_t getChar32Start(int32_t offset) const
Adjust a random-access offset so that it points to the beginning of a Unicode character.
UChar32 char32At(int32_t offset) const
Return the code point that contains the code unit at offset offset.
UnicodeString(const char *src, int32_t textLength, enum EInvariant inv)
Constructs a Unicode string from an invariant-character char * string.
UnicodeString & operator=(const UnicodeString &srcText)
Assignment operator.
UnicodeString & append(UChar32 srcChar)
Append the code point srcChar to the UnicodeString object.
StringClass & toUTF8String(StringClass &result) const
Convert the UnicodeString to UTF-8 and append the result to a standard string.
Definition: unistr.h:1729
UnicodeString & toLower(const Locale &locale)
Convert the characters in this to lower case following the conventions of a specific locale.
UnicodeString & toTitle(BreakIterator *titleIter, const Locale &locale)
Titlecase this string.
UnicodeString tempSubString(int32_t start=0, int32_t length=INT32_MAX) const
Create a temporary substring for the specified range.
int32_t extract(Char16Ptr dest, int32_t destCapacity, UErrorCode &errorCode) const
Copy the contents of the string into dest.
int32_t length() const
Return the length of the UnicodeString object.
Definition: unistr.h:3901
virtual UChar32 getChar32At(int32_t offset) const override
The change in Replaceable to use virtual getChar32At() allows UnicodeString::char32At() to be inline ...
int32_t extract(int32_t start, int32_t startLength, char *target, uint32_t targetLength) const
Copy the characters in the range [start, start + length) into an array of characters in the platform'...
static UnicodeString fromUTF8(StringPiece utf8)
Create a UnicodeString from a UTF-8 string.
UNISTR_FROM_CHAR_EXPLICIT UnicodeString(char16_t ch)
Single char16_t (code unit) constructor.
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 in the range [start, start + length) of the characters in srcChars...
UnicodeString(wchar_t *buffer, int32_t buffLength, int32_t buffCapacity)
Writable-aliasing wchar_t * constructor.
Definition: unistr.h:3140
void setToBogus()
Make this UnicodeString object invalid.
friend void swap(UnicodeString &s1, UnicodeString &s2) noexcept
Non-member UnicodeString swap function.
Definition: unistr.h:1924
int32_t moveIndex32(int32_t index, int32_t delta) const
Move the code unit index along the string by delta code points.
static UnicodeString fromUTF32(const UChar32 *utf32, int32_t length)
Create a UnicodeString from a UTF-32 string.
int32_t countChar32(int32_t start=0, int32_t length=INT32_MAX) const
Count Unicode code points in the length char16_t code units of the string.
UNISTR_FROM_CHAR_EXPLICIT UnicodeString(UChar32 ch)
Single UChar32 (code point) constructor.
UnicodeString & setTo(UBool isTerminated, ConstChar16Ptr text, int32_t textLength)
Aliasing setTo() function, analogous to the readonly-aliasing char16_t* constructor.
UnicodeString & toTitle(BreakIterator *titleIter, const Locale &locale, uint32_t options)
Titlecase this string, with options.
virtual UnicodeString * clone() const override
Clone this object, an instance of a subclass of Replaceable.
int32_t extract(char *dest, int32_t destCapacity, UConverter *cnv, UErrorCode &errorCode) const
Convert the UnicodeString into a codepage string using an existing UConverter.
UnicodeString(UnicodeString &&src) noexcept
Move constructor; might leave src in bogus state.
UnicodeString(const char16_t *text, int32_t textLength)
char16_t* constructor.
UnicodeString & replace(int32_t start, int32_t length, UChar32 srcChar)
Replace the characters in the range [start, start + length) with the code point srcChar.
UnicodeString(const char *src, int32_t srcLength, UConverter *cnv, UErrorCode &errorCode)
char * / UConverter constructor.
UnicodeString(const char *codepageData, int32_t dataLength)
char* constructor.
static UClassID getStaticClassID()
ICU "poor man's RTTI", returns a UClassID for this class.
UnicodeString(uint16_t *buffer, int32_t buffLength, int32_t buffCapacity)
Writable-aliasing uint16_t * constructor.
Definition: unistr.h:3126
int32_t toUTF32(UChar32 *utf32, int32_t capacity, UErrorCode &errorCode) const
Convert the UnicodeString to UTF-32.
UBool isBogus() const
Determine if this object contains a valid string.
Definition: unistr.h:3916
const char16_t * getTerminatedBuffer()
Get a read-only pointer to the internal buffer, making sure that it is NUL-terminated.
UnicodeString(const uint16_t *text, int32_t textLength)
uint16_t * constructor.
Definition: unistr.h:3045
UNISTR_FROM_STRING_EXPLICIT UnicodeString(const char16_t *text)
char16_t* constructor.
virtual UClassID getDynamicClassID() const override
ICU "poor man's RTTI", returns a UClassID for the actual class.
int32_t extract(int32_t start, int32_t startLength, char *target, int32_t targetCapacity, enum EInvariant inv) const
Copy the characters in the range [start, start + startLength) into an array of characters.
UNISTR_FROM_STRING_EXPLICIT UnicodeString(const wchar_t *text)
wchar_t * constructor.
Definition: unistr.h:3011
UnicodeString & setCharAt(int32_t offset, char16_t ch)
Set the character at the specified offset to the specified character.
UnicodeString & setTo(char16_t *buffer, int32_t buffLength, int32_t buffCapacity)
Aliasing setTo() function, analogous to the writable-aliasing char16_t* constructor.
UBool padTrailing(int32_t targetLength, char16_t padChar=0x0020)
Pad the end of this UnicodeString with the character padChar.
UNISTR_FROM_STRING_EXPLICIT UnicodeString(const char *codepageData)
char* constructor.
void releaseBuffer(int32_t newLength=-1)
Release a read/write buffer on a UnicodeString object with an "open" getBuffer(minCapacity).
char16_t * getBuffer(int32_t minCapacity)
Get a read/write pointer to the internal buffer.
void toUTF8(ByteSink &sink) const
Convert the UnicodeString to UTF-8 and write the result to a ByteSink.
virtual UBool hasMetaData() const override
Replaceable API.
UnicodeString & toUpper()
Convert the characters in this to UPPER CASE following the conventions of the default locale.
UnicodeString & toUpper(const Locale &locale)
Convert the characters in this to UPPER CASE following the conventions of a specific locale.
UnicodeString & trim()
Trims leading and trailing whitespace from this UnicodeString.
U_CAPI int32_t u_strlen(const UChar *s)
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
bool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
Definition: stringpiece.h:335
const UChar * toUCharPtr(const char16_t *p)
Converts from const char16_t * to const UChar *.
Definition: char16ptr.h:260
U_COMMON_API UnicodeString operator+(const UnicodeString &s1, const UnicodeString &s2)
Create a new UnicodeString with the concatenation of two others.
#define U_CALLCONV
Similar to U_CDECL_BEGIN/U_CDECL_END, this qualifier is necessary in callback function typedefs to ma...
Definition: platform.h:834
C++ API: Replaceable String.
C++ API: Central ICU header for including the C++ standard <string> header and for related definition...
C++ API: StringPiece: Read-only byte string wrapper class.
struct UConverter UConverter
Definition: ucnv_err.h:96
#define UCONFIG_NO_BREAK_ITERATION
This switch turns off break iteration.
Definition: uconfig.h:358
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
Definition: umachine.h:427
#define INT32_MAX
The largest value a 32 bit signed integer can hold.
Definition: umachine.h:186
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition: umachine.h:247
#define U_CAPI
This is used to declare a function as a public ICU C API.
Definition: umachine.h:110
char16_t UChar
The base type for UTF-16 code units and pointers.
Definition: umachine.h:378
#define U_SIZEOF_UCHAR
Number of bytes in a UChar (always 2).
Definition: umachine.h:330
#define UNISTR_FROM_CHAR_EXPLICIT
This can be defined to be empty or "explicit".
Definition: unistr.h:150
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:70
#define UNISTR_FROM_STRING_EXPLICIT
This can be defined to be empty or "explicit".
Definition: unistr.h:170
#define UNISTR_OBJECT_SIZE
Desired sizeof(UnicodeString) in bytes.
Definition: unistr.h:208
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:96
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:415
#define U_COMMON_API
Set to export library symbols from inside the common library, and to import them from outside.
Definition: utypes.h:300