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,
1493 inline void extract(int32_t start,
1511 int32_t dstStart = 0)
const;
1546 int32_t extract(int32_t start,
1547 int32_t startLength,
1549 int32_t targetCapacity,
1552 #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION 1573 int32_t extract(int32_t start,
1574 int32_t startLength,
1576 uint32_t targetLength)
const;
1580 #if !UCONFIG_NO_CONVERSION 1607 inline int32_t extract(int32_t start,
1608 int32_t startLength,
1610 const char *codepage = 0)
const;
1641 int32_t extract(int32_t start,
1642 int32_t startLength,
1644 uint32_t targetLength,
1645 const char *codepage)
const;
1664 int32_t extract(
char *dest, int32_t destCapacity,
1722 template<
typename StringClass>
1756 inline int32_t
length(
void)
const;
1772 countChar32(int32_t start=0, int32_t length=
INT32_MAX)
const;
1798 hasMoreChar32Than(int32_t start, int32_t length, int32_t number)
const;
1805 inline UBool isEmpty(
void)
const;
1816 inline int32_t getCapacity(
void)
const;
1825 inline int32_t hashCode(
void)
const;
1839 inline UBool isBogus(
void)
const;
1918 friend inline void U_EXPORT2
2038 int32_t textLength);
2061 int32_t buffCapacity);
2263 const char16_t *srcChars,
2363 const char16_t *srcChars,
2476 virtual void copy(int32_t start, int32_t limit, int32_t dest);
2562 inline UnicodeString& removeBetween(int32_t start,
2574 inline UnicodeString &retainBetween(int32_t start, int32_t limit = INT32_MAX);
2589 UBool padLeading(int32_t targetLength,
2590 char16_t padChar = 0x0020);
2603 UBool padTrailing(int32_t targetLength,
2604 char16_t padChar = 0x0020);
2612 inline UBool truncate(int32_t targetLength);
2619 UnicodeString& trim(
void);
2629 inline UnicodeString& reverse(
void);
2639 inline UnicodeString& reverse(int32_t start,
2648 UnicodeString& toUpper(
void);
2657 UnicodeString& toUpper(
const Locale& locale);
2665 UnicodeString& toLower(
void);
2674 UnicodeString& toLower(
const Locale& locale);
2676 #if !UCONFIG_NO_BREAK_ITERATION 2783 UnicodeString &foldCase(uint32_t options=0 );
2832 char16_t *getBuffer(int32_t minCapacity);
2854 void releaseBuffer(int32_t newLength=-1);
2886 inline const char16_t *getBuffer()
const;
2921 const char16_t *getTerminatedBuffer();
2930 inline UnicodeString();
2943 UnicodeString(int32_t capacity,
UChar32 c, int32_t count);
2979 #if !U_CHAR16_IS_TYPEDEF 2994 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN) 3029 UnicodeString(
const char16_t *text,
3030 int32_t textLength);
3032 #if !U_CHAR16_IS_TYPEDEF 3044 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN) 3064 inline UnicodeString(
const std::nullptr_t text, int32_t length);
3088 UnicodeString(
UBool isTerminated,
3090 int32_t textLength);
3110 UnicodeString(char16_t *buffer, int32_t buffLength, int32_t buffCapacity);
3112 #if !U_CHAR16_IS_TYPEDEF 3122 UnicodeString(
Char16Ptr(buffer), buffLength, buffCapacity) {}
3125 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN) 3136 UnicodeString(
Char16Ptr(buffer), buffLength, buffCapacity) {}
3147 inline UnicodeString(std::nullptr_t buffer, int32_t buffLength, int32_t buffCapacity);
3149 #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION 3180 UnicodeString(
const char *codepageData, int32_t dataLength);
3184 #if !UCONFIG_NO_CONVERSION 3203 UnicodeString(
const char *codepageData,
const char *codepage);
3222 UnicodeString(
const char *codepageData, int32_t dataLength,
const char *codepage);
3246 const char *src, int32_t srcLength,
3275 UnicodeString(
const char *src, int32_t length,
enum EInvariant inv);
3294 UnicodeString(
const UnicodeString& that);
3302 UnicodeString(UnicodeString &&src)
U_NOEXCEPT;
3310 UnicodeString(
const UnicodeString& src, int32_t srcStart);
3319 UnicodeString(
const UnicodeString& src, int32_t srcStart, int32_t srcLength);
3342 virtual ~UnicodeString();
3370 static UnicodeString fromUTF32(
const UChar32 *utf32, int32_t length);
3408 UnicodeString unescape()
const;
3429 UChar32 unescapeAt(int32_t &offset)
const;
3436 static UClassID U_EXPORT2 getStaticClassID();
3461 virtual char16_t
getCharAt(int32_t offset)
const;
3479 toUTF8(int32_t start, int32_t len,
3480 char *target, int32_t capacity)
const;
3486 UBool doEquals(
const UnicodeString &text, int32_t len)
const;
3489 doCompare(int32_t start,
3491 const UnicodeString& srcText,
3493 int32_t srcLength)
const;
3495 int8_t doCompare(int32_t start,
3497 const char16_t *srcChars,
3499 int32_t srcLength)
const;
3502 doCompareCodePointOrder(int32_t start,
3504 const UnicodeString& srcText,
3506 int32_t srcLength)
const;
3508 int8_t doCompareCodePointOrder(int32_t start,
3510 const char16_t *srcChars,
3512 int32_t srcLength)
const;
3515 doCaseCompare(int32_t start,
3517 const UnicodeString &srcText,
3520 uint32_t options)
const;
3523 doCaseCompare(int32_t start,
3525 const char16_t *srcChars,
3528 uint32_t options)
const;
3530 int32_t doIndexOf(char16_t c,
3532 int32_t length)
const;
3536 int32_t length)
const;
3538 int32_t doLastIndexOf(char16_t c,
3540 int32_t length)
const;
3542 int32_t doLastIndexOf(
UChar32 c,
3544 int32_t length)
const;
3546 void doExtract(int32_t start,
3549 int32_t dstStart)
const;
3551 inline void doExtract(int32_t start,
3553 UnicodeString& target)
const;
3555 inline char16_t doCharAt(int32_t offset)
const;
3557 UnicodeString& doReplace(int32_t start,
3559 const UnicodeString& srcText,
3563 UnicodeString& doReplace(int32_t start,
3565 const char16_t *srcChars,
3569 UnicodeString& doAppend(
const UnicodeString& src, int32_t srcStart, int32_t srcLength);
3570 UnicodeString& doAppend(
const char16_t *srcChars, int32_t srcStart, int32_t srcLength);
3572 UnicodeString& doReverse(int32_t start,
3576 int32_t doHashCode(
void)
const;
3580 inline char16_t* getArrayStart(
void);
3581 inline const char16_t* getArrayStart(
void)
const;
3583 inline UBool hasShortLength()
const;
3584 inline int32_t getShortLength()
const;
3588 inline UBool isWritable()
const;
3591 inline UBool isBufferWritable()
const;
3594 inline void setZeroLength();
3595 inline void setShortLength(int32_t len);
3596 inline void setLength(int32_t len);
3597 inline void setToEmpty();
3598 inline void setArray(char16_t *array, int32_t len, int32_t capacity);
3605 UBool allocate(int32_t capacity);
3608 void releaseArray(
void);
3614 UnicodeString ©From(
const UnicodeString &src,
UBool fastCopy=
FALSE);
3617 void copyFieldsFrom(UnicodeString &src,
UBool setSrcToBogus)
U_NOEXCEPT;
3620 inline void pinIndex(int32_t& start)
const;
3621 inline void pinIndices(int32_t& start,
3622 int32_t& length)
const;
3624 #if !UCONFIG_NO_CONVERSION 3627 int32_t doExtract(int32_t start, int32_t length,
3628 char *dest, int32_t destCapacity,
3642 void doCodepageCreate(
const char *codepageData,
3644 const char *codepage);
3651 doCodepageCreate(
const char *codepageData,
3669 UBool cloneArrayIfNeeded(int32_t newCapacity = -1,
3670 int32_t growCapacity = -1,
3672 int32_t **pBufferToDelete = 0,
3681 caseMap(int32_t caseLocale, uint32_t options,
3689 int32_t removeRef(
void);
3690 int32_t refCount(
void)
const;
3700 kInvalidUChar=0xffff,
3706 kUsingStackBuffer=2,
3708 kBufferIsReadonly=8,
3711 kAllStorageFlags=0x1f,
3714 kLength1=1<<kLengthShift,
3715 kMaxShortLength=0x3ff,
3716 kLengthIsLarge=0xffe0,
3719 kShortString=kUsingStackBuffer,
3720 kLongString=kRefCounted,
3721 kReadonlyAlias=kBufferIsReadonly,
3727 union StackBufferOrFields;
3728 friend union StackBufferOrFields;
3771 union StackBufferOrFields {
3775 int16_t fLengthAndFlags;
3776 char16_t fBuffer[US_STACKBUF_SIZE];
3779 int16_t fLengthAndFlags;
3809 UnicodeString::pinIndex(int32_t& start)
const 3814 }
else if(start > length()) {
3820 UnicodeString::pinIndices(int32_t& start,
3821 int32_t& _length)
const 3824 int32_t len = length();
3827 }
else if(start > len) {
3832 }
else if(_length > (len - start)) {
3833 _length = (len - start);
3838 UnicodeString::getArrayStart() {
3839 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3840 fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
3843 inline const char16_t*
3844 UnicodeString::getArrayStart()
const {
3845 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3846 fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
3854 UnicodeString::UnicodeString() {
3855 fUnion.fStackFields.fLengthAndFlags=kShortString;
3858 inline UnicodeString::UnicodeString(
const std::nullptr_t ) {
3859 fUnion.fStackFields.fLengthAndFlags=kShortString;
3862 inline UnicodeString::UnicodeString(
const std::nullptr_t , int32_t ) {
3863 fUnion.fStackFields.fLengthAndFlags=kShortString;
3866 inline UnicodeString::UnicodeString(std::nullptr_t , int32_t , int32_t ) {
3867 fUnion.fStackFields.fLengthAndFlags=kShortString;
3874 UnicodeString::hasShortLength()
const {
3875 return fUnion.fFields.fLengthAndFlags>=0;
3879 UnicodeString::getShortLength()
const {
3882 return fUnion.fFields.fLengthAndFlags>>kLengthShift;
3886 UnicodeString::length()
const {
3887 return hasShortLength() ? getShortLength() : fUnion.fFields.fLength;
3891 UnicodeString::getCapacity()
const {
3892 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3893 US_STACKBUF_SIZE : fUnion.fFields.fCapacity;
3897 UnicodeString::hashCode()
const 3898 {
return doHashCode(); }
3901 UnicodeString::isBogus()
const 3902 {
return (
UBool)(fUnion.fFields.fLengthAndFlags & kIsBogus); }
3905 UnicodeString::isWritable()
const 3906 {
return (
UBool)!(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus)); }
3909 UnicodeString::isBufferWritable()
const 3912 !(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus|kBufferIsReadonly)) &&
3913 (!(fUnion.fFields.fLengthAndFlags&kRefCounted) || refCount()==1));
3916 inline const char16_t *
3917 UnicodeString::getBuffer()
const {
3918 if(fUnion.fFields.fLengthAndFlags&(kIsBogus|kOpenGetBuffer)) {
3920 }
else if(fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) {
3921 return fUnion.fStackFields.fBuffer;
3923 return fUnion.fFields.fArray;
3931 UnicodeString::doCompare(int32_t start,
3935 int32_t srcLength)
const 3938 return (int8_t)!isBogus();
3940 srcText.pinIndices(srcStart, srcLength);
3941 return doCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
3951 int32_t len = length(), textLength = text.
length();
3952 return !text.
isBogus() && len == textLength && doEquals(text, len);
3958 {
return (!
operator==(text)); }
3962 {
return doCompare(0, length(), text, 0, text.
length()) == 1; }
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()); }
3981 UnicodeString::compare(int32_t start,
3984 {
return doCompare(start, _length, srcText, 0, srcText.
length()); }
3988 int32_t srcLength)
const 3989 {
return doCompare(0, length(), srcChars, 0, srcLength); }
3992 UnicodeString::compare(int32_t start,
3996 int32_t srcLength)
const 3997 {
return doCompare(start, _length, srcText, srcStart, srcLength); }
4000 UnicodeString::compare(int32_t start,
4002 const char16_t *srcChars)
const 4003 {
return doCompare(start, _length, srcChars, 0, _length); }
4006 UnicodeString::compare(int32_t start,
4008 const char16_t *srcChars,
4010 int32_t srcLength)
const 4011 {
return doCompare(start, _length, srcChars, srcStart, srcLength); }
4014 UnicodeString::compareBetween(int32_t start,
4018 int32_t srcLimit)
const 4019 {
return doCompare(start, limit - start,
4020 srcText, srcStart, srcLimit - srcStart); }
4023 UnicodeString::doCompareCodePointOrder(int32_t start,
4027 int32_t srcLength)
const 4030 return (int8_t)!isBogus();
4032 srcText.pinIndices(srcStart, srcLength);
4033 return doCompareCodePointOrder(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
4039 {
return doCompareCodePointOrder(0, length(), text, 0, text.
length()); }
4042 UnicodeString::compareCodePointOrder(int32_t start,
4045 {
return doCompareCodePointOrder(start, _length, srcText, 0, srcText.
length()); }
4049 int32_t srcLength)
const 4050 {
return doCompareCodePointOrder(0, length(), srcChars, 0, srcLength); }
4053 UnicodeString::compareCodePointOrder(int32_t start,
4057 int32_t srcLength)
const 4058 {
return doCompareCodePointOrder(start, _length, srcText, srcStart, srcLength); }
4061 UnicodeString::compareCodePointOrder(int32_t start,
4063 const char16_t *srcChars)
const 4064 {
return doCompareCodePointOrder(start, _length, srcChars, 0, _length); }
4067 UnicodeString::compareCodePointOrder(int32_t start,
4069 const char16_t *srcChars,
4071 int32_t srcLength)
const 4072 {
return doCompareCodePointOrder(start, _length, srcChars, srcStart, srcLength); }
4075 UnicodeString::compareCodePointOrderBetween(int32_t start,
4079 int32_t srcLimit)
const 4080 {
return doCompareCodePointOrder(start, limit - start,
4081 srcText, srcStart, srcLimit - srcStart); }
4084 UnicodeString::doCaseCompare(int32_t start,
4089 uint32_t options)
const 4092 return (int8_t)!isBogus();
4094 srcText.pinIndices(srcStart, srcLength);
4095 return doCaseCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength, options);
4101 return doCaseCompare(0, length(), text, 0, text.
length(), options);
4105 UnicodeString::caseCompare(int32_t start,
4108 uint32_t options)
const {
4109 return doCaseCompare(start, _length, srcText, 0, srcText.
length(), options);
4115 uint32_t options)
const {
4116 return doCaseCompare(0, length(), srcChars, 0, srcLength, options);
4120 UnicodeString::caseCompare(int32_t start,
4125 uint32_t options)
const {
4126 return doCaseCompare(start, _length, srcText, srcStart, srcLength, options);
4130 UnicodeString::caseCompare(int32_t start,
4132 const char16_t *srcChars,
4133 uint32_t options)
const {
4134 return doCaseCompare(start, _length, srcChars, 0, _length, options);
4138 UnicodeString::caseCompare(int32_t start,
4140 const char16_t *srcChars,
4143 uint32_t options)
const {
4144 return doCaseCompare(start, _length, srcChars, srcStart, srcLength, options);
4148 UnicodeString::caseCompareBetween(int32_t start,
4153 uint32_t options)
const {
4154 return doCaseCompare(start, limit - start, srcText, srcStart, srcLimit - srcStart, options);
4162 int32_t _length)
const 4165 srcText.pinIndices(srcStart, srcLength);
4167 return indexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
4175 {
return indexOf(text, 0, text.
length(), 0, length()); }
4179 int32_t start)
const {
4181 return indexOf(text, 0, text.
length(), start, length() - start);
4187 int32_t _length)
const 4188 {
return indexOf(text, 0, text.
length(), start, _length); }
4191 UnicodeString::indexOf(
const char16_t *srcChars,
4193 int32_t start)
const {
4195 return indexOf(srcChars, 0, srcLength, start, length() - start);
4202 int32_t _length)
const 4203 {
return indexOf(srcChars, 0, srcLength, start, _length); }
4206 UnicodeString::indexOf(char16_t c,
4208 int32_t _length)
const 4209 {
return doIndexOf(c, start, _length); }
4214 int32_t _length)
const 4215 {
return doIndexOf(c, start, _length); }
4218 UnicodeString::indexOf(char16_t c)
const 4219 {
return doIndexOf(c, 0, length()); }
4223 {
return indexOf(c, 0, length()); }
4226 UnicodeString::indexOf(char16_t c,
4227 int32_t start)
const {
4229 return doIndexOf(c, start, length() - start);
4234 int32_t start)
const {
4236 return indexOf(c, start, length() - start);
4243 int32_t _length)
const 4244 {
return lastIndexOf(srcChars, 0, srcLength, start, _length); }
4247 UnicodeString::lastIndexOf(
const char16_t *srcChars,
4249 int32_t start)
const {
4251 return lastIndexOf(srcChars, 0, srcLength, start, length() - start);
4259 int32_t _length)
const 4262 srcText.pinIndices(srcStart, srcLength);
4264 return lastIndexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
4273 int32_t _length)
const 4274 {
return lastIndexOf(text, 0, text.
length(), start, _length); }
4278 int32_t start)
const {
4280 return lastIndexOf(text, 0, text.
length(), start, length() - start);
4285 {
return lastIndexOf(text, 0, text.
length(), 0, length()); }
4288 UnicodeString::lastIndexOf(char16_t c,
4290 int32_t _length)
const 4291 {
return doLastIndexOf(c, start, _length); }
4296 int32_t _length)
const {
4297 return doLastIndexOf(c, start, _length);
4301 UnicodeString::lastIndexOf(char16_t c)
const 4302 {
return doLastIndexOf(c, 0, length()); }
4306 return lastIndexOf(c, 0, length());
4310 UnicodeString::lastIndexOf(char16_t c,
4311 int32_t start)
const {
4313 return doLastIndexOf(c, start, length() - start);
4318 int32_t start)
const {
4320 return lastIndexOf(c, start, length() - start);
4325 {
return compare(0, text.
length(), text, 0, text.
length()) == 0; }
4330 int32_t srcLength)
const 4331 {
return doCompare(0, srcLength, srcText, srcStart, srcLength) == 0; }
4338 return doCompare(0, srcLength, srcChars, 0, srcLength) == 0;
4342 UnicodeString::startsWith(
const char16_t *srcChars, int32_t srcStart, int32_t srcLength)
const {
4346 return doCompare(0, srcLength, srcChars, srcStart, srcLength) == 0;
4351 {
return doCompare(length() - text.
length(), text.
length(),
4352 text, 0, text.
length()) == 0; }
4357 int32_t srcLength)
const {
4358 srcText.pinIndices(srcStart, srcLength);
4359 return doCompare(length() - srcLength, srcLength,
4360 srcText, srcStart, srcLength) == 0;
4365 int32_t srcLength)
const {
4369 return doCompare(length() - srcLength, srcLength,
4370 srcChars, 0, srcLength) == 0;
4374 UnicodeString::endsWith(
const char16_t *srcChars,
4376 int32_t srcLength)
const {
4380 return doCompare(length() - srcLength, srcLength,
4381 srcChars, srcStart, srcLength) == 0;
4388 UnicodeString::replace(int32_t start,
4391 {
return doReplace(start, _length, srcText, 0, srcText.
length()); }
4394 UnicodeString::replace(int32_t start,
4399 {
return doReplace(start, _length, srcText, srcStart, srcLength); }
4402 UnicodeString::replace(int32_t start,
4406 {
return doReplace(start, _length, srcChars, 0, srcLength); }
4409 UnicodeString::replace(int32_t start,
4411 const char16_t *srcChars,
4414 {
return doReplace(start, _length, srcChars, srcStart, srcLength); }
4417 UnicodeString::replace(int32_t start,
4420 {
return doReplace(start, _length, &srcChar, 0, 1); }
4423 UnicodeString::replaceBetween(int32_t start,
4426 {
return doReplace(start, limit - start, srcText, 0, srcText.
length()); }
4429 UnicodeString::replaceBetween(int32_t start,
4434 {
return doReplace(start, limit - start, srcText, srcStart, srcLimit - srcStart); }
4439 {
return findAndReplace(0, length(), oldText, 0, oldText.
length(),
4440 newText, 0, newText.
length()); }
4443 UnicodeString::findAndReplace(int32_t start,
4447 {
return findAndReplace(start, _length, oldText, 0, oldText.
length(),
4448 newText, 0, newText.
length()); }
4454 UnicodeString::doExtract(int32_t start,
4457 { target.
replace(0, target.
length(), *
this, start, _length); }
4460 UnicodeString::extract(int32_t start,
4463 int32_t targetStart)
const 4464 { doExtract(start, _length, target, targetStart); }
4467 UnicodeString::extract(int32_t start,
4470 { doExtract(start, _length, target); }
4472 #if !UCONFIG_NO_CONVERSION 4475 UnicodeString::extract(int32_t start,
4478 const char *codepage)
const 4482 return extract(start, _length, dst, dst!=0 ? 0xffffffff : 0, codepage);
4488 UnicodeString::extractBetween(int32_t start,
4491 int32_t dstStart)
const {
4494 doExtract(start, limit - start, dst, dstStart);
4498 UnicodeString::tempSubStringBetween(int32_t start, int32_t limit)
const {
4499 return tempSubString(start, limit - start);
4503 UnicodeString::doCharAt(int32_t offset)
const 4505 if((uint32_t)offset < (uint32_t)length()) {
4506 return getArrayStart()[offset];
4508 return kInvalidUChar;
4513 UnicodeString::charAt(int32_t offset)
const 4514 {
return doCharAt(offset); }
4517 UnicodeString::operator[] (int32_t offset)
const 4518 {
return doCharAt(offset); }
4521 UnicodeString::isEmpty()
const {
4523 return (fUnion.fFields.fLengthAndFlags>>kLengthShift) == 0;
4530 UnicodeString::setZeroLength() {
4531 fUnion.fFields.fLengthAndFlags &= kAllStorageFlags;
4535 UnicodeString::setShortLength(int32_t len) {
4537 fUnion.fFields.fLengthAndFlags =
4538 (int16_t)((fUnion.fFields.fLengthAndFlags & kAllStorageFlags) | (len << kLengthShift));
4542 UnicodeString::setLength(int32_t len) {
4543 if(len <= kMaxShortLength) {
4544 setShortLength(len);
4546 fUnion.fFields.fLengthAndFlags |= kLengthIsLarge;
4547 fUnion.fFields.fLength = len;
4552 UnicodeString::setToEmpty() {
4553 fUnion.fFields.fLengthAndFlags = kShortString;
4557 UnicodeString::setArray(char16_t *array, int32_t len, int32_t capacity) {
4559 fUnion.fFields.fArray = array;
4560 fUnion.fFields.fCapacity = capacity;
4564 UnicodeString::operator= (char16_t ch)
4565 {
return doReplace(0, length(), &ch, 0, 1); }
4569 {
return replace(0, length(), ch); }
4577 return doReplace(0, length(), srcText, srcStart, srcLength);
4585 srcText.pinIndex(srcStart);
4586 return doReplace(0, length(), srcText, srcStart, srcText.
length() - srcStart);
4592 return copyFrom(srcText);
4596 UnicodeString::setTo(
const char16_t *srcChars,
4600 return doReplace(0, length(), srcChars, 0, srcLength);
4604 UnicodeString::setTo(char16_t srcChar)
4607 return doReplace(0, length(), &srcChar, 0, 1);
4614 return replace(0, length(), srcChar);
4621 {
return doAppend(srcText, srcStart, srcLength); }
4625 {
return doAppend(srcText, 0, srcText.
length()); }
4628 UnicodeString::append(
const char16_t *srcChars,
4631 {
return doAppend(srcChars, srcStart, srcLength); }
4636 {
return doAppend(srcChars, 0, srcLength); }
4639 UnicodeString::append(char16_t srcChar)
4640 {
return doAppend(&srcChar, 0, 1); }
4643 UnicodeString::operator+= (char16_t ch)
4644 {
return doAppend(&ch, 0, 1); }
4653 {
return doAppend(srcText, 0, srcText.
length()); }
4656 UnicodeString::insert(int32_t start,
4660 {
return doReplace(start, 0, srcText, srcStart, srcLength); }
4663 UnicodeString::insert(int32_t start,
4665 {
return doReplace(start, 0, srcText, 0, srcText.
length()); }
4668 UnicodeString::insert(int32_t start,
4669 const char16_t *srcChars,
4672 {
return doReplace(start, 0, srcChars, srcStart, srcLength); }
4675 UnicodeString::insert(int32_t start,
4678 {
return doReplace(start, 0, srcChars, 0, srcLength); }
4681 UnicodeString::insert(int32_t start,
4683 {
return doReplace(start, 0, &srcChar, 0, 1); }
4686 UnicodeString::insert(int32_t start,
4688 {
return replace(start, 0, srcChar); }
4692 UnicodeString::remove()
4704 UnicodeString::remove(int32_t start,
4707 if(start <= 0 && _length ==
INT32_MAX) {
4711 return doReplace(start, _length,
NULL, 0, 0);
4715 UnicodeString::removeBetween(int32_t start,
4717 {
return doReplace(start, limit - start,
NULL, 0, 0); }
4720 UnicodeString::retainBetween(int32_t start, int32_t limit) {
4722 return doReplace(0, start,
NULL, 0, 0);
4726 UnicodeString::truncate(int32_t targetLength)
4728 if(isBogus() && targetLength == 0) {
4732 }
else if((uint32_t)targetLength < (uint32_t)length()) {
4733 setLength(targetLength);
4741 UnicodeString::reverse()
4742 {
return doReverse(0, length()); }
4745 UnicodeString::reverse(int32_t start,
4747 {
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(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.
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.
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.
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.