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 <cstddef>
00032 #include "unicode/utypes.h"
00033 #include "unicode/char16ptr.h"
00034 #include "unicode/rep.h"
00035 #include "unicode/std_string.h"
00036 #include "unicode/stringpiece.h"
00037 #include "unicode/bytestream.h"
00038
00039 struct UConverter;
00040
00041 #ifndef USTRING_H
00042
00045 U_STABLE int32_t U_EXPORT2
00046 u_strlen(const UChar *s);
00047 #endif
00048
00049 U_NAMESPACE_BEGIN
00050
00051 #if !UCONFIG_NO_BREAK_ITERATION
00052 class BreakIterator;
00053 #endif
00054 class Edits;
00055
00056 U_NAMESPACE_END
00057
00058
00065 typedef int32_t U_CALLCONV
00066 UStringCaseMapper(int32_t caseLocale, uint32_t options,
00067 #if !UCONFIG_NO_BREAK_ITERATION
00068 icu::BreakIterator *iter,
00069 #endif
00070 char16_t *dest, int32_t destCapacity,
00071 const char16_t *src, int32_t srcLength,
00072 icu::Edits *edits,
00073 UErrorCode &errorCode);
00074
00075 U_NAMESPACE_BEGIN
00076
00077 class Locale;
00078 class StringCharacterIterator;
00079 class UnicodeStringAppendable;
00080
00081
00082
00093 #define US_INV icu::UnicodeString::kInvariant
00094
00112 #if !U_CHAR16_IS_TYPEDEF
00113 # define UNICODE_STRING(cs, _length) icu::UnicodeString(TRUE, u ## cs, _length)
00114 #else
00115 # define UNICODE_STRING(cs, _length) icu::UnicodeString(TRUE, (const char16_t*)u ## cs, _length)
00116 #endif
00117
00131 #define UNICODE_STRING_SIMPLE(cs) UNICODE_STRING(cs, -1)
00132
00140 #ifndef UNISTR_FROM_CHAR_EXPLICIT
00141 # if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION)
00142
00143 # define UNISTR_FROM_CHAR_EXPLICIT explicit
00144 # else
00145
00146 # define UNISTR_FROM_CHAR_EXPLICIT
00147 # endif
00148 #endif
00149
00160 #ifndef UNISTR_FROM_STRING_EXPLICIT
00161 # if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION)
00162
00163 # define UNISTR_FROM_STRING_EXPLICIT explicit
00164 # else
00165
00166 # define UNISTR_FROM_STRING_EXPLICIT
00167 # endif
00168 #endif
00169
00203 #ifndef UNISTR_OBJECT_SIZE
00204 # define UNISTR_OBJECT_SIZE 64
00205 #endif
00206
00289 class U_COMMON_API UnicodeString : public Replaceable
00290 {
00291 public:
00292
00301 enum EInvariant {
00306 kInvariant
00307 };
00308
00309
00310
00311
00312
00313
00314
00322 inline UBool operator== (const UnicodeString& text) const;
00323
00331 inline UBool operator!= (const UnicodeString& text) const;
00332
00340 inline UBool operator> (const UnicodeString& text) const;
00341
00349 inline UBool operator< (const UnicodeString& text) const;
00350
00358 inline UBool operator>= (const UnicodeString& text) const;
00359
00367 inline UBool operator<= (const UnicodeString& text) const;
00368
00380 inline int8_t compare(const UnicodeString& text) const;
00381
00397 inline int8_t compare(int32_t start,
00398 int32_t length,
00399 const UnicodeString& text) const;
00400
00418 inline int8_t compare(int32_t start,
00419 int32_t length,
00420 const UnicodeString& srcText,
00421 int32_t srcStart,
00422 int32_t srcLength) const;
00423
00436 inline int8_t compare(ConstChar16Ptr srcChars,
00437 int32_t srcLength) const;
00438
00453 inline int8_t compare(int32_t start,
00454 int32_t length,
00455 const char16_t *srcChars) const;
00456
00474 inline int8_t compare(int32_t start,
00475 int32_t length,
00476 const char16_t *srcChars,
00477 int32_t srcStart,
00478 int32_t srcLength) const;
00479
00497 inline int8_t compareBetween(int32_t start,
00498 int32_t limit,
00499 const UnicodeString& srcText,
00500 int32_t srcStart,
00501 int32_t srcLimit) const;
00502
00520 inline int8_t compareCodePointOrder(const UnicodeString& text) const;
00521
00541 inline int8_t compareCodePointOrder(int32_t start,
00542 int32_t length,
00543 const UnicodeString& srcText) const;
00544
00566 inline int8_t compareCodePointOrder(int32_t start,
00567 int32_t length,
00568 const UnicodeString& srcText,
00569 int32_t srcStart,
00570 int32_t srcLength) const;
00571
00590 inline int8_t compareCodePointOrder(ConstChar16Ptr srcChars,
00591 int32_t srcLength) const;
00592
00612 inline int8_t compareCodePointOrder(int32_t start,
00613 int32_t length,
00614 const char16_t *srcChars) const;
00615
00637 inline int8_t compareCodePointOrder(int32_t start,
00638 int32_t length,
00639 const char16_t *srcChars,
00640 int32_t srcStart,
00641 int32_t srcLength) const;
00642
00664 inline int8_t compareCodePointOrderBetween(int32_t start,
00665 int32_t limit,
00666 const UnicodeString& srcText,
00667 int32_t srcStart,
00668 int32_t srcLimit) const;
00669
00688 inline int8_t caseCompare(const UnicodeString& text, uint32_t options) const;
00689
00710 inline int8_t caseCompare(int32_t start,
00711 int32_t length,
00712 const UnicodeString& srcText,
00713 uint32_t options) const;
00714
00737 inline int8_t caseCompare(int32_t start,
00738 int32_t length,
00739 const UnicodeString& srcText,
00740 int32_t srcStart,
00741 int32_t srcLength,
00742 uint32_t options) const;
00743
00763 inline int8_t caseCompare(ConstChar16Ptr srcChars,
00764 int32_t srcLength,
00765 uint32_t options) const;
00766
00787 inline int8_t caseCompare(int32_t start,
00788 int32_t length,
00789 const char16_t *srcChars,
00790 uint32_t options) const;
00791
00814 inline int8_t caseCompare(int32_t start,
00815 int32_t length,
00816 const char16_t *srcChars,
00817 int32_t srcStart,
00818 int32_t srcLength,
00819 uint32_t options) const;
00820
00843 inline int8_t caseCompareBetween(int32_t start,
00844 int32_t limit,
00845 const UnicodeString& srcText,
00846 int32_t srcStart,
00847 int32_t srcLimit,
00848 uint32_t options) const;
00849
00857 inline UBool startsWith(const UnicodeString& text) const;
00858
00869 inline UBool startsWith(const UnicodeString& srcText,
00870 int32_t srcStart,
00871 int32_t srcLength) const;
00872
00881 inline UBool startsWith(ConstChar16Ptr srcChars,
00882 int32_t srcLength) const;
00883
00893 inline UBool startsWith(const char16_t *srcChars,
00894 int32_t srcStart,
00895 int32_t srcLength) const;
00896
00904 inline UBool endsWith(const UnicodeString& text) const;
00905
00916 inline UBool endsWith(const UnicodeString& srcText,
00917 int32_t srcStart,
00918 int32_t srcLength) const;
00919
00928 inline UBool endsWith(ConstChar16Ptr srcChars,
00929 int32_t srcLength) const;
00930
00941 inline UBool endsWith(const char16_t *srcChars,
00942 int32_t srcStart,
00943 int32_t srcLength) const;
00944
00945
00946
00947
00956 inline int32_t indexOf(const UnicodeString& text) const;
00957
00967 inline int32_t indexOf(const UnicodeString& text,
00968 int32_t start) const;
00969
00981 inline int32_t indexOf(const UnicodeString& text,
00982 int32_t start,
00983 int32_t length) const;
00984
01001 inline int32_t indexOf(const UnicodeString& srcText,
01002 int32_t srcStart,
01003 int32_t srcLength,
01004 int32_t start,
01005 int32_t length) const;
01006
01018 inline int32_t indexOf(const char16_t *srcChars,
01019 int32_t srcLength,
01020 int32_t start) const;
01021
01034 inline int32_t indexOf(ConstChar16Ptr srcChars,
01035 int32_t srcLength,
01036 int32_t start,
01037 int32_t length) const;
01038
01055 int32_t indexOf(const char16_t *srcChars,
01056 int32_t srcStart,
01057 int32_t srcLength,
01058 int32_t start,
01059 int32_t length) const;
01060
01068 inline int32_t indexOf(char16_t c) const;
01069
01078 inline int32_t indexOf(UChar32 c) const;
01079
01088 inline int32_t indexOf(char16_t c,
01089 int32_t start) const;
01090
01100 inline int32_t indexOf(UChar32 c,
01101 int32_t start) const;
01102
01113 inline int32_t indexOf(char16_t c,
01114 int32_t start,
01115 int32_t length) const;
01116
01128 inline int32_t indexOf(UChar32 c,
01129 int32_t start,
01130 int32_t length) const;
01131
01140 inline int32_t lastIndexOf(const UnicodeString& text) const;
01141
01151 inline int32_t lastIndexOf(const UnicodeString& text,
01152 int32_t start) const;
01153
01165 inline int32_t lastIndexOf(const UnicodeString& text,
01166 int32_t start,
01167 int32_t length) const;
01168
01185 inline int32_t lastIndexOf(const UnicodeString& srcText,
01186 int32_t srcStart,
01187 int32_t srcLength,
01188 int32_t start,
01189 int32_t length) const;
01190
01201 inline int32_t lastIndexOf(const char16_t *srcChars,
01202 int32_t srcLength,
01203 int32_t start) const;
01204
01217 inline int32_t lastIndexOf(ConstChar16Ptr srcChars,
01218 int32_t srcLength,
01219 int32_t start,
01220 int32_t length) const;
01221
01238 int32_t lastIndexOf(const char16_t *srcChars,
01239 int32_t srcStart,
01240 int32_t srcLength,
01241 int32_t start,
01242 int32_t length) const;
01243
01251 inline int32_t lastIndexOf(char16_t c) const;
01252
01261 inline int32_t lastIndexOf(UChar32 c) const;
01262
01271 inline int32_t lastIndexOf(char16_t c,
01272 int32_t start) const;
01273
01283 inline int32_t lastIndexOf(UChar32 c,
01284 int32_t start) const;
01285
01296 inline int32_t lastIndexOf(char16_t c,
01297 int32_t start,
01298 int32_t length) const;
01299
01311 inline int32_t lastIndexOf(UChar32 c,
01312 int32_t start,
01313 int32_t length) const;
01314
01315
01316
01317
01326 inline char16_t charAt(int32_t offset) const;
01327
01335 inline char16_t operator[] (int32_t offset) const;
01336
01348 UChar32 char32At(int32_t offset) const;
01349
01365 int32_t getChar32Start(int32_t offset) const;
01366
01383 int32_t getChar32Limit(int32_t offset) const;
01384
01435 int32_t moveIndex32(int32_t index, int32_t delta) const;
01436
01437
01438
01454 inline void extract(int32_t start,
01455 int32_t length,
01456 Char16Ptr dst,
01457 int32_t dstStart = 0) const;
01458
01480 int32_t
01481 extract(Char16Ptr dest, int32_t destCapacity,
01482 UErrorCode &errorCode) const;
01483
01494 inline void extract(int32_t start,
01495 int32_t length,
01496 UnicodeString& target) const;
01497
01509 inline void extractBetween(int32_t start,
01510 int32_t limit,
01511 char16_t *dst,
01512 int32_t dstStart = 0) const;
01513
01523 virtual void extractBetween(int32_t start,
01524 int32_t limit,
01525 UnicodeString& target) const;
01526
01548 int32_t extract(int32_t start,
01549 int32_t startLength,
01550 char *target,
01551 int32_t targetCapacity,
01552 enum EInvariant inv) const;
01553
01554 #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
01555
01575 int32_t extract(int32_t start,
01576 int32_t startLength,
01577 char *target,
01578 uint32_t targetLength) const;
01579
01580 #endif
01581
01582 #if !UCONFIG_NO_CONVERSION
01583
01609 inline int32_t extract(int32_t start,
01610 int32_t startLength,
01611 char *target,
01612 const char *codepage = 0) const;
01613
01643 int32_t extract(int32_t start,
01644 int32_t startLength,
01645 char *target,
01646 uint32_t targetLength,
01647 const char *codepage) const;
01648
01666 int32_t extract(char *dest, int32_t destCapacity,
01667 UConverter *cnv,
01668 UErrorCode &errorCode) const;
01669
01670 #endif
01671
01685 UnicodeString tempSubString(int32_t start=0, int32_t length=INT32_MAX) const;
01686
01697 inline UnicodeString tempSubStringBetween(int32_t start, int32_t limit=INT32_MAX) const;
01698
01710 void toUTF8(ByteSink &sink) const;
01711
01724 template<typename StringClass>
01725 StringClass &toUTF8String(StringClass &result) const {
01726 StringByteSink<StringClass> sbs(&result, length());
01727 toUTF8(sbs);
01728 return result;
01729 }
01730
01746 int32_t toUTF32(UChar32 *utf32, int32_t capacity, UErrorCode &errorCode) const;
01747
01748
01749
01758 inline int32_t length(void) const;
01759
01773 int32_t
01774 countChar32(int32_t start=0, int32_t length=INT32_MAX) const;
01775
01799 UBool
01800 hasMoreChar32Than(int32_t start, int32_t length, int32_t number) const;
01801
01807 inline UBool isEmpty(void) const;
01808
01818 inline int32_t getCapacity(void) const;
01819
01820
01821
01827 inline int32_t hashCode(void) const;
01828
01841 inline UBool isBogus(void) const;
01842
01843
01844
01845
01846
01847
01848
01849
01868 UnicodeString &operator=(const UnicodeString &srcText);
01869
01895 UnicodeString &fastCopyFrom(const UnicodeString &src);
01896
01905 UnicodeString &operator=(UnicodeString &&src) U_NOEXCEPT {
01906 return moveFrom(src);
01907 }
01908
01909
01920 UnicodeString &moveFrom(UnicodeString &src) U_NOEXCEPT;
01921
01927 void swap(UnicodeString &other) U_NOEXCEPT;
01928
01935 friend U_COMMON_API inline void U_EXPORT2
01936 swap(UnicodeString &s1, UnicodeString &s2) U_NOEXCEPT {
01937 s1.swap(s2);
01938 }
01939
01947 inline UnicodeString& operator= (char16_t ch);
01948
01956 inline UnicodeString& operator= (UChar32 ch);
01957
01969 inline UnicodeString& setTo(const UnicodeString& srcText,
01970 int32_t srcStart);
01971
01985 inline UnicodeString& setTo(const UnicodeString& srcText,
01986 int32_t srcStart,
01987 int32_t srcLength);
01988
01997 inline UnicodeString& setTo(const UnicodeString& srcText);
01998
02007 inline UnicodeString& setTo(const char16_t *srcChars,
02008 int32_t srcLength);
02009
02018 UnicodeString& setTo(char16_t srcChar);
02019
02028 UnicodeString& setTo(UChar32 srcChar);
02029
02053 UnicodeString &setTo(UBool isTerminated,
02054 ConstChar16Ptr text,
02055 int32_t textLength);
02056
02076 UnicodeString &setTo(char16_t *buffer,
02077 int32_t buffLength,
02078 int32_t buffCapacity);
02079
02120 void setToBogus();
02121
02129 UnicodeString& setCharAt(int32_t offset,
02130 char16_t ch);
02131
02132
02133
02134
02142 inline UnicodeString& operator+= (char16_t ch);
02143
02151 inline UnicodeString& operator+= (UChar32 ch);
02152
02160 inline UnicodeString& operator+= (const UnicodeString& srcText);
02161
02176 inline UnicodeString& append(const UnicodeString& srcText,
02177 int32_t srcStart,
02178 int32_t srcLength);
02179
02187 inline UnicodeString& append(const UnicodeString& srcText);
02188
02202 inline UnicodeString& append(const char16_t *srcChars,
02203 int32_t srcStart,
02204 int32_t srcLength);
02205
02215 inline UnicodeString& append(ConstChar16Ptr srcChars,
02216 int32_t srcLength);
02217
02224 inline UnicodeString& append(char16_t srcChar);
02225
02232 UnicodeString& append(UChar32 srcChar);
02233
02234
02235
02236
02250 inline UnicodeString& insert(int32_t start,
02251 const UnicodeString& srcText,
02252 int32_t srcStart,
02253 int32_t srcLength);
02254
02263 inline UnicodeString& insert(int32_t start,
02264 const UnicodeString& srcText);
02265
02279 inline UnicodeString& insert(int32_t start,
02280 const char16_t *srcChars,
02281 int32_t srcStart,
02282 int32_t srcLength);
02283
02293 inline UnicodeString& insert(int32_t start,
02294 ConstChar16Ptr srcChars,
02295 int32_t srcLength);
02296
02305 inline UnicodeString& insert(int32_t start,
02306 char16_t srcChar);
02307
02316 inline UnicodeString& insert(int32_t start,
02317 UChar32 srcChar);
02318
02319
02320
02321
02339 UnicodeString& replace(int32_t start,
02340 int32_t length,
02341 const UnicodeString& srcText,
02342 int32_t srcStart,
02343 int32_t srcLength);
02344
02357 UnicodeString& replace(int32_t start,
02358 int32_t length,
02359 const UnicodeString& srcText);
02360
02378 UnicodeString& replace(int32_t start,
02379 int32_t length,
02380 const char16_t *srcChars,
02381 int32_t srcStart,
02382 int32_t srcLength);
02383
02396 inline UnicodeString& replace(int32_t start,
02397 int32_t length,
02398 ConstChar16Ptr srcChars,
02399 int32_t srcLength);
02400
02412 inline UnicodeString& replace(int32_t start,
02413 int32_t length,
02414 char16_t srcChar);
02415
02427 UnicodeString& replace(int32_t start, int32_t length, UChar32 srcChar);
02428
02438 inline UnicodeString& replaceBetween(int32_t start,
02439 int32_t limit,
02440 const UnicodeString& srcText);
02441
02456 inline UnicodeString& replaceBetween(int32_t start,
02457 int32_t limit,
02458 const UnicodeString& srcText,
02459 int32_t srcStart,
02460 int32_t srcLimit);
02461
02472 virtual void handleReplaceBetween(int32_t start,
02473 int32_t limit,
02474 const UnicodeString& text);
02475
02481 virtual UBool hasMetaData() const;
02482
02498 virtual void copy(int32_t start, int32_t limit, int32_t dest);
02499
02500
02501
02510 inline UnicodeString& findAndReplace(const UnicodeString& oldText,
02511 const UnicodeString& newText);
02512
02524 inline UnicodeString& findAndReplace(int32_t start,
02525 int32_t length,
02526 const UnicodeString& oldText,
02527 const UnicodeString& newText);
02528
02546 UnicodeString& findAndReplace(int32_t start,
02547 int32_t length,
02548 const UnicodeString& oldText,
02549 int32_t oldStart,
02550 int32_t oldLength,
02551 const UnicodeString& newText,
02552 int32_t newStart,
02553 int32_t newLength);
02554
02555
02556
02557
02563 inline UnicodeString& remove(void);
02564
02573 inline UnicodeString& remove(int32_t start,
02574 int32_t length = (int32_t)INT32_MAX);
02575
02584 inline UnicodeString& removeBetween(int32_t start,
02585 int32_t limit = (int32_t)INT32_MAX);
02586
02596 inline UnicodeString &retainBetween(int32_t start, int32_t limit = INT32_MAX);
02597
02598
02599
02611 UBool padLeading(int32_t targetLength,
02612 char16_t padChar = 0x0020);
02613
02625 UBool padTrailing(int32_t targetLength,
02626 char16_t padChar = 0x0020);
02627
02634 inline UBool truncate(int32_t targetLength);
02635
02641 UnicodeString& trim(void);
02642
02643
02644
02645
02651 inline UnicodeString& reverse(void);
02652
02661 inline UnicodeString& reverse(int32_t start,
02662 int32_t length);
02663
02670 UnicodeString& toUpper(void);
02671
02679 UnicodeString& toUpper(const Locale& locale);
02680
02687 UnicodeString& toLower(void);
02688
02696 UnicodeString& toLower(const Locale& locale);
02697
02698 #if !UCONFIG_NO_BREAK_ITERATION
02699
02726 UnicodeString &toTitle(BreakIterator *titleIter);
02727
02755 UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale);
02756
02788 UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale, uint32_t options);
02789
02790 #endif
02791
02805 UnicodeString &foldCase(uint32_t options=0 );
02806
02807
02808
02809
02810
02854 char16_t *getBuffer(int32_t minCapacity);
02855
02876 void releaseBuffer(int32_t newLength=-1);
02877
02908 inline const char16_t *getBuffer() const;
02909
02943 const char16_t *getTerminatedBuffer();
02944
02945
02946
02947
02948
02952 inline UnicodeString();
02953
02965 UnicodeString(int32_t capacity, UChar32 c, int32_t count);
02966
02976 UNISTR_FROM_CHAR_EXPLICIT UnicodeString(char16_t ch);
02977
02987 UNISTR_FROM_CHAR_EXPLICIT UnicodeString(UChar32 ch);
02988
02999 UNISTR_FROM_STRING_EXPLICIT UnicodeString(const char16_t *text);
03000
03001 #if !U_CHAR16_IS_TYPEDEF
03002
03012 UNISTR_FROM_STRING_EXPLICIT UnicodeString(const uint16_t *text) :
03013 UnicodeString(ConstChar16Ptr(text)) {}
03014 #endif
03015
03016 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
03017
03028 UNISTR_FROM_STRING_EXPLICIT UnicodeString(const wchar_t *text) :
03029 UnicodeString(ConstChar16Ptr(text)) {}
03030 #endif
03031
03042 UNISTR_FROM_STRING_EXPLICIT inline UnicodeString(const std::nullptr_t text);
03043
03051 UnicodeString(const char16_t *text,
03052 int32_t textLength);
03053
03054 #if !U_CHAR16_IS_TYPEDEF
03055
03062 UnicodeString(const uint16_t *text, int32_t length) :
03063 UnicodeString(ConstChar16Ptr(text), length) {}
03064 #endif
03065
03066 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
03067
03075 UnicodeString(const wchar_t *text, int32_t length) :
03076 UnicodeString(ConstChar16Ptr(text), length) {}
03077 #endif
03078
03086 inline UnicodeString(const std::nullptr_t text, int32_t length);
03087
03110 UnicodeString(UBool isTerminated,
03111 ConstChar16Ptr text,
03112 int32_t textLength);
03113
03132 UnicodeString(char16_t *buffer, int32_t buffLength, int32_t buffCapacity);
03133
03134 #if !U_CHAR16_IS_TYPEDEF
03135
03143 UnicodeString(uint16_t *buffer, int32_t buffLength, int32_t buffCapacity) :
03144 UnicodeString(Char16Ptr(buffer), buffLength, buffCapacity) {}
03145 #endif
03146
03147 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
03148
03157 UnicodeString(wchar_t *buffer, int32_t buffLength, int32_t buffCapacity) :
03158 UnicodeString(Char16Ptr(buffer), buffLength, buffCapacity) {}
03159 #endif
03160
03169 inline UnicodeString(std::nullptr_t buffer, int32_t buffLength, int32_t buffCapacity);
03170
03171 #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
03172
03192 UNISTR_FROM_STRING_EXPLICIT UnicodeString(const char *codepageData);
03193
03202 UnicodeString(const char *codepageData, int32_t dataLength);
03203
03204 #endif
03205
03206 #if !UCONFIG_NO_CONVERSION
03207
03225 UnicodeString(const char *codepageData, const char *codepage);
03226
03244 UnicodeString(const char *codepageData, int32_t dataLength, const char *codepage);
03245
03267 UnicodeString(
03268 const char *src, int32_t srcLength,
03269 UConverter *cnv,
03270 UErrorCode &errorCode);
03271
03272 #endif
03273
03298 UnicodeString(const char *src, int32_t length, enum EInvariant inv);
03299
03300
03317 UnicodeString(const UnicodeString& that);
03318
03325 UnicodeString(UnicodeString &&src) U_NOEXCEPT;
03326
03333 UnicodeString(const UnicodeString& src, int32_t srcStart);
03334
03342 UnicodeString(const UnicodeString& src, int32_t srcStart, int32_t srcLength);
03343
03360 virtual Replaceable *clone() const;
03361
03365 virtual ~UnicodeString();
03366
03380 static UnicodeString fromUTF8(StringPiece utf8);
03381
03393 static UnicodeString fromUTF32(const UChar32 *utf32, int32_t length);
03394
03395
03396
03431 UnicodeString unescape() const;
03432
03452 UChar32 unescapeAt(int32_t &offset) const;
03453
03459 static UClassID U_EXPORT2 getStaticClassID();
03460
03466 virtual UClassID getDynamicClassID() const;
03467
03468
03469
03470
03471
03472 protected:
03477 virtual int32_t getLength() const;
03478
03484 virtual char16_t getCharAt(int32_t offset) const;
03485
03491 virtual UChar32 getChar32At(int32_t offset) const;
03492
03493 private:
03494
03495 UnicodeString &setToUTF8(StringPiece utf8);
03496
03497
03498
03499
03500
03501 int32_t
03502 toUTF8(int32_t start, int32_t len,
03503 char *target, int32_t capacity) const;
03504
03509 UBool doEquals(const UnicodeString &text, int32_t len) const;
03510
03511 inline int8_t
03512 doCompare(int32_t start,
03513 int32_t length,
03514 const UnicodeString& srcText,
03515 int32_t srcStart,
03516 int32_t srcLength) const;
03517
03518 int8_t doCompare(int32_t start,
03519 int32_t length,
03520 const char16_t *srcChars,
03521 int32_t srcStart,
03522 int32_t srcLength) const;
03523
03524 inline int8_t
03525 doCompareCodePointOrder(int32_t start,
03526 int32_t length,
03527 const UnicodeString& srcText,
03528 int32_t srcStart,
03529 int32_t srcLength) const;
03530
03531 int8_t doCompareCodePointOrder(int32_t start,
03532 int32_t length,
03533 const char16_t *srcChars,
03534 int32_t srcStart,
03535 int32_t srcLength) const;
03536
03537 inline int8_t
03538 doCaseCompare(int32_t start,
03539 int32_t length,
03540 const UnicodeString &srcText,
03541 int32_t srcStart,
03542 int32_t srcLength,
03543 uint32_t options) const;
03544
03545 int8_t
03546 doCaseCompare(int32_t start,
03547 int32_t length,
03548 const char16_t *srcChars,
03549 int32_t srcStart,
03550 int32_t srcLength,
03551 uint32_t options) const;
03552
03553 int32_t doIndexOf(char16_t c,
03554 int32_t start,
03555 int32_t length) const;
03556
03557 int32_t doIndexOf(UChar32 c,
03558 int32_t start,
03559 int32_t length) const;
03560
03561 int32_t doLastIndexOf(char16_t c,
03562 int32_t start,
03563 int32_t length) const;
03564
03565 int32_t doLastIndexOf(UChar32 c,
03566 int32_t start,
03567 int32_t length) const;
03568
03569 void doExtract(int32_t start,
03570 int32_t length,
03571 char16_t *dst,
03572 int32_t dstStart) const;
03573
03574 inline void doExtract(int32_t start,
03575 int32_t length,
03576 UnicodeString& target) const;
03577
03578 inline char16_t doCharAt(int32_t offset) const;
03579
03580 UnicodeString& doReplace(int32_t start,
03581 int32_t length,
03582 const UnicodeString& srcText,
03583 int32_t srcStart,
03584 int32_t srcLength);
03585
03586 UnicodeString& doReplace(int32_t start,
03587 int32_t length,
03588 const char16_t *srcChars,
03589 int32_t srcStart,
03590 int32_t srcLength);
03591
03592 UnicodeString& doAppend(const UnicodeString& src, int32_t srcStart, int32_t srcLength);
03593 UnicodeString& doAppend(const char16_t *srcChars, int32_t srcStart, int32_t srcLength);
03594
03595 UnicodeString& doReverse(int32_t start,
03596 int32_t length);
03597
03598
03599 int32_t doHashCode(void) const;
03600
03601
03602
03603 inline char16_t* getArrayStart(void);
03604 inline const char16_t* getArrayStart(void) const;
03605
03606 inline UBool hasShortLength() const;
03607 inline int32_t getShortLength() const;
03608
03609
03610
03611 inline UBool isWritable() const;
03612
03613
03614 inline UBool isBufferWritable() const;
03615
03616
03617 inline void setZeroLength();
03618 inline void setShortLength(int32_t len);
03619 inline void setLength(int32_t len);
03620 inline void setToEmpty();
03621 inline void setArray(char16_t *array, int32_t len, int32_t capacity);
03622
03623
03624
03625
03626
03627
03628 UBool allocate(int32_t capacity);
03629
03630
03631 void releaseArray(void);
03632
03633
03634 void unBogus();
03635
03636
03637 UnicodeString ©From(const UnicodeString &src, UBool fastCopy=FALSE);
03638
03639
03640 void copyFieldsFrom(UnicodeString &src, UBool setSrcToBogus) U_NOEXCEPT;
03641
03642
03643 inline void pinIndex(int32_t& start) const;
03644 inline void pinIndices(int32_t& start,
03645 int32_t& length) const;
03646
03647 #if !UCONFIG_NO_CONVERSION
03648
03649
03650 int32_t doExtract(int32_t start, int32_t length,
03651 char *dest, int32_t destCapacity,
03652 UConverter *cnv,
03653 UErrorCode &errorCode) const;
03654
03655
03656
03657
03658
03659
03660
03661
03662
03663
03664
03665 void doCodepageCreate(const char *codepageData,
03666 int32_t dataLength,
03667 const char *codepage);
03668
03669
03670
03671
03672
03673 void
03674 doCodepageCreate(const char *codepageData,
03675 int32_t dataLength,
03676 UConverter *converter,
03677 UErrorCode &status);
03678
03679 #endif
03680
03681
03682
03683
03684
03685
03686
03687
03688
03689
03690
03691
03692 UBool cloneArrayIfNeeded(int32_t newCapacity = -1,
03693 int32_t growCapacity = -1,
03694 UBool doCopyArray = TRUE,
03695 int32_t **pBufferToDelete = 0,
03696 UBool forceClone = FALSE);
03697
03703 UnicodeString &
03704 caseMap(int32_t caseLocale, uint32_t options,
03705 #if !UCONFIG_NO_BREAK_ITERATION
03706 BreakIterator *iter,
03707 #endif
03708 UStringCaseMapper *stringCaseMapper);
03709
03710
03711 void addRef(void);
03712 int32_t removeRef(void);
03713 int32_t refCount(void) const;
03714
03715
03716 enum {
03722 US_STACKBUF_SIZE=(int32_t)(UNISTR_OBJECT_SIZE-sizeof(void *)-2)/U_SIZEOF_UCHAR,
03723 kInvalidUChar=0xffff,
03724 kInvalidHashCode=0,
03725 kEmptyHashCode=1,
03726
03727
03728 kIsBogus=1,
03729 kUsingStackBuffer=2,
03730 kRefCounted=4,
03731 kBufferIsReadonly=8,
03732 kOpenGetBuffer=16,
03733
03734 kAllStorageFlags=0x1f,
03735
03736 kLengthShift=5,
03737 kLength1=1<<kLengthShift,
03738 kMaxShortLength=0x3ff,
03739 kLengthIsLarge=0xffe0,
03740
03741
03742 kShortString=kUsingStackBuffer,
03743 kLongString=kRefCounted,
03744 kReadonlyAlias=kBufferIsReadonly,
03745 kWritableAlias=0
03746 };
03747
03748 friend class UnicodeStringAppendable;
03749
03750 union StackBufferOrFields;
03751 friend union StackBufferOrFields;
03752
03753
03754
03755
03756
03757
03758
03759
03760
03761
03762
03763
03764
03765
03766
03767
03768
03769
03770
03771
03772
03773
03774
03775
03776
03777
03778
03779
03780
03781
03782
03783
03784
03785
03786
03787
03788
03789
03790
03791
03792
03793
03794 union StackBufferOrFields {
03795
03796
03797 struct {
03798 int16_t fLengthAndFlags;
03799 char16_t fBuffer[US_STACKBUF_SIZE];
03800 } fStackFields;
03801 struct {
03802 int16_t fLengthAndFlags;
03803 int32_t fLength;
03804 int32_t fCapacity;
03805
03806
03807 char16_t *fArray;
03808 } fFields;
03809 } fUnion;
03810 };
03811
03820 U_COMMON_API UnicodeString U_EXPORT2
03821 operator+ (const UnicodeString &s1, const UnicodeString &s2);
03822
03823
03824
03825
03826
03827
03828
03829
03830
03831 inline void
03832 UnicodeString::pinIndex(int32_t& start) const
03833 {
03834
03835 if(start < 0) {
03836 start = 0;
03837 } else if(start > length()) {
03838 start = length();
03839 }
03840 }
03841
03842 inline void
03843 UnicodeString::pinIndices(int32_t& start,
03844 int32_t& _length) const
03845 {
03846
03847 int32_t len = length();
03848 if(start < 0) {
03849 start = 0;
03850 } else if(start > len) {
03851 start = len;
03852 }
03853 if(_length < 0) {
03854 _length = 0;
03855 } else if(_length > (len - start)) {
03856 _length = (len - start);
03857 }
03858 }
03859
03860 inline char16_t*
03861 UnicodeString::getArrayStart() {
03862 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
03863 fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
03864 }
03865
03866 inline const char16_t*
03867 UnicodeString::getArrayStart() const {
03868 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
03869 fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
03870 }
03871
03872
03873
03874
03875
03876 inline
03877 UnicodeString::UnicodeString() {
03878 fUnion.fStackFields.fLengthAndFlags=kShortString;
03879 }
03880
03881 inline UnicodeString::UnicodeString(const std::nullptr_t ) {
03882 fUnion.fStackFields.fLengthAndFlags=kShortString;
03883 }
03884
03885 inline UnicodeString::UnicodeString(const std::nullptr_t , int32_t ) {
03886 fUnion.fStackFields.fLengthAndFlags=kShortString;
03887 }
03888
03889 inline UnicodeString::UnicodeString(std::nullptr_t , int32_t , int32_t ) {
03890 fUnion.fStackFields.fLengthAndFlags=kShortString;
03891 }
03892
03893
03894
03895
03896 inline UBool
03897 UnicodeString::hasShortLength() const {
03898 return fUnion.fFields.fLengthAndFlags>=0;
03899 }
03900
03901 inline int32_t
03902 UnicodeString::getShortLength() const {
03903
03904
03905 return fUnion.fFields.fLengthAndFlags>>kLengthShift;
03906 }
03907
03908 inline int32_t
03909 UnicodeString::length() const {
03910 return hasShortLength() ? getShortLength() : fUnion.fFields.fLength;
03911 }
03912
03913 inline int32_t
03914 UnicodeString::getCapacity() const {
03915 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
03916 US_STACKBUF_SIZE : fUnion.fFields.fCapacity;
03917 }
03918
03919 inline int32_t
03920 UnicodeString::hashCode() const
03921 { return doHashCode(); }
03922
03923 inline UBool
03924 UnicodeString::isBogus() const
03925 { return (UBool)(fUnion.fFields.fLengthAndFlags & kIsBogus); }
03926
03927 inline UBool
03928 UnicodeString::isWritable() const
03929 { return (UBool)!(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus)); }
03930
03931 inline UBool
03932 UnicodeString::isBufferWritable() const
03933 {
03934 return (UBool)(
03935 !(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus|kBufferIsReadonly)) &&
03936 (!(fUnion.fFields.fLengthAndFlags&kRefCounted) || refCount()==1));
03937 }
03938
03939 inline const char16_t *
03940 UnicodeString::getBuffer() const {
03941 if(fUnion.fFields.fLengthAndFlags&(kIsBogus|kOpenGetBuffer)) {
03942 return nullptr;
03943 } else if(fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) {
03944 return fUnion.fStackFields.fBuffer;
03945 } else {
03946 return fUnion.fFields.fArray;
03947 }
03948 }
03949
03950
03951
03952
03953 inline int8_t
03954 UnicodeString::doCompare(int32_t start,
03955 int32_t thisLength,
03956 const UnicodeString& srcText,
03957 int32_t srcStart,
03958 int32_t srcLength) const
03959 {
03960 if(srcText.isBogus()) {
03961 return (int8_t)!isBogus();
03962 } else {
03963 srcText.pinIndices(srcStart, srcLength);
03964 return doCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
03965 }
03966 }
03967
03968 inline UBool
03969 UnicodeString::operator== (const UnicodeString& text) const
03970 {
03971 if(isBogus()) {
03972 return text.isBogus();
03973 } else {
03974 int32_t len = length(), textLength = text.length();
03975 return !text.isBogus() && len == textLength && doEquals(text, len);
03976 }
03977 }
03978
03979 inline UBool
03980 UnicodeString::operator!= (const UnicodeString& text) const
03981 { return (! operator==(text)); }
03982
03983 inline UBool
03984 UnicodeString::operator> (const UnicodeString& text) const
03985 { return doCompare(0, length(), text, 0, text.length()) == 1; }
03986
03987 inline UBool
03988 UnicodeString::operator< (const UnicodeString& text) const
03989 { return doCompare(0, length(), text, 0, text.length()) == -1; }
03990
03991 inline UBool
03992 UnicodeString::operator>= (const UnicodeString& text) const
03993 { return doCompare(0, length(), text, 0, text.length()) != -1; }
03994
03995 inline UBool
03996 UnicodeString::operator<= (const UnicodeString& text) const
03997 { return doCompare(0, length(), text, 0, text.length()) != 1; }
03998
03999 inline int8_t
04000 UnicodeString::compare(const UnicodeString& text) const
04001 { return doCompare(0, length(), text, 0, text.length()); }
04002
04003 inline int8_t
04004 UnicodeString::compare(int32_t start,
04005 int32_t _length,
04006 const UnicodeString& srcText) const
04007 { return doCompare(start, _length, srcText, 0, srcText.length()); }
04008
04009 inline int8_t
04010 UnicodeString::compare(ConstChar16Ptr srcChars,
04011 int32_t srcLength) const
04012 { return doCompare(0, length(), srcChars, 0, srcLength); }
04013
04014 inline int8_t
04015 UnicodeString::compare(int32_t start,
04016 int32_t _length,
04017 const UnicodeString& srcText,
04018 int32_t srcStart,
04019 int32_t srcLength) const
04020 { return doCompare(start, _length, srcText, srcStart, srcLength); }
04021
04022 inline int8_t
04023 UnicodeString::compare(int32_t start,
04024 int32_t _length,
04025 const char16_t *srcChars) const
04026 { return doCompare(start, _length, srcChars, 0, _length); }
04027
04028 inline int8_t
04029 UnicodeString::compare(int32_t start,
04030 int32_t _length,
04031 const char16_t *srcChars,
04032 int32_t srcStart,
04033 int32_t srcLength) const
04034 { return doCompare(start, _length, srcChars, srcStart, srcLength); }
04035
04036 inline int8_t
04037 UnicodeString::compareBetween(int32_t start,
04038 int32_t limit,
04039 const UnicodeString& srcText,
04040 int32_t srcStart,
04041 int32_t srcLimit) const
04042 { return doCompare(start, limit - start,
04043 srcText, srcStart, srcLimit - srcStart); }
04044
04045 inline int8_t
04046 UnicodeString::doCompareCodePointOrder(int32_t start,
04047 int32_t thisLength,
04048 const UnicodeString& srcText,
04049 int32_t srcStart,
04050 int32_t srcLength) const
04051 {
04052 if(srcText.isBogus()) {
04053 return (int8_t)!isBogus();
04054 } else {
04055 srcText.pinIndices(srcStart, srcLength);
04056 return doCompareCodePointOrder(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
04057 }
04058 }
04059
04060 inline int8_t
04061 UnicodeString::compareCodePointOrder(const UnicodeString& text) const
04062 { return doCompareCodePointOrder(0, length(), text, 0, text.length()); }
04063
04064 inline int8_t
04065 UnicodeString::compareCodePointOrder(int32_t start,
04066 int32_t _length,
04067 const UnicodeString& srcText) const
04068 { return doCompareCodePointOrder(start, _length, srcText, 0, srcText.length()); }
04069
04070 inline int8_t
04071 UnicodeString::compareCodePointOrder(ConstChar16Ptr srcChars,
04072 int32_t srcLength) const
04073 { return doCompareCodePointOrder(0, length(), srcChars, 0, srcLength); }
04074
04075 inline int8_t
04076 UnicodeString::compareCodePointOrder(int32_t start,
04077 int32_t _length,
04078 const UnicodeString& srcText,
04079 int32_t srcStart,
04080 int32_t srcLength) const
04081 { return doCompareCodePointOrder(start, _length, srcText, srcStart, srcLength); }
04082
04083 inline int8_t
04084 UnicodeString::compareCodePointOrder(int32_t start,
04085 int32_t _length,
04086 const char16_t *srcChars) const
04087 { return doCompareCodePointOrder(start, _length, srcChars, 0, _length); }
04088
04089 inline int8_t
04090 UnicodeString::compareCodePointOrder(int32_t start,
04091 int32_t _length,
04092 const char16_t *srcChars,
04093 int32_t srcStart,
04094 int32_t srcLength) const
04095 { return doCompareCodePointOrder(start, _length, srcChars, srcStart, srcLength); }
04096
04097 inline int8_t
04098 UnicodeString::compareCodePointOrderBetween(int32_t start,
04099 int32_t limit,
04100 const UnicodeString& srcText,
04101 int32_t srcStart,
04102 int32_t srcLimit) const
04103 { return doCompareCodePointOrder(start, limit - start,
04104 srcText, srcStart, srcLimit - srcStart); }
04105
04106 inline int8_t
04107 UnicodeString::doCaseCompare(int32_t start,
04108 int32_t thisLength,
04109 const UnicodeString &srcText,
04110 int32_t srcStart,
04111 int32_t srcLength,
04112 uint32_t options) const
04113 {
04114 if(srcText.isBogus()) {
04115 return (int8_t)!isBogus();
04116 } else {
04117 srcText.pinIndices(srcStart, srcLength);
04118 return doCaseCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength, options);
04119 }
04120 }
04121
04122 inline int8_t
04123 UnicodeString::caseCompare(const UnicodeString &text, uint32_t options) const {
04124 return doCaseCompare(0, length(), text, 0, text.length(), options);
04125 }
04126
04127 inline int8_t
04128 UnicodeString::caseCompare(int32_t start,
04129 int32_t _length,
04130 const UnicodeString &srcText,
04131 uint32_t options) const {
04132 return doCaseCompare(start, _length, srcText, 0, srcText.length(), options);
04133 }
04134
04135 inline int8_t
04136 UnicodeString::caseCompare(ConstChar16Ptr srcChars,
04137 int32_t srcLength,
04138 uint32_t options) const {
04139 return doCaseCompare(0, length(), srcChars, 0, srcLength, options);
04140 }
04141
04142 inline int8_t
04143 UnicodeString::caseCompare(int32_t start,
04144 int32_t _length,
04145 const UnicodeString &srcText,
04146 int32_t srcStart,
04147 int32_t srcLength,
04148 uint32_t options) const {
04149 return doCaseCompare(start, _length, srcText, srcStart, srcLength, options);
04150 }
04151
04152 inline int8_t
04153 UnicodeString::caseCompare(int32_t start,
04154 int32_t _length,
04155 const char16_t *srcChars,
04156 uint32_t options) const {
04157 return doCaseCompare(start, _length, srcChars, 0, _length, options);
04158 }
04159
04160 inline int8_t
04161 UnicodeString::caseCompare(int32_t start,
04162 int32_t _length,
04163 const char16_t *srcChars,
04164 int32_t srcStart,
04165 int32_t srcLength,
04166 uint32_t options) const {
04167 return doCaseCompare(start, _length, srcChars, srcStart, srcLength, options);
04168 }
04169
04170 inline int8_t
04171 UnicodeString::caseCompareBetween(int32_t start,
04172 int32_t limit,
04173 const UnicodeString &srcText,
04174 int32_t srcStart,
04175 int32_t srcLimit,
04176 uint32_t options) const {
04177 return doCaseCompare(start, limit - start, srcText, srcStart, srcLimit - srcStart, options);
04178 }
04179
04180 inline int32_t
04181 UnicodeString::indexOf(const UnicodeString& srcText,
04182 int32_t srcStart,
04183 int32_t srcLength,
04184 int32_t start,
04185 int32_t _length) const
04186 {
04187 if(!srcText.isBogus()) {
04188 srcText.pinIndices(srcStart, srcLength);
04189 if(srcLength > 0) {
04190 return indexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
04191 }
04192 }
04193 return -1;
04194 }
04195
04196 inline int32_t
04197 UnicodeString::indexOf(const UnicodeString& text) const
04198 { return indexOf(text, 0, text.length(), 0, length()); }
04199
04200 inline int32_t
04201 UnicodeString::indexOf(const UnicodeString& text,
04202 int32_t start) const {
04203 pinIndex(start);
04204 return indexOf(text, 0, text.length(), start, length() - start);
04205 }
04206
04207 inline int32_t
04208 UnicodeString::indexOf(const UnicodeString& text,
04209 int32_t start,
04210 int32_t _length) const
04211 { return indexOf(text, 0, text.length(), start, _length); }
04212
04213 inline int32_t
04214 UnicodeString::indexOf(const char16_t *srcChars,
04215 int32_t srcLength,
04216 int32_t start) const {
04217 pinIndex(start);
04218 return indexOf(srcChars, 0, srcLength, start, length() - start);
04219 }
04220
04221 inline int32_t
04222 UnicodeString::indexOf(ConstChar16Ptr srcChars,
04223 int32_t srcLength,
04224 int32_t start,
04225 int32_t _length) const
04226 { return indexOf(srcChars, 0, srcLength, start, _length); }
04227
04228 inline int32_t
04229 UnicodeString::indexOf(char16_t c,
04230 int32_t start,
04231 int32_t _length) const
04232 { return doIndexOf(c, start, _length); }
04233
04234 inline int32_t
04235 UnicodeString::indexOf(UChar32 c,
04236 int32_t start,
04237 int32_t _length) const
04238 { return doIndexOf(c, start, _length); }
04239
04240 inline int32_t
04241 UnicodeString::indexOf(char16_t c) const
04242 { return doIndexOf(c, 0, length()); }
04243
04244 inline int32_t
04245 UnicodeString::indexOf(UChar32 c) const
04246 { return indexOf(c, 0, length()); }
04247
04248 inline int32_t
04249 UnicodeString::indexOf(char16_t c,
04250 int32_t start) const {
04251 pinIndex(start);
04252 return doIndexOf(c, start, length() - start);
04253 }
04254
04255 inline int32_t
04256 UnicodeString::indexOf(UChar32 c,
04257 int32_t start) const {
04258 pinIndex(start);
04259 return indexOf(c, start, length() - start);
04260 }
04261
04262 inline int32_t
04263 UnicodeString::lastIndexOf(ConstChar16Ptr srcChars,
04264 int32_t srcLength,
04265 int32_t start,
04266 int32_t _length) const
04267 { return lastIndexOf(srcChars, 0, srcLength, start, _length); }
04268
04269 inline int32_t
04270 UnicodeString::lastIndexOf(const char16_t *srcChars,
04271 int32_t srcLength,
04272 int32_t start) const {
04273 pinIndex(start);
04274 return lastIndexOf(srcChars, 0, srcLength, start, length() - start);
04275 }
04276
04277 inline int32_t
04278 UnicodeString::lastIndexOf(const UnicodeString& srcText,
04279 int32_t srcStart,
04280 int32_t srcLength,
04281 int32_t start,
04282 int32_t _length) const
04283 {
04284 if(!srcText.isBogus()) {
04285 srcText.pinIndices(srcStart, srcLength);
04286 if(srcLength > 0) {
04287 return lastIndexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
04288 }
04289 }
04290 return -1;
04291 }
04292
04293 inline int32_t
04294 UnicodeString::lastIndexOf(const UnicodeString& text,
04295 int32_t start,
04296 int32_t _length) const
04297 { return lastIndexOf(text, 0, text.length(), start, _length); }
04298
04299 inline int32_t
04300 UnicodeString::lastIndexOf(const UnicodeString& text,
04301 int32_t start) const {
04302 pinIndex(start);
04303 return lastIndexOf(text, 0, text.length(), start, length() - start);
04304 }
04305
04306 inline int32_t
04307 UnicodeString::lastIndexOf(const UnicodeString& text) const
04308 { return lastIndexOf(text, 0, text.length(), 0, length()); }
04309
04310 inline int32_t
04311 UnicodeString::lastIndexOf(char16_t c,
04312 int32_t start,
04313 int32_t _length) const
04314 { return doLastIndexOf(c, start, _length); }
04315
04316 inline int32_t
04317 UnicodeString::lastIndexOf(UChar32 c,
04318 int32_t start,
04319 int32_t _length) const {
04320 return doLastIndexOf(c, start, _length);
04321 }
04322
04323 inline int32_t
04324 UnicodeString::lastIndexOf(char16_t c) const
04325 { return doLastIndexOf(c, 0, length()); }
04326
04327 inline int32_t
04328 UnicodeString::lastIndexOf(UChar32 c) const {
04329 return lastIndexOf(c, 0, length());
04330 }
04331
04332 inline int32_t
04333 UnicodeString::lastIndexOf(char16_t c,
04334 int32_t start) const {
04335 pinIndex(start);
04336 return doLastIndexOf(c, start, length() - start);
04337 }
04338
04339 inline int32_t
04340 UnicodeString::lastIndexOf(UChar32 c,
04341 int32_t start) const {
04342 pinIndex(start);
04343 return lastIndexOf(c, start, length() - start);
04344 }
04345
04346 inline UBool
04347 UnicodeString::startsWith(const UnicodeString& text) const
04348 { return compare(0, text.length(), text, 0, text.length()) == 0; }
04349
04350 inline UBool
04351 UnicodeString::startsWith(const UnicodeString& srcText,
04352 int32_t srcStart,
04353 int32_t srcLength) const
04354 { return doCompare(0, srcLength, srcText, srcStart, srcLength) == 0; }
04355
04356 inline UBool
04357 UnicodeString::startsWith(ConstChar16Ptr srcChars, int32_t srcLength) const {
04358 if(srcLength < 0) {
04359 srcLength = u_strlen(toUCharPtr(srcChars));
04360 }
04361 return doCompare(0, srcLength, srcChars, 0, srcLength) == 0;
04362 }
04363
04364 inline UBool
04365 UnicodeString::startsWith(const char16_t *srcChars, int32_t srcStart, int32_t srcLength) const {
04366 if(srcLength < 0) {
04367 srcLength = u_strlen(toUCharPtr(srcChars));
04368 }
04369 return doCompare(0, srcLength, srcChars, srcStart, srcLength) == 0;
04370 }
04371
04372 inline UBool
04373 UnicodeString::endsWith(const UnicodeString& text) const
04374 { return doCompare(length() - text.length(), text.length(),
04375 text, 0, text.length()) == 0; }
04376
04377 inline UBool
04378 UnicodeString::endsWith(const UnicodeString& srcText,
04379 int32_t srcStart,
04380 int32_t srcLength) const {
04381 srcText.pinIndices(srcStart, srcLength);
04382 return doCompare(length() - srcLength, srcLength,
04383 srcText, srcStart, srcLength) == 0;
04384 }
04385
04386 inline UBool
04387 UnicodeString::endsWith(ConstChar16Ptr srcChars,
04388 int32_t srcLength) const {
04389 if(srcLength < 0) {
04390 srcLength = u_strlen(toUCharPtr(srcChars));
04391 }
04392 return doCompare(length() - srcLength, srcLength,
04393 srcChars, 0, srcLength) == 0;
04394 }
04395
04396 inline UBool
04397 UnicodeString::endsWith(const char16_t *srcChars,
04398 int32_t srcStart,
04399 int32_t srcLength) const {
04400 if(srcLength < 0) {
04401 srcLength = u_strlen(toUCharPtr(srcChars + srcStart));
04402 }
04403 return doCompare(length() - srcLength, srcLength,
04404 srcChars, srcStart, srcLength) == 0;
04405 }
04406
04407
04408
04409
04410 inline UnicodeString&
04411 UnicodeString::replace(int32_t start,
04412 int32_t _length,
04413 const UnicodeString& srcText)
04414 { return doReplace(start, _length, srcText, 0, srcText.length()); }
04415
04416 inline UnicodeString&
04417 UnicodeString::replace(int32_t start,
04418 int32_t _length,
04419 const UnicodeString& srcText,
04420 int32_t srcStart,
04421 int32_t srcLength)
04422 { return doReplace(start, _length, srcText, srcStart, srcLength); }
04423
04424 inline UnicodeString&
04425 UnicodeString::replace(int32_t start,
04426 int32_t _length,
04427 ConstChar16Ptr srcChars,
04428 int32_t srcLength)
04429 { return doReplace(start, _length, srcChars, 0, srcLength); }
04430
04431 inline UnicodeString&
04432 UnicodeString::replace(int32_t start,
04433 int32_t _length,
04434 const char16_t *srcChars,
04435 int32_t srcStart,
04436 int32_t srcLength)
04437 { return doReplace(start, _length, srcChars, srcStart, srcLength); }
04438
04439 inline UnicodeString&
04440 UnicodeString::replace(int32_t start,
04441 int32_t _length,
04442 char16_t srcChar)
04443 { return doReplace(start, _length, &srcChar, 0, 1); }
04444
04445 inline UnicodeString&
04446 UnicodeString::replaceBetween(int32_t start,
04447 int32_t limit,
04448 const UnicodeString& srcText)
04449 { return doReplace(start, limit - start, srcText, 0, srcText.length()); }
04450
04451 inline UnicodeString&
04452 UnicodeString::replaceBetween(int32_t start,
04453 int32_t limit,
04454 const UnicodeString& srcText,
04455 int32_t srcStart,
04456 int32_t srcLimit)
04457 { return doReplace(start, limit - start, srcText, srcStart, srcLimit - srcStart); }
04458
04459 inline UnicodeString&
04460 UnicodeString::findAndReplace(const UnicodeString& oldText,
04461 const UnicodeString& newText)
04462 { return findAndReplace(0, length(), oldText, 0, oldText.length(),
04463 newText, 0, newText.length()); }
04464
04465 inline UnicodeString&
04466 UnicodeString::findAndReplace(int32_t start,
04467 int32_t _length,
04468 const UnicodeString& oldText,
04469 const UnicodeString& newText)
04470 { return findAndReplace(start, _length, oldText, 0, oldText.length(),
04471 newText, 0, newText.length()); }
04472
04473
04474
04475
04476 inline void
04477 UnicodeString::doExtract(int32_t start,
04478 int32_t _length,
04479 UnicodeString& target) const
04480 { target.replace(0, target.length(), *this, start, _length); }
04481
04482 inline void
04483 UnicodeString::extract(int32_t start,
04484 int32_t _length,
04485 Char16Ptr target,
04486 int32_t targetStart) const
04487 { doExtract(start, _length, target, targetStart); }
04488
04489 inline void
04490 UnicodeString::extract(int32_t start,
04491 int32_t _length,
04492 UnicodeString& target) const
04493 { doExtract(start, _length, target); }
04494
04495 #if !UCONFIG_NO_CONVERSION
04496
04497 inline int32_t
04498 UnicodeString::extract(int32_t start,
04499 int32_t _length,
04500 char *dst,
04501 const char *codepage) const
04502
04503 {
04504
04505 return extract(start, _length, dst, dst!=0 ? 0xffffffff : 0, codepage);
04506 }
04507
04508 #endif
04509
04510 inline void
04511 UnicodeString::extractBetween(int32_t start,
04512 int32_t limit,
04513 char16_t *dst,
04514 int32_t dstStart) const {
04515 pinIndex(start);
04516 pinIndex(limit);
04517 doExtract(start, limit - start, dst, dstStart);
04518 }
04519
04520 inline UnicodeString
04521 UnicodeString::tempSubStringBetween(int32_t start, int32_t limit) const {
04522 return tempSubString(start, limit - start);
04523 }
04524
04525 inline char16_t
04526 UnicodeString::doCharAt(int32_t offset) const
04527 {
04528 if((uint32_t)offset < (uint32_t)length()) {
04529 return getArrayStart()[offset];
04530 } else {
04531 return kInvalidUChar;
04532 }
04533 }
04534
04535 inline char16_t
04536 UnicodeString::charAt(int32_t offset) const
04537 { return doCharAt(offset); }
04538
04539 inline char16_t
04540 UnicodeString::operator[] (int32_t offset) const
04541 { return doCharAt(offset); }
04542
04543 inline UBool
04544 UnicodeString::isEmpty() const {
04545
04546 return (fUnion.fFields.fLengthAndFlags>>kLengthShift) == 0;
04547 }
04548
04549
04550
04551
04552 inline void
04553 UnicodeString::setZeroLength() {
04554 fUnion.fFields.fLengthAndFlags &= kAllStorageFlags;
04555 }
04556
04557 inline void
04558 UnicodeString::setShortLength(int32_t len) {
04559
04560 fUnion.fFields.fLengthAndFlags =
04561 (int16_t)((fUnion.fFields.fLengthAndFlags & kAllStorageFlags) | (len << kLengthShift));
04562 }
04563
04564 inline void
04565 UnicodeString::setLength(int32_t len) {
04566 if(len <= kMaxShortLength) {
04567 setShortLength(len);
04568 } else {
04569 fUnion.fFields.fLengthAndFlags |= kLengthIsLarge;
04570 fUnion.fFields.fLength = len;
04571 }
04572 }
04573
04574 inline void
04575 UnicodeString::setToEmpty() {
04576 fUnion.fFields.fLengthAndFlags = kShortString;
04577 }
04578
04579 inline void
04580 UnicodeString::setArray(char16_t *array, int32_t len, int32_t capacity) {
04581 setLength(len);
04582 fUnion.fFields.fArray = array;
04583 fUnion.fFields.fCapacity = capacity;
04584 }
04585
04586 inline UnicodeString&
04587 UnicodeString::operator= (char16_t ch)
04588 { return doReplace(0, length(), &ch, 0, 1); }
04589
04590 inline UnicodeString&
04591 UnicodeString::operator= (UChar32 ch)
04592 { return replace(0, length(), ch); }
04593
04594 inline UnicodeString&
04595 UnicodeString::setTo(const UnicodeString& srcText,
04596 int32_t srcStart,
04597 int32_t srcLength)
04598 {
04599 unBogus();
04600 return doReplace(0, length(), srcText, srcStart, srcLength);
04601 }
04602
04603 inline UnicodeString&
04604 UnicodeString::setTo(const UnicodeString& srcText,
04605 int32_t srcStart)
04606 {
04607 unBogus();
04608 srcText.pinIndex(srcStart);
04609 return doReplace(0, length(), srcText, srcStart, srcText.length() - srcStart);
04610 }
04611
04612 inline UnicodeString&
04613 UnicodeString::setTo(const UnicodeString& srcText)
04614 {
04615 return copyFrom(srcText);
04616 }
04617
04618 inline UnicodeString&
04619 UnicodeString::setTo(const char16_t *srcChars,
04620 int32_t srcLength)
04621 {
04622 unBogus();
04623 return doReplace(0, length(), srcChars, 0, srcLength);
04624 }
04625
04626 inline UnicodeString&
04627 UnicodeString::setTo(char16_t srcChar)
04628 {
04629 unBogus();
04630 return doReplace(0, length(), &srcChar, 0, 1);
04631 }
04632
04633 inline UnicodeString&
04634 UnicodeString::setTo(UChar32 srcChar)
04635 {
04636 unBogus();
04637 return replace(0, length(), srcChar);
04638 }
04639
04640 inline UnicodeString&
04641 UnicodeString::append(const UnicodeString& srcText,
04642 int32_t srcStart,
04643 int32_t srcLength)
04644 { return doAppend(srcText, srcStart, srcLength); }
04645
04646 inline UnicodeString&
04647 UnicodeString::append(const UnicodeString& srcText)
04648 { return doAppend(srcText, 0, srcText.length()); }
04649
04650 inline UnicodeString&
04651 UnicodeString::append(const char16_t *srcChars,
04652 int32_t srcStart,
04653 int32_t srcLength)
04654 { return doAppend(srcChars, srcStart, srcLength); }
04655
04656 inline UnicodeString&
04657 UnicodeString::append(ConstChar16Ptr srcChars,
04658 int32_t srcLength)
04659 { return doAppend(srcChars, 0, srcLength); }
04660
04661 inline UnicodeString&
04662 UnicodeString::append(char16_t srcChar)
04663 { return doAppend(&srcChar, 0, 1); }
04664
04665 inline UnicodeString&
04666 UnicodeString::operator+= (char16_t ch)
04667 { return doAppend(&ch, 0, 1); }
04668
04669 inline UnicodeString&
04670 UnicodeString::operator+= (UChar32 ch) {
04671 return append(ch);
04672 }
04673
04674 inline UnicodeString&
04675 UnicodeString::operator+= (const UnicodeString& srcText)
04676 { return doAppend(srcText, 0, srcText.length()); }
04677
04678 inline UnicodeString&
04679 UnicodeString::insert(int32_t start,
04680 const UnicodeString& srcText,
04681 int32_t srcStart,
04682 int32_t srcLength)
04683 { return doReplace(start, 0, srcText, srcStart, srcLength); }
04684
04685 inline UnicodeString&
04686 UnicodeString::insert(int32_t start,
04687 const UnicodeString& srcText)
04688 { return doReplace(start, 0, srcText, 0, srcText.length()); }
04689
04690 inline UnicodeString&
04691 UnicodeString::insert(int32_t start,
04692 const char16_t *srcChars,
04693 int32_t srcStart,
04694 int32_t srcLength)
04695 { return doReplace(start, 0, srcChars, srcStart, srcLength); }
04696
04697 inline UnicodeString&
04698 UnicodeString::insert(int32_t start,
04699 ConstChar16Ptr srcChars,
04700 int32_t srcLength)
04701 { return doReplace(start, 0, srcChars, 0, srcLength); }
04702
04703 inline UnicodeString&
04704 UnicodeString::insert(int32_t start,
04705 char16_t srcChar)
04706 { return doReplace(start, 0, &srcChar, 0, 1); }
04707
04708 inline UnicodeString&
04709 UnicodeString::insert(int32_t start,
04710 UChar32 srcChar)
04711 { return replace(start, 0, srcChar); }
04712
04713
04714 inline UnicodeString&
04715 UnicodeString::remove()
04716 {
04717
04718 if(isBogus()) {
04719 setToEmpty();
04720 } else {
04721 setZeroLength();
04722 }
04723 return *this;
04724 }
04725
04726 inline UnicodeString&
04727 UnicodeString::remove(int32_t start,
04728 int32_t _length)
04729 {
04730 if(start <= 0 && _length == INT32_MAX) {
04731
04732 return remove();
04733 }
04734 return doReplace(start, _length, NULL, 0, 0);
04735 }
04736
04737 inline UnicodeString&
04738 UnicodeString::removeBetween(int32_t start,
04739 int32_t limit)
04740 { return doReplace(start, limit - start, NULL, 0, 0); }
04741
04742 inline UnicodeString &
04743 UnicodeString::retainBetween(int32_t start, int32_t limit) {
04744 truncate(limit);
04745 return doReplace(0, start, NULL, 0, 0);
04746 }
04747
04748 inline UBool
04749 UnicodeString::truncate(int32_t targetLength)
04750 {
04751 if(isBogus() && targetLength == 0) {
04752
04753 unBogus();
04754 return FALSE;
04755 } else if((uint32_t)targetLength < (uint32_t)length()) {
04756 setLength(targetLength);
04757 return TRUE;
04758 } else {
04759 return FALSE;
04760 }
04761 }
04762
04763 inline UnicodeString&
04764 UnicodeString::reverse()
04765 { return doReverse(0, length()); }
04766
04767 inline UnicodeString&
04768 UnicodeString::reverse(int32_t start,
04769 int32_t _length)
04770 { return doReverse(start, _length); }
04771
04772 U_NAMESPACE_END
04773
04774 #endif