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
00024 #include "unicode/utypes.h"
00025 #include "unicode/uobject.h"
00026 #include "unicode/rep.h"
00027
00028 struct UConverter;
00029 class StringThreadTest;
00030
00031 #ifndef U_COMPARE_CODE_POINT_ORDER
00032
00038 #define U_COMPARE_CODE_POINT_ORDER 0x8000
00039 #endif
00040
00041 #ifndef USTRING_H
00042
00043 U_CAPI int32_t U_EXPORT2
00044 u_strlen(const UChar *s);
00045 #endif
00046
00047 U_NAMESPACE_BEGIN
00048
00049 class Locale;
00050 class UCharReference;
00051 class StringCharacterIterator;
00052 class BreakIterator;
00053
00054
00055
00073 #if U_SIZEOF_WCHAR_T==U_SIZEOF_UCHAR && U_CHARSET_FAMILY==U_ASCII_FAMILY
00074 # define UNICODE_STRING(cs, _length) UnicodeString(TRUE, (const UChar *)L ## cs, _length)
00075 #elif U_SIZEOF_UCHAR==1 && U_CHARSET_FAMILY==U_ASCII_FAMILY
00076 # define UNICODE_STRING(cs, _length) UnicodeString(TRUE, (const UChar *)cs, _length)
00077 #else
00078 # define UNICODE_STRING(cs, _length) UnicodeString(cs, _length, "")
00079 #endif
00080
00094 #if U_SIZEOF_WCHAR_T==U_SIZEOF_UCHAR && U_CHARSET_FAMILY==U_ASCII_FAMILY
00095 # define UNICODE_STRING_SIMPLE(cs) UnicodeString(TRUE, (const UChar *)L ## cs, -1)
00096 #elif U_SIZEOF_UCHAR==1 && U_CHARSET_FAMILY==U_ASCII_FAMILY
00097 # define UNICODE_STRING_SIMPLE(cs) UnicodeString(TRUE, (const UChar *)cs, -1)
00098 #else
00099 # define UNICODE_STRING_SIMPLE(cs) UnicodeString(cs, "")
00100 #endif
00101
00172 class U_COMMON_API UnicodeString : public Replaceable
00173 {
00174 public:
00175
00176
00177
00178
00179
00180
00181
00189 inline UBool operator== (const UnicodeString& text) const;
00190
00198 inline UBool operator!= (const UnicodeString& text) const;
00199
00207 inline UBool operator> (const UnicodeString& text) const;
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
00247 inline int8_t compare(const UnicodeString& text) const;
00248
00263 inline int8_t compare(int32_t start,
00264 int32_t length,
00265 const UnicodeString& srcText) const;
00266
00284 inline int8_t compare(int32_t start,
00285 int32_t length,
00286 const UnicodeString& srcText,
00287 int32_t srcStart,
00288 int32_t srcLength) const;
00289
00302 inline int8_t compare(const UChar *srcChars,
00303 int32_t srcLength) const;
00304
00319 inline int8_t compare(int32_t start,
00320 int32_t length,
00321 const UChar *srcChars) const;
00322
00340 inline int8_t compare(int32_t start,
00341 int32_t length,
00342 const UChar *srcChars,
00343 int32_t srcStart,
00344 int32_t srcLength) const;
00345
00363 inline int8_t compareBetween(int32_t start,
00364 int32_t limit,
00365 const UnicodeString& srcText,
00366 int32_t srcStart,
00367 int32_t srcLimit) const;
00368
00386 inline int8_t compareCodePointOrder(const UnicodeString& text) const;
00387
00407 inline int8_t compareCodePointOrder(int32_t start,
00408 int32_t length,
00409 const UnicodeString& srcText) const;
00410
00432 inline int8_t compareCodePointOrder(int32_t start,
00433 int32_t length,
00434 const UnicodeString& srcText,
00435 int32_t srcStart,
00436 int32_t srcLength) const;
00437
00456 inline int8_t compareCodePointOrder(const UChar *srcChars,
00457 int32_t srcLength) const;
00458
00478 inline int8_t compareCodePointOrder(int32_t start,
00479 int32_t length,
00480 const UChar *srcChars) const;
00481
00503 inline int8_t compareCodePointOrder(int32_t start,
00504 int32_t length,
00505 const UChar *srcChars,
00506 int32_t srcStart,
00507 int32_t srcLength) const;
00508
00530 inline int8_t compareCodePointOrderBetween(int32_t start,
00531 int32_t limit,
00532 const UnicodeString& srcText,
00533 int32_t srcStart,
00534 int32_t srcLimit) const;
00535
00554 inline int8_t caseCompare(const UnicodeString& text, uint32_t options) const;
00555
00576 inline int8_t caseCompare(int32_t start,
00577 int32_t length,
00578 const UnicodeString& srcText,
00579 uint32_t options) const;
00580
00603 inline int8_t caseCompare(int32_t start,
00604 int32_t length,
00605 const UnicodeString& srcText,
00606 int32_t srcStart,
00607 int32_t srcLength,
00608 uint32_t options) const;
00609
00629 inline int8_t caseCompare(const UChar *srcChars,
00630 int32_t srcLength,
00631 uint32_t options) const;
00632
00653 inline int8_t caseCompare(int32_t start,
00654 int32_t length,
00655 const UChar *srcChars,
00656 uint32_t options) const;
00657
00680 inline int8_t caseCompare(int32_t start,
00681 int32_t length,
00682 const UChar *srcChars,
00683 int32_t srcStart,
00684 int32_t srcLength,
00685 uint32_t options) const;
00686
00709 inline int8_t caseCompareBetween(int32_t start,
00710 int32_t limit,
00711 const UnicodeString& srcText,
00712 int32_t srcStart,
00713 int32_t srcLimit,
00714 uint32_t options) const;
00715
00723 inline UBool startsWith(const UnicodeString& text) const;
00724
00735 inline UBool startsWith(const UnicodeString& srcText,
00736 int32_t srcStart,
00737 int32_t srcLength) const;
00738
00747 inline UBool startsWith(const UChar *srcChars,
00748 int32_t srcLength) const;
00749
00759 inline UBool startsWith(const UChar *srcChars,
00760 int32_t srcStart,
00761 int32_t srcLength) const;
00762
00770 inline UBool endsWith(const UnicodeString& text) const;
00771
00782 inline UBool endsWith(const UnicodeString& srcText,
00783 int32_t srcStart,
00784 int32_t srcLength) const;
00785
00794 inline UBool endsWith(const UChar *srcChars,
00795 int32_t srcLength) const;
00796
00807 inline UBool endsWith(const UChar *srcChars,
00808 int32_t srcStart,
00809 int32_t srcLength) const;
00810
00811
00812
00813
00822 inline int32_t indexOf(const UnicodeString& text) const;
00823
00833 inline int32_t indexOf(const UnicodeString& text,
00834 int32_t start) const;
00835
00847 inline int32_t indexOf(const UnicodeString& text,
00848 int32_t start,
00849 int32_t length) const;
00850
00867 inline int32_t indexOf(const UnicodeString& srcText,
00868 int32_t srcStart,
00869 int32_t srcLength,
00870 int32_t start,
00871 int32_t length) const;
00872
00884 inline int32_t indexOf(const UChar *srcChars,
00885 int32_t srcLength,
00886 int32_t start) const;
00887
00900 inline int32_t indexOf(const UChar *srcChars,
00901 int32_t srcLength,
00902 int32_t start,
00903 int32_t length) const;
00904
00921 int32_t indexOf(const UChar *srcChars,
00922 int32_t srcStart,
00923 int32_t srcLength,
00924 int32_t start,
00925 int32_t length) const;
00926
00934 inline int32_t indexOf(UChar c) const;
00935
00944 inline int32_t indexOf(UChar32 c) const;
00945
00954 inline int32_t indexOf(UChar c,
00955 int32_t start) const;
00956
00966 inline int32_t indexOf(UChar32 c,
00967 int32_t start) const;
00968
00979 inline int32_t indexOf(UChar c,
00980 int32_t start,
00981 int32_t length) const;
00982
00994 inline int32_t indexOf(UChar32 c,
00995 int32_t start,
00996 int32_t length) const;
00997
01006 inline int32_t lastIndexOf(const UnicodeString& text) const;
01007
01017 inline int32_t lastIndexOf(const UnicodeString& text,
01018 int32_t start) const;
01019
01031 inline int32_t lastIndexOf(const UnicodeString& text,
01032 int32_t start,
01033 int32_t length) const;
01034
01051 inline int32_t lastIndexOf(const UnicodeString& srcText,
01052 int32_t srcStart,
01053 int32_t srcLength,
01054 int32_t start,
01055 int32_t length) const;
01056
01067 inline int32_t lastIndexOf(const UChar *srcChars,
01068 int32_t srcLength,
01069 int32_t start) const;
01070
01083 inline int32_t lastIndexOf(const UChar *srcChars,
01084 int32_t srcLength,
01085 int32_t start,
01086 int32_t length) const;
01087
01104 int32_t lastIndexOf(const UChar *srcChars,
01105 int32_t srcStart,
01106 int32_t srcLength,
01107 int32_t start,
01108 int32_t length) const;
01109
01117 inline int32_t lastIndexOf(UChar c) const;
01118
01127 inline int32_t lastIndexOf(UChar32 c) const;
01128
01137 inline int32_t lastIndexOf(UChar c,
01138 int32_t start) const;
01139
01149 inline int32_t lastIndexOf(UChar32 c,
01150 int32_t start) const;
01151
01162 inline int32_t lastIndexOf(UChar c,
01163 int32_t start,
01164 int32_t length) const;
01165
01177 inline int32_t lastIndexOf(UChar32 c,
01178 int32_t start,
01179 int32_t length) const;
01180
01181
01182
01183
01192 inline UChar charAt(int32_t offset) const;
01193
01201 inline UChar operator[] (int32_t offset) const;
01202
01214 inline UChar32 char32At(int32_t offset) const;
01215
01231 inline int32_t getChar32Start(int32_t offset) const;
01232
01249 inline int32_t getChar32Limit(int32_t offset) const;
01250
01301 int32_t moveIndex32(int32_t index, int32_t delta) const;
01302
01303
01304
01320 inline void extract(int32_t start,
01321 int32_t length,
01322 UChar *dst,
01323 int32_t dstStart = 0) const;
01324
01346 int32_t
01347 extract(UChar *dest, int32_t destCapacity,
01348 UErrorCode &errorCode) const;
01349
01360 inline void extract(int32_t start,
01361 int32_t length,
01362 UnicodeString& target) const;
01363
01375 inline void extractBetween(int32_t start,
01376 int32_t limit,
01377 UChar *dst,
01378 int32_t dstStart = 0) const;
01379
01389 virtual void extractBetween(int32_t start,
01390 int32_t limit,
01391 UnicodeString& target) const;
01392
01413 inline int32_t extract(int32_t start,
01414 int32_t startLength,
01415 char *target,
01416 const char *codepage = 0) const;
01417
01442 int32_t extract(int32_t start,
01443 int32_t startLength,
01444 char *target,
01445 uint32_t targetLength,
01446 const char *codepage = 0) const;
01447
01465 int32_t extract(char *dest, int32_t destCapacity,
01466 UConverter *cnv,
01467 UErrorCode &errorCode) const;
01468
01469
01470
01477 inline int32_t length(void) const;
01478
01491 int32_t
01492 countChar32(int32_t start=0, int32_t length=INT32_MAX) const;
01493
01517 UBool
01518 hasMoreChar32Than(int32_t start, int32_t length, int32_t number) const;
01519
01525 inline UBool isEmpty(void) const;
01526
01536 inline int32_t getCapacity(void) const;
01537
01538
01539
01545 inline int32_t hashCode(void) const;
01546
01558 inline UBool isBogus(void) const;
01559
01560
01561
01562
01563
01564
01565
01566
01574 UnicodeString &operator=(const UnicodeString &srcText);
01575
01596 UnicodeString &fastCopyFrom(const UnicodeString &src);
01597
01605 inline UnicodeString& operator= (UChar ch);
01606
01614 inline UnicodeString& operator= (UChar32 ch);
01615
01627 inline UnicodeString& setTo(const UnicodeString& srcText,
01628 int32_t srcStart);
01629
01643 inline UnicodeString& setTo(const UnicodeString& srcText,
01644 int32_t srcStart,
01645 int32_t srcLength);
01646
01655 inline UnicodeString& setTo(const UnicodeString& srcText);
01656
01665 inline UnicodeString& setTo(const UChar *srcChars,
01666 int32_t srcLength);
01667
01676 UnicodeString& setTo(UChar srcChar);
01677
01686 UnicodeString& setTo(UChar32 srcChar);
01687
01708 UnicodeString &setTo(UBool isTerminated,
01709 const UChar *text,
01710 int32_t textLength);
01711
01731 UnicodeString &setTo(UChar *buffer,
01732 int32_t buffLength,
01733 int32_t buffCapacity);
01734
01775 void setToBogus();
01776
01784 UnicodeString& setCharAt(int32_t offset,
01785 UChar ch);
01786
01787
01788
01789
01797 inline UnicodeString& operator+= (UChar ch);
01798
01806 inline UnicodeString& operator+= (UChar32 ch);
01807
01816 inline UnicodeString& operator+= (const UnicodeString& srcText);
01817
01832 inline UnicodeString& append(const UnicodeString& srcText,
01833 int32_t srcStart,
01834 int32_t srcLength);
01835
01843 inline UnicodeString& append(const UnicodeString& srcText);
01844
01858 inline UnicodeString& append(const UChar *srcChars,
01859 int32_t srcStart,
01860 int32_t srcLength);
01861
01870 inline UnicodeString& append(const UChar *srcChars,
01871 int32_t srcLength);
01872
01879 inline UnicodeString& append(UChar srcChar);
01880
01887 inline UnicodeString& append(UChar32 srcChar);
01888
01889
01890
01891
01905 inline UnicodeString& insert(int32_t start,
01906 const UnicodeString& srcText,
01907 int32_t srcStart,
01908 int32_t srcLength);
01909
01918 inline UnicodeString& insert(int32_t start,
01919 const UnicodeString& srcText);
01920
01934 inline UnicodeString& insert(int32_t start,
01935 const UChar *srcChars,
01936 int32_t srcStart,
01937 int32_t srcLength);
01938
01948 inline UnicodeString& insert(int32_t start,
01949 const UChar *srcChars,
01950 int32_t srcLength);
01951
01960 inline UnicodeString& insert(int32_t start,
01961 UChar srcChar);
01962
01971 inline UnicodeString& insert(int32_t start,
01972 UChar32 srcChar);
01973
01974
01975
01976
01994 UnicodeString& replace(int32_t start,
01995 int32_t length,
01996 const UnicodeString& srcText,
01997 int32_t srcStart,
01998 int32_t srcLength);
01999
02012 UnicodeString& replace(int32_t start,
02013 int32_t length,
02014 const UnicodeString& srcText);
02015
02033 UnicodeString& replace(int32_t start,
02034 int32_t length,
02035 const UChar *srcChars,
02036 int32_t srcStart,
02037 int32_t srcLength);
02038
02051 inline UnicodeString& replace(int32_t start,
02052 int32_t length,
02053 const UChar *srcChars,
02054 int32_t srcLength);
02055
02067 inline UnicodeString& replace(int32_t start,
02068 int32_t length,
02069 UChar srcChar);
02070
02082 inline UnicodeString& replace(int32_t start,
02083 int32_t length,
02084 UChar32 srcChar);
02085
02095 inline UnicodeString& replaceBetween(int32_t start,
02096 int32_t limit,
02097 const UnicodeString& srcText);
02098
02113 inline UnicodeString& replaceBetween(int32_t start,
02114 int32_t limit,
02115 const UnicodeString& srcText,
02116 int32_t srcStart,
02117 int32_t srcLimit);
02118
02129 virtual void handleReplaceBetween(int32_t start,
02130 int32_t limit,
02131 const UnicodeString& text);
02132
02138 virtual UBool hasMetaData() const;
02139
02155 virtual void copy(int32_t start, int32_t limit, int32_t dest);
02156
02157
02158
02167 inline UnicodeString& findAndReplace(const UnicodeString& oldText,
02168 const UnicodeString& newText);
02169
02181 inline UnicodeString& findAndReplace(int32_t start,
02182 int32_t length,
02183 const UnicodeString& oldText,
02184 const UnicodeString& newText);
02185
02203 UnicodeString& findAndReplace(int32_t start,
02204 int32_t length,
02205 const UnicodeString& oldText,
02206 int32_t oldStart,
02207 int32_t oldLength,
02208 const UnicodeString& newText,
02209 int32_t newStart,
02210 int32_t newLength);
02211
02212
02213
02214
02220 inline UnicodeString& remove(void);
02221
02230 inline UnicodeString& remove(int32_t start,
02231 int32_t length = (int32_t)INT32_MAX);
02232
02241 inline UnicodeString& removeBetween(int32_t start,
02242 int32_t limit = (int32_t)INT32_MAX);
02243
02244
02245
02246
02258 UBool padLeading(int32_t targetLength,
02259 UChar padChar = 0x0020);
02260
02272 UBool padTrailing(int32_t targetLength,
02273 UChar padChar = 0x0020);
02274
02281 inline UBool truncate(int32_t targetLength);
02282
02288 UnicodeString& trim(void);
02289
02290
02291
02292
02298 inline UnicodeString& reverse(void);
02299
02308 inline UnicodeString& reverse(int32_t start,
02309 int32_t length);
02310
02317 UnicodeString& toUpper(void);
02318
02326 UnicodeString& toUpper(const Locale& locale);
02327
02334 UnicodeString& toLower(void);
02335
02343 UnicodeString& toLower(const Locale& locale);
02344
02345 #if !UCONFIG_NO_BREAK_ITERATION
02346
02372 UnicodeString &toTitle(BreakIterator *titleIter);
02373
02400 UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale);
02401
02402 #endif
02403
02415 UnicodeString &foldCase(uint32_t options=0 );
02416
02417
02418
02419
02420
02464 UChar *getBuffer(int32_t minCapacity);
02465
02486 void releaseBuffer(int32_t newLength=-1);
02487
02518 inline const UChar *getBuffer() const;
02519
02553 inline const UChar *getTerminatedBuffer();
02554
02555
02556
02557
02558
02562 UnicodeString();
02563
02575 UnicodeString(int32_t capacity, UChar32 c, int32_t count);
02576
02582 UnicodeString(UChar ch);
02583
02589 UnicodeString(UChar32 ch);
02590
02597 UnicodeString(const UChar *text);
02598
02606 UnicodeString(const UChar *text,
02607 int32_t textLength);
02608
02628 UnicodeString(UBool isTerminated,
02629 const UChar *text,
02630 int32_t textLength);
02631
02650 UnicodeString(UChar *buffer, int32_t buffLength, int32_t buffCapacity);
02651
02663 UnicodeString(const char *codepageData,
02664 const char *codepage = 0);
02665
02678 UnicodeString(const char *codepageData,
02679 int32_t dataLength,
02680 const char *codepage = 0);
02681
02703 UnicodeString(
02704 const char *src, int32_t srcLength,
02705 UConverter *cnv,
02706 UErrorCode &errorCode);
02707
02708
02714 UnicodeString(const UnicodeString& that);
02715
02722 UnicodeString(const UnicodeString& src, int32_t srcStart);
02723
02731 UnicodeString(const UnicodeString& src, int32_t srcStart, int32_t srcLength);
02732
02749 virtual Replaceable *clone() const;
02750
02754 ~UnicodeString();
02755
02756
02757
02758
02793 UnicodeString unescape() const;
02794
02814 UChar32 unescapeAt(int32_t &offset) const;
02815
02821 virtual inline UClassID getDynamicClassID() const;
02822
02828 static inline UClassID getStaticClassID();
02829
02830
02831
02832
02833
02834 protected:
02839 virtual int32_t getLength() const;
02840
02846 virtual UChar getCharAt(int32_t offset) const;
02847
02853 virtual UChar32 getChar32At(int32_t offset) const;
02854
02855 private:
02856
02857 inline int8_t
02858 doCompare(int32_t start,
02859 int32_t length,
02860 const UnicodeString& srcText,
02861 int32_t srcStart,
02862 int32_t srcLength) const;
02863
02864 int8_t doCompare(int32_t start,
02865 int32_t length,
02866 const UChar *srcChars,
02867 int32_t srcStart,
02868 int32_t srcLength) const;
02869
02870 inline int8_t
02871 doCompareCodePointOrder(int32_t start,
02872 int32_t length,
02873 const UnicodeString& srcText,
02874 int32_t srcStart,
02875 int32_t srcLength) const;
02876
02877 int8_t doCompareCodePointOrder(int32_t start,
02878 int32_t length,
02879 const UChar *srcChars,
02880 int32_t srcStart,
02881 int32_t srcLength) const;
02882
02883 inline int8_t
02884 doCaseCompare(int32_t start,
02885 int32_t length,
02886 const UnicodeString &srcText,
02887 int32_t srcStart,
02888 int32_t srcLength,
02889 uint32_t options) const;
02890
02891 int8_t
02892 doCaseCompare(int32_t start,
02893 int32_t length,
02894 const UChar *srcChars,
02895 int32_t srcStart,
02896 int32_t srcLength,
02897 uint32_t options) const;
02898
02899 int32_t doIndexOf(UChar c,
02900 int32_t start,
02901 int32_t length) const;
02902
02903 int32_t doIndexOf(UChar32 c,
02904 int32_t start,
02905 int32_t length) const;
02906
02907 int32_t doLastIndexOf(UChar c,
02908 int32_t start,
02909 int32_t length) const;
02910
02911 int32_t doLastIndexOf(UChar32 c,
02912 int32_t start,
02913 int32_t length) const;
02914
02915 void doExtract(int32_t start,
02916 int32_t length,
02917 UChar *dst,
02918 int32_t dstStart) const;
02919
02920 inline void doExtract(int32_t start,
02921 int32_t length,
02922 UnicodeString& target) const;
02923
02924 inline UChar doCharAt(int32_t offset) const;
02925
02926 UnicodeString& doReplace(int32_t start,
02927 int32_t length,
02928 const UnicodeString& srcText,
02929 int32_t srcStart,
02930 int32_t srcLength);
02931
02932 UnicodeString& doReplace(int32_t start,
02933 int32_t length,
02934 const UChar *srcChars,
02935 int32_t srcStart,
02936 int32_t srcLength);
02937
02938 UnicodeString& doReverse(int32_t start,
02939 int32_t length);
02940
02941
02942 int32_t doHashCode(void) const;
02943
02944
02945 inline UChar* getArrayStart(void);
02946 inline const UChar* getArrayStart(void) const;
02947
02948
02949
02950
02951
02952 UBool allocate(int32_t capacity);
02953
02954
02955 void releaseArray(void);
02956
02957
02958 void unBogus();
02959
02960
02961 UnicodeString ©From(const UnicodeString &src, UBool fastCopy=FALSE);
02962
02963
02964 inline void pinIndex(int32_t& start) const;
02965 inline void pinIndices(int32_t& start,
02966 int32_t& length) const;
02967
02968
02969 int32_t doExtract(int32_t start, int32_t length,
02970 char *dest, int32_t destCapacity,
02971 UConverter *cnv,
02972 UErrorCode &errorCode) const;
02973
02974
02975
02976
02977
02978
02979
02980
02981
02982
02983
02984 void doCodepageCreate(const char *codepageData,
02985 int32_t dataLength,
02986 const char *codepage);
02987
02988
02989
02990
02991
02992 void
02993 doCodepageCreate(const char *codepageData,
02994 int32_t dataLength,
02995 UConverter *converter,
02996 UErrorCode &status);
02997
02998
02999
03000
03001
03002
03003
03004
03005
03006
03007
03008 UBool cloneArrayIfNeeded(int32_t newCapacity = -1,
03009 int32_t growCapacity = -1,
03010 UBool doCopyArray = TRUE,
03011 int32_t **pBufferToDelete = 0,
03012 UBool forceClone = FALSE);
03013
03014
03015 UnicodeString &
03016 caseMap(BreakIterator *titleIter,
03017 const Locale& locale,
03018 uint32_t options,
03019 int32_t toWhichCase);
03020
03021
03022 void addRef(void);
03023 int32_t removeRef(void);
03024 int32_t refCount(void) const;
03025
03026
03027 enum {
03028 US_STACKBUF_SIZE=7,
03029 kInvalidUChar=0xffff,
03030 kGrowSize=128,
03031 kInvalidHashCode=0,
03032 kEmptyHashCode=1,
03033
03034
03035 kIsBogus=1,
03036 kUsingStackBuffer=2,
03037 kRefCounted=4,
03038 kBufferIsReadonly=8,
03039 kOpenGetBuffer=16,
03040
03041
03042
03043 kShortString=kUsingStackBuffer,
03044 kLongString=kRefCounted,
03045 kReadonlyAlias=kBufferIsReadonly,
03046 kWritableAlias=0
03047 };
03048
03049 friend class StringCharacterIterator;
03050 friend class StringThreadTest;
03051
03052
03053
03054
03055
03056
03057
03058
03059
03060
03061
03062
03063
03064 int32_t fLength;
03065 int32_t fCapacity;
03066 UChar *fArray;
03067 uint16_t fFlags;
03068 UChar fStackBuffer [ US_STACKBUF_SIZE ];
03069
03074 static const char fgClassID;
03075 };
03076
03077 U_NAMESPACE_END
03078
03079
03080
03081
03086 inline void
03087 uprv_arrayCopy(const U_NAMESPACE_QUALIFIER UnicodeString *src, U_NAMESPACE_QUALIFIER UnicodeString *dst, int32_t count)
03088 { while(count-- > 0) *dst++ = *src++; }
03089
03094 inline void
03095 uprv_arrayCopy(const U_NAMESPACE_QUALIFIER UnicodeString *src, int32_t srcStart,
03096 U_NAMESPACE_QUALIFIER UnicodeString *dst, int32_t dstStart, int32_t count)
03097 { uprv_arrayCopy(src+srcStart, dst+dstStart, count); }
03098
03099 U_NAMESPACE_BEGIN
03100
03101
03102
03103
03104
03105
03106
03107
03108
03109 inline void
03110 UnicodeString::pinIndex(int32_t& start) const
03111 {
03112
03113 if(start < 0) {
03114 start = 0;
03115 } else if(start > fLength) {
03116 start = fLength;
03117 }
03118 }
03119
03120 inline void
03121 UnicodeString::pinIndices(int32_t& start,
03122 int32_t& _length) const
03123 {
03124
03125 if(start < 0) {
03126 start = 0;
03127 } else if(start > fLength) {
03128 start = fLength;
03129 }
03130 if(_length < 0) {
03131 _length = 0;
03132 } else if(_length > (fLength - start)) {
03133 _length = (fLength - start);
03134 }
03135 }
03136
03137 inline UChar*
03138 UnicodeString::getArrayStart()
03139 { return fArray; }
03140
03141 inline const UChar*
03142 UnicodeString::getArrayStart() const
03143 { return fArray; }
03144
03145
03146
03147
03148 inline UClassID
03149 UnicodeString::getStaticClassID()
03150 { return (UClassID)&fgClassID; }
03151
03152 inline UClassID
03153 UnicodeString::getDynamicClassID() const
03154 { return UnicodeString::getStaticClassID(); }
03155
03156 inline int32_t
03157 UnicodeString::length() const
03158 { return fLength; }
03159
03160 inline int32_t
03161 UnicodeString::getCapacity() const
03162 { return fCapacity; }
03163
03164 inline int32_t
03165 UnicodeString::hashCode() const
03166 { return doHashCode(); }
03167
03168 inline UBool
03169 UnicodeString::isBogus() const
03170 { return (UBool)(fFlags & kIsBogus); }
03171
03172 inline const UChar *
03173 UnicodeString::getBuffer() const {
03174 if(!(fFlags&(kIsBogus|kOpenGetBuffer))) {
03175 return fArray;
03176 } else {
03177 return 0;
03178 }
03179 }
03180
03181
03182
03183
03184 inline int8_t
03185 UnicodeString::doCompare(int32_t start,
03186 int32_t length,
03187 const UnicodeString& srcText,
03188 int32_t srcStart,
03189 int32_t srcLength) const
03190 {
03191 if(srcText.isBogus()) {
03192 return (int8_t)!isBogus();
03193 } else {
03194 srcText.pinIndices(srcStart, srcLength);
03195 return doCompare(start, length, srcText.fArray, srcStart, srcLength);
03196 }
03197 }
03198
03199 inline UBool
03200 UnicodeString::operator== (const UnicodeString& text) const
03201 {
03202 if(isBogus()) {
03203 return text.isBogus();
03204 } else {
03205 return
03206 !text.isBogus() &&
03207 fLength == text.fLength &&
03208 doCompare(0, fLength, text, 0, text.fLength) == 0;
03209 }
03210 }
03211
03212 inline UBool
03213 UnicodeString::operator!= (const UnicodeString& text) const
03214 { return (! operator==(text)); }
03215
03216 inline UBool
03217 UnicodeString::operator> (const UnicodeString& text) const
03218 { return doCompare(0, fLength, text, 0, text.fLength) == 1; }
03219
03220 inline UBool
03221 UnicodeString::operator< (const UnicodeString& text) const
03222 { return doCompare(0, fLength, text, 0, text.fLength) == -1; }
03223
03224 inline UBool
03225 UnicodeString::operator>= (const UnicodeString& text) const
03226 { return doCompare(0, fLength, text, 0, text.fLength) != -1; }
03227
03228 inline UBool
03229 UnicodeString::operator<= (const UnicodeString& text) const
03230 { return doCompare(0, fLength, text, 0, text.fLength) != 1; }
03231
03232 inline int8_t
03233 UnicodeString::compare(const UnicodeString& text) const
03234 { return doCompare(0, fLength, text, 0, text.fLength); }
03235
03236 inline int8_t
03237 UnicodeString::compare(int32_t start,
03238 int32_t _length,
03239 const UnicodeString& srcText) const
03240 { return doCompare(start, _length, srcText, 0, srcText.fLength); }
03241
03242 inline int8_t
03243 UnicodeString::compare(const UChar *srcChars,
03244 int32_t srcLength) const
03245 { return doCompare(0, fLength, srcChars, 0, srcLength); }
03246
03247 inline int8_t
03248 UnicodeString::compare(int32_t start,
03249 int32_t _length,
03250 const UnicodeString& srcText,
03251 int32_t srcStart,
03252 int32_t srcLength) const
03253 { return doCompare(start, _length, srcText, srcStart, srcLength); }
03254
03255 inline int8_t
03256 UnicodeString::compare(int32_t start,
03257 int32_t _length,
03258 const UChar *srcChars) const
03259 { return doCompare(start, _length, srcChars, 0, _length); }
03260
03261 inline int8_t
03262 UnicodeString::compare(int32_t start,
03263 int32_t _length,
03264 const UChar *srcChars,
03265 int32_t srcStart,
03266 int32_t srcLength) const
03267 { return doCompare(start, _length, srcChars, srcStart, srcLength); }
03268
03269 inline int8_t
03270 UnicodeString::compareBetween(int32_t start,
03271 int32_t limit,
03272 const UnicodeString& srcText,
03273 int32_t srcStart,
03274 int32_t srcLimit) const
03275 { return doCompare(start, limit - start,
03276 srcText, srcStart, srcLimit - srcStart); }
03277
03278 inline int8_t
03279 UnicodeString::doCompareCodePointOrder(int32_t start,
03280 int32_t length,
03281 const UnicodeString& srcText,
03282 int32_t srcStart,
03283 int32_t srcLength) const
03284 {
03285 if(srcText.isBogus()) {
03286 return (int8_t)!isBogus();
03287 } else {
03288 srcText.pinIndices(srcStart, srcLength);
03289 return doCompareCodePointOrder(start, length, srcText.fArray, srcStart, srcLength);
03290 }
03291 }
03292
03293 inline int8_t
03294 UnicodeString::compareCodePointOrder(const UnicodeString& text) const
03295 { return doCompareCodePointOrder(0, fLength, text, 0, text.fLength); }
03296
03297 inline int8_t
03298 UnicodeString::compareCodePointOrder(int32_t start,
03299 int32_t _length,
03300 const UnicodeString& srcText) const
03301 { return doCompareCodePointOrder(start, _length, srcText, 0, srcText.fLength); }
03302
03303 inline int8_t
03304 UnicodeString::compareCodePointOrder(const UChar *srcChars,
03305 int32_t srcLength) const
03306 { return doCompareCodePointOrder(0, fLength, srcChars, 0, srcLength); }
03307
03308 inline int8_t
03309 UnicodeString::compareCodePointOrder(int32_t start,
03310 int32_t _length,
03311 const UnicodeString& srcText,
03312 int32_t srcStart,
03313 int32_t srcLength) const
03314 { return doCompareCodePointOrder(start, _length, srcText, srcStart, srcLength); }
03315
03316 inline int8_t
03317 UnicodeString::compareCodePointOrder(int32_t start,
03318 int32_t _length,
03319 const UChar *srcChars) const
03320 { return doCompareCodePointOrder(start, _length, srcChars, 0, _length); }
03321
03322 inline int8_t
03323 UnicodeString::compareCodePointOrder(int32_t start,
03324 int32_t _length,
03325 const UChar *srcChars,
03326 int32_t srcStart,
03327 int32_t srcLength) const
03328 { return doCompareCodePointOrder(start, _length, srcChars, srcStart, srcLength); }
03329
03330 inline int8_t
03331 UnicodeString::compareCodePointOrderBetween(int32_t start,
03332 int32_t limit,
03333 const UnicodeString& srcText,
03334 int32_t srcStart,
03335 int32_t srcLimit) const
03336 { return doCompareCodePointOrder(start, limit - start,
03337 srcText, srcStart, srcLimit - srcStart); }
03338
03339 inline int8_t
03340 UnicodeString::doCaseCompare(int32_t start,
03341 int32_t length,
03342 const UnicodeString &srcText,
03343 int32_t srcStart,
03344 int32_t srcLength,
03345 uint32_t options) const
03346 {
03347 if(srcText.isBogus()) {
03348 return (int8_t)!isBogus();
03349 } else {
03350 srcText.pinIndices(srcStart, srcLength);
03351 return doCaseCompare(start, length, srcText.fArray, srcStart, srcLength, options);
03352 }
03353 }
03354
03355 inline int8_t
03356 UnicodeString::caseCompare(const UnicodeString &text, uint32_t options) const {
03357 return doCaseCompare(0, fLength, text, 0, text.fLength, options);
03358 }
03359
03360 inline int8_t
03361 UnicodeString::caseCompare(int32_t start,
03362 int32_t _length,
03363 const UnicodeString &srcText,
03364 uint32_t options) const {
03365 return doCaseCompare(start, _length, srcText, 0, srcText.fLength, options);
03366 }
03367
03368 inline int8_t
03369 UnicodeString::caseCompare(const UChar *srcChars,
03370 int32_t srcLength,
03371 uint32_t options) const {
03372 return doCaseCompare(0, fLength, srcChars, 0, srcLength, options);
03373 }
03374
03375 inline int8_t
03376 UnicodeString::caseCompare(int32_t start,
03377 int32_t _length,
03378 const UnicodeString &srcText,
03379 int32_t srcStart,
03380 int32_t srcLength,
03381 uint32_t options) const {
03382 return doCaseCompare(start, _length, srcText, srcStart, srcLength, options);
03383 }
03384
03385 inline int8_t
03386 UnicodeString::caseCompare(int32_t start,
03387 int32_t _length,
03388 const UChar *srcChars,
03389 uint32_t options) const {
03390 return doCaseCompare(start, _length, srcChars, 0, _length, options);
03391 }
03392
03393 inline int8_t
03394 UnicodeString::caseCompare(int32_t start,
03395 int32_t _length,
03396 const UChar *srcChars,
03397 int32_t srcStart,
03398 int32_t srcLength,
03399 uint32_t options) const {
03400 return doCaseCompare(start, _length, srcChars, srcStart, srcLength, options);
03401 }
03402
03403 inline int8_t
03404 UnicodeString::caseCompareBetween(int32_t start,
03405 int32_t limit,
03406 const UnicodeString &srcText,
03407 int32_t srcStart,
03408 int32_t srcLimit,
03409 uint32_t options) const {
03410 return doCaseCompare(start, limit - start, srcText, srcStart, srcLimit - srcStart, options);
03411 }
03412
03413 inline int32_t
03414 UnicodeString::indexOf(const UnicodeString& srcText,
03415 int32_t srcStart,
03416 int32_t srcLength,
03417 int32_t start,
03418 int32_t _length) const
03419 {
03420 if(!srcText.isBogus()) {
03421 srcText.pinIndices(srcStart, srcLength);
03422 if(srcLength > 0) {
03423 return indexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
03424 }
03425 }
03426 return -1;
03427 }
03428
03429 inline int32_t
03430 UnicodeString::indexOf(const UnicodeString& text) const
03431 { return indexOf(text, 0, text.fLength, 0, fLength); }
03432
03433 inline int32_t
03434 UnicodeString::indexOf(const UnicodeString& text,
03435 int32_t start) const {
03436 pinIndex(start);
03437 return indexOf(text, 0, text.fLength, start, fLength - start);
03438 }
03439
03440 inline int32_t
03441 UnicodeString::indexOf(const UnicodeString& text,
03442 int32_t start,
03443 int32_t _length) const
03444 { return indexOf(text, 0, text.fLength, start, _length); }
03445
03446 inline int32_t
03447 UnicodeString::indexOf(const UChar *srcChars,
03448 int32_t srcLength,
03449 int32_t start) const {
03450 pinIndex(start);
03451 return indexOf(srcChars, 0, srcLength, start, fLength - start);
03452 }
03453
03454 inline int32_t
03455 UnicodeString::indexOf(const UChar *srcChars,
03456 int32_t srcLength,
03457 int32_t start,
03458 int32_t _length) const
03459 { return indexOf(srcChars, 0, srcLength, start, _length); }
03460
03461 inline int32_t
03462 UnicodeString::indexOf(UChar c,
03463 int32_t start,
03464 int32_t _length) const
03465 { return doIndexOf(c, start, _length); }
03466
03467 inline int32_t
03468 UnicodeString::indexOf(UChar32 c,
03469 int32_t start,
03470 int32_t _length) const
03471 { return doIndexOf(c, start, _length); }
03472
03473 inline int32_t
03474 UnicodeString::indexOf(UChar c) const
03475 { return doIndexOf(c, 0, fLength); }
03476
03477 inline int32_t
03478 UnicodeString::indexOf(UChar32 c) const
03479 { return indexOf(c, 0, fLength); }
03480
03481 inline int32_t
03482 UnicodeString::indexOf(UChar c,
03483 int32_t start) const {
03484 pinIndex(start);
03485 return doIndexOf(c, start, fLength - start);
03486 }
03487
03488 inline int32_t
03489 UnicodeString::indexOf(UChar32 c,
03490 int32_t start) const {
03491 pinIndex(start);
03492 return indexOf(c, start, fLength - start);
03493 }
03494
03495 inline int32_t
03496 UnicodeString::lastIndexOf(const UChar *srcChars,
03497 int32_t srcLength,
03498 int32_t start,
03499 int32_t _length) const
03500 { return lastIndexOf(srcChars, 0, srcLength, start, _length); }
03501
03502 inline int32_t
03503 UnicodeString::lastIndexOf(const UChar *srcChars,
03504 int32_t srcLength,
03505 int32_t start) const {
03506 pinIndex(start);
03507 return lastIndexOf(srcChars, 0, srcLength, start, fLength - start);
03508 }
03509
03510 inline int32_t
03511 UnicodeString::lastIndexOf(const UnicodeString& srcText,
03512 int32_t srcStart,
03513 int32_t srcLength,
03514 int32_t start,
03515 int32_t _length) const
03516 {
03517 if(!srcText.isBogus()) {
03518 srcText.pinIndices(srcStart, srcLength);
03519 if(srcLength > 0) {
03520 return lastIndexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
03521 }
03522 }
03523 return -1;
03524 }
03525
03526 inline int32_t
03527 UnicodeString::lastIndexOf(const UnicodeString& text,
03528 int32_t start,
03529 int32_t _length) const
03530 { return lastIndexOf(text, 0, text.fLength, start, _length); }
03531
03532 inline int32_t
03533 UnicodeString::lastIndexOf(const UnicodeString& text,
03534 int32_t start) const {
03535 pinIndex(start);
03536 return lastIndexOf(text, 0, text.fLength, start, fLength - start);
03537 }
03538
03539 inline int32_t
03540 UnicodeString::lastIndexOf(const UnicodeString& text) const
03541 { return lastIndexOf(text, 0, text.fLength, 0, fLength); }
03542
03543 inline int32_t
03544 UnicodeString::lastIndexOf(UChar c,
03545 int32_t start,
03546 int32_t _length) const
03547 { return doLastIndexOf(c, start, _length); }
03548
03549 inline int32_t
03550 UnicodeString::lastIndexOf(UChar32 c,
03551 int32_t start,
03552 int32_t _length) const {
03553 return doLastIndexOf(c, start, _length);
03554 }
03555
03556 inline int32_t
03557 UnicodeString::lastIndexOf(UChar c) const
03558 { return doLastIndexOf(c, 0, fLength); }
03559
03560 inline int32_t
03561 UnicodeString::lastIndexOf(UChar32 c) const {
03562 return lastIndexOf(c, 0, fLength);
03563 }
03564
03565 inline int32_t
03566 UnicodeString::lastIndexOf(UChar c,
03567 int32_t start) const {
03568 pinIndex(start);
03569 return doLastIndexOf(c, start, fLength - start);
03570 }
03571
03572 inline int32_t
03573 UnicodeString::lastIndexOf(UChar32 c,
03574 int32_t start) const {
03575 pinIndex(start);
03576 return lastIndexOf(c, start, fLength - start);
03577 }
03578
03579 inline UBool
03580 UnicodeString::startsWith(const UnicodeString& text) const
03581 { return compare(0, text.fLength, text, 0, text.fLength) == 0; }
03582
03583 inline UBool
03584 UnicodeString::startsWith(const UnicodeString& srcText,
03585 int32_t srcStart,
03586 int32_t srcLength) const
03587 { return doCompare(0, srcLength, srcText, srcStart, srcLength) == 0; }
03588
03589 inline UBool
03590 UnicodeString::startsWith(const UChar *srcChars,
03591 int32_t srcLength) const
03592 { return doCompare(0, srcLength, srcChars, 0, srcLength) == 0; }
03593
03594 inline UBool
03595 UnicodeString::startsWith(const UChar *srcChars,
03596 int32_t srcStart,
03597 int32_t srcLength) const
03598 { return doCompare(0, srcLength, srcChars, srcStart, srcLength) == 0;}
03599
03600 inline UBool
03601 UnicodeString::endsWith(const UnicodeString& text) const
03602 { return doCompare(fLength - text.fLength, text.fLength,
03603 text, 0, text.fLength) == 0; }
03604
03605 inline UBool
03606 UnicodeString::endsWith(const UnicodeString& srcText,
03607 int32_t srcStart,
03608 int32_t srcLength) const {
03609 srcText.pinIndices(srcStart, srcLength);
03610 return doCompare(fLength - srcLength, srcLength,
03611 srcText, srcStart, srcLength) == 0;
03612 }
03613
03614 inline UBool
03615 UnicodeString::endsWith(const UChar *srcChars,
03616 int32_t srcLength) const {
03617 if(srcLength < 0) {
03618 srcLength = u_strlen(srcChars);
03619 }
03620 return doCompare(fLength - srcLength, srcLength,
03621 srcChars, 0, srcLength) == 0;
03622 }
03623
03624 inline UBool
03625 UnicodeString::endsWith(const UChar *srcChars,
03626 int32_t srcStart,
03627 int32_t srcLength) const {
03628 if(srcLength < 0) {
03629 srcLength = u_strlen(srcChars + srcStart);
03630 }
03631 return doCompare(fLength - srcLength, srcLength,
03632 srcChars, srcStart, srcLength) == 0;
03633 }
03634
03635
03636
03637
03638 inline UnicodeString&
03639 UnicodeString::replace(int32_t start,
03640 int32_t _length,
03641 const UnicodeString& srcText)
03642 { return doReplace(start, _length, srcText, 0, srcText.fLength); }
03643
03644 inline UnicodeString&
03645 UnicodeString::replace(int32_t start,
03646 int32_t _length,
03647 const UnicodeString& srcText,
03648 int32_t srcStart,
03649 int32_t srcLength)
03650 { return doReplace(start, _length, srcText, srcStart, srcLength); }
03651
03652 inline UnicodeString&
03653 UnicodeString::replace(int32_t start,
03654 int32_t _length,
03655 const UChar *srcChars,
03656 int32_t srcLength)
03657 { return doReplace(start, _length, srcChars, 0, srcLength); }
03658
03659 inline UnicodeString&
03660 UnicodeString::replace(int32_t start,
03661 int32_t _length,
03662 const UChar *srcChars,
03663 int32_t srcStart,
03664 int32_t srcLength)
03665 { return doReplace(start, _length, srcChars, srcStart, srcLength); }
03666
03667 inline UnicodeString&
03668 UnicodeString::replace(int32_t start,
03669 int32_t _length,
03670 UChar srcChar)
03671 { return doReplace(start, _length, &srcChar, 0, 1); }
03672
03673 inline UnicodeString&
03674 UnicodeString::replace(int32_t start,
03675 int32_t _length,
03676 UChar32 srcChar) {
03677 UChar buffer[U16_MAX_LENGTH];
03678 int32_t count = 0;
03679 UBool isError = FALSE;
03680 U16_APPEND(buffer, count, U16_MAX_LENGTH, srcChar, isError);
03681 return doReplace(start, _length, buffer, 0, count);
03682 }
03683
03684 inline UnicodeString&
03685 UnicodeString::replaceBetween(int32_t start,
03686 int32_t limit,
03687 const UnicodeString& srcText)
03688 { return doReplace(start, limit - start, srcText, 0, srcText.fLength); }
03689
03690 inline UnicodeString&
03691 UnicodeString::replaceBetween(int32_t start,
03692 int32_t limit,
03693 const UnicodeString& srcText,
03694 int32_t srcStart,
03695 int32_t srcLimit)
03696 { return doReplace(start, limit - start, srcText, srcStart, srcLimit - srcStart); }
03697
03698 inline UnicodeString&
03699 UnicodeString::findAndReplace(const UnicodeString& oldText,
03700 const UnicodeString& newText)
03701 { return findAndReplace(0, fLength, oldText, 0, oldText.fLength,
03702 newText, 0, newText.fLength); }
03703
03704 inline UnicodeString&
03705 UnicodeString::findAndReplace(int32_t start,
03706 int32_t _length,
03707 const UnicodeString& oldText,
03708 const UnicodeString& newText)
03709 { return findAndReplace(start, _length, oldText, 0, oldText.fLength,
03710 newText, 0, newText.fLength); }
03711
03712
03713
03714
03715 inline void
03716 UnicodeString::doExtract(int32_t start,
03717 int32_t _length,
03718 UnicodeString& target) const
03719 { target.replace(0, target.fLength, *this, start, _length); }
03720
03721 inline void
03722 UnicodeString::extract(int32_t start,
03723 int32_t _length,
03724 UChar *target,
03725 int32_t targetStart) const
03726 { doExtract(start, _length, target, targetStart); }
03727
03728 inline void
03729 UnicodeString::extract(int32_t start,
03730 int32_t _length,
03731 UnicodeString& target) const
03732 { doExtract(start, _length, target); }
03733
03734 inline int32_t
03735 UnicodeString::extract(int32_t start,
03736 int32_t _length,
03737 char *dst,
03738 const char *codepage) const
03739
03740 {
03741
03742 return extract(start, _length, dst, dst!=0 ? 0xffffffff : 0, codepage);
03743 }
03744
03745 inline void
03746 UnicodeString::extractBetween(int32_t start,
03747 int32_t limit,
03748 UChar *dst,
03749 int32_t dstStart) const
03750 { doExtract(start, limit - start, dst, dstStart); }
03751
03752 inline UChar
03753 UnicodeString::doCharAt(int32_t offset) const
03754 {
03755 if((uint32_t)offset < (uint32_t)fLength) {
03756 return fArray[offset];
03757 } else {
03758 return kInvalidUChar;
03759 }
03760 }
03761
03762 inline UChar
03763 UnicodeString::charAt(int32_t offset) const
03764 { return doCharAt(offset); }
03765
03766 inline UChar
03767 UnicodeString::operator[] (int32_t offset) const
03768 { return doCharAt(offset); }
03769
03770 inline UChar32
03771 UnicodeString::char32At(int32_t offset) const
03772 {
03773 if((uint32_t)offset < (uint32_t)fLength) {
03774 UChar32 c;
03775 U16_GET(fArray, 0, offset, fLength, c);
03776 return c;
03777 } else {
03778 return kInvalidUChar;
03779 }
03780 }
03781
03782 inline int32_t
03783 UnicodeString::getChar32Start(int32_t offset) const {
03784 if((uint32_t)offset < (uint32_t)fLength) {
03785 U16_SET_CP_START(fArray, 0, offset);
03786 return offset;
03787 } else {
03788 return 0;
03789 }
03790 }
03791
03792 inline int32_t
03793 UnicodeString::getChar32Limit(int32_t offset) const {
03794 if((uint32_t)offset < (uint32_t)fLength) {
03795 U16_SET_CP_LIMIT(fArray, 0, offset, fLength);
03796 return offset;
03797 } else {
03798 return fLength;
03799 }
03800 }
03801
03802 inline UBool
03803 UnicodeString::isEmpty() const {
03804 return fLength == 0;
03805 }
03806
03807
03808
03809
03810 inline const UChar *
03811 UnicodeString::getTerminatedBuffer() {
03812 if(fFlags&(kIsBogus|kOpenGetBuffer)) {
03813 return 0;
03814 } else if(fLength<fCapacity && fArray[fLength]==0) {
03815 return fArray;
03816 } else if(cloneArrayIfNeeded(fLength+1)) {
03817 fArray[fLength]=0;
03818 return fArray;
03819 } else {
03820 return 0;
03821 }
03822 }
03823
03824 inline UnicodeString&
03825 UnicodeString::operator= (UChar ch)
03826 { return doReplace(0, fLength, &ch, 0, 1); }
03827
03828 inline UnicodeString&
03829 UnicodeString::operator= (UChar32 ch)
03830 { return replace(0, fLength, ch); }
03831
03832 inline UnicodeString&
03833 UnicodeString::setTo(const UnicodeString& srcText,
03834 int32_t srcStart,
03835 int32_t srcLength)
03836 {
03837 unBogus();
03838 return doReplace(0, fLength, srcText, srcStart, srcLength);
03839 }
03840
03841 inline UnicodeString&
03842 UnicodeString::setTo(const UnicodeString& srcText,
03843 int32_t srcStart)
03844 {
03845 unBogus();
03846 srcText.pinIndex(srcStart);
03847 return doReplace(0, fLength, srcText, srcStart, srcText.fLength - srcStart);
03848 }
03849
03850 inline UnicodeString&
03851 UnicodeString::setTo(const UnicodeString& srcText)
03852 {
03853 unBogus();
03854 return doReplace(0, fLength, srcText, 0, srcText.fLength);
03855 }
03856
03857 inline UnicodeString&
03858 UnicodeString::setTo(const UChar *srcChars,
03859 int32_t srcLength)
03860 {
03861 unBogus();
03862 return doReplace(0, fLength, srcChars, 0, srcLength);
03863 }
03864
03865 inline UnicodeString&
03866 UnicodeString::setTo(UChar srcChar)
03867 {
03868 unBogus();
03869 return doReplace(0, fLength, &srcChar, 0, 1);
03870 }
03871
03872 inline UnicodeString&
03873 UnicodeString::setTo(UChar32 srcChar)
03874 {
03875 unBogus();
03876 return replace(0, fLength, srcChar);
03877 }
03878
03879 inline UnicodeString&
03880 UnicodeString::operator+= (UChar ch)
03881 { return doReplace(fLength, 0, &ch, 0, 1); }
03882
03883 inline UnicodeString&
03884 UnicodeString::operator+= (UChar32 ch) {
03885 UChar buffer[U16_MAX_LENGTH];
03886 int32_t _length = 0;
03887 UBool isError = FALSE;
03888 U16_APPEND(buffer, _length, U16_MAX_LENGTH, ch, isError);
03889 return doReplace(fLength, 0, buffer, 0, _length);
03890 }
03891
03892 inline UnicodeString&
03893 UnicodeString::operator+= (const UnicodeString& srcText)
03894 { return doReplace(fLength, 0, srcText, 0, srcText.fLength); }
03895
03896 inline UnicodeString&
03897 UnicodeString::append(const UnicodeString& srcText,
03898 int32_t srcStart,
03899 int32_t srcLength)
03900 { return doReplace(fLength, 0, srcText, srcStart, srcLength); }
03901
03902 inline UnicodeString&
03903 UnicodeString::append(const UnicodeString& srcText)
03904 { return doReplace(fLength, 0, srcText, 0, srcText.fLength); }
03905
03906 inline UnicodeString&
03907 UnicodeString::append(const UChar *srcChars,
03908 int32_t srcStart,
03909 int32_t srcLength)
03910 { return doReplace(fLength, 0, srcChars, srcStart, srcLength); }
03911
03912 inline UnicodeString&
03913 UnicodeString::append(const UChar *srcChars,
03914 int32_t srcLength)
03915 { return doReplace(fLength, 0, srcChars, 0, srcLength); }
03916
03917 inline UnicodeString&
03918 UnicodeString::append(UChar srcChar)
03919 { return doReplace(fLength, 0, &srcChar, 0, 1); }
03920
03921 inline UnicodeString&
03922 UnicodeString::append(UChar32 srcChar) {
03923 UChar buffer[U16_MAX_LENGTH];
03924 int32_t _length = 0;
03925 UBool isError = FALSE;
03926 U16_APPEND(buffer, _length, U16_MAX_LENGTH, srcChar, isError);
03927 return doReplace(fLength, 0, buffer, 0, _length);
03928 }
03929
03930 inline UnicodeString&
03931 UnicodeString::insert(int32_t start,
03932 const UnicodeString& srcText,
03933 int32_t srcStart,
03934 int32_t srcLength)
03935 { return doReplace(start, 0, srcText, srcStart, srcLength); }
03936
03937 inline UnicodeString&
03938 UnicodeString::insert(int32_t start,
03939 const UnicodeString& srcText)
03940 { return doReplace(start, 0, srcText, 0, srcText.fLength); }
03941
03942 inline UnicodeString&
03943 UnicodeString::insert(int32_t start,
03944 const UChar *srcChars,
03945 int32_t srcStart,
03946 int32_t srcLength)
03947 { return doReplace(start, 0, srcChars, srcStart, srcLength); }
03948
03949 inline UnicodeString&
03950 UnicodeString::insert(int32_t start,
03951 const UChar *srcChars,
03952 int32_t srcLength)
03953 { return doReplace(start, 0, srcChars, 0, srcLength); }
03954
03955 inline UnicodeString&
03956 UnicodeString::insert(int32_t start,
03957 UChar srcChar)
03958 { return doReplace(start, 0, &srcChar, 0, 1); }
03959
03960 inline UnicodeString&
03961 UnicodeString::insert(int32_t start,
03962 UChar32 srcChar)
03963 { return replace(start, 0, srcChar); }
03964
03965
03966 inline UnicodeString&
03967 UnicodeString::remove()
03968 {
03969
03970 if(isBogus()) {
03971 unBogus();
03972 } else {
03973 fLength = 0;
03974 }
03975 return *this;
03976 }
03977
03978 inline UnicodeString&
03979 UnicodeString::remove(int32_t start,
03980 int32_t _length)
03981 {
03982 if(start <= 0 && _length == INT32_MAX) {
03983
03984 return remove();
03985 } else {
03986 return doReplace(start, _length, NULL, 0, 0);
03987 }
03988 }
03989
03990 inline UnicodeString&
03991 UnicodeString::removeBetween(int32_t start,
03992 int32_t limit)
03993 { return doReplace(start, limit - start, NULL, 0, 0); }
03994
03995 inline UBool
03996 UnicodeString::truncate(int32_t targetLength)
03997 {
03998 if(isBogus() && targetLength == 0) {
03999
04000 unBogus();
04001 return FALSE;
04002 } else if((uint32_t)targetLength < (uint32_t)fLength) {
04003 fLength = targetLength;
04004 return TRUE;
04005 } else {
04006 return FALSE;
04007 }
04008 }
04009
04010 inline UnicodeString&
04011 UnicodeString::reverse()
04012 { return doReverse(0, fLength); }
04013
04014 inline UnicodeString&
04015 UnicodeString::reverse(int32_t start,
04016 int32_t _length)
04017 { return doReverse(start, _length); }
04018
04019
04020 U_NAMESPACE_END
04021
04022 #endif