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
00286 class U_COMMON_API UnicodeString : public Replaceable
00287 {
00288 public:
00289
00298 enum EInvariant {
00303 kInvariant
00304 };
00305
00306
00307
00308
00309
00310
00311
00319 inline UBool operator== (const UnicodeString& text) const;
00320
00328 inline UBool operator!= (const UnicodeString& text) const;
00329
00337 inline UBool operator> (const UnicodeString& text) const;
00338
00346 inline UBool operator< (const UnicodeString& text) const;
00347
00355 inline UBool operator>= (const UnicodeString& text) const;
00356
00364 inline UBool operator<= (const UnicodeString& text) const;
00365
00377 inline int8_t compare(const UnicodeString& text) const;
00378
00394 inline int8_t compare(int32_t start,
00395 int32_t length,
00396 const UnicodeString& text) const;
00397
00415 inline int8_t compare(int32_t start,
00416 int32_t length,
00417 const UnicodeString& srcText,
00418 int32_t srcStart,
00419 int32_t srcLength) const;
00420
00433 inline int8_t compare(ConstChar16Ptr srcChars,
00434 int32_t srcLength) const;
00435
00450 inline int8_t compare(int32_t start,
00451 int32_t length,
00452 const char16_t *srcChars) const;
00453
00471 inline int8_t compare(int32_t start,
00472 int32_t length,
00473 const char16_t *srcChars,
00474 int32_t srcStart,
00475 int32_t srcLength) const;
00476
00494 inline int8_t compareBetween(int32_t start,
00495 int32_t limit,
00496 const UnicodeString& srcText,
00497 int32_t srcStart,
00498 int32_t srcLimit) const;
00499
00517 inline int8_t compareCodePointOrder(const UnicodeString& text) const;
00518
00538 inline int8_t compareCodePointOrder(int32_t start,
00539 int32_t length,
00540 const UnicodeString& srcText) const;
00541
00563 inline int8_t compareCodePointOrder(int32_t start,
00564 int32_t length,
00565 const UnicodeString& srcText,
00566 int32_t srcStart,
00567 int32_t srcLength) const;
00568
00587 inline int8_t compareCodePointOrder(ConstChar16Ptr srcChars,
00588 int32_t srcLength) const;
00589
00609 inline int8_t compareCodePointOrder(int32_t start,
00610 int32_t length,
00611 const char16_t *srcChars) const;
00612
00634 inline int8_t compareCodePointOrder(int32_t start,
00635 int32_t length,
00636 const char16_t *srcChars,
00637 int32_t srcStart,
00638 int32_t srcLength) const;
00639
00661 inline int8_t compareCodePointOrderBetween(int32_t start,
00662 int32_t limit,
00663 const UnicodeString& srcText,
00664 int32_t srcStart,
00665 int32_t srcLimit) const;
00666
00685 inline int8_t caseCompare(const UnicodeString& text, uint32_t options) const;
00686
00707 inline int8_t caseCompare(int32_t start,
00708 int32_t length,
00709 const UnicodeString& srcText,
00710 uint32_t options) const;
00711
00734 inline int8_t caseCompare(int32_t start,
00735 int32_t length,
00736 const UnicodeString& srcText,
00737 int32_t srcStart,
00738 int32_t srcLength,
00739 uint32_t options) const;
00740
00760 inline int8_t caseCompare(ConstChar16Ptr srcChars,
00761 int32_t srcLength,
00762 uint32_t options) const;
00763
00784 inline int8_t caseCompare(int32_t start,
00785 int32_t length,
00786 const char16_t *srcChars,
00787 uint32_t options) const;
00788
00811 inline int8_t caseCompare(int32_t start,
00812 int32_t length,
00813 const char16_t *srcChars,
00814 int32_t srcStart,
00815 int32_t srcLength,
00816 uint32_t options) const;
00817
00840 inline int8_t caseCompareBetween(int32_t start,
00841 int32_t limit,
00842 const UnicodeString& srcText,
00843 int32_t srcStart,
00844 int32_t srcLimit,
00845 uint32_t options) const;
00846
00854 inline UBool startsWith(const UnicodeString& text) const;
00855
00866 inline UBool startsWith(const UnicodeString& srcText,
00867 int32_t srcStart,
00868 int32_t srcLength) const;
00869
00878 inline UBool startsWith(ConstChar16Ptr srcChars,
00879 int32_t srcLength) const;
00880
00890 inline UBool startsWith(const char16_t *srcChars,
00891 int32_t srcStart,
00892 int32_t srcLength) const;
00893
00901 inline UBool endsWith(const UnicodeString& text) const;
00902
00913 inline UBool endsWith(const UnicodeString& srcText,
00914 int32_t srcStart,
00915 int32_t srcLength) const;
00916
00925 inline UBool endsWith(ConstChar16Ptr srcChars,
00926 int32_t srcLength) const;
00927
00938 inline UBool endsWith(const char16_t *srcChars,
00939 int32_t srcStart,
00940 int32_t srcLength) const;
00941
00942
00943
00944
00953 inline int32_t indexOf(const UnicodeString& text) const;
00954
00964 inline int32_t indexOf(const UnicodeString& text,
00965 int32_t start) const;
00966
00978 inline int32_t indexOf(const UnicodeString& text,
00979 int32_t start,
00980 int32_t length) const;
00981
00998 inline int32_t indexOf(const UnicodeString& srcText,
00999 int32_t srcStart,
01000 int32_t srcLength,
01001 int32_t start,
01002 int32_t length) const;
01003
01015 inline int32_t indexOf(const char16_t *srcChars,
01016 int32_t srcLength,
01017 int32_t start) const;
01018
01031 inline int32_t indexOf(ConstChar16Ptr srcChars,
01032 int32_t srcLength,
01033 int32_t start,
01034 int32_t length) const;
01035
01052 int32_t indexOf(const char16_t *srcChars,
01053 int32_t srcStart,
01054 int32_t srcLength,
01055 int32_t start,
01056 int32_t length) const;
01057
01065 inline int32_t indexOf(char16_t c) const;
01066
01075 inline int32_t indexOf(UChar32 c) const;
01076
01085 inline int32_t indexOf(char16_t c,
01086 int32_t start) const;
01087
01097 inline int32_t indexOf(UChar32 c,
01098 int32_t start) const;
01099
01110 inline int32_t indexOf(char16_t c,
01111 int32_t start,
01112 int32_t length) const;
01113
01125 inline int32_t indexOf(UChar32 c,
01126 int32_t start,
01127 int32_t length) const;
01128
01137 inline int32_t lastIndexOf(const UnicodeString& text) const;
01138
01148 inline int32_t lastIndexOf(const UnicodeString& text,
01149 int32_t start) const;
01150
01162 inline int32_t lastIndexOf(const UnicodeString& text,
01163 int32_t start,
01164 int32_t length) const;
01165
01182 inline int32_t lastIndexOf(const UnicodeString& srcText,
01183 int32_t srcStart,
01184 int32_t srcLength,
01185 int32_t start,
01186 int32_t length) const;
01187
01198 inline int32_t lastIndexOf(const char16_t *srcChars,
01199 int32_t srcLength,
01200 int32_t start) const;
01201
01214 inline int32_t lastIndexOf(ConstChar16Ptr srcChars,
01215 int32_t srcLength,
01216 int32_t start,
01217 int32_t length) const;
01218
01235 int32_t lastIndexOf(const char16_t *srcChars,
01236 int32_t srcStart,
01237 int32_t srcLength,
01238 int32_t start,
01239 int32_t length) const;
01240
01248 inline int32_t lastIndexOf(char16_t c) const;
01249
01258 inline int32_t lastIndexOf(UChar32 c) const;
01259
01268 inline int32_t lastIndexOf(char16_t c,
01269 int32_t start) const;
01270
01280 inline int32_t lastIndexOf(UChar32 c,
01281 int32_t start) const;
01282
01293 inline int32_t lastIndexOf(char16_t c,
01294 int32_t start,
01295 int32_t length) const;
01296
01308 inline int32_t lastIndexOf(UChar32 c,
01309 int32_t start,
01310 int32_t length) const;
01311
01312
01313
01314
01323 inline char16_t charAt(int32_t offset) const;
01324
01332 inline char16_t operator[] (int32_t offset) const;
01333
01345 UChar32 char32At(int32_t offset) const;
01346
01362 int32_t getChar32Start(int32_t offset) const;
01363
01380 int32_t getChar32Limit(int32_t offset) const;
01381
01432 int32_t moveIndex32(int32_t index, int32_t delta) const;
01433
01434
01435
01451 inline void extract(int32_t start,
01452 int32_t length,
01453 Char16Ptr dst,
01454 int32_t dstStart = 0) const;
01455
01477 int32_t
01478 extract(Char16Ptr dest, int32_t destCapacity,
01479 UErrorCode &errorCode) const;
01480
01491 inline void extract(int32_t start,
01492 int32_t length,
01493 UnicodeString& target) const;
01494
01506 inline void extractBetween(int32_t start,
01507 int32_t limit,
01508 char16_t *dst,
01509 int32_t dstStart = 0) const;
01510
01520 virtual void extractBetween(int32_t start,
01521 int32_t limit,
01522 UnicodeString& target) const;
01523
01545 int32_t extract(int32_t start,
01546 int32_t startLength,
01547 char *target,
01548 int32_t targetCapacity,
01549 enum EInvariant inv) const;
01550
01551 #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
01552
01572 int32_t extract(int32_t start,
01573 int32_t startLength,
01574 char *target,
01575 uint32_t targetLength) const;
01576
01577 #endif
01578
01579 #if !UCONFIG_NO_CONVERSION
01580
01606 inline int32_t extract(int32_t start,
01607 int32_t startLength,
01608 char *target,
01609 const char *codepage = 0) const;
01610
01640 int32_t extract(int32_t start,
01641 int32_t startLength,
01642 char *target,
01643 uint32_t targetLength,
01644 const char *codepage) const;
01645
01663 int32_t extract(char *dest, int32_t destCapacity,
01664 UConverter *cnv,
01665 UErrorCode &errorCode) const;
01666
01667 #endif
01668
01682 UnicodeString tempSubString(int32_t start=0, int32_t length=INT32_MAX) const;
01683
01694 inline UnicodeString tempSubStringBetween(int32_t start, int32_t limit=INT32_MAX) const;
01695
01707 void toUTF8(ByteSink &sink) const;
01708
01721 template<typename StringClass>
01722 StringClass &toUTF8String(StringClass &result) const {
01723 StringByteSink<StringClass> sbs(&result, length());
01724 toUTF8(sbs);
01725 return result;
01726 }
01727
01743 int32_t toUTF32(UChar32 *utf32, int32_t capacity, UErrorCode &errorCode) const;
01744
01745
01746
01755 inline int32_t length(void) const;
01756
01770 int32_t
01771 countChar32(int32_t start=0, int32_t length=INT32_MAX) const;
01772
01796 UBool
01797 hasMoreChar32Than(int32_t start, int32_t length, int32_t number) const;
01798
01804 inline UBool isEmpty(void) const;
01805
01815 inline int32_t getCapacity(void) const;
01816
01817
01818
01824 inline int32_t hashCode(void) const;
01825
01838 inline UBool isBogus(void) const;
01839
01840
01841
01842
01843
01844
01845
01846
01865 UnicodeString &operator=(const UnicodeString &srcText);
01866
01892 UnicodeString &fastCopyFrom(const UnicodeString &src);
01893
01902 UnicodeString &operator=(UnicodeString &&src) U_NOEXCEPT {
01903 return moveFrom(src);
01904 }
01905
01906
01917 UnicodeString &moveFrom(UnicodeString &src) U_NOEXCEPT;
01918
01924 void swap(UnicodeString &other) U_NOEXCEPT;
01925
01932 friend U_COMMON_API inline void U_EXPORT2
01933 swap(UnicodeString &s1, UnicodeString &s2) U_NOEXCEPT {
01934 s1.swap(s2);
01935 }
01936
01944 inline UnicodeString& operator= (char16_t ch);
01945
01953 inline UnicodeString& operator= (UChar32 ch);
01954
01966 inline UnicodeString& setTo(const UnicodeString& srcText,
01967 int32_t srcStart);
01968
01982 inline UnicodeString& setTo(const UnicodeString& srcText,
01983 int32_t srcStart,
01984 int32_t srcLength);
01985
01994 inline UnicodeString& setTo(const UnicodeString& srcText);
01995
02004 inline UnicodeString& setTo(const char16_t *srcChars,
02005 int32_t srcLength);
02006
02015 UnicodeString& setTo(char16_t srcChar);
02016
02025 UnicodeString& setTo(UChar32 srcChar);
02026
02050 UnicodeString &setTo(UBool isTerminated,
02051 ConstChar16Ptr text,
02052 int32_t textLength);
02053
02073 UnicodeString &setTo(char16_t *buffer,
02074 int32_t buffLength,
02075 int32_t buffCapacity);
02076
02117 void setToBogus();
02118
02126 UnicodeString& setCharAt(int32_t offset,
02127 char16_t ch);
02128
02129
02130
02131
02139 inline UnicodeString& operator+= (char16_t ch);
02140
02148 inline UnicodeString& operator+= (UChar32 ch);
02149
02157 inline UnicodeString& operator+= (const UnicodeString& srcText);
02158
02173 inline UnicodeString& append(const UnicodeString& srcText,
02174 int32_t srcStart,
02175 int32_t srcLength);
02176
02184 inline UnicodeString& append(const UnicodeString& srcText);
02185
02199 inline UnicodeString& append(const char16_t *srcChars,
02200 int32_t srcStart,
02201 int32_t srcLength);
02202
02212 inline UnicodeString& append(ConstChar16Ptr srcChars,
02213 int32_t srcLength);
02214
02221 inline UnicodeString& append(char16_t srcChar);
02222
02229 UnicodeString& append(UChar32 srcChar);
02230
02231
02232
02233
02247 inline UnicodeString& insert(int32_t start,
02248 const UnicodeString& srcText,
02249 int32_t srcStart,
02250 int32_t srcLength);
02251
02260 inline UnicodeString& insert(int32_t start,
02261 const UnicodeString& srcText);
02262
02276 inline UnicodeString& insert(int32_t start,
02277 const char16_t *srcChars,
02278 int32_t srcStart,
02279 int32_t srcLength);
02280
02290 inline UnicodeString& insert(int32_t start,
02291 ConstChar16Ptr srcChars,
02292 int32_t srcLength);
02293
02302 inline UnicodeString& insert(int32_t start,
02303 char16_t srcChar);
02304
02313 inline UnicodeString& insert(int32_t start,
02314 UChar32 srcChar);
02315
02316
02317
02318
02336 UnicodeString& replace(int32_t start,
02337 int32_t length,
02338 const UnicodeString& srcText,
02339 int32_t srcStart,
02340 int32_t srcLength);
02341
02354 UnicodeString& replace(int32_t start,
02355 int32_t length,
02356 const UnicodeString& srcText);
02357
02375 UnicodeString& replace(int32_t start,
02376 int32_t length,
02377 const char16_t *srcChars,
02378 int32_t srcStart,
02379 int32_t srcLength);
02380
02393 inline UnicodeString& replace(int32_t start,
02394 int32_t length,
02395 ConstChar16Ptr srcChars,
02396 int32_t srcLength);
02397
02409 inline UnicodeString& replace(int32_t start,
02410 int32_t length,
02411 char16_t srcChar);
02412
02424 UnicodeString& replace(int32_t start, int32_t length, UChar32 srcChar);
02425
02435 inline UnicodeString& replaceBetween(int32_t start,
02436 int32_t limit,
02437 const UnicodeString& srcText);
02438
02453 inline UnicodeString& replaceBetween(int32_t start,
02454 int32_t limit,
02455 const UnicodeString& srcText,
02456 int32_t srcStart,
02457 int32_t srcLimit);
02458
02469 virtual void handleReplaceBetween(int32_t start,
02470 int32_t limit,
02471 const UnicodeString& text);
02472
02478 virtual UBool hasMetaData() const;
02479
02495 virtual void copy(int32_t start, int32_t limit, int32_t dest);
02496
02497
02498
02507 inline UnicodeString& findAndReplace(const UnicodeString& oldText,
02508 const UnicodeString& newText);
02509
02521 inline UnicodeString& findAndReplace(int32_t start,
02522 int32_t length,
02523 const UnicodeString& oldText,
02524 const UnicodeString& newText);
02525
02543 UnicodeString& findAndReplace(int32_t start,
02544 int32_t length,
02545 const UnicodeString& oldText,
02546 int32_t oldStart,
02547 int32_t oldLength,
02548 const UnicodeString& newText,
02549 int32_t newStart,
02550 int32_t newLength);
02551
02552
02553
02554
02560 inline UnicodeString& remove(void);
02561
02570 inline UnicodeString& remove(int32_t start,
02571 int32_t length = (int32_t)INT32_MAX);
02572
02581 inline UnicodeString& removeBetween(int32_t start,
02582 int32_t limit = (int32_t)INT32_MAX);
02583
02593 inline UnicodeString &retainBetween(int32_t start, int32_t limit = INT32_MAX);
02594
02595
02596
02608 UBool padLeading(int32_t targetLength,
02609 char16_t padChar = 0x0020);
02610
02622 UBool padTrailing(int32_t targetLength,
02623 char16_t padChar = 0x0020);
02624
02631 inline UBool truncate(int32_t targetLength);
02632
02638 UnicodeString& trim(void);
02639
02640
02641
02642
02648 inline UnicodeString& reverse(void);
02649
02658 inline UnicodeString& reverse(int32_t start,
02659 int32_t length);
02660
02667 UnicodeString& toUpper(void);
02668
02676 UnicodeString& toUpper(const Locale& locale);
02677
02684 UnicodeString& toLower(void);
02685
02693 UnicodeString& toLower(const Locale& locale);
02694
02695 #if !UCONFIG_NO_BREAK_ITERATION
02696
02723 UnicodeString &toTitle(BreakIterator *titleIter);
02724
02752 UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale);
02753
02785 UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale, uint32_t options);
02786
02787 #endif
02788
02802 UnicodeString &foldCase(uint32_t options=0 );
02803
02804
02805
02806
02807
02851 char16_t *getBuffer(int32_t minCapacity);
02852
02873 void releaseBuffer(int32_t newLength=-1);
02874
02905 inline const char16_t *getBuffer() const;
02906
02940 const char16_t *getTerminatedBuffer();
02941
02942
02943
02944
02945
02949 inline UnicodeString();
02950
02962 UnicodeString(int32_t capacity, UChar32 c, int32_t count);
02963
02973 UNISTR_FROM_CHAR_EXPLICIT UnicodeString(char16_t ch);
02974
02984 UNISTR_FROM_CHAR_EXPLICIT UnicodeString(UChar32 ch);
02985
02996 UNISTR_FROM_STRING_EXPLICIT UnicodeString(const char16_t *text);
02997
02998
02999
03000
03001
03002 #if !U_CHAR16_IS_TYPEDEF
03003
03013 UNISTR_FROM_STRING_EXPLICIT UnicodeString(const uint16_t *text) :
03014 UnicodeString(ConstChar16Ptr(text)) {}
03015 #endif
03016
03017
03018
03019
03020
03021 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
03022
03033 UNISTR_FROM_STRING_EXPLICIT UnicodeString(const wchar_t *text) :
03034 UnicodeString(ConstChar16Ptr(text)) {}
03035 #endif
03036
03037
03038
03039
03040
03051 UNISTR_FROM_STRING_EXPLICIT inline UnicodeString(const std::nullptr_t text);
03052
03060 UnicodeString(const char16_t *text,
03061 int32_t textLength);
03062
03063
03064
03065
03066
03067 #if !U_CHAR16_IS_TYPEDEF
03068
03075 UnicodeString(const uint16_t *text, int32_t length) :
03076 UnicodeString(ConstChar16Ptr(text), length) {}
03077 #endif
03078
03079
03080
03081
03082
03083 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
03084
03092 UnicodeString(const wchar_t *text, int32_t length) :
03093 UnicodeString(ConstChar16Ptr(text), length) {}
03094 #endif
03095
03096
03097
03098
03099
03107 inline UnicodeString(const std::nullptr_t text, int32_t length);
03108
03131 UnicodeString(UBool isTerminated,
03132 ConstChar16Ptr text,
03133 int32_t textLength);
03134
03153 UnicodeString(char16_t *buffer, int32_t buffLength, int32_t buffCapacity);
03154
03155
03156
03157
03158
03159 #if !U_CHAR16_IS_TYPEDEF
03160
03168 UnicodeString(uint16_t *buffer, int32_t buffLength, int32_t buffCapacity) :
03169 UnicodeString(Char16Ptr(buffer), buffLength, buffCapacity) {}
03170 #endif
03171
03172
03173
03174
03175
03176 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
03177
03186 UnicodeString(wchar_t *buffer, int32_t buffLength, int32_t buffCapacity) :
03187 UnicodeString(Char16Ptr(buffer), buffLength, buffCapacity) {}
03188 #endif
03189
03190
03191
03192
03193
03202 inline UnicodeString(std::nullptr_t buffer, int32_t buffLength, int32_t buffCapacity);
03203
03204 #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
03205
03225 UNISTR_FROM_STRING_EXPLICIT UnicodeString(const char *codepageData);
03226
03235 UnicodeString(const char *codepageData, int32_t dataLength);
03236
03237 #endif
03238
03239 #if !UCONFIG_NO_CONVERSION
03240
03258 UnicodeString(const char *codepageData, const char *codepage);
03259
03277 UnicodeString(const char *codepageData, int32_t dataLength, const char *codepage);
03278
03300 UnicodeString(
03301 const char *src, int32_t srcLength,
03302 UConverter *cnv,
03303 UErrorCode &errorCode);
03304
03305 #endif
03306
03331 UnicodeString(const char *src, int32_t length, enum EInvariant inv);
03332
03333
03350 UnicodeString(const UnicodeString& that);
03351
03358 UnicodeString(UnicodeString &&src) U_NOEXCEPT;
03359
03366 UnicodeString(const UnicodeString& src, int32_t srcStart);
03367
03375 UnicodeString(const UnicodeString& src, int32_t srcStart, int32_t srcLength);
03376
03393 virtual Replaceable *clone() const;
03394
03398 virtual ~UnicodeString();
03399
03413 static UnicodeString fromUTF8(StringPiece utf8);
03414
03426 static UnicodeString fromUTF32(const UChar32 *utf32, int32_t length);
03427
03428
03429
03464 UnicodeString unescape() const;
03465
03485 UChar32 unescapeAt(int32_t &offset) const;
03486
03492 static UClassID U_EXPORT2 getStaticClassID();
03493
03499 virtual UClassID getDynamicClassID() const;
03500
03501
03502
03503
03504
03505 protected:
03510 virtual int32_t getLength() const;
03511
03517 virtual char16_t getCharAt(int32_t offset) const;
03518
03524 virtual UChar32 getChar32At(int32_t offset) const;
03525
03526 private:
03527
03528 UnicodeString &setToUTF8(StringPiece utf8);
03529
03530
03531
03532
03533
03534 int32_t
03535 toUTF8(int32_t start, int32_t len,
03536 char *target, int32_t capacity) const;
03537
03542 UBool doEquals(const UnicodeString &text, int32_t len) const;
03543
03544 inline int8_t
03545 doCompare(int32_t start,
03546 int32_t length,
03547 const UnicodeString& srcText,
03548 int32_t srcStart,
03549 int32_t srcLength) const;
03550
03551 int8_t doCompare(int32_t start,
03552 int32_t length,
03553 const char16_t *srcChars,
03554 int32_t srcStart,
03555 int32_t srcLength) const;
03556
03557 inline int8_t
03558 doCompareCodePointOrder(int32_t start,
03559 int32_t length,
03560 const UnicodeString& srcText,
03561 int32_t srcStart,
03562 int32_t srcLength) const;
03563
03564 int8_t doCompareCodePointOrder(int32_t start,
03565 int32_t length,
03566 const char16_t *srcChars,
03567 int32_t srcStart,
03568 int32_t srcLength) const;
03569
03570 inline int8_t
03571 doCaseCompare(int32_t start,
03572 int32_t length,
03573 const UnicodeString &srcText,
03574 int32_t srcStart,
03575 int32_t srcLength,
03576 uint32_t options) const;
03577
03578 int8_t
03579 doCaseCompare(int32_t start,
03580 int32_t length,
03581 const char16_t *srcChars,
03582 int32_t srcStart,
03583 int32_t srcLength,
03584 uint32_t options) const;
03585
03586 int32_t doIndexOf(char16_t c,
03587 int32_t start,
03588 int32_t length) const;
03589
03590 int32_t doIndexOf(UChar32 c,
03591 int32_t start,
03592 int32_t length) const;
03593
03594 int32_t doLastIndexOf(char16_t c,
03595 int32_t start,
03596 int32_t length) const;
03597
03598 int32_t doLastIndexOf(UChar32 c,
03599 int32_t start,
03600 int32_t length) const;
03601
03602 void doExtract(int32_t start,
03603 int32_t length,
03604 char16_t *dst,
03605 int32_t dstStart) const;
03606
03607 inline void doExtract(int32_t start,
03608 int32_t length,
03609 UnicodeString& target) const;
03610
03611 inline char16_t doCharAt(int32_t offset) const;
03612
03613 UnicodeString& doReplace(int32_t start,
03614 int32_t length,
03615 const UnicodeString& srcText,
03616 int32_t srcStart,
03617 int32_t srcLength);
03618
03619 UnicodeString& doReplace(int32_t start,
03620 int32_t length,
03621 const char16_t *srcChars,
03622 int32_t srcStart,
03623 int32_t srcLength);
03624
03625 UnicodeString& doAppend(const UnicodeString& src, int32_t srcStart, int32_t srcLength);
03626 UnicodeString& doAppend(const char16_t *srcChars, int32_t srcStart, int32_t srcLength);
03627
03628 UnicodeString& doReverse(int32_t start,
03629 int32_t length);
03630
03631
03632 int32_t doHashCode(void) const;
03633
03634
03635
03636 inline char16_t* getArrayStart(void);
03637 inline const char16_t* getArrayStart(void) const;
03638
03639 inline UBool hasShortLength() const;
03640 inline int32_t getShortLength() const;
03641
03642
03643
03644 inline UBool isWritable() const;
03645
03646
03647 inline UBool isBufferWritable() const;
03648
03649
03650 inline void setZeroLength();
03651 inline void setShortLength(int32_t len);
03652 inline void setLength(int32_t len);
03653 inline void setToEmpty();
03654 inline void setArray(char16_t *array, int32_t len, int32_t capacity);
03655
03656
03657
03658
03659
03660
03661 UBool allocate(int32_t capacity);
03662
03663
03664 void releaseArray(void);
03665
03666
03667 void unBogus();
03668
03669
03670 UnicodeString ©From(const UnicodeString &src, UBool fastCopy=FALSE);
03671
03672
03673 void copyFieldsFrom(UnicodeString &src, UBool setSrcToBogus) U_NOEXCEPT;
03674
03675
03676 inline void pinIndex(int32_t& start) const;
03677 inline void pinIndices(int32_t& start,
03678 int32_t& length) const;
03679
03680 #if !UCONFIG_NO_CONVERSION
03681
03682
03683 int32_t doExtract(int32_t start, int32_t length,
03684 char *dest, int32_t destCapacity,
03685 UConverter *cnv,
03686 UErrorCode &errorCode) const;
03687
03688
03689
03690
03691
03692
03693
03694
03695
03696
03697
03698 void doCodepageCreate(const char *codepageData,
03699 int32_t dataLength,
03700 const char *codepage);
03701
03702
03703
03704
03705
03706 void
03707 doCodepageCreate(const char *codepageData,
03708 int32_t dataLength,
03709 UConverter *converter,
03710 UErrorCode &status);
03711
03712 #endif
03713
03714
03715
03716
03717
03718
03719
03720
03721
03722
03723
03724
03725 UBool cloneArrayIfNeeded(int32_t newCapacity = -1,
03726 int32_t growCapacity = -1,
03727 UBool doCopyArray = TRUE,
03728 int32_t **pBufferToDelete = 0,
03729 UBool forceClone = FALSE);
03730
03736 UnicodeString &
03737 caseMap(int32_t caseLocale, uint32_t options,
03738 #if !UCONFIG_NO_BREAK_ITERATION
03739 BreakIterator *iter,
03740 #endif
03741 UStringCaseMapper *stringCaseMapper);
03742
03743
03744 void addRef(void);
03745 int32_t removeRef(void);
03746 int32_t refCount(void) const;
03747
03748
03749 enum {
03755 US_STACKBUF_SIZE=(int32_t)(UNISTR_OBJECT_SIZE-sizeof(void *)-2)/U_SIZEOF_UCHAR,
03756 kInvalidUChar=0xffff,
03757 kInvalidHashCode=0,
03758 kEmptyHashCode=1,
03759
03760
03761 kIsBogus=1,
03762 kUsingStackBuffer=2,
03763 kRefCounted=4,
03764 kBufferIsReadonly=8,
03765 kOpenGetBuffer=16,
03766
03767 kAllStorageFlags=0x1f,
03768
03769 kLengthShift=5,
03770 kLength1=1<<kLengthShift,
03771 kMaxShortLength=0x3ff,
03772 kLengthIsLarge=0xffe0,
03773
03774
03775 kShortString=kUsingStackBuffer,
03776 kLongString=kRefCounted,
03777 kReadonlyAlias=kBufferIsReadonly,
03778 kWritableAlias=0
03779 };
03780
03781 friend class UnicodeStringAppendable;
03782
03783 union StackBufferOrFields;
03784 friend union StackBufferOrFields;
03785
03786
03787
03788
03789
03790
03791
03792
03793
03794
03795
03796
03797
03798
03799
03800
03801
03802
03803
03804
03805
03806
03807
03808
03809
03810
03811
03812
03813
03814
03815
03816
03817
03818
03819
03820
03821
03822
03823
03824
03825
03826
03827 union StackBufferOrFields {
03828
03829
03830 struct {
03831 int16_t fLengthAndFlags;
03832 char16_t fBuffer[US_STACKBUF_SIZE];
03833 } fStackFields;
03834 struct {
03835 int16_t fLengthAndFlags;
03836 int32_t fLength;
03837 int32_t fCapacity;
03838
03839
03840 char16_t *fArray;
03841 } fFields;
03842 } fUnion;
03843 };
03844
03853 U_COMMON_API UnicodeString U_EXPORT2
03854 operator+ (const UnicodeString &s1, const UnicodeString &s2);
03855
03856
03857
03858
03859
03860
03861
03862
03863
03864 inline void
03865 UnicodeString::pinIndex(int32_t& start) const
03866 {
03867
03868 if(start < 0) {
03869 start = 0;
03870 } else if(start > length()) {
03871 start = length();
03872 }
03873 }
03874
03875 inline void
03876 UnicodeString::pinIndices(int32_t& start,
03877 int32_t& _length) const
03878 {
03879
03880 int32_t len = length();
03881 if(start < 0) {
03882 start = 0;
03883 } else if(start > len) {
03884 start = len;
03885 }
03886 if(_length < 0) {
03887 _length = 0;
03888 } else if(_length > (len - start)) {
03889 _length = (len - start);
03890 }
03891 }
03892
03893 inline char16_t*
03894 UnicodeString::getArrayStart() {
03895 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
03896 fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
03897 }
03898
03899 inline const char16_t*
03900 UnicodeString::getArrayStart() const {
03901 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
03902 fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
03903 }
03904
03905
03906
03907
03908
03909 inline
03910 UnicodeString::UnicodeString() {
03911 fUnion.fStackFields.fLengthAndFlags=kShortString;
03912 }
03913
03914 inline UnicodeString::UnicodeString(const std::nullptr_t ) {
03915 fUnion.fStackFields.fLengthAndFlags=kShortString;
03916 }
03917
03918 inline UnicodeString::UnicodeString(const std::nullptr_t , int32_t ) {
03919 fUnion.fStackFields.fLengthAndFlags=kShortString;
03920 }
03921
03922 inline UnicodeString::UnicodeString(std::nullptr_t , int32_t , int32_t ) {
03923 fUnion.fStackFields.fLengthAndFlags=kShortString;
03924 }
03925
03926
03927
03928
03929 inline UBool
03930 UnicodeString::hasShortLength() const {
03931 return fUnion.fFields.fLengthAndFlags>=0;
03932 }
03933
03934 inline int32_t
03935 UnicodeString::getShortLength() const {
03936
03937
03938 return fUnion.fFields.fLengthAndFlags>>kLengthShift;
03939 }
03940
03941 inline int32_t
03942 UnicodeString::length() const {
03943 return hasShortLength() ? getShortLength() : fUnion.fFields.fLength;
03944 }
03945
03946 inline int32_t
03947 UnicodeString::getCapacity() const {
03948 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
03949 US_STACKBUF_SIZE : fUnion.fFields.fCapacity;
03950 }
03951
03952 inline int32_t
03953 UnicodeString::hashCode() const
03954 { return doHashCode(); }
03955
03956 inline UBool
03957 UnicodeString::isBogus() const
03958 { return (UBool)(fUnion.fFields.fLengthAndFlags & kIsBogus); }
03959
03960 inline UBool
03961 UnicodeString::isWritable() const
03962 { return (UBool)!(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus)); }
03963
03964 inline UBool
03965 UnicodeString::isBufferWritable() const
03966 {
03967 return (UBool)(
03968 !(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus|kBufferIsReadonly)) &&
03969 (!(fUnion.fFields.fLengthAndFlags&kRefCounted) || refCount()==1));
03970 }
03971
03972 inline const char16_t *
03973 UnicodeString::getBuffer() const {
03974 if(fUnion.fFields.fLengthAndFlags&(kIsBogus|kOpenGetBuffer)) {
03975 return nullptr;
03976 } else if(fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) {
03977 return fUnion.fStackFields.fBuffer;
03978 } else {
03979 return fUnion.fFields.fArray;
03980 }
03981 }
03982
03983
03984
03985
03986 inline int8_t
03987 UnicodeString::doCompare(int32_t start,
03988 int32_t thisLength,
03989 const UnicodeString& srcText,
03990 int32_t srcStart,
03991 int32_t srcLength) const
03992 {
03993 if(srcText.isBogus()) {
03994 return (int8_t)!isBogus();
03995 } else {
03996 srcText.pinIndices(srcStart, srcLength);
03997 return doCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
03998 }
03999 }
04000
04001 inline UBool
04002 UnicodeString::operator== (const UnicodeString& text) const
04003 {
04004 if(isBogus()) {
04005 return text.isBogus();
04006 } else {
04007 int32_t len = length(), textLength = text.length();
04008 return !text.isBogus() && len == textLength && doEquals(text, len);
04009 }
04010 }
04011
04012 inline UBool
04013 UnicodeString::operator!= (const UnicodeString& text) const
04014 { return (! operator==(text)); }
04015
04016 inline UBool
04017 UnicodeString::operator> (const UnicodeString& text) const
04018 { return doCompare(0, length(), text, 0, text.length()) == 1; }
04019
04020 inline UBool
04021 UnicodeString::operator< (const UnicodeString& text) const
04022 { return doCompare(0, length(), text, 0, text.length()) == -1; }
04023
04024 inline UBool
04025 UnicodeString::operator>= (const UnicodeString& text) const
04026 { return doCompare(0, length(), text, 0, text.length()) != -1; }
04027
04028 inline UBool
04029 UnicodeString::operator<= (const UnicodeString& text) const
04030 { return doCompare(0, length(), text, 0, text.length()) != 1; }
04031
04032 inline int8_t
04033 UnicodeString::compare(const UnicodeString& text) const
04034 { return doCompare(0, length(), text, 0, text.length()); }
04035
04036 inline int8_t
04037 UnicodeString::compare(int32_t start,
04038 int32_t _length,
04039 const UnicodeString& srcText) const
04040 { return doCompare(start, _length, srcText, 0, srcText.length()); }
04041
04042 inline int8_t
04043 UnicodeString::compare(ConstChar16Ptr srcChars,
04044 int32_t srcLength) const
04045 { return doCompare(0, length(), srcChars, 0, srcLength); }
04046
04047 inline int8_t
04048 UnicodeString::compare(int32_t start,
04049 int32_t _length,
04050 const UnicodeString& srcText,
04051 int32_t srcStart,
04052 int32_t srcLength) const
04053 { return doCompare(start, _length, srcText, srcStart, srcLength); }
04054
04055 inline int8_t
04056 UnicodeString::compare(int32_t start,
04057 int32_t _length,
04058 const char16_t *srcChars) const
04059 { return doCompare(start, _length, srcChars, 0, _length); }
04060
04061 inline int8_t
04062 UnicodeString::compare(int32_t start,
04063 int32_t _length,
04064 const char16_t *srcChars,
04065 int32_t srcStart,
04066 int32_t srcLength) const
04067 { return doCompare(start, _length, srcChars, srcStart, srcLength); }
04068
04069 inline int8_t
04070 UnicodeString::compareBetween(int32_t start,
04071 int32_t limit,
04072 const UnicodeString& srcText,
04073 int32_t srcStart,
04074 int32_t srcLimit) const
04075 { return doCompare(start, limit - start,
04076 srcText, srcStart, srcLimit - srcStart); }
04077
04078 inline int8_t
04079 UnicodeString::doCompareCodePointOrder(int32_t start,
04080 int32_t thisLength,
04081 const UnicodeString& srcText,
04082 int32_t srcStart,
04083 int32_t srcLength) const
04084 {
04085 if(srcText.isBogus()) {
04086 return (int8_t)!isBogus();
04087 } else {
04088 srcText.pinIndices(srcStart, srcLength);
04089 return doCompareCodePointOrder(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
04090 }
04091 }
04092
04093 inline int8_t
04094 UnicodeString::compareCodePointOrder(const UnicodeString& text) const
04095 { return doCompareCodePointOrder(0, length(), text, 0, text.length()); }
04096
04097 inline int8_t
04098 UnicodeString::compareCodePointOrder(int32_t start,
04099 int32_t _length,
04100 const UnicodeString& srcText) const
04101 { return doCompareCodePointOrder(start, _length, srcText, 0, srcText.length()); }
04102
04103 inline int8_t
04104 UnicodeString::compareCodePointOrder(ConstChar16Ptr srcChars,
04105 int32_t srcLength) const
04106 { return doCompareCodePointOrder(0, length(), srcChars, 0, srcLength); }
04107
04108 inline int8_t
04109 UnicodeString::compareCodePointOrder(int32_t start,
04110 int32_t _length,
04111 const UnicodeString& srcText,
04112 int32_t srcStart,
04113 int32_t srcLength) const
04114 { return doCompareCodePointOrder(start, _length, srcText, srcStart, srcLength); }
04115
04116 inline int8_t
04117 UnicodeString::compareCodePointOrder(int32_t start,
04118 int32_t _length,
04119 const char16_t *srcChars) const
04120 { return doCompareCodePointOrder(start, _length, srcChars, 0, _length); }
04121
04122 inline int8_t
04123 UnicodeString::compareCodePointOrder(int32_t start,
04124 int32_t _length,
04125 const char16_t *srcChars,
04126 int32_t srcStart,
04127 int32_t srcLength) const
04128 { return doCompareCodePointOrder(start, _length, srcChars, srcStart, srcLength); }
04129
04130 inline int8_t
04131 UnicodeString::compareCodePointOrderBetween(int32_t start,
04132 int32_t limit,
04133 const UnicodeString& srcText,
04134 int32_t srcStart,
04135 int32_t srcLimit) const
04136 { return doCompareCodePointOrder(start, limit - start,
04137 srcText, srcStart, srcLimit - srcStart); }
04138
04139 inline int8_t
04140 UnicodeString::doCaseCompare(int32_t start,
04141 int32_t thisLength,
04142 const UnicodeString &srcText,
04143 int32_t srcStart,
04144 int32_t srcLength,
04145 uint32_t options) const
04146 {
04147 if(srcText.isBogus()) {
04148 return (int8_t)!isBogus();
04149 } else {
04150 srcText.pinIndices(srcStart, srcLength);
04151 return doCaseCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength, options);
04152 }
04153 }
04154
04155 inline int8_t
04156 UnicodeString::caseCompare(const UnicodeString &text, uint32_t options) const {
04157 return doCaseCompare(0, length(), text, 0, text.length(), options);
04158 }
04159
04160 inline int8_t
04161 UnicodeString::caseCompare(int32_t start,
04162 int32_t _length,
04163 const UnicodeString &srcText,
04164 uint32_t options) const {
04165 return doCaseCompare(start, _length, srcText, 0, srcText.length(), options);
04166 }
04167
04168 inline int8_t
04169 UnicodeString::caseCompare(ConstChar16Ptr srcChars,
04170 int32_t srcLength,
04171 uint32_t options) const {
04172 return doCaseCompare(0, length(), srcChars, 0, srcLength, options);
04173 }
04174
04175 inline int8_t
04176 UnicodeString::caseCompare(int32_t start,
04177 int32_t _length,
04178 const UnicodeString &srcText,
04179 int32_t srcStart,
04180 int32_t srcLength,
04181 uint32_t options) const {
04182 return doCaseCompare(start, _length, srcText, srcStart, srcLength, options);
04183 }
04184
04185 inline int8_t
04186 UnicodeString::caseCompare(int32_t start,
04187 int32_t _length,
04188 const char16_t *srcChars,
04189 uint32_t options) const {
04190 return doCaseCompare(start, _length, srcChars, 0, _length, options);
04191 }
04192
04193 inline int8_t
04194 UnicodeString::caseCompare(int32_t start,
04195 int32_t _length,
04196 const char16_t *srcChars,
04197 int32_t srcStart,
04198 int32_t srcLength,
04199 uint32_t options) const {
04200 return doCaseCompare(start, _length, srcChars, srcStart, srcLength, options);
04201 }
04202
04203 inline int8_t
04204 UnicodeString::caseCompareBetween(int32_t start,
04205 int32_t limit,
04206 const UnicodeString &srcText,
04207 int32_t srcStart,
04208 int32_t srcLimit,
04209 uint32_t options) const {
04210 return doCaseCompare(start, limit - start, srcText, srcStart, srcLimit - srcStart, options);
04211 }
04212
04213 inline int32_t
04214 UnicodeString::indexOf(const UnicodeString& srcText,
04215 int32_t srcStart,
04216 int32_t srcLength,
04217 int32_t start,
04218 int32_t _length) const
04219 {
04220 if(!srcText.isBogus()) {
04221 srcText.pinIndices(srcStart, srcLength);
04222 if(srcLength > 0) {
04223 return indexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
04224 }
04225 }
04226 return -1;
04227 }
04228
04229 inline int32_t
04230 UnicodeString::indexOf(const UnicodeString& text) const
04231 { return indexOf(text, 0, text.length(), 0, length()); }
04232
04233 inline int32_t
04234 UnicodeString::indexOf(const UnicodeString& text,
04235 int32_t start) const {
04236 pinIndex(start);
04237 return indexOf(text, 0, text.length(), start, length() - start);
04238 }
04239
04240 inline int32_t
04241 UnicodeString::indexOf(const UnicodeString& text,
04242 int32_t start,
04243 int32_t _length) const
04244 { return indexOf(text, 0, text.length(), start, _length); }
04245
04246 inline int32_t
04247 UnicodeString::indexOf(const char16_t *srcChars,
04248 int32_t srcLength,
04249 int32_t start) const {
04250 pinIndex(start);
04251 return indexOf(srcChars, 0, srcLength, start, length() - start);
04252 }
04253
04254 inline int32_t
04255 UnicodeString::indexOf(ConstChar16Ptr srcChars,
04256 int32_t srcLength,
04257 int32_t start,
04258 int32_t _length) const
04259 { return indexOf(srcChars, 0, srcLength, start, _length); }
04260
04261 inline int32_t
04262 UnicodeString::indexOf(char16_t c,
04263 int32_t start,
04264 int32_t _length) const
04265 { return doIndexOf(c, start, _length); }
04266
04267 inline int32_t
04268 UnicodeString::indexOf(UChar32 c,
04269 int32_t start,
04270 int32_t _length) const
04271 { return doIndexOf(c, start, _length); }
04272
04273 inline int32_t
04274 UnicodeString::indexOf(char16_t c) const
04275 { return doIndexOf(c, 0, length()); }
04276
04277 inline int32_t
04278 UnicodeString::indexOf(UChar32 c) const
04279 { return indexOf(c, 0, length()); }
04280
04281 inline int32_t
04282 UnicodeString::indexOf(char16_t c,
04283 int32_t start) const {
04284 pinIndex(start);
04285 return doIndexOf(c, start, length() - start);
04286 }
04287
04288 inline int32_t
04289 UnicodeString::indexOf(UChar32 c,
04290 int32_t start) const {
04291 pinIndex(start);
04292 return indexOf(c, start, length() - start);
04293 }
04294
04295 inline int32_t
04296 UnicodeString::lastIndexOf(ConstChar16Ptr srcChars,
04297 int32_t srcLength,
04298 int32_t start,
04299 int32_t _length) const
04300 { return lastIndexOf(srcChars, 0, srcLength, start, _length); }
04301
04302 inline int32_t
04303 UnicodeString::lastIndexOf(const char16_t *srcChars,
04304 int32_t srcLength,
04305 int32_t start) const {
04306 pinIndex(start);
04307 return lastIndexOf(srcChars, 0, srcLength, start, length() - start);
04308 }
04309
04310 inline int32_t
04311 UnicodeString::lastIndexOf(const UnicodeString& srcText,
04312 int32_t srcStart,
04313 int32_t srcLength,
04314 int32_t start,
04315 int32_t _length) const
04316 {
04317 if(!srcText.isBogus()) {
04318 srcText.pinIndices(srcStart, srcLength);
04319 if(srcLength > 0) {
04320 return lastIndexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
04321 }
04322 }
04323 return -1;
04324 }
04325
04326 inline int32_t
04327 UnicodeString::lastIndexOf(const UnicodeString& text,
04328 int32_t start,
04329 int32_t _length) const
04330 { return lastIndexOf(text, 0, text.length(), start, _length); }
04331
04332 inline int32_t
04333 UnicodeString::lastIndexOf(const UnicodeString& text,
04334 int32_t start) const {
04335 pinIndex(start);
04336 return lastIndexOf(text, 0, text.length(), start, length() - start);
04337 }
04338
04339 inline int32_t
04340 UnicodeString::lastIndexOf(const UnicodeString& text) const
04341 { return lastIndexOf(text, 0, text.length(), 0, length()); }
04342
04343 inline int32_t
04344 UnicodeString::lastIndexOf(char16_t c,
04345 int32_t start,
04346 int32_t _length) const
04347 { return doLastIndexOf(c, start, _length); }
04348
04349 inline int32_t
04350 UnicodeString::lastIndexOf(UChar32 c,
04351 int32_t start,
04352 int32_t _length) const {
04353 return doLastIndexOf(c, start, _length);
04354 }
04355
04356 inline int32_t
04357 UnicodeString::lastIndexOf(char16_t c) const
04358 { return doLastIndexOf(c, 0, length()); }
04359
04360 inline int32_t
04361 UnicodeString::lastIndexOf(UChar32 c) const {
04362 return lastIndexOf(c, 0, length());
04363 }
04364
04365 inline int32_t
04366 UnicodeString::lastIndexOf(char16_t c,
04367 int32_t start) const {
04368 pinIndex(start);
04369 return doLastIndexOf(c, start, length() - start);
04370 }
04371
04372 inline int32_t
04373 UnicodeString::lastIndexOf(UChar32 c,
04374 int32_t start) const {
04375 pinIndex(start);
04376 return lastIndexOf(c, start, length() - start);
04377 }
04378
04379 inline UBool
04380 UnicodeString::startsWith(const UnicodeString& text) const
04381 { return compare(0, text.length(), text, 0, text.length()) == 0; }
04382
04383 inline UBool
04384 UnicodeString::startsWith(const UnicodeString& srcText,
04385 int32_t srcStart,
04386 int32_t srcLength) const
04387 { return doCompare(0, srcLength, srcText, srcStart, srcLength) == 0; }
04388
04389 inline UBool
04390 UnicodeString::startsWith(ConstChar16Ptr srcChars, int32_t srcLength) const {
04391 if(srcLength < 0) {
04392 srcLength = u_strlen(toUCharPtr(srcChars));
04393 }
04394 return doCompare(0, srcLength, srcChars, 0, srcLength) == 0;
04395 }
04396
04397 inline UBool
04398 UnicodeString::startsWith(const char16_t *srcChars, int32_t srcStart, int32_t srcLength) const {
04399 if(srcLength < 0) {
04400 srcLength = u_strlen(toUCharPtr(srcChars));
04401 }
04402 return doCompare(0, srcLength, srcChars, srcStart, srcLength) == 0;
04403 }
04404
04405 inline UBool
04406 UnicodeString::endsWith(const UnicodeString& text) const
04407 { return doCompare(length() - text.length(), text.length(),
04408 text, 0, text.length()) == 0; }
04409
04410 inline UBool
04411 UnicodeString::endsWith(const UnicodeString& srcText,
04412 int32_t srcStart,
04413 int32_t srcLength) const {
04414 srcText.pinIndices(srcStart, srcLength);
04415 return doCompare(length() - srcLength, srcLength,
04416 srcText, srcStart, srcLength) == 0;
04417 }
04418
04419 inline UBool
04420 UnicodeString::endsWith(ConstChar16Ptr srcChars,
04421 int32_t srcLength) const {
04422 if(srcLength < 0) {
04423 srcLength = u_strlen(toUCharPtr(srcChars));
04424 }
04425 return doCompare(length() - srcLength, srcLength,
04426 srcChars, 0, srcLength) == 0;
04427 }
04428
04429 inline UBool
04430 UnicodeString::endsWith(const char16_t *srcChars,
04431 int32_t srcStart,
04432 int32_t srcLength) const {
04433 if(srcLength < 0) {
04434 srcLength = u_strlen(toUCharPtr(srcChars + srcStart));
04435 }
04436 return doCompare(length() - srcLength, srcLength,
04437 srcChars, srcStart, srcLength) == 0;
04438 }
04439
04440
04441
04442
04443 inline UnicodeString&
04444 UnicodeString::replace(int32_t start,
04445 int32_t _length,
04446 const UnicodeString& srcText)
04447 { return doReplace(start, _length, srcText, 0, srcText.length()); }
04448
04449 inline UnicodeString&
04450 UnicodeString::replace(int32_t start,
04451 int32_t _length,
04452 const UnicodeString& srcText,
04453 int32_t srcStart,
04454 int32_t srcLength)
04455 { return doReplace(start, _length, srcText, srcStart, srcLength); }
04456
04457 inline UnicodeString&
04458 UnicodeString::replace(int32_t start,
04459 int32_t _length,
04460 ConstChar16Ptr srcChars,
04461 int32_t srcLength)
04462 { return doReplace(start, _length, srcChars, 0, srcLength); }
04463
04464 inline UnicodeString&
04465 UnicodeString::replace(int32_t start,
04466 int32_t _length,
04467 const char16_t *srcChars,
04468 int32_t srcStart,
04469 int32_t srcLength)
04470 { return doReplace(start, _length, srcChars, srcStart, srcLength); }
04471
04472 inline UnicodeString&
04473 UnicodeString::replace(int32_t start,
04474 int32_t _length,
04475 char16_t srcChar)
04476 { return doReplace(start, _length, &srcChar, 0, 1); }
04477
04478 inline UnicodeString&
04479 UnicodeString::replaceBetween(int32_t start,
04480 int32_t limit,
04481 const UnicodeString& srcText)
04482 { return doReplace(start, limit - start, srcText, 0, srcText.length()); }
04483
04484 inline UnicodeString&
04485 UnicodeString::replaceBetween(int32_t start,
04486 int32_t limit,
04487 const UnicodeString& srcText,
04488 int32_t srcStart,
04489 int32_t srcLimit)
04490 { return doReplace(start, limit - start, srcText, srcStart, srcLimit - srcStart); }
04491
04492 inline UnicodeString&
04493 UnicodeString::findAndReplace(const UnicodeString& oldText,
04494 const UnicodeString& newText)
04495 { return findAndReplace(0, length(), oldText, 0, oldText.length(),
04496 newText, 0, newText.length()); }
04497
04498 inline UnicodeString&
04499 UnicodeString::findAndReplace(int32_t start,
04500 int32_t _length,
04501 const UnicodeString& oldText,
04502 const UnicodeString& newText)
04503 { return findAndReplace(start, _length, oldText, 0, oldText.length(),
04504 newText, 0, newText.length()); }
04505
04506
04507
04508
04509 inline void
04510 UnicodeString::doExtract(int32_t start,
04511 int32_t _length,
04512 UnicodeString& target) const
04513 { target.replace(0, target.length(), *this, start, _length); }
04514
04515 inline void
04516 UnicodeString::extract(int32_t start,
04517 int32_t _length,
04518 Char16Ptr target,
04519 int32_t targetStart) const
04520 { doExtract(start, _length, target, targetStart); }
04521
04522 inline void
04523 UnicodeString::extract(int32_t start,
04524 int32_t _length,
04525 UnicodeString& target) const
04526 { doExtract(start, _length, target); }
04527
04528 #if !UCONFIG_NO_CONVERSION
04529
04530 inline int32_t
04531 UnicodeString::extract(int32_t start,
04532 int32_t _length,
04533 char *dst,
04534 const char *codepage) const
04535
04536 {
04537
04538 return extract(start, _length, dst, dst!=0 ? 0xffffffff : 0, codepage);
04539 }
04540
04541 #endif
04542
04543 inline void
04544 UnicodeString::extractBetween(int32_t start,
04545 int32_t limit,
04546 char16_t *dst,
04547 int32_t dstStart) const {
04548 pinIndex(start);
04549 pinIndex(limit);
04550 doExtract(start, limit - start, dst, dstStart);
04551 }
04552
04553 inline UnicodeString
04554 UnicodeString::tempSubStringBetween(int32_t start, int32_t limit) const {
04555 return tempSubString(start, limit - start);
04556 }
04557
04558 inline char16_t
04559 UnicodeString::doCharAt(int32_t offset) const
04560 {
04561 if((uint32_t)offset < (uint32_t)length()) {
04562 return getArrayStart()[offset];
04563 } else {
04564 return kInvalidUChar;
04565 }
04566 }
04567
04568 inline char16_t
04569 UnicodeString::charAt(int32_t offset) const
04570 { return doCharAt(offset); }
04571
04572 inline char16_t
04573 UnicodeString::operator[] (int32_t offset) const
04574 { return doCharAt(offset); }
04575
04576 inline UBool
04577 UnicodeString::isEmpty() const {
04578
04579 return (fUnion.fFields.fLengthAndFlags>>kLengthShift) == 0;
04580 }
04581
04582
04583
04584
04585 inline void
04586 UnicodeString::setZeroLength() {
04587 fUnion.fFields.fLengthAndFlags &= kAllStorageFlags;
04588 }
04589
04590 inline void
04591 UnicodeString::setShortLength(int32_t len) {
04592
04593 fUnion.fFields.fLengthAndFlags =
04594 (int16_t)((fUnion.fFields.fLengthAndFlags & kAllStorageFlags) | (len << kLengthShift));
04595 }
04596
04597 inline void
04598 UnicodeString::setLength(int32_t len) {
04599 if(len <= kMaxShortLength) {
04600 setShortLength(len);
04601 } else {
04602 fUnion.fFields.fLengthAndFlags |= kLengthIsLarge;
04603 fUnion.fFields.fLength = len;
04604 }
04605 }
04606
04607 inline void
04608 UnicodeString::setToEmpty() {
04609 fUnion.fFields.fLengthAndFlags = kShortString;
04610 }
04611
04612 inline void
04613 UnicodeString::setArray(char16_t *array, int32_t len, int32_t capacity) {
04614 setLength(len);
04615 fUnion.fFields.fArray = array;
04616 fUnion.fFields.fCapacity = capacity;
04617 }
04618
04619 inline UnicodeString&
04620 UnicodeString::operator= (char16_t ch)
04621 { return doReplace(0, length(), &ch, 0, 1); }
04622
04623 inline UnicodeString&
04624 UnicodeString::operator= (UChar32 ch)
04625 { return replace(0, length(), ch); }
04626
04627 inline UnicodeString&
04628 UnicodeString::setTo(const UnicodeString& srcText,
04629 int32_t srcStart,
04630 int32_t srcLength)
04631 {
04632 unBogus();
04633 return doReplace(0, length(), srcText, srcStart, srcLength);
04634 }
04635
04636 inline UnicodeString&
04637 UnicodeString::setTo(const UnicodeString& srcText,
04638 int32_t srcStart)
04639 {
04640 unBogus();
04641 srcText.pinIndex(srcStart);
04642 return doReplace(0, length(), srcText, srcStart, srcText.length() - srcStart);
04643 }
04644
04645 inline UnicodeString&
04646 UnicodeString::setTo(const UnicodeString& srcText)
04647 {
04648 return copyFrom(srcText);
04649 }
04650
04651 inline UnicodeString&
04652 UnicodeString::setTo(const char16_t *srcChars,
04653 int32_t srcLength)
04654 {
04655 unBogus();
04656 return doReplace(0, length(), srcChars, 0, srcLength);
04657 }
04658
04659 inline UnicodeString&
04660 UnicodeString::setTo(char16_t srcChar)
04661 {
04662 unBogus();
04663 return doReplace(0, length(), &srcChar, 0, 1);
04664 }
04665
04666 inline UnicodeString&
04667 UnicodeString::setTo(UChar32 srcChar)
04668 {
04669 unBogus();
04670 return replace(0, length(), srcChar);
04671 }
04672
04673 inline UnicodeString&
04674 UnicodeString::append(const UnicodeString& srcText,
04675 int32_t srcStart,
04676 int32_t srcLength)
04677 { return doAppend(srcText, srcStart, srcLength); }
04678
04679 inline UnicodeString&
04680 UnicodeString::append(const UnicodeString& srcText)
04681 { return doAppend(srcText, 0, srcText.length()); }
04682
04683 inline UnicodeString&
04684 UnicodeString::append(const char16_t *srcChars,
04685 int32_t srcStart,
04686 int32_t srcLength)
04687 { return doAppend(srcChars, srcStart, srcLength); }
04688
04689 inline UnicodeString&
04690 UnicodeString::append(ConstChar16Ptr srcChars,
04691 int32_t srcLength)
04692 { return doAppend(srcChars, 0, srcLength); }
04693
04694 inline UnicodeString&
04695 UnicodeString::append(char16_t srcChar)
04696 { return doAppend(&srcChar, 0, 1); }
04697
04698 inline UnicodeString&
04699 UnicodeString::operator+= (char16_t ch)
04700 { return doAppend(&ch, 0, 1); }
04701
04702 inline UnicodeString&
04703 UnicodeString::operator+= (UChar32 ch) {
04704 return append(ch);
04705 }
04706
04707 inline UnicodeString&
04708 UnicodeString::operator+= (const UnicodeString& srcText)
04709 { return doAppend(srcText, 0, srcText.length()); }
04710
04711 inline UnicodeString&
04712 UnicodeString::insert(int32_t start,
04713 const UnicodeString& srcText,
04714 int32_t srcStart,
04715 int32_t srcLength)
04716 { return doReplace(start, 0, srcText, srcStart, srcLength); }
04717
04718 inline UnicodeString&
04719 UnicodeString::insert(int32_t start,
04720 const UnicodeString& srcText)
04721 { return doReplace(start, 0, srcText, 0, srcText.length()); }
04722
04723 inline UnicodeString&
04724 UnicodeString::insert(int32_t start,
04725 const char16_t *srcChars,
04726 int32_t srcStart,
04727 int32_t srcLength)
04728 { return doReplace(start, 0, srcChars, srcStart, srcLength); }
04729
04730 inline UnicodeString&
04731 UnicodeString::insert(int32_t start,
04732 ConstChar16Ptr srcChars,
04733 int32_t srcLength)
04734 { return doReplace(start, 0, srcChars, 0, srcLength); }
04735
04736 inline UnicodeString&
04737 UnicodeString::insert(int32_t start,
04738 char16_t srcChar)
04739 { return doReplace(start, 0, &srcChar, 0, 1); }
04740
04741 inline UnicodeString&
04742 UnicodeString::insert(int32_t start,
04743 UChar32 srcChar)
04744 { return replace(start, 0, srcChar); }
04745
04746
04747 inline UnicodeString&
04748 UnicodeString::remove()
04749 {
04750
04751 if(isBogus()) {
04752 setToEmpty();
04753 } else {
04754 setZeroLength();
04755 }
04756 return *this;
04757 }
04758
04759 inline UnicodeString&
04760 UnicodeString::remove(int32_t start,
04761 int32_t _length)
04762 {
04763 if(start <= 0 && _length == INT32_MAX) {
04764
04765 return remove();
04766 }
04767 return doReplace(start, _length, NULL, 0, 0);
04768 }
04769
04770 inline UnicodeString&
04771 UnicodeString::removeBetween(int32_t start,
04772 int32_t limit)
04773 { return doReplace(start, limit - start, NULL, 0, 0); }
04774
04775 inline UnicodeString &
04776 UnicodeString::retainBetween(int32_t start, int32_t limit) {
04777 truncate(limit);
04778 return doReplace(0, start, NULL, 0, 0);
04779 }
04780
04781 inline UBool
04782 UnicodeString::truncate(int32_t targetLength)
04783 {
04784 if(isBogus() && targetLength == 0) {
04785
04786 unBogus();
04787 return FALSE;
04788 } else if((uint32_t)targetLength < (uint32_t)length()) {
04789 setLength(targetLength);
04790 return TRUE;
04791 } else {
04792 return FALSE;
04793 }
04794 }
04795
04796 inline UnicodeString&
04797 UnicodeString::reverse()
04798 { return doReverse(0, length()); }
04799
04800 inline UnicodeString&
04801 UnicodeString::reverse(int32_t start,
04802 int32_t _length)
04803 { return doReverse(start, _length); }
04804
04805 U_NAMESPACE_END
04806
04807 #endif