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,
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;
1894 #if U_HAVE_RVALUE_REFERENCES 1904 return moveFrom(src);
2053 int32_t textLength);
2076 int32_t buffCapacity);
2278 const char16_t *srcChars,
2378 const char16_t *srcChars,
2496 virtual void copy(int32_t start, int32_t limit, int32_t dest);
2582 inline UnicodeString& removeBetween(int32_t start,
2594 inline UnicodeString &retainBetween(int32_t start, int32_t limit = INT32_MAX);
2609 UBool padLeading(int32_t targetLength,
2610 char16_t padChar = 0x0020);
2623 UBool padTrailing(int32_t targetLength,
2624 char16_t padChar = 0x0020);
2632 inline UBool truncate(int32_t targetLength);
2639 UnicodeString& trim(
void);
2649 inline UnicodeString& reverse(
void);
2659 inline UnicodeString& reverse(int32_t start,
2668 UnicodeString& toUpper(
void);
2677 UnicodeString& toUpper(
const Locale& locale);
2685 UnicodeString& toLower(
void);
2694 UnicodeString& toLower(
const Locale& locale);
2696 #if !UCONFIG_NO_BREAK_ITERATION 2803 UnicodeString &foldCase(uint32_t options=0 );
2852 char16_t *getBuffer(int32_t minCapacity);
2874 void releaseBuffer(int32_t newLength=-1);
2906 inline const char16_t *getBuffer()
const;
2941 const char16_t *getTerminatedBuffer();
2950 inline UnicodeString();
2963 UnicodeString(int32_t capacity,
UChar32 c, int32_t count);
3003 #if !U_CHAR16_IS_TYPEDEF 3022 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN) 3061 UnicodeString(
const char16_t *text,
3062 int32_t textLength);
3068 #if !U_CHAR16_IS_TYPEDEF 3084 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN) 3108 inline UnicodeString(
const std::nullptr_t text, int32_t length);
3132 UnicodeString(
UBool isTerminated,
3134 int32_t textLength);
3154 UnicodeString(char16_t *buffer, int32_t buffLength, int32_t buffCapacity);
3160 #if !U_CHAR16_IS_TYPEDEF 3170 UnicodeString(
Char16Ptr(buffer), buffLength, buffCapacity) {}
3177 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN) 3188 UnicodeString(
Char16Ptr(buffer), buffLength, buffCapacity) {}
3203 inline UnicodeString(std::nullptr_t buffer, int32_t buffLength, int32_t buffCapacity);
3205 #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION 3236 UnicodeString(
const char *codepageData, int32_t dataLength);
3240 #if !UCONFIG_NO_CONVERSION 3259 UnicodeString(
const char *codepageData,
const char *codepage);
3278 UnicodeString(
const char *codepageData, int32_t dataLength,
const char *codepage);
3302 const char *src, int32_t srcLength,
3332 UnicodeString(
const char *src, int32_t length,
enum EInvariant inv);
3351 UnicodeString(
const UnicodeString& that);
3353 #if U_HAVE_RVALUE_REFERENCES 3360 UnicodeString(UnicodeString &&src) U_NOEXCEPT;
3369 UnicodeString(
const UnicodeString& src, int32_t srcStart);
3378 UnicodeString(
const UnicodeString& src, int32_t srcStart, int32_t srcLength);
3401 virtual ~UnicodeString();
3429 static UnicodeString fromUTF32(
const UChar32 *utf32, int32_t length);
3467 UnicodeString unescape()
const;
3488 UChar32 unescapeAt(int32_t &offset)
const;
3495 static UClassID U_EXPORT2 getStaticClassID();
3520 virtual char16_t
getCharAt(int32_t offset)
const;
3538 toUTF8(int32_t start, int32_t len,
3539 char *target, int32_t capacity)
const;
3545 UBool doEquals(
const UnicodeString &text, int32_t len)
const;
3548 doCompare(int32_t start,
3550 const UnicodeString& srcText,
3552 int32_t srcLength)
const;
3554 int8_t doCompare(int32_t start,
3556 const char16_t *srcChars,
3558 int32_t srcLength)
const;
3561 doCompareCodePointOrder(int32_t start,
3563 const UnicodeString& srcText,
3565 int32_t srcLength)
const;
3567 int8_t doCompareCodePointOrder(int32_t start,
3569 const char16_t *srcChars,
3571 int32_t srcLength)
const;
3574 doCaseCompare(int32_t start,
3576 const UnicodeString &srcText,
3579 uint32_t options)
const;
3582 doCaseCompare(int32_t start,
3584 const char16_t *srcChars,
3587 uint32_t options)
const;
3589 int32_t doIndexOf(char16_t c,
3591 int32_t length)
const;
3595 int32_t length)
const;
3597 int32_t doLastIndexOf(char16_t c,
3599 int32_t length)
const;
3601 int32_t doLastIndexOf(
UChar32 c,
3603 int32_t length)
const;
3605 void doExtract(int32_t start,
3608 int32_t dstStart)
const;
3610 inline void doExtract(int32_t start,
3612 UnicodeString& target)
const;
3614 inline char16_t doCharAt(int32_t offset)
const;
3616 UnicodeString& doReplace(int32_t start,
3618 const UnicodeString& srcText,
3622 UnicodeString& doReplace(int32_t start,
3624 const char16_t *srcChars,
3628 UnicodeString& doAppend(
const UnicodeString& src, int32_t srcStart, int32_t srcLength);
3629 UnicodeString& doAppend(
const char16_t *srcChars, int32_t srcStart, int32_t srcLength);
3631 UnicodeString& doReverse(int32_t start,
3635 int32_t doHashCode(
void)
const;
3639 inline char16_t* getArrayStart(
void);
3640 inline const char16_t* getArrayStart(
void)
const;
3642 inline UBool hasShortLength()
const;
3643 inline int32_t getShortLength()
const;
3647 inline UBool isWritable()
const;
3650 inline UBool isBufferWritable()
const;
3653 inline void setZeroLength();
3654 inline void setShortLength(int32_t len);
3655 inline void setLength(int32_t len);
3656 inline void setToEmpty();
3657 inline void setArray(char16_t *array, int32_t len, int32_t capacity);
3664 UBool allocate(int32_t capacity);
3667 void releaseArray(
void);
3673 UnicodeString ©From(
const UnicodeString &src,
UBool fastCopy=
FALSE);
3676 void copyFieldsFrom(UnicodeString &src,
UBool setSrcToBogus) U_NOEXCEPT;
3679 inline void pinIndex(int32_t& start)
const;
3680 inline void pinIndices(int32_t& start,
3681 int32_t& length)
const;
3683 #if !UCONFIG_NO_CONVERSION 3686 int32_t doExtract(int32_t start, int32_t length,
3687 char *dest, int32_t destCapacity,
3701 void doCodepageCreate(
const char *codepageData,
3703 const char *codepage);
3710 doCodepageCreate(
const char *codepageData,
3728 UBool cloneArrayIfNeeded(int32_t newCapacity = -1,
3729 int32_t growCapacity = -1,
3731 int32_t **pBufferToDelete = 0,
3740 caseMap(int32_t caseLocale, uint32_t options,
3748 int32_t removeRef(
void);
3749 int32_t refCount(
void)
const;
3759 kInvalidUChar=0xffff,
3765 kUsingStackBuffer=2,
3767 kBufferIsReadonly=8,
3770 kAllStorageFlags=0x1f,
3773 kLength1=1<<kLengthShift,
3774 kMaxShortLength=0x3ff,
3775 kLengthIsLarge=0xffe0,
3778 kShortString=kUsingStackBuffer,
3779 kLongString=kRefCounted,
3780 kReadonlyAlias=kBufferIsReadonly,
3786 union StackBufferOrFields;
3787 friend union StackBufferOrFields;
3830 union StackBufferOrFields {
3834 int16_t fLengthAndFlags;
3835 char16_t fBuffer[US_STACKBUF_SIZE];
3838 int16_t fLengthAndFlags;
3868 UnicodeString::pinIndex(int32_t& start)
const 3873 }
else if(start > length()) {
3879 UnicodeString::pinIndices(int32_t& start,
3880 int32_t& _length)
const 3883 int32_t len = length();
3886 }
else if(start > len) {
3891 }
else if(_length > (len - start)) {
3892 _length = (len - start);
3897 UnicodeString::getArrayStart() {
3898 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3899 fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
3902 inline const char16_t*
3903 UnicodeString::getArrayStart()
const {
3904 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3905 fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
3913 UnicodeString::UnicodeString() {
3914 fUnion.fStackFields.fLengthAndFlags=kShortString;
3917 inline UnicodeString::UnicodeString(
const std::nullptr_t ) {
3918 fUnion.fStackFields.fLengthAndFlags=kShortString;
3921 inline UnicodeString::UnicodeString(
const std::nullptr_t , int32_t ) {
3922 fUnion.fStackFields.fLengthAndFlags=kShortString;
3925 inline UnicodeString::UnicodeString(std::nullptr_t , int32_t , int32_t ) {
3926 fUnion.fStackFields.fLengthAndFlags=kShortString;
3933 UnicodeString::hasShortLength()
const {
3934 return fUnion.fFields.fLengthAndFlags>=0;
3938 UnicodeString::getShortLength()
const {
3941 return fUnion.fFields.fLengthAndFlags>>kLengthShift;
3945 UnicodeString::length()
const {
3946 return hasShortLength() ? getShortLength() : fUnion.fFields.fLength;
3950 UnicodeString::getCapacity()
const {
3951 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3952 US_STACKBUF_SIZE : fUnion.fFields.fCapacity;
3956 UnicodeString::hashCode()
const 3957 {
return doHashCode(); }
3960 UnicodeString::isBogus()
const 3961 {
return (
UBool)(fUnion.fFields.fLengthAndFlags & kIsBogus); }
3964 UnicodeString::isWritable()
const 3965 {
return (
UBool)!(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus)); }
3968 UnicodeString::isBufferWritable()
const 3971 !(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus|kBufferIsReadonly)) &&
3972 (!(fUnion.fFields.fLengthAndFlags&kRefCounted) || refCount()==1));
3975 inline const char16_t *
3976 UnicodeString::getBuffer()
const {
3977 if(fUnion.fFields.fLengthAndFlags&(kIsBogus|kOpenGetBuffer)) {
3979 }
else if(fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) {
3980 return fUnion.fStackFields.fBuffer;
3982 return fUnion.fFields.fArray;
3990 UnicodeString::doCompare(int32_t start,
3994 int32_t srcLength)
const 3997 return (int8_t)!isBogus();
3999 srcText.pinIndices(srcStart, srcLength);
4000 return doCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
4010 int32_t len = length(), textLength = text.
length();
4011 return !text.
isBogus() && len == textLength && doEquals(text, len);
4017 {
return (!
operator==(text)); }
4021 {
return doCompare(0, length(), text, 0, text.
length()) == 1; }
4025 {
return doCompare(0, length(), text, 0, text.
length()) == -1; }
4029 {
return doCompare(0, length(), text, 0, text.
length()) != -1; }
4033 {
return doCompare(0, length(), text, 0, text.
length()) != 1; }
4037 {
return doCompare(0, length(), text, 0, text.
length()); }
4040 UnicodeString::compare(int32_t start,
4043 {
return doCompare(start, _length, srcText, 0, srcText.
length()); }
4047 int32_t srcLength)
const 4048 {
return doCompare(0, length(), srcChars, 0, srcLength); }
4051 UnicodeString::compare(int32_t start,
4055 int32_t srcLength)
const 4056 {
return doCompare(start, _length, srcText, srcStart, srcLength); }
4059 UnicodeString::compare(int32_t start,
4061 const char16_t *srcChars)
const 4062 {
return doCompare(start, _length, srcChars, 0, _length); }
4065 UnicodeString::compare(int32_t start,
4067 const char16_t *srcChars,
4069 int32_t srcLength)
const 4070 {
return doCompare(start, _length, srcChars, srcStart, srcLength); }
4073 UnicodeString::compareBetween(int32_t start,
4077 int32_t srcLimit)
const 4078 {
return doCompare(start, limit - start,
4079 srcText, srcStart, srcLimit - srcStart); }
4082 UnicodeString::doCompareCodePointOrder(int32_t start,
4086 int32_t srcLength)
const 4089 return (int8_t)!isBogus();
4091 srcText.pinIndices(srcStart, srcLength);
4092 return doCompareCodePointOrder(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
4098 {
return doCompareCodePointOrder(0, length(), text, 0, text.
length()); }
4101 UnicodeString::compareCodePointOrder(int32_t start,
4104 {
return doCompareCodePointOrder(start, _length, srcText, 0, srcText.
length()); }
4108 int32_t srcLength)
const 4109 {
return doCompareCodePointOrder(0, length(), srcChars, 0, srcLength); }
4112 UnicodeString::compareCodePointOrder(int32_t start,
4116 int32_t srcLength)
const 4117 {
return doCompareCodePointOrder(start, _length, srcText, srcStart, srcLength); }
4120 UnicodeString::compareCodePointOrder(int32_t start,
4122 const char16_t *srcChars)
const 4123 {
return doCompareCodePointOrder(start, _length, srcChars, 0, _length); }
4126 UnicodeString::compareCodePointOrder(int32_t start,
4128 const char16_t *srcChars,
4130 int32_t srcLength)
const 4131 {
return doCompareCodePointOrder(start, _length, srcChars, srcStart, srcLength); }
4134 UnicodeString::compareCodePointOrderBetween(int32_t start,
4138 int32_t srcLimit)
const 4139 {
return doCompareCodePointOrder(start, limit - start,
4140 srcText, srcStart, srcLimit - srcStart); }
4143 UnicodeString::doCaseCompare(int32_t start,
4148 uint32_t options)
const 4151 return (int8_t)!isBogus();
4153 srcText.pinIndices(srcStart, srcLength);
4154 return doCaseCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength, options);
4160 return doCaseCompare(0, length(), text, 0, text.
length(), options);
4164 UnicodeString::caseCompare(int32_t start,
4167 uint32_t options)
const {
4168 return doCaseCompare(start, _length, srcText, 0, srcText.
length(), options);
4174 uint32_t options)
const {
4175 return doCaseCompare(0, length(), srcChars, 0, srcLength, options);
4179 UnicodeString::caseCompare(int32_t start,
4184 uint32_t options)
const {
4185 return doCaseCompare(start, _length, srcText, srcStart, srcLength, options);
4189 UnicodeString::caseCompare(int32_t start,
4191 const char16_t *srcChars,
4192 uint32_t options)
const {
4193 return doCaseCompare(start, _length, srcChars, 0, _length, options);
4197 UnicodeString::caseCompare(int32_t start,
4199 const char16_t *srcChars,
4202 uint32_t options)
const {
4203 return doCaseCompare(start, _length, srcChars, srcStart, srcLength, options);
4207 UnicodeString::caseCompareBetween(int32_t start,
4212 uint32_t options)
const {
4213 return doCaseCompare(start, limit - start, srcText, srcStart, srcLimit - srcStart, options);
4221 int32_t _length)
const 4224 srcText.pinIndices(srcStart, srcLength);
4226 return indexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
4234 {
return indexOf(text, 0, text.
length(), 0, length()); }
4238 int32_t start)
const {
4240 return indexOf(text, 0, text.
length(), start, length() - start);
4246 int32_t _length)
const 4247 {
return indexOf(text, 0, text.
length(), start, _length); }
4250 UnicodeString::indexOf(
const char16_t *srcChars,
4252 int32_t start)
const {
4254 return indexOf(srcChars, 0, srcLength, start, length() - start);
4261 int32_t _length)
const 4262 {
return indexOf(srcChars, 0, srcLength, start, _length); }
4265 UnicodeString::indexOf(char16_t c,
4267 int32_t _length)
const 4268 {
return doIndexOf(c, start, _length); }
4273 int32_t _length)
const 4274 {
return doIndexOf(c, start, _length); }
4277 UnicodeString::indexOf(char16_t c)
const 4278 {
return doIndexOf(c, 0, length()); }
4282 {
return indexOf(c, 0, length()); }
4285 UnicodeString::indexOf(char16_t c,
4286 int32_t start)
const {
4288 return doIndexOf(c, start, length() - start);
4293 int32_t start)
const {
4295 return indexOf(c, start, length() - start);
4302 int32_t _length)
const 4303 {
return lastIndexOf(srcChars, 0, srcLength, start, _length); }
4306 UnicodeString::lastIndexOf(
const char16_t *srcChars,
4308 int32_t start)
const {
4310 return lastIndexOf(srcChars, 0, srcLength, start, length() - start);
4318 int32_t _length)
const 4321 srcText.pinIndices(srcStart, srcLength);
4323 return lastIndexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
4332 int32_t _length)
const 4333 {
return lastIndexOf(text, 0, text.
length(), start, _length); }
4337 int32_t start)
const {
4339 return lastIndexOf(text, 0, text.
length(), start, length() - start);
4344 {
return lastIndexOf(text, 0, text.
length(), 0, length()); }
4347 UnicodeString::lastIndexOf(char16_t c,
4349 int32_t _length)
const 4350 {
return doLastIndexOf(c, start, _length); }
4355 int32_t _length)
const {
4356 return doLastIndexOf(c, start, _length);
4360 UnicodeString::lastIndexOf(char16_t c)
const 4361 {
return doLastIndexOf(c, 0, length()); }
4365 return lastIndexOf(c, 0, length());
4369 UnicodeString::lastIndexOf(char16_t c,
4370 int32_t start)
const {
4372 return doLastIndexOf(c, start, length() - start);
4377 int32_t start)
const {
4379 return lastIndexOf(c, start, length() - start);
4384 {
return compare(0, text.
length(), text, 0, text.
length()) == 0; }
4389 int32_t srcLength)
const 4390 {
return doCompare(0, srcLength, srcText, srcStart, srcLength) == 0; }
4397 return doCompare(0, srcLength, srcChars, 0, srcLength) == 0;
4401 UnicodeString::startsWith(
const char16_t *srcChars, int32_t srcStart, int32_t srcLength)
const {
4405 return doCompare(0, srcLength, srcChars, srcStart, srcLength) == 0;
4410 {
return doCompare(length() - text.
length(), text.
length(),
4411 text, 0, text.
length()) == 0; }
4416 int32_t srcLength)
const {
4417 srcText.pinIndices(srcStart, srcLength);
4418 return doCompare(length() - srcLength, srcLength,
4419 srcText, srcStart, srcLength) == 0;
4424 int32_t srcLength)
const {
4428 return doCompare(length() - srcLength, srcLength,
4429 srcChars, 0, srcLength) == 0;
4433 UnicodeString::endsWith(
const char16_t *srcChars,
4435 int32_t srcLength)
const {
4439 return doCompare(length() - srcLength, srcLength,
4440 srcChars, srcStart, srcLength) == 0;
4447 UnicodeString::replace(int32_t start,
4450 {
return doReplace(start, _length, srcText, 0, srcText.
length()); }
4453 UnicodeString::replace(int32_t start,
4458 {
return doReplace(start, _length, srcText, srcStart, srcLength); }
4461 UnicodeString::replace(int32_t start,
4465 {
return doReplace(start, _length, srcChars, 0, srcLength); }
4468 UnicodeString::replace(int32_t start,
4470 const char16_t *srcChars,
4473 {
return doReplace(start, _length, srcChars, srcStart, srcLength); }
4476 UnicodeString::replace(int32_t start,
4479 {
return doReplace(start, _length, &srcChar, 0, 1); }
4482 UnicodeString::replaceBetween(int32_t start,
4485 {
return doReplace(start, limit - start, srcText, 0, srcText.
length()); }
4488 UnicodeString::replaceBetween(int32_t start,
4493 {
return doReplace(start, limit - start, srcText, srcStart, srcLimit - srcStart); }
4498 {
return findAndReplace(0, length(), oldText, 0, oldText.
length(),
4499 newText, 0, newText.
length()); }
4502 UnicodeString::findAndReplace(int32_t start,
4506 {
return findAndReplace(start, _length, oldText, 0, oldText.
length(),
4507 newText, 0, newText.
length()); }
4513 UnicodeString::doExtract(int32_t start,
4516 { target.
replace(0, target.
length(), *
this, start, _length); }
4519 UnicodeString::extract(int32_t start,
4522 int32_t targetStart)
const 4523 { doExtract(start, _length, target, targetStart); }
4526 UnicodeString::extract(int32_t start,
4529 { doExtract(start, _length, target); }
4531 #if !UCONFIG_NO_CONVERSION 4534 UnicodeString::extract(int32_t start,
4537 const char *codepage)
const 4541 return extract(start, _length, dst, dst!=0 ? 0xffffffff : 0, codepage);
4547 UnicodeString::extractBetween(int32_t start,
4550 int32_t dstStart)
const {
4553 doExtract(start, limit - start, dst, dstStart);
4557 UnicodeString::tempSubStringBetween(int32_t start, int32_t limit)
const {
4558 return tempSubString(start, limit - start);
4562 UnicodeString::doCharAt(int32_t offset)
const 4564 if((uint32_t)offset < (uint32_t)length()) {
4565 return getArrayStart()[offset];
4567 return kInvalidUChar;
4572 UnicodeString::charAt(int32_t offset)
const 4573 {
return doCharAt(offset); }
4576 UnicodeString::operator[] (int32_t offset)
const 4577 {
return doCharAt(offset); }
4580 UnicodeString::isEmpty()
const {
4582 return (fUnion.fFields.fLengthAndFlags>>kLengthShift) == 0;
4589 UnicodeString::setZeroLength() {
4590 fUnion.fFields.fLengthAndFlags &= kAllStorageFlags;
4594 UnicodeString::setShortLength(int32_t len) {
4596 fUnion.fFields.fLengthAndFlags =
4597 (int16_t)((fUnion.fFields.fLengthAndFlags & kAllStorageFlags) | (len << kLengthShift));
4601 UnicodeString::setLength(int32_t len) {
4602 if(len <= kMaxShortLength) {
4603 setShortLength(len);
4605 fUnion.fFields.fLengthAndFlags |= kLengthIsLarge;
4606 fUnion.fFields.fLength = len;
4611 UnicodeString::setToEmpty() {
4612 fUnion.fFields.fLengthAndFlags = kShortString;
4616 UnicodeString::setArray(char16_t *array, int32_t len, int32_t capacity) {
4618 fUnion.fFields.fArray = array;
4619 fUnion.fFields.fCapacity = capacity;
4623 UnicodeString::operator= (char16_t ch)
4624 {
return doReplace(0, length(), &ch, 0, 1); }
4628 {
return replace(0, length(), ch); }
4636 return doReplace(0, length(), srcText, srcStart, srcLength);
4644 srcText.pinIndex(srcStart);
4645 return doReplace(0, length(), srcText, srcStart, srcText.
length() - srcStart);
4651 return copyFrom(srcText);
4655 UnicodeString::setTo(
const char16_t *srcChars,
4659 return doReplace(0, length(), srcChars, 0, srcLength);
4663 UnicodeString::setTo(char16_t srcChar)
4666 return doReplace(0, length(), &srcChar, 0, 1);
4673 return replace(0, length(), srcChar);
4680 {
return doAppend(srcText, srcStart, srcLength); }
4684 {
return doAppend(srcText, 0, srcText.
length()); }
4687 UnicodeString::append(
const char16_t *srcChars,
4690 {
return doAppend(srcChars, srcStart, srcLength); }
4695 {
return doAppend(srcChars, 0, srcLength); }
4698 UnicodeString::append(char16_t srcChar)
4699 {
return doAppend(&srcChar, 0, 1); }
4702 UnicodeString::operator+= (char16_t ch)
4703 {
return doAppend(&ch, 0, 1); }
4712 {
return doAppend(srcText, 0, srcText.
length()); }
4715 UnicodeString::insert(int32_t start,
4719 {
return doReplace(start, 0, srcText, srcStart, srcLength); }
4722 UnicodeString::insert(int32_t start,
4724 {
return doReplace(start, 0, srcText, 0, srcText.
length()); }
4727 UnicodeString::insert(int32_t start,
4728 const char16_t *srcChars,
4731 {
return doReplace(start, 0, srcChars, srcStart, srcLength); }
4734 UnicodeString::insert(int32_t start,
4737 {
return doReplace(start, 0, srcChars, 0, srcLength); }
4740 UnicodeString::insert(int32_t start,
4742 {
return doReplace(start, 0, &srcChar, 0, 1); }
4745 UnicodeString::insert(int32_t start,
4747 {
return replace(start, 0, srcChar); }
4751 UnicodeString::remove()
4763 UnicodeString::remove(int32_t start,
4766 if(start <= 0 && _length ==
INT32_MAX) {
4770 return doReplace(start, _length,
NULL, 0, 0);
4774 UnicodeString::removeBetween(int32_t start,
4776 {
return doReplace(start, limit - start,
NULL, 0, 0); }
4779 UnicodeString::retainBetween(int32_t start, int32_t limit) {
4781 return doReplace(0, start,
NULL, 0, 0);
4785 UnicodeString::truncate(int32_t targetLength)
4787 if(isBogus() && targetLength == 0) {
4791 }
else if((uint32_t)targetLength < (uint32_t)length()) {
4792 setLength(targetLength);
4800 UnicodeString::reverse()
4801 {
return doReverse(0, length()); }
4804 UnicodeString::reverse(int32_t start,
4806 {
return doReverse(start, _length); }
#define UNISTR_OBJECT_SIZE
Desired sizeof(UnicodeString) in bytes.
An Appendable implementation which writes to a UnicodeString.
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.