ICU 57.1  57.1
unistr.h
Go to the documentation of this file.
1 /*
2 **********************************************************************
3 * Copyright (C) 1998-2016, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
6 *
7 * File unistr.h
8 *
9 * Modification History:
10 *
11 * Date Name Description
12 * 09/25/98 stephen Creation.
13 * 11/11/98 stephen Changed per 11/9 code review.
14 * 04/20/99 stephen Overhauled per 4/16 code review.
15 * 11/18/99 aliu Made to inherit from Replaceable. Added method
16 * handleReplaceBetween(); other methods unchanged.
17 * 06/25/01 grhoten Remove dependency on iostream.
18 ******************************************************************************
19 */
20 
21 #ifndef UNISTR_H
22 #define UNISTR_H
23 
29 #include "unicode/utypes.h"
30 #include "unicode/rep.h"
31 #include "unicode/std_string.h"
32 #include "unicode/stringpiece.h"
33 #include "unicode/bytestream.h"
34 #include "unicode/ucasemap.h"
35 
36 struct UConverter; // unicode/ucnv.h
37 
38 #ifndef U_COMPARE_CODE_POINT_ORDER
39 /* see also ustring.h and unorm.h */
45 #define U_COMPARE_CODE_POINT_ORDER 0x8000
46 #endif
47 
48 #ifndef USTRING_H
49 
52 U_STABLE int32_t U_EXPORT2
53 u_strlen(const UChar *s);
54 #endif
55 
60 #ifndef U_STRING_CASE_MAPPER_DEFINED
61 #define U_STRING_CASE_MAPPER_DEFINED
62 
67 typedef int32_t U_CALLCONV
69  UChar *dest, int32_t destCapacity,
70  const UChar *src, int32_t srcLength,
71  UErrorCode *pErrorCode);
72 
73 #endif
74 
76 
77 class BreakIterator; // unicode/brkiter.h
78 class Locale; // unicode/locid.h
79 class StringCharacterIterator;
80 class UnicodeStringAppendable; // unicode/appendable.h
81 
82 /* The <iostream> include has been moved to unicode/ustream.h */
83 
94 #define US_INV icu::UnicodeString::kInvariant
95 
113 #if defined(U_DECLARE_UTF16)
114 # define UNICODE_STRING(cs, _length) icu::UnicodeString(TRUE, (const UChar *)U_DECLARE_UTF16(cs), _length)
115 #elif U_SIZEOF_WCHAR_T==U_SIZEOF_UCHAR && (U_CHARSET_FAMILY==U_ASCII_FAMILY || (U_SIZEOF_UCHAR == 2 && defined(U_WCHAR_IS_UTF16)))
116 # define UNICODE_STRING(cs, _length) icu::UnicodeString(TRUE, (const UChar *)L ## cs, _length)
117 #elif U_SIZEOF_UCHAR==1 && U_CHARSET_FAMILY==U_ASCII_FAMILY
118 # define UNICODE_STRING(cs, _length) icu::UnicodeString(TRUE, (const UChar *)cs, _length)
119 #else
120 # define UNICODE_STRING(cs, _length) icu::UnicodeString(cs, _length, US_INV)
121 #endif
122 
136 #define UNICODE_STRING_SIMPLE(cs) UNICODE_STRING(cs, -1)
137 
145 #ifndef UNISTR_FROM_CHAR_EXPLICIT
146 # if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION)
147  // Auto-"explicit" in ICU library code.
148 # define UNISTR_FROM_CHAR_EXPLICIT explicit
149 # else
150  // Empty by default for source code compatibility.
151 # define UNISTR_FROM_CHAR_EXPLICIT
152 # endif
153 #endif
154 
165 #ifndef UNISTR_FROM_STRING_EXPLICIT
166 # if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION)
167  // Auto-"explicit" in ICU library code.
168 # define UNISTR_FROM_STRING_EXPLICIT explicit
169 # else
170  // Empty by default for source code compatibility.
171 # define UNISTR_FROM_STRING_EXPLICIT
172 # endif
173 #endif
174 
175 /* Cannot make the following #ifndef U_HIDE_DRAFT_API,
176  it is used to construct other non-internal constants */
210 #ifndef UNISTR_OBJECT_SIZE
211 # define UNISTR_OBJECT_SIZE 64
212 #endif
213 
294 {
295 public:
296 
305  enum EInvariant {
310  kInvariant
311  };
312 
313  //========================================
314  // Read-only operations
315  //========================================
316 
317  /* Comparison - bitwise only - for international comparison use collation */
318 
326  inline UBool operator== (const UnicodeString& text) const;
327 
335  inline UBool operator!= (const UnicodeString& text) const;
336 
344  inline UBool operator> (const UnicodeString& text) const;
345 
353  inline UBool operator< (const UnicodeString& text) const;
354 
362  inline UBool operator>= (const UnicodeString& text) const;
363 
371  inline UBool operator<= (const UnicodeString& text) const;
372 
384  inline int8_t compare(const UnicodeString& text) const;
385 
401  inline int8_t compare(int32_t start,
402  int32_t length,
403  const UnicodeString& text) const;
404 
422  inline int8_t compare(int32_t start,
423  int32_t length,
424  const UnicodeString& srcText,
425  int32_t srcStart,
426  int32_t srcLength) const;
427 
440  inline int8_t compare(const UChar *srcChars,
441  int32_t srcLength) const;
442 
457  inline int8_t compare(int32_t start,
458  int32_t length,
459  const UChar *srcChars) const;
460 
478  inline int8_t compare(int32_t start,
479  int32_t length,
480  const UChar *srcChars,
481  int32_t srcStart,
482  int32_t srcLength) const;
483 
501  inline int8_t compareBetween(int32_t start,
502  int32_t limit,
503  const UnicodeString& srcText,
504  int32_t srcStart,
505  int32_t srcLimit) const;
506 
524  inline int8_t compareCodePointOrder(const UnicodeString& text) const;
525 
545  inline int8_t compareCodePointOrder(int32_t start,
546  int32_t length,
547  const UnicodeString& srcText) const;
548 
570  inline int8_t compareCodePointOrder(int32_t start,
571  int32_t length,
572  const UnicodeString& srcText,
573  int32_t srcStart,
574  int32_t srcLength) const;
575 
594  inline int8_t compareCodePointOrder(const UChar *srcChars,
595  int32_t srcLength) const;
596 
616  inline int8_t compareCodePointOrder(int32_t start,
617  int32_t length,
618  const UChar *srcChars) const;
619 
641  inline int8_t compareCodePointOrder(int32_t start,
642  int32_t length,
643  const UChar *srcChars,
644  int32_t srcStart,
645  int32_t srcLength) const;
646 
668  inline int8_t compareCodePointOrderBetween(int32_t start,
669  int32_t limit,
670  const UnicodeString& srcText,
671  int32_t srcStart,
672  int32_t srcLimit) const;
673 
692  inline int8_t caseCompare(const UnicodeString& text, uint32_t options) const;
693 
714  inline int8_t caseCompare(int32_t start,
715  int32_t length,
716  const UnicodeString& srcText,
717  uint32_t options) const;
718 
741  inline int8_t caseCompare(int32_t start,
742  int32_t length,
743  const UnicodeString& srcText,
744  int32_t srcStart,
745  int32_t srcLength,
746  uint32_t options) const;
747 
767  inline int8_t caseCompare(const UChar *srcChars,
768  int32_t srcLength,
769  uint32_t options) const;
770 
791  inline int8_t caseCompare(int32_t start,
792  int32_t length,
793  const UChar *srcChars,
794  uint32_t options) const;
795 
818  inline int8_t caseCompare(int32_t start,
819  int32_t length,
820  const UChar *srcChars,
821  int32_t srcStart,
822  int32_t srcLength,
823  uint32_t options) const;
824 
847  inline int8_t caseCompareBetween(int32_t start,
848  int32_t limit,
849  const UnicodeString& srcText,
850  int32_t srcStart,
851  int32_t srcLimit,
852  uint32_t options) const;
853 
861  inline UBool startsWith(const UnicodeString& text) const;
862 
873  inline UBool startsWith(const UnicodeString& srcText,
874  int32_t srcStart,
875  int32_t srcLength) const;
876 
885  inline UBool startsWith(const UChar *srcChars,
886  int32_t srcLength) const;
887 
897  inline UBool startsWith(const UChar *srcChars,
898  int32_t srcStart,
899  int32_t srcLength) const;
900 
908  inline UBool endsWith(const UnicodeString& text) const;
909 
920  inline UBool endsWith(const UnicodeString& srcText,
921  int32_t srcStart,
922  int32_t srcLength) const;
923 
932  inline UBool endsWith(const UChar *srcChars,
933  int32_t srcLength) const;
934 
945  inline UBool endsWith(const UChar *srcChars,
946  int32_t srcStart,
947  int32_t srcLength) const;
948 
949 
950  /* Searching - bitwise only */
951 
960  inline int32_t indexOf(const UnicodeString& text) const;
961 
971  inline int32_t indexOf(const UnicodeString& text,
972  int32_t start) const;
973 
985  inline int32_t indexOf(const UnicodeString& text,
986  int32_t start,
987  int32_t length) const;
988 
1005  inline int32_t indexOf(const UnicodeString& srcText,
1006  int32_t srcStart,
1007  int32_t srcLength,
1008  int32_t start,
1009  int32_t length) const;
1010 
1022  inline int32_t indexOf(const UChar *srcChars,
1023  int32_t srcLength,
1024  int32_t start) const;
1025 
1038  inline int32_t indexOf(const UChar *srcChars,
1039  int32_t srcLength,
1040  int32_t start,
1041  int32_t length) const;
1042 
1059  int32_t indexOf(const UChar *srcChars,
1060  int32_t srcStart,
1061  int32_t srcLength,
1062  int32_t start,
1063  int32_t length) const;
1064 
1072  inline int32_t indexOf(UChar c) const;
1073 
1082  inline int32_t indexOf(UChar32 c) const;
1083 
1092  inline int32_t indexOf(UChar c,
1093  int32_t start) const;
1094 
1104  inline int32_t indexOf(UChar32 c,
1105  int32_t start) const;
1106 
1117  inline int32_t indexOf(UChar c,
1118  int32_t start,
1119  int32_t length) const;
1120 
1132  inline int32_t indexOf(UChar32 c,
1133  int32_t start,
1134  int32_t length) const;
1135 
1144  inline int32_t lastIndexOf(const UnicodeString& text) const;
1145 
1155  inline int32_t lastIndexOf(const UnicodeString& text,
1156  int32_t start) const;
1157 
1169  inline int32_t lastIndexOf(const UnicodeString& text,
1170  int32_t start,
1171  int32_t length) const;
1172 
1189  inline int32_t lastIndexOf(const UnicodeString& srcText,
1190  int32_t srcStart,
1191  int32_t srcLength,
1192  int32_t start,
1193  int32_t length) const;
1194 
1205  inline int32_t lastIndexOf(const UChar *srcChars,
1206  int32_t srcLength,
1207  int32_t start) const;
1208 
1221  inline int32_t lastIndexOf(const UChar *srcChars,
1222  int32_t srcLength,
1223  int32_t start,
1224  int32_t length) const;
1225 
1242  int32_t lastIndexOf(const UChar *srcChars,
1243  int32_t srcStart,
1244  int32_t srcLength,
1245  int32_t start,
1246  int32_t length) const;
1247 
1255  inline int32_t lastIndexOf(UChar c) const;
1256 
1265  inline int32_t lastIndexOf(UChar32 c) const;
1266 
1275  inline int32_t lastIndexOf(UChar c,
1276  int32_t start) const;
1277 
1287  inline int32_t lastIndexOf(UChar32 c,
1288  int32_t start) const;
1289 
1300  inline int32_t lastIndexOf(UChar c,
1301  int32_t start,
1302  int32_t length) const;
1303 
1315  inline int32_t lastIndexOf(UChar32 c,
1316  int32_t start,
1317  int32_t length) const;
1318 
1319 
1320  /* Character access */
1321 
1330  inline UChar charAt(int32_t offset) const;
1331 
1339  inline UChar operator[] (int32_t offset) const;
1340 
1352  UChar32 char32At(int32_t offset) const;
1353 
1369  int32_t getChar32Start(int32_t offset) const;
1370 
1387  int32_t getChar32Limit(int32_t offset) const;
1388 
1439  int32_t moveIndex32(int32_t index, int32_t delta) const;
1440 
1441  /* Substring extraction */
1442 
1458  inline void extract(int32_t start,
1459  int32_t length,
1460  UChar *dst,
1461  int32_t dstStart = 0) const;
1462 
1484  int32_t
1485  extract(UChar *dest, int32_t destCapacity,
1486  UErrorCode &errorCode) const;
1487 
1498  inline void extract(int32_t start,
1499  int32_t length,
1500  UnicodeString& target) const;
1501 
1513  inline void extractBetween(int32_t start,
1514  int32_t limit,
1515  UChar *dst,
1516  int32_t dstStart = 0) const;
1517 
1527  virtual void extractBetween(int32_t start,
1528  int32_t limit,
1529  UnicodeString& target) const;
1530 
1552  int32_t extract(int32_t start,
1553  int32_t startLength,
1554  char *target,
1555  int32_t targetCapacity,
1556  enum EInvariant inv) const;
1557 
1558 #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
1559 
1579  int32_t extract(int32_t start,
1580  int32_t startLength,
1581  char *target,
1582  uint32_t targetLength) const;
1583 
1584 #endif
1585 
1586 #if !UCONFIG_NO_CONVERSION
1587 
1613  inline int32_t extract(int32_t start,
1614  int32_t startLength,
1615  char *target,
1616  const char *codepage = 0) const;
1617 
1647  int32_t extract(int32_t start,
1648  int32_t startLength,
1649  char *target,
1650  uint32_t targetLength,
1651  const char *codepage) const;
1652 
1670  int32_t extract(char *dest, int32_t destCapacity,
1671  UConverter *cnv,
1672  UErrorCode &errorCode) const;
1673 
1674 #endif
1675 
1689  UnicodeString tempSubString(int32_t start=0, int32_t length=INT32_MAX) const;
1690 
1701  inline UnicodeString tempSubStringBetween(int32_t start, int32_t limit=INT32_MAX) const;
1702 
1714  void toUTF8(ByteSink &sink) const;
1715 
1716 #if U_HAVE_STD_STRING
1717 
1730  template<typename StringClass>
1731  StringClass &toUTF8String(StringClass &result) const {
1732  StringByteSink<StringClass> sbs(&result);
1733  toUTF8(sbs);
1734  return result;
1735  }
1736 
1737 #endif
1738 
1754  int32_t toUTF32(UChar32 *utf32, int32_t capacity, UErrorCode &errorCode) const;
1755 
1756  /* Length operations */
1757 
1766  inline int32_t length(void) const;
1767 
1781  int32_t
1782  countChar32(int32_t start=0, int32_t length=INT32_MAX) const;
1783 
1807  UBool
1808  hasMoreChar32Than(int32_t start, int32_t length, int32_t number) const;
1809 
1815  inline UBool isEmpty(void) const;
1816 
1826  inline int32_t getCapacity(void) const;
1827 
1828  /* Other operations */
1829 
1835  inline int32_t hashCode(void) const;
1836 
1849  inline UBool isBogus(void) const;
1850 
1851 
1852  //========================================
1853  // Write operations
1854  //========================================
1855 
1856  /* Assignment operations */
1857 
1876  UnicodeString &operator=(const UnicodeString &srcText);
1877 
1903  UnicodeString &fastCopyFrom(const UnicodeString &src);
1904 
1905 #ifndef U_HIDE_DRAFT_API
1906 #if U_HAVE_RVALUE_REFERENCES
1907 
1915  UnicodeString &operator=(UnicodeString &&src) U_NOEXCEPT {
1916  return moveFrom(src);
1917  }
1918 #endif
1919 
1929  UnicodeString &moveFrom(UnicodeString &src) U_NOEXCEPT;
1930 
1936  void swap(UnicodeString &other) U_NOEXCEPT;
1937 #endif /* U_HIDE_DRAFT_API */
1938 
1945  friend U_COMMON_API inline void U_EXPORT2
1946  swap(UnicodeString &s1, UnicodeString &s2) U_NOEXCEPT {
1947  s1.swap(s2);
1948  }
1949 
1957  inline UnicodeString& operator= (UChar ch);
1958 
1966  inline UnicodeString& operator= (UChar32 ch);
1967 
1979  inline UnicodeString& setTo(const UnicodeString& srcText,
1980  int32_t srcStart);
1981 
1995  inline UnicodeString& setTo(const UnicodeString& srcText,
1996  int32_t srcStart,
1997  int32_t srcLength);
1998 
2007  inline UnicodeString& setTo(const UnicodeString& srcText);
2008 
2017  inline UnicodeString& setTo(const UChar *srcChars,
2018  int32_t srcLength);
2019 
2028  UnicodeString& setTo(UChar srcChar);
2029 
2038  UnicodeString& setTo(UChar32 srcChar);
2039 
2063  UnicodeString &setTo(UBool isTerminated,
2064  const UChar *text,
2065  int32_t textLength);
2066 
2086  UnicodeString &setTo(UChar *buffer,
2087  int32_t buffLength,
2088  int32_t buffCapacity);
2089 
2130  void setToBogus();
2131 
2139  UnicodeString& setCharAt(int32_t offset,
2140  UChar ch);
2141 
2142 
2143  /* Append operations */
2144 
2152  inline UnicodeString& operator+= (UChar ch);
2153 
2161  inline UnicodeString& operator+= (UChar32 ch);
2162 
2170  inline UnicodeString& operator+= (const UnicodeString& srcText);
2171 
2186  inline UnicodeString& append(const UnicodeString& srcText,
2187  int32_t srcStart,
2188  int32_t srcLength);
2189 
2197  inline UnicodeString& append(const UnicodeString& srcText);
2198 
2212  inline UnicodeString& append(const UChar *srcChars,
2213  int32_t srcStart,
2214  int32_t srcLength);
2215 
2225  inline UnicodeString& append(const UChar *srcChars,
2226  int32_t srcLength);
2227 
2234  inline UnicodeString& append(UChar srcChar);
2235 
2242  UnicodeString& append(UChar32 srcChar);
2243 
2244 
2245  /* Insert operations */
2246 
2260  inline UnicodeString& insert(int32_t start,
2261  const UnicodeString& srcText,
2262  int32_t srcStart,
2263  int32_t srcLength);
2264 
2273  inline UnicodeString& insert(int32_t start,
2274  const UnicodeString& srcText);
2275 
2289  inline UnicodeString& insert(int32_t start,
2290  const UChar *srcChars,
2291  int32_t srcStart,
2292  int32_t srcLength);
2293 
2303  inline UnicodeString& insert(int32_t start,
2304  const UChar *srcChars,
2305  int32_t srcLength);
2306 
2315  inline UnicodeString& insert(int32_t start,
2316  UChar srcChar);
2317 
2326  inline UnicodeString& insert(int32_t start,
2327  UChar32 srcChar);
2328 
2329 
2330  /* Replace operations */
2331 
2349  UnicodeString& replace(int32_t start,
2350  int32_t length,
2351  const UnicodeString& srcText,
2352  int32_t srcStart,
2353  int32_t srcLength);
2354 
2367  UnicodeString& replace(int32_t start,
2368  int32_t length,
2369  const UnicodeString& srcText);
2370 
2388  UnicodeString& replace(int32_t start,
2389  int32_t length,
2390  const UChar *srcChars,
2391  int32_t srcStart,
2392  int32_t srcLength);
2393 
2406  inline UnicodeString& replace(int32_t start,
2407  int32_t length,
2408  const UChar *srcChars,
2409  int32_t srcLength);
2410 
2422  inline UnicodeString& replace(int32_t start,
2423  int32_t length,
2424  UChar srcChar);
2425 
2437  UnicodeString& replace(int32_t start, int32_t length, UChar32 srcChar);
2438 
2448  inline UnicodeString& replaceBetween(int32_t start,
2449  int32_t limit,
2450  const UnicodeString& srcText);
2451 
2466  inline UnicodeString& replaceBetween(int32_t start,
2467  int32_t limit,
2468  const UnicodeString& srcText,
2469  int32_t srcStart,
2470  int32_t srcLimit);
2471 
2482  virtual void handleReplaceBetween(int32_t start,
2483  int32_t limit,
2484  const UnicodeString& text);
2485 
2491  virtual UBool hasMetaData() const;
2492 
2508  virtual void copy(int32_t start, int32_t limit, int32_t dest);
2509 
2510  /* Search and replace operations */
2511 
2520  inline UnicodeString& findAndReplace(const UnicodeString& oldText,
2521  const UnicodeString& newText);
2522 
2534  inline UnicodeString& findAndReplace(int32_t start,
2535  int32_t length,
2536  const UnicodeString& oldText,
2537  const UnicodeString& newText);
2538 
2556  UnicodeString& findAndReplace(int32_t start,
2557  int32_t length,
2558  const UnicodeString& oldText,
2559  int32_t oldStart,
2560  int32_t oldLength,
2561  const UnicodeString& newText,
2562  int32_t newStart,
2563  int32_t newLength);
2564 
2565 
2566  /* Remove operations */
2567 
2573  inline UnicodeString& remove(void);
2574 
2583  inline UnicodeString& remove(int32_t start,
2584  int32_t length = (int32_t)INT32_MAX);
2585 
2594  inline UnicodeString& removeBetween(int32_t start,
2595  int32_t limit = (int32_t)INT32_MAX);
2596 
2606  inline UnicodeString &retainBetween(int32_t start, int32_t limit = INT32_MAX);
2607 
2608  /* Length operations */
2609 
2621  UBool padLeading(int32_t targetLength,
2622  UChar padChar = 0x0020);
2623 
2635  UBool padTrailing(int32_t targetLength,
2636  UChar padChar = 0x0020);
2637 
2644  inline UBool truncate(int32_t targetLength);
2645 
2651  UnicodeString& trim(void);
2652 
2653 
2654  /* Miscellaneous operations */
2655 
2661  inline UnicodeString& reverse(void);
2662 
2671  inline UnicodeString& reverse(int32_t start,
2672  int32_t length);
2673 
2680  UnicodeString& toUpper(void);
2681 
2689  UnicodeString& toUpper(const Locale& locale);
2690 
2697  UnicodeString& toLower(void);
2698 
2706  UnicodeString& toLower(const Locale& locale);
2707 
2708 #if !UCONFIG_NO_BREAK_ITERATION
2709 
2736  UnicodeString &toTitle(BreakIterator *titleIter);
2737 
2765  UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale);
2766 
2798  UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale, uint32_t options);
2799 
2800 #endif
2801 
2815  UnicodeString &foldCase(uint32_t options=0 /*U_FOLD_CASE_DEFAULT*/);
2816 
2817  //========================================
2818  // Access to the internal buffer
2819  //========================================
2820 
2864  UChar *getBuffer(int32_t minCapacity);
2865 
2886  void releaseBuffer(int32_t newLength=-1);
2887 
2918  inline const UChar *getBuffer() const;
2919 
2953  const UChar *getTerminatedBuffer();
2954 
2955  //========================================
2956  // Constructors
2957  //========================================
2958 
2962  inline UnicodeString();
2963 
2975  UnicodeString(int32_t capacity, UChar32 c, int32_t count);
2976 
2986  UNISTR_FROM_CHAR_EXPLICIT UnicodeString(UChar ch);
2987 
2997  UNISTR_FROM_CHAR_EXPLICIT UnicodeString(UChar32 ch);
2998 
3009  UNISTR_FROM_STRING_EXPLICIT UnicodeString(const UChar *text);
3010 
3018  UnicodeString(const UChar *text,
3019  int32_t textLength);
3020 
3043  UnicodeString(UBool isTerminated,
3044  const UChar *text,
3045  int32_t textLength);
3046 
3065  UnicodeString(UChar *buffer, int32_t buffLength, int32_t buffCapacity);
3066 
3067 #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
3068 
3088  UNISTR_FROM_STRING_EXPLICIT UnicodeString(const char *codepageData);
3089 
3098  UnicodeString(const char *codepageData, int32_t dataLength);
3099 
3100 #endif
3101 
3102 #if !UCONFIG_NO_CONVERSION
3103 
3121  UnicodeString(const char *codepageData, const char *codepage);
3122 
3140  UnicodeString(const char *codepageData, int32_t dataLength, const char *codepage);
3141 
3163  UnicodeString(
3164  const char *src, int32_t srcLength,
3165  UConverter *cnv,
3166  UErrorCode &errorCode);
3167 
3168 #endif
3169 
3194  UnicodeString(const char *src, int32_t length, enum EInvariant inv);
3195 
3196 
3213  UnicodeString(const UnicodeString& that);
3214 
3215 #ifndef U_HIDE_DRAFT_API
3216 #if U_HAVE_RVALUE_REFERENCES
3217 
3223  UnicodeString(UnicodeString &&src) U_NOEXCEPT;
3224 #endif
3225 #endif /* U_HIDE_DRAFT_API */
3226 
3233  UnicodeString(const UnicodeString& src, int32_t srcStart);
3234 
3242  UnicodeString(const UnicodeString& src, int32_t srcStart, int32_t srcLength);
3243 
3260  virtual Replaceable *clone() const;
3261 
3265  virtual ~UnicodeString();
3266 
3280  static UnicodeString fromUTF8(const StringPiece &utf8);
3281 
3293  static UnicodeString fromUTF32(const UChar32 *utf32, int32_t length);
3294 
3295  /* Miscellaneous operations */
3296 
3331  UnicodeString unescape() const;
3332 
3352  UChar32 unescapeAt(int32_t &offset) const;
3353 
3359  static UClassID U_EXPORT2 getStaticClassID();
3360 
3366  virtual UClassID getDynamicClassID() const;
3367 
3368  //========================================
3369  // Implementation methods
3370  //========================================
3371 
3372 protected:
3377  virtual int32_t getLength() const;
3378 
3384  virtual UChar getCharAt(int32_t offset) const;
3385 
3391  virtual UChar32 getChar32At(int32_t offset) const;
3392 
3393 private:
3394  // For char* constructors. Could be made public.
3395  UnicodeString &setToUTF8(const StringPiece &utf8);
3396  // For extract(char*).
3397  // We could make a toUTF8(target, capacity, errorCode) public but not
3398  // this version: New API will be cleaner if we make callers create substrings
3399  // rather than having start+length on every method,
3400  // and it should take a UErrorCode&.
3401  int32_t
3402  toUTF8(int32_t start, int32_t len,
3403  char *target, int32_t capacity) const;
3404 
3409  UBool doEquals(const UnicodeString &text, int32_t len) const;
3410 
3411  inline int8_t
3412  doCompare(int32_t start,
3413  int32_t length,
3414  const UnicodeString& srcText,
3415  int32_t srcStart,
3416  int32_t srcLength) const;
3417 
3418  int8_t doCompare(int32_t start,
3419  int32_t length,
3420  const UChar *srcChars,
3421  int32_t srcStart,
3422  int32_t srcLength) const;
3423 
3424  inline int8_t
3425  doCompareCodePointOrder(int32_t start,
3426  int32_t length,
3427  const UnicodeString& srcText,
3428  int32_t srcStart,
3429  int32_t srcLength) const;
3430 
3431  int8_t doCompareCodePointOrder(int32_t start,
3432  int32_t length,
3433  const UChar *srcChars,
3434  int32_t srcStart,
3435  int32_t srcLength) const;
3436 
3437  inline int8_t
3438  doCaseCompare(int32_t start,
3439  int32_t length,
3440  const UnicodeString &srcText,
3441  int32_t srcStart,
3442  int32_t srcLength,
3443  uint32_t options) const;
3444 
3445  int8_t
3446  doCaseCompare(int32_t start,
3447  int32_t length,
3448  const UChar *srcChars,
3449  int32_t srcStart,
3450  int32_t srcLength,
3451  uint32_t options) const;
3452 
3453  int32_t doIndexOf(UChar c,
3454  int32_t start,
3455  int32_t length) const;
3456 
3457  int32_t doIndexOf(UChar32 c,
3458  int32_t start,
3459  int32_t length) const;
3460 
3461  int32_t doLastIndexOf(UChar c,
3462  int32_t start,
3463  int32_t length) const;
3464 
3465  int32_t doLastIndexOf(UChar32 c,
3466  int32_t start,
3467  int32_t length) const;
3468 
3469  void doExtract(int32_t start,
3470  int32_t length,
3471  UChar *dst,
3472  int32_t dstStart) const;
3473 
3474  inline void doExtract(int32_t start,
3475  int32_t length,
3476  UnicodeString& target) const;
3477 
3478  inline UChar doCharAt(int32_t offset) const;
3479 
3480  UnicodeString& doReplace(int32_t start,
3481  int32_t length,
3482  const UnicodeString& srcText,
3483  int32_t srcStart,
3484  int32_t srcLength);
3485 
3486  UnicodeString& doReplace(int32_t start,
3487  int32_t length,
3488  const UChar *srcChars,
3489  int32_t srcStart,
3490  int32_t srcLength);
3491 
3492  UnicodeString& doAppend(const UnicodeString& src, int32_t srcStart, int32_t srcLength);
3493  UnicodeString& doAppend(const UChar *srcChars, int32_t srcStart, int32_t srcLength);
3494 
3495  UnicodeString& doReverse(int32_t start,
3496  int32_t length);
3497 
3498  // calculate hash code
3499  int32_t doHashCode(void) const;
3500 
3501  // get pointer to start of array
3502  // these do not check for kOpenGetBuffer, unlike the public getBuffer() function
3503  inline UChar* getArrayStart(void);
3504  inline const UChar* getArrayStart(void) const;
3505 
3506  inline UBool hasShortLength() const;
3507  inline int32_t getShortLength() const;
3508 
3509  // A UnicodeString object (not necessarily its current buffer)
3510  // is writable unless it isBogus() or it has an "open" getBuffer(minCapacity).
3511  inline UBool isWritable() const;
3512 
3513  // Is the current buffer writable?
3514  inline UBool isBufferWritable() const;
3515 
3516  // None of the following does releaseArray().
3517  inline void setZeroLength();
3518  inline void setShortLength(int32_t len);
3519  inline void setLength(int32_t len);
3520  inline void setToEmpty();
3521  inline void setArray(UChar *array, int32_t len, int32_t capacity); // sets length but not flags
3522 
3523  // allocate the array; result may be the stack buffer
3524  // sets refCount to 1 if appropriate
3525  // sets fArray, fCapacity, and flags
3526  // sets length to 0
3527  // returns boolean for success or failure
3528  UBool allocate(int32_t capacity);
3529 
3530  // release the array if owned
3531  void releaseArray(void);
3532 
3533  // turn a bogus string into an empty one
3534  void unBogus();
3535 
3536  // implements assigment operator, copy constructor, and fastCopyFrom()
3537  UnicodeString &copyFrom(const UnicodeString &src, UBool fastCopy=FALSE);
3538 
3539  // Copies just the fields without memory management.
3540  void copyFieldsFrom(UnicodeString &src, UBool setSrcToBogus) U_NOEXCEPT;
3541 
3542  // Pin start and limit to acceptable values.
3543  inline void pinIndex(int32_t& start) const;
3544  inline void pinIndices(int32_t& start,
3545  int32_t& length) const;
3546 
3547 #if !UCONFIG_NO_CONVERSION
3548 
3549  /* Internal extract() using UConverter. */
3550  int32_t doExtract(int32_t start, int32_t length,
3551  char *dest, int32_t destCapacity,
3552  UConverter *cnv,
3553  UErrorCode &errorCode) const;
3554 
3555  /*
3556  * Real constructor for converting from codepage data.
3557  * It assumes that it is called with !fRefCounted.
3558  *
3559  * If <code>codepage==0</code>, then the default converter
3560  * is used for the platform encoding.
3561  * If <code>codepage</code> is an empty string (<code>""</code>),
3562  * then a simple conversion is performed on the codepage-invariant
3563  * subset ("invariant characters") of the platform encoding. See utypes.h.
3564  */
3565  void doCodepageCreate(const char *codepageData,
3566  int32_t dataLength,
3567  const char *codepage);
3568 
3569  /*
3570  * Worker function for creating a UnicodeString from
3571  * a codepage string using a UConverter.
3572  */
3573  void
3574  doCodepageCreate(const char *codepageData,
3575  int32_t dataLength,
3576  UConverter *converter,
3577  UErrorCode &status);
3578 
3579 #endif
3580 
3581  /*
3582  * This function is called when write access to the array
3583  * is necessary.
3584  *
3585  * We need to make a copy of the array if
3586  * the buffer is read-only, or
3587  * the buffer is refCounted (shared), and refCount>1, or
3588  * the buffer is too small.
3589  *
3590  * Return FALSE if memory could not be allocated.
3591  */
3592  UBool cloneArrayIfNeeded(int32_t newCapacity = -1,
3593  int32_t growCapacity = -1,
3594  UBool doCopyArray = TRUE,
3595  int32_t **pBufferToDelete = 0,
3596  UBool forceClone = FALSE);
3597 
3603  UnicodeString &
3604  caseMap(const UCaseMap *csm, UStringCaseMapper *stringCaseMapper);
3605 
3606  // ref counting
3607  void addRef(void);
3608  int32_t removeRef(void);
3609  int32_t refCount(void) const;
3610 
3611  // constants
3612  enum {
3618  US_STACKBUF_SIZE=(int32_t)(UNISTR_OBJECT_SIZE-sizeof(void *)-2)/U_SIZEOF_UCHAR,
3619  kInvalidUChar=0xffff, // U+FFFF returned by charAt(invalid index)
3620  kGrowSize=128, // grow size for this buffer
3621  kInvalidHashCode=0, // invalid hash code
3622  kEmptyHashCode=1, // hash code for empty string
3623 
3624  // bit flag values for fLengthAndFlags
3625  kIsBogus=1, // this string is bogus, i.e., not valid or NULL
3626  kUsingStackBuffer=2,// using fUnion.fStackFields instead of fUnion.fFields
3627  kRefCounted=4, // there is a refCount field before the characters in fArray
3628  kBufferIsReadonly=8,// do not write to this buffer
3629  kOpenGetBuffer=16, // getBuffer(minCapacity) was called (is "open"),
3630  // and releaseBuffer(newLength) must be called
3631  kAllStorageFlags=0x1f,
3632 
3633  kLengthShift=5, // remaining 11 bits for non-negative short length, or negative if long
3634  kLength1=1<<kLengthShift,
3635  kMaxShortLength=0x3ff, // max non-negative short length (leaves top bit 0)
3636  kLengthIsLarge=0xffe0, // short length < 0, real length is in fUnion.fFields.fLength
3637 
3638  // combined values for convenience
3639  kShortString=kUsingStackBuffer,
3640  kLongString=kRefCounted,
3641  kReadonlyAlias=kBufferIsReadonly,
3642  kWritableAlias=0
3643  };
3644 
3645  friend class UnicodeStringAppendable;
3646 
3647  union StackBufferOrFields; // forward declaration necessary before friend declaration
3648  friend union StackBufferOrFields; // make US_STACKBUF_SIZE visible inside fUnion
3649 
3650  /*
3651  * The following are all the class fields that are stored
3652  * in each UnicodeString object.
3653  * Note that UnicodeString has virtual functions,
3654  * therefore there is an implicit vtable pointer
3655  * as the first real field.
3656  * The fields should be aligned such that no padding is necessary.
3657  * On 32-bit machines, the size should be 32 bytes,
3658  * on 64-bit machines (8-byte pointers), it should be 40 bytes.
3659  *
3660  * We use a hack to achieve this.
3661  *
3662  * With at least some compilers, each of the following is forced to
3663  * a multiple of sizeof(pointer) [the largest field base unit here is a data pointer],
3664  * rounded up with additional padding if the fields do not already fit that requirement:
3665  * - sizeof(class UnicodeString)
3666  * - offsetof(UnicodeString, fUnion)
3667  * - sizeof(fUnion)
3668  * - sizeof(fStackFields)
3669  *
3670  * We optimize for the longest possible internal buffer for short strings.
3671  * fUnion.fStackFields begins with 2 bytes for storage flags
3672  * and the length of relatively short strings,
3673  * followed by the buffer for short string contents.
3674  * There is no padding inside fStackFields.
3675  *
3676  * Heap-allocated and aliased strings use fUnion.fFields.
3677  * Both fStackFields and fFields must begin with the same fields for flags and short length,
3678  * that is, those must have the same memory offsets inside the object,
3679  * because the flags must be inspected in order to decide which half of fUnion is being used.
3680  * We assume that the compiler does not reorder the fields.
3681  *
3682  * (Padding at the end of fFields is ok:
3683  * As long as it is no larger than fStackFields, it is not wasted space.)
3684  *
3685  * For some of the history of the UnicodeString class fields layout, see
3686  * - ICU ticket #11551 "longer UnicodeString contents in stack buffer"
3687  * - ICU ticket #11336 "UnicodeString: recombine stack buffer arrays"
3688  * - ICU ticket #8322 "why is sizeof(UnicodeString)==48?"
3689  */
3690  // (implicit) *vtable;
3691  union StackBufferOrFields {
3692  // fStackFields is used iff (fLengthAndFlags&kUsingStackBuffer) else fFields is used.
3693  // Each struct of the union must begin with fLengthAndFlags.
3694  struct {
3695  int16_t fLengthAndFlags; // bit fields: see constants above
3696  UChar fBuffer[US_STACKBUF_SIZE]; // buffer for short strings
3697  } fStackFields;
3698  struct {
3699  int16_t fLengthAndFlags; // bit fields: see constants above
3700  int32_t fLength; // number of characters in fArray if >127; else undefined
3701  int32_t fCapacity; // capacity of fArray (in UChars)
3702  // array pointer last to minimize padding for machines with P128 data model
3703  // or pointer sizes that are not a power of 2
3704  UChar *fArray; // the Unicode data
3705  } fFields;
3706  } fUnion;
3707 };
3708 
3717 U_COMMON_API UnicodeString U_EXPORT2
3718 operator+ (const UnicodeString &s1, const UnicodeString &s2);
3719 
3720 //========================================
3721 // Inline members
3722 //========================================
3723 
3724 //========================================
3725 // Privates
3726 //========================================
3727 
3728 inline void
3729 UnicodeString::pinIndex(int32_t& start) const
3730 {
3731  // pin index
3732  if(start < 0) {
3733  start = 0;
3734  } else if(start > length()) {
3735  start = length();
3736  }
3737 }
3738 
3739 inline void
3740 UnicodeString::pinIndices(int32_t& start,
3741  int32_t& _length) const
3742 {
3743  // pin indices
3744  int32_t len = length();
3745  if(start < 0) {
3746  start = 0;
3747  } else if(start > len) {
3748  start = len;
3749  }
3750  if(_length < 0) {
3751  _length = 0;
3752  } else if(_length > (len - start)) {
3753  _length = (len - start);
3754  }
3755 }
3756 
3757 inline UChar*
3758 UnicodeString::getArrayStart() {
3759  return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3760  fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
3761 }
3762 
3763 inline const UChar*
3764 UnicodeString::getArrayStart() const {
3765  return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3766  fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
3767 }
3768 
3769 //========================================
3770 // Default constructor
3771 //========================================
3772 
3773 inline
3774 UnicodeString::UnicodeString() {
3775  fUnion.fStackFields.fLengthAndFlags=kShortString;
3776 }
3777 
3778 //========================================
3779 // Read-only implementation methods
3780 //========================================
3781 inline UBool
3782 UnicodeString::hasShortLength() const {
3783  return fUnion.fFields.fLengthAndFlags>=0;
3784 }
3785 
3786 inline int32_t
3787 UnicodeString::getShortLength() const {
3788  // fLengthAndFlags must be non-negative -> short length >= 0
3789  // and arithmetic or logical shift does not matter.
3790  return fUnion.fFields.fLengthAndFlags>>kLengthShift;
3791 }
3792 
3793 inline int32_t
3794 UnicodeString::length() const {
3795  return hasShortLength() ? getShortLength() : fUnion.fFields.fLength;
3796 }
3797 
3798 inline int32_t
3799 UnicodeString::getCapacity() const {
3800  return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3801  US_STACKBUF_SIZE : fUnion.fFields.fCapacity;
3802 }
3803 
3804 inline int32_t
3805 UnicodeString::hashCode() const
3806 { return doHashCode(); }
3807 
3808 inline UBool
3809 UnicodeString::isBogus() const
3810 { return (UBool)(fUnion.fFields.fLengthAndFlags & kIsBogus); }
3811 
3812 inline UBool
3813 UnicodeString::isWritable() const
3814 { return (UBool)!(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus)); }
3815 
3816 inline UBool
3817 UnicodeString::isBufferWritable() const
3818 {
3819  return (UBool)(
3820  !(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus|kBufferIsReadonly)) &&
3821  (!(fUnion.fFields.fLengthAndFlags&kRefCounted) || refCount()==1));
3822 }
3823 
3824 inline const UChar *
3825 UnicodeString::getBuffer() const {
3826  if(fUnion.fFields.fLengthAndFlags&(kIsBogus|kOpenGetBuffer)) {
3827  return 0;
3828  } else if(fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) {
3829  return fUnion.fStackFields.fBuffer;
3830  } else {
3831  return fUnion.fFields.fArray;
3832  }
3833 }
3834 
3835 //========================================
3836 // Read-only alias methods
3837 //========================================
3838 inline int8_t
3839 UnicodeString::doCompare(int32_t start,
3840  int32_t thisLength,
3841  const UnicodeString& srcText,
3842  int32_t srcStart,
3843  int32_t srcLength) const
3844 {
3845  if(srcText.isBogus()) {
3846  return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
3847  } else {
3848  srcText.pinIndices(srcStart, srcLength);
3849  return doCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
3850  }
3851 }
3852 
3853 inline UBool
3855 {
3856  if(isBogus()) {
3857  return text.isBogus();
3858  } else {
3859  int32_t len = length(), textLength = text.length();
3860  return !text.isBogus() && len == textLength && doEquals(text, len);
3861  }
3862 }
3863 
3864 inline UBool
3866 { return (! operator==(text)); }
3867 
3868 inline UBool
3869 UnicodeString::operator> (const UnicodeString& text) const
3870 { return doCompare(0, length(), text, 0, text.length()) == 1; }
3871 
3872 inline UBool
3873 UnicodeString::operator< (const UnicodeString& text) const
3874 { return doCompare(0, length(), text, 0, text.length()) == -1; }
3875 
3876 inline UBool
3877 UnicodeString::operator>= (const UnicodeString& text) const
3878 { return doCompare(0, length(), text, 0, text.length()) != -1; }
3879 
3880 inline UBool
3881 UnicodeString::operator<= (const UnicodeString& text) const
3882 { return doCompare(0, length(), text, 0, text.length()) != 1; }
3883 
3884 inline int8_t
3885 UnicodeString::compare(const UnicodeString& text) const
3886 { return doCompare(0, length(), text, 0, text.length()); }
3887 
3888 inline int8_t
3889 UnicodeString::compare(int32_t start,
3890  int32_t _length,
3891  const UnicodeString& srcText) const
3892 { return doCompare(start, _length, srcText, 0, srcText.length()); }
3893 
3894 inline int8_t
3895 UnicodeString::compare(const UChar *srcChars,
3896  int32_t srcLength) const
3897 { return doCompare(0, length(), srcChars, 0, srcLength); }
3898 
3899 inline int8_t
3900 UnicodeString::compare(int32_t start,
3901  int32_t _length,
3902  const UnicodeString& srcText,
3903  int32_t srcStart,
3904  int32_t srcLength) const
3905 { return doCompare(start, _length, srcText, srcStart, srcLength); }
3906 
3907 inline int8_t
3908 UnicodeString::compare(int32_t start,
3909  int32_t _length,
3910  const UChar *srcChars) const
3911 { return doCompare(start, _length, srcChars, 0, _length); }
3912 
3913 inline int8_t
3914 UnicodeString::compare(int32_t start,
3915  int32_t _length,
3916  const UChar *srcChars,
3917  int32_t srcStart,
3918  int32_t srcLength) const
3919 { return doCompare(start, _length, srcChars, srcStart, srcLength); }
3920 
3921 inline int8_t
3922 UnicodeString::compareBetween(int32_t start,
3923  int32_t limit,
3924  const UnicodeString& srcText,
3925  int32_t srcStart,
3926  int32_t srcLimit) const
3927 { return doCompare(start, limit - start,
3928  srcText, srcStart, srcLimit - srcStart); }
3929 
3930 inline int8_t
3931 UnicodeString::doCompareCodePointOrder(int32_t start,
3932  int32_t thisLength,
3933  const UnicodeString& srcText,
3934  int32_t srcStart,
3935  int32_t srcLength) const
3936 {
3937  if(srcText.isBogus()) {
3938  return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
3939  } else {
3940  srcText.pinIndices(srcStart, srcLength);
3941  return doCompareCodePointOrder(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
3942  }
3943 }
3944 
3945 inline int8_t
3946 UnicodeString::compareCodePointOrder(const UnicodeString& text) const
3947 { return doCompareCodePointOrder(0, length(), text, 0, text.length()); }
3948 
3949 inline int8_t
3950 UnicodeString::compareCodePointOrder(int32_t start,
3951  int32_t _length,
3952  const UnicodeString& srcText) const
3953 { return doCompareCodePointOrder(start, _length, srcText, 0, srcText.length()); }
3954 
3955 inline int8_t
3956 UnicodeString::compareCodePointOrder(const UChar *srcChars,
3957  int32_t srcLength) const
3958 { return doCompareCodePointOrder(0, length(), srcChars, 0, srcLength); }
3959 
3960 inline int8_t
3961 UnicodeString::compareCodePointOrder(int32_t start,
3962  int32_t _length,
3963  const UnicodeString& srcText,
3964  int32_t srcStart,
3965  int32_t srcLength) const
3966 { return doCompareCodePointOrder(start, _length, srcText, srcStart, srcLength); }
3967 
3968 inline int8_t
3969 UnicodeString::compareCodePointOrder(int32_t start,
3970  int32_t _length,
3971  const UChar *srcChars) const
3972 { return doCompareCodePointOrder(start, _length, srcChars, 0, _length); }
3973 
3974 inline int8_t
3975 UnicodeString::compareCodePointOrder(int32_t start,
3976  int32_t _length,
3977  const UChar *srcChars,
3978  int32_t srcStart,
3979  int32_t srcLength) const
3980 { return doCompareCodePointOrder(start, _length, srcChars, srcStart, srcLength); }
3981 
3982 inline int8_t
3983 UnicodeString::compareCodePointOrderBetween(int32_t start,
3984  int32_t limit,
3985  const UnicodeString& srcText,
3986  int32_t srcStart,
3987  int32_t srcLimit) const
3988 { return doCompareCodePointOrder(start, limit - start,
3989  srcText, srcStart, srcLimit - srcStart); }
3990 
3991 inline int8_t
3992 UnicodeString::doCaseCompare(int32_t start,
3993  int32_t thisLength,
3994  const UnicodeString &srcText,
3995  int32_t srcStart,
3996  int32_t srcLength,
3997  uint32_t options) const
3998 {
3999  if(srcText.isBogus()) {
4000  return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
4001  } else {
4002  srcText.pinIndices(srcStart, srcLength);
4003  return doCaseCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength, options);
4004  }
4005 }
4006 
4007 inline int8_t
4008 UnicodeString::caseCompare(const UnicodeString &text, uint32_t options) const {
4009  return doCaseCompare(0, length(), text, 0, text.length(), options);
4010 }
4011 
4012 inline int8_t
4013 UnicodeString::caseCompare(int32_t start,
4014  int32_t _length,
4015  const UnicodeString &srcText,
4016  uint32_t options) const {
4017  return doCaseCompare(start, _length, srcText, 0, srcText.length(), options);
4018 }
4019 
4020 inline int8_t
4021 UnicodeString::caseCompare(const UChar *srcChars,
4022  int32_t srcLength,
4023  uint32_t options) const {
4024  return doCaseCompare(0, length(), srcChars, 0, srcLength, options);
4025 }
4026 
4027 inline int8_t
4028 UnicodeString::caseCompare(int32_t start,
4029  int32_t _length,
4030  const UnicodeString &srcText,
4031  int32_t srcStart,
4032  int32_t srcLength,
4033  uint32_t options) const {
4034  return doCaseCompare(start, _length, srcText, srcStart, srcLength, options);
4035 }
4036 
4037 inline int8_t
4038 UnicodeString::caseCompare(int32_t start,
4039  int32_t _length,
4040  const UChar *srcChars,
4041  uint32_t options) const {
4042  return doCaseCompare(start, _length, srcChars, 0, _length, options);
4043 }
4044 
4045 inline int8_t
4046 UnicodeString::caseCompare(int32_t start,
4047  int32_t _length,
4048  const UChar *srcChars,
4049  int32_t srcStart,
4050  int32_t srcLength,
4051  uint32_t options) const {
4052  return doCaseCompare(start, _length, srcChars, srcStart, srcLength, options);
4053 }
4054 
4055 inline int8_t
4056 UnicodeString::caseCompareBetween(int32_t start,
4057  int32_t limit,
4058  const UnicodeString &srcText,
4059  int32_t srcStart,
4060  int32_t srcLimit,
4061  uint32_t options) const {
4062  return doCaseCompare(start, limit - start, srcText, srcStart, srcLimit - srcStart, options);
4063 }
4064 
4065 inline int32_t
4066 UnicodeString::indexOf(const UnicodeString& srcText,
4067  int32_t srcStart,
4068  int32_t srcLength,
4069  int32_t start,
4070  int32_t _length) const
4071 {
4072  if(!srcText.isBogus()) {
4073  srcText.pinIndices(srcStart, srcLength);
4074  if(srcLength > 0) {
4075  return indexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
4076  }
4077  }
4078  return -1;
4079 }
4080 
4081 inline int32_t
4082 UnicodeString::indexOf(const UnicodeString& text) const
4083 { return indexOf(text, 0, text.length(), 0, length()); }
4084 
4085 inline int32_t
4086 UnicodeString::indexOf(const UnicodeString& text,
4087  int32_t start) const {
4088  pinIndex(start);
4089  return indexOf(text, 0, text.length(), start, length() - start);
4090 }
4091 
4092 inline int32_t
4093 UnicodeString::indexOf(const UnicodeString& text,
4094  int32_t start,
4095  int32_t _length) const
4096 { return indexOf(text, 0, text.length(), start, _length); }
4097 
4098 inline int32_t
4099 UnicodeString::indexOf(const UChar *srcChars,
4100  int32_t srcLength,
4101  int32_t start) const {
4102  pinIndex(start);
4103  return indexOf(srcChars, 0, srcLength, start, length() - start);
4104 }
4105 
4106 inline int32_t
4107 UnicodeString::indexOf(const UChar *srcChars,
4108  int32_t srcLength,
4109  int32_t start,
4110  int32_t _length) const
4111 { return indexOf(srcChars, 0, srcLength, start, _length); }
4112 
4113 inline int32_t
4114 UnicodeString::indexOf(UChar c,
4115  int32_t start,
4116  int32_t _length) const
4117 { return doIndexOf(c, start, _length); }
4118 
4119 inline int32_t
4120 UnicodeString::indexOf(UChar32 c,
4121  int32_t start,
4122  int32_t _length) const
4123 { return doIndexOf(c, start, _length); }
4124 
4125 inline int32_t
4126 UnicodeString::indexOf(UChar c) const
4127 { return doIndexOf(c, 0, length()); }
4128 
4129 inline int32_t
4130 UnicodeString::indexOf(UChar32 c) const
4131 { return indexOf(c, 0, length()); }
4132 
4133 inline int32_t
4134 UnicodeString::indexOf(UChar c,
4135  int32_t start) const {
4136  pinIndex(start);
4137  return doIndexOf(c, start, length() - start);
4138 }
4139 
4140 inline int32_t
4141 UnicodeString::indexOf(UChar32 c,
4142  int32_t start) const {
4143  pinIndex(start);
4144  return indexOf(c, start, length() - start);
4145 }
4146 
4147 inline int32_t
4148 UnicodeString::lastIndexOf(const UChar *srcChars,
4149  int32_t srcLength,
4150  int32_t start,
4151  int32_t _length) const
4152 { return lastIndexOf(srcChars, 0, srcLength, start, _length); }
4153 
4154 inline int32_t
4155 UnicodeString::lastIndexOf(const UChar *srcChars,
4156  int32_t srcLength,
4157  int32_t start) const {
4158  pinIndex(start);
4159  return lastIndexOf(srcChars, 0, srcLength, start, length() - start);
4160 }
4161 
4162 inline int32_t
4163 UnicodeString::lastIndexOf(const UnicodeString& srcText,
4164  int32_t srcStart,
4165  int32_t srcLength,
4166  int32_t start,
4167  int32_t _length) const
4168 {
4169  if(!srcText.isBogus()) {
4170  srcText.pinIndices(srcStart, srcLength);
4171  if(srcLength > 0) {
4172  return lastIndexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
4173  }
4174  }
4175  return -1;
4176 }
4177 
4178 inline int32_t
4179 UnicodeString::lastIndexOf(const UnicodeString& text,
4180  int32_t start,
4181  int32_t _length) const
4182 { return lastIndexOf(text, 0, text.length(), start, _length); }
4183 
4184 inline int32_t
4185 UnicodeString::lastIndexOf(const UnicodeString& text,
4186  int32_t start) const {
4187  pinIndex(start);
4188  return lastIndexOf(text, 0, text.length(), start, length() - start);
4189 }
4190 
4191 inline int32_t
4192 UnicodeString::lastIndexOf(const UnicodeString& text) const
4193 { return lastIndexOf(text, 0, text.length(), 0, length()); }
4194 
4195 inline int32_t
4196 UnicodeString::lastIndexOf(UChar c,
4197  int32_t start,
4198  int32_t _length) const
4199 { return doLastIndexOf(c, start, _length); }
4200 
4201 inline int32_t
4202 UnicodeString::lastIndexOf(UChar32 c,
4203  int32_t start,
4204  int32_t _length) const {
4205  return doLastIndexOf(c, start, _length);
4206 }
4207 
4208 inline int32_t
4209 UnicodeString::lastIndexOf(UChar c) const
4210 { return doLastIndexOf(c, 0, length()); }
4211 
4212 inline int32_t
4213 UnicodeString::lastIndexOf(UChar32 c) const {
4214  return lastIndexOf(c, 0, length());
4215 }
4216 
4217 inline int32_t
4218 UnicodeString::lastIndexOf(UChar c,
4219  int32_t start) const {
4220  pinIndex(start);
4221  return doLastIndexOf(c, start, length() - start);
4222 }
4223 
4224 inline int32_t
4225 UnicodeString::lastIndexOf(UChar32 c,
4226  int32_t start) const {
4227  pinIndex(start);
4228  return lastIndexOf(c, start, length() - start);
4229 }
4230 
4231 inline UBool
4232 UnicodeString::startsWith(const UnicodeString& text) const
4233 { return compare(0, text.length(), text, 0, text.length()) == 0; }
4234 
4235 inline UBool
4236 UnicodeString::startsWith(const UnicodeString& srcText,
4237  int32_t srcStart,
4238  int32_t srcLength) const
4239 { return doCompare(0, srcLength, srcText, srcStart, srcLength) == 0; }
4240 
4241 inline UBool
4242 UnicodeString::startsWith(const UChar *srcChars, int32_t srcLength) const {
4243  if(srcLength < 0) {
4244  srcLength = u_strlen(srcChars);
4245  }
4246  return doCompare(0, srcLength, srcChars, 0, srcLength) == 0;
4247 }
4248 
4249 inline UBool
4250 UnicodeString::startsWith(const UChar *srcChars, int32_t srcStart, int32_t srcLength) const {
4251  if(srcLength < 0) {
4252  srcLength = u_strlen(srcChars);
4253  }
4254  return doCompare(0, srcLength, srcChars, srcStart, srcLength) == 0;
4255 }
4256 
4257 inline UBool
4258 UnicodeString::endsWith(const UnicodeString& text) const
4259 { return doCompare(length() - text.length(), text.length(),
4260  text, 0, text.length()) == 0; }
4261 
4262 inline UBool
4263 UnicodeString::endsWith(const UnicodeString& srcText,
4264  int32_t srcStart,
4265  int32_t srcLength) const {
4266  srcText.pinIndices(srcStart, srcLength);
4267  return doCompare(length() - srcLength, srcLength,
4268  srcText, srcStart, srcLength) == 0;
4269 }
4270 
4271 inline UBool
4272 UnicodeString::endsWith(const UChar *srcChars,
4273  int32_t srcLength) const {
4274  if(srcLength < 0) {
4275  srcLength = u_strlen(srcChars);
4276  }
4277  return doCompare(length() - srcLength, srcLength,
4278  srcChars, 0, srcLength) == 0;
4279 }
4280 
4281 inline UBool
4282 UnicodeString::endsWith(const UChar *srcChars,
4283  int32_t srcStart,
4284  int32_t srcLength) const {
4285  if(srcLength < 0) {
4286  srcLength = u_strlen(srcChars + srcStart);
4287  }
4288  return doCompare(length() - srcLength, srcLength,
4289  srcChars, srcStart, srcLength) == 0;
4290 }
4291 
4292 //========================================
4293 // replace
4294 //========================================
4295 inline UnicodeString&
4296 UnicodeString::replace(int32_t start,
4297  int32_t _length,
4298  const UnicodeString& srcText)
4299 { return doReplace(start, _length, srcText, 0, srcText.length()); }
4300 
4301 inline UnicodeString&
4302 UnicodeString::replace(int32_t start,
4303  int32_t _length,
4304  const UnicodeString& srcText,
4305  int32_t srcStart,
4306  int32_t srcLength)
4307 { return doReplace(start, _length, srcText, srcStart, srcLength); }
4308 
4309 inline UnicodeString&
4310 UnicodeString::replace(int32_t start,
4311  int32_t _length,
4312  const UChar *srcChars,
4313  int32_t srcLength)
4314 { return doReplace(start, _length, srcChars, 0, srcLength); }
4315 
4316 inline UnicodeString&
4317 UnicodeString::replace(int32_t start,
4318  int32_t _length,
4319  const UChar *srcChars,
4320  int32_t srcStart,
4321  int32_t srcLength)
4322 { return doReplace(start, _length, srcChars, srcStart, srcLength); }
4323 
4324 inline UnicodeString&
4325 UnicodeString::replace(int32_t start,
4326  int32_t _length,
4327  UChar srcChar)
4328 { return doReplace(start, _length, &srcChar, 0, 1); }
4329 
4330 inline UnicodeString&
4331 UnicodeString::replaceBetween(int32_t start,
4332  int32_t limit,
4333  const UnicodeString& srcText)
4334 { return doReplace(start, limit - start, srcText, 0, srcText.length()); }
4335 
4336 inline UnicodeString&
4337 UnicodeString::replaceBetween(int32_t start,
4338  int32_t limit,
4339  const UnicodeString& srcText,
4340  int32_t srcStart,
4341  int32_t srcLimit)
4342 { return doReplace(start, limit - start, srcText, srcStart, srcLimit - srcStart); }
4343 
4344 inline UnicodeString&
4345 UnicodeString::findAndReplace(const UnicodeString& oldText,
4346  const UnicodeString& newText)
4347 { return findAndReplace(0, length(), oldText, 0, oldText.length(),
4348  newText, 0, newText.length()); }
4349 
4350 inline UnicodeString&
4351 UnicodeString::findAndReplace(int32_t start,
4352  int32_t _length,
4353  const UnicodeString& oldText,
4354  const UnicodeString& newText)
4355 { return findAndReplace(start, _length, oldText, 0, oldText.length(),
4356  newText, 0, newText.length()); }
4357 
4358 // ============================
4359 // extract
4360 // ============================
4361 inline void
4362 UnicodeString::doExtract(int32_t start,
4363  int32_t _length,
4364  UnicodeString& target) const
4365 { target.replace(0, target.length(), *this, start, _length); }
4366 
4367 inline void
4368 UnicodeString::extract(int32_t start,
4369  int32_t _length,
4370  UChar *target,
4371  int32_t targetStart) const
4372 { doExtract(start, _length, target, targetStart); }
4373 
4374 inline void
4375 UnicodeString::extract(int32_t start,
4376  int32_t _length,
4377  UnicodeString& target) const
4378 { doExtract(start, _length, target); }
4379 
4380 #if !UCONFIG_NO_CONVERSION
4381 
4382 inline int32_t
4383 UnicodeString::extract(int32_t start,
4384  int32_t _length,
4385  char *dst,
4386  const char *codepage) const
4387 
4388 {
4389  // This dstSize value will be checked explicitly
4390  return extract(start, _length, dst, dst!=0 ? 0xffffffff : 0, codepage);
4391 }
4392 
4393 #endif
4394 
4395 inline void
4396 UnicodeString::extractBetween(int32_t start,
4397  int32_t limit,
4398  UChar *dst,
4399  int32_t dstStart) const {
4400  pinIndex(start);
4401  pinIndex(limit);
4402  doExtract(start, limit - start, dst, dstStart);
4403 }
4404 
4405 inline UnicodeString
4406 UnicodeString::tempSubStringBetween(int32_t start, int32_t limit) const {
4407  return tempSubString(start, limit - start);
4408 }
4409 
4410 inline UChar
4411 UnicodeString::doCharAt(int32_t offset) const
4412 {
4413  if((uint32_t)offset < (uint32_t)length()) {
4414  return getArrayStart()[offset];
4415  } else {
4416  return kInvalidUChar;
4417  }
4418 }
4419 
4420 inline UChar
4421 UnicodeString::charAt(int32_t offset) const
4422 { return doCharAt(offset); }
4423 
4424 inline UChar
4425 UnicodeString::operator[] (int32_t offset) const
4426 { return doCharAt(offset); }
4427 
4428 inline UBool
4429 UnicodeString::isEmpty() const {
4430  // Arithmetic or logical right shift does not matter: only testing for 0.
4431  return (fUnion.fFields.fLengthAndFlags>>kLengthShift) == 0;
4432 }
4433 
4434 //========================================
4435 // Write implementation methods
4436 //========================================
4437 inline void
4438 UnicodeString::setZeroLength() {
4439  fUnion.fFields.fLengthAndFlags &= kAllStorageFlags;
4440 }
4441 
4442 inline void
4443 UnicodeString::setShortLength(int32_t len) {
4444  // requires 0 <= len <= kMaxShortLength
4445  fUnion.fFields.fLengthAndFlags =
4446  (int16_t)((fUnion.fFields.fLengthAndFlags & kAllStorageFlags) | (len << kLengthShift));
4447 }
4448 
4449 inline void
4450 UnicodeString::setLength(int32_t len) {
4451  if(len <= kMaxShortLength) {
4452  setShortLength(len);
4453  } else {
4454  fUnion.fFields.fLengthAndFlags |= kLengthIsLarge;
4455  fUnion.fFields.fLength = len;
4456  }
4457 }
4458 
4459 inline void
4460 UnicodeString::setToEmpty() {
4461  fUnion.fFields.fLengthAndFlags = kShortString;
4462 }
4463 
4464 inline void
4465 UnicodeString::setArray(UChar *array, int32_t len, int32_t capacity) {
4466  setLength(len);
4467  fUnion.fFields.fArray = array;
4468  fUnion.fFields.fCapacity = capacity;
4469 }
4470 
4471 inline UnicodeString&
4472 UnicodeString::operator= (UChar ch)
4473 { return doReplace(0, length(), &ch, 0, 1); }
4474 
4475 inline UnicodeString&
4476 UnicodeString::operator= (UChar32 ch)
4477 { return replace(0, length(), ch); }
4478 
4479 inline UnicodeString&
4480 UnicodeString::setTo(const UnicodeString& srcText,
4481  int32_t srcStart,
4482  int32_t srcLength)
4483 {
4484  unBogus();
4485  return doReplace(0, length(), srcText, srcStart, srcLength);
4486 }
4487 
4488 inline UnicodeString&
4489 UnicodeString::setTo(const UnicodeString& srcText,
4490  int32_t srcStart)
4491 {
4492  unBogus();
4493  srcText.pinIndex(srcStart);
4494  return doReplace(0, length(), srcText, srcStart, srcText.length() - srcStart);
4495 }
4496 
4497 inline UnicodeString&
4498 UnicodeString::setTo(const UnicodeString& srcText)
4499 {
4500  return copyFrom(srcText);
4501 }
4502 
4503 inline UnicodeString&
4504 UnicodeString::setTo(const UChar *srcChars,
4505  int32_t srcLength)
4506 {
4507  unBogus();
4508  return doReplace(0, length(), srcChars, 0, srcLength);
4509 }
4510 
4511 inline UnicodeString&
4512 UnicodeString::setTo(UChar srcChar)
4513 {
4514  unBogus();
4515  return doReplace(0, length(), &srcChar, 0, 1);
4516 }
4517 
4518 inline UnicodeString&
4519 UnicodeString::setTo(UChar32 srcChar)
4520 {
4521  unBogus();
4522  return replace(0, length(), srcChar);
4523 }
4524 
4525 inline UnicodeString&
4526 UnicodeString::append(const UnicodeString& srcText,
4527  int32_t srcStart,
4528  int32_t srcLength)
4529 { return doAppend(srcText, srcStart, srcLength); }
4530 
4531 inline UnicodeString&
4532 UnicodeString::append(const UnicodeString& srcText)
4533 { return doAppend(srcText, 0, srcText.length()); }
4534 
4535 inline UnicodeString&
4536 UnicodeString::append(const UChar *srcChars,
4537  int32_t srcStart,
4538  int32_t srcLength)
4539 { return doAppend(srcChars, srcStart, srcLength); }
4540 
4541 inline UnicodeString&
4542 UnicodeString::append(const UChar *srcChars,
4543  int32_t srcLength)
4544 { return doAppend(srcChars, 0, srcLength); }
4545 
4546 inline UnicodeString&
4547 UnicodeString::append(UChar srcChar)
4548 { return doAppend(&srcChar, 0, 1); }
4549 
4550 inline UnicodeString&
4551 UnicodeString::operator+= (UChar ch)
4552 { return doAppend(&ch, 0, 1); }
4553 
4554 inline UnicodeString&
4555 UnicodeString::operator+= (UChar32 ch) {
4556  return append(ch);
4557 }
4558 
4559 inline UnicodeString&
4560 UnicodeString::operator+= (const UnicodeString& srcText)
4561 { return doAppend(srcText, 0, srcText.length()); }
4562 
4563 inline UnicodeString&
4564 UnicodeString::insert(int32_t start,
4565  const UnicodeString& srcText,
4566  int32_t srcStart,
4567  int32_t srcLength)
4568 { return doReplace(start, 0, srcText, srcStart, srcLength); }
4569 
4570 inline UnicodeString&
4571 UnicodeString::insert(int32_t start,
4572  const UnicodeString& srcText)
4573 { return doReplace(start, 0, srcText, 0, srcText.length()); }
4574 
4575 inline UnicodeString&
4576 UnicodeString::insert(int32_t start,
4577  const UChar *srcChars,
4578  int32_t srcStart,
4579  int32_t srcLength)
4580 { return doReplace(start, 0, srcChars, srcStart, srcLength); }
4581 
4582 inline UnicodeString&
4583 UnicodeString::insert(int32_t start,
4584  const UChar *srcChars,
4585  int32_t srcLength)
4586 { return doReplace(start, 0, srcChars, 0, srcLength); }
4587 
4588 inline UnicodeString&
4589 UnicodeString::insert(int32_t start,
4590  UChar srcChar)
4591 { return doReplace(start, 0, &srcChar, 0, 1); }
4592 
4593 inline UnicodeString&
4594 UnicodeString::insert(int32_t start,
4595  UChar32 srcChar)
4596 { return replace(start, 0, srcChar); }
4597 
4598 
4599 inline UnicodeString&
4600 UnicodeString::remove()
4601 {
4602  // remove() of a bogus string makes the string empty and non-bogus
4603  if(isBogus()) {
4604  setToEmpty();
4605  } else {
4606  setZeroLength();
4607  }
4608  return *this;
4609 }
4610 
4611 inline UnicodeString&
4612 UnicodeString::remove(int32_t start,
4613  int32_t _length)
4614 {
4615  if(start <= 0 && _length == INT32_MAX) {
4616  // remove(guaranteed everything) of a bogus string makes the string empty and non-bogus
4617  return remove();
4618  }
4619  return doReplace(start, _length, NULL, 0, 0);
4620 }
4621 
4622 inline UnicodeString&
4623 UnicodeString::removeBetween(int32_t start,
4624  int32_t limit)
4625 { return doReplace(start, limit - start, NULL, 0, 0); }
4626 
4627 inline UnicodeString &
4628 UnicodeString::retainBetween(int32_t start, int32_t limit) {
4629  truncate(limit);
4630  return doReplace(0, start, NULL, 0, 0);
4631 }
4632 
4633 inline UBool
4634 UnicodeString::truncate(int32_t targetLength)
4635 {
4636  if(isBogus() && targetLength == 0) {
4637  // truncate(0) of a bogus string makes the string empty and non-bogus
4638  unBogus();
4639  return FALSE;
4640  } else if((uint32_t)targetLength < (uint32_t)length()) {
4641  setLength(targetLength);
4642  return TRUE;
4643  } else {
4644  return FALSE;
4645  }
4646 }
4647 
4648 inline UnicodeString&
4649 UnicodeString::reverse()
4650 { return doReverse(0, length()); }
4651 
4652 inline UnicodeString&
4653 UnicodeString::reverse(int32_t start,
4654  int32_t _length)
4655 { return doReverse(start, _length); }
4656 
4658 
4659 #endif
#define UNISTR_OBJECT_SIZE
Desired sizeof(UnicodeString) in bytes.
Definition: unistr.h:211
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:68
An Appendable implementation which writes to a UnicodeString.
Definition: appendable.h:151
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:305
virtual UChar getCharAt(int32_t offset) const =0
Virtual version of charAt().
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:1946
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:849
void * UClassID
UClassID is used to identify classes without using the compiler&#39;s RTTI.
Definition: uobject.h:91
struct UCaseMap UCaseMap
C typedef for struct UCaseMap.
Definition: ucasemap.h:45
#define U_SIZEOF_UCHAR
Number of bytes in a UChar.
Definition: umachine.h:289
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:48
virtual UChar32 getChar32At(int32_t offset) const =0
Virtual version of char32At().
UBool isBogus(void) const
Determine if this object contains a valid string.
Definition: unistr.h:3809
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:71
#define UNISTR_FROM_CHAR_EXPLICIT
This can be defined to be empty or "explicit".
Definition: unistr.h:151
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:129
StringClass & toUTF8String(StringClass &result) const
Convert the UnicodeString to UTF-8 and append the result to a standard string.
Definition: unistr.h:1731
int32_t length() const
Returns the number of 16-bit code units in the text.
Definition: rep.h:243
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:100
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:253
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
Definition: umachine.h:332
#define NULL
Define NULL if necessary, to 0 for C++ and to ((void *)0) for C.
Definition: utypes.h:186
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...
#define TRUE
The TRUE value of a UBool.
Definition: umachine.h:238
#define U_NOEXCEPT
"noexcept" if supported, otherwise empty.
Definition: platform.h:529
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:312
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:130
struct UConverter UConverter
Definition: ucnv_err.h:94
#define INT32_MAX
The largest value a 32 bit signed integer can hold.
Definition: umachine.h:180
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:476
int32_t length(void) const
Return the length of the UnicodeString object.
Definition: unistr.h:3794
UChar charAt(int32_t offset) const
Returns the 16-bit code unit at the given offset into the text.
Definition: rep.h:248
virtual void handleReplaceBetween(int32_t start, int32_t limit, const UnicodeString &text)=0
Replaces a substring of this object with the given text.
Basic definitions for ICU, for both C and C++ APIs.
Implementation of ByteSink that writes to a "string".
Definition: bytestream.h:231
int32_t u_strlen(const UChar *s)
Determine the length of an array of UChar.
virtual Replaceable * clone() const
Clone this object, an instance of a subclass of Replaceable.
#define FALSE
The FALSE value of a UBool.
Definition: umachine.h:242
#define U_COMMON_API
Set to export library symbols from inside the common library, and to import them from outside...
Definition: utypes.h:357
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:293
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:171
A string-like object that points to a sized piece of memory.
Definition: stringpiece.h:52
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:4302
#define U_STABLE
This is used to declare a function as a stable public ICU C API.
Definition: umachine.h:109
int8_t UBool
The ICU boolean type.
Definition: umachine.h:234
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:185
C++ API: Replaceable String.