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
00035 struct UConverter;
00036 class StringThreadTest;
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
00056 U_NAMESPACE_BEGIN
00057
00058 class Locale;
00059 class StringCharacterIterator;
00060 class BreakIterator;
00061
00062
00063
00074 #define US_INV U_NAMESPACE_QUALIFIER UnicodeString::kInvariant
00075
00093 #if defined(U_DECLARE_UTF16)
00094 # define UNICODE_STRING(cs, _length) U_NAMESPACE_QUALIFIER UnicodeString(TRUE, (const UChar *)U_DECLARE_UTF16(cs), _length)
00095 #elif U_SIZEOF_WCHAR_T==U_SIZEOF_UCHAR && (U_CHARSET_FAMILY==U_ASCII_FAMILY || (U_SIZEOF_UCHAR == 2 && defined(U_WCHAR_IS_UTF16)))
00096 # define UNICODE_STRING(cs, _length) U_NAMESPACE_QUALIFIER UnicodeString(TRUE, (const UChar *)L ## cs, _length)
00097 #elif U_SIZEOF_UCHAR==1 && U_CHARSET_FAMILY==U_ASCII_FAMILY
00098 # define UNICODE_STRING(cs, _length) U_NAMESPACE_QUALIFIER UnicodeString(TRUE, (const UChar *)cs, _length)
00099 #else
00100 # define UNICODE_STRING(cs, _length) U_NAMESPACE_QUALIFIER UnicodeString(cs, _length, US_INV)
00101 #endif
00102
00116 #define UNICODE_STRING_SIMPLE(cs) UNICODE_STRING(cs, -1)
00117
00187 class U_COMMON_API UnicodeString : public Replaceable
00188 {
00189 public:
00190
00199 enum EInvariant {
00204 kInvariant
00205 };
00206
00207
00208
00209
00210
00211
00212
00220 inline UBool operator== (const UnicodeString& text) const;
00221
00229 inline UBool operator!= (const UnicodeString& text) const;
00230
00238 inline UBool operator> (const UnicodeString& text) const;
00239
00247 inline UBool operator< (const UnicodeString& text) const;
00248
00256 inline UBool operator>= (const UnicodeString& text) const;
00257
00265 inline UBool operator<= (const UnicodeString& text) const;
00266
00278 inline int8_t compare(const UnicodeString& text) const;
00279
00294 inline int8_t compare(int32_t start,
00295 int32_t length,
00296 const UnicodeString& text) const;
00297
00315 inline int8_t compare(int32_t start,
00316 int32_t length,
00317 const UnicodeString& srcText,
00318 int32_t srcStart,
00319 int32_t srcLength) const;
00320
00333 inline int8_t compare(const UChar *srcChars,
00334 int32_t srcLength) const;
00335
00350 inline int8_t compare(int32_t start,
00351 int32_t length,
00352 const UChar *srcChars) const;
00353
00371 inline int8_t compare(int32_t start,
00372 int32_t length,
00373 const UChar *srcChars,
00374 int32_t srcStart,
00375 int32_t srcLength) const;
00376
00394 inline int8_t compareBetween(int32_t start,
00395 int32_t limit,
00396 const UnicodeString& srcText,
00397 int32_t srcStart,
00398 int32_t srcLimit) const;
00399
00417 inline int8_t compareCodePointOrder(const UnicodeString& text) const;
00418
00438 inline int8_t compareCodePointOrder(int32_t start,
00439 int32_t length,
00440 const UnicodeString& srcText) const;
00441
00463 inline int8_t compareCodePointOrder(int32_t start,
00464 int32_t length,
00465 const UnicodeString& srcText,
00466 int32_t srcStart,
00467 int32_t srcLength) const;
00468
00487 inline int8_t compareCodePointOrder(const UChar *srcChars,
00488 int32_t srcLength) const;
00489
00509 inline int8_t compareCodePointOrder(int32_t start,
00510 int32_t length,
00511 const UChar *srcChars) const;
00512
00534 inline int8_t compareCodePointOrder(int32_t start,
00535 int32_t length,
00536 const UChar *srcChars,
00537 int32_t srcStart,
00538 int32_t srcLength) const;
00539
00561 inline int8_t compareCodePointOrderBetween(int32_t start,
00562 int32_t limit,
00563 const UnicodeString& srcText,
00564 int32_t srcStart,
00565 int32_t srcLimit) const;
00566
00585 inline int8_t caseCompare(const UnicodeString& text, uint32_t options) const;
00586
00607 inline int8_t caseCompare(int32_t start,
00608 int32_t length,
00609 const UnicodeString& srcText,
00610 uint32_t options) const;
00611
00634 inline int8_t caseCompare(int32_t start,
00635 int32_t length,
00636 const UnicodeString& srcText,
00637 int32_t srcStart,
00638 int32_t srcLength,
00639 uint32_t options) const;
00640
00660 inline int8_t caseCompare(const UChar *srcChars,
00661 int32_t srcLength,
00662 uint32_t options) const;
00663
00684 inline int8_t caseCompare(int32_t start,
00685 int32_t length,
00686 const UChar *srcChars,
00687 uint32_t options) const;
00688
00711 inline int8_t caseCompare(int32_t start,
00712 int32_t length,
00713 const UChar *srcChars,
00714 int32_t srcStart,
00715 int32_t srcLength,
00716 uint32_t options) const;
00717
00740 inline int8_t caseCompareBetween(int32_t start,
00741 int32_t limit,
00742 const UnicodeString& srcText,
00743 int32_t srcStart,
00744 int32_t srcLimit,
00745 uint32_t options) const;
00746
00754 inline UBool startsWith(const UnicodeString& text) const;
00755
00766 inline UBool startsWith(const UnicodeString& srcText,
00767 int32_t srcStart,
00768 int32_t srcLength) const;
00769
00778 inline UBool startsWith(const UChar *srcChars,
00779 int32_t srcLength) const;
00780
00790 inline UBool startsWith(const UChar *srcChars,
00791 int32_t srcStart,
00792 int32_t srcLength) const;
00793
00801 inline UBool endsWith(const UnicodeString& text) const;
00802
00813 inline UBool endsWith(const UnicodeString& srcText,
00814 int32_t srcStart,
00815 int32_t srcLength) const;
00816
00825 inline UBool endsWith(const UChar *srcChars,
00826 int32_t srcLength) const;
00827
00838 inline UBool endsWith(const UChar *srcChars,
00839 int32_t srcStart,
00840 int32_t srcLength) const;
00841
00842
00843
00844
00853 inline int32_t indexOf(const UnicodeString& text) const;
00854
00864 inline int32_t indexOf(const UnicodeString& text,
00865 int32_t start) const;
00866
00878 inline int32_t indexOf(const UnicodeString& text,
00879 int32_t start,
00880 int32_t length) const;
00881
00898 inline int32_t indexOf(const UnicodeString& srcText,
00899 int32_t srcStart,
00900 int32_t srcLength,
00901 int32_t start,
00902 int32_t length) const;
00903
00915 inline int32_t indexOf(const UChar *srcChars,
00916 int32_t srcLength,
00917 int32_t start) const;
00918
00931 inline int32_t indexOf(const UChar *srcChars,
00932 int32_t srcLength,
00933 int32_t start,
00934 int32_t length) const;
00935
00952 int32_t indexOf(const UChar *srcChars,
00953 int32_t srcStart,
00954 int32_t srcLength,
00955 int32_t start,
00956 int32_t length) const;
00957
00965 inline int32_t indexOf(UChar c) const;
00966
00975 inline int32_t indexOf(UChar32 c) const;
00976
00985 inline int32_t indexOf(UChar c,
00986 int32_t start) const;
00987
00997 inline int32_t indexOf(UChar32 c,
00998 int32_t start) const;
00999
01010 inline int32_t indexOf(UChar c,
01011 int32_t start,
01012 int32_t length) const;
01013
01025 inline int32_t indexOf(UChar32 c,
01026 int32_t start,
01027 int32_t length) const;
01028
01037 inline int32_t lastIndexOf(const UnicodeString& text) const;
01038
01048 inline int32_t lastIndexOf(const UnicodeString& text,
01049 int32_t start) const;
01050
01062 inline int32_t lastIndexOf(const UnicodeString& text,
01063 int32_t start,
01064 int32_t length) const;
01065
01082 inline int32_t lastIndexOf(const UnicodeString& srcText,
01083 int32_t srcStart,
01084 int32_t srcLength,
01085 int32_t start,
01086 int32_t length) const;
01087
01098 inline int32_t lastIndexOf(const UChar *srcChars,
01099 int32_t srcLength,
01100 int32_t start) const;
01101
01114 inline int32_t lastIndexOf(const UChar *srcChars,
01115 int32_t srcLength,
01116 int32_t start,
01117 int32_t length) const;
01118
01135 int32_t lastIndexOf(const UChar *srcChars,
01136 int32_t srcStart,
01137 int32_t srcLength,
01138 int32_t start,
01139 int32_t length) const;
01140
01148 inline int32_t lastIndexOf(UChar c) const;
01149
01158 inline int32_t lastIndexOf(UChar32 c) const;
01159
01168 inline int32_t lastIndexOf(UChar c,
01169 int32_t start) const;
01170
01180 inline int32_t lastIndexOf(UChar32 c,
01181 int32_t start) const;
01182
01193 inline int32_t lastIndexOf(UChar c,
01194 int32_t start,
01195 int32_t length) const;
01196
01208 inline int32_t lastIndexOf(UChar32 c,
01209 int32_t start,
01210 int32_t length) const;
01211
01212
01213
01214
01223 inline UChar charAt(int32_t offset) const;
01224
01232 inline UChar operator[] (int32_t offset) const;
01233
01245 inline UChar32 char32At(int32_t offset) const;
01246
01262 inline int32_t getChar32Start(int32_t offset) const;
01263
01280 inline int32_t getChar32Limit(int32_t offset) const;
01281
01332 int32_t moveIndex32(int32_t index, int32_t delta) const;
01333
01334
01335
01351 inline void extract(int32_t start,
01352 int32_t length,
01353 UChar *dst,
01354 int32_t dstStart = 0) const;
01355
01377 int32_t
01378 extract(UChar *dest, int32_t destCapacity,
01379 UErrorCode &errorCode) const;
01380
01391 inline void extract(int32_t start,
01392 int32_t length,
01393 UnicodeString& target) const;
01394
01406 inline void extractBetween(int32_t start,
01407 int32_t limit,
01408 UChar *dst,
01409 int32_t dstStart = 0) const;
01410
01420 virtual void extractBetween(int32_t start,
01421 int32_t limit,
01422 UnicodeString& target) const;
01423
01445 int32_t extract(int32_t start,
01446 int32_t startLength,
01447 char *target,
01448 int32_t targetCapacity,
01449 enum EInvariant inv) const;
01450
01451 #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
01452
01472 int32_t extract(int32_t start,
01473 int32_t startLength,
01474 char *target,
01475 uint32_t targetLength) const;
01476
01477 #endif
01478
01479 #if !UCONFIG_NO_CONVERSION
01480
01506 inline int32_t extract(int32_t start,
01507 int32_t startLength,
01508 char *target,
01509 const char *codepage = 0) const;
01510
01540 int32_t extract(int32_t start,
01541 int32_t startLength,
01542 char *target,
01543 uint32_t targetLength,
01544 const char *codepage) const;
01545
01563 int32_t extract(char *dest, int32_t destCapacity,
01564 UConverter *cnv,
01565 UErrorCode &errorCode) const;
01566
01567 #endif
01568
01579 void toUTF8(ByteSink &sink) const;
01580
01581 #if U_HAVE_STD_STRING
01582
01595 template<typename StringClass>
01596 StringClass &toUTF8String(StringClass &result) const {
01597 StringByteSink<StringClass> sbs(&result);
01598 toUTF8(sbs);
01599 return result;
01600 }
01601
01602 #endif
01603
01619 int32_t toUTF32(UChar32 *utf32, int32_t capacity, UErrorCode &errorCode) const;
01620
01621
01622
01631 inline int32_t length(void) const;
01632
01646 int32_t
01647 countChar32(int32_t start=0, int32_t length=INT32_MAX) const;
01648
01672 UBool
01673 hasMoreChar32Than(int32_t start, int32_t length, int32_t number) const;
01674
01680 inline UBool isEmpty(void) const;
01681
01691 inline int32_t getCapacity(void) const;
01692
01693
01694
01700 inline int32_t hashCode(void) const;
01701
01713 inline UBool isBogus(void) const;
01714
01715
01716
01717
01718
01719
01720
01721
01729 UnicodeString &operator=(const UnicodeString &srcText);
01730
01751 UnicodeString &fastCopyFrom(const UnicodeString &src);
01752
01760 inline UnicodeString& operator= (UChar ch);
01761
01769 inline UnicodeString& operator= (UChar32 ch);
01770
01782 inline UnicodeString& setTo(const UnicodeString& srcText,
01783 int32_t srcStart);
01784
01798 inline UnicodeString& setTo(const UnicodeString& srcText,
01799 int32_t srcStart,
01800 int32_t srcLength);
01801
01810 inline UnicodeString& setTo(const UnicodeString& srcText);
01811
01820 inline UnicodeString& setTo(const UChar *srcChars,
01821 int32_t srcLength);
01822
01831 UnicodeString& setTo(UChar srcChar);
01832
01841 UnicodeString& setTo(UChar32 srcChar);
01842
01863 UnicodeString &setTo(UBool isTerminated,
01864 const UChar *text,
01865 int32_t textLength);
01866
01886 UnicodeString &setTo(UChar *buffer,
01887 int32_t buffLength,
01888 int32_t buffCapacity);
01889
01930 void setToBogus();
01931
01939 UnicodeString& setCharAt(int32_t offset,
01940 UChar ch);
01941
01942
01943
01944
01952 inline UnicodeString& operator+= (UChar ch);
01953
01961 inline UnicodeString& operator+= (UChar32 ch);
01962
01971 inline UnicodeString& operator+= (const UnicodeString& srcText);
01972
01987 inline UnicodeString& append(const UnicodeString& srcText,
01988 int32_t srcStart,
01989 int32_t srcLength);
01990
01998 inline UnicodeString& append(const UnicodeString& srcText);
01999
02013 inline UnicodeString& append(const UChar *srcChars,
02014 int32_t srcStart,
02015 int32_t srcLength);
02016
02025 inline UnicodeString& append(const UChar *srcChars,
02026 int32_t srcLength);
02027
02034 inline UnicodeString& append(UChar srcChar);
02035
02042 inline UnicodeString& append(UChar32 srcChar);
02043
02044
02045
02046
02060 inline UnicodeString& insert(int32_t start,
02061 const UnicodeString& srcText,
02062 int32_t srcStart,
02063 int32_t srcLength);
02064
02073 inline UnicodeString& insert(int32_t start,
02074 const UnicodeString& srcText);
02075
02089 inline UnicodeString& insert(int32_t start,
02090 const UChar *srcChars,
02091 int32_t srcStart,
02092 int32_t srcLength);
02093
02103 inline UnicodeString& insert(int32_t start,
02104 const UChar *srcChars,
02105 int32_t srcLength);
02106
02115 inline UnicodeString& insert(int32_t start,
02116 UChar srcChar);
02117
02126 inline UnicodeString& insert(int32_t start,
02127 UChar32 srcChar);
02128
02129
02130
02131
02149 UnicodeString& replace(int32_t start,
02150 int32_t length,
02151 const UnicodeString& srcText,
02152 int32_t srcStart,
02153 int32_t srcLength);
02154
02167 UnicodeString& replace(int32_t start,
02168 int32_t length,
02169 const UnicodeString& srcText);
02170
02188 UnicodeString& replace(int32_t start,
02189 int32_t length,
02190 const UChar *srcChars,
02191 int32_t srcStart,
02192 int32_t srcLength);
02193
02206 inline UnicodeString& replace(int32_t start,
02207 int32_t length,
02208 const UChar *srcChars,
02209 int32_t srcLength);
02210
02222 inline UnicodeString& replace(int32_t start,
02223 int32_t length,
02224 UChar srcChar);
02225
02237 inline UnicodeString& replace(int32_t start,
02238 int32_t length,
02239 UChar32 srcChar);
02240
02250 inline UnicodeString& replaceBetween(int32_t start,
02251 int32_t limit,
02252 const UnicodeString& srcText);
02253
02268 inline UnicodeString& replaceBetween(int32_t start,
02269 int32_t limit,
02270 const UnicodeString& srcText,
02271 int32_t srcStart,
02272 int32_t srcLimit);
02273
02284 virtual void handleReplaceBetween(int32_t start,
02285 int32_t limit,
02286 const UnicodeString& text);
02287
02293 virtual UBool hasMetaData() const;
02294
02310 virtual void copy(int32_t start, int32_t limit, int32_t dest);
02311
02312
02313
02322 inline UnicodeString& findAndReplace(const UnicodeString& oldText,
02323 const UnicodeString& newText);
02324
02336 inline UnicodeString& findAndReplace(int32_t start,
02337 int32_t length,
02338 const UnicodeString& oldText,
02339 const UnicodeString& newText);
02340
02358 UnicodeString& findAndReplace(int32_t start,
02359 int32_t length,
02360 const UnicodeString& oldText,
02361 int32_t oldStart,
02362 int32_t oldLength,
02363 const UnicodeString& newText,
02364 int32_t newStart,
02365 int32_t newLength);
02366
02367
02368
02369
02375 inline UnicodeString& remove(void);
02376
02385 inline UnicodeString& remove(int32_t start,
02386 int32_t length = (int32_t)INT32_MAX);
02387
02396 inline UnicodeString& removeBetween(int32_t start,
02397 int32_t limit = (int32_t)INT32_MAX);
02398
02399
02400
02401
02413 UBool padLeading(int32_t targetLength,
02414 UChar padChar = 0x0020);
02415
02427 UBool padTrailing(int32_t targetLength,
02428 UChar padChar = 0x0020);
02429
02436 inline UBool truncate(int32_t targetLength);
02437
02443 UnicodeString& trim(void);
02444
02445
02446
02447
02453 inline UnicodeString& reverse(void);
02454
02463 inline UnicodeString& reverse(int32_t start,
02464 int32_t length);
02465
02472 UnicodeString& toUpper(void);
02473
02481 UnicodeString& toUpper(const Locale& locale);
02482
02489 UnicodeString& toLower(void);
02490
02498 UnicodeString& toLower(const Locale& locale);
02499
02500 #if !UCONFIG_NO_BREAK_ITERATION
02501
02528 UnicodeString &toTitle(BreakIterator *titleIter);
02529
02557 UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale);
02558
02590 UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale, uint32_t options);
02591
02592 #endif
02593
02605 UnicodeString &foldCase(uint32_t options=0 );
02606
02607
02608
02609
02610
02654 UChar *getBuffer(int32_t minCapacity);
02655
02676 void releaseBuffer(int32_t newLength=-1);
02677
02708 inline const UChar *getBuffer() const;
02709
02743 inline const UChar *getTerminatedBuffer();
02744
02745
02746
02747
02748
02752 UnicodeString();
02753
02765 UnicodeString(int32_t capacity, UChar32 c, int32_t count);
02766
02772 UnicodeString(UChar ch);
02773
02779 UnicodeString(UChar32 ch);
02780
02787 UnicodeString(const UChar *text);
02788
02796 UnicodeString(const UChar *text,
02797 int32_t textLength);
02798
02818 UnicodeString(UBool isTerminated,
02819 const UChar *text,
02820 int32_t textLength);
02821
02840 UnicodeString(UChar *buffer, int32_t buffLength, int32_t buffCapacity);
02841
02842 #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
02843
02850 UnicodeString(const char *codepageData);
02851
02858 UnicodeString(const char *codepageData, int32_t dataLength);
02859
02860 #endif
02861
02862 #if !UCONFIG_NO_CONVERSION
02863
02881 UnicodeString(const char *codepageData, const char *codepage);
02882
02900 UnicodeString(const char *codepageData, int32_t dataLength, const char *codepage);
02901
02923 UnicodeString(
02924 const char *src, int32_t srcLength,
02925 UConverter *cnv,
02926 UErrorCode &errorCode);
02927
02928 #endif
02929
02954 UnicodeString(const char *src, int32_t length, enum EInvariant inv);
02955
02956
02962 UnicodeString(const UnicodeString& that);
02963
02970 UnicodeString(const UnicodeString& src, int32_t srcStart);
02971
02979 UnicodeString(const UnicodeString& src, int32_t srcStart, int32_t srcLength);
02980
02997 virtual Replaceable *clone() const;
02998
03002 virtual ~UnicodeString();
03003
03017 static UnicodeString fromUTF8(const StringPiece &utf8);
03018
03030 static UnicodeString fromUTF32(const UChar32 *utf32, int32_t length);
03031
03032
03033
03068 UnicodeString unescape() const;
03069
03089 UChar32 unescapeAt(int32_t &offset) const;
03090
03096 static UClassID U_EXPORT2 getStaticClassID();
03097
03103 virtual UClassID getDynamicClassID() const;
03104
03105
03106
03107
03108
03109 protected:
03114 virtual int32_t getLength() const;
03115
03121 virtual UChar getCharAt(int32_t offset) const;
03122
03128 virtual UChar32 getChar32At(int32_t offset) const;
03129
03130 private:
03131
03132 UnicodeString &setToUTF8(const StringPiece &utf8);
03133
03134
03135
03136
03137
03138 int32_t
03139 toUTF8(int32_t start, int32_t len,
03140 char *target, int32_t capacity) const;
03141
03142
03143 inline int8_t
03144 doCompare(int32_t start,
03145 int32_t length,
03146 const UnicodeString& srcText,
03147 int32_t srcStart,
03148 int32_t srcLength) const;
03149
03150 int8_t doCompare(int32_t start,
03151 int32_t length,
03152 const UChar *srcChars,
03153 int32_t srcStart,
03154 int32_t srcLength) const;
03155
03156 inline int8_t
03157 doCompareCodePointOrder(int32_t start,
03158 int32_t length,
03159 const UnicodeString& srcText,
03160 int32_t srcStart,
03161 int32_t srcLength) const;
03162
03163 int8_t doCompareCodePointOrder(int32_t start,
03164 int32_t length,
03165 const UChar *srcChars,
03166 int32_t srcStart,
03167 int32_t srcLength) const;
03168
03169 inline int8_t
03170 doCaseCompare(int32_t start,
03171 int32_t length,
03172 const UnicodeString &srcText,
03173 int32_t srcStart,
03174 int32_t srcLength,
03175 uint32_t options) const;
03176
03177 int8_t
03178 doCaseCompare(int32_t start,
03179 int32_t length,
03180 const UChar *srcChars,
03181 int32_t srcStart,
03182 int32_t srcLength,
03183 uint32_t options) const;
03184
03185 int32_t doIndexOf(UChar c,
03186 int32_t start,
03187 int32_t length) const;
03188
03189 int32_t doIndexOf(UChar32 c,
03190 int32_t start,
03191 int32_t length) const;
03192
03193 int32_t doLastIndexOf(UChar c,
03194 int32_t start,
03195 int32_t length) const;
03196
03197 int32_t doLastIndexOf(UChar32 c,
03198 int32_t start,
03199 int32_t length) const;
03200
03201 void doExtract(int32_t start,
03202 int32_t length,
03203 UChar *dst,
03204 int32_t dstStart) const;
03205
03206 inline void doExtract(int32_t start,
03207 int32_t length,
03208 UnicodeString& target) const;
03209
03210 inline UChar doCharAt(int32_t offset) const;
03211
03212 UnicodeString& doReplace(int32_t start,
03213 int32_t length,
03214 const UnicodeString& srcText,
03215 int32_t srcStart,
03216 int32_t srcLength);
03217
03218 UnicodeString& doReplace(int32_t start,
03219 int32_t length,
03220 const UChar *srcChars,
03221 int32_t srcStart,
03222 int32_t srcLength);
03223
03224 UnicodeString& doReverse(int32_t start,
03225 int32_t length);
03226
03227
03228 int32_t doHashCode(void) const;
03229
03230
03231
03232 inline UChar* getArrayStart(void);
03233 inline const UChar* getArrayStart(void) const;
03234
03235
03236
03237 inline UBool isWritable() const;
03238
03239
03240 inline UBool isBufferWritable() const;
03241
03242
03243 inline void setLength(int32_t len);
03244 inline void setToEmpty();
03245 inline void setArray(UChar *array, int32_t len, int32_t capacity);
03246
03247
03248
03249
03250
03251 UBool allocate(int32_t capacity);
03252
03253
03254 void releaseArray(void);
03255
03256
03257 void unBogus();
03258
03259
03260 UnicodeString ©From(const UnicodeString &src, UBool fastCopy=FALSE);
03261
03262
03263 inline void pinIndex(int32_t& start) const;
03264 inline void pinIndices(int32_t& start,
03265 int32_t& length) const;
03266
03267 #if !UCONFIG_NO_CONVERSION
03268
03269
03270 int32_t doExtract(int32_t start, int32_t length,
03271 char *dest, int32_t destCapacity,
03272 UConverter *cnv,
03273 UErrorCode &errorCode) const;
03274
03275
03276
03277
03278
03279
03280
03281
03282
03283
03284
03285 void doCodepageCreate(const char *codepageData,
03286 int32_t dataLength,
03287 const char *codepage);
03288
03289
03290
03291
03292
03293 void
03294 doCodepageCreate(const char *codepageData,
03295 int32_t dataLength,
03296 UConverter *converter,
03297 UErrorCode &status);
03298
03299 #endif
03300
03301
03302
03303
03304
03305
03306
03307
03308
03309
03310
03311
03312 UBool cloneArrayIfNeeded(int32_t newCapacity = -1,
03313 int32_t growCapacity = -1,
03314 UBool doCopyArray = TRUE,
03315 int32_t **pBufferToDelete = 0,
03316 UBool forceClone = FALSE);
03317
03318
03319 UnicodeString &
03320 caseMap(BreakIterator *titleIter,
03321 const char *locale,
03322 uint32_t options,
03323 int32_t toWhichCase);
03324
03325
03326 void addRef(void);
03327 int32_t removeRef(void);
03328 int32_t refCount(void) const;
03329
03330
03331 enum {
03332
03333
03334
03335 US_STACKBUF_SIZE= sizeof(void *)==4 ? 13 : 15,
03336 kInvalidUChar=0xffff,
03337 kGrowSize=128,
03338 kInvalidHashCode=0,
03339 kEmptyHashCode=1,
03340
03341
03342 kIsBogus=1,
03343 kUsingStackBuffer=2,
03344 kRefCounted=4,
03345 kBufferIsReadonly=8,
03346 kOpenGetBuffer=16,
03347
03348
03349
03350 kShortString=kUsingStackBuffer,
03351 kLongString=kRefCounted,
03352 kReadonlyAlias=kBufferIsReadonly,
03353 kWritableAlias=0
03354 };
03355
03356 friend class StringThreadTest;
03357
03358 union StackBufferOrFields;
03359 friend union StackBufferOrFields;
03360
03361
03362
03363
03364
03365
03366
03367
03368
03369
03370
03371
03372
03373 int8_t fShortLength;
03374 uint8_t fFlags;
03375 union StackBufferOrFields {
03376
03377
03378 UChar fStackBuffer [US_STACKBUF_SIZE];
03379 struct {
03380 uint16_t fPadding;
03381 int32_t fLength;
03382 UChar *fArray;
03383 int32_t fCapacity;
03384 } fFields;
03385 } fUnion;
03386 };
03387
03396 U_COMMON_API UnicodeString U_EXPORT2
03397 operator+ (const UnicodeString &s1, const UnicodeString &s2);
03398
03399
03400
03401
03402
03403
03404
03405
03406
03407 inline void
03408 UnicodeString::pinIndex(int32_t& start) const
03409 {
03410
03411 if(start < 0) {
03412 start = 0;
03413 } else if(start > length()) {
03414 start = length();
03415 }
03416 }
03417
03418 inline void
03419 UnicodeString::pinIndices(int32_t& start,
03420 int32_t& _length) const
03421 {
03422
03423 int32_t len = length();
03424 if(start < 0) {
03425 start = 0;
03426 } else if(start > len) {
03427 start = len;
03428 }
03429 if(_length < 0) {
03430 _length = 0;
03431 } else if(_length > (len - start)) {
03432 _length = (len - start);
03433 }
03434 }
03435
03436 inline UChar*
03437 UnicodeString::getArrayStart()
03438 { return (fFlags&kUsingStackBuffer) ? fUnion.fStackBuffer : fUnion.fFields.fArray; }
03439
03440 inline const UChar*
03441 UnicodeString::getArrayStart() const
03442 { return (fFlags&kUsingStackBuffer) ? fUnion.fStackBuffer : fUnion.fFields.fArray; }
03443
03444
03445
03446
03447 inline int32_t
03448 UnicodeString::length() const
03449 { return fShortLength>=0 ? fShortLength : fUnion.fFields.fLength; }
03450
03451 inline int32_t
03452 UnicodeString::getCapacity() const
03453 { return (fFlags&kUsingStackBuffer) ? US_STACKBUF_SIZE : fUnion.fFields.fCapacity; }
03454
03455 inline int32_t
03456 UnicodeString::hashCode() const
03457 { return doHashCode(); }
03458
03459 inline UBool
03460 UnicodeString::isBogus() const
03461 { return (UBool)(fFlags & kIsBogus); }
03462
03463 inline UBool
03464 UnicodeString::isWritable() const
03465 { return (UBool)!(fFlags&(kOpenGetBuffer|kIsBogus)); }
03466
03467 inline UBool
03468 UnicodeString::isBufferWritable() const
03469 {
03470 return (UBool)(
03471 !(fFlags&(kOpenGetBuffer|kIsBogus|kBufferIsReadonly)) &&
03472 (!(fFlags&kRefCounted) || refCount()==1));
03473 }
03474
03475 inline const UChar *
03476 UnicodeString::getBuffer() const {
03477 if(fFlags&(kIsBogus|kOpenGetBuffer)) {
03478 return 0;
03479 } else if(fFlags&kUsingStackBuffer) {
03480 return fUnion.fStackBuffer;
03481 } else {
03482 return fUnion.fFields.fArray;
03483 }
03484 }
03485
03486
03487
03488
03489 inline int8_t
03490 UnicodeString::doCompare(int32_t start,
03491 int32_t thisLength,
03492 const UnicodeString& srcText,
03493 int32_t srcStart,
03494 int32_t srcLength) const
03495 {
03496 if(srcText.isBogus()) {
03497 return (int8_t)!isBogus();
03498 } else {
03499 srcText.pinIndices(srcStart, srcLength);
03500 return doCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
03501 }
03502 }
03503
03504 inline UBool
03505 UnicodeString::operator== (const UnicodeString& text) const
03506 {
03507 if(isBogus()) {
03508 return text.isBogus();
03509 } else {
03510 int32_t len = length(), textLength = text.length();
03511 return
03512 !text.isBogus() &&
03513 len == textLength &&
03514 doCompare(0, len, text, 0, textLength) == 0;
03515 }
03516 }
03517
03518 inline UBool
03519 UnicodeString::operator!= (const UnicodeString& text) const
03520 { return (! operator==(text)); }
03521
03522 inline UBool
03523 UnicodeString::operator> (const UnicodeString& text) const
03524 { return doCompare(0, length(), text, 0, text.length()) == 1; }
03525
03526 inline UBool
03527 UnicodeString::operator< (const UnicodeString& text) const
03528 { return doCompare(0, length(), text, 0, text.length()) == -1; }
03529
03530 inline UBool
03531 UnicodeString::operator>= (const UnicodeString& text) const
03532 { return doCompare(0, length(), text, 0, text.length()) != -1; }
03533
03534 inline UBool
03535 UnicodeString::operator<= (const UnicodeString& text) const
03536 { return doCompare(0, length(), text, 0, text.length()) != 1; }
03537
03538 inline int8_t
03539 UnicodeString::compare(const UnicodeString& text) const
03540 { return doCompare(0, length(), text, 0, text.length()); }
03541
03542 inline int8_t
03543 UnicodeString::compare(int32_t start,
03544 int32_t _length,
03545 const UnicodeString& srcText) const
03546 { return doCompare(start, _length, srcText, 0, srcText.length()); }
03547
03548 inline int8_t
03549 UnicodeString::compare(const UChar *srcChars,
03550 int32_t srcLength) const
03551 { return doCompare(0, length(), srcChars, 0, srcLength); }
03552
03553 inline int8_t
03554 UnicodeString::compare(int32_t start,
03555 int32_t _length,
03556 const UnicodeString& srcText,
03557 int32_t srcStart,
03558 int32_t srcLength) const
03559 { return doCompare(start, _length, srcText, srcStart, srcLength); }
03560
03561 inline int8_t
03562 UnicodeString::compare(int32_t start,
03563 int32_t _length,
03564 const UChar *srcChars) const
03565 { return doCompare(start, _length, srcChars, 0, _length); }
03566
03567 inline int8_t
03568 UnicodeString::compare(int32_t start,
03569 int32_t _length,
03570 const UChar *srcChars,
03571 int32_t srcStart,
03572 int32_t srcLength) const
03573 { return doCompare(start, _length, srcChars, srcStart, srcLength); }
03574
03575 inline int8_t
03576 UnicodeString::compareBetween(int32_t start,
03577 int32_t limit,
03578 const UnicodeString& srcText,
03579 int32_t srcStart,
03580 int32_t srcLimit) const
03581 { return doCompare(start, limit - start,
03582 srcText, srcStart, srcLimit - srcStart); }
03583
03584 inline int8_t
03585 UnicodeString::doCompareCodePointOrder(int32_t start,
03586 int32_t thisLength,
03587 const UnicodeString& srcText,
03588 int32_t srcStart,
03589 int32_t srcLength) const
03590 {
03591 if(srcText.isBogus()) {
03592 return (int8_t)!isBogus();
03593 } else {
03594 srcText.pinIndices(srcStart, srcLength);
03595 return doCompareCodePointOrder(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
03596 }
03597 }
03598
03599 inline int8_t
03600 UnicodeString::compareCodePointOrder(const UnicodeString& text) const
03601 { return doCompareCodePointOrder(0, length(), text, 0, text.length()); }
03602
03603 inline int8_t
03604 UnicodeString::compareCodePointOrder(int32_t start,
03605 int32_t _length,
03606 const UnicodeString& srcText) const
03607 { return doCompareCodePointOrder(start, _length, srcText, 0, srcText.length()); }
03608
03609 inline int8_t
03610 UnicodeString::compareCodePointOrder(const UChar *srcChars,
03611 int32_t srcLength) const
03612 { return doCompareCodePointOrder(0, length(), srcChars, 0, srcLength); }
03613
03614 inline int8_t
03615 UnicodeString::compareCodePointOrder(int32_t start,
03616 int32_t _length,
03617 const UnicodeString& srcText,
03618 int32_t srcStart,
03619 int32_t srcLength) const
03620 { return doCompareCodePointOrder(start, _length, srcText, srcStart, srcLength); }
03621
03622 inline int8_t
03623 UnicodeString::compareCodePointOrder(int32_t start,
03624 int32_t _length,
03625 const UChar *srcChars) const
03626 { return doCompareCodePointOrder(start, _length, srcChars, 0, _length); }
03627
03628 inline int8_t
03629 UnicodeString::compareCodePointOrder(int32_t start,
03630 int32_t _length,
03631 const UChar *srcChars,
03632 int32_t srcStart,
03633 int32_t srcLength) const
03634 { return doCompareCodePointOrder(start, _length, srcChars, srcStart, srcLength); }
03635
03636 inline int8_t
03637 UnicodeString::compareCodePointOrderBetween(int32_t start,
03638 int32_t limit,
03639 const UnicodeString& srcText,
03640 int32_t srcStart,
03641 int32_t srcLimit) const
03642 { return doCompareCodePointOrder(start, limit - start,
03643 srcText, srcStart, srcLimit - srcStart); }
03644
03645 inline int8_t
03646 UnicodeString::doCaseCompare(int32_t start,
03647 int32_t thisLength,
03648 const UnicodeString &srcText,
03649 int32_t srcStart,
03650 int32_t srcLength,
03651 uint32_t options) const
03652 {
03653 if(srcText.isBogus()) {
03654 return (int8_t)!isBogus();
03655 } else {
03656 srcText.pinIndices(srcStart, srcLength);
03657 return doCaseCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength, options);
03658 }
03659 }
03660
03661 inline int8_t
03662 UnicodeString::caseCompare(const UnicodeString &text, uint32_t options) const {
03663 return doCaseCompare(0, length(), text, 0, text.length(), options);
03664 }
03665
03666 inline int8_t
03667 UnicodeString::caseCompare(int32_t start,
03668 int32_t _length,
03669 const UnicodeString &srcText,
03670 uint32_t options) const {
03671 return doCaseCompare(start, _length, srcText, 0, srcText.length(), options);
03672 }
03673
03674 inline int8_t
03675 UnicodeString::caseCompare(const UChar *srcChars,
03676 int32_t srcLength,
03677 uint32_t options) const {
03678 return doCaseCompare(0, length(), srcChars, 0, srcLength, options);
03679 }
03680
03681 inline int8_t
03682 UnicodeString::caseCompare(int32_t start,
03683 int32_t _length,
03684 const UnicodeString &srcText,
03685 int32_t srcStart,
03686 int32_t srcLength,
03687 uint32_t options) const {
03688 return doCaseCompare(start, _length, srcText, srcStart, srcLength, options);
03689 }
03690
03691 inline int8_t
03692 UnicodeString::caseCompare(int32_t start,
03693 int32_t _length,
03694 const UChar *srcChars,
03695 uint32_t options) const {
03696 return doCaseCompare(start, _length, srcChars, 0, _length, options);
03697 }
03698
03699 inline int8_t
03700 UnicodeString::caseCompare(int32_t start,
03701 int32_t _length,
03702 const UChar *srcChars,
03703 int32_t srcStart,
03704 int32_t srcLength,
03705 uint32_t options) const {
03706 return doCaseCompare(start, _length, srcChars, srcStart, srcLength, options);
03707 }
03708
03709 inline int8_t
03710 UnicodeString::caseCompareBetween(int32_t start,
03711 int32_t limit,
03712 const UnicodeString &srcText,
03713 int32_t srcStart,
03714 int32_t srcLimit,
03715 uint32_t options) const {
03716 return doCaseCompare(start, limit - start, srcText, srcStart, srcLimit - srcStart, options);
03717 }
03718
03719 inline int32_t
03720 UnicodeString::indexOf(const UnicodeString& srcText,
03721 int32_t srcStart,
03722 int32_t srcLength,
03723 int32_t start,
03724 int32_t _length) const
03725 {
03726 if(!srcText.isBogus()) {
03727 srcText.pinIndices(srcStart, srcLength);
03728 if(srcLength > 0) {
03729 return indexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
03730 }
03731 }
03732 return -1;
03733 }
03734
03735 inline int32_t
03736 UnicodeString::indexOf(const UnicodeString& text) const
03737 { return indexOf(text, 0, text.length(), 0, length()); }
03738
03739 inline int32_t
03740 UnicodeString::indexOf(const UnicodeString& text,
03741 int32_t start) const {
03742 pinIndex(start);
03743 return indexOf(text, 0, text.length(), start, length() - start);
03744 }
03745
03746 inline int32_t
03747 UnicodeString::indexOf(const UnicodeString& text,
03748 int32_t start,
03749 int32_t _length) const
03750 { return indexOf(text, 0, text.length(), start, _length); }
03751
03752 inline int32_t
03753 UnicodeString::indexOf(const UChar *srcChars,
03754 int32_t srcLength,
03755 int32_t start) const {
03756 pinIndex(start);
03757 return indexOf(srcChars, 0, srcLength, start, length() - start);
03758 }
03759
03760 inline int32_t
03761 UnicodeString::indexOf(const UChar *srcChars,
03762 int32_t srcLength,
03763 int32_t start,
03764 int32_t _length) const
03765 { return indexOf(srcChars, 0, srcLength, start, _length); }
03766
03767 inline int32_t
03768 UnicodeString::indexOf(UChar c,
03769 int32_t start,
03770 int32_t _length) const
03771 { return doIndexOf(c, start, _length); }
03772
03773 inline int32_t
03774 UnicodeString::indexOf(UChar32 c,
03775 int32_t start,
03776 int32_t _length) const
03777 { return doIndexOf(c, start, _length); }
03778
03779 inline int32_t
03780 UnicodeString::indexOf(UChar c) const
03781 { return doIndexOf(c, 0, length()); }
03782
03783 inline int32_t
03784 UnicodeString::indexOf(UChar32 c) const
03785 { return indexOf(c, 0, length()); }
03786
03787 inline int32_t
03788 UnicodeString::indexOf(UChar c,
03789 int32_t start) const {
03790 pinIndex(start);
03791 return doIndexOf(c, start, length() - start);
03792 }
03793
03794 inline int32_t
03795 UnicodeString::indexOf(UChar32 c,
03796 int32_t start) const {
03797 pinIndex(start);
03798 return indexOf(c, start, length() - start);
03799 }
03800
03801 inline int32_t
03802 UnicodeString::lastIndexOf(const UChar *srcChars,
03803 int32_t srcLength,
03804 int32_t start,
03805 int32_t _length) const
03806 { return lastIndexOf(srcChars, 0, srcLength, start, _length); }
03807
03808 inline int32_t
03809 UnicodeString::lastIndexOf(const UChar *srcChars,
03810 int32_t srcLength,
03811 int32_t start) const {
03812 pinIndex(start);
03813 return lastIndexOf(srcChars, 0, srcLength, start, length() - start);
03814 }
03815
03816 inline int32_t
03817 UnicodeString::lastIndexOf(const UnicodeString& srcText,
03818 int32_t srcStart,
03819 int32_t srcLength,
03820 int32_t start,
03821 int32_t _length) const
03822 {
03823 if(!srcText.isBogus()) {
03824 srcText.pinIndices(srcStart, srcLength);
03825 if(srcLength > 0) {
03826 return lastIndexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
03827 }
03828 }
03829 return -1;
03830 }
03831
03832 inline int32_t
03833 UnicodeString::lastIndexOf(const UnicodeString& text,
03834 int32_t start,
03835 int32_t _length) const
03836 { return lastIndexOf(text, 0, text.length(), start, _length); }
03837
03838 inline int32_t
03839 UnicodeString::lastIndexOf(const UnicodeString& text,
03840 int32_t start) const {
03841 pinIndex(start);
03842 return lastIndexOf(text, 0, text.length(), start, length() - start);
03843 }
03844
03845 inline int32_t
03846 UnicodeString::lastIndexOf(const UnicodeString& text) const
03847 { return lastIndexOf(text, 0, text.length(), 0, length()); }
03848
03849 inline int32_t
03850 UnicodeString::lastIndexOf(UChar c,
03851 int32_t start,
03852 int32_t _length) const
03853 { return doLastIndexOf(c, start, _length); }
03854
03855 inline int32_t
03856 UnicodeString::lastIndexOf(UChar32 c,
03857 int32_t start,
03858 int32_t _length) const {
03859 return doLastIndexOf(c, start, _length);
03860 }
03861
03862 inline int32_t
03863 UnicodeString::lastIndexOf(UChar c) const
03864 { return doLastIndexOf(c, 0, length()); }
03865
03866 inline int32_t
03867 UnicodeString::lastIndexOf(UChar32 c) const {
03868 return lastIndexOf(c, 0, length());
03869 }
03870
03871 inline int32_t
03872 UnicodeString::lastIndexOf(UChar c,
03873 int32_t start) const {
03874 pinIndex(start);
03875 return doLastIndexOf(c, start, length() - start);
03876 }
03877
03878 inline int32_t
03879 UnicodeString::lastIndexOf(UChar32 c,
03880 int32_t start) const {
03881 pinIndex(start);
03882 return lastIndexOf(c, start, length() - start);
03883 }
03884
03885 inline UBool
03886 UnicodeString::startsWith(const UnicodeString& text) const
03887 { return compare(0, text.length(), text, 0, text.length()) == 0; }
03888
03889 inline UBool
03890 UnicodeString::startsWith(const UnicodeString& srcText,
03891 int32_t srcStart,
03892 int32_t srcLength) const
03893 { return doCompare(0, srcLength, srcText, srcStart, srcLength) == 0; }
03894
03895 inline UBool
03896 UnicodeString::startsWith(const UChar *srcChars,
03897 int32_t srcLength) const
03898 { return doCompare(0, srcLength, srcChars, 0, srcLength) == 0; }
03899
03900 inline UBool
03901 UnicodeString::startsWith(const UChar *srcChars,
03902 int32_t srcStart,
03903 int32_t srcLength) const
03904 { return doCompare(0, srcLength, srcChars, srcStart, srcLength) == 0;}
03905
03906 inline UBool
03907 UnicodeString::endsWith(const UnicodeString& text) const
03908 { return doCompare(length() - text.length(), text.length(),
03909 text, 0, text.length()) == 0; }
03910
03911 inline UBool
03912 UnicodeString::endsWith(const UnicodeString& srcText,
03913 int32_t srcStart,
03914 int32_t srcLength) const {
03915 srcText.pinIndices(srcStart, srcLength);
03916 return doCompare(length() - srcLength, srcLength,
03917 srcText, srcStart, srcLength) == 0;
03918 }
03919
03920 inline UBool
03921 UnicodeString::endsWith(const UChar *srcChars,
03922 int32_t srcLength) const {
03923 if(srcLength < 0) {
03924 srcLength = u_strlen(srcChars);
03925 }
03926 return doCompare(length() - srcLength, srcLength,
03927 srcChars, 0, srcLength) == 0;
03928 }
03929
03930 inline UBool
03931 UnicodeString::endsWith(const UChar *srcChars,
03932 int32_t srcStart,
03933 int32_t srcLength) const {
03934 if(srcLength < 0) {
03935 srcLength = u_strlen(srcChars + srcStart);
03936 }
03937 return doCompare(length() - srcLength, srcLength,
03938 srcChars, srcStart, srcLength) == 0;
03939 }
03940
03941
03942
03943
03944 inline UnicodeString&
03945 UnicodeString::replace(int32_t start,
03946 int32_t _length,
03947 const UnicodeString& srcText)
03948 { return doReplace(start, _length, srcText, 0, srcText.length()); }
03949
03950 inline UnicodeString&
03951 UnicodeString::replace(int32_t start,
03952 int32_t _length,
03953 const UnicodeString& srcText,
03954 int32_t srcStart,
03955 int32_t srcLength)
03956 { return doReplace(start, _length, srcText, srcStart, srcLength); }
03957
03958 inline UnicodeString&
03959 UnicodeString::replace(int32_t start,
03960 int32_t _length,
03961 const UChar *srcChars,
03962 int32_t srcLength)
03963 { return doReplace(start, _length, srcChars, 0, srcLength); }
03964
03965 inline UnicodeString&
03966 UnicodeString::replace(int32_t start,
03967 int32_t _length,
03968 const UChar *srcChars,
03969 int32_t srcStart,
03970 int32_t srcLength)
03971 { return doReplace(start, _length, srcChars, srcStart, srcLength); }
03972
03973 inline UnicodeString&
03974 UnicodeString::replace(int32_t start,
03975 int32_t _length,
03976 UChar srcChar)
03977 { return doReplace(start, _length, &srcChar, 0, 1); }
03978
03979 inline UnicodeString&
03980 UnicodeString::replace(int32_t start,
03981 int32_t _length,
03982 UChar32 srcChar) {
03983 UChar buffer[U16_MAX_LENGTH];
03984 int32_t count = 0;
03985 UBool isError = FALSE;
03986 U16_APPEND(buffer, count, U16_MAX_LENGTH, srcChar, isError);
03987 return doReplace(start, _length, buffer, 0, count);
03988 }
03989
03990 inline UnicodeString&
03991 UnicodeString::replaceBetween(int32_t start,
03992 int32_t limit,
03993 const UnicodeString& srcText)
03994 { return doReplace(start, limit - start, srcText, 0, srcText.length()); }
03995
03996 inline UnicodeString&
03997 UnicodeString::replaceBetween(int32_t start,
03998 int32_t limit,
03999 const UnicodeString& srcText,
04000 int32_t srcStart,
04001 int32_t srcLimit)
04002 { return doReplace(start, limit - start, srcText, srcStart, srcLimit - srcStart); }
04003
04004 inline UnicodeString&
04005 UnicodeString::findAndReplace(const UnicodeString& oldText,
04006 const UnicodeString& newText)
04007 { return findAndReplace(0, length(), oldText, 0, oldText.length(),
04008 newText, 0, newText.length()); }
04009
04010 inline UnicodeString&
04011 UnicodeString::findAndReplace(int32_t start,
04012 int32_t _length,
04013 const UnicodeString& oldText,
04014 const UnicodeString& newText)
04015 { return findAndReplace(start, _length, oldText, 0, oldText.length(),
04016 newText, 0, newText.length()); }
04017
04018
04019
04020
04021 inline void
04022 UnicodeString::doExtract(int32_t start,
04023 int32_t _length,
04024 UnicodeString& target) const
04025 { target.replace(0, target.length(), *this, start, _length); }
04026
04027 inline void
04028 UnicodeString::extract(int32_t start,
04029 int32_t _length,
04030 UChar *target,
04031 int32_t targetStart) const
04032 { doExtract(start, _length, target, targetStart); }
04033
04034 inline void
04035 UnicodeString::extract(int32_t start,
04036 int32_t _length,
04037 UnicodeString& target) const
04038 { doExtract(start, _length, target); }
04039
04040 #if !UCONFIG_NO_CONVERSION
04041
04042 inline int32_t
04043 UnicodeString::extract(int32_t start,
04044 int32_t _length,
04045 char *dst,
04046 const char *codepage) const
04047
04048 {
04049
04050 return extract(start, _length, dst, dst!=0 ? 0xffffffff : 0, codepage);
04051 }
04052
04053 #endif
04054
04055 inline void
04056 UnicodeString::extractBetween(int32_t start,
04057 int32_t limit,
04058 UChar *dst,
04059 int32_t dstStart) const {
04060 pinIndex(start);
04061 pinIndex(limit);
04062 doExtract(start, limit - start, dst, dstStart);
04063 }
04064
04065 inline UChar
04066 UnicodeString::doCharAt(int32_t offset) const
04067 {
04068 if((uint32_t)offset < (uint32_t)length()) {
04069 return getArrayStart()[offset];
04070 } else {
04071 return kInvalidUChar;
04072 }
04073 }
04074
04075 inline UChar
04076 UnicodeString::charAt(int32_t offset) const
04077 { return doCharAt(offset); }
04078
04079 inline UChar
04080 UnicodeString::operator[] (int32_t offset) const
04081 { return doCharAt(offset); }
04082
04083 inline UChar32
04084 UnicodeString::char32At(int32_t offset) const
04085 {
04086 int32_t len = length();
04087 if((uint32_t)offset < (uint32_t)len) {
04088 const UChar *array = getArrayStart();
04089 UChar32 c;
04090 U16_GET(array, 0, offset, len, c);
04091 return c;
04092 } else {
04093 return kInvalidUChar;
04094 }
04095 }
04096
04097 inline int32_t
04098 UnicodeString::getChar32Start(int32_t offset) const {
04099 if((uint32_t)offset < (uint32_t)length()) {
04100 const UChar *array = getArrayStart();
04101 U16_SET_CP_START(array, 0, offset);
04102 return offset;
04103 } else {
04104 return 0;
04105 }
04106 }
04107
04108 inline int32_t
04109 UnicodeString::getChar32Limit(int32_t offset) const {
04110 int32_t len = length();
04111 if((uint32_t)offset < (uint32_t)len) {
04112 const UChar *array = getArrayStart();
04113 U16_SET_CP_LIMIT(array, 0, offset, len);
04114 return offset;
04115 } else {
04116 return len;
04117 }
04118 }
04119
04120 inline UBool
04121 UnicodeString::isEmpty() const {
04122 return fShortLength == 0;
04123 }
04124
04125
04126
04127
04128 inline void
04129 UnicodeString::setLength(int32_t len) {
04130 if(len <= 127) {
04131 fShortLength = (int8_t)len;
04132 } else {
04133 fShortLength = (int8_t)-1;
04134 fUnion.fFields.fLength = len;
04135 }
04136 }
04137
04138 inline void
04139 UnicodeString::setToEmpty() {
04140 fShortLength = 0;
04141 fFlags = kShortString;
04142 }
04143
04144 inline void
04145 UnicodeString::setArray(UChar *array, int32_t len, int32_t capacity) {
04146 setLength(len);
04147 fUnion.fFields.fArray = array;
04148 fUnion.fFields.fCapacity = capacity;
04149 }
04150
04151 inline const UChar *
04152 UnicodeString::getTerminatedBuffer() {
04153 if(!isWritable()) {
04154 return 0;
04155 } else {
04156 UChar *array = getArrayStart();
04157 int32_t len = length();
04158 if(len < getCapacity()) {
04159 if(!(fFlags&kBufferIsReadonly)) {
04160
04161
04162
04163
04164
04165
04166
04167
04168
04169
04170
04171
04172
04173
04174 array[len] = 0;
04175 }
04176 return array;
04177 } else if(cloneArrayIfNeeded(len+1)) {
04178 array = getArrayStart();
04179 array[len] = 0;
04180 return array;
04181 } else {
04182 return 0;
04183 }
04184 }
04185 }
04186
04187 inline UnicodeString&
04188 UnicodeString::operator= (UChar ch)
04189 { return doReplace(0, length(), &ch, 0, 1); }
04190
04191 inline UnicodeString&
04192 UnicodeString::operator= (UChar32 ch)
04193 { return replace(0, length(), ch); }
04194
04195 inline UnicodeString&
04196 UnicodeString::setTo(const UnicodeString& srcText,
04197 int32_t srcStart,
04198 int32_t srcLength)
04199 {
04200 unBogus();
04201 return doReplace(0, length(), srcText, srcStart, srcLength);
04202 }
04203
04204 inline UnicodeString&
04205 UnicodeString::setTo(const UnicodeString& srcText,
04206 int32_t srcStart)
04207 {
04208 unBogus();
04209 srcText.pinIndex(srcStart);
04210 return doReplace(0, length(), srcText, srcStart, srcText.length() - srcStart);
04211 }
04212
04213 inline UnicodeString&
04214 UnicodeString::setTo(const UnicodeString& srcText)
04215 {
04216 unBogus();
04217 return doReplace(0, length(), srcText, 0, srcText.length());
04218 }
04219
04220 inline UnicodeString&
04221 UnicodeString::setTo(const UChar *srcChars,
04222 int32_t srcLength)
04223 {
04224 unBogus();
04225 return doReplace(0, length(), srcChars, 0, srcLength);
04226 }
04227
04228 inline UnicodeString&
04229 UnicodeString::setTo(UChar srcChar)
04230 {
04231 unBogus();
04232 return doReplace(0, length(), &srcChar, 0, 1);
04233 }
04234
04235 inline UnicodeString&
04236 UnicodeString::setTo(UChar32 srcChar)
04237 {
04238 unBogus();
04239 return replace(0, length(), srcChar);
04240 }
04241
04242 inline UnicodeString&
04243 UnicodeString::append(const UnicodeString& srcText,
04244 int32_t srcStart,
04245 int32_t srcLength)
04246 { return doReplace(length(), 0, srcText, srcStart, srcLength); }
04247
04248 inline UnicodeString&
04249 UnicodeString::append(const UnicodeString& srcText)
04250 { return doReplace(length(), 0, srcText, 0, srcText.length()); }
04251
04252 inline UnicodeString&
04253 UnicodeString::append(const UChar *srcChars,
04254 int32_t srcStart,
04255 int32_t srcLength)
04256 { return doReplace(length(), 0, srcChars, srcStart, srcLength); }
04257
04258 inline UnicodeString&
04259 UnicodeString::append(const UChar *srcChars,
04260 int32_t srcLength)
04261 { return doReplace(length(), 0, srcChars, 0, srcLength); }
04262
04263 inline UnicodeString&
04264 UnicodeString::append(UChar srcChar)
04265 { return doReplace(length(), 0, &srcChar, 0, 1); }
04266
04267 inline UnicodeString&
04268 UnicodeString::append(UChar32 srcChar) {
04269 UChar buffer[U16_MAX_LENGTH];
04270 int32_t _length = 0;
04271 UBool isError = FALSE;
04272 U16_APPEND(buffer, _length, U16_MAX_LENGTH, srcChar, isError);
04273 return doReplace(length(), 0, buffer, 0, _length);
04274 }
04275
04276 inline UnicodeString&
04277 UnicodeString::operator+= (UChar ch)
04278 { return doReplace(length(), 0, &ch, 0, 1); }
04279
04280 inline UnicodeString&
04281 UnicodeString::operator+= (UChar32 ch) {
04282 return append(ch);
04283 }
04284
04285 inline UnicodeString&
04286 UnicodeString::operator+= (const UnicodeString& srcText)
04287 { return doReplace(length(), 0, srcText, 0, srcText.length()); }
04288
04289 inline UnicodeString&
04290 UnicodeString::insert(int32_t start,
04291 const UnicodeString& srcText,
04292 int32_t srcStart,
04293 int32_t srcLength)
04294 { return doReplace(start, 0, srcText, srcStart, srcLength); }
04295
04296 inline UnicodeString&
04297 UnicodeString::insert(int32_t start,
04298 const UnicodeString& srcText)
04299 { return doReplace(start, 0, srcText, 0, srcText.length()); }
04300
04301 inline UnicodeString&
04302 UnicodeString::insert(int32_t start,
04303 const UChar *srcChars,
04304 int32_t srcStart,
04305 int32_t srcLength)
04306 { return doReplace(start, 0, srcChars, srcStart, srcLength); }
04307
04308 inline UnicodeString&
04309 UnicodeString::insert(int32_t start,
04310 const UChar *srcChars,
04311 int32_t srcLength)
04312 { return doReplace(start, 0, srcChars, 0, srcLength); }
04313
04314 inline UnicodeString&
04315 UnicodeString::insert(int32_t start,
04316 UChar srcChar)
04317 { return doReplace(start, 0, &srcChar, 0, 1); }
04318
04319 inline UnicodeString&
04320 UnicodeString::insert(int32_t start,
04321 UChar32 srcChar)
04322 { return replace(start, 0, srcChar); }
04323
04324
04325 inline UnicodeString&
04326 UnicodeString::remove()
04327 {
04328
04329 if(isBogus()) {
04330 unBogus();
04331 } else {
04332 setLength(0);
04333 }
04334 return *this;
04335 }
04336
04337 inline UnicodeString&
04338 UnicodeString::remove(int32_t start,
04339 int32_t _length)
04340 {
04341 if(start <= 0 && _length == INT32_MAX) {
04342
04343 return remove();
04344 }
04345 return doReplace(start, _length, NULL, 0, 0);
04346 }
04347
04348 inline UnicodeString&
04349 UnicodeString::removeBetween(int32_t start,
04350 int32_t limit)
04351 { return doReplace(start, limit - start, NULL, 0, 0); }
04352
04353 inline UBool
04354 UnicodeString::truncate(int32_t targetLength)
04355 {
04356 if(isBogus() && targetLength == 0) {
04357
04358 unBogus();
04359 return FALSE;
04360 } else if((uint32_t)targetLength < (uint32_t)length()) {
04361 setLength(targetLength);
04362 return TRUE;
04363 } else {
04364 return FALSE;
04365 }
04366 }
04367
04368 inline UnicodeString&
04369 UnicodeString::reverse()
04370 { return doReverse(0, length()); }
04371
04372 inline UnicodeString&
04373 UnicodeString::reverse(int32_t start,
04374 int32_t _length)
04375 { return doReverse(start, _length); }
04376
04377 U_NAMESPACE_END
04378
04379 #endif