37 class StringThreadTest;
39 #ifndef U_COMPARE_CODE_POINT_ORDER 46 #define U_COMPARE_CODE_POINT_ORDER 0x8000 62 #ifndef U_STRING_CASE_MAPPER_DEFINED 63 #define U_STRING_CASE_MAPPER_DEFINED 71 UChar *dest, int32_t destCapacity,
72 const UChar *src, int32_t srcLength,
81 class StringCharacterIterator;
82 class UnicodeStringAppendable;
96 #define US_INV icu::UnicodeString::kInvariant 115 #if defined(U_DECLARE_UTF16) 116 # define UNICODE_STRING(cs, _length) icu::UnicodeString(TRUE, (const UChar *)U_DECLARE_UTF16(cs), _length) 117 #elif U_SIZEOF_WCHAR_T==U_SIZEOF_UCHAR && (U_CHARSET_FAMILY==U_ASCII_FAMILY || (U_SIZEOF_UCHAR == 2 && defined(U_WCHAR_IS_UTF16))) 118 # define UNICODE_STRING(cs, _length) icu::UnicodeString(TRUE, (const UChar *)L ## cs, _length) 119 #elif U_SIZEOF_UCHAR==1 && U_CHARSET_FAMILY==U_ASCII_FAMILY 120 # define UNICODE_STRING(cs, _length) icu::UnicodeString(TRUE, (const UChar *)cs, _length) 122 # define UNICODE_STRING(cs, _length) icu::UnicodeString(cs, _length, US_INV) 138 #define UNICODE_STRING_SIMPLE(cs) UNICODE_STRING(cs, -1) 147 #ifndef UNISTR_FROM_CHAR_EXPLICIT 148 # if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION) 150 # define UNISTR_FROM_CHAR_EXPLICIT explicit 153 # define UNISTR_FROM_CHAR_EXPLICIT 167 #ifndef UNISTR_FROM_STRING_EXPLICIT 168 # if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION) 170 # define UNISTR_FROM_STRING_EXPLICIT explicit 173 # 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 inline 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;
3375 inline UBool isWritable()
const;
3378 inline UBool isBufferWritable()
const;
3381 inline void setLength(int32_t len);
3382 inline void setToEmpty();
3383 inline void setArray(
UChar *array, int32_t len, int32_t capacity);
3389 UBool allocate(int32_t capacity);
3392 void releaseArray(
void);
3401 inline void pinIndex(int32_t& start)
const;
3402 inline void pinIndices(int32_t& start,
3403 int32_t& length)
const;
3405 #if !UCONFIG_NO_CONVERSION 3408 int32_t doExtract(int32_t start, int32_t length,
3409 char *dest, int32_t destCapacity,
3423 void doCodepageCreate(
const char *codepageData,
3425 const char *codepage);
3432 doCodepageCreate(
const char *codepageData,
3450 UBool cloneArrayIfNeeded(int32_t newCapacity = -1,
3451 int32_t growCapacity = -1,
3453 int32_t **pBufferToDelete = 0,
3466 int32_t removeRef(
void);
3467 int32_t refCount(
void)
const;
3473 US_STACKBUF_SIZE=
sizeof(
void *)==4 ? 13 : 15,
3474 kInvalidUChar=0xffff,
3481 kUsingStackBuffer=2,
3483 kBufferIsReadonly=8,
3488 kShortString=kUsingStackBuffer,
3489 kLongString=kRefCounted,
3490 kReadonlyAlias=kBufferIsReadonly,
3494 friend class StringThreadTest;
3495 friend class UnicodeStringAppendable;
3497 union StackBufferOrFields;
3498 friend union StackBufferOrFields;
3535 union StackBufferOrFields {
3538 UChar fStackBuffer[8];
3545 UChar fRestOfStackBuffer[US_STACKBUF_SIZE-8];
3546 int8_t fShortLength;
3559 operator+ (
const UnicodeString &s1,
const UnicodeString &s2);
3570 UnicodeString::pinIndex(int32_t& start)
const 3575 }
else if(start > length()) {
3581 UnicodeString::pinIndices(int32_t& start,
3582 int32_t& _length)
const 3585 int32_t len = length();
3588 }
else if(start > len) {
3593 }
else if(_length > (len - start)) {
3594 _length = (len - start);
3599 UnicodeString::getArrayStart()
3600 {
return (fFlags&kUsingStackBuffer) ? fUnion.fStackBuffer : fUnion.fFields.fArray; }
3603 UnicodeString::getArrayStart()
const 3604 {
return (fFlags&kUsingStackBuffer) ? fUnion.fStackBuffer : fUnion.fFields.fArray; }
3610 UnicodeString::length()
const 3611 {
return fShortLength>=0 ? fShortLength : fUnion.fFields.fLength; }
3614 UnicodeString::getCapacity()
const 3615 {
return (fFlags&kUsingStackBuffer) ? US_STACKBUF_SIZE : fUnion.fFields.fCapacity; }
3618 UnicodeString::hashCode()
const 3619 {
return doHashCode(); }
3622 UnicodeString::isBogus()
const 3623 {
return (
UBool)(fFlags & kIsBogus); }
3626 UnicodeString::isWritable()
const 3627 {
return (
UBool)!(fFlags&(kOpenGetBuffer|kIsBogus)); }
3630 UnicodeString::isBufferWritable()
const 3633 !(fFlags&(kOpenGetBuffer|kIsBogus|kBufferIsReadonly)) &&
3634 (!(fFlags&kRefCounted) || refCount()==1));
3637 inline const UChar *
3638 UnicodeString::getBuffer()
const {
3639 if(fFlags&(kIsBogus|kOpenGetBuffer)) {
3641 }
else if(fFlags&kUsingStackBuffer) {
3642 return fUnion.fStackBuffer;
3644 return fUnion.fFields.fArray;
3652 UnicodeString::doCompare(int32_t start,
3656 int32_t srcLength)
const 3659 return (int8_t)!isBogus();
3661 srcText.pinIndices(srcStart, srcLength);
3662 return doCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
3672 int32_t len = length(), textLength = text.
length();
3673 return !text.
isBogus() && len == textLength && doEquals(text, len);
3679 {
return (!
operator==(text)); }
3683 {
return doCompare(0, length(), text, 0, text.
length()) == 1; }
3687 {
return doCompare(0, length(), text, 0, text.
length()) == -1; }
3691 {
return doCompare(0, length(), text, 0, text.
length()) != -1; }
3695 {
return doCompare(0, length(), text, 0, text.
length()) != 1; }
3699 {
return doCompare(0, length(), text, 0, text.
length()); }
3702 UnicodeString::compare(int32_t start,
3705 {
return doCompare(start, _length, srcText, 0, srcText.
length()); }
3708 UnicodeString::compare(
const UChar *srcChars,
3709 int32_t srcLength)
const 3710 {
return doCompare(0, length(), srcChars, 0, srcLength); }
3713 UnicodeString::compare(int32_t start,
3717 int32_t srcLength)
const 3718 {
return doCompare(start, _length, srcText, srcStart, srcLength); }
3721 UnicodeString::compare(int32_t start,
3723 const UChar *srcChars)
const 3724 {
return doCompare(start, _length, srcChars, 0, _length); }
3727 UnicodeString::compare(int32_t start,
3729 const UChar *srcChars,
3731 int32_t srcLength)
const 3732 {
return doCompare(start, _length, srcChars, srcStart, srcLength); }
3735 UnicodeString::compareBetween(int32_t start,
3739 int32_t srcLimit)
const 3740 {
return doCompare(start, limit - start,
3741 srcText, srcStart, srcLimit - srcStart); }
3744 UnicodeString::doCompareCodePointOrder(int32_t start,
3748 int32_t srcLength)
const 3751 return (int8_t)!isBogus();
3753 srcText.pinIndices(srcStart, srcLength);
3754 return doCompareCodePointOrder(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
3760 {
return doCompareCodePointOrder(0, length(), text, 0, text.
length()); }
3763 UnicodeString::compareCodePointOrder(int32_t start,
3766 {
return doCompareCodePointOrder(start, _length, srcText, 0, srcText.
length()); }
3769 UnicodeString::compareCodePointOrder(
const UChar *srcChars,
3770 int32_t srcLength)
const 3771 {
return doCompareCodePointOrder(0, length(), srcChars, 0, srcLength); }
3774 UnicodeString::compareCodePointOrder(int32_t start,
3778 int32_t srcLength)
const 3779 {
return doCompareCodePointOrder(start, _length, srcText, srcStart, srcLength); }
3782 UnicodeString::compareCodePointOrder(int32_t start,
3784 const UChar *srcChars)
const 3785 {
return doCompareCodePointOrder(start, _length, srcChars, 0, _length); }
3788 UnicodeString::compareCodePointOrder(int32_t start,
3790 const UChar *srcChars,
3792 int32_t srcLength)
const 3793 {
return doCompareCodePointOrder(start, _length, srcChars, srcStart, srcLength); }
3796 UnicodeString::compareCodePointOrderBetween(int32_t start,
3800 int32_t srcLimit)
const 3801 {
return doCompareCodePointOrder(start, limit - start,
3802 srcText, srcStart, srcLimit - srcStart); }
3805 UnicodeString::doCaseCompare(int32_t start,
3810 uint32_t options)
const 3813 return (int8_t)!isBogus();
3815 srcText.pinIndices(srcStart, srcLength);
3816 return doCaseCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength, options);
3822 return doCaseCompare(0, length(), text, 0, text.
length(), options);
3826 UnicodeString::caseCompare(int32_t start,
3829 uint32_t options)
const {
3830 return doCaseCompare(start, _length, srcText, 0, srcText.
length(), options);
3834 UnicodeString::caseCompare(
const UChar *srcChars,
3836 uint32_t options)
const {
3837 return doCaseCompare(0, length(), srcChars, 0, srcLength, options);
3841 UnicodeString::caseCompare(int32_t start,
3846 uint32_t options)
const {
3847 return doCaseCompare(start, _length, srcText, srcStart, srcLength, options);
3851 UnicodeString::caseCompare(int32_t start,
3853 const UChar *srcChars,
3854 uint32_t options)
const {
3855 return doCaseCompare(start, _length, srcChars, 0, _length, options);
3859 UnicodeString::caseCompare(int32_t start,
3861 const UChar *srcChars,
3864 uint32_t options)
const {
3865 return doCaseCompare(start, _length, srcChars, srcStart, srcLength, options);
3869 UnicodeString::caseCompareBetween(int32_t start,
3874 uint32_t options)
const {
3875 return doCaseCompare(start, limit - start, srcText, srcStart, srcLimit - srcStart, options);
3883 int32_t _length)
const 3886 srcText.pinIndices(srcStart, srcLength);
3888 return indexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
3896 {
return indexOf(text, 0, text.
length(), 0, length()); }
3900 int32_t start)
const {
3902 return indexOf(text, 0, text.
length(), start, length() - start);
3908 int32_t _length)
const 3909 {
return indexOf(text, 0, text.
length(), start, _length); }
3912 UnicodeString::indexOf(
const UChar *srcChars,
3914 int32_t start)
const {
3916 return indexOf(srcChars, 0, srcLength, start, length() - start);
3920 UnicodeString::indexOf(
const UChar *srcChars,
3923 int32_t _length)
const 3924 {
return indexOf(srcChars, 0, srcLength, start, _length); }
3929 int32_t _length)
const 3930 {
return doIndexOf(c, start, _length); }
3935 int32_t _length)
const 3936 {
return doIndexOf(c, start, _length); }
3940 {
return doIndexOf(c, 0, length()); }
3944 {
return indexOf(c, 0, length()); }
3948 int32_t start)
const {
3950 return doIndexOf(c, start, length() - start);
3955 int32_t start)
const {
3957 return indexOf(c, start, length() - start);
3961 UnicodeString::lastIndexOf(
const UChar *srcChars,
3964 int32_t _length)
const 3965 {
return lastIndexOf(srcChars, 0, srcLength, start, _length); }
3968 UnicodeString::lastIndexOf(
const UChar *srcChars,
3970 int32_t start)
const {
3972 return lastIndexOf(srcChars, 0, srcLength, start, length() - start);
3980 int32_t _length)
const 3983 srcText.pinIndices(srcStart, srcLength);
3985 return lastIndexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
3994 int32_t _length)
const 3995 {
return lastIndexOf(text, 0, text.
length(), start, _length); }
3999 int32_t start)
const {
4001 return lastIndexOf(text, 0, text.
length(), start, length() - start);
4006 {
return lastIndexOf(text, 0, text.
length(), 0, length()); }
4011 int32_t _length)
const 4012 {
return doLastIndexOf(c, start, _length); }
4017 int32_t _length)
const {
4018 return doLastIndexOf(c, start, _length);
4022 UnicodeString::lastIndexOf(
UChar c)
const 4023 {
return doLastIndexOf(c, 0, length()); }
4027 return lastIndexOf(c, 0, length());
4032 int32_t start)
const {
4034 return doLastIndexOf(c, start, length() - start);
4039 int32_t start)
const {
4041 return lastIndexOf(c, start, length() - start);
4046 {
return compare(0, text.
length(), text, 0, text.
length()) == 0; }
4051 int32_t srcLength)
const 4052 {
return doCompare(0, srcLength, srcText, srcStart, srcLength) == 0; }
4055 UnicodeString::startsWith(
const UChar *srcChars, int32_t srcLength)
const {
4059 return doCompare(0, srcLength, srcChars, 0, srcLength) == 0;
4063 UnicodeString::startsWith(
const UChar *srcChars, int32_t srcStart, int32_t srcLength)
const {
4067 return doCompare(0, srcLength, srcChars, srcStart, srcLength) == 0;
4072 {
return doCompare(length() - text.
length(), text.
length(),
4073 text, 0, text.
length()) == 0; }
4078 int32_t srcLength)
const {
4079 srcText.pinIndices(srcStart, srcLength);
4080 return doCompare(length() - srcLength, srcLength,
4081 srcText, srcStart, srcLength) == 0;
4085 UnicodeString::endsWith(
const UChar *srcChars,
4086 int32_t srcLength)
const {
4090 return doCompare(length() - srcLength, srcLength,
4091 srcChars, 0, srcLength) == 0;
4095 UnicodeString::endsWith(
const UChar *srcChars,
4097 int32_t srcLength)
const {
4099 srcLength =
u_strlen(srcChars + srcStart);
4101 return doCompare(length() - srcLength, srcLength,
4102 srcChars, srcStart, srcLength) == 0;
4109 UnicodeString::replace(int32_t start,
4112 {
return doReplace(start, _length, srcText, 0, srcText.
length()); }
4115 UnicodeString::replace(int32_t start,
4120 {
return doReplace(start, _length, srcText, srcStart, srcLength); }
4123 UnicodeString::replace(int32_t start,
4125 const UChar *srcChars,
4127 {
return doReplace(start, _length, srcChars, 0, srcLength); }
4130 UnicodeString::replace(int32_t start,
4132 const UChar *srcChars,
4135 {
return doReplace(start, _length, srcChars, srcStart, srcLength); }
4138 UnicodeString::replace(int32_t start,
4141 {
return doReplace(start, _length, &srcChar, 0, 1); }
4144 UnicodeString::replaceBetween(int32_t start,
4147 {
return doReplace(start, limit - start, srcText, 0, srcText.
length()); }
4150 UnicodeString::replaceBetween(int32_t start,
4155 {
return doReplace(start, limit - start, srcText, srcStart, srcLimit - srcStart); }
4160 {
return findAndReplace(0, length(), oldText, 0, oldText.
length(),
4161 newText, 0, newText.
length()); }
4164 UnicodeString::findAndReplace(int32_t start,
4168 {
return findAndReplace(start, _length, oldText, 0, oldText.
length(),
4169 newText, 0, newText.
length()); }
4175 UnicodeString::doExtract(int32_t start,
4178 { target.
replace(0, target.
length(), *
this, start, _length); }
4181 UnicodeString::extract(int32_t start,
4184 int32_t targetStart)
const 4185 { doExtract(start, _length, target, targetStart); }
4188 UnicodeString::extract(int32_t start,
4191 { doExtract(start, _length, target); }
4193 #if !UCONFIG_NO_CONVERSION 4196 UnicodeString::extract(int32_t start,
4199 const char *codepage)
const 4203 return extract(start, _length, dst, dst!=0 ? 0xffffffff : 0, codepage);
4209 UnicodeString::extractBetween(int32_t start,
4212 int32_t dstStart)
const {
4215 doExtract(start, limit - start, dst, dstStart);
4219 UnicodeString::tempSubStringBetween(int32_t start, int32_t limit)
const {
4220 return tempSubString(start, limit - start);
4224 UnicodeString::doCharAt(int32_t offset)
const 4226 if((uint32_t)offset < (uint32_t)length()) {
4227 return getArrayStart()[offset];
4229 return kInvalidUChar;
4234 UnicodeString::charAt(int32_t offset)
const 4235 {
return doCharAt(offset); }
4238 UnicodeString::operator[] (int32_t offset)
const 4239 {
return doCharAt(offset); }
4242 UnicodeString::isEmpty()
const {
4243 return fShortLength == 0;
4250 UnicodeString::setLength(int32_t len) {
4252 fShortLength = (int8_t)len;
4254 fShortLength = (int8_t)-1;
4255 fUnion.fFields.fLength = len;
4260 UnicodeString::setToEmpty() {
4262 fFlags = kShortString;
4266 UnicodeString::setArray(
UChar *array, int32_t len, int32_t capacity) {
4268 fUnion.fFields.fArray = array;
4269 fUnion.fFields.fCapacity = capacity;
4272 inline const UChar *
4273 UnicodeString::getTerminatedBuffer() {
4277 UChar *array = getArrayStart();
4278 int32_t len = length();
4279 if(len < getCapacity() && ((fFlags&kRefCounted) == 0 || refCount() == 1)) {
4286 if(!(fFlags&kBufferIsReadonly)) {
4304 }
else if(cloneArrayIfNeeded(len+1)) {
4305 array = getArrayStart();
4316 {
return doReplace(0, length(), &ch, 0, 1); }
4320 {
return replace(0, length(), ch); }
4328 return doReplace(0, length(), srcText, srcStart, srcLength);
4336 srcText.pinIndex(srcStart);
4337 return doReplace(0, length(), srcText, srcStart, srcText.
length() - srcStart);
4343 return copyFrom(srcText);
4347 UnicodeString::setTo(
const UChar *srcChars,
4351 return doReplace(0, length(), srcChars, 0, srcLength);
4358 return doReplace(0, length(), &srcChar, 0, 1);
4365 return replace(0, length(), srcChar);
4372 {
return doReplace(length(), 0, srcText, srcStart, srcLength); }
4376 {
return doReplace(length(), 0, srcText, 0, srcText.
length()); }
4379 UnicodeString::append(
const UChar *srcChars,
4382 {
return doReplace(length(), 0, srcChars, srcStart, srcLength); }
4385 UnicodeString::append(
const UChar *srcChars,
4387 {
return doReplace(length(), 0, srcChars, 0, srcLength); }
4391 {
return doReplace(length(), 0, &srcChar, 0, 1); }
4395 {
return doReplace(length(), 0, &ch, 0, 1); }
4404 {
return doReplace(length(), 0, srcText, 0, srcText.
length()); }
4407 UnicodeString::insert(int32_t start,
4411 {
return doReplace(start, 0, srcText, srcStart, srcLength); }
4414 UnicodeString::insert(int32_t start,
4416 {
return doReplace(start, 0, srcText, 0, srcText.
length()); }
4419 UnicodeString::insert(int32_t start,
4420 const UChar *srcChars,
4423 {
return doReplace(start, 0, srcChars, srcStart, srcLength); }
4426 UnicodeString::insert(int32_t start,
4427 const UChar *srcChars,
4429 {
return doReplace(start, 0, srcChars, 0, srcLength); }
4432 UnicodeString::insert(int32_t start,
4434 {
return doReplace(start, 0, &srcChar, 0, 1); }
4437 UnicodeString::insert(int32_t start,
4439 {
return replace(start, 0, srcChar); }
4443 UnicodeString::remove()
4448 if(fFlags & (kIsBogus|kBufferIsReadonly)) {
4457 UnicodeString::remove(int32_t start,
4460 if(start <= 0 && _length ==
INT32_MAX) {
4464 return doReplace(start, _length,
NULL, 0, 0);
4468 UnicodeString::removeBetween(int32_t start,
4470 {
return doReplace(start, limit - start,
NULL, 0, 0); }
4473 UnicodeString::retainBetween(int32_t start, int32_t limit) {
4475 return doReplace(0, start,
NULL, 0, 0);
4479 UnicodeString::truncate(int32_t targetLength)
4481 if(isBogus() && targetLength == 0) {
4485 }
else if((uint32_t)targetLength < (uint32_t)length()) {
4486 setLength(targetLength);
4487 if(fFlags&kBufferIsReadonly) {
4488 fUnion.fFields.fCapacity = targetLength;
4497 UnicodeString::reverse()
4498 {
return doReverse(0, length()); }
4501 UnicodeString::reverse(int32_t start,
4503 {
return doReverse(start, _length); }
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.
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 ...
virtual UChar getCharAt(int32_t offset) const =0
Virtual version of charAt().
virtual void copy(int32_t start, int32_t limit, int32_t dest)=0
Copies a substring of this object, retaining metadata.
virtual UClassID getDynamicClassID() const =0
ICU4C "poor man's RTTI", returns a UClassID for the actual ICU class.
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
struct UCaseMap UCaseMap
C typedef for struct UCaseMap.
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.
virtual UChar32 getChar32At(int32_t offset) const =0
Virtual version of char32At().
UBool isBogus(void) const
Determine if this object contains a valid string.
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 0 for C++ and to ((void *)0) for C.
C++ API: Central ICU header for including the C++ standard <string> header and for related definition...
#define TRUE
The TRUE value of a UBool.
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.
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...
int32_t length(void) const
Return the length of the UnicodeString object.
UChar charAt(int32_t offset) const
Returns the 16-bit code unit at the given offset into the text.
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".
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.
A Locale object represents a specific geographical, political, or cultural region.
C++ API: Replaceable String.