51 #if !UCONFIG_NO_BREAK_ITERATION
70 char16_t *dest, int32_t destCapacity,
71 const char16_t *src, int32_t srcLength,
78 class StringCharacterIterator;
79 class UnicodeStringAppendable;
93 #define US_INV icu::UnicodeString::kInvariant
112 #if !U_CHAR16_IS_TYPEDEF
113 # define UNICODE_STRING(cs, _length) icu::UnicodeString(TRUE, u ## cs, _length)
115 # define UNICODE_STRING(cs, _length) icu::UnicodeString(TRUE, (const char16_t*)u ## cs, _length)
131 #define UNICODE_STRING_SIMPLE(cs) UNICODE_STRING(cs, -1)
140 #ifndef UNISTR_FROM_CHAR_EXPLICIT
141 # if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION)
143 # define UNISTR_FROM_CHAR_EXPLICIT explicit
146 # define UNISTR_FROM_CHAR_EXPLICIT
160 #ifndef UNISTR_FROM_STRING_EXPLICIT
161 # if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION)
163 # define UNISTR_FROM_STRING_EXPLICIT explicit
166 # define UNISTR_FROM_STRING_EXPLICIT
203 #ifndef UNISTR_OBJECT_SIZE
204 # define UNISTR_OBJECT_SIZE 64
394 inline int8_t compare(int32_t start,
415 inline int8_t compare(int32_t start,
419 int32_t srcLength)
const;
434 int32_t srcLength)
const;
450 inline int8_t compare(int32_t start,
452 const char16_t *srcChars)
const;
471 inline int8_t compare(int32_t start,
473 const char16_t *srcChars,
475 int32_t srcLength)
const;
494 inline int8_t compareBetween(int32_t start,
498 int32_t srcLimit)
const;
517 inline int8_t compareCodePointOrder(
const UnicodeString& text)
const;
538 inline int8_t compareCodePointOrder(int32_t start,
563 inline int8_t compareCodePointOrder(int32_t start,
567 int32_t srcLength)
const;
588 int32_t srcLength)
const;
609 inline int8_t compareCodePointOrder(int32_t start,
611 const char16_t *srcChars)
const;
634 inline int8_t compareCodePointOrder(int32_t start,
636 const char16_t *srcChars,
638 int32_t srcLength)
const;
661 inline int8_t compareCodePointOrderBetween(int32_t start,
665 int32_t srcLimit)
const;
685 inline int8_t caseCompare(
const UnicodeString& text, uint32_t options)
const;
707 inline int8_t caseCompare(int32_t start,
710 uint32_t options)
const;
734 inline int8_t caseCompare(int32_t start,
739 uint32_t options)
const;
762 uint32_t options)
const;
784 inline int8_t caseCompare(int32_t start,
786 const char16_t *srcChars,
787 uint32_t options)
const;
811 inline int8_t caseCompare(int32_t start,
813 const char16_t *srcChars,
816 uint32_t options)
const;
840 inline int8_t caseCompareBetween(int32_t start,
845 uint32_t options)
const;
868 int32_t srcLength)
const;
879 int32_t srcLength)
const;
890 inline UBool startsWith(
const char16_t *srcChars,
892 int32_t srcLength)
const;
915 int32_t srcLength)
const;
926 int32_t srcLength)
const;
938 inline UBool endsWith(
const char16_t *srcChars,
940 int32_t srcLength)
const;
965 int32_t start)
const;
980 int32_t length)
const;
1002 int32_t length)
const;
1015 inline int32_t indexOf(
const char16_t *srcChars,
1017 int32_t start)
const;
1034 int32_t length)
const;
1052 int32_t indexOf(
const char16_t *srcChars,
1056 int32_t length)
const;
1065 inline int32_t indexOf(char16_t c)
const;
1075 inline int32_t indexOf(
UChar32 c)
const;
1085 inline int32_t indexOf(char16_t c,
1086 int32_t start)
const;
1097 inline int32_t indexOf(
UChar32 c,
1098 int32_t start)
const;
1110 inline int32_t indexOf(char16_t c,
1112 int32_t length)
const;
1125 inline int32_t indexOf(
UChar32 c,
1127 int32_t length)
const;
1137 inline int32_t lastIndexOf(
const UnicodeString& text)
const;
1149 int32_t start)
const;
1164 int32_t length)
const;
1186 int32_t length)
const;
1198 inline int32_t lastIndexOf(
const char16_t *srcChars,
1200 int32_t start)
const;
1217 int32_t length)
const;
1235 int32_t lastIndexOf(
const char16_t *srcChars,
1239 int32_t length)
const;
1248 inline int32_t lastIndexOf(char16_t c)
const;
1258 inline int32_t lastIndexOf(
UChar32 c)
const;
1268 inline int32_t lastIndexOf(char16_t c,
1269 int32_t start)
const;
1280 inline int32_t lastIndexOf(
UChar32 c,
1281 int32_t start)
const;
1293 inline int32_t lastIndexOf(char16_t c,
1295 int32_t length)
const;
1308 inline int32_t lastIndexOf(
UChar32 c,
1310 int32_t length)
const;
1323 inline char16_t
charAt(int32_t offset)
const;
1332 inline char16_t operator[] (int32_t offset)
const;
1362 int32_t getChar32Start(int32_t offset)
const;
1380 int32_t getChar32Limit(int32_t offset)
const;
1432 int32_t moveIndex32(int32_t index, int32_t delta)
const;
1451 inline void extract(int32_t start,
1454 int32_t dstStart = 0)
const;
1478 extract(
Char16Ptr dest, int32_t destCapacity,
1491 inline void extract(int32_t start,
1509 int32_t dstStart = 0)
const;
1545 int32_t extract(int32_t start,
1546 int32_t startLength,
1548 int32_t targetCapacity,
1549 enum EInvariant inv)
const;
1551 #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
1572 int32_t extract(int32_t start,
1573 int32_t startLength,
1575 uint32_t targetLength)
const;
1579 #if !UCONFIG_NO_CONVERSION
1606 inline int32_t extract(int32_t start,
1607 int32_t startLength,
1609 const char *codepage = 0)
const;
1640 int32_t extract(int32_t start,
1641 int32_t startLength,
1643 uint32_t targetLength,
1644 const char *codepage)
const;
1663 int32_t extract(
char *dest, int32_t destCapacity,
1721 template<
typename StringClass>
1755 inline int32_t
length(
void)
const;
1771 countChar32(int32_t start=0, int32_t length=
INT32_MAX)
const;
1797 hasMoreChar32Than(int32_t start, int32_t length, int32_t number)
const;
1804 inline UBool isEmpty(
void)
const;
1815 inline int32_t getCapacity(
void)
const;
1824 inline int32_t hashCode(
void)
const;
1838 inline UBool isBogus(
void)
const;
1903 return moveFrom(src);
2052 int32_t textLength);
2075 int32_t buffCapacity);
2277 const char16_t *srcChars,
2377 const char16_t *srcChars,
2495 virtual void copy(int32_t start, int32_t limit, int32_t dest);
2608 UBool padLeading(int32_t targetLength,
2609 char16_t padChar = 0x0020);
2622 UBool padTrailing(int32_t targetLength,
2623 char16_t padChar = 0x0020);
2631 inline UBool truncate(int32_t targetLength);
2695 #if !UCONFIG_NO_BREAK_ITERATION
2851 char16_t *getBuffer(int32_t minCapacity);
2873 void releaseBuffer(int32_t newLength=-1);
2905 inline const char16_t *getBuffer()
const;
2940 const char16_t *getTerminatedBuffer();
3002 #if !U_CHAR16_IS_TYPEDEF
3021 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
3061 int32_t textLength);
3067 #if !U_CHAR16_IS_TYPEDEF
3083 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
3107 inline UnicodeString(
const std::nullptr_t text, int32_t length);
3133 int32_t textLength);
3153 UnicodeString(char16_t *buffer, int32_t buffLength, int32_t buffCapacity);
3159 #if !U_CHAR16_IS_TYPEDEF
3176 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
3202 inline UnicodeString(std::nullptr_t buffer, int32_t buffLength, int32_t buffCapacity);
3204 #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
3235 UnicodeString(
const char *codepageData, int32_t dataLength);
3239 #if !UCONFIG_NO_CONVERSION
3258 UnicodeString(
const char *codepageData,
const char *codepage);
3277 UnicodeString(
const char *codepageData, int32_t dataLength,
const char *codepage);
3301 const char *src, int32_t srcLength,
3331 UnicodeString(
const char *src, int32_t length,
enum EInvariant inv);
3426 static UnicodeString fromUTF32(const
UChar32 *utf32, int32_t length);
3464 UnicodeString unescape() const;
3485 UChar32 unescapeAt(int32_t &offset) const;
3492 static
UClassID U_EXPORT2 getStaticClassID();
3499 virtual
UClassID getDynamicClassID() const;
3510 virtual int32_t getLength() const;
3517 virtual char16_t getCharAt(int32_t offset) const;
3524 virtual
UChar32 getChar32At(int32_t offset) const;
3535 toUTF8(int32_t start, int32_t len,
3536 char *target, int32_t capacity) const;
3542 UBool doEquals(const UnicodeString &text, int32_t len) const;
3545 doCompare(int32_t start,
3547 const UnicodeString& srcText,
3549 int32_t srcLength) const;
3551 int8_t doCompare(int32_t start,
3553 const char16_t *srcChars,
3555 int32_t srcLength) const;
3558 doCompareCodePointOrder(int32_t start,
3560 const UnicodeString& srcText,
3562 int32_t srcLength) const;
3564 int8_t doCompareCodePointOrder(int32_t start,
3566 const char16_t *srcChars,
3568 int32_t srcLength) const;
3571 doCaseCompare(int32_t start,
3573 const UnicodeString &srcText,
3576 uint32_t options) const;
3579 doCaseCompare(int32_t start,
3581 const char16_t *srcChars,
3584 uint32_t options) const;
3586 int32_t doIndexOf(char16_t c,
3588 int32_t length) const;
3592 int32_t length) const;
3594 int32_t doLastIndexOf(char16_t c,
3596 int32_t length) const;
3598 int32_t doLastIndexOf(
UChar32 c,
3600 int32_t length) const;
3602 void doExtract(int32_t start,
3605 int32_t dstStart) const;
3607 inline
void doExtract(int32_t start,
3609 UnicodeString& target) const;
3611 inline char16_t doCharAt(int32_t offset) const;
3613 UnicodeString& doReplace(int32_t start,
3615 const UnicodeString& srcText,
3619 UnicodeString& doReplace(int32_t start,
3621 const char16_t *srcChars,
3625 UnicodeString& doAppend(const UnicodeString& src, int32_t srcStart, int32_t srcLength);
3626 UnicodeString& doAppend(const char16_t *srcChars, int32_t srcStart, int32_t srcLength);
3628 UnicodeString& doReverse(int32_t start,
3632 int32_t doHashCode(
void) const;
3636 inline char16_t* getArrayStart(
void);
3637 inline const char16_t* getArrayStart(
void) const;
3639 inline
UBool hasShortLength() const;
3640 inline int32_t getShortLength() const;
3644 inline
UBool isWritable() const;
3647 inline
UBool isBufferWritable() const;
3650 inline
void setZeroLength();
3651 inline
void setShortLength(int32_t len);
3652 inline
void setLength(int32_t len);
3653 inline
void setToEmpty();
3654 inline
void setArray(char16_t *array, int32_t len, int32_t capacity);
3661 UBool allocate(int32_t capacity);
3664 void releaseArray(
void);
3670 UnicodeString ©From(const UnicodeString &src,
UBool fastCopy=
FALSE);
3673 void copyFieldsFrom(UnicodeString &src,
UBool setSrcToBogus) U_NOEXCEPT;
3676 inline
void pinIndex(int32_t& start) const;
3677 inline
void pinIndices(int32_t& start,
3678 int32_t& length) const;
3680 #if !UCONFIG_NO_CONVERSION
3683 int32_t doExtract(int32_t start, int32_t length,
3684 char *dest, int32_t destCapacity,
3698 void doCodepageCreate(
const char *codepageData,
3700 const char *codepage);
3707 doCodepageCreate(
const char *codepageData,
3725 UBool cloneArrayIfNeeded(int32_t newCapacity = -1,
3726 int32_t growCapacity = -1,
3728 int32_t **pBufferToDelete = 0,
3729 UBool forceClone = FALSE);
3737 caseMap(int32_t caseLocale, uint32_t options,
3745 int32_t removeRef(
void);
3746 int32_t refCount(
void)
const;
3756 kInvalidUChar=0xffff,
3762 kUsingStackBuffer=2,
3764 kBufferIsReadonly=8,
3767 kAllStorageFlags=0x1f,
3770 kLength1=1<<kLengthShift,
3771 kMaxShortLength=0x3ff,
3772 kLengthIsLarge=0xffe0,
3775 kShortString=kUsingStackBuffer,
3776 kLongString=kRefCounted,
3777 kReadonlyAlias=kBufferIsReadonly,
3783 union StackBufferOrFields;
3784 friend union StackBufferOrFields;
3827 union StackBufferOrFields {
3831 int16_t fLengthAndFlags;
3832 char16_t fBuffer[US_STACKBUF_SIZE];
3835 int16_t fLengthAndFlags;
3854 operator+ (
const UnicodeString &s1,
const UnicodeString &s2);
3865 UnicodeString::pinIndex(int32_t& start)
const
3870 }
else if(start >
length()) {
3876 UnicodeString::pinIndices(int32_t& start,
3877 int32_t& _length)
const
3883 }
else if(start > len) {
3888 }
else if(_length > (len - start)) {
3889 _length = (len - start);
3894 UnicodeString::getArrayStart() {
3895 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3896 fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
3899 inline const char16_t*
3900 UnicodeString::getArrayStart()
const {
3901 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3902 fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
3911 fUnion.fStackFields.fLengthAndFlags=kShortString;
3915 fUnion.fStackFields.fLengthAndFlags=kShortString;
3919 fUnion.fStackFields.fLengthAndFlags=kShortString;
3923 fUnion.fStackFields.fLengthAndFlags=kShortString;
3930 UnicodeString::hasShortLength()
const {
3931 return fUnion.fFields.fLengthAndFlags>=0;
3935 UnicodeString::getShortLength()
const {
3938 return fUnion.fFields.fLengthAndFlags>>kLengthShift;
3943 return hasShortLength() ? getShortLength() : fUnion.fFields.fLength;
3948 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3949 US_STACKBUF_SIZE : fUnion.fFields.fCapacity;
3954 {
return doHashCode(); }
3958 {
return (
UBool)(fUnion.fFields.fLengthAndFlags & kIsBogus); }
3961 UnicodeString::isWritable()
const
3962 {
return (
UBool)!(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus)); }
3965 UnicodeString::isBufferWritable()
const
3968 !(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus|kBufferIsReadonly)) &&
3969 (!(fUnion.fFields.fLengthAndFlags&kRefCounted) || refCount()==1));
3972 inline const char16_t *
3974 if(fUnion.fFields.fLengthAndFlags&(kIsBogus|kOpenGetBuffer)) {
3976 }
else if(fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) {
3977 return fUnion.fStackFields.fBuffer;
3979 return fUnion.fFields.fArray;
3987 UnicodeString::doCompare(int32_t start,
3989 const UnicodeString& srcText,
3991 int32_t srcLength)
const
3994 return (int8_t)!isBogus();
3996 srcText.pinIndices(srcStart, srcLength);
3997 return doCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
4008 return !text.
isBogus() && len == textLength && doEquals(text, len);
4014 {
return (!
operator==(text)); }
4018 {
return doCompare(0,
length(), text, 0, text.
length()) == 1; }
4022 {
return doCompare(0,
length(), text, 0, text.
length()) == -1; }
4026 {
return doCompare(0,
length(), text, 0, text.
length()) != -1; }
4030 {
return doCompare(0,
length(), text, 0, text.
length()) != 1; }
4034 {
return doCompare(0,
length(), text, 0, text.
length()); }
4039 const UnicodeString& srcText)
const
4040 {
return doCompare(start, _length, srcText, 0, srcText.
length()); }
4044 int32_t srcLength)
const
4045 {
return doCompare(0,
length(), srcChars, 0, srcLength); }
4050 const UnicodeString& srcText,
4052 int32_t srcLength)
const
4053 {
return doCompare(start, _length, srcText, srcStart, srcLength); }
4058 const char16_t *srcChars)
const
4059 {
return doCompare(start, _length, srcChars, 0, _length); }
4064 const char16_t *srcChars,
4066 int32_t srcLength)
const
4067 {
return doCompare(start, _length, srcChars, srcStart, srcLength); }
4072 const UnicodeString& srcText,
4074 int32_t srcLimit)
const
4075 {
return doCompare(start, limit - start,
4076 srcText, srcStart, srcLimit - srcStart); }
4079 UnicodeString::doCompareCodePointOrder(int32_t start,
4081 const UnicodeString& srcText,
4083 int32_t srcLength)
const
4086 return (int8_t)!isBogus();
4088 srcText.pinIndices(srcStart, srcLength);
4089 return doCompareCodePointOrder(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
4095 {
return doCompareCodePointOrder(0,
length(), text, 0, text.
length()); }
4100 const UnicodeString& srcText)
const
4101 {
return doCompareCodePointOrder(start, _length, srcText, 0, srcText.
length()); }
4105 int32_t srcLength)
const
4106 {
return doCompareCodePointOrder(0,
length(), srcChars, 0, srcLength); }
4111 const UnicodeString& srcText,
4113 int32_t srcLength)
const
4114 {
return doCompareCodePointOrder(start, _length, srcText, srcStart, srcLength); }
4119 const char16_t *srcChars)
const
4120 {
return doCompareCodePointOrder(start, _length, srcChars, 0, _length); }
4125 const char16_t *srcChars,
4127 int32_t srcLength)
const
4128 {
return doCompareCodePointOrder(start, _length, srcChars, srcStart, srcLength); }
4133 const UnicodeString& srcText,
4135 int32_t srcLimit)
const
4136 {
return doCompareCodePointOrder(start, limit - start,
4137 srcText, srcStart, srcLimit - srcStart); }
4140 UnicodeString::doCaseCompare(int32_t start,
4142 const UnicodeString &srcText,
4145 uint32_t options)
const
4148 return (int8_t)!isBogus();
4150 srcText.pinIndices(srcStart, srcLength);
4151 return doCaseCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength, options);
4157 return doCaseCompare(0,
length(), text, 0, text.
length(), options);
4163 const UnicodeString &srcText,
4164 uint32_t options)
const {
4165 return doCaseCompare(start, _length, srcText, 0, srcText.
length(), options);
4171 uint32_t options)
const {
4172 return doCaseCompare(0,
length(), srcChars, 0, srcLength, options);
4178 const UnicodeString &srcText,
4181 uint32_t options)
const {
4182 return doCaseCompare(start, _length, srcText, srcStart, srcLength, options);
4188 const char16_t *srcChars,
4189 uint32_t options)
const {
4190 return doCaseCompare(start, _length, srcChars, 0, _length, options);
4196 const char16_t *srcChars,
4199 uint32_t options)
const {
4200 return doCaseCompare(start, _length, srcChars, srcStart, srcLength, options);
4206 const UnicodeString &srcText,
4209 uint32_t options)
const {
4210 return doCaseCompare(start, limit - start, srcText, srcStart, srcLimit - srcStart, options);
4218 int32_t _length)
const
4221 srcText.pinIndices(srcStart, srcLength);
4223 return indexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
4231 {
return indexOf(text, 0, text.
length(), 0,
length()); }
4235 int32_t start)
const {
4237 return indexOf(text, 0, text.
length(), start,
length() - start);
4243 int32_t _length)
const
4244 {
return indexOf(text, 0, text.
length(), start, _length); }
4249 int32_t start)
const {
4251 return indexOf(srcChars, 0, srcLength, start,
length() - start);
4258 int32_t _length)
const
4259 {
return indexOf(srcChars, 0, srcLength, start, _length); }
4264 int32_t _length)
const
4265 {
return doIndexOf(c, start, _length); }
4270 int32_t _length)
const
4271 {
return doIndexOf(c, start, _length); }
4275 {
return doIndexOf(c, 0,
length()); }
4279 {
return indexOf(c, 0,
length()); }
4283 int32_t start)
const {
4285 return doIndexOf(c, start,
length() - start);
4290 int32_t start)
const {
4292 return indexOf(c, start,
length() - start);
4299 int32_t _length)
const
4300 {
return lastIndexOf(srcChars, 0, srcLength, start, _length); }
4305 int32_t start)
const {
4307 return lastIndexOf(srcChars, 0, srcLength, start,
length() - start);
4315 int32_t _length)
const
4318 srcText.pinIndices(srcStart, srcLength);
4320 return lastIndexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
4329 int32_t _length)
const
4330 {
return lastIndexOf(text, 0, text.
length(), start, _length); }
4334 int32_t start)
const {
4336 return lastIndexOf(text, 0, text.
length(), start,
length() - start);
4341 {
return lastIndexOf(text, 0, text.
length(), 0,
length()); }
4346 int32_t _length)
const
4347 {
return doLastIndexOf(c, start, _length); }
4352 int32_t _length)
const {
4353 return doLastIndexOf(c, start, _length);
4358 {
return doLastIndexOf(c, 0,
length()); }
4362 return lastIndexOf(c, 0,
length());
4367 int32_t start)
const {
4369 return doLastIndexOf(c, start,
length() - start);
4374 int32_t start)
const {
4376 return lastIndexOf(c, start,
length() - start);
4381 {
return compare(0, text.
length(), text, 0, text.
length()) == 0; }
4386 int32_t srcLength)
const
4387 {
return doCompare(0, srcLength, srcText, srcStart, srcLength) == 0; }
4394 return doCompare(0, srcLength, srcChars, 0, srcLength) == 0;
4402 return doCompare(0, srcLength, srcChars, srcStart, srcLength) == 0;
4408 text, 0, text.
length()) == 0; }
4413 int32_t srcLength)
const {
4414 srcText.pinIndices(srcStart, srcLength);
4415 return doCompare(
length() - srcLength, srcLength,
4416 srcText, srcStart, srcLength) == 0;
4421 int32_t srcLength)
const {
4425 return doCompare(
length() - srcLength, srcLength,
4426 srcChars, 0, srcLength) == 0;
4432 int32_t srcLength)
const {
4436 return doCompare(
length() - srcLength, srcLength,
4437 srcChars, srcStart, srcLength) == 0;
4443 inline UnicodeString&
4446 const UnicodeString& srcText)
4447 {
return doReplace(start, _length, srcText, 0, srcText.
length()); }
4449 inline UnicodeString&
4452 const UnicodeString& srcText,
4455 {
return doReplace(start, _length, srcText, srcStart, srcLength); }
4457 inline UnicodeString&
4462 {
return doReplace(start, _length, srcChars, 0, srcLength); }
4464 inline UnicodeString&
4467 const char16_t *srcChars,
4470 {
return doReplace(start, _length, srcChars, srcStart, srcLength); }
4472 inline UnicodeString&
4476 {
return doReplace(start, _length, &srcChar, 0, 1); }
4478 inline UnicodeString&
4481 const UnicodeString& srcText)
4482 {
return doReplace(start, limit - start, srcText, 0, srcText.
length()); }
4484 inline UnicodeString&
4487 const UnicodeString& srcText,
4490 {
return doReplace(start, limit - start, srcText, srcStart, srcLimit - srcStart); }
4492 inline UnicodeString&
4494 const UnicodeString& newText)
4495 {
return findAndReplace(0,
length(), oldText, 0, oldText.
length(),
4496 newText, 0, newText.
length()); }
4498 inline UnicodeString&
4501 const UnicodeString& oldText,
4502 const UnicodeString& newText)
4503 {
return findAndReplace(start, _length, oldText, 0, oldText.
length(),
4504 newText, 0, newText.
length()); }
4510 UnicodeString::doExtract(int32_t start,
4512 UnicodeString& target)
const
4513 { target.
replace(0, target.
length(), *
this, start, _length); }
4519 int32_t targetStart)
const
4520 { doExtract(start, _length, target, targetStart); }
4525 UnicodeString& target)
const
4526 { doExtract(start, _length, target); }
4528 #if !UCONFIG_NO_CONVERSION
4534 const char *codepage)
const
4538 return extract(start, _length, dst, dst!=0 ? 0xffffffff : 0, codepage);
4547 int32_t dstStart)
const {
4550 doExtract(start, limit - start, dst, dstStart);
4553 inline UnicodeString
4555 return tempSubString(start, limit - start);
4559 UnicodeString::doCharAt(int32_t offset)
const
4561 if((uint32_t)offset < (uint32_t)
length()) {
4562 return getArrayStart()[offset];
4564 return kInvalidUChar;
4570 {
return doCharAt(offset); }
4574 {
return doCharAt(offset); }
4579 return (fUnion.fFields.fLengthAndFlags>>kLengthShift) == 0;
4586 UnicodeString::setZeroLength() {
4587 fUnion.fFields.fLengthAndFlags &= kAllStorageFlags;
4591 UnicodeString::setShortLength(int32_t len) {
4593 fUnion.fFields.fLengthAndFlags =
4594 (int16_t)((fUnion.fFields.fLengthAndFlags & kAllStorageFlags) | (len << kLengthShift));
4598 UnicodeString::setLength(int32_t len) {
4599 if(len <= kMaxShortLength) {
4600 setShortLength(len);
4602 fUnion.fFields.fLengthAndFlags |= kLengthIsLarge;
4603 fUnion.fFields.fLength = len;
4608 UnicodeString::setToEmpty() {
4609 fUnion.fFields.fLengthAndFlags = kShortString;
4613 UnicodeString::setArray(char16_t *array, int32_t len, int32_t capacity) {
4615 fUnion.fFields.fArray = array;
4616 fUnion.fFields.fCapacity = capacity;
4619 inline UnicodeString&
4621 {
return doReplace(0,
length(), &ch, 0, 1); }
4623 inline UnicodeString&
4625 {
return replace(0,
length(), ch); }
4627 inline UnicodeString&
4633 return doReplace(0,
length(), srcText, srcStart, srcLength);
4636 inline UnicodeString&
4641 srcText.pinIndex(srcStart);
4642 return doReplace(0,
length(), srcText, srcStart, srcText.
length() - srcStart);
4645 inline UnicodeString&
4648 return copyFrom(srcText);
4651 inline UnicodeString&
4656 return doReplace(0,
length(), srcChars, 0, srcLength);
4659 inline UnicodeString&
4663 return doReplace(0,
length(), &srcChar, 0, 1);
4666 inline UnicodeString&
4670 return replace(0,
length(), srcChar);
4673 inline UnicodeString&
4677 {
return doAppend(srcText, srcStart, srcLength); }
4679 inline UnicodeString&
4681 {
return doAppend(srcText, 0, srcText.
length()); }
4683 inline UnicodeString&
4687 {
return doAppend(srcChars, srcStart, srcLength); }
4689 inline UnicodeString&
4692 {
return doAppend(srcChars, 0, srcLength); }
4694 inline UnicodeString&
4696 {
return doAppend(&srcChar, 0, 1); }
4698 inline UnicodeString&
4700 {
return doAppend(&ch, 0, 1); }
4702 inline UnicodeString&
4707 inline UnicodeString&
4709 {
return doAppend(srcText, 0, srcText.
length()); }
4711 inline UnicodeString&
4713 const UnicodeString& srcText,
4716 {
return doReplace(start, 0, srcText, srcStart, srcLength); }
4718 inline UnicodeString&
4720 const UnicodeString& srcText)
4721 {
return doReplace(start, 0, srcText, 0, srcText.
length()); }
4723 inline UnicodeString&
4725 const char16_t *srcChars,
4728 {
return doReplace(start, 0, srcChars, srcStart, srcLength); }
4730 inline UnicodeString&
4734 {
return doReplace(start, 0, srcChars, 0, srcLength); }
4736 inline UnicodeString&
4739 {
return doReplace(start, 0, &srcChar, 0, 1); }
4741 inline UnicodeString&
4744 {
return replace(start, 0, srcChar); }
4747 inline UnicodeString&
4759 inline UnicodeString&
4763 if(start <= 0 && _length ==
INT32_MAX) {
4767 return doReplace(start, _length,
NULL, 0, 0);
4770 inline UnicodeString&
4773 {
return doReplace(start, limit - start,
NULL, 0, 0); }
4775 inline UnicodeString &
4778 return doReplace(0, start,
NULL, 0, 0);
4784 if(isBogus() && targetLength == 0) {
4788 }
else if((uint32_t)targetLength < (uint32_t)
length()) {
4789 setLength(targetLength);
4796 inline UnicodeString&
4798 {
return doReverse(0,
length()); }
4800 inline UnicodeString&
4803 {
return doReverse(start, _length); }
UnicodeString & reverse(void)
Reverse this UnicodeString in place.
#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...
An Appendable implementation which writes to a UnicodeString.
EInvariant
Constant to be used in the UnicodeString(char *, int32_t, EInvariant) constructor which constructs a ...
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.
UBool isBogus(void) const
Determine if this object contains a valid string.
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.
UnicodeString(const wchar_t *text, int32_t length)
wchar_t * constructor.
#define U_SIZEOF_UCHAR
Number of bytes in a UChar.
UnicodeString(const uint16_t *text, int32_t length)
uint16_t * constructor.
UBool operator==(const UnicodeString &text) const
Equality operator.
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.
friend U_COMMON_API void swap(UnicodeString &s1, UnicodeString &s2)
Non-member UnicodeString swap function.
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
Inequality operator.
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.
#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".
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
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 & remove(void)
Remove all characters from the UnicodeString object.
UnicodeString()
Construct an empty UnicodeString.
int32_t getCapacity(void) const
Return the capacity of the internal buffer of the UnicodeString object.
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...
UBool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
#define NULL
Define NULL if necessary, to nullptr for C++ and to ((void *)0) for C.
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...
UBool isEmpty(void) const
Determine if this string is empty.
#define TRUE
The TRUE value of a UBool.
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...
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.
uint16_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.
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
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
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
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...
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.
UnicodeString & operator=(UnicodeString &&src)
Move assignment operator, might leave src in bogus state.
Implementation of ByteSink that writes to a "string".
UBool operator<(const UnicodeString &text) const
Less than operator.
int32_t hashCode(void) const
Generate a hash code for this object.
int32_t u_strlen(const UChar *s)
Determine the length of an array of UChar.
#define FALSE
The FALSE value of a UBool.
#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
A string-like object that points to a sized piece of memory.
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...
int32_t length(void) const
Return the length of the UnicodeString object.
#define U_STABLE
This is used to declare a function as a stable public ICU C API.
int8_t UBool
The ICU boolean type.
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.