37 class StringThreadTest;
39 #ifndef U_COMPARE_CODE_POINT_ORDER
46 #define U_COMPARE_CODE_POINT_ORDER 0x8000
61 #ifndef U_STRING_CASE_MAPPER_DEFINED
62 #define U_STRING_CASE_MAPPER_DEFINED
70 UChar *dest, int32_t destCapacity,
71 const UChar *src, int32_t srcLength,
80 class StringCharacterIterator;
81 class UnicodeStringAppendable;
95 #define US_INV icu::UnicodeString::kInvariant
114 #if defined(U_DECLARE_UTF16)
115 # define UNICODE_STRING(cs, _length) icu::UnicodeString(TRUE, (const UChar *)U_DECLARE_UTF16(cs), _length)
116 #elif U_SIZEOF_WCHAR_T==U_SIZEOF_UCHAR && (U_CHARSET_FAMILY==U_ASCII_FAMILY || (U_SIZEOF_UCHAR == 2 && defined(U_WCHAR_IS_UTF16)))
117 # define UNICODE_STRING(cs, _length) icu::UnicodeString(TRUE, (const UChar *)L ## cs, _length)
118 #elif U_SIZEOF_UCHAR==1 && U_CHARSET_FAMILY==U_ASCII_FAMILY
119 # define UNICODE_STRING(cs, _length) icu::UnicodeString(TRUE, (const UChar *)cs, _length)
121 # define UNICODE_STRING(cs, _length) icu::UnicodeString(cs, _length, US_INV)
137 #define UNICODE_STRING_SIMPLE(cs) UNICODE_STRING(cs, -1)
146 #ifndef UNISTR_FROM_CHAR_EXPLICIT
147 # if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION)
149 # define UNISTR_FROM_CHAR_EXPLICIT explicit
152 # define UNISTR_FROM_CHAR_EXPLICIT
166 #ifndef UNISTR_FROM_STRING_EXPLICIT
167 # if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION)
169 # define UNISTR_FROM_STRING_EXPLICIT explicit
172 # define UNISTR_FROM_STRING_EXPLICIT
353 inline int8_t compare(int32_t start,
374 inline int8_t compare(int32_t start,
378 int32_t srcLength)
const;
392 inline int8_t compare(
const UChar *srcChars,
393 int32_t srcLength)
const;
409 inline int8_t compare(int32_t start,
411 const UChar *srcChars)
const;
430 inline int8_t compare(int32_t start,
432 const UChar *srcChars,
434 int32_t srcLength)
const;
453 inline int8_t compareBetween(int32_t start,
457 int32_t srcLimit)
const;
476 inline int8_t compareCodePointOrder(
const UnicodeString& text)
const;
497 inline int8_t compareCodePointOrder(int32_t start,
522 inline int8_t compareCodePointOrder(int32_t start,
526 int32_t srcLength)
const;
546 inline int8_t compareCodePointOrder(
const UChar *srcChars,
547 int32_t srcLength)
const;
568 inline int8_t compareCodePointOrder(int32_t start,
570 const UChar *srcChars)
const;
593 inline int8_t compareCodePointOrder(int32_t start,
595 const UChar *srcChars,
597 int32_t srcLength)
const;
620 inline int8_t compareCodePointOrderBetween(int32_t start,
624 int32_t srcLimit)
const;
644 inline int8_t caseCompare(
const UnicodeString& text, uint32_t options)
const;
666 inline int8_t caseCompare(int32_t start,
669 uint32_t options)
const;
693 inline int8_t caseCompare(int32_t start,
698 uint32_t options)
const;
719 inline int8_t caseCompare(
const UChar *srcChars,
721 uint32_t options)
const;
743 inline int8_t caseCompare(int32_t start,
745 const UChar *srcChars,
746 uint32_t options)
const;
770 inline int8_t caseCompare(int32_t start,
772 const UChar *srcChars,
775 uint32_t options)
const;
799 inline int8_t caseCompareBetween(int32_t start,
804 uint32_t options)
const;
827 int32_t srcLength)
const;
837 inline UBool startsWith(
const UChar *srcChars,
838 int32_t srcLength)
const;
849 inline UBool startsWith(
const UChar *srcChars,
851 int32_t srcLength)
const;
874 int32_t srcLength)
const;
885 int32_t srcLength)
const;
899 int32_t srcLength)
const;
924 int32_t start)
const;
939 int32_t length)
const;
961 int32_t length)
const;
974 inline int32_t indexOf(
const UChar *srcChars,
976 int32_t start)
const;
990 inline int32_t indexOf(
const UChar *srcChars,
993 int32_t length)
const;
1011 int32_t indexOf(
const UChar *srcChars,
1015 int32_t length)
const;
1024 inline int32_t indexOf(
UChar c)
const;
1034 inline int32_t indexOf(
UChar32 c)
const;
1044 inline int32_t indexOf(
UChar c,
1045 int32_t start)
const;
1056 inline int32_t indexOf(
UChar32 c,
1057 int32_t start)
const;
1069 inline int32_t indexOf(
UChar c,
1071 int32_t length)
const;
1084 inline int32_t indexOf(
UChar32 c,
1086 int32_t length)
const;
1096 inline int32_t lastIndexOf(
const UnicodeString& text)
const;
1108 int32_t start)
const;
1123 int32_t length)
const;
1145 int32_t length)
const;
1157 inline int32_t lastIndexOf(
const UChar *srcChars,
1159 int32_t start)
const;
1173 inline int32_t lastIndexOf(
const UChar *srcChars,
1176 int32_t length)
const;
1194 int32_t lastIndexOf(
const UChar *srcChars,
1198 int32_t length)
const;
1207 inline int32_t lastIndexOf(
UChar c)
const;
1217 inline int32_t lastIndexOf(
UChar32 c)
const;
1227 inline int32_t lastIndexOf(
UChar c,
1228 int32_t start)
const;
1239 inline int32_t lastIndexOf(
UChar32 c,
1240 int32_t start)
const;
1252 inline int32_t lastIndexOf(
UChar c,
1254 int32_t length)
const;
1267 inline int32_t lastIndexOf(
UChar32 c,
1269 int32_t length)
const;
1291 inline UChar operator[] (int32_t offset)
const;
1321 int32_t getChar32Start(int32_t offset)
const;
1339 int32_t getChar32Limit(int32_t offset)
const;
1391 int32_t moveIndex32(int32_t index, int32_t delta)
const;
1410 inline void extract(int32_t start,
1413 int32_t dstStart = 0)
const;
1437 extract(
UChar *dest, int32_t destCapacity,
1450 inline void extract(int32_t start,
1468 int32_t dstStart = 0)
const;
1504 int32_t extract(int32_t start,
1505 int32_t startLength,
1507 int32_t targetCapacity,
1508 enum EInvariant inv)
const;
1510 #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
1531 int32_t extract(int32_t start,
1532 int32_t startLength,
1534 uint32_t targetLength)
const;
1538 #if !UCONFIG_NO_CONVERSION
1565 inline int32_t extract(int32_t start,
1566 int32_t startLength,
1568 const char *codepage = 0)
const;
1599 int32_t extract(int32_t start,
1600 int32_t startLength,
1602 uint32_t targetLength,
1603 const char *codepage)
const;
1622 int32_t extract(
char *dest, int32_t destCapacity,
1668 #if U_HAVE_STD_STRING
1682 template<
typename StringClass>
1718 inline int32_t
length(
void)
const;
1734 countChar32(int32_t start=0, int32_t length=
INT32_MAX)
const;
1760 hasMoreChar32Than(int32_t start, int32_t length, int32_t number)
const;
1767 inline UBool isEmpty(
void)
const;
1778 inline int32_t getCapacity(
void)
const;
1787 inline int32_t hashCode(
void)
const;
1801 inline UBool isBogus(
void)
const;
1958 int32_t textLength);
1981 int32_t buffCapacity);
2183 const UChar *srcChars,
2197 const UChar *srcChars,
2283 const UChar *srcChars,
2301 const UChar *srcChars,
2401 virtual void copy(int32_t start, int32_t limit, int32_t dest);
2514 UBool padLeading(int32_t targetLength,
2515 UChar padChar = 0x0020);
2528 UBool padTrailing(int32_t targetLength,
2529 UChar padChar = 0x0020);
2537 inline UBool truncate(int32_t targetLength);
2601 #if !UCONFIG_NO_BREAK_ITERATION
2757 UChar *getBuffer(int32_t minCapacity);
2779 void releaseBuffer(int32_t newLength=-1);
2811 inline const UChar *getBuffer()
const;
2846 const UChar *getTerminatedBuffer();
2912 int32_t textLength);
2938 int32_t textLength);
2960 #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
2991 UnicodeString(
const char *codepageData, int32_t dataLength);
2995 #if !UCONFIG_NO_CONVERSION
3014 UnicodeString(
const char *codepageData,
const char *codepage);
3033 UnicodeString(
const char *codepageData, int32_t dataLength,
const char *codepage);
3057 const char *src, int32_t srcLength,
3087 UnicodeString(
const char *src, int32_t length,
enum EInvariant inv);
3222 UChar32 unescapeAt(int32_t &offset)
const;
3229 static UClassID U_EXPORT2 getStaticClassID();
3272 toUTF8(int32_t start, int32_t len,
3273 char *target, int32_t capacity)
const;
3282 doCompare(int32_t start,
3286 int32_t srcLength)
const;
3288 int8_t doCompare(int32_t start,
3290 const UChar *srcChars,
3292 int32_t srcLength)
const;
3295 doCompareCodePointOrder(int32_t start,
3299 int32_t srcLength)
const;
3301 int8_t doCompareCodePointOrder(int32_t start,
3303 const UChar *srcChars,
3305 int32_t srcLength)
const;
3308 doCaseCompare(int32_t start,
3313 uint32_t options)
const;
3316 doCaseCompare(int32_t start,
3318 const UChar *srcChars,
3321 uint32_t options)
const;
3323 int32_t doIndexOf(
UChar c,
3325 int32_t length)
const;
3329 int32_t length)
const;
3331 int32_t doLastIndexOf(
UChar c,
3333 int32_t length)
const;
3335 int32_t doLastIndexOf(
UChar32 c,
3337 int32_t length)
const;
3339 void doExtract(int32_t start,
3342 int32_t dstStart)
const;
3344 inline void doExtract(int32_t start,
3348 inline UChar doCharAt(int32_t offset)
const;
3358 const UChar *srcChars,
3366 int32_t doHashCode(
void)
const;
3370 inline UChar* getArrayStart(
void);
3371 inline const UChar* getArrayStart(
void)
const;
3373 inline UBool hasShortLength()
const;
3374 inline int32_t getShortLength()
const;
3378 inline UBool isWritable()
const;
3381 inline UBool isBufferWritable()
const;
3384 inline void setZeroLength();
3385 inline void setShortLength(int32_t len);
3386 inline void setLength(int32_t len);
3387 inline void setToEmpty();
3388 inline void setArray(
UChar *array, int32_t len, int32_t capacity);
3395 UBool allocate(int32_t capacity);
3398 void releaseArray(
void);
3407 inline void pinIndex(int32_t& start)
const;
3408 inline void pinIndices(int32_t& start,
3409 int32_t& length)
const;
3411 #if !UCONFIG_NO_CONVERSION
3414 int32_t doExtract(int32_t start, int32_t length,
3415 char *dest, int32_t destCapacity,
3429 void doCodepageCreate(
const char *codepageData,
3431 const char *codepage);
3438 doCodepageCreate(
const char *codepageData,
3456 UBool cloneArrayIfNeeded(int32_t newCapacity = -1,
3457 int32_t growCapacity = -1,
3459 int32_t **pBufferToDelete = 0,
3472 int32_t removeRef(
void);
3473 int32_t refCount(
void)
const;
3479 US_STACKBUF_SIZE=
sizeof(
void *)==4 ? 13 : 15,
3480 kInvalidUChar=0xffff,
3487 kUsingStackBuffer=2,
3489 kBufferIsReadonly=8,
3492 kAllStorageFlags=0x1f,
3495 kLength1=1<<kLengthShift,
3496 kMaxShortLength=0x3ff,
3497 kLengthIsLarge=0xffe0,
3500 kShortString=kUsingStackBuffer,
3501 kLongString=kRefCounted,
3502 kReadonlyAlias=kBufferIsReadonly,
3506 friend class StringThreadTest;
3509 union StackBufferOrFields;
3510 friend union StackBufferOrFields;
3552 union StackBufferOrFields {
3556 int16_t fLengthAndFlags;
3557 UChar fBuffer[US_STACKBUF_SIZE];
3560 int16_t fLengthAndFlags;
3577 operator+ (
const UnicodeString &s1,
const UnicodeString &s2);
3588 UnicodeString::pinIndex(int32_t& start)
const
3593 }
else if(start >
length()) {
3599 UnicodeString::pinIndices(int32_t& start,
3600 int32_t& _length)
const
3606 }
else if(start > len) {
3611 }
else if(_length > (len - start)) {
3612 _length = (len - start);
3617 UnicodeString::getArrayStart() {
3618 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3619 fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
3623 UnicodeString::getArrayStart()
const {
3624 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3625 fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
3634 fUnion.fStackFields.fLengthAndFlags=kShortString;
3641 UnicodeString::hasShortLength()
const {
3642 return fUnion.fFields.fLengthAndFlags>=0;
3646 UnicodeString::getShortLength()
const {
3649 return fUnion.fFields.fLengthAndFlags>>kLengthShift;
3654 return hasShortLength() ? getShortLength() : fUnion.fFields.fLength;
3659 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3660 US_STACKBUF_SIZE : fUnion.fFields.fCapacity;
3665 {
return doHashCode(); }
3669 {
return (
UBool)(fUnion.fFields.fLengthAndFlags & kIsBogus); }
3672 UnicodeString::isWritable()
const
3673 {
return (
UBool)!(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus)); }
3676 UnicodeString::isBufferWritable()
const
3679 !(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus|kBufferIsReadonly)) &&
3680 (!(fUnion.fFields.fLengthAndFlags&kRefCounted) || refCount()==1));
3683 inline const UChar *
3685 if(fUnion.fFields.fLengthAndFlags&(kIsBogus|kOpenGetBuffer)) {
3687 }
else if(fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) {
3688 return fUnion.fStackFields.fBuffer;
3690 return fUnion.fFields.fArray;
3698 UnicodeString::doCompare(int32_t start,
3702 int32_t srcLength)
const
3705 return (int8_t)!isBogus();
3707 srcText.pinIndices(srcStart, srcLength);
3708 return doCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
3719 return !text.
isBogus() && len == textLength && doEquals(text, len);
3725 {
return (!
operator==(text)); }
3729 {
return doCompare(0,
length(), text, 0, text.
length()) == 1; }
3733 {
return doCompare(0,
length(), text, 0, text.
length()) == -1; }
3737 {
return doCompare(0,
length(), text, 0, text.
length()) != -1; }
3741 {
return doCompare(0,
length(), text, 0, text.
length()) != 1; }
3745 {
return doCompare(0,
length(), text, 0, text.
length()); }
3751 {
return doCompare(start, _length, srcText, 0, srcText.
length()); }
3755 int32_t srcLength)
const
3756 {
return doCompare(0,
length(), srcChars, 0, srcLength); }
3763 int32_t srcLength)
const
3764 {
return doCompare(start, _length, srcText, srcStart, srcLength); }
3769 const UChar *srcChars)
const
3770 {
return doCompare(start, _length, srcChars, 0, _length); }
3775 const UChar *srcChars,
3777 int32_t srcLength)
const
3778 {
return doCompare(start, _length, srcChars, srcStart, srcLength); }
3785 int32_t srcLimit)
const
3786 {
return doCompare(start, limit - start,
3787 srcText, srcStart, srcLimit - srcStart); }
3790 UnicodeString::doCompareCodePointOrder(int32_t start,
3794 int32_t srcLength)
const
3797 return (int8_t)!isBogus();
3799 srcText.pinIndices(srcStart, srcLength);
3800 return doCompareCodePointOrder(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
3806 {
return doCompareCodePointOrder(0,
length(), text, 0, text.
length()); }
3812 {
return doCompareCodePointOrder(start, _length, srcText, 0, srcText.
length()); }
3816 int32_t srcLength)
const
3817 {
return doCompareCodePointOrder(0,
length(), srcChars, 0, srcLength); }
3824 int32_t srcLength)
const
3825 {
return doCompareCodePointOrder(start, _length, srcText, srcStart, srcLength); }
3830 const UChar *srcChars)
const
3831 {
return doCompareCodePointOrder(start, _length, srcChars, 0, _length); }
3836 const UChar *srcChars,
3838 int32_t srcLength)
const
3839 {
return doCompareCodePointOrder(start, _length, srcChars, srcStart, srcLength); }
3846 int32_t srcLimit)
const
3847 {
return doCompareCodePointOrder(start, limit - start,
3848 srcText, srcStart, srcLimit - srcStart); }
3851 UnicodeString::doCaseCompare(int32_t start,
3856 uint32_t options)
const
3859 return (int8_t)!isBogus();
3861 srcText.pinIndices(srcStart, srcLength);
3862 return doCaseCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength, options);
3868 return doCaseCompare(0,
length(), text, 0, text.
length(), options);
3875 uint32_t options)
const {
3876 return doCaseCompare(start, _length, srcText, 0, srcText.
length(), options);
3882 uint32_t options)
const {
3883 return doCaseCompare(0,
length(), srcChars, 0, srcLength, options);
3892 uint32_t options)
const {
3893 return doCaseCompare(start, _length, srcText, srcStart, srcLength, options);
3899 const UChar *srcChars,
3900 uint32_t options)
const {
3901 return doCaseCompare(start, _length, srcChars, 0, _length, options);
3907 const UChar *srcChars,
3910 uint32_t options)
const {
3911 return doCaseCompare(start, _length, srcChars, srcStart, srcLength, options);
3920 uint32_t options)
const {
3921 return doCaseCompare(start, limit - start, srcText, srcStart, srcLimit - srcStart, options);
3929 int32_t _length)
const
3932 srcText.pinIndices(srcStart, srcLength);
3934 return indexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
3942 {
return indexOf(text, 0, text.
length(), 0,
length()); }
3946 int32_t start)
const {
3948 return indexOf(text, 0, text.
length(), start,
length() - start);
3954 int32_t _length)
const
3955 {
return indexOf(text, 0, text.
length(), start, _length); }
3960 int32_t start)
const {
3962 return indexOf(srcChars, 0, srcLength, start,
length() - start);
3969 int32_t _length)
const
3970 {
return indexOf(srcChars, 0, srcLength, start, _length); }
3975 int32_t _length)
const
3976 {
return doIndexOf(c, start, _length); }
3981 int32_t _length)
const
3982 {
return doIndexOf(c, start, _length); }
3986 {
return doIndexOf(c, 0,
length()); }
3990 {
return indexOf(c, 0,
length()); }
3994 int32_t start)
const {
3996 return doIndexOf(c, start,
length() - start);
4001 int32_t start)
const {
4003 return indexOf(c, start,
length() - start);
4010 int32_t _length)
const
4011 {
return lastIndexOf(srcChars, 0, srcLength, start, _length); }
4016 int32_t start)
const {
4018 return lastIndexOf(srcChars, 0, srcLength, start,
length() - start);
4026 int32_t _length)
const
4029 srcText.pinIndices(srcStart, srcLength);
4031 return lastIndexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
4040 int32_t _length)
const
4041 {
return lastIndexOf(text, 0, text.
length(), start, _length); }
4045 int32_t start)
const {
4047 return lastIndexOf(text, 0, text.
length(), start,
length() - start);
4052 {
return lastIndexOf(text, 0, text.
length(), 0,
length()); }
4057 int32_t _length)
const
4058 {
return doLastIndexOf(c, start, _length); }
4063 int32_t _length)
const {
4064 return doLastIndexOf(c, start, _length);
4069 {
return doLastIndexOf(c, 0,
length()); }
4073 return lastIndexOf(c, 0,
length());
4078 int32_t start)
const {
4080 return doLastIndexOf(c, start,
length() - start);
4085 int32_t start)
const {
4087 return lastIndexOf(c, start,
length() - start);
4092 {
return compare(0, text.
length(), text, 0, text.
length()) == 0; }
4097 int32_t srcLength)
const
4098 {
return doCompare(0, srcLength, srcText, srcStart, srcLength) == 0; }
4105 return doCompare(0, srcLength, srcChars, 0, srcLength) == 0;
4113 return doCompare(0, srcLength, srcChars, srcStart, srcLength) == 0;
4119 text, 0, text.
length()) == 0; }
4124 int32_t srcLength)
const {
4125 srcText.pinIndices(srcStart, srcLength);
4126 return doCompare(
length() - srcLength, srcLength,
4127 srcText, srcStart, srcLength) == 0;
4132 int32_t srcLength)
const {
4136 return doCompare(
length() - srcLength, srcLength,
4137 srcChars, 0, srcLength) == 0;
4143 int32_t srcLength)
const {
4145 srcLength =
u_strlen(srcChars + srcStart);
4147 return doCompare(
length() - srcLength, srcLength,
4148 srcChars, srcStart, srcLength) == 0;
4158 {
return doReplace(start, _length, srcText, 0, srcText.
length()); }
4166 {
return doReplace(start, _length, srcText, srcStart, srcLength); }
4171 const UChar *srcChars,
4173 {
return doReplace(start, _length, srcChars, 0, srcLength); }
4178 const UChar *srcChars,
4181 {
return doReplace(start, _length, srcChars, srcStart, srcLength); }
4187 {
return doReplace(start, _length, &srcChar, 0, 1); }
4193 {
return doReplace(start, limit - start, srcText, 0, srcText.
length()); }
4201 {
return doReplace(start, limit - start, srcText, srcStart, srcLimit - srcStart); }
4206 {
return findAndReplace(0,
length(), oldText, 0, oldText.
length(),
4207 newText, 0, newText.
length()); }
4214 {
return findAndReplace(start, _length, oldText, 0, oldText.
length(),
4215 newText, 0, newText.
length()); }
4221 UnicodeString::doExtract(int32_t start,
4224 { target.
replace(0, target.
length(), *
this, start, _length); }
4230 int32_t targetStart)
const
4231 { doExtract(start, _length, target, targetStart); }
4237 { doExtract(start, _length, target); }
4239 #if !UCONFIG_NO_CONVERSION
4245 const char *codepage)
const
4249 return extract(start, _length, dst, dst!=0 ? 0xffffffff : 0, codepage);
4258 int32_t dstStart)
const {
4261 doExtract(start, limit - start, dst, dstStart);
4266 return tempSubString(start, limit - start);
4270 UnicodeString::doCharAt(int32_t offset)
const
4272 if((uint32_t)offset < (uint32_t)
length()) {
4273 return getArrayStart()[offset];
4275 return kInvalidUChar;
4281 {
return doCharAt(offset); }
4285 {
return doCharAt(offset); }
4290 return (fUnion.fFields.fLengthAndFlags>>kLengthShift) == 0;
4297 UnicodeString::setZeroLength() {
4298 fUnion.fFields.fLengthAndFlags &= kAllStorageFlags;
4302 UnicodeString::setShortLength(int32_t len) {
4304 fUnion.fFields.fLengthAndFlags =
4305 (int16_t)((fUnion.fFields.fLengthAndFlags & kAllStorageFlags) | (len << kLengthShift));
4309 UnicodeString::setLength(int32_t len) {
4310 if(len <= kMaxShortLength) {
4311 setShortLength(len);
4313 fUnion.fFields.fLengthAndFlags |= kLengthIsLarge;
4314 fUnion.fFields.fLength = len;
4319 UnicodeString::setToEmpty() {
4320 fUnion.fFields.fLengthAndFlags = kShortString;
4324 UnicodeString::setArray(
UChar *array, int32_t len, int32_t capacity) {
4326 fUnion.fFields.fArray = array;
4327 fUnion.fFields.fCapacity = capacity;
4330 inline UnicodeString&
4332 {
return doReplace(0,
length(), &ch, 0, 1); }
4336 {
return replace(0,
length(), ch); }
4344 return doReplace(0,
length(), srcText, srcStart, srcLength);
4352 srcText.pinIndex(srcStart);
4353 return doReplace(0,
length(), srcText, srcStart, srcText.
length() - srcStart);
4359 return copyFrom(srcText);
4367 return doReplace(0,
length(), srcChars, 0, srcLength);
4374 return doReplace(0,
length(), &srcChar, 0, 1);
4381 return replace(0,
length(), srcChar);
4388 {
return doReplace(
length(), 0, srcText, srcStart, srcLength); }
4392 {
return doReplace(
length(), 0, srcText, 0, srcText.
length()); }
4398 {
return doReplace(
length(), 0, srcChars, srcStart, srcLength); }
4403 {
return doReplace(
length(), 0, srcChars, 0, srcLength); }
4407 {
return doReplace(
length(), 0, &srcChar, 0, 1); }
4411 {
return doReplace(
length(), 0, &ch, 0, 1); }
4420 {
return doReplace(
length(), 0, srcText, 0, srcText.
length()); }
4427 {
return doReplace(start, 0, srcText, srcStart, srcLength); }
4432 {
return doReplace(start, 0, srcText, 0, srcText.
length()); }
4436 const UChar *srcChars,
4439 {
return doReplace(start, 0, srcChars, srcStart, srcLength); }
4443 const UChar *srcChars,
4445 {
return doReplace(start, 0, srcChars, 0, srcLength); }
4450 {
return doReplace(start, 0, &srcChar, 0, 1); }
4455 {
return replace(start, 0, srcChar); }
4474 if(start <= 0 && _length ==
INT32_MAX) {
4478 return doReplace(start, _length,
NULL, 0, 0);
4484 {
return doReplace(start, limit - start,
NULL, 0, 0); }
4489 return doReplace(0, start,
NULL, 0, 0);
4495 if(isBogus() && targetLength == 0) {
4499 }
else if((uint32_t)targetLength < (uint32_t)
length()) {
4500 setLength(targetLength);
4509 {
return doReverse(0,
length()); }
4514 {
return doReverse(start, _length); }
UnicodeString & reverse(void)
Reverse this UnicodeString in place.
virtual Replaceable * clone() const
Clone this object, an instance of a subclass of Replaceable.
int32_t UStringCaseMapper(const UCaseMap *csm, UChar *dest, int32_t destCapacity, const UChar *src, int32_t srcLength, UErrorCode *pErrorCode)
Internal string case mapping function type.
UChar charAt(int32_t offset) const
Returns the 16-bit code unit at the given offset into the text.
UChar charAt(int32_t offset) const
Return the code unit at offset offset.
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.
C API: Unicode case mapping functions using a UCaseMap service object.
EInvariant
Constant to be used in the UnicodeString(char *, int32_t, EInvariant) constructor which constructs a ...
UChar operator[](int32_t offset) const
Return the code unit at offset offset.
virtual UChar getCharAt(int32_t offset) const =0
Virtual version of charAt().
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.
virtual UClassID getDynamicClassID() const
ICU4C "poor man's RTTI", returns a UClassID for the actual ICU class.
UBool operator<=(const UnicodeString &text) const
Less than or equal operator.
virtual UBool hasMetaData() const
Returns true if this object contains metadata.
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.
const UChar * getBuffer() const
Get a read-only pointer to the internal buffer.
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
struct UCaseMap UCaseMap
C typedef for struct UCaseMap.
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.
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.
virtual UChar32 getChar32At(int32_t offset) const =0
Virtual version of char32At().
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.
UnicodeString tempSubStringBetween(int32_t start, int32_t limit=INT32_MAX) const
Create a temporary substring for the specified range.
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.
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.
virtual int32_t getLength() const =0
Virtual version of length().
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.
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 0 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 header and for related definition...
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...
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
Define UChar to be UCHAR_TYPE, if that is #defined (for example, to char16_t), or wchar_t if that is ...
#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
void extractBetween(int32_t start, int32_t limit, UChar *dst, int32_t dstStart=0) const
Copy the characters in the range [start, limit) into the array dst, beginning at dstStart.
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.
void extract(int32_t start, int32_t length, UChar *dst, int32_t dstStart=0) const
Copy the characters in the range [start, start + length) into the array dst, beginning at dstStart...
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.
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...
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.
UnicodeString & operator+=(UChar ch)
Append operator.
#define U_STABLE
This is used to declare a function as a stable public ICU C API.
int8_t UBool
The ICU boolean type.
A Locale object represents a specific geographical, political, or cultural region.
C++ API: Replaceable String.