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);
3485 UChar32 unescapeAt(int32_t &offset)
const;
3492 static UClassID U_EXPORT2 getStaticClassID();
3517 virtual char16_t
getCharAt(int32_t offset)
const;
3535 toUTF8(int32_t start, int32_t len,
3536 char *target, int32_t capacity)
const;
3545 doCompare(int32_t start,
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,
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,
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,
3611 inline char16_t doCharAt(int32_t offset)
const;
3621 const char16_t *srcChars,
3626 UnicodeString& doAppend(
const char16_t *srcChars, int32_t srcStart, int32_t srcLength);
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);
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,
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,
3781 friend class UnicodeStringAppendable;
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 3880 int32_t len = length();
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;
3910 UnicodeString::UnicodeString() {
3911 fUnion.fStackFields.fLengthAndFlags=kShortString;
3914 inline UnicodeString::UnicodeString(
const std::nullptr_t ) {
3915 fUnion.fStackFields.fLengthAndFlags=kShortString;
3918 inline UnicodeString::UnicodeString(
const std::nullptr_t , int32_t ) {
3919 fUnion.fStackFields.fLengthAndFlags=kShortString;
3922 inline UnicodeString::UnicodeString(std::nullptr_t , int32_t , int32_t ) {
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;
3942 UnicodeString::length()
const {
3943 return hasShortLength() ? getShortLength() : fUnion.fFields.fLength;
3947 UnicodeString::getCapacity()
const {
3948 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3949 US_STACKBUF_SIZE : fUnion.fFields.fCapacity;
3953 UnicodeString::hashCode()
const 3954 {
return doHashCode(); }
3957 UnicodeString::isBogus()
const 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 *
3973 UnicodeString::getBuffer()
const {
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,
3991 int32_t srcLength)
const 3994 return (int8_t)!isBogus();
3996 srcText.pinIndices(srcStart, srcLength);
3997 return doCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
4007 int32_t len = length(), textLength = text.
length();
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()); }
4037 UnicodeString::compare(int32_t start,
4040 {
return doCompare(start, _length, srcText, 0, srcText.
length()); }
4044 int32_t srcLength)
const 4045 {
return doCompare(0, length(), srcChars, 0, srcLength); }
4048 UnicodeString::compare(int32_t start,
4052 int32_t srcLength)
const 4053 {
return doCompare(start, _length, srcText, srcStart, srcLength); }
4056 UnicodeString::compare(int32_t start,
4058 const char16_t *srcChars)
const 4059 {
return doCompare(start, _length, srcChars, 0, _length); }
4062 UnicodeString::compare(int32_t start,
4064 const char16_t *srcChars,
4066 int32_t srcLength)
const 4067 {
return doCompare(start, _length, srcChars, srcStart, srcLength); }
4070 UnicodeString::compareBetween(int32_t start,
4074 int32_t srcLimit)
const 4075 {
return doCompare(start, limit - start,
4076 srcText, srcStart, srcLimit - srcStart); }
4079 UnicodeString::doCompareCodePointOrder(int32_t start,
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()); }
4098 UnicodeString::compareCodePointOrder(int32_t start,
4101 {
return doCompareCodePointOrder(start, _length, srcText, 0, srcText.
length()); }
4105 int32_t srcLength)
const 4106 {
return doCompareCodePointOrder(0, length(), srcChars, 0, srcLength); }
4109 UnicodeString::compareCodePointOrder(int32_t start,
4113 int32_t srcLength)
const 4114 {
return doCompareCodePointOrder(start, _length, srcText, srcStart, srcLength); }
4117 UnicodeString::compareCodePointOrder(int32_t start,
4119 const char16_t *srcChars)
const 4120 {
return doCompareCodePointOrder(start, _length, srcChars, 0, _length); }
4123 UnicodeString::compareCodePointOrder(int32_t start,
4125 const char16_t *srcChars,
4127 int32_t srcLength)
const 4128 {
return doCompareCodePointOrder(start, _length, srcChars, srcStart, srcLength); }
4131 UnicodeString::compareCodePointOrderBetween(int32_t start,
4135 int32_t srcLimit)
const 4136 {
return doCompareCodePointOrder(start, limit - start,
4137 srcText, srcStart, srcLimit - srcStart); }
4140 UnicodeString::doCaseCompare(int32_t start,
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);
4161 UnicodeString::caseCompare(int32_t start,
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);
4176 UnicodeString::caseCompare(int32_t start,
4181 uint32_t options)
const {
4182 return doCaseCompare(start, _length, srcText, srcStart, srcLength, options);
4186 UnicodeString::caseCompare(int32_t start,
4188 const char16_t *srcChars,
4189 uint32_t options)
const {
4190 return doCaseCompare(start, _length, srcChars, 0, _length, options);
4194 UnicodeString::caseCompare(int32_t start,
4196 const char16_t *srcChars,
4199 uint32_t options)
const {
4200 return doCaseCompare(start, _length, srcChars, srcStart, srcLength, options);
4204 UnicodeString::caseCompareBetween(int32_t start,
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); }
4247 UnicodeString::indexOf(
const char16_t *srcChars,
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); }
4262 UnicodeString::indexOf(char16_t c,
4264 int32_t _length)
const 4265 {
return doIndexOf(c, start, _length); }
4270 int32_t _length)
const 4271 {
return doIndexOf(c, start, _length); }
4274 UnicodeString::indexOf(char16_t c)
const 4275 {
return doIndexOf(c, 0, length()); }
4279 {
return indexOf(c, 0, length()); }
4282 UnicodeString::indexOf(char16_t c,
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); }
4303 UnicodeString::lastIndexOf(
const char16_t *srcChars,
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()); }
4344 UnicodeString::lastIndexOf(char16_t c,
4346 int32_t _length)
const 4347 {
return doLastIndexOf(c, start, _length); }
4352 int32_t _length)
const {
4353 return doLastIndexOf(c, start, _length);
4357 UnicodeString::lastIndexOf(char16_t c)
const 4358 {
return doLastIndexOf(c, 0, length()); }
4362 return lastIndexOf(c, 0, length());
4366 UnicodeString::lastIndexOf(char16_t c,
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;
4398 UnicodeString::startsWith(
const char16_t *srcChars, int32_t srcStart, int32_t srcLength)
const {
4402 return doCompare(0, srcLength, srcChars, srcStart, srcLength) == 0;
4407 {
return doCompare(length() - text.
length(), text.
length(),
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;
4430 UnicodeString::endsWith(
const char16_t *srcChars,
4432 int32_t srcLength)
const {
4436 return doCompare(length() - srcLength, srcLength,
4437 srcChars, srcStart, srcLength) == 0;
4444 UnicodeString::replace(int32_t start,
4447 {
return doReplace(start, _length, srcText, 0, srcText.
length()); }
4450 UnicodeString::replace(int32_t start,
4455 {
return doReplace(start, _length, srcText, srcStart, srcLength); }
4458 UnicodeString::replace(int32_t start,
4462 {
return doReplace(start, _length, srcChars, 0, srcLength); }
4465 UnicodeString::replace(int32_t start,
4467 const char16_t *srcChars,
4470 {
return doReplace(start, _length, srcChars, srcStart, srcLength); }
4473 UnicodeString::replace(int32_t start,
4476 {
return doReplace(start, _length, &srcChar, 0, 1); }
4479 UnicodeString::replaceBetween(int32_t start,
4482 {
return doReplace(start, limit - start, srcText, 0, srcText.
length()); }
4485 UnicodeString::replaceBetween(int32_t start,
4490 {
return doReplace(start, limit - start, srcText, srcStart, srcLimit - srcStart); }
4495 {
return findAndReplace(0, length(), oldText, 0, oldText.
length(),
4496 newText, 0, newText.
length()); }
4499 UnicodeString::findAndReplace(int32_t start,
4503 {
return findAndReplace(start, _length, oldText, 0, oldText.
length(),
4504 newText, 0, newText.
length()); }
4510 UnicodeString::doExtract(int32_t start,
4513 { target.
replace(0, target.
length(), *
this, start, _length); }
4516 UnicodeString::extract(int32_t start,
4519 int32_t targetStart)
const 4520 { doExtract(start, _length, target, targetStart); }
4523 UnicodeString::extract(int32_t start,
4526 { doExtract(start, _length, target); }
4528 #if !UCONFIG_NO_CONVERSION 4531 UnicodeString::extract(int32_t start,
4534 const char *codepage)
const 4538 return extract(start, _length, dst, dst!=0 ? 0xffffffff : 0, codepage);
4544 UnicodeString::extractBetween(int32_t start,
4547 int32_t dstStart)
const {
4550 doExtract(start, limit - start, dst, dstStart);
4554 UnicodeString::tempSubStringBetween(int32_t start, int32_t limit)
const {
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;
4569 UnicodeString::charAt(int32_t offset)
const 4570 {
return doCharAt(offset); }
4573 UnicodeString::operator[] (int32_t offset)
const 4574 {
return doCharAt(offset); }
4577 UnicodeString::isEmpty()
const {
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&
4620 UnicodeString::operator= (char16_t ch)
4621 {
return doReplace(0, length(), &ch, 0, 1); }
4625 {
return replace(0, length(), ch); }
4633 return doReplace(0, length(), srcText, srcStart, srcLength);
4641 srcText.pinIndex(srcStart);
4642 return doReplace(0, length(), srcText, srcStart, srcText.
length() - srcStart);
4648 return copyFrom(srcText);
4652 UnicodeString::setTo(
const char16_t *srcChars,
4656 return doReplace(0, length(), srcChars, 0, srcLength);
4660 UnicodeString::setTo(char16_t srcChar)
4663 return doReplace(0, length(), &srcChar, 0, 1);
4670 return replace(0, length(), srcChar);
4677 {
return doAppend(srcText, srcStart, srcLength); }
4681 {
return doAppend(srcText, 0, srcText.
length()); }
4684 UnicodeString::append(
const char16_t *srcChars,
4687 {
return doAppend(srcChars, srcStart, srcLength); }
4692 {
return doAppend(srcChars, 0, srcLength); }
4695 UnicodeString::append(char16_t srcChar)
4696 {
return doAppend(&srcChar, 0, 1); }
4699 UnicodeString::operator+= (char16_t ch)
4700 {
return doAppend(&ch, 0, 1); }
4709 {
return doAppend(srcText, 0, srcText.
length()); }
4712 UnicodeString::insert(int32_t start,
4716 {
return doReplace(start, 0, srcText, srcStart, srcLength); }
4719 UnicodeString::insert(int32_t start,
4721 {
return doReplace(start, 0, srcText, 0, srcText.
length()); }
4724 UnicodeString::insert(int32_t start,
4725 const char16_t *srcChars,
4728 {
return doReplace(start, 0, srcChars, srcStart, srcLength); }
4731 UnicodeString::insert(int32_t start,
4734 {
return doReplace(start, 0, srcChars, 0, srcLength); }
4737 UnicodeString::insert(int32_t start,
4739 {
return doReplace(start, 0, &srcChar, 0, 1); }
4742 UnicodeString::insert(int32_t start,
4744 {
return replace(start, 0, srcChar); }
4748 UnicodeString::remove()
4760 UnicodeString::remove(int32_t start,
4763 if(start <= 0 && _length ==
INT32_MAX) {
4767 return doReplace(start, _length,
NULL, 0, 0);
4771 UnicodeString::removeBetween(int32_t start,
4773 {
return doReplace(start, limit - start,
NULL, 0, 0); }
4776 UnicodeString::retainBetween(int32_t start, int32_t limit) {
4778 return doReplace(0, start,
NULL, 0, 0);
4782 UnicodeString::truncate(int32_t targetLength)
4784 if(isBogus() && targetLength == 0) {
4788 }
else if((uint32_t)targetLength < (uint32_t)length()) {
4789 setLength(targetLength);
4797 UnicodeString::reverse()
4798 {
return doReverse(0, length()); }
4801 UnicodeString::reverse(int32_t start,
4803 {
return doReverse(start, _length); }
#define UNISTR_OBJECT_SIZE
Desired sizeof(UnicodeString) in bytes.
EInvariant
Constant to be used in the UnicodeString(char *, int32_t, EInvariant) constructor which constructs a ...
UnicodeString(wchar_t *buffer, int32_t buffLength, int32_t buffCapacity)
Writable-aliasing wchar_t * constructor.
virtual void copy(int32_t start, int32_t limit, int32_t dest)=0
Copies a substring of this object, retaining metadata.
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.
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.
virtual void extractBetween(int32_t start, int32_t limit, UnicodeString &target) const =0
Copies characters in the range [start, limit) into the UnicodeString target.
A ByteSink can be filled with bytes.
friend U_COMMON_API void swap(UnicodeString &s1, UnicodeString &s2)
Non-member UnicodeString swap function.
virtual UChar32 getChar32At(int32_t offset) const =0
Virtual version of char32At().
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.
#define UCONFIG_NO_BREAK_ITERATION
This switch turns off break iteration.
UBool isBogus(void) const
Determine if this object contains a valid string.
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.
StringClass & toUTF8String(StringClass &result) const
Convert the UnicodeString to UTF-8 and append the result to a standard string.
int32_t length() const
Returns the number of 16-bit code units in the text.
C++ API: Interface for writing bytes, and implementation classes.
U_COMMON_API UnicodeString operator+(const UnicodeString &s1, const UnicodeString &s2)
Create a new UnicodeString with the concatenation of two others.
virtual int32_t getLength() const =0
Virtual version of length().
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.
UChar32 char32At(int32_t offset) const
Returns the 32-bit code point at the given 16-bit offset into the text.
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.
virtual UClassID getDynamicClassID() const
ICU4C "poor man's RTTI", returns a UClassID for the actual ICU class.
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 *.
virtual char16_t getCharAt(int32_t offset) const =0
Virtual version of charAt().
#define TRUE
The TRUE value of a UBool.
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.
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...
char16_t charAt(int32_t offset) const
Returns the 16-bit code unit at the given offset into the text.
int32_t length(void) const
Return the length of the UnicodeString object.
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".
int32_t u_strlen(const UChar *s)
Determine the length of an array of UChar.
virtual Replaceable * clone() const
Clone this object, an instance of a subclass of Replaceable.
#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 is a string class that stores Unicode characters directly and provides similar function...
virtual UBool hasMetaData() const
Returns true if this object contains metadata.
#define UNISTR_FROM_STRING_EXPLICIT
This can be defined to be empty or "explicit".
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...
#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.