ICU 58.2  58.2
unistr.h
Go to the documentation of this file.
1 // Copyright (C) 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 **********************************************************************
5 * Copyright (C) 1998-2016, International Business Machines
6 * Corporation and others. All Rights Reserved.
7 **********************************************************************
8 *
9 * File unistr.h
10 *
11 * Modification History:
12 *
13 * Date Name Description
14 * 09/25/98 stephen Creation.
15 * 11/11/98 stephen Changed per 11/9 code review.
16 * 04/20/99 stephen Overhauled per 4/16 code review.
17 * 11/18/99 aliu Made to inherit from Replaceable. Added method
18 * handleReplaceBetween(); other methods unchanged.
19 * 06/25/01 grhoten Remove dependency on iostream.
20 ******************************************************************************
21 */
22 
23 #ifndef UNISTR_H
24 #define UNISTR_H
25 
31 #include "unicode/utypes.h"
32 #include "unicode/rep.h"
33 #include "unicode/std_string.h"
34 #include "unicode/stringpiece.h"
35 #include "unicode/bytestream.h"
36 #include "unicode/ucasemap.h"
37 
38 struct UConverter; // unicode/ucnv.h
39 
40 #ifndef U_COMPARE_CODE_POINT_ORDER
41 /* see also ustring.h and unorm.h */
47 #define U_COMPARE_CODE_POINT_ORDER 0x8000
48 #endif
49 
50 #ifndef USTRING_H
51 
54 U_STABLE int32_t U_EXPORT2
55 u_strlen(const UChar *s);
56 #endif
57 
62 #ifndef U_STRING_CASE_MAPPER_DEFINED
63 #define U_STRING_CASE_MAPPER_DEFINED
64 
69 typedef int32_t U_CALLCONV
71  UChar *dest, int32_t destCapacity,
72  const UChar *src, int32_t srcLength,
73  UErrorCode *pErrorCode);
74 
75 #endif
76 
78 
79 #if !UCONFIG_NO_BREAK_ITERATION
80 class BreakIterator; // unicode/brkiter.h
81 #endif
82 class Locale; // unicode/locid.h
83 class StringCharacterIterator;
84 class UnicodeStringAppendable; // unicode/appendable.h
85 
86 /* The <iostream> include has been moved to unicode/ustream.h */
87 
98 #define US_INV icu::UnicodeString::kInvariant
99 
117 #if defined(U_DECLARE_UTF16)
118 # define UNICODE_STRING(cs, _length) icu::UnicodeString(TRUE, (const UChar *)U_DECLARE_UTF16(cs), _length)
119 #elif U_SIZEOF_WCHAR_T==U_SIZEOF_UCHAR && (U_CHARSET_FAMILY==U_ASCII_FAMILY || (U_SIZEOF_UCHAR == 2 && defined(U_WCHAR_IS_UTF16)))
120 # define UNICODE_STRING(cs, _length) icu::UnicodeString(TRUE, (const UChar *)L ## cs, _length)
121 #elif U_SIZEOF_UCHAR==1 && U_CHARSET_FAMILY==U_ASCII_FAMILY
122 # define UNICODE_STRING(cs, _length) icu::UnicodeString(TRUE, (const UChar *)cs, _length)
123 #else
124 # define UNICODE_STRING(cs, _length) icu::UnicodeString(cs, _length, US_INV)
125 #endif
126 
140 #define UNICODE_STRING_SIMPLE(cs) UNICODE_STRING(cs, -1)
141 
149 #ifndef UNISTR_FROM_CHAR_EXPLICIT
150 # if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION)
151  // Auto-"explicit" in ICU library code.
152 # define UNISTR_FROM_CHAR_EXPLICIT explicit
153 # else
154  // Empty by default for source code compatibility.
155 # define UNISTR_FROM_CHAR_EXPLICIT
156 # endif
157 #endif
158 
169 #ifndef UNISTR_FROM_STRING_EXPLICIT
170 # if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION)
171  // Auto-"explicit" in ICU library code.
172 # define UNISTR_FROM_STRING_EXPLICIT explicit
173 # else
174  // Empty by default for source code compatibility.
175 # define UNISTR_FROM_STRING_EXPLICIT
176 # endif
177 #endif
178 
212 #ifndef UNISTR_OBJECT_SIZE
213 # define UNISTR_OBJECT_SIZE 64
214 #endif
215 
296 {
297 public:
298 
307  enum EInvariant {
312  kInvariant
313  };
314 
315  //========================================
316  // Read-only operations
317  //========================================
318 
319  /* Comparison - bitwise only - for international comparison use collation */
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 
373  inline UBool operator<= (const UnicodeString& text) const;
374 
386  inline int8_t compare(const UnicodeString& text) const;
387 
403  inline int8_t compare(int32_t start,
404  int32_t length,
405  const UnicodeString& text) const;
406 
424  inline int8_t compare(int32_t start,
425  int32_t length,
426  const UnicodeString& srcText,
427  int32_t srcStart,
428  int32_t srcLength) const;
429 
442  inline int8_t compare(const UChar *srcChars,
443  int32_t srcLength) const;
444 
459  inline int8_t compare(int32_t start,
460  int32_t length,
461  const UChar *srcChars) const;
462 
480  inline int8_t compare(int32_t start,
481  int32_t length,
482  const UChar *srcChars,
483  int32_t srcStart,
484  int32_t srcLength) const;
485 
503  inline int8_t compareBetween(int32_t start,
504  int32_t limit,
505  const UnicodeString& srcText,
506  int32_t srcStart,
507  int32_t srcLimit) const;
508 
526  inline int8_t compareCodePointOrder(const UnicodeString& text) const;
527 
547  inline int8_t compareCodePointOrder(int32_t start,
548  int32_t length,
549  const UnicodeString& srcText) const;
550 
572  inline int8_t compareCodePointOrder(int32_t start,
573  int32_t length,
574  const UnicodeString& srcText,
575  int32_t srcStart,
576  int32_t srcLength) const;
577 
596  inline int8_t compareCodePointOrder(const UChar *srcChars,
597  int32_t srcLength) const;
598 
618  inline int8_t compareCodePointOrder(int32_t start,
619  int32_t length,
620  const UChar *srcChars) const;
621 
643  inline int8_t compareCodePointOrder(int32_t start,
644  int32_t length,
645  const UChar *srcChars,
646  int32_t srcStart,
647  int32_t srcLength) const;
648 
670  inline int8_t compareCodePointOrderBetween(int32_t start,
671  int32_t limit,
672  const UnicodeString& srcText,
673  int32_t srcStart,
674  int32_t srcLimit) const;
675 
694  inline int8_t caseCompare(const UnicodeString& text, uint32_t options) const;
695 
716  inline int8_t caseCompare(int32_t start,
717  int32_t length,
718  const UnicodeString& srcText,
719  uint32_t options) const;
720 
743  inline int8_t caseCompare(int32_t start,
744  int32_t length,
745  const UnicodeString& srcText,
746  int32_t srcStart,
747  int32_t srcLength,
748  uint32_t options) const;
749 
769  inline int8_t caseCompare(const UChar *srcChars,
770  int32_t srcLength,
771  uint32_t options) const;
772 
793  inline int8_t caseCompare(int32_t start,
794  int32_t length,
795  const UChar *srcChars,
796  uint32_t options) const;
797 
820  inline int8_t caseCompare(int32_t start,
821  int32_t length,
822  const UChar *srcChars,
823  int32_t srcStart,
824  int32_t srcLength,
825  uint32_t options) const;
826 
849  inline int8_t caseCompareBetween(int32_t start,
850  int32_t limit,
851  const UnicodeString& srcText,
852  int32_t srcStart,
853  int32_t srcLimit,
854  uint32_t options) const;
855 
863  inline UBool startsWith(const UnicodeString& text) const;
864 
875  inline UBool startsWith(const UnicodeString& srcText,
876  int32_t srcStart,
877  int32_t srcLength) const;
878 
887  inline UBool startsWith(const UChar *srcChars,
888  int32_t srcLength) const;
889 
899  inline UBool startsWith(const UChar *srcChars,
900  int32_t srcStart,
901  int32_t srcLength) const;
902 
910  inline UBool endsWith(const UnicodeString& text) const;
911 
922  inline UBool endsWith(const UnicodeString& srcText,
923  int32_t srcStart,
924  int32_t srcLength) const;
925 
934  inline UBool endsWith(const UChar *srcChars,
935  int32_t srcLength) const;
936 
947  inline UBool endsWith(const UChar *srcChars,
948  int32_t srcStart,
949  int32_t srcLength) const;
950 
951 
952  /* Searching - bitwise only */
953 
962  inline int32_t indexOf(const UnicodeString& text) const;
963 
973  inline int32_t indexOf(const UnicodeString& text,
974  int32_t start) const;
975 
987  inline int32_t indexOf(const UnicodeString& text,
988  int32_t start,
989  int32_t length) const;
990 
1007  inline int32_t indexOf(const UnicodeString& srcText,
1008  int32_t srcStart,
1009  int32_t srcLength,
1010  int32_t start,
1011  int32_t length) const;
1012 
1024  inline int32_t indexOf(const UChar *srcChars,
1025  int32_t srcLength,
1026  int32_t start) const;
1027 
1040  inline int32_t indexOf(const UChar *srcChars,
1041  int32_t srcLength,
1042  int32_t start,
1043  int32_t length) const;
1044 
1061  int32_t indexOf(const UChar *srcChars,
1062  int32_t srcStart,
1063  int32_t srcLength,
1064  int32_t start,
1065  int32_t length) const;
1066 
1074  inline int32_t indexOf(UChar c) const;
1075 
1084  inline int32_t indexOf(UChar32 c) const;
1085 
1094  inline int32_t indexOf(UChar c,
1095  int32_t start) const;
1096 
1106  inline int32_t indexOf(UChar32 c,
1107  int32_t start) const;
1108 
1119  inline int32_t indexOf(UChar c,
1120  int32_t start,
1121  int32_t length) const;
1122 
1134  inline int32_t indexOf(UChar32 c,
1135  int32_t start,
1136  int32_t length) const;
1137 
1146  inline int32_t lastIndexOf(const UnicodeString& text) const;
1147 
1157  inline int32_t lastIndexOf(const UnicodeString& text,
1158  int32_t start) const;
1159 
1171  inline int32_t lastIndexOf(const UnicodeString& text,
1172  int32_t start,
1173  int32_t length) const;
1174 
1191  inline int32_t lastIndexOf(const UnicodeString& srcText,
1192  int32_t srcStart,
1193  int32_t srcLength,
1194  int32_t start,
1195  int32_t length) const;
1196 
1207  inline int32_t lastIndexOf(const UChar *srcChars,
1208  int32_t srcLength,
1209  int32_t start) const;
1210 
1223  inline int32_t lastIndexOf(const UChar *srcChars,
1224  int32_t srcLength,
1225  int32_t start,
1226  int32_t length) const;
1227 
1244  int32_t lastIndexOf(const UChar *srcChars,
1245  int32_t srcStart,
1246  int32_t srcLength,
1247  int32_t start,
1248  int32_t length) const;
1249 
1257  inline int32_t lastIndexOf(UChar c) const;
1258 
1267  inline int32_t lastIndexOf(UChar32 c) const;
1268 
1277  inline int32_t lastIndexOf(UChar c,
1278  int32_t start) const;
1279 
1289  inline int32_t lastIndexOf(UChar32 c,
1290  int32_t start) const;
1291 
1302  inline int32_t lastIndexOf(UChar c,
1303  int32_t start,
1304  int32_t length) const;
1305 
1317  inline int32_t lastIndexOf(UChar32 c,
1318  int32_t start,
1319  int32_t length) const;
1320 
1321 
1322  /* Character access */
1323 
1332  inline UChar charAt(int32_t offset) const;
1333 
1341  inline UChar operator[] (int32_t offset) const;
1342 
1354  UChar32 char32At(int32_t offset) const;
1355 
1371  int32_t getChar32Start(int32_t offset) const;
1372 
1389  int32_t getChar32Limit(int32_t offset) const;
1390 
1441  int32_t moveIndex32(int32_t index, int32_t delta) const;
1442 
1443  /* Substring extraction */
1444 
1460  inline void extract(int32_t start,
1461  int32_t length,
1462  UChar *dst,
1463  int32_t dstStart = 0) const;
1464 
1486  int32_t
1487  extract(UChar *dest, int32_t destCapacity,
1488  UErrorCode &errorCode) const;
1489 
1500  inline void extract(int32_t start,
1501  int32_t length,
1502  UnicodeString& target) const;
1503 
1515  inline void extractBetween(int32_t start,
1516  int32_t limit,
1517  UChar *dst,
1518  int32_t dstStart = 0) const;
1519 
1529  virtual void extractBetween(int32_t start,
1530  int32_t limit,
1531  UnicodeString& target) const;
1532 
1554  int32_t extract(int32_t start,
1555  int32_t startLength,
1556  char *target,
1557  int32_t targetCapacity,
1558  enum EInvariant inv) const;
1559 
1560 #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
1561 
1581  int32_t extract(int32_t start,
1582  int32_t startLength,
1583  char *target,
1584  uint32_t targetLength) const;
1585 
1586 #endif
1587 
1588 #if !UCONFIG_NO_CONVERSION
1589 
1615  inline int32_t extract(int32_t start,
1616  int32_t startLength,
1617  char *target,
1618  const char *codepage = 0) const;
1619 
1649  int32_t extract(int32_t start,
1650  int32_t startLength,
1651  char *target,
1652  uint32_t targetLength,
1653  const char *codepage) const;
1654 
1672  int32_t extract(char *dest, int32_t destCapacity,
1673  UConverter *cnv,
1674  UErrorCode &errorCode) const;
1675 
1676 #endif
1677 
1691  UnicodeString tempSubString(int32_t start=0, int32_t length=INT32_MAX) const;
1692 
1703  inline UnicodeString tempSubStringBetween(int32_t start, int32_t limit=INT32_MAX) const;
1704 
1716  void toUTF8(ByteSink &sink) const;
1717 
1718 #if U_HAVE_STD_STRING
1719 
1732  template<typename StringClass>
1733  StringClass &toUTF8String(StringClass &result) const {
1734  StringByteSink<StringClass> sbs(&result);
1735  toUTF8(sbs);
1736  return result;
1737  }
1738 
1739 #endif
1740 
1756  int32_t toUTF32(UChar32 *utf32, int32_t capacity, UErrorCode &errorCode) const;
1757 
1758  /* Length operations */
1759 
1768  inline int32_t length(void) const;
1769 
1783  int32_t
1784  countChar32(int32_t start=0, int32_t length=INT32_MAX) const;
1785 
1809  UBool
1810  hasMoreChar32Than(int32_t start, int32_t length, int32_t number) const;
1811 
1817  inline UBool isEmpty(void) const;
1818 
1828  inline int32_t getCapacity(void) const;
1829 
1830  /* Other operations */
1831 
1837  inline int32_t hashCode(void) const;
1838 
1851  inline UBool isBogus(void) const;
1852 
1853 
1854  //========================================
1855  // Write operations
1856  //========================================
1857 
1858  /* Assignment operations */
1859 
1878  UnicodeString &operator=(const UnicodeString &srcText);
1879 
1905  UnicodeString &fastCopyFrom(const UnicodeString &src);
1906 
1907 #if U_HAVE_RVALUE_REFERENCES
1908 
1916  UnicodeString &operator=(UnicodeString &&src) U_NOEXCEPT {
1917  return moveFrom(src);
1918  }
1919 #endif
1920  // do not use #ifndef U_HIDE_DRAFT_API for moveFrom, needed by non-draft API
1931  UnicodeString &moveFrom(UnicodeString &src) U_NOEXCEPT;
1932 
1938  void swap(UnicodeString &other) U_NOEXCEPT;
1939 
1946  friend U_COMMON_API inline void U_EXPORT2
1947  swap(UnicodeString &s1, UnicodeString &s2) U_NOEXCEPT {
1948  s1.swap(s2);
1949  }
1950 
1958  inline UnicodeString& operator= (UChar ch);
1959 
1967  inline UnicodeString& operator= (UChar32 ch);
1968 
1980  inline UnicodeString& setTo(const UnicodeString& srcText,
1981  int32_t srcStart);
1982 
1996  inline UnicodeString& setTo(const UnicodeString& srcText,
1997  int32_t srcStart,
1998  int32_t srcLength);
1999 
2008  inline UnicodeString& setTo(const UnicodeString& srcText);
2009 
2018  inline UnicodeString& setTo(const UChar *srcChars,
2019  int32_t srcLength);
2020 
2029  UnicodeString& setTo(UChar srcChar);
2030 
2039  UnicodeString& setTo(UChar32 srcChar);
2040 
2064  UnicodeString &setTo(UBool isTerminated,
2065  const UChar *text,
2066  int32_t textLength);
2067 
2087  UnicodeString &setTo(UChar *buffer,
2088  int32_t buffLength,
2089  int32_t buffCapacity);
2090 
2131  void setToBogus();
2132 
2140  UnicodeString& setCharAt(int32_t offset,
2141  UChar ch);
2142 
2143 
2144  /* Append operations */
2145 
2153  inline UnicodeString& operator+= (UChar ch);
2154 
2162  inline UnicodeString& operator+= (UChar32 ch);
2163 
2171  inline UnicodeString& operator+= (const UnicodeString& srcText);
2172 
2187  inline UnicodeString& append(const UnicodeString& srcText,
2188  int32_t srcStart,
2189  int32_t srcLength);
2190 
2198  inline UnicodeString& append(const UnicodeString& srcText);
2199 
2213  inline UnicodeString& append(const UChar *srcChars,
2214  int32_t srcStart,
2215  int32_t srcLength);
2216 
2226  inline UnicodeString& append(const UChar *srcChars,
2227  int32_t srcLength);
2228 
2235  inline UnicodeString& append(UChar srcChar);
2236 
2243  UnicodeString& append(UChar32 srcChar);
2244 
2245 
2246  /* Insert operations */
2247 
2261  inline UnicodeString& insert(int32_t start,
2262  const UnicodeString& srcText,
2263  int32_t srcStart,
2264  int32_t srcLength);
2265 
2274  inline UnicodeString& insert(int32_t start,
2275  const UnicodeString& srcText);
2276 
2290  inline UnicodeString& insert(int32_t start,
2291  const UChar *srcChars,
2292  int32_t srcStart,
2293  int32_t srcLength);
2294 
2304  inline UnicodeString& insert(int32_t start,
2305  const UChar *srcChars,
2306  int32_t srcLength);
2307 
2316  inline UnicodeString& insert(int32_t start,
2317  UChar srcChar);
2318 
2327  inline UnicodeString& insert(int32_t start,
2328  UChar32 srcChar);
2329 
2330 
2331  /* Replace operations */
2332 
2350  UnicodeString& replace(int32_t start,
2351  int32_t length,
2352  const UnicodeString& srcText,
2353  int32_t srcStart,
2354  int32_t srcLength);
2355 
2368  UnicodeString& replace(int32_t start,
2369  int32_t length,
2370  const UnicodeString& srcText);
2371 
2389  UnicodeString& replace(int32_t start,
2390  int32_t length,
2391  const UChar *srcChars,
2392  int32_t srcStart,
2393  int32_t srcLength);
2394 
2407  inline UnicodeString& replace(int32_t start,
2408  int32_t length,
2409  const UChar *srcChars,
2410  int32_t srcLength);
2411 
2423  inline UnicodeString& replace(int32_t start,
2424  int32_t length,
2425  UChar srcChar);
2426 
2438  UnicodeString& replace(int32_t start, int32_t length, UChar32 srcChar);
2439 
2449  inline UnicodeString& replaceBetween(int32_t start,
2450  int32_t limit,
2451  const UnicodeString& srcText);
2452 
2467  inline UnicodeString& replaceBetween(int32_t start,
2468  int32_t limit,
2469  const UnicodeString& srcText,
2470  int32_t srcStart,
2471  int32_t srcLimit);
2472 
2483  virtual void handleReplaceBetween(int32_t start,
2484  int32_t limit,
2485  const UnicodeString& text);
2486 
2492  virtual UBool hasMetaData() const;
2493 
2509  virtual void copy(int32_t start, int32_t limit, int32_t dest);
2510 
2511  /* Search and replace operations */
2512 
2521  inline UnicodeString& findAndReplace(const UnicodeString& oldText,
2522  const UnicodeString& newText);
2523 
2535  inline UnicodeString& findAndReplace(int32_t start,
2536  int32_t length,
2537  const UnicodeString& oldText,
2538  const UnicodeString& newText);
2539 
2557  UnicodeString& findAndReplace(int32_t start,
2558  int32_t length,
2559  const UnicodeString& oldText,
2560  int32_t oldStart,
2561  int32_t oldLength,
2562  const UnicodeString& newText,
2563  int32_t newStart,
2564  int32_t newLength);
2565 
2566 
2567  /* Remove operations */
2568 
2574  inline UnicodeString& remove(void);
2575 
2584  inline UnicodeString& remove(int32_t start,
2585  int32_t length = (int32_t)INT32_MAX);
2586 
2595  inline UnicodeString& removeBetween(int32_t start,
2596  int32_t limit = (int32_t)INT32_MAX);
2597 
2607  inline UnicodeString &retainBetween(int32_t start, int32_t limit = INT32_MAX);
2608 
2609  /* Length operations */
2610 
2622  UBool padLeading(int32_t targetLength,
2623  UChar padChar = 0x0020);
2624 
2636  UBool padTrailing(int32_t targetLength,
2637  UChar padChar = 0x0020);
2638 
2645  inline UBool truncate(int32_t targetLength);
2646 
2652  UnicodeString& trim(void);
2653 
2654 
2655  /* Miscellaneous operations */
2656 
2662  inline UnicodeString& reverse(void);
2663 
2672  inline UnicodeString& reverse(int32_t start,
2673  int32_t length);
2674 
2681  UnicodeString& toUpper(void);
2682 
2690  UnicodeString& toUpper(const Locale& locale);
2691 
2698  UnicodeString& toLower(void);
2699 
2707  UnicodeString& toLower(const Locale& locale);
2708 
2709 #if !UCONFIG_NO_BREAK_ITERATION
2710 
2737  UnicodeString &toTitle(BreakIterator *titleIter);
2738 
2766  UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale);
2767 
2799  UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale, uint32_t options);
2800 
2801 #endif
2802 
2816  UnicodeString &foldCase(uint32_t options=0 /*U_FOLD_CASE_DEFAULT*/);
2817 
2818  //========================================
2819  // Access to the internal buffer
2820  //========================================
2821 
2865  UChar *getBuffer(int32_t minCapacity);
2866 
2887  void releaseBuffer(int32_t newLength=-1);
2888 
2919  inline const UChar *getBuffer() const;
2920 
2954  const UChar *getTerminatedBuffer();
2955 
2956  //========================================
2957  // Constructors
2958  //========================================
2959 
2963  inline UnicodeString();
2964 
2976  UnicodeString(int32_t capacity, UChar32 c, int32_t count);
2977 
2987  UNISTR_FROM_CHAR_EXPLICIT UnicodeString(UChar ch);
2988 
2998  UNISTR_FROM_CHAR_EXPLICIT UnicodeString(UChar32 ch);
2999 
3010  UNISTR_FROM_STRING_EXPLICIT UnicodeString(const UChar *text);
3011 
3019  UnicodeString(const UChar *text,
3020  int32_t textLength);
3021 
3044  UnicodeString(UBool isTerminated,
3045  const UChar *text,
3046  int32_t textLength);
3047 
3066  UnicodeString(UChar *buffer, int32_t buffLength, int32_t buffCapacity);
3067 
3068 #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
3069 
3089  UNISTR_FROM_STRING_EXPLICIT UnicodeString(const char *codepageData);
3090 
3099  UnicodeString(const char *codepageData, int32_t dataLength);
3100 
3101 #endif
3102 
3103 #if !UCONFIG_NO_CONVERSION
3104 
3122  UnicodeString(const char *codepageData, const char *codepage);
3123 
3141  UnicodeString(const char *codepageData, int32_t dataLength, const char *codepage);
3142 
3164  UnicodeString(
3165  const char *src, int32_t srcLength,
3166  UConverter *cnv,
3167  UErrorCode &errorCode);
3168 
3169 #endif
3170 
3195  UnicodeString(const char *src, int32_t length, enum EInvariant inv);
3196 
3197 
3214  UnicodeString(const UnicodeString& that);
3215 
3216 #if U_HAVE_RVALUE_REFERENCES
3217 
3223  UnicodeString(UnicodeString &&src) U_NOEXCEPT;
3224 #endif
3225 
3232  UnicodeString(const UnicodeString& src, int32_t srcStart);
3233 
3241  UnicodeString(const UnicodeString& src, int32_t srcStart, int32_t srcLength);
3242 
3259  virtual Replaceable *clone() const;
3260 
3264  virtual ~UnicodeString();
3265 
3279  static UnicodeString fromUTF8(StringPiece utf8);
3280 
3292  static UnicodeString fromUTF32(const UChar32 *utf32, int32_t length);
3293 
3294  /* Miscellaneous operations */
3295 
3330  UnicodeString unescape() const;
3331 
3351  UChar32 unescapeAt(int32_t &offset) const;
3352 
3358  static UClassID U_EXPORT2 getStaticClassID();
3359 
3365  virtual UClassID getDynamicClassID() const;
3366 
3367  //========================================
3368  // Implementation methods
3369  //========================================
3370 
3371 protected:
3376  virtual int32_t getLength() const;
3377 
3383  virtual UChar getCharAt(int32_t offset) const;
3384 
3390  virtual UChar32 getChar32At(int32_t offset) const;
3391 
3392 private:
3393  // For char* constructors. Could be made public.
3394  UnicodeString &setToUTF8(StringPiece utf8);
3395  // For extract(char*).
3396  // We could make a toUTF8(target, capacity, errorCode) public but not
3397  // this version: New API will be cleaner if we make callers create substrings
3398  // rather than having start+length on every method,
3399  // and it should take a UErrorCode&.
3400  int32_t
3401  toUTF8(int32_t start, int32_t len,
3402  char *target, int32_t capacity) const;
3403 
3408  UBool doEquals(const UnicodeString &text, int32_t len) const;
3409 
3410  inline int8_t
3411  doCompare(int32_t start,
3412  int32_t length,
3413  const UnicodeString& srcText,
3414  int32_t srcStart,
3415  int32_t srcLength) const;
3416 
3417  int8_t doCompare(int32_t start,
3418  int32_t length,
3419  const UChar *srcChars,
3420  int32_t srcStart,
3421  int32_t srcLength) const;
3422 
3423  inline int8_t
3424  doCompareCodePointOrder(int32_t start,
3425  int32_t length,
3426  const UnicodeString& srcText,
3427  int32_t srcStart,
3428  int32_t srcLength) const;
3429 
3430  int8_t doCompareCodePointOrder(int32_t start,
3431  int32_t length,
3432  const UChar *srcChars,
3433  int32_t srcStart,
3434  int32_t srcLength) const;
3435 
3436  inline int8_t
3437  doCaseCompare(int32_t start,
3438  int32_t length,
3439  const UnicodeString &srcText,
3440  int32_t srcStart,
3441  int32_t srcLength,
3442  uint32_t options) const;
3443 
3444  int8_t
3445  doCaseCompare(int32_t start,
3446  int32_t length,
3447  const UChar *srcChars,
3448  int32_t srcStart,
3449  int32_t srcLength,
3450  uint32_t options) const;
3451 
3452  int32_t doIndexOf(UChar c,
3453  int32_t start,
3454  int32_t length) const;
3455 
3456  int32_t doIndexOf(UChar32 c,
3457  int32_t start,
3458  int32_t length) const;
3459 
3460  int32_t doLastIndexOf(UChar c,
3461  int32_t start,
3462  int32_t length) const;
3463 
3464  int32_t doLastIndexOf(UChar32 c,
3465  int32_t start,
3466  int32_t length) const;
3467 
3468  void doExtract(int32_t start,
3469  int32_t length,
3470  UChar *dst,
3471  int32_t dstStart) const;
3472 
3473  inline void doExtract(int32_t start,
3474  int32_t length,
3475  UnicodeString& target) const;
3476 
3477  inline UChar doCharAt(int32_t offset) const;
3478 
3479  UnicodeString& doReplace(int32_t start,
3480  int32_t length,
3481  const UnicodeString& srcText,
3482  int32_t srcStart,
3483  int32_t srcLength);
3484 
3485  UnicodeString& doReplace(int32_t start,
3486  int32_t length,
3487  const UChar *srcChars,
3488  int32_t srcStart,
3489  int32_t srcLength);
3490 
3491  UnicodeString& doAppend(const UnicodeString& src, int32_t srcStart, int32_t srcLength);
3492  UnicodeString& doAppend(const UChar *srcChars, int32_t srcStart, int32_t srcLength);
3493 
3494  UnicodeString& doReverse(int32_t start,
3495  int32_t length);
3496 
3497  // calculate hash code
3498  int32_t doHashCode(void) const;
3499 
3500  // get pointer to start of array
3501  // these do not check for kOpenGetBuffer, unlike the public getBuffer() function
3502  inline UChar* getArrayStart(void);
3503  inline const UChar* getArrayStart(void) const;
3504 
3505  inline UBool hasShortLength() const;
3506  inline int32_t getShortLength() const;
3507 
3508  // A UnicodeString object (not necessarily its current buffer)
3509  // is writable unless it isBogus() or it has an "open" getBuffer(minCapacity).
3510  inline UBool isWritable() const;
3511 
3512  // Is the current buffer writable?
3513  inline UBool isBufferWritable() const;
3514 
3515  // None of the following does releaseArray().
3516  inline void setZeroLength();
3517  inline void setShortLength(int32_t len);
3518  inline void setLength(int32_t len);
3519  inline void setToEmpty();
3520  inline void setArray(UChar *array, int32_t len, int32_t capacity); // sets length but not flags
3521 
3522  // allocate the array; result may be the stack buffer
3523  // sets refCount to 1 if appropriate
3524  // sets fArray, fCapacity, and flags
3525  // sets length to 0
3526  // returns boolean for success or failure
3527  UBool allocate(int32_t capacity);
3528 
3529  // release the array if owned
3530  void releaseArray(void);
3531 
3532  // turn a bogus string into an empty one
3533  void unBogus();
3534 
3535  // implements assigment operator, copy constructor, and fastCopyFrom()
3536  UnicodeString &copyFrom(const UnicodeString &src, UBool fastCopy=FALSE);
3537 
3538  // Copies just the fields without memory management.
3539  void copyFieldsFrom(UnicodeString &src, UBool setSrcToBogus) U_NOEXCEPT;
3540 
3541  // Pin start and limit to acceptable values.
3542  inline void pinIndex(int32_t& start) const;
3543  inline void pinIndices(int32_t& start,
3544  int32_t& length) const;
3545 
3546 #if !UCONFIG_NO_CONVERSION
3547 
3548  /* Internal extract() using UConverter. */
3549  int32_t doExtract(int32_t start, int32_t length,
3550  char *dest, int32_t destCapacity,
3551  UConverter *cnv,
3552  UErrorCode &errorCode) const;
3553 
3554  /*
3555  * Real constructor for converting from codepage data.
3556  * It assumes that it is called with !fRefCounted.
3557  *
3558  * If <code>codepage==0</code>, then the default converter
3559  * is used for the platform encoding.
3560  * If <code>codepage</code> is an empty string (<code>""</code>),
3561  * then a simple conversion is performed on the codepage-invariant
3562  * subset ("invariant characters") of the platform encoding. See utypes.h.
3563  */
3564  void doCodepageCreate(const char *codepageData,
3565  int32_t dataLength,
3566  const char *codepage);
3567 
3568  /*
3569  * Worker function for creating a UnicodeString from
3570  * a codepage string using a UConverter.
3571  */
3572  void
3573  doCodepageCreate(const char *codepageData,
3574  int32_t dataLength,
3575  UConverter *converter,
3576  UErrorCode &status);
3577 
3578 #endif
3579 
3580  /*
3581  * This function is called when write access to the array
3582  * is necessary.
3583  *
3584  * We need to make a copy of the array if
3585  * the buffer is read-only, or
3586  * the buffer is refCounted (shared), and refCount>1, or
3587  * the buffer is too small.
3588  *
3589  * Return FALSE if memory could not be allocated.
3590  */
3591  UBool cloneArrayIfNeeded(int32_t newCapacity = -1,
3592  int32_t growCapacity = -1,
3593  UBool doCopyArray = TRUE,
3594  int32_t **pBufferToDelete = 0,
3595  UBool forceClone = FALSE);
3596 
3602  UnicodeString &
3603  caseMap(const UCaseMap *csm, UStringCaseMapper *stringCaseMapper);
3604 
3605  // ref counting
3606  void addRef(void);
3607  int32_t removeRef(void);
3608  int32_t refCount(void) const;
3609 
3610  // constants
3611  enum {
3617  US_STACKBUF_SIZE=(int32_t)(UNISTR_OBJECT_SIZE-sizeof(void *)-2)/U_SIZEOF_UCHAR,
3618  kInvalidUChar=0xffff, // U+FFFF returned by charAt(invalid index)
3619  kInvalidHashCode=0, // invalid hash code
3620  kEmptyHashCode=1, // hash code for empty string
3621 
3622  // bit flag values for fLengthAndFlags
3623  kIsBogus=1, // this string is bogus, i.e., not valid or NULL
3624  kUsingStackBuffer=2,// using fUnion.fStackFields instead of fUnion.fFields
3625  kRefCounted=4, // there is a refCount field before the characters in fArray
3626  kBufferIsReadonly=8,// do not write to this buffer
3627  kOpenGetBuffer=16, // getBuffer(minCapacity) was called (is "open"),
3628  // and releaseBuffer(newLength) must be called
3629  kAllStorageFlags=0x1f,
3630 
3631  kLengthShift=5, // remaining 11 bits for non-negative short length, or negative if long
3632  kLength1=1<<kLengthShift,
3633  kMaxShortLength=0x3ff, // max non-negative short length (leaves top bit 0)
3634  kLengthIsLarge=0xffe0, // short length < 0, real length is in fUnion.fFields.fLength
3635 
3636  // combined values for convenience
3637  kShortString=kUsingStackBuffer,
3638  kLongString=kRefCounted,
3639  kReadonlyAlias=kBufferIsReadonly,
3640  kWritableAlias=0
3641  };
3642 
3643  friend class UnicodeStringAppendable;
3644 
3645  union StackBufferOrFields; // forward declaration necessary before friend declaration
3646  friend union StackBufferOrFields; // make US_STACKBUF_SIZE visible inside fUnion
3647 
3648  /*
3649  * The following are all the class fields that are stored
3650  * in each UnicodeString object.
3651  * Note that UnicodeString has virtual functions,
3652  * therefore there is an implicit vtable pointer
3653  * as the first real field.
3654  * The fields should be aligned such that no padding is necessary.
3655  * On 32-bit machines, the size should be 32 bytes,
3656  * on 64-bit machines (8-byte pointers), it should be 40 bytes.
3657  *
3658  * We use a hack to achieve this.
3659  *
3660  * With at least some compilers, each of the following is forced to
3661  * a multiple of sizeof(pointer) [the largest field base unit here is a data pointer],
3662  * rounded up with additional padding if the fields do not already fit that requirement:
3663  * - sizeof(class UnicodeString)
3664  * - offsetof(UnicodeString, fUnion)
3665  * - sizeof(fUnion)
3666  * - sizeof(fStackFields)
3667  *
3668  * We optimize for the longest possible internal buffer for short strings.
3669  * fUnion.fStackFields begins with 2 bytes for storage flags
3670  * and the length of relatively short strings,
3671  * followed by the buffer for short string contents.
3672  * There is no padding inside fStackFields.
3673  *
3674  * Heap-allocated and aliased strings use fUnion.fFields.
3675  * Both fStackFields and fFields must begin with the same fields for flags and short length,
3676  * that is, those must have the same memory offsets inside the object,
3677  * because the flags must be inspected in order to decide which half of fUnion is being used.
3678  * We assume that the compiler does not reorder the fields.
3679  *
3680  * (Padding at the end of fFields is ok:
3681  * As long as it is no larger than fStackFields, it is not wasted space.)
3682  *
3683  * For some of the history of the UnicodeString class fields layout, see
3684  * - ICU ticket #11551 "longer UnicodeString contents in stack buffer"
3685  * - ICU ticket #11336 "UnicodeString: recombine stack buffer arrays"
3686  * - ICU ticket #8322 "why is sizeof(UnicodeString)==48?"
3687  */
3688  // (implicit) *vtable;
3689  union StackBufferOrFields {
3690  // fStackFields is used iff (fLengthAndFlags&kUsingStackBuffer) else fFields is used.
3691  // Each struct of the union must begin with fLengthAndFlags.
3692  struct {
3693  int16_t fLengthAndFlags; // bit fields: see constants above
3694  UChar fBuffer[US_STACKBUF_SIZE]; // buffer for short strings
3695  } fStackFields;
3696  struct {
3697  int16_t fLengthAndFlags; // bit fields: see constants above
3698  int32_t fLength; // number of characters in fArray if >127; else undefined
3699  int32_t fCapacity; // capacity of fArray (in UChars)
3700  // array pointer last to minimize padding for machines with P128 data model
3701  // or pointer sizes that are not a power of 2
3702  UChar *fArray; // the Unicode data
3703  } fFields;
3704  } fUnion;
3705 };
3706 
3715 U_COMMON_API UnicodeString U_EXPORT2
3716 operator+ (const UnicodeString &s1, const UnicodeString &s2);
3717 
3718 //========================================
3719 // Inline members
3720 //========================================
3721 
3722 //========================================
3723 // Privates
3724 //========================================
3725 
3726 inline void
3727 UnicodeString::pinIndex(int32_t& start) const
3728 {
3729  // pin index
3730  if(start < 0) {
3731  start = 0;
3732  } else if(start > length()) {
3733  start = length();
3734  }
3735 }
3736 
3737 inline void
3738 UnicodeString::pinIndices(int32_t& start,
3739  int32_t& _length) const
3740 {
3741  // pin indices
3742  int32_t len = length();
3743  if(start < 0) {
3744  start = 0;
3745  } else if(start > len) {
3746  start = len;
3747  }
3748  if(_length < 0) {
3749  _length = 0;
3750  } else if(_length > (len - start)) {
3751  _length = (len - start);
3752  }
3753 }
3754 
3755 inline UChar*
3756 UnicodeString::getArrayStart() {
3757  return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3758  fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
3759 }
3760 
3761 inline const UChar*
3762 UnicodeString::getArrayStart() const {
3763  return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3764  fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
3765 }
3766 
3767 //========================================
3768 // Default constructor
3769 //========================================
3770 
3771 inline
3772 UnicodeString::UnicodeString() {
3773  fUnion.fStackFields.fLengthAndFlags=kShortString;
3774 }
3775 
3776 //========================================
3777 // Read-only implementation methods
3778 //========================================
3779 inline UBool
3780 UnicodeString::hasShortLength() const {
3781  return fUnion.fFields.fLengthAndFlags>=0;
3782 }
3783 
3784 inline int32_t
3785 UnicodeString::getShortLength() const {
3786  // fLengthAndFlags must be non-negative -> short length >= 0
3787  // and arithmetic or logical shift does not matter.
3788  return fUnion.fFields.fLengthAndFlags>>kLengthShift;
3789 }
3790 
3791 inline int32_t
3792 UnicodeString::length() const {
3793  return hasShortLength() ? getShortLength() : fUnion.fFields.fLength;
3794 }
3795 
3796 inline int32_t
3797 UnicodeString::getCapacity() const {
3798  return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3799  US_STACKBUF_SIZE : fUnion.fFields.fCapacity;
3800 }
3801 
3802 inline int32_t
3803 UnicodeString::hashCode() const
3804 { return doHashCode(); }
3805 
3806 inline UBool
3807 UnicodeString::isBogus() const
3808 { return (UBool)(fUnion.fFields.fLengthAndFlags & kIsBogus); }
3809 
3810 inline UBool
3811 UnicodeString::isWritable() const
3812 { return (UBool)!(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus)); }
3813 
3814 inline UBool
3815 UnicodeString::isBufferWritable() const
3816 {
3817  return (UBool)(
3818  !(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus|kBufferIsReadonly)) &&
3819  (!(fUnion.fFields.fLengthAndFlags&kRefCounted) || refCount()==1));
3820 }
3821 
3822 inline const UChar *
3823 UnicodeString::getBuffer() const {
3824  if(fUnion.fFields.fLengthAndFlags&(kIsBogus|kOpenGetBuffer)) {
3825  return 0;
3826  } else if(fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) {
3827  return fUnion.fStackFields.fBuffer;
3828  } else {
3829  return fUnion.fFields.fArray;
3830  }
3831 }
3832 
3833 //========================================
3834 // Read-only alias methods
3835 //========================================
3836 inline int8_t
3837 UnicodeString::doCompare(int32_t start,
3838  int32_t thisLength,
3839  const UnicodeString& srcText,
3840  int32_t srcStart,
3841  int32_t srcLength) const
3842 {
3843  if(srcText.isBogus()) {
3844  return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
3845  } else {
3846  srcText.pinIndices(srcStart, srcLength);
3847  return doCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
3848  }
3849 }
3850 
3851 inline UBool
3853 {
3854  if(isBogus()) {
3855  return text.isBogus();
3856  } else {
3857  int32_t len = length(), textLength = text.length();
3858  return !text.isBogus() && len == textLength && doEquals(text, len);
3859  }
3860 }
3861 
3862 inline UBool
3864 { return (! operator==(text)); }
3865 
3866 inline UBool
3867 UnicodeString::operator> (const UnicodeString& text) const
3868 { return doCompare(0, length(), text, 0, text.length()) == 1; }
3869 
3870 inline UBool
3871 UnicodeString::operator< (const UnicodeString& text) const
3872 { return doCompare(0, length(), text, 0, text.length()) == -1; }
3873 
3874 inline UBool
3875 UnicodeString::operator>= (const UnicodeString& text) const
3876 { return doCompare(0, length(), text, 0, text.length()) != -1; }
3877 
3878 inline UBool
3879 UnicodeString::operator<= (const UnicodeString& text) const
3880 { return doCompare(0, length(), text, 0, text.length()) != 1; }
3881 
3882 inline int8_t
3883 UnicodeString::compare(const UnicodeString& text) const
3884 { return doCompare(0, length(), text, 0, text.length()); }
3885 
3886 inline int8_t
3887 UnicodeString::compare(int32_t start,
3888  int32_t _length,
3889  const UnicodeString& srcText) const
3890 { return doCompare(start, _length, srcText, 0, srcText.length()); }
3891 
3892 inline int8_t
3893 UnicodeString::compare(const UChar *srcChars,
3894  int32_t srcLength) const
3895 { return doCompare(0, length(), srcChars, 0, srcLength); }
3896 
3897 inline int8_t
3898 UnicodeString::compare(int32_t start,
3899  int32_t _length,
3900  const UnicodeString& srcText,
3901  int32_t srcStart,
3902  int32_t srcLength) const
3903 { return doCompare(start, _length, srcText, srcStart, srcLength); }
3904 
3905 inline int8_t
3906 UnicodeString::compare(int32_t start,
3907  int32_t _length,
3908  const UChar *srcChars) const
3909 { return doCompare(start, _length, srcChars, 0, _length); }
3910 
3911 inline int8_t
3912 UnicodeString::compare(int32_t start,
3913  int32_t _length,
3914  const UChar *srcChars,
3915  int32_t srcStart,
3916  int32_t srcLength) const
3917 { return doCompare(start, _length, srcChars, srcStart, srcLength); }
3918 
3919 inline int8_t
3920 UnicodeString::compareBetween(int32_t start,
3921  int32_t limit,
3922  const UnicodeString& srcText,
3923  int32_t srcStart,
3924  int32_t srcLimit) const
3925 { return doCompare(start, limit - start,
3926  srcText, srcStart, srcLimit - srcStart); }
3927 
3928 inline int8_t
3929 UnicodeString::doCompareCodePointOrder(int32_t start,
3930  int32_t thisLength,
3931  const UnicodeString& srcText,
3932  int32_t srcStart,
3933  int32_t srcLength) const
3934 {
3935  if(srcText.isBogus()) {
3936  return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
3937  } else {
3938  srcText.pinIndices(srcStart, srcLength);
3939  return doCompareCodePointOrder(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
3940  }
3941 }
3942 
3943 inline int8_t
3944 UnicodeString::compareCodePointOrder(const UnicodeString& text) const
3945 { return doCompareCodePointOrder(0, length(), text, 0, text.length()); }
3946 
3947 inline int8_t
3948 UnicodeString::compareCodePointOrder(int32_t start,
3949  int32_t _length,
3950  const UnicodeString& srcText) const
3951 { return doCompareCodePointOrder(start, _length, srcText, 0, srcText.length()); }
3952 
3953 inline int8_t
3954 UnicodeString::compareCodePointOrder(const UChar *srcChars,
3955  int32_t srcLength) const
3956 { return doCompareCodePointOrder(0, length(), srcChars, 0, srcLength); }
3957 
3958 inline int8_t
3959 UnicodeString::compareCodePointOrder(int32_t start,
3960  int32_t _length,
3961  const UnicodeString& srcText,
3962  int32_t srcStart,
3963  int32_t srcLength) const
3964 { return doCompareCodePointOrder(start, _length, srcText, srcStart, srcLength); }
3965 
3966 inline int8_t
3967 UnicodeString::compareCodePointOrder(int32_t start,
3968  int32_t _length,
3969  const UChar *srcChars) const
3970 { return doCompareCodePointOrder(start, _length, srcChars, 0, _length); }
3971 
3972 inline int8_t
3973 UnicodeString::compareCodePointOrder(int32_t start,
3974  int32_t _length,
3975  const UChar *srcChars,
3976  int32_t srcStart,
3977  int32_t srcLength) const
3978 { return doCompareCodePointOrder(start, _length, srcChars, srcStart, srcLength); }
3979 
3980 inline int8_t
3981 UnicodeString::compareCodePointOrderBetween(int32_t start,
3982  int32_t limit,
3983  const UnicodeString& srcText,
3984  int32_t srcStart,
3985  int32_t srcLimit) const
3986 { return doCompareCodePointOrder(start, limit - start,
3987  srcText, srcStart, srcLimit - srcStart); }
3988 
3989 inline int8_t
3990 UnicodeString::doCaseCompare(int32_t start,
3991  int32_t thisLength,
3992  const UnicodeString &srcText,
3993  int32_t srcStart,
3994  int32_t srcLength,
3995  uint32_t options) const
3996 {
3997  if(srcText.isBogus()) {
3998  return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
3999  } else {
4000  srcText.pinIndices(srcStart, srcLength);
4001  return doCaseCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength, options);
4002  }
4003 }
4004 
4005 inline int8_t
4006 UnicodeString::caseCompare(const UnicodeString &text, uint32_t options) const {
4007  return doCaseCompare(0, length(), text, 0, text.length(), options);
4008 }
4009 
4010 inline int8_t
4011 UnicodeString::caseCompare(int32_t start,
4012  int32_t _length,
4013  const UnicodeString &srcText,
4014  uint32_t options) const {
4015  return doCaseCompare(start, _length, srcText, 0, srcText.length(), options);
4016 }
4017 
4018 inline int8_t
4019 UnicodeString::caseCompare(const UChar *srcChars,
4020  int32_t srcLength,
4021  uint32_t options) const {
4022  return doCaseCompare(0, length(), srcChars, 0, srcLength, options);
4023 }
4024 
4025 inline int8_t
4026 UnicodeString::caseCompare(int32_t start,
4027  int32_t _length,
4028  const UnicodeString &srcText,
4029  int32_t srcStart,
4030  int32_t srcLength,
4031  uint32_t options) const {
4032  return doCaseCompare(start, _length, srcText, srcStart, srcLength, options);
4033 }
4034 
4035 inline int8_t
4036 UnicodeString::caseCompare(int32_t start,
4037  int32_t _length,
4038  const UChar *srcChars,
4039  uint32_t options) const {
4040  return doCaseCompare(start, _length, srcChars, 0, _length, options);
4041 }
4042 
4043 inline int8_t
4044 UnicodeString::caseCompare(int32_t start,
4045  int32_t _length,
4046  const UChar *srcChars,
4047  int32_t srcStart,
4048  int32_t srcLength,
4049  uint32_t options) const {
4050  return doCaseCompare(start, _length, srcChars, srcStart, srcLength, options);
4051 }
4052 
4053 inline int8_t
4054 UnicodeString::caseCompareBetween(int32_t start,
4055  int32_t limit,
4056  const UnicodeString &srcText,
4057  int32_t srcStart,
4058  int32_t srcLimit,
4059  uint32_t options) const {
4060  return doCaseCompare(start, limit - start, srcText, srcStart, srcLimit - srcStart, options);
4061 }
4062 
4063 inline int32_t
4064 UnicodeString::indexOf(const UnicodeString& srcText,
4065  int32_t srcStart,
4066  int32_t srcLength,
4067  int32_t start,
4068  int32_t _length) const
4069 {
4070  if(!srcText.isBogus()) {
4071  srcText.pinIndices(srcStart, srcLength);
4072  if(srcLength > 0) {
4073  return indexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
4074  }
4075  }
4076  return -1;
4077 }
4078 
4079 inline int32_t
4080 UnicodeString::indexOf(const UnicodeString& text) const
4081 { return indexOf(text, 0, text.length(), 0, length()); }
4082 
4083 inline int32_t
4084 UnicodeString::indexOf(const UnicodeString& text,
4085  int32_t start) const {
4086  pinIndex(start);
4087  return indexOf(text, 0, text.length(), start, length() - start);
4088 }
4089 
4090 inline int32_t
4091 UnicodeString::indexOf(const UnicodeString& text,
4092  int32_t start,
4093  int32_t _length) const
4094 { return indexOf(text, 0, text.length(), start, _length); }
4095 
4096 inline int32_t
4097 UnicodeString::indexOf(const UChar *srcChars,
4098  int32_t srcLength,
4099  int32_t start) const {
4100  pinIndex(start);
4101  return indexOf(srcChars, 0, srcLength, start, length() - start);
4102 }
4103 
4104 inline int32_t
4105 UnicodeString::indexOf(const UChar *srcChars,
4106  int32_t srcLength,
4107  int32_t start,
4108  int32_t _length) const
4109 { return indexOf(srcChars, 0, srcLength, start, _length); }
4110 
4111 inline int32_t
4112 UnicodeString::indexOf(UChar c,
4113  int32_t start,
4114  int32_t _length) const
4115 { return doIndexOf(c, start, _length); }
4116 
4117 inline int32_t
4118 UnicodeString::indexOf(UChar32 c,
4119  int32_t start,
4120  int32_t _length) const
4121 { return doIndexOf(c, start, _length); }
4122 
4123 inline int32_t
4124 UnicodeString::indexOf(UChar c) const
4125 { return doIndexOf(c, 0, length()); }
4126 
4127 inline int32_t
4128 UnicodeString::indexOf(UChar32 c) const
4129 { return indexOf(c, 0, length()); }
4130 
4131 inline int32_t
4132 UnicodeString::indexOf(UChar c,
4133  int32_t start) const {
4134  pinIndex(start);
4135  return doIndexOf(c, start, length() - start);
4136 }
4137 
4138 inline int32_t
4139 UnicodeString::indexOf(UChar32 c,
4140  int32_t start) const {
4141  pinIndex(start);
4142  return indexOf(c, start, length() - start);
4143 }
4144 
4145 inline int32_t
4146 UnicodeString::lastIndexOf(const UChar *srcChars,
4147  int32_t srcLength,
4148  int32_t start,
4149  int32_t _length) const
4150 { return lastIndexOf(srcChars, 0, srcLength, start, _length); }
4151 
4152 inline int32_t
4153 UnicodeString::lastIndexOf(const UChar *srcChars,
4154  int32_t srcLength,
4155  int32_t start) const {
4156  pinIndex(start);
4157  return lastIndexOf(srcChars, 0, srcLength, start, length() - start);
4158 }
4159 
4160 inline int32_t
4161 UnicodeString::lastIndexOf(const UnicodeString& srcText,
4162  int32_t srcStart,
4163  int32_t srcLength,
4164  int32_t start,
4165  int32_t _length) const
4166 {
4167  if(!srcText.isBogus()) {
4168  srcText.pinIndices(srcStart, srcLength);
4169  if(srcLength > 0) {
4170  return lastIndexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
4171  }
4172  }
4173  return -1;
4174 }
4175 
4176 inline int32_t
4177 UnicodeString::lastIndexOf(const UnicodeString& text,
4178  int32_t start,
4179  int32_t _length) const
4180 { return lastIndexOf(text, 0, text.length(), start, _length); }
4181 
4182 inline int32_t
4183 UnicodeString::lastIndexOf(const UnicodeString& text,
4184  int32_t start) const {
4185  pinIndex(start);
4186  return lastIndexOf(text, 0, text.length(), start, length() - start);
4187 }
4188 
4189 inline int32_t
4190 UnicodeString::lastIndexOf(const UnicodeString& text) const
4191 { return lastIndexOf(text, 0, text.length(), 0, length()); }
4192 
4193 inline int32_t
4194 UnicodeString::lastIndexOf(UChar c,
4195  int32_t start,
4196  int32_t _length) const
4197 { return doLastIndexOf(c, start, _length); }
4198 
4199 inline int32_t
4200 UnicodeString::lastIndexOf(UChar32 c,
4201  int32_t start,
4202  int32_t _length) const {
4203  return doLastIndexOf(c, start, _length);
4204 }
4205 
4206 inline int32_t
4207 UnicodeString::lastIndexOf(UChar c) const
4208 { return doLastIndexOf(c, 0, length()); }
4209 
4210 inline int32_t
4211 UnicodeString::lastIndexOf(UChar32 c) const {
4212  return lastIndexOf(c, 0, length());
4213 }
4214 
4215 inline int32_t
4216 UnicodeString::lastIndexOf(UChar c,
4217  int32_t start) const {
4218  pinIndex(start);
4219  return doLastIndexOf(c, start, length() - start);
4220 }
4221 
4222 inline int32_t
4223 UnicodeString::lastIndexOf(UChar32 c,
4224  int32_t start) const {
4225  pinIndex(start);
4226  return lastIndexOf(c, start, length() - start);
4227 }
4228 
4229 inline UBool
4230 UnicodeString::startsWith(const UnicodeString& text) const
4231 { return compare(0, text.length(), text, 0, text.length()) == 0; }
4232 
4233 inline UBool
4234 UnicodeString::startsWith(const UnicodeString& srcText,
4235  int32_t srcStart,
4236  int32_t srcLength) const
4237 { return doCompare(0, srcLength, srcText, srcStart, srcLength) == 0; }
4238 
4239 inline UBool
4240 UnicodeString::startsWith(const UChar *srcChars, int32_t srcLength) const {
4241  if(srcLength < 0) {
4242  srcLength = u_strlen(srcChars);
4243  }
4244  return doCompare(0, srcLength, srcChars, 0, srcLength) == 0;
4245 }
4246 
4247 inline UBool
4248 UnicodeString::startsWith(const UChar *srcChars, int32_t srcStart, int32_t srcLength) const {
4249  if(srcLength < 0) {
4250  srcLength = u_strlen(srcChars);
4251  }
4252  return doCompare(0, srcLength, srcChars, srcStart, srcLength) == 0;
4253 }
4254 
4255 inline UBool
4256 UnicodeString::endsWith(const UnicodeString& text) const
4257 { return doCompare(length() - text.length(), text.length(),
4258  text, 0, text.length()) == 0; }
4259 
4260 inline UBool
4261 UnicodeString::endsWith(const UnicodeString& srcText,
4262  int32_t srcStart,
4263  int32_t srcLength) const {
4264  srcText.pinIndices(srcStart, srcLength);
4265  return doCompare(length() - srcLength, srcLength,
4266  srcText, srcStart, srcLength) == 0;
4267 }
4268 
4269 inline UBool
4270 UnicodeString::endsWith(const UChar *srcChars,
4271  int32_t srcLength) const {
4272  if(srcLength < 0) {
4273  srcLength = u_strlen(srcChars);
4274  }
4275  return doCompare(length() - srcLength, srcLength,
4276  srcChars, 0, srcLength) == 0;
4277 }
4278 
4279 inline UBool
4280 UnicodeString::endsWith(const UChar *srcChars,
4281  int32_t srcStart,
4282  int32_t srcLength) const {
4283  if(srcLength < 0) {
4284  srcLength = u_strlen(srcChars + srcStart);
4285  }
4286  return doCompare(length() - srcLength, srcLength,
4287  srcChars, srcStart, srcLength) == 0;
4288 }
4289 
4290 //========================================
4291 // replace
4292 //========================================
4293 inline UnicodeString&
4294 UnicodeString::replace(int32_t start,
4295  int32_t _length,
4296  const UnicodeString& srcText)
4297 { return doReplace(start, _length, srcText, 0, srcText.length()); }
4298 
4299 inline UnicodeString&
4300 UnicodeString::replace(int32_t start,
4301  int32_t _length,
4302  const UnicodeString& srcText,
4303  int32_t srcStart,
4304  int32_t srcLength)
4305 { return doReplace(start, _length, srcText, srcStart, srcLength); }
4306 
4307 inline UnicodeString&
4308 UnicodeString::replace(int32_t start,
4309  int32_t _length,
4310  const UChar *srcChars,
4311  int32_t srcLength)
4312 { return doReplace(start, _length, srcChars, 0, srcLength); }
4313 
4314 inline UnicodeString&
4315 UnicodeString::replace(int32_t start,
4316  int32_t _length,
4317  const UChar *srcChars,
4318  int32_t srcStart,
4319  int32_t srcLength)
4320 { return doReplace(start, _length, srcChars, srcStart, srcLength); }
4321 
4322 inline UnicodeString&
4323 UnicodeString::replace(int32_t start,
4324  int32_t _length,
4325  UChar srcChar)
4326 { return doReplace(start, _length, &srcChar, 0, 1); }
4327 
4328 inline UnicodeString&
4329 UnicodeString::replaceBetween(int32_t start,
4330  int32_t limit,
4331  const UnicodeString& srcText)
4332 { return doReplace(start, limit - start, srcText, 0, srcText.length()); }
4333 
4334 inline UnicodeString&
4335 UnicodeString::replaceBetween(int32_t start,
4336  int32_t limit,
4337  const UnicodeString& srcText,
4338  int32_t srcStart,
4339  int32_t srcLimit)
4340 { return doReplace(start, limit - start, srcText, srcStart, srcLimit - srcStart); }
4341 
4342 inline UnicodeString&
4343 UnicodeString::findAndReplace(const UnicodeString& oldText,
4344  const UnicodeString& newText)
4345 { return findAndReplace(0, length(), oldText, 0, oldText.length(),
4346  newText, 0, newText.length()); }
4347 
4348 inline UnicodeString&
4349 UnicodeString::findAndReplace(int32_t start,
4350  int32_t _length,
4351  const UnicodeString& oldText,
4352  const UnicodeString& newText)
4353 { return findAndReplace(start, _length, oldText, 0, oldText.length(),
4354  newText, 0, newText.length()); }
4355 
4356 // ============================
4357 // extract
4358 // ============================
4359 inline void
4360 UnicodeString::doExtract(int32_t start,
4361  int32_t _length,
4362  UnicodeString& target) const
4363 { target.replace(0, target.length(), *this, start, _length); }
4364 
4365 inline void
4366 UnicodeString::extract(int32_t start,
4367  int32_t _length,
4368  UChar *target,
4369  int32_t targetStart) const
4370 { doExtract(start, _length, target, targetStart); }
4371 
4372 inline void
4373 UnicodeString::extract(int32_t start,
4374  int32_t _length,
4375  UnicodeString& target) const
4376 { doExtract(start, _length, target); }
4377 
4378 #if !UCONFIG_NO_CONVERSION
4379 
4380 inline int32_t
4381 UnicodeString::extract(int32_t start,
4382  int32_t _length,
4383  char *dst,
4384  const char *codepage) const
4385 
4386 {
4387  // This dstSize value will be checked explicitly
4388  return extract(start, _length, dst, dst!=0 ? 0xffffffff : 0, codepage);
4389 }
4390 
4391 #endif
4392 
4393 inline void
4394 UnicodeString::extractBetween(int32_t start,
4395  int32_t limit,
4396  UChar *dst,
4397  int32_t dstStart) const {
4398  pinIndex(start);
4399  pinIndex(limit);
4400  doExtract(start, limit - start, dst, dstStart);
4401 }
4402 
4403 inline UnicodeString
4404 UnicodeString::tempSubStringBetween(int32_t start, int32_t limit) const {
4405  return tempSubString(start, limit - start);
4406 }
4407 
4408 inline UChar
4409 UnicodeString::doCharAt(int32_t offset) const
4410 {
4411  if((uint32_t)offset < (uint32_t)length()) {
4412  return getArrayStart()[offset];
4413  } else {
4414  return kInvalidUChar;
4415  }
4416 }
4417 
4418 inline UChar
4419 UnicodeString::charAt(int32_t offset) const
4420 { return doCharAt(offset); }
4421 
4422 inline UChar
4423 UnicodeString::operator[] (int32_t offset) const
4424 { return doCharAt(offset); }
4425 
4426 inline UBool
4427 UnicodeString::isEmpty() const {
4428  // Arithmetic or logical right shift does not matter: only testing for 0.
4429  return (fUnion.fFields.fLengthAndFlags>>kLengthShift) == 0;
4430 }
4431 
4432 //========================================
4433 // Write implementation methods
4434 //========================================
4435 inline void
4436 UnicodeString::setZeroLength() {
4437  fUnion.fFields.fLengthAndFlags &= kAllStorageFlags;
4438 }
4439 
4440 inline void
4441 UnicodeString::setShortLength(int32_t len) {
4442  // requires 0 <= len <= kMaxShortLength
4443  fUnion.fFields.fLengthAndFlags =
4444  (int16_t)((fUnion.fFields.fLengthAndFlags & kAllStorageFlags) | (len << kLengthShift));
4445 }
4446 
4447 inline void
4448 UnicodeString::setLength(int32_t len) {
4449  if(len <= kMaxShortLength) {
4450  setShortLength(len);
4451  } else {
4452  fUnion.fFields.fLengthAndFlags |= kLengthIsLarge;
4453  fUnion.fFields.fLength = len;
4454  }
4455 }
4456 
4457 inline void
4458 UnicodeString::setToEmpty() {
4459  fUnion.fFields.fLengthAndFlags = kShortString;
4460 }
4461 
4462 inline void
4463 UnicodeString::setArray(UChar *array, int32_t len, int32_t capacity) {
4464  setLength(len);
4465  fUnion.fFields.fArray = array;
4466  fUnion.fFields.fCapacity = capacity;
4467 }
4468 
4469 inline UnicodeString&
4470 UnicodeString::operator= (UChar ch)
4471 { return doReplace(0, length(), &ch, 0, 1); }
4472 
4473 inline UnicodeString&
4474 UnicodeString::operator= (UChar32 ch)
4475 { return replace(0, length(), ch); }
4476 
4477 inline UnicodeString&
4478 UnicodeString::setTo(const UnicodeString& srcText,
4479  int32_t srcStart,
4480  int32_t srcLength)
4481 {
4482  unBogus();
4483  return doReplace(0, length(), srcText, srcStart, srcLength);
4484 }
4485 
4486 inline UnicodeString&
4487 UnicodeString::setTo(const UnicodeString& srcText,
4488  int32_t srcStart)
4489 {
4490  unBogus();
4491  srcText.pinIndex(srcStart);
4492  return doReplace(0, length(), srcText, srcStart, srcText.length() - srcStart);
4493 }
4494 
4495 inline UnicodeString&
4496 UnicodeString::setTo(const UnicodeString& srcText)
4497 {
4498  return copyFrom(srcText);
4499 }
4500 
4501 inline UnicodeString&
4502 UnicodeString::setTo(const UChar *srcChars,
4503  int32_t srcLength)
4504 {
4505  unBogus();
4506  return doReplace(0, length(), srcChars, 0, srcLength);
4507 }
4508 
4509 inline UnicodeString&
4510 UnicodeString::setTo(UChar srcChar)
4511 {
4512  unBogus();
4513  return doReplace(0, length(), &srcChar, 0, 1);
4514 }
4515 
4516 inline UnicodeString&
4517 UnicodeString::setTo(UChar32 srcChar)
4518 {
4519  unBogus();
4520  return replace(0, length(), srcChar);
4521 }
4522 
4523 inline UnicodeString&
4524 UnicodeString::append(const UnicodeString& srcText,
4525  int32_t srcStart,
4526  int32_t srcLength)
4527 { return doAppend(srcText, srcStart, srcLength); }
4528 
4529 inline UnicodeString&
4530 UnicodeString::append(const UnicodeString& srcText)
4531 { return doAppend(srcText, 0, srcText.length()); }
4532 
4533 inline UnicodeString&
4534 UnicodeString::append(const UChar *srcChars,
4535  int32_t srcStart,
4536  int32_t srcLength)
4537 { return doAppend(srcChars, srcStart, srcLength); }
4538 
4539 inline UnicodeString&
4540 UnicodeString::append(const UChar *srcChars,
4541  int32_t srcLength)
4542 { return doAppend(srcChars, 0, srcLength); }
4543 
4544 inline UnicodeString&
4545 UnicodeString::append(UChar srcChar)
4546 { return doAppend(&srcChar, 0, 1); }
4547 
4548 inline UnicodeString&
4549 UnicodeString::operator+= (UChar ch)
4550 { return doAppend(&ch, 0, 1); }
4551 
4552 inline UnicodeString&
4553 UnicodeString::operator+= (UChar32 ch) {
4554  return append(ch);
4555 }
4556 
4557 inline UnicodeString&
4558 UnicodeString::operator+= (const UnicodeString& srcText)
4559 { return doAppend(srcText, 0, srcText.length()); }
4560 
4561 inline UnicodeString&
4562 UnicodeString::insert(int32_t start,
4563  const UnicodeString& srcText,
4564  int32_t srcStart,
4565  int32_t srcLength)
4566 { return doReplace(start, 0, srcText, srcStart, srcLength); }
4567 
4568 inline UnicodeString&
4569 UnicodeString::insert(int32_t start,
4570  const UnicodeString& srcText)
4571 { return doReplace(start, 0, srcText, 0, srcText.length()); }
4572 
4573 inline UnicodeString&
4574 UnicodeString::insert(int32_t start,
4575  const UChar *srcChars,
4576  int32_t srcStart,
4577  int32_t srcLength)
4578 { return doReplace(start, 0, srcChars, srcStart, srcLength); }
4579 
4580 inline UnicodeString&
4581 UnicodeString::insert(int32_t start,
4582  const UChar *srcChars,
4583  int32_t srcLength)
4584 { return doReplace(start, 0, srcChars, 0, srcLength); }
4585 
4586 inline UnicodeString&
4587 UnicodeString::insert(int32_t start,
4588  UChar srcChar)
4589 { return doReplace(start, 0, &srcChar, 0, 1); }
4590 
4591 inline UnicodeString&
4592 UnicodeString::insert(int32_t start,
4593  UChar32 srcChar)
4594 { return replace(start, 0, srcChar); }
4595 
4596 
4597 inline UnicodeString&
4598 UnicodeString::remove()
4599 {
4600  // remove() of a bogus string makes the string empty and non-bogus
4601  if(isBogus()) {
4602  setToEmpty();
4603  } else {
4604  setZeroLength();
4605  }
4606  return *this;
4607 }
4608 
4609 inline UnicodeString&
4610 UnicodeString::remove(int32_t start,
4611  int32_t _length)
4612 {
4613  if(start <= 0 && _length == INT32_MAX) {
4614  // remove(guaranteed everything) of a bogus string makes the string empty and non-bogus
4615  return remove();
4616  }
4617  return doReplace(start, _length, NULL, 0, 0);
4618 }
4619 
4620 inline UnicodeString&
4621 UnicodeString::removeBetween(int32_t start,
4622  int32_t limit)
4623 { return doReplace(start, limit - start, NULL, 0, 0); }
4624 
4625 inline UnicodeString &
4626 UnicodeString::retainBetween(int32_t start, int32_t limit) {
4627  truncate(limit);
4628  return doReplace(0, start, NULL, 0, 0);
4629 }
4630 
4631 inline UBool
4632 UnicodeString::truncate(int32_t targetLength)
4633 {
4634  if(isBogus() && targetLength == 0) {
4635  // truncate(0) of a bogus string makes the string empty and non-bogus
4636  unBogus();
4637  return FALSE;
4638  } else if((uint32_t)targetLength < (uint32_t)length()) {
4639  setLength(targetLength);
4640  return TRUE;
4641  } else {
4642  return FALSE;
4643  }
4644 }
4645 
4646 inline UnicodeString&
4647 UnicodeString::reverse()
4648 { return doReverse(0, length()); }
4649 
4650 inline UnicodeString&
4651 UnicodeString::reverse(int32_t start,
4652  int32_t _length)
4653 { return doReverse(start, _length); }
4654 
4656 
4657 #endif
#define UNISTR_OBJECT_SIZE
Desired sizeof(UnicodeString) in bytes.
Definition: unistr.h:213
virtual Replaceable * clone() const
Clone this object, an instance of a subclass of Replaceable.
int32_t UStringCaseMapper(const UCaseMap *csm, UChar *dest, int32_t destCapacity, const UChar *src, int32_t srcLength, UErrorCode *pErrorCode)
Internal string case mapping function type.
Definition: unistr.h:70
UChar 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
C API: Unicode case mapping functions using a UCaseMap service object.
EInvariant
Constant to be used in the UnicodeString(char *, int32_t, EInvariant) constructor which constructs a ...
Definition: unistr.h:307
virtual UChar getCharAt(int32_t offset) const =0
Virtual version of charAt().
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.
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:3807
friend U_COMMON_API void swap(UnicodeString &s1, UnicodeString &s2) U_NOEXCEPT
Non-member UnicodeString swap function.
Definition: unistr.h:1947
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:857
void * UClassID
UClassID is used to identify classes without using the compiler&#39;s RTTI.
Definition: uobject.h:93
struct UCaseMap UCaseMap
C typedef for struct UCaseMap.
Definition: ucasemap.h:47
#define U_SIZEOF_UCHAR
Number of bytes in a UChar.
Definition: umachine.h:314
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().
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:155
#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:1733
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:220
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
Definition: umachine.h:357
#define NULL
Define NULL if necessary, to 0 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...
#define TRUE
The TRUE value of a UBool.
Definition: umachine.h:263
#define U_NOEXCEPT
"noexcept" if supported, otherwise empty.
Definition: platform.h:531
uint16_t UChar
Define UChar to be UCHAR_TYPE, if that is #defined (for example, to char16_t), or wchar_t if that is ...
Definition: umachine.h:337
#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:205
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:396
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:233
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:267
#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:295
#define UNISTR_FROM_STRING_EXPLICIT
This can be defined to be empty or "explicit".
Definition: unistr.h:175
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:4300
int32_t length(void) const
Return the length of the UnicodeString object.
Definition: unistr.h:3792
#define U_STABLE
This is used to declare a function as a stable public ICU C API.
Definition: umachine.h:134
int8_t UBool
The ICU boolean type.
Definition: umachine.h:259
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:187
C++ API: Replaceable String.