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
00048 U_STABLE int32_t U_EXPORT2
00049 u_strlen(const UChar *s);
00050 #endif
00051
00052 U_NAMESPACE_BEGIN
00053
00054 #if !UCONFIG_NO_BREAK_ITERATION
00055 class BreakIterator;
00056 #endif
00057 class Edits;
00058
00059 U_NAMESPACE_END
00060
00061
00068 typedef int32_t U_CALLCONV
00069 UStringCaseMapper(int32_t caseLocale, uint32_t options,
00070 #if !UCONFIG_NO_BREAK_ITERATION
00071 icu::BreakIterator *iter,
00072 #endif
00073 char16_t *dest, int32_t destCapacity,
00074 const char16_t *src, int32_t srcLength,
00075 icu::Edits *edits,
00076 UErrorCode &errorCode);
00077
00078 U_NAMESPACE_BEGIN
00079
00080 class Locale;
00081 class StringCharacterIterator;
00082 class UnicodeStringAppendable;
00083
00084
00085
00096 #define US_INV icu::UnicodeString::kInvariant
00097
00115 #if !U_CHAR16_IS_TYPEDEF
00116 # define UNICODE_STRING(cs, _length) icu::UnicodeString(TRUE, u ## cs, _length)
00117 #else
00118 # define UNICODE_STRING(cs, _length) icu::UnicodeString(TRUE, (const char16_t*)u ## cs, _length)
00119 #endif
00120
00134 #define UNICODE_STRING_SIMPLE(cs) UNICODE_STRING(cs, -1)
00135
00143 #ifndef UNISTR_FROM_CHAR_EXPLICIT
00144 # if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION)
00145
00146 # define UNISTR_FROM_CHAR_EXPLICIT explicit
00147 # else
00148
00149 # define UNISTR_FROM_CHAR_EXPLICIT
00150 # endif
00151 #endif
00152
00163 #ifndef UNISTR_FROM_STRING_EXPLICIT
00164 # if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION)
00165
00166 # define UNISTR_FROM_STRING_EXPLICIT explicit
00167 # else
00168
00169 # define UNISTR_FROM_STRING_EXPLICIT
00170 # endif
00171 #endif
00172
00206 #ifndef UNISTR_OBJECT_SIZE
00207 # define UNISTR_OBJECT_SIZE 64
00208 #endif
00209
00294 class U_COMMON_API UnicodeString : public Replaceable
00295 {
00296 public:
00297
00306 enum EInvariant {
00311 kInvariant
00312 };
00313
00314
00315
00316
00317
00318
00319
00327 inline UBool operator== (const UnicodeString& text) const;
00328
00336 inline UBool operator!= (const UnicodeString& text) const;
00337
00345 inline UBool operator> (const UnicodeString& text) const;
00346
00354 inline UBool operator< (const UnicodeString& text) const;
00355
00363 inline UBool operator>= (const UnicodeString& text) const;
00364
00372 inline UBool operator<= (const UnicodeString& text) const;
00373
00385 inline int8_t compare(const UnicodeString& text) const;
00386
00402 inline int8_t compare(int32_t start,
00403 int32_t length,
00404 const UnicodeString& text) const;
00405
00423 inline int8_t compare(int32_t start,
00424 int32_t length,
00425 const UnicodeString& srcText,
00426 int32_t srcStart,
00427 int32_t srcLength) const;
00428
00441 inline int8_t compare(ConstChar16Ptr srcChars,
00442 int32_t srcLength) const;
00443
00458 inline int8_t compare(int32_t start,
00459 int32_t length,
00460 const char16_t *srcChars) const;
00461
00479 inline int8_t compare(int32_t start,
00480 int32_t length,
00481 const char16_t *srcChars,
00482 int32_t srcStart,
00483 int32_t srcLength) const;
00484
00502 inline int8_t compareBetween(int32_t start,
00503 int32_t limit,
00504 const UnicodeString& srcText,
00505 int32_t srcStart,
00506 int32_t srcLimit) const;
00507
00525 inline int8_t compareCodePointOrder(const UnicodeString& text) const;
00526
00546 inline int8_t compareCodePointOrder(int32_t start,
00547 int32_t length,
00548 const UnicodeString& srcText) const;
00549
00571 inline int8_t compareCodePointOrder(int32_t start,
00572 int32_t length,
00573 const UnicodeString& srcText,
00574 int32_t srcStart,
00575 int32_t srcLength) const;
00576
00595 inline int8_t compareCodePointOrder(ConstChar16Ptr srcChars,
00596 int32_t srcLength) const;
00597
00617 inline int8_t compareCodePointOrder(int32_t start,
00618 int32_t length,
00619 const char16_t *srcChars) const;
00620
00642 inline int8_t compareCodePointOrder(int32_t start,
00643 int32_t length,
00644 const char16_t *srcChars,
00645 int32_t srcStart,
00646 int32_t srcLength) const;
00647
00669 inline int8_t compareCodePointOrderBetween(int32_t start,
00670 int32_t limit,
00671 const UnicodeString& srcText,
00672 int32_t srcStart,
00673 int32_t srcLimit) const;
00674
00693 inline int8_t caseCompare(const UnicodeString& text, uint32_t options) const;
00694
00715 inline int8_t caseCompare(int32_t start,
00716 int32_t length,
00717 const UnicodeString& srcText,
00718 uint32_t options) const;
00719
00742 inline int8_t caseCompare(int32_t start,
00743 int32_t length,
00744 const UnicodeString& srcText,
00745 int32_t srcStart,
00746 int32_t srcLength,
00747 uint32_t options) const;
00748
00768 inline int8_t caseCompare(ConstChar16Ptr srcChars,
00769 int32_t srcLength,
00770 uint32_t options) const;
00771
00792 inline int8_t caseCompare(int32_t start,
00793 int32_t length,
00794 const char16_t *srcChars,
00795 uint32_t options) const;
00796
00819 inline int8_t caseCompare(int32_t start,
00820 int32_t length,
00821 const char16_t *srcChars,
00822 int32_t srcStart,
00823 int32_t srcLength,
00824 uint32_t options) const;
00825
00848 inline int8_t caseCompareBetween(int32_t start,
00849 int32_t limit,
00850 const UnicodeString& srcText,
00851 int32_t srcStart,
00852 int32_t srcLimit,
00853 uint32_t options) const;
00854
00862 inline UBool startsWith(const UnicodeString& text) const;
00863
00874 inline UBool startsWith(const UnicodeString& srcText,
00875 int32_t srcStart,
00876 int32_t srcLength) const;
00877
00886 inline UBool startsWith(ConstChar16Ptr srcChars,
00887 int32_t srcLength) const;
00888
00898 inline UBool startsWith(const char16_t *srcChars,
00899 int32_t srcStart,
00900 int32_t srcLength) const;
00901
00909 inline UBool endsWith(const UnicodeString& text) const;
00910
00921 inline UBool endsWith(const UnicodeString& srcText,
00922 int32_t srcStart,
00923 int32_t srcLength) const;
00924
00933 inline UBool endsWith(ConstChar16Ptr srcChars,
00934 int32_t srcLength) const;
00935
00946 inline UBool endsWith(const char16_t *srcChars,
00947 int32_t srcStart,
00948 int32_t srcLength) const;
00949
00950
00951
00952
00961 inline int32_t indexOf(const UnicodeString& text) const;
00962
00972 inline int32_t indexOf(const UnicodeString& text,
00973 int32_t start) const;
00974
00986 inline int32_t indexOf(const UnicodeString& text,
00987 int32_t start,
00988 int32_t length) const;
00989
01006 inline int32_t indexOf(const UnicodeString& srcText,
01007 int32_t srcStart,
01008 int32_t srcLength,
01009 int32_t start,
01010 int32_t length) const;
01011
01023 inline int32_t indexOf(const char16_t *srcChars,
01024 int32_t srcLength,
01025 int32_t start) const;
01026
01039 inline int32_t indexOf(ConstChar16Ptr srcChars,
01040 int32_t srcLength,
01041 int32_t start,
01042 int32_t length) const;
01043
01060 int32_t indexOf(const char16_t *srcChars,
01061 int32_t srcStart,
01062 int32_t srcLength,
01063 int32_t start,
01064 int32_t length) const;
01065
01073 inline int32_t indexOf(char16_t c) const;
01074
01083 inline int32_t indexOf(UChar32 c) const;
01084
01093 inline int32_t indexOf(char16_t c,
01094 int32_t start) const;
01095
01105 inline int32_t indexOf(UChar32 c,
01106 int32_t start) const;
01107
01118 inline int32_t indexOf(char16_t c,
01119 int32_t start,
01120 int32_t length) const;
01121
01133 inline int32_t indexOf(UChar32 c,
01134 int32_t start,
01135 int32_t length) const;
01136
01145 inline int32_t lastIndexOf(const UnicodeString& text) const;
01146
01156 inline int32_t lastIndexOf(const UnicodeString& text,
01157 int32_t start) const;
01158
01170 inline int32_t lastIndexOf(const UnicodeString& text,
01171 int32_t start,
01172 int32_t length) const;
01173
01190 inline int32_t lastIndexOf(const UnicodeString& srcText,
01191 int32_t srcStart,
01192 int32_t srcLength,
01193 int32_t start,
01194 int32_t length) const;
01195
01206 inline int32_t lastIndexOf(const char16_t *srcChars,
01207 int32_t srcLength,
01208 int32_t start) const;
01209
01222 inline int32_t lastIndexOf(ConstChar16Ptr srcChars,
01223 int32_t srcLength,
01224 int32_t start,
01225 int32_t length) const;
01226
01243 int32_t lastIndexOf(const char16_t *srcChars,
01244 int32_t srcStart,
01245 int32_t srcLength,
01246 int32_t start,
01247 int32_t length) const;
01248
01256 inline int32_t lastIndexOf(char16_t c) const;
01257
01266 inline int32_t lastIndexOf(UChar32 c) const;
01267
01276 inline int32_t lastIndexOf(char16_t c,
01277 int32_t start) const;
01278
01288 inline int32_t lastIndexOf(UChar32 c,
01289 int32_t start) const;
01290
01301 inline int32_t lastIndexOf(char16_t c,
01302 int32_t start,
01303 int32_t length) const;
01304
01316 inline int32_t lastIndexOf(UChar32 c,
01317 int32_t start,
01318 int32_t length) const;
01319
01320
01321
01322
01331 inline char16_t charAt(int32_t offset) const;
01332
01340 inline char16_t operator[] (int32_t offset) const;
01341
01353 UChar32 char32At(int32_t offset) const;
01354
01370 int32_t getChar32Start(int32_t offset) const;
01371
01388 int32_t getChar32Limit(int32_t offset) const;
01389
01440 int32_t moveIndex32(int32_t index, int32_t delta) const;
01441
01442
01443
01459 inline void extract(int32_t start,
01460 int32_t length,
01461 Char16Ptr dst,
01462 int32_t dstStart = 0) const;
01463
01485 int32_t
01486 extract(Char16Ptr dest, int32_t destCapacity,
01487 UErrorCode &errorCode) const;
01488
01498 inline void extract(int32_t start,
01499 int32_t length,
01500 UnicodeString& target) const;
01501
01513 inline void extractBetween(int32_t start,
01514 int32_t limit,
01515 char16_t *dst,
01516 int32_t dstStart = 0) const;
01517
01526 virtual void extractBetween(int32_t start,
01527 int32_t limit,
01528 UnicodeString& target) const;
01529
01551 int32_t extract(int32_t start,
01552 int32_t startLength,
01553 char *target,
01554 int32_t targetCapacity,
01555 enum EInvariant inv) const;
01556
01557 #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
01558
01578 int32_t extract(int32_t start,
01579 int32_t startLength,
01580 char *target,
01581 uint32_t targetLength) const;
01582
01583 #endif
01584
01585 #if !UCONFIG_NO_CONVERSION
01586
01612 inline int32_t extract(int32_t start,
01613 int32_t startLength,
01614 char *target,
01615 const char *codepage = 0) const;
01616
01646 int32_t extract(int32_t start,
01647 int32_t startLength,
01648 char *target,
01649 uint32_t targetLength,
01650 const char *codepage) const;
01651
01669 int32_t extract(char *dest, int32_t destCapacity,
01670 UConverter *cnv,
01671 UErrorCode &errorCode) const;
01672
01673 #endif
01674
01688 UnicodeString tempSubString(int32_t start=0, int32_t length=INT32_MAX) const;
01689
01700 inline UnicodeString tempSubStringBetween(int32_t start, int32_t limit=INT32_MAX) const;
01701
01713 void toUTF8(ByteSink &sink) const;
01714
01727 template<typename StringClass>
01728 StringClass &toUTF8String(StringClass &result) const {
01729 StringByteSink<StringClass> sbs(&result, length());
01730 toUTF8(sbs);
01731 return result;
01732 }
01733
01749 int32_t toUTF32(UChar32 *utf32, int32_t capacity, UErrorCode &errorCode) const;
01750
01751
01752
01761 inline int32_t length(void) const;
01762
01776 int32_t
01777 countChar32(int32_t start=0, int32_t length=INT32_MAX) const;
01778
01802 UBool
01803 hasMoreChar32Than(int32_t start, int32_t length, int32_t number) const;
01804
01810 inline UBool isEmpty(void) const;
01811
01821 inline int32_t getCapacity(void) const;
01822
01823
01824
01830 inline int32_t hashCode(void) const;
01831
01844 inline UBool isBogus(void) const;
01845
01846
01847
01848
01849
01850
01851
01852
01871 UnicodeString &operator=(const UnicodeString &srcText);
01872
01898 UnicodeString &fastCopyFrom(const UnicodeString &src);
01899
01908 UnicodeString &operator=(UnicodeString &&src) U_NOEXCEPT;
01909
01915 void swap(UnicodeString &other) U_NOEXCEPT;
01916
01923 friend inline void U_EXPORT2
01924 swap(UnicodeString &s1, UnicodeString &s2) U_NOEXCEPT {
01925 s1.swap(s2);
01926 }
01927
01935 inline UnicodeString& operator= (char16_t ch);
01936
01944 inline UnicodeString& operator= (UChar32 ch);
01945
01957 inline UnicodeString& setTo(const UnicodeString& srcText,
01958 int32_t srcStart);
01959
01973 inline UnicodeString& setTo(const UnicodeString& srcText,
01974 int32_t srcStart,
01975 int32_t srcLength);
01976
01985 inline UnicodeString& setTo(const UnicodeString& srcText);
01986
01995 inline UnicodeString& setTo(const char16_t *srcChars,
01996 int32_t srcLength);
01997
02006 inline UnicodeString& setTo(char16_t srcChar);
02007
02016 inline UnicodeString& setTo(UChar32 srcChar);
02017
02041 UnicodeString &setTo(UBool isTerminated,
02042 ConstChar16Ptr text,
02043 int32_t textLength);
02044
02064 UnicodeString &setTo(char16_t *buffer,
02065 int32_t buffLength,
02066 int32_t buffCapacity);
02067
02107 void setToBogus();
02108
02116 UnicodeString& setCharAt(int32_t offset,
02117 char16_t ch);
02118
02119
02120
02121
02129 inline UnicodeString& operator+= (char16_t ch);
02130
02138 inline UnicodeString& operator+= (UChar32 ch);
02139
02147 inline UnicodeString& operator+= (const UnicodeString& srcText);
02148
02163 inline UnicodeString& append(const UnicodeString& srcText,
02164 int32_t srcStart,
02165 int32_t srcLength);
02166
02174 inline UnicodeString& append(const UnicodeString& srcText);
02175
02189 inline UnicodeString& append(const char16_t *srcChars,
02190 int32_t srcStart,
02191 int32_t srcLength);
02192
02202 inline UnicodeString& append(ConstChar16Ptr srcChars,
02203 int32_t srcLength);
02204
02211 inline UnicodeString& append(char16_t srcChar);
02212
02219 UnicodeString& append(UChar32 srcChar);
02220
02221
02222
02223
02237 inline UnicodeString& insert(int32_t start,
02238 const UnicodeString& srcText,
02239 int32_t srcStart,
02240 int32_t srcLength);
02241
02250 inline UnicodeString& insert(int32_t start,
02251 const UnicodeString& srcText);
02252
02266 inline UnicodeString& insert(int32_t start,
02267 const char16_t *srcChars,
02268 int32_t srcStart,
02269 int32_t srcLength);
02270
02280 inline UnicodeString& insert(int32_t start,
02281 ConstChar16Ptr srcChars,
02282 int32_t srcLength);
02283
02292 inline UnicodeString& insert(int32_t start,
02293 char16_t srcChar);
02294
02303 inline UnicodeString& insert(int32_t start,
02304 UChar32 srcChar);
02305
02306
02307
02308
02326 inline UnicodeString& replace(int32_t start,
02327 int32_t length,
02328 const UnicodeString& srcText,
02329 int32_t srcStart,
02330 int32_t srcLength);
02331
02344 inline UnicodeString& replace(int32_t start,
02345 int32_t length,
02346 const UnicodeString& srcText);
02347
02365 inline UnicodeString& replace(int32_t start,
02366 int32_t length,
02367 const char16_t *srcChars,
02368 int32_t srcStart,
02369 int32_t srcLength);
02370
02383 inline UnicodeString& replace(int32_t start,
02384 int32_t length,
02385 ConstChar16Ptr srcChars,
02386 int32_t srcLength);
02387
02399 inline UnicodeString& replace(int32_t start,
02400 int32_t length,
02401 char16_t srcChar);
02402
02414 UnicodeString& replace(int32_t start, int32_t length, UChar32 srcChar);
02415
02425 inline UnicodeString& replaceBetween(int32_t start,
02426 int32_t limit,
02427 const UnicodeString& srcText);
02428
02443 inline UnicodeString& replaceBetween(int32_t start,
02444 int32_t limit,
02445 const UnicodeString& srcText,
02446 int32_t srcStart,
02447 int32_t srcLimit);
02448
02456 virtual void handleReplaceBetween(int32_t start,
02457 int32_t limit,
02458 const UnicodeString& text);
02459
02465 virtual UBool hasMetaData() const;
02466
02480 virtual void copy(int32_t start, int32_t limit, int32_t dest);
02481
02482
02483
02492 inline UnicodeString& findAndReplace(const UnicodeString& oldText,
02493 const UnicodeString& newText);
02494
02506 inline UnicodeString& findAndReplace(int32_t start,
02507 int32_t length,
02508 const UnicodeString& oldText,
02509 const UnicodeString& newText);
02510
02528 UnicodeString& findAndReplace(int32_t start,
02529 int32_t length,
02530 const UnicodeString& oldText,
02531 int32_t oldStart,
02532 int32_t oldLength,
02533 const UnicodeString& newText,
02534 int32_t newStart,
02535 int32_t newLength);
02536
02537
02538
02539
02548 inline UnicodeString& remove();
02549
02558 inline UnicodeString& remove(int32_t start,
02559 int32_t length = (int32_t)INT32_MAX);
02560
02569 inline UnicodeString& removeBetween(int32_t start,
02570 int32_t limit = (int32_t)INT32_MAX);
02571
02581 inline UnicodeString &retainBetween(int32_t start, int32_t limit = INT32_MAX);
02582
02583
02584
02596 UBool padLeading(int32_t targetLength,
02597 char16_t padChar = 0x0020);
02598
02610 UBool padTrailing(int32_t targetLength,
02611 char16_t padChar = 0x0020);
02612
02619 inline UBool truncate(int32_t targetLength);
02620
02626 UnicodeString& trim(void);
02627
02628
02629
02630
02636 inline UnicodeString& reverse(void);
02637
02646 inline UnicodeString& reverse(int32_t start,
02647 int32_t length);
02648
02655 UnicodeString& toUpper(void);
02656
02664 UnicodeString& toUpper(const Locale& locale);
02665
02672 UnicodeString& toLower(void);
02673
02681 UnicodeString& toLower(const Locale& locale);
02682
02683 #if !UCONFIG_NO_BREAK_ITERATION
02684
02711 UnicodeString &toTitle(BreakIterator *titleIter);
02712
02740 UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale);
02741
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;
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;
03448
03449
03450
03451
03452
03453 protected:
03458 virtual int32_t getLength() const;
03459
03465 virtual char16_t getCharAt(int32_t offset) const;
03466
03472 virtual UChar32 getChar32At(int32_t offset) const;
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 UBool
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 UBool
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