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();
2998 #if !U_CHAR16_IS_TYPEDEF
3013 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
3049 int32_t textLength);
3051 #if !U_CHAR16_IS_TYPEDEF
3063 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
3083 inline UnicodeString(
const std::nullptr_t text, int32_t length);
3109 int32_t textLength);
3129 UnicodeString(char16_t *buffer, int32_t buffLength, int32_t buffCapacity);
3131 #if !U_CHAR16_IS_TYPEDEF
3144 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
3166 inline UnicodeString(std::nullptr_t buffer, int32_t buffLength, int32_t buffCapacity);
3168 #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
3199 UnicodeString(
const char *codepageData, int32_t dataLength);
3203 #if !UCONFIG_NO_CONVERSION
3222 UnicodeString(
const char *codepageData,
const char *codepage);
3241 UnicodeString(
const char *codepageData, int32_t dataLength,
const char *codepage);
3265 const char *src, int32_t srcLength,
3295 UnicodeString(
const char *src, int32_t length,
enum EInvariant inv);
3390 static UnicodeString fromUTF32(const
UChar32 *utf32, int32_t length);
3428 UnicodeString unescape() const;
3449 UChar32 unescapeAt(int32_t &offset) const;
3456 static
UClassID U_EXPORT2 getStaticClassID();
3463 virtual
UClassID getDynamicClassID() const;
3474 virtual int32_t getLength() const;
3481 virtual char16_t getCharAt(int32_t offset) const;
3488 virtual
UChar32 getChar32At(int32_t offset) const;
3499 toUTF8(int32_t start, int32_t len,
3500 char *target, int32_t capacity) const;
3506 UBool doEquals(const UnicodeString &text, int32_t len) const;
3509 doCompare(int32_t start,
3511 const UnicodeString& srcText,
3513 int32_t srcLength) const;
3515 int8_t doCompare(int32_t start,
3517 const char16_t *srcChars,
3519 int32_t srcLength) const;
3522 doCompareCodePointOrder(int32_t start,
3524 const UnicodeString& srcText,
3526 int32_t srcLength) const;
3528 int8_t doCompareCodePointOrder(int32_t start,
3530 const char16_t *srcChars,
3532 int32_t srcLength) const;
3535 doCaseCompare(int32_t start,
3537 const UnicodeString &srcText,
3540 uint32_t options) const;
3543 doCaseCompare(int32_t start,
3545 const char16_t *srcChars,
3548 uint32_t options) const;
3550 int32_t doIndexOf(char16_t c,
3552 int32_t length) const;
3556 int32_t length) const;
3558 int32_t doLastIndexOf(char16_t c,
3560 int32_t length) const;
3562 int32_t doLastIndexOf(
UChar32 c,
3564 int32_t length) const;
3566 void doExtract(int32_t start,
3569 int32_t dstStart) const;
3571 inline
void doExtract(int32_t start,
3573 UnicodeString& target) const;
3575 inline char16_t doCharAt(int32_t offset) const;
3577 UnicodeString& doReplace(int32_t start,
3579 const UnicodeString& srcText,
3583 UnicodeString& doReplace(int32_t start,
3585 const char16_t *srcChars,
3589 UnicodeString& doAppend(const UnicodeString& src, int32_t srcStart, int32_t srcLength);
3590 UnicodeString& doAppend(const char16_t *srcChars, int32_t srcStart, int32_t srcLength);
3592 UnicodeString& doReverse(int32_t start,
3596 int32_t doHashCode(
void) const;
3600 inline char16_t* getArrayStart(
void);
3601 inline const char16_t* getArrayStart(
void) const;
3603 inline
UBool hasShortLength() const;
3604 inline int32_t getShortLength() const;
3608 inline
UBool isWritable() const;
3611 inline
UBool isBufferWritable() const;
3614 inline
void setZeroLength();
3615 inline
void setShortLength(int32_t len);
3616 inline
void setLength(int32_t len);
3617 inline
void setToEmpty();
3618 inline
void setArray(char16_t *array, int32_t len, int32_t capacity);
3625 UBool allocate(int32_t capacity);
3628 void releaseArray(
void);
3634 UnicodeString ©From(const UnicodeString &src,
UBool fastCopy=
FALSE);
3637 void copyFieldsFrom(UnicodeString &src,
UBool setSrcToBogus) U_NOEXCEPT;
3640 inline
void pinIndex(int32_t& start) const;
3641 inline
void pinIndices(int32_t& start,
3642 int32_t& length) const;
3644 #if !UCONFIG_NO_CONVERSION
3647 int32_t doExtract(int32_t start, int32_t length,
3648 char *dest, int32_t destCapacity,
3662 void doCodepageCreate(
const char *codepageData,
3664 const char *codepage);
3671 doCodepageCreate(
const char *codepageData,
3689 UBool cloneArrayIfNeeded(int32_t newCapacity = -1,
3690 int32_t growCapacity = -1,
3692 int32_t **pBufferToDelete = 0,
3693 UBool forceClone = FALSE);
3701 caseMap(int32_t caseLocale, uint32_t options,
3709 int32_t removeRef(
void);
3710 int32_t refCount(
void)
const;
3720 kInvalidUChar=0xffff,
3726 kUsingStackBuffer=2,
3728 kBufferIsReadonly=8,
3731 kAllStorageFlags=0x1f,
3734 kLength1=1<<kLengthShift,
3735 kMaxShortLength=0x3ff,
3736 kLengthIsLarge=0xffe0,
3739 kShortString=kUsingStackBuffer,
3740 kLongString=kRefCounted,
3741 kReadonlyAlias=kBufferIsReadonly,
3747 union StackBufferOrFields;
3748 friend union StackBufferOrFields;
3791 union StackBufferOrFields {
3795 int16_t fLengthAndFlags;
3796 char16_t fBuffer[US_STACKBUF_SIZE];
3799 int16_t fLengthAndFlags;
3818 operator+ (
const UnicodeString &s1,
const UnicodeString &s2);
3829 UnicodeString::pinIndex(int32_t& start)
const
3834 }
else if(start >
length()) {
3840 UnicodeString::pinIndices(int32_t& start,
3841 int32_t& _length)
const
3847 }
else if(start > len) {
3852 }
else if(_length > (len - start)) {
3853 _length = (len - start);
3858 UnicodeString::getArrayStart() {
3859 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3860 fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
3863 inline const char16_t*
3864 UnicodeString::getArrayStart()
const {
3865 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3866 fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
3875 fUnion.fStackFields.fLengthAndFlags=kShortString;
3879 fUnion.fStackFields.fLengthAndFlags=kShortString;
3883 fUnion.fStackFields.fLengthAndFlags=kShortString;
3887 fUnion.fStackFields.fLengthAndFlags=kShortString;
3894 UnicodeString::hasShortLength()
const {
3895 return fUnion.fFields.fLengthAndFlags>=0;
3899 UnicodeString::getShortLength()
const {
3902 return fUnion.fFields.fLengthAndFlags>>kLengthShift;
3907 return hasShortLength() ? getShortLength() : fUnion.fFields.fLength;
3912 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3913 US_STACKBUF_SIZE : fUnion.fFields.fCapacity;
3918 {
return doHashCode(); }
3922 {
return (
UBool)(fUnion.fFields.fLengthAndFlags & kIsBogus); }
3925 UnicodeString::isWritable()
const
3926 {
return (
UBool)!(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus)); }
3929 UnicodeString::isBufferWritable()
const
3932 !(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus|kBufferIsReadonly)) &&
3933 (!(fUnion.fFields.fLengthAndFlags&kRefCounted) || refCount()==1));
3936 inline const char16_t *
3938 if(fUnion.fFields.fLengthAndFlags&(kIsBogus|kOpenGetBuffer)) {
3940 }
else if(fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) {
3941 return fUnion.fStackFields.fBuffer;
3943 return fUnion.fFields.fArray;
3951 UnicodeString::doCompare(int32_t start,
3953 const UnicodeString& srcText,
3955 int32_t srcLength)
const
3958 return (int8_t)!isBogus();
3960 srcText.pinIndices(srcStart, srcLength);
3961 return doCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
3972 return !text.
isBogus() && len == textLength && doEquals(text, len);
3978 {
return (!
operator==(text)); }
3982 {
return doCompare(0,
length(), text, 0, text.
length()) == 1; }
3986 {
return doCompare(0,
length(), text, 0, text.
length()) == -1; }
3990 {
return doCompare(0,
length(), text, 0, text.
length()) != -1; }
3994 {
return doCompare(0,
length(), text, 0, text.
length()) != 1; }
3998 {
return doCompare(0,
length(), text, 0, text.
length()); }
4003 const UnicodeString& srcText)
const
4004 {
return doCompare(start, _length, srcText, 0, srcText.
length()); }
4008 int32_t srcLength)
const
4009 {
return doCompare(0,
length(), srcChars, 0, srcLength); }
4014 const UnicodeString& srcText,
4016 int32_t srcLength)
const
4017 {
return doCompare(start, _length, srcText, srcStart, srcLength); }
4022 const char16_t *srcChars)
const
4023 {
return doCompare(start, _length, srcChars, 0, _length); }
4028 const char16_t *srcChars,
4030 int32_t srcLength)
const
4031 {
return doCompare(start, _length, srcChars, srcStart, srcLength); }
4036 const UnicodeString& srcText,
4038 int32_t srcLimit)
const
4039 {
return doCompare(start, limit - start,
4040 srcText, srcStart, srcLimit - srcStart); }
4043 UnicodeString::doCompareCodePointOrder(int32_t start,
4045 const UnicodeString& srcText,
4047 int32_t srcLength)
const
4050 return (int8_t)!isBogus();
4052 srcText.pinIndices(srcStart, srcLength);
4053 return doCompareCodePointOrder(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
4059 {
return doCompareCodePointOrder(0,
length(), text, 0, text.
length()); }
4064 const UnicodeString& srcText)
const
4065 {
return doCompareCodePointOrder(start, _length, srcText, 0, srcText.
length()); }
4069 int32_t srcLength)
const
4070 {
return doCompareCodePointOrder(0,
length(), srcChars, 0, srcLength); }
4075 const UnicodeString& srcText,
4077 int32_t srcLength)
const
4078 {
return doCompareCodePointOrder(start, _length, srcText, srcStart, srcLength); }
4083 const char16_t *srcChars)
const
4084 {
return doCompareCodePointOrder(start, _length, srcChars, 0, _length); }
4089 const char16_t *srcChars,
4091 int32_t srcLength)
const
4092 {
return doCompareCodePointOrder(start, _length, srcChars, srcStart, srcLength); }
4097 const UnicodeString& srcText,
4099 int32_t srcLimit)
const
4100 {
return doCompareCodePointOrder(start, limit - start,
4101 srcText, srcStart, srcLimit - srcStart); }
4104 UnicodeString::doCaseCompare(int32_t start,
4106 const UnicodeString &srcText,
4109 uint32_t options)
const
4112 return (int8_t)!isBogus();
4114 srcText.pinIndices(srcStart, srcLength);
4115 return doCaseCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength, options);
4121 return doCaseCompare(0,
length(), text, 0, text.
length(), options);
4127 const UnicodeString &srcText,
4128 uint32_t options)
const {
4129 return doCaseCompare(start, _length, srcText, 0, srcText.
length(), options);
4135 uint32_t options)
const {
4136 return doCaseCompare(0,
length(), srcChars, 0, srcLength, options);
4142 const UnicodeString &srcText,
4145 uint32_t options)
const {
4146 return doCaseCompare(start, _length, srcText, srcStart, srcLength, options);
4152 const char16_t *srcChars,
4153 uint32_t options)
const {
4154 return doCaseCompare(start, _length, srcChars, 0, _length, options);
4160 const char16_t *srcChars,
4163 uint32_t options)
const {
4164 return doCaseCompare(start, _length, srcChars, srcStart, srcLength, options);
4170 const UnicodeString &srcText,
4173 uint32_t options)
const {
4174 return doCaseCompare(start, limit - start, srcText, srcStart, srcLimit - srcStart, options);
4182 int32_t _length)
const
4185 srcText.pinIndices(srcStart, srcLength);
4187 return indexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
4195 {
return indexOf(text, 0, text.
length(), 0,
length()); }
4199 int32_t start)
const {
4201 return indexOf(text, 0, text.
length(), start,
length() - start);
4207 int32_t _length)
const
4208 {
return indexOf(text, 0, text.
length(), start, _length); }
4213 int32_t start)
const {
4215 return indexOf(srcChars, 0, srcLength, start,
length() - start);
4222 int32_t _length)
const
4223 {
return indexOf(srcChars, 0, srcLength, start, _length); }
4228 int32_t _length)
const
4229 {
return doIndexOf(c, start, _length); }
4234 int32_t _length)
const
4235 {
return doIndexOf(c, start, _length); }
4239 {
return doIndexOf(c, 0,
length()); }
4243 {
return indexOf(c, 0,
length()); }
4247 int32_t start)
const {
4249 return doIndexOf(c, start,
length() - start);
4254 int32_t start)
const {
4256 return indexOf(c, start,
length() - start);
4263 int32_t _length)
const
4264 {
return lastIndexOf(srcChars, 0, srcLength, start, _length); }
4269 int32_t start)
const {
4271 return lastIndexOf(srcChars, 0, srcLength, start,
length() - start);
4279 int32_t _length)
const
4282 srcText.pinIndices(srcStart, srcLength);
4284 return lastIndexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
4293 int32_t _length)
const
4294 {
return lastIndexOf(text, 0, text.
length(), start, _length); }
4298 int32_t start)
const {
4300 return lastIndexOf(text, 0, text.
length(), start,
length() - start);
4305 {
return lastIndexOf(text, 0, text.
length(), 0,
length()); }
4310 int32_t _length)
const
4311 {
return doLastIndexOf(c, start, _length); }
4316 int32_t _length)
const {
4317 return doLastIndexOf(c, start, _length);
4322 {
return doLastIndexOf(c, 0,
length()); }
4326 return lastIndexOf(c, 0,
length());
4331 int32_t start)
const {
4333 return doLastIndexOf(c, start,
length() - start);
4338 int32_t start)
const {
4340 return lastIndexOf(c, start,
length() - start);
4345 {
return compare(0, text.
length(), text, 0, text.
length()) == 0; }
4350 int32_t srcLength)
const
4351 {
return doCompare(0, srcLength, srcText, srcStart, srcLength) == 0; }
4358 return doCompare(0, srcLength, srcChars, 0, srcLength) == 0;
4366 return doCompare(0, srcLength, srcChars, srcStart, srcLength) == 0;
4372 text, 0, text.
length()) == 0; }
4377 int32_t srcLength)
const {
4378 srcText.pinIndices(srcStart, srcLength);
4379 return doCompare(
length() - srcLength, srcLength,
4380 srcText, srcStart, srcLength) == 0;
4385 int32_t srcLength)
const {
4389 return doCompare(
length() - srcLength, srcLength,
4390 srcChars, 0, srcLength) == 0;
4396 int32_t srcLength)
const {
4400 return doCompare(
length() - srcLength, srcLength,
4401 srcChars, srcStart, srcLength) == 0;
4407 inline UnicodeString&
4410 const UnicodeString& srcText)
4411 {
return doReplace(start, _length, srcText, 0, srcText.
length()); }
4413 inline UnicodeString&
4416 const UnicodeString& srcText,
4419 {
return doReplace(start, _length, srcText, srcStart, srcLength); }
4421 inline UnicodeString&
4426 {
return doReplace(start, _length, srcChars, 0, srcLength); }
4428 inline UnicodeString&
4431 const char16_t *srcChars,
4434 {
return doReplace(start, _length, srcChars, srcStart, srcLength); }
4436 inline UnicodeString&
4440 {
return doReplace(start, _length, &srcChar, 0, 1); }
4442 inline UnicodeString&
4445 const UnicodeString& srcText)
4446 {
return doReplace(start, limit - start, srcText, 0, srcText.
length()); }
4448 inline UnicodeString&
4451 const UnicodeString& srcText,
4454 {
return doReplace(start, limit - start, srcText, srcStart, srcLimit - srcStart); }
4456 inline UnicodeString&
4458 const UnicodeString& newText)
4459 {
return findAndReplace(0,
length(), oldText, 0, oldText.
length(),
4460 newText, 0, newText.
length()); }
4462 inline UnicodeString&
4465 const UnicodeString& oldText,
4466 const UnicodeString& newText)
4467 {
return findAndReplace(start, _length, oldText, 0, oldText.
length(),
4468 newText, 0, newText.
length()); }
4474 UnicodeString::doExtract(int32_t start,
4476 UnicodeString& target)
const
4477 { target.
replace(0, target.
length(), *
this, start, _length); }
4483 int32_t targetStart)
const
4484 { doExtract(start, _length, target, targetStart); }
4489 UnicodeString& target)
const
4490 { doExtract(start, _length, target); }
4492 #if !UCONFIG_NO_CONVERSION
4498 const char *codepage)
const
4502 return extract(start, _length, dst, dst!=0 ? 0xffffffff : 0, codepage);
4511 int32_t dstStart)
const {
4514 doExtract(start, limit - start, dst, dstStart);
4517 inline UnicodeString
4519 return tempSubString(start, limit - start);
4523 UnicodeString::doCharAt(int32_t offset)
const
4525 if((uint32_t)offset < (uint32_t)
length()) {
4526 return getArrayStart()[offset];
4528 return kInvalidUChar;
4534 {
return doCharAt(offset); }
4538 {
return doCharAt(offset); }
4543 return (fUnion.fFields.fLengthAndFlags>>kLengthShift) == 0;
4550 UnicodeString::setZeroLength() {
4551 fUnion.fFields.fLengthAndFlags &= kAllStorageFlags;
4555 UnicodeString::setShortLength(int32_t len) {
4557 fUnion.fFields.fLengthAndFlags =
4558 (int16_t)((fUnion.fFields.fLengthAndFlags & kAllStorageFlags) | (len << kLengthShift));
4562 UnicodeString::setLength(int32_t len) {
4563 if(len <= kMaxShortLength) {
4564 setShortLength(len);
4566 fUnion.fFields.fLengthAndFlags |= kLengthIsLarge;
4567 fUnion.fFields.fLength = len;
4572 UnicodeString::setToEmpty() {
4573 fUnion.fFields.fLengthAndFlags = kShortString;
4577 UnicodeString::setArray(char16_t *array, int32_t len, int32_t capacity) {
4579 fUnion.fFields.fArray = array;
4580 fUnion.fFields.fCapacity = capacity;
4583 inline UnicodeString&
4585 {
return doReplace(0,
length(), &ch, 0, 1); }
4587 inline UnicodeString&
4589 {
return replace(0,
length(), ch); }
4591 inline UnicodeString&
4597 return doReplace(0,
length(), srcText, srcStart, srcLength);
4600 inline UnicodeString&
4605 srcText.pinIndex(srcStart);
4606 return doReplace(0,
length(), srcText, srcStart, srcText.
length() - srcStart);
4609 inline UnicodeString&
4612 return copyFrom(srcText);
4615 inline UnicodeString&
4620 return doReplace(0,
length(), srcChars, 0, srcLength);
4623 inline UnicodeString&
4627 return doReplace(0,
length(), &srcChar, 0, 1);
4630 inline UnicodeString&
4634 return replace(0,
length(), srcChar);
4637 inline UnicodeString&
4641 {
return doAppend(srcText, srcStart, srcLength); }
4643 inline UnicodeString&
4645 {
return doAppend(srcText, 0, srcText.
length()); }
4647 inline UnicodeString&
4651 {
return doAppend(srcChars, srcStart, srcLength); }
4653 inline UnicodeString&
4656 {
return doAppend(srcChars, 0, srcLength); }
4658 inline UnicodeString&
4660 {
return doAppend(&srcChar, 0, 1); }
4662 inline UnicodeString&
4664 {
return doAppend(&ch, 0, 1); }
4666 inline UnicodeString&
4671 inline UnicodeString&
4673 {
return doAppend(srcText, 0, srcText.
length()); }
4675 inline UnicodeString&
4677 const UnicodeString& srcText,
4680 {
return doReplace(start, 0, srcText, srcStart, srcLength); }
4682 inline UnicodeString&
4684 const UnicodeString& srcText)
4685 {
return doReplace(start, 0, srcText, 0, srcText.
length()); }
4687 inline UnicodeString&
4689 const char16_t *srcChars,
4692 {
return doReplace(start, 0, srcChars, srcStart, srcLength); }
4694 inline UnicodeString&
4698 {
return doReplace(start, 0, srcChars, 0, srcLength); }
4700 inline UnicodeString&
4703 {
return doReplace(start, 0, &srcChar, 0, 1); }
4705 inline UnicodeString&
4708 {
return replace(start, 0, srcChar); }
4711 inline UnicodeString&
4723 inline UnicodeString&
4727 if(start <= 0 && _length ==
INT32_MAX) {
4731 return doReplace(start, _length,
NULL, 0, 0);
4734 inline UnicodeString&
4737 {
return doReplace(start, limit - start,
NULL, 0, 0); }
4739 inline UnicodeString &
4742 return doReplace(0, start,
NULL, 0, 0);
4748 if(isBogus() && targetLength == 0) {
4752 }
else if((uint32_t)targetLength < (uint32_t)
length()) {
4753 setLength(targetLength);
4760 inline UnicodeString&
4762 {
return doReverse(0,
length()); }
4764 inline UnicodeString&
4767 {
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.