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;
3633 UnicodeString::UnicodeString() {
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;
3653 UnicodeString::length()
const {
3654 return hasShortLength() ? getShortLength() : fUnion.fFields.fLength;
3658 UnicodeString::getCapacity()
const {
3659 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3660 US_STACKBUF_SIZE : fUnion.fFields.fCapacity;
3664 UnicodeString::hashCode()
const
3665 {
return doHashCode(); }
3668 UnicodeString::isBogus()
const
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 *
3684 UnicodeString::getBuffer()
const {
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()); }
3748 UnicodeString::compare(int32_t start,
3751 {
return doCompare(start, _length, srcText, 0, srcText.
length()); }
3754 UnicodeString::compare(
const UChar *srcChars,
3755 int32_t srcLength)
const
3756 {
return doCompare(0,
length(), srcChars, 0, srcLength); }
3759 UnicodeString::compare(int32_t start,
3763 int32_t srcLength)
const
3764 {
return doCompare(start, _length, srcText, srcStart, srcLength); }
3767 UnicodeString::compare(int32_t start,
3769 const UChar *srcChars)
const
3770 {
return doCompare(start, _length, srcChars, 0, _length); }
3773 UnicodeString::compare(int32_t start,
3775 const UChar *srcChars,
3777 int32_t srcLength)
const
3778 {
return doCompare(start, _length, srcChars, srcStart, srcLength); }
3781 UnicodeString::compareBetween(int32_t start,
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()); }
3809 UnicodeString::compareCodePointOrder(int32_t start,
3812 {
return doCompareCodePointOrder(start, _length, srcText, 0, srcText.
length()); }
3815 UnicodeString::compareCodePointOrder(
const UChar *srcChars,
3816 int32_t srcLength)
const
3817 {
return doCompareCodePointOrder(0,
length(), srcChars, 0, srcLength); }
3820 UnicodeString::compareCodePointOrder(int32_t start,
3824 int32_t srcLength)
const
3825 {
return doCompareCodePointOrder(start, _length, srcText, srcStart, srcLength); }
3828 UnicodeString::compareCodePointOrder(int32_t start,
3830 const UChar *srcChars)
const
3831 {
return doCompareCodePointOrder(start, _length, srcChars, 0, _length); }
3834 UnicodeString::compareCodePointOrder(int32_t start,
3836 const UChar *srcChars,
3838 int32_t srcLength)
const
3839 {
return doCompareCodePointOrder(start, _length, srcChars, srcStart, srcLength); }
3842 UnicodeString::compareCodePointOrderBetween(int32_t start,
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);
3872 UnicodeString::caseCompare(int32_t start,
3875 uint32_t options)
const {
3876 return doCaseCompare(start, _length, srcText, 0, srcText.
length(), options);
3880 UnicodeString::caseCompare(
const UChar *srcChars,
3882 uint32_t options)
const {
3883 return doCaseCompare(0,
length(), srcChars, 0, srcLength, options);
3887 UnicodeString::caseCompare(int32_t start,
3892 uint32_t options)
const {
3893 return doCaseCompare(start, _length, srcText, srcStart, srcLength, options);
3897 UnicodeString::caseCompare(int32_t start,
3899 const UChar *srcChars,
3900 uint32_t options)
const {
3901 return doCaseCompare(start, _length, srcChars, 0, _length, options);
3905 UnicodeString::caseCompare(int32_t start,
3907 const UChar *srcChars,
3910 uint32_t options)
const {
3911 return doCaseCompare(start, _length, srcChars, srcStart, srcLength, options);
3915 UnicodeString::caseCompareBetween(int32_t start,
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); }
3958 UnicodeString::indexOf(
const UChar *srcChars,
3960 int32_t start)
const {
3962 return indexOf(srcChars, 0, srcLength, start,
length() - start);
3966 UnicodeString::indexOf(
const UChar *srcChars,
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);
4007 UnicodeString::lastIndexOf(
const UChar *srcChars,
4010 int32_t _length)
const
4011 {
return lastIndexOf(srcChars, 0, srcLength, start, _length); }
4014 UnicodeString::lastIndexOf(
const UChar *srcChars,
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);
4068 UnicodeString::lastIndexOf(
UChar c)
const
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; }
4101 UnicodeString::startsWith(
const UChar *srcChars, int32_t srcLength)
const {
4105 return doCompare(0, srcLength, srcChars, 0, srcLength) == 0;
4109 UnicodeString::startsWith(
const UChar *srcChars, int32_t srcStart, int32_t srcLength)
const {
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;
4131 UnicodeString::endsWith(
const UChar *srcChars,
4132 int32_t srcLength)
const {
4136 return doCompare(
length() - srcLength, srcLength,
4137 srcChars, 0, srcLength) == 0;
4141 UnicodeString::endsWith(
const UChar *srcChars,
4143 int32_t srcLength)
const {
4145 srcLength =
u_strlen(srcChars + srcStart);
4147 return doCompare(
length() - srcLength, srcLength,
4148 srcChars, srcStart, srcLength) == 0;
4155 UnicodeString::replace(int32_t start,
4158 {
return doReplace(start, _length, srcText, 0, srcText.
length()); }
4161 UnicodeString::replace(int32_t start,
4166 {
return doReplace(start, _length, srcText, srcStart, srcLength); }
4169 UnicodeString::replace(int32_t start,
4171 const UChar *srcChars,
4173 {
return doReplace(start, _length, srcChars, 0, srcLength); }
4176 UnicodeString::replace(int32_t start,
4178 const UChar *srcChars,
4181 {
return doReplace(start, _length, srcChars, srcStart, srcLength); }
4184 UnicodeString::replace(int32_t start,
4187 {
return doReplace(start, _length, &srcChar, 0, 1); }
4190 UnicodeString::replaceBetween(int32_t start,
4193 {
return doReplace(start, limit - start, srcText, 0, srcText.
length()); }
4196 UnicodeString::replaceBetween(int32_t start,
4201 {
return doReplace(start, limit - start, srcText, srcStart, srcLimit - srcStart); }
4206 {
return findAndReplace(0,
length(), oldText, 0, oldText.
length(),
4207 newText, 0, newText.
length()); }
4210 UnicodeString::findAndReplace(int32_t start,
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); }
4227 UnicodeString::extract(int32_t start,
4230 int32_t targetStart)
const
4231 { doExtract(start, _length, target, targetStart); }
4234 UnicodeString::extract(int32_t start,
4237 { doExtract(start, _length, target); }
4239 #if !UCONFIG_NO_CONVERSION
4242 UnicodeString::extract(int32_t start,
4245 const char *codepage)
const
4249 return extract(start, _length, dst, dst!=0 ? 0xffffffff : 0, codepage);
4255 UnicodeString::extractBetween(int32_t start,
4258 int32_t dstStart)
const {
4261 doExtract(start, limit - start, dst, dstStart);
4265 UnicodeString::tempSubStringBetween(int32_t start, int32_t limit)
const {
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;
4280 UnicodeString::charAt(int32_t offset)
const
4281 {
return doCharAt(offset); }
4284 UnicodeString::operator[] (int32_t offset)
const
4285 {
return doCharAt(offset); }
4288 UnicodeString::isEmpty()
const {
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);
4363 UnicodeString::setTo(
const UChar *srcChars,
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()); }
4395 UnicodeString::append(
const UChar *srcChars,
4398 {
return doReplace(
length(), 0, srcChars, srcStart, srcLength); }
4401 UnicodeString::append(
const UChar *srcChars,
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()); }
4423 UnicodeString::insert(int32_t start,
4427 {
return doReplace(start, 0, srcText, srcStart, srcLength); }
4430 UnicodeString::insert(int32_t start,
4432 {
return doReplace(start, 0, srcText, 0, srcText.
length()); }
4435 UnicodeString::insert(int32_t start,
4436 const UChar *srcChars,
4439 {
return doReplace(start, 0, srcChars, srcStart, srcLength); }
4442 UnicodeString::insert(int32_t start,
4443 const UChar *srcChars,
4445 {
return doReplace(start, 0, srcChars, 0, srcLength); }
4448 UnicodeString::insert(int32_t start,
4450 {
return doReplace(start, 0, &srcChar, 0, 1); }
4453 UnicodeString::insert(int32_t start,
4455 {
return replace(start, 0, srcChar); }
4459 UnicodeString::remove()
4471 UnicodeString::remove(int32_t start,
4474 if(start <= 0 && _length ==
INT32_MAX) {
4478 return doReplace(start, _length,
NULL, 0, 0);
4482 UnicodeString::removeBetween(int32_t start,
4484 {
return doReplace(start, limit - start,
NULL, 0, 0); }
4487 UnicodeString::retainBetween(int32_t start, int32_t limit) {
4489 return doReplace(0, start,
NULL, 0, 0);
4493 UnicodeString::truncate(int32_t targetLength)
4495 if(isBogus() && targetLength == 0) {
4499 }
else if((uint32_t)targetLength < (uint32_t)
length()) {
4500 setLength(targetLength);
4508 UnicodeString::reverse()
4509 {
return doReverse(0,
length()); }
4512 UnicodeString::reverse(int32_t start,
4514 {
return doReverse(start, _length); }