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
36struct 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
52U_STABLE int32_t U_EXPORT2
53u_strlen(const UChar *s);
54#endif
55
60#ifndef U_STRING_CASE_MAPPER_DEFINED
61#define U_STRING_CASE_MAPPER_DEFINED
62
67typedef int32_t U_CALLCONV
69 UChar *dest, int32_t destCapacity,
70 const UChar *src, int32_t srcLength,
72
73#endif
74
76
77class BreakIterator; // unicode/brkiter.h
78class Locale; // unicode/locid.h
80class 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{
295public:
296
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
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
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>
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
1877
1904
1905#ifndef U_HIDE_DRAFT_API
1906#if U_HAVE_RVALUE_REFERENCES
1916 return moveFrom(src);
1917 }
1918#endif
1930
1937#endif /* U_HIDE_DRAFT_API */
1938
1945 friend U_COMMON_API inline void U_EXPORT2
1949
1958
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
2039
2064 const UChar *text,
2065 int32_t textLength);
2066
2087 int32_t buffLength,
2088 int32_t buffCapacity);
2089
2131
2139 UnicodeString& setCharAt(int32_t offset,
2140 UChar ch);
2141
2142
2143 /* Append operations */
2144
2153
2162
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
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,
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
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
2622 UChar padChar = 0x0020);
2623
2636 UChar padChar = 0x0020);
2637
2644 inline UBool truncate(int32_t targetLength);
2645
2652
2653
2654 /* Miscellaneous operations */
2655
2661 inline UnicodeString& reverse(void);
2662
2671 inline UnicodeString& reverse(int32_t start,
2672 int32_t length);
2673
2681
2690
2698
2707
2708#if !UCONFIG_NO_BREAK_ITERATION
2709
2737
2766
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
2865
2886 void releaseBuffer(int32_t newLength=-1);
2887
2918 inline const UChar *getBuffer() const;
2919
2954
2955 //========================================
2956 // Constructors
2957 //========================================
2958
2962 inline UnicodeString();
2963
2975 UnicodeString(int32_t capacity, UChar32 c, int32_t count);
2976
2987
2998
3010
3019 int32_t textLength);
3020
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
3089
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
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
3214
3215#ifndef U_HIDE_DRAFT_API
3216#if U_HAVE_RVALUE_REFERENCES
3224#endif
3225#endif /* U_HIDE_DRAFT_API */
3226
3234
3243
3260 virtual Replaceable *clone() const;
3261
3266
3281
3293 static UnicodeString fromUTF32(const UChar32 *utf32, int32_t length);
3294
3295 /* Miscellaneous operations */
3296
3332
3352 UChar32 unescapeAt(int32_t &offset) const;
3353
3360
3367
3368 //========================================
3369 // Implementation methods
3370 //========================================
3371
3372protected:
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
3393private:
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()
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,
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,
3595 int32_t **pBufferToDelete = 0,
3597
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
3719
3720//========================================
3721// Inline members
3722//========================================
3723
3724//========================================
3725// Privates
3726//========================================
3727
3728inline void
3729UnicodeString::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
3739inline void
3740UnicodeString::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
3757inline UChar*
3758UnicodeString::getArrayStart() {
3759 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3760 fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
3761}
3762
3763inline const UChar*
3764UnicodeString::getArrayStart() const {
3765 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3766 fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
3767}
3768
3769//========================================
3770// Default constructor
3771//========================================
3772
3773inline
3775 fUnion.fStackFields.fLengthAndFlags=kShortString;
3776}
3777
3778//========================================
3779// Read-only implementation methods
3780//========================================
3781inline UBool
3782UnicodeString::hasShortLength() const {
3783 return fUnion.fFields.fLengthAndFlags>=0;
3784}
3785
3786inline int32_t
3787UnicodeString::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
3793inline int32_t
3795 return hasShortLength() ? getShortLength() : fUnion.fFields.fLength;
3796}
3797
3798inline int32_t
3800 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3801 US_STACKBUF_SIZE : fUnion.fFields.fCapacity;
3802}
3803
3804inline int32_t
3806{ return doHashCode(); }
3807
3808inline UBool
3810{ return (UBool)(fUnion.fFields.fLengthAndFlags & kIsBogus); }
3811
3812inline UBool
3813UnicodeString::isWritable() const
3814{ return (UBool)!(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus)); }
3815
3816inline UBool
3817UnicodeString::isBufferWritable() const
3818{
3819 return (UBool)(
3820 !(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus|kBufferIsReadonly)) &&
3821 (!(fUnion.fFields.fLengthAndFlags&kRefCounted) || refCount()==1));
3822}
3823
3824inline const UChar *
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//========================================
3838inline int8_t
3839UnicodeString::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
3853inline 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
3864inline UBool
3866{ return (! operator==(text)); }
3867
3868inline UBool
3870{ return doCompare(0, length(), text, 0, text.length()) == 1; }
3871
3872inline UBool
3874{ return doCompare(0, length(), text, 0, text.length()) == -1; }
3875
3876inline UBool
3878{ return doCompare(0, length(), text, 0, text.length()) != -1; }
3879
3880inline UBool
3882{ return doCompare(0, length(), text, 0, text.length()) != 1; }
3883
3884inline int8_t
3886{ return doCompare(0, length(), text, 0, text.length()); }
3887
3888inline int8_t
3890 int32_t _length,
3891 const UnicodeString& srcText) const
3892{ return doCompare(start, _length, srcText, 0, srcText.length()); }
3893
3894inline int8_t
3896 int32_t srcLength) const
3897{ return doCompare(0, length(), srcChars, 0, srcLength); }
3898
3899inline int8_t
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
3907inline int8_t
3909 int32_t _length,
3910 const UChar *srcChars) const
3911{ return doCompare(start, _length, srcChars, 0, _length); }
3912
3913inline int8_t
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
3921inline int8_t
3923 int32_t limit,
3924 const UnicodeString& srcText,
3925 int32_t srcStart,
3926 int32_t srcLimit) const
3927{ return doCompare(start, limit - start,
3929
3930inline int8_t
3931UnicodeString::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
3945inline int8_t
3947{ return doCompareCodePointOrder(0, length(), text, 0, text.length()); }
3948
3949inline int8_t
3951 int32_t _length,
3952 const UnicodeString& srcText) const
3953{ return doCompareCodePointOrder(start, _length, srcText, 0, srcText.length()); }
3954
3955inline int8_t
3957 int32_t srcLength) const
3958{ return doCompareCodePointOrder(0, length(), srcChars, 0, srcLength); }
3959
3960inline int8_t
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
3968inline int8_t
3970 int32_t _length,
3971 const UChar *srcChars) const
3972{ return doCompareCodePointOrder(start, _length, srcChars, 0, _length); }
3973
3974inline int8_t
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
3982inline int8_t
3984 int32_t limit,
3985 const UnicodeString& srcText,
3986 int32_t srcStart,
3987 int32_t srcLimit) const
3988{ return doCompareCodePointOrder(start, limit - start,
3990
3991inline int8_t
3992UnicodeString::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
4007inline int8_t
4009 return doCaseCompare(0, length(), text, 0, text.length(), options);
4010}
4011
4012inline int8_t
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
4020inline int8_t
4022 int32_t srcLength,
4023 uint32_t options) const {
4024 return doCaseCompare(0, length(), srcChars, 0, srcLength, options);
4025}
4026
4027inline int8_t
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
4037inline int8_t
4039 int32_t _length,
4040 const UChar *srcChars,
4041 uint32_t options) const {
4042 return doCaseCompare(start, _length, srcChars, 0, _length, options);
4043}
4044
4045inline int8_t
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
4055inline int8_t
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
4065inline int32_t
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
4081inline int32_t
4083{ return indexOf(text, 0, text.length(), 0, length()); }
4084
4085inline int32_t
4087 int32_t start) const {
4088 pinIndex(start);
4089 return indexOf(text, 0, text.length(), start, length() - start);
4090}
4091
4092inline int32_t
4094 int32_t start,
4095 int32_t _length) const
4096{ return indexOf(text, 0, text.length(), start, _length); }
4097
4098inline int32_t
4100 int32_t srcLength,
4101 int32_t start) const {
4102 pinIndex(start);
4103 return indexOf(srcChars, 0, srcLength, start, length() - start);
4104}
4105
4106inline int32_t
4108 int32_t srcLength,
4109 int32_t start,
4110 int32_t _length) const
4111{ return indexOf(srcChars, 0, srcLength, start, _length); }
4112
4113inline int32_t
4115 int32_t start,
4116 int32_t _length) const
4117{ return doIndexOf(c, start, _length); }
4118
4119inline int32_t
4121 int32_t start,
4122 int32_t _length) const
4123{ return doIndexOf(c, start, _length); }
4124
4125inline int32_t
4127{ return doIndexOf(c, 0, length()); }
4128
4129inline int32_t
4131{ return indexOf(c, 0, length()); }
4132
4133inline int32_t
4135 int32_t start) const {
4136 pinIndex(start);
4137 return doIndexOf(c, start, length() - start);
4138}
4139
4140inline int32_t
4142 int32_t start) const {
4143 pinIndex(start);
4144 return indexOf(c, start, length() - start);
4145}
4146
4147inline int32_t
4149 int32_t srcLength,
4150 int32_t start,
4151 int32_t _length) const
4152{ return lastIndexOf(srcChars, 0, srcLength, start, _length); }
4153
4154inline int32_t
4156 int32_t srcLength,
4157 int32_t start) const {
4158 pinIndex(start);
4159 return lastIndexOf(srcChars, 0, srcLength, start, length() - start);
4160}
4161
4162inline int32_t
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
4178inline int32_t
4180 int32_t start,
4181 int32_t _length) const
4182{ return lastIndexOf(text, 0, text.length(), start, _length); }
4183
4184inline int32_t
4186 int32_t start) const {
4187 pinIndex(start);
4188 return lastIndexOf(text, 0, text.length(), start, length() - start);
4189}
4190
4191inline int32_t
4193{ return lastIndexOf(text, 0, text.length(), 0, length()); }
4194
4195inline int32_t
4197 int32_t start,
4198 int32_t _length) const
4199{ return doLastIndexOf(c, start, _length); }
4200
4201inline int32_t
4203 int32_t start,
4204 int32_t _length) const {
4205 return doLastIndexOf(c, start, _length);
4206}
4207
4208inline int32_t
4210{ return doLastIndexOf(c, 0, length()); }
4211
4212inline int32_t
4214 return lastIndexOf(c, 0, length());
4215}
4216
4217inline int32_t
4219 int32_t start) const {
4220 pinIndex(start);
4221 return doLastIndexOf(c, start, length() - start);
4222}
4223
4224inline int32_t
4226 int32_t start) const {
4227 pinIndex(start);
4228 return lastIndexOf(c, start, length() - start);
4229}
4230
4231inline UBool
4233{ return compare(0, text.length(), text, 0, text.length()) == 0; }
4234
4235inline UBool
4237 int32_t srcStart,
4238 int32_t srcLength) const
4239{ return doCompare(0, srcLength, srcText, srcStart, srcLength) == 0; }
4240
4241inline UBool
4243 if(srcLength < 0) {
4244 srcLength = u_strlen(srcChars);
4245 }
4246 return doCompare(0, srcLength, srcChars, 0, srcLength) == 0;
4247}
4248
4249inline UBool
4251 if(srcLength < 0) {
4252 srcLength = u_strlen(srcChars);
4253 }
4254 return doCompare(0, srcLength, srcChars, srcStart, srcLength) == 0;
4255}
4256
4257inline UBool
4259{ return doCompare(length() - text.length(), text.length(),
4260 text, 0, text.length()) == 0; }
4261
4262inline UBool
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
4271inline UBool
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
4281inline UBool
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//========================================
4295inline UnicodeString&
4297 int32_t _length,
4298 const UnicodeString& srcText)
4299{ return doReplace(start, _length, srcText, 0, srcText.length()); }
4300
4301inline UnicodeString&
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
4309inline UnicodeString&
4311 int32_t _length,
4312 const UChar *srcChars,
4313 int32_t srcLength)
4314{ return doReplace(start, _length, srcChars, 0, srcLength); }
4315
4316inline UnicodeString&
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
4324inline UnicodeString&
4326 int32_t _length,
4327 UChar srcChar)
4328{ return doReplace(start, _length, &srcChar, 0, 1); }
4329
4330inline UnicodeString&
4332 int32_t limit,
4333 const UnicodeString& srcText)
4334{ return doReplace(start, limit - start, srcText, 0, srcText.length()); }
4335
4336inline UnicodeString&
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
4344inline UnicodeString&
4346 const UnicodeString& newText)
4347{ return findAndReplace(0, length(), oldText, 0, oldText.length(),
4348 newText, 0, newText.length()); }
4349
4350inline UnicodeString&
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// ============================
4361inline void
4362UnicodeString::doExtract(int32_t start,
4363 int32_t _length,
4364 UnicodeString& target) const
4365{ target.replace(0, target.length(), *this, start, _length); }
4366
4367inline void
4369 int32_t _length,
4370 UChar *target,
4371 int32_t targetStart) const
4372{ doExtract(start, _length, target, targetStart); }
4373
4374inline void
4376 int32_t _length,
4377 UnicodeString& target) const
4378{ doExtract(start, _length, target); }
4379
4380#if !UCONFIG_NO_CONVERSION
4381
4382inline int32_t
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
4395inline void
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
4405inline UnicodeString
4406UnicodeString::tempSubStringBetween(int32_t start, int32_t limit) const {
4407 return tempSubString(start, limit - start);
4408}
4409
4410inline UChar
4411UnicodeString::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
4420inline UChar
4421UnicodeString::charAt(int32_t offset) const
4422{ return doCharAt(offset); }
4423
4424inline UChar
4425UnicodeString::operator[] (int32_t offset) const
4426{ return doCharAt(offset); }
4427
4428inline UBool
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//========================================
4437inline void
4438UnicodeString::setZeroLength() {
4439 fUnion.fFields.fLengthAndFlags &= kAllStorageFlags;
4440}
4441
4442inline void
4443UnicodeString::setShortLength(int32_t len) {
4444 // requires 0 <= len <= kMaxShortLength
4445 fUnion.fFields.fLengthAndFlags =
4446 (int16_t)((fUnion.fFields.fLengthAndFlags & kAllStorageFlags) | (len << kLengthShift));
4447}
4448
4449inline void
4450UnicodeString::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
4459inline void
4460UnicodeString::setToEmpty() {
4461 fUnion.fFields.fLengthAndFlags = kShortString;
4462}
4463
4464inline void
4465UnicodeString::setArray(UChar *array, int32_t len, int32_t capacity) {
4466 setLength(len);
4467 fUnion.fFields.fArray = array;
4468 fUnion.fFields.fCapacity = capacity;
4469}
4470
4471inline UnicodeString&
4473{ return doReplace(0, length(), &ch, 0, 1); }
4474
4475inline UnicodeString&
4478
4479inline UnicodeString&
4481 int32_t srcStart,
4482 int32_t srcLength)
4483{
4484 unBogus();
4485 return doReplace(0, length(), srcText, srcStart, srcLength);
4486}
4487
4488inline UnicodeString&
4490 int32_t srcStart)
4491{
4492 unBogus();
4493 srcText.pinIndex(srcStart);
4494 return doReplace(0, length(), srcText, srcStart, srcText.length() - srcStart);
4495}
4496
4497inline UnicodeString&
4499{
4500 return copyFrom(srcText);
4501}
4502
4503inline UnicodeString&
4505 int32_t srcLength)
4506{
4507 unBogus();
4508 return doReplace(0, length(), srcChars, 0, srcLength);
4509}
4510
4511inline UnicodeString&
4513{
4514 unBogus();
4515 return doReplace(0, length(), &srcChar, 0, 1);
4516}
4517
4518inline UnicodeString&
4520{
4521 unBogus();
4522 return replace(0, length(), srcChar);
4523}
4524
4525inline UnicodeString&
4527 int32_t srcStart,
4528 int32_t srcLength)
4529{ return doAppend(srcText, srcStart, srcLength); }
4530
4531inline UnicodeString&
4533{ return doAppend(srcText, 0, srcText.length()); }
4534
4535inline UnicodeString&
4537 int32_t srcStart,
4538 int32_t srcLength)
4539{ return doAppend(srcChars, srcStart, srcLength); }
4540
4541inline UnicodeString&
4543 int32_t srcLength)
4544{ return doAppend(srcChars, 0, srcLength); }
4545
4546inline UnicodeString&
4548{ return doAppend(&srcChar, 0, 1); }
4549
4550inline UnicodeString&
4552{ return doAppend(&ch, 0, 1); }
4553
4554inline UnicodeString&
4558
4559inline UnicodeString&
4561{ return doAppend(srcText, 0, srcText.length()); }
4562
4563inline UnicodeString&
4565 const UnicodeString& srcText,
4566 int32_t srcStart,
4567 int32_t srcLength)
4568{ return doReplace(start, 0, srcText, srcStart, srcLength); }
4569
4570inline UnicodeString&
4572 const UnicodeString& srcText)
4573{ return doReplace(start, 0, srcText, 0, srcText.length()); }
4574
4575inline UnicodeString&
4577 const UChar *srcChars,
4578 int32_t srcStart,
4579 int32_t srcLength)
4580{ return doReplace(start, 0, srcChars, srcStart, srcLength); }
4581
4582inline UnicodeString&
4584 const UChar *srcChars,
4585 int32_t srcLength)
4586{ return doReplace(start, 0, srcChars, 0, srcLength); }
4587
4588inline UnicodeString&
4590 UChar srcChar)
4591{ return doReplace(start, 0, &srcChar, 0, 1); }
4592
4593inline UnicodeString&
4596{ return replace(start, 0, srcChar); }
4597
4598
4599inline UnicodeString&
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
4611inline UnicodeString&
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
4622inline UnicodeString&
4624 int32_t limit)
4625{ return doReplace(start, limit - start, NULL, 0, 0); }
4626
4627inline UnicodeString &
4628UnicodeString::retainBetween(int32_t start, int32_t limit) {
4629 truncate(limit);
4630 return doReplace(0, start, NULL, 0, 0);
4631}
4632
4633inline UBool
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
4648inline UnicodeString&
4650{ return doReverse(0, length()); }
4651
4652inline UnicodeString&
4654 int32_t _length)
4655{ return doReverse(start, _length); }
4656
4658
4659#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
"Smart pointer" base class; do not use directly: use LocalPointer etc.
A Locale object represents a specific geographical, political, or cultural region.
Definition locid.h:185
Replaceable is an abstract base class representing a string of characters that supports the replaceme...
Definition rep.h:71
int32_t length() const
Returns the number of 16-bit code units in the text.
Definition rep.h:243
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:248
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:151
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:294
UnicodeString()
Construct an empty UnicodeString.
Definition unistr.h:3774
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:4425
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:4564
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:4368
int8_t caseCompare(const UnicodeString &text, uint32_t options) const
Compare two strings case-insensitively using full case folding.
Definition unistr.h:4008
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:3922
UnicodeString & findAndReplace(const UnicodeString &oldText, const UnicodeString &newText)
Replace all occurrences of characters in oldText with the characters in newText.
Definition unistr.h:4345
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:4406
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:4489
UBool endsWith(const UnicodeString &text) const
Determine if this ends with the characters in text
Definition unistr.h:4258
UnicodeString & operator+=(UChar ch)
Append operator.
Definition unistr.h:4551
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:4331
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:3946
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:4192
virtual ~UnicodeString()
Destructor.
UBool operator!=(const UnicodeString &text) const
Inequality operator.
Definition unistr.h:3865
UBool operator<=(const UnicodeString &text) const
Less than or equal operator.
Definition unistr.h:3881
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:4623
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:3873
UBool operator>=(const UnicodeString &text) const
Greater than or equal operator.
Definition unistr.h:3877
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:4628
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:4232
UChar charAt(int32_t offset) const
Return the code unit at offset offset.
Definition unistr.h:4421
UBool operator>(const UnicodeString &text) const
Greater than operator.
Definition unistr.h:3869
void swap(UnicodeString &other) U_NOEXCEPT
Swap strings.
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:305
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 + startLength) 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.
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:4302
int32_t length(void) const
Return the length of the UnicodeString object.
Definition unistr.h:3794
int32_t getCapacity(void) const
Return the capacity of the internal buffer of the UnicodeString object.
Definition unistr.h:3799
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:3854
UnicodeString & moveFrom(UnicodeString &src) U_NOEXCEPT
Move assignment, might leave src in bogus state.
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:3983
UnicodeString & reverse(void)
Reverse this UnicodeString in place.
Definition unistr.h:4649
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:3805
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:4396
friend U_COMMON_API void swap(UnicodeString &s1, UnicodeString &s2) U_NOEXCEPT
Non-member UnicodeString swap function.
Definition unistr.h:1946
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:3885
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:4634
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:1731
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:3825
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:4429
int32_t indexOf(const UnicodeString &text) const
Locate in this the first occurrence of the characters in text, using bitwise comparison.
Definition unistr.h:4082
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:4600
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:3809
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:4056
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:4526
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:849
#define U_NOEXCEPT
"noexcept" if supported, otherwise empty.
Definition platform.h:529
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:332
#define INT32_MAX
The largest value a 32 bit signed integer can hold.
Definition umachine.h:180
int8_t UBool
The ICU boolean type.
Definition umachine.h:234
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_SIZEOF_UCHAR
Number of bytes in a UChar.
Definition umachine.h:289
#define TRUE
The TRUE value of a UBool.
Definition umachine.h:238
#define FALSE
The FALSE value of a UBool.
Definition umachine.h:242
#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:151
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:171
#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
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