00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef UNISTR_H
00024 #define UNISTR_H
00025
00031 #include "unicode/utypes.h"
00032
00033 #if U_SHOW_CPLUSPLUS_API
00034
00035 #include <cstddef>
00036 #include "unicode/char16ptr.h"
00037 #include "unicode/rep.h"
00038 #include "unicode/std_string.h"
00039 #include "unicode/stringpiece.h"
00040 #include "unicode/bytestream.h"
00041
00042 struct UConverter;
00043
00044 #ifndef USTRING_H
00045
00050 U_CAPI int32_t U_EXPORT2 u_strlen(const UChar *s);
00051 #endif
00052
00053 U_NAMESPACE_BEGIN
00054
00055 #if !UCONFIG_NO_BREAK_ITERATION
00056 class BreakIterator;
00057 #endif
00058 class Edits;
00059
00060 U_NAMESPACE_END
00061
00062
00069 typedef int32_t U_CALLCONV
00070 UStringCaseMapper(int32_t caseLocale, uint32_t options,
00071 #if !UCONFIG_NO_BREAK_ITERATION
00072 icu::BreakIterator *iter,
00073 #endif
00074 char16_t *dest, int32_t destCapacity,
00075 const char16_t *src, int32_t srcLength,
00076 icu::Edits *edits,
00077 UErrorCode &errorCode);
00078
00079 U_NAMESPACE_BEGIN
00080
00081 class Locale;
00082 class StringCharacterIterator;
00083 class UnicodeStringAppendable;
00084
00085
00086
00097 #define US_INV icu::UnicodeString::kInvariant
00098
00116 #if !U_CHAR16_IS_TYPEDEF
00117 # define UNICODE_STRING(cs, _length) icu::UnicodeString(true, u ## cs, _length)
00118 #else
00119 # define UNICODE_STRING(cs, _length) icu::UnicodeString(true, (const char16_t*)u ## cs, _length)
00120 #endif
00121
00135 #define UNICODE_STRING_SIMPLE(cs) UNICODE_STRING(cs, -1)
00136
00144 #ifndef UNISTR_FROM_CHAR_EXPLICIT
00145 # if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION)
00146
00147 # define UNISTR_FROM_CHAR_EXPLICIT explicit
00148 # else
00149
00150 # define UNISTR_FROM_CHAR_EXPLICIT
00151 # endif
00152 #endif
00153
00164 #ifndef UNISTR_FROM_STRING_EXPLICIT
00165 # if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION)
00166
00167 # define UNISTR_FROM_STRING_EXPLICIT explicit
00168 # else
00169
00170 # define UNISTR_FROM_STRING_EXPLICIT
00171 # endif
00172 #endif
00173
00207 #ifndef UNISTR_OBJECT_SIZE
00208 # define UNISTR_OBJECT_SIZE 64
00209 #endif
00210
00295 class U_COMMON_API UnicodeString : public Replaceable
00296 {
00297 public:
00298
00307 enum EInvariant {
00312 kInvariant
00313 };
00314
00315
00316
00317
00318
00319
00320
00328 inline bool operator== (const UnicodeString& text) const;
00329
00337 inline bool operator!= (const UnicodeString& text) const;
00338
00346 inline UBool operator> (const UnicodeString& text) const;
00347
00355 inline UBool operator< (const UnicodeString& text) const;
00356
00364 inline UBool operator>= (const UnicodeString& text) const;
00365
00373 inline UBool operator<= (const UnicodeString& text) const;
00374
00386 inline int8_t compare(const UnicodeString& text) const;
00387
00403 inline int8_t compare(int32_t start,
00404 int32_t length,
00405 const UnicodeString& text) const;
00406
00424 inline int8_t compare(int32_t start,
00425 int32_t length,
00426 const UnicodeString& srcText,
00427 int32_t srcStart,
00428 int32_t srcLength) const;
00429
00442 inline int8_t compare(ConstChar16Ptr srcChars,
00443 int32_t srcLength) const;
00444
00459 inline int8_t compare(int32_t start,
00460 int32_t length,
00461 const char16_t *srcChars) const;
00462
00480 inline int8_t compare(int32_t start,
00481 int32_t length,
00482 const char16_t *srcChars,
00483 int32_t srcStart,
00484 int32_t srcLength) const;
00485
00503 inline int8_t compareBetween(int32_t start,
00504 int32_t limit,
00505 const UnicodeString& srcText,
00506 int32_t srcStart,
00507 int32_t srcLimit) const;
00508
00526 inline int8_t compareCodePointOrder(const UnicodeString& text) const;
00527
00547 inline int8_t compareCodePointOrder(int32_t start,
00548 int32_t length,
00549 const UnicodeString& srcText) const;
00550
00572 inline int8_t compareCodePointOrder(int32_t start,
00573 int32_t length,
00574 const UnicodeString& srcText,
00575 int32_t srcStart,
00576 int32_t srcLength) const;
00577
00596 inline int8_t compareCodePointOrder(ConstChar16Ptr srcChars,
00597 int32_t srcLength) const;
00598
00618 inline int8_t compareCodePointOrder(int32_t start,
00619 int32_t length,
00620 const char16_t *srcChars) const;
00621
00643 inline int8_t compareCodePointOrder(int32_t start,
00644 int32_t length,
00645 const char16_t *srcChars,
00646 int32_t srcStart,
00647 int32_t srcLength) const;
00648
00670 inline int8_t compareCodePointOrderBetween(int32_t start,
00671 int32_t limit,
00672 const UnicodeString& srcText,
00673 int32_t srcStart,
00674 int32_t srcLimit) const;
00675
00694 inline int8_t caseCompare(const UnicodeString& text, uint32_t options) const;
00695
00716 inline int8_t caseCompare(int32_t start,
00717 int32_t length,
00718 const UnicodeString& srcText,
00719 uint32_t options) const;
00720
00743 inline int8_t caseCompare(int32_t start,
00744 int32_t length,
00745 const UnicodeString& srcText,
00746 int32_t srcStart,
00747 int32_t srcLength,
00748 uint32_t options) const;
00749
00769 inline int8_t caseCompare(ConstChar16Ptr srcChars,
00770 int32_t srcLength,
00771 uint32_t options) const;
00772
00793 inline int8_t caseCompare(int32_t start,
00794 int32_t length,
00795 const char16_t *srcChars,
00796 uint32_t options) const;
00797
00820 inline int8_t caseCompare(int32_t start,
00821 int32_t length,
00822 const char16_t *srcChars,
00823 int32_t srcStart,
00824 int32_t srcLength,
00825 uint32_t options) const;
00826
00849 inline int8_t caseCompareBetween(int32_t start,
00850 int32_t limit,
00851 const UnicodeString& srcText,
00852 int32_t srcStart,
00853 int32_t srcLimit,
00854 uint32_t options) const;
00855
00863 inline UBool startsWith(const UnicodeString& text) const;
00864
00875 inline UBool startsWith(const UnicodeString& srcText,
00876 int32_t srcStart,
00877 int32_t srcLength) const;
00878
00887 inline UBool startsWith(ConstChar16Ptr srcChars,
00888 int32_t srcLength) const;
00889
00899 inline UBool startsWith(const char16_t *srcChars,
00900 int32_t srcStart,
00901 int32_t srcLength) const;
00902
00910 inline UBool endsWith(const UnicodeString& text) const;
00911
00922 inline UBool endsWith(const UnicodeString& srcText,
00923 int32_t srcStart,
00924 int32_t srcLength) const;
00925
00934 inline UBool endsWith(ConstChar16Ptr srcChars,
00935 int32_t srcLength) const;
00936
00947 inline UBool endsWith(const char16_t *srcChars,
00948 int32_t srcStart,
00949 int32_t srcLength) const;
00950
00951
00952
00953
00962 inline int32_t indexOf(const UnicodeString& text) const;
00963
00973 inline int32_t indexOf(const UnicodeString& text,
00974 int32_t start) const;
00975
00987 inline int32_t indexOf(const UnicodeString& text,
00988 int32_t start,
00989 int32_t length) const;
00990
01007 inline int32_t indexOf(const UnicodeString& srcText,
01008 int32_t srcStart,
01009 int32_t srcLength,
01010 int32_t start,
01011 int32_t length) const;
01012
01024 inline int32_t indexOf(const char16_t *srcChars,
01025 int32_t srcLength,
01026 int32_t start) const;
01027
01040 inline int32_t indexOf(ConstChar16Ptr srcChars,
01041 int32_t srcLength,
01042 int32_t start,
01043 int32_t length) const;
01044
01061 int32_t indexOf(const char16_t *srcChars,
01062 int32_t srcStart,
01063 int32_t srcLength,
01064 int32_t start,
01065 int32_t length) const;
01066
01074 inline int32_t indexOf(char16_t c) const;
01075
01084 inline int32_t indexOf(UChar32 c) const;
01085
01094 inline int32_t indexOf(char16_t c,
01095 int32_t start) const;
01096
01106 inline int32_t indexOf(UChar32 c,
01107 int32_t start) const;
01108
01119 inline int32_t indexOf(char16_t c,
01120 int32_t start,
01121 int32_t length) const;
01122
01134 inline int32_t indexOf(UChar32 c,
01135 int32_t start,
01136 int32_t length) const;
01137
01146 inline int32_t lastIndexOf(const UnicodeString& text) const;
01147
01157 inline int32_t lastIndexOf(const UnicodeString& text,
01158 int32_t start) const;
01159
01171 inline int32_t lastIndexOf(const UnicodeString& text,
01172 int32_t start,
01173 int32_t length) const;
01174
01191 inline int32_t lastIndexOf(const UnicodeString& srcText,
01192 int32_t srcStart,
01193 int32_t srcLength,
01194 int32_t start,
01195 int32_t length) const;
01196
01207 inline int32_t lastIndexOf(const char16_t *srcChars,
01208 int32_t srcLength,
01209 int32_t start) const;
01210
01223 inline int32_t lastIndexOf(ConstChar16Ptr srcChars,
01224 int32_t srcLength,
01225 int32_t start,
01226 int32_t length) const;
01227
01244 int32_t lastIndexOf(const char16_t *srcChars,
01245 int32_t srcStart,
01246 int32_t srcLength,
01247 int32_t start,
01248 int32_t length) const;
01249
01257 inline int32_t lastIndexOf(char16_t c) const;
01258
01267 inline int32_t lastIndexOf(UChar32 c) const;
01268
01277 inline int32_t lastIndexOf(char16_t c,
01278 int32_t start) const;
01279
01289 inline int32_t lastIndexOf(UChar32 c,
01290 int32_t start) const;
01291
01302 inline int32_t lastIndexOf(char16_t c,
01303 int32_t start,
01304 int32_t length) const;
01305
01317 inline int32_t lastIndexOf(UChar32 c,
01318 int32_t start,
01319 int32_t length) const;
01320
01321
01322
01323
01332 inline char16_t charAt(int32_t offset) const;
01333
01341 inline char16_t operator[] (int32_t offset) const;
01342
01354 UChar32 char32At(int32_t offset) const;
01355
01371 int32_t getChar32Start(int32_t offset) const;
01372
01389 int32_t getChar32Limit(int32_t offset) const;
01390
01441 int32_t moveIndex32(int32_t index, int32_t delta) const;
01442
01443
01444
01460 inline void extract(int32_t start,
01461 int32_t length,
01462 Char16Ptr dst,
01463 int32_t dstStart = 0) const;
01464
01486 int32_t
01487 extract(Char16Ptr dest, int32_t destCapacity,
01488 UErrorCode &errorCode) const;
01489
01499 inline void extract(int32_t start,
01500 int32_t length,
01501 UnicodeString& target) const;
01502
01514 inline void extractBetween(int32_t start,
01515 int32_t limit,
01516 char16_t *dst,
01517 int32_t dstStart = 0) const;
01518
01527 virtual void extractBetween(int32_t start,
01528 int32_t limit,
01529 UnicodeString& target) const override;
01530
01552 int32_t extract(int32_t start,
01553 int32_t startLength,
01554 char *target,
01555 int32_t targetCapacity,
01556 enum EInvariant inv) const;
01557
01558 #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
01559
01579 int32_t extract(int32_t start,
01580 int32_t startLength,
01581 char *target,
01582 uint32_t targetLength) const;
01583
01584 #endif
01585
01586 #if !UCONFIG_NO_CONVERSION
01587
01613 inline int32_t extract(int32_t start,
01614 int32_t startLength,
01615 char *target,
01616 const char *codepage = 0) const;
01617
01647 int32_t extract(int32_t start,
01648 int32_t startLength,
01649 char *target,
01650 uint32_t targetLength,
01651 const char *codepage) const;
01652
01670 int32_t extract(char *dest, int32_t destCapacity,
01671 UConverter *cnv,
01672 UErrorCode &errorCode) const;
01673
01674 #endif
01675
01689 UnicodeString tempSubString(int32_t start=0, int32_t length=INT32_MAX) const;
01690
01701 inline UnicodeString tempSubStringBetween(int32_t start, int32_t limit=INT32_MAX) const;
01702
01714 void toUTF8(ByteSink &sink) const;
01715
01728 template<typename StringClass>
01729 StringClass &toUTF8String(StringClass &result) const {
01730 StringByteSink<StringClass> sbs(&result, length());
01731 toUTF8(sbs);
01732 return result;
01733 }
01734
01750 int32_t toUTF32(UChar32 *utf32, int32_t capacity, UErrorCode &errorCode) const;
01751
01752
01753
01762 inline int32_t length(void) const;
01763
01777 int32_t
01778 countChar32(int32_t start=0, int32_t length=INT32_MAX) const;
01779
01803 UBool
01804 hasMoreChar32Than(int32_t start, int32_t length, int32_t number) const;
01805
01811 inline UBool isEmpty(void) const;
01812
01822 inline int32_t getCapacity(void) const;
01823
01824
01825
01831 inline int32_t hashCode(void) const;
01832
01845 inline UBool isBogus(void) const;
01846
01847
01848
01849
01850
01851
01852
01853
01872 UnicodeString &operator=(const UnicodeString &srcText);
01873
01899 UnicodeString &fastCopyFrom(const UnicodeString &src);
01900
01909 UnicodeString &operator=(UnicodeString &&src) U_NOEXCEPT;
01910
01916 void swap(UnicodeString &other) U_NOEXCEPT;
01917
01924 friend inline void U_EXPORT2
01925 swap(UnicodeString &s1, UnicodeString &s2) U_NOEXCEPT {
01926 s1.swap(s2);
01927 }
01928
01936 inline UnicodeString& operator= (char16_t ch);
01937
01945 inline UnicodeString& operator= (UChar32 ch);
01946
01958 inline UnicodeString& setTo(const UnicodeString& srcText,
01959 int32_t srcStart);
01960
01974 inline UnicodeString& setTo(const UnicodeString& srcText,
01975 int32_t srcStart,
01976 int32_t srcLength);
01977
01986 inline UnicodeString& setTo(const UnicodeString& srcText);
01987
01996 inline UnicodeString& setTo(const char16_t *srcChars,
01997 int32_t srcLength);
01998
02007 inline UnicodeString& setTo(char16_t srcChar);
02008
02017 inline UnicodeString& setTo(UChar32 srcChar);
02018
02042 UnicodeString &setTo(UBool isTerminated,
02043 ConstChar16Ptr text,
02044 int32_t textLength);
02045
02065 UnicodeString &setTo(char16_t *buffer,
02066 int32_t buffLength,
02067 int32_t buffCapacity);
02068
02108 void setToBogus();
02109
02117 UnicodeString& setCharAt(int32_t offset,
02118 char16_t ch);
02119
02120
02121
02122
02130 inline UnicodeString& operator+= (char16_t ch);
02131
02139 inline UnicodeString& operator+= (UChar32 ch);
02140
02148 inline UnicodeString& operator+= (const UnicodeString& srcText);
02149
02164 inline UnicodeString& append(const UnicodeString& srcText,
02165 int32_t srcStart,
02166 int32_t srcLength);
02167
02175 inline UnicodeString& append(const UnicodeString& srcText);
02176
02190 inline UnicodeString& append(const char16_t *srcChars,
02191 int32_t srcStart,
02192 int32_t srcLength);
02193
02203 inline UnicodeString& append(ConstChar16Ptr srcChars,
02204 int32_t srcLength);
02205
02212 inline UnicodeString& append(char16_t srcChar);
02213
02220 UnicodeString& append(UChar32 srcChar);
02221
02222
02223
02224
02238 inline UnicodeString& insert(int32_t start,
02239 const UnicodeString& srcText,
02240 int32_t srcStart,
02241 int32_t srcLength);
02242
02251 inline UnicodeString& insert(int32_t start,
02252 const UnicodeString& srcText);
02253
02267 inline UnicodeString& insert(int32_t start,
02268 const char16_t *srcChars,
02269 int32_t srcStart,
02270 int32_t srcLength);
02271
02281 inline UnicodeString& insert(int32_t start,
02282 ConstChar16Ptr srcChars,
02283 int32_t srcLength);
02284
02293 inline UnicodeString& insert(int32_t start,
02294 char16_t srcChar);
02295
02304 inline UnicodeString& insert(int32_t start,
02305 UChar32 srcChar);
02306
02307
02308
02309
02327 inline UnicodeString& replace(int32_t start,
02328 int32_t length,
02329 const UnicodeString& srcText,
02330 int32_t srcStart,
02331 int32_t srcLength);
02332
02345 inline UnicodeString& replace(int32_t start,
02346 int32_t length,
02347 const UnicodeString& srcText);
02348
02366 inline UnicodeString& replace(int32_t start,
02367 int32_t length,
02368 const char16_t *srcChars,
02369 int32_t srcStart,
02370 int32_t srcLength);
02371
02384 inline UnicodeString& replace(int32_t start,
02385 int32_t length,
02386 ConstChar16Ptr srcChars,
02387 int32_t srcLength);
02388
02400 inline UnicodeString& replace(int32_t start,
02401 int32_t length,
02402 char16_t srcChar);
02403
02415 UnicodeString& replace(int32_t start, int32_t length, UChar32 srcChar);
02416
02426 inline UnicodeString& replaceBetween(int32_t start,
02427 int32_t limit,
02428 const UnicodeString& srcText);
02429
02444 inline UnicodeString& replaceBetween(int32_t start,
02445 int32_t limit,
02446 const UnicodeString& srcText,
02447 int32_t srcStart,
02448 int32_t srcLimit);
02449
02457 virtual void handleReplaceBetween(int32_t start,
02458 int32_t limit,
02459 const UnicodeString& text) override;
02460
02466 virtual UBool hasMetaData() const override;
02467
02481 virtual void copy(int32_t start, int32_t limit, int32_t dest) override;
02482
02483
02484
02493 inline UnicodeString& findAndReplace(const UnicodeString& oldText,
02494 const UnicodeString& newText);
02495
02507 inline UnicodeString& findAndReplace(int32_t start,
02508 int32_t length,
02509 const UnicodeString& oldText,
02510 const UnicodeString& newText);
02511
02529 UnicodeString& findAndReplace(int32_t start,
02530 int32_t length,
02531 const UnicodeString& oldText,
02532 int32_t oldStart,
02533 int32_t oldLength,
02534 const UnicodeString& newText,
02535 int32_t newStart,
02536 int32_t newLength);
02537
02538
02539
02540
02549 inline UnicodeString& remove();
02550
02559 inline UnicodeString& remove(int32_t start,
02560 int32_t length = (int32_t)INT32_MAX);
02561
02570 inline UnicodeString& removeBetween(int32_t start,
02571 int32_t limit = (int32_t)INT32_MAX);
02572
02582 inline UnicodeString &retainBetween(int32_t start, int32_t limit = INT32_MAX);
02583
02584
02585
02597 UBool padLeading(int32_t targetLength,
02598 char16_t padChar = 0x0020);
02599
02611 UBool padTrailing(int32_t targetLength,
02612 char16_t padChar = 0x0020);
02613
02620 inline UBool truncate(int32_t targetLength);
02621
02627 UnicodeString& trim(void);
02628
02629
02630
02631
02637 inline UnicodeString& reverse(void);
02638
02647 inline UnicodeString& reverse(int32_t start,
02648 int32_t length);
02649
02656 UnicodeString& toUpper(void);
02657
02665 UnicodeString& toUpper(const Locale& locale);
02666
02673 UnicodeString& toLower(void);
02674
02682 UnicodeString& toLower(const Locale& locale);
02683
02684 #if !UCONFIG_NO_BREAK_ITERATION
02685
02712 UnicodeString &toTitle(BreakIterator *titleIter);
02713
02741 UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale);
02742
02773 UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale, uint32_t options);
02774
02775 #endif
02776
02790 UnicodeString &foldCase(uint32_t options=0 );
02791
02792
02793
02794
02795
02839 char16_t *getBuffer(int32_t minCapacity);
02840
02861 void releaseBuffer(int32_t newLength=-1);
02862
02893 inline const char16_t *getBuffer() const;
02894
02928 const char16_t *getTerminatedBuffer();
02929
02930
02931
02932
02933
02937 inline UnicodeString();
02938
02950 UnicodeString(int32_t capacity, UChar32 c, int32_t count);
02951
02961 UNISTR_FROM_CHAR_EXPLICIT UnicodeString(char16_t ch);
02962
02972 UNISTR_FROM_CHAR_EXPLICIT UnicodeString(UChar32 ch);
02973
02984 UNISTR_FROM_STRING_EXPLICIT UnicodeString(const char16_t *text);
02985
02986 #if !U_CHAR16_IS_TYPEDEF
02987
02997 UNISTR_FROM_STRING_EXPLICIT UnicodeString(const uint16_t *text) :
02998 UnicodeString(ConstChar16Ptr(text)) {}
02999 #endif
03000
03001 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
03002
03013 UNISTR_FROM_STRING_EXPLICIT UnicodeString(const wchar_t *text) :
03014 UnicodeString(ConstChar16Ptr(text)) {}
03015 #endif
03016
03027 UNISTR_FROM_STRING_EXPLICIT inline UnicodeString(const std::nullptr_t text);
03028
03036 UnicodeString(const char16_t *text,
03037 int32_t textLength);
03038
03039 #if !U_CHAR16_IS_TYPEDEF
03040
03047 UnicodeString(const uint16_t *text, int32_t textLength) :
03048 UnicodeString(ConstChar16Ptr(text), textLength) {}
03049 #endif
03050
03051 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
03052
03060 UnicodeString(const wchar_t *text, int32_t textLength) :
03061 UnicodeString(ConstChar16Ptr(text), textLength) {}
03062 #endif
03063
03071 inline UnicodeString(const std::nullptr_t text, int32_t textLength);
03072
03095 UnicodeString(UBool isTerminated,
03096 ConstChar16Ptr text,
03097 int32_t textLength);
03098
03117 UnicodeString(char16_t *buffer, int32_t buffLength, int32_t buffCapacity);
03118
03119 #if !U_CHAR16_IS_TYPEDEF
03120
03128 UnicodeString(uint16_t *buffer, int32_t buffLength, int32_t buffCapacity) :
03129 UnicodeString(Char16Ptr(buffer), buffLength, buffCapacity) {}
03130 #endif
03131
03132 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
03133
03142 UnicodeString(wchar_t *buffer, int32_t buffLength, int32_t buffCapacity) :
03143 UnicodeString(Char16Ptr(buffer), buffLength, buffCapacity) {}
03144 #endif
03145
03154 inline UnicodeString(std::nullptr_t buffer, int32_t buffLength, int32_t buffCapacity);
03155
03156 #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
03157
03177 UNISTR_FROM_STRING_EXPLICIT UnicodeString(const char *codepageData);
03178
03187 UnicodeString(const char *codepageData, int32_t dataLength);
03188
03189 #endif
03190
03191 #if !UCONFIG_NO_CONVERSION
03192
03210 UnicodeString(const char *codepageData, const char *codepage);
03211
03229 UnicodeString(const char *codepageData, int32_t dataLength, const char *codepage);
03230
03252 UnicodeString(
03253 const char *src, int32_t srcLength,
03254 UConverter *cnv,
03255 UErrorCode &errorCode);
03256
03257 #endif
03258
03282 UnicodeString(const char *src, int32_t textLength, enum EInvariant inv);
03283
03284
03301 UnicodeString(const UnicodeString& that);
03302
03309 UnicodeString(UnicodeString &&src) U_NOEXCEPT;
03310
03317 UnicodeString(const UnicodeString& src, int32_t srcStart);
03318
03326 UnicodeString(const UnicodeString& src, int32_t srcStart, int32_t srcLength);
03327
03341 virtual UnicodeString *clone() const override;
03342
03346 virtual ~UnicodeString();
03347
03361 static UnicodeString fromUTF8(StringPiece utf8);
03362
03374 static UnicodeString fromUTF32(const UChar32 *utf32, int32_t length);
03375
03376
03377
03412 UnicodeString unescape() const;
03413
03433 UChar32 unescapeAt(int32_t &offset) const;
03434
03440 static UClassID U_EXPORT2 getStaticClassID();
03441
03447 virtual UClassID getDynamicClassID() const override;
03448
03449
03450
03451
03452
03453 protected:
03458 virtual int32_t getLength() const override;
03459
03465 virtual char16_t getCharAt(int32_t offset) const override;
03466
03472 virtual UChar32 getChar32At(int32_t offset) const override;
03473
03474 private:
03475
03476 UnicodeString &setToUTF8(StringPiece utf8);
03477
03478
03479
03480
03481
03482 int32_t
03483 toUTF8(int32_t start, int32_t len,
03484 char *target, int32_t capacity) const;
03485
03490 UBool doEquals(const UnicodeString &text, int32_t len) const;
03491
03492 inline int8_t
03493 doCompare(int32_t start,
03494 int32_t length,
03495 const UnicodeString& srcText,
03496 int32_t srcStart,
03497 int32_t srcLength) const;
03498
03499 int8_t doCompare(int32_t start,
03500 int32_t length,
03501 const char16_t *srcChars,
03502 int32_t srcStart,
03503 int32_t srcLength) const;
03504
03505 inline int8_t
03506 doCompareCodePointOrder(int32_t start,
03507 int32_t length,
03508 const UnicodeString& srcText,
03509 int32_t srcStart,
03510 int32_t srcLength) const;
03511
03512 int8_t doCompareCodePointOrder(int32_t start,
03513 int32_t length,
03514 const char16_t *srcChars,
03515 int32_t srcStart,
03516 int32_t srcLength) const;
03517
03518 inline int8_t
03519 doCaseCompare(int32_t start,
03520 int32_t length,
03521 const UnicodeString &srcText,
03522 int32_t srcStart,
03523 int32_t srcLength,
03524 uint32_t options) const;
03525
03526 int8_t
03527 doCaseCompare(int32_t start,
03528 int32_t length,
03529 const char16_t *srcChars,
03530 int32_t srcStart,
03531 int32_t srcLength,
03532 uint32_t options) const;
03533
03534 int32_t doIndexOf(char16_t c,
03535 int32_t start,
03536 int32_t length) const;
03537
03538 int32_t doIndexOf(UChar32 c,
03539 int32_t start,
03540 int32_t length) const;
03541
03542 int32_t doLastIndexOf(char16_t c,
03543 int32_t start,
03544 int32_t length) const;
03545
03546 int32_t doLastIndexOf(UChar32 c,
03547 int32_t start,
03548 int32_t length) const;
03549
03550 void doExtract(int32_t start,
03551 int32_t length,
03552 char16_t *dst,
03553 int32_t dstStart) const;
03554
03555 inline void doExtract(int32_t start,
03556 int32_t length,
03557 UnicodeString& target) const;
03558
03559 inline char16_t doCharAt(int32_t offset) const;
03560
03561 UnicodeString& doReplace(int32_t start,
03562 int32_t length,
03563 const UnicodeString& srcText,
03564 int32_t srcStart,
03565 int32_t srcLength);
03566
03567 UnicodeString& doReplace(int32_t start,
03568 int32_t length,
03569 const char16_t *srcChars,
03570 int32_t srcStart,
03571 int32_t srcLength);
03572
03573 UnicodeString& doAppend(const UnicodeString& src, int32_t srcStart, int32_t srcLength);
03574 UnicodeString& doAppend(const char16_t *srcChars, int32_t srcStart, int32_t srcLength);
03575
03576 UnicodeString& doReverse(int32_t start,
03577 int32_t length);
03578
03579
03580 int32_t doHashCode(void) const;
03581
03582
03583
03584 inline char16_t* getArrayStart(void);
03585 inline const char16_t* getArrayStart(void) const;
03586
03587 inline UBool hasShortLength() const;
03588 inline int32_t getShortLength() const;
03589
03590
03591
03592 inline UBool isWritable() const;
03593
03594
03595 inline UBool isBufferWritable() const;
03596
03597
03598 inline void setZeroLength();
03599 inline void setShortLength(int32_t len);
03600 inline void setLength(int32_t len);
03601 inline void setToEmpty();
03602 inline void setArray(char16_t *array, int32_t len, int32_t capacity);
03603
03604
03605
03606
03607
03608
03609 UBool allocate(int32_t capacity);
03610
03611
03612 void releaseArray(void);
03613
03614
03615 void unBogus();
03616
03617
03618 UnicodeString ©From(const UnicodeString &src, UBool fastCopy=false);
03619
03620
03621 void copyFieldsFrom(UnicodeString &src, UBool setSrcToBogus) U_NOEXCEPT;
03622
03623
03624 inline void pinIndex(int32_t& start) const;
03625 inline void pinIndices(int32_t& start,
03626 int32_t& length) const;
03627
03628 #if !UCONFIG_NO_CONVERSION
03629
03630
03631 int32_t doExtract(int32_t start, int32_t length,
03632 char *dest, int32_t destCapacity,
03633 UConverter *cnv,
03634 UErrorCode &errorCode) const;
03635
03636
03637
03638
03639
03640
03641
03642
03643
03644
03645
03646 void doCodepageCreate(const char *codepageData,
03647 int32_t dataLength,
03648 const char *codepage);
03649
03650
03651
03652
03653
03654 void
03655 doCodepageCreate(const char *codepageData,
03656 int32_t dataLength,
03657 UConverter *converter,
03658 UErrorCode &status);
03659
03660 #endif
03661
03662
03663
03664
03665
03666
03667
03668
03669
03670
03671
03672
03673 UBool cloneArrayIfNeeded(int32_t newCapacity = -1,
03674 int32_t growCapacity = -1,
03675 UBool doCopyArray = true,
03676 int32_t **pBufferToDelete = 0,
03677 UBool forceClone = false);
03678
03684 UnicodeString &
03685 caseMap(int32_t caseLocale, uint32_t options,
03686 #if !UCONFIG_NO_BREAK_ITERATION
03687 BreakIterator *iter,
03688 #endif
03689 UStringCaseMapper *stringCaseMapper);
03690
03691
03692 void addRef(void);
03693 int32_t removeRef(void);
03694 int32_t refCount(void) const;
03695
03696
03697 enum {
03703 US_STACKBUF_SIZE=(int32_t)(UNISTR_OBJECT_SIZE-sizeof(void *)-2)/U_SIZEOF_UCHAR,
03704 kInvalidUChar=0xffff,
03705 kInvalidHashCode=0,
03706 kEmptyHashCode=1,
03707
03708
03709 kIsBogus=1,
03710 kUsingStackBuffer=2,
03711 kRefCounted=4,
03712 kBufferIsReadonly=8,
03713 kOpenGetBuffer=16,
03714
03715 kAllStorageFlags=0x1f,
03716
03717 kLengthShift=5,
03718 kLength1=1<<kLengthShift,
03719 kMaxShortLength=0x3ff,
03720 kLengthIsLarge=0xffe0,
03721
03722
03723 kShortString=kUsingStackBuffer,
03724 kLongString=kRefCounted,
03725 kReadonlyAlias=kBufferIsReadonly,
03726 kWritableAlias=0
03727 };
03728
03729 friend class UnicodeStringAppendable;
03730
03731 union StackBufferOrFields;
03732 friend union StackBufferOrFields;
03733
03734
03735
03736
03737
03738
03739
03740
03741
03742
03743
03744
03745
03746
03747
03748
03749
03750
03751
03752
03753
03754
03755
03756
03757
03758
03759
03760
03761
03762
03763
03764
03765
03766
03767
03768
03769
03770
03771
03772
03773
03774
03775 union StackBufferOrFields {
03776
03777
03778 struct {
03779 int16_t fLengthAndFlags;
03780 char16_t fBuffer[US_STACKBUF_SIZE];
03781 } fStackFields;
03782 struct {
03783 int16_t fLengthAndFlags;
03784 int32_t fLength;
03785 int32_t fCapacity;
03786
03787
03788 char16_t *fArray;
03789 } fFields;
03790 } fUnion;
03791 };
03792
03801 U_COMMON_API UnicodeString U_EXPORT2
03802 operator+ (const UnicodeString &s1, const UnicodeString &s2);
03803
03804
03805
03806
03807
03808
03809
03810
03811
03812 inline void
03813 UnicodeString::pinIndex(int32_t& start) const
03814 {
03815
03816 if(start < 0) {
03817 start = 0;
03818 } else if(start > length()) {
03819 start = length();
03820 }
03821 }
03822
03823 inline void
03824 UnicodeString::pinIndices(int32_t& start,
03825 int32_t& _length) const
03826 {
03827
03828 int32_t len = length();
03829 if(start < 0) {
03830 start = 0;
03831 } else if(start > len) {
03832 start = len;
03833 }
03834 if(_length < 0) {
03835 _length = 0;
03836 } else if(_length > (len - start)) {
03837 _length = (len - start);
03838 }
03839 }
03840
03841 inline char16_t*
03842 UnicodeString::getArrayStart() {
03843 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
03844 fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
03845 }
03846
03847 inline const char16_t*
03848 UnicodeString::getArrayStart() const {
03849 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
03850 fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
03851 }
03852
03853
03854
03855
03856
03857 inline
03858 UnicodeString::UnicodeString() {
03859 fUnion.fStackFields.fLengthAndFlags=kShortString;
03860 }
03861
03862 inline UnicodeString::UnicodeString(const std::nullptr_t ) {
03863 fUnion.fStackFields.fLengthAndFlags=kShortString;
03864 }
03865
03866 inline UnicodeString::UnicodeString(const std::nullptr_t , int32_t ) {
03867 fUnion.fStackFields.fLengthAndFlags=kShortString;
03868 }
03869
03870 inline UnicodeString::UnicodeString(std::nullptr_t , int32_t , int32_t ) {
03871 fUnion.fStackFields.fLengthAndFlags=kShortString;
03872 }
03873
03874
03875
03876
03877 inline UBool
03878 UnicodeString::hasShortLength() const {
03879 return fUnion.fFields.fLengthAndFlags>=0;
03880 }
03881
03882 inline int32_t
03883 UnicodeString::getShortLength() const {
03884
03885
03886 return fUnion.fFields.fLengthAndFlags>>kLengthShift;
03887 }
03888
03889 inline int32_t
03890 UnicodeString::length() const {
03891 return hasShortLength() ? getShortLength() : fUnion.fFields.fLength;
03892 }
03893
03894 inline int32_t
03895 UnicodeString::getCapacity() const {
03896 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
03897 US_STACKBUF_SIZE : fUnion.fFields.fCapacity;
03898 }
03899
03900 inline int32_t
03901 UnicodeString::hashCode() const
03902 { return doHashCode(); }
03903
03904 inline UBool
03905 UnicodeString::isBogus() const
03906 { return (UBool)(fUnion.fFields.fLengthAndFlags & kIsBogus); }
03907
03908 inline UBool
03909 UnicodeString::isWritable() const
03910 { return (UBool)!(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus)); }
03911
03912 inline UBool
03913 UnicodeString::isBufferWritable() const
03914 {
03915 return (UBool)(
03916 !(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus|kBufferIsReadonly)) &&
03917 (!(fUnion.fFields.fLengthAndFlags&kRefCounted) || refCount()==1));
03918 }
03919
03920 inline const char16_t *
03921 UnicodeString::getBuffer() const {
03922 if(fUnion.fFields.fLengthAndFlags&(kIsBogus|kOpenGetBuffer)) {
03923 return nullptr;
03924 } else if(fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) {
03925 return fUnion.fStackFields.fBuffer;
03926 } else {
03927 return fUnion.fFields.fArray;
03928 }
03929 }
03930
03931
03932
03933
03934 inline int8_t
03935 UnicodeString::doCompare(int32_t start,
03936 int32_t thisLength,
03937 const UnicodeString& srcText,
03938 int32_t srcStart,
03939 int32_t srcLength) const
03940 {
03941 if(srcText.isBogus()) {
03942 return (int8_t)!isBogus();
03943 } else {
03944 srcText.pinIndices(srcStart, srcLength);
03945 return doCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
03946 }
03947 }
03948
03949 inline bool
03950 UnicodeString::operator== (const UnicodeString& text) const
03951 {
03952 if(isBogus()) {
03953 return text.isBogus();
03954 } else {
03955 int32_t len = length(), textLength = text.length();
03956 return !text.isBogus() && len == textLength && doEquals(text, len);
03957 }
03958 }
03959
03960 inline bool
03961 UnicodeString::operator!= (const UnicodeString& text) const
03962 { return (! operator==(text)); }
03963
03964 inline UBool
03965 UnicodeString::operator> (const UnicodeString& text) const
03966 { return doCompare(0, length(), text, 0, text.length()) == 1; }
03967
03968 inline UBool
03969 UnicodeString::operator< (const UnicodeString& text) const
03970 { return doCompare(0, length(), text, 0, text.length()) == -1; }
03971
03972 inline UBool
03973 UnicodeString::operator>= (const UnicodeString& text) const
03974 { return doCompare(0, length(), text, 0, text.length()) != -1; }
03975
03976 inline UBool
03977 UnicodeString::operator<= (const UnicodeString& text) const
03978 { return doCompare(0, length(), text, 0, text.length()) != 1; }
03979
03980 inline int8_t
03981 UnicodeString::compare(const UnicodeString& text) const
03982 { return doCompare(0, length(), text, 0, text.length()); }
03983
03984 inline int8_t
03985 UnicodeString::compare(int32_t start,
03986 int32_t _length,
03987 const UnicodeString& srcText) const
03988 { return doCompare(start, _length, srcText, 0, srcText.length()); }
03989
03990 inline int8_t
03991 UnicodeString::compare(ConstChar16Ptr srcChars,
03992 int32_t srcLength) const
03993 { return doCompare(0, length(), srcChars, 0, srcLength); }
03994
03995 inline int8_t
03996 UnicodeString::compare(int32_t start,
03997 int32_t _length,
03998 const UnicodeString& srcText,
03999 int32_t srcStart,
04000 int32_t srcLength) const
04001 { return doCompare(start, _length, srcText, srcStart, srcLength); }
04002
04003 inline int8_t
04004 UnicodeString::compare(int32_t start,
04005 int32_t _length,
04006 const char16_t *srcChars) const
04007 { return doCompare(start, _length, srcChars, 0, _length); }
04008
04009 inline int8_t
04010 UnicodeString::compare(int32_t start,
04011 int32_t _length,
04012 const char16_t *srcChars,
04013 int32_t srcStart,
04014 int32_t srcLength) const
04015 { return doCompare(start, _length, srcChars, srcStart, srcLength); }
04016
04017 inline int8_t
04018 UnicodeString::compareBetween(int32_t start,
04019 int32_t limit,
04020 const UnicodeString& srcText,
04021 int32_t srcStart,
04022 int32_t srcLimit) const
04023 { return doCompare(start, limit - start,
04024 srcText, srcStart, srcLimit - srcStart); }
04025
04026 inline int8_t
04027 UnicodeString::doCompareCodePointOrder(int32_t start,
04028 int32_t thisLength,
04029 const UnicodeString& srcText,
04030 int32_t srcStart,
04031 int32_t srcLength) const
04032 {
04033 if(srcText.isBogus()) {
04034 return (int8_t)!isBogus();
04035 } else {
04036 srcText.pinIndices(srcStart, srcLength);
04037 return doCompareCodePointOrder(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
04038 }
04039 }
04040
04041 inline int8_t
04042 UnicodeString::compareCodePointOrder(const UnicodeString& text) const
04043 { return doCompareCodePointOrder(0, length(), text, 0, text.length()); }
04044
04045 inline int8_t
04046 UnicodeString::compareCodePointOrder(int32_t start,
04047 int32_t _length,
04048 const UnicodeString& srcText) const
04049 { return doCompareCodePointOrder(start, _length, srcText, 0, srcText.length()); }
04050
04051 inline int8_t
04052 UnicodeString::compareCodePointOrder(ConstChar16Ptr srcChars,
04053 int32_t srcLength) const
04054 { return doCompareCodePointOrder(0, length(), srcChars, 0, srcLength); }
04055
04056 inline int8_t
04057 UnicodeString::compareCodePointOrder(int32_t start,
04058 int32_t _length,
04059 const UnicodeString& srcText,
04060 int32_t srcStart,
04061 int32_t srcLength) const
04062 { return doCompareCodePointOrder(start, _length, srcText, srcStart, srcLength); }
04063
04064 inline int8_t
04065 UnicodeString::compareCodePointOrder(int32_t start,
04066 int32_t _length,
04067 const char16_t *srcChars) const
04068 { return doCompareCodePointOrder(start, _length, srcChars, 0, _length); }
04069
04070 inline int8_t
04071 UnicodeString::compareCodePointOrder(int32_t start,
04072 int32_t _length,
04073 const char16_t *srcChars,
04074 int32_t srcStart,
04075 int32_t srcLength) const
04076 { return doCompareCodePointOrder(start, _length, srcChars, srcStart, srcLength); }
04077
04078 inline int8_t
04079 UnicodeString::compareCodePointOrderBetween(int32_t start,
04080 int32_t limit,
04081 const UnicodeString& srcText,
04082 int32_t srcStart,
04083 int32_t srcLimit) const
04084 { return doCompareCodePointOrder(start, limit - start,
04085 srcText, srcStart, srcLimit - srcStart); }
04086
04087 inline int8_t
04088 UnicodeString::doCaseCompare(int32_t start,
04089 int32_t thisLength,
04090 const UnicodeString &srcText,
04091 int32_t srcStart,
04092 int32_t srcLength,
04093 uint32_t options) const
04094 {
04095 if(srcText.isBogus()) {
04096 return (int8_t)!isBogus();
04097 } else {
04098 srcText.pinIndices(srcStart, srcLength);
04099 return doCaseCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength, options);
04100 }
04101 }
04102
04103 inline int8_t
04104 UnicodeString::caseCompare(const UnicodeString &text, uint32_t options) const {
04105 return doCaseCompare(0, length(), text, 0, text.length(), options);
04106 }
04107
04108 inline int8_t
04109 UnicodeString::caseCompare(int32_t start,
04110 int32_t _length,
04111 const UnicodeString &srcText,
04112 uint32_t options) const {
04113 return doCaseCompare(start, _length, srcText, 0, srcText.length(), options);
04114 }
04115
04116 inline int8_t
04117 UnicodeString::caseCompare(ConstChar16Ptr srcChars,
04118 int32_t srcLength,
04119 uint32_t options) const {
04120 return doCaseCompare(0, length(), srcChars, 0, srcLength, options);
04121 }
04122
04123 inline int8_t
04124 UnicodeString::caseCompare(int32_t start,
04125 int32_t _length,
04126 const UnicodeString &srcText,
04127 int32_t srcStart,
04128 int32_t srcLength,
04129 uint32_t options) const {
04130 return doCaseCompare(start, _length, srcText, srcStart, srcLength, options);
04131 }
04132
04133 inline int8_t
04134 UnicodeString::caseCompare(int32_t start,
04135 int32_t _length,
04136 const char16_t *srcChars,
04137 uint32_t options) const {
04138 return doCaseCompare(start, _length, srcChars, 0, _length, options);
04139 }
04140
04141 inline int8_t
04142 UnicodeString::caseCompare(int32_t start,
04143 int32_t _length,
04144 const char16_t *srcChars,
04145 int32_t srcStart,
04146 int32_t srcLength,
04147 uint32_t options) const {
04148 return doCaseCompare(start, _length, srcChars, srcStart, srcLength, options);
04149 }
04150
04151 inline int8_t
04152 UnicodeString::caseCompareBetween(int32_t start,
04153 int32_t limit,
04154 const UnicodeString &srcText,
04155 int32_t srcStart,
04156 int32_t srcLimit,
04157 uint32_t options) const {
04158 return doCaseCompare(start, limit - start, srcText, srcStart, srcLimit - srcStart, options);
04159 }
04160
04161 inline int32_t
04162 UnicodeString::indexOf(const UnicodeString& srcText,
04163 int32_t srcStart,
04164 int32_t srcLength,
04165 int32_t start,
04166 int32_t _length) const
04167 {
04168 if(!srcText.isBogus()) {
04169 srcText.pinIndices(srcStart, srcLength);
04170 if(srcLength > 0) {
04171 return indexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
04172 }
04173 }
04174 return -1;
04175 }
04176
04177 inline int32_t
04178 UnicodeString::indexOf(const UnicodeString& text) const
04179 { return indexOf(text, 0, text.length(), 0, length()); }
04180
04181 inline int32_t
04182 UnicodeString::indexOf(const UnicodeString& text,
04183 int32_t start) const {
04184 pinIndex(start);
04185 return indexOf(text, 0, text.length(), start, length() - start);
04186 }
04187
04188 inline int32_t
04189 UnicodeString::indexOf(const UnicodeString& text,
04190 int32_t start,
04191 int32_t _length) const
04192 { return indexOf(text, 0, text.length(), start, _length); }
04193
04194 inline int32_t
04195 UnicodeString::indexOf(const char16_t *srcChars,
04196 int32_t srcLength,
04197 int32_t start) const {
04198 pinIndex(start);
04199 return indexOf(srcChars, 0, srcLength, start, length() - start);
04200 }
04201
04202 inline int32_t
04203 UnicodeString::indexOf(ConstChar16Ptr srcChars,
04204 int32_t srcLength,
04205 int32_t start,
04206 int32_t _length) const
04207 { return indexOf(srcChars, 0, srcLength, start, _length); }
04208
04209 inline int32_t
04210 UnicodeString::indexOf(char16_t c,
04211 int32_t start,
04212 int32_t _length) const
04213 { return doIndexOf(c, start, _length); }
04214
04215 inline int32_t
04216 UnicodeString::indexOf(UChar32 c,
04217 int32_t start,
04218 int32_t _length) const
04219 { return doIndexOf(c, start, _length); }
04220
04221 inline int32_t
04222 UnicodeString::indexOf(char16_t c) const
04223 { return doIndexOf(c, 0, length()); }
04224
04225 inline int32_t
04226 UnicodeString::indexOf(UChar32 c) const
04227 { return indexOf(c, 0, length()); }
04228
04229 inline int32_t
04230 UnicodeString::indexOf(char16_t c,
04231 int32_t start) const {
04232 pinIndex(start);
04233 return doIndexOf(c, start, length() - start);
04234 }
04235
04236 inline int32_t
04237 UnicodeString::indexOf(UChar32 c,
04238 int32_t start) const {
04239 pinIndex(start);
04240 return indexOf(c, start, length() - start);
04241 }
04242
04243 inline int32_t
04244 UnicodeString::lastIndexOf(ConstChar16Ptr srcChars,
04245 int32_t srcLength,
04246 int32_t start,
04247 int32_t _length) const
04248 { return lastIndexOf(srcChars, 0, srcLength, start, _length); }
04249
04250 inline int32_t
04251 UnicodeString::lastIndexOf(const char16_t *srcChars,
04252 int32_t srcLength,
04253 int32_t start) const {
04254 pinIndex(start);
04255 return lastIndexOf(srcChars, 0, srcLength, start, length() - start);
04256 }
04257
04258 inline int32_t
04259 UnicodeString::lastIndexOf(const UnicodeString& srcText,
04260 int32_t srcStart,
04261 int32_t srcLength,
04262 int32_t start,
04263 int32_t _length) const
04264 {
04265 if(!srcText.isBogus()) {
04266 srcText.pinIndices(srcStart, srcLength);
04267 if(srcLength > 0) {
04268 return lastIndexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
04269 }
04270 }
04271 return -1;
04272 }
04273
04274 inline int32_t
04275 UnicodeString::lastIndexOf(const UnicodeString& text,
04276 int32_t start,
04277 int32_t _length) const
04278 { return lastIndexOf(text, 0, text.length(), start, _length); }
04279
04280 inline int32_t
04281 UnicodeString::lastIndexOf(const UnicodeString& text,
04282 int32_t start) const {
04283 pinIndex(start);
04284 return lastIndexOf(text, 0, text.length(), start, length() - start);
04285 }
04286
04287 inline int32_t
04288 UnicodeString::lastIndexOf(const UnicodeString& text) const
04289 { return lastIndexOf(text, 0, text.length(), 0, length()); }
04290
04291 inline int32_t
04292 UnicodeString::lastIndexOf(char16_t c,
04293 int32_t start,
04294 int32_t _length) const
04295 { return doLastIndexOf(c, start, _length); }
04296
04297 inline int32_t
04298 UnicodeString::lastIndexOf(UChar32 c,
04299 int32_t start,
04300 int32_t _length) const {
04301 return doLastIndexOf(c, start, _length);
04302 }
04303
04304 inline int32_t
04305 UnicodeString::lastIndexOf(char16_t c) const
04306 { return doLastIndexOf(c, 0, length()); }
04307
04308 inline int32_t
04309 UnicodeString::lastIndexOf(UChar32 c) const {
04310 return lastIndexOf(c, 0, length());
04311 }
04312
04313 inline int32_t
04314 UnicodeString::lastIndexOf(char16_t c,
04315 int32_t start) const {
04316 pinIndex(start);
04317 return doLastIndexOf(c, start, length() - start);
04318 }
04319
04320 inline int32_t
04321 UnicodeString::lastIndexOf(UChar32 c,
04322 int32_t start) const {
04323 pinIndex(start);
04324 return lastIndexOf(c, start, length() - start);
04325 }
04326
04327 inline UBool
04328 UnicodeString::startsWith(const UnicodeString& text) const
04329 { return compare(0, text.length(), text, 0, text.length()) == 0; }
04330
04331 inline UBool
04332 UnicodeString::startsWith(const UnicodeString& srcText,
04333 int32_t srcStart,
04334 int32_t srcLength) const
04335 { return doCompare(0, srcLength, srcText, srcStart, srcLength) == 0; }
04336
04337 inline UBool
04338 UnicodeString::startsWith(ConstChar16Ptr srcChars, int32_t srcLength) const {
04339 if(srcLength < 0) {
04340 srcLength = u_strlen(toUCharPtr(srcChars));
04341 }
04342 return doCompare(0, srcLength, srcChars, 0, srcLength) == 0;
04343 }
04344
04345 inline UBool
04346 UnicodeString::startsWith(const char16_t *srcChars, int32_t srcStart, int32_t srcLength) const {
04347 if(srcLength < 0) {
04348 srcLength = u_strlen(toUCharPtr(srcChars));
04349 }
04350 return doCompare(0, srcLength, srcChars, srcStart, srcLength) == 0;
04351 }
04352
04353 inline UBool
04354 UnicodeString::endsWith(const UnicodeString& text) const
04355 { return doCompare(length() - text.length(), text.length(),
04356 text, 0, text.length()) == 0; }
04357
04358 inline UBool
04359 UnicodeString::endsWith(const UnicodeString& srcText,
04360 int32_t srcStart,
04361 int32_t srcLength) const {
04362 srcText.pinIndices(srcStart, srcLength);
04363 return doCompare(length() - srcLength, srcLength,
04364 srcText, srcStart, srcLength) == 0;
04365 }
04366
04367 inline UBool
04368 UnicodeString::endsWith(ConstChar16Ptr srcChars,
04369 int32_t srcLength) const {
04370 if(srcLength < 0) {
04371 srcLength = u_strlen(toUCharPtr(srcChars));
04372 }
04373 return doCompare(length() - srcLength, srcLength,
04374 srcChars, 0, srcLength) == 0;
04375 }
04376
04377 inline UBool
04378 UnicodeString::endsWith(const char16_t *srcChars,
04379 int32_t srcStart,
04380 int32_t srcLength) const {
04381 if(srcLength < 0) {
04382 srcLength = u_strlen(toUCharPtr(srcChars + srcStart));
04383 }
04384 return doCompare(length() - srcLength, srcLength,
04385 srcChars, srcStart, srcLength) == 0;
04386 }
04387
04388
04389
04390
04391 inline UnicodeString&
04392 UnicodeString::replace(int32_t start,
04393 int32_t _length,
04394 const UnicodeString& srcText)
04395 { return doReplace(start, _length, srcText, 0, srcText.length()); }
04396
04397 inline UnicodeString&
04398 UnicodeString::replace(int32_t start,
04399 int32_t _length,
04400 const UnicodeString& srcText,
04401 int32_t srcStart,
04402 int32_t srcLength)
04403 { return doReplace(start, _length, srcText, srcStart, srcLength); }
04404
04405 inline UnicodeString&
04406 UnicodeString::replace(int32_t start,
04407 int32_t _length,
04408 ConstChar16Ptr srcChars,
04409 int32_t srcLength)
04410 { return doReplace(start, _length, srcChars, 0, srcLength); }
04411
04412 inline UnicodeString&
04413 UnicodeString::replace(int32_t start,
04414 int32_t _length,
04415 const char16_t *srcChars,
04416 int32_t srcStart,
04417 int32_t srcLength)
04418 { return doReplace(start, _length, srcChars, srcStart, srcLength); }
04419
04420 inline UnicodeString&
04421 UnicodeString::replace(int32_t start,
04422 int32_t _length,
04423 char16_t srcChar)
04424 { return doReplace(start, _length, &srcChar, 0, 1); }
04425
04426 inline UnicodeString&
04427 UnicodeString::replaceBetween(int32_t start,
04428 int32_t limit,
04429 const UnicodeString& srcText)
04430 { return doReplace(start, limit - start, srcText, 0, srcText.length()); }
04431
04432 inline UnicodeString&
04433 UnicodeString::replaceBetween(int32_t start,
04434 int32_t limit,
04435 const UnicodeString& srcText,
04436 int32_t srcStart,
04437 int32_t srcLimit)
04438 { return doReplace(start, limit - start, srcText, srcStart, srcLimit - srcStart); }
04439
04440 inline UnicodeString&
04441 UnicodeString::findAndReplace(const UnicodeString& oldText,
04442 const UnicodeString& newText)
04443 { return findAndReplace(0, length(), oldText, 0, oldText.length(),
04444 newText, 0, newText.length()); }
04445
04446 inline UnicodeString&
04447 UnicodeString::findAndReplace(int32_t start,
04448 int32_t _length,
04449 const UnicodeString& oldText,
04450 const UnicodeString& newText)
04451 { return findAndReplace(start, _length, oldText, 0, oldText.length(),
04452 newText, 0, newText.length()); }
04453
04454
04455
04456
04457 inline void
04458 UnicodeString::doExtract(int32_t start,
04459 int32_t _length,
04460 UnicodeString& target) const
04461 { target.replace(0, target.length(), *this, start, _length); }
04462
04463 inline void
04464 UnicodeString::extract(int32_t start,
04465 int32_t _length,
04466 Char16Ptr target,
04467 int32_t targetStart) const
04468 { doExtract(start, _length, target, targetStart); }
04469
04470 inline void
04471 UnicodeString::extract(int32_t start,
04472 int32_t _length,
04473 UnicodeString& target) const
04474 { doExtract(start, _length, target); }
04475
04476 #if !UCONFIG_NO_CONVERSION
04477
04478 inline int32_t
04479 UnicodeString::extract(int32_t start,
04480 int32_t _length,
04481 char *dst,
04482 const char *codepage) const
04483
04484 {
04485
04486 return extract(start, _length, dst, dst!=0 ? 0xffffffff : 0, codepage);
04487 }
04488
04489 #endif
04490
04491 inline void
04492 UnicodeString::extractBetween(int32_t start,
04493 int32_t limit,
04494 char16_t *dst,
04495 int32_t dstStart) const {
04496 pinIndex(start);
04497 pinIndex(limit);
04498 doExtract(start, limit - start, dst, dstStart);
04499 }
04500
04501 inline UnicodeString
04502 UnicodeString::tempSubStringBetween(int32_t start, int32_t limit) const {
04503 return tempSubString(start, limit - start);
04504 }
04505
04506 inline char16_t
04507 UnicodeString::doCharAt(int32_t offset) const
04508 {
04509 if((uint32_t)offset < (uint32_t)length()) {
04510 return getArrayStart()[offset];
04511 } else {
04512 return kInvalidUChar;
04513 }
04514 }
04515
04516 inline char16_t
04517 UnicodeString::charAt(int32_t offset) const
04518 { return doCharAt(offset); }
04519
04520 inline char16_t
04521 UnicodeString::operator[] (int32_t offset) const
04522 { return doCharAt(offset); }
04523
04524 inline UBool
04525 UnicodeString::isEmpty() const {
04526
04527 return (fUnion.fFields.fLengthAndFlags>>kLengthShift) == 0;
04528 }
04529
04530
04531
04532
04533 inline void
04534 UnicodeString::setZeroLength() {
04535 fUnion.fFields.fLengthAndFlags &= kAllStorageFlags;
04536 }
04537
04538 inline void
04539 UnicodeString::setShortLength(int32_t len) {
04540
04541 fUnion.fFields.fLengthAndFlags =
04542 (int16_t)((fUnion.fFields.fLengthAndFlags & kAllStorageFlags) | (len << kLengthShift));
04543 }
04544
04545 inline void
04546 UnicodeString::setLength(int32_t len) {
04547 if(len <= kMaxShortLength) {
04548 setShortLength(len);
04549 } else {
04550 fUnion.fFields.fLengthAndFlags |= kLengthIsLarge;
04551 fUnion.fFields.fLength = len;
04552 }
04553 }
04554
04555 inline void
04556 UnicodeString::setToEmpty() {
04557 fUnion.fFields.fLengthAndFlags = kShortString;
04558 }
04559
04560 inline void
04561 UnicodeString::setArray(char16_t *array, int32_t len, int32_t capacity) {
04562 setLength(len);
04563 fUnion.fFields.fArray = array;
04564 fUnion.fFields.fCapacity = capacity;
04565 }
04566
04567 inline UnicodeString&
04568 UnicodeString::operator= (char16_t ch)
04569 { return doReplace(0, length(), &ch, 0, 1); }
04570
04571 inline UnicodeString&
04572 UnicodeString::operator= (UChar32 ch)
04573 { return replace(0, length(), ch); }
04574
04575 inline UnicodeString&
04576 UnicodeString::setTo(const UnicodeString& srcText,
04577 int32_t srcStart,
04578 int32_t srcLength)
04579 {
04580 unBogus();
04581 return doReplace(0, length(), srcText, srcStart, srcLength);
04582 }
04583
04584 inline UnicodeString&
04585 UnicodeString::setTo(const UnicodeString& srcText,
04586 int32_t srcStart)
04587 {
04588 unBogus();
04589 srcText.pinIndex(srcStart);
04590 return doReplace(0, length(), srcText, srcStart, srcText.length() - srcStart);
04591 }
04592
04593 inline UnicodeString&
04594 UnicodeString::setTo(const UnicodeString& srcText)
04595 {
04596 return copyFrom(srcText);
04597 }
04598
04599 inline UnicodeString&
04600 UnicodeString::setTo(const char16_t *srcChars,
04601 int32_t srcLength)
04602 {
04603 unBogus();
04604 return doReplace(0, length(), srcChars, 0, srcLength);
04605 }
04606
04607 inline UnicodeString&
04608 UnicodeString::setTo(char16_t srcChar)
04609 {
04610 unBogus();
04611 return doReplace(0, length(), &srcChar, 0, 1);
04612 }
04613
04614 inline UnicodeString&
04615 UnicodeString::setTo(UChar32 srcChar)
04616 {
04617 unBogus();
04618 return replace(0, length(), srcChar);
04619 }
04620
04621 inline UnicodeString&
04622 UnicodeString::append(const UnicodeString& srcText,
04623 int32_t srcStart,
04624 int32_t srcLength)
04625 { return doAppend(srcText, srcStart, srcLength); }
04626
04627 inline UnicodeString&
04628 UnicodeString::append(const UnicodeString& srcText)
04629 { return doAppend(srcText, 0, srcText.length()); }
04630
04631 inline UnicodeString&
04632 UnicodeString::append(const char16_t *srcChars,
04633 int32_t srcStart,
04634 int32_t srcLength)
04635 { return doAppend(srcChars, srcStart, srcLength); }
04636
04637 inline UnicodeString&
04638 UnicodeString::append(ConstChar16Ptr srcChars,
04639 int32_t srcLength)
04640 { return doAppend(srcChars, 0, srcLength); }
04641
04642 inline UnicodeString&
04643 UnicodeString::append(char16_t srcChar)
04644 { return doAppend(&srcChar, 0, 1); }
04645
04646 inline UnicodeString&
04647 UnicodeString::operator+= (char16_t ch)
04648 { return doAppend(&ch, 0, 1); }
04649
04650 inline UnicodeString&
04651 UnicodeString::operator+= (UChar32 ch) {
04652 return append(ch);
04653 }
04654
04655 inline UnicodeString&
04656 UnicodeString::operator+= (const UnicodeString& srcText)
04657 { return doAppend(srcText, 0, srcText.length()); }
04658
04659 inline UnicodeString&
04660 UnicodeString::insert(int32_t start,
04661 const UnicodeString& srcText,
04662 int32_t srcStart,
04663 int32_t srcLength)
04664 { return doReplace(start, 0, srcText, srcStart, srcLength); }
04665
04666 inline UnicodeString&
04667 UnicodeString::insert(int32_t start,
04668 const UnicodeString& srcText)
04669 { return doReplace(start, 0, srcText, 0, srcText.length()); }
04670
04671 inline UnicodeString&
04672 UnicodeString::insert(int32_t start,
04673 const char16_t *srcChars,
04674 int32_t srcStart,
04675 int32_t srcLength)
04676 { return doReplace(start, 0, srcChars, srcStart, srcLength); }
04677
04678 inline UnicodeString&
04679 UnicodeString::insert(int32_t start,
04680 ConstChar16Ptr srcChars,
04681 int32_t srcLength)
04682 { return doReplace(start, 0, srcChars, 0, srcLength); }
04683
04684 inline UnicodeString&
04685 UnicodeString::insert(int32_t start,
04686 char16_t srcChar)
04687 { return doReplace(start, 0, &srcChar, 0, 1); }
04688
04689 inline UnicodeString&
04690 UnicodeString::insert(int32_t start,
04691 UChar32 srcChar)
04692 { return replace(start, 0, srcChar); }
04693
04694
04695 inline UnicodeString&
04696 UnicodeString::remove()
04697 {
04698
04699 if(isBogus()) {
04700 setToEmpty();
04701 } else {
04702 setZeroLength();
04703 }
04704 return *this;
04705 }
04706
04707 inline UnicodeString&
04708 UnicodeString::remove(int32_t start,
04709 int32_t _length)
04710 {
04711 if(start <= 0 && _length == INT32_MAX) {
04712
04713 return remove();
04714 }
04715 return doReplace(start, _length, NULL, 0, 0);
04716 }
04717
04718 inline UnicodeString&
04719 UnicodeString::removeBetween(int32_t start,
04720 int32_t limit)
04721 { return doReplace(start, limit - start, NULL, 0, 0); }
04722
04723 inline UnicodeString &
04724 UnicodeString::retainBetween(int32_t start, int32_t limit) {
04725 truncate(limit);
04726 return doReplace(0, start, NULL, 0, 0);
04727 }
04728
04729 inline UBool
04730 UnicodeString::truncate(int32_t targetLength)
04731 {
04732 if(isBogus() && targetLength == 0) {
04733
04734 unBogus();
04735 return false;
04736 } else if((uint32_t)targetLength < (uint32_t)length()) {
04737 setLength(targetLength);
04738 return true;
04739 } else {
04740 return false;
04741 }
04742 }
04743
04744 inline UnicodeString&
04745 UnicodeString::reverse()
04746 { return doReverse(0, length()); }
04747
04748 inline UnicodeString&
04749 UnicodeString::reverse(int32_t start,
04750 int32_t _length)
04751 { return doReverse(start, _length); }
04752
04753 U_NAMESPACE_END
04754
04755 #endif
04756
04757 #endif