33 #if U_SHOW_CPLUSPLUS_API 36 #include <string_view> 56 #if !UCONFIG_NO_BREAK_ITERATION 75 char16_t *dest, int32_t destCapacity,
76 const char16_t *src, int32_t srcLength,
83 class StringCharacterIterator;
84 class UnicodeStringAppendable;
98 #define US_INV icu::UnicodeString::kInvariant 120 #if !U_CHAR16_IS_TYPEDEF 121 # define UNICODE_STRING(cs, _length) icu::UnicodeString(true, u ## cs, _length) 123 # 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 330 #ifndef U_HIDE_DRAFT_API 346 template<
typename S,
typename = std::enable_if_t<ConvertibleToU16StringView<S>>>
348 std::u16string_view sv(internal::toU16StringView(text));
350 return !isBogus() && (len =
length()) == sv.length() && doEquals(sv.data(), len);
352 #endif // U_HIDE_DRAFT_API 363 #ifndef U_HIDE_DRAFT_API 381 template<
typename S,
typename = std::enable_if_t<ConvertibleToU16StringView<S>>>
385 #endif // U_HIDE_DRAFT_API 451 inline int8_t compare(int32_t start,
472 inline int8_t compare(int32_t start,
476 int32_t srcLength)
const;
491 int32_t srcLength)
const;
507 inline int8_t compare(int32_t start,
509 const char16_t *srcChars)
const;
528 inline int8_t compare(int32_t start,
530 const char16_t *srcChars,
532 int32_t srcLength)
const;
551 inline int8_t compareBetween(int32_t start,
555 int32_t srcLimit)
const;
574 inline int8_t compareCodePointOrder(
const UnicodeString& text)
const;
595 inline int8_t compareCodePointOrder(int32_t start,
620 inline int8_t compareCodePointOrder(int32_t start,
624 int32_t srcLength)
const;
645 int32_t srcLength)
const;
666 inline int8_t compareCodePointOrder(int32_t start,
668 const char16_t *srcChars)
const;
691 inline int8_t compareCodePointOrder(int32_t start,
693 const char16_t *srcChars,
695 int32_t srcLength)
const;
718 inline int8_t compareCodePointOrderBetween(int32_t start,
722 int32_t srcLimit)
const;
742 inline int8_t caseCompare(
const UnicodeString& text, uint32_t options)
const;
764 inline int8_t caseCompare(int32_t start,
767 uint32_t options)
const;
791 inline int8_t caseCompare(int32_t start,
796 uint32_t options)
const;
819 uint32_t options)
const;
841 inline int8_t caseCompare(int32_t start,
843 const char16_t *srcChars,
844 uint32_t options)
const;
868 inline int8_t caseCompare(int32_t start,
870 const char16_t *srcChars,
873 uint32_t options)
const;
897 inline int8_t caseCompareBetween(int32_t start,
902 uint32_t options)
const;
925 int32_t srcLength)
const;
936 int32_t srcLength)
const;
947 inline UBool startsWith(
const char16_t *srcChars,
949 int32_t srcLength)
const;
972 int32_t srcLength)
const;
983 int32_t srcLength)
const;
995 inline UBool endsWith(
const char16_t *srcChars,
997 int32_t srcLength)
const;
1022 int32_t start)
const;
1037 int32_t length)
const;
1059 int32_t length)
const;
1072 inline int32_t indexOf(
const char16_t *srcChars,
1074 int32_t start)
const;
1091 int32_t length)
const;
1109 int32_t indexOf(
const char16_t *srcChars,
1113 int32_t length)
const;
1122 inline int32_t indexOf(char16_t c)
const;
1132 inline int32_t indexOf(
UChar32 c)
const;
1142 inline int32_t indexOf(char16_t c,
1143 int32_t start)
const;
1154 inline int32_t indexOf(
UChar32 c,
1155 int32_t start)
const;
1167 inline int32_t indexOf(char16_t c,
1169 int32_t length)
const;
1182 inline int32_t indexOf(
UChar32 c,
1184 int32_t length)
const;
1194 inline int32_t lastIndexOf(
const UnicodeString& text)
const;
1206 int32_t start)
const;
1221 int32_t length)
const;
1243 int32_t length)
const;
1255 inline int32_t lastIndexOf(
const char16_t *srcChars,
1257 int32_t start)
const;
1274 int32_t length)
const;
1292 int32_t lastIndexOf(
const char16_t *srcChars,
1296 int32_t length)
const;
1305 inline int32_t lastIndexOf(char16_t c)
const;
1315 inline int32_t lastIndexOf(
UChar32 c)
const;
1325 inline int32_t lastIndexOf(char16_t c,
1326 int32_t start)
const;
1337 inline int32_t lastIndexOf(
UChar32 c,
1338 int32_t start)
const;
1350 inline int32_t lastIndexOf(char16_t c,
1352 int32_t length)
const;
1365 inline int32_t lastIndexOf(
UChar32 c,
1367 int32_t length)
const;
1380 inline char16_t
charAt(int32_t offset)
const;
1389 inline char16_t operator[] (int32_t offset)
const;
1419 int32_t getChar32Start(int32_t offset)
const;
1437 int32_t getChar32Limit(int32_t offset)
const;
1489 int32_t moveIndex32(int32_t index, int32_t delta)
const;
1508 inline void extract(int32_t start,
1511 int32_t dstStart = 0)
const;
1535 extract(
Char16Ptr dest, int32_t destCapacity,
1547 inline void extract(int32_t start,
1565 int32_t dstStart = 0)
const;
1600 int32_t extract(int32_t start,
1601 int32_t startLength,
1603 int32_t targetCapacity,
1604 enum EInvariant inv)
const;
1606 #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION 1627 int32_t extract(int32_t start,
1628 int32_t startLength,
1630 uint32_t targetLength)
const;
1634 #if !UCONFIG_NO_CONVERSION 1661 inline int32_t extract(int32_t start,
1662 int32_t startLength,
1664 const char* codepage =
nullptr)
const;
1695 int32_t extract(int32_t start,
1696 int32_t startLength,
1698 uint32_t targetLength,
1699 const char *codepage)
const;
1718 int32_t extract(
char *dest, int32_t destCapacity,
1776 template<
typename StringClass>
1810 inline int32_t
length()
const;
1826 countChar32(int32_t start=0, int32_t length=
INT32_MAX)
const;
1852 hasMoreChar32Than(int32_t start, int32_t length, int32_t number)
const;
1859 inline UBool isEmpty()
const;
1870 inline int32_t getCapacity()
const;
1879 inline int32_t hashCode()
const;
1893 inline UBool isBogus()
const;
1948 #ifndef U_HIDE_DRAFT_API 1959 template<
typename S,
typename = std::enable_if_t<ConvertibleToU16StringView<S>>>
1962 return doReplace(0,
length(), internal::toU16StringView(src));
1964 #endif // U_HIDE_DRAFT_API 1989 friend inline void U_EXPORT2
2109 int32_t textLength);
2132 int32_t buffCapacity);
2215 #ifndef U_HIDE_DRAFT_API 2226 template<
typename S,
typename = std::enable_if_t<ConvertibleToU16StringView<S>>>
2228 return doAppend(internal::toU16StringView(src));
2230 #endif // U_HIDE_DRAFT_API 2288 #ifndef U_HIDE_DRAFT_API 2299 template<
typename S,
typename = std::enable_if_t<ConvertibleToU16StringView<S>>>
2301 return doAppend(internal::toU16StringView(src));
2303 #endif // U_HIDE_DRAFT_API 2367 const char16_t *srcChars,
2467 const char16_t *srcChars,
2580 virtual void copy(int32_t start, int32_t limit, int32_t dest)
override;
2659 int32_t length =
static_cast<int32_t
>(
INT32_MAX));
2670 int32_t limit = static_cast<int32_t>(
INT32_MAX));
2696 UBool padLeading(int32_t targetLength,
2697 char16_t padChar = 0x0020);
2710 UBool padTrailing(int32_t targetLength,
2711 char16_t padChar = 0x0020);
2719 inline UBool truncate(int32_t targetLength);
2782 #if !UCONFIG_NO_BREAK_ITERATION 2937 char16_t *getBuffer(int32_t minCapacity);
2959 void releaseBuffer(int32_t newLength=-1);
2991 inline const char16_t *getBuffer()
const;
3026 const char16_t *getTerminatedBuffer();
3028 #ifndef U_HIDE_DRAFT_API 3035 inline operator std::u16string_view()
const {
3036 return {getBuffer(),
static_cast<std::u16string_view::size_type
>(
length())};
3039 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN) 3049 inline operator std::wstring_view()
const {
3050 const char16_t *p = getBuffer();
3051 #ifdef U_ALIASING_BARRIER 3054 return {
reinterpret_cast<const wchar_t *
>(p), (std::wstring_view::size_type)
length() };
3056 #endif // U_SIZEOF_WCHAR_T 3057 #endif // U_HIDE_DRAFT_API 3103 #ifdef U_HIDE_DRAFT_API 3125 #endif // U_HIDE_DRAFT_API 3127 #if !U_CHAR16_IS_TYPEDEF && \ 3128 (defined(U_HIDE_DRAFT_API) || (defined(_LIBCPP_VERSION) && _LIBCPP_VERSION >= 180000)) 3149 UnicodeString(ConstChar16Ptr(text), -1) {}
3152 #if defined(U_HIDE_DRAFT_API) && (U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)) 3174 UnicodeString(ConstChar16Ptr(text), -1) {}
3205 UnicodeString(
const char16_t *text,
3206 int32_t textLength);
3208 #if !U_CHAR16_IS_TYPEDEF 3229 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN) 3258 inline UnicodeString(
const std::nullptr_t text, int32_t textLength);
3260 #ifndef U_HIDE_DRAFT_API 3273 template<
typename S,
typename = std::enable_if_t<ConvertibleToU16StringView<S>>>
3275 fUnion.fFields.fLengthAndFlags = kShortString;
3276 doAppend(internal::toU16StringViewNullable(text));
3278 #endif // U_HIDE_DRAFT_API 3312 int32_t textLength);
3332 UnicodeString(char16_t *buffer, int32_t buffLength, int32_t buffCapacity);
3334 #if !U_CHAR16_IS_TYPEDEF 3347 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN) 3369 inline UnicodeString(std::nullptr_t buffer, int32_t buffLength, int32_t buffCapacity);
3371 #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION 3406 UnicodeString(
const char *codepageData, int32_t dataLength);
3410 #if !UCONFIG_NO_CONVERSION 3429 UnicodeString(
const char *codepageData,
const char *codepage);
3448 UnicodeString(
const char *codepageData, int32_t dataLength,
const char *codepage);
3472 const char *src, int32_t srcLength,
3510 UnicodeString(
const char *src, int32_t textLength,
enum EInvariant inv);
3576 #ifndef U_HIDE_DRAFT_API 3599 template<
typename S,
typename = std::enable_if_t<ConvertibleToU16StringView<S>>>
3601 return readOnlyAliasFromU16StringView(internal::toU16StringView(text));
3624 return readOnlyAliasFromUnicodeString(text);
3626 #endif // U_HIDE_DRAFT_API 3713 UChar32 unescapeAt(int32_t &offset)
const;
3720 static UClassID U_EXPORT2 getStaticClassID();
3738 virtual int32_t
getLength()
const override;
3745 virtual char16_t
getCharAt(int32_t offset)
const override;
3755 static UnicodeString readOnlyAliasFromU16StringView(std::u16string_view text);
3766 toUTF8(int32_t start, int32_t len,
3767 char *target, int32_t capacity)
const;
3774 return doEquals(text.getArrayStart(), len);
3776 UBool doEquals(
const char16_t *text, int32_t len)
const;
3779 doEqualsSubstring(int32_t start,
3781 const UnicodeString& srcText,
3783 int32_t srcLength)
const;
3785 UBool doEqualsSubstring(int32_t start,
3787 const char16_t *srcChars,
3789 int32_t srcLength)
const;
3792 doCompare(int32_t start,
3794 const UnicodeString& srcText,
3796 int32_t srcLength)
const;
3798 int8_t doCompare(int32_t start,
3800 const char16_t *srcChars,
3802 int32_t srcLength)
const;
3805 doCompareCodePointOrder(int32_t start,
3807 const UnicodeString& srcText,
3809 int32_t srcLength)
const;
3811 int8_t doCompareCodePointOrder(int32_t start,
3813 const char16_t *srcChars,
3815 int32_t srcLength)
const;
3818 doCaseCompare(int32_t start,
3820 const UnicodeString &srcText,
3823 uint32_t options)
const;
3826 doCaseCompare(int32_t start,
3828 const char16_t *srcChars,
3831 uint32_t options)
const;
3833 int32_t doIndexOf(char16_t c,
3835 int32_t length)
const;
3839 int32_t length)
const;
3841 int32_t doLastIndexOf(char16_t c,
3843 int32_t length)
const;
3845 int32_t doLastIndexOf(
UChar32 c,
3847 int32_t length)
const;
3849 void doExtract(int32_t start,
3852 int32_t dstStart)
const;
3854 inline void doExtract(int32_t start,
3856 UnicodeString& target)
const;
3858 inline char16_t doCharAt(int32_t offset)
const;
3860 UnicodeString& doReplace(int32_t start,
3862 const UnicodeString& srcText,
3866 UnicodeString& doReplace(int32_t start,
3868 const char16_t *srcChars,
3871 UnicodeString& doReplace(int32_t start, int32_t length, std::u16string_view src);
3873 UnicodeString& doAppend(
const UnicodeString& src, int32_t srcStart, int32_t srcLength);
3874 UnicodeString& doAppend(
const char16_t *srcChars, int32_t srcStart, int32_t srcLength);
3875 UnicodeString& doAppend(std::u16string_view src);
3877 UnicodeString& doReverse(int32_t start,
3881 int32_t doHashCode()
const;
3885 inline char16_t* getArrayStart();
3886 inline const char16_t* getArrayStart()
const;
3888 inline UBool hasShortLength()
const;
3889 inline int32_t getShortLength()
const;
3893 inline UBool isWritable()
const;
3896 inline UBool isBufferWritable()
const;
3899 inline void setZeroLength();
3900 inline void setShortLength(int32_t len);
3901 inline void setLength(int32_t len);
3902 inline void setToEmpty();
3903 inline void setArray(char16_t *array, int32_t len, int32_t capacity);
3910 UBool allocate(int32_t capacity);
3913 void releaseArray();
3919 UnicodeString ©From(
const UnicodeString &src,
UBool fastCopy=
false);
3922 void copyFieldsFrom(UnicodeString &src,
UBool setSrcToBogus) noexcept;
3925 inline void pinIndex(int32_t& start)
const;
3926 inline void pinIndices(int32_t& start,
3927 int32_t& length)
const;
3929 #if !UCONFIG_NO_CONVERSION 3932 int32_t doExtract(int32_t start, int32_t length,
3933 char *dest, int32_t destCapacity,
3947 void doCodepageCreate(
const char *codepageData,
3949 const char *codepage);
3956 doCodepageCreate(
const char *codepageData,
3974 UBool cloneArrayIfNeeded(int32_t newCapacity = -1,
3975 int32_t growCapacity = -1,
3976 UBool doCopyArray =
true,
3977 int32_t** pBufferToDelete =
nullptr,
3978 UBool forceClone =
false);
3986 caseMap(int32_t caseLocale, uint32_t options,
3988 BreakIterator *iter,
3994 int32_t removeRef();
3995 int32_t refCount()
const;
4005 kInvalidUChar=0xffff,
4011 kUsingStackBuffer=2,
4013 kBufferIsReadonly=8,
4016 kAllStorageFlags=0x1f,
4019 kLength1=1<<kLengthShift,
4020 kMaxShortLength=0x3ff,
4021 kLengthIsLarge=0xffe0,
4024 kShortString=kUsingStackBuffer,
4025 kLongString=kRefCounted,
4026 kReadonlyAlias=kBufferIsReadonly,
4030 friend class UnicodeStringAppendable;
4032 union StackBufferOrFields;
4033 friend union StackBufferOrFields;
4076 union StackBufferOrFields {
4080 int16_t fLengthAndFlags;
4081 char16_t fBuffer[US_STACKBUF_SIZE];
4084 int16_t fLengthAndFlags;
4103 operator+ (
const UnicodeString &s1,
const UnicodeString &s2);
4105 #ifndef U_HIDE_DRAFT_API 4116 template<
typename S,
typename = std::enable_if_t<ConvertibleToU16StringView<S>>>
4120 #endif // U_HIDE_DRAFT_API 4122 #ifndef U_FORCE_HIDE_INTERNAL_API 4137 UnicodeString::pinIndex(int32_t& start)
const 4142 }
else if(start > length()) {
4148 UnicodeString::pinIndices(int32_t& start,
4149 int32_t& _length)
const 4152 int32_t len = length();
4155 }
else if(start > len) {
4160 }
else if(_length > (len - start)) {
4161 _length = (len - start);
4166 UnicodeString::getArrayStart() {
4167 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
4168 fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
4171 inline const char16_t*
4172 UnicodeString::getArrayStart()
const {
4173 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
4174 fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
4182 UnicodeString::UnicodeString() {
4183 fUnion.fStackFields.fLengthAndFlags=kShortString;
4186 inline UnicodeString::UnicodeString(
const std::nullptr_t ) {
4187 fUnion.fStackFields.fLengthAndFlags=kShortString;
4190 inline UnicodeString::UnicodeString(
const std::nullptr_t , int32_t ) {
4191 fUnion.fStackFields.fLengthAndFlags=kShortString;
4194 inline UnicodeString::UnicodeString(std::nullptr_t , int32_t , int32_t ) {
4195 fUnion.fStackFields.fLengthAndFlags=kShortString;
4202 UnicodeString::hasShortLength()
const {
4203 return fUnion.fFields.fLengthAndFlags>=0;
4207 UnicodeString::getShortLength()
const {
4210 return fUnion.fFields.fLengthAndFlags>>kLengthShift;
4214 UnicodeString::length()
const {
4215 return hasShortLength() ? getShortLength() : fUnion.fFields.fLength;
4219 UnicodeString::getCapacity()
const {
4220 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
4221 US_STACKBUF_SIZE : fUnion.fFields.fCapacity;
4225 UnicodeString::hashCode()
const 4226 {
return doHashCode(); }
4229 UnicodeString::isBogus()
const 4230 {
return fUnion.fFields.fLengthAndFlags & kIsBogus; }
4233 UnicodeString::isWritable()
const 4234 {
return !(fUnion.fFields.fLengthAndFlags & (kOpenGetBuffer | kIsBogus)); }
4237 UnicodeString::isBufferWritable()
const 4240 !(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus|kBufferIsReadonly)) &&
4241 (!(fUnion.fFields.fLengthAndFlags&kRefCounted) || refCount()==1);
4244 inline const char16_t *
4245 UnicodeString::getBuffer()
const {
4246 if(fUnion.fFields.fLengthAndFlags&(kIsBogus|kOpenGetBuffer)) {
4248 }
else if(fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) {
4249 return fUnion.fStackFields.fBuffer;
4251 return fUnion.fFields.fArray;
4259 UnicodeString::doCompare(int32_t start,
4263 int32_t srcLength)
const 4266 return static_cast<int8_t
>(!isBogus());
4268 srcText.pinIndices(srcStart, srcLength);
4269 return doCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
4274 UnicodeString::doEqualsSubstring(int32_t start,
4276 const UnicodeString& srcText,
4278 int32_t srcLength)
const 4280 if(srcText.isBogus()) {
4283 srcText.pinIndices(srcStart, srcLength);
4284 return !isBogus() && doEqualsSubstring(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
4294 int32_t len = length(), textLength = text.
length();
4295 return !text.
isBogus() && len == textLength && doEquals(text, len);
4301 {
return (!
operator==(text)); }
4305 {
return doCompare(0, length(), text, 0, text.
length()) == 1; }
4309 {
return doCompare(0, length(), text, 0, text.
length()) == -1; }
4313 {
return doCompare(0, length(), text, 0, text.
length()) != -1; }
4317 {
return doCompare(0, length(), text, 0, text.
length()) != 1; }
4321 {
return doCompare(0, length(), text, 0, text.
length()); }
4324 UnicodeString::compare(int32_t start,
4327 {
return doCompare(start, _length, srcText, 0, srcText.
length()); }
4331 int32_t srcLength)
const 4332 {
return doCompare(0, length(), srcChars, 0, srcLength); }
4335 UnicodeString::compare(int32_t start,
4339 int32_t srcLength)
const 4340 {
return doCompare(start, _length, srcText, srcStart, srcLength); }
4343 UnicodeString::compare(int32_t start,
4345 const char16_t *srcChars)
const 4346 {
return doCompare(start, _length, srcChars, 0, _length); }
4349 UnicodeString::compare(int32_t start,
4351 const char16_t *srcChars,
4353 int32_t srcLength)
const 4354 {
return doCompare(start, _length, srcChars, srcStart, srcLength); }
4357 UnicodeString::compareBetween(int32_t start,
4361 int32_t srcLimit)
const 4362 {
return doCompare(start, limit - start,
4363 srcText, srcStart, srcLimit - srcStart); }
4366 UnicodeString::doCompareCodePointOrder(int32_t start,
4370 int32_t srcLength)
const 4373 return static_cast<int8_t
>(!isBogus());
4375 srcText.pinIndices(srcStart, srcLength);
4376 return doCompareCodePointOrder(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
4382 {
return doCompareCodePointOrder(0, length(), text, 0, text.
length()); }
4385 UnicodeString::compareCodePointOrder(int32_t start,
4388 {
return doCompareCodePointOrder(start, _length, srcText, 0, srcText.
length()); }
4392 int32_t srcLength)
const 4393 {
return doCompareCodePointOrder(0, length(), srcChars, 0, srcLength); }
4396 UnicodeString::compareCodePointOrder(int32_t start,
4400 int32_t srcLength)
const 4401 {
return doCompareCodePointOrder(start, _length, srcText, srcStart, srcLength); }
4404 UnicodeString::compareCodePointOrder(int32_t start,
4406 const char16_t *srcChars)
const 4407 {
return doCompareCodePointOrder(start, _length, srcChars, 0, _length); }
4410 UnicodeString::compareCodePointOrder(int32_t start,
4412 const char16_t *srcChars,
4414 int32_t srcLength)
const 4415 {
return doCompareCodePointOrder(start, _length, srcChars, srcStart, srcLength); }
4418 UnicodeString::compareCodePointOrderBetween(int32_t start,
4422 int32_t srcLimit)
const 4423 {
return doCompareCodePointOrder(start, limit - start,
4424 srcText, srcStart, srcLimit - srcStart); }
4427 UnicodeString::doCaseCompare(int32_t start,
4432 uint32_t options)
const 4435 return static_cast<int8_t
>(!isBogus());
4437 srcText.pinIndices(srcStart, srcLength);
4438 return doCaseCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength, options);
4444 return doCaseCompare(0, length(), text, 0, text.
length(), options);
4448 UnicodeString::caseCompare(int32_t start,
4451 uint32_t options)
const {
4452 return doCaseCompare(start, _length, srcText, 0, srcText.
length(), options);
4458 uint32_t options)
const {
4459 return doCaseCompare(0, length(), srcChars, 0, srcLength, options);
4463 UnicodeString::caseCompare(int32_t start,
4468 uint32_t options)
const {
4469 return doCaseCompare(start, _length, srcText, srcStart, srcLength, options);
4473 UnicodeString::caseCompare(int32_t start,
4475 const char16_t *srcChars,
4476 uint32_t options)
const {
4477 return doCaseCompare(start, _length, srcChars, 0, _length, options);
4481 UnicodeString::caseCompare(int32_t start,
4483 const char16_t *srcChars,
4486 uint32_t options)
const {
4487 return doCaseCompare(start, _length, srcChars, srcStart, srcLength, options);
4491 UnicodeString::caseCompareBetween(int32_t start,
4496 uint32_t options)
const {
4497 return doCaseCompare(start, limit - start, srcText, srcStart, srcLimit - srcStart, options);
4505 int32_t _length)
const 4508 srcText.pinIndices(srcStart, srcLength);
4510 return indexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
4518 {
return indexOf(text, 0, text.
length(), 0, length()); }
4522 int32_t start)
const {
4524 return indexOf(text, 0, text.
length(), start, length() - start);
4530 int32_t _length)
const 4531 {
return indexOf(text, 0, text.
length(), start, _length); }
4534 UnicodeString::indexOf(
const char16_t *srcChars,
4536 int32_t start)
const {
4538 return indexOf(srcChars, 0, srcLength, start, length() - start);
4545 int32_t _length)
const 4546 {
return indexOf(srcChars, 0, srcLength, start, _length); }
4549 UnicodeString::indexOf(char16_t c,
4551 int32_t _length)
const 4552 {
return doIndexOf(c, start, _length); }
4557 int32_t _length)
const 4558 {
return doIndexOf(c, start, _length); }
4561 UnicodeString::indexOf(char16_t c)
const 4562 {
return doIndexOf(c, 0, length()); }
4566 {
return indexOf(c, 0, length()); }
4569 UnicodeString::indexOf(char16_t c,
4570 int32_t start)
const {
4572 return doIndexOf(c, start, length() - start);
4577 int32_t start)
const {
4579 return indexOf(c, start, length() - start);
4586 int32_t _length)
const 4587 {
return lastIndexOf(srcChars, 0, srcLength, start, _length); }
4590 UnicodeString::lastIndexOf(
const char16_t *srcChars,
4592 int32_t start)
const {
4594 return lastIndexOf(srcChars, 0, srcLength, start, length() - start);
4602 int32_t _length)
const 4605 srcText.pinIndices(srcStart, srcLength);
4607 return lastIndexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
4616 int32_t _length)
const 4617 {
return lastIndexOf(text, 0, text.
length(), start, _length); }
4621 int32_t start)
const {
4623 return lastIndexOf(text, 0, text.
length(), start, length() - start);
4628 {
return lastIndexOf(text, 0, text.
length(), 0, length()); }
4631 UnicodeString::lastIndexOf(char16_t c,
4633 int32_t _length)
const 4634 {
return doLastIndexOf(c, start, _length); }
4639 int32_t _length)
const {
4640 return doLastIndexOf(c, start, _length);
4644 UnicodeString::lastIndexOf(char16_t c)
const 4645 {
return doLastIndexOf(c, 0, length()); }
4649 return lastIndexOf(c, 0, length());
4653 UnicodeString::lastIndexOf(char16_t c,
4654 int32_t start)
const {
4656 return doLastIndexOf(c, start, length() - start);
4661 int32_t start)
const {
4663 return lastIndexOf(c, start, length() - start);
4668 {
return doEqualsSubstring(0, text.
length(), text, 0, text.
length()); }
4673 int32_t srcLength)
const 4674 {
return doEqualsSubstring(0, srcLength, srcText, srcStart, srcLength); }
4681 return doEqualsSubstring(0, srcLength, srcChars, 0, srcLength);
4685 UnicodeString::startsWith(
const char16_t *srcChars, int32_t srcStart, int32_t srcLength)
const {
4689 return doEqualsSubstring(0, srcLength, srcChars, srcStart, srcLength);
4694 {
return doEqualsSubstring(length() - text.
length(), text.
length(),
4695 text, 0, text.
length()); }
4700 int32_t srcLength)
const {
4701 srcText.pinIndices(srcStart, srcLength);
4702 return doEqualsSubstring(length() - srcLength, srcLength,
4703 srcText, srcStart, srcLength);
4708 int32_t srcLength)
const {
4712 return doEqualsSubstring(length() - srcLength, srcLength, srcChars, 0, srcLength);
4716 UnicodeString::endsWith(
const char16_t *srcChars,
4718 int32_t srcLength)
const {
4722 return doEqualsSubstring(length() - srcLength, srcLength,
4723 srcChars, srcStart, srcLength);
4730 UnicodeString::replace(int32_t start,
4733 {
return doReplace(start, _length, srcText, 0, srcText.
length()); }
4736 UnicodeString::replace(int32_t start,
4741 {
return doReplace(start, _length, srcText, srcStart, srcLength); }
4744 UnicodeString::replace(int32_t start,
4748 {
return doReplace(start, _length, srcChars, 0, srcLength); }
4751 UnicodeString::replace(int32_t start,
4753 const char16_t *srcChars,
4756 {
return doReplace(start, _length, srcChars, srcStart, srcLength); }
4759 UnicodeString::replace(int32_t start,
4762 {
return doReplace(start, _length, &srcChar, 0, 1); }
4765 UnicodeString::replaceBetween(int32_t start,
4768 {
return doReplace(start, limit - start, srcText, 0, srcText.
length()); }
4771 UnicodeString::replaceBetween(int32_t start,
4776 {
return doReplace(start, limit - start, srcText, srcStart, srcLimit - srcStart); }
4781 {
return findAndReplace(0, length(), oldText, 0, oldText.
length(),
4782 newText, 0, newText.
length()); }
4785 UnicodeString::findAndReplace(int32_t start,
4789 {
return findAndReplace(start, _length, oldText, 0, oldText.
length(),
4790 newText, 0, newText.
length()); }
4796 UnicodeString::doExtract(int32_t start,
4799 { target.
replace(0, target.
length(), *
this, start, _length); }
4802 UnicodeString::extract(int32_t start,
4805 int32_t targetStart)
const 4806 { doExtract(start, _length, target, targetStart); }
4809 UnicodeString::extract(int32_t start,
4812 { doExtract(start, _length, target); }
4814 #if !UCONFIG_NO_CONVERSION 4817 UnicodeString::extract(int32_t start,
4820 const char *codepage)
const 4824 return extract(start, _length, dst, dst !=
nullptr ? 0xffffffff : 0, codepage);
4830 UnicodeString::extractBetween(int32_t start,
4833 int32_t dstStart)
const {
4836 doExtract(start, limit - start, dst, dstStart);
4840 UnicodeString::tempSubStringBetween(int32_t start, int32_t limit)
const {
4841 return tempSubString(start, limit - start);
4845 UnicodeString::doCharAt(int32_t offset)
const 4847 if (static_cast<uint32_t>(offset) < static_cast<uint32_t>(length())) {
4848 return getArrayStart()[offset];
4850 return kInvalidUChar;
4855 UnicodeString::charAt(int32_t offset)
const 4856 {
return doCharAt(offset); }
4859 UnicodeString::operator[] (int32_t offset)
const 4860 {
return doCharAt(offset); }
4863 UnicodeString::isEmpty()
const {
4865 return (fUnion.fFields.fLengthAndFlags>>kLengthShift) == 0;
4872 UnicodeString::setZeroLength() {
4873 fUnion.fFields.fLengthAndFlags &= kAllStorageFlags;
4877 UnicodeString::setShortLength(int32_t len) {
4879 fUnion.fFields.fLengthAndFlags =
4880 static_cast<int16_t
>((fUnion.fFields.fLengthAndFlags & kAllStorageFlags) | (len << kLengthShift));
4884 UnicodeString::setLength(int32_t len) {
4885 if(len <= kMaxShortLength) {
4886 setShortLength(len);
4888 fUnion.fFields.fLengthAndFlags |= kLengthIsLarge;
4889 fUnion.fFields.fLength = len;
4894 UnicodeString::setToEmpty() {
4895 fUnion.fFields.fLengthAndFlags = kShortString;
4899 UnicodeString::setArray(char16_t *array, int32_t len, int32_t capacity) {
4901 fUnion.fFields.fArray = array;
4902 fUnion.fFields.fCapacity = capacity;
4905 inline UnicodeString&
4906 UnicodeString::operator= (char16_t ch)
4907 {
return doReplace(0, length(), &ch, 0, 1); }
4911 {
return replace(0, length(), ch); }
4919 return doReplace(0, length(), srcText, srcStart, srcLength);
4927 srcText.pinIndex(srcStart);
4928 return doReplace(0, length(), srcText, srcStart, srcText.
length() - srcStart);
4934 return copyFrom(srcText);
4938 UnicodeString::setTo(
const char16_t *srcChars,
4942 return doReplace(0, length(), srcChars, 0, srcLength);
4946 UnicodeString::setTo(char16_t srcChar)
4949 return doReplace(0, length(), &srcChar, 0, 1);
4956 return replace(0, length(), srcChar);
4963 {
return doAppend(srcText, srcStart, srcLength); }
4967 {
return doAppend(srcText, 0, srcText.
length()); }
4970 UnicodeString::append(
const char16_t *srcChars,
4973 {
return doAppend(srcChars, srcStart, srcLength); }
4978 {
return doAppend(srcChars, 0, srcLength); }
4981 UnicodeString::append(char16_t srcChar)
4982 {
return doAppend(&srcChar, 0, 1); }
4985 UnicodeString::operator+= (char16_t ch)
4986 {
return doAppend(&ch, 0, 1); }
4995 {
return doAppend(srcText, 0, srcText.
length()); }
4998 UnicodeString::insert(int32_t start,
5002 {
return doReplace(start, 0, srcText, srcStart, srcLength); }
5005 UnicodeString::insert(int32_t start,
5007 {
return doReplace(start, 0, srcText, 0, srcText.
length()); }
5010 UnicodeString::insert(int32_t start,
5011 const char16_t *srcChars,
5014 {
return doReplace(start, 0, srcChars, srcStart, srcLength); }
5017 UnicodeString::insert(int32_t start,
5020 {
return doReplace(start, 0, srcChars, 0, srcLength); }
5023 UnicodeString::insert(int32_t start,
5025 {
return doReplace(start, 0, &srcChar, 0, 1); }
5028 UnicodeString::insert(int32_t start,
5030 {
return replace(start, 0, srcChar); }
5034 UnicodeString::remove()
5046 UnicodeString::remove(int32_t start,
5049 if(start <= 0 && _length ==
INT32_MAX) {
5053 return doReplace(start, _length,
nullptr, 0, 0);
5057 UnicodeString::removeBetween(int32_t start,
5059 {
return doReplace(start, limit - start,
nullptr, 0, 0); }
5062 UnicodeString::retainBetween(int32_t start, int32_t limit) {
5064 return doReplace(0, start,
nullptr, 0, 0);
5068 UnicodeString::truncate(int32_t targetLength)
5070 if(isBogus() && targetLength == 0) {
5074 }
else if (static_cast<uint32_t>(targetLength) < static_cast<uint32_t>(length())) {
5075 setLength(targetLength);
5083 UnicodeString::reverse()
5084 {
return doReverse(0, length()); }
5087 UnicodeString::reverse(int32_t start,
5089 {
return doReverse(start, _length); }
#define UNISTR_OBJECT_SIZE
Desired sizeof(UnicodeString) in bytes.
UnicodeString & operator=(const S &src)
Assignment operator.
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 & append(const S &src)
Appends the characters in src which is, or which is implicitly convertible to, a std::u16string_view ...
int32_t length() const
Return the length of the UnicodeString object.
UnicodeString(const uint16_t *text, int32_t textLength)
uint16_t * constructor.
bool operator==(const S &text) const
Equality operator.
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.
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().
UnicodeString operator+(const UnicodeString &s1, const S &s2)
Creates a new UnicodeString from the concatenation of a UnicodeString and s2 which is...
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_COMMON_API UnicodeString unistr_internalConcat(const UnicodeString &s1, std::u16string_view s2)
UNISTR_FROM_STRING_EXPLICIT UnicodeString(const S &text)
Constructor from text which is, or which is implicitly convertible to, a std::u16string_view or (if U...
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.
#define U_ALIASING_BARRIER(ptr)
Barrier for pointer anti-aliasing optimizations even across function boundaries.
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".
UnicodeString & operator+=(const S &src)
Append operator.
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.
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().
static UnicodeString readOnlyAlias(const S &text)
Readonly-aliasing factory method.
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.
static UnicodeString readOnlyAlias(const UnicodeString &text)
Readonly-aliasing factory method.
char16_t charAt(int32_t offset) const
Returns the 16-bit code unit at the given offset into the text.
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.
bool operator!=(const S &text) const
Inequality operator.
#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...
UBool isBogus() const
Determine if this object contains a valid string.
A Locale object represents a specific geographical, political, or cultural region.
C++ API: Replaceable String.