ICU 60.0.1  60.0.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);
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 
1903  return moveFrom(src);
1904  }
1905 
1906  // do not use #ifndef U_HIDE_DRAFT_API for moveFrom, needed by non-draft API
1917  UnicodeString &moveFrom(UnicodeString &src) U_NOEXCEPT;
1918 
1924  void swap(UnicodeString &other) U_NOEXCEPT;
1925 
1932  friend U_COMMON_API inline void U_EXPORT2
1933  swap(UnicodeString &s1, UnicodeString &s2) U_NOEXCEPT {
1934  s1.swap(s2);
1935  }
1936 
1944  inline UnicodeString& operator= (char16_t ch);
1945 
1953  inline UnicodeString& operator= (UChar32 ch);
1954 
1966  inline UnicodeString& setTo(const UnicodeString& srcText,
1967  int32_t srcStart);
1968 
1982  inline UnicodeString& setTo(const UnicodeString& srcText,
1983  int32_t srcStart,
1984  int32_t srcLength);
1985 
1994  inline UnicodeString& setTo(const UnicodeString& srcText);
1995 
2004  inline UnicodeString& setTo(const char16_t *srcChars,
2005  int32_t srcLength);
2006 
2015  UnicodeString& setTo(char16_t srcChar);
2016 
2025  UnicodeString& setTo(UChar32 srcChar);
2026 
2050  UnicodeString &setTo(UBool isTerminated,
2051  ConstChar16Ptr text,
2052  int32_t textLength);
2053 
2073  UnicodeString &setTo(char16_t *buffer,
2074  int32_t buffLength,
2075  int32_t buffCapacity);
2076 
2117  void setToBogus();
2118 
2126  UnicodeString& setCharAt(int32_t offset,
2127  char16_t ch);
2128 
2129 
2130  /* Append operations */
2131 
2139  inline UnicodeString& operator+= (char16_t ch);
2140 
2148  inline UnicodeString& operator+= (UChar32 ch);
2149 
2157  inline UnicodeString& operator+= (const UnicodeString& srcText);
2158 
2173  inline UnicodeString& append(const UnicodeString& srcText,
2174  int32_t srcStart,
2175  int32_t srcLength);
2176 
2184  inline UnicodeString& append(const UnicodeString& srcText);
2185 
2199  inline UnicodeString& append(const char16_t *srcChars,
2200  int32_t srcStart,
2201  int32_t srcLength);
2202 
2212  inline UnicodeString& append(ConstChar16Ptr srcChars,
2213  int32_t srcLength);
2214 
2221  inline UnicodeString& append(char16_t srcChar);
2222 
2229  UnicodeString& append(UChar32 srcChar);
2230 
2231 
2232  /* Insert operations */
2233 
2247  inline UnicodeString& insert(int32_t start,
2248  const UnicodeString& srcText,
2249  int32_t srcStart,
2250  int32_t srcLength);
2251 
2260  inline UnicodeString& insert(int32_t start,
2261  const UnicodeString& srcText);
2262 
2276  inline UnicodeString& insert(int32_t start,
2277  const char16_t *srcChars,
2278  int32_t srcStart,
2279  int32_t srcLength);
2280 
2290  inline UnicodeString& insert(int32_t start,
2291  ConstChar16Ptr srcChars,
2292  int32_t srcLength);
2293 
2302  inline UnicodeString& insert(int32_t start,
2303  char16_t srcChar);
2304 
2313  inline UnicodeString& insert(int32_t start,
2314  UChar32 srcChar);
2315 
2316 
2317  /* Replace operations */
2318 
2336  UnicodeString& replace(int32_t start,
2337  int32_t length,
2338  const UnicodeString& srcText,
2339  int32_t srcStart,
2340  int32_t srcLength);
2341 
2354  UnicodeString& replace(int32_t start,
2355  int32_t length,
2356  const UnicodeString& srcText);
2357 
2375  UnicodeString& replace(int32_t start,
2376  int32_t length,
2377  const char16_t *srcChars,
2378  int32_t srcStart,
2379  int32_t srcLength);
2380 
2393  inline UnicodeString& replace(int32_t start,
2394  int32_t length,
2395  ConstChar16Ptr srcChars,
2396  int32_t srcLength);
2397 
2409  inline UnicodeString& replace(int32_t start,
2410  int32_t length,
2411  char16_t srcChar);
2412 
2424  UnicodeString& replace(int32_t start, int32_t length, UChar32 srcChar);
2425 
2435  inline UnicodeString& replaceBetween(int32_t start,
2436  int32_t limit,
2437  const UnicodeString& srcText);
2438 
2453  inline UnicodeString& replaceBetween(int32_t start,
2454  int32_t limit,
2455  const UnicodeString& srcText,
2456  int32_t srcStart,
2457  int32_t srcLimit);
2458 
2469  virtual void handleReplaceBetween(int32_t start,
2470  int32_t limit,
2471  const UnicodeString& text);
2472 
2478  virtual UBool hasMetaData() const;
2479 
2495  virtual void copy(int32_t start, int32_t limit, int32_t dest);
2496 
2497  /* Search and replace operations */
2498 
2507  inline UnicodeString& findAndReplace(const UnicodeString& oldText,
2508  const UnicodeString& newText);
2509 
2521  inline UnicodeString& findAndReplace(int32_t start,
2522  int32_t length,
2523  const UnicodeString& oldText,
2524  const UnicodeString& newText);
2525 
2543  UnicodeString& findAndReplace(int32_t start,
2544  int32_t length,
2545  const UnicodeString& oldText,
2546  int32_t oldStart,
2547  int32_t oldLength,
2548  const UnicodeString& newText,
2549  int32_t newStart,
2550  int32_t newLength);
2551 
2552 
2553  /* Remove operations */
2554 
2560  inline UnicodeString& remove(void);
2561 
2570  inline UnicodeString& remove(int32_t start,
2571  int32_t length = (int32_t)INT32_MAX);
2572 
2581  inline UnicodeString& removeBetween(int32_t start,
2582  int32_t limit = (int32_t)INT32_MAX);
2583 
2593  inline UnicodeString &retainBetween(int32_t start, int32_t limit = INT32_MAX);
2594 
2595  /* Length operations */
2596 
2608  UBool padLeading(int32_t targetLength,
2609  char16_t padChar = 0x0020);
2610 
2622  UBool padTrailing(int32_t targetLength,
2623  char16_t padChar = 0x0020);
2624 
2631  inline UBool truncate(int32_t targetLength);
2632 
2638  UnicodeString& trim(void);
2639 
2640 
2641  /* Miscellaneous operations */
2642 
2648  inline UnicodeString& reverse(void);
2649 
2658  inline UnicodeString& reverse(int32_t start,
2659  int32_t length);
2660 
2667  UnicodeString& toUpper(void);
2668 
2676  UnicodeString& toUpper(const Locale& locale);
2677 
2684  UnicodeString& toLower(void);
2685 
2693  UnicodeString& toLower(const Locale& locale);
2694 
2695 #if !UCONFIG_NO_BREAK_ITERATION
2696 
2723  UnicodeString &toTitle(BreakIterator *titleIter);
2724 
2752  UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale);
2753 
2785  UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale, uint32_t options);
2786 
2787 #endif
2788 
2802  UnicodeString &foldCase(uint32_t options=0 /*U_FOLD_CASE_DEFAULT*/);
2803 
2804  //========================================
2805  // Access to the internal buffer
2806  //========================================
2807 
2851  char16_t *getBuffer(int32_t minCapacity);
2852 
2873  void releaseBuffer(int32_t newLength=-1);
2874 
2905  inline const char16_t *getBuffer() const;
2906 
2940  const char16_t *getTerminatedBuffer();
2941 
2942  //========================================
2943  // Constructors
2944  //========================================
2945 
2949  inline UnicodeString();
2950 
2962  UnicodeString(int32_t capacity, UChar32 c, int32_t count);
2963 
2973  UNISTR_FROM_CHAR_EXPLICIT UnicodeString(char16_t ch);
2974 
2984  UNISTR_FROM_CHAR_EXPLICIT UnicodeString(UChar32 ch);
2985 
2996  UNISTR_FROM_STRING_EXPLICIT UnicodeString(const char16_t *text);
2997 
2998  /*
2999  * Do not use #ifndef U_HIDE_DRAFT_API for the following constructor,
3000  * it should always be available regardless of U_HIDE_DRAFT_API status
3001  */
3002 #if !U_CHAR16_IS_TYPEDEF
3003 
3014  UnicodeString(ConstChar16Ptr(text)) {}
3015 #endif
3016 
3017  /*
3018  * Do not use #ifndef U_HIDE_DRAFT_API for the following constructor,
3019  * it should always be available regardless of U_HIDE_DRAFT_API status
3020  */
3021 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
3022 
3034  UnicodeString(ConstChar16Ptr(text)) {}
3035 #endif
3036 
3037  /*
3038  * Do not use #ifndef U_HIDE_DRAFT_API for the following constructor,
3039  * it should always be available regardless of U_HIDE_DRAFT_API status
3040  */
3051  UNISTR_FROM_STRING_EXPLICIT inline UnicodeString(const std::nullptr_t text);
3052 
3060  UnicodeString(const char16_t *text,
3061  int32_t textLength);
3062 
3063  /*
3064  * Do not use #ifndef U_HIDE_DRAFT_API for the following constructor,
3065  * it should always be available regardless of U_HIDE_DRAFT_API status
3066  */
3067 #if !U_CHAR16_IS_TYPEDEF
3068 
3075  UnicodeString(const uint16_t *text, int32_t length) :
3076  UnicodeString(ConstChar16Ptr(text), length) {}
3077 #endif
3078 
3079  /*
3080  * Do not use #ifndef U_HIDE_DRAFT_API for the following constructor,
3081  * it should always be available regardless of U_HIDE_DRAFT_API status
3082  */
3083 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
3084 
3092  UnicodeString(const wchar_t *text, int32_t length) :
3093  UnicodeString(ConstChar16Ptr(text), length) {}
3094 #endif
3095 
3096  /*
3097  * Do not use #ifndef U_HIDE_DRAFT_API for the following constructor,
3098  * it should always be available regardless of U_HIDE_DRAFT_API status
3099  */
3107  inline UnicodeString(const std::nullptr_t text, int32_t length);
3108 
3131  UnicodeString(UBool isTerminated,
3132  ConstChar16Ptr text,
3133  int32_t textLength);
3134 
3153  UnicodeString(char16_t *buffer, int32_t buffLength, int32_t buffCapacity);
3154 
3155  /*
3156  * Do not use #ifndef U_HIDE_DRAFT_API for the following constructor,
3157  * it should always be available regardless of U_HIDE_DRAFT_API status
3158  */
3159 #if !U_CHAR16_IS_TYPEDEF
3160 
3168  UnicodeString(uint16_t *buffer, int32_t buffLength, int32_t buffCapacity) :
3169  UnicodeString(Char16Ptr(buffer), buffLength, buffCapacity) {}
3170 #endif
3171 
3172  /*
3173  * Do not use #ifndef U_HIDE_DRAFT_API for the following constructor,
3174  * it should always be available regardless of U_HIDE_DRAFT_API status
3175  */
3176 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
3177 
3186  UnicodeString(wchar_t *buffer, int32_t buffLength, int32_t buffCapacity) :
3187  UnicodeString(Char16Ptr(buffer), buffLength, buffCapacity) {}
3188 #endif
3189 
3190  /*
3191  * Do not use #ifndef U_HIDE_DRAFT_API for the following constructor,
3192  * it should always be available regardless of U_HIDE_DRAFT_API status
3193  */
3202  inline UnicodeString(std::nullptr_t buffer, int32_t buffLength, int32_t buffCapacity);
3203 
3204 #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
3205 
3225  UNISTR_FROM_STRING_EXPLICIT UnicodeString(const char *codepageData);
3226 
3235  UnicodeString(const char *codepageData, int32_t dataLength);
3236 
3237 #endif
3238 
3239 #if !UCONFIG_NO_CONVERSION
3240 
3258  UnicodeString(const char *codepageData, const char *codepage);
3259 
3277  UnicodeString(const char *codepageData, int32_t dataLength, const char *codepage);
3278 
3300  UnicodeString(
3301  const char *src, int32_t srcLength,
3302  UConverter *cnv,
3303  UErrorCode &errorCode);
3304 
3305 #endif
3306 
3331  UnicodeString(const char *src, int32_t length, enum EInvariant inv);
3332 
3333 
3350  UnicodeString(const UnicodeString& that);
3351 
3358  UnicodeString(UnicodeString &&src) U_NOEXCEPT;
3359 
3366  UnicodeString(const UnicodeString& src, int32_t srcStart);
3367 
3375  UnicodeString(const UnicodeString& src, int32_t srcStart, int32_t srcLength);
3376 
3393  virtual Replaceable *clone() const;
3394 
3398  virtual ~UnicodeString();
3399 
3413  static UnicodeString fromUTF8(StringPiece utf8);
3414 
3426  static UnicodeString fromUTF32(const UChar32 *utf32, int32_t length);
3427 
3428  /* Miscellaneous operations */
3429 
3464  UnicodeString unescape() const;
3465 
3485  UChar32 unescapeAt(int32_t &offset) const;
3486 
3492  static UClassID U_EXPORT2 getStaticClassID();
3493 
3499  virtual UClassID getDynamicClassID() const;
3500 
3501  //========================================
3502  // Implementation methods
3503  //========================================
3504 
3505 protected:
3510  virtual int32_t getLength() const;
3511 
3517  virtual char16_t getCharAt(int32_t offset) const;
3518 
3524  virtual UChar32 getChar32At(int32_t offset) const;
3525 
3526 private:
3527  // For char* constructors. Could be made public.
3528  UnicodeString &setToUTF8(StringPiece utf8);
3529  // For extract(char*).
3530  // We could make a toUTF8(target, capacity, errorCode) public but not
3531  // this version: New API will be cleaner if we make callers create substrings
3532  // rather than having start+length on every method,
3533  // and it should take a UErrorCode&.
3534  int32_t
3535  toUTF8(int32_t start, int32_t len,
3536  char *target, int32_t capacity) const;
3537 
3542  UBool doEquals(const UnicodeString &text, int32_t len) const;
3543 
3544  inline int8_t
3545  doCompare(int32_t start,
3546  int32_t length,
3547  const UnicodeString& srcText,
3548  int32_t srcStart,
3549  int32_t srcLength) const;
3550 
3551  int8_t doCompare(int32_t start,
3552  int32_t length,
3553  const char16_t *srcChars,
3554  int32_t srcStart,
3555  int32_t srcLength) const;
3556 
3557  inline int8_t
3558  doCompareCodePointOrder(int32_t start,
3559  int32_t length,
3560  const UnicodeString& srcText,
3561  int32_t srcStart,
3562  int32_t srcLength) const;
3563 
3564  int8_t doCompareCodePointOrder(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  doCaseCompare(int32_t start,
3572  int32_t length,
3573  const UnicodeString &srcText,
3574  int32_t srcStart,
3575  int32_t srcLength,
3576  uint32_t options) const;
3577 
3578  int8_t
3579  doCaseCompare(int32_t start,
3580  int32_t length,
3581  const char16_t *srcChars,
3582  int32_t srcStart,
3583  int32_t srcLength,
3584  uint32_t options) const;
3585 
3586  int32_t doIndexOf(char16_t c,
3587  int32_t start,
3588  int32_t length) const;
3589 
3590  int32_t doIndexOf(UChar32 c,
3591  int32_t start,
3592  int32_t length) const;
3593 
3594  int32_t doLastIndexOf(char16_t c,
3595  int32_t start,
3596  int32_t length) const;
3597 
3598  int32_t doLastIndexOf(UChar32 c,
3599  int32_t start,
3600  int32_t length) const;
3601 
3602  void doExtract(int32_t start,
3603  int32_t length,
3604  char16_t *dst,
3605  int32_t dstStart) const;
3606 
3607  inline void doExtract(int32_t start,
3608  int32_t length,
3609  UnicodeString& target) const;
3610 
3611  inline char16_t doCharAt(int32_t offset) const;
3612 
3613  UnicodeString& doReplace(int32_t start,
3614  int32_t length,
3615  const UnicodeString& srcText,
3616  int32_t srcStart,
3617  int32_t srcLength);
3618 
3619  UnicodeString& doReplace(int32_t start,
3620  int32_t length,
3621  const char16_t *srcChars,
3622  int32_t srcStart,
3623  int32_t srcLength);
3624 
3625  UnicodeString& doAppend(const UnicodeString& src, int32_t srcStart, int32_t srcLength);
3626  UnicodeString& doAppend(const char16_t *srcChars, int32_t srcStart, int32_t srcLength);
3627 
3628  UnicodeString& doReverse(int32_t start,
3629  int32_t length);
3630 
3631  // calculate hash code
3632  int32_t doHashCode(void) const;
3633 
3634  // get pointer to start of array
3635  // these do not check for kOpenGetBuffer, unlike the public getBuffer() function
3636  inline char16_t* getArrayStart(void);
3637  inline const char16_t* getArrayStart(void) const;
3638 
3639  inline UBool hasShortLength() const;
3640  inline int32_t getShortLength() const;
3641 
3642  // A UnicodeString object (not necessarily its current buffer)
3643  // is writable unless it isBogus() or it has an "open" getBuffer(minCapacity).
3644  inline UBool isWritable() const;
3645 
3646  // Is the current buffer writable?
3647  inline UBool isBufferWritable() const;
3648 
3649  // None of the following does releaseArray().
3650  inline void setZeroLength();
3651  inline void setShortLength(int32_t len);
3652  inline void setLength(int32_t len);
3653  inline void setToEmpty();
3654  inline void setArray(char16_t *array, int32_t len, int32_t capacity); // sets length but not flags
3655 
3656  // allocate the array; result may be the stack buffer
3657  // sets refCount to 1 if appropriate
3658  // sets fArray, fCapacity, and flags
3659  // sets length to 0
3660  // returns boolean for success or failure
3661  UBool allocate(int32_t capacity);
3662 
3663  // release the array if owned
3664  void releaseArray(void);
3665 
3666  // turn a bogus string into an empty one
3667  void unBogus();
3668 
3669  // implements assigment operator, copy constructor, and fastCopyFrom()
3670  UnicodeString &copyFrom(const UnicodeString &src, UBool fastCopy=FALSE);
3671 
3672  // Copies just the fields without memory management.
3673  void copyFieldsFrom(UnicodeString &src, UBool setSrcToBogus) U_NOEXCEPT;
3674 
3675  // Pin start and limit to acceptable values.
3676  inline void pinIndex(int32_t& start) const;
3677  inline void pinIndices(int32_t& start,
3678  int32_t& length) const;
3679 
3680 #if !UCONFIG_NO_CONVERSION
3681 
3682  /* Internal extract() using UConverter. */
3683  int32_t doExtract(int32_t start, int32_t length,
3684  char *dest, int32_t destCapacity,
3685  UConverter *cnv,
3686  UErrorCode &errorCode) const;
3687 
3688  /*
3689  * Real constructor for converting from codepage data.
3690  * It assumes that it is called with !fRefCounted.
3691  *
3692  * If <code>codepage==0</code>, then the default converter
3693  * is used for the platform encoding.
3694  * If <code>codepage</code> is an empty string (<code>""</code>),
3695  * then a simple conversion is performed on the codepage-invariant
3696  * subset ("invariant characters") of the platform encoding. See utypes.h.
3697  */
3698  void doCodepageCreate(const char *codepageData,
3699  int32_t dataLength,
3700  const char *codepage);
3701 
3702  /*
3703  * Worker function for creating a UnicodeString from
3704  * a codepage string using a UConverter.
3705  */
3706  void
3707  doCodepageCreate(const char *codepageData,
3708  int32_t dataLength,
3709  UConverter *converter,
3710  UErrorCode &status);
3711 
3712 #endif
3713 
3714  /*
3715  * This function is called when write access to the array
3716  * is necessary.
3717  *
3718  * We need to make a copy of the array if
3719  * the buffer is read-only, or
3720  * the buffer is refCounted (shared), and refCount>1, or
3721  * the buffer is too small.
3722  *
3723  * Return FALSE if memory could not be allocated.
3724  */
3725  UBool cloneArrayIfNeeded(int32_t newCapacity = -1,
3726  int32_t growCapacity = -1,
3727  UBool doCopyArray = TRUE,
3728  int32_t **pBufferToDelete = 0,
3729  UBool forceClone = FALSE);
3730 
3736  UnicodeString &
3737  caseMap(int32_t caseLocale, uint32_t options,
3739  BreakIterator *iter,
3740 #endif
3741  UStringCaseMapper *stringCaseMapper);
3742 
3743  // ref counting
3744  void addRef(void);
3745  int32_t removeRef(void);
3746  int32_t refCount(void) const;
3747 
3748  // constants
3749  enum {
3755  US_STACKBUF_SIZE=(int32_t)(UNISTR_OBJECT_SIZE-sizeof(void *)-2)/U_SIZEOF_UCHAR,
3756  kInvalidUChar=0xffff, // U+FFFF returned by charAt(invalid index)
3757  kInvalidHashCode=0, // invalid hash code
3758  kEmptyHashCode=1, // hash code for empty string
3759 
3760  // bit flag values for fLengthAndFlags
3761  kIsBogus=1, // this string is bogus, i.e., not valid or NULL
3762  kUsingStackBuffer=2,// using fUnion.fStackFields instead of fUnion.fFields
3763  kRefCounted=4, // there is a refCount field before the characters in fArray
3764  kBufferIsReadonly=8,// do not write to this buffer
3765  kOpenGetBuffer=16, // getBuffer(minCapacity) was called (is "open"),
3766  // and releaseBuffer(newLength) must be called
3767  kAllStorageFlags=0x1f,
3768 
3769  kLengthShift=5, // remaining 11 bits for non-negative short length, or negative if long
3770  kLength1=1<<kLengthShift,
3771  kMaxShortLength=0x3ff, // max non-negative short length (leaves top bit 0)
3772  kLengthIsLarge=0xffe0, // short length < 0, real length is in fUnion.fFields.fLength
3773 
3774  // combined values for convenience
3775  kShortString=kUsingStackBuffer,
3776  kLongString=kRefCounted,
3777  kReadonlyAlias=kBufferIsReadonly,
3778  kWritableAlias=0
3779  };
3780 
3781  friend class UnicodeStringAppendable;
3782 
3783  union StackBufferOrFields; // forward declaration necessary before friend declaration
3784  friend union StackBufferOrFields; // make US_STACKBUF_SIZE visible inside fUnion
3785 
3786  /*
3787  * The following are all the class fields that are stored
3788  * in each UnicodeString object.
3789  * Note that UnicodeString has virtual functions,
3790  * therefore there is an implicit vtable pointer
3791  * as the first real field.
3792  * The fields should be aligned such that no padding is necessary.
3793  * On 32-bit machines, the size should be 32 bytes,
3794  * on 64-bit machines (8-byte pointers), it should be 40 bytes.
3795  *
3796  * We use a hack to achieve this.
3797  *
3798  * With at least some compilers, each of the following is forced to
3799  * a multiple of sizeof(pointer) [the largest field base unit here is a data pointer],
3800  * rounded up with additional padding if the fields do not already fit that requirement:
3801  * - sizeof(class UnicodeString)
3802  * - offsetof(UnicodeString, fUnion)
3803  * - sizeof(fUnion)
3804  * - sizeof(fStackFields)
3805  *
3806  * We optimize for the longest possible internal buffer for short strings.
3807  * fUnion.fStackFields begins with 2 bytes for storage flags
3808  * and the length of relatively short strings,
3809  * followed by the buffer for short string contents.
3810  * There is no padding inside fStackFields.
3811  *
3812  * Heap-allocated and aliased strings use fUnion.fFields.
3813  * Both fStackFields and fFields must begin with the same fields for flags and short length,
3814  * that is, those must have the same memory offsets inside the object,
3815  * because the flags must be inspected in order to decide which half of fUnion is being used.
3816  * We assume that the compiler does not reorder the fields.
3817  *
3818  * (Padding at the end of fFields is ok:
3819  * As long as it is no larger than fStackFields, it is not wasted space.)
3820  *
3821  * For some of the history of the UnicodeString class fields layout, see
3822  * - ICU ticket #11551 "longer UnicodeString contents in stack buffer"
3823  * - ICU ticket #11336 "UnicodeString: recombine stack buffer arrays"
3824  * - ICU ticket #8322 "why is sizeof(UnicodeString)==48?"
3825  */
3826  // (implicit) *vtable;
3827  union StackBufferOrFields {
3828  // fStackFields is used iff (fLengthAndFlags&kUsingStackBuffer) else fFields is used.
3829  // Each struct of the union must begin with fLengthAndFlags.
3830  struct {
3831  int16_t fLengthAndFlags; // bit fields: see constants above
3832  char16_t fBuffer[US_STACKBUF_SIZE]; // buffer for short strings
3833  } fStackFields;
3834  struct {
3835  int16_t fLengthAndFlags; // bit fields: see constants above
3836  int32_t fLength; // number of characters in fArray if >127; else undefined
3837  int32_t fCapacity; // capacity of fArray (in char16_ts)
3838  // array pointer last to minimize padding for machines with P128 data model
3839  // or pointer sizes that are not a power of 2
3840  char16_t *fArray; // the Unicode data
3841  } fFields;
3842  } fUnion;
3843 };
3844 
3853 U_COMMON_API UnicodeString U_EXPORT2
3854 operator+ (const UnicodeString &s1, const UnicodeString &s2);
3855 
3856 //========================================
3857 // Inline members
3858 //========================================
3859 
3860 //========================================
3861 // Privates
3862 //========================================
3863 
3864 inline void
3865 UnicodeString::pinIndex(int32_t& start) const
3866 {
3867  // pin index
3868  if(start < 0) {
3869  start = 0;
3870  } else if(start > length()) {
3871  start = length();
3872  }
3873 }
3874 
3875 inline void
3876 UnicodeString::pinIndices(int32_t& start,
3877  int32_t& _length) const
3878 {
3879  // pin indices
3880  int32_t len = length();
3881  if(start < 0) {
3882  start = 0;
3883  } else if(start > len) {
3884  start = len;
3885  }
3886  if(_length < 0) {
3887  _length = 0;
3888  } else if(_length > (len - start)) {
3889  _length = (len - start);
3890  }
3891 }
3892 
3893 inline char16_t*
3894 UnicodeString::getArrayStart() {
3895  return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3896  fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
3897 }
3898 
3899 inline const char16_t*
3900 UnicodeString::getArrayStart() const {
3901  return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3902  fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
3903 }
3904 
3905 //========================================
3906 // Default constructor
3907 //========================================
3908 
3909 inline
3910 UnicodeString::UnicodeString() {
3911  fUnion.fStackFields.fLengthAndFlags=kShortString;
3912 }
3913 
3914 inline UnicodeString::UnicodeString(const std::nullptr_t /*text*/) {
3915  fUnion.fStackFields.fLengthAndFlags=kShortString;
3916 }
3917 
3918 inline UnicodeString::UnicodeString(const std::nullptr_t /*text*/, int32_t /*length*/) {
3919  fUnion.fStackFields.fLengthAndFlags=kShortString;
3920 }
3921 
3922 inline UnicodeString::UnicodeString(std::nullptr_t /*buffer*/, int32_t /*buffLength*/, int32_t /*buffCapacity*/) {
3923  fUnion.fStackFields.fLengthAndFlags=kShortString;
3924 }
3925 
3926 //========================================
3927 // Read-only implementation methods
3928 //========================================
3929 inline UBool
3930 UnicodeString::hasShortLength() const {
3931  return fUnion.fFields.fLengthAndFlags>=0;
3932 }
3933 
3934 inline int32_t
3935 UnicodeString::getShortLength() const {
3936  // fLengthAndFlags must be non-negative -> short length >= 0
3937  // and arithmetic or logical shift does not matter.
3938  return fUnion.fFields.fLengthAndFlags>>kLengthShift;
3939 }
3940 
3941 inline int32_t
3942 UnicodeString::length() const {
3943  return hasShortLength() ? getShortLength() : fUnion.fFields.fLength;
3944 }
3945 
3946 inline int32_t
3947 UnicodeString::getCapacity() const {
3948  return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3949  US_STACKBUF_SIZE : fUnion.fFields.fCapacity;
3950 }
3951 
3952 inline int32_t
3953 UnicodeString::hashCode() const
3954 { return doHashCode(); }
3955 
3956 inline UBool
3957 UnicodeString::isBogus() const
3958 { return (UBool)(fUnion.fFields.fLengthAndFlags & kIsBogus); }
3959 
3960 inline UBool
3961 UnicodeString::isWritable() const
3962 { return (UBool)!(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus)); }
3963 
3964 inline UBool
3965 UnicodeString::isBufferWritable() const
3966 {
3967  return (UBool)(
3968  !(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus|kBufferIsReadonly)) &&
3969  (!(fUnion.fFields.fLengthAndFlags&kRefCounted) || refCount()==1));
3970 }
3971 
3972 inline const char16_t *
3973 UnicodeString::getBuffer() const {
3974  if(fUnion.fFields.fLengthAndFlags&(kIsBogus|kOpenGetBuffer)) {
3975  return nullptr;
3976  } else if(fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) {
3977  return fUnion.fStackFields.fBuffer;
3978  } else {
3979  return fUnion.fFields.fArray;
3980  }
3981 }
3982 
3983 //========================================
3984 // Read-only alias methods
3985 //========================================
3986 inline int8_t
3987 UnicodeString::doCompare(int32_t start,
3988  int32_t thisLength,
3989  const UnicodeString& srcText,
3990  int32_t srcStart,
3991  int32_t srcLength) const
3992 {
3993  if(srcText.isBogus()) {
3994  return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
3995  } else {
3996  srcText.pinIndices(srcStart, srcLength);
3997  return doCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
3998  }
3999 }
4000 
4001 inline UBool
4003 {
4004  if(isBogus()) {
4005  return text.isBogus();
4006  } else {
4007  int32_t len = length(), textLength = text.length();
4008  return !text.isBogus() && len == textLength && doEquals(text, len);
4009  }
4010 }
4011 
4012 inline UBool
4014 { return (! operator==(text)); }
4015 
4016 inline UBool
4017 UnicodeString::operator> (const UnicodeString& text) const
4018 { return doCompare(0, length(), text, 0, text.length()) == 1; }
4019 
4020 inline UBool
4021 UnicodeString::operator< (const UnicodeString& text) const
4022 { return doCompare(0, length(), text, 0, text.length()) == -1; }
4023 
4024 inline UBool
4025 UnicodeString::operator>= (const UnicodeString& text) const
4026 { return doCompare(0, length(), text, 0, text.length()) != -1; }
4027 
4028 inline UBool
4029 UnicodeString::operator<= (const UnicodeString& text) const
4030 { return doCompare(0, length(), text, 0, text.length()) != 1; }
4031 
4032 inline int8_t
4033 UnicodeString::compare(const UnicodeString& text) const
4034 { return doCompare(0, length(), text, 0, text.length()); }
4035 
4036 inline int8_t
4037 UnicodeString::compare(int32_t start,
4038  int32_t _length,
4039  const UnicodeString& srcText) const
4040 { return doCompare(start, _length, srcText, 0, srcText.length()); }
4041 
4042 inline int8_t
4043 UnicodeString::compare(ConstChar16Ptr srcChars,
4044  int32_t srcLength) const
4045 { return doCompare(0, length(), srcChars, 0, srcLength); }
4046 
4047 inline int8_t
4048 UnicodeString::compare(int32_t start,
4049  int32_t _length,
4050  const UnicodeString& srcText,
4051  int32_t srcStart,
4052  int32_t srcLength) const
4053 { return doCompare(start, _length, srcText, srcStart, srcLength); }
4054 
4055 inline int8_t
4056 UnicodeString::compare(int32_t start,
4057  int32_t _length,
4058  const char16_t *srcChars) const
4059 { return doCompare(start, _length, srcChars, 0, _length); }
4060 
4061 inline int8_t
4062 UnicodeString::compare(int32_t start,
4063  int32_t _length,
4064  const char16_t *srcChars,
4065  int32_t srcStart,
4066  int32_t srcLength) const
4067 { return doCompare(start, _length, srcChars, srcStart, srcLength); }
4068 
4069 inline int8_t
4070 UnicodeString::compareBetween(int32_t start,
4071  int32_t limit,
4072  const UnicodeString& srcText,
4073  int32_t srcStart,
4074  int32_t srcLimit) const
4075 { return doCompare(start, limit - start,
4076  srcText, srcStart, srcLimit - srcStart); }
4077 
4078 inline int8_t
4079 UnicodeString::doCompareCodePointOrder(int32_t start,
4080  int32_t thisLength,
4081  const UnicodeString& srcText,
4082  int32_t srcStart,
4083  int32_t srcLength) const
4084 {
4085  if(srcText.isBogus()) {
4086  return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
4087  } else {
4088  srcText.pinIndices(srcStart, srcLength);
4089  return doCompareCodePointOrder(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
4090  }
4091 }
4092 
4093 inline int8_t
4094 UnicodeString::compareCodePointOrder(const UnicodeString& text) const
4095 { return doCompareCodePointOrder(0, length(), text, 0, text.length()); }
4096 
4097 inline int8_t
4098 UnicodeString::compareCodePointOrder(int32_t start,
4099  int32_t _length,
4100  const UnicodeString& srcText) const
4101 { return doCompareCodePointOrder(start, _length, srcText, 0, srcText.length()); }
4102 
4103 inline int8_t
4104 UnicodeString::compareCodePointOrder(ConstChar16Ptr srcChars,
4105  int32_t srcLength) const
4106 { return doCompareCodePointOrder(0, length(), srcChars, 0, srcLength); }
4107 
4108 inline int8_t
4109 UnicodeString::compareCodePointOrder(int32_t start,
4110  int32_t _length,
4111  const UnicodeString& srcText,
4112  int32_t srcStart,
4113  int32_t srcLength) const
4114 { return doCompareCodePointOrder(start, _length, srcText, srcStart, srcLength); }
4115 
4116 inline int8_t
4117 UnicodeString::compareCodePointOrder(int32_t start,
4118  int32_t _length,
4119  const char16_t *srcChars) const
4120 { return doCompareCodePointOrder(start, _length, srcChars, 0, _length); }
4121 
4122 inline int8_t
4123 UnicodeString::compareCodePointOrder(int32_t start,
4124  int32_t _length,
4125  const char16_t *srcChars,
4126  int32_t srcStart,
4127  int32_t srcLength) const
4128 { return doCompareCodePointOrder(start, _length, srcChars, srcStart, srcLength); }
4129 
4130 inline int8_t
4131 UnicodeString::compareCodePointOrderBetween(int32_t start,
4132  int32_t limit,
4133  const UnicodeString& srcText,
4134  int32_t srcStart,
4135  int32_t srcLimit) const
4136 { return doCompareCodePointOrder(start, limit - start,
4137  srcText, srcStart, srcLimit - srcStart); }
4138 
4139 inline int8_t
4140 UnicodeString::doCaseCompare(int32_t start,
4141  int32_t thisLength,
4142  const UnicodeString &srcText,
4143  int32_t srcStart,
4144  int32_t srcLength,
4145  uint32_t options) const
4146 {
4147  if(srcText.isBogus()) {
4148  return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
4149  } else {
4150  srcText.pinIndices(srcStart, srcLength);
4151  return doCaseCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength, options);
4152  }
4153 }
4154 
4155 inline int8_t
4156 UnicodeString::caseCompare(const UnicodeString &text, uint32_t options) const {
4157  return doCaseCompare(0, length(), text, 0, text.length(), options);
4158 }
4159 
4160 inline int8_t
4161 UnicodeString::caseCompare(int32_t start,
4162  int32_t _length,
4163  const UnicodeString &srcText,
4164  uint32_t options) const {
4165  return doCaseCompare(start, _length, srcText, 0, srcText.length(), options);
4166 }
4167 
4168 inline int8_t
4169 UnicodeString::caseCompare(ConstChar16Ptr srcChars,
4170  int32_t srcLength,
4171  uint32_t options) const {
4172  return doCaseCompare(0, length(), srcChars, 0, srcLength, options);
4173 }
4174 
4175 inline int8_t
4176 UnicodeString::caseCompare(int32_t start,
4177  int32_t _length,
4178  const UnicodeString &srcText,
4179  int32_t srcStart,
4180  int32_t srcLength,
4181  uint32_t options) const {
4182  return doCaseCompare(start, _length, srcText, srcStart, srcLength, options);
4183 }
4184 
4185 inline int8_t
4186 UnicodeString::caseCompare(int32_t start,
4187  int32_t _length,
4188  const char16_t *srcChars,
4189  uint32_t options) const {
4190  return doCaseCompare(start, _length, srcChars, 0, _length, options);
4191 }
4192 
4193 inline int8_t
4194 UnicodeString::caseCompare(int32_t start,
4195  int32_t _length,
4196  const char16_t *srcChars,
4197  int32_t srcStart,
4198  int32_t srcLength,
4199  uint32_t options) const {
4200  return doCaseCompare(start, _length, srcChars, srcStart, srcLength, options);
4201 }
4202 
4203 inline int8_t
4204 UnicodeString::caseCompareBetween(int32_t start,
4205  int32_t limit,
4206  const UnicodeString &srcText,
4207  int32_t srcStart,
4208  int32_t srcLimit,
4209  uint32_t options) const {
4210  return doCaseCompare(start, limit - start, srcText, srcStart, srcLimit - srcStart, options);
4211 }
4212 
4213 inline int32_t
4214 UnicodeString::indexOf(const UnicodeString& srcText,
4215  int32_t srcStart,
4216  int32_t srcLength,
4217  int32_t start,
4218  int32_t _length) const
4219 {
4220  if(!srcText.isBogus()) {
4221  srcText.pinIndices(srcStart, srcLength);
4222  if(srcLength > 0) {
4223  return indexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
4224  }
4225  }
4226  return -1;
4227 }
4228 
4229 inline int32_t
4230 UnicodeString::indexOf(const UnicodeString& text) const
4231 { return indexOf(text, 0, text.length(), 0, length()); }
4232 
4233 inline int32_t
4234 UnicodeString::indexOf(const UnicodeString& text,
4235  int32_t start) const {
4236  pinIndex(start);
4237  return indexOf(text, 0, text.length(), start, length() - start);
4238 }
4239 
4240 inline int32_t
4241 UnicodeString::indexOf(const UnicodeString& text,
4242  int32_t start,
4243  int32_t _length) const
4244 { return indexOf(text, 0, text.length(), start, _length); }
4245 
4246 inline int32_t
4247 UnicodeString::indexOf(const char16_t *srcChars,
4248  int32_t srcLength,
4249  int32_t start) const {
4250  pinIndex(start);
4251  return indexOf(srcChars, 0, srcLength, start, length() - start);
4252 }
4253 
4254 inline int32_t
4255 UnicodeString::indexOf(ConstChar16Ptr srcChars,
4256  int32_t srcLength,
4257  int32_t start,
4258  int32_t _length) const
4259 { return indexOf(srcChars, 0, srcLength, start, _length); }
4260 
4261 inline int32_t
4262 UnicodeString::indexOf(char16_t c,
4263  int32_t start,
4264  int32_t _length) const
4265 { return doIndexOf(c, start, _length); }
4266 
4267 inline int32_t
4268 UnicodeString::indexOf(UChar32 c,
4269  int32_t start,
4270  int32_t _length) const
4271 { return doIndexOf(c, start, _length); }
4272 
4273 inline int32_t
4274 UnicodeString::indexOf(char16_t c) const
4275 { return doIndexOf(c, 0, length()); }
4276 
4277 inline int32_t
4278 UnicodeString::indexOf(UChar32 c) const
4279 { return indexOf(c, 0, length()); }
4280 
4281 inline int32_t
4282 UnicodeString::indexOf(char16_t c,
4283  int32_t start) const {
4284  pinIndex(start);
4285  return doIndexOf(c, start, length() - start);
4286 }
4287 
4288 inline int32_t
4289 UnicodeString::indexOf(UChar32 c,
4290  int32_t start) const {
4291  pinIndex(start);
4292  return indexOf(c, start, length() - start);
4293 }
4294 
4295 inline int32_t
4296 UnicodeString::lastIndexOf(ConstChar16Ptr srcChars,
4297  int32_t srcLength,
4298  int32_t start,
4299  int32_t _length) const
4300 { return lastIndexOf(srcChars, 0, srcLength, start, _length); }
4301 
4302 inline int32_t
4303 UnicodeString::lastIndexOf(const char16_t *srcChars,
4304  int32_t srcLength,
4305  int32_t start) const {
4306  pinIndex(start);
4307  return lastIndexOf(srcChars, 0, srcLength, start, length() - start);
4308 }
4309 
4310 inline int32_t
4311 UnicodeString::lastIndexOf(const UnicodeString& srcText,
4312  int32_t srcStart,
4313  int32_t srcLength,
4314  int32_t start,
4315  int32_t _length) const
4316 {
4317  if(!srcText.isBogus()) {
4318  srcText.pinIndices(srcStart, srcLength);
4319  if(srcLength > 0) {
4320  return lastIndexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
4321  }
4322  }
4323  return -1;
4324 }
4325 
4326 inline int32_t
4327 UnicodeString::lastIndexOf(const UnicodeString& text,
4328  int32_t start,
4329  int32_t _length) const
4330 { return lastIndexOf(text, 0, text.length(), start, _length); }
4331 
4332 inline int32_t
4333 UnicodeString::lastIndexOf(const UnicodeString& text,
4334  int32_t start) const {
4335  pinIndex(start);
4336  return lastIndexOf(text, 0, text.length(), start, length() - start);
4337 }
4338 
4339 inline int32_t
4340 UnicodeString::lastIndexOf(const UnicodeString& text) const
4341 { return lastIndexOf(text, 0, text.length(), 0, length()); }
4342 
4343 inline int32_t
4344 UnicodeString::lastIndexOf(char16_t c,
4345  int32_t start,
4346  int32_t _length) const
4347 { return doLastIndexOf(c, start, _length); }
4348 
4349 inline int32_t
4350 UnicodeString::lastIndexOf(UChar32 c,
4351  int32_t start,
4352  int32_t _length) const {
4353  return doLastIndexOf(c, start, _length);
4354 }
4355 
4356 inline int32_t
4357 UnicodeString::lastIndexOf(char16_t c) const
4358 { return doLastIndexOf(c, 0, length()); }
4359 
4360 inline int32_t
4361 UnicodeString::lastIndexOf(UChar32 c) const {
4362  return lastIndexOf(c, 0, length());
4363 }
4364 
4365 inline int32_t
4366 UnicodeString::lastIndexOf(char16_t c,
4367  int32_t start) const {
4368  pinIndex(start);
4369  return doLastIndexOf(c, start, length() - start);
4370 }
4371 
4372 inline int32_t
4373 UnicodeString::lastIndexOf(UChar32 c,
4374  int32_t start) const {
4375  pinIndex(start);
4376  return lastIndexOf(c, start, length() - start);
4377 }
4378 
4379 inline UBool
4380 UnicodeString::startsWith(const UnicodeString& text) const
4381 { return compare(0, text.length(), text, 0, text.length()) == 0; }
4382 
4383 inline UBool
4384 UnicodeString::startsWith(const UnicodeString& srcText,
4385  int32_t srcStart,
4386  int32_t srcLength) const
4387 { return doCompare(0, srcLength, srcText, srcStart, srcLength) == 0; }
4388 
4389 inline UBool
4390 UnicodeString::startsWith(ConstChar16Ptr srcChars, int32_t srcLength) const {
4391  if(srcLength < 0) {
4392  srcLength = u_strlen(toUCharPtr(srcChars));
4393  }
4394  return doCompare(0, srcLength, srcChars, 0, srcLength) == 0;
4395 }
4396 
4397 inline UBool
4398 UnicodeString::startsWith(const char16_t *srcChars, int32_t srcStart, int32_t srcLength) const {
4399  if(srcLength < 0) {
4400  srcLength = u_strlen(toUCharPtr(srcChars));
4401  }
4402  return doCompare(0, srcLength, srcChars, srcStart, srcLength) == 0;
4403 }
4404 
4405 inline UBool
4406 UnicodeString::endsWith(const UnicodeString& text) const
4407 { return doCompare(length() - text.length(), text.length(),
4408  text, 0, text.length()) == 0; }
4409 
4410 inline UBool
4411 UnicodeString::endsWith(const UnicodeString& srcText,
4412  int32_t srcStart,
4413  int32_t srcLength) const {
4414  srcText.pinIndices(srcStart, srcLength);
4415  return doCompare(length() - srcLength, srcLength,
4416  srcText, srcStart, srcLength) == 0;
4417 }
4418 
4419 inline UBool
4420 UnicodeString::endsWith(ConstChar16Ptr srcChars,
4421  int32_t srcLength) const {
4422  if(srcLength < 0) {
4423  srcLength = u_strlen(toUCharPtr(srcChars));
4424  }
4425  return doCompare(length() - srcLength, srcLength,
4426  srcChars, 0, srcLength) == 0;
4427 }
4428 
4429 inline UBool
4430 UnicodeString::endsWith(const char16_t *srcChars,
4431  int32_t srcStart,
4432  int32_t srcLength) const {
4433  if(srcLength < 0) {
4434  srcLength = u_strlen(toUCharPtr(srcChars + srcStart));
4435  }
4436  return doCompare(length() - srcLength, srcLength,
4437  srcChars, srcStart, srcLength) == 0;
4438 }
4439 
4440 //========================================
4441 // replace
4442 //========================================
4443 inline UnicodeString&
4444 UnicodeString::replace(int32_t start,
4445  int32_t _length,
4446  const UnicodeString& srcText)
4447 { return doReplace(start, _length, srcText, 0, srcText.length()); }
4448 
4449 inline UnicodeString&
4450 UnicodeString::replace(int32_t start,
4451  int32_t _length,
4452  const UnicodeString& srcText,
4453  int32_t srcStart,
4454  int32_t srcLength)
4455 { return doReplace(start, _length, srcText, srcStart, srcLength); }
4456 
4457 inline UnicodeString&
4458 UnicodeString::replace(int32_t start,
4459  int32_t _length,
4460  ConstChar16Ptr srcChars,
4461  int32_t srcLength)
4462 { return doReplace(start, _length, srcChars, 0, srcLength); }
4463 
4464 inline UnicodeString&
4465 UnicodeString::replace(int32_t start,
4466  int32_t _length,
4467  const char16_t *srcChars,
4468  int32_t srcStart,
4469  int32_t srcLength)
4470 { return doReplace(start, _length, srcChars, srcStart, srcLength); }
4471 
4472 inline UnicodeString&
4473 UnicodeString::replace(int32_t start,
4474  int32_t _length,
4475  char16_t srcChar)
4476 { return doReplace(start, _length, &srcChar, 0, 1); }
4477 
4478 inline UnicodeString&
4479 UnicodeString::replaceBetween(int32_t start,
4480  int32_t limit,
4481  const UnicodeString& srcText)
4482 { return doReplace(start, limit - start, srcText, 0, srcText.length()); }
4483 
4484 inline UnicodeString&
4485 UnicodeString::replaceBetween(int32_t start,
4486  int32_t limit,
4487  const UnicodeString& srcText,
4488  int32_t srcStart,
4489  int32_t srcLimit)
4490 { return doReplace(start, limit - start, srcText, srcStart, srcLimit - srcStart); }
4491 
4492 inline UnicodeString&
4493 UnicodeString::findAndReplace(const UnicodeString& oldText,
4494  const UnicodeString& newText)
4495 { return findAndReplace(0, length(), oldText, 0, oldText.length(),
4496  newText, 0, newText.length()); }
4497 
4498 inline UnicodeString&
4499 UnicodeString::findAndReplace(int32_t start,
4500  int32_t _length,
4501  const UnicodeString& oldText,
4502  const UnicodeString& newText)
4503 { return findAndReplace(start, _length, oldText, 0, oldText.length(),
4504  newText, 0, newText.length()); }
4505 
4506 // ============================
4507 // extract
4508 // ============================
4509 inline void
4510 UnicodeString::doExtract(int32_t start,
4511  int32_t _length,
4512  UnicodeString& target) const
4513 { target.replace(0, target.length(), *this, start, _length); }
4514 
4515 inline void
4516 UnicodeString::extract(int32_t start,
4517  int32_t _length,
4518  Char16Ptr target,
4519  int32_t targetStart) const
4520 { doExtract(start, _length, target, targetStart); }
4521 
4522 inline void
4523 UnicodeString::extract(int32_t start,
4524  int32_t _length,
4525  UnicodeString& target) const
4526 { doExtract(start, _length, target); }
4527 
4528 #if !UCONFIG_NO_CONVERSION
4529 
4530 inline int32_t
4531 UnicodeString::extract(int32_t start,
4532  int32_t _length,
4533  char *dst,
4534  const char *codepage) const
4535 
4536 {
4537  // This dstSize value will be checked explicitly
4538  return extract(start, _length, dst, dst!=0 ? 0xffffffff : 0, codepage);
4539 }
4540 
4541 #endif
4542 
4543 inline void
4544 UnicodeString::extractBetween(int32_t start,
4545  int32_t limit,
4546  char16_t *dst,
4547  int32_t dstStart) const {
4548  pinIndex(start);
4549  pinIndex(limit);
4550  doExtract(start, limit - start, dst, dstStart);
4551 }
4552 
4553 inline UnicodeString
4554 UnicodeString::tempSubStringBetween(int32_t start, int32_t limit) const {
4555  return tempSubString(start, limit - start);
4556 }
4557 
4558 inline char16_t
4559 UnicodeString::doCharAt(int32_t offset) const
4560 {
4561  if((uint32_t)offset < (uint32_t)length()) {
4562  return getArrayStart()[offset];
4563  } else {
4564  return kInvalidUChar;
4565  }
4566 }
4567 
4568 inline char16_t
4569 UnicodeString::charAt(int32_t offset) const
4570 { return doCharAt(offset); }
4571 
4572 inline char16_t
4573 UnicodeString::operator[] (int32_t offset) const
4574 { return doCharAt(offset); }
4575 
4576 inline UBool
4577 UnicodeString::isEmpty() const {
4578  // Arithmetic or logical right shift does not matter: only testing for 0.
4579  return (fUnion.fFields.fLengthAndFlags>>kLengthShift) == 0;
4580 }
4581 
4582 //========================================
4583 // Write implementation methods
4584 //========================================
4585 inline void
4586 UnicodeString::setZeroLength() {
4587  fUnion.fFields.fLengthAndFlags &= kAllStorageFlags;
4588 }
4589 
4590 inline void
4591 UnicodeString::setShortLength(int32_t len) {
4592  // requires 0 <= len <= kMaxShortLength
4593  fUnion.fFields.fLengthAndFlags =
4594  (int16_t)((fUnion.fFields.fLengthAndFlags & kAllStorageFlags) | (len << kLengthShift));
4595 }
4596 
4597 inline void
4598 UnicodeString::setLength(int32_t len) {
4599  if(len <= kMaxShortLength) {
4600  setShortLength(len);
4601  } else {
4602  fUnion.fFields.fLengthAndFlags |= kLengthIsLarge;
4603  fUnion.fFields.fLength = len;
4604  }
4605 }
4606 
4607 inline void
4608 UnicodeString::setToEmpty() {
4609  fUnion.fFields.fLengthAndFlags = kShortString;
4610 }
4611 
4612 inline void
4613 UnicodeString::setArray(char16_t *array, int32_t len, int32_t capacity) {
4614  setLength(len);
4615  fUnion.fFields.fArray = array;
4616  fUnion.fFields.fCapacity = capacity;
4617 }
4618 
4619 inline UnicodeString&
4620 UnicodeString::operator= (char16_t ch)
4621 { return doReplace(0, length(), &ch, 0, 1); }
4622 
4623 inline UnicodeString&
4624 UnicodeString::operator= (UChar32 ch)
4625 { return replace(0, length(), ch); }
4626 
4627 inline UnicodeString&
4628 UnicodeString::setTo(const UnicodeString& srcText,
4629  int32_t srcStart,
4630  int32_t srcLength)
4631 {
4632  unBogus();
4633  return doReplace(0, length(), srcText, srcStart, srcLength);
4634 }
4635 
4636 inline UnicodeString&
4637 UnicodeString::setTo(const UnicodeString& srcText,
4638  int32_t srcStart)
4639 {
4640  unBogus();
4641  srcText.pinIndex(srcStart);
4642  return doReplace(0, length(), srcText, srcStart, srcText.length() - srcStart);
4643 }
4644 
4645 inline UnicodeString&
4646 UnicodeString::setTo(const UnicodeString& srcText)
4647 {
4648  return copyFrom(srcText);
4649 }
4650 
4651 inline UnicodeString&
4652 UnicodeString::setTo(const char16_t *srcChars,
4653  int32_t srcLength)
4654 {
4655  unBogus();
4656  return doReplace(0, length(), srcChars, 0, srcLength);
4657 }
4658 
4659 inline UnicodeString&
4660 UnicodeString::setTo(char16_t srcChar)
4661 {
4662  unBogus();
4663  return doReplace(0, length(), &srcChar, 0, 1);
4664 }
4665 
4666 inline UnicodeString&
4667 UnicodeString::setTo(UChar32 srcChar)
4668 {
4669  unBogus();
4670  return replace(0, length(), srcChar);
4671 }
4672 
4673 inline UnicodeString&
4674 UnicodeString::append(const UnicodeString& srcText,
4675  int32_t srcStart,
4676  int32_t srcLength)
4677 { return doAppend(srcText, srcStart, srcLength); }
4678 
4679 inline UnicodeString&
4680 UnicodeString::append(const UnicodeString& srcText)
4681 { return doAppend(srcText, 0, srcText.length()); }
4682 
4683 inline UnicodeString&
4684 UnicodeString::append(const char16_t *srcChars,
4685  int32_t srcStart,
4686  int32_t srcLength)
4687 { return doAppend(srcChars, srcStart, srcLength); }
4688 
4689 inline UnicodeString&
4690 UnicodeString::append(ConstChar16Ptr srcChars,
4691  int32_t srcLength)
4692 { return doAppend(srcChars, 0, srcLength); }
4693 
4694 inline UnicodeString&
4695 UnicodeString::append(char16_t srcChar)
4696 { return doAppend(&srcChar, 0, 1); }
4697 
4698 inline UnicodeString&
4699 UnicodeString::operator+= (char16_t ch)
4700 { return doAppend(&ch, 0, 1); }
4701 
4702 inline UnicodeString&
4703 UnicodeString::operator+= (UChar32 ch) {
4704  return append(ch);
4705 }
4706 
4707 inline UnicodeString&
4708 UnicodeString::operator+= (const UnicodeString& srcText)
4709 { return doAppend(srcText, 0, srcText.length()); }
4710 
4711 inline UnicodeString&
4712 UnicodeString::insert(int32_t start,
4713  const UnicodeString& srcText,
4714  int32_t srcStart,
4715  int32_t srcLength)
4716 { return doReplace(start, 0, srcText, srcStart, srcLength); }
4717 
4718 inline UnicodeString&
4719 UnicodeString::insert(int32_t start,
4720  const UnicodeString& srcText)
4721 { return doReplace(start, 0, srcText, 0, srcText.length()); }
4722 
4723 inline UnicodeString&
4724 UnicodeString::insert(int32_t start,
4725  const char16_t *srcChars,
4726  int32_t srcStart,
4727  int32_t srcLength)
4728 { return doReplace(start, 0, srcChars, srcStart, srcLength); }
4729 
4730 inline UnicodeString&
4731 UnicodeString::insert(int32_t start,
4732  ConstChar16Ptr srcChars,
4733  int32_t srcLength)
4734 { return doReplace(start, 0, srcChars, 0, srcLength); }
4735 
4736 inline UnicodeString&
4737 UnicodeString::insert(int32_t start,
4738  char16_t srcChar)
4739 { return doReplace(start, 0, &srcChar, 0, 1); }
4740 
4741 inline UnicodeString&
4742 UnicodeString::insert(int32_t start,
4743  UChar32 srcChar)
4744 { return replace(start, 0, srcChar); }
4745 
4746 
4747 inline UnicodeString&
4748 UnicodeString::remove()
4749 {
4750  // remove() of a bogus string makes the string empty and non-bogus
4751  if(isBogus()) {
4752  setToEmpty();
4753  } else {
4754  setZeroLength();
4755  }
4756  return *this;
4757 }
4758 
4759 inline UnicodeString&
4760 UnicodeString::remove(int32_t start,
4761  int32_t _length)
4762 {
4763  if(start <= 0 && _length == INT32_MAX) {
4764  // remove(guaranteed everything) of a bogus string makes the string empty and non-bogus
4765  return remove();
4766  }
4767  return doReplace(start, _length, NULL, 0, 0);
4768 }
4769 
4770 inline UnicodeString&
4771 UnicodeString::removeBetween(int32_t start,
4772  int32_t limit)
4773 { return doReplace(start, limit - start, NULL, 0, 0); }
4774 
4775 inline UnicodeString &
4776 UnicodeString::retainBetween(int32_t start, int32_t limit) {
4777  truncate(limit);
4778  return doReplace(0, start, NULL, 0, 0);
4779 }
4780 
4781 inline UBool
4782 UnicodeString::truncate(int32_t targetLength)
4783 {
4784  if(isBogus() && targetLength == 0) {
4785  // truncate(0) of a bogus string makes the string empty and non-bogus
4786  unBogus();
4787  return FALSE;
4788  } else if((uint32_t)targetLength < (uint32_t)length()) {
4789  setLength(targetLength);
4790  return TRUE;
4791  } else {
4792  return FALSE;
4793  }
4794 }
4795 
4796 inline UnicodeString&
4797 UnicodeString::reverse()
4798 { return doReverse(0, length()); }
4799 
4800 inline UnicodeString&
4801 UnicodeString::reverse(int32_t start,
4802  int32_t _length)
4803 { return doReverse(start, _length); }
4804 
4806 
4807 #endif
#define UNISTR_OBJECT_SIZE
Desired sizeof(UnicodeString) in bytes.
Definition: unistr.h:204
virtual Replaceable * clone() const
Clone this object, an instance of a subclass of Replaceable.
char16_t charAt(int32_t offset) const
Returns the 16-bit code unit at the given offset into the text.
Definition: rep.h:250
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 & operator=(UnicodeString &&src) U_NOEXCEPT
Move assignment operator, might leave src in bogus state.
Definition: unistr.h:1902
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
virtual UClassID getDynamicClassID() const
ICU4C "poor man&#39;s RTTI", returns a UClassID for the actual ICU class.
virtual UBool hasMetaData() const
Returns true if this object contains metadata.
UnicodeString(wchar_t *buffer, int32_t buffLength, int32_t buffCapacity)
Writable-aliasing wchar_t * constructor.
Definition: unistr.h:3186
virtual void copy(int32_t start, int32_t limit, int32_t dest)=0
Copies a substring of this object, retaining metadata.
UBool isBogus(void) const
Determine if this object contains a valid string.
Definition: unistr.h:3957
friend U_COMMON_API void swap(UnicodeString &s1, UnicodeString &s2) U_NOEXCEPT
Non-member UnicodeString swap function.
Definition: unistr.h:1933
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:830
UNISTR_FROM_STRING_EXPLICIT UnicodeString(const uint16_t *text)
uint16_t * constructor.
Definition: unistr.h:3013
UNISTR_FROM_STRING_EXPLICIT UnicodeString(const wchar_t *text)
wchar_t * constructor.
Definition: unistr.h:3033
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:3092
#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:3075
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:66
#define UCONFIG_NO_BREAK_ITERATION
This switch turns off break iteration.
Definition: uconfig.h:345
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
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
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
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:498
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:3168
#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 * 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.
#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
int32_t length() const
Returns the number of 16-bit code units in the text.
Definition: rep.h:245
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:286
#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:4450
int32_t length(void) const
Return the length of the UnicodeString object.
Definition: unistr.h:3942
#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.