33 #if U_SHOW_CPLUSPLUS_API 55 #if !UCONFIG_NO_BREAK_ITERATION 74 char16_t *dest, int32_t destCapacity,
75 const char16_t *src, int32_t srcLength,
82 class StringCharacterIterator;
83 class UnicodeStringAppendable;
97 #define US_INV icu::UnicodeString::kInvariant 116 #if !U_CHAR16_IS_TYPEDEF 117 # define UNICODE_STRING(cs, _length) icu::UnicodeString(true, u ## cs, _length) 119 # define UNICODE_STRING(cs, _length) icu::UnicodeString(true, (const char16_t*)u ## cs, _length) 135 #define UNICODE_STRING_SIMPLE(cs) UNICODE_STRING(cs, -1) 144 #ifndef UNISTR_FROM_CHAR_EXPLICIT 145 # if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION) 147 # define UNISTR_FROM_CHAR_EXPLICIT explicit 150 # define UNISTR_FROM_CHAR_EXPLICIT 164 #ifndef UNISTR_FROM_STRING_EXPLICIT 165 # if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION) 167 # define UNISTR_FROM_STRING_EXPLICIT explicit 170 # define UNISTR_FROM_STRING_EXPLICIT 207 #ifndef UNISTR_OBJECT_SIZE 208 # define UNISTR_OBJECT_SIZE 64 403 inline int8_t compare(int32_t start,
424 inline int8_t compare(int32_t start,
428 int32_t srcLength)
const;
443 int32_t srcLength)
const;
459 inline int8_t compare(int32_t start,
461 const char16_t *srcChars)
const;
480 inline int8_t compare(int32_t start,
482 const char16_t *srcChars,
484 int32_t srcLength)
const;
503 inline int8_t compareBetween(int32_t start,
507 int32_t srcLimit)
const;
526 inline int8_t compareCodePointOrder(
const UnicodeString& text)
const;
547 inline int8_t compareCodePointOrder(int32_t start,
572 inline int8_t compareCodePointOrder(int32_t start,
576 int32_t srcLength)
const;
597 int32_t srcLength)
const;
618 inline int8_t compareCodePointOrder(int32_t start,
620 const char16_t *srcChars)
const;
643 inline int8_t compareCodePointOrder(int32_t start,
645 const char16_t *srcChars,
647 int32_t srcLength)
const;
670 inline int8_t compareCodePointOrderBetween(int32_t start,
674 int32_t srcLimit)
const;
694 inline int8_t caseCompare(
const UnicodeString& text, uint32_t options)
const;
716 inline int8_t caseCompare(int32_t start,
719 uint32_t options)
const;
743 inline int8_t caseCompare(int32_t start,
748 uint32_t options)
const;
771 uint32_t options)
const;
793 inline int8_t caseCompare(int32_t start,
795 const char16_t *srcChars,
796 uint32_t options)
const;
820 inline int8_t caseCompare(int32_t start,
822 const char16_t *srcChars,
825 uint32_t options)
const;
849 inline int8_t caseCompareBetween(int32_t start,
854 uint32_t options)
const;
877 int32_t srcLength)
const;
888 int32_t srcLength)
const;
899 inline UBool startsWith(
const char16_t *srcChars,
901 int32_t srcLength)
const;
924 int32_t srcLength)
const;
935 int32_t srcLength)
const;
947 inline UBool endsWith(
const char16_t *srcChars,
949 int32_t srcLength)
const;
974 int32_t start)
const;
989 int32_t length)
const;
1011 int32_t length)
const;
1024 inline int32_t indexOf(
const char16_t *srcChars,
1026 int32_t start)
const;
1043 int32_t length)
const;
1061 int32_t indexOf(
const char16_t *srcChars,
1065 int32_t length)
const;
1074 inline int32_t indexOf(char16_t c)
const;
1084 inline int32_t indexOf(
UChar32 c)
const;
1094 inline int32_t indexOf(char16_t c,
1095 int32_t start)
const;
1106 inline int32_t indexOf(
UChar32 c,
1107 int32_t start)
const;
1119 inline int32_t indexOf(char16_t c,
1121 int32_t length)
const;
1134 inline int32_t indexOf(
UChar32 c,
1136 int32_t length)
const;
1146 inline int32_t lastIndexOf(
const UnicodeString& text)
const;
1158 int32_t start)
const;
1173 int32_t length)
const;
1195 int32_t length)
const;
1207 inline int32_t lastIndexOf(
const char16_t *srcChars,
1209 int32_t start)
const;
1226 int32_t length)
const;
1244 int32_t lastIndexOf(
const char16_t *srcChars,
1248 int32_t length)
const;
1257 inline int32_t lastIndexOf(char16_t c)
const;
1267 inline int32_t lastIndexOf(
UChar32 c)
const;
1277 inline int32_t lastIndexOf(char16_t c,
1278 int32_t start)
const;
1289 inline int32_t lastIndexOf(
UChar32 c,
1290 int32_t start)
const;
1302 inline int32_t lastIndexOf(char16_t c,
1304 int32_t length)
const;
1317 inline int32_t lastIndexOf(
UChar32 c,
1319 int32_t length)
const;
1332 inline char16_t
charAt(int32_t offset)
const;
1341 inline char16_t operator[] (int32_t offset)
const;
1371 int32_t getChar32Start(int32_t offset)
const;
1389 int32_t getChar32Limit(int32_t offset)
const;
1441 int32_t moveIndex32(int32_t index, int32_t delta)
const;
1460 inline void extract(int32_t start,
1463 int32_t dstStart = 0)
const;
1487 extract(
Char16Ptr dest, int32_t destCapacity,
1499 inline void extract(int32_t start,
1517 int32_t dstStart = 0)
const;
1552 int32_t extract(int32_t start,
1553 int32_t startLength,
1555 int32_t targetCapacity,
1556 enum EInvariant inv)
const;
1558 #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION 1579 int32_t extract(int32_t start,
1580 int32_t startLength,
1582 uint32_t targetLength)
const;
1586 #if !UCONFIG_NO_CONVERSION 1613 inline int32_t extract(int32_t start,
1614 int32_t startLength,
1616 const char *codepage = 0)
const;
1647 int32_t extract(int32_t start,
1648 int32_t startLength,
1650 uint32_t targetLength,
1651 const char *codepage)
const;
1670 int32_t extract(
char *dest, int32_t destCapacity,
1728 template<
typename StringClass>
1762 inline int32_t
length(
void)
const;
1778 countChar32(int32_t start=0, int32_t length=
INT32_MAX)
const;
1804 hasMoreChar32Than(int32_t start, int32_t length, int32_t number)
const;
1811 inline UBool isEmpty(
void)
const;
1822 inline int32_t getCapacity(
void)
const;
1831 inline int32_t hashCode(
void)
const;
1845 inline UBool isBogus(
void)
const;
1924 friend inline void U_EXPORT2
2044 int32_t textLength);
2067 int32_t buffCapacity);
2268 const char16_t *srcChars,
2368 const char16_t *srcChars,
2481 virtual void copy(int32_t start, int32_t limit, int32_t dest)
override;
2597 UBool padLeading(int32_t targetLength,
2598 char16_t padChar = 0x0020);
2611 UBool padTrailing(int32_t targetLength,
2612 char16_t padChar = 0x0020);
2620 inline UBool truncate(int32_t targetLength);
2684 #if !UCONFIG_NO_BREAK_ITERATION 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();
2986 #if !U_CHAR16_IS_TYPEDEF 3001 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN) 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);
3097 int32_t textLength);
3117 UnicodeString(char16_t *buffer, int32_t buffLength, int32_t buffCapacity);
3119 #if !U_CHAR16_IS_TYPEDEF 3132 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN) 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);
3433 UChar32 unescapeAt(int32_t &offset)
const;
3440 static UClassID U_EXPORT2 getStaticClassID();
3458 virtual int32_t
getLength()
const override;
3465 virtual char16_t
getCharAt(int32_t offset)
const override;
3483 toUTF8(int32_t start, int32_t len,
3484 char *target, int32_t capacity)
const;
3493 doEqualsSubstring(int32_t start,
3497 int32_t srcLength)
const;
3499 UBool doEqualsSubstring(int32_t start,
3501 const char16_t *srcChars,
3503 int32_t srcLength)
const;
3506 doCompare(int32_t start,
3510 int32_t srcLength)
const;
3512 int8_t doCompare(int32_t start,
3514 const char16_t *srcChars,
3516 int32_t srcLength)
const;
3519 doCompareCodePointOrder(int32_t start,
3523 int32_t srcLength)
const;
3525 int8_t doCompareCodePointOrder(int32_t start,
3527 const char16_t *srcChars,
3529 int32_t srcLength)
const;
3532 doCaseCompare(int32_t start,
3537 uint32_t options)
const;
3540 doCaseCompare(int32_t start,
3542 const char16_t *srcChars,
3545 uint32_t options)
const;
3547 int32_t doIndexOf(char16_t c,
3549 int32_t length)
const;
3553 int32_t length)
const;
3555 int32_t doLastIndexOf(char16_t c,
3557 int32_t length)
const;
3559 int32_t doLastIndexOf(
UChar32 c,
3561 int32_t length)
const;
3563 void doExtract(int32_t start,
3566 int32_t dstStart)
const;
3568 inline void doExtract(int32_t start,
3572 inline char16_t doCharAt(int32_t offset)
const;
3582 const char16_t *srcChars,
3587 UnicodeString& doAppend(
const char16_t *srcChars, int32_t srcStart, int32_t srcLength);
3593 int32_t doHashCode(
void)
const;
3597 inline char16_t* getArrayStart(
void);
3598 inline const char16_t* getArrayStart(
void)
const;
3600 inline UBool hasShortLength()
const;
3601 inline int32_t getShortLength()
const;
3605 inline UBool isWritable()
const;
3608 inline UBool isBufferWritable()
const;
3611 inline void setZeroLength();
3612 inline void setShortLength(int32_t len);
3613 inline void setLength(int32_t len);
3614 inline void setToEmpty();
3615 inline void setArray(char16_t *array, int32_t len, int32_t capacity);
3622 UBool allocate(int32_t capacity);
3625 void releaseArray(
void);
3637 inline void pinIndex(int32_t& start)
const;
3638 inline void pinIndices(int32_t& start,
3639 int32_t& length)
const;
3641 #if !UCONFIG_NO_CONVERSION 3644 int32_t doExtract(int32_t start, int32_t length,
3645 char *dest, int32_t destCapacity,
3659 void doCodepageCreate(
const char *codepageData,
3661 const char *codepage);
3668 doCodepageCreate(
const char *codepageData,
3686 UBool cloneArrayIfNeeded(int32_t newCapacity = -1,
3687 int32_t growCapacity = -1,
3688 UBool doCopyArray =
true,
3689 int32_t **pBufferToDelete = 0,
3690 UBool forceClone =
false);
3698 caseMap(int32_t caseLocale, uint32_t options,
3706 int32_t removeRef(
void);
3707 int32_t refCount(
void)
const;
3717 kInvalidUChar=0xffff,
3723 kUsingStackBuffer=2,
3725 kBufferIsReadonly=8,
3728 kAllStorageFlags=0x1f,
3731 kLength1=1<<kLengthShift,
3732 kMaxShortLength=0x3ff,
3733 kLengthIsLarge=0xffe0,
3736 kShortString=kUsingStackBuffer,
3737 kLongString=kRefCounted,
3738 kReadonlyAlias=kBufferIsReadonly,
3742 friend class UnicodeStringAppendable;
3744 union StackBufferOrFields;
3745 friend union StackBufferOrFields;
3788 union StackBufferOrFields {
3792 int16_t fLengthAndFlags;
3793 char16_t fBuffer[US_STACKBUF_SIZE];
3796 int16_t fLengthAndFlags;
3815 operator+ (
const UnicodeString &s1,
const UnicodeString &s2);
3826 UnicodeString::pinIndex(int32_t& start)
const 3831 }
else if(start > length()) {
3837 UnicodeString::pinIndices(int32_t& start,
3838 int32_t& _length)
const 3841 int32_t len = length();
3844 }
else if(start > len) {
3849 }
else if(_length > (len - start)) {
3850 _length = (len - start);
3855 UnicodeString::getArrayStart() {
3856 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3857 fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
3860 inline const char16_t*
3861 UnicodeString::getArrayStart()
const {
3862 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3863 fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
3871 UnicodeString::UnicodeString() {
3872 fUnion.fStackFields.fLengthAndFlags=kShortString;
3875 inline UnicodeString::UnicodeString(
const std::nullptr_t ) {
3876 fUnion.fStackFields.fLengthAndFlags=kShortString;
3879 inline UnicodeString::UnicodeString(
const std::nullptr_t , int32_t ) {
3880 fUnion.fStackFields.fLengthAndFlags=kShortString;
3883 inline UnicodeString::UnicodeString(std::nullptr_t , int32_t , int32_t ) {
3884 fUnion.fStackFields.fLengthAndFlags=kShortString;
3891 UnicodeString::hasShortLength()
const {
3892 return fUnion.fFields.fLengthAndFlags>=0;
3896 UnicodeString::getShortLength()
const {
3899 return fUnion.fFields.fLengthAndFlags>>kLengthShift;
3903 UnicodeString::length()
const {
3904 return hasShortLength() ? getShortLength() : fUnion.fFields.fLength;
3908 UnicodeString::getCapacity()
const {
3909 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3910 US_STACKBUF_SIZE : fUnion.fFields.fCapacity;
3914 UnicodeString::hashCode()
const 3915 {
return doHashCode(); }
3918 UnicodeString::isBogus()
const 3919 {
return (
UBool)(fUnion.fFields.fLengthAndFlags & kIsBogus); }
3922 UnicodeString::isWritable()
const 3923 {
return (
UBool)!(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus)); }
3926 UnicodeString::isBufferWritable()
const 3929 !(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus|kBufferIsReadonly)) &&
3930 (!(fUnion.fFields.fLengthAndFlags&kRefCounted) || refCount()==1));
3933 inline const char16_t *
3934 UnicodeString::getBuffer()
const {
3935 if(fUnion.fFields.fLengthAndFlags&(kIsBogus|kOpenGetBuffer)) {
3937 }
else if(fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) {
3938 return fUnion.fStackFields.fBuffer;
3940 return fUnion.fFields.fArray;
3948 UnicodeString::doCompare(int32_t start,
3952 int32_t srcLength)
const 3955 return (int8_t)!isBogus();
3957 srcText.pinIndices(srcStart, srcLength);
3958 return doCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
3963 UnicodeString::doEqualsSubstring(int32_t start,
3965 const UnicodeString& srcText,
3967 int32_t srcLength)
const 3969 if(srcText.isBogus()) {
3972 srcText.pinIndices(srcStart, srcLength);
3973 return !isBogus() && doEqualsSubstring(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
3983 int32_t len = length(), textLength = text.
length();
3984 return !text.
isBogus() && len == textLength && doEquals(text, len);
3990 {
return (!
operator==(text)); }
3994 {
return doCompare(0, length(), text, 0, text.
length()) == 1; }
3998 {
return doCompare(0, length(), text, 0, text.
length()) == -1; }
4002 {
return doCompare(0, length(), text, 0, text.
length()) != -1; }
4006 {
return doCompare(0, length(), text, 0, text.
length()) != 1; }
4010 {
return doCompare(0, length(), text, 0, text.
length()); }
4013 UnicodeString::compare(int32_t start,
4016 {
return doCompare(start, _length, srcText, 0, srcText.
length()); }
4020 int32_t srcLength)
const 4021 {
return doCompare(0, length(), srcChars, 0, srcLength); }
4024 UnicodeString::compare(int32_t start,
4028 int32_t srcLength)
const 4029 {
return doCompare(start, _length, srcText, srcStart, srcLength); }
4032 UnicodeString::compare(int32_t start,
4034 const char16_t *srcChars)
const 4035 {
return doCompare(start, _length, srcChars, 0, _length); }
4038 UnicodeString::compare(int32_t start,
4040 const char16_t *srcChars,
4042 int32_t srcLength)
const 4043 {
return doCompare(start, _length, srcChars, srcStart, srcLength); }
4046 UnicodeString::compareBetween(int32_t start,
4050 int32_t srcLimit)
const 4051 {
return doCompare(start, limit - start,
4052 srcText, srcStart, srcLimit - srcStart); }
4055 UnicodeString::doCompareCodePointOrder(int32_t start,
4059 int32_t srcLength)
const 4062 return (int8_t)!isBogus();
4064 srcText.pinIndices(srcStart, srcLength);
4065 return doCompareCodePointOrder(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
4071 {
return doCompareCodePointOrder(0, length(), text, 0, text.
length()); }
4074 UnicodeString::compareCodePointOrder(int32_t start,
4077 {
return doCompareCodePointOrder(start, _length, srcText, 0, srcText.
length()); }
4081 int32_t srcLength)
const 4082 {
return doCompareCodePointOrder(0, length(), srcChars, 0, srcLength); }
4085 UnicodeString::compareCodePointOrder(int32_t start,
4089 int32_t srcLength)
const 4090 {
return doCompareCodePointOrder(start, _length, srcText, srcStart, srcLength); }
4093 UnicodeString::compareCodePointOrder(int32_t start,
4095 const char16_t *srcChars)
const 4096 {
return doCompareCodePointOrder(start, _length, srcChars, 0, _length); }
4099 UnicodeString::compareCodePointOrder(int32_t start,
4101 const char16_t *srcChars,
4103 int32_t srcLength)
const 4104 {
return doCompareCodePointOrder(start, _length, srcChars, srcStart, srcLength); }
4107 UnicodeString::compareCodePointOrderBetween(int32_t start,
4111 int32_t srcLimit)
const 4112 {
return doCompareCodePointOrder(start, limit - start,
4113 srcText, srcStart, srcLimit - srcStart); }
4116 UnicodeString::doCaseCompare(int32_t start,
4121 uint32_t options)
const 4124 return (int8_t)!isBogus();
4126 srcText.pinIndices(srcStart, srcLength);
4127 return doCaseCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength, options);
4133 return doCaseCompare(0, length(), text, 0, text.
length(), options);
4137 UnicodeString::caseCompare(int32_t start,
4140 uint32_t options)
const {
4141 return doCaseCompare(start, _length, srcText, 0, srcText.
length(), options);
4147 uint32_t options)
const {
4148 return doCaseCompare(0, length(), srcChars, 0, srcLength, options);
4152 UnicodeString::caseCompare(int32_t start,
4157 uint32_t options)
const {
4158 return doCaseCompare(start, _length, srcText, srcStart, srcLength, options);
4162 UnicodeString::caseCompare(int32_t start,
4164 const char16_t *srcChars,
4165 uint32_t options)
const {
4166 return doCaseCompare(start, _length, srcChars, 0, _length, options);
4170 UnicodeString::caseCompare(int32_t start,
4172 const char16_t *srcChars,
4175 uint32_t options)
const {
4176 return doCaseCompare(start, _length, srcChars, srcStart, srcLength, options);
4180 UnicodeString::caseCompareBetween(int32_t start,
4185 uint32_t options)
const {
4186 return doCaseCompare(start, limit - start, srcText, srcStart, srcLimit - srcStart, options);
4194 int32_t _length)
const 4197 srcText.pinIndices(srcStart, srcLength);
4199 return indexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
4207 {
return indexOf(text, 0, text.
length(), 0, length()); }
4211 int32_t start)
const {
4213 return indexOf(text, 0, text.
length(), start, length() - start);
4219 int32_t _length)
const 4220 {
return indexOf(text, 0, text.
length(), start, _length); }
4223 UnicodeString::indexOf(
const char16_t *srcChars,
4225 int32_t start)
const {
4227 return indexOf(srcChars, 0, srcLength, start, length() - start);
4234 int32_t _length)
const 4235 {
return indexOf(srcChars, 0, srcLength, start, _length); }
4238 UnicodeString::indexOf(char16_t c,
4240 int32_t _length)
const 4241 {
return doIndexOf(c, start, _length); }
4246 int32_t _length)
const 4247 {
return doIndexOf(c, start, _length); }
4250 UnicodeString::indexOf(char16_t c)
const 4251 {
return doIndexOf(c, 0, length()); }
4255 {
return indexOf(c, 0, length()); }
4258 UnicodeString::indexOf(char16_t c,
4259 int32_t start)
const {
4261 return doIndexOf(c, start, length() - start);
4266 int32_t start)
const {
4268 return indexOf(c, start, length() - start);
4275 int32_t _length)
const 4276 {
return lastIndexOf(srcChars, 0, srcLength, start, _length); }
4279 UnicodeString::lastIndexOf(
const char16_t *srcChars,
4281 int32_t start)
const {
4283 return lastIndexOf(srcChars, 0, srcLength, start, length() - start);
4291 int32_t _length)
const 4294 srcText.pinIndices(srcStart, srcLength);
4296 return lastIndexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
4305 int32_t _length)
const 4306 {
return lastIndexOf(text, 0, text.
length(), start, _length); }
4310 int32_t start)
const {
4312 return lastIndexOf(text, 0, text.
length(), start, length() - start);
4317 {
return lastIndexOf(text, 0, text.
length(), 0, length()); }
4320 UnicodeString::lastIndexOf(char16_t c,
4322 int32_t _length)
const 4323 {
return doLastIndexOf(c, start, _length); }
4328 int32_t _length)
const {
4329 return doLastIndexOf(c, start, _length);
4333 UnicodeString::lastIndexOf(char16_t c)
const 4334 {
return doLastIndexOf(c, 0, length()); }
4338 return lastIndexOf(c, 0, length());
4342 UnicodeString::lastIndexOf(char16_t c,
4343 int32_t start)
const {
4345 return doLastIndexOf(c, start, length() - start);
4350 int32_t start)
const {
4352 return lastIndexOf(c, start, length() - start);
4357 {
return doEqualsSubstring(0, text.
length(), text, 0, text.
length()); }
4362 int32_t srcLength)
const 4363 {
return doEqualsSubstring(0, srcLength, srcText, srcStart, srcLength); }
4370 return doEqualsSubstring(0, srcLength, srcChars, 0, srcLength);
4374 UnicodeString::startsWith(
const char16_t *srcChars, int32_t srcStart, int32_t srcLength)
const {
4378 return doEqualsSubstring(0, srcLength, srcChars, srcStart, srcLength);
4383 {
return doEqualsSubstring(length() - text.
length(), text.
length(),
4384 text, 0, text.
length()); }
4389 int32_t srcLength)
const {
4390 srcText.pinIndices(srcStart, srcLength);
4391 return doEqualsSubstring(length() - srcLength, srcLength,
4392 srcText, srcStart, srcLength);
4397 int32_t srcLength)
const {
4401 return doEqualsSubstring(length() - srcLength, srcLength, srcChars, 0, srcLength);
4405 UnicodeString::endsWith(
const char16_t *srcChars,
4407 int32_t srcLength)
const {
4411 return doEqualsSubstring(length() - srcLength, srcLength,
4412 srcChars, srcStart, srcLength);
4419 UnicodeString::replace(int32_t start,
4422 {
return doReplace(start, _length, srcText, 0, srcText.
length()); }
4425 UnicodeString::replace(int32_t start,
4430 {
return doReplace(start, _length, srcText, srcStart, srcLength); }
4433 UnicodeString::replace(int32_t start,
4437 {
return doReplace(start, _length, srcChars, 0, srcLength); }
4440 UnicodeString::replace(int32_t start,
4442 const char16_t *srcChars,
4445 {
return doReplace(start, _length, srcChars, srcStart, srcLength); }
4448 UnicodeString::replace(int32_t start,
4451 {
return doReplace(start, _length, &srcChar, 0, 1); }
4454 UnicodeString::replaceBetween(int32_t start,
4457 {
return doReplace(start, limit - start, srcText, 0, srcText.
length()); }
4460 UnicodeString::replaceBetween(int32_t start,
4465 {
return doReplace(start, limit - start, srcText, srcStart, srcLimit - srcStart); }
4470 {
return findAndReplace(0, length(), oldText, 0, oldText.
length(),
4471 newText, 0, newText.
length()); }
4474 UnicodeString::findAndReplace(int32_t start,
4478 {
return findAndReplace(start, _length, oldText, 0, oldText.
length(),
4479 newText, 0, newText.
length()); }
4485 UnicodeString::doExtract(int32_t start,
4488 { target.
replace(0, target.
length(), *
this, start, _length); }
4491 UnicodeString::extract(int32_t start,
4494 int32_t targetStart)
const 4495 { doExtract(start, _length, target, targetStart); }
4498 UnicodeString::extract(int32_t start,
4501 { doExtract(start, _length, target); }
4503 #if !UCONFIG_NO_CONVERSION 4506 UnicodeString::extract(int32_t start,
4509 const char *codepage)
const 4513 return extract(start, _length, dst, dst!=0 ? 0xffffffff : 0, codepage);
4519 UnicodeString::extractBetween(int32_t start,
4522 int32_t dstStart)
const {
4525 doExtract(start, limit - start, dst, dstStart);
4529 UnicodeString::tempSubStringBetween(int32_t start, int32_t limit)
const {
4530 return tempSubString(start, limit - start);
4534 UnicodeString::doCharAt(int32_t offset)
const 4536 if((uint32_t)offset < (uint32_t)length()) {
4537 return getArrayStart()[offset];
4539 return kInvalidUChar;
4544 UnicodeString::charAt(int32_t offset)
const 4545 {
return doCharAt(offset); }
4548 UnicodeString::operator[] (int32_t offset)
const 4549 {
return doCharAt(offset); }
4552 UnicodeString::isEmpty()
const {
4554 return (fUnion.fFields.fLengthAndFlags>>kLengthShift) == 0;
4561 UnicodeString::setZeroLength() {
4562 fUnion.fFields.fLengthAndFlags &= kAllStorageFlags;
4566 UnicodeString::setShortLength(int32_t len) {
4568 fUnion.fFields.fLengthAndFlags =
4569 (int16_t)((fUnion.fFields.fLengthAndFlags & kAllStorageFlags) | (len << kLengthShift));
4573 UnicodeString::setLength(int32_t len) {
4574 if(len <= kMaxShortLength) {
4575 setShortLength(len);
4577 fUnion.fFields.fLengthAndFlags |= kLengthIsLarge;
4578 fUnion.fFields.fLength = len;
4583 UnicodeString::setToEmpty() {
4584 fUnion.fFields.fLengthAndFlags = kShortString;
4588 UnicodeString::setArray(char16_t *array, int32_t len, int32_t capacity) {
4590 fUnion.fFields.fArray = array;
4591 fUnion.fFields.fCapacity = capacity;
4594 inline UnicodeString&
4595 UnicodeString::operator= (char16_t ch)
4596 {
return doReplace(0, length(), &ch, 0, 1); }
4600 {
return replace(0, length(), ch); }
4608 return doReplace(0, length(), srcText, srcStart, srcLength);
4616 srcText.pinIndex(srcStart);
4617 return doReplace(0, length(), srcText, srcStart, srcText.
length() - srcStart);
4623 return copyFrom(srcText);
4627 UnicodeString::setTo(
const char16_t *srcChars,
4631 return doReplace(0, length(), srcChars, 0, srcLength);
4635 UnicodeString::setTo(char16_t srcChar)
4638 return doReplace(0, length(), &srcChar, 0, 1);
4645 return replace(0, length(), srcChar);
4652 {
return doAppend(srcText, srcStart, srcLength); }
4656 {
return doAppend(srcText, 0, srcText.
length()); }
4659 UnicodeString::append(
const char16_t *srcChars,
4662 {
return doAppend(srcChars, srcStart, srcLength); }
4667 {
return doAppend(srcChars, 0, srcLength); }
4670 UnicodeString::append(char16_t srcChar)
4671 {
return doAppend(&srcChar, 0, 1); }
4674 UnicodeString::operator+= (char16_t ch)
4675 {
return doAppend(&ch, 0, 1); }
4684 {
return doAppend(srcText, 0, srcText.
length()); }
4687 UnicodeString::insert(int32_t start,
4691 {
return doReplace(start, 0, srcText, srcStart, srcLength); }
4694 UnicodeString::insert(int32_t start,
4696 {
return doReplace(start, 0, srcText, 0, srcText.
length()); }
4699 UnicodeString::insert(int32_t start,
4700 const char16_t *srcChars,
4703 {
return doReplace(start, 0, srcChars, srcStart, srcLength); }
4706 UnicodeString::insert(int32_t start,
4709 {
return doReplace(start, 0, srcChars, 0, srcLength); }
4712 UnicodeString::insert(int32_t start,
4714 {
return doReplace(start, 0, &srcChar, 0, 1); }
4717 UnicodeString::insert(int32_t start,
4719 {
return replace(start, 0, srcChar); }
4723 UnicodeString::remove()
4735 UnicodeString::remove(int32_t start,
4738 if(start <= 0 && _length ==
INT32_MAX) {
4742 return doReplace(start, _length,
nullptr, 0, 0);
4746 UnicodeString::removeBetween(int32_t start,
4748 {
return doReplace(start, limit - start,
nullptr, 0, 0); }
4751 UnicodeString::retainBetween(int32_t start, int32_t limit) {
4753 return doReplace(0, start,
nullptr, 0, 0);
4757 UnicodeString::truncate(int32_t targetLength)
4759 if(isBogus() && targetLength == 0) {
4763 }
else if((uint32_t)targetLength < (uint32_t)length()) {
4764 setLength(targetLength);
4772 UnicodeString::reverse()
4773 {
return doReverse(0, length()); }
4776 UnicodeString::reverse(int32_t start,
4778 {
return doReverse(start, _length); }
#define UNISTR_OBJECT_SIZE
Desired sizeof(UnicodeString) in bytes.
bool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
EInvariant
Constant to be used in the UnicodeString(char *, int32_t, EInvariant) constructor which constructs a ...
#define U_CAPI
This is used to declare a function as a public ICU C API.
UnicodeString(const uint16_t *text, int32_t textLength)
uint16_t * constructor.
friend void swap(UnicodeString &s1, UnicodeString &s2) noexcept
Non-member UnicodeString swap function.
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 (always 2).
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.
U_CAPI int32_t u_strlen(const UChar *s)
Determine the length of an array of UChar.
#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".
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...
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.
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().
char16_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".
virtual Replaceable * clone() const
Clone this object, an instance of a subclass of Replaceable.
#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...
int8_t UBool
The ICU boolean type, a signed-byte integer.
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.