ICU 59.1  59.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 <cstddef>
32 #include "unicode/utypes.h"
33 #include "unicode/char16ptr.h"
34 #include "unicode/rep.h"
35 #include "unicode/std_string.h"
36 #include "unicode/stringpiece.h"
37 #include "unicode/bytestream.h"
38 
39 struct UConverter; // unicode/ucnv.h
40 
41 #ifndef U_COMPARE_CODE_POINT_ORDER
42 /* see also ustring.h and unorm.h */
48 #define U_COMPARE_CODE_POINT_ORDER 0x8000
49 #endif
50 
51 #ifndef USTRING_H
52 
55 U_STABLE int32_t U_EXPORT2
56 u_strlen(const UChar *s);
57 #endif
58 
60 
61 #if !UCONFIG_NO_BREAK_ITERATION
62 class BreakIterator; // unicode/brkiter.h
63 #endif
64 class Edits;
65 
67 
68 // Not #ifndef U_HIDE_INTERNAL_API because UnicodeString needs the UStringCaseMapper.
75 typedef int32_t U_CALLCONV
76 UStringCaseMapper(int32_t caseLocale, uint32_t options,
78  icu::BreakIterator *iter,
79 #endif
80  char16_t *dest, int32_t destCapacity,
81  const char16_t *src, int32_t srcLength,
82  icu::Edits *edits,
83  UErrorCode &errorCode);
84 
86 
87 class Locale; // unicode/locid.h
88 class StringCharacterIterator;
89 class UnicodeStringAppendable; // unicode/appendable.h
90 
91 /* The <iostream> include has been moved to unicode/ustream.h */
92 
103 #define US_INV icu::UnicodeString::kInvariant
104 
122 #if !U_CHAR16_IS_TYPEDEF
123 # define UNICODE_STRING(cs, _length) icu::UnicodeString(TRUE, u ## cs, _length)
124 #else
125 # define UNICODE_STRING(cs, _length) icu::UnicodeString(TRUE, (const char16_t*)u ## cs, _length)
126 #endif
127 
141 #define UNICODE_STRING_SIMPLE(cs) UNICODE_STRING(cs, -1)
142 
150 #ifndef UNISTR_FROM_CHAR_EXPLICIT
151 # if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION)
152  // Auto-"explicit" in ICU library code.
153 # define UNISTR_FROM_CHAR_EXPLICIT explicit
154 # else
155  // Empty by default for source code compatibility.
156 # define UNISTR_FROM_CHAR_EXPLICIT
157 # endif
158 #endif
159 
170 #ifndef UNISTR_FROM_STRING_EXPLICIT
171 # if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION)
172  // Auto-"explicit" in ICU library code.
173 # define UNISTR_FROM_STRING_EXPLICIT explicit
174 # else
175  // Empty by default for source code compatibility.
176 # define UNISTR_FROM_STRING_EXPLICIT
177 # endif
178 #endif
179 
213 #ifndef UNISTR_OBJECT_SIZE
214 # define UNISTR_OBJECT_SIZE 64
215 #endif
216 
297 {
298 public:
299 
308  enum EInvariant {
313  kInvariant
314  };
315 
316  //========================================
317  // Read-only operations
318  //========================================
319 
320  /* Comparison - bitwise only - for international comparison use collation */
321 
329  inline UBool operator== (const UnicodeString& text) const;
330 
338  inline UBool operator!= (const UnicodeString& text) const;
339 
347  inline UBool operator> (const UnicodeString& text) const;
348 
356  inline UBool operator< (const UnicodeString& text) const;
357 
365  inline UBool operator>= (const UnicodeString& text) const;
366 
374  inline UBool operator<= (const UnicodeString& text) const;
375 
387  inline int8_t compare(const UnicodeString& text) const;
388 
404  inline int8_t compare(int32_t start,
405  int32_t length,
406  const UnicodeString& text) const;
407 
425  inline int8_t compare(int32_t start,
426  int32_t length,
427  const UnicodeString& srcText,
428  int32_t srcStart,
429  int32_t srcLength) const;
430 
443  inline int8_t compare(ConstChar16Ptr srcChars,
444  int32_t srcLength) const;
445 
460  inline int8_t compare(int32_t start,
461  int32_t length,
462  const char16_t *srcChars) const;
463 
481  inline int8_t compare(int32_t start,
482  int32_t length,
483  const char16_t *srcChars,
484  int32_t srcStart,
485  int32_t srcLength) const;
486 
504  inline int8_t compareBetween(int32_t start,
505  int32_t limit,
506  const UnicodeString& srcText,
507  int32_t srcStart,
508  int32_t srcLimit) const;
509 
527  inline int8_t compareCodePointOrder(const UnicodeString& text) const;
528 
548  inline int8_t compareCodePointOrder(int32_t start,
549  int32_t length,
550  const UnicodeString& srcText) const;
551 
573  inline int8_t compareCodePointOrder(int32_t start,
574  int32_t length,
575  const UnicodeString& srcText,
576  int32_t srcStart,
577  int32_t srcLength) const;
578 
597  inline int8_t compareCodePointOrder(ConstChar16Ptr srcChars,
598  int32_t srcLength) const;
599 
619  inline int8_t compareCodePointOrder(int32_t start,
620  int32_t length,
621  const char16_t *srcChars) const;
622 
644  inline int8_t compareCodePointOrder(int32_t start,
645  int32_t length,
646  const char16_t *srcChars,
647  int32_t srcStart,
648  int32_t srcLength) const;
649 
671  inline int8_t compareCodePointOrderBetween(int32_t start,
672  int32_t limit,
673  const UnicodeString& srcText,
674  int32_t srcStart,
675  int32_t srcLimit) const;
676 
695  inline int8_t caseCompare(const UnicodeString& text, uint32_t options) const;
696 
717  inline int8_t caseCompare(int32_t start,
718  int32_t length,
719  const UnicodeString& srcText,
720  uint32_t options) const;
721 
744  inline int8_t caseCompare(int32_t start,
745  int32_t length,
746  const UnicodeString& srcText,
747  int32_t srcStart,
748  int32_t srcLength,
749  uint32_t options) const;
750 
770  inline int8_t caseCompare(ConstChar16Ptr srcChars,
771  int32_t srcLength,
772  uint32_t options) const;
773 
794  inline int8_t caseCompare(int32_t start,
795  int32_t length,
796  const char16_t *srcChars,
797  uint32_t options) const;
798 
821  inline int8_t caseCompare(int32_t start,
822  int32_t length,
823  const char16_t *srcChars,
824  int32_t srcStart,
825  int32_t srcLength,
826  uint32_t options) const;
827 
850  inline int8_t caseCompareBetween(int32_t start,
851  int32_t limit,
852  const UnicodeString& srcText,
853  int32_t srcStart,
854  int32_t srcLimit,
855  uint32_t options) const;
856 
864  inline UBool startsWith(const UnicodeString& text) const;
865 
876  inline UBool startsWith(const UnicodeString& srcText,
877  int32_t srcStart,
878  int32_t srcLength) const;
879 
888  inline UBool startsWith(ConstChar16Ptr srcChars,
889  int32_t srcLength) const;
890 
900  inline UBool startsWith(const char16_t *srcChars,
901  int32_t srcStart,
902  int32_t srcLength) const;
903 
911  inline UBool endsWith(const UnicodeString& text) const;
912 
923  inline UBool endsWith(const UnicodeString& srcText,
924  int32_t srcStart,
925  int32_t srcLength) const;
926 
935  inline UBool endsWith(ConstChar16Ptr srcChars,
936  int32_t srcLength) const;
937 
948  inline UBool endsWith(const char16_t *srcChars,
949  int32_t srcStart,
950  int32_t srcLength) const;
951 
952 
953  /* Searching - bitwise only */
954 
963  inline int32_t indexOf(const UnicodeString& text) const;
964 
974  inline int32_t indexOf(const UnicodeString& text,
975  int32_t start) const;
976 
988  inline int32_t indexOf(const UnicodeString& text,
989  int32_t start,
990  int32_t length) const;
991 
1008  inline int32_t indexOf(const UnicodeString& srcText,
1009  int32_t srcStart,
1010  int32_t srcLength,
1011  int32_t start,
1012  int32_t length) const;
1013 
1025  inline int32_t indexOf(const char16_t *srcChars,
1026  int32_t srcLength,
1027  int32_t start) const;
1028 
1041  inline int32_t indexOf(ConstChar16Ptr srcChars,
1042  int32_t srcLength,
1043  int32_t start,
1044  int32_t length) const;
1045 
1062  int32_t indexOf(const char16_t *srcChars,
1063  int32_t srcStart,
1064  int32_t srcLength,
1065  int32_t start,
1066  int32_t length) const;
1067 
1075  inline int32_t indexOf(char16_t c) const;
1076 
1085  inline int32_t indexOf(UChar32 c) const;
1086 
1095  inline int32_t indexOf(char16_t c,
1096  int32_t start) const;
1097 
1107  inline int32_t indexOf(UChar32 c,
1108  int32_t start) const;
1109 
1120  inline int32_t indexOf(char16_t c,
1121  int32_t start,
1122  int32_t length) const;
1123 
1135  inline int32_t indexOf(UChar32 c,
1136  int32_t start,
1137  int32_t length) const;
1138 
1147  inline int32_t lastIndexOf(const UnicodeString& text) const;
1148 
1158  inline int32_t lastIndexOf(const UnicodeString& text,
1159  int32_t start) const;
1160 
1172  inline int32_t lastIndexOf(const UnicodeString& text,
1173  int32_t start,
1174  int32_t length) const;
1175 
1192  inline int32_t lastIndexOf(const UnicodeString& srcText,
1193  int32_t srcStart,
1194  int32_t srcLength,
1195  int32_t start,
1196  int32_t length) const;
1197 
1208  inline int32_t lastIndexOf(const char16_t *srcChars,
1209  int32_t srcLength,
1210  int32_t start) const;
1211 
1224  inline int32_t lastIndexOf(ConstChar16Ptr srcChars,
1225  int32_t srcLength,
1226  int32_t start,
1227  int32_t length) const;
1228 
1245  int32_t lastIndexOf(const char16_t *srcChars,
1246  int32_t srcStart,
1247  int32_t srcLength,
1248  int32_t start,
1249  int32_t length) const;
1250 
1258  inline int32_t lastIndexOf(char16_t c) const;
1259 
1268  inline int32_t lastIndexOf(UChar32 c) const;
1269 
1278  inline int32_t lastIndexOf(char16_t c,
1279  int32_t start) const;
1280 
1290  inline int32_t lastIndexOf(UChar32 c,
1291  int32_t start) const;
1292 
1303  inline int32_t lastIndexOf(char16_t c,
1304  int32_t start,
1305  int32_t length) const;
1306 
1318  inline int32_t lastIndexOf(UChar32 c,
1319  int32_t start,
1320  int32_t length) const;
1321 
1322 
1323  /* Character access */
1324 
1333  inline char16_t charAt(int32_t offset) const;
1334 
1342  inline char16_t operator[] (int32_t offset) const;
1343 
1355  UChar32 char32At(int32_t offset) const;
1356 
1372  int32_t getChar32Start(int32_t offset) const;
1373 
1390  int32_t getChar32Limit(int32_t offset) const;
1391 
1442  int32_t moveIndex32(int32_t index, int32_t delta) const;
1443 
1444  /* Substring extraction */
1445 
1461  inline void extract(int32_t start,
1462  int32_t length,
1463  Char16Ptr dst,
1464  int32_t dstStart = 0) const;
1465 
1487  int32_t
1488  extract(Char16Ptr dest, int32_t destCapacity,
1489  UErrorCode &errorCode) const;
1490 
1501  inline void extract(int32_t start,
1502  int32_t length,
1503  UnicodeString& target) const;
1504 
1516  inline void extractBetween(int32_t start,
1517  int32_t limit,
1518  char16_t *dst,
1519  int32_t dstStart = 0) const;
1520 
1530  virtual void extractBetween(int32_t start,
1531  int32_t limit,
1532  UnicodeString& target) const;
1533 
1555  int32_t extract(int32_t start,
1556  int32_t startLength,
1557  char *target,
1558  int32_t targetCapacity,
1559  enum EInvariant inv) const;
1560 
1561 #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
1562 
1582  int32_t extract(int32_t start,
1583  int32_t startLength,
1584  char *target,
1585  uint32_t targetLength) const;
1586 
1587 #endif
1588 
1589 #if !UCONFIG_NO_CONVERSION
1590 
1616  inline int32_t extract(int32_t start,
1617  int32_t startLength,
1618  char *target,
1619  const char *codepage = 0) const;
1620 
1650  int32_t extract(int32_t start,
1651  int32_t startLength,
1652  char *target,
1653  uint32_t targetLength,
1654  const char *codepage) const;
1655 
1673  int32_t extract(char *dest, int32_t destCapacity,
1674  UConverter *cnv,
1675  UErrorCode &errorCode) const;
1676 
1677 #endif
1678 
1692  UnicodeString tempSubString(int32_t start=0, int32_t length=INT32_MAX) const;
1693 
1704  inline UnicodeString tempSubStringBetween(int32_t start, int32_t limit=INT32_MAX) const;
1705 
1717  void toUTF8(ByteSink &sink) const;
1718 
1731  template<typename StringClass>
1732  StringClass &toUTF8String(StringClass &result) const {
1733  StringByteSink<StringClass> sbs(&result);
1734  toUTF8(sbs);
1735  return result;
1736  }
1737 
1753  int32_t toUTF32(UChar32 *utf32, int32_t capacity, UErrorCode &errorCode) const;
1754 
1755  /* Length operations */
1756 
1765  inline int32_t length(void) const;
1766 
1780  int32_t
1781  countChar32(int32_t start=0, int32_t length=INT32_MAX) const;
1782 
1806  UBool
1807  hasMoreChar32Than(int32_t start, int32_t length, int32_t number) const;
1808 
1814  inline UBool isEmpty(void) const;
1815 
1825  inline int32_t getCapacity(void) const;
1826 
1827  /* Other operations */
1828 
1834  inline int32_t hashCode(void) const;
1835 
1848  inline UBool isBogus(void) const;
1849 
1850 
1851  //========================================
1852  // Write operations
1853  //========================================
1854 
1855  /* Assignment operations */
1856 
1875  UnicodeString &operator=(const UnicodeString &srcText);
1876 
1902  UnicodeString &fastCopyFrom(const UnicodeString &src);
1903 
1904 #if U_HAVE_RVALUE_REFERENCES
1905 
1914  return moveFrom(src);
1915  }
1916 #endif
1917  // do not use #ifndef U_HIDE_DRAFT_API for moveFrom, needed by non-draft API
1928  UnicodeString &moveFrom(UnicodeString &src) U_NOEXCEPT;
1929 
1935  void swap(UnicodeString &other) U_NOEXCEPT;
1936 
1943  friend U_COMMON_API inline void U_EXPORT2
1944  swap(UnicodeString &s1, UnicodeString &s2) U_NOEXCEPT {
1945  s1.swap(s2);
1946  }
1947 
1955  inline UnicodeString& operator= (char16_t ch);
1956 
1964  inline UnicodeString& operator= (UChar32 ch);
1965 
1977  inline UnicodeString& setTo(const UnicodeString& srcText,
1978  int32_t srcStart);
1979 
1993  inline UnicodeString& setTo(const UnicodeString& srcText,
1994  int32_t srcStart,
1995  int32_t srcLength);
1996 
2005  inline UnicodeString& setTo(const UnicodeString& srcText);
2006 
2015  inline UnicodeString& setTo(const char16_t *srcChars,
2016  int32_t srcLength);
2017 
2026  UnicodeString& setTo(char16_t srcChar);
2027 
2036  UnicodeString& setTo(UChar32 srcChar);
2037 
2061  UnicodeString &setTo(UBool isTerminated,
2062  ConstChar16Ptr text,
2063  int32_t textLength);
2064 
2084  UnicodeString &setTo(char16_t *buffer,
2085  int32_t buffLength,
2086  int32_t buffCapacity);
2087 
2128  void setToBogus();
2129 
2137  UnicodeString& setCharAt(int32_t offset,
2138  char16_t ch);
2139 
2140 
2141  /* Append operations */
2142 
2150  inline UnicodeString& operator+= (char16_t ch);
2151 
2159  inline UnicodeString& operator+= (UChar32 ch);
2160 
2168  inline UnicodeString& operator+= (const UnicodeString& srcText);
2169 
2184  inline UnicodeString& append(const UnicodeString& srcText,
2185  int32_t srcStart,
2186  int32_t srcLength);
2187 
2195  inline UnicodeString& append(const UnicodeString& srcText);
2196 
2210  inline UnicodeString& append(const char16_t *srcChars,
2211  int32_t srcStart,
2212  int32_t srcLength);
2213 
2223  inline UnicodeString& append(ConstChar16Ptr srcChars,
2224  int32_t srcLength);
2225 
2232  inline UnicodeString& append(char16_t srcChar);
2233 
2240  UnicodeString& append(UChar32 srcChar);
2241 
2242 
2243  /* Insert operations */
2244 
2258  inline UnicodeString& insert(int32_t start,
2259  const UnicodeString& srcText,
2260  int32_t srcStart,
2261  int32_t srcLength);
2262 
2271  inline UnicodeString& insert(int32_t start,
2272  const UnicodeString& srcText);
2273 
2287  inline UnicodeString& insert(int32_t start,
2288  const char16_t *srcChars,
2289  int32_t srcStart,
2290  int32_t srcLength);
2291 
2301  inline UnicodeString& insert(int32_t start,
2302  ConstChar16Ptr srcChars,
2303  int32_t srcLength);
2304 
2313  inline UnicodeString& insert(int32_t start,
2314  char16_t srcChar);
2315 
2324  inline UnicodeString& insert(int32_t start,
2325  UChar32 srcChar);
2326 
2327 
2328  /* Replace operations */
2329 
2347  UnicodeString& replace(int32_t start,
2348  int32_t length,
2349  const UnicodeString& srcText,
2350  int32_t srcStart,
2351  int32_t srcLength);
2352 
2365  UnicodeString& replace(int32_t start,
2366  int32_t length,
2367  const UnicodeString& srcText);
2368 
2386  UnicodeString& replace(int32_t start,
2387  int32_t length,
2388  const char16_t *srcChars,
2389  int32_t srcStart,
2390  int32_t srcLength);
2391 
2404  inline UnicodeString& replace(int32_t start,
2405  int32_t length,
2406  ConstChar16Ptr srcChars,
2407  int32_t srcLength);
2408 
2420  inline UnicodeString& replace(int32_t start,
2421  int32_t length,
2422  char16_t srcChar);
2423 
2435  UnicodeString& replace(int32_t start, int32_t length, UChar32 srcChar);
2436 
2446  inline UnicodeString& replaceBetween(int32_t start,
2447  int32_t limit,
2448  const UnicodeString& srcText);
2449 
2464  inline UnicodeString& replaceBetween(int32_t start,
2465  int32_t limit,
2466  const UnicodeString& srcText,
2467  int32_t srcStart,
2468  int32_t srcLimit);
2469 
2480  virtual void handleReplaceBetween(int32_t start,
2481  int32_t limit,
2482  const UnicodeString& text);
2483 
2489  virtual UBool hasMetaData() const;
2490 
2506  virtual void copy(int32_t start, int32_t limit, int32_t dest);
2507 
2508  /* Search and replace operations */
2509 
2518  inline UnicodeString& findAndReplace(const UnicodeString& oldText,
2519  const UnicodeString& newText);
2520 
2532  inline UnicodeString& findAndReplace(int32_t start,
2533  int32_t length,
2534  const UnicodeString& oldText,
2535  const UnicodeString& newText);
2536 
2554  UnicodeString& findAndReplace(int32_t start,
2555  int32_t length,
2556  const UnicodeString& oldText,
2557  int32_t oldStart,
2558  int32_t oldLength,
2559  const UnicodeString& newText,
2560  int32_t newStart,
2561  int32_t newLength);
2562 
2563 
2564  /* Remove operations */
2565 
2571  inline UnicodeString& remove(void);
2572 
2581  inline UnicodeString& remove(int32_t start,
2582  int32_t length = (int32_t)INT32_MAX);
2583 
2592  inline UnicodeString& removeBetween(int32_t start,
2593  int32_t limit = (int32_t)INT32_MAX);
2594 
2604  inline UnicodeString &retainBetween(int32_t start, int32_t limit = INT32_MAX);
2605 
2606  /* Length operations */
2607 
2619  UBool padLeading(int32_t targetLength,
2620  char16_t padChar = 0x0020);
2621 
2633  UBool padTrailing(int32_t targetLength,
2634  char16_t padChar = 0x0020);
2635 
2642  inline UBool truncate(int32_t targetLength);
2643 
2649  UnicodeString& trim(void);
2650 
2651 
2652  /* Miscellaneous operations */
2653 
2659  inline UnicodeString& reverse(void);
2660 
2669  inline UnicodeString& reverse(int32_t start,
2670  int32_t length);
2671 
2678  UnicodeString& toUpper(void);
2679 
2687  UnicodeString& toUpper(const Locale& locale);
2688 
2695  UnicodeString& toLower(void);
2696 
2704  UnicodeString& toLower(const Locale& locale);
2705 
2706 #if !UCONFIG_NO_BREAK_ITERATION
2707 
2734  UnicodeString &toTitle(BreakIterator *titleIter);
2735 
2763  UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale);
2764 
2796  UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale, uint32_t options);
2797 
2798 #endif
2799 
2813  UnicodeString &foldCase(uint32_t options=0 /*U_FOLD_CASE_DEFAULT*/);
2814 
2815  //========================================
2816  // Access to the internal buffer
2817  //========================================
2818 
2862  char16_t *getBuffer(int32_t minCapacity);
2863 
2884  void releaseBuffer(int32_t newLength=-1);
2885 
2916  inline const char16_t *getBuffer() const;
2917 
2951  const char16_t *getTerminatedBuffer();
2952 
2953  //========================================
2954  // Constructors
2955  //========================================
2956 
2960  inline UnicodeString();
2961 
2973  UnicodeString(int32_t capacity, UChar32 c, int32_t count);
2974 
2984  UNISTR_FROM_CHAR_EXPLICIT UnicodeString(char16_t ch);
2985 
2995  UNISTR_FROM_CHAR_EXPLICIT UnicodeString(UChar32 ch);
2996 
3007  UNISTR_FROM_STRING_EXPLICIT UnicodeString(const char16_t *text);
3008 
3009  /*
3010  * Do not use #ifndef U_HIDE_DRAFT_API for the following constructor,
3011  * it should always be available regardless of U_HIDE_DRAFT_API status
3012  */
3013 #if !U_CHAR16_IS_TYPEDEF
3014 
3025  UnicodeString(ConstChar16Ptr(text)) {}
3026 #endif
3027 
3028  /*
3029  * Do not use #ifndef U_HIDE_DRAFT_API for the following constructor,
3030  * it should always be available regardless of U_HIDE_DRAFT_API status
3031  */
3032 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
3033 
3045  UnicodeString(ConstChar16Ptr(text)) {}
3046 #endif
3047 
3048  /*
3049  * Do not use #ifndef U_HIDE_DRAFT_API for the following constructor,
3050  * it should always be available regardless of U_HIDE_DRAFT_API status
3051  */
3062  UNISTR_FROM_STRING_EXPLICIT inline UnicodeString(const std::nullptr_t text);
3063 
3071  UnicodeString(const char16_t *text,
3072  int32_t textLength);
3073 
3074  /*
3075  * Do not use #ifndef U_HIDE_DRAFT_API for the following constructor,
3076  * it should always be available regardless of U_HIDE_DRAFT_API status
3077  */
3078 #if !U_CHAR16_IS_TYPEDEF
3079 
3086  UnicodeString(const uint16_t *text, int32_t length) :
3087  UnicodeString(ConstChar16Ptr(text), length) {}
3088 #endif
3089 
3090  /*
3091  * Do not use #ifndef U_HIDE_DRAFT_API for the following constructor,
3092  * it should always be available regardless of U_HIDE_DRAFT_API status
3093  */
3094 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
3095 
3103  UnicodeString(const wchar_t *text, int32_t length) :
3104  UnicodeString(ConstChar16Ptr(text), length) {}
3105 #endif
3106 
3107  /*
3108  * Do not use #ifndef U_HIDE_DRAFT_API for the following constructor,
3109  * it should always be available regardless of U_HIDE_DRAFT_API status
3110  */
3118  inline UnicodeString(const std::nullptr_t text, int32_t length);
3119 
3142  UnicodeString(UBool isTerminated,
3143  ConstChar16Ptr text,
3144  int32_t textLength);
3145 
3164  UnicodeString(char16_t *buffer, int32_t buffLength, int32_t buffCapacity);
3165 
3166  /*
3167  * Do not use #ifndef U_HIDE_DRAFT_API for the following constructor,
3168  * it should always be available regardless of U_HIDE_DRAFT_API status
3169  */
3170 #if !U_CHAR16_IS_TYPEDEF
3171 
3179  UnicodeString(uint16_t *buffer, int32_t buffLength, int32_t buffCapacity) :
3180  UnicodeString(Char16Ptr(buffer), buffLength, buffCapacity) {}
3181 #endif
3182 
3183  /*
3184  * Do not use #ifndef U_HIDE_DRAFT_API for the following constructor,
3185  * it should always be available regardless of U_HIDE_DRAFT_API status
3186  */
3187 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
3188 
3197  UnicodeString(wchar_t *buffer, int32_t buffLength, int32_t buffCapacity) :
3198  UnicodeString(Char16Ptr(buffer), buffLength, buffCapacity) {}
3199 #endif
3200 
3201  /*
3202  * Do not use #ifndef U_HIDE_DRAFT_API for the following constructor,
3203  * it should always be available regardless of U_HIDE_DRAFT_API status
3204  */
3213  inline UnicodeString(std::nullptr_t buffer, int32_t buffLength, int32_t buffCapacity);
3214 
3215 #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
3216 
3236  UNISTR_FROM_STRING_EXPLICIT UnicodeString(const char *codepageData);
3237 
3246  UnicodeString(const char *codepageData, int32_t dataLength);
3247 
3248 #endif
3249 
3250 #if !UCONFIG_NO_CONVERSION
3251 
3269  UnicodeString(const char *codepageData, const char *codepage);
3270 
3288  UnicodeString(const char *codepageData, int32_t dataLength, const char *codepage);
3289 
3311  UnicodeString(
3312  const char *src, int32_t srcLength,
3313  UConverter *cnv,
3314  UErrorCode &errorCode);
3315 
3316 #endif
3317 
3342  UnicodeString(const char *src, int32_t length, enum EInvariant inv);
3343 
3344 
3361  UnicodeString(const UnicodeString& that);
3362 
3363 #if U_HAVE_RVALUE_REFERENCES
3364 
3370  UnicodeString(UnicodeString &&src) U_NOEXCEPT;
3371 #endif
3372 
3379  UnicodeString(const UnicodeString& src, int32_t srcStart);
3380 
3388  UnicodeString(const UnicodeString& src, int32_t srcStart, int32_t srcLength);
3389 
3406  virtual Replaceable *clone() const;
3407 
3411  virtual ~UnicodeString();
3412 
3426  static UnicodeString fromUTF8(StringPiece utf8);
3427 
3439  static UnicodeString fromUTF32(const UChar32 *utf32, int32_t length);
3440 
3441  /* Miscellaneous operations */
3442 
3477  UnicodeString unescape() const;
3478 
3498  UChar32 unescapeAt(int32_t &offset) const;
3499 
3505  static UClassID U_EXPORT2 getStaticClassID();
3506 
3512  virtual UClassID getDynamicClassID() const;
3513 
3514  //========================================
3515  // Implementation methods
3516  //========================================
3517 
3518 protected:
3523  virtual int32_t getLength() const;
3524 
3530  virtual char16_t getCharAt(int32_t offset) const;
3531 
3537  virtual UChar32 getChar32At(int32_t offset) const;
3538 
3539 private:
3540  // For char* constructors. Could be made public.
3541  UnicodeString &setToUTF8(StringPiece utf8);
3542  // For extract(char*).
3543  // We could make a toUTF8(target, capacity, errorCode) public but not
3544  // this version: New API will be cleaner if we make callers create substrings
3545  // rather than having start+length on every method,
3546  // and it should take a UErrorCode&.
3547  int32_t
3548  toUTF8(int32_t start, int32_t len,
3549  char *target, int32_t capacity) const;
3550 
3555  UBool doEquals(const UnicodeString &text, int32_t len) const;
3556 
3557  inline int8_t
3558  doCompare(int32_t start,
3559  int32_t length,
3560  const UnicodeString& srcText,
3561  int32_t srcStart,
3562  int32_t srcLength) const;
3563 
3564  int8_t doCompare(int32_t start,
3565  int32_t length,
3566  const char16_t *srcChars,
3567  int32_t srcStart,
3568  int32_t srcLength) const;
3569 
3570  inline int8_t
3571  doCompareCodePointOrder(int32_t start,
3572  int32_t length,
3573  const UnicodeString& srcText,
3574  int32_t srcStart,
3575  int32_t srcLength) const;
3576 
3577  int8_t doCompareCodePointOrder(int32_t start,
3578  int32_t length,
3579  const char16_t *srcChars,
3580  int32_t srcStart,
3581  int32_t srcLength) const;
3582 
3583  inline int8_t
3584  doCaseCompare(int32_t start,
3585  int32_t length,
3586  const UnicodeString &srcText,
3587  int32_t srcStart,
3588  int32_t srcLength,
3589  uint32_t options) const;
3590 
3591  int8_t
3592  doCaseCompare(int32_t start,
3593  int32_t length,
3594  const char16_t *srcChars,
3595  int32_t srcStart,
3596  int32_t srcLength,
3597  uint32_t options) const;
3598 
3599  int32_t doIndexOf(char16_t c,
3600  int32_t start,
3601  int32_t length) const;
3602 
3603  int32_t doIndexOf(UChar32 c,
3604  int32_t start,
3605  int32_t length) const;
3606 
3607  int32_t doLastIndexOf(char16_t c,
3608  int32_t start,
3609  int32_t length) const;
3610 
3611  int32_t doLastIndexOf(UChar32 c,
3612  int32_t start,
3613  int32_t length) const;
3614 
3615  void doExtract(int32_t start,
3616  int32_t length,
3617  char16_t *dst,
3618  int32_t dstStart) const;
3619 
3620  inline void doExtract(int32_t start,
3621  int32_t length,
3622  UnicodeString& target) const;
3623 
3624  inline char16_t doCharAt(int32_t offset) const;
3625 
3626  UnicodeString& doReplace(int32_t start,
3627  int32_t length,
3628  const UnicodeString& srcText,
3629  int32_t srcStart,
3630  int32_t srcLength);
3631 
3632  UnicodeString& doReplace(int32_t start,
3633  int32_t length,
3634  const char16_t *srcChars,
3635  int32_t srcStart,
3636  int32_t srcLength);
3637 
3638  UnicodeString& doAppend(const UnicodeString& src, int32_t srcStart, int32_t srcLength);
3639  UnicodeString& doAppend(const char16_t *srcChars, int32_t srcStart, int32_t srcLength);
3640 
3641  UnicodeString& doReverse(int32_t start,
3642  int32_t length);
3643 
3644  // calculate hash code
3645  int32_t doHashCode(void) const;
3646 
3647  // get pointer to start of array
3648  // these do not check for kOpenGetBuffer, unlike the public getBuffer() function
3649  inline char16_t* getArrayStart(void);
3650  inline const char16_t* getArrayStart(void) const;
3651 
3652  inline UBool hasShortLength() const;
3653  inline int32_t getShortLength() const;
3654 
3655  // A UnicodeString object (not necessarily its current buffer)
3656  // is writable unless it isBogus() or it has an "open" getBuffer(minCapacity).
3657  inline UBool isWritable() const;
3658 
3659  // Is the current buffer writable?
3660  inline UBool isBufferWritable() const;
3661 
3662  // None of the following does releaseArray().
3663  inline void setZeroLength();
3664  inline void setShortLength(int32_t len);
3665  inline void setLength(int32_t len);
3666  inline void setToEmpty();
3667  inline void setArray(char16_t *array, int32_t len, int32_t capacity); // sets length but not flags
3668 
3669  // allocate the array; result may be the stack buffer
3670  // sets refCount to 1 if appropriate
3671  // sets fArray, fCapacity, and flags
3672  // sets length to 0
3673  // returns boolean for success or failure
3674  UBool allocate(int32_t capacity);
3675 
3676  // release the array if owned
3677  void releaseArray(void);
3678 
3679  // turn a bogus string into an empty one
3680  void unBogus();
3681 
3682  // implements assigment operator, copy constructor, and fastCopyFrom()
3683  UnicodeString &copyFrom(const UnicodeString &src, UBool fastCopy=FALSE);
3684 
3685  // Copies just the fields without memory management.
3686  void copyFieldsFrom(UnicodeString &src, UBool setSrcToBogus) U_NOEXCEPT;
3687 
3688  // Pin start and limit to acceptable values.
3689  inline void pinIndex(int32_t& start) const;
3690  inline void pinIndices(int32_t& start,
3691  int32_t& length) const;
3692 
3693 #if !UCONFIG_NO_CONVERSION
3694 
3695  /* Internal extract() using UConverter. */
3696  int32_t doExtract(int32_t start, int32_t length,
3697  char *dest, int32_t destCapacity,
3698  UConverter *cnv,
3699  UErrorCode &errorCode) const;
3700 
3701  /*
3702  * Real constructor for converting from codepage data.
3703  * It assumes that it is called with !fRefCounted.
3704  *
3705  * If <code>codepage==0</code>, then the default converter
3706  * is used for the platform encoding.
3707  * If <code>codepage</code> is an empty string (<code>""</code>),
3708  * then a simple conversion is performed on the codepage-invariant
3709  * subset ("invariant characters") of the platform encoding. See utypes.h.
3710  */
3711  void doCodepageCreate(const char *codepageData,
3712  int32_t dataLength,
3713  const char *codepage);
3714 
3715  /*
3716  * Worker function for creating a UnicodeString from
3717  * a codepage string using a UConverter.
3718  */
3719  void
3720  doCodepageCreate(const char *codepageData,
3721  int32_t dataLength,
3722  UConverter *converter,
3723  UErrorCode &status);
3724 
3725 #endif
3726 
3727  /*
3728  * This function is called when write access to the array
3729  * is necessary.
3730  *
3731  * We need to make a copy of the array if
3732  * the buffer is read-only, or
3733  * the buffer is refCounted (shared), and refCount>1, or
3734  * the buffer is too small.
3735  *
3736  * Return FALSE if memory could not be allocated.
3737  */
3738  UBool cloneArrayIfNeeded(int32_t newCapacity = -1,
3739  int32_t growCapacity = -1,
3740  UBool doCopyArray = TRUE,
3741  int32_t **pBufferToDelete = 0,
3742  UBool forceClone = FALSE);
3743 
3749  UnicodeString &
3750  caseMap(int32_t caseLocale, uint32_t options,
3752  BreakIterator *iter,
3753 #endif
3754  UStringCaseMapper *stringCaseMapper);
3755 
3756  // ref counting
3757  void addRef(void);
3758  int32_t removeRef(void);
3759  int32_t refCount(void) const;
3760 
3761  // constants
3762  enum {
3768  US_STACKBUF_SIZE=(int32_t)(UNISTR_OBJECT_SIZE-sizeof(void *)-2)/U_SIZEOF_UCHAR,
3769  kInvalidUChar=0xffff, // U+FFFF returned by charAt(invalid index)
3770  kInvalidHashCode=0, // invalid hash code
3771  kEmptyHashCode=1, // hash code for empty string
3772 
3773  // bit flag values for fLengthAndFlags
3774  kIsBogus=1, // this string is bogus, i.e., not valid or NULL
3775  kUsingStackBuffer=2,// using fUnion.fStackFields instead of fUnion.fFields
3776  kRefCounted=4, // there is a refCount field before the characters in fArray
3777  kBufferIsReadonly=8,// do not write to this buffer
3778  kOpenGetBuffer=16, // getBuffer(minCapacity) was called (is "open"),
3779  // and releaseBuffer(newLength) must be called
3780  kAllStorageFlags=0x1f,
3781 
3782  kLengthShift=5, // remaining 11 bits for non-negative short length, or negative if long
3783  kLength1=1<<kLengthShift,
3784  kMaxShortLength=0x3ff, // max non-negative short length (leaves top bit 0)
3785  kLengthIsLarge=0xffe0, // short length < 0, real length is in fUnion.fFields.fLength
3786 
3787  // combined values for convenience
3788  kShortString=kUsingStackBuffer,
3789  kLongString=kRefCounted,
3790  kReadonlyAlias=kBufferIsReadonly,
3791  kWritableAlias=0
3792  };
3793 
3794  friend class UnicodeStringAppendable;
3795 
3796  union StackBufferOrFields; // forward declaration necessary before friend declaration
3797  friend union StackBufferOrFields; // make US_STACKBUF_SIZE visible inside fUnion
3798 
3799  /*
3800  * The following are all the class fields that are stored
3801  * in each UnicodeString object.
3802  * Note that UnicodeString has virtual functions,
3803  * therefore there is an implicit vtable pointer
3804  * as the first real field.
3805  * The fields should be aligned such that no padding is necessary.
3806  * On 32-bit machines, the size should be 32 bytes,
3807  * on 64-bit machines (8-byte pointers), it should be 40 bytes.
3808  *
3809  * We use a hack to achieve this.
3810  *
3811  * With at least some compilers, each of the following is forced to
3812  * a multiple of sizeof(pointer) [the largest field base unit here is a data pointer],
3813  * rounded up with additional padding if the fields do not already fit that requirement:
3814  * - sizeof(class UnicodeString)
3815  * - offsetof(UnicodeString, fUnion)
3816  * - sizeof(fUnion)
3817  * - sizeof(fStackFields)
3818  *
3819  * We optimize for the longest possible internal buffer for short strings.
3820  * fUnion.fStackFields begins with 2 bytes for storage flags
3821  * and the length of relatively short strings,
3822  * followed by the buffer for short string contents.
3823  * There is no padding inside fStackFields.
3824  *
3825  * Heap-allocated and aliased strings use fUnion.fFields.
3826  * Both fStackFields and fFields must begin with the same fields for flags and short length,
3827  * that is, those must have the same memory offsets inside the object,
3828  * because the flags must be inspected in order to decide which half of fUnion is being used.
3829  * We assume that the compiler does not reorder the fields.
3830  *
3831  * (Padding at the end of fFields is ok:
3832  * As long as it is no larger than fStackFields, it is not wasted space.)
3833  *
3834  * For some of the history of the UnicodeString class fields layout, see
3835  * - ICU ticket #11551 "longer UnicodeString contents in stack buffer"
3836  * - ICU ticket #11336 "UnicodeString: recombine stack buffer arrays"
3837  * - ICU ticket #8322 "why is sizeof(UnicodeString)==48?"
3838  */
3839  // (implicit) *vtable;
3840  union StackBufferOrFields {
3841  // fStackFields is used iff (fLengthAndFlags&kUsingStackBuffer) else fFields is used.
3842  // Each struct of the union must begin with fLengthAndFlags.
3843  struct {
3844  int16_t fLengthAndFlags; // bit fields: see constants above
3845  char16_t fBuffer[US_STACKBUF_SIZE]; // buffer for short strings
3846  } fStackFields;
3847  struct {
3848  int16_t fLengthAndFlags; // bit fields: see constants above
3849  int32_t fLength; // number of characters in fArray if >127; else undefined
3850  int32_t fCapacity; // capacity of fArray (in char16_ts)
3851  // array pointer last to minimize padding for machines with P128 data model
3852  // or pointer sizes that are not a power of 2
3853  char16_t *fArray; // the Unicode data
3854  } fFields;
3855  } fUnion;
3856 };
3857 
3866 U_COMMON_API UnicodeString U_EXPORT2
3867 operator+ (const UnicodeString &s1, const UnicodeString &s2);
3868 
3869 //========================================
3870 // Inline members
3871 //========================================
3872 
3873 //========================================
3874 // Privates
3875 //========================================
3876 
3877 inline void
3878 UnicodeString::pinIndex(int32_t& start) const
3879 {
3880  // pin index
3881  if(start < 0) {
3882  start = 0;
3883  } else if(start > length()) {
3884  start = length();
3885  }
3886 }
3887 
3888 inline void
3889 UnicodeString::pinIndices(int32_t& start,
3890  int32_t& _length) const
3891 {
3892  // pin indices
3893  int32_t len = length();
3894  if(start < 0) {
3895  start = 0;
3896  } else if(start > len) {
3897  start = len;
3898  }
3899  if(_length < 0) {
3900  _length = 0;
3901  } else if(_length > (len - start)) {
3902  _length = (len - start);
3903  }
3904 }
3905 
3906 inline char16_t*
3907 UnicodeString::getArrayStart() {
3908  return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3909  fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
3910 }
3911 
3912 inline const char16_t*
3913 UnicodeString::getArrayStart() const {
3914  return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3915  fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
3916 }
3917 
3918 //========================================
3919 // Default constructor
3920 //========================================
3921 
3922 inline
3923 UnicodeString::UnicodeString() {
3924  fUnion.fStackFields.fLengthAndFlags=kShortString;
3925 }
3926 
3927 inline UnicodeString::UnicodeString(const std::nullptr_t /*text*/) {
3928  fUnion.fStackFields.fLengthAndFlags=kShortString;
3929 }
3930 
3931 inline UnicodeString::UnicodeString(const std::nullptr_t /*text*/, int32_t /*length*/) {
3932  fUnion.fStackFields.fLengthAndFlags=kShortString;
3933 }
3934 
3935 inline UnicodeString::UnicodeString(std::nullptr_t /*buffer*/, int32_t /*buffLength*/, int32_t /*buffCapacity*/) {
3936  fUnion.fStackFields.fLengthAndFlags=kShortString;
3937 }
3938 
3939 //========================================
3940 // Read-only implementation methods
3941 //========================================
3942 inline UBool
3943 UnicodeString::hasShortLength() const {
3944  return fUnion.fFields.fLengthAndFlags>=0;
3945 }
3946 
3947 inline int32_t
3948 UnicodeString::getShortLength() const {
3949  // fLengthAndFlags must be non-negative -> short length >= 0
3950  // and arithmetic or logical shift does not matter.
3951  return fUnion.fFields.fLengthAndFlags>>kLengthShift;
3952 }
3953 
3954 inline int32_t
3955 UnicodeString::length() const {
3956  return hasShortLength() ? getShortLength() : fUnion.fFields.fLength;
3957 }
3958 
3959 inline int32_t
3960 UnicodeString::getCapacity() const {
3961  return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3962  US_STACKBUF_SIZE : fUnion.fFields.fCapacity;
3963 }
3964 
3965 inline int32_t
3966 UnicodeString::hashCode() const
3967 { return doHashCode(); }
3968 
3969 inline UBool
3970 UnicodeString::isBogus() const
3971 { return (UBool)(fUnion.fFields.fLengthAndFlags & kIsBogus); }
3972 
3973 inline UBool
3974 UnicodeString::isWritable() const
3975 { return (UBool)!(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus)); }
3976 
3977 inline UBool
3978 UnicodeString::isBufferWritable() const
3979 {
3980  return (UBool)(
3981  !(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus|kBufferIsReadonly)) &&
3982  (!(fUnion.fFields.fLengthAndFlags&kRefCounted) || refCount()==1));
3983 }
3984 
3985 inline const char16_t *
3986 UnicodeString::getBuffer() const {
3987  if(fUnion.fFields.fLengthAndFlags&(kIsBogus|kOpenGetBuffer)) {
3988  return nullptr;
3989  } else if(fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) {
3990  return fUnion.fStackFields.fBuffer;
3991  } else {
3992  return fUnion.fFields.fArray;
3993  }
3994 }
3995 
3996 //========================================
3997 // Read-only alias methods
3998 //========================================
3999 inline int8_t
4000 UnicodeString::doCompare(int32_t start,
4001  int32_t thisLength,
4002  const UnicodeString& srcText,
4003  int32_t srcStart,
4004  int32_t srcLength) const
4005 {
4006  if(srcText.isBogus()) {
4007  return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
4008  } else {
4009  srcText.pinIndices(srcStart, srcLength);
4010  return doCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
4011  }
4012 }
4013 
4014 inline UBool
4016 {
4017  if(isBogus()) {
4018  return text.isBogus();
4019  } else {
4020  int32_t len = length(), textLength = text.length();
4021  return !text.isBogus() && len == textLength && doEquals(text, len);
4022  }
4023 }
4024 
4025 inline UBool
4027 { return (! operator==(text)); }
4028 
4029 inline UBool
4030 UnicodeString::operator> (const UnicodeString& text) const
4031 { return doCompare(0, length(), text, 0, text.length()) == 1; }
4032 
4033 inline UBool
4034 UnicodeString::operator< (const UnicodeString& text) const
4035 { return doCompare(0, length(), text, 0, text.length()) == -1; }
4036 
4037 inline UBool
4038 UnicodeString::operator>= (const UnicodeString& text) const
4039 { return doCompare(0, length(), text, 0, text.length()) != -1; }
4040 
4041 inline UBool
4042 UnicodeString::operator<= (const UnicodeString& text) const
4043 { return doCompare(0, length(), text, 0, text.length()) != 1; }
4044 
4045 inline int8_t
4046 UnicodeString::compare(const UnicodeString& text) const
4047 { return doCompare(0, length(), text, 0, text.length()); }
4048 
4049 inline int8_t
4050 UnicodeString::compare(int32_t start,
4051  int32_t _length,
4052  const UnicodeString& srcText) const
4053 { return doCompare(start, _length, srcText, 0, srcText.length()); }
4054 
4055 inline int8_t
4056 UnicodeString::compare(ConstChar16Ptr srcChars,
4057  int32_t srcLength) const
4058 { return doCompare(0, length(), srcChars, 0, srcLength); }
4059 
4060 inline int8_t
4061 UnicodeString::compare(int32_t start,
4062  int32_t _length,
4063  const UnicodeString& srcText,
4064  int32_t srcStart,
4065  int32_t srcLength) const
4066 { return doCompare(start, _length, srcText, srcStart, srcLength); }
4067 
4068 inline int8_t
4069 UnicodeString::compare(int32_t start,
4070  int32_t _length,
4071  const char16_t *srcChars) const
4072 { return doCompare(start, _length, srcChars, 0, _length); }
4073 
4074 inline int8_t
4075 UnicodeString::compare(int32_t start,
4076  int32_t _length,
4077  const char16_t *srcChars,
4078  int32_t srcStart,
4079  int32_t srcLength) const
4080 { return doCompare(start, _length, srcChars, srcStart, srcLength); }
4081 
4082 inline int8_t
4083 UnicodeString::compareBetween(int32_t start,
4084  int32_t limit,
4085  const UnicodeString& srcText,
4086  int32_t srcStart,
4087  int32_t srcLimit) const
4088 { return doCompare(start, limit - start,
4089  srcText, srcStart, srcLimit - srcStart); }
4090 
4091 inline int8_t
4092 UnicodeString::doCompareCodePointOrder(int32_t start,
4093  int32_t thisLength,
4094  const UnicodeString& srcText,
4095  int32_t srcStart,
4096  int32_t srcLength) const
4097 {
4098  if(srcText.isBogus()) {
4099  return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
4100  } else {
4101  srcText.pinIndices(srcStart, srcLength);
4102  return doCompareCodePointOrder(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
4103  }
4104 }
4105 
4106 inline int8_t
4107 UnicodeString::compareCodePointOrder(const UnicodeString& text) const
4108 { return doCompareCodePointOrder(0, length(), text, 0, text.length()); }
4109 
4110 inline int8_t
4111 UnicodeString::compareCodePointOrder(int32_t start,
4112  int32_t _length,
4113  const UnicodeString& srcText) const
4114 { return doCompareCodePointOrder(start, _length, srcText, 0, srcText.length()); }
4115 
4116 inline int8_t
4117 UnicodeString::compareCodePointOrder(ConstChar16Ptr srcChars,
4118  int32_t srcLength) const
4119 { return doCompareCodePointOrder(0, length(), srcChars, 0, srcLength); }
4120 
4121 inline int8_t
4122 UnicodeString::compareCodePointOrder(int32_t start,
4123  int32_t _length,
4124  const UnicodeString& srcText,
4125  int32_t srcStart,
4126  int32_t srcLength) const
4127 { return doCompareCodePointOrder(start, _length, srcText, srcStart, srcLength); }
4128 
4129 inline int8_t
4130 UnicodeString::compareCodePointOrder(int32_t start,
4131  int32_t _length,
4132  const char16_t *srcChars) const
4133 { return doCompareCodePointOrder(start, _length, srcChars, 0, _length); }
4134 
4135 inline int8_t
4136 UnicodeString::compareCodePointOrder(int32_t start,
4137  int32_t _length,
4138  const char16_t *srcChars,
4139  int32_t srcStart,
4140  int32_t srcLength) const
4141 { return doCompareCodePointOrder(start, _length, srcChars, srcStart, srcLength); }
4142 
4143 inline int8_t
4144 UnicodeString::compareCodePointOrderBetween(int32_t start,
4145  int32_t limit,
4146  const UnicodeString& srcText,
4147  int32_t srcStart,
4148  int32_t srcLimit) const
4149 { return doCompareCodePointOrder(start, limit - start,
4150  srcText, srcStart, srcLimit - srcStart); }
4151 
4152 inline int8_t
4153 UnicodeString::doCaseCompare(int32_t start,
4154  int32_t thisLength,
4155  const UnicodeString &srcText,
4156  int32_t srcStart,
4157  int32_t srcLength,
4158  uint32_t options) const
4159 {
4160  if(srcText.isBogus()) {
4161  return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
4162  } else {
4163  srcText.pinIndices(srcStart, srcLength);
4164  return doCaseCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength, options);
4165  }
4166 }
4167 
4168 inline int8_t
4169 UnicodeString::caseCompare(const UnicodeString &text, uint32_t options) const {
4170  return doCaseCompare(0, length(), text, 0, text.length(), options);
4171 }
4172 
4173 inline int8_t
4174 UnicodeString::caseCompare(int32_t start,
4175  int32_t _length,
4176  const UnicodeString &srcText,
4177  uint32_t options) const {
4178  return doCaseCompare(start, _length, srcText, 0, srcText.length(), options);
4179 }
4180 
4181 inline int8_t
4182 UnicodeString::caseCompare(ConstChar16Ptr srcChars,
4183  int32_t srcLength,
4184  uint32_t options) const {
4185  return doCaseCompare(0, length(), srcChars, 0, srcLength, options);
4186 }
4187 
4188 inline int8_t
4189 UnicodeString::caseCompare(int32_t start,
4190  int32_t _length,
4191  const UnicodeString &srcText,
4192  int32_t srcStart,
4193  int32_t srcLength,
4194  uint32_t options) const {
4195  return doCaseCompare(start, _length, srcText, srcStart, srcLength, options);
4196 }
4197 
4198 inline int8_t
4199 UnicodeString::caseCompare(int32_t start,
4200  int32_t _length,
4201  const char16_t *srcChars,
4202  uint32_t options) const {
4203  return doCaseCompare(start, _length, srcChars, 0, _length, options);
4204 }
4205 
4206 inline int8_t
4207 UnicodeString::caseCompare(int32_t start,
4208  int32_t _length,
4209  const char16_t *srcChars,
4210  int32_t srcStart,
4211  int32_t srcLength,
4212  uint32_t options) const {
4213  return doCaseCompare(start, _length, srcChars, srcStart, srcLength, options);
4214 }
4215 
4216 inline int8_t
4217 UnicodeString::caseCompareBetween(int32_t start,
4218  int32_t limit,
4219  const UnicodeString &srcText,
4220  int32_t srcStart,
4221  int32_t srcLimit,
4222  uint32_t options) const {
4223  return doCaseCompare(start, limit - start, srcText, srcStart, srcLimit - srcStart, options);
4224 }
4225 
4226 inline int32_t
4227 UnicodeString::indexOf(const UnicodeString& srcText,
4228  int32_t srcStart,
4229  int32_t srcLength,
4230  int32_t start,
4231  int32_t _length) const
4232 {
4233  if(!srcText.isBogus()) {
4234  srcText.pinIndices(srcStart, srcLength);
4235  if(srcLength > 0) {
4236  return indexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
4237  }
4238  }
4239  return -1;
4240 }
4241 
4242 inline int32_t
4243 UnicodeString::indexOf(const UnicodeString& text) const
4244 { return indexOf(text, 0, text.length(), 0, length()); }
4245 
4246 inline int32_t
4247 UnicodeString::indexOf(const UnicodeString& text,
4248  int32_t start) const {
4249  pinIndex(start);
4250  return indexOf(text, 0, text.length(), start, length() - start);
4251 }
4252 
4253 inline int32_t
4254 UnicodeString::indexOf(const UnicodeString& text,
4255  int32_t start,
4256  int32_t _length) const
4257 { return indexOf(text, 0, text.length(), start, _length); }
4258 
4259 inline int32_t
4260 UnicodeString::indexOf(const char16_t *srcChars,
4261  int32_t srcLength,
4262  int32_t start) const {
4263  pinIndex(start);
4264  return indexOf(srcChars, 0, srcLength, start, length() - start);
4265 }
4266 
4267 inline int32_t
4268 UnicodeString::indexOf(ConstChar16Ptr srcChars,
4269  int32_t srcLength,
4270  int32_t start,
4271  int32_t _length) const
4272 { return indexOf(srcChars, 0, srcLength, start, _length); }
4273 
4274 inline int32_t
4275 UnicodeString::indexOf(char16_t c,
4276  int32_t start,
4277  int32_t _length) const
4278 { return doIndexOf(c, start, _length); }
4279 
4280 inline int32_t
4281 UnicodeString::indexOf(UChar32 c,
4282  int32_t start,
4283  int32_t _length) const
4284 { return doIndexOf(c, start, _length); }
4285 
4286 inline int32_t
4287 UnicodeString::indexOf(char16_t c) const
4288 { return doIndexOf(c, 0, length()); }
4289 
4290 inline int32_t
4291 UnicodeString::indexOf(UChar32 c) const
4292 { return indexOf(c, 0, length()); }
4293 
4294 inline int32_t
4295 UnicodeString::indexOf(char16_t c,
4296  int32_t start) const {
4297  pinIndex(start);
4298  return doIndexOf(c, start, length() - start);
4299 }
4300 
4301 inline int32_t
4302 UnicodeString::indexOf(UChar32 c,
4303  int32_t start) const {
4304  pinIndex(start);
4305  return indexOf(c, start, length() - start);
4306 }
4307 
4308 inline int32_t
4309 UnicodeString::lastIndexOf(ConstChar16Ptr srcChars,
4310  int32_t srcLength,
4311  int32_t start,
4312  int32_t _length) const
4313 { return lastIndexOf(srcChars, 0, srcLength, start, _length); }
4314 
4315 inline int32_t
4316 UnicodeString::lastIndexOf(const char16_t *srcChars,
4317  int32_t srcLength,
4318  int32_t start) const {
4319  pinIndex(start);
4320  return lastIndexOf(srcChars, 0, srcLength, start, length() - start);
4321 }
4322 
4323 inline int32_t
4324 UnicodeString::lastIndexOf(const UnicodeString& srcText,
4325  int32_t srcStart,
4326  int32_t srcLength,
4327  int32_t start,
4328  int32_t _length) const
4329 {
4330  if(!srcText.isBogus()) {
4331  srcText.pinIndices(srcStart, srcLength);
4332  if(srcLength > 0) {
4333  return lastIndexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
4334  }
4335  }
4336  return -1;
4337 }
4338 
4339 inline int32_t
4340 UnicodeString::lastIndexOf(const UnicodeString& text,
4341  int32_t start,
4342  int32_t _length) const
4343 { return lastIndexOf(text, 0, text.length(), start, _length); }
4344 
4345 inline int32_t
4346 UnicodeString::lastIndexOf(const UnicodeString& text,
4347  int32_t start) const {
4348  pinIndex(start);
4349  return lastIndexOf(text, 0, text.length(), start, length() - start);
4350 }
4351 
4352 inline int32_t
4353 UnicodeString::lastIndexOf(const UnicodeString& text) const
4354 { return lastIndexOf(text, 0, text.length(), 0, length()); }
4355 
4356 inline int32_t
4357 UnicodeString::lastIndexOf(char16_t c,
4358  int32_t start,
4359  int32_t _length) const
4360 { return doLastIndexOf(c, start, _length); }
4361 
4362 inline int32_t
4363 UnicodeString::lastIndexOf(UChar32 c,
4364  int32_t start,
4365  int32_t _length) const {
4366  return doLastIndexOf(c, start, _length);
4367 }
4368 
4369 inline int32_t
4370 UnicodeString::lastIndexOf(char16_t c) const
4371 { return doLastIndexOf(c, 0, length()); }
4372 
4373 inline int32_t
4374 UnicodeString::lastIndexOf(UChar32 c) const {
4375  return lastIndexOf(c, 0, length());
4376 }
4377 
4378 inline int32_t
4379 UnicodeString::lastIndexOf(char16_t c,
4380  int32_t start) const {
4381  pinIndex(start);
4382  return doLastIndexOf(c, start, length() - start);
4383 }
4384 
4385 inline int32_t
4386 UnicodeString::lastIndexOf(UChar32 c,
4387  int32_t start) const {
4388  pinIndex(start);
4389  return lastIndexOf(c, start, length() - start);
4390 }
4391 
4392 inline UBool
4393 UnicodeString::startsWith(const UnicodeString& text) const
4394 { return compare(0, text.length(), text, 0, text.length()) == 0; }
4395 
4396 inline UBool
4397 UnicodeString::startsWith(const UnicodeString& srcText,
4398  int32_t srcStart,
4399  int32_t srcLength) const
4400 { return doCompare(0, srcLength, srcText, srcStart, srcLength) == 0; }
4401 
4402 inline UBool
4403 UnicodeString::startsWith(ConstChar16Ptr srcChars, int32_t srcLength) const {
4404  if(srcLength < 0) {
4405  srcLength = u_strlen(toUCharPtr(srcChars));
4406  }
4407  return doCompare(0, srcLength, srcChars, 0, srcLength) == 0;
4408 }
4409 
4410 inline UBool
4411 UnicodeString::startsWith(const char16_t *srcChars, int32_t srcStart, int32_t srcLength) const {
4412  if(srcLength < 0) {
4413  srcLength = u_strlen(toUCharPtr(srcChars));
4414  }
4415  return doCompare(0, srcLength, srcChars, srcStart, srcLength) == 0;
4416 }
4417 
4418 inline UBool
4419 UnicodeString::endsWith(const UnicodeString& text) const
4420 { return doCompare(length() - text.length(), text.length(),
4421  text, 0, text.length()) == 0; }
4422 
4423 inline UBool
4424 UnicodeString::endsWith(const UnicodeString& srcText,
4425  int32_t srcStart,
4426  int32_t srcLength) const {
4427  srcText.pinIndices(srcStart, srcLength);
4428  return doCompare(length() - srcLength, srcLength,
4429  srcText, srcStart, srcLength) == 0;
4430 }
4431 
4432 inline UBool
4433 UnicodeString::endsWith(ConstChar16Ptr srcChars,
4434  int32_t srcLength) const {
4435  if(srcLength < 0) {
4436  srcLength = u_strlen(toUCharPtr(srcChars));
4437  }
4438  return doCompare(length() - srcLength, srcLength,
4439  srcChars, 0, srcLength) == 0;
4440 }
4441 
4442 inline UBool
4443 UnicodeString::endsWith(const char16_t *srcChars,
4444  int32_t srcStart,
4445  int32_t srcLength) const {
4446  if(srcLength < 0) {
4447  srcLength = u_strlen(toUCharPtr(srcChars + srcStart));
4448  }
4449  return doCompare(length() - srcLength, srcLength,
4450  srcChars, srcStart, srcLength) == 0;
4451 }
4452 
4453 //========================================
4454 // replace
4455 //========================================
4456 inline UnicodeString&
4457 UnicodeString::replace(int32_t start,
4458  int32_t _length,
4459  const UnicodeString& srcText)
4460 { return doReplace(start, _length, srcText, 0, srcText.length()); }
4461 
4462 inline UnicodeString&
4463 UnicodeString::replace(int32_t start,
4464  int32_t _length,
4465  const UnicodeString& srcText,
4466  int32_t srcStart,
4467  int32_t srcLength)
4468 { return doReplace(start, _length, srcText, srcStart, srcLength); }
4469 
4470 inline UnicodeString&
4471 UnicodeString::replace(int32_t start,
4472  int32_t _length,
4473  ConstChar16Ptr srcChars,
4474  int32_t srcLength)
4475 { return doReplace(start, _length, srcChars, 0, srcLength); }
4476 
4477 inline UnicodeString&
4478 UnicodeString::replace(int32_t start,
4479  int32_t _length,
4480  const char16_t *srcChars,
4481  int32_t srcStart,
4482  int32_t srcLength)
4483 { return doReplace(start, _length, srcChars, srcStart, srcLength); }
4484 
4485 inline UnicodeString&
4486 UnicodeString::replace(int32_t start,
4487  int32_t _length,
4488  char16_t srcChar)
4489 { return doReplace(start, _length, &srcChar, 0, 1); }
4490 
4491 inline UnicodeString&
4492 UnicodeString::replaceBetween(int32_t start,
4493  int32_t limit,
4494  const UnicodeString& srcText)
4495 { return doReplace(start, limit - start, srcText, 0, srcText.length()); }
4496 
4497 inline UnicodeString&
4498 UnicodeString::replaceBetween(int32_t start,
4499  int32_t limit,
4500  const UnicodeString& srcText,
4501  int32_t srcStart,
4502  int32_t srcLimit)
4503 { return doReplace(start, limit - start, srcText, srcStart, srcLimit - srcStart); }
4504 
4505 inline UnicodeString&
4506 UnicodeString::findAndReplace(const UnicodeString& oldText,
4507  const UnicodeString& newText)
4508 { return findAndReplace(0, length(), oldText, 0, oldText.length(),
4509  newText, 0, newText.length()); }
4510 
4511 inline UnicodeString&
4512 UnicodeString::findAndReplace(int32_t start,
4513  int32_t _length,
4514  const UnicodeString& oldText,
4515  const UnicodeString& newText)
4516 { return findAndReplace(start, _length, oldText, 0, oldText.length(),
4517  newText, 0, newText.length()); }
4518 
4519 // ============================
4520 // extract
4521 // ============================
4522 inline void
4523 UnicodeString::doExtract(int32_t start,
4524  int32_t _length,
4525  UnicodeString& target) const
4526 { target.replace(0, target.length(), *this, start, _length); }
4527 
4528 inline void
4529 UnicodeString::extract(int32_t start,
4530  int32_t _length,
4531  Char16Ptr target,
4532  int32_t targetStart) const
4533 { doExtract(start, _length, target, targetStart); }
4534 
4535 inline void
4536 UnicodeString::extract(int32_t start,
4537  int32_t _length,
4538  UnicodeString& target) const
4539 { doExtract(start, _length, target); }
4540 
4541 #if !UCONFIG_NO_CONVERSION
4542 
4543 inline int32_t
4544 UnicodeString::extract(int32_t start,
4545  int32_t _length,
4546  char *dst,
4547  const char *codepage) const
4548 
4549 {
4550  // This dstSize value will be checked explicitly
4551  return extract(start, _length, dst, dst!=0 ? 0xffffffff : 0, codepage);
4552 }
4553 
4554 #endif
4555 
4556 inline void
4557 UnicodeString::extractBetween(int32_t start,
4558  int32_t limit,
4559  char16_t *dst,
4560  int32_t dstStart) const {
4561  pinIndex(start);
4562  pinIndex(limit);
4563  doExtract(start, limit - start, dst, dstStart);
4564 }
4565 
4566 inline UnicodeString
4567 UnicodeString::tempSubStringBetween(int32_t start, int32_t limit) const {
4568  return tempSubString(start, limit - start);
4569 }
4570 
4571 inline char16_t
4572 UnicodeString::doCharAt(int32_t offset) const
4573 {
4574  if((uint32_t)offset < (uint32_t)length()) {
4575  return getArrayStart()[offset];
4576  } else {
4577  return kInvalidUChar;
4578  }
4579 }
4580 
4581 inline char16_t
4582 UnicodeString::charAt(int32_t offset) const
4583 { return doCharAt(offset); }
4584 
4585 inline char16_t
4586 UnicodeString::operator[] (int32_t offset) const
4587 { return doCharAt(offset); }
4588 
4589 inline UBool
4590 UnicodeString::isEmpty() const {
4591  // Arithmetic or logical right shift does not matter: only testing for 0.
4592  return (fUnion.fFields.fLengthAndFlags>>kLengthShift) == 0;
4593 }
4594 
4595 //========================================
4596 // Write implementation methods
4597 //========================================
4598 inline void
4599 UnicodeString::setZeroLength() {
4600  fUnion.fFields.fLengthAndFlags &= kAllStorageFlags;
4601 }
4602 
4603 inline void
4604 UnicodeString::setShortLength(int32_t len) {
4605  // requires 0 <= len <= kMaxShortLength
4606  fUnion.fFields.fLengthAndFlags =
4607  (int16_t)((fUnion.fFields.fLengthAndFlags & kAllStorageFlags) | (len << kLengthShift));
4608 }
4609 
4610 inline void
4611 UnicodeString::setLength(int32_t len) {
4612  if(len <= kMaxShortLength) {
4613  setShortLength(len);
4614  } else {
4615  fUnion.fFields.fLengthAndFlags |= kLengthIsLarge;
4616  fUnion.fFields.fLength = len;
4617  }
4618 }
4619 
4620 inline void
4621 UnicodeString::setToEmpty() {
4622  fUnion.fFields.fLengthAndFlags = kShortString;
4623 }
4624 
4625 inline void
4626 UnicodeString::setArray(char16_t *array, int32_t len, int32_t capacity) {
4627  setLength(len);
4628  fUnion.fFields.fArray = array;
4629  fUnion.fFields.fCapacity = capacity;
4630 }
4631 
4632 inline UnicodeString&
4633 UnicodeString::operator= (char16_t ch)
4634 { return doReplace(0, length(), &ch, 0, 1); }
4635 
4636 inline UnicodeString&
4637 UnicodeString::operator= (UChar32 ch)
4638 { return replace(0, length(), ch); }
4639 
4640 inline UnicodeString&
4641 UnicodeString::setTo(const UnicodeString& srcText,
4642  int32_t srcStart,
4643  int32_t srcLength)
4644 {
4645  unBogus();
4646  return doReplace(0, length(), srcText, srcStart, srcLength);
4647 }
4648 
4649 inline UnicodeString&
4650 UnicodeString::setTo(const UnicodeString& srcText,
4651  int32_t srcStart)
4652 {
4653  unBogus();
4654  srcText.pinIndex(srcStart);
4655  return doReplace(0, length(), srcText, srcStart, srcText.length() - srcStart);
4656 }
4657 
4658 inline UnicodeString&
4659 UnicodeString::setTo(const UnicodeString& srcText)
4660 {
4661  return copyFrom(srcText);
4662 }
4663 
4664 inline UnicodeString&
4665 UnicodeString::setTo(const char16_t *srcChars,
4666  int32_t srcLength)
4667 {
4668  unBogus();
4669  return doReplace(0, length(), srcChars, 0, srcLength);
4670 }
4671 
4672 inline UnicodeString&
4673 UnicodeString::setTo(char16_t srcChar)
4674 {
4675  unBogus();
4676  return doReplace(0, length(), &srcChar, 0, 1);
4677 }
4678 
4679 inline UnicodeString&
4680 UnicodeString::setTo(UChar32 srcChar)
4681 {
4682  unBogus();
4683  return replace(0, length(), srcChar);
4684 }
4685 
4686 inline UnicodeString&
4687 UnicodeString::append(const UnicodeString& srcText,
4688  int32_t srcStart,
4689  int32_t srcLength)
4690 { return doAppend(srcText, srcStart, srcLength); }
4691 
4692 inline UnicodeString&
4693 UnicodeString::append(const UnicodeString& srcText)
4694 { return doAppend(srcText, 0, srcText.length()); }
4695 
4696 inline UnicodeString&
4697 UnicodeString::append(const char16_t *srcChars,
4698  int32_t srcStart,
4699  int32_t srcLength)
4700 { return doAppend(srcChars, srcStart, srcLength); }
4701 
4702 inline UnicodeString&
4703 UnicodeString::append(ConstChar16Ptr srcChars,
4704  int32_t srcLength)
4705 { return doAppend(srcChars, 0, srcLength); }
4706 
4707 inline UnicodeString&
4708 UnicodeString::append(char16_t srcChar)
4709 { return doAppend(&srcChar, 0, 1); }
4710 
4711 inline UnicodeString&
4712 UnicodeString::operator+= (char16_t ch)
4713 { return doAppend(&ch, 0, 1); }
4714 
4715 inline UnicodeString&
4716 UnicodeString::operator+= (UChar32 ch) {
4717  return append(ch);
4718 }
4719 
4720 inline UnicodeString&
4721 UnicodeString::operator+= (const UnicodeString& srcText)
4722 { return doAppend(srcText, 0, srcText.length()); }
4723 
4724 inline UnicodeString&
4725 UnicodeString::insert(int32_t start,
4726  const UnicodeString& srcText,
4727  int32_t srcStart,
4728  int32_t srcLength)
4729 { return doReplace(start, 0, srcText, srcStart, srcLength); }
4730 
4731 inline UnicodeString&
4732 UnicodeString::insert(int32_t start,
4733  const UnicodeString& srcText)
4734 { return doReplace(start, 0, srcText, 0, srcText.length()); }
4735 
4736 inline UnicodeString&
4737 UnicodeString::insert(int32_t start,
4738  const char16_t *srcChars,
4739  int32_t srcStart,
4740  int32_t srcLength)
4741 { return doReplace(start, 0, srcChars, srcStart, srcLength); }
4742 
4743 inline UnicodeString&
4744 UnicodeString::insert(int32_t start,
4745  ConstChar16Ptr srcChars,
4746  int32_t srcLength)
4747 { return doReplace(start, 0, srcChars, 0, srcLength); }
4748 
4749 inline UnicodeString&
4750 UnicodeString::insert(int32_t start,
4751  char16_t srcChar)
4752 { return doReplace(start, 0, &srcChar, 0, 1); }
4753 
4754 inline UnicodeString&
4755 UnicodeString::insert(int32_t start,
4756  UChar32 srcChar)
4757 { return replace(start, 0, srcChar); }
4758 
4759 
4760 inline UnicodeString&
4761 UnicodeString::remove()
4762 {
4763  // remove() of a bogus string makes the string empty and non-bogus
4764  if(isBogus()) {
4765  setToEmpty();
4766  } else {
4767  setZeroLength();
4768  }
4769  return *this;
4770 }
4771 
4772 inline UnicodeString&
4773 UnicodeString::remove(int32_t start,
4774  int32_t _length)
4775 {
4776  if(start <= 0 && _length == INT32_MAX) {
4777  // remove(guaranteed everything) of a bogus string makes the string empty and non-bogus
4778  return remove();
4779  }
4780  return doReplace(start, _length, NULL, 0, 0);
4781 }
4782 
4783 inline UnicodeString&
4784 UnicodeString::removeBetween(int32_t start,
4785  int32_t limit)
4786 { return doReplace(start, limit - start, NULL, 0, 0); }
4787 
4788 inline UnicodeString &
4789 UnicodeString::retainBetween(int32_t start, int32_t limit) {
4790  truncate(limit);
4791  return doReplace(0, start, NULL, 0, 0);
4792 }
4793 
4794 inline UBool
4795 UnicodeString::truncate(int32_t targetLength)
4796 {
4797  if(isBogus() && targetLength == 0) {
4798  // truncate(0) of a bogus string makes the string empty and non-bogus
4799  unBogus();
4800  return FALSE;
4801  } else if((uint32_t)targetLength < (uint32_t)length()) {
4802  setLength(targetLength);
4803  return TRUE;
4804  } else {
4805  return FALSE;
4806  }
4807 }
4808 
4809 inline UnicodeString&
4810 UnicodeString::reverse()
4811 { return doReverse(0, length()); }
4812 
4813 inline UnicodeString&
4814 UnicodeString::reverse(int32_t start,
4815  int32_t _length)
4816 { return doReverse(start, _length); }
4817 
4819 
4820 #endif
#define UNISTR_OBJECT_SIZE
Desired sizeof(UnicodeString) in bytes.
Definition: unistr.h:214
An Appendable implementation which writes to a UnicodeString.
Definition: appendable.h:153
EInvariant
Constant to be used in the UnicodeString(char *, int32_t, EInvariant) constructor which constructs a ...
Definition: unistr.h:308
UnicodeString & operator=(UnicodeString &&src) U_NOEXCEPT
Move assignment operator, might leave src in bogus state.
Definition: unistr.h:1913
UnicodeString(wchar_t *buffer, int32_t buffLength, int32_t buffCapacity)
Writable-aliasing wchar_t * constructor.
Definition: unistr.h:3197
virtual void copy(int32_t start, int32_t limit, int32_t dest)=0
Copies a substring of this object, retaining metadata.
friend U_COMMON_API void swap(UnicodeString &s1, UnicodeString &s2) U_NOEXCEPT
Non-member UnicodeString swap function.
Definition: unistr.h:1944
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:871
UNISTR_FROM_STRING_EXPLICIT UnicodeString(const uint16_t *text)
uint16_t * constructor.
Definition: unistr.h:3024
UNISTR_FROM_STRING_EXPLICIT UnicodeString(const wchar_t *text)
wchar_t * constructor.
Definition: unistr.h:3044
void * UClassID
UClassID is used to identify classes without using the compiler&#39;s RTTI.
Definition: uobject.h:93
UnicodeString(const wchar_t *text, int32_t length)
wchar_t * constructor.
Definition: unistr.h:3103
#define U_SIZEOF_UCHAR
Number of bytes in a UChar.
Definition: umachine.h:291
UnicodeString(const uint16_t *text, int32_t length)
uint16_t * constructor.
Definition: unistr.h:3086
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:50
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:76
#define UCONFIG_NO_BREAK_ITERATION
This switch turns off break iteration.
Definition: uconfig.h:345
UBool isBogus(void) const
Determine if this object contains a valid string.
Definition: unistr.h:3970
Records lengths of string edits but not replacement text.
Definition: edits.h:32
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:73
#define UNISTR_FROM_CHAR_EXPLICIT
This can be defined to be empty or "explicit".
Definition: unistr.h:156
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:131
StringClass & toUTF8String(StringClass &result) const
Convert the UnicodeString to UTF-8 and append the result to a standard string.
Definition: unistr.h:1732
int32_t length() const
Returns the number of 16-bit code units in the text.
Definition: rep.h:245
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:102
UBool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
Definition: stringpiece.h:218
UChar32 char32At(int32_t offset) const
Returns the 32-bit code point at the given 16-bit offset into the text.
Definition: rep.h:255
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
Definition: umachine.h:396
#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:255
virtual char16_t getCharAt(int32_t offset) const =0
Virtual version of charAt().
#define TRUE
The TRUE value of a UBool.
Definition: umachine.h:240
#define U_NOEXCEPT
"noexcept" if supported, otherwise empty.
Definition: platform.h:539
uint16_t UChar
The base type for UTF-16 code units and pointers.
Definition: umachine.h:349
UnicodeString(uint16_t *buffer, int32_t buffLength, int32_t buffCapacity)
Writable-aliasing uint16_t * constructor.
Definition: unistr.h:3179
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:132
struct UConverter UConverter
Definition: ucnv_err.h:96
#define INT32_MAX
The largest value a 32 bit signed integer can hold.
Definition: umachine.h:182
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:396
char16_t charAt(int32_t offset) const
Returns the 16-bit code unit at the given offset into the text.
Definition: rep.h:250
int32_t length(void) const
Return the length of the UnicodeString object.
Definition: unistr.h:3955
char16_t * wrapper with implicit conversion from distinct but bit-compatible pointer types...
Definition: char16ptr.h:39
const char16_t * wrapper with implicit conversion from distinct but bit-compatible pointer types...
Definition: char16ptr.h:146
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:231
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:244
#define U_COMMON_API
Set to export library symbols from inside the common library, and to import them from outside...
Definition: utypes.h:359
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:296
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:176
A string-like object that points to a sized piece of memory.
Definition: stringpiece.h:54
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:4463
#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:236
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:188
C++ API: Replaceable String.