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
01493 inline void extract(int32_t start,
01494 int32_t length,
01495 UnicodeString& target) const;
01496
01508 inline void extractBetween(int32_t start,
01509 int32_t limit,
01510 char16_t *dst,
01511 int32_t dstStart = 0) const;
01512
01521 virtual void extractBetween(int32_t start,
01522 int32_t limit,
01523 UnicodeString& target) const;
01524
01546 int32_t extract(int32_t start,
01547 int32_t startLength,
01548 char *target,
01549 int32_t targetCapacity,
01550 enum EInvariant inv) const;
01551
01552 #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
01553
01573 int32_t extract(int32_t start,
01574 int32_t startLength,
01575 char *target,
01576 uint32_t targetLength) const;
01577
01578 #endif
01579
01580 #if !UCONFIG_NO_CONVERSION
01581
01607 inline int32_t extract(int32_t start,
01608 int32_t startLength,
01609 char *target,
01610 const char *codepage = 0) const;
01611
01641 int32_t extract(int32_t start,
01642 int32_t startLength,
01643 char *target,
01644 uint32_t targetLength,
01645 const char *codepage) const;
01646
01664 int32_t extract(char *dest, int32_t destCapacity,
01665 UConverter *cnv,
01666 UErrorCode &errorCode) const;
01667
01668 #endif
01669
01683 UnicodeString tempSubString(int32_t start=0, int32_t length=INT32_MAX) const;
01684
01695 inline UnicodeString tempSubStringBetween(int32_t start, int32_t limit=INT32_MAX) const;
01696
01708 void toUTF8(ByteSink &sink) const;
01709
01722 template<typename StringClass>
01723 StringClass &toUTF8String(StringClass &result) const {
01724 StringByteSink<StringClass> sbs(&result, length());
01725 toUTF8(sbs);
01726 return result;
01727 }
01728
01744 int32_t toUTF32(UChar32 *utf32, int32_t capacity, UErrorCode &errorCode) const;
01745
01746
01747
01756 inline int32_t length(void) const;
01757
01771 int32_t
01772 countChar32(int32_t start=0, int32_t length=INT32_MAX) const;
01773
01797 UBool
01798 hasMoreChar32Than(int32_t start, int32_t length, int32_t number) const;
01799
01805 inline UBool isEmpty(void) const;
01806
01816 inline int32_t getCapacity(void) const;
01817
01818
01819
01825 inline int32_t hashCode(void) const;
01826
01839 inline UBool isBogus(void) const;
01840
01841
01842
01843
01844
01845
01846
01847
01866 UnicodeString &operator=(const UnicodeString &srcText);
01867
01893 UnicodeString &fastCopyFrom(const UnicodeString &src);
01894
01903 UnicodeString &operator=(UnicodeString &&src) U_NOEXCEPT;
01904
01910 void swap(UnicodeString &other) U_NOEXCEPT;
01911
01918 friend inline void U_EXPORT2
01919 swap(UnicodeString &s1, UnicodeString &s2) U_NOEXCEPT {
01920 s1.swap(s2);
01921 }
01922
01930 inline UnicodeString& operator= (char16_t ch);
01931
01939 inline UnicodeString& operator= (UChar32 ch);
01940
01952 inline UnicodeString& setTo(const UnicodeString& srcText,
01953 int32_t srcStart);
01954
01968 inline UnicodeString& setTo(const UnicodeString& srcText,
01969 int32_t srcStart,
01970 int32_t srcLength);
01971
01980 inline UnicodeString& setTo(const UnicodeString& srcText);
01981
01990 inline UnicodeString& setTo(const char16_t *srcChars,
01991 int32_t srcLength);
01992
02001 inline UnicodeString& setTo(char16_t srcChar);
02002
02011 inline UnicodeString& setTo(UChar32 srcChar);
02012
02036 UnicodeString &setTo(UBool isTerminated,
02037 ConstChar16Ptr text,
02038 int32_t textLength);
02039
02059 UnicodeString &setTo(char16_t *buffer,
02060 int32_t buffLength,
02061 int32_t buffCapacity);
02062
02103 void setToBogus();
02104
02112 UnicodeString& setCharAt(int32_t offset,
02113 char16_t ch);
02114
02115
02116
02117
02125 inline UnicodeString& operator+= (char16_t ch);
02126
02134 inline UnicodeString& operator+= (UChar32 ch);
02135
02143 inline UnicodeString& operator+= (const UnicodeString& srcText);
02144
02159 inline UnicodeString& append(const UnicodeString& srcText,
02160 int32_t srcStart,
02161 int32_t srcLength);
02162
02170 inline UnicodeString& append(const UnicodeString& srcText);
02171
02185 inline UnicodeString& append(const char16_t *srcChars,
02186 int32_t srcStart,
02187 int32_t srcLength);
02188
02198 inline UnicodeString& append(ConstChar16Ptr srcChars,
02199 int32_t srcLength);
02200
02207 inline UnicodeString& append(char16_t srcChar);
02208
02215 UnicodeString& append(UChar32 srcChar);
02216
02217
02218
02219
02233 inline UnicodeString& insert(int32_t start,
02234 const UnicodeString& srcText,
02235 int32_t srcStart,
02236 int32_t srcLength);
02237
02246 inline UnicodeString& insert(int32_t start,
02247 const UnicodeString& srcText);
02248
02262 inline UnicodeString& insert(int32_t start,
02263 const char16_t *srcChars,
02264 int32_t srcStart,
02265 int32_t srcLength);
02266
02276 inline UnicodeString& insert(int32_t start,
02277 ConstChar16Ptr srcChars,
02278 int32_t srcLength);
02279
02288 inline UnicodeString& insert(int32_t start,
02289 char16_t srcChar);
02290
02299 inline UnicodeString& insert(int32_t start,
02300 UChar32 srcChar);
02301
02302
02303
02304
02322 inline UnicodeString& replace(int32_t start,
02323 int32_t length,
02324 const UnicodeString& srcText,
02325 int32_t srcStart,
02326 int32_t srcLength);
02327
02340 inline UnicodeString& replace(int32_t start,
02341 int32_t length,
02342 const UnicodeString& srcText);
02343
02361 inline UnicodeString& replace(int32_t start,
02362 int32_t length,
02363 const char16_t *srcChars,
02364 int32_t srcStart,
02365 int32_t srcLength);
02366
02379 inline UnicodeString& replace(int32_t start,
02380 int32_t length,
02381 ConstChar16Ptr srcChars,
02382 int32_t srcLength);
02383
02395 inline UnicodeString& replace(int32_t start,
02396 int32_t length,
02397 char16_t srcChar);
02398
02410 UnicodeString& replace(int32_t start, int32_t length, UChar32 srcChar);
02411
02421 inline UnicodeString& replaceBetween(int32_t start,
02422 int32_t limit,
02423 const UnicodeString& srcText);
02424
02439 inline UnicodeString& replaceBetween(int32_t start,
02440 int32_t limit,
02441 const UnicodeString& srcText,
02442 int32_t srcStart,
02443 int32_t srcLimit);
02444
02452 virtual void handleReplaceBetween(int32_t start,
02453 int32_t limit,
02454 const UnicodeString& text);
02455
02461 virtual UBool hasMetaData() const;
02462
02476 virtual void copy(int32_t start, int32_t limit, int32_t dest);
02477
02478
02479
02488 inline UnicodeString& findAndReplace(const UnicodeString& oldText,
02489 const UnicodeString& newText);
02490
02502 inline UnicodeString& findAndReplace(int32_t start,
02503 int32_t length,
02504 const UnicodeString& oldText,
02505 const UnicodeString& newText);
02506
02524 UnicodeString& findAndReplace(int32_t start,
02525 int32_t length,
02526 const UnicodeString& oldText,
02527 int32_t oldStart,
02528 int32_t oldLength,
02529 const UnicodeString& newText,
02530 int32_t newStart,
02531 int32_t newLength);
02532
02533
02534
02535
02541 inline UnicodeString& remove(void);
02542
02551 inline UnicodeString& remove(int32_t start,
02552 int32_t length = (int32_t)INT32_MAX);
02553
02562 inline UnicodeString& removeBetween(int32_t start,
02563 int32_t limit = (int32_t)INT32_MAX);
02564
02574 inline UnicodeString &retainBetween(int32_t start, int32_t limit = INT32_MAX);
02575
02576
02577
02589 UBool padLeading(int32_t targetLength,
02590 char16_t padChar = 0x0020);
02591
02603 UBool padTrailing(int32_t targetLength,
02604 char16_t padChar = 0x0020);
02605
02612 inline UBool truncate(int32_t targetLength);
02613
02619 UnicodeString& trim(void);
02620
02621
02622
02623
02629 inline UnicodeString& reverse(void);
02630
02639 inline UnicodeString& reverse(int32_t start,
02640 int32_t length);
02641
02648 UnicodeString& toUpper(void);
02649
02657 UnicodeString& toUpper(const Locale& locale);
02658
02665 UnicodeString& toLower(void);
02666
02674 UnicodeString& toLower(const Locale& locale);
02675
02676 #if !UCONFIG_NO_BREAK_ITERATION
02677
02704 UnicodeString &toTitle(BreakIterator *titleIter);
02705
02733 UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale);
02734
02766 UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale, uint32_t options);
02767
02768 #endif
02769
02783 UnicodeString &foldCase(uint32_t options=0 );
02784
02785
02786
02787
02788
02832 char16_t *getBuffer(int32_t minCapacity);
02833
02854 void releaseBuffer(int32_t newLength=-1);
02855
02886 inline const char16_t *getBuffer() const;
02887
02921 const char16_t *getTerminatedBuffer();
02922
02923
02924
02925
02926
02930 inline UnicodeString();
02931
02943 UnicodeString(int32_t capacity, UChar32 c, int32_t count);
02944
02954 UNISTR_FROM_CHAR_EXPLICIT UnicodeString(char16_t ch);
02955
02965 UNISTR_FROM_CHAR_EXPLICIT UnicodeString(UChar32 ch);
02966
02977 UNISTR_FROM_STRING_EXPLICIT UnicodeString(const char16_t *text);
02978
02979 #if !U_CHAR16_IS_TYPEDEF
02980
02990 UNISTR_FROM_STRING_EXPLICIT UnicodeString(const uint16_t *text) :
02991 UnicodeString(ConstChar16Ptr(text)) {}
02992 #endif
02993
02994 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
02995
03006 UNISTR_FROM_STRING_EXPLICIT UnicodeString(const wchar_t *text) :
03007 UnicodeString(ConstChar16Ptr(text)) {}
03008 #endif
03009
03020 UNISTR_FROM_STRING_EXPLICIT inline UnicodeString(const std::nullptr_t text);
03021
03029 UnicodeString(const char16_t *text,
03030 int32_t textLength);
03031
03032 #if !U_CHAR16_IS_TYPEDEF
03033
03040 UnicodeString(const uint16_t *text, int32_t length) :
03041 UnicodeString(ConstChar16Ptr(text), length) {}
03042 #endif
03043
03044 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
03045
03053 UnicodeString(const wchar_t *text, int32_t length) :
03054 UnicodeString(ConstChar16Ptr(text), length) {}
03055 #endif
03056
03064 inline UnicodeString(const std::nullptr_t text, int32_t length);
03065
03088 UnicodeString(UBool isTerminated,
03089 ConstChar16Ptr text,
03090 int32_t textLength);
03091
03110 UnicodeString(char16_t *buffer, int32_t buffLength, int32_t buffCapacity);
03111
03112 #if !U_CHAR16_IS_TYPEDEF
03113
03121 UnicodeString(uint16_t *buffer, int32_t buffLength, int32_t buffCapacity) :
03122 UnicodeString(Char16Ptr(buffer), buffLength, buffCapacity) {}
03123 #endif
03124
03125 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
03126
03135 UnicodeString(wchar_t *buffer, int32_t buffLength, int32_t buffCapacity) :
03136 UnicodeString(Char16Ptr(buffer), buffLength, buffCapacity) {}
03137 #endif
03138
03147 inline UnicodeString(std::nullptr_t buffer, int32_t buffLength, int32_t buffCapacity);
03148
03149 #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
03150
03170 UNISTR_FROM_STRING_EXPLICIT UnicodeString(const char *codepageData);
03171
03180 UnicodeString(const char *codepageData, int32_t dataLength);
03181
03182 #endif
03183
03184 #if !UCONFIG_NO_CONVERSION
03185
03203 UnicodeString(const char *codepageData, const char *codepage);
03204
03222 UnicodeString(const char *codepageData, int32_t dataLength, const char *codepage);
03223
03245 UnicodeString(
03246 const char *src, int32_t srcLength,
03247 UConverter *cnv,
03248 UErrorCode &errorCode);
03249
03250 #endif
03251
03275 UnicodeString(const char *src, int32_t length, enum EInvariant inv);
03276
03277
03294 UnicodeString(const UnicodeString& that);
03295
03302 UnicodeString(UnicodeString &&src) U_NOEXCEPT;
03303
03310 UnicodeString(const UnicodeString& src, int32_t srcStart);
03311
03319 UnicodeString(const UnicodeString& src, int32_t srcStart, int32_t srcLength);
03320
03337 virtual Replaceable *clone() const;
03338
03342 virtual ~UnicodeString();
03343
03357 static UnicodeString fromUTF8(StringPiece utf8);
03358
03370 static UnicodeString fromUTF32(const UChar32 *utf32, int32_t length);
03371
03372
03373
03408 UnicodeString unescape() const;
03409
03429 UChar32 unescapeAt(int32_t &offset) const;
03430
03436 static UClassID U_EXPORT2 getStaticClassID();
03437
03443 virtual UClassID getDynamicClassID() const;
03444
03445
03446
03447
03448
03449 protected:
03454 virtual int32_t getLength() const;
03455
03461 virtual char16_t getCharAt(int32_t offset) const;
03462
03468 virtual UChar32 getChar32At(int32_t offset) const;
03469
03470 private:
03471
03472 UnicodeString &setToUTF8(StringPiece utf8);
03473
03474
03475
03476
03477
03478 int32_t
03479 toUTF8(int32_t start, int32_t len,
03480 char *target, int32_t capacity) const;
03481
03486 UBool doEquals(const UnicodeString &text, int32_t len) const;
03487
03488 inline int8_t
03489 doCompare(int32_t start,
03490 int32_t length,
03491 const UnicodeString& srcText,
03492 int32_t srcStart,
03493 int32_t srcLength) const;
03494
03495 int8_t doCompare(int32_t start,
03496 int32_t length,
03497 const char16_t *srcChars,
03498 int32_t srcStart,
03499 int32_t srcLength) const;
03500
03501 inline int8_t
03502 doCompareCodePointOrder(int32_t start,
03503 int32_t length,
03504 const UnicodeString& srcText,
03505 int32_t srcStart,
03506 int32_t srcLength) const;
03507
03508 int8_t doCompareCodePointOrder(int32_t start,
03509 int32_t length,
03510 const char16_t *srcChars,
03511 int32_t srcStart,
03512 int32_t srcLength) const;
03513
03514 inline int8_t
03515 doCaseCompare(int32_t start,
03516 int32_t length,
03517 const UnicodeString &srcText,
03518 int32_t srcStart,
03519 int32_t srcLength,
03520 uint32_t options) const;
03521
03522 int8_t
03523 doCaseCompare(int32_t start,
03524 int32_t length,
03525 const char16_t *srcChars,
03526 int32_t srcStart,
03527 int32_t srcLength,
03528 uint32_t options) const;
03529
03530 int32_t doIndexOf(char16_t c,
03531 int32_t start,
03532 int32_t length) const;
03533
03534 int32_t doIndexOf(UChar32 c,
03535 int32_t start,
03536 int32_t length) const;
03537
03538 int32_t doLastIndexOf(char16_t c,
03539 int32_t start,
03540 int32_t length) const;
03541
03542 int32_t doLastIndexOf(UChar32 c,
03543 int32_t start,
03544 int32_t length) const;
03545
03546 void doExtract(int32_t start,
03547 int32_t length,
03548 char16_t *dst,
03549 int32_t dstStart) const;
03550
03551 inline void doExtract(int32_t start,
03552 int32_t length,
03553 UnicodeString& target) const;
03554
03555 inline char16_t doCharAt(int32_t offset) const;
03556
03557 UnicodeString& doReplace(int32_t start,
03558 int32_t length,
03559 const UnicodeString& srcText,
03560 int32_t srcStart,
03561 int32_t srcLength);
03562
03563 UnicodeString& doReplace(int32_t start,
03564 int32_t length,
03565 const char16_t *srcChars,
03566 int32_t srcStart,
03567 int32_t srcLength);
03568
03569 UnicodeString& doAppend(const UnicodeString& src, int32_t srcStart, int32_t srcLength);
03570 UnicodeString& doAppend(const char16_t *srcChars, int32_t srcStart, int32_t srcLength);
03571
03572 UnicodeString& doReverse(int32_t start,
03573 int32_t length);
03574
03575
03576 int32_t doHashCode(void) const;
03577
03578
03579
03580 inline char16_t* getArrayStart(void);
03581 inline const char16_t* getArrayStart(void) const;
03582
03583 inline UBool hasShortLength() const;
03584 inline int32_t getShortLength() const;
03585
03586
03587
03588 inline UBool isWritable() const;
03589
03590
03591 inline UBool isBufferWritable() const;
03592
03593
03594 inline void setZeroLength();
03595 inline void setShortLength(int32_t len);
03596 inline void setLength(int32_t len);
03597 inline void setToEmpty();
03598 inline void setArray(char16_t *array, int32_t len, int32_t capacity);
03599
03600
03601
03602
03603
03604
03605 UBool allocate(int32_t capacity);
03606
03607
03608 void releaseArray(void);
03609
03610
03611 void unBogus();
03612
03613
03614 UnicodeString ©From(const UnicodeString &src, UBool fastCopy=FALSE);
03615
03616
03617 void copyFieldsFrom(UnicodeString &src, UBool setSrcToBogus) U_NOEXCEPT;
03618
03619
03620 inline void pinIndex(int32_t& start) const;
03621 inline void pinIndices(int32_t& start,
03622 int32_t& length) const;
03623
03624 #if !UCONFIG_NO_CONVERSION
03625
03626
03627 int32_t doExtract(int32_t start, int32_t length,
03628 char *dest, int32_t destCapacity,
03629 UConverter *cnv,
03630 UErrorCode &errorCode) const;
03631
03632
03633
03634
03635
03636
03637
03638
03639
03640
03641
03642 void doCodepageCreate(const char *codepageData,
03643 int32_t dataLength,
03644 const char *codepage);
03645
03646
03647
03648
03649
03650 void
03651 doCodepageCreate(const char *codepageData,
03652 int32_t dataLength,
03653 UConverter *converter,
03654 UErrorCode &status);
03655
03656 #endif
03657
03658
03659
03660
03661
03662
03663
03664
03665
03666
03667
03668
03669 UBool cloneArrayIfNeeded(int32_t newCapacity = -1,
03670 int32_t growCapacity = -1,
03671 UBool doCopyArray = TRUE,
03672 int32_t **pBufferToDelete = 0,
03673 UBool forceClone = FALSE);
03674
03680 UnicodeString &
03681 caseMap(int32_t caseLocale, uint32_t options,
03682 #if !UCONFIG_NO_BREAK_ITERATION
03683 BreakIterator *iter,
03684 #endif
03685 UStringCaseMapper *stringCaseMapper);
03686
03687
03688 void addRef(void);
03689 int32_t removeRef(void);
03690 int32_t refCount(void) const;
03691
03692
03693 enum {
03699 US_STACKBUF_SIZE=(int32_t)(UNISTR_OBJECT_SIZE-sizeof(void *)-2)/U_SIZEOF_UCHAR,
03700 kInvalidUChar=0xffff,
03701 kInvalidHashCode=0,
03702 kEmptyHashCode=1,
03703
03704
03705 kIsBogus=1,
03706 kUsingStackBuffer=2,
03707 kRefCounted=4,
03708 kBufferIsReadonly=8,
03709 kOpenGetBuffer=16,
03710
03711 kAllStorageFlags=0x1f,
03712
03713 kLengthShift=5,
03714 kLength1=1<<kLengthShift,
03715 kMaxShortLength=0x3ff,
03716 kLengthIsLarge=0xffe0,
03717
03718
03719 kShortString=kUsingStackBuffer,
03720 kLongString=kRefCounted,
03721 kReadonlyAlias=kBufferIsReadonly,
03722 kWritableAlias=0
03723 };
03724
03725 friend class UnicodeStringAppendable;
03726
03727 union StackBufferOrFields;
03728 friend union StackBufferOrFields;
03729
03730
03731
03732
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 union StackBufferOrFields {
03772
03773
03774 struct {
03775 int16_t fLengthAndFlags;
03776 char16_t fBuffer[US_STACKBUF_SIZE];
03777 } fStackFields;
03778 struct {
03779 int16_t fLengthAndFlags;
03780 int32_t fLength;
03781 int32_t fCapacity;
03782
03783
03784 char16_t *fArray;
03785 } fFields;
03786 } fUnion;
03787 };
03788
03797 U_COMMON_API UnicodeString U_EXPORT2
03798 operator+ (const UnicodeString &s1, const UnicodeString &s2);
03799
03800
03801
03802
03803
03804
03805
03806
03807
03808 inline void
03809 UnicodeString::pinIndex(int32_t& start) const
03810 {
03811
03812 if(start < 0) {
03813 start = 0;
03814 } else if(start > length()) {
03815 start = length();
03816 }
03817 }
03818
03819 inline void
03820 UnicodeString::pinIndices(int32_t& start,
03821 int32_t& _length) const
03822 {
03823
03824 int32_t len = length();
03825 if(start < 0) {
03826 start = 0;
03827 } else if(start > len) {
03828 start = len;
03829 }
03830 if(_length < 0) {
03831 _length = 0;
03832 } else if(_length > (len - start)) {
03833 _length = (len - start);
03834 }
03835 }
03836
03837 inline char16_t*
03838 UnicodeString::getArrayStart() {
03839 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
03840 fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
03841 }
03842
03843 inline const char16_t*
03844 UnicodeString::getArrayStart() const {
03845 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
03846 fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
03847 }
03848
03849
03850
03851
03852
03853 inline
03854 UnicodeString::UnicodeString() {
03855 fUnion.fStackFields.fLengthAndFlags=kShortString;
03856 }
03857
03858 inline UnicodeString::UnicodeString(const std::nullptr_t ) {
03859 fUnion.fStackFields.fLengthAndFlags=kShortString;
03860 }
03861
03862 inline UnicodeString::UnicodeString(const std::nullptr_t , int32_t ) {
03863 fUnion.fStackFields.fLengthAndFlags=kShortString;
03864 }
03865
03866 inline UnicodeString::UnicodeString(std::nullptr_t , int32_t , int32_t ) {
03867 fUnion.fStackFields.fLengthAndFlags=kShortString;
03868 }
03869
03870
03871
03872
03873 inline UBool
03874 UnicodeString::hasShortLength() const {
03875 return fUnion.fFields.fLengthAndFlags>=0;
03876 }
03877
03878 inline int32_t
03879 UnicodeString::getShortLength() const {
03880
03881
03882 return fUnion.fFields.fLengthAndFlags>>kLengthShift;
03883 }
03884
03885 inline int32_t
03886 UnicodeString::length() const {
03887 return hasShortLength() ? getShortLength() : fUnion.fFields.fLength;
03888 }
03889
03890 inline int32_t
03891 UnicodeString::getCapacity() const {
03892 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
03893 US_STACKBUF_SIZE : fUnion.fFields.fCapacity;
03894 }
03895
03896 inline int32_t
03897 UnicodeString::hashCode() const
03898 { return doHashCode(); }
03899
03900 inline UBool
03901 UnicodeString::isBogus() const
03902 { return (UBool)(fUnion.fFields.fLengthAndFlags & kIsBogus); }
03903
03904 inline UBool
03905 UnicodeString::isWritable() const
03906 { return (UBool)!(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus)); }
03907
03908 inline UBool
03909 UnicodeString::isBufferWritable() const
03910 {
03911 return (UBool)(
03912 !(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus|kBufferIsReadonly)) &&
03913 (!(fUnion.fFields.fLengthAndFlags&kRefCounted) || refCount()==1));
03914 }
03915
03916 inline const char16_t *
03917 UnicodeString::getBuffer() const {
03918 if(fUnion.fFields.fLengthAndFlags&(kIsBogus|kOpenGetBuffer)) {
03919 return nullptr;
03920 } else if(fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) {
03921 return fUnion.fStackFields.fBuffer;
03922 } else {
03923 return fUnion.fFields.fArray;
03924 }
03925 }
03926
03927
03928
03929
03930 inline int8_t
03931 UnicodeString::doCompare(int32_t start,
03932 int32_t thisLength,
03933 const UnicodeString& srcText,
03934 int32_t srcStart,
03935 int32_t srcLength) const
03936 {
03937 if(srcText.isBogus()) {
03938 return (int8_t)!isBogus();
03939 } else {
03940 srcText.pinIndices(srcStart, srcLength);
03941 return doCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
03942 }
03943 }
03944
03945 inline UBool
03946 UnicodeString::operator== (const UnicodeString& text) const
03947 {
03948 if(isBogus()) {
03949 return text.isBogus();
03950 } else {
03951 int32_t len = length(), textLength = text.length();
03952 return !text.isBogus() && len == textLength && doEquals(text, len);
03953 }
03954 }
03955
03956 inline UBool
03957 UnicodeString::operator!= (const UnicodeString& text) const
03958 { return (! operator==(text)); }
03959
03960 inline UBool
03961 UnicodeString::operator> (const UnicodeString& text) const
03962 { return doCompare(0, length(), text, 0, text.length()) == 1; }
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 int8_t
03977 UnicodeString::compare(const UnicodeString& text) const
03978 { return doCompare(0, length(), text, 0, text.length()); }
03979
03980 inline int8_t
03981 UnicodeString::compare(int32_t start,
03982 int32_t _length,
03983 const UnicodeString& srcText) const
03984 { return doCompare(start, _length, srcText, 0, srcText.length()); }
03985
03986 inline int8_t
03987 UnicodeString::compare(ConstChar16Ptr srcChars,
03988 int32_t srcLength) const
03989 { return doCompare(0, length(), srcChars, 0, srcLength); }
03990
03991 inline int8_t
03992 UnicodeString::compare(int32_t start,
03993 int32_t _length,
03994 const UnicodeString& srcText,
03995 int32_t srcStart,
03996 int32_t srcLength) const
03997 { return doCompare(start, _length, srcText, srcStart, srcLength); }
03998
03999 inline int8_t
04000 UnicodeString::compare(int32_t start,
04001 int32_t _length,
04002 const char16_t *srcChars) const
04003 { return doCompare(start, _length, srcChars, 0, _length); }
04004
04005 inline int8_t
04006 UnicodeString::compare(int32_t start,
04007 int32_t _length,
04008 const char16_t *srcChars,
04009 int32_t srcStart,
04010 int32_t srcLength) const
04011 { return doCompare(start, _length, srcChars, srcStart, srcLength); }
04012
04013 inline int8_t
04014 UnicodeString::compareBetween(int32_t start,
04015 int32_t limit,
04016 const UnicodeString& srcText,
04017 int32_t srcStart,
04018 int32_t srcLimit) const
04019 { return doCompare(start, limit - start,
04020 srcText, srcStart, srcLimit - srcStart); }
04021
04022 inline int8_t
04023 UnicodeString::doCompareCodePointOrder(int32_t start,
04024 int32_t thisLength,
04025 const UnicodeString& srcText,
04026 int32_t srcStart,
04027 int32_t srcLength) const
04028 {
04029 if(srcText.isBogus()) {
04030 return (int8_t)!isBogus();
04031 } else {
04032 srcText.pinIndices(srcStart, srcLength);
04033 return doCompareCodePointOrder(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
04034 }
04035 }
04036
04037 inline int8_t
04038 UnicodeString::compareCodePointOrder(const UnicodeString& text) const
04039 { return doCompareCodePointOrder(0, length(), text, 0, text.length()); }
04040
04041 inline int8_t
04042 UnicodeString::compareCodePointOrder(int32_t start,
04043 int32_t _length,
04044 const UnicodeString& srcText) const
04045 { return doCompareCodePointOrder(start, _length, srcText, 0, srcText.length()); }
04046
04047 inline int8_t
04048 UnicodeString::compareCodePointOrder(ConstChar16Ptr srcChars,
04049 int32_t srcLength) const
04050 { return doCompareCodePointOrder(0, length(), srcChars, 0, srcLength); }
04051
04052 inline int8_t
04053 UnicodeString::compareCodePointOrder(int32_t start,
04054 int32_t _length,
04055 const UnicodeString& srcText,
04056 int32_t srcStart,
04057 int32_t srcLength) const
04058 { return doCompareCodePointOrder(start, _length, srcText, srcStart, srcLength); }
04059
04060 inline int8_t
04061 UnicodeString::compareCodePointOrder(int32_t start,
04062 int32_t _length,
04063 const char16_t *srcChars) const
04064 { return doCompareCodePointOrder(start, _length, srcChars, 0, _length); }
04065
04066 inline int8_t
04067 UnicodeString::compareCodePointOrder(int32_t start,
04068 int32_t _length,
04069 const char16_t *srcChars,
04070 int32_t srcStart,
04071 int32_t srcLength) const
04072 { return doCompareCodePointOrder(start, _length, srcChars, srcStart, srcLength); }
04073
04074 inline int8_t
04075 UnicodeString::compareCodePointOrderBetween(int32_t start,
04076 int32_t limit,
04077 const UnicodeString& srcText,
04078 int32_t srcStart,
04079 int32_t srcLimit) const
04080 { return doCompareCodePointOrder(start, limit - start,
04081 srcText, srcStart, srcLimit - srcStart); }
04082
04083 inline int8_t
04084 UnicodeString::doCaseCompare(int32_t start,
04085 int32_t thisLength,
04086 const UnicodeString &srcText,
04087 int32_t srcStart,
04088 int32_t srcLength,
04089 uint32_t options) const
04090 {
04091 if(srcText.isBogus()) {
04092 return (int8_t)!isBogus();
04093 } else {
04094 srcText.pinIndices(srcStart, srcLength);
04095 return doCaseCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength, options);
04096 }
04097 }
04098
04099 inline int8_t
04100 UnicodeString::caseCompare(const UnicodeString &text, uint32_t options) const {
04101 return doCaseCompare(0, length(), text, 0, text.length(), options);
04102 }
04103
04104 inline int8_t
04105 UnicodeString::caseCompare(int32_t start,
04106 int32_t _length,
04107 const UnicodeString &srcText,
04108 uint32_t options) const {
04109 return doCaseCompare(start, _length, srcText, 0, srcText.length(), options);
04110 }
04111
04112 inline int8_t
04113 UnicodeString::caseCompare(ConstChar16Ptr srcChars,
04114 int32_t srcLength,
04115 uint32_t options) const {
04116 return doCaseCompare(0, length(), srcChars, 0, srcLength, options);
04117 }
04118
04119 inline int8_t
04120 UnicodeString::caseCompare(int32_t start,
04121 int32_t _length,
04122 const UnicodeString &srcText,
04123 int32_t srcStart,
04124 int32_t srcLength,
04125 uint32_t options) const {
04126 return doCaseCompare(start, _length, srcText, srcStart, srcLength, options);
04127 }
04128
04129 inline int8_t
04130 UnicodeString::caseCompare(int32_t start,
04131 int32_t _length,
04132 const char16_t *srcChars,
04133 uint32_t options) const {
04134 return doCaseCompare(start, _length, srcChars, 0, _length, options);
04135 }
04136
04137 inline int8_t
04138 UnicodeString::caseCompare(int32_t start,
04139 int32_t _length,
04140 const char16_t *srcChars,
04141 int32_t srcStart,
04142 int32_t srcLength,
04143 uint32_t options) const {
04144 return doCaseCompare(start, _length, srcChars, srcStart, srcLength, options);
04145 }
04146
04147 inline int8_t
04148 UnicodeString::caseCompareBetween(int32_t start,
04149 int32_t limit,
04150 const UnicodeString &srcText,
04151 int32_t srcStart,
04152 int32_t srcLimit,
04153 uint32_t options) const {
04154 return doCaseCompare(start, limit - start, srcText, srcStart, srcLimit - srcStart, options);
04155 }
04156
04157 inline int32_t
04158 UnicodeString::indexOf(const UnicodeString& srcText,
04159 int32_t srcStart,
04160 int32_t srcLength,
04161 int32_t start,
04162 int32_t _length) const
04163 {
04164 if(!srcText.isBogus()) {
04165 srcText.pinIndices(srcStart, srcLength);
04166 if(srcLength > 0) {
04167 return indexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
04168 }
04169 }
04170 return -1;
04171 }
04172
04173 inline int32_t
04174 UnicodeString::indexOf(const UnicodeString& text) const
04175 { return indexOf(text, 0, text.length(), 0, length()); }
04176
04177 inline int32_t
04178 UnicodeString::indexOf(const UnicodeString& text,
04179 int32_t start) const {
04180 pinIndex(start);
04181 return indexOf(text, 0, text.length(), start, length() - start);
04182 }
04183
04184 inline int32_t
04185 UnicodeString::indexOf(const UnicodeString& text,
04186 int32_t start,
04187 int32_t _length) const
04188 { return indexOf(text, 0, text.length(), start, _length); }
04189
04190 inline int32_t
04191 UnicodeString::indexOf(const char16_t *srcChars,
04192 int32_t srcLength,
04193 int32_t start) const {
04194 pinIndex(start);
04195 return indexOf(srcChars, 0, srcLength, start, length() - start);
04196 }
04197
04198 inline int32_t
04199 UnicodeString::indexOf(ConstChar16Ptr srcChars,
04200 int32_t srcLength,
04201 int32_t start,
04202 int32_t _length) const
04203 { return indexOf(srcChars, 0, srcLength, start, _length); }
04204
04205 inline int32_t
04206 UnicodeString::indexOf(char16_t c,
04207 int32_t start,
04208 int32_t _length) const
04209 { return doIndexOf(c, start, _length); }
04210
04211 inline int32_t
04212 UnicodeString::indexOf(UChar32 c,
04213 int32_t start,
04214 int32_t _length) const
04215 { return doIndexOf(c, start, _length); }
04216
04217 inline int32_t
04218 UnicodeString::indexOf(char16_t c) const
04219 { return doIndexOf(c, 0, length()); }
04220
04221 inline int32_t
04222 UnicodeString::indexOf(UChar32 c) const
04223 { return indexOf(c, 0, length()); }
04224
04225 inline int32_t
04226 UnicodeString::indexOf(char16_t c,
04227 int32_t start) const {
04228 pinIndex(start);
04229 return doIndexOf(c, start, length() - start);
04230 }
04231
04232 inline int32_t
04233 UnicodeString::indexOf(UChar32 c,
04234 int32_t start) const {
04235 pinIndex(start);
04236 return indexOf(c, start, length() - start);
04237 }
04238
04239 inline int32_t
04240 UnicodeString::lastIndexOf(ConstChar16Ptr srcChars,
04241 int32_t srcLength,
04242 int32_t start,
04243 int32_t _length) const
04244 { return lastIndexOf(srcChars, 0, srcLength, start, _length); }
04245
04246 inline int32_t
04247 UnicodeString::lastIndexOf(const char16_t *srcChars,
04248 int32_t srcLength,
04249 int32_t start) const {
04250 pinIndex(start);
04251 return lastIndexOf(srcChars, 0, srcLength, start, length() - start);
04252 }
04253
04254 inline int32_t
04255 UnicodeString::lastIndexOf(const UnicodeString& srcText,
04256 int32_t srcStart,
04257 int32_t srcLength,
04258 int32_t start,
04259 int32_t _length) const
04260 {
04261 if(!srcText.isBogus()) {
04262 srcText.pinIndices(srcStart, srcLength);
04263 if(srcLength > 0) {
04264 return lastIndexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
04265 }
04266 }
04267 return -1;
04268 }
04269
04270 inline int32_t
04271 UnicodeString::lastIndexOf(const UnicodeString& text,
04272 int32_t start,
04273 int32_t _length) const
04274 { return lastIndexOf(text, 0, text.length(), start, _length); }
04275
04276 inline int32_t
04277 UnicodeString::lastIndexOf(const UnicodeString& text,
04278 int32_t start) const {
04279 pinIndex(start);
04280 return lastIndexOf(text, 0, text.length(), start, length() - start);
04281 }
04282
04283 inline int32_t
04284 UnicodeString::lastIndexOf(const UnicodeString& text) const
04285 { return lastIndexOf(text, 0, text.length(), 0, length()); }
04286
04287 inline int32_t
04288 UnicodeString::lastIndexOf(char16_t c,
04289 int32_t start,
04290 int32_t _length) const
04291 { return doLastIndexOf(c, start, _length); }
04292
04293 inline int32_t
04294 UnicodeString::lastIndexOf(UChar32 c,
04295 int32_t start,
04296 int32_t _length) const {
04297 return doLastIndexOf(c, start, _length);
04298 }
04299
04300 inline int32_t
04301 UnicodeString::lastIndexOf(char16_t c) const
04302 { return doLastIndexOf(c, 0, length()); }
04303
04304 inline int32_t
04305 UnicodeString::lastIndexOf(UChar32 c) const {
04306 return lastIndexOf(c, 0, length());
04307 }
04308
04309 inline int32_t
04310 UnicodeString::lastIndexOf(char16_t c,
04311 int32_t start) const {
04312 pinIndex(start);
04313 return doLastIndexOf(c, start, length() - start);
04314 }
04315
04316 inline int32_t
04317 UnicodeString::lastIndexOf(UChar32 c,
04318 int32_t start) const {
04319 pinIndex(start);
04320 return lastIndexOf(c, start, length() - start);
04321 }
04322
04323 inline UBool
04324 UnicodeString::startsWith(const UnicodeString& text) const
04325 { return compare(0, text.length(), text, 0, text.length()) == 0; }
04326
04327 inline UBool
04328 UnicodeString::startsWith(const UnicodeString& srcText,
04329 int32_t srcStart,
04330 int32_t srcLength) const
04331 { return doCompare(0, srcLength, srcText, srcStart, srcLength) == 0; }
04332
04333 inline UBool
04334 UnicodeString::startsWith(ConstChar16Ptr srcChars, int32_t srcLength) const {
04335 if(srcLength < 0) {
04336 srcLength = u_strlen(toUCharPtr(srcChars));
04337 }
04338 return doCompare(0, srcLength, srcChars, 0, srcLength) == 0;
04339 }
04340
04341 inline UBool
04342 UnicodeString::startsWith(const char16_t *srcChars, int32_t srcStart, int32_t srcLength) const {
04343 if(srcLength < 0) {
04344 srcLength = u_strlen(toUCharPtr(srcChars));
04345 }
04346 return doCompare(0, srcLength, srcChars, srcStart, srcLength) == 0;
04347 }
04348
04349 inline UBool
04350 UnicodeString::endsWith(const UnicodeString& text) const
04351 { return doCompare(length() - text.length(), text.length(),
04352 text, 0, text.length()) == 0; }
04353
04354 inline UBool
04355 UnicodeString::endsWith(const UnicodeString& srcText,
04356 int32_t srcStart,
04357 int32_t srcLength) const {
04358 srcText.pinIndices(srcStart, srcLength);
04359 return doCompare(length() - srcLength, srcLength,
04360 srcText, srcStart, srcLength) == 0;
04361 }
04362
04363 inline UBool
04364 UnicodeString::endsWith(ConstChar16Ptr srcChars,
04365 int32_t srcLength) const {
04366 if(srcLength < 0) {
04367 srcLength = u_strlen(toUCharPtr(srcChars));
04368 }
04369 return doCompare(length() - srcLength, srcLength,
04370 srcChars, 0, srcLength) == 0;
04371 }
04372
04373 inline UBool
04374 UnicodeString::endsWith(const char16_t *srcChars,
04375 int32_t srcStart,
04376 int32_t srcLength) const {
04377 if(srcLength < 0) {
04378 srcLength = u_strlen(toUCharPtr(srcChars + srcStart));
04379 }
04380 return doCompare(length() - srcLength, srcLength,
04381 srcChars, srcStart, srcLength) == 0;
04382 }
04383
04384
04385
04386
04387 inline UnicodeString&
04388 UnicodeString::replace(int32_t start,
04389 int32_t _length,
04390 const UnicodeString& srcText)
04391 { return doReplace(start, _length, srcText, 0, srcText.length()); }
04392
04393 inline UnicodeString&
04394 UnicodeString::replace(int32_t start,
04395 int32_t _length,
04396 const UnicodeString& srcText,
04397 int32_t srcStart,
04398 int32_t srcLength)
04399 { return doReplace(start, _length, srcText, srcStart, srcLength); }
04400
04401 inline UnicodeString&
04402 UnicodeString::replace(int32_t start,
04403 int32_t _length,
04404 ConstChar16Ptr srcChars,
04405 int32_t srcLength)
04406 { return doReplace(start, _length, srcChars, 0, srcLength); }
04407
04408 inline UnicodeString&
04409 UnicodeString::replace(int32_t start,
04410 int32_t _length,
04411 const char16_t *srcChars,
04412 int32_t srcStart,
04413 int32_t srcLength)
04414 { return doReplace(start, _length, srcChars, srcStart, srcLength); }
04415
04416 inline UnicodeString&
04417 UnicodeString::replace(int32_t start,
04418 int32_t _length,
04419 char16_t srcChar)
04420 { return doReplace(start, _length, &srcChar, 0, 1); }
04421
04422 inline UnicodeString&
04423 UnicodeString::replaceBetween(int32_t start,
04424 int32_t limit,
04425 const UnicodeString& srcText)
04426 { return doReplace(start, limit - start, srcText, 0, srcText.length()); }
04427
04428 inline UnicodeString&
04429 UnicodeString::replaceBetween(int32_t start,
04430 int32_t limit,
04431 const UnicodeString& srcText,
04432 int32_t srcStart,
04433 int32_t srcLimit)
04434 { return doReplace(start, limit - start, srcText, srcStart, srcLimit - srcStart); }
04435
04436 inline UnicodeString&
04437 UnicodeString::findAndReplace(const UnicodeString& oldText,
04438 const UnicodeString& newText)
04439 { return findAndReplace(0, length(), oldText, 0, oldText.length(),
04440 newText, 0, newText.length()); }
04441
04442 inline UnicodeString&
04443 UnicodeString::findAndReplace(int32_t start,
04444 int32_t _length,
04445 const UnicodeString& oldText,
04446 const UnicodeString& newText)
04447 { return findAndReplace(start, _length, oldText, 0, oldText.length(),
04448 newText, 0, newText.length()); }
04449
04450
04451
04452
04453 inline void
04454 UnicodeString::doExtract(int32_t start,
04455 int32_t _length,
04456 UnicodeString& target) const
04457 { target.replace(0, target.length(), *this, start, _length); }
04458
04459 inline void
04460 UnicodeString::extract(int32_t start,
04461 int32_t _length,
04462 Char16Ptr target,
04463 int32_t targetStart) const
04464 { doExtract(start, _length, target, targetStart); }
04465
04466 inline void
04467 UnicodeString::extract(int32_t start,
04468 int32_t _length,
04469 UnicodeString& target) const
04470 { doExtract(start, _length, target); }
04471
04472 #if !UCONFIG_NO_CONVERSION
04473
04474 inline int32_t
04475 UnicodeString::extract(int32_t start,
04476 int32_t _length,
04477 char *dst,
04478 const char *codepage) const
04479
04480 {
04481
04482 return extract(start, _length, dst, dst!=0 ? 0xffffffff : 0, codepage);
04483 }
04484
04485 #endif
04486
04487 inline void
04488 UnicodeString::extractBetween(int32_t start,
04489 int32_t limit,
04490 char16_t *dst,
04491 int32_t dstStart) const {
04492 pinIndex(start);
04493 pinIndex(limit);
04494 doExtract(start, limit - start, dst, dstStart);
04495 }
04496
04497 inline UnicodeString
04498 UnicodeString::tempSubStringBetween(int32_t start, int32_t limit) const {
04499 return tempSubString(start, limit - start);
04500 }
04501
04502 inline char16_t
04503 UnicodeString::doCharAt(int32_t offset) const
04504 {
04505 if((uint32_t)offset < (uint32_t)length()) {
04506 return getArrayStart()[offset];
04507 } else {
04508 return kInvalidUChar;
04509 }
04510 }
04511
04512 inline char16_t
04513 UnicodeString::charAt(int32_t offset) const
04514 { return doCharAt(offset); }
04515
04516 inline char16_t
04517 UnicodeString::operator[] (int32_t offset) const
04518 { return doCharAt(offset); }
04519
04520 inline UBool
04521 UnicodeString::isEmpty() const {
04522
04523 return (fUnion.fFields.fLengthAndFlags>>kLengthShift) == 0;
04524 }
04525
04526
04527
04528
04529 inline void
04530 UnicodeString::setZeroLength() {
04531 fUnion.fFields.fLengthAndFlags &= kAllStorageFlags;
04532 }
04533
04534 inline void
04535 UnicodeString::setShortLength(int32_t len) {
04536
04537 fUnion.fFields.fLengthAndFlags =
04538 (int16_t)((fUnion.fFields.fLengthAndFlags & kAllStorageFlags) | (len << kLengthShift));
04539 }
04540
04541 inline void
04542 UnicodeString::setLength(int32_t len) {
04543 if(len <= kMaxShortLength) {
04544 setShortLength(len);
04545 } else {
04546 fUnion.fFields.fLengthAndFlags |= kLengthIsLarge;
04547 fUnion.fFields.fLength = len;
04548 }
04549 }
04550
04551 inline void
04552 UnicodeString::setToEmpty() {
04553 fUnion.fFields.fLengthAndFlags = kShortString;
04554 }
04555
04556 inline void
04557 UnicodeString::setArray(char16_t *array, int32_t len, int32_t capacity) {
04558 setLength(len);
04559 fUnion.fFields.fArray = array;
04560 fUnion.fFields.fCapacity = capacity;
04561 }
04562
04563 inline UnicodeString&
04564 UnicodeString::operator= (char16_t ch)
04565 { return doReplace(0, length(), &ch, 0, 1); }
04566
04567 inline UnicodeString&
04568 UnicodeString::operator= (UChar32 ch)
04569 { return replace(0, length(), ch); }
04570
04571 inline UnicodeString&
04572 UnicodeString::setTo(const UnicodeString& srcText,
04573 int32_t srcStart,
04574 int32_t srcLength)
04575 {
04576 unBogus();
04577 return doReplace(0, length(), srcText, srcStart, srcLength);
04578 }
04579
04580 inline UnicodeString&
04581 UnicodeString::setTo(const UnicodeString& srcText,
04582 int32_t srcStart)
04583 {
04584 unBogus();
04585 srcText.pinIndex(srcStart);
04586 return doReplace(0, length(), srcText, srcStart, srcText.length() - srcStart);
04587 }
04588
04589 inline UnicodeString&
04590 UnicodeString::setTo(const UnicodeString& srcText)
04591 {
04592 return copyFrom(srcText);
04593 }
04594
04595 inline UnicodeString&
04596 UnicodeString::setTo(const char16_t *srcChars,
04597 int32_t srcLength)
04598 {
04599 unBogus();
04600 return doReplace(0, length(), srcChars, 0, srcLength);
04601 }
04602
04603 inline UnicodeString&
04604 UnicodeString::setTo(char16_t srcChar)
04605 {
04606 unBogus();
04607 return doReplace(0, length(), &srcChar, 0, 1);
04608 }
04609
04610 inline UnicodeString&
04611 UnicodeString::setTo(UChar32 srcChar)
04612 {
04613 unBogus();
04614 return replace(0, length(), srcChar);
04615 }
04616
04617 inline UnicodeString&
04618 UnicodeString::append(const UnicodeString& srcText,
04619 int32_t srcStart,
04620 int32_t srcLength)
04621 { return doAppend(srcText, srcStart, srcLength); }
04622
04623 inline UnicodeString&
04624 UnicodeString::append(const UnicodeString& srcText)
04625 { return doAppend(srcText, 0, srcText.length()); }
04626
04627 inline UnicodeString&
04628 UnicodeString::append(const char16_t *srcChars,
04629 int32_t srcStart,
04630 int32_t srcLength)
04631 { return doAppend(srcChars, srcStart, srcLength); }
04632
04633 inline UnicodeString&
04634 UnicodeString::append(ConstChar16Ptr srcChars,
04635 int32_t srcLength)
04636 { return doAppend(srcChars, 0, srcLength); }
04637
04638 inline UnicodeString&
04639 UnicodeString::append(char16_t srcChar)
04640 { return doAppend(&srcChar, 0, 1); }
04641
04642 inline UnicodeString&
04643 UnicodeString::operator+= (char16_t ch)
04644 { return doAppend(&ch, 0, 1); }
04645
04646 inline UnicodeString&
04647 UnicodeString::operator+= (UChar32 ch) {
04648 return append(ch);
04649 }
04650
04651 inline UnicodeString&
04652 UnicodeString::operator+= (const UnicodeString& srcText)
04653 { return doAppend(srcText, 0, srcText.length()); }
04654
04655 inline UnicodeString&
04656 UnicodeString::insert(int32_t start,
04657 const UnicodeString& srcText,
04658 int32_t srcStart,
04659 int32_t srcLength)
04660 { return doReplace(start, 0, srcText, srcStart, srcLength); }
04661
04662 inline UnicodeString&
04663 UnicodeString::insert(int32_t start,
04664 const UnicodeString& srcText)
04665 { return doReplace(start, 0, srcText, 0, srcText.length()); }
04666
04667 inline UnicodeString&
04668 UnicodeString::insert(int32_t start,
04669 const char16_t *srcChars,
04670 int32_t srcStart,
04671 int32_t srcLength)
04672 { return doReplace(start, 0, srcChars, srcStart, srcLength); }
04673
04674 inline UnicodeString&
04675 UnicodeString::insert(int32_t start,
04676 ConstChar16Ptr srcChars,
04677 int32_t srcLength)
04678 { return doReplace(start, 0, srcChars, 0, srcLength); }
04679
04680 inline UnicodeString&
04681 UnicodeString::insert(int32_t start,
04682 char16_t srcChar)
04683 { return doReplace(start, 0, &srcChar, 0, 1); }
04684
04685 inline UnicodeString&
04686 UnicodeString::insert(int32_t start,
04687 UChar32 srcChar)
04688 { return replace(start, 0, srcChar); }
04689
04690
04691 inline UnicodeString&
04692 UnicodeString::remove()
04693 {
04694
04695 if(isBogus()) {
04696 setToEmpty();
04697 } else {
04698 setZeroLength();
04699 }
04700 return *this;
04701 }
04702
04703 inline UnicodeString&
04704 UnicodeString::remove(int32_t start,
04705 int32_t _length)
04706 {
04707 if(start <= 0 && _length == INT32_MAX) {
04708
04709 return remove();
04710 }
04711 return doReplace(start, _length, NULL, 0, 0);
04712 }
04713
04714 inline UnicodeString&
04715 UnicodeString::removeBetween(int32_t start,
04716 int32_t limit)
04717 { return doReplace(start, limit - start, NULL, 0, 0); }
04718
04719 inline UnicodeString &
04720 UnicodeString::retainBetween(int32_t start, int32_t limit) {
04721 truncate(limit);
04722 return doReplace(0, start, NULL, 0, 0);
04723 }
04724
04725 inline UBool
04726 UnicodeString::truncate(int32_t targetLength)
04727 {
04728 if(isBogus() && targetLength == 0) {
04729
04730 unBogus();
04731 return FALSE;
04732 } else if((uint32_t)targetLength < (uint32_t)length()) {
04733 setLength(targetLength);
04734 return TRUE;
04735 } else {
04736 return FALSE;
04737 }
04738 }
04739
04740 inline UnicodeString&
04741 UnicodeString::reverse()
04742 { return doReverse(0, length()); }
04743
04744 inline UnicodeString&
04745 UnicodeString::reverse(int32_t start,
04746 int32_t _length)
04747 { return doReverse(start, _length); }
04748
04749 U_NAMESPACE_END
04750
04751 #endif