33#if U_SHOW_CPLUSPLUS_API
56#if !UCONFIG_NO_BREAK_ITERATION
75 char16_t *dest, int32_t destCapacity,
76 const char16_t *src, int32_t srcLength,
83class StringCharacterIterator;
84class 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
354 template<
typename S,
typename = std::enable_if_t<ConvertibleToU16StringView<S>>>
358 return !
isBogus() && (len =
length()) == sv.length() && doEquals(sv.data(), len);
387 template<
typename S,
typename = std::enable_if_t<ConvertibleToU16StringView<S>>>
456 inline int8_t compare(int32_t start,
477 inline int8_t compare(int32_t start,
481 int32_t srcLength)
const;
496 int32_t srcLength)
const;
512 inline int8_t compare(int32_t start,
514 const char16_t *srcChars)
const;
533 inline int8_t compare(int32_t start,
535 const char16_t *srcChars,
537 int32_t srcLength)
const;
556 inline int8_t compareBetween(int32_t start,
560 int32_t srcLimit)
const;
579 inline int8_t compareCodePointOrder(
const UnicodeString& text)
const;
600 inline int8_t compareCodePointOrder(int32_t start,
625 inline int8_t compareCodePointOrder(int32_t start,
629 int32_t srcLength)
const;
650 int32_t srcLength)
const;
671 inline int8_t compareCodePointOrder(int32_t start,
673 const char16_t *srcChars)
const;
696 inline int8_t compareCodePointOrder(int32_t start,
698 const char16_t *srcChars,
700 int32_t srcLength)
const;
723 inline int8_t compareCodePointOrderBetween(int32_t start,
727 int32_t srcLimit)
const;
747 inline int8_t caseCompare(
const UnicodeString& text, uint32_t options)
const;
769 inline int8_t caseCompare(int32_t start,
772 uint32_t options)
const;
796 inline int8_t caseCompare(int32_t start,
801 uint32_t options)
const;
824 uint32_t options)
const;
846 inline int8_t caseCompare(int32_t start,
848 const char16_t *srcChars,
849 uint32_t options)
const;
873 inline int8_t caseCompare(int32_t start,
875 const char16_t *srcChars,
878 uint32_t options)
const;
902 inline int8_t caseCompareBetween(int32_t start,
907 uint32_t options)
const;
930 int32_t srcLength)
const;
941 int32_t srcLength)
const;
952 inline UBool startsWith(
const char16_t *srcChars,
954 int32_t srcLength)
const;
977 int32_t srcLength)
const;
988 int32_t srcLength)
const;
1000 inline UBool endsWith(
const char16_t *srcChars,
1002 int32_t srcLength)
const;
1027 int32_t start)
const;
1042 int32_t length)
const;
1064 int32_t length)
const;
1077 inline int32_t indexOf(
const char16_t *srcChars,
1079 int32_t start)
const;
1096 int32_t length)
const;
1127 inline int32_t
indexOf(
char16_t c)
const;
1147 inline int32_t
indexOf(
char16_t c,
1148 int32_t start)
const;
1160 int32_t start)
const;
1172 inline int32_t
indexOf(
char16_t c,
1211 int32_t start)
const;
1260 inline int32_t
lastIndexOf(
const char16_t *srcChars,
1262 int32_t start)
const;
1331 int32_t start)
const;
1343 int32_t start)
const;
1385 inline char16_t charAt(int32_t offset)
const;
1394 inline char16_t operator[] (int32_t offset)
const;
1513 inline void extract(int32_t start,
1516 int32_t dstStart = 0)
const;
1552 inline void extract(int32_t start,
1570 int32_t dstStart = 0)
const;
1606 int32_t startLength,
1608 int32_t targetCapacity,
1611#if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
1633 int32_t startLength,
1635 uint32_t targetLength)
const;
1639#if !UCONFIG_NO_CONVERSION
1666 inline int32_t
extract(int32_t start,
1667 int32_t startLength,
1669 const char* codepage =
nullptr)
const;
1701 int32_t startLength,
1703 uint32_t targetLength,
1704 const char *codepage)
const;
1755 int32_t limit =
INT32_MAX)
const U_LIFETIME_BOUND;
1783 template <
typename StringClass>
1790#ifndef U_HIDE_DRAFT_API
1802 template<
typename StringClass>
1838 inline int32_t
length()
const;
1923#ifndef U_HIDE_DRAFT_API
1929 using unspecified_iterator = std::u16string_view::const_iterator;
1930 using unspecified_reverse_iterator = std::u16string_view::const_reverse_iterator;
1938 unspecified_iterator
begin()
const {
return std::u16string_view(*this).begin(); }
1944 unspecified_iterator
end()
const {
return std::u16string_view(*this).end(); }
1950 unspecified_reverse_iterator
rbegin()
const {
return std::u16string_view(*this).rbegin(); }
1956 unspecified_reverse_iterator
rend()
const {
return std::u16string_view(*this).rend(); }
2022 template <
typename S,
typename = std::enable_if_t<ConvertibleToU16StringView<S>>>
2051 friend inline void U_EXPORT2
2063 inline UnicodeString& operator=(
char16_t ch) U_LIFETIME_BOUND;
2102 int32_t srcLength) U_LIFETIME_BOUND;
2122 inline UnicodeString& setTo(
const char16_t* srcChars, int32_t srcLength) U_LIFETIME_BOUND;
2132 inline UnicodeString& setTo(
char16_t srcChar) U_LIFETIME_BOUND;
2169 int32_t textLength) U_LIFETIME_BOUND;
2192 int32_t buffCapacity) U_LIFETIME_BOUND;
2283 template <
typename S,
typename = std::enable_if_t<ConvertibleToU16StringView<S>>>
2304 int32_t srcLength) U_LIFETIME_BOUND;
2330 int32_t srcLength) U_LIFETIME_BOUND;
2353 template <
typename S,
typename = std::enable_if_t<ConvertibleToU16StringView<S>>>
2364 inline UnicodeString& append(
char16_t srcChar) U_LIFETIME_BOUND;
2374#ifndef U_HIDE_DRAFT_API
2403 int32_t srcLength) U_LIFETIME_BOUND;
2429 const char16_t* srcChars,
2431 int32_t srcLength) U_LIFETIME_BOUND;
2444 int32_t srcLength) U_LIFETIME_BOUND;
2454 inline UnicodeString& insert(int32_t start,
char16_t srcChar) U_LIFETIME_BOUND;
2489 int32_t srcLength) U_LIFETIME_BOUND;
2526 const char16_t* srcChars,
2528 int32_t srcLength) U_LIFETIME_BOUND;
2545 int32_t srcLength) U_LIFETIME_BOUND;
2558 inline UnicodeString& replace(int32_t start, int32_t length,
char16_t srcChar) U_LIFETIME_BOUND;
2604 int32_t srcLimit) U_LIFETIME_BOUND;
2637 virtual void copy(int32_t start, int32_t limit, int32_t dest)
override;
2692 int32_t newLength) U_LIFETIME_BOUND;
2754 char16_t padChar = 0x0020);
2768 char16_t padChar = 0x0020);
2838#if !UCONFIG_NO_BREAK_ITERATION
2929 uint32_t options) U_LIFETIME_BOUND;
3049 inline const
char16_t*
getBuffer() const U_LIFETIME_BOUND;
3093 return {
getBuffer(),
static_cast<std::u16string_view::size_type
>(
length())};
3096#if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
3106 inline operator std::wstring_view()
const {
3108#ifdef U_ALIASING_BARRIER
3111 return {
reinterpret_cast<const wchar_t *
>(p), (std::wstring_view::size_type)
length() };
3159#ifdef U_HIDE_DRAFT_API
3183#if !U_CHAR16_IS_TYPEDEF && \
3184 (defined(U_HIDE_DRAFT_API) || (defined(_LIBCPP_VERSION) && _LIBCPP_VERSION >= 180000))
3208#if defined(U_HIDE_DRAFT_API) && (U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN))
3230 UnicodeString(ConstChar16Ptr(text), -1) {}
3262 int32_t textLength);
3264#if !U_CHAR16_IS_TYPEDEF
3285#if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
3314 inline UnicodeString(
const std::nullptr_t text, int32_t textLength);
3328 template<
typename S,
typename = std::enable_if_t<ConvertibleToU16StringView<S>>>
3330 fUnion.fFields.fLengthAndFlags = kShortString;
3366 int32_t textLength);
3386 UnicodeString(
char16_t* buffer U_LIFETIME_BOUND, int32_t buffLength, int32_t buffCapacity);
3388#if !U_CHAR16_IS_TYPEDEF
3397 UnicodeString(uint16_t* buffer U_LIFETIME_BOUND, int32_t buffLength, int32_t buffCapacity) :
3401#if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
3411 UnicodeString(
wchar_t* buffer U_LIFETIME_BOUND, int32_t buffLength, int32_t buffCapacity) :
3423 inline UnicodeString(std::nullptr_t buffer, int32_t buffLength, int32_t buffCapacity);
3425#if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
3464#if !UCONFIG_NO_CONVERSION
3502 UnicodeString(
const char *codepageData, int32_t dataLength,
const char *codepage);
3526 const char *src, int32_t srcLength,
3652 template <
typename S,
typename = std::enable_if_t<ConvertibleToU16StringView<S>>>
3677 return readOnlyAliasFromUnicodeString(text);
3807 static UnicodeString readOnlyAliasFromU16StringView(std::u16string_view text U_LIFETIME_BOUND);
3818 toUTF8(int32_t start, int32_t len,
3819 char *target, int32_t capacity)
const;
3826 return doEquals(text.getArrayStart(), len);
3828 UBool doEquals(
const char16_t *text, int32_t len)
const;
3831 doEqualsSubstring(int32_t start,
3835 int32_t srcLength)
const;
3837 UBool doEqualsSubstring(int32_t start,
3839 const char16_t *srcChars,
3841 int32_t srcLength)
const;
3844 doCompare(int32_t start,
3848 int32_t srcLength)
const;
3850 int8_t doCompare(int32_t start,
3852 const char16_t *srcChars,
3854 int32_t srcLength)
const;
3857 doCompareCodePointOrder(int32_t start,
3861 int32_t srcLength)
const;
3863 int8_t doCompareCodePointOrder(int32_t start,
3865 const char16_t *srcChars,
3867 int32_t srcLength)
const;
3870 doCaseCompare(int32_t start,
3875 uint32_t options)
const;
3878 doCaseCompare(int32_t start,
3880 const char16_t *srcChars,
3883 uint32_t options)
const;
3885 int32_t doIndexOf(
char16_t c,
3887 int32_t length)
const;
3891 int32_t length)
const;
3893 int32_t doLastIndexOf(
char16_t c,
3895 int32_t length)
const;
3897 int32_t doLastIndexOf(
UChar32 c,
3899 int32_t length)
const;
3901 void doExtract(int32_t start,
3904 int32_t dstStart)
const;
3906 inline void doExtract(int32_t start,
3910 inline char16_t doCharAt(int32_t offset)
const;
3916 int32_t srcLength) U_LIFETIME_BOUND;
3920 const char16_t* srcChars,
3922 int32_t srcLength) U_LIFETIME_BOUND;
3923 UnicodeString& doReplace(int32_t start, int32_t length, std::u16string_view src) U_LIFETIME_BOUND;
3927 int32_t srcLength) U_LIFETIME_BOUND;
3930 int32_t srcLength) U_LIFETIME_BOUND;
3931 UnicodeString& doAppend(std::u16string_view src) U_LIFETIME_BOUND;
3933 UnicodeString& doReverse(int32_t start, int32_t length) U_LIFETIME_BOUND;
3936 int32_t doHashCode()
const;
3940 inline char16_t* getArrayStart() U_LIFETIME_BOUND;
3941 inline const
char16_t* getArrayStart() const U_LIFETIME_BOUND;
3943 inline
UBool hasShortLength() const;
3944 inline int32_t getShortLength() const;
3948 inline
UBool isWritable() const;
3951 inline
UBool isBufferWritable() const;
3954 inline
void setZeroLength();
3955 inline
void setShortLength(int32_t len);
3956 inline
void setLength(int32_t len);
3957 inline
void setToEmpty();
3958 inline
void setArray(
char16_t *array, int32_t len, int32_t capacity);
3965 UBool allocate(int32_t capacity);
3968 void releaseArray();
3980 inline
void pinIndex(int32_t& start) const;
3981 inline
void pinIndices(int32_t& start,
3982 int32_t& length) const;
3984#if !UCONFIG_NO_CONVERSION
3987 int32_t doExtract(int32_t start, int32_t length,
3988 char *dest, int32_t destCapacity,
4002 void doCodepageCreate(
const char *codepageData,
4004 const char *codepage);
4011 doCodepageCreate(
const char *codepageData,
4029 UBool cloneArrayIfNeeded(int32_t newCapacity = -1,
4030 int32_t growCapacity = -1,
4031 UBool doCopyArray =
true,
4032 int32_t** pBufferToDelete =
nullptr,
4033 UBool forceClone =
false);
4049 int32_t removeRef();
4050 int32_t refCount()
const;
4060 kInvalidUChar=0xffff,
4066 kUsingStackBuffer=2,
4068 kBufferIsReadonly=8,
4071 kAllStorageFlags=0x1f,
4074 kLength1=1<<kLengthShift,
4075 kMaxShortLength=0x3ff,
4076 kLengthIsLarge=0xffe0,
4079 kShortString=kUsingStackBuffer,
4080 kLongString=kRefCounted,
4081 kReadonlyAlias=kBufferIsReadonly,
4085 friend class UnicodeStringAppendable;
4087 union StackBufferOrFields;
4088 friend union StackBufferOrFields;
4131 union StackBufferOrFields {
4135 int16_t fLengthAndFlags;
4136 char16_t fBuffer[US_STACKBUF_SIZE];
4139 int16_t fLengthAndFlags;
4171 typename US,
typename S,
4172 typename = std::enable_if_t<ConvertibleToU16StringView<S> && std::is_same_v<US, UnicodeString>>>
4177#ifndef U_FORCE_HIDE_INTERNAL_API
4192UnicodeString::pinIndex(int32_t& start)
const
4197 }
else if(start > length()) {
4203UnicodeString::pinIndices(int32_t& start,
4204 int32_t& _length)
const
4207 int32_t len = length();
4210 }
else if(start > len) {
4215 }
else if(_length > (len - start)) {
4216 _length = (len - start);
4221UnicodeString::getArrayStart() U_LIFETIME_BOUND {
4222 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
4223 fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
4226inline const char16_t*
4227UnicodeString::getArrayStart() const U_LIFETIME_BOUND {
4228 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
4229 fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
4238 fUnion.fStackFields.fLengthAndFlags=kShortString;
4242 fUnion.fStackFields.fLengthAndFlags=kShortString;
4246 fUnion.fStackFields.fLengthAndFlags=kShortString;
4250 fUnion.fStackFields.fLengthAndFlags=kShortString;
4257UnicodeString::hasShortLength()
const {
4258 return fUnion.fFields.fLengthAndFlags>=0;
4262UnicodeString::getShortLength()
const {
4265 return fUnion.fFields.fLengthAndFlags>>kLengthShift;
4270 return hasShortLength() ? getShortLength() : fUnion.fFields.fLength;
4275 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
4276 US_STACKBUF_SIZE : fUnion.fFields.fCapacity;
4281{
return doHashCode(); }
4285{
return fUnion.fFields.fLengthAndFlags & kIsBogus; }
4288UnicodeString::isWritable()
const
4289{
return !(fUnion.fFields.fLengthAndFlags & (kOpenGetBuffer | kIsBogus)); }
4292UnicodeString::isBufferWritable()
const
4295 !(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus|kBufferIsReadonly)) &&
4296 (!(fUnion.fFields.fLengthAndFlags&kRefCounted) || refCount()==1);
4299inline const char16_t *
4301 if(fUnion.fFields.fLengthAndFlags&(kIsBogus|kOpenGetBuffer)) {
4303 }
else if(fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) {
4304 return fUnion.fStackFields.fBuffer;
4306 return fUnion.fFields.fArray;
4314UnicodeString::doCompare(int32_t start,
4318 int32_t srcLength)
const
4321 return static_cast<int8_t
>(!isBogus());
4323 srcText.pinIndices(srcStart, srcLength);
4324 return doCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
4329UnicodeString::doEqualsSubstring(int32_t start,
4331 const UnicodeString& srcText,
4333 int32_t srcLength)
const
4335 if(srcText.isBogus()) {
4338 srcText.pinIndices(srcStart, srcLength);
4339 return !isBogus() && doEqualsSubstring(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
4350 return !text.
isBogus() && len == textLength && doEquals(text, len);
4356{
return (!
operator==(text)); }
4360{
return doCompare(0,
length(), text, 0, text.
length()) == 1; }
4364{
return doCompare(0,
length(), text, 0, text.
length()) == -1; }
4368{
return doCompare(0,
length(), text, 0, text.
length()) != -1; }
4372{
return doCompare(0,
length(), text, 0, text.
length()) != 1; }
4376{
return doCompare(0,
length(), text, 0, text.
length()); }
4382{
return doCompare(start, _length, srcText, 0, srcText.
length()); }
4386 int32_t srcLength)
const
4387{
return doCompare(0,
length(), srcChars, 0, srcLength); }
4394 int32_t srcLength)
const
4395{
return doCompare(start, _length, srcText, srcStart, srcLength); }
4400 const char16_t *srcChars)
const
4401{
return doCompare(start, _length, srcChars, 0, _length); }
4406 const char16_t *srcChars,
4408 int32_t srcLength)
const
4409{
return doCompare(start, _length, srcChars, srcStart, srcLength); }
4416 int32_t srcLimit)
const
4417{
return doCompare(start, limit - start,
4418 srcText, srcStart, srcLimit - srcStart); }
4421UnicodeString::doCompareCodePointOrder(int32_t start,
4425 int32_t srcLength)
const
4428 return static_cast<int8_t
>(!isBogus());
4430 srcText.pinIndices(srcStart, srcLength);
4431 return doCompareCodePointOrder(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
4437{
return doCompareCodePointOrder(0,
length(), text, 0, text.
length()); }
4443{
return doCompareCodePointOrder(start, _length, srcText, 0, srcText.
length()); }
4447 int32_t srcLength)
const
4448{
return doCompareCodePointOrder(0,
length(), srcChars, 0, srcLength); }
4455 int32_t srcLength)
const
4456{
return doCompareCodePointOrder(start, _length, srcText, srcStart, srcLength); }
4461 const char16_t *srcChars)
const
4462{
return doCompareCodePointOrder(start, _length, srcChars, 0, _length); }
4467 const char16_t *srcChars,
4469 int32_t srcLength)
const
4470{
return doCompareCodePointOrder(start, _length, srcChars, srcStart, srcLength); }
4477 int32_t srcLimit)
const
4478{
return doCompareCodePointOrder(start, limit - start,
4479 srcText, srcStart, srcLimit - srcStart); }
4482UnicodeString::doCaseCompare(int32_t start,
4487 uint32_t options)
const
4490 return static_cast<int8_t
>(!isBogus());
4492 srcText.pinIndices(srcStart, srcLength);
4493 return doCaseCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength, options);
4499 return doCaseCompare(0,
length(), text, 0, text.
length(), options);
4506 uint32_t options)
const {
4507 return doCaseCompare(start, _length, srcText, 0, srcText.
length(), options);
4513 uint32_t options)
const {
4514 return doCaseCompare(0,
length(), srcChars, 0, srcLength, options);
4523 uint32_t options)
const {
4524 return doCaseCompare(start, _length, srcText, srcStart, srcLength, options);
4530 const char16_t *srcChars,
4531 uint32_t options)
const {
4532 return doCaseCompare(start, _length, srcChars, 0, _length, options);
4538 const char16_t *srcChars,
4541 uint32_t options)
const {
4542 return doCaseCompare(start, _length, srcChars, srcStart, srcLength, options);
4551 uint32_t options)
const {
4552 return doCaseCompare(start, limit - start, srcText, srcStart, srcLimit - srcStart, options);
4560 int32_t _length)
const
4563 srcText.pinIndices(srcStart, srcLength);
4565 return indexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
4577 int32_t start)
const {
4585 int32_t _length)
const
4591 int32_t start)
const {
4593 return indexOf(srcChars, 0, srcLength, start,
length() - start);
4600 int32_t _length)
const
4601{
return indexOf(srcChars, 0, srcLength, start, _length); }
4606 int32_t _length)
const
4607{
return doIndexOf(c, start, _length); }
4612 int32_t _length)
const
4613{
return doIndexOf(c, start, _length); }
4617{
return doIndexOf(c, 0,
length()); }
4625 int32_t start)
const {
4627 return doIndexOf(c, start,
length() - start);
4632 int32_t start)
const {
4641 int32_t _length)
const
4642{
return lastIndexOf(srcChars, 0, srcLength, start, _length); }
4647 int32_t start)
const {
4657 int32_t _length)
const
4660 srcText.pinIndices(srcStart, srcLength);
4662 return lastIndexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
4671 int32_t _length)
const
4676 int32_t start)
const {
4688 int32_t _length)
const
4689{
return doLastIndexOf(c, start, _length); }
4694 int32_t _length)
const {
4695 return doLastIndexOf(c, start, _length);
4700{
return doLastIndexOf(c, 0,
length()); }
4709 int32_t start)
const {
4711 return doLastIndexOf(c, start,
length() - start);
4716 int32_t start)
const {
4723{
return doEqualsSubstring(0, text.
length(), text, 0, text.
length()); }
4728 int32_t srcLength)
const
4729{
return doEqualsSubstring(0, srcLength, srcText, srcStart, srcLength); }
4734 srcLength =
u_strlen(toUCharPtr(srcChars));
4736 return doEqualsSubstring(0, srcLength, srcChars, 0, srcLength);
4742 srcLength =
u_strlen(toUCharPtr(srcChars));
4744 return doEqualsSubstring(0, srcLength, srcChars, srcStart, srcLength);
4750 text, 0, text.
length()); }
4755 int32_t srcLength)
const {
4756 srcText.pinIndices(srcStart, srcLength);
4757 return doEqualsSubstring(
length() - srcLength, srcLength,
4758 srcText, srcStart, srcLength);
4763 int32_t srcLength)
const {
4765 srcLength =
u_strlen(toUCharPtr(srcChars));
4767 return doEqualsSubstring(
length() - srcLength, srcLength, srcChars, 0, srcLength);
4773 int32_t srcLength)
const {
4775 srcLength =
u_strlen(toUCharPtr(srcChars + srcStart));
4777 return doEqualsSubstring(
length() - srcLength, srcLength,
4778 srcChars, srcStart, srcLength);
4788{
return doReplace(start, _length, srcText, 0, srcText.
length()); }
4795 int32_t srcLength) U_LIFETIME_BOUND
4796{
return doReplace(start, _length, srcText, srcStart, srcLength); }
4802 int32_t srcLength) U_LIFETIME_BOUND
4803{
return doReplace(start, _length, srcChars, 0, srcLength); }
4808 const char16_t* srcChars,
4810 int32_t srcLength) U_LIFETIME_BOUND
4811{
return doReplace(start, _length, srcChars, srcStart, srcLength); }
4816 char16_t srcChar) U_LIFETIME_BOUND
4817{
return doReplace(start, _length, &srcChar, 0, 1); }
4823{
return doReplace(start, limit - start, srcText, 0, srcText.
length()); }
4830 int32_t srcLimit) U_LIFETIME_BOUND
4831{
return doReplace(start, limit - start, srcText, srcStart, srcLimit - srcStart); }
4837 newText, 0, newText.length()); }
4844{
return findAndReplace(start, _length, oldText, 0, oldText.length(),
4845 newText, 0, newText.length()); }
4851UnicodeString::doExtract(int32_t start,
4854{ target.
replace(0, target.
length(), *
this, start, _length); }
4860 int32_t targetStart)
const
4861{ doExtract(start, _length, target, targetStart); }
4867{ doExtract(start, _length, target); }
4869#if !UCONFIG_NO_CONVERSION
4875 const char *codepage)
const
4879 return extract(start, _length, dst, dst !=
nullptr ? 0xffffffff : 0, codepage);
4888 int32_t dstStart)
const {
4891 doExtract(start, limit - start, dst, dstStart);
4900UnicodeString::doCharAt(int32_t offset)
const
4902 if (
static_cast<uint32_t
>(offset) <
static_cast<uint32_t
>(length())) {
4903 return getArrayStart()[offset];
4905 return kInvalidUChar;
4911{
return doCharAt(offset); }
4914UnicodeString::operator[] (int32_t offset)
const
4915{
return doCharAt(offset); }
4920 return (fUnion.fFields.fLengthAndFlags>>kLengthShift) == 0;
4927UnicodeString::setZeroLength() {
4928 fUnion.fFields.fLengthAndFlags &= kAllStorageFlags;
4932UnicodeString::setShortLength(int32_t len) {
4934 fUnion.fFields.fLengthAndFlags =
4935 static_cast<int16_t
>((fUnion.fFields.fLengthAndFlags & kAllStorageFlags) | (len << kLengthShift));
4939UnicodeString::setLength(int32_t len) {
4940 if(len <= kMaxShortLength) {
4941 setShortLength(len);
4943 fUnion.fFields.fLengthAndFlags |= kLengthIsLarge;
4944 fUnion.fFields.fLength = len;
4949UnicodeString::setToEmpty() {
4950 fUnion.fFields.fLengthAndFlags = kShortString;
4954UnicodeString::setArray(
char16_t *array, int32_t len, int32_t capacity) {
4956 fUnion.fFields.fArray = array;
4957 fUnion.fFields.fCapacity = capacity;
4960inline UnicodeString&
4962{
return doReplace(0,
length(), &ch, 0, 1); }
4971 int32_t srcLength) U_LIFETIME_BOUND
4974 return doReplace(0,
length(), srcText, srcStart, srcLength);
4979 int32_t srcStart) U_LIFETIME_BOUND
4982 srcText.pinIndex(srcStart);
4983 return doReplace(0,
length(), srcText, srcStart, srcText.
length() - srcStart);
4989 return copyFrom(srcText);
4994 int32_t srcLength) U_LIFETIME_BOUND
4997 return doReplace(0,
length(), srcChars, 0, srcLength);
5004 return doReplace(0,
length(), &srcChar, 0, 1);
5017 int32_t srcLength) U_LIFETIME_BOUND
5018{
return doAppend(srcText, srcStart, srcLength); }
5022{
return doAppend(srcText, 0, srcText.
length()); }
5027 int32_t srcLength) U_LIFETIME_BOUND
5028{
return doAppend(srcChars, srcStart, srcLength); }
5032 int32_t srcLength) U_LIFETIME_BOUND
5033{
return doAppend(srcChars, 0, srcLength); }
5037{
return doAppend(&srcChar, 0, 1); }
5041{
return doAppend(&ch, 0, 1); }
5050{
return doAppend(srcText, 0, srcText.
length()); }
5056 int32_t srcLength) U_LIFETIME_BOUND
5057{
return doReplace(start, 0, srcText, srcStart, srcLength); }
5062{
return doReplace(start, 0, srcText, 0, srcText.
length()); }
5066 const char16_t* srcChars,
5068 int32_t srcLength) U_LIFETIME_BOUND
5069{
return doReplace(start, 0, srcChars, srcStart, srcLength); }
5074 int32_t srcLength) U_LIFETIME_BOUND
5075{
return doReplace(start, 0, srcChars, 0, srcLength); }
5079 char16_t srcChar) U_LIFETIME_BOUND
5080{
return doReplace(start, 0, &srcChar, 0, 1); }
5084 UChar32 srcChar) U_LIFETIME_BOUND
5085{
return replace(start, 0, srcChar); }
5102 int32_t _length) U_LIFETIME_BOUND
5104 if(start <= 0 && _length ==
INT32_MAX) {
5108 return doReplace(start, _length,
nullptr, 0, 0);
5113 int32_t limit) U_LIFETIME_BOUND
5114{
return doReplace(start, limit - start,
nullptr, 0, 0); }
5119 return doReplace(0, start,
nullptr, 0, 0);
5125 if(
isBogus() && targetLength == 0) {
5129 }
else if (
static_cast<uint32_t
>(targetLength) <
static_cast<uint32_t
>(
length())) {
5130 setLength(targetLength);
5139{
return doReverse(0,
length()); }
5143 int32_t _length) U_LIFETIME_BOUND
5144{
return doReverse(start, _length); }
C++ API: Interface for writing bytes, and implementation classes.
C++ API: char16_t pointer wrappers with implicit conversion from bit-compatible raw pointer types.
std::u16string_view toU16StringView(std::u16string_view sv)
Pass-through overload.
std::u16string_view toU16StringViewNullable(const T &text)
Pass-through overload.
#define U_ALIASING_BARRIER(ptr)
Barrier for pointer anti-aliasing optimizations even across function boundaries.
The BreakIterator class implements methods for finding the location of boundaries in text.
A ByteSink can be filled with bytes.
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.
Records lengths of string edits but not replacement text.
A Locale object represents a specific geographical, political, or cultural region.
virtual void extractBetween(int32_t start, int32_t limit, UnicodeString &target) const =0
Copies characters in the range [start, limit) into the UnicodeString target.
char16_t charAt(int32_t offset) const
Returns the 16-bit code unit at the given offset into the text.
int32_t length() const
Returns the number of 16-bit code units in the text.
Replaceable()
Default constructor.
Implementation of ByteSink that writes to a "string".
A string-like object that points to a sized piece of memory.
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
int32_t indexOf(const char16_t *srcChars, int32_t srcStart, int32_t srcLength, int32_t start, int32_t length) const
Locate in this the first occurrence in the range [start, start + length) of the characters in srcChar...
UnicodeString(const UnicodeString &that)
Copy constructor.
char16_t charAt(int32_t offset) const
Return the code unit at offset offset.
void push_back(char16_t c)
Appends the code unit c to the UnicodeString object.
void swap(UnicodeString &other) noexcept
Swap strings.
virtual char16_t getCharAt(int32_t offset) const override
The change in Replaceable to use virtual getCharAt() allows UnicodeString::charAt() to be inline agai...
bool operator==(const S &text) const
Equality operator.
int8_t caseCompareBetween(int32_t start, int32_t limit, const UnicodeString &srcText, int32_t srcStart, int32_t srcLimit, uint32_t options) const
Compare two strings case-insensitively using full case folding.
virtual int32_t getLength() const override
Implement Replaceable::getLength() (see jitterbug 1027).
int32_t hashCode() const
Generate a hash code for this object.
UnicodeString & setTo(char16_t *buffer, int32_t buffLength, int32_t buffCapacity)
Aliasing setTo() function, analogous to the writable-aliasing char16_t* constructor.
UnicodeString & operator=(const S &src)
Assignment operator.
UnicodeString & operator=(UnicodeString &&src) noexcept
Move assignment operator; might leave src in bogus state.
UChar32 unescapeAt(int32_t &offset) const
Unescape a single escape sequence and return the represented character.
UnicodeString(const wchar_t *text, int32_t textLength)
wchar_t * constructor.
virtual void handleReplaceBetween(int32_t start, int32_t limit, const UnicodeString &text) override
Replace a substring of this object with the given text.
UBool hasMoreChar32Than(int32_t start, int32_t length, int32_t number) const
Check if the length char16_t code units of the string contain more Unicode code points than a certain...
UnicodeString(const UnicodeString &src, int32_t srcStart, int32_t srcLength)
'Substring' constructor from subrange of source string.
int32_t lastIndexOf(const UnicodeString &text) const
Locate in this the last occurrence of the characters in text, using bitwise comparison.
UnicodeString & reverse()
Reverse this UnicodeString in place.
virtual ~UnicodeString()
Destructor.
UnicodeString(const char *codepageData, int32_t dataLength, const char *codepage)
char* constructor.
UnicodeString(const char *codepageData, const char *codepage)
char* constructor.
UnicodeString(UBool isTerminated, ConstChar16Ptr text, int32_t textLength)
Readonly-aliasing char16_t* constructor.
static UnicodeString readOnlyAlias(const UnicodeString &text)
Readonly-aliasing factory method.
UnicodeString & toTitle(BreakIterator *titleIter, const Locale &locale, uint32_t options)
Titlecase this string, with options.
UnicodeString & append(UChar32 srcChar)
Append the code point srcChar to the UnicodeString object.
EInvariant
Constant to be used in the UnicodeString(char *, int32_t, EInvariant) constructor which constructs a ...
bool operator!=(const S &text) const
Inequality operator.
UnicodeString unescape() const
Unescape a string of characters and return a string containing the result.
UnicodeString(const UnicodeString &src, int32_t srcStart)
'Substring' constructor from tail of source string.
int32_t getChar32Limit(int32_t offset) const
Adjust a random-access offset so that it points behind a Unicode character.
UnicodeString(char16_t *buffer, int32_t buffLength, int32_t buffCapacity)
Writable-aliasing char16_t* constructor.
UnicodeString & findAndReplace(int32_t start, int32_t length, const UnicodeString &oldText, int32_t oldStart, int32_t oldLength, const UnicodeString &newText, int32_t newStart, int32_t newLength)
Replace all occurrences of characters in oldText in the range [oldStart, oldStart + oldLength) with t...
UnicodeString(int32_t capacity, UChar32 c, int32_t count)
Construct a UnicodeString with capacity to hold capacity char16_ts.
UnicodeString & operator+=(const S &src)
Append operator.
int32_t getCapacity() const
Return the capacity of the internal buffer of the UnicodeString object.
int32_t extract(int32_t start, int32_t startLength, char *target, uint32_t targetLength, const char *codepage) const
Copy the characters in the range [start, start + length) into an array of characters in a specified c...
UnicodeString & operator+=(char16_t ch)
Append operator.
virtual void copy(int32_t start, int32_t limit, int32_t dest) override
Copy a substring of this object, retaining attribute (out-of-band) information.
operator std::u16string_view() const
Converts to a std::u16string_view.
virtual void extractBetween(int32_t start, int32_t limit, UnicodeString &target) const override
Copy the characters in the range [start, limit) into the UnicodeString target.
int8_t compareCodePointOrder(const UnicodeString &text) const
Compare two Unicode strings in code point order.
UnicodeString & insert(int32_t start, const UnicodeString &srcText, int32_t srcStart, int32_t srcLength)
Insert the characters in srcText in the range [srcStart, srcStart + srcLength) into the UnicodeString...
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...
UnicodeString & toTitle(BreakIterator *titleIter)
Titlecase this string, convenience function using the default locale.
int8_t compare(const UnicodeString &text) const
Compare the characters bitwise in this UnicodeString to the characters in text.
UnicodeString & fastCopyFrom(const UnicodeString &src)
Almost the same as the assignment operator.
virtual UnicodeString * clone() const override
Clone this object, an instance of a subclass of Replaceable.
UBool padLeading(int32_t targetLength, char16_t padChar=0x0020)
Pad the start of this UnicodeString with the character padChar.
int32_t getChar32Start(int32_t offset) const
Adjust a random-access offset so that it points to the beginning of a Unicode character.
UnicodeString & append(const S &src)
Appends the characters in src which is, or which is implicitly convertible to, a std::u16string_view ...
UChar32 char32At(int32_t offset) const
Return the code point that contains the code unit at offset offset.
UnicodeString tempSubStringBetween(int32_t start, int32_t limit=INT32_MAX) const
Create a temporary substring for the specified range.
UnicodeString(const char *src, int32_t textLength, enum EInvariant inv)
Constructs a Unicode string from an invariant-character char * string.
int8_t caseCompare(const UnicodeString &text, uint32_t options) const
Compare two strings case-insensitively using full case folding.
UnicodeString tempSubString(int32_t start=0, int32_t length=INT32_MAX) const
Create a temporary substring for the specified range.
int32_t extract(Char16Ptr dest, int32_t destCapacity, UErrorCode &errorCode) const
Copy the contents of the string into dest.
int32_t length() const
Return the length of the UnicodeString object.
unspecified_reverse_iterator rend() const
virtual UChar32 getChar32At(int32_t offset) const override
The change in Replaceable to use virtual getChar32At() allows UnicodeString::char32At() to be inline ...
int32_t extract(int32_t start, int32_t startLength, char *target, uint32_t targetLength) const
Copy the characters in the range [start, start + length) into an array of characters in the platform'...
static UnicodeString fromUTF8(StringPiece utf8)
Create a UnicodeString from a UTF-8 string.
UNISTR_FROM_CHAR_EXPLICIT UnicodeString(char16_t ch)
Single char16_t (code unit) constructor.
int32_t lastIndexOf(const char16_t *srcChars, int32_t srcStart, int32_t srcLength, int32_t start, int32_t length) const
Locate in this the last occurrence in the range [start, start + length) of the characters in srcChars...
UnicodeString(wchar_t *buffer, int32_t buffLength, int32_t buffCapacity)
Writable-aliasing wchar_t * constructor.
void setToBogus()
Make this UnicodeString object invalid.
friend void swap(UnicodeString &s1, UnicodeString &s2) noexcept
Non-member UnicodeString swap function.
int32_t moveIndex32(int32_t index, int32_t delta) const
Move the code unit index along the string by delta code points.
static UnicodeString fromUTF32(const UChar32 *utf32, int32_t length)
Create a UnicodeString from a UTF-32 string.
UnicodeString & replace(int32_t start, int32_t length, UChar32 srcChar)
Replace the characters in the range [start, start + length) with the code point srcChar.
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...
UnicodeString & findAndReplace(const UnicodeString &oldText, const UnicodeString &newText)
Replace all occurrences of characters in oldText with the characters in newText.
int32_t countChar32(int32_t start=0, int32_t length=INT32_MAX) const
Count Unicode code points in the length char16_t code units of the string.
StringClass toUTF8String() const
Convert the UnicodeString to a UTF-8 string.
UNISTR_FROM_CHAR_EXPLICIT UnicodeString(UChar32 ch)
Single UChar32 (code point) constructor.
static UnicodeString readOnlyAlias(const S &text)
Readonly-aliasing factory method.
UnicodeString & trim()
Trims leading and trailing whitespace from this UnicodeString.
unspecified_iterator begin() const
UBool startsWith(const UnicodeString &text) const
Determine if this starts with the characters in text.
UnicodeString & operator=(const UnicodeString &srcText)
Assignment operator.
UBool truncate(int32_t targetLength)
Truncate this UnicodeString to the targetLength.
UnicodeString & setTo(UBool isTerminated, ConstChar16Ptr text, int32_t textLength)
Aliasing setTo() function, analogous to the readonly-aliasing char16_t* constructor.
int32_t extract(char *dest, int32_t destCapacity, UConverter *cnv, UErrorCode &errorCode) const
Convert the UnicodeString into a codepage string using an existing UConverter.
StringClass & toUTF8String(StringClass &result) const
Convert the UnicodeString to UTF-8 and append the result to a standard string.
UnicodeString(UnicodeString &&src) noexcept
Move constructor; might leave src in bogus state.
void extract(int32_t start, int32_t length, Char16Ptr dst, int32_t dstStart=0) const
Copy the characters in the range [start, start + length) into the array dst, beginning at dstStart.
UnicodeString & toUpper()
Convert the characters in this to UPPER CASE following the conventions of the default locale.
UnicodeString(const char16_t *text, int32_t textLength)
char16_t* constructor.
UBool endsWith(const UnicodeString &text) const
Determine if this ends with the characters in text.
UnicodeString(const char *src, int32_t srcLength, UConverter *cnv, UErrorCode &errorCode)
char * / UConverter constructor.
UnicodeString(const char *codepageData, int32_t dataLength)
char* constructor.
static UClassID getStaticClassID()
ICU "poor man's RTTI", returns a UClassID for this class.
UnicodeString(uint16_t *buffer, int32_t buffLength, int32_t buffCapacity)
Writable-aliasing uint16_t * constructor.
int32_t toUTF32(UChar32 *utf32, int32_t capacity, UErrorCode &errorCode) const
Convert the UnicodeString to UTF-32.
UBool isBogus() const
Determine if this object contains a valid string.
UnicodeString & toTitle(BreakIterator *titleIter, const Locale &locale)
Titlecase this string.
UnicodeString & setTo(const UnicodeString &srcText, int32_t srcStart)
Set the text in the UnicodeString object to the characters in srcText in the range [srcStart,...
UnicodeString & foldCase(uint32_t options=0)
Case-folds the characters in this string.
int8_t compareBetween(int32_t start, int32_t limit, const UnicodeString &srcText, int32_t srcStart, int32_t srcLimit) const
Compare the characters bitwise in the range [start, limit) with the characters in srcText in the rang...
UnicodeString()
Construct an empty UnicodeString.
const char16_t * getTerminatedBuffer()
Get a read-only pointer to the internal buffer, making sure that it is NUL-terminated.
UnicodeString(const uint16_t *text, int32_t textLength)
uint16_t * constructor.
unspecified_reverse_iterator rbegin() const
UnicodeString & setCharAt(int32_t offset, char16_t ch)
Set the character at the specified offset to the specified character.
UnicodeString & append(const UnicodeString &srcText, int32_t srcStart, int32_t srcLength)
Append the characters in srcText in the range [srcStart, srcStart + srcLength) to the UnicodeString o...
virtual UClassID getDynamicClassID() const override
ICU "poor man's RTTI", returns a UClassID for the actual class.
int32_t extract(int32_t start, int32_t startLength, char *target, int32_t targetCapacity, enum EInvariant inv) const
Copy the characters in the range [start, start + startLength) into an array of characters.
UnicodeString & replaceBetween(int32_t start, int32_t limit, const UnicodeString &srcText)
Replace the characters in the range [start, limit) with the characters in srcText.
UnicodeString & removeBetween(int32_t start, int32_t limit=static_cast< int32_t >(INT32_MAX))
Remove the characters in the range [start, limit) from the UnicodeString object.
char16_t * getBuffer(int32_t minCapacity)
Get a read/write pointer to the internal buffer.
UnicodeString & toLower()
Convert the characters in this to lower case following the conventions of the default locale.
int32_t indexOf(const UnicodeString &text) const
Locate in this the first occurrence of the characters in text, using bitwise comparison.
UBool padTrailing(int32_t targetLength, char16_t padChar=0x0020)
Pad the end of this UnicodeString with the character padChar.
UNISTR_FROM_STRING_EXPLICIT UnicodeString(const char *codepageData)
char* constructor.
void releaseBuffer(int32_t newLength=-1)
Release a read/write buffer on a UnicodeString object with an "open" getBuffer(minCapacity).
void extractBetween(int32_t start, int32_t limit, char16_t *dst, int32_t dstStart=0) const
Copy the characters in the range [start, limit) into the array dst, beginning at dstStart.
UnicodeString & remove()
Removes all characters from the UnicodeString object and clears the bogus flag.
void toUTF8(ByteSink &sink) const
Convert the UnicodeString to UTF-8 and write the result to a ByteSink.
char16_t value_type
C++ boilerplate.
unspecified_iterator end() const
UBool isEmpty() const
Determine if this string is empty.
UnicodeString & retainBetween(int32_t start, int32_t limit=INT32_MAX)
Retain only the characters in the range [start, limit) from the UnicodeString object.
virtual UBool hasMetaData() const override
Replaceable API.
int8_t compareCodePointOrderBetween(int32_t start, int32_t limit, const UnicodeString &srcText, int32_t srcStart, int32_t srcLimit) const
Compare two Unicode strings in code point order.
U_CAPI int32_t u_strlen(const UChar *s)
U_COMMON_API UnicodeString unistr_internalConcat(const UnicodeString &s1, std::u16string_view s2)
U_COMMON_API UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
bool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
U_COMMON_API UnicodeString operator+(const UnicodeString &s1, const UnicodeString &s2)
Creates a new UnicodeString from the concatenation of two others.
C++ API: Replaceable String.
C++ API: Central ICU header for including the C++ standard <string> header and for related definition...
C++ API: StringPiece: Read-only byte string wrapper class.
struct UConverter UConverter
#define UCONFIG_NO_BREAK_ITERATION
This switch turns off break iteration.
char16_t UChar
The base type for UTF-16 code units and pointers.
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
#define INT32_MAX
The largest value a 32 bit signed integer can hold.
int8_t UBool
The ICU boolean type, a signed-byte integer.
#define U_CAPI
This is used to declare a function as a public ICU C API.
#define U_SIZEOF_UCHAR
Number of bytes in a UChar (always 2).
#define UNISTR_FROM_CHAR_EXPLICIT
This can be defined to be empty or "explicit".
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 UNISTR_FROM_STRING_EXPLICIT
This can be defined to be empty or "explicit".
#define UNISTR_OBJECT_SIZE
Desired sizeof(UnicodeString) in bytes.
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
#define U_COMMON_API
Set to export library symbols from inside the common library, and to import them from outside.