51 #if !UCONFIG_NO_BREAK_ITERATION
70 char16_t *dest, int32_t destCapacity,
71 const char16_t *src, int32_t srcLength,
78 class StringCharacterIterator;
79 class UnicodeStringAppendable;
93 #define US_INV icu::UnicodeString::kInvariant
112 #if !U_CHAR16_IS_TYPEDEF
113 # define UNICODE_STRING(cs, _length) icu::UnicodeString(TRUE, u ## cs, _length)
115 # define UNICODE_STRING(cs, _length) icu::UnicodeString(TRUE, (const char16_t*)u ## cs, _length)
131 #define UNICODE_STRING_SIMPLE(cs) UNICODE_STRING(cs, -1)
140 #ifndef UNISTR_FROM_CHAR_EXPLICIT
141 # if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION)
143 # define UNISTR_FROM_CHAR_EXPLICIT explicit
146 # define UNISTR_FROM_CHAR_EXPLICIT
160 #ifndef UNISTR_FROM_STRING_EXPLICIT
161 # if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION)
163 # define UNISTR_FROM_STRING_EXPLICIT explicit
166 # define UNISTR_FROM_STRING_EXPLICIT
203 #ifndef UNISTR_OBJECT_SIZE
204 # define UNISTR_OBJECT_SIZE 64
397 inline int8_t compare(int32_t start,
418 inline int8_t compare(int32_t start,
422 int32_t srcLength)
const;
437 int32_t srcLength)
const;
453 inline int8_t compare(int32_t start,
455 const char16_t *srcChars)
const;
474 inline int8_t compare(int32_t start,
476 const char16_t *srcChars,
478 int32_t srcLength)
const;
497 inline int8_t compareBetween(int32_t start,
501 int32_t srcLimit)
const;
520 inline int8_t compareCodePointOrder(
const UnicodeString& text)
const;
541 inline int8_t compareCodePointOrder(int32_t start,
566 inline int8_t compareCodePointOrder(int32_t start,
570 int32_t srcLength)
const;
591 int32_t srcLength)
const;
612 inline int8_t compareCodePointOrder(int32_t start,
614 const char16_t *srcChars)
const;
637 inline int8_t compareCodePointOrder(int32_t start,
639 const char16_t *srcChars,
641 int32_t srcLength)
const;
664 inline int8_t compareCodePointOrderBetween(int32_t start,
668 int32_t srcLimit)
const;
688 inline int8_t caseCompare(
const UnicodeString& text, uint32_t options)
const;
710 inline int8_t caseCompare(int32_t start,
713 uint32_t options)
const;
737 inline int8_t caseCompare(int32_t start,
742 uint32_t options)
const;
765 uint32_t options)
const;
787 inline int8_t caseCompare(int32_t start,
789 const char16_t *srcChars,
790 uint32_t options)
const;
814 inline int8_t caseCompare(int32_t start,
816 const char16_t *srcChars,
819 uint32_t options)
const;
843 inline int8_t caseCompareBetween(int32_t start,
848 uint32_t options)
const;
871 int32_t srcLength)
const;
882 int32_t srcLength)
const;
893 inline UBool startsWith(
const char16_t *srcChars,
895 int32_t srcLength)
const;
918 int32_t srcLength)
const;
929 int32_t srcLength)
const;
941 inline UBool endsWith(
const char16_t *srcChars,
943 int32_t srcLength)
const;
968 int32_t start)
const;
983 int32_t length)
const;
1005 int32_t length)
const;
1018 inline int32_t indexOf(
const char16_t *srcChars,
1020 int32_t start)
const;
1037 int32_t length)
const;
1055 int32_t indexOf(
const char16_t *srcChars,
1059 int32_t length)
const;
1068 inline int32_t indexOf(char16_t c)
const;
1078 inline int32_t indexOf(
UChar32 c)
const;
1088 inline int32_t indexOf(char16_t c,
1089 int32_t start)
const;
1100 inline int32_t indexOf(
UChar32 c,
1101 int32_t start)
const;
1113 inline int32_t indexOf(char16_t c,
1115 int32_t length)
const;
1128 inline int32_t indexOf(
UChar32 c,
1130 int32_t length)
const;
1140 inline int32_t lastIndexOf(
const UnicodeString& text)
const;
1152 int32_t start)
const;
1167 int32_t length)
const;
1189 int32_t length)
const;
1201 inline int32_t lastIndexOf(
const char16_t *srcChars,
1203 int32_t start)
const;
1220 int32_t length)
const;
1238 int32_t lastIndexOf(
const char16_t *srcChars,
1242 int32_t length)
const;
1251 inline int32_t lastIndexOf(char16_t c)
const;
1261 inline int32_t lastIndexOf(
UChar32 c)
const;
1271 inline int32_t lastIndexOf(char16_t c,
1272 int32_t start)
const;
1283 inline int32_t lastIndexOf(
UChar32 c,
1284 int32_t start)
const;
1296 inline int32_t lastIndexOf(char16_t c,
1298 int32_t length)
const;
1311 inline int32_t lastIndexOf(
UChar32 c,
1313 int32_t length)
const;
1326 inline char16_t
charAt(int32_t offset)
const;
1335 inline char16_t operator[] (int32_t offset)
const;
1365 int32_t getChar32Start(int32_t offset)
const;
1383 int32_t getChar32Limit(int32_t offset)
const;
1435 int32_t moveIndex32(int32_t index, int32_t delta)
const;
1454 inline void extract(int32_t start,
1457 int32_t dstStart = 0)
const;
1481 extract(
Char16Ptr dest, int32_t destCapacity,
1493 inline void extract(int32_t start,
1511 int32_t dstStart = 0)
const;
1546 int32_t extract(int32_t start,
1547 int32_t startLength,
1549 int32_t targetCapacity,
1550 enum EInvariant inv)
const;
1552 #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
1573 int32_t extract(int32_t start,
1574 int32_t startLength,
1576 uint32_t targetLength)
const;
1580 #if !UCONFIG_NO_CONVERSION
1607 inline int32_t extract(int32_t start,
1608 int32_t startLength,
1610 const char *codepage = 0)
const;
1641 int32_t extract(int32_t start,
1642 int32_t startLength,
1644 uint32_t targetLength,
1645 const char *codepage)
const;
1664 int32_t extract(
char *dest, int32_t destCapacity,
1722 template<
typename StringClass>
1756 inline int32_t
length(
void)
const;
1772 countChar32(int32_t start=0, int32_t length=
INT32_MAX)
const;
1798 hasMoreChar32Than(int32_t start, int32_t length, int32_t number)
const;
1805 inline UBool isEmpty(
void)
const;
1816 inline int32_t getCapacity(
void)
const;
1825 inline int32_t hashCode(
void)
const;
1839 inline UBool isBogus(
void)
const;
1918 friend inline
void U_EXPORT2
2038 int32_t textLength);
2061 int32_t buffCapacity);
2263 const char16_t *srcChars,
2363 const char16_t *srcChars,
2476 virtual void copy(int32_t start, int32_t limit, int32_t dest);
2589 UBool padLeading(int32_t targetLength,
2590 char16_t padChar = 0x0020);
2603 UBool padTrailing(int32_t targetLength,
2604 char16_t padChar = 0x0020);
2612 inline UBool truncate(int32_t targetLength);
2676 #if !UCONFIG_NO_BREAK_ITERATION
2832 char16_t *getBuffer(int32_t minCapacity);
2854 void releaseBuffer(int32_t newLength=-1);
2886 inline const char16_t *getBuffer()
const;
2921 const char16_t *getTerminatedBuffer();
2979 #if !U_CHAR16_IS_TYPEDEF
2994 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
3030 int32_t textLength);
3032 #if !U_CHAR16_IS_TYPEDEF
3044 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
3064 inline UnicodeString(
const std::nullptr_t text, int32_t length);
3090 int32_t textLength);
3110 UnicodeString(char16_t *buffer, int32_t buffLength, int32_t buffCapacity);
3112 #if !U_CHAR16_IS_TYPEDEF
3125 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
3147 inline UnicodeString(std::nullptr_t buffer, int32_t buffLength, int32_t buffCapacity);
3149 #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
3180 UnicodeString(
const char *codepageData, int32_t dataLength);
3184 #if !UCONFIG_NO_CONVERSION
3203 UnicodeString(
const char *codepageData,
const char *codepage);
3222 UnicodeString(
const char *codepageData, int32_t dataLength,
const char *codepage);
3246 const char *src, int32_t srcLength,
3275 UnicodeString(
const char *src, int32_t length,
enum EInvariant inv);
3370 static UnicodeString fromUTF32(const
UChar32 *utf32, int32_t length);
3408 UnicodeString unescape() const;
3429 UChar32 unescapeAt(int32_t &offset) const;
3436 static
UClassID U_EXPORT2 getStaticClassID();
3443 virtual
UClassID getDynamicClassID() const;
3454 virtual int32_t getLength() const;
3461 virtual char16_t getCharAt(int32_t offset) const;
3468 virtual
UChar32 getChar32At(int32_t offset) const;
3479 toUTF8(int32_t start, int32_t len,
3480 char *target, int32_t capacity) const;
3486 UBool doEquals(const UnicodeString &text, int32_t len) const;
3489 doCompare(int32_t start,
3491 const UnicodeString& srcText,
3493 int32_t srcLength) const;
3495 int8_t doCompare(int32_t start,
3497 const char16_t *srcChars,
3499 int32_t srcLength) const;
3502 doCompareCodePointOrder(int32_t start,
3504 const UnicodeString& srcText,
3506 int32_t srcLength) const;
3508 int8_t doCompareCodePointOrder(int32_t start,
3510 const char16_t *srcChars,
3512 int32_t srcLength) const;
3515 doCaseCompare(int32_t start,
3517 const UnicodeString &srcText,
3520 uint32_t options) const;
3523 doCaseCompare(int32_t start,
3525 const char16_t *srcChars,
3528 uint32_t options) const;
3530 int32_t doIndexOf(char16_t c,
3532 int32_t length) const;
3536 int32_t length) const;
3538 int32_t doLastIndexOf(char16_t c,
3540 int32_t length) const;
3542 int32_t doLastIndexOf(
UChar32 c,
3544 int32_t length) const;
3546 void doExtract(int32_t start,
3549 int32_t dstStart) const;
3551 inline
void doExtract(int32_t start,
3553 UnicodeString& target) const;
3555 inline char16_t doCharAt(int32_t offset) const;
3557 UnicodeString& doReplace(int32_t start,
3559 const UnicodeString& srcText,
3563 UnicodeString& doReplace(int32_t start,
3565 const char16_t *srcChars,
3569 UnicodeString& doAppend(const UnicodeString& src, int32_t srcStart, int32_t srcLength);
3570 UnicodeString& doAppend(const char16_t *srcChars, int32_t srcStart, int32_t srcLength);
3572 UnicodeString& doReverse(int32_t start,
3576 int32_t doHashCode(
void) const;
3580 inline char16_t* getArrayStart(
void);
3581 inline const char16_t* getArrayStart(
void) const;
3583 inline
UBool hasShortLength() const;
3584 inline int32_t getShortLength() const;
3588 inline
UBool isWritable() const;
3591 inline
UBool isBufferWritable() const;
3594 inline
void setZeroLength();
3595 inline
void setShortLength(int32_t len);
3596 inline
void setLength(int32_t len);
3597 inline
void setToEmpty();
3598 inline
void setArray(char16_t *array, int32_t len, int32_t capacity);
3605 UBool allocate(int32_t capacity);
3608 void releaseArray(
void);
3614 UnicodeString ©From(const UnicodeString &src,
UBool fastCopy=
FALSE);
3617 void copyFieldsFrom(UnicodeString &src,
UBool setSrcToBogus) U_NOEXCEPT;
3620 inline
void pinIndex(int32_t& start) const;
3621 inline
void pinIndices(int32_t& start,
3622 int32_t& length) const;
3624 #if !UCONFIG_NO_CONVERSION
3627 int32_t doExtract(int32_t start, int32_t length,
3628 char *dest, int32_t destCapacity,
3642 void doCodepageCreate(
const char *codepageData,
3644 const char *codepage);
3651 doCodepageCreate(
const char *codepageData,
3669 UBool cloneArrayIfNeeded(int32_t newCapacity = -1,
3670 int32_t growCapacity = -1,
3672 int32_t **pBufferToDelete = 0,
3673 UBool forceClone = FALSE);
3681 caseMap(int32_t caseLocale, uint32_t options,
3689 int32_t removeRef(
void);
3690 int32_t refCount(
void)
const;
3700 kInvalidUChar=0xffff,
3706 kUsingStackBuffer=2,
3708 kBufferIsReadonly=8,
3711 kAllStorageFlags=0x1f,
3714 kLength1=1<<kLengthShift,
3715 kMaxShortLength=0x3ff,
3716 kLengthIsLarge=0xffe0,
3719 kShortString=kUsingStackBuffer,
3720 kLongString=kRefCounted,
3721 kReadonlyAlias=kBufferIsReadonly,
3727 union StackBufferOrFields;
3728 friend union StackBufferOrFields;
3771 union StackBufferOrFields {
3775 int16_t fLengthAndFlags;
3776 char16_t fBuffer[US_STACKBUF_SIZE];
3779 int16_t fLengthAndFlags;
3798 operator+ (
const UnicodeString &s1,
const UnicodeString &s2);
3809 UnicodeString::pinIndex(int32_t& start)
const
3814 }
else if(start >
length()) {
3820 UnicodeString::pinIndices(int32_t& start,
3821 int32_t& _length)
const
3827 }
else if(start > len) {
3832 }
else if(_length > (len - start)) {
3833 _length = (len - start);
3838 UnicodeString::getArrayStart() {
3839 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3840 fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
3843 inline const char16_t*
3844 UnicodeString::getArrayStart()
const {
3845 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3846 fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
3855 fUnion.fStackFields.fLengthAndFlags=kShortString;
3859 fUnion.fStackFields.fLengthAndFlags=kShortString;
3863 fUnion.fStackFields.fLengthAndFlags=kShortString;
3867 fUnion.fStackFields.fLengthAndFlags=kShortString;
3874 UnicodeString::hasShortLength()
const {
3875 return fUnion.fFields.fLengthAndFlags>=0;
3879 UnicodeString::getShortLength()
const {
3882 return fUnion.fFields.fLengthAndFlags>>kLengthShift;
3887 return hasShortLength() ? getShortLength() : fUnion.fFields.fLength;
3892 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3893 US_STACKBUF_SIZE : fUnion.fFields.fCapacity;
3898 {
return doHashCode(); }
3902 {
return (
UBool)(fUnion.fFields.fLengthAndFlags & kIsBogus); }
3905 UnicodeString::isWritable()
const
3906 {
return (
UBool)!(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus)); }
3909 UnicodeString::isBufferWritable()
const
3912 !(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus|kBufferIsReadonly)) &&
3913 (!(fUnion.fFields.fLengthAndFlags&kRefCounted) || refCount()==1));
3916 inline const char16_t *
3918 if(fUnion.fFields.fLengthAndFlags&(kIsBogus|kOpenGetBuffer)) {
3920 }
else if(fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) {
3921 return fUnion.fStackFields.fBuffer;
3923 return fUnion.fFields.fArray;
3931 UnicodeString::doCompare(int32_t start,
3933 const UnicodeString& srcText,
3935 int32_t srcLength)
const
3938 return (int8_t)!isBogus();
3940 srcText.pinIndices(srcStart, srcLength);
3941 return doCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
3952 return !text.
isBogus() && len == textLength && doEquals(text, len);
3958 {
return (!
operator==(text)); }
3962 {
return doCompare(0,
length(), text, 0, text.
length()) == 1; }
3966 {
return doCompare(0,
length(), text, 0, text.
length()) == -1; }
3970 {
return doCompare(0,
length(), text, 0, text.
length()) != -1; }
3974 {
return doCompare(0,
length(), text, 0, text.
length()) != 1; }
3978 {
return doCompare(0,
length(), text, 0, text.
length()); }
3983 const UnicodeString& srcText)
const
3984 {
return doCompare(start, _length, srcText, 0, srcText.
length()); }
3988 int32_t srcLength)
const
3989 {
return doCompare(0,
length(), srcChars, 0, srcLength); }
3994 const UnicodeString& srcText,
3996 int32_t srcLength)
const
3997 {
return doCompare(start, _length, srcText, srcStart, srcLength); }
4002 const char16_t *srcChars)
const
4003 {
return doCompare(start, _length, srcChars, 0, _length); }
4008 const char16_t *srcChars,
4010 int32_t srcLength)
const
4011 {
return doCompare(start, _length, srcChars, srcStart, srcLength); }
4016 const UnicodeString& srcText,
4018 int32_t srcLimit)
const
4019 {
return doCompare(start, limit - start,
4020 srcText, srcStart, srcLimit - srcStart); }
4023 UnicodeString::doCompareCodePointOrder(int32_t start,
4025 const UnicodeString& srcText,
4027 int32_t srcLength)
const
4030 return (int8_t)!isBogus();
4032 srcText.pinIndices(srcStart, srcLength);
4033 return doCompareCodePointOrder(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
4039 {
return doCompareCodePointOrder(0,
length(), text, 0, text.
length()); }
4044 const UnicodeString& srcText)
const
4045 {
return doCompareCodePointOrder(start, _length, srcText, 0, srcText.
length()); }
4049 int32_t srcLength)
const
4050 {
return doCompareCodePointOrder(0,
length(), srcChars, 0, srcLength); }
4055 const UnicodeString& srcText,
4057 int32_t srcLength)
const
4058 {
return doCompareCodePointOrder(start, _length, srcText, srcStart, srcLength); }
4063 const char16_t *srcChars)
const
4064 {
return doCompareCodePointOrder(start, _length, srcChars, 0, _length); }
4069 const char16_t *srcChars,
4071 int32_t srcLength)
const
4072 {
return doCompareCodePointOrder(start, _length, srcChars, srcStart, srcLength); }
4077 const UnicodeString& srcText,
4079 int32_t srcLimit)
const
4080 {
return doCompareCodePointOrder(start, limit - start,
4081 srcText, srcStart, srcLimit - srcStart); }
4084 UnicodeString::doCaseCompare(int32_t start,
4086 const UnicodeString &srcText,
4089 uint32_t options)
const
4092 return (int8_t)!isBogus();
4094 srcText.pinIndices(srcStart, srcLength);
4095 return doCaseCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength, options);
4101 return doCaseCompare(0,
length(), text, 0, text.
length(), options);
4107 const UnicodeString &srcText,
4108 uint32_t options)
const {
4109 return doCaseCompare(start, _length, srcText, 0, srcText.
length(), options);
4115 uint32_t options)
const {
4116 return doCaseCompare(0,
length(), srcChars, 0, srcLength, options);
4122 const UnicodeString &srcText,
4125 uint32_t options)
const {
4126 return doCaseCompare(start, _length, srcText, srcStart, srcLength, options);
4132 const char16_t *srcChars,
4133 uint32_t options)
const {
4134 return doCaseCompare(start, _length, srcChars, 0, _length, options);
4140 const char16_t *srcChars,
4143 uint32_t options)
const {
4144 return doCaseCompare(start, _length, srcChars, srcStart, srcLength, options);
4150 const UnicodeString &srcText,
4153 uint32_t options)
const {
4154 return doCaseCompare(start, limit - start, srcText, srcStart, srcLimit - srcStart, options);
4162 int32_t _length)
const
4165 srcText.pinIndices(srcStart, srcLength);
4167 return indexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
4175 {
return indexOf(text, 0, text.
length(), 0,
length()); }
4179 int32_t start)
const {
4181 return indexOf(text, 0, text.
length(), start,
length() - start);
4187 int32_t _length)
const
4188 {
return indexOf(text, 0, text.
length(), start, _length); }
4193 int32_t start)
const {
4195 return indexOf(srcChars, 0, srcLength, start,
length() - start);
4202 int32_t _length)
const
4203 {
return indexOf(srcChars, 0, srcLength, start, _length); }
4208 int32_t _length)
const
4209 {
return doIndexOf(c, start, _length); }
4214 int32_t _length)
const
4215 {
return doIndexOf(c, start, _length); }
4219 {
return doIndexOf(c, 0,
length()); }
4223 {
return indexOf(c, 0,
length()); }
4227 int32_t start)
const {
4229 return doIndexOf(c, start,
length() - start);
4234 int32_t start)
const {
4236 return indexOf(c, start,
length() - start);
4243 int32_t _length)
const
4244 {
return lastIndexOf(srcChars, 0, srcLength, start, _length); }
4249 int32_t start)
const {
4251 return lastIndexOf(srcChars, 0, srcLength, start,
length() - start);
4259 int32_t _length)
const
4262 srcText.pinIndices(srcStart, srcLength);
4264 return lastIndexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
4273 int32_t _length)
const
4274 {
return lastIndexOf(text, 0, text.
length(), start, _length); }
4278 int32_t start)
const {
4280 return lastIndexOf(text, 0, text.
length(), start,
length() - start);
4285 {
return lastIndexOf(text, 0, text.
length(), 0,
length()); }
4290 int32_t _length)
const
4291 {
return doLastIndexOf(c, start, _length); }
4296 int32_t _length)
const {
4297 return doLastIndexOf(c, start, _length);
4302 {
return doLastIndexOf(c, 0,
length()); }
4306 return lastIndexOf(c, 0,
length());
4311 int32_t start)
const {
4313 return doLastIndexOf(c, start,
length() - start);
4318 int32_t start)
const {
4320 return lastIndexOf(c, start,
length() - start);
4325 {
return compare(0, text.
length(), text, 0, text.
length()) == 0; }
4330 int32_t srcLength)
const
4331 {
return doCompare(0, srcLength, srcText, srcStart, srcLength) == 0; }
4338 return doCompare(0, srcLength, srcChars, 0, srcLength) == 0;
4346 return doCompare(0, srcLength, srcChars, srcStart, srcLength) == 0;
4352 text, 0, text.
length()) == 0; }
4357 int32_t srcLength)
const {
4358 srcText.pinIndices(srcStart, srcLength);
4359 return doCompare(
length() - srcLength, srcLength,
4360 srcText, srcStart, srcLength) == 0;
4365 int32_t srcLength)
const {
4369 return doCompare(
length() - srcLength, srcLength,
4370 srcChars, 0, srcLength) == 0;
4376 int32_t srcLength)
const {
4380 return doCompare(
length() - srcLength, srcLength,
4381 srcChars, srcStart, srcLength) == 0;
4387 inline UnicodeString&
4390 const UnicodeString& srcText)
4391 {
return doReplace(start, _length, srcText, 0, srcText.
length()); }
4393 inline UnicodeString&
4396 const UnicodeString& srcText,
4399 {
return doReplace(start, _length, srcText, srcStart, srcLength); }
4401 inline UnicodeString&
4406 {
return doReplace(start, _length, srcChars, 0, srcLength); }
4408 inline UnicodeString&
4411 const char16_t *srcChars,
4414 {
return doReplace(start, _length, srcChars, srcStart, srcLength); }
4416 inline UnicodeString&
4420 {
return doReplace(start, _length, &srcChar, 0, 1); }
4422 inline UnicodeString&
4425 const UnicodeString& srcText)
4426 {
return doReplace(start, limit - start, srcText, 0, srcText.
length()); }
4428 inline UnicodeString&
4431 const UnicodeString& srcText,
4434 {
return doReplace(start, limit - start, srcText, srcStart, srcLimit - srcStart); }
4436 inline UnicodeString&
4438 const UnicodeString& newText)
4439 {
return findAndReplace(0,
length(), oldText, 0, oldText.
length(),
4440 newText, 0, newText.
length()); }
4442 inline UnicodeString&
4445 const UnicodeString& oldText,
4446 const UnicodeString& newText)
4447 {
return findAndReplace(start, _length, oldText, 0, oldText.
length(),
4448 newText, 0, newText.
length()); }
4454 UnicodeString::doExtract(int32_t start,
4456 UnicodeString& target)
const
4457 { target.
replace(0, target.
length(), *
this, start, _length); }
4463 int32_t targetStart)
const
4464 { doExtract(start, _length, target, targetStart); }
4469 UnicodeString& target)
const
4470 { doExtract(start, _length, target); }
4472 #if !UCONFIG_NO_CONVERSION
4478 const char *codepage)
const
4482 return extract(start, _length, dst, dst!=0 ? 0xffffffff : 0, codepage);
4491 int32_t dstStart)
const {
4494 doExtract(start, limit - start, dst, dstStart);
4497 inline UnicodeString
4499 return tempSubString(start, limit - start);
4503 UnicodeString::doCharAt(int32_t offset)
const
4505 if((uint32_t)offset < (uint32_t)
length()) {
4506 return getArrayStart()[offset];
4508 return kInvalidUChar;
4514 {
return doCharAt(offset); }
4518 {
return doCharAt(offset); }
4523 return (fUnion.fFields.fLengthAndFlags>>kLengthShift) == 0;
4530 UnicodeString::setZeroLength() {
4531 fUnion.fFields.fLengthAndFlags &= kAllStorageFlags;
4535 UnicodeString::setShortLength(int32_t len) {
4537 fUnion.fFields.fLengthAndFlags =
4538 (int16_t)((fUnion.fFields.fLengthAndFlags & kAllStorageFlags) | (len << kLengthShift));
4542 UnicodeString::setLength(int32_t len) {
4543 if(len <= kMaxShortLength) {
4544 setShortLength(len);
4546 fUnion.fFields.fLengthAndFlags |= kLengthIsLarge;
4547 fUnion.fFields.fLength = len;
4552 UnicodeString::setToEmpty() {
4553 fUnion.fFields.fLengthAndFlags = kShortString;
4557 UnicodeString::setArray(char16_t *array, int32_t len, int32_t capacity) {
4559 fUnion.fFields.fArray = array;
4560 fUnion.fFields.fCapacity = capacity;
4563 inline UnicodeString&
4565 {
return doReplace(0,
length(), &ch, 0, 1); }
4567 inline UnicodeString&
4569 {
return replace(0,
length(), ch); }
4571 inline UnicodeString&
4577 return doReplace(0,
length(), srcText, srcStart, srcLength);
4580 inline UnicodeString&
4585 srcText.pinIndex(srcStart);
4586 return doReplace(0,
length(), srcText, srcStart, srcText.
length() - srcStart);
4589 inline UnicodeString&
4592 return copyFrom(srcText);
4595 inline UnicodeString&
4600 return doReplace(0,
length(), srcChars, 0, srcLength);
4603 inline UnicodeString&
4607 return doReplace(0,
length(), &srcChar, 0, 1);
4610 inline UnicodeString&
4614 return replace(0,
length(), srcChar);
4617 inline UnicodeString&
4621 {
return doAppend(srcText, srcStart, srcLength); }
4623 inline UnicodeString&
4625 {
return doAppend(srcText, 0, srcText.
length()); }
4627 inline UnicodeString&
4631 {
return doAppend(srcChars, srcStart, srcLength); }
4633 inline UnicodeString&
4636 {
return doAppend(srcChars, 0, srcLength); }
4638 inline UnicodeString&
4640 {
return doAppend(&srcChar, 0, 1); }
4642 inline UnicodeString&
4644 {
return doAppend(&ch, 0, 1); }
4646 inline UnicodeString&
4651 inline UnicodeString&
4653 {
return doAppend(srcText, 0, srcText.
length()); }
4655 inline UnicodeString&
4657 const UnicodeString& srcText,
4660 {
return doReplace(start, 0, srcText, srcStart, srcLength); }
4662 inline UnicodeString&
4664 const UnicodeString& srcText)
4665 {
return doReplace(start, 0, srcText, 0, srcText.
length()); }
4667 inline UnicodeString&
4669 const char16_t *srcChars,
4672 {
return doReplace(start, 0, srcChars, srcStart, srcLength); }
4674 inline UnicodeString&
4678 {
return doReplace(start, 0, srcChars, 0, srcLength); }
4680 inline UnicodeString&
4683 {
return doReplace(start, 0, &srcChar, 0, 1); }
4685 inline UnicodeString&
4688 {
return replace(start, 0, srcChar); }
4691 inline UnicodeString&
4703 inline UnicodeString&
4707 if(start <= 0 && _length ==
INT32_MAX) {
4711 return doReplace(start, _length,
NULL, 0, 0);
4714 inline UnicodeString&
4717 {
return doReplace(start, limit - start,
NULL, 0, 0); }
4719 inline UnicodeString &
4722 return doReplace(0, start,
NULL, 0, 0);
4728 if(isBogus() && targetLength == 0) {
4732 }
else if((uint32_t)targetLength < (uint32_t)
length()) {
4733 setLength(targetLength);
4740 inline UnicodeString&
4742 {
return doReverse(0,
length()); }
4744 inline UnicodeString&
4747 {
return doReverse(start, _length); }
UnicodeString & reverse(void)
Reverse this UnicodeString in place.
#define UNISTR_OBJECT_SIZE
Desired sizeof(UnicodeString) in bytes.
char16_t charAt(int32_t offset) const
Returns the 16-bit code unit at the given offset into the text.
UnicodeString & setTo(const UnicodeString &srcText, int32_t srcStart)
Set the text in the UnicodeString object to the characters in srcText in the range [srcStart...
An Appendable implementation which writes to a UnicodeString.
EInvariant
Constant to be used in the UnicodeString(char *, int32_t, EInvariant) constructor which constructs a ...
UChar32 char32At(int32_t offset) const
Returns the 32-bit code point at the given 16-bit offset into the text.
int8_t caseCompare(const UnicodeString &text, uint32_t options) const
Compare two strings case-insensitively using full case folding.
UBool operator<=(const UnicodeString &text) const
Less than or equal operator.
virtual UBool hasMetaData() const
Returns true if this object contains metadata.
UnicodeString(wchar_t *buffer, int32_t buffLength, int32_t buffCapacity)
Writable-aliasing wchar_t * constructor.
int32_t lastIndexOf(const UnicodeString &text) const
Locate in this the last occurrence of the characters in text, using bitwise comparison.
virtual void copy(int32_t start, int32_t limit, int32_t dest)=0
Copies a substring of this object, retaining metadata.
UnicodeString & retainBetween(int32_t start, int32_t limit=INT32_MAX)
Retain only the characters in the range [start, limit) from the UnicodeString object.
UBool isBogus(void) const
Determine if this object contains a valid string.
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.
char16_t operator[](int32_t offset) const
Return the code unit at offset offset.
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.
UnicodeString(const wchar_t *text, int32_t length)
wchar_t * constructor.
#define U_SIZEOF_UCHAR
Number of bytes in a UChar.
UnicodeString(const uint16_t *text, int32_t length)
uint16_t * constructor.
UBool operator==(const UnicodeString &text) const
Equality operator.
virtual void extractBetween(int32_t start, int32_t limit, UnicodeString &target) const =0
Copies characters in the range [start, limit) into the UnicodeString target.
UnicodeString & findAndReplace(const UnicodeString &oldText, const UnicodeString &newText)
Replace all occurrences of characters in oldText with the characters in newText.
A ByteSink can be filled with bytes.
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.
UBool operator!=(const UnicodeString &text) const
Inequality operator.
UBool operator>(const UnicodeString &text) const
Greater than operator.
UnicodeString & removeBetween(int32_t start, int32_t limit=(int32_t) INT32_MAX)
Remove the characters in the range [start, limit) from the UnicodeString object.
#define UCONFIG_NO_BREAK_ITERATION
This switch turns off break iteration.
UnicodeString tempSubStringBetween(int32_t start, int32_t limit=INT32_MAX) const
Create a temporary substring for the specified range.
Records lengths of string edits but not replacement text.
C++ API: StringPiece: Read-only byte string wrapper class.
Replaceable is an abstract base class representing a string of characters that supports the replaceme...
#define UNISTR_FROM_CHAR_EXPLICIT
This can be defined to be empty or "explicit".
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
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.
StringClass & toUTF8String(StringClass &result) const
Convert the UnicodeString to UTF-8 and append the result to a standard string.
C++ API: Interface for writing bytes, and implementation classes.
UBool truncate(int32_t targetLength)
Truncate this UnicodeString to the targetLength.
U_COMMON_API UnicodeString operator+(const UnicodeString &s1, const UnicodeString &s2)
Create a new UnicodeString with the concatenation of two others.
UnicodeString & remove(void)
Remove all characters from the UnicodeString object.
UnicodeString()
Construct an empty UnicodeString.
int32_t getCapacity(void) const
Return the capacity of the internal buffer of the UnicodeString object.
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 & 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...
The BreakIterator class implements methods for finding the location of boundaries in text...
UBool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
#define NULL
Define NULL if necessary, to nullptr for C++ and to ((void *)0) for C.
UnicodeString & replaceBetween(int32_t start, int32_t limit, const UnicodeString &srcText)
Replace the characters in the range [start, limit) with the characters in srcText.
C++ API: Central ICU header for including the C++ standard header and for related definition...
const UChar * toUCharPtr(const char16_t *p)
Converts from const char16_t * to const UChar *.
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...
UBool isEmpty(void) const
Determine if this string is empty.
#define TRUE
The TRUE value of a UBool.
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...
const char16_t * getBuffer() const
Get a read-only pointer to the internal buffer.
UBool operator>=(const UnicodeString &text) const
Greater than or equal 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.
uint16_t UChar
The base type for UTF-16 code units and pointers.
UnicodeString(uint16_t *buffer, int32_t buffLength, int32_t buffCapacity)
Writable-aliasing uint16_t * constructor.
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
int8_t compareCodePointOrder(const UnicodeString &text) const
Compare two Unicode strings in code point order.
UBool startsWith(const UnicodeString &text) const
Determine if this starts with the characters in text
char16_t charAt(int32_t offset) const
Return the code unit at offset offset.
struct UConverter UConverter
#define INT32_MAX
The largest value a 32 bit signed integer can hold.
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
UnicodeString & operator=(const UnicodeString &srcText)
Assignment operator.
int32_t indexOf(const UnicodeString &text) const
Locate in this the first occurrence of the characters in text, using bitwise comparison.
int8_t compare(const UnicodeString &text) const
Compare the characters bitwise in this UnicodeString to the characters in 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".
UBool operator<(const UnicodeString &text) const
Less than operator.
int32_t hashCode(void) const
Generate a hash code for this object.
int32_t u_strlen(const UChar *s)
Determine the length of an array of UChar.
#define FALSE
The FALSE value of a UBool.
#define U_COMMON_API
Set to export library symbols from inside the common library, and to import them from outside...
UnicodeString & operator+=(char16_t ch)
Append operator.
int32_t length() const
Returns the number of 16-bit code units in the text.
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
#define UNISTR_FROM_STRING_EXPLICIT
This can be defined to be empty or "explicit".
UBool endsWith(const UnicodeString &text) const
Determine if this ends with the characters in text
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...
int32_t length(void) const
Return the length of the UnicodeString object.
#define U_STABLE
This is used to declare a function as a stable public ICU C API.
int8_t UBool
The ICU boolean type.
C++ API: char16_t pointer wrappers with implicit conversion from bit-compatible raw pointer types...
A Locale object represents a specific geographical, political, or cultural region.
C++ API: Replaceable String.