ICU 65.1  65.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
45 
48 U_STABLE int32_t U_EXPORT2
49 u_strlen(const UChar *s);
50 #endif
51 
52 U_NAMESPACE_BEGIN
53 
54 #if !UCONFIG_NO_BREAK_ITERATION
55 class BreakIterator; // unicode/brkiter.h
56 #endif
57 class Edits;
58 
59 U_NAMESPACE_END
60 
61 // Not #ifndef U_HIDE_INTERNAL_API because UnicodeString needs the UStringCaseMapper.
68 typedef int32_t U_CALLCONV
69 UStringCaseMapper(int32_t caseLocale, uint32_t options,
71  icu::BreakIterator *iter,
72 #endif
73  char16_t *dest, int32_t destCapacity,
74  const char16_t *src, int32_t srcLength,
75  icu::Edits *edits,
76  UErrorCode &errorCode);
77 
78 U_NAMESPACE_BEGIN
79 
80 class Locale; // unicode/locid.h
81 class StringCharacterIterator;
82 class UnicodeStringAppendable; // unicode/appendable.h
83 
84 /* The <iostream> include has been moved to unicode/ustream.h */
85 
96 #define US_INV icu::UnicodeString::kInvariant
97 
115 #if !U_CHAR16_IS_TYPEDEF
116 # define UNICODE_STRING(cs, _length) icu::UnicodeString(TRUE, u ## cs, _length)
117 #else
118 # define UNICODE_STRING(cs, _length) icu::UnicodeString(TRUE, (const char16_t*)u ## cs, _length)
119 #endif
120 
134 #define UNICODE_STRING_SIMPLE(cs) UNICODE_STRING(cs, -1)
135 
143 #ifndef UNISTR_FROM_CHAR_EXPLICIT
144 # if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION)
145  // Auto-"explicit" in ICU library code.
146 # define UNISTR_FROM_CHAR_EXPLICIT explicit
147 # else
148  // Empty by default for source code compatibility.
149 # define UNISTR_FROM_CHAR_EXPLICIT
150 # endif
151 #endif
152 
163 #ifndef UNISTR_FROM_STRING_EXPLICIT
164 # if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION)
165  // Auto-"explicit" in ICU library code.
166 # define UNISTR_FROM_STRING_EXPLICIT explicit
167 # else
168  // Empty by default for source code compatibility.
169 # define UNISTR_FROM_STRING_EXPLICIT
170 # endif
171 #endif
172 
206 #ifndef UNISTR_OBJECT_SIZE
207 # define UNISTR_OBJECT_SIZE 64
208 #endif
209 
295 {
296 public:
297 
306  enum EInvariant {
311  kInvariant
312  };
313 
314  //========================================
315  // Read-only operations
316  //========================================
317 
318  /* Comparison - bitwise only - for international comparison use collation */
319 
327  inline UBool operator== (const UnicodeString& text) const;
328 
336  inline UBool operator!= (const UnicodeString& text) const;
337 
345  inline UBool operator> (const UnicodeString& text) const;
346 
354  inline UBool operator< (const UnicodeString& text) const;
355 
363  inline UBool operator>= (const UnicodeString& text) const;
364 
372  inline UBool operator<= (const UnicodeString& text) const;
373 
385  inline int8_t compare(const UnicodeString& text) const;
386 
402  inline int8_t compare(int32_t start,
403  int32_t length,
404  const UnicodeString& text) const;
405 
423  inline int8_t compare(int32_t start,
424  int32_t length,
425  const UnicodeString& srcText,
426  int32_t srcStart,
427  int32_t srcLength) const;
428 
441  inline int8_t compare(ConstChar16Ptr srcChars,
442  int32_t srcLength) const;
443 
458  inline int8_t compare(int32_t start,
459  int32_t length,
460  const char16_t *srcChars) const;
461 
479  inline int8_t compare(int32_t start,
480  int32_t length,
481  const char16_t *srcChars,
482  int32_t srcStart,
483  int32_t srcLength) const;
484 
502  inline int8_t compareBetween(int32_t start,
503  int32_t limit,
504  const UnicodeString& srcText,
505  int32_t srcStart,
506  int32_t srcLimit) const;
507 
525  inline int8_t compareCodePointOrder(const UnicodeString& text) const;
526 
546  inline int8_t compareCodePointOrder(int32_t start,
547  int32_t length,
548  const UnicodeString& srcText) const;
549 
571  inline int8_t compareCodePointOrder(int32_t start,
572  int32_t length,
573  const UnicodeString& srcText,
574  int32_t srcStart,
575  int32_t srcLength) const;
576 
595  inline int8_t compareCodePointOrder(ConstChar16Ptr srcChars,
596  int32_t srcLength) const;
597 
617  inline int8_t compareCodePointOrder(int32_t start,
618  int32_t length,
619  const char16_t *srcChars) const;
620 
642  inline int8_t compareCodePointOrder(int32_t start,
643  int32_t length,
644  const char16_t *srcChars,
645  int32_t srcStart,
646  int32_t srcLength) const;
647 
669  inline int8_t compareCodePointOrderBetween(int32_t start,
670  int32_t limit,
671  const UnicodeString& srcText,
672  int32_t srcStart,
673  int32_t srcLimit) const;
674 
693  inline int8_t caseCompare(const UnicodeString& text, uint32_t options) const;
694 
715  inline int8_t caseCompare(int32_t start,
716  int32_t length,
717  const UnicodeString& srcText,
718  uint32_t options) const;
719 
742  inline int8_t caseCompare(int32_t start,
743  int32_t length,
744  const UnicodeString& srcText,
745  int32_t srcStart,
746  int32_t srcLength,
747  uint32_t options) const;
748 
768  inline int8_t caseCompare(ConstChar16Ptr srcChars,
769  int32_t srcLength,
770  uint32_t options) const;
771 
792  inline int8_t caseCompare(int32_t start,
793  int32_t length,
794  const char16_t *srcChars,
795  uint32_t options) const;
796 
819  inline int8_t caseCompare(int32_t start,
820  int32_t length,
821  const char16_t *srcChars,
822  int32_t srcStart,
823  int32_t srcLength,
824  uint32_t options) const;
825 
848  inline int8_t caseCompareBetween(int32_t start,
849  int32_t limit,
850  const UnicodeString& srcText,
851  int32_t srcStart,
852  int32_t srcLimit,
853  uint32_t options) const;
854 
862  inline UBool startsWith(const UnicodeString& text) const;
863 
874  inline UBool startsWith(const UnicodeString& srcText,
875  int32_t srcStart,
876  int32_t srcLength) const;
877 
886  inline UBool startsWith(ConstChar16Ptr srcChars,
887  int32_t srcLength) const;
888 
898  inline UBool startsWith(const char16_t *srcChars,
899  int32_t srcStart,
900  int32_t srcLength) const;
901 
909  inline UBool endsWith(const UnicodeString& text) const;
910 
921  inline UBool endsWith(const UnicodeString& srcText,
922  int32_t srcStart,
923  int32_t srcLength) const;
924 
933  inline UBool endsWith(ConstChar16Ptr srcChars,
934  int32_t srcLength) const;
935 
946  inline UBool endsWith(const char16_t *srcChars,
947  int32_t srcStart,
948  int32_t srcLength) const;
949 
950 
951  /* Searching - bitwise only */
952 
961  inline int32_t indexOf(const UnicodeString& text) const;
962 
972  inline int32_t indexOf(const UnicodeString& text,
973  int32_t start) const;
974 
986  inline int32_t indexOf(const UnicodeString& text,
987  int32_t start,
988  int32_t length) const;
989 
1006  inline int32_t indexOf(const UnicodeString& srcText,
1007  int32_t srcStart,
1008  int32_t srcLength,
1009  int32_t start,
1010  int32_t length) const;
1011 
1023  inline int32_t indexOf(const char16_t *srcChars,
1024  int32_t srcLength,
1025  int32_t start) const;
1026 
1039  inline int32_t indexOf(ConstChar16Ptr srcChars,
1040  int32_t srcLength,
1041  int32_t start,
1042  int32_t length) const;
1043 
1060  int32_t indexOf(const char16_t *srcChars,
1061  int32_t srcStart,
1062  int32_t srcLength,
1063  int32_t start,
1064  int32_t length) const;
1065 
1073  inline int32_t indexOf(char16_t c) const;
1074 
1083  inline int32_t indexOf(UChar32 c) const;
1084 
1093  inline int32_t indexOf(char16_t c,
1094  int32_t start) const;
1095 
1105  inline int32_t indexOf(UChar32 c,
1106  int32_t start) const;
1107 
1118  inline int32_t indexOf(char16_t c,
1119  int32_t start,
1120  int32_t length) const;
1121 
1133  inline int32_t indexOf(UChar32 c,
1134  int32_t start,
1135  int32_t length) const;
1136 
1145  inline int32_t lastIndexOf(const UnicodeString& text) const;
1146 
1156  inline int32_t lastIndexOf(const UnicodeString& text,
1157  int32_t start) const;
1158 
1170  inline int32_t lastIndexOf(const UnicodeString& text,
1171  int32_t start,
1172  int32_t length) const;
1173 
1190  inline int32_t lastIndexOf(const UnicodeString& srcText,
1191  int32_t srcStart,
1192  int32_t srcLength,
1193  int32_t start,
1194  int32_t length) const;
1195 
1206  inline int32_t lastIndexOf(const char16_t *srcChars,
1207  int32_t srcLength,
1208  int32_t start) const;
1209 
1222  inline int32_t lastIndexOf(ConstChar16Ptr srcChars,
1223  int32_t srcLength,
1224  int32_t start,
1225  int32_t length) const;
1226 
1243  int32_t lastIndexOf(const char16_t *srcChars,
1244  int32_t srcStart,
1245  int32_t srcLength,
1246  int32_t start,
1247  int32_t length) const;
1248 
1256  inline int32_t lastIndexOf(char16_t c) const;
1257 
1266  inline int32_t lastIndexOf(UChar32 c) const;
1267 
1276  inline int32_t lastIndexOf(char16_t c,
1277  int32_t start) const;
1278 
1288  inline int32_t lastIndexOf(UChar32 c,
1289  int32_t start) const;
1290 
1301  inline int32_t lastIndexOf(char16_t c,
1302  int32_t start,
1303  int32_t length) const;
1304 
1316  inline int32_t lastIndexOf(UChar32 c,
1317  int32_t start,
1318  int32_t length) const;
1319 
1320 
1321  /* Character access */
1322 
1331  inline char16_t charAt(int32_t offset) const;
1332 
1340  inline char16_t operator[] (int32_t offset) const;
1341 
1353  UChar32 char32At(int32_t offset) const;
1354 
1370  int32_t getChar32Start(int32_t offset) const;
1371 
1388  int32_t getChar32Limit(int32_t offset) const;
1389 
1440  int32_t moveIndex32(int32_t index, int32_t delta) const;
1441 
1442  /* Substring extraction */
1443 
1459  inline void extract(int32_t start,
1460  int32_t length,
1461  Char16Ptr dst,
1462  int32_t dstStart = 0) const;
1463 
1485  int32_t
1486  extract(Char16Ptr dest, int32_t destCapacity,
1487  UErrorCode &errorCode) const;
1488 
1498  inline void extract(int32_t start,
1499  int32_t length,
1500  UnicodeString& target) const;
1501 
1513  inline void extractBetween(int32_t start,
1514  int32_t limit,
1515  char16_t *dst,
1516  int32_t dstStart = 0) const;
1517 
1526  virtual void extractBetween(int32_t start,
1527  int32_t limit,
1528  UnicodeString& target) const;
1529 
1551  int32_t extract(int32_t start,
1552  int32_t startLength,
1553  char *target,
1554  int32_t targetCapacity,
1555  enum EInvariant inv) const;
1556 
1557 #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
1558 
1578  int32_t extract(int32_t start,
1579  int32_t startLength,
1580  char *target,
1581  uint32_t targetLength) const;
1582 
1583 #endif
1584 
1585 #if !UCONFIG_NO_CONVERSION
1586 
1612  inline int32_t extract(int32_t start,
1613  int32_t startLength,
1614  char *target,
1615  const char *codepage = 0) const;
1616 
1646  int32_t extract(int32_t start,
1647  int32_t startLength,
1648  char *target,
1649  uint32_t targetLength,
1650  const char *codepage) const;
1651 
1669  int32_t extract(char *dest, int32_t destCapacity,
1670  UConverter *cnv,
1671  UErrorCode &errorCode) const;
1672 
1673 #endif
1674 
1688  UnicodeString tempSubString(int32_t start=0, int32_t length=INT32_MAX) const;
1689 
1700  inline UnicodeString tempSubStringBetween(int32_t start, int32_t limit=INT32_MAX) const;
1701 
1713  void toUTF8(ByteSink &sink) const;
1714 
1727  template<typename StringClass>
1728  StringClass &toUTF8String(StringClass &result) const {
1729  StringByteSink<StringClass> sbs(&result, length());
1730  toUTF8(sbs);
1731  return result;
1732  }
1733 
1749  int32_t toUTF32(UChar32 *utf32, int32_t capacity, UErrorCode &errorCode) const;
1750 
1751  /* Length operations */
1752 
1761  inline int32_t length(void) const;
1762 
1776  int32_t
1777  countChar32(int32_t start=0, int32_t length=INT32_MAX) const;
1778 
1802  UBool
1803  hasMoreChar32Than(int32_t start, int32_t length, int32_t number) const;
1804 
1810  inline UBool isEmpty(void) const;
1811 
1821  inline int32_t getCapacity(void) const;
1822 
1823  /* Other operations */
1824 
1830  inline int32_t hashCode(void) const;
1831 
1844  inline UBool isBogus(void) const;
1845 
1846 
1847  //========================================
1848  // Write operations
1849  //========================================
1850 
1851  /* Assignment operations */
1852 
1871  UnicodeString &operator=(const UnicodeString &srcText);
1872 
1898  UnicodeString &fastCopyFrom(const UnicodeString &src);
1899 
1908  UnicodeString &operator=(UnicodeString &&src) U_NOEXCEPT;
1909 
1915  void swap(UnicodeString &other) U_NOEXCEPT;
1916 
1923  friend inline void U_EXPORT2
1924  swap(UnicodeString &s1, UnicodeString &s2) U_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 
2219  UnicodeString& append(UChar32 srcChar);
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);
2459 
2465  virtual UBool hasMetaData() const;
2466 
2480  virtual void copy(int32_t start, int32_t limit, int32_t dest);
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 
2528  UnicodeString& findAndReplace(int32_t start,
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 
2626  UnicodeString& trim(void);
2627 
2628 
2629  /* Miscellaneous operations */
2630 
2636  inline UnicodeString& reverse(void);
2637 
2646  inline UnicodeString& reverse(int32_t start,
2647  int32_t length);
2648 
2655  UnicodeString& toUpper(void);
2656 
2664  UnicodeString& toUpper(const Locale& locale);
2665 
2672  UnicodeString& toLower(void);
2673 
2681  UnicodeString& toLower(const Locale& locale);
2682 
2683 #if !UCONFIG_NO_BREAK_ITERATION
2684 
2711  UnicodeString &toTitle(BreakIterator *titleIter);
2712 
2740  UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale);
2741 
2773  UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale, uint32_t options);
2774 
2775 #endif
2776 
2790  UnicodeString &foldCase(uint32_t options=0 /*U_FOLD_CASE_DEFAULT*/);
2791 
2792  //========================================
2793  // Access to the internal buffer
2794  //========================================
2795 
2839  char16_t *getBuffer(int32_t minCapacity);
2840 
2861  void releaseBuffer(int32_t newLength=-1);
2862 
2893  inline const char16_t *getBuffer() const;
2894 
2928  const char16_t *getTerminatedBuffer();
2929 
2930  //========================================
2931  // Constructors
2932  //========================================
2933 
2937  inline UnicodeString();
2938 
2950  UnicodeString(int32_t capacity, UChar32 c, int32_t count);
2951 
2961  UNISTR_FROM_CHAR_EXPLICIT UnicodeString(char16_t ch);
2962 
2972  UNISTR_FROM_CHAR_EXPLICIT UnicodeString(UChar32 ch);
2973 
2984  UNISTR_FROM_STRING_EXPLICIT UnicodeString(const char16_t *text);
2985 
2986 #if !U_CHAR16_IS_TYPEDEF
2987 
2998  UnicodeString(ConstChar16Ptr(text)) {}
2999 #endif
3000 
3001 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
3002 
3014  UnicodeString(ConstChar16Ptr(text)) {}
3015 #endif
3016 
3027  UNISTR_FROM_STRING_EXPLICIT inline UnicodeString(const std::nullptr_t text);
3028 
3036  UnicodeString(const char16_t *text,
3037  int32_t textLength);
3038 
3039 #if !U_CHAR16_IS_TYPEDEF
3040 
3047  UnicodeString(const uint16_t *text, int32_t textLength) :
3048  UnicodeString(ConstChar16Ptr(text), textLength) {}
3049 #endif
3050 
3051 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
3052 
3060  UnicodeString(const wchar_t *text, int32_t textLength) :
3061  UnicodeString(ConstChar16Ptr(text), textLength) {}
3062 #endif
3063 
3071  inline UnicodeString(const std::nullptr_t text, int32_t textLength);
3072 
3095  UnicodeString(UBool isTerminated,
3096  ConstChar16Ptr text,
3097  int32_t textLength);
3098 
3117  UnicodeString(char16_t *buffer, int32_t buffLength, int32_t buffCapacity);
3118 
3119 #if !U_CHAR16_IS_TYPEDEF
3120 
3128  UnicodeString(uint16_t *buffer, int32_t buffLength, int32_t buffCapacity) :
3129  UnicodeString(Char16Ptr(buffer), buffLength, buffCapacity) {}
3130 #endif
3131 
3132 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
3133 
3142  UnicodeString(wchar_t *buffer, int32_t buffLength, int32_t buffCapacity) :
3143  UnicodeString(Char16Ptr(buffer), buffLength, buffCapacity) {}
3144 #endif
3145 
3154  inline UnicodeString(std::nullptr_t buffer, int32_t buffLength, int32_t buffCapacity);
3155 
3156 #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
3157 
3177  UNISTR_FROM_STRING_EXPLICIT UnicodeString(const char *codepageData);
3178 
3187  UnicodeString(const char *codepageData, int32_t dataLength);
3188 
3189 #endif
3190 
3191 #if !UCONFIG_NO_CONVERSION
3192 
3210  UnicodeString(const char *codepageData, const char *codepage);
3211 
3229  UnicodeString(const char *codepageData, int32_t dataLength, const char *codepage);
3230 
3252  UnicodeString(
3253  const char *src, int32_t srcLength,
3254  UConverter *cnv,
3255  UErrorCode &errorCode);
3256 
3257 #endif
3258 
3282  UnicodeString(const char *src, int32_t textLength, enum EInvariant inv);
3283 
3284 
3301  UnicodeString(const UnicodeString& that);
3302 
3309  UnicodeString(UnicodeString &&src) U_NOEXCEPT;
3310 
3317  UnicodeString(const UnicodeString& src, int32_t srcStart);
3318 
3326  UnicodeString(const UnicodeString& src, int32_t srcStart, int32_t srcLength);
3327 
3341  virtual UnicodeString *clone() const;
3342 
3346  virtual ~UnicodeString();
3347 
3361  static UnicodeString fromUTF8(StringPiece utf8);
3362 
3374  static UnicodeString fromUTF32(const UChar32 *utf32, int32_t length);
3375 
3376  /* Miscellaneous operations */
3377 
3412  UnicodeString unescape() const;
3413 
3433  UChar32 unescapeAt(int32_t &offset) const;
3434 
3440  static UClassID U_EXPORT2 getStaticClassID();
3441 
3447  virtual UClassID getDynamicClassID() const;
3448 
3449  //========================================
3450  // Implementation methods
3451  //========================================
3452 
3453 protected:
3458  virtual int32_t getLength() const;
3459 
3465  virtual char16_t getCharAt(int32_t offset) const;
3466 
3472  virtual UChar32 getChar32At(int32_t offset) const;
3473 
3474 private:
3475  // For char* constructors. Could be made public.
3476  UnicodeString &setToUTF8(StringPiece utf8);
3477  // For extract(char*).
3478  // We could make a toUTF8(target, capacity, errorCode) public but not
3479  // this version: New API will be cleaner if we make callers create substrings
3480  // rather than having start+length on every method,
3481  // and it should take a UErrorCode&.
3482  int32_t
3483  toUTF8(int32_t start, int32_t len,
3484  char *target, int32_t capacity) const;
3485 
3490  UBool doEquals(const UnicodeString &text, int32_t len) const;
3491 
3492  inline int8_t
3493  doCompare(int32_t start,
3494  int32_t length,
3495  const UnicodeString& srcText,
3496  int32_t srcStart,
3497  int32_t srcLength) const;
3498 
3499  int8_t doCompare(int32_t start,
3500  int32_t length,
3501  const char16_t *srcChars,
3502  int32_t srcStart,
3503  int32_t srcLength) const;
3504 
3505  inline int8_t
3506  doCompareCodePointOrder(int32_t start,
3507  int32_t length,
3508  const UnicodeString& srcText,
3509  int32_t srcStart,
3510  int32_t srcLength) const;
3511 
3512  int8_t doCompareCodePointOrder(int32_t start,
3513  int32_t length,
3514  const char16_t *srcChars,
3515  int32_t srcStart,
3516  int32_t srcLength) const;
3517 
3518  inline int8_t
3519  doCaseCompare(int32_t start,
3520  int32_t length,
3521  const UnicodeString &srcText,
3522  int32_t srcStart,
3523  int32_t srcLength,
3524  uint32_t options) const;
3525 
3526  int8_t
3527  doCaseCompare(int32_t start,
3528  int32_t length,
3529  const char16_t *srcChars,
3530  int32_t srcStart,
3531  int32_t srcLength,
3532  uint32_t options) const;
3533 
3534  int32_t doIndexOf(char16_t c,
3535  int32_t start,
3536  int32_t length) const;
3537 
3538  int32_t doIndexOf(UChar32 c,
3539  int32_t start,
3540  int32_t length) const;
3541 
3542  int32_t doLastIndexOf(char16_t c,
3543  int32_t start,
3544  int32_t length) const;
3545 
3546  int32_t doLastIndexOf(UChar32 c,
3547  int32_t start,
3548  int32_t length) const;
3549 
3550  void doExtract(int32_t start,
3551  int32_t length,
3552  char16_t *dst,
3553  int32_t dstStart) const;
3554 
3555  inline void doExtract(int32_t start,
3556  int32_t length,
3557  UnicodeString& target) const;
3558 
3559  inline char16_t doCharAt(int32_t offset) const;
3560 
3561  UnicodeString& doReplace(int32_t start,
3562  int32_t length,
3563  const UnicodeString& srcText,
3564  int32_t srcStart,
3565  int32_t srcLength);
3566 
3567  UnicodeString& doReplace(int32_t start,
3568  int32_t length,
3569  const char16_t *srcChars,
3570  int32_t srcStart,
3571  int32_t srcLength);
3572 
3573  UnicodeString& doAppend(const UnicodeString& src, int32_t srcStart, int32_t srcLength);
3574  UnicodeString& doAppend(const char16_t *srcChars, int32_t srcStart, int32_t srcLength);
3575 
3576  UnicodeString& doReverse(int32_t start,
3577  int32_t length);
3578 
3579  // calculate hash code
3580  int32_t doHashCode(void) const;
3581 
3582  // get pointer to start of array
3583  // these do not check for kOpenGetBuffer, unlike the public getBuffer() function
3584  inline char16_t* getArrayStart(void);
3585  inline const char16_t* getArrayStart(void) const;
3586 
3587  inline UBool hasShortLength() const;
3588  inline int32_t getShortLength() const;
3589 
3590  // A UnicodeString object (not necessarily its current buffer)
3591  // is writable unless it isBogus() or it has an "open" getBuffer(minCapacity).
3592  inline UBool isWritable() const;
3593 
3594  // Is the current buffer writable?
3595  inline UBool isBufferWritable() const;
3596 
3597  // None of the following does releaseArray().
3598  inline void setZeroLength();
3599  inline void setShortLength(int32_t len);
3600  inline void setLength(int32_t len);
3601  inline void setToEmpty();
3602  inline void setArray(char16_t *array, int32_t len, int32_t capacity); // sets length but not flags
3603 
3604  // allocate the array; result may be the stack buffer
3605  // sets refCount to 1 if appropriate
3606  // sets fArray, fCapacity, and flags
3607  // sets length to 0
3608  // returns boolean for success or failure
3609  UBool allocate(int32_t capacity);
3610 
3611  // release the array if owned
3612  void releaseArray(void);
3613 
3614  // turn a bogus string into an empty one
3615  void unBogus();
3616 
3617  // implements assigment operator, copy constructor, and fastCopyFrom()
3618  UnicodeString &copyFrom(const UnicodeString &src, UBool fastCopy=FALSE);
3619 
3620  // Copies just the fields without memory management.
3621  void copyFieldsFrom(UnicodeString &src, UBool setSrcToBogus) U_NOEXCEPT;
3622 
3623  // Pin start and limit to acceptable values.
3624  inline void pinIndex(int32_t& start) const;
3625  inline void pinIndices(int32_t& start,
3626  int32_t& length) const;
3627 
3628 #if !UCONFIG_NO_CONVERSION
3629 
3630  /* Internal extract() using UConverter. */
3631  int32_t doExtract(int32_t start, int32_t length,
3632  char *dest, int32_t destCapacity,
3633  UConverter *cnv,
3634  UErrorCode &errorCode) const;
3635 
3636  /*
3637  * Real constructor for converting from codepage data.
3638  * It assumes that it is called with !fRefCounted.
3639  *
3640  * If `codepage==0`, then the default converter
3641  * is used for the platform encoding.
3642  * If `codepage` is an empty string (`""`),
3643  * then a simple conversion is performed on the codepage-invariant
3644  * subset ("invariant characters") of the platform encoding. See utypes.h.
3645  */
3646  void doCodepageCreate(const char *codepageData,
3647  int32_t dataLength,
3648  const char *codepage);
3649 
3650  /*
3651  * Worker function for creating a UnicodeString from
3652  * a codepage string using a UConverter.
3653  */
3654  void
3655  doCodepageCreate(const char *codepageData,
3656  int32_t dataLength,
3657  UConverter *converter,
3658  UErrorCode &status);
3659 
3660 #endif
3661 
3662  /*
3663  * This function is called when write access to the array
3664  * is necessary.
3665  *
3666  * We need to make a copy of the array if
3667  * the buffer is read-only, or
3668  * the buffer is refCounted (shared), and refCount>1, or
3669  * the buffer is too small.
3670  *
3671  * Return FALSE if memory could not be allocated.
3672  */
3673  UBool cloneArrayIfNeeded(int32_t newCapacity = -1,
3674  int32_t growCapacity = -1,
3675  UBool doCopyArray = TRUE,
3676  int32_t **pBufferToDelete = 0,
3677  UBool forceClone = FALSE);
3678 
3684  UnicodeString &
3685  caseMap(int32_t caseLocale, uint32_t options,
3687  BreakIterator *iter,
3688 #endif
3689  UStringCaseMapper *stringCaseMapper);
3690 
3691  // ref counting
3692  void addRef(void);
3693  int32_t removeRef(void);
3694  int32_t refCount(void) const;
3695 
3696  // constants
3697  enum {
3703  US_STACKBUF_SIZE=(int32_t)(UNISTR_OBJECT_SIZE-sizeof(void *)-2)/U_SIZEOF_UCHAR,
3704  kInvalidUChar=0xffff, // U+FFFF returned by charAt(invalid index)
3705  kInvalidHashCode=0, // invalid hash code
3706  kEmptyHashCode=1, // hash code for empty string
3707 
3708  // bit flag values for fLengthAndFlags
3709  kIsBogus=1, // this string is bogus, i.e., not valid or NULL
3710  kUsingStackBuffer=2,// using fUnion.fStackFields instead of fUnion.fFields
3711  kRefCounted=4, // there is a refCount field before the characters in fArray
3712  kBufferIsReadonly=8,// do not write to this buffer
3713  kOpenGetBuffer=16, // getBuffer(minCapacity) was called (is "open"),
3714  // and releaseBuffer(newLength) must be called
3715  kAllStorageFlags=0x1f,
3716 
3717  kLengthShift=5, // remaining 11 bits for non-negative short length, or negative if long
3718  kLength1=1<<kLengthShift,
3719  kMaxShortLength=0x3ff, // max non-negative short length (leaves top bit 0)
3720  kLengthIsLarge=0xffe0, // short length < 0, real length is in fUnion.fFields.fLength
3721 
3722  // combined values for convenience
3723  kShortString=kUsingStackBuffer,
3724  kLongString=kRefCounted,
3725  kReadonlyAlias=kBufferIsReadonly,
3726  kWritableAlias=0
3727  };
3728 
3729  friend class UnicodeStringAppendable;
3730 
3731  union StackBufferOrFields; // forward declaration necessary before friend declaration
3732  friend union StackBufferOrFields; // make US_STACKBUF_SIZE visible inside fUnion
3733 
3734  /*
3735  * The following are all the class fields that are stored
3736  * in each UnicodeString object.
3737  * Note that UnicodeString has virtual functions,
3738  * therefore there is an implicit vtable pointer
3739  * as the first real field.
3740  * The fields should be aligned such that no padding is necessary.
3741  * On 32-bit machines, the size should be 32 bytes,
3742  * on 64-bit machines (8-byte pointers), it should be 40 bytes.
3743  *
3744  * We use a hack to achieve this.
3745  *
3746  * With at least some compilers, each of the following is forced to
3747  * a multiple of sizeof(pointer) [the largest field base unit here is a data pointer],
3748  * rounded up with additional padding if the fields do not already fit that requirement:
3749  * - sizeof(class UnicodeString)
3750  * - offsetof(UnicodeString, fUnion)
3751  * - sizeof(fUnion)
3752  * - sizeof(fStackFields)
3753  *
3754  * We optimize for the longest possible internal buffer for short strings.
3755  * fUnion.fStackFields begins with 2 bytes for storage flags
3756  * and the length of relatively short strings,
3757  * followed by the buffer for short string contents.
3758  * There is no padding inside fStackFields.
3759  *
3760  * Heap-allocated and aliased strings use fUnion.fFields.
3761  * Both fStackFields and fFields must begin with the same fields for flags and short length,
3762  * that is, those must have the same memory offsets inside the object,
3763  * because the flags must be inspected in order to decide which half of fUnion is being used.
3764  * We assume that the compiler does not reorder the fields.
3765  *
3766  * (Padding at the end of fFields is ok:
3767  * As long as it is no larger than fStackFields, it is not wasted space.)
3768  *
3769  * For some of the history of the UnicodeString class fields layout, see
3770  * - ICU ticket #11551 "longer UnicodeString contents in stack buffer"
3771  * - ICU ticket #11336 "UnicodeString: recombine stack buffer arrays"
3772  * - ICU ticket #8322 "why is sizeof(UnicodeString)==48?"
3773  */
3774  // (implicit) *vtable;
3775  union StackBufferOrFields {
3776  // fStackFields is used iff (fLengthAndFlags&kUsingStackBuffer) else fFields is used.
3777  // Each struct of the union must begin with fLengthAndFlags.
3778  struct {
3779  int16_t fLengthAndFlags; // bit fields: see constants above
3780  char16_t fBuffer[US_STACKBUF_SIZE]; // buffer for short strings
3781  } fStackFields;
3782  struct {
3783  int16_t fLengthAndFlags; // bit fields: see constants above
3784  int32_t fLength; // number of characters in fArray if >127; else undefined
3785  int32_t fCapacity; // capacity of fArray (in char16_ts)
3786  // array pointer last to minimize padding for machines with P128 data model
3787  // or pointer sizes that are not a power of 2
3788  char16_t *fArray; // the Unicode data
3789  } fFields;
3790  } fUnion;
3791 };
3792 
3801 U_COMMON_API UnicodeString U_EXPORT2
3802 operator+ (const UnicodeString &s1, const UnicodeString &s2);
3803 
3804 //========================================
3805 // Inline members
3806 //========================================
3807 
3808 //========================================
3809 // Privates
3810 //========================================
3811 
3812 inline void
3813 UnicodeString::pinIndex(int32_t& start) const
3814 {
3815  // pin index
3816  if(start < 0) {
3817  start = 0;
3818  } else if(start > length()) {
3819  start = length();
3820  }
3821 }
3822 
3823 inline void
3824 UnicodeString::pinIndices(int32_t& start,
3825  int32_t& _length) const
3826 {
3827  // pin indices
3828  int32_t len = length();
3829  if(start < 0) {
3830  start = 0;
3831  } else if(start > len) {
3832  start = len;
3833  }
3834  if(_length < 0) {
3835  _length = 0;
3836  } else if(_length > (len - start)) {
3837  _length = (len - start);
3838  }
3839 }
3840 
3841 inline char16_t*
3842 UnicodeString::getArrayStart() {
3843  return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3844  fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
3845 }
3846 
3847 inline const char16_t*
3848 UnicodeString::getArrayStart() const {
3849  return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3850  fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
3851 }
3852 
3853 //========================================
3854 // Default constructor
3855 //========================================
3856 
3857 inline
3858 UnicodeString::UnicodeString() {
3859  fUnion.fStackFields.fLengthAndFlags=kShortString;
3860 }
3861 
3862 inline UnicodeString::UnicodeString(const std::nullptr_t /*text*/) {
3863  fUnion.fStackFields.fLengthAndFlags=kShortString;
3864 }
3865 
3866 inline UnicodeString::UnicodeString(const std::nullptr_t /*text*/, int32_t /*length*/) {
3867  fUnion.fStackFields.fLengthAndFlags=kShortString;
3868 }
3869 
3870 inline UnicodeString::UnicodeString(std::nullptr_t /*buffer*/, int32_t /*buffLength*/, int32_t /*buffCapacity*/) {
3871  fUnion.fStackFields.fLengthAndFlags=kShortString;
3872 }
3873 
3874 //========================================
3875 // Read-only implementation methods
3876 //========================================
3877 inline UBool
3878 UnicodeString::hasShortLength() const {
3879  return fUnion.fFields.fLengthAndFlags>=0;
3880 }
3881 
3882 inline int32_t
3883 UnicodeString::getShortLength() const {
3884  // fLengthAndFlags must be non-negative -> short length >= 0
3885  // and arithmetic or logical shift does not matter.
3886  return fUnion.fFields.fLengthAndFlags>>kLengthShift;
3887 }
3888 
3889 inline int32_t
3890 UnicodeString::length() const {
3891  return hasShortLength() ? getShortLength() : fUnion.fFields.fLength;
3892 }
3893 
3894 inline int32_t
3895 UnicodeString::getCapacity() const {
3896  return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3897  US_STACKBUF_SIZE : fUnion.fFields.fCapacity;
3898 }
3899 
3900 inline int32_t
3901 UnicodeString::hashCode() const
3902 { return doHashCode(); }
3903 
3904 inline UBool
3905 UnicodeString::isBogus() const
3906 { return (UBool)(fUnion.fFields.fLengthAndFlags & kIsBogus); }
3907 
3908 inline UBool
3909 UnicodeString::isWritable() const
3910 { return (UBool)!(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus)); }
3911 
3912 inline UBool
3913 UnicodeString::isBufferWritable() const
3914 {
3915  return (UBool)(
3916  !(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus|kBufferIsReadonly)) &&
3917  (!(fUnion.fFields.fLengthAndFlags&kRefCounted) || refCount()==1));
3918 }
3919 
3920 inline const char16_t *
3921 UnicodeString::getBuffer() const {
3922  if(fUnion.fFields.fLengthAndFlags&(kIsBogus|kOpenGetBuffer)) {
3923  return nullptr;
3924  } else if(fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) {
3925  return fUnion.fStackFields.fBuffer;
3926  } else {
3927  return fUnion.fFields.fArray;
3928  }
3929 }
3930 
3931 //========================================
3932 // Read-only alias methods
3933 //========================================
3934 inline int8_t
3935 UnicodeString::doCompare(int32_t start,
3936  int32_t thisLength,
3937  const UnicodeString& srcText,
3938  int32_t srcStart,
3939  int32_t srcLength) const
3940 {
3941  if(srcText.isBogus()) {
3942  return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
3943  } else {
3944  srcText.pinIndices(srcStart, srcLength);
3945  return doCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
3946  }
3947 }
3948 
3949 inline UBool
3951 {
3952  if(isBogus()) {
3953  return text.isBogus();
3954  } else {
3955  int32_t len = length(), textLength = text.length();
3956  return !text.isBogus() && len == textLength && doEquals(text, len);
3957  }
3958 }
3959 
3960 inline UBool
3962 { return (! operator==(text)); }
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 UBool
3977 UnicodeString::operator<= (const UnicodeString& text) const
3978 { return doCompare(0, length(), text, 0, text.length()) != 1; }
3979 
3980 inline int8_t
3981 UnicodeString::compare(const UnicodeString& text) const
3982 { return doCompare(0, length(), text, 0, text.length()); }
3983 
3984 inline int8_t
3985 UnicodeString::compare(int32_t start,
3986  int32_t _length,
3987  const UnicodeString& srcText) const
3988 { return doCompare(start, _length, srcText, 0, srcText.length()); }
3989 
3990 inline int8_t
3991 UnicodeString::compare(ConstChar16Ptr srcChars,
3992  int32_t srcLength) const
3993 { return doCompare(0, length(), srcChars, 0, srcLength); }
3994 
3995 inline int8_t
3996 UnicodeString::compare(int32_t start,
3997  int32_t _length,
3998  const UnicodeString& srcText,
3999  int32_t srcStart,
4000  int32_t srcLength) const
4001 { return doCompare(start, _length, srcText, srcStart, srcLength); }
4002 
4003 inline int8_t
4004 UnicodeString::compare(int32_t start,
4005  int32_t _length,
4006  const char16_t *srcChars) const
4007 { return doCompare(start, _length, srcChars, 0, _length); }
4008 
4009 inline int8_t
4010 UnicodeString::compare(int32_t start,
4011  int32_t _length,
4012  const char16_t *srcChars,
4013  int32_t srcStart,
4014  int32_t srcLength) const
4015 { return doCompare(start, _length, srcChars, srcStart, srcLength); }
4016 
4017 inline int8_t
4018 UnicodeString::compareBetween(int32_t start,
4019  int32_t limit,
4020  const UnicodeString& srcText,
4021  int32_t srcStart,
4022  int32_t srcLimit) const
4023 { return doCompare(start, limit - start,
4024  srcText, srcStart, srcLimit - srcStart); }
4025 
4026 inline int8_t
4027 UnicodeString::doCompareCodePointOrder(int32_t start,
4028  int32_t thisLength,
4029  const UnicodeString& srcText,
4030  int32_t srcStart,
4031  int32_t srcLength) const
4032 {
4033  if(srcText.isBogus()) {
4034  return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
4035  } else {
4036  srcText.pinIndices(srcStart, srcLength);
4037  return doCompareCodePointOrder(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
4038  }
4039 }
4040 
4041 inline int8_t
4042 UnicodeString::compareCodePointOrder(const UnicodeString& text) const
4043 { return doCompareCodePointOrder(0, length(), text, 0, text.length()); }
4044 
4045 inline int8_t
4046 UnicodeString::compareCodePointOrder(int32_t start,
4047  int32_t _length,
4048  const UnicodeString& srcText) const
4049 { return doCompareCodePointOrder(start, _length, srcText, 0, srcText.length()); }
4050 
4051 inline int8_t
4052 UnicodeString::compareCodePointOrder(ConstChar16Ptr srcChars,
4053  int32_t srcLength) const
4054 { return doCompareCodePointOrder(0, length(), srcChars, 0, srcLength); }
4055 
4056 inline int8_t
4057 UnicodeString::compareCodePointOrder(int32_t start,
4058  int32_t _length,
4059  const UnicodeString& srcText,
4060  int32_t srcStart,
4061  int32_t srcLength) const
4062 { return doCompareCodePointOrder(start, _length, srcText, srcStart, srcLength); }
4063 
4064 inline int8_t
4065 UnicodeString::compareCodePointOrder(int32_t start,
4066  int32_t _length,
4067  const char16_t *srcChars) const
4068 { return doCompareCodePointOrder(start, _length, srcChars, 0, _length); }
4069 
4070 inline int8_t
4071 UnicodeString::compareCodePointOrder(int32_t start,
4072  int32_t _length,
4073  const char16_t *srcChars,
4074  int32_t srcStart,
4075  int32_t srcLength) const
4076 { return doCompareCodePointOrder(start, _length, srcChars, srcStart, srcLength); }
4077 
4078 inline int8_t
4079 UnicodeString::compareCodePointOrderBetween(int32_t start,
4080  int32_t limit,
4081  const UnicodeString& srcText,
4082  int32_t srcStart,
4083  int32_t srcLimit) const
4084 { return doCompareCodePointOrder(start, limit - start,
4085  srcText, srcStart, srcLimit - srcStart); }
4086 
4087 inline int8_t
4088 UnicodeString::doCaseCompare(int32_t start,
4089  int32_t thisLength,
4090  const UnicodeString &srcText,
4091  int32_t srcStart,
4092  int32_t srcLength,
4093  uint32_t options) const
4094 {
4095  if(srcText.isBogus()) {
4096  return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
4097  } else {
4098  srcText.pinIndices(srcStart, srcLength);
4099  return doCaseCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength, options);
4100  }
4101 }
4102 
4103 inline int8_t
4104 UnicodeString::caseCompare(const UnicodeString &text, uint32_t options) const {
4105  return doCaseCompare(0, length(), text, 0, text.length(), options);
4106 }
4107 
4108 inline int8_t
4109 UnicodeString::caseCompare(int32_t start,
4110  int32_t _length,
4111  const UnicodeString &srcText,
4112  uint32_t options) const {
4113  return doCaseCompare(start, _length, srcText, 0, srcText.length(), options);
4114 }
4115 
4116 inline int8_t
4117 UnicodeString::caseCompare(ConstChar16Ptr srcChars,
4118  int32_t srcLength,
4119  uint32_t options) const {
4120  return doCaseCompare(0, length(), srcChars, 0, srcLength, options);
4121 }
4122 
4123 inline int8_t
4124 UnicodeString::caseCompare(int32_t start,
4125  int32_t _length,
4126  const UnicodeString &srcText,
4127  int32_t srcStart,
4128  int32_t srcLength,
4129  uint32_t options) const {
4130  return doCaseCompare(start, _length, srcText, srcStart, srcLength, options);
4131 }
4132 
4133 inline int8_t
4134 UnicodeString::caseCompare(int32_t start,
4135  int32_t _length,
4136  const char16_t *srcChars,
4137  uint32_t options) const {
4138  return doCaseCompare(start, _length, srcChars, 0, _length, options);
4139 }
4140 
4141 inline int8_t
4142 UnicodeString::caseCompare(int32_t start,
4143  int32_t _length,
4144  const char16_t *srcChars,
4145  int32_t srcStart,
4146  int32_t srcLength,
4147  uint32_t options) const {
4148  return doCaseCompare(start, _length, srcChars, srcStart, srcLength, options);
4149 }
4150 
4151 inline int8_t
4152 UnicodeString::caseCompareBetween(int32_t start,
4153  int32_t limit,
4154  const UnicodeString &srcText,
4155  int32_t srcStart,
4156  int32_t srcLimit,
4157  uint32_t options) const {
4158  return doCaseCompare(start, limit - start, srcText, srcStart, srcLimit - srcStart, options);
4159 }
4160 
4161 inline int32_t
4162 UnicodeString::indexOf(const UnicodeString& srcText,
4163  int32_t srcStart,
4164  int32_t srcLength,
4165  int32_t start,
4166  int32_t _length) const
4167 {
4168  if(!srcText.isBogus()) {
4169  srcText.pinIndices(srcStart, srcLength);
4170  if(srcLength > 0) {
4171  return indexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
4172  }
4173  }
4174  return -1;
4175 }
4176 
4177 inline int32_t
4178 UnicodeString::indexOf(const UnicodeString& text) const
4179 { return indexOf(text, 0, text.length(), 0, length()); }
4180 
4181 inline int32_t
4182 UnicodeString::indexOf(const UnicodeString& text,
4183  int32_t start) const {
4184  pinIndex(start);
4185  return indexOf(text, 0, text.length(), start, length() - start);
4186 }
4187 
4188 inline int32_t
4189 UnicodeString::indexOf(const UnicodeString& text,
4190  int32_t start,
4191  int32_t _length) const
4192 { return indexOf(text, 0, text.length(), start, _length); }
4193 
4194 inline int32_t
4195 UnicodeString::indexOf(const char16_t *srcChars,
4196  int32_t srcLength,
4197  int32_t start) const {
4198  pinIndex(start);
4199  return indexOf(srcChars, 0, srcLength, start, length() - start);
4200 }
4201 
4202 inline int32_t
4203 UnicodeString::indexOf(ConstChar16Ptr srcChars,
4204  int32_t srcLength,
4205  int32_t start,
4206  int32_t _length) const
4207 { return indexOf(srcChars, 0, srcLength, start, _length); }
4208 
4209 inline int32_t
4210 UnicodeString::indexOf(char16_t c,
4211  int32_t start,
4212  int32_t _length) const
4213 { return doIndexOf(c, start, _length); }
4214 
4215 inline int32_t
4216 UnicodeString::indexOf(UChar32 c,
4217  int32_t start,
4218  int32_t _length) const
4219 { return doIndexOf(c, start, _length); }
4220 
4221 inline int32_t
4222 UnicodeString::indexOf(char16_t c) const
4223 { return doIndexOf(c, 0, length()); }
4224 
4225 inline int32_t
4226 UnicodeString::indexOf(UChar32 c) const
4227 { return indexOf(c, 0, length()); }
4228 
4229 inline int32_t
4230 UnicodeString::indexOf(char16_t c,
4231  int32_t start) const {
4232  pinIndex(start);
4233  return doIndexOf(c, start, length() - start);
4234 }
4235 
4236 inline int32_t
4237 UnicodeString::indexOf(UChar32 c,
4238  int32_t start) const {
4239  pinIndex(start);
4240  return indexOf(c, start, length() - start);
4241 }
4242 
4243 inline int32_t
4244 UnicodeString::lastIndexOf(ConstChar16Ptr srcChars,
4245  int32_t srcLength,
4246  int32_t start,
4247  int32_t _length) const
4248 { return lastIndexOf(srcChars, 0, srcLength, start, _length); }
4249 
4250 inline int32_t
4251 UnicodeString::lastIndexOf(const char16_t *srcChars,
4252  int32_t srcLength,
4253  int32_t start) const {
4254  pinIndex(start);
4255  return lastIndexOf(srcChars, 0, srcLength, start, length() - start);
4256 }
4257 
4258 inline int32_t
4259 UnicodeString::lastIndexOf(const UnicodeString& srcText,
4260  int32_t srcStart,
4261  int32_t srcLength,
4262  int32_t start,
4263  int32_t _length) const
4264 {
4265  if(!srcText.isBogus()) {
4266  srcText.pinIndices(srcStart, srcLength);
4267  if(srcLength > 0) {
4268  return lastIndexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
4269  }
4270  }
4271  return -1;
4272 }
4273 
4274 inline int32_t
4275 UnicodeString::lastIndexOf(const UnicodeString& text,
4276  int32_t start,
4277  int32_t _length) const
4278 { return lastIndexOf(text, 0, text.length(), start, _length); }
4279 
4280 inline int32_t
4281 UnicodeString::lastIndexOf(const UnicodeString& text,
4282  int32_t start) const {
4283  pinIndex(start);
4284  return lastIndexOf(text, 0, text.length(), start, length() - start);
4285 }
4286 
4287 inline int32_t
4288 UnicodeString::lastIndexOf(const UnicodeString& text) const
4289 { return lastIndexOf(text, 0, text.length(), 0, length()); }
4290 
4291 inline int32_t
4292 UnicodeString::lastIndexOf(char16_t c,
4293  int32_t start,
4294  int32_t _length) const
4295 { return doLastIndexOf(c, start, _length); }
4296 
4297 inline int32_t
4298 UnicodeString::lastIndexOf(UChar32 c,
4299  int32_t start,
4300  int32_t _length) const {
4301  return doLastIndexOf(c, start, _length);
4302 }
4303 
4304 inline int32_t
4305 UnicodeString::lastIndexOf(char16_t c) const
4306 { return doLastIndexOf(c, 0, length()); }
4307 
4308 inline int32_t
4309 UnicodeString::lastIndexOf(UChar32 c) const {
4310  return lastIndexOf(c, 0, length());
4311 }
4312 
4313 inline int32_t
4314 UnicodeString::lastIndexOf(char16_t c,
4315  int32_t start) const {
4316  pinIndex(start);
4317  return doLastIndexOf(c, start, length() - start);
4318 }
4319 
4320 inline int32_t
4321 UnicodeString::lastIndexOf(UChar32 c,
4322  int32_t start) const {
4323  pinIndex(start);
4324  return lastIndexOf(c, start, length() - start);
4325 }
4326 
4327 inline UBool
4328 UnicodeString::startsWith(const UnicodeString& text) const
4329 { return compare(0, text.length(), text, 0, text.length()) == 0; }
4330 
4331 inline UBool
4332 UnicodeString::startsWith(const UnicodeString& srcText,
4333  int32_t srcStart,
4334  int32_t srcLength) const
4335 { return doCompare(0, srcLength, srcText, srcStart, srcLength) == 0; }
4336 
4337 inline UBool
4338 UnicodeString::startsWith(ConstChar16Ptr srcChars, int32_t srcLength) const {
4339  if(srcLength < 0) {
4340  srcLength = u_strlen(toUCharPtr(srcChars));
4341  }
4342  return doCompare(0, srcLength, srcChars, 0, srcLength) == 0;
4343 }
4344 
4345 inline UBool
4346 UnicodeString::startsWith(const char16_t *srcChars, int32_t srcStart, int32_t srcLength) const {
4347  if(srcLength < 0) {
4348  srcLength = u_strlen(toUCharPtr(srcChars));
4349  }
4350  return doCompare(0, srcLength, srcChars, srcStart, srcLength) == 0;
4351 }
4352 
4353 inline UBool
4354 UnicodeString::endsWith(const UnicodeString& text) const
4355 { return doCompare(length() - text.length(), text.length(),
4356  text, 0, text.length()) == 0; }
4357 
4358 inline UBool
4359 UnicodeString::endsWith(const UnicodeString& srcText,
4360  int32_t srcStart,
4361  int32_t srcLength) const {
4362  srcText.pinIndices(srcStart, srcLength);
4363  return doCompare(length() - srcLength, srcLength,
4364  srcText, srcStart, srcLength) == 0;
4365 }
4366 
4367 inline UBool
4368 UnicodeString::endsWith(ConstChar16Ptr srcChars,
4369  int32_t srcLength) const {
4370  if(srcLength < 0) {
4371  srcLength = u_strlen(toUCharPtr(srcChars));
4372  }
4373  return doCompare(length() - srcLength, srcLength,
4374  srcChars, 0, srcLength) == 0;
4375 }
4376 
4377 inline UBool
4378 UnicodeString::endsWith(const char16_t *srcChars,
4379  int32_t srcStart,
4380  int32_t srcLength) const {
4381  if(srcLength < 0) {
4382  srcLength = u_strlen(toUCharPtr(srcChars + srcStart));
4383  }
4384  return doCompare(length() - srcLength, srcLength,
4385  srcChars, srcStart, srcLength) == 0;
4386 }
4387 
4388 //========================================
4389 // replace
4390 //========================================
4391 inline UnicodeString&
4392 UnicodeString::replace(int32_t start,
4393  int32_t _length,
4394  const UnicodeString& srcText)
4395 { return doReplace(start, _length, srcText, 0, srcText.length()); }
4396 
4397 inline UnicodeString&
4398 UnicodeString::replace(int32_t start,
4399  int32_t _length,
4400  const UnicodeString& srcText,
4401  int32_t srcStart,
4402  int32_t srcLength)
4403 { return doReplace(start, _length, srcText, srcStart, srcLength); }
4404 
4405 inline UnicodeString&
4406 UnicodeString::replace(int32_t start,
4407  int32_t _length,
4408  ConstChar16Ptr srcChars,
4409  int32_t srcLength)
4410 { return doReplace(start, _length, srcChars, 0, srcLength); }
4411 
4412 inline UnicodeString&
4413 UnicodeString::replace(int32_t start,
4414  int32_t _length,
4415  const char16_t *srcChars,
4416  int32_t srcStart,
4417  int32_t srcLength)
4418 { return doReplace(start, _length, srcChars, srcStart, srcLength); }
4419 
4420 inline UnicodeString&
4421 UnicodeString::replace(int32_t start,
4422  int32_t _length,
4423  char16_t srcChar)
4424 { return doReplace(start, _length, &srcChar, 0, 1); }
4425 
4426 inline UnicodeString&
4427 UnicodeString::replaceBetween(int32_t start,
4428  int32_t limit,
4429  const UnicodeString& srcText)
4430 { return doReplace(start, limit - start, srcText, 0, srcText.length()); }
4431 
4432 inline UnicodeString&
4433 UnicodeString::replaceBetween(int32_t start,
4434  int32_t limit,
4435  const UnicodeString& srcText,
4436  int32_t srcStart,
4437  int32_t srcLimit)
4438 { return doReplace(start, limit - start, srcText, srcStart, srcLimit - srcStart); }
4439 
4440 inline UnicodeString&
4441 UnicodeString::findAndReplace(const UnicodeString& oldText,
4442  const UnicodeString& newText)
4443 { return findAndReplace(0, length(), oldText, 0, oldText.length(),
4444  newText, 0, newText.length()); }
4445 
4446 inline UnicodeString&
4447 UnicodeString::findAndReplace(int32_t start,
4448  int32_t _length,
4449  const UnicodeString& oldText,
4450  const UnicodeString& newText)
4451 { return findAndReplace(start, _length, oldText, 0, oldText.length(),
4452  newText, 0, newText.length()); }
4453 
4454 // ============================
4455 // extract
4456 // ============================
4457 inline void
4458 UnicodeString::doExtract(int32_t start,
4459  int32_t _length,
4460  UnicodeString& target) const
4461 { target.replace(0, target.length(), *this, start, _length); }
4462 
4463 inline void
4464 UnicodeString::extract(int32_t start,
4465  int32_t _length,
4466  Char16Ptr target,
4467  int32_t targetStart) const
4468 { doExtract(start, _length, target, targetStart); }
4469 
4470 inline void
4471 UnicodeString::extract(int32_t start,
4472  int32_t _length,
4473  UnicodeString& target) const
4474 { doExtract(start, _length, target); }
4475 
4476 #if !UCONFIG_NO_CONVERSION
4477 
4478 inline int32_t
4479 UnicodeString::extract(int32_t start,
4480  int32_t _length,
4481  char *dst,
4482  const char *codepage) const
4483 
4484 {
4485  // This dstSize value will be checked explicitly
4486  return extract(start, _length, dst, dst!=0 ? 0xffffffff : 0, codepage);
4487 }
4488 
4489 #endif
4490 
4491 inline void
4492 UnicodeString::extractBetween(int32_t start,
4493  int32_t limit,
4494  char16_t *dst,
4495  int32_t dstStart) const {
4496  pinIndex(start);
4497  pinIndex(limit);
4498  doExtract(start, limit - start, dst, dstStart);
4499 }
4500 
4501 inline UnicodeString
4502 UnicodeString::tempSubStringBetween(int32_t start, int32_t limit) const {
4503  return tempSubString(start, limit - start);
4504 }
4505 
4506 inline char16_t
4507 UnicodeString::doCharAt(int32_t offset) const
4508 {
4509  if((uint32_t)offset < (uint32_t)length()) {
4510  return getArrayStart()[offset];
4511  } else {
4512  return kInvalidUChar;
4513  }
4514 }
4515 
4516 inline char16_t
4517 UnicodeString::charAt(int32_t offset) const
4518 { return doCharAt(offset); }
4519 
4520 inline char16_t
4521 UnicodeString::operator[] (int32_t offset) const
4522 { return doCharAt(offset); }
4523 
4524 inline UBool
4525 UnicodeString::isEmpty() const {
4526  // Arithmetic or logical right shift does not matter: only testing for 0.
4527  return (fUnion.fFields.fLengthAndFlags>>kLengthShift) == 0;
4528 }
4529 
4530 //========================================
4531 // Write implementation methods
4532 //========================================
4533 inline void
4534 UnicodeString::setZeroLength() {
4535  fUnion.fFields.fLengthAndFlags &= kAllStorageFlags;
4536 }
4537 
4538 inline void
4539 UnicodeString::setShortLength(int32_t len) {
4540  // requires 0 <= len <= kMaxShortLength
4541  fUnion.fFields.fLengthAndFlags =
4542  (int16_t)((fUnion.fFields.fLengthAndFlags & kAllStorageFlags) | (len << kLengthShift));
4543 }
4544 
4545 inline void
4546 UnicodeString::setLength(int32_t len) {
4547  if(len <= kMaxShortLength) {
4548  setShortLength(len);
4549  } else {
4550  fUnion.fFields.fLengthAndFlags |= kLengthIsLarge;
4551  fUnion.fFields.fLength = len;
4552  }
4553 }
4554 
4555 inline void
4556 UnicodeString::setToEmpty() {
4557  fUnion.fFields.fLengthAndFlags = kShortString;
4558 }
4559 
4560 inline void
4561 UnicodeString::setArray(char16_t *array, int32_t len, int32_t capacity) {
4562  setLength(len);
4563  fUnion.fFields.fArray = array;
4564  fUnion.fFields.fCapacity = capacity;
4565 }
4566 
4567 inline UnicodeString&
4568 UnicodeString::operator= (char16_t ch)
4569 { return doReplace(0, length(), &ch, 0, 1); }
4570 
4571 inline UnicodeString&
4572 UnicodeString::operator= (UChar32 ch)
4573 { return replace(0, length(), ch); }
4574 
4575 inline UnicodeString&
4576 UnicodeString::setTo(const UnicodeString& srcText,
4577  int32_t srcStart,
4578  int32_t srcLength)
4579 {
4580  unBogus();
4581  return doReplace(0, length(), srcText, srcStart, srcLength);
4582 }
4583 
4584 inline UnicodeString&
4585 UnicodeString::setTo(const UnicodeString& srcText,
4586  int32_t srcStart)
4587 {
4588  unBogus();
4589  srcText.pinIndex(srcStart);
4590  return doReplace(0, length(), srcText, srcStart, srcText.length() - srcStart);
4591 }
4592 
4593 inline UnicodeString&
4594 UnicodeString::setTo(const UnicodeString& srcText)
4595 {
4596  return copyFrom(srcText);
4597 }
4598 
4599 inline UnicodeString&
4600 UnicodeString::setTo(const char16_t *srcChars,
4601  int32_t srcLength)
4602 {
4603  unBogus();
4604  return doReplace(0, length(), srcChars, 0, srcLength);
4605 }
4606 
4607 inline UnicodeString&
4608 UnicodeString::setTo(char16_t srcChar)
4609 {
4610  unBogus();
4611  return doReplace(0, length(), &srcChar, 0, 1);
4612 }
4613 
4614 inline UnicodeString&
4615 UnicodeString::setTo(UChar32 srcChar)
4616 {
4617  unBogus();
4618  return replace(0, length(), srcChar);
4619 }
4620 
4621 inline UnicodeString&
4622 UnicodeString::append(const UnicodeString& srcText,
4623  int32_t srcStart,
4624  int32_t srcLength)
4625 { return doAppend(srcText, srcStart, srcLength); }
4626 
4627 inline UnicodeString&
4628 UnicodeString::append(const UnicodeString& srcText)
4629 { return doAppend(srcText, 0, srcText.length()); }
4630 
4631 inline UnicodeString&
4632 UnicodeString::append(const char16_t *srcChars,
4633  int32_t srcStart,
4634  int32_t srcLength)
4635 { return doAppend(srcChars, srcStart, srcLength); }
4636 
4637 inline UnicodeString&
4638 UnicodeString::append(ConstChar16Ptr srcChars,
4639  int32_t srcLength)
4640 { return doAppend(srcChars, 0, srcLength); }
4641 
4642 inline UnicodeString&
4643 UnicodeString::append(char16_t srcChar)
4644 { return doAppend(&srcChar, 0, 1); }
4645 
4646 inline UnicodeString&
4647 UnicodeString::operator+= (char16_t ch)
4648 { return doAppend(&ch, 0, 1); }
4649 
4650 inline UnicodeString&
4651 UnicodeString::operator+= (UChar32 ch) {
4652  return append(ch);
4653 }
4654 
4655 inline UnicodeString&
4656 UnicodeString::operator+= (const UnicodeString& srcText)
4657 { return doAppend(srcText, 0, srcText.length()); }
4658 
4659 inline UnicodeString&
4660 UnicodeString::insert(int32_t start,
4661  const UnicodeString& srcText,
4662  int32_t srcStart,
4663  int32_t srcLength)
4664 { return doReplace(start, 0, srcText, srcStart, srcLength); }
4665 
4666 inline UnicodeString&
4667 UnicodeString::insert(int32_t start,
4668  const UnicodeString& srcText)
4669 { return doReplace(start, 0, srcText, 0, srcText.length()); }
4670 
4671 inline UnicodeString&
4672 UnicodeString::insert(int32_t start,
4673  const char16_t *srcChars,
4674  int32_t srcStart,
4675  int32_t srcLength)
4676 { return doReplace(start, 0, srcChars, srcStart, srcLength); }
4677 
4678 inline UnicodeString&
4679 UnicodeString::insert(int32_t start,
4680  ConstChar16Ptr srcChars,
4681  int32_t srcLength)
4682 { return doReplace(start, 0, srcChars, 0, srcLength); }
4683 
4684 inline UnicodeString&
4685 UnicodeString::insert(int32_t start,
4686  char16_t srcChar)
4687 { return doReplace(start, 0, &srcChar, 0, 1); }
4688 
4689 inline UnicodeString&
4690 UnicodeString::insert(int32_t start,
4691  UChar32 srcChar)
4692 { return replace(start, 0, srcChar); }
4693 
4694 
4695 inline UnicodeString&
4696 UnicodeString::remove()
4697 {
4698  // remove() of a bogus string makes the string empty and non-bogus
4699  if(isBogus()) {
4700  setToEmpty();
4701  } else {
4702  setZeroLength();
4703  }
4704  return *this;
4705 }
4706 
4707 inline UnicodeString&
4708 UnicodeString::remove(int32_t start,
4709  int32_t _length)
4710 {
4711  if(start <= 0 && _length == INT32_MAX) {
4712  // remove(guaranteed everything) of a bogus string makes the string empty and non-bogus
4713  return remove();
4714  }
4715  return doReplace(start, _length, NULL, 0, 0);
4716 }
4717 
4718 inline UnicodeString&
4719 UnicodeString::removeBetween(int32_t start,
4720  int32_t limit)
4721 { return doReplace(start, limit - start, NULL, 0, 0); }
4722 
4723 inline UnicodeString &
4724 UnicodeString::retainBetween(int32_t start, int32_t limit) {
4725  truncate(limit);
4726  return doReplace(0, start, NULL, 0, 0);
4727 }
4728 
4729 inline UBool
4730 UnicodeString::truncate(int32_t targetLength)
4731 {
4732  if(isBogus() && targetLength == 0) {
4733  // truncate(0) of a bogus string makes the string empty and non-bogus
4734  unBogus();
4735  return FALSE;
4736  } else if((uint32_t)targetLength < (uint32_t)length()) {
4737  setLength(targetLength);
4738  return TRUE;
4739  } else {
4740  return FALSE;
4741  }
4742 }
4743 
4744 inline UnicodeString&
4745 UnicodeString::reverse()
4746 { return doReverse(0, length()); }
4747 
4748 inline UnicodeString&
4749 UnicodeString::reverse(int32_t start,
4750  int32_t _length)
4751 { return doReverse(start, _length); }
4752 
4753 U_NAMESPACE_END
4754 
4755 #endif /* U_SHOW_CPLUSPLUS_API */
4756 
4757 #endif
#define UNISTR_OBJECT_SIZE
Desired sizeof(UnicodeString) in bytes.
Definition: unistr.h:207
An Appendable implementation which writes to a UnicodeString.
Definition: appendable.h:156
EInvariant
Constant to be used in the UnicodeString(char *, int32_t, EInvariant) constructor which constructs a ...
Definition: unistr.h:306
UnicodeString(const uint16_t *text, int32_t textLength)
uint16_t * constructor.
Definition: unistr.h:3047
UnicodeString(wchar_t *buffer, int32_t buffLength, int32_t buffCapacity)
Writable-aliasing wchar_t * constructor.
Definition: unistr.h:3142
virtual void copy(int32_t start, int32_t limit, int32_t dest)=0
Copies a substring of this object, retaining metadata.
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
#define U_CALLCONV
Similar to U_CDECL_BEGIN/U_CDECL_END, this qualifier is necessary in callback function typedefs to ma...
Definition: platform.h:870
UNISTR_FROM_STRING_EXPLICIT UnicodeString(const uint16_t *text)
uint16_t * constructor.
Definition: unistr.h:2997
UNISTR_FROM_STRING_EXPLICIT UnicodeString(const wchar_t *text)
wchar_t * constructor.
Definition: unistr.h:3013
void * UClassID
UClassID is used to identify classes without using the compiler&#39;s RTTI.
Definition: uobject.h:96
#define U_SIZEOF_UCHAR
Number of bytes in a UChar.
Definition: umachine.h:316
virtual void extractBetween(int32_t start, int32_t limit, UnicodeString &target) const =0
Copies characters in the range [start, limit) into the UnicodeString target.
A ByteSink can be filled with bytes.
Definition: bytestream.h:53
virtual UChar32 getChar32At(int32_t offset) const =0
Virtual version of char32At().
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:69
#define UCONFIG_NO_BREAK_ITERATION
This switch turns off break iteration.
Definition: uconfig.h:348
UBool isBogus(void) const
Determine if this object contains a valid string.
Definition: unistr.h:3905
Records lengths of string edits but not replacement text.
Definition: edits.h:80
C++ API: StringPiece: Read-only byte string wrapper class.
Replaceable is an abstract base class representing a string of characters that supports the replaceme...
Definition: rep.h:77
#define UNISTR_FROM_CHAR_EXPLICIT
This can be defined to be empty or "explicit".
Definition: unistr.h:149
friend void swap(UnicodeString &s1, UnicodeString &s2) U_NOEXCEPT
Non-member UnicodeString swap function.
Definition: unistr.h:1924
StringClass & toUTF8String(StringClass &result) const
Convert the UnicodeString to UTF-8 and append the result to a standard string.
Definition: unistr.h:1728
int32_t length() const
Returns the number of 16-bit code units in the text.
Definition: rep.h:246
C++ API: Interface for writing bytes, and implementation classes.
U_COMMON_API UnicodeString operator+(const UnicodeString &s1, const UnicodeString &s2)
Create a new UnicodeString with the concatenation of two others.
virtual int32_t getLength() const =0
Virtual version of length().
The BreakIterator class implements methods for finding the location of boundaries in text...
Definition: brkiter.h:106
UBool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
Definition: stringpiece.h:251
UnicodeString(const wchar_t *text, int32_t textLength)
wchar_t * constructor.
Definition: unistr.h:3060
UChar32 char32At(int32_t offset) const
Returns the 32-bit code point at the given 16-bit offset into the text.
Definition: rep.h:256
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
Definition: umachine.h:425
#define NULL
Define NULL if necessary, to nullptr for C++ and to ((void *)0) for C.
Definition: utypes.h:188
virtual UClassID getDynamicClassID() const
ICU4C "poor man&#39;s RTTI", returns a UClassID for the actual ICU class.
C++ API: Central ICU header for including the C++ standard <string> header and for related definition...
const UChar * toUCharPtr(const char16_t *p)
Converts from const char16_t * to const UChar *.
Definition: char16ptr.h:260
virtual char16_t getCharAt(int32_t offset) const =0
Virtual version of charAt().
#define TRUE
The TRUE value of a UBool.
Definition: umachine.h:265
#define U_NOEXCEPT
"noexcept" if supported, otherwise empty.
Definition: platform.h:529
uint16_t UChar
The base type for UTF-16 code units and pointers.
Definition: umachine.h:378
UnicodeString(uint16_t *buffer, int32_t buffLength, int32_t buffCapacity)
Writable-aliasing uint16_t * constructor.
Definition: unistr.h:3128
struct UConverter UConverter
Definition: ucnv_err.h:96
#define INT32_MAX
The largest value a 32 bit signed integer can hold.
Definition: umachine.h:207
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:415
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(void) const
Return the length of the UnicodeString object.
Definition: unistr.h:3890
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
virtual void handleReplaceBetween(int32_t start, int32_t limit, const UnicodeString &text)=0
Replaces a substring of this object with the given text.
Basic definitions for ICU, for both C and C++ APIs.
Implementation of ByteSink that writes to a "string".
Definition: bytestream.h:235
int32_t u_strlen(const UChar *s)
Determine the length of an array of UChar.
virtual Replaceable * clone() const
Clone this object, an instance of a subclass of Replaceable.
#define FALSE
The FALSE value of a UBool.
Definition: umachine.h:269
#define U_COMMON_API
Set to export library symbols from inside the common library, and to import them from outside...
Definition: utypes.h:300
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:294
virtual UBool hasMetaData() const
Returns true if this object contains metadata.
#define UNISTR_FROM_STRING_EXPLICIT
This can be defined to be empty or "explicit".
Definition: unistr.h:169
A string-like object that points to a sized piece of memory.
Definition: stringpiece.h:60
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:4398
#define U_STABLE
This is used to declare a function as a stable public ICU C API.
Definition: umachine.h:111
int8_t UBool
The ICU boolean type.
Definition: umachine.h:261
C++ API: char16_t pointer wrappers with implicit conversion from bit-compatible raw pointer types...
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:195
C++ API: Replaceable String.