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/rep.h"
00030
00031 struct UConverter;
00032 class StringThreadTest;
00033
00034 #ifndef U_COMPARE_CODE_POINT_ORDER
00035
00041 #define U_COMPARE_CODE_POINT_ORDER 0x8000
00042 #endif
00043
00044 #ifndef USTRING_H
00045
00048 U_STABLE int32_t U_EXPORT2
00049 u_strlen(const UChar *s);
00050 #endif
00051
00052 U_NAMESPACE_BEGIN
00053
00054 class Locale;
00055 class StringCharacterIterator;
00056 class BreakIterator;
00057
00058
00059
00070 #define US_INV U_NAMESPACE_QUALIFIER UnicodeString::kInvariant
00071
00089 #if defined(U_DECLARE_UTF16)
00090 # define UNICODE_STRING(cs, _length) U_NAMESPACE_QUALIFIER UnicodeString(TRUE, (const UChar *)U_DECLARE_UTF16(cs), _length)
00091 #elif U_SIZEOF_WCHAR_T==U_SIZEOF_UCHAR && (U_CHARSET_FAMILY==U_ASCII_FAMILY || (U_SIZEOF_UCHAR == 2 && defined(U_WCHAR_IS_UTF16)))
00092 # define UNICODE_STRING(cs, _length) U_NAMESPACE_QUALIFIER UnicodeString(TRUE, (const UChar *)L ## cs, _length)
00093 #elif U_SIZEOF_UCHAR==1 && U_CHARSET_FAMILY==U_ASCII_FAMILY
00094 # define UNICODE_STRING(cs, _length) U_NAMESPACE_QUALIFIER UnicodeString(TRUE, (const UChar *)cs, _length)
00095 #else
00096 # define UNICODE_STRING(cs, _length) U_NAMESPACE_QUALIFIER UnicodeString(cs, _length, US_INV)
00097 #endif
00098
00112 #define UNICODE_STRING_SIMPLE(cs) UNICODE_STRING(cs, -1)
00113
00183 class U_COMMON_API UnicodeString : public Replaceable
00184 {
00185 public:
00186
00195 enum EInvariant {
00200 kInvariant
00201 };
00202
00203
00204
00205
00206
00207
00208
00216 inline UBool operator== (const UnicodeString& text) const;
00217
00225 inline UBool operator!= (const UnicodeString& text) const;
00226
00234 inline UBool operator> (const UnicodeString& text) const;
00235
00243 inline UBool operator< (const UnicodeString& text) const;
00244
00252 inline UBool operator>= (const UnicodeString& text) const;
00253
00261 inline UBool operator<= (const UnicodeString& text) const;
00262
00274 inline int8_t compare(const UnicodeString& text) const;
00275
00290 inline int8_t compare(int32_t start,
00291 int32_t length,
00292 const UnicodeString& text) const;
00293
00311 inline int8_t compare(int32_t start,
00312 int32_t length,
00313 const UnicodeString& srcText,
00314 int32_t srcStart,
00315 int32_t srcLength) const;
00316
00329 inline int8_t compare(const UChar *srcChars,
00330 int32_t srcLength) const;
00331
00346 inline int8_t compare(int32_t start,
00347 int32_t length,
00348 const UChar *srcChars) const;
00349
00367 inline int8_t compare(int32_t start,
00368 int32_t length,
00369 const UChar *srcChars,
00370 int32_t srcStart,
00371 int32_t srcLength) const;
00372
00390 inline int8_t compareBetween(int32_t start,
00391 int32_t limit,
00392 const UnicodeString& srcText,
00393 int32_t srcStart,
00394 int32_t srcLimit) const;
00395
00413 inline int8_t compareCodePointOrder(const UnicodeString& text) const;
00414
00434 inline int8_t compareCodePointOrder(int32_t start,
00435 int32_t length,
00436 const UnicodeString& srcText) const;
00437
00459 inline int8_t compareCodePointOrder(int32_t start,
00460 int32_t length,
00461 const UnicodeString& srcText,
00462 int32_t srcStart,
00463 int32_t srcLength) const;
00464
00483 inline int8_t compareCodePointOrder(const UChar *srcChars,
00484 int32_t srcLength) const;
00485
00505 inline int8_t compareCodePointOrder(int32_t start,
00506 int32_t length,
00507 const UChar *srcChars) const;
00508
00530 inline int8_t compareCodePointOrder(int32_t start,
00531 int32_t length,
00532 const UChar *srcChars,
00533 int32_t srcStart,
00534 int32_t srcLength) const;
00535
00557 inline int8_t compareCodePointOrderBetween(int32_t start,
00558 int32_t limit,
00559 const UnicodeString& srcText,
00560 int32_t srcStart,
00561 int32_t srcLimit) const;
00562
00581 inline int8_t caseCompare(const UnicodeString& text, uint32_t options) const;
00582
00603 inline int8_t caseCompare(int32_t start,
00604 int32_t length,
00605 const UnicodeString& srcText,
00606 uint32_t options) const;
00607
00630 inline int8_t caseCompare(int32_t start,
00631 int32_t length,
00632 const UnicodeString& srcText,
00633 int32_t srcStart,
00634 int32_t srcLength,
00635 uint32_t options) const;
00636
00656 inline int8_t caseCompare(const UChar *srcChars,
00657 int32_t srcLength,
00658 uint32_t options) const;
00659
00680 inline int8_t caseCompare(int32_t start,
00681 int32_t length,
00682 const UChar *srcChars,
00683 uint32_t options) const;
00684
00707 inline int8_t caseCompare(int32_t start,
00708 int32_t length,
00709 const UChar *srcChars,
00710 int32_t srcStart,
00711 int32_t srcLength,
00712 uint32_t options) const;
00713
00736 inline int8_t caseCompareBetween(int32_t start,
00737 int32_t limit,
00738 const UnicodeString& srcText,
00739 int32_t srcStart,
00740 int32_t srcLimit,
00741 uint32_t options) const;
00742
00750 inline UBool startsWith(const UnicodeString& text) const;
00751
00762 inline UBool startsWith(const UnicodeString& srcText,
00763 int32_t srcStart,
00764 int32_t srcLength) const;
00765
00774 inline UBool startsWith(const UChar *srcChars,
00775 int32_t srcLength) const;
00776
00786 inline UBool startsWith(const UChar *srcChars,
00787 int32_t srcStart,
00788 int32_t srcLength) const;
00789
00797 inline UBool endsWith(const UnicodeString& text) const;
00798
00809 inline UBool endsWith(const UnicodeString& srcText,
00810 int32_t srcStart,
00811 int32_t srcLength) const;
00812
00821 inline UBool endsWith(const UChar *srcChars,
00822 int32_t srcLength) const;
00823
00834 inline UBool endsWith(const UChar *srcChars,
00835 int32_t srcStart,
00836 int32_t srcLength) const;
00837
00838
00839
00840
00849 inline int32_t indexOf(const UnicodeString& text) const;
00850
00860 inline int32_t indexOf(const UnicodeString& text,
00861 int32_t start) const;
00862
00874 inline int32_t indexOf(const UnicodeString& text,
00875 int32_t start,
00876 int32_t length) const;
00877
00894 inline int32_t indexOf(const UnicodeString& srcText,
00895 int32_t srcStart,
00896 int32_t srcLength,
00897 int32_t start,
00898 int32_t length) const;
00899
00911 inline int32_t indexOf(const UChar *srcChars,
00912 int32_t srcLength,
00913 int32_t start) const;
00914
00927 inline int32_t indexOf(const UChar *srcChars,
00928 int32_t srcLength,
00929 int32_t start,
00930 int32_t length) const;
00931
00948 int32_t indexOf(const UChar *srcChars,
00949 int32_t srcStart,
00950 int32_t srcLength,
00951 int32_t start,
00952 int32_t length) const;
00953
00961 inline int32_t indexOf(UChar c) const;
00962
00971 inline int32_t indexOf(UChar32 c) const;
00972
00981 inline int32_t indexOf(UChar c,
00982 int32_t start) const;
00983
00993 inline int32_t indexOf(UChar32 c,
00994 int32_t start) const;
00995
01006 inline int32_t indexOf(UChar c,
01007 int32_t start,
01008 int32_t length) const;
01009
01021 inline int32_t indexOf(UChar32 c,
01022 int32_t start,
01023 int32_t length) const;
01024
01033 inline int32_t lastIndexOf(const UnicodeString& text) const;
01034
01044 inline int32_t lastIndexOf(const UnicodeString& text,
01045 int32_t start) const;
01046
01058 inline int32_t lastIndexOf(const UnicodeString& text,
01059 int32_t start,
01060 int32_t length) const;
01061
01078 inline int32_t lastIndexOf(const UnicodeString& srcText,
01079 int32_t srcStart,
01080 int32_t srcLength,
01081 int32_t start,
01082 int32_t length) const;
01083
01094 inline int32_t lastIndexOf(const UChar *srcChars,
01095 int32_t srcLength,
01096 int32_t start) const;
01097
01110 inline int32_t lastIndexOf(const UChar *srcChars,
01111 int32_t srcLength,
01112 int32_t start,
01113 int32_t length) const;
01114
01131 int32_t lastIndexOf(const UChar *srcChars,
01132 int32_t srcStart,
01133 int32_t srcLength,
01134 int32_t start,
01135 int32_t length) const;
01136
01144 inline int32_t lastIndexOf(UChar c) const;
01145
01154 inline int32_t lastIndexOf(UChar32 c) const;
01155
01164 inline int32_t lastIndexOf(UChar c,
01165 int32_t start) const;
01166
01176 inline int32_t lastIndexOf(UChar32 c,
01177 int32_t start) const;
01178
01189 inline int32_t lastIndexOf(UChar c,
01190 int32_t start,
01191 int32_t length) const;
01192
01204 inline int32_t lastIndexOf(UChar32 c,
01205 int32_t start,
01206 int32_t length) const;
01207
01208
01209
01210
01219 inline UChar charAt(int32_t offset) const;
01220
01228 inline UChar operator[] (int32_t offset) const;
01229
01241 inline UChar32 char32At(int32_t offset) const;
01242
01258 inline int32_t getChar32Start(int32_t offset) const;
01259
01276 inline int32_t getChar32Limit(int32_t offset) const;
01277
01328 int32_t moveIndex32(int32_t index, int32_t delta) const;
01329
01330
01331
01347 inline void extract(int32_t start,
01348 int32_t length,
01349 UChar *dst,
01350 int32_t dstStart = 0) const;
01351
01373 int32_t
01374 extract(UChar *dest, int32_t destCapacity,
01375 UErrorCode &errorCode) const;
01376
01387 inline void extract(int32_t start,
01388 int32_t length,
01389 UnicodeString& target) const;
01390
01402 inline void extractBetween(int32_t start,
01403 int32_t limit,
01404 UChar *dst,
01405 int32_t dstStart = 0) const;
01406
01416 virtual void extractBetween(int32_t start,
01417 int32_t limit,
01418 UnicodeString& target) const;
01419
01441 int32_t extract(int32_t start,
01442 int32_t startLength,
01443 char *target,
01444 int32_t targetCapacity,
01445 enum EInvariant inv) const;
01446
01447 #if !UCONFIG_NO_CONVERSION
01448
01474 inline int32_t extract(int32_t start,
01475 int32_t startLength,
01476 char *target,
01477 const char *codepage = 0) const;
01478
01508 int32_t extract(int32_t start,
01509 int32_t startLength,
01510 char *target,
01511 uint32_t targetLength,
01512 const char *codepage = 0) const;
01513
01531 int32_t extract(char *dest, int32_t destCapacity,
01532 UConverter *cnv,
01533 UErrorCode &errorCode) const;
01534
01535 #endif
01536
01537
01538
01547 inline int32_t length(void) const;
01548
01562 int32_t
01563 countChar32(int32_t start=0, int32_t length=INT32_MAX) const;
01564
01588 UBool
01589 hasMoreChar32Than(int32_t start, int32_t length, int32_t number) const;
01590
01596 inline UBool isEmpty(void) const;
01597
01607 inline int32_t getCapacity(void) const;
01608
01609
01610
01616 inline int32_t hashCode(void) const;
01617
01629 inline UBool isBogus(void) const;
01630
01631
01632
01633
01634
01635
01636
01637
01645 UnicodeString &operator=(const UnicodeString &srcText);
01646
01667 UnicodeString &fastCopyFrom(const UnicodeString &src);
01668
01676 inline UnicodeString& operator= (UChar ch);
01677
01685 inline UnicodeString& operator= (UChar32 ch);
01686
01698 inline UnicodeString& setTo(const UnicodeString& srcText,
01699 int32_t srcStart);
01700
01714 inline UnicodeString& setTo(const UnicodeString& srcText,
01715 int32_t srcStart,
01716 int32_t srcLength);
01717
01726 inline UnicodeString& setTo(const UnicodeString& srcText);
01727
01736 inline UnicodeString& setTo(const UChar *srcChars,
01737 int32_t srcLength);
01738
01747 UnicodeString& setTo(UChar srcChar);
01748
01757 UnicodeString& setTo(UChar32 srcChar);
01758
01779 UnicodeString &setTo(UBool isTerminated,
01780 const UChar *text,
01781 int32_t textLength);
01782
01802 UnicodeString &setTo(UChar *buffer,
01803 int32_t buffLength,
01804 int32_t buffCapacity);
01805
01846 void setToBogus();
01847
01855 UnicodeString& setCharAt(int32_t offset,
01856 UChar ch);
01857
01858
01859
01860
01868 inline UnicodeString& operator+= (UChar ch);
01869
01877 inline UnicodeString& operator+= (UChar32 ch);
01878
01887 inline UnicodeString& operator+= (const UnicodeString& srcText);
01888
01903 inline UnicodeString& append(const UnicodeString& srcText,
01904 int32_t srcStart,
01905 int32_t srcLength);
01906
01914 inline UnicodeString& append(const UnicodeString& srcText);
01915
01929 inline UnicodeString& append(const UChar *srcChars,
01930 int32_t srcStart,
01931 int32_t srcLength);
01932
01941 inline UnicodeString& append(const UChar *srcChars,
01942 int32_t srcLength);
01943
01950 inline UnicodeString& append(UChar srcChar);
01951
01958 inline UnicodeString& append(UChar32 srcChar);
01959
01960
01961
01962
01976 inline UnicodeString& insert(int32_t start,
01977 const UnicodeString& srcText,
01978 int32_t srcStart,
01979 int32_t srcLength);
01980
01989 inline UnicodeString& insert(int32_t start,
01990 const UnicodeString& srcText);
01991
02005 inline UnicodeString& insert(int32_t start,
02006 const UChar *srcChars,
02007 int32_t srcStart,
02008 int32_t srcLength);
02009
02019 inline UnicodeString& insert(int32_t start,
02020 const UChar *srcChars,
02021 int32_t srcLength);
02022
02031 inline UnicodeString& insert(int32_t start,
02032 UChar srcChar);
02033
02042 inline UnicodeString& insert(int32_t start,
02043 UChar32 srcChar);
02044
02045
02046
02047
02065 UnicodeString& replace(int32_t start,
02066 int32_t length,
02067 const UnicodeString& srcText,
02068 int32_t srcStart,
02069 int32_t srcLength);
02070
02083 UnicodeString& replace(int32_t start,
02084 int32_t length,
02085 const UnicodeString& srcText);
02086
02104 UnicodeString& replace(int32_t start,
02105 int32_t length,
02106 const UChar *srcChars,
02107 int32_t srcStart,
02108 int32_t srcLength);
02109
02122 inline UnicodeString& replace(int32_t start,
02123 int32_t length,
02124 const UChar *srcChars,
02125 int32_t srcLength);
02126
02138 inline UnicodeString& replace(int32_t start,
02139 int32_t length,
02140 UChar srcChar);
02141
02153 inline UnicodeString& replace(int32_t start,
02154 int32_t length,
02155 UChar32 srcChar);
02156
02166 inline UnicodeString& replaceBetween(int32_t start,
02167 int32_t limit,
02168 const UnicodeString& srcText);
02169
02184 inline UnicodeString& replaceBetween(int32_t start,
02185 int32_t limit,
02186 const UnicodeString& srcText,
02187 int32_t srcStart,
02188 int32_t srcLimit);
02189
02200 virtual void handleReplaceBetween(int32_t start,
02201 int32_t limit,
02202 const UnicodeString& text);
02203
02209 virtual UBool hasMetaData() const;
02210
02226 virtual void copy(int32_t start, int32_t limit, int32_t dest);
02227
02228
02229
02238 inline UnicodeString& findAndReplace(const UnicodeString& oldText,
02239 const UnicodeString& newText);
02240
02252 inline UnicodeString& findAndReplace(int32_t start,
02253 int32_t length,
02254 const UnicodeString& oldText,
02255 const UnicodeString& newText);
02256
02274 UnicodeString& findAndReplace(int32_t start,
02275 int32_t length,
02276 const UnicodeString& oldText,
02277 int32_t oldStart,
02278 int32_t oldLength,
02279 const UnicodeString& newText,
02280 int32_t newStart,
02281 int32_t newLength);
02282
02283
02284
02285
02291 inline UnicodeString& remove(void);
02292
02301 inline UnicodeString& remove(int32_t start,
02302 int32_t length = (int32_t)INT32_MAX);
02303
02312 inline UnicodeString& removeBetween(int32_t start,
02313 int32_t limit = (int32_t)INT32_MAX);
02314
02315
02316
02317
02329 UBool padLeading(int32_t targetLength,
02330 UChar padChar = 0x0020);
02331
02343 UBool padTrailing(int32_t targetLength,
02344 UChar padChar = 0x0020);
02345
02352 inline UBool truncate(int32_t targetLength);
02353
02359 UnicodeString& trim(void);
02360
02361
02362
02363
02369 inline UnicodeString& reverse(void);
02370
02379 inline UnicodeString& reverse(int32_t start,
02380 int32_t length);
02381
02388 UnicodeString& toUpper(void);
02389
02397 UnicodeString& toUpper(const Locale& locale);
02398
02405 UnicodeString& toLower(void);
02406
02414 UnicodeString& toLower(const Locale& locale);
02415
02416 #if !UCONFIG_NO_BREAK_ITERATION
02417
02444 UnicodeString &toTitle(BreakIterator *titleIter);
02445
02473 UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale);
02474
02506 UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale, uint32_t options);
02507
02508 #endif
02509
02521 UnicodeString &foldCase(uint32_t options=0 );
02522
02523
02524
02525
02526
02570 UChar *getBuffer(int32_t minCapacity);
02571
02592 void releaseBuffer(int32_t newLength=-1);
02593
02624 inline const UChar *getBuffer() const;
02625
02659 inline const UChar *getTerminatedBuffer();
02660
02661
02662
02663
02664
02668 UnicodeString();
02669
02681 UnicodeString(int32_t capacity, UChar32 c, int32_t count);
02682
02688 UnicodeString(UChar ch);
02689
02695 UnicodeString(UChar32 ch);
02696
02703 UnicodeString(const UChar *text);
02704
02712 UnicodeString(const UChar *text,
02713 int32_t textLength);
02714
02734 UnicodeString(UBool isTerminated,
02735 const UChar *text,
02736 int32_t textLength);
02737
02756 UnicodeString(UChar *buffer, int32_t buffLength, int32_t buffCapacity);
02757
02758 #if !UCONFIG_NO_CONVERSION
02759
02777 UnicodeString(const char *codepageData,
02778 const char *codepage = 0);
02779
02797 UnicodeString(const char *codepageData,
02798 int32_t dataLength,
02799 const char *codepage = 0);
02800
02822 UnicodeString(
02823 const char *src, int32_t srcLength,
02824 UConverter *cnv,
02825 UErrorCode &errorCode);
02826
02827 #endif
02828
02853 UnicodeString(const char *src, int32_t length, enum EInvariant inv);
02854
02855
02861 UnicodeString(const UnicodeString& that);
02862
02869 UnicodeString(const UnicodeString& src, int32_t srcStart);
02870
02878 UnicodeString(const UnicodeString& src, int32_t srcStart, int32_t srcLength);
02879
02896 virtual Replaceable *clone() const;
02897
02901 virtual ~UnicodeString();
02902
02903
02904
02905
02940 UnicodeString unescape() const;
02941
02961 UChar32 unescapeAt(int32_t &offset) const;
02962
02968 static UClassID U_EXPORT2 getStaticClassID();
02969
02975 virtual UClassID getDynamicClassID() const;
02976
02977
02978
02979
02980
02981 protected:
02986 virtual int32_t getLength() const;
02987
02993 virtual UChar getCharAt(int32_t offset) const;
02994
03000 virtual UChar32 getChar32At(int32_t offset) const;
03001
03002 private:
03003
03004 inline int8_t
03005 doCompare(int32_t start,
03006 int32_t length,
03007 const UnicodeString& srcText,
03008 int32_t srcStart,
03009 int32_t srcLength) const;
03010
03011 int8_t doCompare(int32_t start,
03012 int32_t length,
03013 const UChar *srcChars,
03014 int32_t srcStart,
03015 int32_t srcLength) const;
03016
03017 inline int8_t
03018 doCompareCodePointOrder(int32_t start,
03019 int32_t length,
03020 const UnicodeString& srcText,
03021 int32_t srcStart,
03022 int32_t srcLength) const;
03023
03024 int8_t doCompareCodePointOrder(int32_t start,
03025 int32_t length,
03026 const UChar *srcChars,
03027 int32_t srcStart,
03028 int32_t srcLength) const;
03029
03030 inline int8_t
03031 doCaseCompare(int32_t start,
03032 int32_t length,
03033 const UnicodeString &srcText,
03034 int32_t srcStart,
03035 int32_t srcLength,
03036 uint32_t options) const;
03037
03038 int8_t
03039 doCaseCompare(int32_t start,
03040 int32_t length,
03041 const UChar *srcChars,
03042 int32_t srcStart,
03043 int32_t srcLength,
03044 uint32_t options) const;
03045
03046 int32_t doIndexOf(UChar c,
03047 int32_t start,
03048 int32_t length) const;
03049
03050 int32_t doIndexOf(UChar32 c,
03051 int32_t start,
03052 int32_t length) const;
03053
03054 int32_t doLastIndexOf(UChar c,
03055 int32_t start,
03056 int32_t length) const;
03057
03058 int32_t doLastIndexOf(UChar32 c,
03059 int32_t start,
03060 int32_t length) const;
03061
03062 void doExtract(int32_t start,
03063 int32_t length,
03064 UChar *dst,
03065 int32_t dstStart) const;
03066
03067 inline void doExtract(int32_t start,
03068 int32_t length,
03069 UnicodeString& target) const;
03070
03071 inline UChar doCharAt(int32_t offset) const;
03072
03073 UnicodeString& doReplace(int32_t start,
03074 int32_t length,
03075 const UnicodeString& srcText,
03076 int32_t srcStart,
03077 int32_t srcLength);
03078
03079 UnicodeString& doReplace(int32_t start,
03080 int32_t length,
03081 const UChar *srcChars,
03082 int32_t srcStart,
03083 int32_t srcLength);
03084
03085 UnicodeString& doReverse(int32_t start,
03086 int32_t length);
03087
03088
03089 int32_t doHashCode(void) const;
03090
03091
03092 inline UChar* getArrayStart(void);
03093 inline const UChar* getArrayStart(void) const;
03094
03095
03096
03097
03098
03099 UBool allocate(int32_t capacity);
03100
03101
03102 void releaseArray(void);
03103
03104
03105 void unBogus();
03106
03107
03108 UnicodeString ©From(const UnicodeString &src, UBool fastCopy=FALSE);
03109
03110
03111 inline void pinIndex(int32_t& start) const;
03112 inline void pinIndices(int32_t& start,
03113 int32_t& length) const;
03114
03115 #if !UCONFIG_NO_CONVERSION
03116
03117
03118 int32_t doExtract(int32_t start, int32_t length,
03119 char *dest, int32_t destCapacity,
03120 UConverter *cnv,
03121 UErrorCode &errorCode) const;
03122
03123
03124
03125
03126
03127
03128
03129
03130
03131
03132
03133 void doCodepageCreate(const char *codepageData,
03134 int32_t dataLength,
03135 const char *codepage);
03136
03137
03138
03139
03140
03141 void
03142 doCodepageCreate(const char *codepageData,
03143 int32_t dataLength,
03144 UConverter *converter,
03145 UErrorCode &status);
03146
03147 #endif
03148
03149
03150
03151
03152
03153
03154
03155
03156
03157
03158
03159
03160 UBool cloneArrayIfNeeded(int32_t newCapacity = -1,
03161 int32_t growCapacity = -1,
03162 UBool doCopyArray = TRUE,
03163 int32_t **pBufferToDelete = 0,
03164 UBool forceClone = FALSE);
03165
03166
03167 UnicodeString &
03168 caseMap(BreakIterator *titleIter,
03169 const char *locale,
03170 uint32_t options,
03171 int32_t toWhichCase);
03172
03173
03174 void addRef(void);
03175 int32_t removeRef(void);
03176 int32_t refCount(void) const;
03177
03178
03179 enum {
03180 US_STACKBUF_SIZE=7,
03181 kInvalidUChar=0xffff,
03182 kGrowSize=128,
03183 kInvalidHashCode=0,
03184 kEmptyHashCode=1,
03185
03186
03187 kIsBogus=1,
03188 kUsingStackBuffer=2,
03189 kRefCounted=4,
03190 kBufferIsReadonly=8,
03191 kOpenGetBuffer=16,
03192
03193
03194
03195 kShortString=kUsingStackBuffer,
03196 kLongString=kRefCounted,
03197 kReadonlyAlias=kBufferIsReadonly,
03198 kWritableAlias=0
03199 };
03200
03201 friend class StringCharacterIterator;
03202 friend class StringThreadTest;
03203
03204
03205
03206
03207
03208
03209
03210
03211
03212
03213
03214
03215
03216 int32_t fLength;
03217 int32_t fCapacity;
03218 UChar *fArray;
03219 uint16_t fFlags;
03220 UChar fStackBuffer [ US_STACKBUF_SIZE ];
03221
03222 };
03223
03232 U_COMMON_API UnicodeString U_EXPORT2
03233 operator+ (const UnicodeString &s1, const UnicodeString &s2);
03234
03235
03236
03237
03238
03239
03240
03241
03242
03243 inline void
03244 UnicodeString::pinIndex(int32_t& start) const
03245 {
03246
03247 if(start < 0) {
03248 start = 0;
03249 } else if(start > fLength) {
03250 start = fLength;
03251 }
03252 }
03253
03254 inline void
03255 UnicodeString::pinIndices(int32_t& start,
03256 int32_t& _length) const
03257 {
03258
03259 if(start < 0) {
03260 start = 0;
03261 } else if(start > fLength) {
03262 start = fLength;
03263 }
03264 if(_length < 0) {
03265 _length = 0;
03266 } else if(_length > (fLength - start)) {
03267 _length = (fLength - start);
03268 }
03269 }
03270
03271 inline UChar*
03272 UnicodeString::getArrayStart()
03273 { return fArray; }
03274
03275 inline const UChar*
03276 UnicodeString::getArrayStart() const
03277 { return fArray; }
03278
03279
03280
03281
03282 inline int32_t
03283 UnicodeString::length() const
03284 { return fLength; }
03285
03286 inline int32_t
03287 UnicodeString::getCapacity() const
03288 { return fCapacity; }
03289
03290 inline int32_t
03291 UnicodeString::hashCode() const
03292 { return doHashCode(); }
03293
03294 inline UBool
03295 UnicodeString::isBogus() const
03296 { return (UBool)(fFlags & kIsBogus); }
03297
03298 inline const UChar *
03299 UnicodeString::getBuffer() const {
03300 if(!(fFlags&(kIsBogus|kOpenGetBuffer))) {
03301 return fArray;
03302 } else {
03303 return 0;
03304 }
03305 }
03306
03307
03308
03309
03310 inline int8_t
03311 UnicodeString::doCompare(int32_t start,
03312 int32_t length,
03313 const UnicodeString& srcText,
03314 int32_t srcStart,
03315 int32_t srcLength) const
03316 {
03317 if(srcText.isBogus()) {
03318 return (int8_t)!isBogus();
03319 } else {
03320 srcText.pinIndices(srcStart, srcLength);
03321 return doCompare(start, length, srcText.fArray, srcStart, srcLength);
03322 }
03323 }
03324
03325 inline UBool
03326 UnicodeString::operator== (const UnicodeString& text) const
03327 {
03328 if(isBogus()) {
03329 return text.isBogus();
03330 } else {
03331 return
03332 !text.isBogus() &&
03333 fLength == text.fLength &&
03334 doCompare(0, fLength, text, 0, text.fLength) == 0;
03335 }
03336 }
03337
03338 inline UBool
03339 UnicodeString::operator!= (const UnicodeString& text) const
03340 { return (! operator==(text)); }
03341
03342 inline UBool
03343 UnicodeString::operator> (const UnicodeString& text) const
03344 { return doCompare(0, fLength, text, 0, text.fLength) == 1; }
03345
03346 inline UBool
03347 UnicodeString::operator< (const UnicodeString& text) const
03348 { return doCompare(0, fLength, text, 0, text.fLength) == -1; }
03349
03350 inline UBool
03351 UnicodeString::operator>= (const UnicodeString& text) const
03352 { return doCompare(0, fLength, text, 0, text.fLength) != -1; }
03353
03354 inline UBool
03355 UnicodeString::operator<= (const UnicodeString& text) const
03356 { return doCompare(0, fLength, text, 0, text.fLength) != 1; }
03357
03358 inline int8_t
03359 UnicodeString::compare(const UnicodeString& text) const
03360 { return doCompare(0, fLength, text, 0, text.fLength); }
03361
03362 inline int8_t
03363 UnicodeString::compare(int32_t start,
03364 int32_t _length,
03365 const UnicodeString& srcText) const
03366 { return doCompare(start, _length, srcText, 0, srcText.fLength); }
03367
03368 inline int8_t
03369 UnicodeString::compare(const UChar *srcChars,
03370 int32_t srcLength) const
03371 { return doCompare(0, fLength, srcChars, 0, srcLength); }
03372
03373 inline int8_t
03374 UnicodeString::compare(int32_t start,
03375 int32_t _length,
03376 const UnicodeString& srcText,
03377 int32_t srcStart,
03378 int32_t srcLength) const
03379 { return doCompare(start, _length, srcText, srcStart, srcLength); }
03380
03381 inline int8_t
03382 UnicodeString::compare(int32_t start,
03383 int32_t _length,
03384 const UChar *srcChars) const
03385 { return doCompare(start, _length, srcChars, 0, _length); }
03386
03387 inline int8_t
03388 UnicodeString::compare(int32_t start,
03389 int32_t _length,
03390 const UChar *srcChars,
03391 int32_t srcStart,
03392 int32_t srcLength) const
03393 { return doCompare(start, _length, srcChars, srcStart, srcLength); }
03394
03395 inline int8_t
03396 UnicodeString::compareBetween(int32_t start,
03397 int32_t limit,
03398 const UnicodeString& srcText,
03399 int32_t srcStart,
03400 int32_t srcLimit) const
03401 { return doCompare(start, limit - start,
03402 srcText, srcStart, srcLimit - srcStart); }
03403
03404 inline int8_t
03405 UnicodeString::doCompareCodePointOrder(int32_t start,
03406 int32_t length,
03407 const UnicodeString& srcText,
03408 int32_t srcStart,
03409 int32_t srcLength) const
03410 {
03411 if(srcText.isBogus()) {
03412 return (int8_t)!isBogus();
03413 } else {
03414 srcText.pinIndices(srcStart, srcLength);
03415 return doCompareCodePointOrder(start, length, srcText.fArray, srcStart, srcLength);
03416 }
03417 }
03418
03419 inline int8_t
03420 UnicodeString::compareCodePointOrder(const UnicodeString& text) const
03421 { return doCompareCodePointOrder(0, fLength, text, 0, text.fLength); }
03422
03423 inline int8_t
03424 UnicodeString::compareCodePointOrder(int32_t start,
03425 int32_t _length,
03426 const UnicodeString& srcText) const
03427 { return doCompareCodePointOrder(start, _length, srcText, 0, srcText.fLength); }
03428
03429 inline int8_t
03430 UnicodeString::compareCodePointOrder(const UChar *srcChars,
03431 int32_t srcLength) const
03432 { return doCompareCodePointOrder(0, fLength, srcChars, 0, srcLength); }
03433
03434 inline int8_t
03435 UnicodeString::compareCodePointOrder(int32_t start,
03436 int32_t _length,
03437 const UnicodeString& srcText,
03438 int32_t srcStart,
03439 int32_t srcLength) const
03440 { return doCompareCodePointOrder(start, _length, srcText, srcStart, srcLength); }
03441
03442 inline int8_t
03443 UnicodeString::compareCodePointOrder(int32_t start,
03444 int32_t _length,
03445 const UChar *srcChars) const
03446 { return doCompareCodePointOrder(start, _length, srcChars, 0, _length); }
03447
03448 inline int8_t
03449 UnicodeString::compareCodePointOrder(int32_t start,
03450 int32_t _length,
03451 const UChar *srcChars,
03452 int32_t srcStart,
03453 int32_t srcLength) const
03454 { return doCompareCodePointOrder(start, _length, srcChars, srcStart, srcLength); }
03455
03456 inline int8_t
03457 UnicodeString::compareCodePointOrderBetween(int32_t start,
03458 int32_t limit,
03459 const UnicodeString& srcText,
03460 int32_t srcStart,
03461 int32_t srcLimit) const
03462 { return doCompareCodePointOrder(start, limit - start,
03463 srcText, srcStart, srcLimit - srcStart); }
03464
03465 inline int8_t
03466 UnicodeString::doCaseCompare(int32_t start,
03467 int32_t length,
03468 const UnicodeString &srcText,
03469 int32_t srcStart,
03470 int32_t srcLength,
03471 uint32_t options) const
03472 {
03473 if(srcText.isBogus()) {
03474 return (int8_t)!isBogus();
03475 } else {
03476 srcText.pinIndices(srcStart, srcLength);
03477 return doCaseCompare(start, length, srcText.fArray, srcStart, srcLength, options);
03478 }
03479 }
03480
03481 inline int8_t
03482 UnicodeString::caseCompare(const UnicodeString &text, uint32_t options) const {
03483 return doCaseCompare(0, fLength, text, 0, text.fLength, options);
03484 }
03485
03486 inline int8_t
03487 UnicodeString::caseCompare(int32_t start,
03488 int32_t _length,
03489 const UnicodeString &srcText,
03490 uint32_t options) const {
03491 return doCaseCompare(start, _length, srcText, 0, srcText.fLength, options);
03492 }
03493
03494 inline int8_t
03495 UnicodeString::caseCompare(const UChar *srcChars,
03496 int32_t srcLength,
03497 uint32_t options) const {
03498 return doCaseCompare(0, fLength, srcChars, 0, srcLength, options);
03499 }
03500
03501 inline int8_t
03502 UnicodeString::caseCompare(int32_t start,
03503 int32_t _length,
03504 const UnicodeString &srcText,
03505 int32_t srcStart,
03506 int32_t srcLength,
03507 uint32_t options) const {
03508 return doCaseCompare(start, _length, srcText, srcStart, srcLength, options);
03509 }
03510
03511 inline int8_t
03512 UnicodeString::caseCompare(int32_t start,
03513 int32_t _length,
03514 const UChar *srcChars,
03515 uint32_t options) const {
03516 return doCaseCompare(start, _length, srcChars, 0, _length, options);
03517 }
03518
03519 inline int8_t
03520 UnicodeString::caseCompare(int32_t start,
03521 int32_t _length,
03522 const UChar *srcChars,
03523 int32_t srcStart,
03524 int32_t srcLength,
03525 uint32_t options) const {
03526 return doCaseCompare(start, _length, srcChars, srcStart, srcLength, options);
03527 }
03528
03529 inline int8_t
03530 UnicodeString::caseCompareBetween(int32_t start,
03531 int32_t limit,
03532 const UnicodeString &srcText,
03533 int32_t srcStart,
03534 int32_t srcLimit,
03535 uint32_t options) const {
03536 return doCaseCompare(start, limit - start, srcText, srcStart, srcLimit - srcStart, options);
03537 }
03538
03539 inline int32_t
03540 UnicodeString::indexOf(const UnicodeString& srcText,
03541 int32_t srcStart,
03542 int32_t srcLength,
03543 int32_t start,
03544 int32_t _length) const
03545 {
03546 if(!srcText.isBogus()) {
03547 srcText.pinIndices(srcStart, srcLength);
03548 if(srcLength > 0) {
03549 return indexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
03550 }
03551 }
03552 return -1;
03553 }
03554
03555 inline int32_t
03556 UnicodeString::indexOf(const UnicodeString& text) const
03557 { return indexOf(text, 0, text.fLength, 0, fLength); }
03558
03559 inline int32_t
03560 UnicodeString::indexOf(const UnicodeString& text,
03561 int32_t start) const {
03562 pinIndex(start);
03563 return indexOf(text, 0, text.fLength, start, fLength - start);
03564 }
03565
03566 inline int32_t
03567 UnicodeString::indexOf(const UnicodeString& text,
03568 int32_t start,
03569 int32_t _length) const
03570 { return indexOf(text, 0, text.fLength, start, _length); }
03571
03572 inline int32_t
03573 UnicodeString::indexOf(const UChar *srcChars,
03574 int32_t srcLength,
03575 int32_t start) const {
03576 pinIndex(start);
03577 return indexOf(srcChars, 0, srcLength, start, fLength - start);
03578 }
03579
03580 inline int32_t
03581 UnicodeString::indexOf(const UChar *srcChars,
03582 int32_t srcLength,
03583 int32_t start,
03584 int32_t _length) const
03585 { return indexOf(srcChars, 0, srcLength, start, _length); }
03586
03587 inline int32_t
03588 UnicodeString::indexOf(UChar c,
03589 int32_t start,
03590 int32_t _length) const
03591 { return doIndexOf(c, start, _length); }
03592
03593 inline int32_t
03594 UnicodeString::indexOf(UChar32 c,
03595 int32_t start,
03596 int32_t _length) const
03597 { return doIndexOf(c, start, _length); }
03598
03599 inline int32_t
03600 UnicodeString::indexOf(UChar c) const
03601 { return doIndexOf(c, 0, fLength); }
03602
03603 inline int32_t
03604 UnicodeString::indexOf(UChar32 c) const
03605 { return indexOf(c, 0, fLength); }
03606
03607 inline int32_t
03608 UnicodeString::indexOf(UChar c,
03609 int32_t start) const {
03610 pinIndex(start);
03611 return doIndexOf(c, start, fLength - start);
03612 }
03613
03614 inline int32_t
03615 UnicodeString::indexOf(UChar32 c,
03616 int32_t start) const {
03617 pinIndex(start);
03618 return indexOf(c, start, fLength - start);
03619 }
03620
03621 inline int32_t
03622 UnicodeString::lastIndexOf(const UChar *srcChars,
03623 int32_t srcLength,
03624 int32_t start,
03625 int32_t _length) const
03626 { return lastIndexOf(srcChars, 0, srcLength, start, _length); }
03627
03628 inline int32_t
03629 UnicodeString::lastIndexOf(const UChar *srcChars,
03630 int32_t srcLength,
03631 int32_t start) const {
03632 pinIndex(start);
03633 return lastIndexOf(srcChars, 0, srcLength, start, fLength - start);
03634 }
03635
03636 inline int32_t
03637 UnicodeString::lastIndexOf(const UnicodeString& srcText,
03638 int32_t srcStart,
03639 int32_t srcLength,
03640 int32_t start,
03641 int32_t _length) const
03642 {
03643 if(!srcText.isBogus()) {
03644 srcText.pinIndices(srcStart, srcLength);
03645 if(srcLength > 0) {
03646 return lastIndexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
03647 }
03648 }
03649 return -1;
03650 }
03651
03652 inline int32_t
03653 UnicodeString::lastIndexOf(const UnicodeString& text,
03654 int32_t start,
03655 int32_t _length) const
03656 { return lastIndexOf(text, 0, text.fLength, start, _length); }
03657
03658 inline int32_t
03659 UnicodeString::lastIndexOf(const UnicodeString& text,
03660 int32_t start) const {
03661 pinIndex(start);
03662 return lastIndexOf(text, 0, text.fLength, start, fLength - start);
03663 }
03664
03665 inline int32_t
03666 UnicodeString::lastIndexOf(const UnicodeString& text) const
03667 { return lastIndexOf(text, 0, text.fLength, 0, fLength); }
03668
03669 inline int32_t
03670 UnicodeString::lastIndexOf(UChar c,
03671 int32_t start,
03672 int32_t _length) const
03673 { return doLastIndexOf(c, start, _length); }
03674
03675 inline int32_t
03676 UnicodeString::lastIndexOf(UChar32 c,
03677 int32_t start,
03678 int32_t _length) const {
03679 return doLastIndexOf(c, start, _length);
03680 }
03681
03682 inline int32_t
03683 UnicodeString::lastIndexOf(UChar c) const
03684 { return doLastIndexOf(c, 0, fLength); }
03685
03686 inline int32_t
03687 UnicodeString::lastIndexOf(UChar32 c) const {
03688 return lastIndexOf(c, 0, fLength);
03689 }
03690
03691 inline int32_t
03692 UnicodeString::lastIndexOf(UChar c,
03693 int32_t start) const {
03694 pinIndex(start);
03695 return doLastIndexOf(c, start, fLength - start);
03696 }
03697
03698 inline int32_t
03699 UnicodeString::lastIndexOf(UChar32 c,
03700 int32_t start) const {
03701 pinIndex(start);
03702 return lastIndexOf(c, start, fLength - start);
03703 }
03704
03705 inline UBool
03706 UnicodeString::startsWith(const UnicodeString& text) const
03707 { return compare(0, text.fLength, text, 0, text.fLength) == 0; }
03708
03709 inline UBool
03710 UnicodeString::startsWith(const UnicodeString& srcText,
03711 int32_t srcStart,
03712 int32_t srcLength) const
03713 { return doCompare(0, srcLength, srcText, srcStart, srcLength) == 0; }
03714
03715 inline UBool
03716 UnicodeString::startsWith(const UChar *srcChars,
03717 int32_t srcLength) const
03718 { return doCompare(0, srcLength, srcChars, 0, srcLength) == 0; }
03719
03720 inline UBool
03721 UnicodeString::startsWith(const UChar *srcChars,
03722 int32_t srcStart,
03723 int32_t srcLength) const
03724 { return doCompare(0, srcLength, srcChars, srcStart, srcLength) == 0;}
03725
03726 inline UBool
03727 UnicodeString::endsWith(const UnicodeString& text) const
03728 { return doCompare(fLength - text.fLength, text.fLength,
03729 text, 0, text.fLength) == 0; }
03730
03731 inline UBool
03732 UnicodeString::endsWith(const UnicodeString& srcText,
03733 int32_t srcStart,
03734 int32_t srcLength) const {
03735 srcText.pinIndices(srcStart, srcLength);
03736 return doCompare(fLength - srcLength, srcLength,
03737 srcText, srcStart, srcLength) == 0;
03738 }
03739
03740 inline UBool
03741 UnicodeString::endsWith(const UChar *srcChars,
03742 int32_t srcLength) const {
03743 if(srcLength < 0) {
03744 srcLength = u_strlen(srcChars);
03745 }
03746 return doCompare(fLength - srcLength, srcLength,
03747 srcChars, 0, srcLength) == 0;
03748 }
03749
03750 inline UBool
03751 UnicodeString::endsWith(const UChar *srcChars,
03752 int32_t srcStart,
03753 int32_t srcLength) const {
03754 if(srcLength < 0) {
03755 srcLength = u_strlen(srcChars + srcStart);
03756 }
03757 return doCompare(fLength - srcLength, srcLength,
03758 srcChars, srcStart, srcLength) == 0;
03759 }
03760
03761
03762
03763
03764 inline UnicodeString&
03765 UnicodeString::replace(int32_t start,
03766 int32_t _length,
03767 const UnicodeString& srcText)
03768 { return doReplace(start, _length, srcText, 0, srcText.fLength); }
03769
03770 inline UnicodeString&
03771 UnicodeString::replace(int32_t start,
03772 int32_t _length,
03773 const UnicodeString& srcText,
03774 int32_t srcStart,
03775 int32_t srcLength)
03776 { return doReplace(start, _length, srcText, srcStart, srcLength); }
03777
03778 inline UnicodeString&
03779 UnicodeString::replace(int32_t start,
03780 int32_t _length,
03781 const UChar *srcChars,
03782 int32_t srcLength)
03783 { return doReplace(start, _length, srcChars, 0, srcLength); }
03784
03785 inline UnicodeString&
03786 UnicodeString::replace(int32_t start,
03787 int32_t _length,
03788 const UChar *srcChars,
03789 int32_t srcStart,
03790 int32_t srcLength)
03791 { return doReplace(start, _length, srcChars, srcStart, srcLength); }
03792
03793 inline UnicodeString&
03794 UnicodeString::replace(int32_t start,
03795 int32_t _length,
03796 UChar srcChar)
03797 { return doReplace(start, _length, &srcChar, 0, 1); }
03798
03799 inline UnicodeString&
03800 UnicodeString::replace(int32_t start,
03801 int32_t _length,
03802 UChar32 srcChar) {
03803 UChar buffer[U16_MAX_LENGTH];
03804 int32_t count = 0;
03805 UBool isError = FALSE;
03806 U16_APPEND(buffer, count, U16_MAX_LENGTH, srcChar, isError);
03807 return doReplace(start, _length, buffer, 0, count);
03808 }
03809
03810 inline UnicodeString&
03811 UnicodeString::replaceBetween(int32_t start,
03812 int32_t limit,
03813 const UnicodeString& srcText)
03814 { return doReplace(start, limit - start, srcText, 0, srcText.fLength); }
03815
03816 inline UnicodeString&
03817 UnicodeString::replaceBetween(int32_t start,
03818 int32_t limit,
03819 const UnicodeString& srcText,
03820 int32_t srcStart,
03821 int32_t srcLimit)
03822 { return doReplace(start, limit - start, srcText, srcStart, srcLimit - srcStart); }
03823
03824 inline UnicodeString&
03825 UnicodeString::findAndReplace(const UnicodeString& oldText,
03826 const UnicodeString& newText)
03827 { return findAndReplace(0, fLength, oldText, 0, oldText.fLength,
03828 newText, 0, newText.fLength); }
03829
03830 inline UnicodeString&
03831 UnicodeString::findAndReplace(int32_t start,
03832 int32_t _length,
03833 const UnicodeString& oldText,
03834 const UnicodeString& newText)
03835 { return findAndReplace(start, _length, oldText, 0, oldText.fLength,
03836 newText, 0, newText.fLength); }
03837
03838
03839
03840
03841 inline void
03842 UnicodeString::doExtract(int32_t start,
03843 int32_t _length,
03844 UnicodeString& target) const
03845 { target.replace(0, target.fLength, *this, start, _length); }
03846
03847 inline void
03848 UnicodeString::extract(int32_t start,
03849 int32_t _length,
03850 UChar *target,
03851 int32_t targetStart) const
03852 { doExtract(start, _length, target, targetStart); }
03853
03854 inline void
03855 UnicodeString::extract(int32_t start,
03856 int32_t _length,
03857 UnicodeString& target) const
03858 { doExtract(start, _length, target); }
03859
03860 #if !UCONFIG_NO_CONVERSION
03861
03862 inline int32_t
03863 UnicodeString::extract(int32_t start,
03864 int32_t _length,
03865 char *dst,
03866 const char *codepage) const
03867
03868 {
03869
03870 return extract(start, _length, dst, dst!=0 ? 0xffffffff : 0, codepage);
03871 }
03872
03873 #endif
03874
03875 inline void
03876 UnicodeString::extractBetween(int32_t start,
03877 int32_t limit,
03878 UChar *dst,
03879 int32_t dstStart) const {
03880 pinIndex(start);
03881 pinIndex(limit);
03882 doExtract(start, limit - start, dst, dstStart);
03883 }
03884
03885 inline UChar
03886 UnicodeString::doCharAt(int32_t offset) const
03887 {
03888 if((uint32_t)offset < (uint32_t)fLength) {
03889 return fArray[offset];
03890 } else {
03891 return kInvalidUChar;
03892 }
03893 }
03894
03895 inline UChar
03896 UnicodeString::charAt(int32_t offset) const
03897 { return doCharAt(offset); }
03898
03899 inline UChar
03900 UnicodeString::operator[] (int32_t offset) const
03901 { return doCharAt(offset); }
03902
03903 inline UChar32
03904 UnicodeString::char32At(int32_t offset) const
03905 {
03906 if((uint32_t)offset < (uint32_t)fLength) {
03907 UChar32 c;
03908 U16_GET(fArray, 0, offset, fLength, c);
03909 return c;
03910 } else {
03911 return kInvalidUChar;
03912 }
03913 }
03914
03915 inline int32_t
03916 UnicodeString::getChar32Start(int32_t offset) const {
03917 if((uint32_t)offset < (uint32_t)fLength) {
03918 U16_SET_CP_START(fArray, 0, offset);
03919 return offset;
03920 } else {
03921 return 0;
03922 }
03923 }
03924
03925 inline int32_t
03926 UnicodeString::getChar32Limit(int32_t offset) const {
03927 if((uint32_t)offset < (uint32_t)fLength) {
03928 U16_SET_CP_LIMIT(fArray, 0, offset, fLength);
03929 return offset;
03930 } else {
03931 return fLength;
03932 }
03933 }
03934
03935 inline UBool
03936 UnicodeString::isEmpty() const {
03937 return fLength == 0;
03938 }
03939
03940
03941
03942
03943 inline const UChar *
03944 UnicodeString::getTerminatedBuffer() {
03945 if(fFlags&(kIsBogus|kOpenGetBuffer)) {
03946 return 0;
03947 } else if(fLength<fCapacity && fArray[fLength]==0) {
03948 return fArray;
03949 } else if(cloneArrayIfNeeded(fLength+1)) {
03950 fArray[fLength]=0;
03951 return fArray;
03952 } else {
03953 return 0;
03954 }
03955 }
03956
03957 inline UnicodeString&
03958 UnicodeString::operator= (UChar ch)
03959 { return doReplace(0, fLength, &ch, 0, 1); }
03960
03961 inline UnicodeString&
03962 UnicodeString::operator= (UChar32 ch)
03963 { return replace(0, fLength, ch); }
03964
03965 inline UnicodeString&
03966 UnicodeString::setTo(const UnicodeString& srcText,
03967 int32_t srcStart,
03968 int32_t srcLength)
03969 {
03970 unBogus();
03971 return doReplace(0, fLength, srcText, srcStart, srcLength);
03972 }
03973
03974 inline UnicodeString&
03975 UnicodeString::setTo(const UnicodeString& srcText,
03976 int32_t srcStart)
03977 {
03978 unBogus();
03979 srcText.pinIndex(srcStart);
03980 return doReplace(0, fLength, srcText, srcStart, srcText.fLength - srcStart);
03981 }
03982
03983 inline UnicodeString&
03984 UnicodeString::setTo(const UnicodeString& srcText)
03985 {
03986 unBogus();
03987 return doReplace(0, fLength, srcText, 0, srcText.fLength);
03988 }
03989
03990 inline UnicodeString&
03991 UnicodeString::setTo(const UChar *srcChars,
03992 int32_t srcLength)
03993 {
03994 unBogus();
03995 return doReplace(0, fLength, srcChars, 0, srcLength);
03996 }
03997
03998 inline UnicodeString&
03999 UnicodeString::setTo(UChar srcChar)
04000 {
04001 unBogus();
04002 return doReplace(0, fLength, &srcChar, 0, 1);
04003 }
04004
04005 inline UnicodeString&
04006 UnicodeString::setTo(UChar32 srcChar)
04007 {
04008 unBogus();
04009 return replace(0, fLength, srcChar);
04010 }
04011
04012 inline UnicodeString&
04013 UnicodeString::append(const UnicodeString& srcText,
04014 int32_t srcStart,
04015 int32_t srcLength)
04016 { return doReplace(fLength, 0, srcText, srcStart, srcLength); }
04017
04018 inline UnicodeString&
04019 UnicodeString::append(const UnicodeString& srcText)
04020 { return doReplace(fLength, 0, srcText, 0, srcText.fLength); }
04021
04022 inline UnicodeString&
04023 UnicodeString::append(const UChar *srcChars,
04024 int32_t srcStart,
04025 int32_t srcLength)
04026 { return doReplace(fLength, 0, srcChars, srcStart, srcLength); }
04027
04028 inline UnicodeString&
04029 UnicodeString::append(const UChar *srcChars,
04030 int32_t srcLength)
04031 { return doReplace(fLength, 0, srcChars, 0, srcLength); }
04032
04033 inline UnicodeString&
04034 UnicodeString::append(UChar srcChar)
04035 { return doReplace(fLength, 0, &srcChar, 0, 1); }
04036
04037 inline UnicodeString&
04038 UnicodeString::append(UChar32 srcChar) {
04039 UChar buffer[U16_MAX_LENGTH];
04040 int32_t _length = 0;
04041 UBool isError = FALSE;
04042 U16_APPEND(buffer, _length, U16_MAX_LENGTH, srcChar, isError);
04043 return doReplace(fLength, 0, buffer, 0, _length);
04044 }
04045
04046 inline UnicodeString&
04047 UnicodeString::operator+= (UChar ch)
04048 { return doReplace(fLength, 0, &ch, 0, 1); }
04049
04050 inline UnicodeString&
04051 UnicodeString::operator+= (UChar32 ch) {
04052 return append(ch);
04053 }
04054
04055 inline UnicodeString&
04056 UnicodeString::operator+= (const UnicodeString& srcText)
04057 { return doReplace(fLength, 0, srcText, 0, srcText.fLength); }
04058
04059 inline UnicodeString&
04060 UnicodeString::insert(int32_t start,
04061 const UnicodeString& srcText,
04062 int32_t srcStart,
04063 int32_t srcLength)
04064 { return doReplace(start, 0, srcText, srcStart, srcLength); }
04065
04066 inline UnicodeString&
04067 UnicodeString::insert(int32_t start,
04068 const UnicodeString& srcText)
04069 { return doReplace(start, 0, srcText, 0, srcText.fLength); }
04070
04071 inline UnicodeString&
04072 UnicodeString::insert(int32_t start,
04073 const UChar *srcChars,
04074 int32_t srcStart,
04075 int32_t srcLength)
04076 { return doReplace(start, 0, srcChars, srcStart, srcLength); }
04077
04078 inline UnicodeString&
04079 UnicodeString::insert(int32_t start,
04080 const UChar *srcChars,
04081 int32_t srcLength)
04082 { return doReplace(start, 0, srcChars, 0, srcLength); }
04083
04084 inline UnicodeString&
04085 UnicodeString::insert(int32_t start,
04086 UChar srcChar)
04087 { return doReplace(start, 0, &srcChar, 0, 1); }
04088
04089 inline UnicodeString&
04090 UnicodeString::insert(int32_t start,
04091 UChar32 srcChar)
04092 { return replace(start, 0, srcChar); }
04093
04094
04095 inline UnicodeString&
04096 UnicodeString::remove()
04097 {
04098
04099 if(isBogus()) {
04100 unBogus();
04101 } else {
04102 fLength = 0;
04103 }
04104 return *this;
04105 }
04106
04107 inline UnicodeString&
04108 UnicodeString::remove(int32_t start,
04109 int32_t _length)
04110 {
04111 if(start <= 0 && _length == INT32_MAX) {
04112
04113 return remove();
04114 }
04115 return doReplace(start, _length, NULL, 0, 0);
04116 }
04117
04118 inline UnicodeString&
04119 UnicodeString::removeBetween(int32_t start,
04120 int32_t limit)
04121 { return doReplace(start, limit - start, NULL, 0, 0); }
04122
04123 inline UBool
04124 UnicodeString::truncate(int32_t targetLength)
04125 {
04126 if(isBogus() && targetLength == 0) {
04127
04128 unBogus();
04129 return FALSE;
04130 } else if((uint32_t)targetLength < (uint32_t)fLength) {
04131 fLength = targetLength;
04132 return TRUE;
04133 } else {
04134 return FALSE;
04135 }
04136 }
04137
04138 inline UnicodeString&
04139 UnicodeString::reverse()
04140 { return doReverse(0, fLength); }
04141
04142 inline UnicodeString&
04143 UnicodeString::reverse(int32_t start,
04144 int32_t _length)
04145 { return doReverse(start, _length); }
04146
04147 U_NAMESPACE_END
04148
04149 #endif