ICU 60.1  60.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 USTRING_H
42 
45 U_STABLE int32_t U_EXPORT2
46 u_strlen(const UChar *s);
47 #endif
48 
50 
51 #if !UCONFIG_NO_BREAK_ITERATION
52 class BreakIterator; // unicode/brkiter.h
53 #endif
54 class Edits;
55 
57 
58 // Not #ifndef U_HIDE_INTERNAL_API because UnicodeString needs the UStringCaseMapper.
65 typedef int32_t U_CALLCONV
66 UStringCaseMapper(int32_t caseLocale, uint32_t options,
68  icu::BreakIterator *iter,
69 #endif
70  char16_t *dest, int32_t destCapacity,
71  const char16_t *src, int32_t srcLength,
72  icu::Edits *edits,
73  UErrorCode &errorCode);
74 
76 
77 class Locale; // unicode/locid.h
78 class StringCharacterIterator;
79 class UnicodeStringAppendable; // unicode/appendable.h
80 
81 /* The <iostream> include has been moved to unicode/ustream.h */
82 
93 #define US_INV icu::UnicodeString::kInvariant
94 
112 #if !U_CHAR16_IS_TYPEDEF
113 # define UNICODE_STRING(cs, _length) icu::UnicodeString(TRUE, u ## cs, _length)
114 #else
115 # define UNICODE_STRING(cs, _length) icu::UnicodeString(TRUE, (const char16_t*)u ## cs, _length)
116 #endif
117 
131 #define UNICODE_STRING_SIMPLE(cs) UNICODE_STRING(cs, -1)
132 
140 #ifndef UNISTR_FROM_CHAR_EXPLICIT
141 # if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION)
142  // Auto-"explicit" in ICU library code.
143 # define UNISTR_FROM_CHAR_EXPLICIT explicit
144 # else
145  // Empty by default for source code compatibility.
146 # define UNISTR_FROM_CHAR_EXPLICIT
147 # endif
148 #endif
149 
160 #ifndef UNISTR_FROM_STRING_EXPLICIT
161 # if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION)
162  // Auto-"explicit" in ICU library code.
163 # define UNISTR_FROM_STRING_EXPLICIT explicit
164 # else
165  // Empty by default for source code compatibility.
166 # define UNISTR_FROM_STRING_EXPLICIT
167 # endif
168 #endif
169 
203 #ifndef UNISTR_OBJECT_SIZE
204 # define UNISTR_OBJECT_SIZE 64
205 #endif
206 
287 {
288 public:
289 
298  enum EInvariant {
303  kInvariant
304  };
305 
306  //========================================
307  // Read-only operations
308  //========================================
309 
310  /* Comparison - bitwise only - for international comparison use collation */
311 
319  inline UBool operator== (const UnicodeString& text) const;
320 
328  inline UBool operator!= (const UnicodeString& text) const;
329 
337  inline UBool operator> (const UnicodeString& text) const;
338 
346  inline UBool operator< (const UnicodeString& text) const;
347 
355  inline UBool operator>= (const UnicodeString& text) const;
356 
364  inline UBool operator<= (const UnicodeString& text) const;
365 
377  inline int8_t compare(const UnicodeString& text) const;
378 
394  inline int8_t compare(int32_t start,
395  int32_t length,
396  const UnicodeString& text) const;
397 
415  inline int8_t compare(int32_t start,
416  int32_t length,
417  const UnicodeString& srcText,
418  int32_t srcStart,
419  int32_t srcLength) const;
420 
433  inline int8_t compare(ConstChar16Ptr srcChars,
434  int32_t srcLength) const;
435 
450  inline int8_t compare(int32_t start,
451  int32_t length,
452  const char16_t *srcChars) const;
453 
471  inline int8_t compare(int32_t start,
472  int32_t length,
473  const char16_t *srcChars,
474  int32_t srcStart,
475  int32_t srcLength) const;
476 
494  inline int8_t compareBetween(int32_t start,
495  int32_t limit,
496  const UnicodeString& srcText,
497  int32_t srcStart,
498  int32_t srcLimit) const;
499 
517  inline int8_t compareCodePointOrder(const UnicodeString& text) const;
518 
538  inline int8_t compareCodePointOrder(int32_t start,
539  int32_t length,
540  const UnicodeString& srcText) const;
541 
563  inline int8_t compareCodePointOrder(int32_t start,
564  int32_t length,
565  const UnicodeString& srcText,
566  int32_t srcStart,
567  int32_t srcLength) const;
568 
587  inline int8_t compareCodePointOrder(ConstChar16Ptr srcChars,
588  int32_t srcLength) const;
589 
609  inline int8_t compareCodePointOrder(int32_t start,
610  int32_t length,
611  const char16_t *srcChars) const;
612 
634  inline int8_t compareCodePointOrder(int32_t start,
635  int32_t length,
636  const char16_t *srcChars,
637  int32_t srcStart,
638  int32_t srcLength) const;
639 
661  inline int8_t compareCodePointOrderBetween(int32_t start,
662  int32_t limit,
663  const UnicodeString& srcText,
664  int32_t srcStart,
665  int32_t srcLimit) const;
666 
685  inline int8_t caseCompare(const UnicodeString& text, uint32_t options) const;
686 
707  inline int8_t caseCompare(int32_t start,
708  int32_t length,
709  const UnicodeString& srcText,
710  uint32_t options) const;
711 
734  inline int8_t caseCompare(int32_t start,
735  int32_t length,
736  const UnicodeString& srcText,
737  int32_t srcStart,
738  int32_t srcLength,
739  uint32_t options) const;
740 
760  inline int8_t caseCompare(ConstChar16Ptr srcChars,
761  int32_t srcLength,
762  uint32_t options) const;
763 
784  inline int8_t caseCompare(int32_t start,
785  int32_t length,
786  const char16_t *srcChars,
787  uint32_t options) const;
788 
811  inline int8_t caseCompare(int32_t start,
812  int32_t length,
813  const char16_t *srcChars,
814  int32_t srcStart,
815  int32_t srcLength,
816  uint32_t options) const;
817 
840  inline int8_t caseCompareBetween(int32_t start,
841  int32_t limit,
842  const UnicodeString& srcText,
843  int32_t srcStart,
844  int32_t srcLimit,
845  uint32_t options) const;
846 
854  inline UBool startsWith(const UnicodeString& text) const;
855 
866  inline UBool startsWith(const UnicodeString& srcText,
867  int32_t srcStart,
868  int32_t srcLength) const;
869 
878  inline UBool startsWith(ConstChar16Ptr srcChars,
879  int32_t srcLength) const;
880 
890  inline UBool startsWith(const char16_t *srcChars,
891  int32_t srcStart,
892  int32_t srcLength) const;
893 
901  inline UBool endsWith(const UnicodeString& text) const;
902 
913  inline UBool endsWith(const UnicodeString& srcText,
914  int32_t srcStart,
915  int32_t srcLength) const;
916 
925  inline UBool endsWith(ConstChar16Ptr srcChars,
926  int32_t srcLength) const;
927 
938  inline UBool endsWith(const char16_t *srcChars,
939  int32_t srcStart,
940  int32_t srcLength) const;
941 
942 
943  /* Searching - bitwise only */
944 
953  inline int32_t indexOf(const UnicodeString& text) const;
954 
964  inline int32_t indexOf(const UnicodeString& text,
965  int32_t start) const;
966 
978  inline int32_t indexOf(const UnicodeString& text,
979  int32_t start,
980  int32_t length) const;
981 
998  inline int32_t indexOf(const UnicodeString& srcText,
999  int32_t srcStart,
1000  int32_t srcLength,
1001  int32_t start,
1002  int32_t length) const;
1003 
1015  inline int32_t indexOf(const char16_t *srcChars,
1016  int32_t srcLength,
1017  int32_t start) const;
1018 
1031  inline int32_t indexOf(ConstChar16Ptr srcChars,
1032  int32_t srcLength,
1033  int32_t start,
1034  int32_t length) const;
1035 
1052  int32_t indexOf(const char16_t *srcChars,
1053  int32_t srcStart,
1054  int32_t srcLength,
1055  int32_t start,
1056  int32_t length) const;
1057 
1065  inline int32_t indexOf(char16_t c) const;
1066 
1075  inline int32_t indexOf(UChar32 c) const;
1076 
1085  inline int32_t indexOf(char16_t c,
1086  int32_t start) const;
1087 
1097  inline int32_t indexOf(UChar32 c,
1098  int32_t start) const;
1099 
1110  inline int32_t indexOf(char16_t c,
1111  int32_t start,
1112  int32_t length) const;
1113 
1125  inline int32_t indexOf(UChar32 c,
1126  int32_t start,
1127  int32_t length) const;
1128 
1137  inline int32_t lastIndexOf(const UnicodeString& text) const;
1138 
1148  inline int32_t lastIndexOf(const UnicodeString& text,
1149  int32_t start) const;
1150 
1162  inline int32_t lastIndexOf(const UnicodeString& text,
1163  int32_t start,
1164  int32_t length) const;
1165 
1182  inline int32_t lastIndexOf(const UnicodeString& srcText,
1183  int32_t srcStart,
1184  int32_t srcLength,
1185  int32_t start,
1186  int32_t length) const;
1187 
1198  inline int32_t lastIndexOf(const char16_t *srcChars,
1199  int32_t srcLength,
1200  int32_t start) const;
1201 
1214  inline int32_t lastIndexOf(ConstChar16Ptr srcChars,
1215  int32_t srcLength,
1216  int32_t start,
1217  int32_t length) const;
1218 
1235  int32_t lastIndexOf(const char16_t *srcChars,
1236  int32_t srcStart,
1237  int32_t srcLength,
1238  int32_t start,
1239  int32_t length) const;
1240 
1248  inline int32_t lastIndexOf(char16_t c) const;
1249 
1258  inline int32_t lastIndexOf(UChar32 c) const;
1259 
1268  inline int32_t lastIndexOf(char16_t c,
1269  int32_t start) const;
1270 
1280  inline int32_t lastIndexOf(UChar32 c,
1281  int32_t start) const;
1282 
1293  inline int32_t lastIndexOf(char16_t c,
1294  int32_t start,
1295  int32_t length) const;
1296 
1308  inline int32_t lastIndexOf(UChar32 c,
1309  int32_t start,
1310  int32_t length) const;
1311 
1312 
1313  /* Character access */
1314 
1323  inline char16_t charAt(int32_t offset) const;
1324 
1332  inline char16_t operator[] (int32_t offset) const;
1333 
1345  UChar32 char32At(int32_t offset) const;
1346 
1362  int32_t getChar32Start(int32_t offset) const;
1363 
1380  int32_t getChar32Limit(int32_t offset) const;
1381 
1432  int32_t moveIndex32(int32_t index, int32_t delta) const;
1433 
1434  /* Substring extraction */
1435 
1451  inline void extract(int32_t start,
1452  int32_t length,
1453  Char16Ptr dst,
1454  int32_t dstStart = 0) const;
1455 
1477  int32_t
1478  extract(Char16Ptr dest, int32_t destCapacity,
1479  UErrorCode &errorCode) const;
1480 
1491  inline void extract(int32_t start,
1492  int32_t length,
1493  UnicodeString& target) const;
1494 
1506  inline void extractBetween(int32_t start,
1507  int32_t limit,
1508  char16_t *dst,
1509  int32_t dstStart = 0) const;
1510 
1520  virtual void extractBetween(int32_t start,
1521  int32_t limit,
1522  UnicodeString& target) const;
1523 
1545  int32_t extract(int32_t start,
1546  int32_t startLength,
1547  char *target,
1548  int32_t targetCapacity,
1549  enum EInvariant inv) const;
1550 
1551 #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
1552 
1572  int32_t extract(int32_t start,
1573  int32_t startLength,
1574  char *target,
1575  uint32_t targetLength) const;
1576 
1577 #endif
1578 
1579 #if !UCONFIG_NO_CONVERSION
1580 
1606  inline int32_t extract(int32_t start,
1607  int32_t startLength,
1608  char *target,
1609  const char *codepage = 0) const;
1610 
1640  int32_t extract(int32_t start,
1641  int32_t startLength,
1642  char *target,
1643  uint32_t targetLength,
1644  const char *codepage) const;
1645 
1663  int32_t extract(char *dest, int32_t destCapacity,
1664  UConverter *cnv,
1665  UErrorCode &errorCode) const;
1666 
1667 #endif
1668 
1682  UnicodeString tempSubString(int32_t start=0, int32_t length=INT32_MAX) const;
1683 
1694  inline UnicodeString tempSubStringBetween(int32_t start, int32_t limit=INT32_MAX) const;
1695 
1707  void toUTF8(ByteSink &sink) const;
1708 
1721  template<typename StringClass>
1722  StringClass &toUTF8String(StringClass &result) const {
1723  StringByteSink<StringClass> sbs(&result, length());
1724  toUTF8(sbs);
1725  return result;
1726  }
1727 
1743  int32_t toUTF32(UChar32 *utf32, int32_t capacity, UErrorCode &errorCode) const;
1744 
1745  /* Length operations */
1746 
1755  inline int32_t length(void) const;
1756 
1770  int32_t
1771  countChar32(int32_t start=0, int32_t length=INT32_MAX) const;
1772 
1796  UBool
1797  hasMoreChar32Than(int32_t start, int32_t length, int32_t number) const;
1798 
1804  inline UBool isEmpty(void) const;
1805 
1815  inline int32_t getCapacity(void) const;
1816 
1817  /* Other operations */
1818 
1824  inline int32_t hashCode(void) const;
1825 
1838  inline UBool isBogus(void) const;
1839 
1840 
1841  //========================================
1842  // Write operations
1843  //========================================
1844 
1845  /* Assignment operations */
1846 
1865  UnicodeString &operator=(const UnicodeString &srcText);
1866 
1892  UnicodeString &fastCopyFrom(const UnicodeString &src);
1893 
1894 #if U_HAVE_RVALUE_REFERENCES
1895 
1904  return moveFrom(src);
1905  }
1906 #endif
1907  // do not use #ifndef U_HIDE_DRAFT_API for moveFrom, needed by non-draft API
1918  UnicodeString &moveFrom(UnicodeString &src) U_NOEXCEPT;
1919 
1925  void swap(UnicodeString &other) U_NOEXCEPT;
1926 
1933  friend U_COMMON_API inline void U_EXPORT2
1934  swap(UnicodeString &s1, UnicodeString &s2) U_NOEXCEPT {
1935  s1.swap(s2);
1936  }
1937 
1945  inline UnicodeString& operator= (char16_t ch);
1946 
1954  inline UnicodeString& operator= (UChar32 ch);
1955 
1967  inline UnicodeString& setTo(const UnicodeString& srcText,
1968  int32_t srcStart);
1969 
1983  inline UnicodeString& setTo(const UnicodeString& srcText,
1984  int32_t srcStart,
1985  int32_t srcLength);
1986 
1995  inline UnicodeString& setTo(const UnicodeString& srcText);
1996 
2005  inline UnicodeString& setTo(const char16_t *srcChars,
2006  int32_t srcLength);
2007 
2016  UnicodeString& setTo(char16_t srcChar);
2017 
2026  UnicodeString& setTo(UChar32 srcChar);
2027 
2051  UnicodeString &setTo(UBool isTerminated,
2052  ConstChar16Ptr text,
2053  int32_t textLength);
2054 
2074  UnicodeString &setTo(char16_t *buffer,
2075  int32_t buffLength,
2076  int32_t buffCapacity);
2077 
2118  void setToBogus();
2119 
2127  UnicodeString& setCharAt(int32_t offset,
2128  char16_t ch);
2129 
2130 
2131  /* Append operations */
2132 
2140  inline UnicodeString& operator+= (char16_t ch);
2141 
2149  inline UnicodeString& operator+= (UChar32 ch);
2150 
2158  inline UnicodeString& operator+= (const UnicodeString& srcText);
2159 
2174  inline UnicodeString& append(const UnicodeString& srcText,
2175  int32_t srcStart,
2176  int32_t srcLength);
2177 
2185  inline UnicodeString& append(const UnicodeString& srcText);
2186 
2200  inline UnicodeString& append(const char16_t *srcChars,
2201  int32_t srcStart,
2202  int32_t srcLength);
2203 
2213  inline UnicodeString& append(ConstChar16Ptr srcChars,
2214  int32_t srcLength);
2215 
2222  inline UnicodeString& append(char16_t srcChar);
2223 
2230  UnicodeString& append(UChar32 srcChar);
2231 
2232 
2233  /* Insert operations */
2234 
2248  inline UnicodeString& insert(int32_t start,
2249  const UnicodeString& srcText,
2250  int32_t srcStart,
2251  int32_t srcLength);
2252 
2261  inline UnicodeString& insert(int32_t start,
2262  const UnicodeString& srcText);
2263 
2277  inline UnicodeString& insert(int32_t start,
2278  const char16_t *srcChars,
2279  int32_t srcStart,
2280  int32_t srcLength);
2281 
2291  inline UnicodeString& insert(int32_t start,
2292  ConstChar16Ptr srcChars,
2293  int32_t srcLength);
2294 
2303  inline UnicodeString& insert(int32_t start,
2304  char16_t srcChar);
2305 
2314  inline UnicodeString& insert(int32_t start,
2315  UChar32 srcChar);
2316 
2317 
2318  /* Replace operations */
2319 
2337  UnicodeString& replace(int32_t start,
2338  int32_t length,
2339  const UnicodeString& srcText,
2340  int32_t srcStart,
2341  int32_t srcLength);
2342 
2355  UnicodeString& replace(int32_t start,
2356  int32_t length,
2357  const UnicodeString& srcText);
2358 
2376  UnicodeString& replace(int32_t start,
2377  int32_t length,
2378  const char16_t *srcChars,
2379  int32_t srcStart,
2380  int32_t srcLength);
2381 
2394  inline UnicodeString& replace(int32_t start,
2395  int32_t length,
2396  ConstChar16Ptr srcChars,
2397  int32_t srcLength);
2398 
2410  inline UnicodeString& replace(int32_t start,
2411  int32_t length,
2412  char16_t srcChar);
2413 
2425  UnicodeString& replace(int32_t start, int32_t length, UChar32 srcChar);
2426 
2436  inline UnicodeString& replaceBetween(int32_t start,
2437  int32_t limit,
2438  const UnicodeString& srcText);
2439 
2454  inline UnicodeString& replaceBetween(int32_t start,
2455  int32_t limit,
2456  const UnicodeString& srcText,
2457  int32_t srcStart,
2458  int32_t srcLimit);
2459 
2470  virtual void handleReplaceBetween(int32_t start,
2471  int32_t limit,
2472  const UnicodeString& text);
2473 
2479  virtual UBool hasMetaData() const;
2480 
2496  virtual void copy(int32_t start, int32_t limit, int32_t dest);
2497 
2498  /* Search and replace operations */
2499 
2508  inline UnicodeString& findAndReplace(const UnicodeString& oldText,
2509  const UnicodeString& newText);
2510 
2522  inline UnicodeString& findAndReplace(int32_t start,
2523  int32_t length,
2524  const UnicodeString& oldText,
2525  const UnicodeString& newText);
2526 
2544  UnicodeString& findAndReplace(int32_t start,
2545  int32_t length,
2546  const UnicodeString& oldText,
2547  int32_t oldStart,
2548  int32_t oldLength,
2549  const UnicodeString& newText,
2550  int32_t newStart,
2551  int32_t newLength);
2552 
2553 
2554  /* Remove operations */
2555 
2561  inline UnicodeString& remove(void);
2562 
2571  inline UnicodeString& remove(int32_t start,
2572  int32_t length = (int32_t)INT32_MAX);
2573 
2582  inline UnicodeString& removeBetween(int32_t start,
2583  int32_t limit = (int32_t)INT32_MAX);
2584 
2594  inline UnicodeString &retainBetween(int32_t start, int32_t limit = INT32_MAX);
2595 
2596  /* Length operations */
2597 
2609  UBool padLeading(int32_t targetLength,
2610  char16_t padChar = 0x0020);
2611 
2623  UBool padTrailing(int32_t targetLength,
2624  char16_t padChar = 0x0020);
2625 
2632  inline UBool truncate(int32_t targetLength);
2633 
2639  UnicodeString& trim(void);
2640 
2641 
2642  /* Miscellaneous operations */
2643 
2649  inline UnicodeString& reverse(void);
2650 
2659  inline UnicodeString& reverse(int32_t start,
2660  int32_t length);
2661 
2668  UnicodeString& toUpper(void);
2669 
2677  UnicodeString& toUpper(const Locale& locale);
2678 
2685  UnicodeString& toLower(void);
2686 
2694  UnicodeString& toLower(const Locale& locale);
2695 
2696 #if !UCONFIG_NO_BREAK_ITERATION
2697 
2724  UnicodeString &toTitle(BreakIterator *titleIter);
2725 
2753  UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale);
2754 
2786  UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale, uint32_t options);
2787 
2788 #endif
2789 
2803  UnicodeString &foldCase(uint32_t options=0 /*U_FOLD_CASE_DEFAULT*/);
2804 
2805  //========================================
2806  // Access to the internal buffer
2807  //========================================
2808 
2852  char16_t *getBuffer(int32_t minCapacity);
2853 
2874  void releaseBuffer(int32_t newLength=-1);
2875 
2906  inline const char16_t *getBuffer() const;
2907 
2941  const char16_t *getTerminatedBuffer();
2942 
2943  //========================================
2944  // Constructors
2945  //========================================
2946 
2950  inline UnicodeString();
2951 
2963  UnicodeString(int32_t capacity, UChar32 c, int32_t count);
2964 
2974  UNISTR_FROM_CHAR_EXPLICIT UnicodeString(char16_t ch);
2975 
2985  UNISTR_FROM_CHAR_EXPLICIT UnicodeString(UChar32 ch);
2986 
2997  UNISTR_FROM_STRING_EXPLICIT UnicodeString(const char16_t *text);
2998 
2999  /*
3000  * Do not use #ifndef U_HIDE_DRAFT_API for the following constructor,
3001  * it should always be available regardless of U_HIDE_DRAFT_API status
3002  */
3003 #if !U_CHAR16_IS_TYPEDEF
3004 
3015  UnicodeString(ConstChar16Ptr(text)) {}
3016 #endif
3017 
3018  /*
3019  * Do not use #ifndef U_HIDE_DRAFT_API for the following constructor,
3020  * it should always be available regardless of U_HIDE_DRAFT_API status
3021  */
3022 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
3023 
3035  UnicodeString(ConstChar16Ptr(text)) {}
3036 #endif
3037 
3038  /*
3039  * Do not use #ifndef U_HIDE_DRAFT_API for the following constructor,
3040  * it should always be available regardless of U_HIDE_DRAFT_API status
3041  */
3052  UNISTR_FROM_STRING_EXPLICIT inline UnicodeString(const std::nullptr_t text);
3053 
3061  UnicodeString(const char16_t *text,
3062  int32_t textLength);
3063 
3064  /*
3065  * Do not use #ifndef U_HIDE_DRAFT_API for the following constructor,
3066  * it should always be available regardless of U_HIDE_DRAFT_API status
3067  */
3068 #if !U_CHAR16_IS_TYPEDEF
3069 
3076  UnicodeString(const uint16_t *text, int32_t length) :
3077  UnicodeString(ConstChar16Ptr(text), length) {}
3078 #endif
3079 
3080  /*
3081  * Do not use #ifndef U_HIDE_DRAFT_API for the following constructor,
3082  * it should always be available regardless of U_HIDE_DRAFT_API status
3083  */
3084 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
3085 
3093  UnicodeString(const wchar_t *text, int32_t length) :
3094  UnicodeString(ConstChar16Ptr(text), length) {}
3095 #endif
3096 
3097  /*
3098  * Do not use #ifndef U_HIDE_DRAFT_API for the following constructor,
3099  * it should always be available regardless of U_HIDE_DRAFT_API status
3100  */
3108  inline UnicodeString(const std::nullptr_t text, int32_t length);
3109 
3132  UnicodeString(UBool isTerminated,
3133  ConstChar16Ptr text,
3134  int32_t textLength);
3135 
3154  UnicodeString(char16_t *buffer, int32_t buffLength, int32_t buffCapacity);
3155 
3156  /*
3157  * Do not use #ifndef U_HIDE_DRAFT_API for the following constructor,
3158  * it should always be available regardless of U_HIDE_DRAFT_API status
3159  */
3160 #if !U_CHAR16_IS_TYPEDEF
3161 
3169  UnicodeString(uint16_t *buffer, int32_t buffLength, int32_t buffCapacity) :
3170  UnicodeString(Char16Ptr(buffer), buffLength, buffCapacity) {}
3171 #endif
3172 
3173  /*
3174  * Do not use #ifndef U_HIDE_DRAFT_API for the following constructor,
3175  * it should always be available regardless of U_HIDE_DRAFT_API status
3176  */
3177 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
3178 
3187  UnicodeString(wchar_t *buffer, int32_t buffLength, int32_t buffCapacity) :
3188  UnicodeString(Char16Ptr(buffer), buffLength, buffCapacity) {}
3189 #endif
3190 
3191  /*
3192  * Do not use #ifndef U_HIDE_DRAFT_API for the following constructor,
3193  * it should always be available regardless of U_HIDE_DRAFT_API status
3194  */
3203  inline UnicodeString(std::nullptr_t buffer, int32_t buffLength, int32_t buffCapacity);
3204 
3205 #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
3206 
3226  UNISTR_FROM_STRING_EXPLICIT UnicodeString(const char *codepageData);
3227 
3236  UnicodeString(const char *codepageData, int32_t dataLength);
3237 
3238 #endif
3239 
3240 #if !UCONFIG_NO_CONVERSION
3241 
3259  UnicodeString(const char *codepageData, const char *codepage);
3260 
3278  UnicodeString(const char *codepageData, int32_t dataLength, const char *codepage);
3279 
3301  UnicodeString(
3302  const char *src, int32_t srcLength,
3303  UConverter *cnv,
3304  UErrorCode &errorCode);
3305 
3306 #endif
3307 
3332  UnicodeString(const char *src, int32_t length, enum EInvariant inv);
3333 
3334 
3351  UnicodeString(const UnicodeString& that);
3352 
3353 #if U_HAVE_RVALUE_REFERENCES
3354 
3360  UnicodeString(UnicodeString &&src) U_NOEXCEPT;
3361 #endif
3362 
3369  UnicodeString(const UnicodeString& src, int32_t srcStart);
3370 
3378  UnicodeString(const UnicodeString& src, int32_t srcStart, int32_t srcLength);
3379 
3396  virtual Replaceable *clone() const;
3397 
3401  virtual ~UnicodeString();
3402 
3416  static UnicodeString fromUTF8(StringPiece utf8);
3417 
3429  static UnicodeString fromUTF32(const UChar32 *utf32, int32_t length);
3430 
3431  /* Miscellaneous operations */
3432 
3467  UnicodeString unescape() const;
3468 
3488  UChar32 unescapeAt(int32_t &offset) const;
3489 
3495  static UClassID U_EXPORT2 getStaticClassID();
3496 
3502  virtual UClassID getDynamicClassID() const;
3503 
3504  //========================================
3505  // Implementation methods
3506  //========================================
3507 
3508 protected:
3513  virtual int32_t getLength() const;
3514 
3520  virtual char16_t getCharAt(int32_t offset) const;
3521 
3527  virtual UChar32 getChar32At(int32_t offset) const;
3528 
3529 private:
3530  // For char* constructors. Could be made public.
3531  UnicodeString &setToUTF8(StringPiece utf8);
3532  // For extract(char*).
3533  // We could make a toUTF8(target, capacity, errorCode) public but not
3534  // this version: New API will be cleaner if we make callers create substrings
3535  // rather than having start+length on every method,
3536  // and it should take a UErrorCode&.
3537  int32_t
3538  toUTF8(int32_t start, int32_t len,
3539  char *target, int32_t capacity) const;
3540 
3545  UBool doEquals(const UnicodeString &text, int32_t len) const;
3546 
3547  inline int8_t
3548  doCompare(int32_t start,
3549  int32_t length,
3550  const UnicodeString& srcText,
3551  int32_t srcStart,
3552  int32_t srcLength) const;
3553 
3554  int8_t doCompare(int32_t start,
3555  int32_t length,
3556  const char16_t *srcChars,
3557  int32_t srcStart,
3558  int32_t srcLength) const;
3559 
3560  inline int8_t
3561  doCompareCodePointOrder(int32_t start,
3562  int32_t length,
3563  const UnicodeString& srcText,
3564  int32_t srcStart,
3565  int32_t srcLength) const;
3566 
3567  int8_t doCompareCodePointOrder(int32_t start,
3568  int32_t length,
3569  const char16_t *srcChars,
3570  int32_t srcStart,
3571  int32_t srcLength) const;
3572 
3573  inline int8_t
3574  doCaseCompare(int32_t start,
3575  int32_t length,
3576  const UnicodeString &srcText,
3577  int32_t srcStart,
3578  int32_t srcLength,
3579  uint32_t options) const;
3580 
3581  int8_t
3582  doCaseCompare(int32_t start,
3583  int32_t length,
3584  const char16_t *srcChars,
3585  int32_t srcStart,
3586  int32_t srcLength,
3587  uint32_t options) const;
3588 
3589  int32_t doIndexOf(char16_t c,
3590  int32_t start,
3591  int32_t length) const;
3592 
3593  int32_t doIndexOf(UChar32 c,
3594  int32_t start,
3595  int32_t length) const;
3596 
3597  int32_t doLastIndexOf(char16_t c,
3598  int32_t start,
3599  int32_t length) const;
3600 
3601  int32_t doLastIndexOf(UChar32 c,
3602  int32_t start,
3603  int32_t length) const;
3604 
3605  void doExtract(int32_t start,
3606  int32_t length,
3607  char16_t *dst,
3608  int32_t dstStart) const;
3609 
3610  inline void doExtract(int32_t start,
3611  int32_t length,
3612  UnicodeString& target) const;
3613 
3614  inline char16_t doCharAt(int32_t offset) const;
3615 
3616  UnicodeString& doReplace(int32_t start,
3617  int32_t length,
3618  const UnicodeString& srcText,
3619  int32_t srcStart,
3620  int32_t srcLength);
3621 
3622  UnicodeString& doReplace(int32_t start,
3623  int32_t length,
3624  const char16_t *srcChars,
3625  int32_t srcStart,
3626  int32_t srcLength);
3627 
3628  UnicodeString& doAppend(const UnicodeString& src, int32_t srcStart, int32_t srcLength);
3629  UnicodeString& doAppend(const char16_t *srcChars, int32_t srcStart, int32_t srcLength);
3630 
3631  UnicodeString& doReverse(int32_t start,
3632  int32_t length);
3633 
3634  // calculate hash code
3635  int32_t doHashCode(void) const;
3636 
3637  // get pointer to start of array
3638  // these do not check for kOpenGetBuffer, unlike the public getBuffer() function
3639  inline char16_t* getArrayStart(void);
3640  inline const char16_t* getArrayStart(void) const;
3641 
3642  inline UBool hasShortLength() const;
3643  inline int32_t getShortLength() const;
3644 
3645  // A UnicodeString object (not necessarily its current buffer)
3646  // is writable unless it isBogus() or it has an "open" getBuffer(minCapacity).
3647  inline UBool isWritable() const;
3648 
3649  // Is the current buffer writable?
3650  inline UBool isBufferWritable() const;
3651 
3652  // None of the following does releaseArray().
3653  inline void setZeroLength();
3654  inline void setShortLength(int32_t len);
3655  inline void setLength(int32_t len);
3656  inline void setToEmpty();
3657  inline void setArray(char16_t *array, int32_t len, int32_t capacity); // sets length but not flags
3658 
3659  // allocate the array; result may be the stack buffer
3660  // sets refCount to 1 if appropriate
3661  // sets fArray, fCapacity, and flags
3662  // sets length to 0
3663  // returns boolean for success or failure
3664  UBool allocate(int32_t capacity);
3665 
3666  // release the array if owned
3667  void releaseArray(void);
3668 
3669  // turn a bogus string into an empty one
3670  void unBogus();
3671 
3672  // implements assigment operator, copy constructor, and fastCopyFrom()
3673  UnicodeString &copyFrom(const UnicodeString &src, UBool fastCopy=FALSE);
3674 
3675  // Copies just the fields without memory management.
3676  void copyFieldsFrom(UnicodeString &src, UBool setSrcToBogus) U_NOEXCEPT;
3677 
3678  // Pin start and limit to acceptable values.
3679  inline void pinIndex(int32_t& start) const;
3680  inline void pinIndices(int32_t& start,
3681  int32_t& length) const;
3682 
3683 #if !UCONFIG_NO_CONVERSION
3684 
3685  /* Internal extract() using UConverter. */
3686  int32_t doExtract(int32_t start, int32_t length,
3687  char *dest, int32_t destCapacity,
3688  UConverter *cnv,
3689  UErrorCode &errorCode) const;
3690 
3691  /*
3692  * Real constructor for converting from codepage data.
3693  * It assumes that it is called with !fRefCounted.
3694  *
3695  * If <code>codepage==0</code>, then the default converter
3696  * is used for the platform encoding.
3697  * If <code>codepage</code> is an empty string (<code>""</code>),
3698  * then a simple conversion is performed on the codepage-invariant
3699  * subset ("invariant characters") of the platform encoding. See utypes.h.
3700  */
3701  void doCodepageCreate(const char *codepageData,
3702  int32_t dataLength,
3703  const char *codepage);
3704 
3705  /*
3706  * Worker function for creating a UnicodeString from
3707  * a codepage string using a UConverter.
3708  */
3709  void
3710  doCodepageCreate(const char *codepageData,
3711  int32_t dataLength,
3712  UConverter *converter,
3713  UErrorCode &status);
3714 
3715 #endif
3716 
3717  /*
3718  * This function is called when write access to the array
3719  * is necessary.
3720  *
3721  * We need to make a copy of the array if
3722  * the buffer is read-only, or
3723  * the buffer is refCounted (shared), and refCount>1, or
3724  * the buffer is too small.
3725  *
3726  * Return FALSE if memory could not be allocated.
3727  */
3728  UBool cloneArrayIfNeeded(int32_t newCapacity = -1,
3729  int32_t growCapacity = -1,
3730  UBool doCopyArray = TRUE,
3731  int32_t **pBufferToDelete = 0,
3732  UBool forceClone = FALSE);
3733 
3739  UnicodeString &
3740  caseMap(int32_t caseLocale, uint32_t options,
3742  BreakIterator *iter,
3743 #endif
3744  UStringCaseMapper *stringCaseMapper);
3745 
3746  // ref counting
3747  void addRef(void);
3748  int32_t removeRef(void);
3749  int32_t refCount(void) const;
3750 
3751  // constants
3752  enum {
3758  US_STACKBUF_SIZE=(int32_t)(UNISTR_OBJECT_SIZE-sizeof(void *)-2)/U_SIZEOF_UCHAR,
3759  kInvalidUChar=0xffff, // U+FFFF returned by charAt(invalid index)
3760  kInvalidHashCode=0, // invalid hash code
3761  kEmptyHashCode=1, // hash code for empty string
3762 
3763  // bit flag values for fLengthAndFlags
3764  kIsBogus=1, // this string is bogus, i.e., not valid or NULL
3765  kUsingStackBuffer=2,// using fUnion.fStackFields instead of fUnion.fFields
3766  kRefCounted=4, // there is a refCount field before the characters in fArray
3767  kBufferIsReadonly=8,// do not write to this buffer
3768  kOpenGetBuffer=16, // getBuffer(minCapacity) was called (is "open"),
3769  // and releaseBuffer(newLength) must be called
3770  kAllStorageFlags=0x1f,
3771 
3772  kLengthShift=5, // remaining 11 bits for non-negative short length, or negative if long
3773  kLength1=1<<kLengthShift,
3774  kMaxShortLength=0x3ff, // max non-negative short length (leaves top bit 0)
3775  kLengthIsLarge=0xffe0, // short length < 0, real length is in fUnion.fFields.fLength
3776 
3777  // combined values for convenience
3778  kShortString=kUsingStackBuffer,
3779  kLongString=kRefCounted,
3780  kReadonlyAlias=kBufferIsReadonly,
3781  kWritableAlias=0
3782  };
3783 
3784  friend class UnicodeStringAppendable;
3785 
3786  union StackBufferOrFields; // forward declaration necessary before friend declaration
3787  friend union StackBufferOrFields; // make US_STACKBUF_SIZE visible inside fUnion
3788 
3789  /*
3790  * The following are all the class fields that are stored
3791  * in each UnicodeString object.
3792  * Note that UnicodeString has virtual functions,
3793  * therefore there is an implicit vtable pointer
3794  * as the first real field.
3795  * The fields should be aligned such that no padding is necessary.
3796  * On 32-bit machines, the size should be 32 bytes,
3797  * on 64-bit machines (8-byte pointers), it should be 40 bytes.
3798  *
3799  * We use a hack to achieve this.
3800  *
3801  * With at least some compilers, each of the following is forced to
3802  * a multiple of sizeof(pointer) [the largest field base unit here is a data pointer],
3803  * rounded up with additional padding if the fields do not already fit that requirement:
3804  * - sizeof(class UnicodeString)
3805  * - offsetof(UnicodeString, fUnion)
3806  * - sizeof(fUnion)
3807  * - sizeof(fStackFields)
3808  *
3809  * We optimize for the longest possible internal buffer for short strings.
3810  * fUnion.fStackFields begins with 2 bytes for storage flags
3811  * and the length of relatively short strings,
3812  * followed by the buffer for short string contents.
3813  * There is no padding inside fStackFields.
3814  *
3815  * Heap-allocated and aliased strings use fUnion.fFields.
3816  * Both fStackFields and fFields must begin with the same fields for flags and short length,
3817  * that is, those must have the same memory offsets inside the object,
3818  * because the flags must be inspected in order to decide which half of fUnion is being used.
3819  * We assume that the compiler does not reorder the fields.
3820  *
3821  * (Padding at the end of fFields is ok:
3822  * As long as it is no larger than fStackFields, it is not wasted space.)
3823  *
3824  * For some of the history of the UnicodeString class fields layout, see
3825  * - ICU ticket #11551 "longer UnicodeString contents in stack buffer"
3826  * - ICU ticket #11336 "UnicodeString: recombine stack buffer arrays"
3827  * - ICU ticket #8322 "why is sizeof(UnicodeString)==48?"
3828  */
3829  // (implicit) *vtable;
3830  union StackBufferOrFields {
3831  // fStackFields is used iff (fLengthAndFlags&kUsingStackBuffer) else fFields is used.
3832  // Each struct of the union must begin with fLengthAndFlags.
3833  struct {
3834  int16_t fLengthAndFlags; // bit fields: see constants above
3835  char16_t fBuffer[US_STACKBUF_SIZE]; // buffer for short strings
3836  } fStackFields;
3837  struct {
3838  int16_t fLengthAndFlags; // bit fields: see constants above
3839  int32_t fLength; // number of characters in fArray if >127; else undefined
3840  int32_t fCapacity; // capacity of fArray (in char16_ts)
3841  // array pointer last to minimize padding for machines with P128 data model
3842  // or pointer sizes that are not a power of 2
3843  char16_t *fArray; // the Unicode data
3844  } fFields;
3845  } fUnion;
3846 };
3847 
3856 U_COMMON_API UnicodeString U_EXPORT2
3857 operator+ (const UnicodeString &s1, const UnicodeString &s2);
3858 
3859 //========================================
3860 // Inline members
3861 //========================================
3862 
3863 //========================================
3864 // Privates
3865 //========================================
3866 
3867 inline void
3868 UnicodeString::pinIndex(int32_t& start) const
3869 {
3870  // pin index
3871  if(start < 0) {
3872  start = 0;
3873  } else if(start > length()) {
3874  start = length();
3875  }
3876 }
3877 
3878 inline void
3879 UnicodeString::pinIndices(int32_t& start,
3880  int32_t& _length) const
3881 {
3882  // pin indices
3883  int32_t len = length();
3884  if(start < 0) {
3885  start = 0;
3886  } else if(start > len) {
3887  start = len;
3888  }
3889  if(_length < 0) {
3890  _length = 0;
3891  } else if(_length > (len - start)) {
3892  _length = (len - start);
3893  }
3894 }
3895 
3896 inline char16_t*
3897 UnicodeString::getArrayStart() {
3898  return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3899  fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
3900 }
3901 
3902 inline const char16_t*
3903 UnicodeString::getArrayStart() const {
3904  return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3905  fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
3906 }
3907 
3908 //========================================
3909 // Default constructor
3910 //========================================
3911 
3912 inline
3913 UnicodeString::UnicodeString() {
3914  fUnion.fStackFields.fLengthAndFlags=kShortString;
3915 }
3916 
3917 inline UnicodeString::UnicodeString(const std::nullptr_t /*text*/) {
3918  fUnion.fStackFields.fLengthAndFlags=kShortString;
3919 }
3920 
3921 inline UnicodeString::UnicodeString(const std::nullptr_t /*text*/, int32_t /*length*/) {
3922  fUnion.fStackFields.fLengthAndFlags=kShortString;
3923 }
3924 
3925 inline UnicodeString::UnicodeString(std::nullptr_t /*buffer*/, int32_t /*buffLength*/, int32_t /*buffCapacity*/) {
3926  fUnion.fStackFields.fLengthAndFlags=kShortString;
3927 }
3928 
3929 //========================================
3930 // Read-only implementation methods
3931 //========================================
3932 inline UBool
3933 UnicodeString::hasShortLength() const {
3934  return fUnion.fFields.fLengthAndFlags>=0;
3935 }
3936 
3937 inline int32_t
3938 UnicodeString::getShortLength() const {
3939  // fLengthAndFlags must be non-negative -> short length >= 0
3940  // and arithmetic or logical shift does not matter.
3941  return fUnion.fFields.fLengthAndFlags>>kLengthShift;
3942 }
3943 
3944 inline int32_t
3945 UnicodeString::length() const {
3946  return hasShortLength() ? getShortLength() : fUnion.fFields.fLength;
3947 }
3948 
3949 inline int32_t
3950 UnicodeString::getCapacity() const {
3951  return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3952  US_STACKBUF_SIZE : fUnion.fFields.fCapacity;
3953 }
3954 
3955 inline int32_t
3956 UnicodeString::hashCode() const
3957 { return doHashCode(); }
3958 
3959 inline UBool
3960 UnicodeString::isBogus() const
3961 { return (UBool)(fUnion.fFields.fLengthAndFlags & kIsBogus); }
3962 
3963 inline UBool
3964 UnicodeString::isWritable() const
3965 { return (UBool)!(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus)); }
3966 
3967 inline UBool
3968 UnicodeString::isBufferWritable() const
3969 {
3970  return (UBool)(
3971  !(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus|kBufferIsReadonly)) &&
3972  (!(fUnion.fFields.fLengthAndFlags&kRefCounted) || refCount()==1));
3973 }
3974 
3975 inline const char16_t *
3976 UnicodeString::getBuffer() const {
3977  if(fUnion.fFields.fLengthAndFlags&(kIsBogus|kOpenGetBuffer)) {
3978  return nullptr;
3979  } else if(fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) {
3980  return fUnion.fStackFields.fBuffer;
3981  } else {
3982  return fUnion.fFields.fArray;
3983  }
3984 }
3985 
3986 //========================================
3987 // Read-only alias methods
3988 //========================================
3989 inline int8_t
3990 UnicodeString::doCompare(int32_t start,
3991  int32_t thisLength,
3992  const UnicodeString& srcText,
3993  int32_t srcStart,
3994  int32_t srcLength) const
3995 {
3996  if(srcText.isBogus()) {
3997  return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
3998  } else {
3999  srcText.pinIndices(srcStart, srcLength);
4000  return doCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
4001  }
4002 }
4003 
4004 inline UBool
4006 {
4007  if(isBogus()) {
4008  return text.isBogus();
4009  } else {
4010  int32_t len = length(), textLength = text.length();
4011  return !text.isBogus() && len == textLength && doEquals(text, len);
4012  }
4013 }
4014 
4015 inline UBool
4017 { return (! operator==(text)); }
4018 
4019 inline UBool
4020 UnicodeString::operator> (const UnicodeString& text) const
4021 { return doCompare(0, length(), text, 0, text.length()) == 1; }
4022 
4023 inline UBool
4024 UnicodeString::operator< (const UnicodeString& text) const
4025 { return doCompare(0, length(), text, 0, text.length()) == -1; }
4026 
4027 inline UBool
4028 UnicodeString::operator>= (const UnicodeString& text) const
4029 { return doCompare(0, length(), text, 0, text.length()) != -1; }
4030 
4031 inline UBool
4032 UnicodeString::operator<= (const UnicodeString& text) const
4033 { return doCompare(0, length(), text, 0, text.length()) != 1; }
4034 
4035 inline int8_t
4036 UnicodeString::compare(const UnicodeString& text) const
4037 { return doCompare(0, length(), text, 0, text.length()); }
4038 
4039 inline int8_t
4040 UnicodeString::compare(int32_t start,
4041  int32_t _length,
4042  const UnicodeString& srcText) const
4043 { return doCompare(start, _length, srcText, 0, srcText.length()); }
4044 
4045 inline int8_t
4046 UnicodeString::compare(ConstChar16Ptr srcChars,
4047  int32_t srcLength) const
4048 { return doCompare(0, length(), srcChars, 0, srcLength); }
4049 
4050 inline int8_t
4051 UnicodeString::compare(int32_t start,
4052  int32_t _length,
4053  const UnicodeString& srcText,
4054  int32_t srcStart,
4055  int32_t srcLength) const
4056 { return doCompare(start, _length, srcText, srcStart, srcLength); }
4057 
4058 inline int8_t
4059 UnicodeString::compare(int32_t start,
4060  int32_t _length,
4061  const char16_t *srcChars) const
4062 { return doCompare(start, _length, srcChars, 0, _length); }
4063 
4064 inline int8_t
4065 UnicodeString::compare(int32_t start,
4066  int32_t _length,
4067  const char16_t *srcChars,
4068  int32_t srcStart,
4069  int32_t srcLength) const
4070 { return doCompare(start, _length, srcChars, srcStart, srcLength); }
4071 
4072 inline int8_t
4073 UnicodeString::compareBetween(int32_t start,
4074  int32_t limit,
4075  const UnicodeString& srcText,
4076  int32_t srcStart,
4077  int32_t srcLimit) const
4078 { return doCompare(start, limit - start,
4079  srcText, srcStart, srcLimit - srcStart); }
4080 
4081 inline int8_t
4082 UnicodeString::doCompareCodePointOrder(int32_t start,
4083  int32_t thisLength,
4084  const UnicodeString& srcText,
4085  int32_t srcStart,
4086  int32_t srcLength) const
4087 {
4088  if(srcText.isBogus()) {
4089  return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
4090  } else {
4091  srcText.pinIndices(srcStart, srcLength);
4092  return doCompareCodePointOrder(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
4093  }
4094 }
4095 
4096 inline int8_t
4097 UnicodeString::compareCodePointOrder(const UnicodeString& text) const
4098 { return doCompareCodePointOrder(0, length(), text, 0, text.length()); }
4099 
4100 inline int8_t
4101 UnicodeString::compareCodePointOrder(int32_t start,
4102  int32_t _length,
4103  const UnicodeString& srcText) const
4104 { return doCompareCodePointOrder(start, _length, srcText, 0, srcText.length()); }
4105 
4106 inline int8_t
4107 UnicodeString::compareCodePointOrder(ConstChar16Ptr srcChars,
4108  int32_t srcLength) const
4109 { return doCompareCodePointOrder(0, length(), srcChars, 0, srcLength); }
4110 
4111 inline int8_t
4112 UnicodeString::compareCodePointOrder(int32_t start,
4113  int32_t _length,
4114  const UnicodeString& srcText,
4115  int32_t srcStart,
4116  int32_t srcLength) const
4117 { return doCompareCodePointOrder(start, _length, srcText, srcStart, srcLength); }
4118 
4119 inline int8_t
4120 UnicodeString::compareCodePointOrder(int32_t start,
4121  int32_t _length,
4122  const char16_t *srcChars) const
4123 { return doCompareCodePointOrder(start, _length, srcChars, 0, _length); }
4124 
4125 inline int8_t
4126 UnicodeString::compareCodePointOrder(int32_t start,
4127  int32_t _length,
4128  const char16_t *srcChars,
4129  int32_t srcStart,
4130  int32_t srcLength) const
4131 { return doCompareCodePointOrder(start, _length, srcChars, srcStart, srcLength); }
4132 
4133 inline int8_t
4134 UnicodeString::compareCodePointOrderBetween(int32_t start,
4135  int32_t limit,
4136  const UnicodeString& srcText,
4137  int32_t srcStart,
4138  int32_t srcLimit) const
4139 { return doCompareCodePointOrder(start, limit - start,
4140  srcText, srcStart, srcLimit - srcStart); }
4141 
4142 inline int8_t
4143 UnicodeString::doCaseCompare(int32_t start,
4144  int32_t thisLength,
4145  const UnicodeString &srcText,
4146  int32_t srcStart,
4147  int32_t srcLength,
4148  uint32_t options) const
4149 {
4150  if(srcText.isBogus()) {
4151  return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
4152  } else {
4153  srcText.pinIndices(srcStart, srcLength);
4154  return doCaseCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength, options);
4155  }
4156 }
4157 
4158 inline int8_t
4159 UnicodeString::caseCompare(const UnicodeString &text, uint32_t options) const {
4160  return doCaseCompare(0, length(), text, 0, text.length(), options);
4161 }
4162 
4163 inline int8_t
4164 UnicodeString::caseCompare(int32_t start,
4165  int32_t _length,
4166  const UnicodeString &srcText,
4167  uint32_t options) const {
4168  return doCaseCompare(start, _length, srcText, 0, srcText.length(), options);
4169 }
4170 
4171 inline int8_t
4172 UnicodeString::caseCompare(ConstChar16Ptr srcChars,
4173  int32_t srcLength,
4174  uint32_t options) const {
4175  return doCaseCompare(0, length(), srcChars, 0, srcLength, options);
4176 }
4177 
4178 inline int8_t
4179 UnicodeString::caseCompare(int32_t start,
4180  int32_t _length,
4181  const UnicodeString &srcText,
4182  int32_t srcStart,
4183  int32_t srcLength,
4184  uint32_t options) const {
4185  return doCaseCompare(start, _length, srcText, srcStart, srcLength, options);
4186 }
4187 
4188 inline int8_t
4189 UnicodeString::caseCompare(int32_t start,
4190  int32_t _length,
4191  const char16_t *srcChars,
4192  uint32_t options) const {
4193  return doCaseCompare(start, _length, srcChars, 0, _length, options);
4194 }
4195 
4196 inline int8_t
4197 UnicodeString::caseCompare(int32_t start,
4198  int32_t _length,
4199  const char16_t *srcChars,
4200  int32_t srcStart,
4201  int32_t srcLength,
4202  uint32_t options) const {
4203  return doCaseCompare(start, _length, srcChars, srcStart, srcLength, options);
4204 }
4205 
4206 inline int8_t
4207 UnicodeString::caseCompareBetween(int32_t start,
4208  int32_t limit,
4209  const UnicodeString &srcText,
4210  int32_t srcStart,
4211  int32_t srcLimit,
4212  uint32_t options) const {
4213  return doCaseCompare(start, limit - start, srcText, srcStart, srcLimit - srcStart, options);
4214 }
4215 
4216 inline int32_t
4217 UnicodeString::indexOf(const UnicodeString& srcText,
4218  int32_t srcStart,
4219  int32_t srcLength,
4220  int32_t start,
4221  int32_t _length) const
4222 {
4223  if(!srcText.isBogus()) {
4224  srcText.pinIndices(srcStart, srcLength);
4225  if(srcLength > 0) {
4226  return indexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
4227  }
4228  }
4229  return -1;
4230 }
4231 
4232 inline int32_t
4233 UnicodeString::indexOf(const UnicodeString& text) const
4234 { return indexOf(text, 0, text.length(), 0, length()); }
4235 
4236 inline int32_t
4237 UnicodeString::indexOf(const UnicodeString& text,
4238  int32_t start) const {
4239  pinIndex(start);
4240  return indexOf(text, 0, text.length(), start, length() - start);
4241 }
4242 
4243 inline int32_t
4244 UnicodeString::indexOf(const UnicodeString& text,
4245  int32_t start,
4246  int32_t _length) const
4247 { return indexOf(text, 0, text.length(), start, _length); }
4248 
4249 inline int32_t
4250 UnicodeString::indexOf(const char16_t *srcChars,
4251  int32_t srcLength,
4252  int32_t start) const {
4253  pinIndex(start);
4254  return indexOf(srcChars, 0, srcLength, start, length() - start);
4255 }
4256 
4257 inline int32_t
4258 UnicodeString::indexOf(ConstChar16Ptr srcChars,
4259  int32_t srcLength,
4260  int32_t start,
4261  int32_t _length) const
4262 { return indexOf(srcChars, 0, srcLength, start, _length); }
4263 
4264 inline int32_t
4265 UnicodeString::indexOf(char16_t c,
4266  int32_t start,
4267  int32_t _length) const
4268 { return doIndexOf(c, start, _length); }
4269 
4270 inline int32_t
4271 UnicodeString::indexOf(UChar32 c,
4272  int32_t start,
4273  int32_t _length) const
4274 { return doIndexOf(c, start, _length); }
4275 
4276 inline int32_t
4277 UnicodeString::indexOf(char16_t c) const
4278 { return doIndexOf(c, 0, length()); }
4279 
4280 inline int32_t
4281 UnicodeString::indexOf(UChar32 c) const
4282 { return indexOf(c, 0, length()); }
4283 
4284 inline int32_t
4285 UnicodeString::indexOf(char16_t c,
4286  int32_t start) const {
4287  pinIndex(start);
4288  return doIndexOf(c, start, length() - start);
4289 }
4290 
4291 inline int32_t
4292 UnicodeString::indexOf(UChar32 c,
4293  int32_t start) const {
4294  pinIndex(start);
4295  return indexOf(c, start, length() - start);
4296 }
4297 
4298 inline int32_t
4299 UnicodeString::lastIndexOf(ConstChar16Ptr srcChars,
4300  int32_t srcLength,
4301  int32_t start,
4302  int32_t _length) const
4303 { return lastIndexOf(srcChars, 0, srcLength, start, _length); }
4304 
4305 inline int32_t
4306 UnicodeString::lastIndexOf(const char16_t *srcChars,
4307  int32_t srcLength,
4308  int32_t start) const {
4309  pinIndex(start);
4310  return lastIndexOf(srcChars, 0, srcLength, start, length() - start);
4311 }
4312 
4313 inline int32_t
4314 UnicodeString::lastIndexOf(const UnicodeString& srcText,
4315  int32_t srcStart,
4316  int32_t srcLength,
4317  int32_t start,
4318  int32_t _length) const
4319 {
4320  if(!srcText.isBogus()) {
4321  srcText.pinIndices(srcStart, srcLength);
4322  if(srcLength > 0) {
4323  return lastIndexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
4324  }
4325  }
4326  return -1;
4327 }
4328 
4329 inline int32_t
4330 UnicodeString::lastIndexOf(const UnicodeString& text,
4331  int32_t start,
4332  int32_t _length) const
4333 { return lastIndexOf(text, 0, text.length(), start, _length); }
4334 
4335 inline int32_t
4336 UnicodeString::lastIndexOf(const UnicodeString& text,
4337  int32_t start) const {
4338  pinIndex(start);
4339  return lastIndexOf(text, 0, text.length(), start, length() - start);
4340 }
4341 
4342 inline int32_t
4343 UnicodeString::lastIndexOf(const UnicodeString& text) const
4344 { return lastIndexOf(text, 0, text.length(), 0, length()); }
4345 
4346 inline int32_t
4347 UnicodeString::lastIndexOf(char16_t c,
4348  int32_t start,
4349  int32_t _length) const
4350 { return doLastIndexOf(c, start, _length); }
4351 
4352 inline int32_t
4353 UnicodeString::lastIndexOf(UChar32 c,
4354  int32_t start,
4355  int32_t _length) const {
4356  return doLastIndexOf(c, start, _length);
4357 }
4358 
4359 inline int32_t
4360 UnicodeString::lastIndexOf(char16_t c) const
4361 { return doLastIndexOf(c, 0, length()); }
4362 
4363 inline int32_t
4364 UnicodeString::lastIndexOf(UChar32 c) const {
4365  return lastIndexOf(c, 0, length());
4366 }
4367 
4368 inline int32_t
4369 UnicodeString::lastIndexOf(char16_t c,
4370  int32_t start) const {
4371  pinIndex(start);
4372  return doLastIndexOf(c, start, length() - start);
4373 }
4374 
4375 inline int32_t
4376 UnicodeString::lastIndexOf(UChar32 c,
4377  int32_t start) const {
4378  pinIndex(start);
4379  return lastIndexOf(c, start, length() - start);
4380 }
4381 
4382 inline UBool
4383 UnicodeString::startsWith(const UnicodeString& text) const
4384 { return compare(0, text.length(), text, 0, text.length()) == 0; }
4385 
4386 inline UBool
4387 UnicodeString::startsWith(const UnicodeString& srcText,
4388  int32_t srcStart,
4389  int32_t srcLength) const
4390 { return doCompare(0, srcLength, srcText, srcStart, srcLength) == 0; }
4391 
4392 inline UBool
4393 UnicodeString::startsWith(ConstChar16Ptr srcChars, int32_t srcLength) const {
4394  if(srcLength < 0) {
4395  srcLength = u_strlen(toUCharPtr(srcChars));
4396  }
4397  return doCompare(0, srcLength, srcChars, 0, srcLength) == 0;
4398 }
4399 
4400 inline UBool
4401 UnicodeString::startsWith(const char16_t *srcChars, int32_t srcStart, int32_t srcLength) const {
4402  if(srcLength < 0) {
4403  srcLength = u_strlen(toUCharPtr(srcChars));
4404  }
4405  return doCompare(0, srcLength, srcChars, srcStart, srcLength) == 0;
4406 }
4407 
4408 inline UBool
4409 UnicodeString::endsWith(const UnicodeString& text) const
4410 { return doCompare(length() - text.length(), text.length(),
4411  text, 0, text.length()) == 0; }
4412 
4413 inline UBool
4414 UnicodeString::endsWith(const UnicodeString& srcText,
4415  int32_t srcStart,
4416  int32_t srcLength) const {
4417  srcText.pinIndices(srcStart, srcLength);
4418  return doCompare(length() - srcLength, srcLength,
4419  srcText, srcStart, srcLength) == 0;
4420 }
4421 
4422 inline UBool
4423 UnicodeString::endsWith(ConstChar16Ptr srcChars,
4424  int32_t srcLength) const {
4425  if(srcLength < 0) {
4426  srcLength = u_strlen(toUCharPtr(srcChars));
4427  }
4428  return doCompare(length() - srcLength, srcLength,
4429  srcChars, 0, srcLength) == 0;
4430 }
4431 
4432 inline UBool
4433 UnicodeString::endsWith(const char16_t *srcChars,
4434  int32_t srcStart,
4435  int32_t srcLength) const {
4436  if(srcLength < 0) {
4437  srcLength = u_strlen(toUCharPtr(srcChars + srcStart));
4438  }
4439  return doCompare(length() - srcLength, srcLength,
4440  srcChars, srcStart, srcLength) == 0;
4441 }
4442 
4443 //========================================
4444 // replace
4445 //========================================
4446 inline UnicodeString&
4447 UnicodeString::replace(int32_t start,
4448  int32_t _length,
4449  const UnicodeString& srcText)
4450 { return doReplace(start, _length, srcText, 0, srcText.length()); }
4451 
4452 inline UnicodeString&
4453 UnicodeString::replace(int32_t start,
4454  int32_t _length,
4455  const UnicodeString& srcText,
4456  int32_t srcStart,
4457  int32_t srcLength)
4458 { return doReplace(start, _length, srcText, srcStart, srcLength); }
4459 
4460 inline UnicodeString&
4461 UnicodeString::replace(int32_t start,
4462  int32_t _length,
4463  ConstChar16Ptr srcChars,
4464  int32_t srcLength)
4465 { return doReplace(start, _length, srcChars, 0, srcLength); }
4466 
4467 inline UnicodeString&
4468 UnicodeString::replace(int32_t start,
4469  int32_t _length,
4470  const char16_t *srcChars,
4471  int32_t srcStart,
4472  int32_t srcLength)
4473 { return doReplace(start, _length, srcChars, srcStart, srcLength); }
4474 
4475 inline UnicodeString&
4476 UnicodeString::replace(int32_t start,
4477  int32_t _length,
4478  char16_t srcChar)
4479 { return doReplace(start, _length, &srcChar, 0, 1); }
4480 
4481 inline UnicodeString&
4482 UnicodeString::replaceBetween(int32_t start,
4483  int32_t limit,
4484  const UnicodeString& srcText)
4485 { return doReplace(start, limit - start, srcText, 0, srcText.length()); }
4486 
4487 inline UnicodeString&
4488 UnicodeString::replaceBetween(int32_t start,
4489  int32_t limit,
4490  const UnicodeString& srcText,
4491  int32_t srcStart,
4492  int32_t srcLimit)
4493 { return doReplace(start, limit - start, srcText, srcStart, srcLimit - srcStart); }
4494 
4495 inline UnicodeString&
4496 UnicodeString::findAndReplace(const UnicodeString& oldText,
4497  const UnicodeString& newText)
4498 { return findAndReplace(0, length(), oldText, 0, oldText.length(),
4499  newText, 0, newText.length()); }
4500 
4501 inline UnicodeString&
4502 UnicodeString::findAndReplace(int32_t start,
4503  int32_t _length,
4504  const UnicodeString& oldText,
4505  const UnicodeString& newText)
4506 { return findAndReplace(start, _length, oldText, 0, oldText.length(),
4507  newText, 0, newText.length()); }
4508 
4509 // ============================
4510 // extract
4511 // ============================
4512 inline void
4513 UnicodeString::doExtract(int32_t start,
4514  int32_t _length,
4515  UnicodeString& target) const
4516 { target.replace(0, target.length(), *this, start, _length); }
4517 
4518 inline void
4519 UnicodeString::extract(int32_t start,
4520  int32_t _length,
4521  Char16Ptr target,
4522  int32_t targetStart) const
4523 { doExtract(start, _length, target, targetStart); }
4524 
4525 inline void
4526 UnicodeString::extract(int32_t start,
4527  int32_t _length,
4528  UnicodeString& target) const
4529 { doExtract(start, _length, target); }
4530 
4531 #if !UCONFIG_NO_CONVERSION
4532 
4533 inline int32_t
4534 UnicodeString::extract(int32_t start,
4535  int32_t _length,
4536  char *dst,
4537  const char *codepage) const
4538 
4539 {
4540  // This dstSize value will be checked explicitly
4541  return extract(start, _length, dst, dst!=0 ? 0xffffffff : 0, codepage);
4542 }
4543 
4544 #endif
4545 
4546 inline void
4547 UnicodeString::extractBetween(int32_t start,
4548  int32_t limit,
4549  char16_t *dst,
4550  int32_t dstStart) const {
4551  pinIndex(start);
4552  pinIndex(limit);
4553  doExtract(start, limit - start, dst, dstStart);
4554 }
4555 
4556 inline UnicodeString
4557 UnicodeString::tempSubStringBetween(int32_t start, int32_t limit) const {
4558  return tempSubString(start, limit - start);
4559 }
4560 
4561 inline char16_t
4562 UnicodeString::doCharAt(int32_t offset) const
4563 {
4564  if((uint32_t)offset < (uint32_t)length()) {
4565  return getArrayStart()[offset];
4566  } else {
4567  return kInvalidUChar;
4568  }
4569 }
4570 
4571 inline char16_t
4572 UnicodeString::charAt(int32_t offset) const
4573 { return doCharAt(offset); }
4574 
4575 inline char16_t
4576 UnicodeString::operator[] (int32_t offset) const
4577 { return doCharAt(offset); }
4578 
4579 inline UBool
4580 UnicodeString::isEmpty() const {
4581  // Arithmetic or logical right shift does not matter: only testing for 0.
4582  return (fUnion.fFields.fLengthAndFlags>>kLengthShift) == 0;
4583 }
4584 
4585 //========================================
4586 // Write implementation methods
4587 //========================================
4588 inline void
4589 UnicodeString::setZeroLength() {
4590  fUnion.fFields.fLengthAndFlags &= kAllStorageFlags;
4591 }
4592 
4593 inline void
4594 UnicodeString::setShortLength(int32_t len) {
4595  // requires 0 <= len <= kMaxShortLength
4596  fUnion.fFields.fLengthAndFlags =
4597  (int16_t)((fUnion.fFields.fLengthAndFlags & kAllStorageFlags) | (len << kLengthShift));
4598 }
4599 
4600 inline void
4601 UnicodeString::setLength(int32_t len) {
4602  if(len <= kMaxShortLength) {
4603  setShortLength(len);
4604  } else {
4605  fUnion.fFields.fLengthAndFlags |= kLengthIsLarge;
4606  fUnion.fFields.fLength = len;
4607  }
4608 }
4609 
4610 inline void
4611 UnicodeString::setToEmpty() {
4612  fUnion.fFields.fLengthAndFlags = kShortString;
4613 }
4614 
4615 inline void
4616 UnicodeString::setArray(char16_t *array, int32_t len, int32_t capacity) {
4617  setLength(len);
4618  fUnion.fFields.fArray = array;
4619  fUnion.fFields.fCapacity = capacity;
4620 }
4621 
4622 inline UnicodeString&
4623 UnicodeString::operator= (char16_t ch)
4624 { return doReplace(0, length(), &ch, 0, 1); }
4625 
4626 inline UnicodeString&
4627 UnicodeString::operator= (UChar32 ch)
4628 { return replace(0, length(), ch); }
4629 
4630 inline UnicodeString&
4631 UnicodeString::setTo(const UnicodeString& srcText,
4632  int32_t srcStart,
4633  int32_t srcLength)
4634 {
4635  unBogus();
4636  return doReplace(0, length(), srcText, srcStart, srcLength);
4637 }
4638 
4639 inline UnicodeString&
4640 UnicodeString::setTo(const UnicodeString& srcText,
4641  int32_t srcStart)
4642 {
4643  unBogus();
4644  srcText.pinIndex(srcStart);
4645  return doReplace(0, length(), srcText, srcStart, srcText.length() - srcStart);
4646 }
4647 
4648 inline UnicodeString&
4649 UnicodeString::setTo(const UnicodeString& srcText)
4650 {
4651  return copyFrom(srcText);
4652 }
4653 
4654 inline UnicodeString&
4655 UnicodeString::setTo(const char16_t *srcChars,
4656  int32_t srcLength)
4657 {
4658  unBogus();
4659  return doReplace(0, length(), srcChars, 0, srcLength);
4660 }
4661 
4662 inline UnicodeString&
4663 UnicodeString::setTo(char16_t srcChar)
4664 {
4665  unBogus();
4666  return doReplace(0, length(), &srcChar, 0, 1);
4667 }
4668 
4669 inline UnicodeString&
4670 UnicodeString::setTo(UChar32 srcChar)
4671 {
4672  unBogus();
4673  return replace(0, length(), srcChar);
4674 }
4675 
4676 inline UnicodeString&
4677 UnicodeString::append(const UnicodeString& srcText,
4678  int32_t srcStart,
4679  int32_t srcLength)
4680 { return doAppend(srcText, srcStart, srcLength); }
4681 
4682 inline UnicodeString&
4683 UnicodeString::append(const UnicodeString& srcText)
4684 { return doAppend(srcText, 0, srcText.length()); }
4685 
4686 inline UnicodeString&
4687 UnicodeString::append(const char16_t *srcChars,
4688  int32_t srcStart,
4689  int32_t srcLength)
4690 { return doAppend(srcChars, srcStart, srcLength); }
4691 
4692 inline UnicodeString&
4693 UnicodeString::append(ConstChar16Ptr srcChars,
4694  int32_t srcLength)
4695 { return doAppend(srcChars, 0, srcLength); }
4696 
4697 inline UnicodeString&
4698 UnicodeString::append(char16_t srcChar)
4699 { return doAppend(&srcChar, 0, 1); }
4700 
4701 inline UnicodeString&
4702 UnicodeString::operator+= (char16_t ch)
4703 { return doAppend(&ch, 0, 1); }
4704 
4705 inline UnicodeString&
4706 UnicodeString::operator+= (UChar32 ch) {
4707  return append(ch);
4708 }
4709 
4710 inline UnicodeString&
4711 UnicodeString::operator+= (const UnicodeString& srcText)
4712 { return doAppend(srcText, 0, srcText.length()); }
4713 
4714 inline UnicodeString&
4715 UnicodeString::insert(int32_t start,
4716  const UnicodeString& srcText,
4717  int32_t srcStart,
4718  int32_t srcLength)
4719 { return doReplace(start, 0, srcText, srcStart, srcLength); }
4720 
4721 inline UnicodeString&
4722 UnicodeString::insert(int32_t start,
4723  const UnicodeString& srcText)
4724 { return doReplace(start, 0, srcText, 0, srcText.length()); }
4725 
4726 inline UnicodeString&
4727 UnicodeString::insert(int32_t start,
4728  const char16_t *srcChars,
4729  int32_t srcStart,
4730  int32_t srcLength)
4731 { return doReplace(start, 0, srcChars, srcStart, srcLength); }
4732 
4733 inline UnicodeString&
4734 UnicodeString::insert(int32_t start,
4735  ConstChar16Ptr srcChars,
4736  int32_t srcLength)
4737 { return doReplace(start, 0, srcChars, 0, srcLength); }
4738 
4739 inline UnicodeString&
4740 UnicodeString::insert(int32_t start,
4741  char16_t srcChar)
4742 { return doReplace(start, 0, &srcChar, 0, 1); }
4743 
4744 inline UnicodeString&
4745 UnicodeString::insert(int32_t start,
4746  UChar32 srcChar)
4747 { return replace(start, 0, srcChar); }
4748 
4749 
4750 inline UnicodeString&
4751 UnicodeString::remove()
4752 {
4753  // remove() of a bogus string makes the string empty and non-bogus
4754  if(isBogus()) {
4755  setToEmpty();
4756  } else {
4757  setZeroLength();
4758  }
4759  return *this;
4760 }
4761 
4762 inline UnicodeString&
4763 UnicodeString::remove(int32_t start,
4764  int32_t _length)
4765 {
4766  if(start <= 0 && _length == INT32_MAX) {
4767  // remove(guaranteed everything) of a bogus string makes the string empty and non-bogus
4768  return remove();
4769  }
4770  return doReplace(start, _length, NULL, 0, 0);
4771 }
4772 
4773 inline UnicodeString&
4774 UnicodeString::removeBetween(int32_t start,
4775  int32_t limit)
4776 { return doReplace(start, limit - start, NULL, 0, 0); }
4777 
4778 inline UnicodeString &
4779 UnicodeString::retainBetween(int32_t start, int32_t limit) {
4780  truncate(limit);
4781  return doReplace(0, start, NULL, 0, 0);
4782 }
4783 
4784 inline UBool
4785 UnicodeString::truncate(int32_t targetLength)
4786 {
4787  if(isBogus() && targetLength == 0) {
4788  // truncate(0) of a bogus string makes the string empty and non-bogus
4789  unBogus();
4790  return FALSE;
4791  } else if((uint32_t)targetLength < (uint32_t)length()) {
4792  setLength(targetLength);
4793  return TRUE;
4794  } else {
4795  return FALSE;
4796  }
4797 }
4798 
4799 inline UnicodeString&
4800 UnicodeString::reverse()
4801 { return doReverse(0, length()); }
4802 
4803 inline UnicodeString&
4804 UnicodeString::reverse(int32_t start,
4805  int32_t _length)
4806 { return doReverse(start, _length); }
4807 
4809 
4810 #endif
#define UNISTR_OBJECT_SIZE
Desired sizeof(UnicodeString) in bytes.
Definition: unistr.h:204
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:298
UnicodeString(wchar_t *buffer, int32_t buffLength, int32_t buffCapacity)
Writable-aliasing wchar_t * constructor.
Definition: unistr.h:3187
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:864
UNISTR_FROM_STRING_EXPLICIT UnicodeString(const uint16_t *text)
uint16_t * constructor.
Definition: unistr.h:3014
UNISTR_FROM_STRING_EXPLICIT UnicodeString(const wchar_t *text)
wchar_t * constructor.
Definition: unistr.h:3034
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:3093
#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:3076
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
friend U_COMMON_API void swap(UnicodeString &s1, UnicodeString &s2)
Non-member UnicodeString swap function.
Definition: unistr.h:1934
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:66
#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:3960
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:146
#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:1722
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
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:3169
#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:3945
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.
UnicodeString & operator=(UnicodeString &&src)
Move assignment operator, might leave src in bogus state.
Definition: unistr.h:1903
Implementation of ByteSink that writes to a "string".
Definition: bytestream.h:232
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:286
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:166
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:4453
#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.