33 #if U_SHOW_CPLUSPLUS_API 54 #if !UCONFIG_NO_BREAK_ITERATION 73 char16_t *dest, int32_t destCapacity,
74 const char16_t *src, int32_t srcLength,
81 class StringCharacterIterator;
82 class UnicodeStringAppendable;
96 #define US_INV icu::UnicodeString::kInvariant 115 #if !U_CHAR16_IS_TYPEDEF 116 # define UNICODE_STRING(cs, _length) icu::UnicodeString(TRUE, u ## cs, _length) 118 # define UNICODE_STRING(cs, _length) icu::UnicodeString(TRUE, (const char16_t*)u ## cs, _length) 134 #define UNICODE_STRING_SIMPLE(cs) UNICODE_STRING(cs, -1) 143 #ifndef UNISTR_FROM_CHAR_EXPLICIT 144 # if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION) 146 # define UNISTR_FROM_CHAR_EXPLICIT explicit 149 # define UNISTR_FROM_CHAR_EXPLICIT 163 #ifndef UNISTR_FROM_STRING_EXPLICIT 164 # if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION) 166 # define UNISTR_FROM_STRING_EXPLICIT explicit 169 # define UNISTR_FROM_STRING_EXPLICIT 206 #ifndef UNISTR_OBJECT_SIZE 207 # define UNISTR_OBJECT_SIZE 64 402 inline int8_t compare(int32_t start,
423 inline int8_t compare(int32_t start,
427 int32_t srcLength)
const;
442 int32_t srcLength)
const;
458 inline int8_t compare(int32_t start,
460 const char16_t *srcChars)
const;
479 inline int8_t compare(int32_t start,
481 const char16_t *srcChars,
483 int32_t srcLength)
const;
502 inline int8_t compareBetween(int32_t start,
506 int32_t srcLimit)
const;
525 inline int8_t compareCodePointOrder(
const UnicodeString& text)
const;
546 inline int8_t compareCodePointOrder(int32_t start,
571 inline int8_t compareCodePointOrder(int32_t start,
575 int32_t srcLength)
const;
596 int32_t srcLength)
const;
617 inline int8_t compareCodePointOrder(int32_t start,
619 const char16_t *srcChars)
const;
642 inline int8_t compareCodePointOrder(int32_t start,
644 const char16_t *srcChars,
646 int32_t srcLength)
const;
669 inline int8_t compareCodePointOrderBetween(int32_t start,
673 int32_t srcLimit)
const;
693 inline int8_t caseCompare(
const UnicodeString& text, uint32_t options)
const;
715 inline int8_t caseCompare(int32_t start,
718 uint32_t options)
const;
742 inline int8_t caseCompare(int32_t start,
747 uint32_t options)
const;
770 uint32_t options)
const;
792 inline int8_t caseCompare(int32_t start,
794 const char16_t *srcChars,
795 uint32_t options)
const;
819 inline int8_t caseCompare(int32_t start,
821 const char16_t *srcChars,
824 uint32_t options)
const;
848 inline int8_t caseCompareBetween(int32_t start,
853 uint32_t options)
const;
876 int32_t srcLength)
const;
887 int32_t srcLength)
const;
898 inline UBool startsWith(
const char16_t *srcChars,
900 int32_t srcLength)
const;
923 int32_t srcLength)
const;
934 int32_t srcLength)
const;
946 inline UBool endsWith(
const char16_t *srcChars,
948 int32_t srcLength)
const;
973 int32_t start)
const;
988 int32_t length)
const;
1010 int32_t length)
const;
1023 inline int32_t indexOf(
const char16_t *srcChars,
1025 int32_t start)
const;
1042 int32_t length)
const;
1060 int32_t indexOf(
const char16_t *srcChars,
1064 int32_t length)
const;
1073 inline int32_t indexOf(char16_t c)
const;
1083 inline int32_t indexOf(
UChar32 c)
const;
1093 inline int32_t indexOf(char16_t c,
1094 int32_t start)
const;
1105 inline int32_t indexOf(
UChar32 c,
1106 int32_t start)
const;
1118 inline int32_t indexOf(char16_t c,
1120 int32_t length)
const;
1133 inline int32_t indexOf(
UChar32 c,
1135 int32_t length)
const;
1145 inline int32_t lastIndexOf(
const UnicodeString& text)
const;
1157 int32_t start)
const;
1172 int32_t length)
const;
1194 int32_t length)
const;
1206 inline int32_t lastIndexOf(
const char16_t *srcChars,
1208 int32_t start)
const;
1225 int32_t length)
const;
1243 int32_t lastIndexOf(
const char16_t *srcChars,
1247 int32_t length)
const;
1256 inline int32_t lastIndexOf(char16_t c)
const;
1266 inline int32_t lastIndexOf(
UChar32 c)
const;
1276 inline int32_t lastIndexOf(char16_t c,
1277 int32_t start)
const;
1288 inline int32_t lastIndexOf(
UChar32 c,
1289 int32_t start)
const;
1301 inline int32_t lastIndexOf(char16_t c,
1303 int32_t length)
const;
1316 inline int32_t lastIndexOf(
UChar32 c,
1318 int32_t length)
const;
1331 inline char16_t
charAt(int32_t offset)
const;
1340 inline char16_t operator[] (int32_t offset)
const;
1370 int32_t getChar32Start(int32_t offset)
const;
1388 int32_t getChar32Limit(int32_t offset)
const;
1440 int32_t moveIndex32(int32_t index, int32_t delta)
const;
1459 inline void extract(int32_t start,
1462 int32_t dstStart = 0)
const;
1486 extract(
Char16Ptr dest, int32_t destCapacity,
1498 inline void extract(int32_t start,
1516 int32_t dstStart = 0)
const;
1551 int32_t extract(int32_t start,
1552 int32_t startLength,
1554 int32_t targetCapacity,
1557 #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION 1578 int32_t extract(int32_t start,
1579 int32_t startLength,
1581 uint32_t targetLength)
const;
1585 #if !UCONFIG_NO_CONVERSION 1612 inline int32_t extract(int32_t start,
1613 int32_t startLength,
1615 const char *codepage = 0)
const;
1646 int32_t extract(int32_t start,
1647 int32_t startLength,
1649 uint32_t targetLength,
1650 const char *codepage)
const;
1669 int32_t extract(
char *dest, int32_t destCapacity,
1727 template<
typename StringClass>
1761 inline int32_t
length(
void)
const;
1777 countChar32(int32_t start=0, int32_t length=
INT32_MAX)
const;
1803 hasMoreChar32Than(int32_t start, int32_t length, int32_t number)
const;
1810 inline UBool isEmpty(
void)
const;
1821 inline int32_t getCapacity(
void)
const;
1830 inline int32_t hashCode(
void)
const;
1844 inline UBool isBogus(
void)
const;
1923 friend inline void U_EXPORT2
2043 int32_t textLength);
2066 int32_t buffCapacity);
2267 const char16_t *srcChars,
2367 const char16_t *srcChars,
2480 virtual void copy(int32_t start, int32_t limit, int32_t dest);
2569 inline UnicodeString& removeBetween(int32_t start,
2581 inline UnicodeString &retainBetween(int32_t start, int32_t limit = INT32_MAX);
2596 UBool padLeading(int32_t targetLength,
2597 char16_t padChar = 0x0020);
2610 UBool padTrailing(int32_t targetLength,
2611 char16_t padChar = 0x0020);
2619 inline UBool truncate(int32_t targetLength);
2626 UnicodeString& trim(
void);
2636 inline UnicodeString& reverse(
void);
2646 inline UnicodeString& reverse(int32_t start,
2655 UnicodeString& toUpper(
void);
2664 UnicodeString& toUpper(
const Locale& locale);
2672 UnicodeString& toLower(
void);
2681 UnicodeString& toLower(
const Locale& locale);
2683 #if !UCONFIG_NO_BREAK_ITERATION 2790 UnicodeString &foldCase(uint32_t options=0 );
2839 char16_t *getBuffer(int32_t minCapacity);
2861 void releaseBuffer(int32_t newLength=-1);
2893 inline const char16_t *getBuffer()
const;
2928 const char16_t *getTerminatedBuffer();
2937 inline UnicodeString();
2950 UnicodeString(int32_t capacity,
UChar32 c, int32_t count);
2986 #if !U_CHAR16_IS_TYPEDEF 3001 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN) 3036 UnicodeString(
const char16_t *text,
3037 int32_t textLength);
3039 #if !U_CHAR16_IS_TYPEDEF 3051 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN) 3071 inline UnicodeString(
const std::nullptr_t text, int32_t textLength);
3095 UnicodeString(
UBool isTerminated,
3097 int32_t textLength);
3117 UnicodeString(char16_t *buffer, int32_t buffLength, int32_t buffCapacity);
3119 #if !U_CHAR16_IS_TYPEDEF 3129 UnicodeString(
Char16Ptr(buffer), buffLength, buffCapacity) {}
3132 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN) 3143 UnicodeString(
Char16Ptr(buffer), buffLength, buffCapacity) {}
3154 inline UnicodeString(std::nullptr_t buffer, int32_t buffLength, int32_t buffCapacity);
3156 #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION 3187 UnicodeString(
const char *codepageData, int32_t dataLength);
3191 #if !UCONFIG_NO_CONVERSION 3210 UnicodeString(
const char *codepageData,
const char *codepage);
3229 UnicodeString(
const char *codepageData, int32_t dataLength,
const char *codepage);
3253 const char *src, int32_t srcLength,
3282 UnicodeString(
const char *src, int32_t textLength,
enum EInvariant inv);
3301 UnicodeString(
const UnicodeString& that);
3309 UnicodeString(UnicodeString &&src)
U_NOEXCEPT;
3317 UnicodeString(
const UnicodeString& src, int32_t srcStart);
3326 UnicodeString(
const UnicodeString& src, int32_t srcStart, int32_t srcLength);
3341 virtual UnicodeString *
clone()
const;
3346 virtual ~UnicodeString();
3374 static UnicodeString fromUTF32(
const UChar32 *utf32, int32_t length);
3412 UnicodeString unescape()
const;
3433 UChar32 unescapeAt(int32_t &offset)
const;
3440 static UClassID U_EXPORT2 getStaticClassID();
3465 virtual char16_t
getCharAt(int32_t offset)
const;
3483 toUTF8(int32_t start, int32_t len,
3484 char *target, int32_t capacity)
const;
3490 UBool doEquals(
const UnicodeString &text, int32_t len)
const;
3493 doCompare(int32_t start,
3495 const UnicodeString& srcText,
3497 int32_t srcLength)
const;
3499 int8_t doCompare(int32_t start,
3501 const char16_t *srcChars,
3503 int32_t srcLength)
const;
3506 doCompareCodePointOrder(int32_t start,
3508 const UnicodeString& srcText,
3510 int32_t srcLength)
const;
3512 int8_t doCompareCodePointOrder(int32_t start,
3514 const char16_t *srcChars,
3516 int32_t srcLength)
const;
3519 doCaseCompare(int32_t start,
3521 const UnicodeString &srcText,
3524 uint32_t options)
const;
3527 doCaseCompare(int32_t start,
3529 const char16_t *srcChars,
3532 uint32_t options)
const;
3534 int32_t doIndexOf(char16_t c,
3536 int32_t length)
const;
3540 int32_t length)
const;
3542 int32_t doLastIndexOf(char16_t c,
3544 int32_t length)
const;
3546 int32_t doLastIndexOf(
UChar32 c,
3548 int32_t length)
const;
3550 void doExtract(int32_t start,
3553 int32_t dstStart)
const;
3555 inline void doExtract(int32_t start,
3557 UnicodeString& target)
const;
3559 inline char16_t doCharAt(int32_t offset)
const;
3561 UnicodeString& doReplace(int32_t start,
3563 const UnicodeString& srcText,
3567 UnicodeString& doReplace(int32_t start,
3569 const char16_t *srcChars,
3573 UnicodeString& doAppend(
const UnicodeString& src, int32_t srcStart, int32_t srcLength);
3574 UnicodeString& doAppend(
const char16_t *srcChars, int32_t srcStart, int32_t srcLength);
3576 UnicodeString& doReverse(int32_t start,
3580 int32_t doHashCode(
void)
const;
3584 inline char16_t* getArrayStart(
void);
3585 inline const char16_t* getArrayStart(
void)
const;
3587 inline UBool hasShortLength()
const;
3588 inline int32_t getShortLength()
const;
3592 inline UBool isWritable()
const;
3595 inline UBool isBufferWritable()
const;
3598 inline void setZeroLength();
3599 inline void setShortLength(int32_t len);
3600 inline void setLength(int32_t len);
3601 inline void setToEmpty();
3602 inline void setArray(char16_t *array, int32_t len, int32_t capacity);
3609 UBool allocate(int32_t capacity);
3612 void releaseArray(
void);
3618 UnicodeString ©From(
const UnicodeString &src,
UBool fastCopy=
FALSE);
3621 void copyFieldsFrom(UnicodeString &src,
UBool setSrcToBogus)
U_NOEXCEPT;
3624 inline void pinIndex(int32_t& start)
const;
3625 inline void pinIndices(int32_t& start,
3626 int32_t& length)
const;
3628 #if !UCONFIG_NO_CONVERSION 3631 int32_t doExtract(int32_t start, int32_t length,
3632 char *dest, int32_t destCapacity,
3646 void doCodepageCreate(
const char *codepageData,
3648 const char *codepage);
3655 doCodepageCreate(
const char *codepageData,
3673 UBool cloneArrayIfNeeded(int32_t newCapacity = -1,
3674 int32_t growCapacity = -1,
3676 int32_t **pBufferToDelete = 0,
3685 caseMap(int32_t caseLocale, uint32_t options,
3693 int32_t removeRef(
void);
3694 int32_t refCount(
void)
const;
3704 kInvalidUChar=0xffff,
3710 kUsingStackBuffer=2,
3712 kBufferIsReadonly=8,
3715 kAllStorageFlags=0x1f,
3718 kLength1=1<<kLengthShift,
3719 kMaxShortLength=0x3ff,
3720 kLengthIsLarge=0xffe0,
3723 kShortString=kUsingStackBuffer,
3724 kLongString=kRefCounted,
3725 kReadonlyAlias=kBufferIsReadonly,
3731 union StackBufferOrFields;
3732 friend union StackBufferOrFields;
3775 union StackBufferOrFields {
3779 int16_t fLengthAndFlags;
3780 char16_t fBuffer[US_STACKBUF_SIZE];
3783 int16_t fLengthAndFlags;
3813 UnicodeString::pinIndex(int32_t& start)
const 3818 }
else if(start > length()) {
3824 UnicodeString::pinIndices(int32_t& start,
3825 int32_t& _length)
const 3828 int32_t len = length();
3831 }
else if(start > len) {
3836 }
else if(_length > (len - start)) {
3837 _length = (len - start);
3842 UnicodeString::getArrayStart() {
3843 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3844 fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
3847 inline const char16_t*
3848 UnicodeString::getArrayStart()
const {
3849 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3850 fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
3858 UnicodeString::UnicodeString() {
3859 fUnion.fStackFields.fLengthAndFlags=kShortString;
3862 inline UnicodeString::UnicodeString(
const std::nullptr_t ) {
3863 fUnion.fStackFields.fLengthAndFlags=kShortString;
3866 inline UnicodeString::UnicodeString(
const std::nullptr_t , int32_t ) {
3867 fUnion.fStackFields.fLengthAndFlags=kShortString;
3870 inline UnicodeString::UnicodeString(std::nullptr_t , int32_t , int32_t ) {
3871 fUnion.fStackFields.fLengthAndFlags=kShortString;
3878 UnicodeString::hasShortLength()
const {
3879 return fUnion.fFields.fLengthAndFlags>=0;
3883 UnicodeString::getShortLength()
const {
3886 return fUnion.fFields.fLengthAndFlags>>kLengthShift;
3890 UnicodeString::length()
const {
3891 return hasShortLength() ? getShortLength() : fUnion.fFields.fLength;
3895 UnicodeString::getCapacity()
const {
3896 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3897 US_STACKBUF_SIZE : fUnion.fFields.fCapacity;
3901 UnicodeString::hashCode()
const 3902 {
return doHashCode(); }
3905 UnicodeString::isBogus()
const 3906 {
return (
UBool)(fUnion.fFields.fLengthAndFlags & kIsBogus); }
3909 UnicodeString::isWritable()
const 3910 {
return (
UBool)!(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus)); }
3913 UnicodeString::isBufferWritable()
const 3916 !(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus|kBufferIsReadonly)) &&
3917 (!(fUnion.fFields.fLengthAndFlags&kRefCounted) || refCount()==1));
3920 inline const char16_t *
3921 UnicodeString::getBuffer()
const {
3922 if(fUnion.fFields.fLengthAndFlags&(kIsBogus|kOpenGetBuffer)) {
3924 }
else if(fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) {
3925 return fUnion.fStackFields.fBuffer;
3927 return fUnion.fFields.fArray;
3935 UnicodeString::doCompare(int32_t start,
3939 int32_t srcLength)
const 3942 return (int8_t)!isBogus();
3944 srcText.pinIndices(srcStart, srcLength);
3945 return doCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
3955 int32_t len = length(), textLength = text.
length();
3956 return !text.
isBogus() && len == textLength && doEquals(text, len);
3962 {
return (!
operator==(text)); }
3966 {
return doCompare(0, length(), text, 0, text.
length()) == 1; }
3970 {
return doCompare(0, length(), text, 0, text.
length()) == -1; }
3974 {
return doCompare(0, length(), text, 0, text.
length()) != -1; }
3978 {
return doCompare(0, length(), text, 0, text.
length()) != 1; }
3982 {
return doCompare(0, length(), text, 0, text.
length()); }
3985 UnicodeString::compare(int32_t start,
3988 {
return doCompare(start, _length, srcText, 0, srcText.
length()); }
3992 int32_t srcLength)
const 3993 {
return doCompare(0, length(), srcChars, 0, srcLength); }
3996 UnicodeString::compare(int32_t start,
4000 int32_t srcLength)
const 4001 {
return doCompare(start, _length, srcText, srcStart, srcLength); }
4004 UnicodeString::compare(int32_t start,
4006 const char16_t *srcChars)
const 4007 {
return doCompare(start, _length, srcChars, 0, _length); }
4010 UnicodeString::compare(int32_t start,
4012 const char16_t *srcChars,
4014 int32_t srcLength)
const 4015 {
return doCompare(start, _length, srcChars, srcStart, srcLength); }
4018 UnicodeString::compareBetween(int32_t start,
4022 int32_t srcLimit)
const 4023 {
return doCompare(start, limit - start,
4024 srcText, srcStart, srcLimit - srcStart); }
4027 UnicodeString::doCompareCodePointOrder(int32_t start,
4031 int32_t srcLength)
const 4034 return (int8_t)!isBogus();
4036 srcText.pinIndices(srcStart, srcLength);
4037 return doCompareCodePointOrder(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
4043 {
return doCompareCodePointOrder(0, length(), text, 0, text.
length()); }
4046 UnicodeString::compareCodePointOrder(int32_t start,
4049 {
return doCompareCodePointOrder(start, _length, srcText, 0, srcText.
length()); }
4053 int32_t srcLength)
const 4054 {
return doCompareCodePointOrder(0, length(), srcChars, 0, srcLength); }
4057 UnicodeString::compareCodePointOrder(int32_t start,
4061 int32_t srcLength)
const 4062 {
return doCompareCodePointOrder(start, _length, srcText, srcStart, srcLength); }
4065 UnicodeString::compareCodePointOrder(int32_t start,
4067 const char16_t *srcChars)
const 4068 {
return doCompareCodePointOrder(start, _length, srcChars, 0, _length); }
4071 UnicodeString::compareCodePointOrder(int32_t start,
4073 const char16_t *srcChars,
4075 int32_t srcLength)
const 4076 {
return doCompareCodePointOrder(start, _length, srcChars, srcStart, srcLength); }
4079 UnicodeString::compareCodePointOrderBetween(int32_t start,
4083 int32_t srcLimit)
const 4084 {
return doCompareCodePointOrder(start, limit - start,
4085 srcText, srcStart, srcLimit - srcStart); }
4088 UnicodeString::doCaseCompare(int32_t start,
4093 uint32_t options)
const 4096 return (int8_t)!isBogus();
4098 srcText.pinIndices(srcStart, srcLength);
4099 return doCaseCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength, options);
4105 return doCaseCompare(0, length(), text, 0, text.
length(), options);
4109 UnicodeString::caseCompare(int32_t start,
4112 uint32_t options)
const {
4113 return doCaseCompare(start, _length, srcText, 0, srcText.
length(), options);
4119 uint32_t options)
const {
4120 return doCaseCompare(0, length(), srcChars, 0, srcLength, options);
4124 UnicodeString::caseCompare(int32_t start,
4129 uint32_t options)
const {
4130 return doCaseCompare(start, _length, srcText, srcStart, srcLength, options);
4134 UnicodeString::caseCompare(int32_t start,
4136 const char16_t *srcChars,
4137 uint32_t options)
const {
4138 return doCaseCompare(start, _length, srcChars, 0, _length, options);
4142 UnicodeString::caseCompare(int32_t start,
4144 const char16_t *srcChars,
4147 uint32_t options)
const {
4148 return doCaseCompare(start, _length, srcChars, srcStart, srcLength, options);
4152 UnicodeString::caseCompareBetween(int32_t start,
4157 uint32_t options)
const {
4158 return doCaseCompare(start, limit - start, srcText, srcStart, srcLimit - srcStart, options);
4166 int32_t _length)
const 4169 srcText.pinIndices(srcStart, srcLength);
4171 return indexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
4179 {
return indexOf(text, 0, text.
length(), 0, length()); }
4183 int32_t start)
const {
4185 return indexOf(text, 0, text.
length(), start, length() - start);
4191 int32_t _length)
const 4192 {
return indexOf(text, 0, text.
length(), start, _length); }
4195 UnicodeString::indexOf(
const char16_t *srcChars,
4197 int32_t start)
const {
4199 return indexOf(srcChars, 0, srcLength, start, length() - start);
4206 int32_t _length)
const 4207 {
return indexOf(srcChars, 0, srcLength, start, _length); }
4210 UnicodeString::indexOf(char16_t c,
4212 int32_t _length)
const 4213 {
return doIndexOf(c, start, _length); }
4218 int32_t _length)
const 4219 {
return doIndexOf(c, start, _length); }
4222 UnicodeString::indexOf(char16_t c)
const 4223 {
return doIndexOf(c, 0, length()); }
4227 {
return indexOf(c, 0, length()); }
4230 UnicodeString::indexOf(char16_t c,
4231 int32_t start)
const {
4233 return doIndexOf(c, start, length() - start);
4238 int32_t start)
const {
4240 return indexOf(c, start, length() - start);
4247 int32_t _length)
const 4248 {
return lastIndexOf(srcChars, 0, srcLength, start, _length); }
4251 UnicodeString::lastIndexOf(
const char16_t *srcChars,
4253 int32_t start)
const {
4255 return lastIndexOf(srcChars, 0, srcLength, start, length() - start);
4263 int32_t _length)
const 4266 srcText.pinIndices(srcStart, srcLength);
4268 return lastIndexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
4277 int32_t _length)
const 4278 {
return lastIndexOf(text, 0, text.
length(), start, _length); }
4282 int32_t start)
const {
4284 return lastIndexOf(text, 0, text.
length(), start, length() - start);
4289 {
return lastIndexOf(text, 0, text.
length(), 0, length()); }
4292 UnicodeString::lastIndexOf(char16_t c,
4294 int32_t _length)
const 4295 {
return doLastIndexOf(c, start, _length); }
4300 int32_t _length)
const {
4301 return doLastIndexOf(c, start, _length);
4305 UnicodeString::lastIndexOf(char16_t c)
const 4306 {
return doLastIndexOf(c, 0, length()); }
4310 return lastIndexOf(c, 0, length());
4314 UnicodeString::lastIndexOf(char16_t c,
4315 int32_t start)
const {
4317 return doLastIndexOf(c, start, length() - start);
4322 int32_t start)
const {
4324 return lastIndexOf(c, start, length() - start);
4329 {
return compare(0, text.
length(), text, 0, text.
length()) == 0; }
4334 int32_t srcLength)
const 4335 {
return doCompare(0, srcLength, srcText, srcStart, srcLength) == 0; }
4342 return doCompare(0, srcLength, srcChars, 0, srcLength) == 0;
4346 UnicodeString::startsWith(
const char16_t *srcChars, int32_t srcStart, int32_t srcLength)
const {
4350 return doCompare(0, srcLength, srcChars, srcStart, srcLength) == 0;
4355 {
return doCompare(length() - text.
length(), text.
length(),
4356 text, 0, text.
length()) == 0; }
4361 int32_t srcLength)
const {
4362 srcText.pinIndices(srcStart, srcLength);
4363 return doCompare(length() - srcLength, srcLength,
4364 srcText, srcStart, srcLength) == 0;
4369 int32_t srcLength)
const {
4373 return doCompare(length() - srcLength, srcLength,
4374 srcChars, 0, srcLength) == 0;
4378 UnicodeString::endsWith(
const char16_t *srcChars,
4380 int32_t srcLength)
const {
4384 return doCompare(length() - srcLength, srcLength,
4385 srcChars, srcStart, srcLength) == 0;
4392 UnicodeString::replace(int32_t start,
4395 {
return doReplace(start, _length, srcText, 0, srcText.
length()); }
4398 UnicodeString::replace(int32_t start,
4403 {
return doReplace(start, _length, srcText, srcStart, srcLength); }
4406 UnicodeString::replace(int32_t start,
4410 {
return doReplace(start, _length, srcChars, 0, srcLength); }
4413 UnicodeString::replace(int32_t start,
4415 const char16_t *srcChars,
4418 {
return doReplace(start, _length, srcChars, srcStart, srcLength); }
4421 UnicodeString::replace(int32_t start,
4424 {
return doReplace(start, _length, &srcChar, 0, 1); }
4427 UnicodeString::replaceBetween(int32_t start,
4430 {
return doReplace(start, limit - start, srcText, 0, srcText.
length()); }
4433 UnicodeString::replaceBetween(int32_t start,
4438 {
return doReplace(start, limit - start, srcText, srcStart, srcLimit - srcStart); }
4443 {
return findAndReplace(0, length(), oldText, 0, oldText.
length(),
4444 newText, 0, newText.
length()); }
4447 UnicodeString::findAndReplace(int32_t start,
4451 {
return findAndReplace(start, _length, oldText, 0, oldText.
length(),
4452 newText, 0, newText.
length()); }
4458 UnicodeString::doExtract(int32_t start,
4461 { target.
replace(0, target.
length(), *
this, start, _length); }
4464 UnicodeString::extract(int32_t start,
4467 int32_t targetStart)
const 4468 { doExtract(start, _length, target, targetStart); }
4471 UnicodeString::extract(int32_t start,
4474 { doExtract(start, _length, target); }
4476 #if !UCONFIG_NO_CONVERSION 4479 UnicodeString::extract(int32_t start,
4482 const char *codepage)
const 4486 return extract(start, _length, dst, dst!=0 ? 0xffffffff : 0, codepage);
4492 UnicodeString::extractBetween(int32_t start,
4495 int32_t dstStart)
const {
4498 doExtract(start, limit - start, dst, dstStart);
4502 UnicodeString::tempSubStringBetween(int32_t start, int32_t limit)
const {
4503 return tempSubString(start, limit - start);
4507 UnicodeString::doCharAt(int32_t offset)
const 4509 if((uint32_t)offset < (uint32_t)length()) {
4510 return getArrayStart()[offset];
4512 return kInvalidUChar;
4517 UnicodeString::charAt(int32_t offset)
const 4518 {
return doCharAt(offset); }
4521 UnicodeString::operator[] (int32_t offset)
const 4522 {
return doCharAt(offset); }
4525 UnicodeString::isEmpty()
const {
4527 return (fUnion.fFields.fLengthAndFlags>>kLengthShift) == 0;
4534 UnicodeString::setZeroLength() {
4535 fUnion.fFields.fLengthAndFlags &= kAllStorageFlags;
4539 UnicodeString::setShortLength(int32_t len) {
4541 fUnion.fFields.fLengthAndFlags =
4542 (int16_t)((fUnion.fFields.fLengthAndFlags & kAllStorageFlags) | (len << kLengthShift));
4546 UnicodeString::setLength(int32_t len) {
4547 if(len <= kMaxShortLength) {
4548 setShortLength(len);
4550 fUnion.fFields.fLengthAndFlags |= kLengthIsLarge;
4551 fUnion.fFields.fLength = len;
4556 UnicodeString::setToEmpty() {
4557 fUnion.fFields.fLengthAndFlags = kShortString;
4561 UnicodeString::setArray(char16_t *array, int32_t len, int32_t capacity) {
4563 fUnion.fFields.fArray = array;
4564 fUnion.fFields.fCapacity = capacity;
4568 UnicodeString::operator= (char16_t ch)
4569 {
return doReplace(0, length(), &ch, 0, 1); }
4573 {
return replace(0, length(), ch); }
4581 return doReplace(0, length(), srcText, srcStart, srcLength);
4589 srcText.pinIndex(srcStart);
4590 return doReplace(0, length(), srcText, srcStart, srcText.
length() - srcStart);
4596 return copyFrom(srcText);
4600 UnicodeString::setTo(
const char16_t *srcChars,
4604 return doReplace(0, length(), srcChars, 0, srcLength);
4608 UnicodeString::setTo(char16_t srcChar)
4611 return doReplace(0, length(), &srcChar, 0, 1);
4618 return replace(0, length(), srcChar);
4625 {
return doAppend(srcText, srcStart, srcLength); }
4629 {
return doAppend(srcText, 0, srcText.
length()); }
4632 UnicodeString::append(
const char16_t *srcChars,
4635 {
return doAppend(srcChars, srcStart, srcLength); }
4640 {
return doAppend(srcChars, 0, srcLength); }
4643 UnicodeString::append(char16_t srcChar)
4644 {
return doAppend(&srcChar, 0, 1); }
4647 UnicodeString::operator+= (char16_t ch)
4648 {
return doAppend(&ch, 0, 1); }
4657 {
return doAppend(srcText, 0, srcText.
length()); }
4660 UnicodeString::insert(int32_t start,
4664 {
return doReplace(start, 0, srcText, srcStart, srcLength); }
4667 UnicodeString::insert(int32_t start,
4669 {
return doReplace(start, 0, srcText, 0, srcText.
length()); }
4672 UnicodeString::insert(int32_t start,
4673 const char16_t *srcChars,
4676 {
return doReplace(start, 0, srcChars, srcStart, srcLength); }
4679 UnicodeString::insert(int32_t start,
4682 {
return doReplace(start, 0, srcChars, 0, srcLength); }
4685 UnicodeString::insert(int32_t start,
4687 {
return doReplace(start, 0, &srcChar, 0, 1); }
4690 UnicodeString::insert(int32_t start,
4692 {
return replace(start, 0, srcChar); }
4696 UnicodeString::remove()
4708 UnicodeString::remove(int32_t start,
4711 if(start <= 0 && _length ==
INT32_MAX) {
4715 return doReplace(start, _length,
NULL, 0, 0);
4719 UnicodeString::removeBetween(int32_t start,
4721 {
return doReplace(start, limit - start,
NULL, 0, 0); }
4724 UnicodeString::retainBetween(int32_t start, int32_t limit) {
4726 return doReplace(0, start,
NULL, 0, 0);
4730 UnicodeString::truncate(int32_t targetLength)
4732 if(isBogus() && targetLength == 0) {
4736 }
else if((uint32_t)targetLength < (uint32_t)length()) {
4737 setLength(targetLength);
4745 UnicodeString::reverse()
4746 {
return doReverse(0, length()); }
4749 UnicodeString::reverse(int32_t start,
4751 {
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(const uint16_t *text, int32_t textLength)
uint16_t * constructor.
UnicodeString(wchar_t *buffer, int32_t buffLength, int32_t buffCapacity)
Writable-aliasing wchar_t * constructor.
virtual void copy(int32_t start, int32_t limit, int32_t dest)=0
Copies a substring of this object, retaining metadata.
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
UNISTR_FROM_STRING_EXPLICIT UnicodeString(const uint16_t *text)
uint16_t * constructor.
UNISTR_FROM_STRING_EXPLICIT UnicodeString(const wchar_t *text)
wchar_t * constructor.
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
#define U_SIZEOF_UCHAR
Number of bytes in a UChar.
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".
friend void swap(UnicodeString &s1, UnicodeString &s2) U_NOEXCEPT
Non-member UnicodeString swap function.
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.
UnicodeString(const wchar_t *text, int32_t textLength)
wchar_t * constructor.
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.
struct UConverter UConverter
#define INT32_MAX
The largest value a 32 bit signed integer can hold.
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
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.