ICU 75.1 75.1
Loading...
Searching...
No Matches
unistr.h
Go to the documentation of this file.
1// © 2016 and later: Unicode, Inc. and others.
2// License & terms of use: http://www.unicode.org/copyright.html
3/*
4**********************************************************************
5* Copyright (C) 1998-2016, International Business Machines
6* Corporation and others. All Rights Reserved.
7**********************************************************************
8*
9* File unistr.h
10*
11* Modification History:
12*
13* Date Name Description
14* 09/25/98 stephen Creation.
15* 11/11/98 stephen Changed per 11/9 code review.
16* 04/20/99 stephen Overhauled per 4/16 code review.
17* 11/18/99 aliu Made to inherit from Replaceable. Added method
18* handleReplaceBetween(); other methods unchanged.
19* 06/25/01 grhoten Remove dependency on iostream.
20******************************************************************************
21*/
22
23#ifndef UNISTR_H
24#define UNISTR_H
25
31#include "unicode/utypes.h"
32
33#if U_SHOW_CPLUSPLUS_API
34
35#include <cstddef>
36#include "unicode/char16ptr.h"
37#include "unicode/rep.h"
38#include "unicode/std_string.h"
39#include "unicode/stringpiece.h"
40#include "unicode/bytestream.h"
41
42struct UConverter; // unicode/ucnv.h
43
44#ifndef USTRING_H
50U_CAPI int32_t U_EXPORT2 u_strlen(const UChar *s);
51#endif
52
53U_NAMESPACE_BEGIN
54
55#if !UCONFIG_NO_BREAK_ITERATION
56class BreakIterator; // unicode/brkiter.h
57#endif
58class Edits;
59
60U_NAMESPACE_END
61
62// Not #ifndef U_HIDE_INTERNAL_API because UnicodeString needs the UStringCaseMapper.
69typedef int32_t U_CALLCONV
70UStringCaseMapper(int32_t caseLocale, uint32_t options,
73#endif
74 char16_t *dest, int32_t destCapacity,
75 const char16_t *src, int32_t srcLength,
76 icu::Edits *edits,
77 UErrorCode &errorCode);
78
79U_NAMESPACE_BEGIN
80
81class Locale; // unicode/locid.h
82class StringCharacterIterator;
83class UnicodeStringAppendable; // unicode/appendable.h
84
85/* The <iostream> include has been moved to unicode/ustream.h */
86
97#define US_INV icu::UnicodeString::kInvariant
98
116#if !U_CHAR16_IS_TYPEDEF
117# define UNICODE_STRING(cs, _length) icu::UnicodeString(true, u ## cs, _length)
118#else
119# define UNICODE_STRING(cs, _length) icu::UnicodeString(true, (const char16_t*)u ## cs, _length)
120#endif
121
135#define UNICODE_STRING_SIMPLE(cs) UNICODE_STRING(cs, -1)
136
144#ifndef UNISTR_FROM_CHAR_EXPLICIT
145# if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION)
146 // Auto-"explicit" in ICU library code.
147# define UNISTR_FROM_CHAR_EXPLICIT explicit
148# else
149 // Empty by default for source code compatibility.
150# define UNISTR_FROM_CHAR_EXPLICIT
151# endif
152#endif
153
164#ifndef UNISTR_FROM_STRING_EXPLICIT
165# if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION)
166 // Auto-"explicit" in ICU library code.
167# define UNISTR_FROM_STRING_EXPLICIT explicit
168# else
169 // Empty by default for source code compatibility.
170# define UNISTR_FROM_STRING_EXPLICIT
171# endif
172#endif
173
207#ifndef UNISTR_OBJECT_SIZE
208# define UNISTR_OBJECT_SIZE 64
209#endif
210
296{
297public:
298
312 kInvariant
313 };
314
315 //========================================
316 // Read-only operations
317 //========================================
318
319 /* Comparison - bitwise only - for international comparison use collation */
320
328 inline bool operator== (const UnicodeString& text) const;
329
337 inline bool operator!= (const UnicodeString& text) const;
338
346 inline UBool operator> (const UnicodeString& text) const;
347
355 inline UBool operator< (const UnicodeString& text) const;
356
364 inline UBool operator>= (const UnicodeString& text) const;
365
373 inline UBool operator<= (const UnicodeString& text) const;
374
386 inline int8_t compare(const UnicodeString& text) const;
387
403 inline int8_t compare(int32_t start,
404 int32_t length,
405 const UnicodeString& text) const;
406
424 inline int8_t compare(int32_t start,
425 int32_t length,
426 const UnicodeString& srcText,
428 int32_t srcLength) const;
429
442 inline int8_t compare(ConstChar16Ptr srcChars,
443 int32_t srcLength) const;
444
459 inline int8_t compare(int32_t start,
460 int32_t length,
461 const char16_t *srcChars) const;
462
480 inline int8_t compare(int32_t start,
481 int32_t length,
482 const char16_t *srcChars,
484 int32_t srcLength) const;
485
503 inline int8_t compareBetween(int32_t start,
504 int32_t limit,
505 const UnicodeString& srcText,
507 int32_t srcLimit) const;
508
526 inline int8_t compareCodePointOrder(const UnicodeString& text) const;
527
547 inline int8_t compareCodePointOrder(int32_t start,
548 int32_t length,
549 const UnicodeString& srcText) const;
550
572 inline int8_t compareCodePointOrder(int32_t start,
573 int32_t length,
574 const UnicodeString& srcText,
576 int32_t srcLength) const;
577
596 inline int8_t compareCodePointOrder(ConstChar16Ptr srcChars,
597 int32_t srcLength) const;
598
618 inline int8_t compareCodePointOrder(int32_t start,
619 int32_t length,
620 const char16_t *srcChars) const;
621
643 inline int8_t compareCodePointOrder(int32_t start,
644 int32_t length,
645 const char16_t *srcChars,
647 int32_t srcLength) const;
648
670 inline int8_t compareCodePointOrderBetween(int32_t start,
671 int32_t limit,
672 const UnicodeString& srcText,
674 int32_t srcLimit) const;
675
694 inline int8_t caseCompare(const UnicodeString& text, uint32_t options) const;
695
716 inline int8_t caseCompare(int32_t start,
717 int32_t length,
718 const UnicodeString& srcText,
719 uint32_t options) const;
720
743 inline int8_t caseCompare(int32_t start,
744 int32_t length,
745 const UnicodeString& srcText,
748 uint32_t options) const;
749
769 inline int8_t caseCompare(ConstChar16Ptr srcChars,
771 uint32_t options) const;
772
793 inline int8_t caseCompare(int32_t start,
794 int32_t length,
795 const char16_t *srcChars,
796 uint32_t options) const;
797
820 inline int8_t caseCompare(int32_t start,
821 int32_t length,
822 const char16_t *srcChars,
825 uint32_t options) const;
826
849 inline int8_t caseCompareBetween(int32_t start,
850 int32_t limit,
851 const UnicodeString& srcText,
854 uint32_t options) const;
855
863 inline UBool startsWith(const UnicodeString& text) const;
864
875 inline UBool startsWith(const UnicodeString& srcText,
877 int32_t srcLength) const;
878
887 inline UBool startsWith(ConstChar16Ptr srcChars,
888 int32_t srcLength) const;
889
899 inline UBool startsWith(const char16_t *srcChars,
901 int32_t srcLength) const;
902
910 inline UBool endsWith(const UnicodeString& text) const;
911
922 inline UBool endsWith(const UnicodeString& srcText,
924 int32_t srcLength) const;
925
934 inline UBool endsWith(ConstChar16Ptr srcChars,
935 int32_t srcLength) const;
936
947 inline UBool endsWith(const char16_t *srcChars,
949 int32_t srcLength) const;
950
951
952 /* Searching - bitwise only */
953
962 inline int32_t indexOf(const UnicodeString& text) const;
963
973 inline int32_t indexOf(const UnicodeString& text,
974 int32_t start) const;
975
987 inline int32_t indexOf(const UnicodeString& text,
988 int32_t start,
989 int32_t length) const;
990
1007 inline int32_t indexOf(const UnicodeString& srcText,
1010 int32_t start,
1011 int32_t length) const;
1012
1024 inline int32_t indexOf(const char16_t *srcChars,
1026 int32_t start) const;
1027
1040 inline int32_t indexOf(ConstChar16Ptr srcChars,
1042 int32_t start,
1043 int32_t length) const;
1044
1061 int32_t indexOf(const char16_t *srcChars,
1064 int32_t start,
1065 int32_t length) const;
1066
1074 inline int32_t indexOf(char16_t c) const;
1075
1084 inline int32_t indexOf(UChar32 c) const;
1085
1094 inline int32_t indexOf(char16_t c,
1095 int32_t start) const;
1096
1106 inline int32_t indexOf(UChar32 c,
1107 int32_t start) const;
1108
1119 inline int32_t indexOf(char16_t c,
1120 int32_t start,
1121 int32_t length) const;
1122
1134 inline int32_t indexOf(UChar32 c,
1135 int32_t start,
1136 int32_t length) const;
1137
1146 inline int32_t lastIndexOf(const UnicodeString& text) const;
1147
1157 inline int32_t lastIndexOf(const UnicodeString& text,
1158 int32_t start) const;
1159
1171 inline int32_t lastIndexOf(const UnicodeString& text,
1172 int32_t start,
1173 int32_t length) const;
1174
1191 inline int32_t lastIndexOf(const UnicodeString& srcText,
1194 int32_t start,
1195 int32_t length) const;
1196
1207 inline int32_t lastIndexOf(const char16_t *srcChars,
1209 int32_t start) const;
1210
1223 inline int32_t lastIndexOf(ConstChar16Ptr srcChars,
1225 int32_t start,
1226 int32_t length) const;
1227
1247 int32_t start,
1248 int32_t length) const;
1249
1257 inline int32_t lastIndexOf(char16_t c) const;
1258
1267 inline int32_t lastIndexOf(UChar32 c) const;
1268
1277 inline int32_t lastIndexOf(char16_t c,
1278 int32_t start) const;
1279
1289 inline int32_t lastIndexOf(UChar32 c,
1290 int32_t start) const;
1291
1302 inline int32_t lastIndexOf(char16_t c,
1303 int32_t start,
1304 int32_t length) const;
1305
1317 inline int32_t lastIndexOf(UChar32 c,
1318 int32_t start,
1319 int32_t length) const;
1320
1321
1322 /* Character access */
1323
1332 inline char16_t charAt(int32_t offset) const;
1333
1341 inline char16_t operator[] (int32_t offset) const;
1342
1354 UChar32 char32At(int32_t offset) const;
1355
1372
1390
1441 int32_t moveIndex32(int32_t index, int32_t delta) const;
1442
1443 /* Substring extraction */
1444
1460 inline void extract(int32_t start,
1461 int32_t length,
1462 Char16Ptr dst,
1463 int32_t dstStart = 0) const;
1464
1486 int32_t
1488 UErrorCode &errorCode) const;
1489
1499 inline void extract(int32_t start,
1500 int32_t length,
1501 UnicodeString& target) const;
1502
1514 inline void extractBetween(int32_t start,
1515 int32_t limit,
1516 char16_t *dst,
1517 int32_t dstStart = 0) const;
1518
1527 virtual void extractBetween(int32_t start,
1528 int32_t limit,
1529 UnicodeString& target) const override;
1530
1554 char *target,
1556 enum EInvariant inv) const;
1557
1558#if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
1559
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,
1615 char* target,
1616 const char* codepage = nullptr) const;
1617
1649 char *target,
1651 const char *codepage) const;
1652
1671 UConverter *cnv,
1672 UErrorCode &errorCode) const;
1673
1674#endif
1675
1690
1701 inline UnicodeString tempSubStringBetween(int32_t start, int32_t limit=INT32_MAX) const;
1702
1714 void toUTF8(ByteSink &sink) const;
1715
1728 template<typename StringClass>
1731 toUTF8(sbs);
1732 return result;
1733 }
1734
1750 int32_t toUTF32(UChar32 *utf32, int32_t capacity, UErrorCode &errorCode) const;
1751
1752 /* Length operations */
1753
1762 inline int32_t length() const;
1763
1777 int32_t
1778 countChar32(int32_t start=0, int32_t length=INT32_MAX) const;
1779
1803 UBool
1804 hasMoreChar32Than(int32_t start, int32_t length, int32_t number) const;
1805
1811 inline UBool isEmpty() const;
1812
1822 inline int32_t getCapacity() const;
1823
1824 /* Other operations */
1825
1831 inline int32_t hashCode() const;
1832
1845 inline UBool isBogus() const;
1846
1847 //========================================
1848 // Write operations
1849 //========================================
1850
1851 /* Assignment operations */
1852
1872
1899
1909
1915 void swap(UnicodeString &other) noexcept;
1916
1923 friend inline void U_EXPORT2
1925 s1.swap(s2);
1926 }
1927
1935 inline UnicodeString& operator= (char16_t ch);
1936
1945
1957 inline UnicodeString& setTo(const UnicodeString& srcText,
1959
1973 inline UnicodeString& setTo(const UnicodeString& srcText,
1976
1985 inline UnicodeString& setTo(const UnicodeString& srcText);
1986
1995 inline UnicodeString& setTo(const char16_t *srcChars,
1997
2006 inline UnicodeString& setTo(char16_t srcChar);
2007
2016 inline UnicodeString& setTo(UChar32 srcChar);
2017
2042 ConstChar16Ptr text,
2043 int32_t textLength);
2044
2064 UnicodeString &setTo(char16_t *buffer,
2067
2108
2117 char16_t ch);
2118
2119
2120 /* Append operations */
2121
2129 inline UnicodeString& operator+= (char16_t ch);
2130
2139
2148
2163 inline UnicodeString& append(const UnicodeString& srcText,
2166
2174 inline UnicodeString& append(const UnicodeString& srcText);
2175
2189 inline UnicodeString& append(const char16_t *srcChars,
2192
2202 inline UnicodeString& append(ConstChar16Ptr srcChars,
2204
2211 inline UnicodeString& append(char16_t srcChar);
2212
2220
2221
2222 /* Insert operations */
2223
2237 inline UnicodeString& insert(int32_t start,
2238 const UnicodeString& srcText,
2241
2250 inline UnicodeString& insert(int32_t start,
2251 const UnicodeString& srcText);
2252
2266 inline UnicodeString& insert(int32_t start,
2267 const char16_t *srcChars,
2270
2280 inline UnicodeString& insert(int32_t start,
2283
2292 inline UnicodeString& insert(int32_t start,
2293 char16_t srcChar);
2294
2303 inline UnicodeString& insert(int32_t start,
2305
2306
2307 /* Replace operations */
2308
2326 inline UnicodeString& replace(int32_t start,
2327 int32_t length,
2328 const UnicodeString& srcText,
2331
2344 inline UnicodeString& replace(int32_t start,
2345 int32_t length,
2346 const UnicodeString& srcText);
2347
2365 inline UnicodeString& replace(int32_t start,
2366 int32_t length,
2367 const char16_t *srcChars,
2370
2383 inline UnicodeString& replace(int32_t start,
2384 int32_t length,
2387
2399 inline UnicodeString& replace(int32_t start,
2400 int32_t length,
2401 char16_t srcChar);
2402
2415
2425 inline UnicodeString& replaceBetween(int32_t start,
2426 int32_t limit,
2427 const UnicodeString& srcText);
2428
2443 inline UnicodeString& replaceBetween(int32_t start,
2444 int32_t limit,
2445 const UnicodeString& srcText,
2448
2456 virtual void handleReplaceBetween(int32_t start,
2457 int32_t limit,
2458 const UnicodeString& text) override;
2459
2465 virtual UBool hasMetaData() const override;
2466
2480 virtual void copy(int32_t start, int32_t limit, int32_t dest) override;
2481
2482 /* Search and replace operations */
2483
2492 inline UnicodeString& findAndReplace(const UnicodeString& oldText,
2493 const UnicodeString& newText);
2494
2506 inline UnicodeString& findAndReplace(int32_t start,
2507 int32_t length,
2508 const UnicodeString& oldText,
2509 const UnicodeString& newText);
2510
2529 int32_t length,
2530 const UnicodeString& oldText,
2532 int32_t oldLength,
2533 const UnicodeString& newText,
2535 int32_t newLength);
2536
2537
2538 /* Remove operations */
2539
2548 inline UnicodeString& remove();
2549
2558 inline UnicodeString& remove(int32_t start,
2559 int32_t length = (int32_t)INT32_MAX);
2560
2569 inline UnicodeString& removeBetween(int32_t start,
2570 int32_t limit = (int32_t)INT32_MAX);
2571
2581 inline UnicodeString &retainBetween(int32_t start, int32_t limit = INT32_MAX);
2582
2583 /* Length operations */
2584
2597 char16_t padChar = 0x0020);
2598
2611 char16_t padChar = 0x0020);
2612
2619 inline UBool truncate(int32_t targetLength);
2620
2627
2628 /* Miscellaneous operations */
2629
2635 inline UnicodeString& reverse();
2636
2645 inline UnicodeString& reverse(int32_t start,
2646 int32_t length);
2647
2655
2664
2672
2681
2682#if !UCONFIG_NO_BREAK_ITERATION
2683
2711
2740
2772
2773#endif
2774
2788 UnicodeString &foldCase(uint32_t options=0 /*U_FOLD_CASE_DEFAULT*/);
2789
2790 //========================================
2791 // Access to the internal buffer
2792 //========================================
2793
2838
2859 void releaseBuffer(int32_t newLength=-1);
2860
2891 inline const char16_t *getBuffer() const;
2892
2926 const char16_t *getTerminatedBuffer();
2927
2928 //========================================
2929 // Constructors
2930 //========================================
2931
2935 inline UnicodeString();
2936
2949
2960
2971
2983
2984#if !U_CHAR16_IS_TYPEDEF
2997#endif
2998
2999#if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
3013#endif
3014
3025 UNISTR_FROM_STRING_EXPLICIT inline UnicodeString(const std::nullptr_t text);
3026
3034 UnicodeString(const char16_t *text,
3035 int32_t textLength);
3036
3037#if !U_CHAR16_IS_TYPEDEF
3045 UnicodeString(const uint16_t *text, int32_t textLength) :
3046 UnicodeString(ConstChar16Ptr(text), textLength) {}
3047#endif
3048
3049#if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
3058 UnicodeString(const wchar_t *text, int32_t textLength) :
3059 UnicodeString(ConstChar16Ptr(text), textLength) {}
3060#endif
3061
3069 inline UnicodeString(const std::nullptr_t text, int32_t textLength);
3070
3094 ConstChar16Ptr text,
3095 int32_t textLength);
3096
3116
3117#if !U_CHAR16_IS_TYPEDEF
3128#endif
3129
3130#if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
3142#endif
3143
3152 inline UnicodeString(std::nullptr_t buffer, int32_t buffLength, int32_t buffCapacity);
3153
3154#if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
3155
3176
3186
3187#endif
3188
3189#if !UCONFIG_NO_CONVERSION
3190
3208 UnicodeString(const char *codepageData, const char *codepage);
3209
3228
3251 const char *src, int32_t srcLength,
3252 UConverter *cnv,
3253 UErrorCode &errorCode);
3254
3255#endif
3256
3280 UnicodeString(const char *src, int32_t textLength, enum EInvariant inv);
3281
3282
3300
3308
3316
3325
3339 virtual UnicodeString *clone() const override;
3340
3345
3360
3373
3374 /* Miscellaneous operations */
3375
3411
3432
3439
3445 virtual UClassID getDynamicClassID() const override;
3446
3447 //========================================
3448 // Implementation methods
3449 //========================================
3450
3451protected:
3456 virtual int32_t getLength() const override;
3457
3463 virtual char16_t getCharAt(int32_t offset) const override;
3464
3470 virtual UChar32 getChar32At(int32_t offset) const override;
3471
3472private:
3473 // For char* constructors. Could be made public.
3474 UnicodeString &setToUTF8(StringPiece utf8);
3475 // For extract(char*).
3476 // We could make a toUTF8(target, capacity, errorCode) public but not
3477 // this version: New API will be cleaner if we make callers create substrings
3478 // rather than having start+length on every method,
3479 // and it should take a UErrorCode&.
3480 int32_t
3481 toUTF8(int32_t start, int32_t len,
3482 char *target, int32_t capacity) const;
3483
3488 UBool doEquals(const UnicodeString &text, int32_t len) const;
3489
3490 inline UBool
3491 doEqualsSubstring(int32_t start,
3492 int32_t length,
3493 const UnicodeString& srcText,
3495 int32_t srcLength) const;
3496
3497 UBool doEqualsSubstring(int32_t start,
3498 int32_t length,
3499 const char16_t *srcChars,
3501 int32_t srcLength) const;
3502
3503 inline int8_t
3504 doCompare(int32_t start,
3505 int32_t length,
3506 const UnicodeString& srcText,
3508 int32_t srcLength) const;
3509
3510 int8_t doCompare(int32_t start,
3511 int32_t length,
3512 const char16_t *srcChars,
3514 int32_t srcLength) const;
3515
3516 inline int8_t
3517 doCompareCodePointOrder(int32_t start,
3518 int32_t length,
3519 const UnicodeString& srcText,
3521 int32_t srcLength) const;
3522
3523 int8_t doCompareCodePointOrder(int32_t start,
3524 int32_t length,
3525 const char16_t *srcChars,
3527 int32_t srcLength) const;
3528
3529 inline int8_t
3530 doCaseCompare(int32_t start,
3531 int32_t length,
3532 const UnicodeString &srcText,
3535 uint32_t options) const;
3536
3537 int8_t
3538 doCaseCompare(int32_t start,
3539 int32_t length,
3540 const char16_t *srcChars,
3543 uint32_t options) const;
3544
3545 int32_t doIndexOf(char16_t c,
3546 int32_t start,
3547 int32_t length) const;
3548
3549 int32_t doIndexOf(UChar32 c,
3550 int32_t start,
3551 int32_t length) const;
3552
3553 int32_t doLastIndexOf(char16_t c,
3554 int32_t start,
3555 int32_t length) const;
3556
3557 int32_t doLastIndexOf(UChar32 c,
3558 int32_t start,
3559 int32_t length) const;
3560
3561 void doExtract(int32_t start,
3562 int32_t length,
3563 char16_t *dst,
3564 int32_t dstStart) const;
3565
3566 inline void doExtract(int32_t start,
3567 int32_t length,
3568 UnicodeString& target) const;
3569
3570 inline char16_t doCharAt(int32_t offset) const;
3571
3572 UnicodeString& doReplace(int32_t start,
3573 int32_t length,
3574 const UnicodeString& srcText,
3577
3578 UnicodeString& doReplace(int32_t start,
3579 int32_t length,
3580 const char16_t *srcChars,
3583
3585 UnicodeString& doAppend(const char16_t *srcChars, int32_t srcStart, int32_t srcLength);
3586
3587 UnicodeString& doReverse(int32_t start,
3588 int32_t length);
3589
3590 // calculate hash code
3591 int32_t doHashCode() const;
3592
3593 // get pointer to start of array
3594 // these do not check for kOpenGetBuffer, unlike the public getBuffer() function
3595 inline char16_t* getArrayStart();
3596 inline const char16_t* getArrayStart() const;
3597
3598 inline UBool hasShortLength() const;
3599 inline int32_t getShortLength() const;
3600
3601 // A UnicodeString object (not necessarily its current buffer)
3602 // is writable unless it isBogus() or it has an "open" getBuffer(minCapacity).
3603 inline UBool isWritable() const;
3604
3605 // Is the current buffer writable?
3606 inline UBool isBufferWritable() const;
3607
3608 // None of the following does releaseArray().
3609 inline void setZeroLength();
3610 inline void setShortLength(int32_t len);
3611 inline void setLength(int32_t len);
3612 inline void setToEmpty();
3613 inline void setArray(char16_t *array, int32_t len, int32_t capacity); // sets length but not flags
3614
3615 // allocate the array; result may be the stack buffer
3616 // sets refCount to 1 if appropriate
3617 // sets fArray, fCapacity, and flags
3618 // sets length to 0
3619 // returns boolean for success or failure
3620 UBool allocate(int32_t capacity);
3621
3622 // release the array if owned
3623 void releaseArray();
3624
3625 // turn a bogus string into an empty one
3626 void unBogus();
3627
3628 // implements assignment operator, copy constructor, and fastCopyFrom()
3629 UnicodeString &copyFrom(const UnicodeString &src, UBool fastCopy=false);
3630
3631 // Copies just the fields without memory management.
3632 void copyFieldsFrom(UnicodeString &src, UBool setSrcToBogus) noexcept;
3633
3634 // Pin start and limit to acceptable values.
3635 inline void pinIndex(int32_t& start) const;
3636 inline void pinIndices(int32_t& start,
3637 int32_t& length) const;
3638
3639#if !UCONFIG_NO_CONVERSION
3640
3641 /* Internal extract() using UConverter. */
3642 int32_t doExtract(int32_t start, int32_t length,
3643 char *dest, int32_t destCapacity,
3644 UConverter *cnv,
3645 UErrorCode &errorCode) const;
3646
3647 /*
3648 * Real constructor for converting from codepage data.
3649 * It assumes that it is called with !fRefCounted.
3650 *
3651 * If `codepage==0`, then the default converter
3652 * is used for the platform encoding.
3653 * If `codepage` is an empty string (`""`),
3654 * then a simple conversion is performed on the codepage-invariant
3655 * subset ("invariant characters") of the platform encoding. See utypes.h.
3656 */
3657 void doCodepageCreate(const char *codepageData,
3659 const char *codepage);
3660
3661 /*
3662 * Worker function for creating a UnicodeString from
3663 * a codepage string using a UConverter.
3664 */
3665 void
3666 doCodepageCreate(const char *codepageData,
3668 UConverter *converter,
3670
3671#endif
3672
3673 /*
3674 * This function is called when write access to the array
3675 * is necessary.
3676 *
3677 * We need to make a copy of the array if
3678 * the buffer is read-only, or
3679 * the buffer is refCounted (shared), and refCount>1, or
3680 * the buffer is too small.
3681 *
3682 * Return false if memory could not be allocated.
3683 */
3684 UBool cloneArrayIfNeeded(int32_t newCapacity = -1,
3685 int32_t growCapacity = -1,
3686 UBool doCopyArray = true,
3687 int32_t** pBufferToDelete = nullptr,
3688 UBool forceClone = false);
3689
3696 caseMap(int32_t caseLocale, uint32_t options,
3699#endif
3701
3702 // ref counting
3703 void addRef();
3704 int32_t removeRef();
3705 int32_t refCount() const;
3706
3707 // constants
3708 enum {
3714 US_STACKBUF_SIZE=(int32_t)(UNISTR_OBJECT_SIZE-sizeof(void *)-2)/U_SIZEOF_UCHAR,
3715 kInvalidUChar=0xffff, // U+FFFF returned by charAt(invalid index)
3716 kInvalidHashCode=0, // invalid hash code
3717 kEmptyHashCode=1, // hash code for empty string
3718
3719 // bit flag values for fLengthAndFlags
3720 kIsBogus=1, // this string is bogus, i.e., not valid or nullptr
3721 kUsingStackBuffer=2,// using fUnion.fStackFields instead of fUnion.fFields
3722 kRefCounted=4, // there is a refCount field before the characters in fArray
3723 kBufferIsReadonly=8,// do not write to this buffer
3724 kOpenGetBuffer=16, // getBuffer(minCapacity) was called (is "open"),
3725 // and releaseBuffer(newLength) must be called
3726 kAllStorageFlags=0x1f,
3727
3728 kLengthShift=5, // remaining 11 bits for non-negative short length, or negative if long
3729 kLength1=1<<kLengthShift,
3730 kMaxShortLength=0x3ff, // max non-negative short length (leaves top bit 0)
3731 kLengthIsLarge=0xffe0, // short length < 0, real length is in fUnion.fFields.fLength
3732
3733 // combined values for convenience
3734 kShortString=kUsingStackBuffer,
3735 kLongString=kRefCounted,
3736 kReadonlyAlias=kBufferIsReadonly,
3737 kWritableAlias=0
3738 };
3739
3740 friend class UnicodeStringAppendable;
3741
3742 union StackBufferOrFields; // forward declaration necessary before friend declaration
3743 friend union StackBufferOrFields; // make US_STACKBUF_SIZE visible inside fUnion
3744
3745 /*
3746 * The following are all the class fields that are stored
3747 * in each UnicodeString object.
3748 * Note that UnicodeString has virtual functions,
3749 * therefore there is an implicit vtable pointer
3750 * as the first real field.
3751 * The fields should be aligned such that no padding is necessary.
3752 * On 32-bit machines, the size should be 32 bytes,
3753 * on 64-bit machines (8-byte pointers), it should be 40 bytes.
3754 *
3755 * We use a hack to achieve this.
3756 *
3757 * With at least some compilers, each of the following is forced to
3758 * a multiple of sizeof(pointer) [the largest field base unit here is a data pointer],
3759 * rounded up with additional padding if the fields do not already fit that requirement:
3760 * - sizeof(class UnicodeString)
3761 * - offsetof(UnicodeString, fUnion)
3762 * - sizeof(fUnion)
3763 * - sizeof(fStackFields)
3764 *
3765 * We optimize for the longest possible internal buffer for short strings.
3766 * fUnion.fStackFields begins with 2 bytes for storage flags
3767 * and the length of relatively short strings,
3768 * followed by the buffer for short string contents.
3769 * There is no padding inside fStackFields.
3770 *
3771 * Heap-allocated and aliased strings use fUnion.fFields.
3772 * Both fStackFields and fFields must begin with the same fields for flags and short length,
3773 * that is, those must have the same memory offsets inside the object,
3774 * because the flags must be inspected in order to decide which half of fUnion is being used.
3775 * We assume that the compiler does not reorder the fields.
3776 *
3777 * (Padding at the end of fFields is ok:
3778 * As long as it is no larger than fStackFields, it is not wasted space.)
3779 *
3780 * For some of the history of the UnicodeString class fields layout, see
3781 * - ICU ticket #11551 "longer UnicodeString contents in stack buffer"
3782 * - ICU ticket #11336 "UnicodeString: recombine stack buffer arrays"
3783 * - ICU ticket #8322 "why is sizeof(UnicodeString)==48?"
3784 */
3785 // (implicit) *vtable;
3786 union StackBufferOrFields {
3787 // fStackFields is used iff (fLengthAndFlags&kUsingStackBuffer) else fFields is used.
3788 // Each struct of the union must begin with fLengthAndFlags.
3789 struct {
3790 int16_t fLengthAndFlags; // bit fields: see constants above
3791 char16_t fBuffer[US_STACKBUF_SIZE]; // buffer for short strings
3792 } fStackFields;
3793 struct {
3794 int16_t fLengthAndFlags; // bit fields: see constants above
3795 int32_t fLength; // number of characters in fArray if >127; else undefined
3796 int32_t fCapacity; // capacity of fArray (in char16_ts)
3797 // array pointer last to minimize padding for machines with P128 data model
3798 // or pointer sizes that are not a power of 2
3799 char16_t *fArray; // the Unicode data
3800 } fFields;
3801 } fUnion;
3802};
3803
3812U_COMMON_API UnicodeString U_EXPORT2
3814
3815//========================================
3816// Inline members
3817//========================================
3818
3819//========================================
3820// Privates
3821//========================================
3822
3823inline void
3824UnicodeString::pinIndex(int32_t& start) const
3825{
3826 // pin index
3827 if(start < 0) {
3828 start = 0;
3829 } else if(start > length()) {
3830 start = length();
3831 }
3832}
3833
3834inline void
3835UnicodeString::pinIndices(int32_t& start,
3836 int32_t& _length) const
3837{
3838 // pin indices
3839 int32_t len = length();
3840 if(start < 0) {
3841 start = 0;
3842 } else if(start > len) {
3843 start = len;
3844 }
3845 if(_length < 0) {
3846 _length = 0;
3847 } else if(_length > (len - start)) {
3848 _length = (len - start);
3849 }
3850}
3851
3852inline char16_t*
3853UnicodeString::getArrayStart() {
3854 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3855 fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
3856}
3857
3858inline const char16_t*
3859UnicodeString::getArrayStart() const {
3860 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3861 fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
3862}
3863
3864//========================================
3865// Default constructor
3866//========================================
3867
3868inline
3869UnicodeString::UnicodeString() {
3870 fUnion.fStackFields.fLengthAndFlags=kShortString;
3871}
3872
3873inline UnicodeString::UnicodeString(const std::nullptr_t /*text*/) {
3874 fUnion.fStackFields.fLengthAndFlags=kShortString;
3875}
3876
3877inline UnicodeString::UnicodeString(const std::nullptr_t /*text*/, int32_t /*length*/) {
3878 fUnion.fStackFields.fLengthAndFlags=kShortString;
3879}
3880
3881inline UnicodeString::UnicodeString(std::nullptr_t /*buffer*/, int32_t /*buffLength*/, int32_t /*buffCapacity*/) {
3882 fUnion.fStackFields.fLengthAndFlags=kShortString;
3883}
3884
3885//========================================
3886// Read-only implementation methods
3887//========================================
3888inline UBool
3889UnicodeString::hasShortLength() const {
3890 return fUnion.fFields.fLengthAndFlags>=0;
3891}
3892
3893inline int32_t
3894UnicodeString::getShortLength() const {
3895 // fLengthAndFlags must be non-negative -> short length >= 0
3896 // and arithmetic or logical shift does not matter.
3897 return fUnion.fFields.fLengthAndFlags>>kLengthShift;
3898}
3899
3900inline int32_t
3901UnicodeString::length() const {
3902 return hasShortLength() ? getShortLength() : fUnion.fFields.fLength;
3903}
3904
3905inline int32_t
3906UnicodeString::getCapacity() const {
3907 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3908 US_STACKBUF_SIZE : fUnion.fFields.fCapacity;
3909}
3910
3911inline int32_t
3912UnicodeString::hashCode() const
3913{ return doHashCode(); }
3914
3915inline UBool
3916UnicodeString::isBogus() const
3917{ return (UBool)(fUnion.fFields.fLengthAndFlags & kIsBogus); }
3918
3919inline UBool
3920UnicodeString::isWritable() const
3921{ return (UBool)!(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus)); }
3922
3923inline UBool
3924UnicodeString::isBufferWritable() const
3925{
3926 return (UBool)(
3927 !(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus|kBufferIsReadonly)) &&
3928 (!(fUnion.fFields.fLengthAndFlags&kRefCounted) || refCount()==1));
3929}
3930
3931inline const char16_t *
3932UnicodeString::getBuffer() const {
3933 if(fUnion.fFields.fLengthAndFlags&(kIsBogus|kOpenGetBuffer)) {
3934 return nullptr;
3935 } else if(fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) {
3936 return fUnion.fStackFields.fBuffer;
3937 } else {
3938 return fUnion.fFields.fArray;
3939 }
3940}
3941
3942//========================================
3943// Read-only alias methods
3944//========================================
3945inline int8_t
3946UnicodeString::doCompare(int32_t start,
3948 const UnicodeString& srcText,
3950 int32_t srcLength) const
3951{
3952 if(srcText.isBogus()) {
3953 return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
3954 } else {
3955 srcText.pinIndices(srcStart, srcLength);
3956 return doCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
3957 }
3958}
3959
3960inline UBool
3961UnicodeString::doEqualsSubstring(int32_t start,
3962 int32_t thisLength,
3963 const UnicodeString& srcText,
3964 int32_t srcStart,
3965 int32_t srcLength) const
3966{
3967 if(srcText.isBogus()) {
3968 return isBogus();
3969 } else {
3970 srcText.pinIndices(srcStart, srcLength);
3971 return !isBogus() && doEqualsSubstring(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
3972 }
3973}
3974
3975inline bool
3976UnicodeString::operator== (const UnicodeString& text) const
3977{
3978 if(isBogus()) {
3979 return text.isBogus();
3980 } else {
3981 int32_t len = length(), textLength = text.length();
3982 return !text.isBogus() && len == textLength && doEquals(text, len);
3983 }
3984}
3985
3986inline bool
3987UnicodeString::operator!= (const UnicodeString& text) const
3988{ return (! operator==(text)); }
3989
3990inline UBool
3991UnicodeString::operator> (const UnicodeString& text) const
3992{ return doCompare(0, length(), text, 0, text.length()) == 1; }
3993
3994inline UBool
3995UnicodeString::operator< (const UnicodeString& text) const
3996{ return doCompare(0, length(), text, 0, text.length()) == -1; }
3997
3998inline UBool
3999UnicodeString::operator>= (const UnicodeString& text) const
4000{ return doCompare(0, length(), text, 0, text.length()) != -1; }
4001
4002inline UBool
4003UnicodeString::operator<= (const UnicodeString& text) const
4004{ return doCompare(0, length(), text, 0, text.length()) != 1; }
4005
4006inline int8_t
4007UnicodeString::compare(const UnicodeString& text) const
4008{ return doCompare(0, length(), text, 0, text.length()); }
4009
4010inline int8_t
4011UnicodeString::compare(int32_t start,
4013 const UnicodeString& srcText) const
4014{ return doCompare(start, _length, srcText, 0, srcText.length()); }
4015
4016inline int8_t
4017UnicodeString::compare(ConstChar16Ptr srcChars,
4018 int32_t srcLength) const
4019{ return doCompare(0, length(), srcChars, 0, srcLength); }
4020
4021inline int8_t
4022UnicodeString::compare(int32_t start,
4024 const UnicodeString& srcText,
4026 int32_t srcLength) const
4027{ return doCompare(start, _length, srcText, srcStart, srcLength); }
4028
4029inline int8_t
4030UnicodeString::compare(int32_t start,
4032 const char16_t *srcChars) const
4033{ return doCompare(start, _length, srcChars, 0, _length); }
4034
4035inline int8_t
4036UnicodeString::compare(int32_t start,
4038 const char16_t *srcChars,
4040 int32_t srcLength) const
4041{ return doCompare(start, _length, srcChars, srcStart, srcLength); }
4042
4043inline int8_t
4044UnicodeString::compareBetween(int32_t start,
4045 int32_t limit,
4046 const UnicodeString& srcText,
4048 int32_t srcLimit) const
4049{ return doCompare(start, limit - start,
4051
4052inline int8_t
4053UnicodeString::doCompareCodePointOrder(int32_t start,
4055 const UnicodeString& srcText,
4057 int32_t srcLength) const
4058{
4059 if(srcText.isBogus()) {
4060 return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
4061 } else {
4062 srcText.pinIndices(srcStart, srcLength);
4063 return doCompareCodePointOrder(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
4064 }
4065}
4066
4067inline int8_t
4068UnicodeString::compareCodePointOrder(const UnicodeString& text) const
4069{ return doCompareCodePointOrder(0, length(), text, 0, text.length()); }
4070
4071inline int8_t
4072UnicodeString::compareCodePointOrder(int32_t start,
4074 const UnicodeString& srcText) const
4075{ return doCompareCodePointOrder(start, _length, srcText, 0, srcText.length()); }
4076
4077inline int8_t
4078UnicodeString::compareCodePointOrder(ConstChar16Ptr srcChars,
4079 int32_t srcLength) const
4080{ return doCompareCodePointOrder(0, length(), srcChars, 0, srcLength); }
4081
4082inline int8_t
4083UnicodeString::compareCodePointOrder(int32_t start,
4085 const UnicodeString& srcText,
4087 int32_t srcLength) const
4088{ return doCompareCodePointOrder(start, _length, srcText, srcStart, srcLength); }
4089
4090inline int8_t
4091UnicodeString::compareCodePointOrder(int32_t start,
4093 const char16_t *srcChars) const
4094{ return doCompareCodePointOrder(start, _length, srcChars, 0, _length); }
4095
4096inline int8_t
4097UnicodeString::compareCodePointOrder(int32_t start,
4099 const char16_t *srcChars,
4101 int32_t srcLength) const
4102{ return doCompareCodePointOrder(start, _length, srcChars, srcStart, srcLength); }
4103
4104inline int8_t
4105UnicodeString::compareCodePointOrderBetween(int32_t start,
4106 int32_t limit,
4107 const UnicodeString& srcText,
4109 int32_t srcLimit) const
4110{ return doCompareCodePointOrder(start, limit - start,
4112
4113inline int8_t
4114UnicodeString::doCaseCompare(int32_t start,
4116 const UnicodeString &srcText,
4119 uint32_t options) const
4120{
4121 if(srcText.isBogus()) {
4122 return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
4123 } else {
4124 srcText.pinIndices(srcStart, srcLength);
4125 return doCaseCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength, options);
4126 }
4127}
4128
4129inline int8_t
4130UnicodeString::caseCompare(const UnicodeString &text, uint32_t options) const {
4131 return doCaseCompare(0, length(), text, 0, text.length(), options);
4132}
4133
4134inline int8_t
4135UnicodeString::caseCompare(int32_t start,
4137 const UnicodeString &srcText,
4138 uint32_t options) const {
4139 return doCaseCompare(start, _length, srcText, 0, srcText.length(), options);
4140}
4141
4142inline int8_t
4143UnicodeString::caseCompare(ConstChar16Ptr srcChars,
4145 uint32_t options) const {
4146 return doCaseCompare(0, length(), srcChars, 0, srcLength, options);
4147}
4148
4149inline int8_t
4150UnicodeString::caseCompare(int32_t start,
4152 const UnicodeString &srcText,
4155 uint32_t options) const {
4156 return doCaseCompare(start, _length, srcText, srcStart, srcLength, options);
4157}
4158
4159inline int8_t
4160UnicodeString::caseCompare(int32_t start,
4162 const char16_t *srcChars,
4163 uint32_t options) const {
4164 return doCaseCompare(start, _length, srcChars, 0, _length, options);
4165}
4166
4167inline int8_t
4168UnicodeString::caseCompare(int32_t start,
4170 const char16_t *srcChars,
4173 uint32_t options) const {
4174 return doCaseCompare(start, _length, srcChars, srcStart, srcLength, options);
4175}
4176
4177inline int8_t
4178UnicodeString::caseCompareBetween(int32_t start,
4179 int32_t limit,
4180 const UnicodeString &srcText,
4183 uint32_t options) const {
4184 return doCaseCompare(start, limit - start, srcText, srcStart, srcLimit - srcStart, options);
4185}
4186
4187inline int32_t
4188UnicodeString::indexOf(const UnicodeString& srcText,
4191 int32_t start,
4192 int32_t _length) const
4193{
4194 if(!srcText.isBogus()) {
4195 srcText.pinIndices(srcStart, srcLength);
4196 if(srcLength > 0) {
4197 return indexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
4198 }
4199 }
4200 return -1;
4201}
4202
4203inline int32_t
4204UnicodeString::indexOf(const UnicodeString& text) const
4205{ return indexOf(text, 0, text.length(), 0, length()); }
4206
4207inline int32_t
4208UnicodeString::indexOf(const UnicodeString& text,
4209 int32_t start) const {
4210 pinIndex(start);
4211 return indexOf(text, 0, text.length(), start, length() - start);
4212}
4213
4214inline int32_t
4215UnicodeString::indexOf(const UnicodeString& text,
4216 int32_t start,
4217 int32_t _length) const
4218{ return indexOf(text, 0, text.length(), start, _length); }
4219
4220inline int32_t
4221UnicodeString::indexOf(const char16_t *srcChars,
4223 int32_t start) const {
4224 pinIndex(start);
4225 return indexOf(srcChars, 0, srcLength, start, length() - start);
4226}
4227
4228inline int32_t
4229UnicodeString::indexOf(ConstChar16Ptr srcChars,
4231 int32_t start,
4232 int32_t _length) const
4233{ return indexOf(srcChars, 0, srcLength, start, _length); }
4234
4235inline int32_t
4236UnicodeString::indexOf(char16_t c,
4237 int32_t start,
4238 int32_t _length) const
4239{ return doIndexOf(c, start, _length); }
4240
4241inline int32_t
4242UnicodeString::indexOf(UChar32 c,
4243 int32_t start,
4244 int32_t _length) const
4245{ return doIndexOf(c, start, _length); }
4246
4247inline int32_t
4248UnicodeString::indexOf(char16_t c) const
4249{ return doIndexOf(c, 0, length()); }
4250
4251inline int32_t
4252UnicodeString::indexOf(UChar32 c) const
4253{ return indexOf(c, 0, length()); }
4254
4255inline int32_t
4256UnicodeString::indexOf(char16_t c,
4257 int32_t start) const {
4258 pinIndex(start);
4259 return doIndexOf(c, start, length() - start);
4260}
4261
4262inline int32_t
4263UnicodeString::indexOf(UChar32 c,
4264 int32_t start) const {
4265 pinIndex(start);
4266 return indexOf(c, start, length() - start);
4267}
4268
4269inline int32_t
4270UnicodeString::lastIndexOf(ConstChar16Ptr srcChars,
4272 int32_t start,
4273 int32_t _length) const
4274{ return lastIndexOf(srcChars, 0, srcLength, start, _length); }
4275
4276inline int32_t
4277UnicodeString::lastIndexOf(const char16_t *srcChars,
4279 int32_t start) const {
4280 pinIndex(start);
4281 return lastIndexOf(srcChars, 0, srcLength, start, length() - start);
4282}
4283
4284inline int32_t
4285UnicodeString::lastIndexOf(const UnicodeString& srcText,
4288 int32_t start,
4289 int32_t _length) const
4290{
4291 if(!srcText.isBogus()) {
4292 srcText.pinIndices(srcStart, srcLength);
4293 if(srcLength > 0) {
4294 return lastIndexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
4295 }
4296 }
4297 return -1;
4298}
4299
4300inline int32_t
4301UnicodeString::lastIndexOf(const UnicodeString& text,
4302 int32_t start,
4303 int32_t _length) const
4304{ return lastIndexOf(text, 0, text.length(), start, _length); }
4305
4306inline int32_t
4307UnicodeString::lastIndexOf(const UnicodeString& text,
4308 int32_t start) const {
4309 pinIndex(start);
4310 return lastIndexOf(text, 0, text.length(), start, length() - start);
4311}
4312
4313inline int32_t
4314UnicodeString::lastIndexOf(const UnicodeString& text) const
4315{ return lastIndexOf(text, 0, text.length(), 0, length()); }
4316
4317inline int32_t
4318UnicodeString::lastIndexOf(char16_t c,
4319 int32_t start,
4320 int32_t _length) const
4321{ return doLastIndexOf(c, start, _length); }
4322
4323inline int32_t
4324UnicodeString::lastIndexOf(UChar32 c,
4325 int32_t start,
4326 int32_t _length) const {
4327 return doLastIndexOf(c, start, _length);
4328}
4329
4330inline int32_t
4331UnicodeString::lastIndexOf(char16_t c) const
4332{ return doLastIndexOf(c, 0, length()); }
4333
4334inline int32_t
4335UnicodeString::lastIndexOf(UChar32 c) const {
4336 return lastIndexOf(c, 0, length());
4337}
4338
4339inline int32_t
4340UnicodeString::lastIndexOf(char16_t c,
4341 int32_t start) const {
4342 pinIndex(start);
4343 return doLastIndexOf(c, start, length() - start);
4344}
4345
4346inline int32_t
4347UnicodeString::lastIndexOf(UChar32 c,
4348 int32_t start) const {
4349 pinIndex(start);
4350 return lastIndexOf(c, start, length() - start);
4351}
4352
4353inline UBool
4354UnicodeString::startsWith(const UnicodeString& text) const
4355{ return doEqualsSubstring(0, text.length(), text, 0, text.length()); }
4356
4357inline UBool
4358UnicodeString::startsWith(const UnicodeString& srcText,
4360 int32_t srcLength) const
4361{ return doEqualsSubstring(0, srcLength, srcText, srcStart, srcLength); }
4362
4363inline UBool
4364UnicodeString::startsWith(ConstChar16Ptr srcChars, int32_t srcLength) const {
4365 if(srcLength < 0) {
4367 }
4368 return doEqualsSubstring(0, srcLength, srcChars, 0, srcLength);
4369}
4370
4371inline UBool
4372UnicodeString::startsWith(const char16_t *srcChars, int32_t srcStart, int32_t srcLength) const {
4373 if(srcLength < 0) {
4375 }
4376 return doEqualsSubstring(0, srcLength, srcChars, srcStart, srcLength);
4377}
4378
4379inline UBool
4380UnicodeString::endsWith(const UnicodeString& text) const
4381{ return doEqualsSubstring(length() - text.length(), text.length(),
4382 text, 0, text.length()); }
4383
4384inline UBool
4385UnicodeString::endsWith(const UnicodeString& srcText,
4387 int32_t srcLength) const {
4388 srcText.pinIndices(srcStart, srcLength);
4389 return doEqualsSubstring(length() - srcLength, srcLength,
4391}
4392
4393inline UBool
4394UnicodeString::endsWith(ConstChar16Ptr srcChars,
4395 int32_t srcLength) const {
4396 if(srcLength < 0) {
4398 }
4399 return doEqualsSubstring(length() - srcLength, srcLength, srcChars, 0, srcLength);
4400}
4401
4402inline UBool
4403UnicodeString::endsWith(const char16_t *srcChars,
4405 int32_t srcLength) const {
4406 if(srcLength < 0) {
4408 }
4409 return doEqualsSubstring(length() - srcLength, srcLength,
4411}
4412
4413//========================================
4414// replace
4415//========================================
4416inline UnicodeString&
4417UnicodeString::replace(int32_t start,
4419 const UnicodeString& srcText)
4420{ return doReplace(start, _length, srcText, 0, srcText.length()); }
4421
4422inline UnicodeString&
4423UnicodeString::replace(int32_t start,
4425 const UnicodeString& srcText,
4428{ return doReplace(start, _length, srcText, srcStart, srcLength); }
4429
4430inline UnicodeString&
4431UnicodeString::replace(int32_t start,
4435{ return doReplace(start, _length, srcChars, 0, srcLength); }
4436
4437inline UnicodeString&
4438UnicodeString::replace(int32_t start,
4440 const char16_t *srcChars,
4443{ return doReplace(start, _length, srcChars, srcStart, srcLength); }
4444
4445inline UnicodeString&
4446UnicodeString::replace(int32_t start,
4448 char16_t srcChar)
4449{ return doReplace(start, _length, &srcChar, 0, 1); }
4450
4451inline UnicodeString&
4452UnicodeString::replaceBetween(int32_t start,
4453 int32_t limit,
4454 const UnicodeString& srcText)
4455{ return doReplace(start, limit - start, srcText, 0, srcText.length()); }
4456
4457inline UnicodeString&
4458UnicodeString::replaceBetween(int32_t start,
4459 int32_t limit,
4460 const UnicodeString& srcText,
4463{ return doReplace(start, limit - start, srcText, srcStart, srcLimit - srcStart); }
4464
4465inline UnicodeString&
4466UnicodeString::findAndReplace(const UnicodeString& oldText,
4467 const UnicodeString& newText)
4468{ return findAndReplace(0, length(), oldText, 0, oldText.length(),
4469 newText, 0, newText.length()); }
4470
4471inline UnicodeString&
4472UnicodeString::findAndReplace(int32_t start,
4474 const UnicodeString& oldText,
4475 const UnicodeString& newText)
4476{ return findAndReplace(start, _length, oldText, 0, oldText.length(),
4477 newText, 0, newText.length()); }
4478
4479// ============================
4480// extract
4481// ============================
4482inline void
4483UnicodeString::doExtract(int32_t start,
4485 UnicodeString& target) const
4486{ target.replace(0, target.length(), *this, start, _length); }
4487
4488inline void
4489UnicodeString::extract(int32_t start,
4491 Char16Ptr target,
4492 int32_t targetStart) const
4493{ doExtract(start, _length, target, targetStart); }
4494
4495inline void
4496UnicodeString::extract(int32_t start,
4498 UnicodeString& target) const
4499{ doExtract(start, _length, target); }
4500
4501#if !UCONFIG_NO_CONVERSION
4502
4503inline int32_t
4504UnicodeString::extract(int32_t start,
4506 char *dst,
4507 const char *codepage) const
4508
4509{
4510 // This dstSize value will be checked explicitly
4511 return extract(start, _length, dst, dst != nullptr ? 0xffffffff : 0, codepage);
4512}
4513
4514#endif
4515
4516inline void
4517UnicodeString::extractBetween(int32_t start,
4518 int32_t limit,
4519 char16_t *dst,
4520 int32_t dstStart) const {
4521 pinIndex(start);
4522 pinIndex(limit);
4523 doExtract(start, limit - start, dst, dstStart);
4524}
4525
4526inline UnicodeString
4527UnicodeString::tempSubStringBetween(int32_t start, int32_t limit) const {
4528 return tempSubString(start, limit - start);
4529}
4530
4531inline char16_t
4532UnicodeString::doCharAt(int32_t offset) const
4533{
4534 if((uint32_t)offset < (uint32_t)length()) {
4535 return getArrayStart()[offset];
4536 } else {
4537 return kInvalidUChar;
4538 }
4539}
4540
4541inline char16_t
4542UnicodeString::charAt(int32_t offset) const
4543{ return doCharAt(offset); }
4544
4545inline char16_t
4546UnicodeString::operator[] (int32_t offset) const
4547{ return doCharAt(offset); }
4548
4549inline UBool
4550UnicodeString::isEmpty() const {
4551 // Arithmetic or logical right shift does not matter: only testing for 0.
4552 return (fUnion.fFields.fLengthAndFlags>>kLengthShift) == 0;
4553}
4554
4555//========================================
4556// Write implementation methods
4557//========================================
4558inline void
4559UnicodeString::setZeroLength() {
4560 fUnion.fFields.fLengthAndFlags &= kAllStorageFlags;
4561}
4562
4563inline void
4564UnicodeString::setShortLength(int32_t len) {
4565 // requires 0 <= len <= kMaxShortLength
4566 fUnion.fFields.fLengthAndFlags =
4567 (int16_t)((fUnion.fFields.fLengthAndFlags & kAllStorageFlags) | (len << kLengthShift));
4568}
4569
4570inline void
4571UnicodeString::setLength(int32_t len) {
4572 if(len <= kMaxShortLength) {
4573 setShortLength(len);
4574 } else {
4575 fUnion.fFields.fLengthAndFlags |= kLengthIsLarge;
4576 fUnion.fFields.fLength = len;
4577 }
4578}
4579
4580inline void
4581UnicodeString::setToEmpty() {
4582 fUnion.fFields.fLengthAndFlags = kShortString;
4583}
4584
4585inline void
4586UnicodeString::setArray(char16_t *array, int32_t len, int32_t capacity) {
4587 setLength(len);
4588 fUnion.fFields.fArray = array;
4589 fUnion.fFields.fCapacity = capacity;
4590}
4591
4592inline UnicodeString&
4593UnicodeString::operator= (char16_t ch)
4594{ return doReplace(0, length(), &ch, 0, 1); }
4595
4596inline UnicodeString&
4597UnicodeString::operator= (UChar32 ch)
4598{ return replace(0, length(), ch); }
4599
4600inline UnicodeString&
4601UnicodeString::setTo(const UnicodeString& srcText,
4604{
4605 unBogus();
4606 return doReplace(0, length(), srcText, srcStart, srcLength);
4607}
4608
4609inline UnicodeString&
4610UnicodeString::setTo(const UnicodeString& srcText,
4612{
4613 unBogus();
4614 srcText.pinIndex(srcStart);
4615 return doReplace(0, length(), srcText, srcStart, srcText.length() - srcStart);
4616}
4617
4618inline UnicodeString&
4619UnicodeString::setTo(const UnicodeString& srcText)
4620{
4621 return copyFrom(srcText);
4622}
4623
4624inline UnicodeString&
4625UnicodeString::setTo(const char16_t *srcChars,
4627{
4628 unBogus();
4629 return doReplace(0, length(), srcChars, 0, srcLength);
4630}
4631
4632inline UnicodeString&
4633UnicodeString::setTo(char16_t srcChar)
4634{
4635 unBogus();
4636 return doReplace(0, length(), &srcChar, 0, 1);
4637}
4638
4639inline UnicodeString&
4640UnicodeString::setTo(UChar32 srcChar)
4641{
4642 unBogus();
4643 return replace(0, length(), srcChar);
4644}
4645
4646inline UnicodeString&
4647UnicodeString::append(const UnicodeString& srcText,
4650{ return doAppend(srcText, srcStart, srcLength); }
4651
4652inline UnicodeString&
4653UnicodeString::append(const UnicodeString& srcText)
4654{ return doAppend(srcText, 0, srcText.length()); }
4655
4656inline UnicodeString&
4657UnicodeString::append(const char16_t *srcChars,
4660{ return doAppend(srcChars, srcStart, srcLength); }
4661
4662inline UnicodeString&
4663UnicodeString::append(ConstChar16Ptr srcChars,
4665{ return doAppend(srcChars, 0, srcLength); }
4666
4667inline UnicodeString&
4668UnicodeString::append(char16_t srcChar)
4669{ return doAppend(&srcChar, 0, 1); }
4670
4671inline UnicodeString&
4672UnicodeString::operator+= (char16_t ch)
4673{ return doAppend(&ch, 0, 1); }
4674
4675inline UnicodeString&
4676UnicodeString::operator+= (UChar32 ch) {
4677 return append(ch);
4678}
4679
4680inline UnicodeString&
4681UnicodeString::operator+= (const UnicodeString& srcText)
4682{ return doAppend(srcText, 0, srcText.length()); }
4683
4684inline UnicodeString&
4685UnicodeString::insert(int32_t start,
4686 const UnicodeString& srcText,
4689{ return doReplace(start, 0, srcText, srcStart, srcLength); }
4690
4691inline UnicodeString&
4692UnicodeString::insert(int32_t start,
4693 const UnicodeString& srcText)
4694{ return doReplace(start, 0, srcText, 0, srcText.length()); }
4695
4696inline UnicodeString&
4697UnicodeString::insert(int32_t start,
4698 const char16_t *srcChars,
4701{ return doReplace(start, 0, srcChars, srcStart, srcLength); }
4702
4703inline UnicodeString&
4704UnicodeString::insert(int32_t start,
4707{ return doReplace(start, 0, srcChars, 0, srcLength); }
4708
4709inline UnicodeString&
4710UnicodeString::insert(int32_t start,
4711 char16_t srcChar)
4712{ return doReplace(start, 0, &srcChar, 0, 1); }
4713
4714inline UnicodeString&
4715UnicodeString::insert(int32_t start,
4717{ return replace(start, 0, srcChar); }
4718
4719
4720inline UnicodeString&
4721UnicodeString::remove()
4722{
4723 // remove() of a bogus string makes the string empty and non-bogus
4724 if(isBogus()) {
4725 setToEmpty();
4726 } else {
4727 setZeroLength();
4728 }
4729 return *this;
4730}
4731
4732inline UnicodeString&
4733UnicodeString::remove(int32_t start,
4735{
4736 if(start <= 0 && _length == INT32_MAX) {
4737 // remove(guaranteed everything) of a bogus string makes the string empty and non-bogus
4738 return remove();
4739 }
4740 return doReplace(start, _length, nullptr, 0, 0);
4741}
4742
4743inline UnicodeString&
4744UnicodeString::removeBetween(int32_t start,
4745 int32_t limit)
4746{ return doReplace(start, limit - start, nullptr, 0, 0); }
4747
4748inline UnicodeString &
4749UnicodeString::retainBetween(int32_t start, int32_t limit) {
4750 truncate(limit);
4751 return doReplace(0, start, nullptr, 0, 0);
4752}
4753
4754inline UBool
4755UnicodeString::truncate(int32_t targetLength)
4756{
4757 if(isBogus() && targetLength == 0) {
4758 // truncate(0) of a bogus string makes the string empty and non-bogus
4759 unBogus();
4760 return false;
4761 } else if((uint32_t)targetLength < (uint32_t)length()) {
4762 setLength(targetLength);
4763 return true;
4764 } else {
4765 return false;
4766 }
4767}
4768
4769inline UnicodeString&
4770UnicodeString::reverse()
4771{ return doReverse(0, length()); }
4772
4773inline UnicodeString&
4774UnicodeString::reverse(int32_t start,
4776{ return doReverse(start, _length); }
4777
4779
4780#endif /* U_SHOW_CPLUSPLUS_API */
4781
4782#endif
C++ API: Interface for writing bytes, and implementation classes.
C++ API: char16_t pointer wrappers with implicit conversion from bit-compatible raw pointer types.
The BreakIterator class implements methods for finding the location of boundaries in text.
Definition brkiter.h:106
A ByteSink can be filled with bytes.
Definition bytestream.h:53
char16_t * wrapper with implicit conversion from distinct but bit-compatible pointer types.
Definition char16ptr.h:42
const char16_t * wrapper with implicit conversion from distinct but bit-compatible pointer types.
Definition char16ptr.h:149
Records lengths of string edits but not replacement text.
Definition edits.h:80
"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:195
Replaceable is an abstract base class representing a string of characters that supports the replaceme...
Definition rep.h:77
virtual void extractBetween(int32_t start, int32_t limit, UnicodeString &target) const =0
Copies characters in the range [start, limit) into the UnicodeString target.
char16_t charAt(int32_t offset) const
Returns the 16-bit code unit at the given offset into the text.
Definition rep.h:251
int32_t length() const
Returns the number of 16-bit code units in the text.
Definition rep.h:246
A string-like object that points to a sized piece of memory.
Definition stringpiece.h:60
An Appendable implementation which writes to a UnicodeString.
Definition appendable.h:156
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:296
int32_t indexOf(const char16_t *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.
void swap(UnicodeString &other) noexcept
Swap strings.
virtual char16_t getCharAt(int32_t offset) const override
The change in Replaceable to use virtual getCharAt() allows UnicodeString::charAt() to be inline agai...
virtual int32_t getLength() const override
Implement Replaceable::getLength() (see jitterbug 1027).
UnicodeString & setTo(char16_t *buffer, int32_t buffLength, int32_t buffCapacity)
Aliasing setTo() function, analogous to the writable-aliasing char16_t* constructor.
UnicodeString & operator=(UnicodeString &&src) noexcept
Move assignment operator; might leave src in bogus state.
UChar32 unescapeAt(int32_t &offset) const
Unescape a single escape sequence and return the represented character.
UnicodeString(const wchar_t *text, int32_t textLength)
wchar_t * constructor.
Definition unistr.h:3058
virtual void handleReplaceBetween(int32_t start, int32_t limit, const UnicodeString &text) override
Replace a substring of this object with the given text.
UBool hasMoreChar32Than(int32_t start, int32_t length, int32_t number) const
Check if the length char16_t code units of the string contain more Unicode code points than a certain...
UnicodeString(const UnicodeString &src, int32_t srcStart, int32_t srcLength)
'Substring' constructor from subrange of source string.
virtual ~UnicodeString()
Destructor.
UnicodeString(const char *codepageData, int32_t dataLength, const char *codepage)
char* constructor.
UnicodeString(const char *codepageData, const char *codepage)
char* constructor.
UnicodeString(UBool isTerminated, ConstChar16Ptr text, int32_t textLength)
Readonly-aliasing char16_t* constructor.
UnicodeString & toTitle(BreakIterator *titleIter, const Locale &locale, uint32_t options)
Titlecase this string, with options.
UnicodeString & append(UChar32 srcChar)
Append the code point srcChar to the UnicodeString object.
EInvariant
Constant to be used in the UnicodeString(char *, int32_t, EInvariant) constructor which constructs a ...
Definition unistr.h:307
UnicodeString unescape() const
Unescape a string of characters and return a string containing the result.
UnicodeString(const UnicodeString &src, int32_t srcStart)
'Substring' constructor from tail of source string.
int32_t getChar32Limit(int32_t offset) const
Adjust a random-access offset so that it points behind a Unicode character.
UnicodeString(char16_t *buffer, int32_t buffLength, int32_t buffCapacity)
Writable-aliasing char16_t* constructor.
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(int32_t capacity, UChar32 c, int32_t count)
Construct a UnicodeString with capacity to hold capacity char16_ts.
UNISTR_FROM_STRING_EXPLICIT UnicodeString(const uint16_t *text)
uint16_t * constructor.
Definition unistr.h:2995
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...
virtual void copy(int32_t start, int32_t limit, int32_t dest) override
Copy a substring of this object, retaining attribute (out-of-band) information.
virtual void extractBetween(int32_t start, int32_t limit, UnicodeString &target) const override
Copy the characters in the range [start, limit) into the UnicodeString target.
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:4423
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.
virtual UnicodeString * clone() const override
Clone this object, an instance of a subclass of Replaceable.
UBool padLeading(int32_t targetLength, char16_t padChar=0x0020)
Pad the start of this UnicodeString with the character padChar.
int32_t getChar32Start(int32_t offset) const
Adjust a random-access offset so that it points to the beginning of a Unicode character.
UChar32 char32At(int32_t offset) const
Return the code point that contains the code unit at offset offset.
UnicodeString(const char *src, int32_t textLength, enum EInvariant inv)
Constructs a Unicode string from an invariant-character char * string.
UnicodeString tempSubString(int32_t start=0, int32_t length=INT32_MAX) const
Create a temporary substring for the specified range.
int32_t extract(Char16Ptr dest, int32_t destCapacity, UErrorCode &errorCode) const
Copy the contents of the string into dest.
int32_t length() const
Return the length of the UnicodeString object.
Definition unistr.h:3901
virtual UChar32 getChar32At(int32_t offset) const override
The change in Replaceable to use virtual getChar32At() allows UnicodeString::char32At() to be inline ...
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'...
static UnicodeString fromUTF8(StringPiece utf8)
Create a UnicodeString from a UTF-8 string.
UNISTR_FROM_CHAR_EXPLICIT UnicodeString(char16_t ch)
Single char16_t (code unit) constructor.
int32_t lastIndexOf(const char16_t *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...
UnicodeString(wchar_t *buffer, int32_t buffLength, int32_t buffCapacity)
Writable-aliasing wchar_t * constructor.
Definition unistr.h:3140
void setToBogus()
Make this UnicodeString object invalid.
friend void swap(UnicodeString &s1, UnicodeString &s2) noexcept
Non-member UnicodeString swap function.
Definition unistr.h:1924
int32_t moveIndex32(int32_t index, int32_t delta) const
Move the code unit index along the string by delta code points.
static UnicodeString fromUTF32(const UChar32 *utf32, int32_t length)
Create a UnicodeString from a UTF-32 string.
UnicodeString & replace(int32_t start, int32_t length, UChar32 srcChar)
Replace the characters in the range [start, start + length) with the code point srcChar.
int32_t countChar32(int32_t start=0, int32_t length=INT32_MAX) const
Count Unicode code points in the length char16_t code units of the string.
UNISTR_FROM_CHAR_EXPLICIT UnicodeString(UChar32 ch)
Single UChar32 (code point) constructor.
UnicodeString & trim()
Trims leading and trailing whitespace from this UnicodeString.
UnicodeString & operator=(const UnicodeString &srcText)
Assignment operator.
UnicodeString & setTo(UBool isTerminated, ConstChar16Ptr text, int32_t textLength)
Aliasing setTo() function, analogous to the readonly-aliasing char16_t* constructor.
int32_t extract(char *dest, int32_t destCapacity, UConverter *cnv, UErrorCode &errorCode) const
Convert the UnicodeString into a codepage string using an existing UConverter.
StringClass & toUTF8String(StringClass &result) const
Convert the UnicodeString to UTF-8 and append the result to a standard string.
Definition unistr.h:1729
UnicodeString(UnicodeString &&src) noexcept
Move constructor; might leave src in bogus state.
UnicodeString & toUpper()
Convert the characters in this to UPPER CASE following the conventions of the default locale.
UnicodeString(const char16_t *text, int32_t textLength)
char16_t* constructor.
UnicodeString(const char *src, int32_t srcLength, UConverter *cnv, UErrorCode &errorCode)
char * / UConverter constructor.
UnicodeString(const char *codepageData, int32_t dataLength)
char* constructor.
static UClassID getStaticClassID()
ICU "poor man's RTTI", returns a UClassID for this class.
UnicodeString(uint16_t *buffer, int32_t buffLength, int32_t buffCapacity)
Writable-aliasing uint16_t * constructor.
Definition unistr.h:3126
int32_t toUTF32(UChar32 *utf32, int32_t capacity, UErrorCode &errorCode) const
Convert the UnicodeString to UTF-32.
UBool isBogus() const
Determine if this object contains a valid string.
Definition unistr.h:3916
UnicodeString & toLower(const Locale &locale)
Convert the characters in this to lower case following the conventions of a specific locale.
UnicodeString & toTitle(BreakIterator *titleIter, const Locale &locale)
Titlecase this string.
UnicodeString & foldCase(uint32_t options=0)
Case-folds the characters in this string.
const char16_t * getTerminatedBuffer()
Get a read-only pointer to the internal buffer, making sure that it is NUL-terminated.
UnicodeString(const uint16_t *text, int32_t textLength)
uint16_t * constructor.
Definition unistr.h:3045
UNISTR_FROM_STRING_EXPLICIT UnicodeString(const char16_t *text)
char16_t* constructor.
UnicodeString & toUpper(const Locale &locale)
Convert the characters in this to UPPER CASE following the conventions of a specific locale.
UnicodeString & setCharAt(int32_t offset, char16_t ch)
Set the character at the specified offset to the specified character.
virtual UClassID getDynamicClassID() const override
ICU "poor man's RTTI", returns a UClassID for the actual class.
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.
UNISTR_FROM_STRING_EXPLICIT UnicodeString(const wchar_t *text)
wchar_t * constructor.
Definition unistr.h:3011
char16_t * getBuffer(int32_t minCapacity)
Get a read/write pointer to the internal buffer.
UnicodeString & toLower()
Convert the characters in this to lower case following the conventions of the default locale.
UBool padTrailing(int32_t targetLength, char16_t padChar=0x0020)
Pad the end of this UnicodeString with the character padChar.
UNISTR_FROM_STRING_EXPLICIT UnicodeString(const char *codepageData)
char* constructor.
void releaseBuffer(int32_t newLength=-1)
Release a read/write buffer on a UnicodeString object with an "open" getBuffer(minCapacity).
void toUTF8(ByteSink &sink) const
Convert the UnicodeString to UTF-8 and write the result to a ByteSink.
virtual UBool hasMetaData() const override
Replaceable API.
U_CAPI int32_t u_strlen(const UChar *s)
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
bool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
const UChar * toUCharPtr(const char16_t *p)
Converts from const char16_t * to const UChar *.
Definition char16ptr.h:260
#define U_CALLCONV
Similar to U_CDECL_BEGIN/U_CDECL_END, this qualifier is necessary in callback function typedefs to ma...
Definition platform.h:823
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.
struct UConverter UConverter
Definition ucnv_err.h:96
#define UCONFIG_NO_BREAK_ITERATION
This switch turns off break iteration.
Definition uconfig.h:358
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
Definition umachine.h:427
#define INT32_MAX
The largest value a 32 bit signed integer can hold.
Definition umachine.h:186
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition umachine.h:247
#define U_CAPI
This is used to declare a function as a public ICU C API.
Definition umachine.h:110
char16_t UChar
The base type for UTF-16 code units and pointers.
Definition umachine.h:378
#define U_SIZEOF_UCHAR
Number of bytes in a UChar (always 2).
Definition umachine.h:330
#define UNISTR_FROM_CHAR_EXPLICIT
This can be defined to be empty or "explicit".
Definition unistr.h:150
int32_t UStringCaseMapper(int32_t caseLocale, uint32_t options, icu::BreakIterator *iter, char16_t *dest, int32_t destCapacity, const char16_t *src, int32_t srcLength, icu::Edits *edits, UErrorCode &errorCode)
Internal string case mapping function type.
Definition unistr.h:70
#define UNISTR_FROM_STRING_EXPLICIT
This can be defined to be empty or "explicit".
Definition unistr.h:170
#define UNISTR_OBJECT_SIZE
Desired sizeof(UnicodeString) in bytes.
Definition unistr.h:208
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.
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition utypes.h:415
#define U_COMMON_API
Set to export library symbols from inside the common library, and to import them from outside.
Definition utypes.h:300