00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef UNISTR_H
00022 #define UNISTR_H
00023
00029 #include "unicode/utypes.h"
00030 #include "unicode/rep.h"
00031 #include "unicode/std_string.h"
00032 #include "unicode/stringpiece.h"
00033 #include "unicode/bytestream.h"
00034 #include "unicode/ucasemap.h"
00035
00036 struct UConverter;
00037
00038 #ifndef U_COMPARE_CODE_POINT_ORDER
00039
00045 #define U_COMPARE_CODE_POINT_ORDER 0x8000
00046 #endif
00047
00048 #ifndef USTRING_H
00049
00052 U_STABLE int32_t U_EXPORT2
00053 u_strlen(const UChar *s);
00054 #endif
00055
00060 #ifndef U_STRING_CASE_MAPPER_DEFINED
00061 #define U_STRING_CASE_MAPPER_DEFINED
00062
00067 typedef int32_t U_CALLCONV
00068 UStringCaseMapper(const UCaseMap *csm,
00069 UChar *dest, int32_t destCapacity,
00070 const UChar *src, int32_t srcLength,
00071 UErrorCode *pErrorCode);
00072
00073 #endif
00074
00075 U_NAMESPACE_BEGIN
00076
00077 class BreakIterator;
00078 class Locale;
00079 class StringCharacterIterator;
00080 class UnicodeStringAppendable;
00081
00082
00083
00094 #define US_INV icu::UnicodeString::kInvariant
00095
00113 #if defined(U_DECLARE_UTF16)
00114 # define UNICODE_STRING(cs, _length) icu::UnicodeString(TRUE, (const UChar *)U_DECLARE_UTF16(cs), _length)
00115 #elif U_SIZEOF_WCHAR_T==U_SIZEOF_UCHAR && (U_CHARSET_FAMILY==U_ASCII_FAMILY || (U_SIZEOF_UCHAR == 2 && defined(U_WCHAR_IS_UTF16)))
00116 # define UNICODE_STRING(cs, _length) icu::UnicodeString(TRUE, (const UChar *)L ## cs, _length)
00117 #elif U_SIZEOF_UCHAR==1 && U_CHARSET_FAMILY==U_ASCII_FAMILY
00118 # define UNICODE_STRING(cs, _length) icu::UnicodeString(TRUE, (const UChar *)cs, _length)
00119 #else
00120 # define UNICODE_STRING(cs, _length) icu::UnicodeString(cs, _length, US_INV)
00121 #endif
00122
00136 #define UNICODE_STRING_SIMPLE(cs) UNICODE_STRING(cs, -1)
00137
00145 #ifndef UNISTR_FROM_CHAR_EXPLICIT
00146 # if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION)
00147
00148 # define UNISTR_FROM_CHAR_EXPLICIT explicit
00149 # else
00150
00151 # define UNISTR_FROM_CHAR_EXPLICIT
00152 # endif
00153 #endif
00154
00165 #ifndef UNISTR_FROM_STRING_EXPLICIT
00166 # if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION)
00167
00168 # define UNISTR_FROM_STRING_EXPLICIT explicit
00169 # else
00170
00171 # define UNISTR_FROM_STRING_EXPLICIT
00172 # endif
00173 #endif
00174
00175
00176
00210 #ifndef UNISTR_OBJECT_SIZE
00211 # define UNISTR_OBJECT_SIZE 64
00212 #endif
00213
00293 class U_COMMON_API UnicodeString : public Replaceable
00294 {
00295 public:
00296
00305 enum EInvariant {
00310 kInvariant
00311 };
00312
00313
00314
00315
00316
00317
00318
00326 inline UBool operator== (const UnicodeString& text) const;
00327
00335 inline UBool operator!= (const UnicodeString& text) const;
00336
00344 inline UBool operator> (const UnicodeString& text) const;
00345
00353 inline UBool operator< (const UnicodeString& text) const;
00354
00362 inline UBool operator>= (const UnicodeString& text) const;
00363
00371 inline UBool operator<= (const UnicodeString& text) const;
00372
00384 inline int8_t compare(const UnicodeString& text) const;
00385
00401 inline int8_t compare(int32_t start,
00402 int32_t length,
00403 const UnicodeString& text) const;
00404
00422 inline int8_t compare(int32_t start,
00423 int32_t length,
00424 const UnicodeString& srcText,
00425 int32_t srcStart,
00426 int32_t srcLength) const;
00427
00440 inline int8_t compare(const UChar *srcChars,
00441 int32_t srcLength) const;
00442
00457 inline int8_t compare(int32_t start,
00458 int32_t length,
00459 const UChar *srcChars) const;
00460
00478 inline int8_t compare(int32_t start,
00479 int32_t length,
00480 const UChar *srcChars,
00481 int32_t srcStart,
00482 int32_t srcLength) const;
00483
00501 inline int8_t compareBetween(int32_t start,
00502 int32_t limit,
00503 const UnicodeString& srcText,
00504 int32_t srcStart,
00505 int32_t srcLimit) const;
00506
00524 inline int8_t compareCodePointOrder(const UnicodeString& text) const;
00525
00545 inline int8_t compareCodePointOrder(int32_t start,
00546 int32_t length,
00547 const UnicodeString& srcText) const;
00548
00570 inline int8_t compareCodePointOrder(int32_t start,
00571 int32_t length,
00572 const UnicodeString& srcText,
00573 int32_t srcStart,
00574 int32_t srcLength) const;
00575
00594 inline int8_t compareCodePointOrder(const UChar *srcChars,
00595 int32_t srcLength) const;
00596
00616 inline int8_t compareCodePointOrder(int32_t start,
00617 int32_t length,
00618 const UChar *srcChars) const;
00619
00641 inline int8_t compareCodePointOrder(int32_t start,
00642 int32_t length,
00643 const UChar *srcChars,
00644 int32_t srcStart,
00645 int32_t srcLength) const;
00646
00668 inline int8_t compareCodePointOrderBetween(int32_t start,
00669 int32_t limit,
00670 const UnicodeString& srcText,
00671 int32_t srcStart,
00672 int32_t srcLimit) const;
00673
00692 inline int8_t caseCompare(const UnicodeString& text, uint32_t options) const;
00693
00714 inline int8_t caseCompare(int32_t start,
00715 int32_t length,
00716 const UnicodeString& srcText,
00717 uint32_t options) const;
00718
00741 inline int8_t caseCompare(int32_t start,
00742 int32_t length,
00743 const UnicodeString& srcText,
00744 int32_t srcStart,
00745 int32_t srcLength,
00746 uint32_t options) const;
00747
00767 inline int8_t caseCompare(const UChar *srcChars,
00768 int32_t srcLength,
00769 uint32_t options) const;
00770
00791 inline int8_t caseCompare(int32_t start,
00792 int32_t length,
00793 const UChar *srcChars,
00794 uint32_t options) const;
00795
00818 inline int8_t caseCompare(int32_t start,
00819 int32_t length,
00820 const UChar *srcChars,
00821 int32_t srcStart,
00822 int32_t srcLength,
00823 uint32_t options) const;
00824
00847 inline int8_t caseCompareBetween(int32_t start,
00848 int32_t limit,
00849 const UnicodeString& srcText,
00850 int32_t srcStart,
00851 int32_t srcLimit,
00852 uint32_t options) const;
00853
00861 inline UBool startsWith(const UnicodeString& text) const;
00862
00873 inline UBool startsWith(const UnicodeString& srcText,
00874 int32_t srcStart,
00875 int32_t srcLength) const;
00876
00885 inline UBool startsWith(const UChar *srcChars,
00886 int32_t srcLength) const;
00887
00897 inline UBool startsWith(const UChar *srcChars,
00898 int32_t srcStart,
00899 int32_t srcLength) const;
00900
00908 inline UBool endsWith(const UnicodeString& text) const;
00909
00920 inline UBool endsWith(const UnicodeString& srcText,
00921 int32_t srcStart,
00922 int32_t srcLength) const;
00923
00932 inline UBool endsWith(const UChar *srcChars,
00933 int32_t srcLength) const;
00934
00945 inline UBool endsWith(const UChar *srcChars,
00946 int32_t srcStart,
00947 int32_t srcLength) const;
00948
00949
00950
00951
00960 inline int32_t indexOf(const UnicodeString& text) const;
00961
00971 inline int32_t indexOf(const UnicodeString& text,
00972 int32_t start) const;
00973
00985 inline int32_t indexOf(const UnicodeString& text,
00986 int32_t start,
00987 int32_t length) const;
00988
01005 inline int32_t indexOf(const UnicodeString& srcText,
01006 int32_t srcStart,
01007 int32_t srcLength,
01008 int32_t start,
01009 int32_t length) const;
01010
01022 inline int32_t indexOf(const UChar *srcChars,
01023 int32_t srcLength,
01024 int32_t start) const;
01025
01038 inline int32_t indexOf(const UChar *srcChars,
01039 int32_t srcLength,
01040 int32_t start,
01041 int32_t length) const;
01042
01059 int32_t indexOf(const UChar *srcChars,
01060 int32_t srcStart,
01061 int32_t srcLength,
01062 int32_t start,
01063 int32_t length) const;
01064
01072 inline int32_t indexOf(UChar c) const;
01073
01082 inline int32_t indexOf(UChar32 c) const;
01083
01092 inline int32_t indexOf(UChar c,
01093 int32_t start) const;
01094
01104 inline int32_t indexOf(UChar32 c,
01105 int32_t start) const;
01106
01117 inline int32_t indexOf(UChar c,
01118 int32_t start,
01119 int32_t length) const;
01120
01132 inline int32_t indexOf(UChar32 c,
01133 int32_t start,
01134 int32_t length) const;
01135
01144 inline int32_t lastIndexOf(const UnicodeString& text) const;
01145
01155 inline int32_t lastIndexOf(const UnicodeString& text,
01156 int32_t start) const;
01157
01169 inline int32_t lastIndexOf(const UnicodeString& text,
01170 int32_t start,
01171 int32_t length) const;
01172
01189 inline int32_t lastIndexOf(const UnicodeString& srcText,
01190 int32_t srcStart,
01191 int32_t srcLength,
01192 int32_t start,
01193 int32_t length) const;
01194
01205 inline int32_t lastIndexOf(const UChar *srcChars,
01206 int32_t srcLength,
01207 int32_t start) const;
01208
01221 inline int32_t lastIndexOf(const UChar *srcChars,
01222 int32_t srcLength,
01223 int32_t start,
01224 int32_t length) const;
01225
01242 int32_t lastIndexOf(const UChar *srcChars,
01243 int32_t srcStart,
01244 int32_t srcLength,
01245 int32_t start,
01246 int32_t length) const;
01247
01255 inline int32_t lastIndexOf(UChar c) const;
01256
01265 inline int32_t lastIndexOf(UChar32 c) const;
01266
01275 inline int32_t lastIndexOf(UChar c,
01276 int32_t start) const;
01277
01287 inline int32_t lastIndexOf(UChar32 c,
01288 int32_t start) const;
01289
01300 inline int32_t lastIndexOf(UChar c,
01301 int32_t start,
01302 int32_t length) const;
01303
01315 inline int32_t lastIndexOf(UChar32 c,
01316 int32_t start,
01317 int32_t length) const;
01318
01319
01320
01321
01330 inline UChar charAt(int32_t offset) const;
01331
01339 inline UChar operator[] (int32_t offset) const;
01340
01352 UChar32 char32At(int32_t offset) const;
01353
01369 int32_t getChar32Start(int32_t offset) const;
01370
01387 int32_t getChar32Limit(int32_t offset) const;
01388
01439 int32_t moveIndex32(int32_t index, int32_t delta) const;
01440
01441
01442
01458 inline void extract(int32_t start,
01459 int32_t length,
01460 UChar *dst,
01461 int32_t dstStart = 0) const;
01462
01484 int32_t
01485 extract(UChar *dest, int32_t destCapacity,
01486 UErrorCode &errorCode) const;
01487
01498 inline void extract(int32_t start,
01499 int32_t length,
01500 UnicodeString& target) const;
01501
01513 inline void extractBetween(int32_t start,
01514 int32_t limit,
01515 UChar *dst,
01516 int32_t dstStart = 0) const;
01517
01527 virtual void extractBetween(int32_t start,
01528 int32_t limit,
01529 UnicodeString& target) const;
01530
01552 int32_t extract(int32_t start,
01553 int32_t startLength,
01554 char *target,
01555 int32_t targetCapacity,
01556 enum EInvariant inv) const;
01557
01558 #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
01559
01579 int32_t extract(int32_t start,
01580 int32_t startLength,
01581 char *target,
01582 uint32_t targetLength) const;
01583
01584 #endif
01585
01586 #if !UCONFIG_NO_CONVERSION
01587
01613 inline int32_t extract(int32_t start,
01614 int32_t startLength,
01615 char *target,
01616 const char *codepage = 0) const;
01617
01647 int32_t extract(int32_t start,
01648 int32_t startLength,
01649 char *target,
01650 uint32_t targetLength,
01651 const char *codepage) const;
01652
01670 int32_t extract(char *dest, int32_t destCapacity,
01671 UConverter *cnv,
01672 UErrorCode &errorCode) const;
01673
01674 #endif
01675
01689 UnicodeString tempSubString(int32_t start=0, int32_t length=INT32_MAX) const;
01690
01701 inline UnicodeString tempSubStringBetween(int32_t start, int32_t limit=INT32_MAX) const;
01702
01714 void toUTF8(ByteSink &sink) const;
01715
01716 #if U_HAVE_STD_STRING
01717
01730 template<typename StringClass>
01731 StringClass &toUTF8String(StringClass &result) const {
01732 StringByteSink<StringClass> sbs(&result);
01733 toUTF8(sbs);
01734 return result;
01735 }
01736
01737 #endif
01738
01754 int32_t toUTF32(UChar32 *utf32, int32_t capacity, UErrorCode &errorCode) const;
01755
01756
01757
01766 inline int32_t length(void) const;
01767
01781 int32_t
01782 countChar32(int32_t start=0, int32_t length=INT32_MAX) const;
01783
01807 UBool
01808 hasMoreChar32Than(int32_t start, int32_t length, int32_t number) const;
01809
01815 inline UBool isEmpty(void) const;
01816
01826 inline int32_t getCapacity(void) const;
01827
01828
01829
01835 inline int32_t hashCode(void) const;
01836
01849 inline UBool isBogus(void) const;
01850
01851
01852
01853
01854
01855
01856
01857
01876 UnicodeString &operator=(const UnicodeString &srcText);
01877
01903 UnicodeString &fastCopyFrom(const UnicodeString &src);
01904
01905 #ifndef U_HIDE_DRAFT_API
01906 #if U_HAVE_RVALUE_REFERENCES
01907
01915 UnicodeString &operator=(UnicodeString &&src) U_NOEXCEPT {
01916 return moveFrom(src);
01917 }
01918 #endif
01919
01929 UnicodeString &moveFrom(UnicodeString &src) U_NOEXCEPT;
01930
01936 void swap(UnicodeString &other) U_NOEXCEPT;
01937 #endif
01938
01945 friend U_COMMON_API inline void U_EXPORT2
01946 swap(UnicodeString &s1, UnicodeString &s2) U_NOEXCEPT {
01947 s1.swap(s2);
01948 }
01949
01957 inline UnicodeString& operator= (UChar ch);
01958
01966 inline UnicodeString& operator= (UChar32 ch);
01967
01979 inline UnicodeString& setTo(const UnicodeString& srcText,
01980 int32_t srcStart);
01981
01995 inline UnicodeString& setTo(const UnicodeString& srcText,
01996 int32_t srcStart,
01997 int32_t srcLength);
01998
02007 inline UnicodeString& setTo(const UnicodeString& srcText);
02008
02017 inline UnicodeString& setTo(const UChar *srcChars,
02018 int32_t srcLength);
02019
02028 UnicodeString& setTo(UChar srcChar);
02029
02038 UnicodeString& setTo(UChar32 srcChar);
02039
02063 UnicodeString &setTo(UBool isTerminated,
02064 const UChar *text,
02065 int32_t textLength);
02066
02086 UnicodeString &setTo(UChar *buffer,
02087 int32_t buffLength,
02088 int32_t buffCapacity);
02089
02130 void setToBogus();
02131
02139 UnicodeString& setCharAt(int32_t offset,
02140 UChar ch);
02141
02142
02143
02144
02152 inline UnicodeString& operator+= (UChar ch);
02153
02161 inline UnicodeString& operator+= (UChar32 ch);
02162
02170 inline UnicodeString& operator+= (const UnicodeString& srcText);
02171
02186 inline UnicodeString& append(const UnicodeString& srcText,
02187 int32_t srcStart,
02188 int32_t srcLength);
02189
02197 inline UnicodeString& append(const UnicodeString& srcText);
02198
02212 inline UnicodeString& append(const UChar *srcChars,
02213 int32_t srcStart,
02214 int32_t srcLength);
02215
02225 inline UnicodeString& append(const UChar *srcChars,
02226 int32_t srcLength);
02227
02234 inline UnicodeString& append(UChar srcChar);
02235
02242 UnicodeString& append(UChar32 srcChar);
02243
02244
02245
02246
02260 inline UnicodeString& insert(int32_t start,
02261 const UnicodeString& srcText,
02262 int32_t srcStart,
02263 int32_t srcLength);
02264
02273 inline UnicodeString& insert(int32_t start,
02274 const UnicodeString& srcText);
02275
02289 inline UnicodeString& insert(int32_t start,
02290 const UChar *srcChars,
02291 int32_t srcStart,
02292 int32_t srcLength);
02293
02303 inline UnicodeString& insert(int32_t start,
02304 const UChar *srcChars,
02305 int32_t srcLength);
02306
02315 inline UnicodeString& insert(int32_t start,
02316 UChar srcChar);
02317
02326 inline UnicodeString& insert(int32_t start,
02327 UChar32 srcChar);
02328
02329
02330
02331
02349 UnicodeString& replace(int32_t start,
02350 int32_t length,
02351 const UnicodeString& srcText,
02352 int32_t srcStart,
02353 int32_t srcLength);
02354
02367 UnicodeString& replace(int32_t start,
02368 int32_t length,
02369 const UnicodeString& srcText);
02370
02388 UnicodeString& replace(int32_t start,
02389 int32_t length,
02390 const UChar *srcChars,
02391 int32_t srcStart,
02392 int32_t srcLength);
02393
02406 inline UnicodeString& replace(int32_t start,
02407 int32_t length,
02408 const UChar *srcChars,
02409 int32_t srcLength);
02410
02422 inline UnicodeString& replace(int32_t start,
02423 int32_t length,
02424 UChar srcChar);
02425
02437 UnicodeString& replace(int32_t start, int32_t length, UChar32 srcChar);
02438
02448 inline UnicodeString& replaceBetween(int32_t start,
02449 int32_t limit,
02450 const UnicodeString& srcText);
02451
02466 inline UnicodeString& replaceBetween(int32_t start,
02467 int32_t limit,
02468 const UnicodeString& srcText,
02469 int32_t srcStart,
02470 int32_t srcLimit);
02471
02482 virtual void handleReplaceBetween(int32_t start,
02483 int32_t limit,
02484 const UnicodeString& text);
02485
02491 virtual UBool hasMetaData() const;
02492
02508 virtual void copy(int32_t start, int32_t limit, int32_t dest);
02509
02510
02511
02520 inline UnicodeString& findAndReplace(const UnicodeString& oldText,
02521 const UnicodeString& newText);
02522
02534 inline UnicodeString& findAndReplace(int32_t start,
02535 int32_t length,
02536 const UnicodeString& oldText,
02537 const UnicodeString& newText);
02538
02556 UnicodeString& findAndReplace(int32_t start,
02557 int32_t length,
02558 const UnicodeString& oldText,
02559 int32_t oldStart,
02560 int32_t oldLength,
02561 const UnicodeString& newText,
02562 int32_t newStart,
02563 int32_t newLength);
02564
02565
02566
02567
02573 inline UnicodeString& remove(void);
02574
02583 inline UnicodeString& remove(int32_t start,
02584 int32_t length = (int32_t)INT32_MAX);
02585
02594 inline UnicodeString& removeBetween(int32_t start,
02595 int32_t limit = (int32_t)INT32_MAX);
02596
02606 inline UnicodeString &retainBetween(int32_t start, int32_t limit = INT32_MAX);
02607
02608
02609
02621 UBool padLeading(int32_t targetLength,
02622 UChar padChar = 0x0020);
02623
02635 UBool padTrailing(int32_t targetLength,
02636 UChar padChar = 0x0020);
02637
02644 inline UBool truncate(int32_t targetLength);
02645
02651 UnicodeString& trim(void);
02652
02653
02654
02655
02661 inline UnicodeString& reverse(void);
02662
02671 inline UnicodeString& reverse(int32_t start,
02672 int32_t length);
02673
02680 UnicodeString& toUpper(void);
02681
02689 UnicodeString& toUpper(const Locale& locale);
02690
02697 UnicodeString& toLower(void);
02698
02706 UnicodeString& toLower(const Locale& locale);
02707
02708 #if !UCONFIG_NO_BREAK_ITERATION
02709
02736 UnicodeString &toTitle(BreakIterator *titleIter);
02737
02765 UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale);
02766
02798 UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale, uint32_t options);
02799
02800 #endif
02801
02815 UnicodeString &foldCase(uint32_t options=0 );
02816
02817
02818
02819
02820
02864 UChar *getBuffer(int32_t minCapacity);
02865
02886 void releaseBuffer(int32_t newLength=-1);
02887
02918 inline const UChar *getBuffer() const;
02919
02953 const UChar *getTerminatedBuffer();
02954
02955
02956
02957
02958
02962 inline UnicodeString();
02963
02975 UnicodeString(int32_t capacity, UChar32 c, int32_t count);
02976
02986 UNISTR_FROM_CHAR_EXPLICIT UnicodeString(UChar ch);
02987
02997 UNISTR_FROM_CHAR_EXPLICIT UnicodeString(UChar32 ch);
02998
03009 UNISTR_FROM_STRING_EXPLICIT UnicodeString(const UChar *text);
03010
03018 UnicodeString(const UChar *text,
03019 int32_t textLength);
03020
03043 UnicodeString(UBool isTerminated,
03044 const UChar *text,
03045 int32_t textLength);
03046
03065 UnicodeString(UChar *buffer, int32_t buffLength, int32_t buffCapacity);
03066
03067 #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
03068
03088 UNISTR_FROM_STRING_EXPLICIT UnicodeString(const char *codepageData);
03089
03098 UnicodeString(const char *codepageData, int32_t dataLength);
03099
03100 #endif
03101
03102 #if !UCONFIG_NO_CONVERSION
03103
03121 UnicodeString(const char *codepageData, const char *codepage);
03122
03140 UnicodeString(const char *codepageData, int32_t dataLength, const char *codepage);
03141
03163 UnicodeString(
03164 const char *src, int32_t srcLength,
03165 UConverter *cnv,
03166 UErrorCode &errorCode);
03167
03168 #endif
03169
03194 UnicodeString(const char *src, int32_t length, enum EInvariant inv);
03195
03196
03213 UnicodeString(const UnicodeString& that);
03214
03215 #ifndef U_HIDE_DRAFT_API
03216 #if U_HAVE_RVALUE_REFERENCES
03217
03223 UnicodeString(UnicodeString &&src) U_NOEXCEPT;
03224 #endif
03225 #endif
03226
03233 UnicodeString(const UnicodeString& src, int32_t srcStart);
03234
03242 UnicodeString(const UnicodeString& src, int32_t srcStart, int32_t srcLength);
03243
03260 virtual Replaceable *clone() const;
03261
03265 virtual ~UnicodeString();
03266
03280 static UnicodeString fromUTF8(const StringPiece &utf8);
03281
03293 static UnicodeString fromUTF32(const UChar32 *utf32, int32_t length);
03294
03295
03296
03331 UnicodeString unescape() const;
03332
03352 UChar32 unescapeAt(int32_t &offset) const;
03353
03359 static UClassID U_EXPORT2 getStaticClassID();
03360
03366 virtual UClassID getDynamicClassID() const;
03367
03368
03369
03370
03371
03372 protected:
03377 virtual int32_t getLength() const;
03378
03384 virtual UChar getCharAt(int32_t offset) const;
03385
03391 virtual UChar32 getChar32At(int32_t offset) const;
03392
03393 private:
03394
03395 UnicodeString &setToUTF8(const StringPiece &utf8);
03396
03397
03398
03399
03400
03401 int32_t
03402 toUTF8(int32_t start, int32_t len,
03403 char *target, int32_t capacity) const;
03404
03409 UBool doEquals(const UnicodeString &text, int32_t len) const;
03410
03411 inline int8_t
03412 doCompare(int32_t start,
03413 int32_t length,
03414 const UnicodeString& srcText,
03415 int32_t srcStart,
03416 int32_t srcLength) const;
03417
03418 int8_t doCompare(int32_t start,
03419 int32_t length,
03420 const UChar *srcChars,
03421 int32_t srcStart,
03422 int32_t srcLength) const;
03423
03424 inline int8_t
03425 doCompareCodePointOrder(int32_t start,
03426 int32_t length,
03427 const UnicodeString& srcText,
03428 int32_t srcStart,
03429 int32_t srcLength) const;
03430
03431 int8_t doCompareCodePointOrder(int32_t start,
03432 int32_t length,
03433 const UChar *srcChars,
03434 int32_t srcStart,
03435 int32_t srcLength) const;
03436
03437 inline int8_t
03438 doCaseCompare(int32_t start,
03439 int32_t length,
03440 const UnicodeString &srcText,
03441 int32_t srcStart,
03442 int32_t srcLength,
03443 uint32_t options) const;
03444
03445 int8_t
03446 doCaseCompare(int32_t start,
03447 int32_t length,
03448 const UChar *srcChars,
03449 int32_t srcStart,
03450 int32_t srcLength,
03451 uint32_t options) const;
03452
03453 int32_t doIndexOf(UChar c,
03454 int32_t start,
03455 int32_t length) const;
03456
03457 int32_t doIndexOf(UChar32 c,
03458 int32_t start,
03459 int32_t length) const;
03460
03461 int32_t doLastIndexOf(UChar c,
03462 int32_t start,
03463 int32_t length) const;
03464
03465 int32_t doLastIndexOf(UChar32 c,
03466 int32_t start,
03467 int32_t length) const;
03468
03469 void doExtract(int32_t start,
03470 int32_t length,
03471 UChar *dst,
03472 int32_t dstStart) const;
03473
03474 inline void doExtract(int32_t start,
03475 int32_t length,
03476 UnicodeString& target) const;
03477
03478 inline UChar doCharAt(int32_t offset) const;
03479
03480 UnicodeString& doReplace(int32_t start,
03481 int32_t length,
03482 const UnicodeString& srcText,
03483 int32_t srcStart,
03484 int32_t srcLength);
03485
03486 UnicodeString& doReplace(int32_t start,
03487 int32_t length,
03488 const UChar *srcChars,
03489 int32_t srcStart,
03490 int32_t srcLength);
03491
03492 UnicodeString& doAppend(const UnicodeString& src, int32_t srcStart, int32_t srcLength);
03493 UnicodeString& doAppend(const UChar *srcChars, int32_t srcStart, int32_t srcLength);
03494
03495 UnicodeString& doReverse(int32_t start,
03496 int32_t length);
03497
03498
03499 int32_t doHashCode(void) const;
03500
03501
03502
03503 inline UChar* getArrayStart(void);
03504 inline const UChar* getArrayStart(void) const;
03505
03506 inline UBool hasShortLength() const;
03507 inline int32_t getShortLength() const;
03508
03509
03510
03511 inline UBool isWritable() const;
03512
03513
03514 inline UBool isBufferWritable() const;
03515
03516
03517 inline void setZeroLength();
03518 inline void setShortLength(int32_t len);
03519 inline void setLength(int32_t len);
03520 inline void setToEmpty();
03521 inline void setArray(UChar *array, int32_t len, int32_t capacity);
03522
03523
03524
03525
03526
03527
03528 UBool allocate(int32_t capacity);
03529
03530
03531 void releaseArray(void);
03532
03533
03534 void unBogus();
03535
03536
03537 UnicodeString ©From(const UnicodeString &src, UBool fastCopy=FALSE);
03538
03539
03540 void copyFieldsFrom(UnicodeString &src, UBool setSrcToBogus) U_NOEXCEPT;
03541
03542
03543 inline void pinIndex(int32_t& start) const;
03544 inline void pinIndices(int32_t& start,
03545 int32_t& length) const;
03546
03547 #if !UCONFIG_NO_CONVERSION
03548
03549
03550 int32_t doExtract(int32_t start, int32_t length,
03551 char *dest, int32_t destCapacity,
03552 UConverter *cnv,
03553 UErrorCode &errorCode) const;
03554
03555
03556
03557
03558
03559
03560
03561
03562
03563
03564
03565 void doCodepageCreate(const char *codepageData,
03566 int32_t dataLength,
03567 const char *codepage);
03568
03569
03570
03571
03572
03573 void
03574 doCodepageCreate(const char *codepageData,
03575 int32_t dataLength,
03576 UConverter *converter,
03577 UErrorCode &status);
03578
03579 #endif
03580
03581
03582
03583
03584
03585
03586
03587
03588
03589
03590
03591
03592 UBool cloneArrayIfNeeded(int32_t newCapacity = -1,
03593 int32_t growCapacity = -1,
03594 UBool doCopyArray = TRUE,
03595 int32_t **pBufferToDelete = 0,
03596 UBool forceClone = FALSE);
03597
03603 UnicodeString &
03604 caseMap(const UCaseMap *csm, UStringCaseMapper *stringCaseMapper);
03605
03606
03607 void addRef(void);
03608 int32_t removeRef(void);
03609 int32_t refCount(void) const;
03610
03611
03612 enum {
03618 US_STACKBUF_SIZE=(int32_t)(UNISTR_OBJECT_SIZE-sizeof(void *)-2)/U_SIZEOF_UCHAR,
03619 kInvalidUChar=0xffff,
03620 kGrowSize=128,
03621 kInvalidHashCode=0,
03622 kEmptyHashCode=1,
03623
03624
03625 kIsBogus=1,
03626 kUsingStackBuffer=2,
03627 kRefCounted=4,
03628 kBufferIsReadonly=8,
03629 kOpenGetBuffer=16,
03630
03631 kAllStorageFlags=0x1f,
03632
03633 kLengthShift=5,
03634 kLength1=1<<kLengthShift,
03635 kMaxShortLength=0x3ff,
03636 kLengthIsLarge=0xffe0,
03637
03638
03639 kShortString=kUsingStackBuffer,
03640 kLongString=kRefCounted,
03641 kReadonlyAlias=kBufferIsReadonly,
03642 kWritableAlias=0
03643 };
03644
03645 friend class UnicodeStringAppendable;
03646
03647 union StackBufferOrFields;
03648 friend union StackBufferOrFields;
03649
03650
03651
03652
03653
03654
03655
03656
03657
03658
03659
03660
03661
03662
03663
03664
03665
03666
03667
03668
03669
03670
03671
03672
03673
03674
03675
03676
03677
03678
03679
03680
03681
03682
03683
03684
03685
03686
03687
03688
03689
03690
03691 union StackBufferOrFields {
03692
03693
03694 struct {
03695 int16_t fLengthAndFlags;
03696 UChar fBuffer[US_STACKBUF_SIZE];
03697 } fStackFields;
03698 struct {
03699 int16_t fLengthAndFlags;
03700 int32_t fLength;
03701 int32_t fCapacity;
03702
03703
03704 UChar *fArray;
03705 } fFields;
03706 } fUnion;
03707 };
03708
03717 U_COMMON_API UnicodeString U_EXPORT2
03718 operator+ (const UnicodeString &s1, const UnicodeString &s2);
03719
03720
03721
03722
03723
03724
03725
03726
03727
03728 inline void
03729 UnicodeString::pinIndex(int32_t& start) const
03730 {
03731
03732 if(start < 0) {
03733 start = 0;
03734 } else if(start > length()) {
03735 start = length();
03736 }
03737 }
03738
03739 inline void
03740 UnicodeString::pinIndices(int32_t& start,
03741 int32_t& _length) const
03742 {
03743
03744 int32_t len = length();
03745 if(start < 0) {
03746 start = 0;
03747 } else if(start > len) {
03748 start = len;
03749 }
03750 if(_length < 0) {
03751 _length = 0;
03752 } else if(_length > (len - start)) {
03753 _length = (len - start);
03754 }
03755 }
03756
03757 inline UChar*
03758 UnicodeString::getArrayStart() {
03759 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
03760 fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
03761 }
03762
03763 inline const UChar*
03764 UnicodeString::getArrayStart() const {
03765 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
03766 fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
03767 }
03768
03769
03770
03771
03772
03773 inline
03774 UnicodeString::UnicodeString() {
03775 fUnion.fStackFields.fLengthAndFlags=kShortString;
03776 }
03777
03778
03779
03780
03781 inline UBool
03782 UnicodeString::hasShortLength() const {
03783 return fUnion.fFields.fLengthAndFlags>=0;
03784 }
03785
03786 inline int32_t
03787 UnicodeString::getShortLength() const {
03788
03789
03790 return fUnion.fFields.fLengthAndFlags>>kLengthShift;
03791 }
03792
03793 inline int32_t
03794 UnicodeString::length() const {
03795 return hasShortLength() ? getShortLength() : fUnion.fFields.fLength;
03796 }
03797
03798 inline int32_t
03799 UnicodeString::getCapacity() const {
03800 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
03801 US_STACKBUF_SIZE : fUnion.fFields.fCapacity;
03802 }
03803
03804 inline int32_t
03805 UnicodeString::hashCode() const
03806 { return doHashCode(); }
03807
03808 inline UBool
03809 UnicodeString::isBogus() const
03810 { return (UBool)(fUnion.fFields.fLengthAndFlags & kIsBogus); }
03811
03812 inline UBool
03813 UnicodeString::isWritable() const
03814 { return (UBool)!(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus)); }
03815
03816 inline UBool
03817 UnicodeString::isBufferWritable() const
03818 {
03819 return (UBool)(
03820 !(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus|kBufferIsReadonly)) &&
03821 (!(fUnion.fFields.fLengthAndFlags&kRefCounted) || refCount()==1));
03822 }
03823
03824 inline const UChar *
03825 UnicodeString::getBuffer() const {
03826 if(fUnion.fFields.fLengthAndFlags&(kIsBogus|kOpenGetBuffer)) {
03827 return 0;
03828 } else if(fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) {
03829 return fUnion.fStackFields.fBuffer;
03830 } else {
03831 return fUnion.fFields.fArray;
03832 }
03833 }
03834
03835
03836
03837
03838 inline int8_t
03839 UnicodeString::doCompare(int32_t start,
03840 int32_t thisLength,
03841 const UnicodeString& srcText,
03842 int32_t srcStart,
03843 int32_t srcLength) const
03844 {
03845 if(srcText.isBogus()) {
03846 return (int8_t)!isBogus();
03847 } else {
03848 srcText.pinIndices(srcStart, srcLength);
03849 return doCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
03850 }
03851 }
03852
03853 inline UBool
03854 UnicodeString::operator== (const UnicodeString& text) const
03855 {
03856 if(isBogus()) {
03857 return text.isBogus();
03858 } else {
03859 int32_t len = length(), textLength = text.length();
03860 return !text.isBogus() && len == textLength && doEquals(text, len);
03861 }
03862 }
03863
03864 inline UBool
03865 UnicodeString::operator!= (const UnicodeString& text) const
03866 { return (! operator==(text)); }
03867
03868 inline UBool
03869 UnicodeString::operator> (const UnicodeString& text) const
03870 { return doCompare(0, length(), text, 0, text.length()) == 1; }
03871
03872 inline UBool
03873 UnicodeString::operator< (const UnicodeString& text) const
03874 { return doCompare(0, length(), text, 0, text.length()) == -1; }
03875
03876 inline UBool
03877 UnicodeString::operator>= (const UnicodeString& text) const
03878 { return doCompare(0, length(), text, 0, text.length()) != -1; }
03879
03880 inline UBool
03881 UnicodeString::operator<= (const UnicodeString& text) const
03882 { return doCompare(0, length(), text, 0, text.length()) != 1; }
03883
03884 inline int8_t
03885 UnicodeString::compare(const UnicodeString& text) const
03886 { return doCompare(0, length(), text, 0, text.length()); }
03887
03888 inline int8_t
03889 UnicodeString::compare(int32_t start,
03890 int32_t _length,
03891 const UnicodeString& srcText) const
03892 { return doCompare(start, _length, srcText, 0, srcText.length()); }
03893
03894 inline int8_t
03895 UnicodeString::compare(const UChar *srcChars,
03896 int32_t srcLength) const
03897 { return doCompare(0, length(), srcChars, 0, srcLength); }
03898
03899 inline int8_t
03900 UnicodeString::compare(int32_t start,
03901 int32_t _length,
03902 const UnicodeString& srcText,
03903 int32_t srcStart,
03904 int32_t srcLength) const
03905 { return doCompare(start, _length, srcText, srcStart, srcLength); }
03906
03907 inline int8_t
03908 UnicodeString::compare(int32_t start,
03909 int32_t _length,
03910 const UChar *srcChars) const
03911 { return doCompare(start, _length, srcChars, 0, _length); }
03912
03913 inline int8_t
03914 UnicodeString::compare(int32_t start,
03915 int32_t _length,
03916 const UChar *srcChars,
03917 int32_t srcStart,
03918 int32_t srcLength) const
03919 { return doCompare(start, _length, srcChars, srcStart, srcLength); }
03920
03921 inline int8_t
03922 UnicodeString::compareBetween(int32_t start,
03923 int32_t limit,
03924 const UnicodeString& srcText,
03925 int32_t srcStart,
03926 int32_t srcLimit) const
03927 { return doCompare(start, limit - start,
03928 srcText, srcStart, srcLimit - srcStart); }
03929
03930 inline int8_t
03931 UnicodeString::doCompareCodePointOrder(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 doCompareCodePointOrder(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
03942 }
03943 }
03944
03945 inline int8_t
03946 UnicodeString::compareCodePointOrder(const UnicodeString& text) const
03947 { return doCompareCodePointOrder(0, length(), text, 0, text.length()); }
03948
03949 inline int8_t
03950 UnicodeString::compareCodePointOrder(int32_t start,
03951 int32_t _length,
03952 const UnicodeString& srcText) const
03953 { return doCompareCodePointOrder(start, _length, srcText, 0, srcText.length()); }
03954
03955 inline int8_t
03956 UnicodeString::compareCodePointOrder(const UChar *srcChars,
03957 int32_t srcLength) const
03958 { return doCompareCodePointOrder(0, length(), srcChars, 0, srcLength); }
03959
03960 inline int8_t
03961 UnicodeString::compareCodePointOrder(int32_t start,
03962 int32_t _length,
03963 const UnicodeString& srcText,
03964 int32_t srcStart,
03965 int32_t srcLength) const
03966 { return doCompareCodePointOrder(start, _length, srcText, srcStart, srcLength); }
03967
03968 inline int8_t
03969 UnicodeString::compareCodePointOrder(int32_t start,
03970 int32_t _length,
03971 const UChar *srcChars) const
03972 { return doCompareCodePointOrder(start, _length, srcChars, 0, _length); }
03973
03974 inline int8_t
03975 UnicodeString::compareCodePointOrder(int32_t start,
03976 int32_t _length,
03977 const UChar *srcChars,
03978 int32_t srcStart,
03979 int32_t srcLength) const
03980 { return doCompareCodePointOrder(start, _length, srcChars, srcStart, srcLength); }
03981
03982 inline int8_t
03983 UnicodeString::compareCodePointOrderBetween(int32_t start,
03984 int32_t limit,
03985 const UnicodeString& srcText,
03986 int32_t srcStart,
03987 int32_t srcLimit) const
03988 { return doCompareCodePointOrder(start, limit - start,
03989 srcText, srcStart, srcLimit - srcStart); }
03990
03991 inline int8_t
03992 UnicodeString::doCaseCompare(int32_t start,
03993 int32_t thisLength,
03994 const UnicodeString &srcText,
03995 int32_t srcStart,
03996 int32_t srcLength,
03997 uint32_t options) const
03998 {
03999 if(srcText.isBogus()) {
04000 return (int8_t)!isBogus();
04001 } else {
04002 srcText.pinIndices(srcStart, srcLength);
04003 return doCaseCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength, options);
04004 }
04005 }
04006
04007 inline int8_t
04008 UnicodeString::caseCompare(const UnicodeString &text, uint32_t options) const {
04009 return doCaseCompare(0, length(), text, 0, text.length(), options);
04010 }
04011
04012 inline int8_t
04013 UnicodeString::caseCompare(int32_t start,
04014 int32_t _length,
04015 const UnicodeString &srcText,
04016 uint32_t options) const {
04017 return doCaseCompare(start, _length, srcText, 0, srcText.length(), options);
04018 }
04019
04020 inline int8_t
04021 UnicodeString::caseCompare(const UChar *srcChars,
04022 int32_t srcLength,
04023 uint32_t options) const {
04024 return doCaseCompare(0, length(), srcChars, 0, srcLength, options);
04025 }
04026
04027 inline int8_t
04028 UnicodeString::caseCompare(int32_t start,
04029 int32_t _length,
04030 const UnicodeString &srcText,
04031 int32_t srcStart,
04032 int32_t srcLength,
04033 uint32_t options) const {
04034 return doCaseCompare(start, _length, srcText, srcStart, srcLength, options);
04035 }
04036
04037 inline int8_t
04038 UnicodeString::caseCompare(int32_t start,
04039 int32_t _length,
04040 const UChar *srcChars,
04041 uint32_t options) const {
04042 return doCaseCompare(start, _length, srcChars, 0, _length, options);
04043 }
04044
04045 inline int8_t
04046 UnicodeString::caseCompare(int32_t start,
04047 int32_t _length,
04048 const UChar *srcChars,
04049 int32_t srcStart,
04050 int32_t srcLength,
04051 uint32_t options) const {
04052 return doCaseCompare(start, _length, srcChars, srcStart, srcLength, options);
04053 }
04054
04055 inline int8_t
04056 UnicodeString::caseCompareBetween(int32_t start,
04057 int32_t limit,
04058 const UnicodeString &srcText,
04059 int32_t srcStart,
04060 int32_t srcLimit,
04061 uint32_t options) const {
04062 return doCaseCompare(start, limit - start, srcText, srcStart, srcLimit - srcStart, options);
04063 }
04064
04065 inline int32_t
04066 UnicodeString::indexOf(const UnicodeString& srcText,
04067 int32_t srcStart,
04068 int32_t srcLength,
04069 int32_t start,
04070 int32_t _length) const
04071 {
04072 if(!srcText.isBogus()) {
04073 srcText.pinIndices(srcStart, srcLength);
04074 if(srcLength > 0) {
04075 return indexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
04076 }
04077 }
04078 return -1;
04079 }
04080
04081 inline int32_t
04082 UnicodeString::indexOf(const UnicodeString& text) const
04083 { return indexOf(text, 0, text.length(), 0, length()); }
04084
04085 inline int32_t
04086 UnicodeString::indexOf(const UnicodeString& text,
04087 int32_t start) const {
04088 pinIndex(start);
04089 return indexOf(text, 0, text.length(), start, length() - start);
04090 }
04091
04092 inline int32_t
04093 UnicodeString::indexOf(const UnicodeString& text,
04094 int32_t start,
04095 int32_t _length) const
04096 { return indexOf(text, 0, text.length(), start, _length); }
04097
04098 inline int32_t
04099 UnicodeString::indexOf(const UChar *srcChars,
04100 int32_t srcLength,
04101 int32_t start) const {
04102 pinIndex(start);
04103 return indexOf(srcChars, 0, srcLength, start, length() - start);
04104 }
04105
04106 inline int32_t
04107 UnicodeString::indexOf(const UChar *srcChars,
04108 int32_t srcLength,
04109 int32_t start,
04110 int32_t _length) const
04111 { return indexOf(srcChars, 0, srcLength, start, _length); }
04112
04113 inline int32_t
04114 UnicodeString::indexOf(UChar c,
04115 int32_t start,
04116 int32_t _length) const
04117 { return doIndexOf(c, start, _length); }
04118
04119 inline int32_t
04120 UnicodeString::indexOf(UChar32 c,
04121 int32_t start,
04122 int32_t _length) const
04123 { return doIndexOf(c, start, _length); }
04124
04125 inline int32_t
04126 UnicodeString::indexOf(UChar c) const
04127 { return doIndexOf(c, 0, length()); }
04128
04129 inline int32_t
04130 UnicodeString::indexOf(UChar32 c) const
04131 { return indexOf(c, 0, length()); }
04132
04133 inline int32_t
04134 UnicodeString::indexOf(UChar c,
04135 int32_t start) const {
04136 pinIndex(start);
04137 return doIndexOf(c, start, length() - start);
04138 }
04139
04140 inline int32_t
04141 UnicodeString::indexOf(UChar32 c,
04142 int32_t start) const {
04143 pinIndex(start);
04144 return indexOf(c, start, length() - start);
04145 }
04146
04147 inline int32_t
04148 UnicodeString::lastIndexOf(const UChar *srcChars,
04149 int32_t srcLength,
04150 int32_t start,
04151 int32_t _length) const
04152 { return lastIndexOf(srcChars, 0, srcLength, start, _length); }
04153
04154 inline int32_t
04155 UnicodeString::lastIndexOf(const UChar *srcChars,
04156 int32_t srcLength,
04157 int32_t start) const {
04158 pinIndex(start);
04159 return lastIndexOf(srcChars, 0, srcLength, start, length() - start);
04160 }
04161
04162 inline int32_t
04163 UnicodeString::lastIndexOf(const UnicodeString& srcText,
04164 int32_t srcStart,
04165 int32_t srcLength,
04166 int32_t start,
04167 int32_t _length) const
04168 {
04169 if(!srcText.isBogus()) {
04170 srcText.pinIndices(srcStart, srcLength);
04171 if(srcLength > 0) {
04172 return lastIndexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
04173 }
04174 }
04175 return -1;
04176 }
04177
04178 inline int32_t
04179 UnicodeString::lastIndexOf(const UnicodeString& text,
04180 int32_t start,
04181 int32_t _length) const
04182 { return lastIndexOf(text, 0, text.length(), start, _length); }
04183
04184 inline int32_t
04185 UnicodeString::lastIndexOf(const UnicodeString& text,
04186 int32_t start) const {
04187 pinIndex(start);
04188 return lastIndexOf(text, 0, text.length(), start, length() - start);
04189 }
04190
04191 inline int32_t
04192 UnicodeString::lastIndexOf(const UnicodeString& text) const
04193 { return lastIndexOf(text, 0, text.length(), 0, length()); }
04194
04195 inline int32_t
04196 UnicodeString::lastIndexOf(UChar c,
04197 int32_t start,
04198 int32_t _length) const
04199 { return doLastIndexOf(c, start, _length); }
04200
04201 inline int32_t
04202 UnicodeString::lastIndexOf(UChar32 c,
04203 int32_t start,
04204 int32_t _length) const {
04205 return doLastIndexOf(c, start, _length);
04206 }
04207
04208 inline int32_t
04209 UnicodeString::lastIndexOf(UChar c) const
04210 { return doLastIndexOf(c, 0, length()); }
04211
04212 inline int32_t
04213 UnicodeString::lastIndexOf(UChar32 c) const {
04214 return lastIndexOf(c, 0, length());
04215 }
04216
04217 inline int32_t
04218 UnicodeString::lastIndexOf(UChar c,
04219 int32_t start) const {
04220 pinIndex(start);
04221 return doLastIndexOf(c, start, length() - start);
04222 }
04223
04224 inline int32_t
04225 UnicodeString::lastIndexOf(UChar32 c,
04226 int32_t start) const {
04227 pinIndex(start);
04228 return lastIndexOf(c, start, length() - start);
04229 }
04230
04231 inline UBool
04232 UnicodeString::startsWith(const UnicodeString& text) const
04233 { return compare(0, text.length(), text, 0, text.length()) == 0; }
04234
04235 inline UBool
04236 UnicodeString::startsWith(const UnicodeString& srcText,
04237 int32_t srcStart,
04238 int32_t srcLength) const
04239 { return doCompare(0, srcLength, srcText, srcStart, srcLength) == 0; }
04240
04241 inline UBool
04242 UnicodeString::startsWith(const UChar *srcChars, int32_t srcLength) const {
04243 if(srcLength < 0) {
04244 srcLength = u_strlen(srcChars);
04245 }
04246 return doCompare(0, srcLength, srcChars, 0, srcLength) == 0;
04247 }
04248
04249 inline UBool
04250 UnicodeString::startsWith(const UChar *srcChars, int32_t srcStart, int32_t srcLength) const {
04251 if(srcLength < 0) {
04252 srcLength = u_strlen(srcChars);
04253 }
04254 return doCompare(0, srcLength, srcChars, srcStart, srcLength) == 0;
04255 }
04256
04257 inline UBool
04258 UnicodeString::endsWith(const UnicodeString& text) const
04259 { return doCompare(length() - text.length(), text.length(),
04260 text, 0, text.length()) == 0; }
04261
04262 inline UBool
04263 UnicodeString::endsWith(const UnicodeString& srcText,
04264 int32_t srcStart,
04265 int32_t srcLength) const {
04266 srcText.pinIndices(srcStart, srcLength);
04267 return doCompare(length() - srcLength, srcLength,
04268 srcText, srcStart, srcLength) == 0;
04269 }
04270
04271 inline UBool
04272 UnicodeString::endsWith(const UChar *srcChars,
04273 int32_t srcLength) const {
04274 if(srcLength < 0) {
04275 srcLength = u_strlen(srcChars);
04276 }
04277 return doCompare(length() - srcLength, srcLength,
04278 srcChars, 0, srcLength) == 0;
04279 }
04280
04281 inline UBool
04282 UnicodeString::endsWith(const UChar *srcChars,
04283 int32_t srcStart,
04284 int32_t srcLength) const {
04285 if(srcLength < 0) {
04286 srcLength = u_strlen(srcChars + srcStart);
04287 }
04288 return doCompare(length() - srcLength, srcLength,
04289 srcChars, srcStart, srcLength) == 0;
04290 }
04291
04292
04293
04294
04295 inline UnicodeString&
04296 UnicodeString::replace(int32_t start,
04297 int32_t _length,
04298 const UnicodeString& srcText)
04299 { return doReplace(start, _length, srcText, 0, srcText.length()); }
04300
04301 inline UnicodeString&
04302 UnicodeString::replace(int32_t start,
04303 int32_t _length,
04304 const UnicodeString& srcText,
04305 int32_t srcStart,
04306 int32_t srcLength)
04307 { return doReplace(start, _length, srcText, srcStart, srcLength); }
04308
04309 inline UnicodeString&
04310 UnicodeString::replace(int32_t start,
04311 int32_t _length,
04312 const UChar *srcChars,
04313 int32_t srcLength)
04314 { return doReplace(start, _length, srcChars, 0, srcLength); }
04315
04316 inline UnicodeString&
04317 UnicodeString::replace(int32_t start,
04318 int32_t _length,
04319 const UChar *srcChars,
04320 int32_t srcStart,
04321 int32_t srcLength)
04322 { return doReplace(start, _length, srcChars, srcStart, srcLength); }
04323
04324 inline UnicodeString&
04325 UnicodeString::replace(int32_t start,
04326 int32_t _length,
04327 UChar srcChar)
04328 { return doReplace(start, _length, &srcChar, 0, 1); }
04329
04330 inline UnicodeString&
04331 UnicodeString::replaceBetween(int32_t start,
04332 int32_t limit,
04333 const UnicodeString& srcText)
04334 { return doReplace(start, limit - start, srcText, 0, srcText.length()); }
04335
04336 inline UnicodeString&
04337 UnicodeString::replaceBetween(int32_t start,
04338 int32_t limit,
04339 const UnicodeString& srcText,
04340 int32_t srcStart,
04341 int32_t srcLimit)
04342 { return doReplace(start, limit - start, srcText, srcStart, srcLimit - srcStart); }
04343
04344 inline UnicodeString&
04345 UnicodeString::findAndReplace(const UnicodeString& oldText,
04346 const UnicodeString& newText)
04347 { return findAndReplace(0, length(), oldText, 0, oldText.length(),
04348 newText, 0, newText.length()); }
04349
04350 inline UnicodeString&
04351 UnicodeString::findAndReplace(int32_t start,
04352 int32_t _length,
04353 const UnicodeString& oldText,
04354 const UnicodeString& newText)
04355 { return findAndReplace(start, _length, oldText, 0, oldText.length(),
04356 newText, 0, newText.length()); }
04357
04358
04359
04360
04361 inline void
04362 UnicodeString::doExtract(int32_t start,
04363 int32_t _length,
04364 UnicodeString& target) const
04365 { target.replace(0, target.length(), *this, start, _length); }
04366
04367 inline void
04368 UnicodeString::extract(int32_t start,
04369 int32_t _length,
04370 UChar *target,
04371 int32_t targetStart) const
04372 { doExtract(start, _length, target, targetStart); }
04373
04374 inline void
04375 UnicodeString::extract(int32_t start,
04376 int32_t _length,
04377 UnicodeString& target) const
04378 { doExtract(start, _length, target); }
04379
04380 #if !UCONFIG_NO_CONVERSION
04381
04382 inline int32_t
04383 UnicodeString::extract(int32_t start,
04384 int32_t _length,
04385 char *dst,
04386 const char *codepage) const
04387
04388 {
04389
04390 return extract(start, _length, dst, dst!=0 ? 0xffffffff : 0, codepage);
04391 }
04392
04393 #endif
04394
04395 inline void
04396 UnicodeString::extractBetween(int32_t start,
04397 int32_t limit,
04398 UChar *dst,
04399 int32_t dstStart) const {
04400 pinIndex(start);
04401 pinIndex(limit);
04402 doExtract(start, limit - start, dst, dstStart);
04403 }
04404
04405 inline UnicodeString
04406 UnicodeString::tempSubStringBetween(int32_t start, int32_t limit) const {
04407 return tempSubString(start, limit - start);
04408 }
04409
04410 inline UChar
04411 UnicodeString::doCharAt(int32_t offset) const
04412 {
04413 if((uint32_t)offset < (uint32_t)length()) {
04414 return getArrayStart()[offset];
04415 } else {
04416 return kInvalidUChar;
04417 }
04418 }
04419
04420 inline UChar
04421 UnicodeString::charAt(int32_t offset) const
04422 { return doCharAt(offset); }
04423
04424 inline UChar
04425 UnicodeString::operator[] (int32_t offset) const
04426 { return doCharAt(offset); }
04427
04428 inline UBool
04429 UnicodeString::isEmpty() const {
04430
04431 return (fUnion.fFields.fLengthAndFlags>>kLengthShift) == 0;
04432 }
04433
04434
04435
04436
04437 inline void
04438 UnicodeString::setZeroLength() {
04439 fUnion.fFields.fLengthAndFlags &= kAllStorageFlags;
04440 }
04441
04442 inline void
04443 UnicodeString::setShortLength(int32_t len) {
04444
04445 fUnion.fFields.fLengthAndFlags =
04446 (int16_t)((fUnion.fFields.fLengthAndFlags & kAllStorageFlags) | (len << kLengthShift));
04447 }
04448
04449 inline void
04450 UnicodeString::setLength(int32_t len) {
04451 if(len <= kMaxShortLength) {
04452 setShortLength(len);
04453 } else {
04454 fUnion.fFields.fLengthAndFlags |= kLengthIsLarge;
04455 fUnion.fFields.fLength = len;
04456 }
04457 }
04458
04459 inline void
04460 UnicodeString::setToEmpty() {
04461 fUnion.fFields.fLengthAndFlags = kShortString;
04462 }
04463
04464 inline void
04465 UnicodeString::setArray(UChar *array, int32_t len, int32_t capacity) {
04466 setLength(len);
04467 fUnion.fFields.fArray = array;
04468 fUnion.fFields.fCapacity = capacity;
04469 }
04470
04471 inline UnicodeString&
04472 UnicodeString::operator= (UChar ch)
04473 { return doReplace(0, length(), &ch, 0, 1); }
04474
04475 inline UnicodeString&
04476 UnicodeString::operator= (UChar32 ch)
04477 { return replace(0, length(), ch); }
04478
04479 inline UnicodeString&
04480 UnicodeString::setTo(const UnicodeString& srcText,
04481 int32_t srcStart,
04482 int32_t srcLength)
04483 {
04484 unBogus();
04485 return doReplace(0, length(), srcText, srcStart, srcLength);
04486 }
04487
04488 inline UnicodeString&
04489 UnicodeString::setTo(const UnicodeString& srcText,
04490 int32_t srcStart)
04491 {
04492 unBogus();
04493 srcText.pinIndex(srcStart);
04494 return doReplace(0, length(), srcText, srcStart, srcText.length() - srcStart);
04495 }
04496
04497 inline UnicodeString&
04498 UnicodeString::setTo(const UnicodeString& srcText)
04499 {
04500 return copyFrom(srcText);
04501 }
04502
04503 inline UnicodeString&
04504 UnicodeString::setTo(const UChar *srcChars,
04505 int32_t srcLength)
04506 {
04507 unBogus();
04508 return doReplace(0, length(), srcChars, 0, srcLength);
04509 }
04510
04511 inline UnicodeString&
04512 UnicodeString::setTo(UChar srcChar)
04513 {
04514 unBogus();
04515 return doReplace(0, length(), &srcChar, 0, 1);
04516 }
04517
04518 inline UnicodeString&
04519 UnicodeString::setTo(UChar32 srcChar)
04520 {
04521 unBogus();
04522 return replace(0, length(), srcChar);
04523 }
04524
04525 inline UnicodeString&
04526 UnicodeString::append(const UnicodeString& srcText,
04527 int32_t srcStart,
04528 int32_t srcLength)
04529 { return doAppend(srcText, srcStart, srcLength); }
04530
04531 inline UnicodeString&
04532 UnicodeString::append(const UnicodeString& srcText)
04533 { return doAppend(srcText, 0, srcText.length()); }
04534
04535 inline UnicodeString&
04536 UnicodeString::append(const UChar *srcChars,
04537 int32_t srcStart,
04538 int32_t srcLength)
04539 { return doAppend(srcChars, srcStart, srcLength); }
04540
04541 inline UnicodeString&
04542 UnicodeString::append(const UChar *srcChars,
04543 int32_t srcLength)
04544 { return doAppend(srcChars, 0, srcLength); }
04545
04546 inline UnicodeString&
04547 UnicodeString::append(UChar srcChar)
04548 { return doAppend(&srcChar, 0, 1); }
04549
04550 inline UnicodeString&
04551 UnicodeString::operator+= (UChar ch)
04552 { return doAppend(&ch, 0, 1); }
04553
04554 inline UnicodeString&
04555 UnicodeString::operator+= (UChar32 ch) {
04556 return append(ch);
04557 }
04558
04559 inline UnicodeString&
04560 UnicodeString::operator+= (const UnicodeString& srcText)
04561 { return doAppend(srcText, 0, srcText.length()); }
04562
04563 inline UnicodeString&
04564 UnicodeString::insert(int32_t start,
04565 const UnicodeString& srcText,
04566 int32_t srcStart,
04567 int32_t srcLength)
04568 { return doReplace(start, 0, srcText, srcStart, srcLength); }
04569
04570 inline UnicodeString&
04571 UnicodeString::insert(int32_t start,
04572 const UnicodeString& srcText)
04573 { return doReplace(start, 0, srcText, 0, srcText.length()); }
04574
04575 inline UnicodeString&
04576 UnicodeString::insert(int32_t start,
04577 const UChar *srcChars,
04578 int32_t srcStart,
04579 int32_t srcLength)
04580 { return doReplace(start, 0, srcChars, srcStart, srcLength); }
04581
04582 inline UnicodeString&
04583 UnicodeString::insert(int32_t start,
04584 const UChar *srcChars,
04585 int32_t srcLength)
04586 { return doReplace(start, 0, srcChars, 0, srcLength); }
04587
04588 inline UnicodeString&
04589 UnicodeString::insert(int32_t start,
04590 UChar srcChar)
04591 { return doReplace(start, 0, &srcChar, 0, 1); }
04592
04593 inline UnicodeString&
04594 UnicodeString::insert(int32_t start,
04595 UChar32 srcChar)
04596 { return replace(start, 0, srcChar); }
04597
04598
04599 inline UnicodeString&
04600 UnicodeString::remove()
04601 {
04602
04603 if(isBogus()) {
04604 setToEmpty();
04605 } else {
04606 setZeroLength();
04607 }
04608 return *this;
04609 }
04610
04611 inline UnicodeString&
04612 UnicodeString::remove(int32_t start,
04613 int32_t _length)
04614 {
04615 if(start <= 0 && _length == INT32_MAX) {
04616
04617 return remove();
04618 }
04619 return doReplace(start, _length, NULL, 0, 0);
04620 }
04621
04622 inline UnicodeString&
04623 UnicodeString::removeBetween(int32_t start,
04624 int32_t limit)
04625 { return doReplace(start, limit - start, NULL, 0, 0); }
04626
04627 inline UnicodeString &
04628 UnicodeString::retainBetween(int32_t start, int32_t limit) {
04629 truncate(limit);
04630 return doReplace(0, start, NULL, 0, 0);
04631 }
04632
04633 inline UBool
04634 UnicodeString::truncate(int32_t targetLength)
04635 {
04636 if(isBogus() && targetLength == 0) {
04637
04638 unBogus();
04639 return FALSE;
04640 } else if((uint32_t)targetLength < (uint32_t)length()) {
04641 setLength(targetLength);
04642 return TRUE;
04643 } else {
04644 return FALSE;
04645 }
04646 }
04647
04648 inline UnicodeString&
04649 UnicodeString::reverse()
04650 { return doReverse(0, length()); }
04651
04652 inline UnicodeString&
04653 UnicodeString::reverse(int32_t start,
04654 int32_t _length)
04655 { return doReverse(start, _length); }
04656
04657 U_NAMESPACE_END
04658
04659 #endif