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 397 inline int8_t compare(int32_t start,
418 inline int8_t compare(int32_t start,
422 int32_t srcLength)
const;
437 int32_t srcLength)
const;
453 inline int8_t compare(int32_t start,
455 const char16_t *srcChars)
const;
474 inline int8_t compare(int32_t start,
476 const char16_t *srcChars,
478 int32_t srcLength)
const;
497 inline int8_t compareBetween(int32_t start,
501 int32_t srcLimit)
const;
520 inline int8_t compareCodePointOrder(
const UnicodeString& text)
const;
541 inline int8_t compareCodePointOrder(int32_t start,
566 inline int8_t compareCodePointOrder(int32_t start,
570 int32_t srcLength)
const;
591 int32_t srcLength)
const;
612 inline int8_t compareCodePointOrder(int32_t start,
614 const char16_t *srcChars)
const;
637 inline int8_t compareCodePointOrder(int32_t start,
639 const char16_t *srcChars,
641 int32_t srcLength)
const;
664 inline int8_t compareCodePointOrderBetween(int32_t start,
668 int32_t srcLimit)
const;
688 inline int8_t caseCompare(
const UnicodeString& text, uint32_t options)
const;
710 inline int8_t caseCompare(int32_t start,
713 uint32_t options)
const;
737 inline int8_t caseCompare(int32_t start,
742 uint32_t options)
const;
765 uint32_t options)
const;
787 inline int8_t caseCompare(int32_t start,
789 const char16_t *srcChars,
790 uint32_t options)
const;
814 inline int8_t caseCompare(int32_t start,
816 const char16_t *srcChars,
819 uint32_t options)
const;
843 inline int8_t caseCompareBetween(int32_t start,
848 uint32_t options)
const;
871 int32_t srcLength)
const;
882 int32_t srcLength)
const;
893 inline UBool startsWith(
const char16_t *srcChars,
895 int32_t srcLength)
const;
918 int32_t srcLength)
const;
929 int32_t srcLength)
const;
941 inline UBool endsWith(
const char16_t *srcChars,
943 int32_t srcLength)
const;
968 int32_t start)
const;
983 int32_t length)
const;
1005 int32_t length)
const;
1018 inline int32_t indexOf(
const char16_t *srcChars,
1020 int32_t start)
const;
1037 int32_t length)
const;
1055 int32_t indexOf(
const char16_t *srcChars,
1059 int32_t length)
const;
1068 inline int32_t indexOf(char16_t c)
const;
1078 inline int32_t indexOf(
UChar32 c)
const;
1088 inline int32_t indexOf(char16_t c,
1089 int32_t start)
const;
1100 inline int32_t indexOf(
UChar32 c,
1101 int32_t start)
const;
1113 inline int32_t indexOf(char16_t c,
1115 int32_t length)
const;
1128 inline int32_t indexOf(
UChar32 c,
1130 int32_t length)
const;
1140 inline int32_t lastIndexOf(
const UnicodeString& text)
const;
1152 int32_t start)
const;
1167 int32_t length)
const;
1189 int32_t length)
const;
1201 inline int32_t lastIndexOf(
const char16_t *srcChars,
1203 int32_t start)
const;
1220 int32_t length)
const;
1238 int32_t lastIndexOf(
const char16_t *srcChars,
1242 int32_t length)
const;
1251 inline int32_t lastIndexOf(char16_t c)
const;
1261 inline int32_t lastIndexOf(
UChar32 c)
const;
1271 inline int32_t lastIndexOf(char16_t c,
1272 int32_t start)
const;
1283 inline int32_t lastIndexOf(
UChar32 c,
1284 int32_t start)
const;
1296 inline int32_t lastIndexOf(char16_t c,
1298 int32_t length)
const;
1311 inline int32_t lastIndexOf(
UChar32 c,
1313 int32_t length)
const;
1326 inline char16_t
charAt(int32_t offset)
const;
1335 inline char16_t operator[] (int32_t offset)
const;
1365 int32_t getChar32Start(int32_t offset)
const;
1383 int32_t getChar32Limit(int32_t offset)
const;
1435 int32_t moveIndex32(int32_t index, int32_t delta)
const;
1454 inline void extract(int32_t start,
1457 int32_t dstStart = 0)
const;
1481 extract(
Char16Ptr dest, int32_t destCapacity,
1494 inline void extract(int32_t start,
1512 int32_t dstStart = 0)
const;
1548 int32_t extract(int32_t start,
1549 int32_t startLength,
1551 int32_t targetCapacity,
1554 #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION 1575 int32_t extract(int32_t start,
1576 int32_t startLength,
1578 uint32_t targetLength)
const;
1582 #if !UCONFIG_NO_CONVERSION 1609 inline int32_t extract(int32_t start,
1610 int32_t startLength,
1612 const char *codepage = 0)
const;
1643 int32_t extract(int32_t start,
1644 int32_t startLength,
1646 uint32_t targetLength,
1647 const char *codepage)
const;
1666 int32_t extract(
char *dest, int32_t destCapacity,
1724 template<
typename StringClass>
1758 inline int32_t
length(
void)
const;
1774 countChar32(int32_t start=0, int32_t length=
INT32_MAX)
const;
1800 hasMoreChar32Than(int32_t start, int32_t length, int32_t number)
const;
1807 inline UBool isEmpty(
void)
const;
1818 inline int32_t getCapacity(
void)
const;
1827 inline int32_t hashCode(
void)
const;
1841 inline UBool isBogus(
void)
const;
1906 return moveFrom(src);
2055 int32_t textLength);
2078 int32_t buffCapacity);
2280 const char16_t *srcChars,
2380 const char16_t *srcChars,
2498 virtual void copy(int32_t start, int32_t limit, int32_t dest);
2584 inline UnicodeString& removeBetween(int32_t start,
2596 inline UnicodeString &retainBetween(int32_t start, int32_t limit = INT32_MAX);
2611 UBool padLeading(int32_t targetLength,
2612 char16_t padChar = 0x0020);
2625 UBool padTrailing(int32_t targetLength,
2626 char16_t padChar = 0x0020);
2634 inline UBool truncate(int32_t targetLength);
2641 UnicodeString& trim(
void);
2651 inline UnicodeString& reverse(
void);
2661 inline UnicodeString& reverse(int32_t start,
2670 UnicodeString& toUpper(
void);
2679 UnicodeString& toUpper(
const Locale& locale);
2687 UnicodeString& toLower(
void);
2696 UnicodeString& toLower(
const Locale& locale);
2698 #if !UCONFIG_NO_BREAK_ITERATION 2805 UnicodeString &foldCase(uint32_t options=0 );
2854 char16_t *getBuffer(int32_t minCapacity);
2876 void releaseBuffer(int32_t newLength=-1);
2908 inline const char16_t *getBuffer()
const;
2943 const char16_t *getTerminatedBuffer();
2952 inline UnicodeString();
2965 UnicodeString(int32_t capacity,
UChar32 c, int32_t count);
3001 #if !U_CHAR16_IS_TYPEDEF 3016 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN) 3051 UnicodeString(
const char16_t *text,
3052 int32_t textLength);
3054 #if !U_CHAR16_IS_TYPEDEF 3066 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN) 3086 inline UnicodeString(
const std::nullptr_t text, int32_t length);
3110 UnicodeString(
UBool isTerminated,
3112 int32_t textLength);
3132 UnicodeString(char16_t *buffer, int32_t buffLength, int32_t buffCapacity);
3134 #if !U_CHAR16_IS_TYPEDEF 3144 UnicodeString(
Char16Ptr(buffer), buffLength, buffCapacity) {}
3147 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN) 3158 UnicodeString(
Char16Ptr(buffer), buffLength, buffCapacity) {}
3169 inline UnicodeString(std::nullptr_t buffer, int32_t buffLength, int32_t buffCapacity);
3171 #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION 3202 UnicodeString(
const char *codepageData, int32_t dataLength);
3206 #if !UCONFIG_NO_CONVERSION 3225 UnicodeString(
const char *codepageData,
const char *codepage);
3244 UnicodeString(
const char *codepageData, int32_t dataLength,
const char *codepage);
3268 const char *src, int32_t srcLength,
3298 UnicodeString(
const char *src, int32_t length,
enum EInvariant inv);
3317 UnicodeString(
const UnicodeString& that);
3325 UnicodeString(UnicodeString &&src)
U_NOEXCEPT;
3333 UnicodeString(
const UnicodeString& src, int32_t srcStart);
3342 UnicodeString(
const UnicodeString& src, int32_t srcStart, int32_t srcLength);
3365 virtual ~UnicodeString();
3393 static UnicodeString fromUTF32(
const UChar32 *utf32, int32_t length);
3431 UnicodeString unescape()
const;
3452 UChar32 unescapeAt(int32_t &offset)
const;
3459 static UClassID U_EXPORT2 getStaticClassID();
3484 virtual char16_t
getCharAt(int32_t offset)
const;
3502 toUTF8(int32_t start, int32_t len,
3503 char *target, int32_t capacity)
const;
3509 UBool doEquals(
const UnicodeString &text, int32_t len)
const;
3512 doCompare(int32_t start,
3514 const UnicodeString& srcText,
3516 int32_t srcLength)
const;
3518 int8_t doCompare(int32_t start,
3520 const char16_t *srcChars,
3522 int32_t srcLength)
const;
3525 doCompareCodePointOrder(int32_t start,
3527 const UnicodeString& srcText,
3529 int32_t srcLength)
const;
3531 int8_t doCompareCodePointOrder(int32_t start,
3533 const char16_t *srcChars,
3535 int32_t srcLength)
const;
3538 doCaseCompare(int32_t start,
3540 const UnicodeString &srcText,
3543 uint32_t options)
const;
3546 doCaseCompare(int32_t start,
3548 const char16_t *srcChars,
3551 uint32_t options)
const;
3553 int32_t doIndexOf(char16_t c,
3555 int32_t length)
const;
3559 int32_t length)
const;
3561 int32_t doLastIndexOf(char16_t c,
3563 int32_t length)
const;
3565 int32_t doLastIndexOf(
UChar32 c,
3567 int32_t length)
const;
3569 void doExtract(int32_t start,
3572 int32_t dstStart)
const;
3574 inline void doExtract(int32_t start,
3576 UnicodeString& target)
const;
3578 inline char16_t doCharAt(int32_t offset)
const;
3580 UnicodeString& doReplace(int32_t start,
3582 const UnicodeString& srcText,
3586 UnicodeString& doReplace(int32_t start,
3588 const char16_t *srcChars,
3592 UnicodeString& doAppend(
const UnicodeString& src, int32_t srcStart, int32_t srcLength);
3593 UnicodeString& doAppend(
const char16_t *srcChars, int32_t srcStart, int32_t srcLength);
3595 UnicodeString& doReverse(int32_t start,
3599 int32_t doHashCode(
void)
const;
3603 inline char16_t* getArrayStart(
void);
3604 inline const char16_t* getArrayStart(
void)
const;
3606 inline UBool hasShortLength()
const;
3607 inline int32_t getShortLength()
const;
3611 inline UBool isWritable()
const;
3614 inline UBool isBufferWritable()
const;
3617 inline void setZeroLength();
3618 inline void setShortLength(int32_t len);
3619 inline void setLength(int32_t len);
3620 inline void setToEmpty();
3621 inline void setArray(char16_t *array, int32_t len, int32_t capacity);
3628 UBool allocate(int32_t capacity);
3631 void releaseArray(
void);
3637 UnicodeString ©From(
const UnicodeString &src,
UBool fastCopy=
FALSE);
3640 void copyFieldsFrom(UnicodeString &src,
UBool setSrcToBogus)
U_NOEXCEPT;
3643 inline void pinIndex(int32_t& start)
const;
3644 inline void pinIndices(int32_t& start,
3645 int32_t& length)
const;
3647 #if !UCONFIG_NO_CONVERSION 3650 int32_t doExtract(int32_t start, int32_t length,
3651 char *dest, int32_t destCapacity,
3665 void doCodepageCreate(
const char *codepageData,
3667 const char *codepage);
3674 doCodepageCreate(
const char *codepageData,
3692 UBool cloneArrayIfNeeded(int32_t newCapacity = -1,
3693 int32_t growCapacity = -1,
3695 int32_t **pBufferToDelete = 0,
3704 caseMap(int32_t caseLocale, uint32_t options,
3712 int32_t removeRef(
void);
3713 int32_t refCount(
void)
const;
3723 kInvalidUChar=0xffff,
3729 kUsingStackBuffer=2,
3731 kBufferIsReadonly=8,
3734 kAllStorageFlags=0x1f,
3737 kLength1=1<<kLengthShift,
3738 kMaxShortLength=0x3ff,
3739 kLengthIsLarge=0xffe0,
3742 kShortString=kUsingStackBuffer,
3743 kLongString=kRefCounted,
3744 kReadonlyAlias=kBufferIsReadonly,
3750 union StackBufferOrFields;
3751 friend union StackBufferOrFields;
3794 union StackBufferOrFields {
3798 int16_t fLengthAndFlags;
3799 char16_t fBuffer[US_STACKBUF_SIZE];
3802 int16_t fLengthAndFlags;
3832 UnicodeString::pinIndex(int32_t& start)
const 3837 }
else if(start > length()) {
3843 UnicodeString::pinIndices(int32_t& start,
3844 int32_t& _length)
const 3847 int32_t len = length();
3850 }
else if(start > len) {
3855 }
else if(_length > (len - start)) {
3856 _length = (len - start);
3861 UnicodeString::getArrayStart() {
3862 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3863 fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
3866 inline const char16_t*
3867 UnicodeString::getArrayStart()
const {
3868 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3869 fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
3877 UnicodeString::UnicodeString() {
3878 fUnion.fStackFields.fLengthAndFlags=kShortString;
3881 inline UnicodeString::UnicodeString(
const std::nullptr_t ) {
3882 fUnion.fStackFields.fLengthAndFlags=kShortString;
3885 inline UnicodeString::UnicodeString(
const std::nullptr_t , int32_t ) {
3886 fUnion.fStackFields.fLengthAndFlags=kShortString;
3889 inline UnicodeString::UnicodeString(std::nullptr_t , int32_t , int32_t ) {
3890 fUnion.fStackFields.fLengthAndFlags=kShortString;
3897 UnicodeString::hasShortLength()
const {
3898 return fUnion.fFields.fLengthAndFlags>=0;
3902 UnicodeString::getShortLength()
const {
3905 return fUnion.fFields.fLengthAndFlags>>kLengthShift;
3909 UnicodeString::length()
const {
3910 return hasShortLength() ? getShortLength() : fUnion.fFields.fLength;
3914 UnicodeString::getCapacity()
const {
3915 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3916 US_STACKBUF_SIZE : fUnion.fFields.fCapacity;
3920 UnicodeString::hashCode()
const 3921 {
return doHashCode(); }
3924 UnicodeString::isBogus()
const 3925 {
return (
UBool)(fUnion.fFields.fLengthAndFlags & kIsBogus); }
3928 UnicodeString::isWritable()
const 3929 {
return (
UBool)!(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus)); }
3932 UnicodeString::isBufferWritable()
const 3935 !(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus|kBufferIsReadonly)) &&
3936 (!(fUnion.fFields.fLengthAndFlags&kRefCounted) || refCount()==1));
3939 inline const char16_t *
3940 UnicodeString::getBuffer()
const {
3941 if(fUnion.fFields.fLengthAndFlags&(kIsBogus|kOpenGetBuffer)) {
3943 }
else if(fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) {
3944 return fUnion.fStackFields.fBuffer;
3946 return fUnion.fFields.fArray;
3954 UnicodeString::doCompare(int32_t start,
3958 int32_t srcLength)
const 3961 return (int8_t)!isBogus();
3963 srcText.pinIndices(srcStart, srcLength);
3964 return doCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
3974 int32_t len = length(), textLength = text.
length();
3975 return !text.
isBogus() && len == textLength && doEquals(text, len);
3981 {
return (!
operator==(text)); }
3985 {
return doCompare(0, length(), text, 0, text.
length()) == 1; }
3989 {
return doCompare(0, length(), text, 0, text.
length()) == -1; }
3993 {
return doCompare(0, length(), text, 0, text.
length()) != -1; }
3997 {
return doCompare(0, length(), text, 0, text.
length()) != 1; }
4001 {
return doCompare(0, length(), text, 0, text.
length()); }
4004 UnicodeString::compare(int32_t start,
4007 {
return doCompare(start, _length, srcText, 0, srcText.
length()); }
4011 int32_t srcLength)
const 4012 {
return doCompare(0, length(), srcChars, 0, srcLength); }
4015 UnicodeString::compare(int32_t start,
4019 int32_t srcLength)
const 4020 {
return doCompare(start, _length, srcText, srcStart, srcLength); }
4023 UnicodeString::compare(int32_t start,
4025 const char16_t *srcChars)
const 4026 {
return doCompare(start, _length, srcChars, 0, _length); }
4029 UnicodeString::compare(int32_t start,
4031 const char16_t *srcChars,
4033 int32_t srcLength)
const 4034 {
return doCompare(start, _length, srcChars, srcStart, srcLength); }
4037 UnicodeString::compareBetween(int32_t start,
4041 int32_t srcLimit)
const 4042 {
return doCompare(start, limit - start,
4043 srcText, srcStart, srcLimit - srcStart); }
4046 UnicodeString::doCompareCodePointOrder(int32_t start,
4050 int32_t srcLength)
const 4053 return (int8_t)!isBogus();
4055 srcText.pinIndices(srcStart, srcLength);
4056 return doCompareCodePointOrder(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
4062 {
return doCompareCodePointOrder(0, length(), text, 0, text.
length()); }
4065 UnicodeString::compareCodePointOrder(int32_t start,
4068 {
return doCompareCodePointOrder(start, _length, srcText, 0, srcText.
length()); }
4072 int32_t srcLength)
const 4073 {
return doCompareCodePointOrder(0, length(), srcChars, 0, srcLength); }
4076 UnicodeString::compareCodePointOrder(int32_t start,
4080 int32_t srcLength)
const 4081 {
return doCompareCodePointOrder(start, _length, srcText, srcStart, srcLength); }
4084 UnicodeString::compareCodePointOrder(int32_t start,
4086 const char16_t *srcChars)
const 4087 {
return doCompareCodePointOrder(start, _length, srcChars, 0, _length); }
4090 UnicodeString::compareCodePointOrder(int32_t start,
4092 const char16_t *srcChars,
4094 int32_t srcLength)
const 4095 {
return doCompareCodePointOrder(start, _length, srcChars, srcStart, srcLength); }
4098 UnicodeString::compareCodePointOrderBetween(int32_t start,
4102 int32_t srcLimit)
const 4103 {
return doCompareCodePointOrder(start, limit - start,
4104 srcText, srcStart, srcLimit - srcStart); }
4107 UnicodeString::doCaseCompare(int32_t start,
4112 uint32_t options)
const 4115 return (int8_t)!isBogus();
4117 srcText.pinIndices(srcStart, srcLength);
4118 return doCaseCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength, options);
4124 return doCaseCompare(0, length(), text, 0, text.
length(), options);
4128 UnicodeString::caseCompare(int32_t start,
4131 uint32_t options)
const {
4132 return doCaseCompare(start, _length, srcText, 0, srcText.
length(), options);
4138 uint32_t options)
const {
4139 return doCaseCompare(0, length(), srcChars, 0, srcLength, options);
4143 UnicodeString::caseCompare(int32_t start,
4148 uint32_t options)
const {
4149 return doCaseCompare(start, _length, srcText, srcStart, srcLength, options);
4153 UnicodeString::caseCompare(int32_t start,
4155 const char16_t *srcChars,
4156 uint32_t options)
const {
4157 return doCaseCompare(start, _length, srcChars, 0, _length, options);
4161 UnicodeString::caseCompare(int32_t start,
4163 const char16_t *srcChars,
4166 uint32_t options)
const {
4167 return doCaseCompare(start, _length, srcChars, srcStart, srcLength, options);
4171 UnicodeString::caseCompareBetween(int32_t start,
4176 uint32_t options)
const {
4177 return doCaseCompare(start, limit - start, srcText, srcStart, srcLimit - srcStart, options);
4185 int32_t _length)
const 4188 srcText.pinIndices(srcStart, srcLength);
4190 return indexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
4198 {
return indexOf(text, 0, text.
length(), 0, length()); }
4202 int32_t start)
const {
4204 return indexOf(text, 0, text.
length(), start, length() - start);
4210 int32_t _length)
const 4211 {
return indexOf(text, 0, text.
length(), start, _length); }
4214 UnicodeString::indexOf(
const char16_t *srcChars,
4216 int32_t start)
const {
4218 return indexOf(srcChars, 0, srcLength, start, length() - start);
4225 int32_t _length)
const 4226 {
return indexOf(srcChars, 0, srcLength, start, _length); }
4229 UnicodeString::indexOf(char16_t c,
4231 int32_t _length)
const 4232 {
return doIndexOf(c, start, _length); }
4237 int32_t _length)
const 4238 {
return doIndexOf(c, start, _length); }
4241 UnicodeString::indexOf(char16_t c)
const 4242 {
return doIndexOf(c, 0, length()); }
4246 {
return indexOf(c, 0, length()); }
4249 UnicodeString::indexOf(char16_t c,
4250 int32_t start)
const {
4252 return doIndexOf(c, start, length() - start);
4257 int32_t start)
const {
4259 return indexOf(c, start, length() - start);
4266 int32_t _length)
const 4267 {
return lastIndexOf(srcChars, 0, srcLength, start, _length); }
4270 UnicodeString::lastIndexOf(
const char16_t *srcChars,
4272 int32_t start)
const {
4274 return lastIndexOf(srcChars, 0, srcLength, start, length() - start);
4282 int32_t _length)
const 4285 srcText.pinIndices(srcStart, srcLength);
4287 return lastIndexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
4296 int32_t _length)
const 4297 {
return lastIndexOf(text, 0, text.
length(), start, _length); }
4301 int32_t start)
const {
4303 return lastIndexOf(text, 0, text.
length(), start, length() - start);
4308 {
return lastIndexOf(text, 0, text.
length(), 0, length()); }
4311 UnicodeString::lastIndexOf(char16_t c,
4313 int32_t _length)
const 4314 {
return doLastIndexOf(c, start, _length); }
4319 int32_t _length)
const {
4320 return doLastIndexOf(c, start, _length);
4324 UnicodeString::lastIndexOf(char16_t c)
const 4325 {
return doLastIndexOf(c, 0, length()); }
4329 return lastIndexOf(c, 0, length());
4333 UnicodeString::lastIndexOf(char16_t c,
4334 int32_t start)
const {
4336 return doLastIndexOf(c, start, length() - start);
4341 int32_t start)
const {
4343 return lastIndexOf(c, start, length() - start);
4348 {
return compare(0, text.
length(), text, 0, text.
length()) == 0; }
4353 int32_t srcLength)
const 4354 {
return doCompare(0, srcLength, srcText, srcStart, srcLength) == 0; }
4361 return doCompare(0, srcLength, srcChars, 0, srcLength) == 0;
4365 UnicodeString::startsWith(
const char16_t *srcChars, int32_t srcStart, int32_t srcLength)
const {
4369 return doCompare(0, srcLength, srcChars, srcStart, srcLength) == 0;
4374 {
return doCompare(length() - text.
length(), text.
length(),
4375 text, 0, text.
length()) == 0; }
4380 int32_t srcLength)
const {
4381 srcText.pinIndices(srcStart, srcLength);
4382 return doCompare(length() - srcLength, srcLength,
4383 srcText, srcStart, srcLength) == 0;
4388 int32_t srcLength)
const {
4392 return doCompare(length() - srcLength, srcLength,
4393 srcChars, 0, srcLength) == 0;
4397 UnicodeString::endsWith(
const char16_t *srcChars,
4399 int32_t srcLength)
const {
4403 return doCompare(length() - srcLength, srcLength,
4404 srcChars, srcStart, srcLength) == 0;
4411 UnicodeString::replace(int32_t start,
4414 {
return doReplace(start, _length, srcText, 0, srcText.
length()); }
4417 UnicodeString::replace(int32_t start,
4422 {
return doReplace(start, _length, srcText, srcStart, srcLength); }
4425 UnicodeString::replace(int32_t start,
4429 {
return doReplace(start, _length, srcChars, 0, srcLength); }
4432 UnicodeString::replace(int32_t start,
4434 const char16_t *srcChars,
4437 {
return doReplace(start, _length, srcChars, srcStart, srcLength); }
4440 UnicodeString::replace(int32_t start,
4443 {
return doReplace(start, _length, &srcChar, 0, 1); }
4446 UnicodeString::replaceBetween(int32_t start,
4449 {
return doReplace(start, limit - start, srcText, 0, srcText.
length()); }
4452 UnicodeString::replaceBetween(int32_t start,
4457 {
return doReplace(start, limit - start, srcText, srcStart, srcLimit - srcStart); }
4462 {
return findAndReplace(0, length(), oldText, 0, oldText.
length(),
4463 newText, 0, newText.
length()); }
4466 UnicodeString::findAndReplace(int32_t start,
4470 {
return findAndReplace(start, _length, oldText, 0, oldText.
length(),
4471 newText, 0, newText.
length()); }
4477 UnicodeString::doExtract(int32_t start,
4480 { target.
replace(0, target.
length(), *
this, start, _length); }
4483 UnicodeString::extract(int32_t start,
4486 int32_t targetStart)
const 4487 { doExtract(start, _length, target, targetStart); }
4490 UnicodeString::extract(int32_t start,
4493 { doExtract(start, _length, target); }
4495 #if !UCONFIG_NO_CONVERSION 4498 UnicodeString::extract(int32_t start,
4501 const char *codepage)
const 4505 return extract(start, _length, dst, dst!=0 ? 0xffffffff : 0, codepage);
4511 UnicodeString::extractBetween(int32_t start,
4514 int32_t dstStart)
const {
4517 doExtract(start, limit - start, dst, dstStart);
4521 UnicodeString::tempSubStringBetween(int32_t start, int32_t limit)
const {
4522 return tempSubString(start, limit - start);
4526 UnicodeString::doCharAt(int32_t offset)
const 4528 if((uint32_t)offset < (uint32_t)length()) {
4529 return getArrayStart()[offset];
4531 return kInvalidUChar;
4536 UnicodeString::charAt(int32_t offset)
const 4537 {
return doCharAt(offset); }
4540 UnicodeString::operator[] (int32_t offset)
const 4541 {
return doCharAt(offset); }
4544 UnicodeString::isEmpty()
const {
4546 return (fUnion.fFields.fLengthAndFlags>>kLengthShift) == 0;
4553 UnicodeString::setZeroLength() {
4554 fUnion.fFields.fLengthAndFlags &= kAllStorageFlags;
4558 UnicodeString::setShortLength(int32_t len) {
4560 fUnion.fFields.fLengthAndFlags =
4561 (int16_t)((fUnion.fFields.fLengthAndFlags & kAllStorageFlags) | (len << kLengthShift));
4565 UnicodeString::setLength(int32_t len) {
4566 if(len <= kMaxShortLength) {
4567 setShortLength(len);
4569 fUnion.fFields.fLengthAndFlags |= kLengthIsLarge;
4570 fUnion.fFields.fLength = len;
4575 UnicodeString::setToEmpty() {
4576 fUnion.fFields.fLengthAndFlags = kShortString;
4580 UnicodeString::setArray(char16_t *array, int32_t len, int32_t capacity) {
4582 fUnion.fFields.fArray = array;
4583 fUnion.fFields.fCapacity = capacity;
4587 UnicodeString::operator= (char16_t ch)
4588 {
return doReplace(0, length(), &ch, 0, 1); }
4592 {
return replace(0, length(), ch); }
4600 return doReplace(0, length(), srcText, srcStart, srcLength);
4608 srcText.pinIndex(srcStart);
4609 return doReplace(0, length(), srcText, srcStart, srcText.
length() - srcStart);
4615 return copyFrom(srcText);
4619 UnicodeString::setTo(
const char16_t *srcChars,
4623 return doReplace(0, length(), srcChars, 0, srcLength);
4627 UnicodeString::setTo(char16_t srcChar)
4630 return doReplace(0, length(), &srcChar, 0, 1);
4637 return replace(0, length(), srcChar);
4644 {
return doAppend(srcText, srcStart, srcLength); }
4648 {
return doAppend(srcText, 0, srcText.
length()); }
4651 UnicodeString::append(
const char16_t *srcChars,
4654 {
return doAppend(srcChars, srcStart, srcLength); }
4659 {
return doAppend(srcChars, 0, srcLength); }
4662 UnicodeString::append(char16_t srcChar)
4663 {
return doAppend(&srcChar, 0, 1); }
4666 UnicodeString::operator+= (char16_t ch)
4667 {
return doAppend(&ch, 0, 1); }
4676 {
return doAppend(srcText, 0, srcText.
length()); }
4679 UnicodeString::insert(int32_t start,
4683 {
return doReplace(start, 0, srcText, srcStart, srcLength); }
4686 UnicodeString::insert(int32_t start,
4688 {
return doReplace(start, 0, srcText, 0, srcText.
length()); }
4691 UnicodeString::insert(int32_t start,
4692 const char16_t *srcChars,
4695 {
return doReplace(start, 0, srcChars, srcStart, srcLength); }
4698 UnicodeString::insert(int32_t start,
4701 {
return doReplace(start, 0, srcChars, 0, srcLength); }
4704 UnicodeString::insert(int32_t start,
4706 {
return doReplace(start, 0, &srcChar, 0, 1); }
4709 UnicodeString::insert(int32_t start,
4711 {
return replace(start, 0, srcChar); }
4715 UnicodeString::remove()
4727 UnicodeString::remove(int32_t start,
4730 if(start <= 0 && _length ==
INT32_MAX) {
4734 return doReplace(start, _length,
NULL, 0, 0);
4738 UnicodeString::removeBetween(int32_t start,
4740 {
return doReplace(start, limit - start,
NULL, 0, 0); }
4743 UnicodeString::retainBetween(int32_t start, int32_t limit) {
4745 return doReplace(0, start,
NULL, 0, 0);
4749 UnicodeString::truncate(int32_t targetLength)
4751 if(isBogus() && targetLength == 0) {
4755 }
else if((uint32_t)targetLength < (uint32_t)length()) {
4756 setLength(targetLength);
4764 UnicodeString::reverse()
4765 {
return doReverse(0, length()); }
4768 UnicodeString::reverse(int32_t start,
4770 {
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 & operator=(UnicodeString &&src) U_NOEXCEPT
Move assignment operator; might leave src in bogus state.
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.
friend U_COMMON_API void swap(UnicodeString &s1, UnicodeString &s2) U_NOEXCEPT
Non-member UnicodeString swap function.
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.
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.
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.