ICU 50.2 50.2
unistr.h
Go to the documentation of this file.
1/*
2**********************************************************************
3* Copyright (C) 1998-2012, 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
28
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
36struct UConverter; // unicode/ucnv.h
37class StringThreadTest;
38
39#ifndef U_COMPARE_CODE_POINT_ORDER
40/* see also ustring.h and unorm.h */
46#define U_COMPARE_CODE_POINT_ORDER 0x8000
47#endif
48
49#ifndef USTRING_H
53U_STABLE int32_t U_EXPORT2
54u_strlen(const UChar *s);
55#endif
56
61
62#ifndef U_STRING_CASE_MAPPER_DEFINED
63#define U_STRING_CASE_MAPPER_DEFINED
64
69typedef 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
79class BreakIterator; // unicode/brkiter.h
80class Locale; // unicode/locid.h
82class UnicodeStringAppendable; // unicode/appendable.h
83
84/* The <iostream> include has been moved to unicode/ustream.h */
85
96#define US_INV icu::UnicodeString::kInvariant
97
115#if defined(U_DECLARE_UTF16)
116# define UNICODE_STRING(cs, _length) icu::UnicodeString(TRUE, (const UChar *)U_DECLARE_UTF16(cs), _length)
117#elif U_SIZEOF_WCHAR_T==U_SIZEOF_UCHAR && (U_CHARSET_FAMILY==U_ASCII_FAMILY || (U_SIZEOF_UCHAR == 2 && defined(U_WCHAR_IS_UTF16)))
118# define UNICODE_STRING(cs, _length) icu::UnicodeString(TRUE, (const UChar *)L ## cs, _length)
119#elif U_SIZEOF_UCHAR==1 && U_CHARSET_FAMILY==U_ASCII_FAMILY
120# define UNICODE_STRING(cs, _length) icu::UnicodeString(TRUE, (const UChar *)cs, _length)
121#else
122# define UNICODE_STRING(cs, _length) icu::UnicodeString(cs, _length, US_INV)
123#endif
124
138#define UNICODE_STRING_SIMPLE(cs) UNICODE_STRING(cs, -1)
139
147#ifndef UNISTR_FROM_CHAR_EXPLICIT
148# if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION)
149 // Auto-"explicit" in ICU library code.
150# define UNISTR_FROM_CHAR_EXPLICIT explicit
151# else
152 // Empty by default for source code compatibility.
153# define UNISTR_FROM_CHAR_EXPLICIT
154# endif
155#endif
156
167#ifndef UNISTR_FROM_STRING_EXPLICIT
168# if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION)
169 // Auto-"explicit" in ICU library code.
170# define UNISTR_FROM_STRING_EXPLICIT explicit
171# else
172 // Empty by default for source code compatibility.
173# define UNISTR_FROM_STRING_EXPLICIT
174# endif
175#endif
176
247{
248public:
249
265
266 //========================================
267 // Read-only operations
268 //========================================
269
270 /* Comparison - bitwise only - for international comparison use collation */
271
279 inline UBool operator== (const UnicodeString& text) const;
280
288 inline UBool operator!= (const UnicodeString& text) const;
289
297 inline UBool operator> (const UnicodeString& text) const;
298
306 inline UBool operator< (const UnicodeString& text) const;
307
315 inline UBool operator>= (const UnicodeString& text) const;
316
324 inline UBool operator<= (const UnicodeString& text) const;
325
337 inline int8_t compare(const UnicodeString& text) const;
338
353 inline int8_t compare(int32_t start,
354 int32_t length,
355 const UnicodeString& text) const;
356
374 inline int8_t compare(int32_t start,
375 int32_t length,
376 const UnicodeString& srcText,
377 int32_t srcStart,
378 int32_t srcLength) const;
379
392 inline int8_t compare(const UChar *srcChars,
393 int32_t srcLength) const;
394
409 inline int8_t compare(int32_t start,
410 int32_t length,
411 const UChar *srcChars) const;
412
430 inline int8_t compare(int32_t start,
431 int32_t length,
432 const UChar *srcChars,
433 int32_t srcStart,
434 int32_t srcLength) const;
435
453 inline int8_t compareBetween(int32_t start,
454 int32_t limit,
455 const UnicodeString& srcText,
456 int32_t srcStart,
457 int32_t srcLimit) const;
458
476 inline int8_t compareCodePointOrder(const UnicodeString& text) const;
477
497 inline int8_t compareCodePointOrder(int32_t start,
498 int32_t length,
499 const UnicodeString& srcText) const;
500
522 inline int8_t compareCodePointOrder(int32_t start,
523 int32_t length,
524 const UnicodeString& srcText,
525 int32_t srcStart,
526 int32_t srcLength) const;
527
546 inline int8_t compareCodePointOrder(const UChar *srcChars,
547 int32_t srcLength) const;
548
568 inline int8_t compareCodePointOrder(int32_t start,
569 int32_t length,
570 const UChar *srcChars) const;
571
593 inline int8_t compareCodePointOrder(int32_t start,
594 int32_t length,
595 const UChar *srcChars,
596 int32_t srcStart,
597 int32_t srcLength) const;
598
620 inline int8_t compareCodePointOrderBetween(int32_t start,
621 int32_t limit,
622 const UnicodeString& srcText,
623 int32_t srcStart,
624 int32_t srcLimit) const;
625
644 inline int8_t caseCompare(const UnicodeString& text, uint32_t options) const;
645
666 inline int8_t caseCompare(int32_t start,
667 int32_t length,
668 const UnicodeString& srcText,
669 uint32_t options) const;
670
693 inline int8_t caseCompare(int32_t start,
694 int32_t length,
695 const UnicodeString& srcText,
696 int32_t srcStart,
697 int32_t srcLength,
698 uint32_t options) const;
699
719 inline int8_t caseCompare(const UChar *srcChars,
720 int32_t srcLength,
721 uint32_t options) const;
722
743 inline int8_t caseCompare(int32_t start,
744 int32_t length,
745 const UChar *srcChars,
746 uint32_t options) const;
747
770 inline int8_t caseCompare(int32_t start,
771 int32_t length,
772 const UChar *srcChars,
773 int32_t srcStart,
774 int32_t srcLength,
775 uint32_t options) const;
776
799 inline int8_t caseCompareBetween(int32_t start,
800 int32_t limit,
801 const UnicodeString& srcText,
802 int32_t srcStart,
803 int32_t srcLimit,
804 uint32_t options) const;
805
813 inline UBool startsWith(const UnicodeString& text) const;
814
825 inline UBool startsWith(const UnicodeString& srcText,
826 int32_t srcStart,
827 int32_t srcLength) const;
828
837 inline UBool startsWith(const UChar *srcChars,
838 int32_t srcLength) const;
839
849 inline UBool startsWith(const UChar *srcChars,
850 int32_t srcStart,
851 int32_t srcLength) const;
852
860 inline UBool endsWith(const UnicodeString& text) const;
861
872 inline UBool endsWith(const UnicodeString& srcText,
873 int32_t srcStart,
874 int32_t srcLength) const;
875
884 inline UBool endsWith(const UChar *srcChars,
885 int32_t srcLength) const;
886
897 inline UBool endsWith(const UChar *srcChars,
898 int32_t srcStart,
899 int32_t srcLength) const;
900
901
902 /* Searching - bitwise only */
903
912 inline int32_t indexOf(const UnicodeString& text) const;
913
923 inline int32_t indexOf(const UnicodeString& text,
924 int32_t start) const;
925
937 inline int32_t indexOf(const UnicodeString& text,
938 int32_t start,
939 int32_t length) const;
940
957 inline int32_t indexOf(const UnicodeString& srcText,
958 int32_t srcStart,
959 int32_t srcLength,
960 int32_t start,
961 int32_t length) const;
962
974 inline int32_t indexOf(const UChar *srcChars,
975 int32_t srcLength,
976 int32_t start) const;
977
990 inline int32_t indexOf(const UChar *srcChars,
991 int32_t srcLength,
992 int32_t start,
993 int32_t length) const;
994
1011 int32_t indexOf(const UChar *srcChars,
1012 int32_t srcStart,
1013 int32_t srcLength,
1014 int32_t start,
1015 int32_t length) const;
1016
1024 inline int32_t indexOf(UChar c) const;
1025
1034 inline int32_t indexOf(UChar32 c) const;
1035
1044 inline int32_t indexOf(UChar c,
1045 int32_t start) const;
1046
1056 inline int32_t indexOf(UChar32 c,
1057 int32_t start) const;
1058
1069 inline int32_t indexOf(UChar c,
1070 int32_t start,
1071 int32_t length) const;
1072
1084 inline int32_t indexOf(UChar32 c,
1085 int32_t start,
1086 int32_t length) const;
1087
1096 inline int32_t lastIndexOf(const UnicodeString& text) const;
1097
1107 inline int32_t lastIndexOf(const UnicodeString& text,
1108 int32_t start) const;
1109
1121 inline int32_t lastIndexOf(const UnicodeString& text,
1122 int32_t start,
1123 int32_t length) const;
1124
1141 inline int32_t lastIndexOf(const UnicodeString& srcText,
1142 int32_t srcStart,
1143 int32_t srcLength,
1144 int32_t start,
1145 int32_t length) const;
1146
1157 inline int32_t lastIndexOf(const UChar *srcChars,
1158 int32_t srcLength,
1159 int32_t start) const;
1160
1173 inline int32_t lastIndexOf(const UChar *srcChars,
1174 int32_t srcLength,
1175 int32_t start,
1176 int32_t length) const;
1177
1194 int32_t lastIndexOf(const UChar *srcChars,
1195 int32_t srcStart,
1196 int32_t srcLength,
1197 int32_t start,
1198 int32_t length) const;
1199
1207 inline int32_t lastIndexOf(UChar c) const;
1208
1217 inline int32_t lastIndexOf(UChar32 c) const;
1218
1227 inline int32_t lastIndexOf(UChar c,
1228 int32_t start) const;
1229
1239 inline int32_t lastIndexOf(UChar32 c,
1240 int32_t start) const;
1241
1252 inline int32_t lastIndexOf(UChar c,
1253 int32_t start,
1254 int32_t length) const;
1255
1267 inline int32_t lastIndexOf(UChar32 c,
1268 int32_t start,
1269 int32_t length) const;
1270
1271
1272 /* Character access */
1273
1282 inline UChar charAt(int32_t offset) const;
1283
1291 inline UChar operator[] (int32_t offset) const;
1292
1304 UChar32 char32At(int32_t offset) const;
1305
1321 int32_t getChar32Start(int32_t offset) const;
1322
1339 int32_t getChar32Limit(int32_t offset) const;
1340
1391 int32_t moveIndex32(int32_t index, int32_t delta) const;
1392
1393 /* Substring extraction */
1394
1410 inline void extract(int32_t start,
1411 int32_t length,
1412 UChar *dst,
1413 int32_t dstStart = 0) const;
1414
1436 int32_t
1437 extract(UChar *dest, int32_t destCapacity,
1438 UErrorCode &errorCode) const;
1439
1450 inline void extract(int32_t start,
1451 int32_t length,
1452 UnicodeString& target) const;
1453
1465 inline void extractBetween(int32_t start,
1466 int32_t limit,
1467 UChar *dst,
1468 int32_t dstStart = 0) const;
1469
1479 virtual void extractBetween(int32_t start,
1480 int32_t limit,
1481 UnicodeString& target) const;
1482
1504 int32_t extract(int32_t start,
1505 int32_t startLength,
1506 char *target,
1507 int32_t targetCapacity,
1508 enum EInvariant inv) const;
1509
1510#if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
1511
1531 int32_t extract(int32_t start,
1532 int32_t startLength,
1533 char *target,
1534 uint32_t targetLength) const;
1535
1536#endif
1537
1538#if !UCONFIG_NO_CONVERSION
1539
1565 inline int32_t extract(int32_t start,
1566 int32_t startLength,
1567 char *target,
1568 const char *codepage = 0) const;
1569
1599 int32_t extract(int32_t start,
1600 int32_t startLength,
1601 char *target,
1602 uint32_t targetLength,
1603 const char *codepage) const;
1604
1622 int32_t extract(char *dest, int32_t destCapacity,
1623 UConverter *cnv,
1624 UErrorCode &errorCode) const;
1625
1626#endif
1627
1641 UnicodeString tempSubString(int32_t start=0, int32_t length=INT32_MAX) const;
1642
1653 inline UnicodeString tempSubStringBetween(int32_t start, int32_t limit=INT32_MAX) const;
1654
1666 void toUTF8(ByteSink &sink) const;
1667
1668#if U_HAVE_STD_STRING
1669
1682 template<typename StringClass>
1683 StringClass &toUTF8String(StringClass &result) const {
1684 StringByteSink<StringClass> sbs(&result);
1685 toUTF8(sbs);
1686 return result;
1687 }
1688
1689#endif
1690
1706 int32_t toUTF32(UChar32 *utf32, int32_t capacity, UErrorCode &errorCode) const;
1707
1708 /* Length operations */
1709
1718 inline int32_t length(void) const;
1719
1733 int32_t
1734 countChar32(int32_t start=0, int32_t length=INT32_MAX) const;
1735
1759 UBool
1760 hasMoreChar32Than(int32_t start, int32_t length, int32_t number) const;
1761
1767 inline UBool isEmpty(void) const;
1768
1778 inline int32_t getCapacity(void) const;
1779
1780 /* Other operations */
1781
1787 inline int32_t hashCode(void) const;
1788
1801 inline UBool isBogus(void) const;
1802
1803
1804 //========================================
1805 // Write operations
1806 //========================================
1807
1808 /* Assignment operations */
1809
1818
1842
1850 inline UnicodeString& operator= (UChar ch);
1851
1859 inline UnicodeString& operator= (UChar32 ch);
1860
1872 inline UnicodeString& setTo(const UnicodeString& srcText,
1873 int32_t srcStart);
1874
1888 inline UnicodeString& setTo(const UnicodeString& srcText,
1889 int32_t srcStart,
1890 int32_t srcLength);
1891
1900 inline UnicodeString& setTo(const UnicodeString& srcText);
1901
1910 inline UnicodeString& setTo(const UChar *srcChars,
1911 int32_t srcLength);
1912
1921 UnicodeString& setTo(UChar srcChar);
1922
1931 UnicodeString& setTo(UChar32 srcChar);
1932
1957 const UChar *text,
1958 int32_t textLength);
1959
1980 int32_t buffLength,
1981 int32_t buffCapacity);
1982
2024
2032 UnicodeString& setCharAt(int32_t offset,
2033 UChar ch);
2034
2035
2036 /* Append operations */
2037
2045 inline UnicodeString& operator+= (UChar ch);
2046
2054 inline UnicodeString& operator+= (UChar32 ch);
2055
2063 inline UnicodeString& operator+= (const UnicodeString& srcText);
2064
2079 inline UnicodeString& append(const UnicodeString& srcText,
2080 int32_t srcStart,
2081 int32_t srcLength);
2082
2090 inline UnicodeString& append(const UnicodeString& srcText);
2091
2105 inline UnicodeString& append(const UChar *srcChars,
2106 int32_t srcStart,
2107 int32_t srcLength);
2108
2118 inline UnicodeString& append(const UChar *srcChars,
2119 int32_t srcLength);
2120
2127 inline UnicodeString& append(UChar srcChar);
2128
2136
2137
2138 /* Insert operations */
2139
2153 inline UnicodeString& insert(int32_t start,
2154 const UnicodeString& srcText,
2155 int32_t srcStart,
2156 int32_t srcLength);
2157
2166 inline UnicodeString& insert(int32_t start,
2167 const UnicodeString& srcText);
2168
2182 inline UnicodeString& insert(int32_t start,
2183 const UChar *srcChars,
2184 int32_t srcStart,
2185 int32_t srcLength);
2186
2196 inline UnicodeString& insert(int32_t start,
2197 const UChar *srcChars,
2198 int32_t srcLength);
2199
2208 inline UnicodeString& insert(int32_t start,
2209 UChar srcChar);
2210
2219 inline UnicodeString& insert(int32_t start,
2220 UChar32 srcChar);
2221
2222
2223 /* Replace operations */
2224
2242 UnicodeString& replace(int32_t start,
2243 int32_t length,
2244 const UnicodeString& srcText,
2245 int32_t srcStart,
2246 int32_t srcLength);
2247
2260 UnicodeString& replace(int32_t start,
2261 int32_t length,
2262 const UnicodeString& srcText);
2263
2281 UnicodeString& replace(int32_t start,
2282 int32_t length,
2283 const UChar *srcChars,
2284 int32_t srcStart,
2285 int32_t srcLength);
2286
2299 inline UnicodeString& replace(int32_t start,
2300 int32_t length,
2301 const UChar *srcChars,
2302 int32_t srcLength);
2303
2315 inline UnicodeString& replace(int32_t start,
2316 int32_t length,
2317 UChar srcChar);
2318
2330 UnicodeString& replace(int32_t start, int32_t length, UChar32 srcChar);
2331
2341 inline UnicodeString& replaceBetween(int32_t start,
2342 int32_t limit,
2343 const UnicodeString& srcText);
2344
2359 inline UnicodeString& replaceBetween(int32_t start,
2360 int32_t limit,
2361 const UnicodeString& srcText,
2362 int32_t srcStart,
2363 int32_t srcLimit);
2364
2375 virtual void handleReplaceBetween(int32_t start,
2376 int32_t limit,
2377 const UnicodeString& text);
2378
2384 virtual UBool hasMetaData() const;
2385
2401 virtual void copy(int32_t start, int32_t limit, int32_t dest);
2402
2403 /* Search and replace operations */
2404
2413 inline UnicodeString& findAndReplace(const UnicodeString& oldText,
2414 const UnicodeString& newText);
2415
2427 inline UnicodeString& findAndReplace(int32_t start,
2428 int32_t length,
2429 const UnicodeString& oldText,
2430 const UnicodeString& newText);
2431
2450 int32_t length,
2451 const UnicodeString& oldText,
2452 int32_t oldStart,
2453 int32_t oldLength,
2454 const UnicodeString& newText,
2455 int32_t newStart,
2456 int32_t newLength);
2457
2458
2459 /* Remove operations */
2460
2466 inline UnicodeString& remove(void);
2467
2476 inline UnicodeString& remove(int32_t start,
2477 int32_t length = (int32_t)INT32_MAX);
2478
2487 inline UnicodeString& removeBetween(int32_t start,
2488 int32_t limit = (int32_t)INT32_MAX);
2489
2499 inline UnicodeString &retainBetween(int32_t start, int32_t limit = INT32_MAX);
2500
2501 /* Length operations */
2502
2514 UBool padLeading(int32_t targetLength,
2515 UChar padChar = 0x0020);
2516
2528 UBool padTrailing(int32_t targetLength,
2529 UChar padChar = 0x0020);
2530
2537 inline UBool truncate(int32_t targetLength);
2538
2545
2546
2547 /* Miscellaneous operations */
2548
2554 inline UnicodeString& reverse(void);
2555
2564 inline UnicodeString& reverse(int32_t start,
2565 int32_t length);
2566
2574
2583
2591
2600
2601#if !UCONFIG_NO_BREAK_ITERATION
2602
2630
2658 UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale);
2659
2691 UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale, uint32_t options);
2692
2693#endif
2694
2708 UnicodeString &foldCase(uint32_t options=0 /*U_FOLD_CASE_DEFAULT*/);
2709
2710 //========================================
2711 // Access to the internal buffer
2712 //========================================
2713
2757 UChar *getBuffer(int32_t minCapacity);
2758
2779 void releaseBuffer(int32_t newLength=-1);
2780
2811 inline const UChar *getBuffer() const;
2812
2846 inline const UChar *getTerminatedBuffer();
2847
2848 //========================================
2849 // Constructors
2850 //========================================
2851
2856
2868 UnicodeString(int32_t capacity, UChar32 c, int32_t count);
2869
2880
2891
2903
2912 int32_t textLength);
2913
2936 UnicodeString(UBool isTerminated,
2937 const UChar *text,
2938 int32_t textLength);
2939
2958 UnicodeString(UChar *buffer, int32_t buffLength, int32_t buffCapacity);
2959
2960#if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
2961
2982
2991 UnicodeString(const char *codepageData, int32_t dataLength);
2992
2993#endif
2994
2995#if !UCONFIG_NO_CONVERSION
2996
3014 UnicodeString(const char *codepageData, const char *codepage);
3015
3033 UnicodeString(const char *codepageData, int32_t dataLength, const char *codepage);
3034
3057 const char *src, int32_t srcLength,
3058 UConverter *cnv,
3059 UErrorCode &errorCode);
3060
3061#endif
3062
3087 UnicodeString(const char *src, int32_t length, enum EInvariant inv);
3088
3089
3096
3103 UnicodeString(const UnicodeString& src, int32_t srcStart);
3104
3112 UnicodeString(const UnicodeString& src, int32_t srcStart, int32_t srcLength);
3113
3130 virtual Replaceable *clone() const;
3131
3136
3151
3163 static UnicodeString fromUTF32(const UChar32 *utf32, int32_t length);
3164
3165 /* Miscellaneous operations */
3166
3202
3222 UChar32 unescapeAt(int32_t &offset) const;
3223
3229 static UClassID U_EXPORT2 getStaticClassID();
3230
3237
3238 //========================================
3239 // Implementation methods
3240 //========================================
3241
3242protected:
3247 virtual int32_t getLength() const;
3248
3254 virtual UChar getCharAt(int32_t offset) const;
3255
3261 virtual UChar32 getChar32At(int32_t offset) const;
3262
3263private:
3264 // For char* constructors. Could be made public.
3265 UnicodeString &setToUTF8(const StringPiece &utf8);
3266 // For extract(char*).
3267 // We could make a toUTF8(target, capacity, errorCode) public but not
3268 // this version: New API will be cleaner if we make callers create substrings
3269 // rather than having start+length on every method,
3270 // and it should take a UErrorCode&.
3271 int32_t
3272 toUTF8(int32_t start, int32_t len,
3273 char *target, int32_t capacity) const;
3274
3279 UBool doEquals(const UnicodeString &text, int32_t len) const;
3280
3281 inline int8_t
3282 doCompare(int32_t start,
3283 int32_t length,
3284 const UnicodeString& srcText,
3285 int32_t srcStart,
3286 int32_t srcLength) const;
3287
3288 int8_t doCompare(int32_t start,
3289 int32_t length,
3290 const UChar *srcChars,
3291 int32_t srcStart,
3292 int32_t srcLength) const;
3293
3294 inline int8_t
3295 doCompareCodePointOrder(int32_t start,
3296 int32_t length,
3297 const UnicodeString& srcText,
3298 int32_t srcStart,
3299 int32_t srcLength) const;
3300
3301 int8_t doCompareCodePointOrder(int32_t start,
3302 int32_t length,
3303 const UChar *srcChars,
3304 int32_t srcStart,
3305 int32_t srcLength) const;
3306
3307 inline int8_t
3308 doCaseCompare(int32_t start,
3309 int32_t length,
3310 const UnicodeString &srcText,
3311 int32_t srcStart,
3312 int32_t srcLength,
3313 uint32_t options) const;
3314
3315 int8_t
3316 doCaseCompare(int32_t start,
3317 int32_t length,
3318 const UChar *srcChars,
3319 int32_t srcStart,
3320 int32_t srcLength,
3321 uint32_t options) const;
3322
3323 int32_t doIndexOf(UChar c,
3324 int32_t start,
3325 int32_t length) const;
3326
3327 int32_t doIndexOf(UChar32 c,
3328 int32_t start,
3329 int32_t length) const;
3330
3331 int32_t doLastIndexOf(UChar c,
3332 int32_t start,
3333 int32_t length) const;
3334
3335 int32_t doLastIndexOf(UChar32 c,
3336 int32_t start,
3337 int32_t length) const;
3338
3339 void doExtract(int32_t start,
3340 int32_t length,
3341 UChar *dst,
3342 int32_t dstStart) const;
3343
3344 inline void doExtract(int32_t start,
3345 int32_t length,
3346 UnicodeString& target) const;
3347
3348 inline UChar doCharAt(int32_t offset) const;
3349
3350 UnicodeString& doReplace(int32_t start,
3351 int32_t length,
3352 const UnicodeString& srcText,
3353 int32_t srcStart,
3354 int32_t srcLength);
3355
3356 UnicodeString& doReplace(int32_t start,
3357 int32_t length,
3358 const UChar *srcChars,
3359 int32_t srcStart,
3360 int32_t srcLength);
3361
3362 UnicodeString& doReverse(int32_t start,
3363 int32_t length);
3364
3365 // calculate hash code
3366 int32_t doHashCode(void) const;
3367
3368 // get pointer to start of array
3369 // these do not check for kOpenGetBuffer, unlike the public getBuffer() function
3370 inline UChar* getArrayStart(void);
3371 inline const UChar* getArrayStart(void) const;
3372
3373 // A UnicodeString object (not necessarily its current buffer)
3374 // is writable unless it isBogus() or it has an "open" getBuffer(minCapacity).
3375 inline UBool isWritable() const;
3376
3377 // Is the current buffer writable?
3378 inline UBool isBufferWritable() const;
3379
3380 // None of the following does releaseArray().
3381 inline void setLength(int32_t len); // sets only fShortLength and fLength
3382 inline void setToEmpty(); // sets fFlags=kShortString
3383 inline void setArray(UChar *array, int32_t len, int32_t capacity); // does not set fFlags
3384
3385 // allocate the array; result may be fStackBuffer
3386 // sets refCount to 1 if appropriate
3387 // sets fArray, fCapacity, and fFlags
3388 // returns boolean for success or failure
3389 UBool allocate(int32_t capacity);
3390
3391 // release the array if owned
3392 void releaseArray(void);
3393
3394 // turn a bogus string into an empty one
3395 void unBogus();
3396
3397 // implements assigment operator, copy constructor, and fastCopyFrom()
3398 UnicodeString &copyFrom(const UnicodeString &src, UBool fastCopy=FALSE);
3399
3400 // Pin start and limit to acceptable values.
3401 inline void pinIndex(int32_t& start) const;
3402 inline void pinIndices(int32_t& start,
3403 int32_t& length) const;
3404
3405#if !UCONFIG_NO_CONVERSION
3406
3407 /* Internal extract() using UConverter. */
3408 int32_t doExtract(int32_t start, int32_t length,
3409 char *dest, int32_t destCapacity,
3410 UConverter *cnv,
3411 UErrorCode &errorCode) const;
3412
3413 /*
3414 * Real constructor for converting from codepage data.
3415 * It assumes that it is called with !fRefCounted.
3416 *
3417 * If <code>codepage==0</code>, then the default converter
3418 * is used for the platform encoding.
3419 * If <code>codepage</code> is an empty string (<code>""</code>),
3420 * then a simple conversion is performed on the codepage-invariant
3421 * subset ("invariant characters") of the platform encoding. See utypes.h.
3422 */
3423 void doCodepageCreate(const char *codepageData,
3424 int32_t dataLength,
3425 const char *codepage);
3426
3427 /*
3428 * Worker function for creating a UnicodeString from
3429 * a codepage string using a UConverter.
3430 */
3431 void
3432 doCodepageCreate(const char *codepageData,
3433 int32_t dataLength,
3434 UConverter *converter,
3435 UErrorCode &status);
3436
3437#endif
3438
3439 /*
3440 * This function is called when write access to the array
3441 * is necessary.
3442 *
3443 * We need to make a copy of the array if
3444 * the buffer is read-only, or
3445 * the buffer is refCounted (shared), and refCount>1, or
3446 * the buffer is too small.
3447 *
3448 * Return FALSE if memory could not be allocated.
3449 */
3450 UBool cloneArrayIfNeeded(int32_t newCapacity = -1,
3451 int32_t growCapacity = -1,
3452 UBool doCopyArray = TRUE,
3453 int32_t **pBufferToDelete = 0,
3454 UBool forceClone = FALSE);
3455
3462 caseMap(const UCaseMap *csm, UStringCaseMapper *stringCaseMapper);
3463
3464 // ref counting
3465 void addRef(void);
3466 int32_t removeRef(void);
3467 int32_t refCount(void) const;
3468
3469 // constants
3470 enum {
3471 // Set the stack buffer size so that sizeof(UnicodeString) is,
3472 // naturally (without padding), a multiple of sizeof(pointer).
3473 US_STACKBUF_SIZE= sizeof(void *)==4 ? 13 : 15, // Size of stack buffer for short strings
3474 kInvalidUChar=0xffff, // invalid UChar index
3475 kGrowSize=128, // grow size for this buffer
3476 kInvalidHashCode=0, // invalid hash code
3477 kEmptyHashCode=1, // hash code for empty string
3478
3479 // bit flag values for fFlags
3480 kIsBogus=1, // this string is bogus, i.e., not valid or NULL
3481 kUsingStackBuffer=2,// using fUnion.fStackBuffer instead of fUnion.fFields
3482 kRefCounted=4, // there is a refCount field before the characters in fArray
3483 kBufferIsReadonly=8,// do not write to this buffer
3484 kOpenGetBuffer=16, // getBuffer(minCapacity) was called (is "open"),
3485 // and releaseBuffer(newLength) must be called
3486
3487 // combined values for convenience
3488 kShortString=kUsingStackBuffer,
3489 kLongString=kRefCounted,
3490 kReadonlyAlias=kBufferIsReadonly,
3491 kWritableAlias=0
3492 };
3493
3494 friend class StringThreadTest;
3495 friend class UnicodeStringAppendable;
3496
3497 union StackBufferOrFields; // forward declaration necessary before friend declaration
3498 friend union StackBufferOrFields; // make US_STACKBUF_SIZE visible inside fUnion
3499
3500 /*
3501 * The following are all the class fields that are stored
3502 * in each UnicodeString object.
3503 * Note that UnicodeString has virtual functions,
3504 * therefore there is an implicit vtable pointer
3505 * as the first real field.
3506 * The fields should be aligned such that no padding is necessary.
3507 * On 32-bit machines, the size should be 32 bytes,
3508 * on 64-bit machines (8-byte pointers), it should be 40 bytes.
3509 *
3510 * We use a hack to achieve this.
3511 *
3512 * With at least some compilers, each of the following is forced to
3513 * a multiple of sizeof(pointer) [the largest field base unit here is a data pointer],
3514 * rounded up with additional padding if the fields do not already fit that requirement:
3515 * - sizeof(class UnicodeString)
3516 * - offsetof(UnicodeString, fUnion)
3517 * - sizeof(fUnion)
3518 * - sizeof(fFields)
3519 *
3520 * In order to avoid padding, we make sizeof(fStackBuffer)=16 (=8 UChars)
3521 * which is at least as large as sizeof(fFields) on 32-bit and 64-bit machines.
3522 * (Padding at the end of fFields is ok:
3523 * As long as there is no padding after fStackBuffer, it is not wasted space.)
3524 *
3525 * We further assume that the compiler does not reorder the fields,
3526 * so that fRestOfStackBuffer (which holds a few more UChars) immediately follows after fUnion,
3527 * with at most some padding (but no other field) in between.
3528 * (Padding there would be wasted space, but functionally harmless.)
3529 *
3530 * We use a few more sizeof(pointer)'s chunks of space with
3531 * fRestOfStackBuffer, fShortLength and fFlags,
3532 * to get up exactly to the intended sizeof(UnicodeString).
3533 */
3534 // (implicit) *vtable;
3535 union StackBufferOrFields {
3536 // fStackBuffer is used iff (fFlags&kUsingStackBuffer)
3537 // else fFields is used
3538 UChar fStackBuffer[8]; // buffer for short strings, together with fRestOfStackBuffer
3539 struct {
3540 UChar *fArray; // the Unicode data
3541 int32_t fCapacity; // capacity of fArray (in UChars)
3542 int32_t fLength; // number of characters in fArray if >127; else undefined
3543 } fFields;
3544 } fUnion;
3545 UChar fRestOfStackBuffer[US_STACKBUF_SIZE-8];
3546 int8_t fShortLength; // 0..127: length <0: real length is in fUnion.fFields.fLength
3547 uint8_t fFlags; // bit flags: see constants above
3548};
3549
3558U_COMMON_API UnicodeString U_EXPORT2
3560
3561//========================================
3562// Inline members
3563//========================================
3564
3565//========================================
3566// Privates
3567//========================================
3568
3569inline void
3570UnicodeString::pinIndex(int32_t& start) const
3571{
3572 // pin index
3573 if(start < 0) {
3574 start = 0;
3575 } else if(start > length()) {
3576 start = length();
3577 }
3578}
3579
3580inline void
3581UnicodeString::pinIndices(int32_t& start,
3582 int32_t& _length) const
3583{
3584 // pin indices
3585 int32_t len = length();
3586 if(start < 0) {
3587 start = 0;
3588 } else if(start > len) {
3589 start = len;
3590 }
3591 if(_length < 0) {
3592 _length = 0;
3593 } else if(_length > (len - start)) {
3594 _length = (len - start);
3595 }
3596}
3597
3598inline UChar*
3599UnicodeString::getArrayStart()
3600{ return (fFlags&kUsingStackBuffer) ? fUnion.fStackBuffer : fUnion.fFields.fArray; }
3601
3602inline const UChar*
3603UnicodeString::getArrayStart() const
3604{ return (fFlags&kUsingStackBuffer) ? fUnion.fStackBuffer : fUnion.fFields.fArray; }
3605
3606//========================================
3607// Read-only implementation methods
3608//========================================
3609inline int32_t
3611{ return fShortLength>=0 ? fShortLength : fUnion.fFields.fLength; }
3612
3613inline int32_t
3615{ return (fFlags&kUsingStackBuffer) ? US_STACKBUF_SIZE : fUnion.fFields.fCapacity; }
3616
3617inline int32_t
3619{ return doHashCode(); }
3620
3621inline UBool
3623{ return (UBool)(fFlags & kIsBogus); }
3624
3625inline UBool
3626UnicodeString::isWritable() const
3627{ return (UBool)!(fFlags&(kOpenGetBuffer|kIsBogus)); }
3628
3629inline UBool
3630UnicodeString::isBufferWritable() const
3631{
3632 return (UBool)(
3633 !(fFlags&(kOpenGetBuffer|kIsBogus|kBufferIsReadonly)) &&
3634 (!(fFlags&kRefCounted) || refCount()==1));
3635}
3636
3637inline const UChar *
3639 if(fFlags&(kIsBogus|kOpenGetBuffer)) {
3640 return 0;
3641 } else if(fFlags&kUsingStackBuffer) {
3642 return fUnion.fStackBuffer;
3643 } else {
3644 return fUnion.fFields.fArray;
3645 }
3646}
3647
3648//========================================
3649// Read-only alias methods
3650//========================================
3651inline int8_t
3652UnicodeString::doCompare(int32_t start,
3653 int32_t thisLength,
3654 const UnicodeString& srcText,
3655 int32_t srcStart,
3656 int32_t srcLength) const
3657{
3658 if(srcText.isBogus()) {
3659 return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
3660 } else {
3661 srcText.pinIndices(srcStart, srcLength);
3662 return doCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
3663 }
3664}
3665
3666inline UBool
3668{
3669 if(isBogus()) {
3670 return text.isBogus();
3671 } else {
3672 int32_t len = length(), textLength = text.length();
3673 return !text.isBogus() && len == textLength && doEquals(text, len);
3674 }
3675}
3676
3677inline UBool
3679{ return (! operator==(text)); }
3680
3681inline UBool
3683{ return doCompare(0, length(), text, 0, text.length()) == 1; }
3684
3685inline UBool
3687{ return doCompare(0, length(), text, 0, text.length()) == -1; }
3688
3689inline UBool
3691{ return doCompare(0, length(), text, 0, text.length()) != -1; }
3692
3693inline UBool
3695{ return doCompare(0, length(), text, 0, text.length()) != 1; }
3696
3697inline int8_t
3699{ return doCompare(0, length(), text, 0, text.length()); }
3700
3701inline int8_t
3703 int32_t _length,
3704 const UnicodeString& srcText) const
3705{ return doCompare(start, _length, srcText, 0, srcText.length()); }
3706
3707inline int8_t
3709 int32_t srcLength) const
3710{ return doCompare(0, length(), srcChars, 0, srcLength); }
3711
3712inline int8_t
3714 int32_t _length,
3715 const UnicodeString& srcText,
3716 int32_t srcStart,
3717 int32_t srcLength) const
3718{ return doCompare(start, _length, srcText, srcStart, srcLength); }
3719
3720inline int8_t
3722 int32_t _length,
3723 const UChar *srcChars) const
3724{ return doCompare(start, _length, srcChars, 0, _length); }
3725
3726inline int8_t
3728 int32_t _length,
3729 const UChar *srcChars,
3730 int32_t srcStart,
3731 int32_t srcLength) const
3732{ return doCompare(start, _length, srcChars, srcStart, srcLength); }
3733
3734inline int8_t
3736 int32_t limit,
3737 const UnicodeString& srcText,
3738 int32_t srcStart,
3739 int32_t srcLimit) const
3740{ return doCompare(start, limit - start,
3741 srcText, srcStart, srcLimit - srcStart); }
3742
3743inline int8_t
3744UnicodeString::doCompareCodePointOrder(int32_t start,
3745 int32_t thisLength,
3746 const UnicodeString& srcText,
3747 int32_t srcStart,
3748 int32_t srcLength) const
3749{
3750 if(srcText.isBogus()) {
3751 return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
3752 } else {
3753 srcText.pinIndices(srcStart, srcLength);
3754 return doCompareCodePointOrder(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
3755 }
3756}
3757
3758inline int8_t
3760{ return doCompareCodePointOrder(0, length(), text, 0, text.length()); }
3761
3762inline int8_t
3764 int32_t _length,
3765 const UnicodeString& srcText) const
3766{ return doCompareCodePointOrder(start, _length, srcText, 0, srcText.length()); }
3767
3768inline int8_t
3770 int32_t srcLength) const
3771{ return doCompareCodePointOrder(0, length(), srcChars, 0, srcLength); }
3772
3773inline int8_t
3775 int32_t _length,
3776 const UnicodeString& srcText,
3777 int32_t srcStart,
3778 int32_t srcLength) const
3779{ return doCompareCodePointOrder(start, _length, srcText, srcStart, srcLength); }
3780
3781inline int8_t
3783 int32_t _length,
3784 const UChar *srcChars) const
3785{ return doCompareCodePointOrder(start, _length, srcChars, 0, _length); }
3786
3787inline int8_t
3789 int32_t _length,
3790 const UChar *srcChars,
3791 int32_t srcStart,
3792 int32_t srcLength) const
3793{ return doCompareCodePointOrder(start, _length, srcChars, srcStart, srcLength); }
3794
3795inline int8_t
3797 int32_t limit,
3798 const UnicodeString& srcText,
3799 int32_t srcStart,
3800 int32_t srcLimit) const
3801{ return doCompareCodePointOrder(start, limit - start,
3802 srcText, srcStart, srcLimit - srcStart); }
3803
3804inline int8_t
3805UnicodeString::doCaseCompare(int32_t start,
3806 int32_t thisLength,
3807 const UnicodeString &srcText,
3808 int32_t srcStart,
3809 int32_t srcLength,
3810 uint32_t options) const
3811{
3812 if(srcText.isBogus()) {
3813 return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
3814 } else {
3815 srcText.pinIndices(srcStart, srcLength);
3816 return doCaseCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength, options);
3817 }
3818}
3819
3820inline int8_t
3821UnicodeString::caseCompare(const UnicodeString &text, uint32_t options) const {
3822 return doCaseCompare(0, length(), text, 0, text.length(), options);
3823}
3824
3825inline int8_t
3827 int32_t _length,
3828 const UnicodeString &srcText,
3829 uint32_t options) const {
3830 return doCaseCompare(start, _length, srcText, 0, srcText.length(), options);
3831}
3832
3833inline int8_t
3835 int32_t srcLength,
3836 uint32_t options) const {
3837 return doCaseCompare(0, length(), srcChars, 0, srcLength, options);
3838}
3839
3840inline int8_t
3842 int32_t _length,
3843 const UnicodeString &srcText,
3844 int32_t srcStart,
3845 int32_t srcLength,
3846 uint32_t options) const {
3847 return doCaseCompare(start, _length, srcText, srcStart, srcLength, options);
3848}
3849
3850inline int8_t
3852 int32_t _length,
3853 const UChar *srcChars,
3854 uint32_t options) const {
3855 return doCaseCompare(start, _length, srcChars, 0, _length, options);
3856}
3857
3858inline int8_t
3860 int32_t _length,
3861 const UChar *srcChars,
3862 int32_t srcStart,
3863 int32_t srcLength,
3864 uint32_t options) const {
3865 return doCaseCompare(start, _length, srcChars, srcStart, srcLength, options);
3866}
3867
3868inline int8_t
3870 int32_t limit,
3871 const UnicodeString &srcText,
3872 int32_t srcStart,
3873 int32_t srcLimit,
3874 uint32_t options) const {
3875 return doCaseCompare(start, limit - start, srcText, srcStart, srcLimit - srcStart, options);
3876}
3877
3878inline int32_t
3880 int32_t srcStart,
3881 int32_t srcLength,
3882 int32_t start,
3883 int32_t _length) const
3884{
3885 if(!srcText.isBogus()) {
3886 srcText.pinIndices(srcStart, srcLength);
3887 if(srcLength > 0) {
3888 return indexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
3889 }
3890 }
3891 return -1;
3892}
3893
3894inline int32_t
3896{ return indexOf(text, 0, text.length(), 0, length()); }
3897
3898inline int32_t
3900 int32_t start) const {
3901 pinIndex(start);
3902 return indexOf(text, 0, text.length(), start, length() - start);
3903}
3904
3905inline int32_t
3907 int32_t start,
3908 int32_t _length) const
3909{ return indexOf(text, 0, text.length(), start, _length); }
3910
3911inline int32_t
3913 int32_t srcLength,
3914 int32_t start) const {
3915 pinIndex(start);
3916 return indexOf(srcChars, 0, srcLength, start, length() - start);
3917}
3918
3919inline int32_t
3921 int32_t srcLength,
3922 int32_t start,
3923 int32_t _length) const
3924{ return indexOf(srcChars, 0, srcLength, start, _length); }
3925
3926inline int32_t
3928 int32_t start,
3929 int32_t _length) const
3930{ return doIndexOf(c, start, _length); }
3931
3932inline int32_t
3934 int32_t start,
3935 int32_t _length) const
3936{ return doIndexOf(c, start, _length); }
3937
3938inline int32_t
3940{ return doIndexOf(c, 0, length()); }
3941
3942inline int32_t
3944{ return indexOf(c, 0, length()); }
3945
3946inline int32_t
3948 int32_t start) const {
3949 pinIndex(start);
3950 return doIndexOf(c, start, length() - start);
3951}
3952
3953inline int32_t
3955 int32_t start) const {
3956 pinIndex(start);
3957 return indexOf(c, start, length() - start);
3958}
3959
3960inline int32_t
3962 int32_t srcLength,
3963 int32_t start,
3964 int32_t _length) const
3965{ return lastIndexOf(srcChars, 0, srcLength, start, _length); }
3966
3967inline int32_t
3969 int32_t srcLength,
3970 int32_t start) const {
3971 pinIndex(start);
3972 return lastIndexOf(srcChars, 0, srcLength, start, length() - start);
3973}
3974
3975inline int32_t
3977 int32_t srcStart,
3978 int32_t srcLength,
3979 int32_t start,
3980 int32_t _length) const
3981{
3982 if(!srcText.isBogus()) {
3983 srcText.pinIndices(srcStart, srcLength);
3984 if(srcLength > 0) {
3985 return lastIndexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
3986 }
3987 }
3988 return -1;
3989}
3990
3991inline int32_t
3993 int32_t start,
3994 int32_t _length) const
3995{ return lastIndexOf(text, 0, text.length(), start, _length); }
3996
3997inline int32_t
3999 int32_t start) const {
4000 pinIndex(start);
4001 return lastIndexOf(text, 0, text.length(), start, length() - start);
4002}
4003
4004inline int32_t
4006{ return lastIndexOf(text, 0, text.length(), 0, length()); }
4007
4008inline int32_t
4010 int32_t start,
4011 int32_t _length) const
4012{ return doLastIndexOf(c, start, _length); }
4013
4014inline int32_t
4016 int32_t start,
4017 int32_t _length) const {
4018 return doLastIndexOf(c, start, _length);
4019}
4020
4021inline int32_t
4023{ return doLastIndexOf(c, 0, length()); }
4024
4025inline int32_t
4027 return lastIndexOf(c, 0, length());
4028}
4029
4030inline int32_t
4032 int32_t start) const {
4033 pinIndex(start);
4034 return doLastIndexOf(c, start, length() - start);
4035}
4036
4037inline int32_t
4039 int32_t start) const {
4040 pinIndex(start);
4041 return lastIndexOf(c, start, length() - start);
4042}
4043
4044inline UBool
4046{ return compare(0, text.length(), text, 0, text.length()) == 0; }
4047
4048inline UBool
4050 int32_t srcStart,
4051 int32_t srcLength) const
4052{ return doCompare(0, srcLength, srcText, srcStart, srcLength) == 0; }
4053
4054inline UBool
4055UnicodeString::startsWith(const UChar *srcChars, int32_t srcLength) const {
4056 if(srcLength < 0) {
4057 srcLength = u_strlen(srcChars);
4058 }
4059 return doCompare(0, srcLength, srcChars, 0, srcLength) == 0;
4060}
4061
4062inline UBool
4063UnicodeString::startsWith(const UChar *srcChars, int32_t srcStart, int32_t srcLength) const {
4064 if(srcLength < 0) {
4065 srcLength = u_strlen(srcChars);
4066 }
4067 return doCompare(0, srcLength, srcChars, srcStart, srcLength) == 0;
4068}
4069
4070inline UBool
4072{ return doCompare(length() - text.length(), text.length(),
4073 text, 0, text.length()) == 0; }
4074
4075inline UBool
4077 int32_t srcStart,
4078 int32_t srcLength) const {
4079 srcText.pinIndices(srcStart, srcLength);
4080 return doCompare(length() - srcLength, srcLength,
4081 srcText, srcStart, srcLength) == 0;
4082}
4083
4084inline UBool
4086 int32_t srcLength) const {
4087 if(srcLength < 0) {
4088 srcLength = u_strlen(srcChars);
4089 }
4090 return doCompare(length() - srcLength, srcLength,
4091 srcChars, 0, srcLength) == 0;
4092}
4093
4094inline UBool
4096 int32_t srcStart,
4097 int32_t srcLength) const {
4098 if(srcLength < 0) {
4099 srcLength = u_strlen(srcChars + srcStart);
4100 }
4101 return doCompare(length() - srcLength, srcLength,
4102 srcChars, srcStart, srcLength) == 0;
4103}
4104
4105//========================================
4106// replace
4107//========================================
4108inline UnicodeString&
4110 int32_t _length,
4111 const UnicodeString& srcText)
4112{ return doReplace(start, _length, srcText, 0, srcText.length()); }
4113
4114inline UnicodeString&
4116 int32_t _length,
4117 const UnicodeString& srcText,
4118 int32_t srcStart,
4119 int32_t srcLength)
4120{ return doReplace(start, _length, srcText, srcStart, srcLength); }
4121
4122inline UnicodeString&
4124 int32_t _length,
4125 const UChar *srcChars,
4126 int32_t srcLength)
4127{ return doReplace(start, _length, srcChars, 0, srcLength); }
4128
4129inline UnicodeString&
4131 int32_t _length,
4132 const UChar *srcChars,
4133 int32_t srcStart,
4134 int32_t srcLength)
4135{ return doReplace(start, _length, srcChars, srcStart, srcLength); }
4136
4137inline UnicodeString&
4139 int32_t _length,
4140 UChar srcChar)
4141{ return doReplace(start, _length, &srcChar, 0, 1); }
4142
4143inline UnicodeString&
4145 int32_t limit,
4146 const UnicodeString& srcText)
4147{ return doReplace(start, limit - start, srcText, 0, srcText.length()); }
4148
4149inline UnicodeString&
4151 int32_t limit,
4152 const UnicodeString& srcText,
4153 int32_t srcStart,
4154 int32_t srcLimit)
4155{ return doReplace(start, limit - start, srcText, srcStart, srcLimit - srcStart); }
4156
4157inline UnicodeString&
4159 const UnicodeString& newText)
4160{ return findAndReplace(0, length(), oldText, 0, oldText.length(),
4161 newText, 0, newText.length()); }
4162
4163inline UnicodeString&
4165 int32_t _length,
4166 const UnicodeString& oldText,
4167 const UnicodeString& newText)
4168{ return findAndReplace(start, _length, oldText, 0, oldText.length(),
4169 newText, 0, newText.length()); }
4170
4171// ============================
4172// extract
4173// ============================
4174inline void
4175UnicodeString::doExtract(int32_t start,
4176 int32_t _length,
4177 UnicodeString& target) const
4178{ target.replace(0, target.length(), *this, start, _length); }
4179
4180inline void
4182 int32_t _length,
4183 UChar *target,
4184 int32_t targetStart) const
4185{ doExtract(start, _length, target, targetStart); }
4186
4187inline void
4189 int32_t _length,
4190 UnicodeString& target) const
4191{ doExtract(start, _length, target); }
4192
4193#if !UCONFIG_NO_CONVERSION
4194
4195inline int32_t
4197 int32_t _length,
4198 char *dst,
4199 const char *codepage) const
4200
4201{
4202 // This dstSize value will be checked explicitly
4203 return extract(start, _length, dst, dst!=0 ? 0xffffffff : 0, codepage);
4204}
4205
4206#endif
4207
4208inline void
4210 int32_t limit,
4211 UChar *dst,
4212 int32_t dstStart) const {
4213 pinIndex(start);
4214 pinIndex(limit);
4215 doExtract(start, limit - start, dst, dstStart);
4216}
4217
4218inline UnicodeString
4219UnicodeString::tempSubStringBetween(int32_t start, int32_t limit) const {
4220 return tempSubString(start, limit - start);
4221}
4222
4223inline UChar
4224UnicodeString::doCharAt(int32_t offset) const
4225{
4226 if((uint32_t)offset < (uint32_t)length()) {
4227 return getArrayStart()[offset];
4228 } else {
4229 return kInvalidUChar;
4230 }
4231}
4232
4233inline UChar
4234UnicodeString::charAt(int32_t offset) const
4235{ return doCharAt(offset); }
4236
4237inline UChar
4238UnicodeString::operator[] (int32_t offset) const
4239{ return doCharAt(offset); }
4240
4241inline UBool
4243 return fShortLength == 0;
4244}
4245
4246//========================================
4247// Write implementation methods
4248//========================================
4249inline void
4250UnicodeString::setLength(int32_t len) {
4251 if(len <= 127) {
4252 fShortLength = (int8_t)len;
4253 } else {
4254 fShortLength = (int8_t)-1;
4255 fUnion.fFields.fLength = len;
4256 }
4257}
4258
4259inline void
4260UnicodeString::setToEmpty() {
4261 fShortLength = 0;
4262 fFlags = kShortString;
4263}
4264
4265inline void
4266UnicodeString::setArray(UChar *array, int32_t len, int32_t capacity) {
4267 setLength(len);
4268 fUnion.fFields.fArray = array;
4269 fUnion.fFields.fCapacity = capacity;
4270}
4271
4272inline const UChar *
4274 if(!isWritable()) {
4275 return 0;
4276 } else {
4277 UChar *array = getArrayStart();
4278 int32_t len = length();
4279 if(len < getCapacity() && ((fFlags&kRefCounted) == 0 || refCount() == 1)) {
4280 /*
4281 * kRefCounted: Do not write the NUL if the buffer is shared.
4282 * That is mostly safe, except when the length of one copy was modified
4283 * without copy-on-write, e.g., via truncate(newLength) or remove(void).
4284 * Then the NUL would be written into the middle of another copy's string.
4285 */
4286 if(!(fFlags&kBufferIsReadonly)) {
4287 /*
4288 * We must not write to a readonly buffer, but it is known to be
4289 * NUL-terminated if len<capacity.
4290 * A shared, allocated buffer (refCount()>1) must not have its contents
4291 * modified, but the NUL at [len] is beyond the string contents,
4292 * and multiple string objects and threads writing the same NUL into the
4293 * same location is harmless.
4294 * In all other cases, the buffer is fully writable and it is anyway safe
4295 * to write the NUL.
4296 *
4297 * Note: An earlier version of this code tested whether there is a NUL
4298 * at [len] already, but, while safe, it generated lots of warnings from
4299 * tools like valgrind and Purify.
4300 */
4301 array[len] = 0;
4302 }
4303 return array;
4304 } else if(cloneArrayIfNeeded(len+1)) {
4305 array = getArrayStart();
4306 array[len] = 0;
4307 return array;
4308 } else {
4309 return 0;
4310 }
4311 }
4312}
4313
4314inline UnicodeString&
4316{ return doReplace(0, length(), &ch, 0, 1); }
4317
4318inline UnicodeString&
4320{ return replace(0, length(), ch); }
4321
4322inline UnicodeString&
4324 int32_t srcStart,
4325 int32_t srcLength)
4326{
4327 unBogus();
4328 return doReplace(0, length(), srcText, srcStart, srcLength);
4329}
4330
4331inline UnicodeString&
4333 int32_t srcStart)
4334{
4335 unBogus();
4336 srcText.pinIndex(srcStart);
4337 return doReplace(0, length(), srcText, srcStart, srcText.length() - srcStart);
4338}
4339
4340inline UnicodeString&
4342{
4343 return copyFrom(srcText);
4344}
4345
4346inline UnicodeString&
4348 int32_t srcLength)
4349{
4350 unBogus();
4351 return doReplace(0, length(), srcChars, 0, srcLength);
4352}
4353
4354inline UnicodeString&
4356{
4357 unBogus();
4358 return doReplace(0, length(), &srcChar, 0, 1);
4359}
4360
4361inline UnicodeString&
4363{
4364 unBogus();
4365 return replace(0, length(), srcChar);
4366}
4367
4368inline UnicodeString&
4370 int32_t srcStart,
4371 int32_t srcLength)
4372{ return doReplace(length(), 0, srcText, srcStart, srcLength); }
4373
4374inline UnicodeString&
4376{ return doReplace(length(), 0, srcText, 0, srcText.length()); }
4377
4378inline UnicodeString&
4380 int32_t srcStart,
4381 int32_t srcLength)
4382{ return doReplace(length(), 0, srcChars, srcStart, srcLength); }
4383
4384inline UnicodeString&
4386 int32_t srcLength)
4387{ return doReplace(length(), 0, srcChars, 0, srcLength); }
4388
4389inline UnicodeString&
4391{ return doReplace(length(), 0, &srcChar, 0, 1); }
4392
4393inline UnicodeString&
4395{ return doReplace(length(), 0, &ch, 0, 1); }
4396
4397inline UnicodeString&
4399 return append(ch);
4400}
4401
4402inline UnicodeString&
4404{ return doReplace(length(), 0, srcText, 0, srcText.length()); }
4405
4406inline UnicodeString&
4408 const UnicodeString& srcText,
4409 int32_t srcStart,
4410 int32_t srcLength)
4411{ return doReplace(start, 0, srcText, srcStart, srcLength); }
4412
4413inline UnicodeString&
4415 const UnicodeString& srcText)
4416{ return doReplace(start, 0, srcText, 0, srcText.length()); }
4417
4418inline UnicodeString&
4420 const UChar *srcChars,
4421 int32_t srcStart,
4422 int32_t srcLength)
4423{ return doReplace(start, 0, srcChars, srcStart, srcLength); }
4424
4425inline UnicodeString&
4427 const UChar *srcChars,
4428 int32_t srcLength)
4429{ return doReplace(start, 0, srcChars, 0, srcLength); }
4430
4431inline UnicodeString&
4433 UChar srcChar)
4434{ return doReplace(start, 0, &srcChar, 0, 1); }
4435
4436inline UnicodeString&
4438 UChar32 srcChar)
4439{ return replace(start, 0, srcChar); }
4440
4441
4442inline UnicodeString&
4444{
4445 // remove() of a bogus string makes the string empty and non-bogus
4446 // we also un-alias a read-only alias to deal with NUL-termination
4447 // issues with getTerminatedBuffer()
4448 if(fFlags & (kIsBogus|kBufferIsReadonly)) {
4449 setToEmpty();
4450 } else {
4451 fShortLength = 0;
4452 }
4453 return *this;
4454}
4455
4456inline UnicodeString&
4458 int32_t _length)
4459{
4460 if(start <= 0 && _length == INT32_MAX) {
4461 // remove(guaranteed everything) of a bogus string makes the string empty and non-bogus
4462 return remove();
4463 }
4464 return doReplace(start, _length, NULL, 0, 0);
4465}
4466
4467inline UnicodeString&
4469 int32_t limit)
4470{ return doReplace(start, limit - start, NULL, 0, 0); }
4471
4472inline UnicodeString &
4473UnicodeString::retainBetween(int32_t start, int32_t limit) {
4474 truncate(limit);
4475 return doReplace(0, start, NULL, 0, 0);
4476}
4477
4478inline UBool
4479UnicodeString::truncate(int32_t targetLength)
4480{
4481 if(isBogus() && targetLength == 0) {
4482 // truncate(0) of a bogus string makes the string empty and non-bogus
4483 unBogus();
4484 return FALSE;
4485 } else if((uint32_t)targetLength < (uint32_t)length()) {
4486 setLength(targetLength);
4487 if(fFlags&kBufferIsReadonly) {
4488 fUnion.fFields.fCapacity = targetLength; // not NUL-terminated any more
4489 }
4490 return TRUE;
4491 } else {
4492 return FALSE;
4493 }
4494}
4495
4496inline UnicodeString&
4498{ return doReverse(0, length()); }
4499
4500inline UnicodeString&
4502 int32_t _length)
4503{ return doReverse(start, _length); }
4504
4506
4507#endif
C++ API: Interface for writing bytes, and implementation classes.
The BreakIterator class implements methods for finding the location of boundaries in text.
Definition brkiter.h:100
A ByteSink can be filled with bytes.
Definition bytestream.h:48
A Locale object represents a specific geographical, political, or cultural region.
Definition locid.h:182
int32_t length() const
Returns the number of 16-bit code units in the text.
Definition rep.h:241
virtual void extractBetween(int32_t start, int32_t limit, UnicodeString &target) const =0
Copies characters in the range [start, limit) into the UnicodeString target.
UChar charAt(int32_t offset) const
Returns the 16-bit code unit at the given offset into the text.
Definition rep.h:246
Replaceable()
Default constructor.
Implementation of ByteSink that writes to a "string".
Definition bytestream.h:231
A concrete subclass of CharacterIterator that iterates over the characters (code units or code points...
Definition schriter.h:43
A string-like object that points to a sized piece of memory.
Definition stringpiece.h:52
An Appendable implementation which writes to a UnicodeString.
Definition appendable.h:155
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:247
UnicodeString()
Construct an empty UnicodeString.
UnicodeString(int32_t capacity, UChar32 c, int32_t count)
Construct a UnicodeString with capacity to hold capacity UChars.
void setToBogus()
Make this UnicodeString object invalid.
UChar operator[](int32_t offset) const
Return the code unit at offset offset.
Definition unistr.h:4238
virtual void handleReplaceBetween(int32_t start, int32_t limit, const UnicodeString &text)
Replace a substring of this object with the given text.
virtual UBool hasMetaData() const
Replaceable API.
UnicodeString & findAndReplace(int32_t start, int32_t length, const UnicodeString &oldText, int32_t oldStart, int32_t oldLength, const UnicodeString &newText, int32_t newStart, int32_t newLength)
Replace all occurrences of characters in oldText in the range [oldStart, oldStart + oldLength) with t...
UnicodeString & insert(int32_t start, const UnicodeString &srcText, int32_t srcStart, int32_t srcLength)
Insert the characters in srcText in the range [srcStart, srcStart + srcLength) into the UnicodeString...
Definition unistr.h:4407
void extract(int32_t start, int32_t length, UChar *dst, int32_t dstStart=0) const
Copy the characters in the range [start, start + length) into the array dst, beginning at dstStart.
Definition unistr.h:4181
int8_t caseCompare(const UnicodeString &text, uint32_t options) const
Compare two strings case-insensitively using full case folding.
Definition unistr.h:3821
UBool hasMoreChar32Than(int32_t start, int32_t length, int32_t number) const
Check if the length UChar code units of the string contain more Unicode code points than a certain nu...
UnicodeString(UBool isTerminated, const UChar *text, int32_t textLength)
Readonly-aliasing UChar* constructor.
UnicodeString(const char *codepageData, int32_t dataLength)
char* constructor.
int8_t compareBetween(int32_t start, int32_t limit, const UnicodeString &srcText, int32_t srcStart, int32_t srcLimit) const
Compare the characters bitwise in the range [start, limit) with the characters in srcText in the rang...
Definition unistr.h:3735
UnicodeString & findAndReplace(const UnicodeString &oldText, const UnicodeString &newText)
Replace all occurrences of characters in oldText with the characters in newText.
Definition unistr.h:4158
static UnicodeString fromUTF8(const StringPiece &utf8)
Create a UnicodeString from a UTF-8 string.
void toUTF8(ByteSink &sink) const
Convert the UnicodeString to UTF-8 and write the result to a ByteSink.
UnicodeString tempSubStringBetween(int32_t start, int32_t limit=INT32_MAX) const
Create a temporary substring for the specified range.
Definition unistr.h:4219
UnicodeString(const UChar *text, int32_t textLength)
UChar* constructor.
UnicodeString & setTo(const UnicodeString &srcText, int32_t srcStart)
Set the text in the UnicodeString object to the characters in srcText in the range [srcStart,...
Definition unistr.h:4332
UBool endsWith(const UnicodeString &text) const
Determine if this ends with the characters in text
Definition unistr.h:4071
UnicodeString & operator+=(UChar ch)
Append operator.
Definition unistr.h:4394
virtual Replaceable * clone() const
Clone this object, an instance of a subclass of Replaceable.
int32_t extract(int32_t start, int32_t startLength, char *target, uint32_t targetLength) const
Copy the characters in the range [start, start + length) into an array of characters in the platform'...
UnicodeString & replaceBetween(int32_t start, int32_t limit, const UnicodeString &srcText)
Replace the characters in the range [start, limit) with the characters in srcText.
Definition unistr.h:4144
int32_t indexOf(const UChar *srcChars, int32_t srcStart, int32_t srcLength, int32_t start, int32_t length) const
Locate in this the first occurrence in the range [start, start + length) of the characters in srcChar...
UnicodeString(const UnicodeString &that)
Copy constructor.
UNISTR_FROM_CHAR_EXPLICIT UnicodeString(UChar32 ch)
Single UChar32 (code point) constructor.
int8_t compareCodePointOrder(const UnicodeString &text) const
Compare two Unicode strings in code point order.
Definition unistr.h:3759
UnicodeString(const char *src, int32_t srcLength, UConverter *cnv, UErrorCode &errorCode)
char * / UConverter constructor.
UnicodeString & operator=(const UnicodeString &srcText)
Assignment operator.
UnicodeString(const char *codepageData, int32_t dataLength, const char *codepage)
char* constructor.
UNISTR_FROM_CHAR_EXPLICIT UnicodeString(UChar ch)
Single UChar (code unit) constructor.
int32_t lastIndexOf(const UnicodeString &text) const
Locate in this the last occurrence of the characters in text, using bitwise comparison.
Definition unistr.h:4005
virtual ~UnicodeString()
Destructor.
UBool operator!=(const UnicodeString &text) const
Inequality operator.
Definition unistr.h:3678
UBool operator<=(const UnicodeString &text) const
Less than or equal operator.
Definition unistr.h:3694
static UnicodeString fromUTF32(const UChar32 *utf32, int32_t length)
Create a UnicodeString from a UTF-32 string.
UnicodeString & removeBetween(int32_t start, int32_t limit=(int32_t) INT32_MAX)
Remove the characters in the range [start, limit) from the UnicodeString object.
Definition unistr.h:4468
UnicodeString & append(UChar32 srcChar)
Append the code point srcChar to the UnicodeString object.
int32_t extract(char *dest, int32_t destCapacity, UConverter *cnv, UErrorCode &errorCode) const
Convert the UnicodeString into a codepage string using an existing UConverter.
UnicodeString & setCharAt(int32_t offset, UChar ch)
Set the character at the specified offset to the specified character.
UBool operator<(const UnicodeString &text) const
Less than operator.
Definition unistr.h:3686
UBool operator>=(const UnicodeString &text) const
Greater than or equal operator.
Definition unistr.h:3690
UnicodeString & retainBetween(int32_t start, int32_t limit=INT32_MAX)
Retain only the characters in the range [start, limit) from the UnicodeString object.
Definition unistr.h:4473
int32_t getChar32Limit(int32_t offset) const
Adjust a random-access offset so that it points behind a Unicode character.
virtual void copy(int32_t start, int32_t limit, int32_t dest)
Copy a substring of this object, retaining attribute (out-of-band) information.
virtual UChar32 getChar32At(int32_t offset) const
The change in Replaceable to use virtual getChar32At() allows UnicodeString::char32At() to be inline ...
UBool startsWith(const UnicodeString &text) const
Determine if this starts with the characters in text
Definition unistr.h:4045
UChar charAt(int32_t offset) const
Return the code unit at offset offset.
Definition unistr.h:4234
UBool operator>(const UnicodeString &text) const
Greater than operator.
Definition unistr.h:3682
UnicodeString & toUpper(const Locale &locale)
Convert the characters in this to UPPER CASE following the conventions of a specific locale.
EInvariant
Constant to be used in the UnicodeString(char *, int32_t, EInvariant) constructor which constructs a ...
Definition unistr.h:258
UnicodeString & foldCase(uint32_t options=0)
Case-folds the characters in this string.
UChar32 unescapeAt(int32_t &offset) const
Unescape a single escape sequence and return the represented character.
UChar * getBuffer(int32_t minCapacity)
Get a read/write pointer to the internal buffer.
int32_t extract(int32_t start, int32_t startLength, char *target, int32_t targetCapacity, enum EInvariant inv) const
Copy the characters in the range [start, start + length) into an array of characters.
UnicodeString & toLower(const Locale &locale)
Convert the characters in this to lower case following the conventions of a specific locale.
const UChar * getTerminatedBuffer()
Get a read-only pointer to the internal buffer, making sure that it is NUL-terminated.
Definition unistr.h:4273
virtual UClassID getDynamicClassID() const
ICU "poor man's RTTI", returns a UClassID for the actual class.
UnicodeString & toUpper(void)
Convert the characters in this to UPPER CASE following the conventions of the default locale.
UnicodeString(const char *src, int32_t length, enum EInvariant inv)
Constructs a Unicode string from an invariant-character char * string.
virtual UChar getCharAt(int32_t offset) const
The change in Replaceable to use virtual getCharAt() allows UnicodeString::charAt() to be inline agai...
UnicodeString(const char *codepageData, const char *codepage)
char* constructor.
UnicodeString(const UnicodeString &src, int32_t srcStart)
'Substring' constructor from tail of source string.
UnicodeString & toTitle(BreakIterator *titleIter, const Locale &locale)
Titlecase this string.
int32_t getChar32Start(int32_t offset) const
Adjust a random-access offset so that it points to the beginning of a Unicode character.
static UClassID getStaticClassID()
ICU "poor man's RTTI", returns a UClassID for this class.
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:4115
int32_t length(void) const
Return the length of the UnicodeString object.
Definition unistr.h:3610
int32_t getCapacity(void) const
Return the capacity of the internal buffer of the UnicodeString object.
Definition unistr.h:3614
int32_t moveIndex32(int32_t index, int32_t delta) const
Move the code unit index along the string by delta code points.
UnicodeString & replace(int32_t start, int32_t length, UChar32 srcChar)
Replace the characters in the range [start, start + length) with the code point srcChar.
void releaseBuffer(int32_t newLength=-1)
Release a read/write buffer on a UnicodeString object with an "open" getBuffer(minCapacity).
UBool operator==(const UnicodeString &text) const
Equality operator.
Definition unistr.h:3667
int8_t compareCodePointOrderBetween(int32_t start, int32_t limit, const UnicodeString &srcText, int32_t srcStart, int32_t srcLimit) const
Compare two Unicode strings in code point order.
Definition unistr.h:3796
UnicodeString & reverse(void)
Reverse this UnicodeString in place.
Definition unistr.h:4497
int32_t countChar32(int32_t start=0, int32_t length=INT32_MAX) const
Count Unicode code points in the length UChar code units of the string.
virtual void extractBetween(int32_t start, int32_t limit, UnicodeString &target) const
Copy the characters in the range [start, limit) into the UnicodeString target.
int32_t lastIndexOf(const UChar *srcChars, int32_t srcStart, int32_t srcLength, int32_t start, int32_t length) const
Locate in this the last occurrence in the range [start, start + length) of the characters in srcChars...
int32_t toUTF32(UChar32 *utf32, int32_t capacity, UErrorCode &errorCode) const
Convert the UnicodeString to UTF-32.
int32_t hashCode(void) const
Generate a hash code for this object.
Definition unistr.h:3618
void extractBetween(int32_t start, int32_t limit, UChar *dst, int32_t dstStart=0) const
Copy the characters in the range [start, limit) into the array dst, beginning at dstStart.
Definition unistr.h:4209
UnicodeString & setTo(UBool isTerminated, const UChar *text, int32_t textLength)
Aliasing setTo() function, analogous to the readonly-aliasing UChar* constructor.
UChar32 char32At(int32_t offset) const
Return the code point that contains the code unit at offset offset.
int32_t extract(UChar *dest, int32_t destCapacity, UErrorCode &errorCode) const
Copy the contents of the string into dest.
UnicodeString & toTitle(BreakIterator *titleIter, const Locale &locale, uint32_t options)
Titlecase this string, with options.
int8_t compare(const UnicodeString &text) const
Compare the characters bitwise in this UnicodeString to the characters in text.
Definition unistr.h:3698
UNISTR_FROM_STRING_EXPLICIT UnicodeString(const char *codepageData)
char* constructor.
UnicodeString unescape() const
Unescape a string of characters and return a string containing the result.
UnicodeString & toLower(void)
Convert the characters in this to lower case following the conventions of the default locale.
UBool truncate(int32_t targetLength)
Truncate this UnicodeString to the targetLength.
Definition unistr.h:4479
int32_t extract(int32_t start, int32_t startLength, char *target, uint32_t targetLength, const char *codepage) const
Copy the characters in the range [start, start + length) into an array of characters in a specified c...
UnicodeString tempSubString(int32_t start=0, int32_t length=INT32_MAX) const
Create a temporary substring for the specified range.
StringClass & toUTF8String(StringClass &result) const
Convert the UnicodeString to UTF-8 and append the result to a standard string.
Definition unistr.h:1683
UnicodeString & trim(void)
Trims leading and trailing whitespace from this UnicodeString.
const UChar * getBuffer() const
Get a read-only pointer to the internal buffer.
Definition unistr.h:3638
UnicodeString & setTo(UChar *buffer, int32_t buffLength, int32_t buffCapacity)
Aliasing setTo() function, analogous to the writable-aliasing UChar* constructor.
UBool isEmpty(void) const
Determine if this string is empty.
Definition unistr.h:4242
int32_t indexOf(const UnicodeString &text) const
Locate in this the first occurrence of the characters in text, using bitwise comparison.
Definition unistr.h:3895
UNISTR_FROM_STRING_EXPLICIT UnicodeString(const UChar *text)
UChar* constructor.
UnicodeString & toTitle(BreakIterator *titleIter)
Titlecase this string, convenience function using the default locale.
UnicodeString & fastCopyFrom(const UnicodeString &src)
Almost the same as the assignment operator.
UBool padLeading(int32_t targetLength, UChar padChar=0x0020)
Pad the start of this UnicodeString with the character padChar.
UnicodeString & remove(void)
Remove all characters from the UnicodeString object.
Definition unistr.h:4443
virtual int32_t getLength() const
Implement Replaceable::getLength() (see jitterbug 1027).
UBool isBogus(void) const
Determine if this object contains a valid string.
Definition unistr.h:3622
int8_t caseCompareBetween(int32_t start, int32_t limit, const UnicodeString &srcText, int32_t srcStart, int32_t srcLimit, uint32_t options) const
Compare two strings case-insensitively using full case folding.
Definition unistr.h:3869
UBool padTrailing(int32_t targetLength, UChar padChar=0x0020)
Pad the end of this UnicodeString with the character padChar.
UnicodeString & append(const UnicodeString &srcText, int32_t srcStart, int32_t srcLength)
Append the characters in srcText in the range [srcStart, srcStart + srcLength) to the UnicodeString o...
Definition unistr.h:4369
UnicodeString(const UnicodeString &src, int32_t srcStart, int32_t srcLength)
'Substring' constructor from subrange of source string.
UnicodeString(UChar *buffer, int32_t buffLength, int32_t buffCapacity)
Writable-aliasing UChar* constructor.
#define U_CALLCONV
Similar to U_CDECL_BEGIN/U_CDECL_END, this qualifier is necessary in callback function typedefs to ma...
Definition platform.h:751
C++ API: Replaceable String.
C++ API: Central ICU header for including the C++ standard <string> header and for related definition...
C++ API: StringPiece: Read-only byte string wrapper class.
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
UBool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
C API: Unicode case mapping functions using a UCaseMap service object.
struct UCaseMap UCaseMap
C typedef for struct UCaseMap.
Definition ucasemap.h:45
struct UConverter UConverter
Definition ucnv_err.h:94
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
Definition umachine.h:298
#define INT32_MAX
The largest value a 32 bit signed integer can hold.
Definition umachine.h:146
int8_t UBool
The ICU boolean type.
Definition umachine.h:200
#define TRUE
The TRUE value of a UBool.
Definition umachine.h:204
#define FALSE
The FALSE value of a UBool.
Definition umachine.h:208
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:278
#define U_STABLE
This is used to declare a function as a stable public ICU C API.
Definition umachine.h:109
#define UNISTR_FROM_CHAR_EXPLICIT
This can be defined to be empty or "explicit".
Definition unistr.h:153
U_COMMON_API UnicodeString operator+(const UnicodeString &s1, const UnicodeString &s2)
Create a new UnicodeString with the concatenation of two others.
#define UNISTR_FROM_STRING_EXPLICIT
This can be defined to be empty or "explicit".
Definition unistr.h:173
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
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition uobject.h:96
Basic definitions for ICU, for both C and C++ APIs.
#define NULL
Define NULL if necessary, to 0 for C++ and to ((void *)0) for C.
Definition utypes.h:186
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers,...
Definition utypes.h:476
#define U_COMMON_API
Set to export library symbols from inside the common library, and to import them from outside.
Definition utypes.h:357
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition uversion.h:130
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition uversion.h:129