ICU 63.1  63.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 
290 {
291 public:
292 
301  enum EInvariant {
306  kInvariant
307  };
308 
309  //========================================
310  // Read-only operations
311  //========================================
312 
313  /* Comparison - bitwise only - for international comparison use collation */
314 
322  inline UBool operator== (const UnicodeString& text) const;
323 
331  inline UBool operator!= (const UnicodeString& text) const;
332 
340  inline UBool operator> (const UnicodeString& text) const;
341 
349  inline UBool operator< (const UnicodeString& text) const;
350 
358  inline UBool operator>= (const UnicodeString& text) const;
359 
367  inline UBool operator<= (const UnicodeString& text) const;
368 
380  inline int8_t compare(const UnicodeString& text) const;
381 
397  inline int8_t compare(int32_t start,
398  int32_t length,
399  const UnicodeString& text) const;
400 
418  inline int8_t compare(int32_t start,
419  int32_t length,
420  const UnicodeString& srcText,
421  int32_t srcStart,
422  int32_t srcLength) const;
423 
436  inline int8_t compare(ConstChar16Ptr srcChars,
437  int32_t srcLength) const;
438 
453  inline int8_t compare(int32_t start,
454  int32_t length,
455  const char16_t *srcChars) const;
456 
474  inline int8_t compare(int32_t start,
475  int32_t length,
476  const char16_t *srcChars,
477  int32_t srcStart,
478  int32_t srcLength) const;
479 
497  inline int8_t compareBetween(int32_t start,
498  int32_t limit,
499  const UnicodeString& srcText,
500  int32_t srcStart,
501  int32_t srcLimit) const;
502 
520  inline int8_t compareCodePointOrder(const UnicodeString& text) const;
521 
541  inline int8_t compareCodePointOrder(int32_t start,
542  int32_t length,
543  const UnicodeString& srcText) const;
544 
566  inline int8_t compareCodePointOrder(int32_t start,
567  int32_t length,
568  const UnicodeString& srcText,
569  int32_t srcStart,
570  int32_t srcLength) const;
571 
590  inline int8_t compareCodePointOrder(ConstChar16Ptr srcChars,
591  int32_t srcLength) const;
592 
612  inline int8_t compareCodePointOrder(int32_t start,
613  int32_t length,
614  const char16_t *srcChars) const;
615 
637  inline int8_t compareCodePointOrder(int32_t start,
638  int32_t length,
639  const char16_t *srcChars,
640  int32_t srcStart,
641  int32_t srcLength) const;
642 
664  inline int8_t compareCodePointOrderBetween(int32_t start,
665  int32_t limit,
666  const UnicodeString& srcText,
667  int32_t srcStart,
668  int32_t srcLimit) const;
669 
688  inline int8_t caseCompare(const UnicodeString& text, uint32_t options) const;
689 
710  inline int8_t caseCompare(int32_t start,
711  int32_t length,
712  const UnicodeString& srcText,
713  uint32_t options) const;
714 
737  inline int8_t caseCompare(int32_t start,
738  int32_t length,
739  const UnicodeString& srcText,
740  int32_t srcStart,
741  int32_t srcLength,
742  uint32_t options) const;
743 
763  inline int8_t caseCompare(ConstChar16Ptr srcChars,
764  int32_t srcLength,
765  uint32_t options) const;
766 
787  inline int8_t caseCompare(int32_t start,
788  int32_t length,
789  const char16_t *srcChars,
790  uint32_t options) const;
791 
814  inline int8_t caseCompare(int32_t start,
815  int32_t length,
816  const char16_t *srcChars,
817  int32_t srcStart,
818  int32_t srcLength,
819  uint32_t options) const;
820 
843  inline int8_t caseCompareBetween(int32_t start,
844  int32_t limit,
845  const UnicodeString& srcText,
846  int32_t srcStart,
847  int32_t srcLimit,
848  uint32_t options) const;
849 
857  inline UBool startsWith(const UnicodeString& text) const;
858 
869  inline UBool startsWith(const UnicodeString& srcText,
870  int32_t srcStart,
871  int32_t srcLength) const;
872 
881  inline UBool startsWith(ConstChar16Ptr srcChars,
882  int32_t srcLength) const;
883 
893  inline UBool startsWith(const char16_t *srcChars,
894  int32_t srcStart,
895  int32_t srcLength) const;
896 
904  inline UBool endsWith(const UnicodeString& text) const;
905 
916  inline UBool endsWith(const UnicodeString& srcText,
917  int32_t srcStart,
918  int32_t srcLength) const;
919 
928  inline UBool endsWith(ConstChar16Ptr srcChars,
929  int32_t srcLength) const;
930 
941  inline UBool endsWith(const char16_t *srcChars,
942  int32_t srcStart,
943  int32_t srcLength) const;
944 
945 
946  /* Searching - bitwise only */
947 
956  inline int32_t indexOf(const UnicodeString& text) const;
957 
967  inline int32_t indexOf(const UnicodeString& text,
968  int32_t start) const;
969 
981  inline int32_t indexOf(const UnicodeString& text,
982  int32_t start,
983  int32_t length) const;
984 
1001  inline int32_t indexOf(const UnicodeString& srcText,
1002  int32_t srcStart,
1003  int32_t srcLength,
1004  int32_t start,
1005  int32_t length) const;
1006 
1018  inline int32_t indexOf(const char16_t *srcChars,
1019  int32_t srcLength,
1020  int32_t start) const;
1021 
1034  inline int32_t indexOf(ConstChar16Ptr srcChars,
1035  int32_t srcLength,
1036  int32_t start,
1037  int32_t length) const;
1038 
1055  int32_t indexOf(const char16_t *srcChars,
1056  int32_t srcStart,
1057  int32_t srcLength,
1058  int32_t start,
1059  int32_t length) const;
1060 
1068  inline int32_t indexOf(char16_t c) const;
1069 
1078  inline int32_t indexOf(UChar32 c) const;
1079 
1088  inline int32_t indexOf(char16_t c,
1089  int32_t start) const;
1090 
1100  inline int32_t indexOf(UChar32 c,
1101  int32_t start) const;
1102 
1113  inline int32_t indexOf(char16_t c,
1114  int32_t start,
1115  int32_t length) const;
1116 
1128  inline int32_t indexOf(UChar32 c,
1129  int32_t start,
1130  int32_t length) const;
1131 
1140  inline int32_t lastIndexOf(const UnicodeString& text) const;
1141 
1151  inline int32_t lastIndexOf(const UnicodeString& text,
1152  int32_t start) const;
1153 
1165  inline int32_t lastIndexOf(const UnicodeString& text,
1166  int32_t start,
1167  int32_t length) const;
1168 
1185  inline int32_t lastIndexOf(const UnicodeString& srcText,
1186  int32_t srcStart,
1187  int32_t srcLength,
1188  int32_t start,
1189  int32_t length) const;
1190 
1201  inline int32_t lastIndexOf(const char16_t *srcChars,
1202  int32_t srcLength,
1203  int32_t start) const;
1204 
1217  inline int32_t lastIndexOf(ConstChar16Ptr srcChars,
1218  int32_t srcLength,
1219  int32_t start,
1220  int32_t length) const;
1221 
1238  int32_t lastIndexOf(const char16_t *srcChars,
1239  int32_t srcStart,
1240  int32_t srcLength,
1241  int32_t start,
1242  int32_t length) const;
1243 
1251  inline int32_t lastIndexOf(char16_t c) const;
1252 
1261  inline int32_t lastIndexOf(UChar32 c) const;
1262 
1271  inline int32_t lastIndexOf(char16_t c,
1272  int32_t start) const;
1273 
1283  inline int32_t lastIndexOf(UChar32 c,
1284  int32_t start) const;
1285 
1296  inline int32_t lastIndexOf(char16_t c,
1297  int32_t start,
1298  int32_t length) const;
1299 
1311  inline int32_t lastIndexOf(UChar32 c,
1312  int32_t start,
1313  int32_t length) const;
1314 
1315 
1316  /* Character access */
1317 
1326  inline char16_t charAt(int32_t offset) const;
1327 
1335  inline char16_t operator[] (int32_t offset) const;
1336 
1348  UChar32 char32At(int32_t offset) const;
1349 
1365  int32_t getChar32Start(int32_t offset) const;
1366 
1383  int32_t getChar32Limit(int32_t offset) const;
1384 
1435  int32_t moveIndex32(int32_t index, int32_t delta) const;
1436 
1437  /* Substring extraction */
1438 
1454  inline void extract(int32_t start,
1455  int32_t length,
1456  Char16Ptr dst,
1457  int32_t dstStart = 0) const;
1458 
1480  int32_t
1481  extract(Char16Ptr dest, int32_t destCapacity,
1482  UErrorCode &errorCode) const;
1483 
1494  inline void extract(int32_t start,
1495  int32_t length,
1496  UnicodeString& target) const;
1497 
1509  inline void extractBetween(int32_t start,
1510  int32_t limit,
1511  char16_t *dst,
1512  int32_t dstStart = 0) const;
1513 
1523  virtual void extractBetween(int32_t start,
1524  int32_t limit,
1525  UnicodeString& target) const;
1526 
1548  int32_t extract(int32_t start,
1549  int32_t startLength,
1550  char *target,
1551  int32_t targetCapacity,
1552  enum EInvariant inv) const;
1553 
1554 #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
1555 
1575  int32_t extract(int32_t start,
1576  int32_t startLength,
1577  char *target,
1578  uint32_t targetLength) const;
1579 
1580 #endif
1581 
1582 #if !UCONFIG_NO_CONVERSION
1583 
1609  inline int32_t extract(int32_t start,
1610  int32_t startLength,
1611  char *target,
1612  const char *codepage = 0) const;
1613 
1643  int32_t extract(int32_t start,
1644  int32_t startLength,
1645  char *target,
1646  uint32_t targetLength,
1647  const char *codepage) const;
1648 
1666  int32_t extract(char *dest, int32_t destCapacity,
1667  UConverter *cnv,
1668  UErrorCode &errorCode) const;
1669 
1670 #endif
1671 
1685  UnicodeString tempSubString(int32_t start=0, int32_t length=INT32_MAX) const;
1686 
1697  inline UnicodeString tempSubStringBetween(int32_t start, int32_t limit=INT32_MAX) const;
1698 
1710  void toUTF8(ByteSink &sink) const;
1711 
1724  template<typename StringClass>
1725  StringClass &toUTF8String(StringClass &result) const {
1726  StringByteSink<StringClass> sbs(&result, length());
1727  toUTF8(sbs);
1728  return result;
1729  }
1730 
1746  int32_t toUTF32(UChar32 *utf32, int32_t capacity, UErrorCode &errorCode) const;
1747 
1748  /* Length operations */
1749 
1758  inline int32_t length(void) const;
1759 
1773  int32_t
1774  countChar32(int32_t start=0, int32_t length=INT32_MAX) const;
1775 
1799  UBool
1800  hasMoreChar32Than(int32_t start, int32_t length, int32_t number) const;
1801 
1807  inline UBool isEmpty(void) const;
1808 
1818  inline int32_t getCapacity(void) const;
1819 
1820  /* Other operations */
1821 
1827  inline int32_t hashCode(void) const;
1828 
1841  inline UBool isBogus(void) const;
1842 
1843 
1844  //========================================
1845  // Write operations
1846  //========================================
1847 
1848  /* Assignment operations */
1849 
1868  UnicodeString &operator=(const UnicodeString &srcText);
1869 
1895  UnicodeString &fastCopyFrom(const UnicodeString &src);
1896 
1906  return moveFrom(src);
1907  }
1908 
1909  // do not use #ifndef U_HIDE_DRAFT_API for moveFrom, needed by non-draft API
1920  UnicodeString &moveFrom(UnicodeString &src) U_NOEXCEPT;
1921 
1927  void swap(UnicodeString &other) U_NOEXCEPT;
1928 
1935  friend U_COMMON_API inline void U_EXPORT2
1936  swap(UnicodeString &s1, UnicodeString &s2) U_NOEXCEPT {
1937  s1.swap(s2);
1938  }
1939 
1947  inline UnicodeString& operator= (char16_t ch);
1948 
1956  inline UnicodeString& operator= (UChar32 ch);
1957 
1969  inline UnicodeString& setTo(const UnicodeString& srcText,
1970  int32_t srcStart);
1971 
1985  inline UnicodeString& setTo(const UnicodeString& srcText,
1986  int32_t srcStart,
1987  int32_t srcLength);
1988 
1997  inline UnicodeString& setTo(const UnicodeString& srcText);
1998 
2007  inline UnicodeString& setTo(const char16_t *srcChars,
2008  int32_t srcLength);
2009 
2018  UnicodeString& setTo(char16_t srcChar);
2019 
2028  UnicodeString& setTo(UChar32 srcChar);
2029 
2053  UnicodeString &setTo(UBool isTerminated,
2054  ConstChar16Ptr text,
2055  int32_t textLength);
2056 
2076  UnicodeString &setTo(char16_t *buffer,
2077  int32_t buffLength,
2078  int32_t buffCapacity);
2079 
2120  void setToBogus();
2121 
2129  UnicodeString& setCharAt(int32_t offset,
2130  char16_t ch);
2131 
2132 
2133  /* Append operations */
2134 
2142  inline UnicodeString& operator+= (char16_t ch);
2143 
2151  inline UnicodeString& operator+= (UChar32 ch);
2152 
2160  inline UnicodeString& operator+= (const UnicodeString& srcText);
2161 
2176  inline UnicodeString& append(const UnicodeString& srcText,
2177  int32_t srcStart,
2178  int32_t srcLength);
2179 
2187  inline UnicodeString& append(const UnicodeString& srcText);
2188 
2202  inline UnicodeString& append(const char16_t *srcChars,
2203  int32_t srcStart,
2204  int32_t srcLength);
2205 
2215  inline UnicodeString& append(ConstChar16Ptr srcChars,
2216  int32_t srcLength);
2217 
2224  inline UnicodeString& append(char16_t srcChar);
2225 
2232  UnicodeString& append(UChar32 srcChar);
2233 
2234 
2235  /* Insert operations */
2236 
2250  inline UnicodeString& insert(int32_t start,
2251  const UnicodeString& srcText,
2252  int32_t srcStart,
2253  int32_t srcLength);
2254 
2263  inline UnicodeString& insert(int32_t start,
2264  const UnicodeString& srcText);
2265 
2279  inline UnicodeString& insert(int32_t start,
2280  const char16_t *srcChars,
2281  int32_t srcStart,
2282  int32_t srcLength);
2283 
2293  inline UnicodeString& insert(int32_t start,
2294  ConstChar16Ptr srcChars,
2295  int32_t srcLength);
2296 
2305  inline UnicodeString& insert(int32_t start,
2306  char16_t srcChar);
2307 
2316  inline UnicodeString& insert(int32_t start,
2317  UChar32 srcChar);
2318 
2319 
2320  /* Replace operations */
2321 
2339  UnicodeString& replace(int32_t start,
2340  int32_t length,
2341  const UnicodeString& srcText,
2342  int32_t srcStart,
2343  int32_t srcLength);
2344 
2357  UnicodeString& replace(int32_t start,
2358  int32_t length,
2359  const UnicodeString& srcText);
2360 
2378  UnicodeString& replace(int32_t start,
2379  int32_t length,
2380  const char16_t *srcChars,
2381  int32_t srcStart,
2382  int32_t srcLength);
2383 
2396  inline UnicodeString& replace(int32_t start,
2397  int32_t length,
2398  ConstChar16Ptr srcChars,
2399  int32_t srcLength);
2400 
2412  inline UnicodeString& replace(int32_t start,
2413  int32_t length,
2414  char16_t srcChar);
2415 
2427  UnicodeString& replace(int32_t start, int32_t length, UChar32 srcChar);
2428 
2438  inline UnicodeString& replaceBetween(int32_t start,
2439  int32_t limit,
2440  const UnicodeString& srcText);
2441 
2456  inline UnicodeString& replaceBetween(int32_t start,
2457  int32_t limit,
2458  const UnicodeString& srcText,
2459  int32_t srcStart,
2460  int32_t srcLimit);
2461 
2472  virtual void handleReplaceBetween(int32_t start,
2473  int32_t limit,
2474  const UnicodeString& text);
2475 
2481  virtual UBool hasMetaData() const;
2482 
2498  virtual void copy(int32_t start, int32_t limit, int32_t dest);
2499 
2500  /* Search and replace operations */
2501 
2510  inline UnicodeString& findAndReplace(const UnicodeString& oldText,
2511  const UnicodeString& newText);
2512 
2524  inline UnicodeString& findAndReplace(int32_t start,
2525  int32_t length,
2526  const UnicodeString& oldText,
2527  const UnicodeString& newText);
2528 
2546  UnicodeString& findAndReplace(int32_t start,
2547  int32_t length,
2548  const UnicodeString& oldText,
2549  int32_t oldStart,
2550  int32_t oldLength,
2551  const UnicodeString& newText,
2552  int32_t newStart,
2553  int32_t newLength);
2554 
2555 
2556  /* Remove operations */
2557 
2563  inline UnicodeString& remove(void);
2564 
2573  inline UnicodeString& remove(int32_t start,
2574  int32_t length = (int32_t)INT32_MAX);
2575 
2584  inline UnicodeString& removeBetween(int32_t start,
2585  int32_t limit = (int32_t)INT32_MAX);
2586 
2596  inline UnicodeString &retainBetween(int32_t start, int32_t limit = INT32_MAX);
2597 
2598  /* Length operations */
2599 
2611  UBool padLeading(int32_t targetLength,
2612  char16_t padChar = 0x0020);
2613 
2625  UBool padTrailing(int32_t targetLength,
2626  char16_t padChar = 0x0020);
2627 
2634  inline UBool truncate(int32_t targetLength);
2635 
2641  UnicodeString& trim(void);
2642 
2643 
2644  /* Miscellaneous operations */
2645 
2651  inline UnicodeString& reverse(void);
2652 
2661  inline UnicodeString& reverse(int32_t start,
2662  int32_t length);
2663 
2670  UnicodeString& toUpper(void);
2671 
2679  UnicodeString& toUpper(const Locale& locale);
2680 
2687  UnicodeString& toLower(void);
2688 
2696  UnicodeString& toLower(const Locale& locale);
2697 
2698 #if !UCONFIG_NO_BREAK_ITERATION
2699 
2726  UnicodeString &toTitle(BreakIterator *titleIter);
2727 
2755  UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale);
2756 
2788  UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale, uint32_t options);
2789 
2790 #endif
2791 
2805  UnicodeString &foldCase(uint32_t options=0 /*U_FOLD_CASE_DEFAULT*/);
2806 
2807  //========================================
2808  // Access to the internal buffer
2809  //========================================
2810 
2854  char16_t *getBuffer(int32_t minCapacity);
2855 
2876  void releaseBuffer(int32_t newLength=-1);
2877 
2908  inline const char16_t *getBuffer() const;
2909 
2943  const char16_t *getTerminatedBuffer();
2944 
2945  //========================================
2946  // Constructors
2947  //========================================
2948 
2952  inline UnicodeString();
2953 
2965  UnicodeString(int32_t capacity, UChar32 c, int32_t count);
2966 
2976  UNISTR_FROM_CHAR_EXPLICIT UnicodeString(char16_t ch);
2977 
2987  UNISTR_FROM_CHAR_EXPLICIT UnicodeString(UChar32 ch);
2988 
2999  UNISTR_FROM_STRING_EXPLICIT UnicodeString(const char16_t *text);
3000 
3001 #if !U_CHAR16_IS_TYPEDEF
3002 
3013  UnicodeString(ConstChar16Ptr(text)) {}
3014 #endif
3015 
3016 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
3017 
3029  UnicodeString(ConstChar16Ptr(text)) {}
3030 #endif
3031 
3042  UNISTR_FROM_STRING_EXPLICIT inline UnicodeString(const std::nullptr_t text);
3043 
3051  UnicodeString(const char16_t *text,
3052  int32_t textLength);
3053 
3054 #if !U_CHAR16_IS_TYPEDEF
3055 
3062  UnicodeString(const uint16_t *text, int32_t length) :
3063  UnicodeString(ConstChar16Ptr(text), length) {}
3064 #endif
3065 
3066 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
3067 
3075  UnicodeString(const wchar_t *text, int32_t length) :
3076  UnicodeString(ConstChar16Ptr(text), length) {}
3077 #endif
3078 
3086  inline UnicodeString(const std::nullptr_t text, int32_t length);
3087 
3110  UnicodeString(UBool isTerminated,
3111  ConstChar16Ptr text,
3112  int32_t textLength);
3113 
3132  UnicodeString(char16_t *buffer, int32_t buffLength, int32_t buffCapacity);
3133 
3134 #if !U_CHAR16_IS_TYPEDEF
3135 
3143  UnicodeString(uint16_t *buffer, int32_t buffLength, int32_t buffCapacity) :
3144  UnicodeString(Char16Ptr(buffer), buffLength, buffCapacity) {}
3145 #endif
3146 
3147 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
3148 
3157  UnicodeString(wchar_t *buffer, int32_t buffLength, int32_t buffCapacity) :
3158  UnicodeString(Char16Ptr(buffer), buffLength, buffCapacity) {}
3159 #endif
3160 
3169  inline UnicodeString(std::nullptr_t buffer, int32_t buffLength, int32_t buffCapacity);
3170 
3171 #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
3172 
3192  UNISTR_FROM_STRING_EXPLICIT UnicodeString(const char *codepageData);
3193 
3202  UnicodeString(const char *codepageData, int32_t dataLength);
3203 
3204 #endif
3205 
3206 #if !UCONFIG_NO_CONVERSION
3207 
3225  UnicodeString(const char *codepageData, const char *codepage);
3226 
3244  UnicodeString(const char *codepageData, int32_t dataLength, const char *codepage);
3245 
3267  UnicodeString(
3268  const char *src, int32_t srcLength,
3269  UConverter *cnv,
3270  UErrorCode &errorCode);
3271 
3272 #endif
3273 
3298  UnicodeString(const char *src, int32_t length, enum EInvariant inv);
3299 
3300 
3317  UnicodeString(const UnicodeString& that);
3318 
3325  UnicodeString(UnicodeString &&src) U_NOEXCEPT;
3326 
3333  UnicodeString(const UnicodeString& src, int32_t srcStart);
3334 
3342  UnicodeString(const UnicodeString& src, int32_t srcStart, int32_t srcLength);
3343 
3360  virtual Replaceable *clone() const;
3361 
3365  virtual ~UnicodeString();
3366 
3380  static UnicodeString fromUTF8(StringPiece utf8);
3381 
3393  static UnicodeString fromUTF32(const UChar32 *utf32, int32_t length);
3394 
3395  /* Miscellaneous operations */
3396 
3431  UnicodeString unescape() const;
3432 
3452  UChar32 unescapeAt(int32_t &offset) const;
3453 
3459  static UClassID U_EXPORT2 getStaticClassID();
3460 
3466  virtual UClassID getDynamicClassID() const;
3467 
3468  //========================================
3469  // Implementation methods
3470  //========================================
3471 
3472 protected:
3477  virtual int32_t getLength() const;
3478 
3484  virtual char16_t getCharAt(int32_t offset) const;
3485 
3491  virtual UChar32 getChar32At(int32_t offset) const;
3492 
3493 private:
3494  // For char* constructors. Could be made public.
3495  UnicodeString &setToUTF8(StringPiece utf8);
3496  // For extract(char*).
3497  // We could make a toUTF8(target, capacity, errorCode) public but not
3498  // this version: New API will be cleaner if we make callers create substrings
3499  // rather than having start+length on every method,
3500  // and it should take a UErrorCode&.
3501  int32_t
3502  toUTF8(int32_t start, int32_t len,
3503  char *target, int32_t capacity) const;
3504 
3509  UBool doEquals(const UnicodeString &text, int32_t len) const;
3510 
3511  inline int8_t
3512  doCompare(int32_t start,
3513  int32_t length,
3514  const UnicodeString& srcText,
3515  int32_t srcStart,
3516  int32_t srcLength) const;
3517 
3518  int8_t doCompare(int32_t start,
3519  int32_t length,
3520  const char16_t *srcChars,
3521  int32_t srcStart,
3522  int32_t srcLength) const;
3523 
3524  inline int8_t
3525  doCompareCodePointOrder(int32_t start,
3526  int32_t length,
3527  const UnicodeString& srcText,
3528  int32_t srcStart,
3529  int32_t srcLength) const;
3530 
3531  int8_t doCompareCodePointOrder(int32_t start,
3532  int32_t length,
3533  const char16_t *srcChars,
3534  int32_t srcStart,
3535  int32_t srcLength) const;
3536 
3537  inline int8_t
3538  doCaseCompare(int32_t start,
3539  int32_t length,
3540  const UnicodeString &srcText,
3541  int32_t srcStart,
3542  int32_t srcLength,
3543  uint32_t options) const;
3544 
3545  int8_t
3546  doCaseCompare(int32_t start,
3547  int32_t length,
3548  const char16_t *srcChars,
3549  int32_t srcStart,
3550  int32_t srcLength,
3551  uint32_t options) const;
3552 
3553  int32_t doIndexOf(char16_t c,
3554  int32_t start,
3555  int32_t length) const;
3556 
3557  int32_t doIndexOf(UChar32 c,
3558  int32_t start,
3559  int32_t length) const;
3560 
3561  int32_t doLastIndexOf(char16_t c,
3562  int32_t start,
3563  int32_t length) const;
3564 
3565  int32_t doLastIndexOf(UChar32 c,
3566  int32_t start,
3567  int32_t length) const;
3568 
3569  void doExtract(int32_t start,
3570  int32_t length,
3571  char16_t *dst,
3572  int32_t dstStart) const;
3573 
3574  inline void doExtract(int32_t start,
3575  int32_t length,
3576  UnicodeString& target) const;
3577 
3578  inline char16_t doCharAt(int32_t offset) const;
3579 
3580  UnicodeString& doReplace(int32_t start,
3581  int32_t length,
3582  const UnicodeString& srcText,
3583  int32_t srcStart,
3584  int32_t srcLength);
3585 
3586  UnicodeString& doReplace(int32_t start,
3587  int32_t length,
3588  const char16_t *srcChars,
3589  int32_t srcStart,
3590  int32_t srcLength);
3591 
3592  UnicodeString& doAppend(const UnicodeString& src, int32_t srcStart, int32_t srcLength);
3593  UnicodeString& doAppend(const char16_t *srcChars, int32_t srcStart, int32_t srcLength);
3594 
3595  UnicodeString& doReverse(int32_t start,
3596  int32_t length);
3597 
3598  // calculate hash code
3599  int32_t doHashCode(void) const;
3600 
3601  // get pointer to start of array
3602  // these do not check for kOpenGetBuffer, unlike the public getBuffer() function
3603  inline char16_t* getArrayStart(void);
3604  inline const char16_t* getArrayStart(void) const;
3605 
3606  inline UBool hasShortLength() const;
3607  inline int32_t getShortLength() const;
3608 
3609  // A UnicodeString object (not necessarily its current buffer)
3610  // is writable unless it isBogus() or it has an "open" getBuffer(minCapacity).
3611  inline UBool isWritable() const;
3612 
3613  // Is the current buffer writable?
3614  inline UBool isBufferWritable() const;
3615 
3616  // None of the following does releaseArray().
3617  inline void setZeroLength();
3618  inline void setShortLength(int32_t len);
3619  inline void setLength(int32_t len);
3620  inline void setToEmpty();
3621  inline void setArray(char16_t *array, int32_t len, int32_t capacity); // sets length but not flags
3622 
3623  // allocate the array; result may be the stack buffer
3624  // sets refCount to 1 if appropriate
3625  // sets fArray, fCapacity, and flags
3626  // sets length to 0
3627  // returns boolean for success or failure
3628  UBool allocate(int32_t capacity);
3629 
3630  // release the array if owned
3631  void releaseArray(void);
3632 
3633  // turn a bogus string into an empty one
3634  void unBogus();
3635 
3636  // implements assigment operator, copy constructor, and fastCopyFrom()
3637  UnicodeString &copyFrom(const UnicodeString &src, UBool fastCopy=FALSE);
3638 
3639  // Copies just the fields without memory management.
3640  void copyFieldsFrom(UnicodeString &src, UBool setSrcToBogus) U_NOEXCEPT;
3641 
3642  // Pin start and limit to acceptable values.
3643  inline void pinIndex(int32_t& start) const;
3644  inline void pinIndices(int32_t& start,
3645  int32_t& length) const;
3646 
3647 #if !UCONFIG_NO_CONVERSION
3648 
3649  /* Internal extract() using UConverter. */
3650  int32_t doExtract(int32_t start, int32_t length,
3651  char *dest, int32_t destCapacity,
3652  UConverter *cnv,
3653  UErrorCode &errorCode) const;
3654 
3655  /*
3656  * Real constructor for converting from codepage data.
3657  * It assumes that it is called with !fRefCounted.
3658  *
3659  * If <code>codepage==0</code>, then the default converter
3660  * is used for the platform encoding.
3661  * If <code>codepage</code> is an empty string (<code>""</code>),
3662  * then a simple conversion is performed on the codepage-invariant
3663  * subset ("invariant characters") of the platform encoding. See utypes.h.
3664  */
3665  void doCodepageCreate(const char *codepageData,
3666  int32_t dataLength,
3667  const char *codepage);
3668 
3669  /*
3670  * Worker function for creating a UnicodeString from
3671  * a codepage string using a UConverter.
3672  */
3673  void
3674  doCodepageCreate(const char *codepageData,
3675  int32_t dataLength,
3676  UConverter *converter,
3677  UErrorCode &status);
3678 
3679 #endif
3680 
3681  /*
3682  * This function is called when write access to the array
3683  * is necessary.
3684  *
3685  * We need to make a copy of the array if
3686  * the buffer is read-only, or
3687  * the buffer is refCounted (shared), and refCount>1, or
3688  * the buffer is too small.
3689  *
3690  * Return FALSE if memory could not be allocated.
3691  */
3692  UBool cloneArrayIfNeeded(int32_t newCapacity = -1,
3693  int32_t growCapacity = -1,
3694  UBool doCopyArray = TRUE,
3695  int32_t **pBufferToDelete = 0,
3696  UBool forceClone = FALSE);
3697 
3703  UnicodeString &
3704  caseMap(int32_t caseLocale, uint32_t options,
3706  BreakIterator *iter,
3707 #endif
3708  UStringCaseMapper *stringCaseMapper);
3709 
3710  // ref counting
3711  void addRef(void);
3712  int32_t removeRef(void);
3713  int32_t refCount(void) const;
3714 
3715  // constants
3716  enum {
3722  US_STACKBUF_SIZE=(int32_t)(UNISTR_OBJECT_SIZE-sizeof(void *)-2)/U_SIZEOF_UCHAR,
3723  kInvalidUChar=0xffff, // U+FFFF returned by charAt(invalid index)
3724  kInvalidHashCode=0, // invalid hash code
3725  kEmptyHashCode=1, // hash code for empty string
3726 
3727  // bit flag values for fLengthAndFlags
3728  kIsBogus=1, // this string is bogus, i.e., not valid or NULL
3729  kUsingStackBuffer=2,// using fUnion.fStackFields instead of fUnion.fFields
3730  kRefCounted=4, // there is a refCount field before the characters in fArray
3731  kBufferIsReadonly=8,// do not write to this buffer
3732  kOpenGetBuffer=16, // getBuffer(minCapacity) was called (is "open"),
3733  // and releaseBuffer(newLength) must be called
3734  kAllStorageFlags=0x1f,
3735 
3736  kLengthShift=5, // remaining 11 bits for non-negative short length, or negative if long
3737  kLength1=1<<kLengthShift,
3738  kMaxShortLength=0x3ff, // max non-negative short length (leaves top bit 0)
3739  kLengthIsLarge=0xffe0, // short length < 0, real length is in fUnion.fFields.fLength
3740 
3741  // combined values for convenience
3742  kShortString=kUsingStackBuffer,
3743  kLongString=kRefCounted,
3744  kReadonlyAlias=kBufferIsReadonly,
3745  kWritableAlias=0
3746  };
3747 
3748  friend class UnicodeStringAppendable;
3749 
3750  union StackBufferOrFields; // forward declaration necessary before friend declaration
3751  friend union StackBufferOrFields; // make US_STACKBUF_SIZE visible inside fUnion
3752 
3753  /*
3754  * The following are all the class fields that are stored
3755  * in each UnicodeString object.
3756  * Note that UnicodeString has virtual functions,
3757  * therefore there is an implicit vtable pointer
3758  * as the first real field.
3759  * The fields should be aligned such that no padding is necessary.
3760  * On 32-bit machines, the size should be 32 bytes,
3761  * on 64-bit machines (8-byte pointers), it should be 40 bytes.
3762  *
3763  * We use a hack to achieve this.
3764  *
3765  * With at least some compilers, each of the following is forced to
3766  * a multiple of sizeof(pointer) [the largest field base unit here is a data pointer],
3767  * rounded up with additional padding if the fields do not already fit that requirement:
3768  * - sizeof(class UnicodeString)
3769  * - offsetof(UnicodeString, fUnion)
3770  * - sizeof(fUnion)
3771  * - sizeof(fStackFields)
3772  *
3773  * We optimize for the longest possible internal buffer for short strings.
3774  * fUnion.fStackFields begins with 2 bytes for storage flags
3775  * and the length of relatively short strings,
3776  * followed by the buffer for short string contents.
3777  * There is no padding inside fStackFields.
3778  *
3779  * Heap-allocated and aliased strings use fUnion.fFields.
3780  * Both fStackFields and fFields must begin with the same fields for flags and short length,
3781  * that is, those must have the same memory offsets inside the object,
3782  * because the flags must be inspected in order to decide which half of fUnion is being used.
3783  * We assume that the compiler does not reorder the fields.
3784  *
3785  * (Padding at the end of fFields is ok:
3786  * As long as it is no larger than fStackFields, it is not wasted space.)
3787  *
3788  * For some of the history of the UnicodeString class fields layout, see
3789  * - ICU ticket #11551 "longer UnicodeString contents in stack buffer"
3790  * - ICU ticket #11336 "UnicodeString: recombine stack buffer arrays"
3791  * - ICU ticket #8322 "why is sizeof(UnicodeString)==48?"
3792  */
3793  // (implicit) *vtable;
3794  union StackBufferOrFields {
3795  // fStackFields is used iff (fLengthAndFlags&kUsingStackBuffer) else fFields is used.
3796  // Each struct of the union must begin with fLengthAndFlags.
3797  struct {
3798  int16_t fLengthAndFlags; // bit fields: see constants above
3799  char16_t fBuffer[US_STACKBUF_SIZE]; // buffer for short strings
3800  } fStackFields;
3801  struct {
3802  int16_t fLengthAndFlags; // bit fields: see constants above
3803  int32_t fLength; // number of characters in fArray if >127; else undefined
3804  int32_t fCapacity; // capacity of fArray (in char16_ts)
3805  // array pointer last to minimize padding for machines with P128 data model
3806  // or pointer sizes that are not a power of 2
3807  char16_t *fArray; // the Unicode data
3808  } fFields;
3809  } fUnion;
3810 };
3811 
3820 U_COMMON_API UnicodeString U_EXPORT2
3821 operator+ (const UnicodeString &s1, const UnicodeString &s2);
3822 
3823 //========================================
3824 // Inline members
3825 //========================================
3826 
3827 //========================================
3828 // Privates
3829 //========================================
3830 
3831 inline void
3832 UnicodeString::pinIndex(int32_t& start) const
3833 {
3834  // pin index
3835  if(start < 0) {
3836  start = 0;
3837  } else if(start > length()) {
3838  start = length();
3839  }
3840 }
3841 
3842 inline void
3843 UnicodeString::pinIndices(int32_t& start,
3844  int32_t& _length) const
3845 {
3846  // pin indices
3847  int32_t len = length();
3848  if(start < 0) {
3849  start = 0;
3850  } else if(start > len) {
3851  start = len;
3852  }
3853  if(_length < 0) {
3854  _length = 0;
3855  } else if(_length > (len - start)) {
3856  _length = (len - start);
3857  }
3858 }
3859 
3860 inline char16_t*
3861 UnicodeString::getArrayStart() {
3862  return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3863  fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
3864 }
3865 
3866 inline const char16_t*
3867 UnicodeString::getArrayStart() const {
3868  return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3869  fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
3870 }
3871 
3872 //========================================
3873 // Default constructor
3874 //========================================
3875 
3876 inline
3877 UnicodeString::UnicodeString() {
3878  fUnion.fStackFields.fLengthAndFlags=kShortString;
3879 }
3880 
3881 inline UnicodeString::UnicodeString(const std::nullptr_t /*text*/) {
3882  fUnion.fStackFields.fLengthAndFlags=kShortString;
3883 }
3884 
3885 inline UnicodeString::UnicodeString(const std::nullptr_t /*text*/, int32_t /*length*/) {
3886  fUnion.fStackFields.fLengthAndFlags=kShortString;
3887 }
3888 
3889 inline UnicodeString::UnicodeString(std::nullptr_t /*buffer*/, int32_t /*buffLength*/, int32_t /*buffCapacity*/) {
3890  fUnion.fStackFields.fLengthAndFlags=kShortString;
3891 }
3892 
3893 //========================================
3894 // Read-only implementation methods
3895 //========================================
3896 inline UBool
3897 UnicodeString::hasShortLength() const {
3898  return fUnion.fFields.fLengthAndFlags>=0;
3899 }
3900 
3901 inline int32_t
3902 UnicodeString::getShortLength() const {
3903  // fLengthAndFlags must be non-negative -> short length >= 0
3904  // and arithmetic or logical shift does not matter.
3905  return fUnion.fFields.fLengthAndFlags>>kLengthShift;
3906 }
3907 
3908 inline int32_t
3909 UnicodeString::length() const {
3910  return hasShortLength() ? getShortLength() : fUnion.fFields.fLength;
3911 }
3912 
3913 inline int32_t
3914 UnicodeString::getCapacity() const {
3915  return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3916  US_STACKBUF_SIZE : fUnion.fFields.fCapacity;
3917 }
3918 
3919 inline int32_t
3920 UnicodeString::hashCode() const
3921 { return doHashCode(); }
3922 
3923 inline UBool
3924 UnicodeString::isBogus() const
3925 { return (UBool)(fUnion.fFields.fLengthAndFlags & kIsBogus); }
3926 
3927 inline UBool
3928 UnicodeString::isWritable() const
3929 { return (UBool)!(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus)); }
3930 
3931 inline UBool
3932 UnicodeString::isBufferWritable() const
3933 {
3934  return (UBool)(
3935  !(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus|kBufferIsReadonly)) &&
3936  (!(fUnion.fFields.fLengthAndFlags&kRefCounted) || refCount()==1));
3937 }
3938 
3939 inline const char16_t *
3940 UnicodeString::getBuffer() const {
3941  if(fUnion.fFields.fLengthAndFlags&(kIsBogus|kOpenGetBuffer)) {
3942  return nullptr;
3943  } else if(fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) {
3944  return fUnion.fStackFields.fBuffer;
3945  } else {
3946  return fUnion.fFields.fArray;
3947  }
3948 }
3949 
3950 //========================================
3951 // Read-only alias methods
3952 //========================================
3953 inline int8_t
3954 UnicodeString::doCompare(int32_t start,
3955  int32_t thisLength,
3956  const UnicodeString& srcText,
3957  int32_t srcStart,
3958  int32_t srcLength) const
3959 {
3960  if(srcText.isBogus()) {
3961  return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
3962  } else {
3963  srcText.pinIndices(srcStart, srcLength);
3964  return doCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
3965  }
3966 }
3967 
3968 inline UBool
3970 {
3971  if(isBogus()) {
3972  return text.isBogus();
3973  } else {
3974  int32_t len = length(), textLength = text.length();
3975  return !text.isBogus() && len == textLength && doEquals(text, len);
3976  }
3977 }
3978 
3979 inline UBool
3981 { return (! operator==(text)); }
3982 
3983 inline UBool
3984 UnicodeString::operator> (const UnicodeString& text) const
3985 { return doCompare(0, length(), text, 0, text.length()) == 1; }
3986 
3987 inline UBool
3988 UnicodeString::operator< (const UnicodeString& text) const
3989 { return doCompare(0, length(), text, 0, text.length()) == -1; }
3990 
3991 inline UBool
3992 UnicodeString::operator>= (const UnicodeString& text) const
3993 { return doCompare(0, length(), text, 0, text.length()) != -1; }
3994 
3995 inline UBool
3996 UnicodeString::operator<= (const UnicodeString& text) const
3997 { return doCompare(0, length(), text, 0, text.length()) != 1; }
3998 
3999 inline int8_t
4000 UnicodeString::compare(const UnicodeString& text) const
4001 { return doCompare(0, length(), text, 0, text.length()); }
4002 
4003 inline int8_t
4004 UnicodeString::compare(int32_t start,
4005  int32_t _length,
4006  const UnicodeString& srcText) const
4007 { return doCompare(start, _length, srcText, 0, srcText.length()); }
4008 
4009 inline int8_t
4010 UnicodeString::compare(ConstChar16Ptr srcChars,
4011  int32_t srcLength) const
4012 { return doCompare(0, length(), srcChars, 0, srcLength); }
4013 
4014 inline int8_t
4015 UnicodeString::compare(int32_t start,
4016  int32_t _length,
4017  const UnicodeString& srcText,
4018  int32_t srcStart,
4019  int32_t srcLength) const
4020 { return doCompare(start, _length, srcText, srcStart, srcLength); }
4021 
4022 inline int8_t
4023 UnicodeString::compare(int32_t start,
4024  int32_t _length,
4025  const char16_t *srcChars) const
4026 { return doCompare(start, _length, srcChars, 0, _length); }
4027 
4028 inline int8_t
4029 UnicodeString::compare(int32_t start,
4030  int32_t _length,
4031  const char16_t *srcChars,
4032  int32_t srcStart,
4033  int32_t srcLength) const
4034 { return doCompare(start, _length, srcChars, srcStart, srcLength); }
4035 
4036 inline int8_t
4037 UnicodeString::compareBetween(int32_t start,
4038  int32_t limit,
4039  const UnicodeString& srcText,
4040  int32_t srcStart,
4041  int32_t srcLimit) const
4042 { return doCompare(start, limit - start,
4043  srcText, srcStart, srcLimit - srcStart); }
4044 
4045 inline int8_t
4046 UnicodeString::doCompareCodePointOrder(int32_t start,
4047  int32_t thisLength,
4048  const UnicodeString& srcText,
4049  int32_t srcStart,
4050  int32_t srcLength) const
4051 {
4052  if(srcText.isBogus()) {
4053  return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
4054  } else {
4055  srcText.pinIndices(srcStart, srcLength);
4056  return doCompareCodePointOrder(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
4057  }
4058 }
4059 
4060 inline int8_t
4061 UnicodeString::compareCodePointOrder(const UnicodeString& text) const
4062 { return doCompareCodePointOrder(0, length(), text, 0, text.length()); }
4063 
4064 inline int8_t
4065 UnicodeString::compareCodePointOrder(int32_t start,
4066  int32_t _length,
4067  const UnicodeString& srcText) const
4068 { return doCompareCodePointOrder(start, _length, srcText, 0, srcText.length()); }
4069 
4070 inline int8_t
4071 UnicodeString::compareCodePointOrder(ConstChar16Ptr srcChars,
4072  int32_t srcLength) const
4073 { return doCompareCodePointOrder(0, length(), srcChars, 0, srcLength); }
4074 
4075 inline int8_t
4076 UnicodeString::compareCodePointOrder(int32_t start,
4077  int32_t _length,
4078  const UnicodeString& srcText,
4079  int32_t srcStart,
4080  int32_t srcLength) const
4081 { return doCompareCodePointOrder(start, _length, srcText, srcStart, srcLength); }
4082 
4083 inline int8_t
4084 UnicodeString::compareCodePointOrder(int32_t start,
4085  int32_t _length,
4086  const char16_t *srcChars) const
4087 { return doCompareCodePointOrder(start, _length, srcChars, 0, _length); }
4088 
4089 inline int8_t
4090 UnicodeString::compareCodePointOrder(int32_t start,
4091  int32_t _length,
4092  const char16_t *srcChars,
4093  int32_t srcStart,
4094  int32_t srcLength) const
4095 { return doCompareCodePointOrder(start, _length, srcChars, srcStart, srcLength); }
4096 
4097 inline int8_t
4098 UnicodeString::compareCodePointOrderBetween(int32_t start,
4099  int32_t limit,
4100  const UnicodeString& srcText,
4101  int32_t srcStart,
4102  int32_t srcLimit) const
4103 { return doCompareCodePointOrder(start, limit - start,
4104  srcText, srcStart, srcLimit - srcStart); }
4105 
4106 inline int8_t
4107 UnicodeString::doCaseCompare(int32_t start,
4108  int32_t thisLength,
4109  const UnicodeString &srcText,
4110  int32_t srcStart,
4111  int32_t srcLength,
4112  uint32_t options) const
4113 {
4114  if(srcText.isBogus()) {
4115  return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
4116  } else {
4117  srcText.pinIndices(srcStart, srcLength);
4118  return doCaseCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength, options);
4119  }
4120 }
4121 
4122 inline int8_t
4123 UnicodeString::caseCompare(const UnicodeString &text, uint32_t options) const {
4124  return doCaseCompare(0, length(), text, 0, text.length(), options);
4125 }
4126 
4127 inline int8_t
4128 UnicodeString::caseCompare(int32_t start,
4129  int32_t _length,
4130  const UnicodeString &srcText,
4131  uint32_t options) const {
4132  return doCaseCompare(start, _length, srcText, 0, srcText.length(), options);
4133 }
4134 
4135 inline int8_t
4136 UnicodeString::caseCompare(ConstChar16Ptr srcChars,
4137  int32_t srcLength,
4138  uint32_t options) const {
4139  return doCaseCompare(0, length(), srcChars, 0, srcLength, options);
4140 }
4141 
4142 inline int8_t
4143 UnicodeString::caseCompare(int32_t start,
4144  int32_t _length,
4145  const UnicodeString &srcText,
4146  int32_t srcStart,
4147  int32_t srcLength,
4148  uint32_t options) const {
4149  return doCaseCompare(start, _length, srcText, srcStart, srcLength, options);
4150 }
4151 
4152 inline int8_t
4153 UnicodeString::caseCompare(int32_t start,
4154  int32_t _length,
4155  const char16_t *srcChars,
4156  uint32_t options) const {
4157  return doCaseCompare(start, _length, srcChars, 0, _length, options);
4158 }
4159 
4160 inline int8_t
4161 UnicodeString::caseCompare(int32_t start,
4162  int32_t _length,
4163  const char16_t *srcChars,
4164  int32_t srcStart,
4165  int32_t srcLength,
4166  uint32_t options) const {
4167  return doCaseCompare(start, _length, srcChars, srcStart, srcLength, options);
4168 }
4169 
4170 inline int8_t
4171 UnicodeString::caseCompareBetween(int32_t start,
4172  int32_t limit,
4173  const UnicodeString &srcText,
4174  int32_t srcStart,
4175  int32_t srcLimit,
4176  uint32_t options) const {
4177  return doCaseCompare(start, limit - start, srcText, srcStart, srcLimit - srcStart, options);
4178 }
4179 
4180 inline int32_t
4181 UnicodeString::indexOf(const UnicodeString& srcText,
4182  int32_t srcStart,
4183  int32_t srcLength,
4184  int32_t start,
4185  int32_t _length) const
4186 {
4187  if(!srcText.isBogus()) {
4188  srcText.pinIndices(srcStart, srcLength);
4189  if(srcLength > 0) {
4190  return indexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
4191  }
4192  }
4193  return -1;
4194 }
4195 
4196 inline int32_t
4197 UnicodeString::indexOf(const UnicodeString& text) const
4198 { return indexOf(text, 0, text.length(), 0, length()); }
4199 
4200 inline int32_t
4201 UnicodeString::indexOf(const UnicodeString& text,
4202  int32_t start) const {
4203  pinIndex(start);
4204  return indexOf(text, 0, text.length(), start, length() - start);
4205 }
4206 
4207 inline int32_t
4208 UnicodeString::indexOf(const UnicodeString& text,
4209  int32_t start,
4210  int32_t _length) const
4211 { return indexOf(text, 0, text.length(), start, _length); }
4212 
4213 inline int32_t
4214 UnicodeString::indexOf(const char16_t *srcChars,
4215  int32_t srcLength,
4216  int32_t start) const {
4217  pinIndex(start);
4218  return indexOf(srcChars, 0, srcLength, start, length() - start);
4219 }
4220 
4221 inline int32_t
4222 UnicodeString::indexOf(ConstChar16Ptr srcChars,
4223  int32_t srcLength,
4224  int32_t start,
4225  int32_t _length) const
4226 { return indexOf(srcChars, 0, srcLength, start, _length); }
4227 
4228 inline int32_t
4229 UnicodeString::indexOf(char16_t c,
4230  int32_t start,
4231  int32_t _length) const
4232 { return doIndexOf(c, start, _length); }
4233 
4234 inline int32_t
4235 UnicodeString::indexOf(UChar32 c,
4236  int32_t start,
4237  int32_t _length) const
4238 { return doIndexOf(c, start, _length); }
4239 
4240 inline int32_t
4241 UnicodeString::indexOf(char16_t c) const
4242 { return doIndexOf(c, 0, length()); }
4243 
4244 inline int32_t
4245 UnicodeString::indexOf(UChar32 c) const
4246 { return indexOf(c, 0, length()); }
4247 
4248 inline int32_t
4249 UnicodeString::indexOf(char16_t c,
4250  int32_t start) const {
4251  pinIndex(start);
4252  return doIndexOf(c, start, length() - start);
4253 }
4254 
4255 inline int32_t
4256 UnicodeString::indexOf(UChar32 c,
4257  int32_t start) const {
4258  pinIndex(start);
4259  return indexOf(c, start, length() - start);
4260 }
4261 
4262 inline int32_t
4263 UnicodeString::lastIndexOf(ConstChar16Ptr srcChars,
4264  int32_t srcLength,
4265  int32_t start,
4266  int32_t _length) const
4267 { return lastIndexOf(srcChars, 0, srcLength, start, _length); }
4268 
4269 inline int32_t
4270 UnicodeString::lastIndexOf(const char16_t *srcChars,
4271  int32_t srcLength,
4272  int32_t start) const {
4273  pinIndex(start);
4274  return lastIndexOf(srcChars, 0, srcLength, start, length() - start);
4275 }
4276 
4277 inline int32_t
4278 UnicodeString::lastIndexOf(const UnicodeString& srcText,
4279  int32_t srcStart,
4280  int32_t srcLength,
4281  int32_t start,
4282  int32_t _length) const
4283 {
4284  if(!srcText.isBogus()) {
4285  srcText.pinIndices(srcStart, srcLength);
4286  if(srcLength > 0) {
4287  return lastIndexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
4288  }
4289  }
4290  return -1;
4291 }
4292 
4293 inline int32_t
4294 UnicodeString::lastIndexOf(const UnicodeString& text,
4295  int32_t start,
4296  int32_t _length) const
4297 { return lastIndexOf(text, 0, text.length(), start, _length); }
4298 
4299 inline int32_t
4300 UnicodeString::lastIndexOf(const UnicodeString& text,
4301  int32_t start) const {
4302  pinIndex(start);
4303  return lastIndexOf(text, 0, text.length(), start, length() - start);
4304 }
4305 
4306 inline int32_t
4307 UnicodeString::lastIndexOf(const UnicodeString& text) const
4308 { return lastIndexOf(text, 0, text.length(), 0, length()); }
4309 
4310 inline int32_t
4311 UnicodeString::lastIndexOf(char16_t c,
4312  int32_t start,
4313  int32_t _length) const
4314 { return doLastIndexOf(c, start, _length); }
4315 
4316 inline int32_t
4317 UnicodeString::lastIndexOf(UChar32 c,
4318  int32_t start,
4319  int32_t _length) const {
4320  return doLastIndexOf(c, start, _length);
4321 }
4322 
4323 inline int32_t
4324 UnicodeString::lastIndexOf(char16_t c) const
4325 { return doLastIndexOf(c, 0, length()); }
4326 
4327 inline int32_t
4328 UnicodeString::lastIndexOf(UChar32 c) const {
4329  return lastIndexOf(c, 0, length());
4330 }
4331 
4332 inline int32_t
4333 UnicodeString::lastIndexOf(char16_t c,
4334  int32_t start) const {
4335  pinIndex(start);
4336  return doLastIndexOf(c, start, length() - start);
4337 }
4338 
4339 inline int32_t
4340 UnicodeString::lastIndexOf(UChar32 c,
4341  int32_t start) const {
4342  pinIndex(start);
4343  return lastIndexOf(c, start, length() - start);
4344 }
4345 
4346 inline UBool
4347 UnicodeString::startsWith(const UnicodeString& text) const
4348 { return compare(0, text.length(), text, 0, text.length()) == 0; }
4349 
4350 inline UBool
4351 UnicodeString::startsWith(const UnicodeString& srcText,
4352  int32_t srcStart,
4353  int32_t srcLength) const
4354 { return doCompare(0, srcLength, srcText, srcStart, srcLength) == 0; }
4355 
4356 inline UBool
4357 UnicodeString::startsWith(ConstChar16Ptr srcChars, int32_t srcLength) const {
4358  if(srcLength < 0) {
4359  srcLength = u_strlen(toUCharPtr(srcChars));
4360  }
4361  return doCompare(0, srcLength, srcChars, 0, srcLength) == 0;
4362 }
4363 
4364 inline UBool
4365 UnicodeString::startsWith(const char16_t *srcChars, int32_t srcStart, int32_t srcLength) const {
4366  if(srcLength < 0) {
4367  srcLength = u_strlen(toUCharPtr(srcChars));
4368  }
4369  return doCompare(0, srcLength, srcChars, srcStart, srcLength) == 0;
4370 }
4371 
4372 inline UBool
4373 UnicodeString::endsWith(const UnicodeString& text) const
4374 { return doCompare(length() - text.length(), text.length(),
4375  text, 0, text.length()) == 0; }
4376 
4377 inline UBool
4378 UnicodeString::endsWith(const UnicodeString& srcText,
4379  int32_t srcStart,
4380  int32_t srcLength) const {
4381  srcText.pinIndices(srcStart, srcLength);
4382  return doCompare(length() - srcLength, srcLength,
4383  srcText, srcStart, srcLength) == 0;
4384 }
4385 
4386 inline UBool
4387 UnicodeString::endsWith(ConstChar16Ptr srcChars,
4388  int32_t srcLength) const {
4389  if(srcLength < 0) {
4390  srcLength = u_strlen(toUCharPtr(srcChars));
4391  }
4392  return doCompare(length() - srcLength, srcLength,
4393  srcChars, 0, srcLength) == 0;
4394 }
4395 
4396 inline UBool
4397 UnicodeString::endsWith(const char16_t *srcChars,
4398  int32_t srcStart,
4399  int32_t srcLength) const {
4400  if(srcLength < 0) {
4401  srcLength = u_strlen(toUCharPtr(srcChars + srcStart));
4402  }
4403  return doCompare(length() - srcLength, srcLength,
4404  srcChars, srcStart, srcLength) == 0;
4405 }
4406 
4407 //========================================
4408 // replace
4409 //========================================
4410 inline UnicodeString&
4411 UnicodeString::replace(int32_t start,
4412  int32_t _length,
4413  const UnicodeString& srcText)
4414 { return doReplace(start, _length, srcText, 0, srcText.length()); }
4415 
4416 inline UnicodeString&
4417 UnicodeString::replace(int32_t start,
4418  int32_t _length,
4419  const UnicodeString& srcText,
4420  int32_t srcStart,
4421  int32_t srcLength)
4422 { return doReplace(start, _length, srcText, srcStart, srcLength); }
4423 
4424 inline UnicodeString&
4425 UnicodeString::replace(int32_t start,
4426  int32_t _length,
4427  ConstChar16Ptr srcChars,
4428  int32_t srcLength)
4429 { return doReplace(start, _length, srcChars, 0, srcLength); }
4430 
4431 inline UnicodeString&
4432 UnicodeString::replace(int32_t start,
4433  int32_t _length,
4434  const char16_t *srcChars,
4435  int32_t srcStart,
4436  int32_t srcLength)
4437 { return doReplace(start, _length, srcChars, srcStart, srcLength); }
4438 
4439 inline UnicodeString&
4440 UnicodeString::replace(int32_t start,
4441  int32_t _length,
4442  char16_t srcChar)
4443 { return doReplace(start, _length, &srcChar, 0, 1); }
4444 
4445 inline UnicodeString&
4446 UnicodeString::replaceBetween(int32_t start,
4447  int32_t limit,
4448  const UnicodeString& srcText)
4449 { return doReplace(start, limit - start, srcText, 0, srcText.length()); }
4450 
4451 inline UnicodeString&
4452 UnicodeString::replaceBetween(int32_t start,
4453  int32_t limit,
4454  const UnicodeString& srcText,
4455  int32_t srcStart,
4456  int32_t srcLimit)
4457 { return doReplace(start, limit - start, srcText, srcStart, srcLimit - srcStart); }
4458 
4459 inline UnicodeString&
4460 UnicodeString::findAndReplace(const UnicodeString& oldText,
4461  const UnicodeString& newText)
4462 { return findAndReplace(0, length(), oldText, 0, oldText.length(),
4463  newText, 0, newText.length()); }
4464 
4465 inline UnicodeString&
4466 UnicodeString::findAndReplace(int32_t start,
4467  int32_t _length,
4468  const UnicodeString& oldText,
4469  const UnicodeString& newText)
4470 { return findAndReplace(start, _length, oldText, 0, oldText.length(),
4471  newText, 0, newText.length()); }
4472 
4473 // ============================
4474 // extract
4475 // ============================
4476 inline void
4477 UnicodeString::doExtract(int32_t start,
4478  int32_t _length,
4479  UnicodeString& target) const
4480 { target.replace(0, target.length(), *this, start, _length); }
4481 
4482 inline void
4483 UnicodeString::extract(int32_t start,
4484  int32_t _length,
4485  Char16Ptr target,
4486  int32_t targetStart) const
4487 { doExtract(start, _length, target, targetStart); }
4488 
4489 inline void
4490 UnicodeString::extract(int32_t start,
4491  int32_t _length,
4492  UnicodeString& target) const
4493 { doExtract(start, _length, target); }
4494 
4495 #if !UCONFIG_NO_CONVERSION
4496 
4497 inline int32_t
4498 UnicodeString::extract(int32_t start,
4499  int32_t _length,
4500  char *dst,
4501  const char *codepage) const
4502 
4503 {
4504  // This dstSize value will be checked explicitly
4505  return extract(start, _length, dst, dst!=0 ? 0xffffffff : 0, codepage);
4506 }
4507 
4508 #endif
4509 
4510 inline void
4511 UnicodeString::extractBetween(int32_t start,
4512  int32_t limit,
4513  char16_t *dst,
4514  int32_t dstStart) const {
4515  pinIndex(start);
4516  pinIndex(limit);
4517  doExtract(start, limit - start, dst, dstStart);
4518 }
4519 
4520 inline UnicodeString
4521 UnicodeString::tempSubStringBetween(int32_t start, int32_t limit) const {
4522  return tempSubString(start, limit - start);
4523 }
4524 
4525 inline char16_t
4526 UnicodeString::doCharAt(int32_t offset) const
4527 {
4528  if((uint32_t)offset < (uint32_t)length()) {
4529  return getArrayStart()[offset];
4530  } else {
4531  return kInvalidUChar;
4532  }
4533 }
4534 
4535 inline char16_t
4536 UnicodeString::charAt(int32_t offset) const
4537 { return doCharAt(offset); }
4538 
4539 inline char16_t
4540 UnicodeString::operator[] (int32_t offset) const
4541 { return doCharAt(offset); }
4542 
4543 inline UBool
4544 UnicodeString::isEmpty() const {
4545  // Arithmetic or logical right shift does not matter: only testing for 0.
4546  return (fUnion.fFields.fLengthAndFlags>>kLengthShift) == 0;
4547 }
4548 
4549 //========================================
4550 // Write implementation methods
4551 //========================================
4552 inline void
4553 UnicodeString::setZeroLength() {
4554  fUnion.fFields.fLengthAndFlags &= kAllStorageFlags;
4555 }
4556 
4557 inline void
4558 UnicodeString::setShortLength(int32_t len) {
4559  // requires 0 <= len <= kMaxShortLength
4560  fUnion.fFields.fLengthAndFlags =
4561  (int16_t)((fUnion.fFields.fLengthAndFlags & kAllStorageFlags) | (len << kLengthShift));
4562 }
4563 
4564 inline void
4565 UnicodeString::setLength(int32_t len) {
4566  if(len <= kMaxShortLength) {
4567  setShortLength(len);
4568  } else {
4569  fUnion.fFields.fLengthAndFlags |= kLengthIsLarge;
4570  fUnion.fFields.fLength = len;
4571  }
4572 }
4573 
4574 inline void
4575 UnicodeString::setToEmpty() {
4576  fUnion.fFields.fLengthAndFlags = kShortString;
4577 }
4578 
4579 inline void
4580 UnicodeString::setArray(char16_t *array, int32_t len, int32_t capacity) {
4581  setLength(len);
4582  fUnion.fFields.fArray = array;
4583  fUnion.fFields.fCapacity = capacity;
4584 }
4585 
4586 inline UnicodeString&
4587 UnicodeString::operator= (char16_t ch)
4588 { return doReplace(0, length(), &ch, 0, 1); }
4589 
4590 inline UnicodeString&
4591 UnicodeString::operator= (UChar32 ch)
4592 { return replace(0, length(), ch); }
4593 
4594 inline UnicodeString&
4595 UnicodeString::setTo(const UnicodeString& srcText,
4596  int32_t srcStart,
4597  int32_t srcLength)
4598 {
4599  unBogus();
4600  return doReplace(0, length(), srcText, srcStart, srcLength);
4601 }
4602 
4603 inline UnicodeString&
4604 UnicodeString::setTo(const UnicodeString& srcText,
4605  int32_t srcStart)
4606 {
4607  unBogus();
4608  srcText.pinIndex(srcStart);
4609  return doReplace(0, length(), srcText, srcStart, srcText.length() - srcStart);
4610 }
4611 
4612 inline UnicodeString&
4613 UnicodeString::setTo(const UnicodeString& srcText)
4614 {
4615  return copyFrom(srcText);
4616 }
4617 
4618 inline UnicodeString&
4619 UnicodeString::setTo(const char16_t *srcChars,
4620  int32_t srcLength)
4621 {
4622  unBogus();
4623  return doReplace(0, length(), srcChars, 0, srcLength);
4624 }
4625 
4626 inline UnicodeString&
4627 UnicodeString::setTo(char16_t srcChar)
4628 {
4629  unBogus();
4630  return doReplace(0, length(), &srcChar, 0, 1);
4631 }
4632 
4633 inline UnicodeString&
4634 UnicodeString::setTo(UChar32 srcChar)
4635 {
4636  unBogus();
4637  return replace(0, length(), srcChar);
4638 }
4639 
4640 inline UnicodeString&
4641 UnicodeString::append(const UnicodeString& srcText,
4642  int32_t srcStart,
4643  int32_t srcLength)
4644 { return doAppend(srcText, srcStart, srcLength); }
4645 
4646 inline UnicodeString&
4647 UnicodeString::append(const UnicodeString& srcText)
4648 { return doAppend(srcText, 0, srcText.length()); }
4649 
4650 inline UnicodeString&
4651 UnicodeString::append(const char16_t *srcChars,
4652  int32_t srcStart,
4653  int32_t srcLength)
4654 { return doAppend(srcChars, srcStart, srcLength); }
4655 
4656 inline UnicodeString&
4657 UnicodeString::append(ConstChar16Ptr srcChars,
4658  int32_t srcLength)
4659 { return doAppend(srcChars, 0, srcLength); }
4660 
4661 inline UnicodeString&
4662 UnicodeString::append(char16_t srcChar)
4663 { return doAppend(&srcChar, 0, 1); }
4664 
4665 inline UnicodeString&
4666 UnicodeString::operator+= (char16_t ch)
4667 { return doAppend(&ch, 0, 1); }
4668 
4669 inline UnicodeString&
4670 UnicodeString::operator+= (UChar32 ch) {
4671  return append(ch);
4672 }
4673 
4674 inline UnicodeString&
4675 UnicodeString::operator+= (const UnicodeString& srcText)
4676 { return doAppend(srcText, 0, srcText.length()); }
4677 
4678 inline UnicodeString&
4679 UnicodeString::insert(int32_t start,
4680  const UnicodeString& srcText,
4681  int32_t srcStart,
4682  int32_t srcLength)
4683 { return doReplace(start, 0, srcText, srcStart, srcLength); }
4684 
4685 inline UnicodeString&
4686 UnicodeString::insert(int32_t start,
4687  const UnicodeString& srcText)
4688 { return doReplace(start, 0, srcText, 0, srcText.length()); }
4689 
4690 inline UnicodeString&
4691 UnicodeString::insert(int32_t start,
4692  const char16_t *srcChars,
4693  int32_t srcStart,
4694  int32_t srcLength)
4695 { return doReplace(start, 0, srcChars, srcStart, srcLength); }
4696 
4697 inline UnicodeString&
4698 UnicodeString::insert(int32_t start,
4699  ConstChar16Ptr srcChars,
4700  int32_t srcLength)
4701 { return doReplace(start, 0, srcChars, 0, srcLength); }
4702 
4703 inline UnicodeString&
4704 UnicodeString::insert(int32_t start,
4705  char16_t srcChar)
4706 { return doReplace(start, 0, &srcChar, 0, 1); }
4707 
4708 inline UnicodeString&
4709 UnicodeString::insert(int32_t start,
4710  UChar32 srcChar)
4711 { return replace(start, 0, srcChar); }
4712 
4713 
4714 inline UnicodeString&
4715 UnicodeString::remove()
4716 {
4717  // remove() of a bogus string makes the string empty and non-bogus
4718  if(isBogus()) {
4719  setToEmpty();
4720  } else {
4721  setZeroLength();
4722  }
4723  return *this;
4724 }
4725 
4726 inline UnicodeString&
4727 UnicodeString::remove(int32_t start,
4728  int32_t _length)
4729 {
4730  if(start <= 0 && _length == INT32_MAX) {
4731  // remove(guaranteed everything) of a bogus string makes the string empty and non-bogus
4732  return remove();
4733  }
4734  return doReplace(start, _length, NULL, 0, 0);
4735 }
4736 
4737 inline UnicodeString&
4738 UnicodeString::removeBetween(int32_t start,
4739  int32_t limit)
4740 { return doReplace(start, limit - start, NULL, 0, 0); }
4741 
4742 inline UnicodeString &
4743 UnicodeString::retainBetween(int32_t start, int32_t limit) {
4744  truncate(limit);
4745  return doReplace(0, start, NULL, 0, 0);
4746 }
4747 
4748 inline UBool
4749 UnicodeString::truncate(int32_t targetLength)
4750 {
4751  if(isBogus() && targetLength == 0) {
4752  // truncate(0) of a bogus string makes the string empty and non-bogus
4753  unBogus();
4754  return FALSE;
4755  } else if((uint32_t)targetLength < (uint32_t)length()) {
4756  setLength(targetLength);
4757  return TRUE;
4758  } else {
4759  return FALSE;
4760  }
4761 }
4762 
4763 inline UnicodeString&
4764 UnicodeString::reverse()
4765 { return doReverse(0, length()); }
4766 
4767 inline UnicodeString&
4768 UnicodeString::reverse(int32_t start,
4769  int32_t _length)
4770 { return doReverse(start, _length); }
4771 
4773 
4774 #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:301
UnicodeString & operator=(UnicodeString &&src) U_NOEXCEPT
Move assignment operator; might leave src in bogus state.
Definition: unistr.h:1905
UnicodeString(wchar_t *buffer, int32_t buffLength, int32_t buffCapacity)
Writable-aliasing wchar_t * constructor.
Definition: unistr.h:3157
virtual void copy(int32_t start, int32_t limit, int32_t dest)=0
Copies a substring of this object, retaining metadata.
friend U_COMMON_API void swap(UnicodeString &s1, UnicodeString &s2) U_NOEXCEPT
Non-member UnicodeString swap function.
Definition: unistr.h:1936
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:840
UNISTR_FROM_STRING_EXPLICIT UnicodeString(const uint16_t *text)
uint16_t * constructor.
Definition: unistr.h:3012
UNISTR_FROM_STRING_EXPLICIT UnicodeString(const wchar_t *text)
wchar_t * constructor.
Definition: unistr.h:3028
void * UClassID
UClassID is used to identify classes without using the compiler&#39;s RTTI.
Definition: uobject.h:90
UnicodeString(const wchar_t *text, int32_t length)
wchar_t * constructor.
Definition: unistr.h:3075
#define U_SIZEOF_UCHAR
Number of bytes in a UChar.
Definition: umachine.h:280
UnicodeString(const uint16_t *text, int32_t length)
uint16_t * constructor.
Definition: unistr.h:3062
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:348
UBool isBogus(void) const
Determine if this object contains a valid string.
Definition: unistr.h:3924
Records lengths of string edits but not replacement text.
Definition: edits.h:77
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:137
StringClass & toUTF8String(StringClass &result) const
Convert the UnicodeString to UTF-8 and append the result to a standard string.
Definition: unistr.h:1725
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:389
#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:257
virtual char16_t getCharAt(int32_t offset) const =0
Virtual version of charAt().
#define TRUE
The TRUE value of a UBool.
Definition: umachine.h:229
#define U_NOEXCEPT
"noexcept" if supported, otherwise empty.
Definition: platform.h:503
uint16_t UChar
The base type for UTF-16 code units and pointers.
Definition: umachine.h:342
UnicodeString(uint16_t *buffer, int32_t buffLength, int32_t buffCapacity)
Writable-aliasing uint16_t * constructor.
Definition: unistr.h:3143
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:138
struct UConverter UConverter
Definition: ucnv_err.h:96
#define INT32_MAX
The largest value a 32 bit signed integer can hold.
Definition: umachine.h:171
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:401
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:3909
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: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:233
#define U_COMMON_API
Set to export library symbols from inside the common library, and to import them from outside...
Definition: utypes.h:300
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:289
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:4417
#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:225
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:192
C++ API: Replaceable String.