33 #if U_SHOW_CPLUSPLUS_API
55 #if !UCONFIG_NO_BREAK_ITERATION
74 char16_t *dest, int32_t destCapacity,
75 const char16_t *src, int32_t srcLength,
82 class StringCharacterIterator;
83 class UnicodeStringAppendable;
97 #define US_INV icu::UnicodeString::kInvariant
116 #if !U_CHAR16_IS_TYPEDEF
117 # define UNICODE_STRING(cs, _length) icu::UnicodeString(true, u ## cs, _length)
119 # define UNICODE_STRING(cs, _length) icu::UnicodeString(true, (const char16_t*)u ## cs, _length)
135 #define UNICODE_STRING_SIMPLE(cs) UNICODE_STRING(cs, -1)
144 #ifndef UNISTR_FROM_CHAR_EXPLICIT
145 # if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION)
147 # define UNISTR_FROM_CHAR_EXPLICIT explicit
150 # define UNISTR_FROM_CHAR_EXPLICIT
164 #ifndef UNISTR_FROM_STRING_EXPLICIT
165 # if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION)
167 # define UNISTR_FROM_STRING_EXPLICIT explicit
170 # define UNISTR_FROM_STRING_EXPLICIT
207 #ifndef UNISTR_OBJECT_SIZE
208 # define UNISTR_OBJECT_SIZE 64
403 inline int8_t compare(int32_t start,
424 inline int8_t compare(int32_t start,
428 int32_t srcLength)
const;
443 int32_t srcLength)
const;
459 inline int8_t compare(int32_t start,
461 const char16_t *srcChars)
const;
480 inline int8_t compare(int32_t start,
482 const char16_t *srcChars,
484 int32_t srcLength)
const;
503 inline int8_t compareBetween(int32_t start,
507 int32_t srcLimit)
const;
526 inline int8_t compareCodePointOrder(
const UnicodeString& text)
const;
547 inline int8_t compareCodePointOrder(int32_t start,
572 inline int8_t compareCodePointOrder(int32_t start,
576 int32_t srcLength)
const;
597 int32_t srcLength)
const;
618 inline int8_t compareCodePointOrder(int32_t start,
620 const char16_t *srcChars)
const;
643 inline int8_t compareCodePointOrder(int32_t start,
645 const char16_t *srcChars,
647 int32_t srcLength)
const;
670 inline int8_t compareCodePointOrderBetween(int32_t start,
674 int32_t srcLimit)
const;
694 inline int8_t caseCompare(
const UnicodeString& text, uint32_t options)
const;
716 inline int8_t caseCompare(int32_t start,
719 uint32_t options)
const;
743 inline int8_t caseCompare(int32_t start,
748 uint32_t options)
const;
771 uint32_t options)
const;
793 inline int8_t caseCompare(int32_t start,
795 const char16_t *srcChars,
796 uint32_t options)
const;
820 inline int8_t caseCompare(int32_t start,
822 const char16_t *srcChars,
825 uint32_t options)
const;
849 inline int8_t caseCompareBetween(int32_t start,
854 uint32_t options)
const;
877 int32_t srcLength)
const;
888 int32_t srcLength)
const;
899 inline UBool startsWith(
const char16_t *srcChars,
901 int32_t srcLength)
const;
924 int32_t srcLength)
const;
935 int32_t srcLength)
const;
947 inline UBool endsWith(
const char16_t *srcChars,
949 int32_t srcLength)
const;
974 int32_t start)
const;
989 int32_t length)
const;
1011 int32_t length)
const;
1024 inline int32_t indexOf(
const char16_t *srcChars,
1026 int32_t start)
const;
1043 int32_t length)
const;
1061 int32_t indexOf(
const char16_t *srcChars,
1065 int32_t length)
const;
1074 inline int32_t indexOf(char16_t c)
const;
1084 inline int32_t indexOf(
UChar32 c)
const;
1094 inline int32_t indexOf(char16_t c,
1095 int32_t start)
const;
1106 inline int32_t indexOf(
UChar32 c,
1107 int32_t start)
const;
1119 inline int32_t indexOf(char16_t c,
1121 int32_t length)
const;
1134 inline int32_t indexOf(
UChar32 c,
1136 int32_t length)
const;
1146 inline int32_t lastIndexOf(
const UnicodeString& text)
const;
1158 int32_t start)
const;
1173 int32_t length)
const;
1195 int32_t length)
const;
1207 inline int32_t lastIndexOf(
const char16_t *srcChars,
1209 int32_t start)
const;
1226 int32_t length)
const;
1244 int32_t lastIndexOf(
const char16_t *srcChars,
1248 int32_t length)
const;
1257 inline int32_t lastIndexOf(char16_t c)
const;
1267 inline int32_t lastIndexOf(
UChar32 c)
const;
1277 inline int32_t lastIndexOf(char16_t c,
1278 int32_t start)
const;
1289 inline int32_t lastIndexOf(
UChar32 c,
1290 int32_t start)
const;
1302 inline int32_t lastIndexOf(char16_t c,
1304 int32_t length)
const;
1317 inline int32_t lastIndexOf(
UChar32 c,
1319 int32_t length)
const;
1332 inline char16_t
charAt(int32_t offset)
const;
1341 inline char16_t operator[] (int32_t offset)
const;
1371 int32_t getChar32Start(int32_t offset)
const;
1389 int32_t getChar32Limit(int32_t offset)
const;
1441 int32_t moveIndex32(int32_t index, int32_t delta)
const;
1460 inline void extract(int32_t start,
1463 int32_t dstStart = 0)
const;
1487 extract(
Char16Ptr dest, int32_t destCapacity,
1499 inline void extract(int32_t start,
1517 int32_t dstStart = 0)
const;
1552 int32_t extract(int32_t start,
1553 int32_t startLength,
1555 int32_t targetCapacity,
1556 enum EInvariant inv)
const;
1558 #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
1579 int32_t extract(int32_t start,
1580 int32_t startLength,
1582 uint32_t targetLength)
const;
1586 #if !UCONFIG_NO_CONVERSION
1613 inline int32_t extract(int32_t start,
1614 int32_t startLength,
1616 const char* codepage =
nullptr)
const;
1647 int32_t extract(int32_t start,
1648 int32_t startLength,
1650 uint32_t targetLength,
1651 const char *codepage)
const;
1670 int32_t extract(
char *dest, int32_t destCapacity,
1728 template<
typename StringClass>
1762 inline int32_t
length()
const;
1778 countChar32(int32_t start=0, int32_t length=
INT32_MAX)
const;
1804 hasMoreChar32Than(int32_t start, int32_t length, int32_t number)
const;
1811 inline UBool isEmpty()
const;
1822 inline int32_t getCapacity()
const;
1831 inline int32_t hashCode()
const;
1845 inline UBool isBogus()
const;
1923 friend inline
void U_EXPORT2
2043 int32_t textLength);
2066 int32_t buffCapacity);
2267 const char16_t *srcChars,
2367 const char16_t *srcChars,
2480 virtual void copy(int32_t start, int32_t limit, int32_t dest)
override;
2596 UBool padLeading(int32_t targetLength,
2597 char16_t padChar = 0x0020);
2610 UBool padTrailing(int32_t targetLength,
2611 char16_t padChar = 0x0020);
2619 inline UBool truncate(int32_t targetLength);
2682 #if !UCONFIG_NO_BREAK_ITERATION
2837 char16_t *getBuffer(int32_t minCapacity);
2859 void releaseBuffer(int32_t newLength=-1);
2891 inline const char16_t *getBuffer()
const;
2926 const char16_t *getTerminatedBuffer();
2984 #if !U_CHAR16_IS_TYPEDEF
2999 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
3035 int32_t textLength);
3037 #if !U_CHAR16_IS_TYPEDEF
3049 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
3069 inline UnicodeString(
const std::nullptr_t text, int32_t textLength);
3095 int32_t textLength);
3115 UnicodeString(char16_t *buffer, int32_t buffLength, int32_t buffCapacity);
3117 #if !U_CHAR16_IS_TYPEDEF
3130 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
3152 inline UnicodeString(std::nullptr_t buffer, int32_t buffLength, int32_t buffCapacity);
3154 #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
3185 UnicodeString(
const char *codepageData, int32_t dataLength);
3189 #if !UCONFIG_NO_CONVERSION
3208 UnicodeString(
const char *codepageData,
const char *codepage);
3227 UnicodeString(
const char *codepageData, int32_t dataLength,
const char *codepage);
3251 const char *src, int32_t srcLength,
3280 UnicodeString(
const char *src, int32_t textLength,
enum EInvariant inv);
3372 static UnicodeString fromUTF32(const
UChar32 *utf32, int32_t length);
3410 UnicodeString unescape() const;
3431 UChar32 unescapeAt(int32_t &offset) const;
3438 static
UClassID U_EXPORT2 getStaticClassID();
3445 virtual
UClassID getDynamicClassID() const override;
3456 virtual int32_t getLength() const override;
3463 virtual char16_t getCharAt(int32_t offset) const override;
3470 virtual
UChar32 getChar32At(int32_t offset) const override;
3481 toUTF8(int32_t start, int32_t len,
3482 char *target, int32_t capacity) const;
3488 UBool doEquals(const UnicodeString &text, int32_t len) const;
3491 doEqualsSubstring(int32_t start,
3493 const UnicodeString& srcText,
3495 int32_t srcLength) const;
3497 UBool doEqualsSubstring(int32_t start,
3499 const char16_t *srcChars,
3501 int32_t srcLength) const;
3504 doCompare(int32_t start,
3506 const UnicodeString& srcText,
3508 int32_t srcLength) const;
3510 int8_t doCompare(int32_t start,
3512 const char16_t *srcChars,
3514 int32_t srcLength) const;
3517 doCompareCodePointOrder(int32_t start,
3519 const UnicodeString& srcText,
3521 int32_t srcLength) const;
3523 int8_t doCompareCodePointOrder(int32_t start,
3525 const char16_t *srcChars,
3527 int32_t srcLength) const;
3530 doCaseCompare(int32_t start,
3532 const UnicodeString &srcText,
3535 uint32_t options) const;
3538 doCaseCompare(int32_t start,
3540 const char16_t *srcChars,
3543 uint32_t options) const;
3545 int32_t doIndexOf(char16_t c,
3547 int32_t length) const;
3551 int32_t length) const;
3553 int32_t doLastIndexOf(char16_t c,
3555 int32_t length) const;
3557 int32_t doLastIndexOf(
UChar32 c,
3559 int32_t length) const;
3561 void doExtract(int32_t start,
3564 int32_t dstStart) const;
3566 inline
void doExtract(int32_t start,
3568 UnicodeString& target) const;
3570 inline char16_t doCharAt(int32_t offset) const;
3572 UnicodeString& doReplace(int32_t start,
3574 const UnicodeString& srcText,
3578 UnicodeString& doReplace(int32_t start,
3580 const char16_t *srcChars,
3584 UnicodeString& doAppend(const UnicodeString& src, int32_t srcStart, int32_t srcLength);
3585 UnicodeString& doAppend(const char16_t *srcChars, int32_t srcStart, int32_t srcLength);
3587 UnicodeString& doReverse(int32_t start,
3591 int32_t doHashCode() const;
3595 inline char16_t* getArrayStart();
3596 inline const char16_t* getArrayStart() const;
3598 inline
UBool hasShortLength() const;
3599 inline int32_t getShortLength() const;
3603 inline
UBool isWritable() const;
3606 inline
UBool isBufferWritable() const;
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);
3620 UBool allocate(int32_t capacity);
3623 void releaseArray();
3629 UnicodeString ©From(const UnicodeString &src,
UBool fastCopy=false);
3632 void copyFieldsFrom(UnicodeString &src,
UBool setSrcToBogus) noexcept;
3635 inline
void pinIndex(int32_t& start) const;
3636 inline
void pinIndices(int32_t& start,
3637 int32_t& length) const;
3639 #if !UCONFIG_NO_CONVERSION
3642 int32_t doExtract(int32_t start, int32_t length,
3643 char *dest, int32_t destCapacity,
3657 void doCodepageCreate(
const char *codepageData,
3659 const char *codepage);
3666 doCodepageCreate(
const char *codepageData,
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);
3696 caseMap(int32_t caseLocale, uint32_t options,
3704 int32_t removeRef();
3705 int32_t refCount()
const;
3715 kInvalidUChar=0xffff,
3721 kUsingStackBuffer=2,
3723 kBufferIsReadonly=8,
3726 kAllStorageFlags=0x1f,
3729 kLength1=1<<kLengthShift,
3730 kMaxShortLength=0x3ff,
3731 kLengthIsLarge=0xffe0,
3734 kShortString=kUsingStackBuffer,
3735 kLongString=kRefCounted,
3736 kReadonlyAlias=kBufferIsReadonly,
3742 union StackBufferOrFields;
3743 friend union StackBufferOrFields;
3786 union StackBufferOrFields {
3790 int16_t fLengthAndFlags;
3791 char16_t fBuffer[US_STACKBUF_SIZE];
3794 int16_t fLengthAndFlags;
3813 operator+ (
const UnicodeString &s1,
const UnicodeString &s2);
3824 UnicodeString::pinIndex(int32_t& start)
const
3829 }
else if(start >
length()) {
3835 UnicodeString::pinIndices(int32_t& start,
3836 int32_t& _length)
const
3842 }
else if(start > len) {
3847 }
else if(_length > (len - start)) {
3848 _length = (len - start);
3853 UnicodeString::getArrayStart() {
3854 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3855 fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
3858 inline const char16_t*
3859 UnicodeString::getArrayStart()
const {
3860 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3861 fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
3870 fUnion.fStackFields.fLengthAndFlags=kShortString;
3874 fUnion.fStackFields.fLengthAndFlags=kShortString;
3878 fUnion.fStackFields.fLengthAndFlags=kShortString;
3882 fUnion.fStackFields.fLengthAndFlags=kShortString;
3889 UnicodeString::hasShortLength()
const {
3890 return fUnion.fFields.fLengthAndFlags>=0;
3894 UnicodeString::getShortLength()
const {
3897 return fUnion.fFields.fLengthAndFlags>>kLengthShift;
3902 return hasShortLength() ? getShortLength() : fUnion.fFields.fLength;
3907 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3908 US_STACKBUF_SIZE : fUnion.fFields.fCapacity;
3913 {
return doHashCode(); }
3917 {
return (
UBool)(fUnion.fFields.fLengthAndFlags & kIsBogus); }
3920 UnicodeString::isWritable()
const
3921 {
return (
UBool)!(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus)); }
3924 UnicodeString::isBufferWritable()
const
3927 !(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus|kBufferIsReadonly)) &&
3928 (!(fUnion.fFields.fLengthAndFlags&kRefCounted) || refCount()==1));
3931 inline const char16_t *
3933 if(fUnion.fFields.fLengthAndFlags&(kIsBogus|kOpenGetBuffer)) {
3935 }
else if(fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) {
3936 return fUnion.fStackFields.fBuffer;
3938 return fUnion.fFields.fArray;
3946 UnicodeString::doCompare(int32_t start,
3948 const UnicodeString& srcText,
3950 int32_t srcLength)
const
3953 return (int8_t)!isBogus();
3955 srcText.pinIndices(srcStart, srcLength);
3956 return doCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
3961 UnicodeString::doEqualsSubstring(int32_t start,
3963 const UnicodeString& srcText,
3965 int32_t srcLength)
const
3967 if(srcText.isBogus()) {
3970 srcText.pinIndices(srcStart, srcLength);
3971 return !isBogus() && doEqualsSubstring(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
3982 return !text.
isBogus() && len == textLength && doEquals(text, len);
3988 {
return (!
operator==(text)); }
3992 {
return doCompare(0,
length(), text, 0, text.
length()) == 1; }
3996 {
return doCompare(0,
length(), text, 0, text.
length()) == -1; }
4000 {
return doCompare(0,
length(), text, 0, text.
length()) != -1; }
4004 {
return doCompare(0,
length(), text, 0, text.
length()) != 1; }
4008 {
return doCompare(0,
length(), text, 0, text.
length()); }
4013 const UnicodeString& srcText)
const
4014 {
return doCompare(start, _length, srcText, 0, srcText.
length()); }
4018 int32_t srcLength)
const
4019 {
return doCompare(0,
length(), srcChars, 0, srcLength); }
4024 const UnicodeString& srcText,
4026 int32_t srcLength)
const
4027 {
return doCompare(start, _length, srcText, srcStart, srcLength); }
4032 const char16_t *srcChars)
const
4033 {
return doCompare(start, _length, srcChars, 0, _length); }
4038 const char16_t *srcChars,
4040 int32_t srcLength)
const
4041 {
return doCompare(start, _length, srcChars, srcStart, srcLength); }
4046 const UnicodeString& srcText,
4048 int32_t srcLimit)
const
4049 {
return doCompare(start, limit - start,
4050 srcText, srcStart, srcLimit - srcStart); }
4053 UnicodeString::doCompareCodePointOrder(int32_t start,
4055 const UnicodeString& srcText,
4057 int32_t srcLength)
const
4060 return (int8_t)!isBogus();
4062 srcText.pinIndices(srcStart, srcLength);
4063 return doCompareCodePointOrder(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
4069 {
return doCompareCodePointOrder(0,
length(), text, 0, text.
length()); }
4074 const UnicodeString& srcText)
const
4075 {
return doCompareCodePointOrder(start, _length, srcText, 0, srcText.
length()); }
4079 int32_t srcLength)
const
4080 {
return doCompareCodePointOrder(0,
length(), srcChars, 0, srcLength); }
4085 const UnicodeString& srcText,
4087 int32_t srcLength)
const
4088 {
return doCompareCodePointOrder(start, _length, srcText, srcStart, srcLength); }
4093 const char16_t *srcChars)
const
4094 {
return doCompareCodePointOrder(start, _length, srcChars, 0, _length); }
4099 const char16_t *srcChars,
4101 int32_t srcLength)
const
4102 {
return doCompareCodePointOrder(start, _length, srcChars, srcStart, srcLength); }
4107 const UnicodeString& srcText,
4109 int32_t srcLimit)
const
4110 {
return doCompareCodePointOrder(start, limit - start,
4111 srcText, srcStart, srcLimit - srcStart); }
4114 UnicodeString::doCaseCompare(int32_t start,
4116 const UnicodeString &srcText,
4119 uint32_t options)
const
4122 return (int8_t)!isBogus();
4124 srcText.pinIndices(srcStart, srcLength);
4125 return doCaseCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength, options);
4131 return doCaseCompare(0,
length(), text, 0, text.
length(), options);
4137 const UnicodeString &srcText,
4138 uint32_t options)
const {
4139 return doCaseCompare(start, _length, srcText, 0, srcText.
length(), options);
4145 uint32_t options)
const {
4146 return doCaseCompare(0,
length(), srcChars, 0, srcLength, options);
4152 const UnicodeString &srcText,
4155 uint32_t options)
const {
4156 return doCaseCompare(start, _length, srcText, srcStart, srcLength, options);
4162 const char16_t *srcChars,
4163 uint32_t options)
const {
4164 return doCaseCompare(start, _length, srcChars, 0, _length, options);
4170 const char16_t *srcChars,
4173 uint32_t options)
const {
4174 return doCaseCompare(start, _length, srcChars, srcStart, srcLength, options);
4180 const UnicodeString &srcText,
4183 uint32_t options)
const {
4184 return doCaseCompare(start, limit - start, srcText, srcStart, srcLimit - srcStart, options);
4192 int32_t _length)
const
4195 srcText.pinIndices(srcStart, srcLength);
4197 return indexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
4205 {
return indexOf(text, 0, text.
length(), 0,
length()); }
4209 int32_t start)
const {
4211 return indexOf(text, 0, text.
length(), start,
length() - start);
4217 int32_t _length)
const
4218 {
return indexOf(text, 0, text.
length(), start, _length); }
4223 int32_t start)
const {
4225 return indexOf(srcChars, 0, srcLength, start,
length() - start);
4232 int32_t _length)
const
4233 {
return indexOf(srcChars, 0, srcLength, start, _length); }
4238 int32_t _length)
const
4239 {
return doIndexOf(c, start, _length); }
4244 int32_t _length)
const
4245 {
return doIndexOf(c, start, _length); }
4249 {
return doIndexOf(c, 0,
length()); }
4253 {
return indexOf(c, 0,
length()); }
4257 int32_t start)
const {
4259 return doIndexOf(c, start,
length() - start);
4264 int32_t start)
const {
4266 return indexOf(c, start,
length() - start);
4273 int32_t _length)
const
4274 {
return lastIndexOf(srcChars, 0, srcLength, start, _length); }
4279 int32_t start)
const {
4281 return lastIndexOf(srcChars, 0, srcLength, start,
length() - start);
4289 int32_t _length)
const
4292 srcText.pinIndices(srcStart, srcLength);
4294 return lastIndexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
4303 int32_t _length)
const
4304 {
return lastIndexOf(text, 0, text.
length(), start, _length); }
4308 int32_t start)
const {
4310 return lastIndexOf(text, 0, text.
length(), start,
length() - start);
4315 {
return lastIndexOf(text, 0, text.
length(), 0,
length()); }
4320 int32_t _length)
const
4321 {
return doLastIndexOf(c, start, _length); }
4326 int32_t _length)
const {
4327 return doLastIndexOf(c, start, _length);
4332 {
return doLastIndexOf(c, 0,
length()); }
4336 return lastIndexOf(c, 0,
length());
4341 int32_t start)
const {
4343 return doLastIndexOf(c, start,
length() - start);
4348 int32_t start)
const {
4350 return lastIndexOf(c, start,
length() - start);
4355 {
return doEqualsSubstring(0, text.
length(), text, 0, text.
length()); }
4360 int32_t srcLength)
const
4361 {
return doEqualsSubstring(0, srcLength, srcText, srcStart, srcLength); }
4368 return doEqualsSubstring(0, srcLength, srcChars, 0, srcLength);
4376 return doEqualsSubstring(0, srcLength, srcChars, srcStart, srcLength);
4382 text, 0, text.
length()); }
4387 int32_t srcLength)
const {
4388 srcText.pinIndices(srcStart, srcLength);
4389 return doEqualsSubstring(
length() - srcLength, srcLength,
4390 srcText, srcStart, srcLength);
4395 int32_t srcLength)
const {
4399 return doEqualsSubstring(
length() - srcLength, srcLength, srcChars, 0, srcLength);
4405 int32_t srcLength)
const {
4409 return doEqualsSubstring(
length() - srcLength, srcLength,
4410 srcChars, srcStart, srcLength);
4416 inline UnicodeString&
4419 const UnicodeString& srcText)
4420 {
return doReplace(start, _length, srcText, 0, srcText.
length()); }
4422 inline UnicodeString&
4425 const UnicodeString& srcText,
4428 {
return doReplace(start, _length, srcText, srcStart, srcLength); }
4430 inline UnicodeString&
4435 {
return doReplace(start, _length, srcChars, 0, srcLength); }
4437 inline UnicodeString&
4440 const char16_t *srcChars,
4443 {
return doReplace(start, _length, srcChars, srcStart, srcLength); }
4445 inline UnicodeString&
4449 {
return doReplace(start, _length, &srcChar, 0, 1); }
4451 inline UnicodeString&
4454 const UnicodeString& srcText)
4455 {
return doReplace(start, limit - start, srcText, 0, srcText.
length()); }
4457 inline UnicodeString&
4460 const UnicodeString& srcText,
4463 {
return doReplace(start, limit - start, srcText, srcStart, srcLimit - srcStart); }
4465 inline UnicodeString&
4467 const UnicodeString& newText)
4468 {
return findAndReplace(0,
length(), oldText, 0, oldText.
length(),
4469 newText, 0, newText.
length()); }
4471 inline UnicodeString&
4474 const UnicodeString& oldText,
4475 const UnicodeString& newText)
4476 {
return findAndReplace(start, _length, oldText, 0, oldText.
length(),
4477 newText, 0, newText.
length()); }
4483 UnicodeString::doExtract(int32_t start,
4485 UnicodeString& target)
const
4486 { target.
replace(0, target.
length(), *
this, start, _length); }
4492 int32_t targetStart)
const
4493 { doExtract(start, _length, target, targetStart); }
4498 UnicodeString& target)
const
4499 { doExtract(start, _length, target); }
4501 #if !UCONFIG_NO_CONVERSION
4507 const char *codepage)
const
4511 return extract(start, _length, dst, dst !=
nullptr ? 0xffffffff : 0, codepage);
4520 int32_t dstStart)
const {
4523 doExtract(start, limit - start, dst, dstStart);
4526 inline UnicodeString
4528 return tempSubString(start, limit - start);
4532 UnicodeString::doCharAt(int32_t offset)
const
4534 if((uint32_t)offset < (uint32_t)
length()) {
4535 return getArrayStart()[offset];
4537 return kInvalidUChar;
4543 {
return doCharAt(offset); }
4547 {
return doCharAt(offset); }
4552 return (fUnion.fFields.fLengthAndFlags>>kLengthShift) == 0;
4559 UnicodeString::setZeroLength() {
4560 fUnion.fFields.fLengthAndFlags &= kAllStorageFlags;
4564 UnicodeString::setShortLength(int32_t len) {
4566 fUnion.fFields.fLengthAndFlags =
4567 (int16_t)((fUnion.fFields.fLengthAndFlags & kAllStorageFlags) | (len << kLengthShift));
4571 UnicodeString::setLength(int32_t len) {
4572 if(len <= kMaxShortLength) {
4573 setShortLength(len);
4575 fUnion.fFields.fLengthAndFlags |= kLengthIsLarge;
4576 fUnion.fFields.fLength = len;
4581 UnicodeString::setToEmpty() {
4582 fUnion.fFields.fLengthAndFlags = kShortString;
4586 UnicodeString::setArray(char16_t *array, int32_t len, int32_t capacity) {
4588 fUnion.fFields.fArray = array;
4589 fUnion.fFields.fCapacity = capacity;
4592 inline UnicodeString&
4594 {
return doReplace(0,
length(), &ch, 0, 1); }
4596 inline UnicodeString&
4598 {
return replace(0,
length(), ch); }
4600 inline UnicodeString&
4606 return doReplace(0,
length(), srcText, srcStart, srcLength);
4609 inline UnicodeString&
4614 srcText.pinIndex(srcStart);
4615 return doReplace(0,
length(), srcText, srcStart, srcText.
length() - srcStart);
4618 inline UnicodeString&
4621 return copyFrom(srcText);
4624 inline UnicodeString&
4629 return doReplace(0,
length(), srcChars, 0, srcLength);
4632 inline UnicodeString&
4636 return doReplace(0,
length(), &srcChar, 0, 1);
4639 inline UnicodeString&
4643 return replace(0,
length(), srcChar);
4646 inline UnicodeString&
4650 {
return doAppend(srcText, srcStart, srcLength); }
4652 inline UnicodeString&
4654 {
return doAppend(srcText, 0, srcText.
length()); }
4656 inline UnicodeString&
4660 {
return doAppend(srcChars, srcStart, srcLength); }
4662 inline UnicodeString&
4665 {
return doAppend(srcChars, 0, srcLength); }
4667 inline UnicodeString&
4669 {
return doAppend(&srcChar, 0, 1); }
4671 inline UnicodeString&
4673 {
return doAppend(&ch, 0, 1); }
4675 inline UnicodeString&
4680 inline UnicodeString&
4682 {
return doAppend(srcText, 0, srcText.
length()); }
4684 inline UnicodeString&
4686 const UnicodeString& srcText,
4689 {
return doReplace(start, 0, srcText, srcStart, srcLength); }
4691 inline UnicodeString&
4693 const UnicodeString& srcText)
4694 {
return doReplace(start, 0, srcText, 0, srcText.
length()); }
4696 inline UnicodeString&
4698 const char16_t *srcChars,
4701 {
return doReplace(start, 0, srcChars, srcStart, srcLength); }
4703 inline UnicodeString&
4707 {
return doReplace(start, 0, srcChars, 0, srcLength); }
4709 inline UnicodeString&
4712 {
return doReplace(start, 0, &srcChar, 0, 1); }
4714 inline UnicodeString&
4717 {
return replace(start, 0, srcChar); }
4720 inline UnicodeString&
4732 inline UnicodeString&
4736 if(start <= 0 && _length ==
INT32_MAX) {
4740 return doReplace(start, _length,
nullptr, 0, 0);
4743 inline UnicodeString&
4746 {
return doReplace(start, limit - start,
nullptr, 0, 0); }
4748 inline UnicodeString &
4751 return doReplace(0, start,
nullptr, 0, 0);
4757 if(isBogus() && targetLength == 0) {
4761 }
else if((uint32_t)targetLength < (uint32_t)
length()) {
4762 setLength(targetLength);
4769 inline UnicodeString&
4771 {
return doReverse(0,
length()); }
4773 inline UnicodeString&
4776 {
return doReverse(start, _length); }
int32_t hashCode() const
Generate a hash code for this object.
#define UNISTR_OBJECT_SIZE
Desired sizeof(UnicodeString) in bytes.
char16_t charAt(int32_t offset) const
Returns the 16-bit code unit at the given offset into the text.
UnicodeString & setTo(const UnicodeString &srcText, int32_t srcStart)
Set the text in the UnicodeString object to the characters in srcText in the range [srcStart...
bool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
An Appendable implementation which writes to a UnicodeString.
EInvariant
Constant to be used in the UnicodeString(char *, int32_t, EInvariant) constructor which constructs a ...
#define U_CAPI
This is used to declare a function as a public ICU C API.
UnicodeString(const uint16_t *text, int32_t textLength)
uint16_t * constructor.
UChar32 char32At(int32_t offset) const
Returns the 32-bit code point at the given 16-bit offset into the text.
int8_t caseCompare(const UnicodeString &text, uint32_t options) const
Compare two strings case-insensitively using full case folding.
UBool operator<=(const UnicodeString &text) const
Less than or equal operator.
virtual UBool hasMetaData() const
Returns true if this object contains metadata.
UnicodeString(wchar_t *buffer, int32_t buffLength, int32_t buffCapacity)
Writable-aliasing wchar_t * constructor.
int32_t lastIndexOf(const UnicodeString &text) const
Locate in this the last occurrence of the characters in text, using bitwise comparison.
virtual void copy(int32_t start, int32_t limit, int32_t dest)=0
Copies a substring of this object, retaining metadata.
UnicodeString & retainBetween(int32_t start, int32_t limit=INT32_MAX)
Retain only the characters in the range [start, limit) from the UnicodeString object.
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
UNISTR_FROM_STRING_EXPLICIT UnicodeString(const uint16_t *text)
uint16_t * constructor.
UNISTR_FROM_STRING_EXPLICIT UnicodeString(const wchar_t *text)
wchar_t * constructor.
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
char16_t operator[](int32_t offset) const
Return the code unit at offset offset.
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.
#define U_SIZEOF_UCHAR
Number of bytes in a UChar (always 2).
virtual void extractBetween(int32_t start, int32_t limit, UnicodeString &target) const =0
Copies characters in the range [start, limit) into the UnicodeString target.
UnicodeString & findAndReplace(const UnicodeString &oldText, const UnicodeString &newText)
Replace all occurrences of characters in oldText with the characters in newText.
A ByteSink can be filled with bytes.
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.
UBool operator>(const UnicodeString &text) const
Greater than operator.
UnicodeString & removeBetween(int32_t start, int32_t limit=(int32_t) INT32_MAX)
Remove the characters in the range [start, limit) from the UnicodeString object.
U_CAPI int32_t u_strlen(const UChar *s)
Determine the length of an array of UChar.
#define UCONFIG_NO_BREAK_ITERATION
This switch turns off break iteration.
UnicodeString tempSubStringBetween(int32_t start, int32_t limit=INT32_MAX) const
Create a temporary substring for the specified range.
Records lengths of string edits but not replacement text.
C++ API: StringPiece: Read-only byte string wrapper class.
Replaceable is an abstract base class representing a string of characters that supports the replaceme...
#define UNISTR_FROM_CHAR_EXPLICIT
This can be defined to be empty or "explicit".
void extractBetween(int32_t start, int32_t limit, char16_t *dst, int32_t dstStart=0) const
Copy the characters in the range [start, limit) into the array dst, beginning at dstStart.
StringClass & toUTF8String(StringClass &result) const
Convert the UnicodeString to UTF-8 and append the result to a standard string.
C++ API: Interface for writing bytes, and implementation classes.
UBool truncate(int32_t targetLength)
Truncate this UnicodeString to the targetLength.
U_COMMON_API UnicodeString operator+(const UnicodeString &s1, const UnicodeString &s2)
Create a new UnicodeString with the concatenation of two others.
UnicodeString()
Construct an empty UnicodeString.
void extract(int32_t start, int32_t length, Char16Ptr dst, int32_t dstStart=0) const
Copy the characters in the range [start, start + length) into the array dst, beginning at dstStart...
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...
The BreakIterator class implements methods for finding the location of boundaries in text...
UnicodeString(const wchar_t *text, int32_t textLength)
wchar_t * constructor.
UnicodeString & remove()
Removes all characters from the UnicodeString object and clears the bogus flag.
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
UnicodeString & replaceBetween(int32_t start, int32_t limit, const UnicodeString &srcText)
Replace the characters in the range [start, limit) with the characters in srcText.
C++ API: Central ICU header for including the C++ standard <string> header and for related definition...
const UChar * toUCharPtr(const char16_t *p)
Converts from const char16_t * to const UChar *.
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...
int32_t getCapacity() const
Return the capacity of the internal buffer of the UnicodeString object.
UBool isBogus() const
Determine if this object contains a valid string.
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...
bool operator==(const UnicodeString &text) const
Equality operator.
const char16_t * getBuffer() const
Get a read-only pointer to the internal buffer.
UBool operator>=(const UnicodeString &text) const
Greater than or equal operator.
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.
char16_t UChar
The base type for UTF-16 code units and pointers.
UnicodeString(uint16_t *buffer, int32_t buffLength, int32_t buffCapacity)
Writable-aliasing uint16_t * constructor.
int8_t compareCodePointOrder(const UnicodeString &text) const
Compare two Unicode strings in code point order.
UBool startsWith(const UnicodeString &text) const
Determine if this starts with the characters in text
char16_t charAt(int32_t offset) const
Return the code unit at offset offset.
struct UConverter UConverter
#define INT32_MAX
The largest value a 32 bit signed integer can hold.
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
UnicodeString & operator=(const UnicodeString &srcText)
Assignment operator.
int32_t indexOf(const UnicodeString &text) const
Locate in this the first occurrence of the characters in text, using bitwise comparison.
int8_t compare(const UnicodeString &text) const
Compare the characters bitwise in this UnicodeString to the characters in text.
char16_t * wrapper with implicit conversion from distinct but bit-compatible pointer types...
const char16_t * wrapper with implicit conversion from distinct but bit-compatible pointer types...
int32_t length() const
Return the length of the UnicodeString object.
virtual void handleReplaceBetween(int32_t start, int32_t limit, const UnicodeString &text)=0
Replaces a substring of this object with the given text.
Basic definitions for ICU, for both C and C++ APIs.
void swap(UnicodeString &other) noexcept
Swap strings.
Implementation of ByteSink that writes to a "string".
UBool operator<(const UnicodeString &text) const
Less than operator.
#define U_COMMON_API
Set to export library symbols from inside the common library, and to import them from outside...
UnicodeString & operator+=(char16_t ch)
Append operator.
int32_t length() const
Returns the number of 16-bit code units in the text.
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
#define UNISTR_FROM_STRING_EXPLICIT
This can be defined to be empty or "explicit".
UBool endsWith(const UnicodeString &text) const
Determine if this ends with the characters in text
UnicodeString & reverse()
Reverse this UnicodeString in place.
A string-like object that points to a sized piece of memory.
bool operator!=(const UnicodeString &text) const
Inequality operator.
UBool isEmpty() const
Determine if this string is empty.
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...
int8_t UBool
The ICU boolean type, a signed-byte integer.
C++ API: char16_t pointer wrappers with implicit conversion from bit-compatible raw pointer types...
A Locale object represents a specific geographical, political, or cultural region.
C++ API: Replaceable String.