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/rep.h"
00025
00026
struct UConverter;
00027
class StringThreadTest;
00028
00029
#ifndef U_COMPARE_CODE_POINT_ORDER
00030
00036
#define U_COMPARE_CODE_POINT_ORDER 0x8000
00037 #endif
00038
00039
#ifndef USTRING_H
00040
00041
U_STABLE int32_t U_EXPORT2
00042
u_strlen(
const UChar *s);
00043
#endif
00044
00045
U_NAMESPACE_BEGIN
00046
00047
class Locale;
00048
class StringCharacterIterator;
00049
class BreakIterator;
00050
00051
00052
00070
#if U_SIZEOF_WCHAR_T==U_SIZEOF_UCHAR && U_CHARSET_FAMILY==U_ASCII_FAMILY
00071
# define UNICODE_STRING(cs, _length) UnicodeString(TRUE, (const UChar *)L ## cs, _length)
00072
#elif U_SIZEOF_UCHAR==1 && U_CHARSET_FAMILY==U_ASCII_FAMILY
00073 # define UNICODE_STRING(cs, _length) UnicodeString(TRUE, (const UChar *)cs, _length)
00074
#else
00075
# define UNICODE_STRING(cs, _length) UnicodeString(cs, _length, "")
00076
#endif
00077
00091
#if U_SIZEOF_WCHAR_T==U_SIZEOF_UCHAR && U_CHARSET_FAMILY==U_ASCII_FAMILY
00092
# define UNICODE_STRING_SIMPLE(cs) UnicodeString(TRUE, (const UChar *)L ## cs, -1)
00093
#elif U_SIZEOF_UCHAR==1 && U_CHARSET_FAMILY==U_ASCII_FAMILY
00094
# define UNICODE_STRING_SIMPLE(cs) UnicodeString(TRUE, (const UChar *)cs, -1)
00095 #else
00096
# define UNICODE_STRING_SIMPLE(cs) UnicodeString(cs, "")
00097
#endif
00098
00169
class U_COMMON_API UnicodeString :
public Replaceable
00170 {
00171
public:
00172
00173
00174
00175
00176
00177
00178
00186
inline UBool operator== (
const UnicodeString& text)
const;
00187
00195
inline UBool operator!= (
const UnicodeString& text)
const;
00196
00204
inline UBool operator> (
const UnicodeString& text)
const;
00205
00213
inline UBool operator< (
const UnicodeString& text)
const;
00214
00222
inline UBool operator>= (
const UnicodeString& text)
const;
00223
00231
inline UBool operator<= (
const UnicodeString& text)
const;
00232
00244
inline int8_t compare(
const UnicodeString& text)
const;
00245
00260
inline int8_t compare(int32_t start,
00261 int32_t
length,
00262
const UnicodeString& text)
const;
00263
00281
inline int8_t compare(int32_t start,
00282 int32_t length,
00283
const UnicodeString& srcText,
00284 int32_t srcStart,
00285 int32_t srcLength)
const;
00286
00299
inline int8_t compare(
const UChar *srcChars,
00300 int32_t srcLength)
const;
00301
00316
inline int8_t compare(int32_t start,
00317 int32_t length,
00318
const UChar *srcChars)
const;
00319
00337
inline int8_t compare(int32_t start,
00338 int32_t length,
00339
const UChar *srcChars,
00340 int32_t srcStart,
00341 int32_t srcLength)
const;
00342
00360
inline int8_t compareBetween(int32_t start,
00361 int32_t limit,
00362
const UnicodeString& srcText,
00363 int32_t srcStart,
00364 int32_t srcLimit)
const;
00365
00383
inline int8_t compareCodePointOrder(
const UnicodeString& text)
const;
00384
00404
inline int8_t compareCodePointOrder(int32_t start,
00405 int32_t length,
00406
const UnicodeString& srcText)
const;
00407
00429
inline int8_t compareCodePointOrder(int32_t start,
00430 int32_t length,
00431
const UnicodeString& srcText,
00432 int32_t srcStart,
00433 int32_t srcLength)
const;
00434
00453
inline int8_t compareCodePointOrder(
const UChar *srcChars,
00454 int32_t srcLength)
const;
00455
00475
inline int8_t compareCodePointOrder(int32_t start,
00476 int32_t length,
00477
const UChar *srcChars)
const;
00478
00500
inline int8_t compareCodePointOrder(int32_t start,
00501 int32_t length,
00502
const UChar *srcChars,
00503 int32_t srcStart,
00504 int32_t srcLength)
const;
00505
00527
inline int8_t compareCodePointOrderBetween(int32_t start,
00528 int32_t limit,
00529
const UnicodeString& srcText,
00530 int32_t srcStart,
00531 int32_t srcLimit)
const;
00532
00551
inline int8_t caseCompare(
const UnicodeString& text,
uint32_t options)
const;
00552
00573
inline int8_t caseCompare(int32_t start,
00574 int32_t length,
00575
const UnicodeString& srcText,
00576 uint32_t options)
const;
00577
00600
inline int8_t caseCompare(int32_t start,
00601 int32_t length,
00602
const UnicodeString& srcText,
00603 int32_t srcStart,
00604 int32_t srcLength,
00605 uint32_t options)
const;
00606
00626
inline int8_t caseCompare(
const UChar *srcChars,
00627 int32_t srcLength,
00628 uint32_t options)
const;
00629
00650
inline int8_t caseCompare(int32_t start,
00651 int32_t length,
00652
const UChar *srcChars,
00653 uint32_t options)
const;
00654
00677
inline int8_t caseCompare(int32_t start,
00678 int32_t length,
00679
const UChar *srcChars,
00680 int32_t srcStart,
00681 int32_t srcLength,
00682 uint32_t options)
const;
00683
00706
inline int8_t caseCompareBetween(int32_t start,
00707 int32_t limit,
00708
const UnicodeString& srcText,
00709 int32_t srcStart,
00710 int32_t srcLimit,
00711 uint32_t options)
const;
00712
00720
inline UBool startsWith(
const UnicodeString& text)
const;
00721
00732
inline UBool startsWith(
const UnicodeString& srcText,
00733 int32_t srcStart,
00734 int32_t srcLength)
const;
00735
00744
inline UBool startsWith(
const UChar *srcChars,
00745 int32_t srcLength)
const;
00746
00756
inline UBool startsWith(
const UChar *srcChars,
00757 int32_t srcStart,
00758 int32_t srcLength)
const;
00759
00767
inline UBool endsWith(
const UnicodeString& text)
const;
00768
00779
inline UBool endsWith(
const UnicodeString& srcText,
00780 int32_t srcStart,
00781 int32_t srcLength)
const;
00782
00791
inline UBool endsWith(
const UChar *srcChars,
00792 int32_t srcLength)
const;
00793
00804
inline UBool endsWith(
const UChar *srcChars,
00805 int32_t srcStart,
00806 int32_t srcLength)
const;
00807
00808
00809
00810
00819
inline int32_t indexOf(
const UnicodeString& text)
const;
00820
00830
inline int32_t indexOf(
const UnicodeString& text,
00831 int32_t start)
const;
00832
00844
inline int32_t indexOf(
const UnicodeString& text,
00845 int32_t start,
00846 int32_t length)
const;
00847
00864
inline int32_t indexOf(
const UnicodeString& srcText,
00865 int32_t srcStart,
00866 int32_t srcLength,
00867 int32_t start,
00868 int32_t length)
const;
00869
00881
inline int32_t indexOf(
const UChar *srcChars,
00882 int32_t srcLength,
00883 int32_t start)
const;
00884
00897
inline int32_t indexOf(
const UChar *srcChars,
00898 int32_t srcLength,
00899 int32_t start,
00900 int32_t length)
const;
00901
00918
int32_t indexOf(
const UChar *srcChars,
00919 int32_t srcStart,
00920 int32_t srcLength,
00921 int32_t start,
00922 int32_t length)
const;
00923
00931
inline int32_t indexOf(UChar c)
const;
00932
00941
inline int32_t indexOf(
UChar32 c)
const;
00942
00951
inline int32_t indexOf(UChar c,
00952 int32_t start)
const;
00953
00963
inline int32_t indexOf(UChar32 c,
00964 int32_t start)
const;
00965
00976
inline int32_t indexOf(UChar c,
00977 int32_t start,
00978 int32_t length)
const;
00979
00991
inline int32_t indexOf(UChar32 c,
00992 int32_t start,
00993 int32_t length)
const;
00994
01003
inline int32_t lastIndexOf(
const UnicodeString& text)
const;
01004
01014
inline int32_t lastIndexOf(
const UnicodeString& text,
01015 int32_t start)
const;
01016
01028
inline int32_t lastIndexOf(
const UnicodeString& text,
01029 int32_t start,
01030 int32_t length)
const;
01031
01048
inline int32_t lastIndexOf(
const UnicodeString& srcText,
01049 int32_t srcStart,
01050 int32_t srcLength,
01051 int32_t start,
01052 int32_t length)
const;
01053
01064
inline int32_t lastIndexOf(
const UChar *srcChars,
01065 int32_t srcLength,
01066 int32_t start)
const;
01067
01080
inline int32_t lastIndexOf(
const UChar *srcChars,
01081 int32_t srcLength,
01082 int32_t start,
01083 int32_t length)
const;
01084
01101
int32_t lastIndexOf(
const UChar *srcChars,
01102 int32_t srcStart,
01103 int32_t srcLength,
01104 int32_t start,
01105 int32_t length)
const;
01106
01114
inline int32_t lastIndexOf(UChar c)
const;
01115
01124
inline int32_t lastIndexOf(UChar32 c)
const;
01125
01134
inline int32_t lastIndexOf(UChar c,
01135 int32_t start)
const;
01136
01146
inline int32_t lastIndexOf(UChar32 c,
01147 int32_t start)
const;
01148
01159
inline int32_t lastIndexOf(UChar c,
01160 int32_t start,
01161 int32_t length)
const;
01162
01174
inline int32_t lastIndexOf(UChar32 c,
01175 int32_t start,
01176 int32_t length)
const;
01177
01178
01179
01180
01189
inline UChar charAt(int32_t offset)
const;
01190
01198
inline UChar operator[] (int32_t offset)
const;
01199
01211
inline UChar32 char32At(int32_t offset)
const;
01212
01228
inline int32_t getChar32Start(int32_t offset)
const;
01229
01246
inline int32_t getChar32Limit(int32_t offset)
const;
01247
01298
int32_t moveIndex32(int32_t index, int32_t delta)
const;
01299
01300
01301
01317
inline void extract(int32_t start,
01318 int32_t length,
01319 UChar *dst,
01320 int32_t dstStart = 0)
const;
01321
01343
int32_t
01344 extract(UChar *dest, int32_t destCapacity,
01345
UErrorCode &errorCode)
const;
01346
01357
inline void extract(int32_t start,
01358 int32_t length,
01359 UnicodeString& target)
const;
01360
01372
inline void extractBetween(int32_t start,
01373 int32_t limit,
01374 UChar *dst,
01375 int32_t dstStart = 0)
const;
01376
01386
virtual void extractBetween(int32_t start,
01387 int32_t limit,
01388 UnicodeString& target)
const;
01389
01410
inline int32_t extract(int32_t start,
01411 int32_t startLength,
01412
char *target,
01413
const char *codepage = 0)
const;
01414
01439
int32_t extract(int32_t start,
01440 int32_t startLength,
01441
char *target,
01442 uint32_t targetLength,
01443
const char *codepage = 0)
const;
01444
01462
int32_t extract(
char *dest, int32_t destCapacity,
01463
UConverter *cnv,
01464 UErrorCode &errorCode)
const;
01465
01466
01467
01476
inline int32_t length(
void) const;
01477
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
02373 UnicodeString &toTitle(
BreakIterator *titleIter);
02374
02402 UnicodeString &toTitle(
BreakIterator *titleIter, const
Locale &locale);
02403
02404 #endif
02405
02417 UnicodeString &foldCase(uint32_t options=0 );
02418
02419
02420
02421
02422
02466 UChar *getBuffer(int32_t minCapacity);
02467
02488
void releaseBuffer(int32_t newLength=-1);
02489
02520 inline const UChar *getBuffer() const;
02521
02555 inline const UChar *getTerminatedBuffer();
02556
02557
02558
02559
02560
02564 UnicodeString();
02565
02577 UnicodeString(int32_t capacity, UChar32 c, int32_t count);
02578
02584 UnicodeString(UChar ch);
02585
02591 UnicodeString(UChar32 ch);
02592
02599 UnicodeString(const UChar *text);
02600
02608 UnicodeString(const UChar *text,
02609 int32_t textLength);
02610
02630 UnicodeString(UBool isTerminated,
02631 const UChar *text,
02632 int32_t textLength);
02633
02652 UnicodeString(UChar *buffer, int32_t buffLength, int32_t buffCapacity);
02653
02665 UnicodeString(const
char *codepageData,
02666 const
char *codepage = 0);
02667
02680 UnicodeString(const
char *codepageData,
02681 int32_t dataLength,
02682 const
char *codepage = 0);
02683
02705 UnicodeString(
02706 const
char *src, int32_t srcLength,
02707 UConverter *cnv,
02708 UErrorCode &errorCode);
02709
02710
02716 UnicodeString(const UnicodeString& that);
02717
02724 UnicodeString(const UnicodeString& src, int32_t srcStart);
02725
02733 UnicodeString(const UnicodeString& src, int32_t srcStart, int32_t srcLength);
02734
02751 virtual
Replaceable *clone() const;
02752
02756 ~UnicodeString();
02757
02758
02759
02760
02795 UnicodeString unescape() const;
02796
02816 UChar32 unescapeAt(int32_t &offset) const;
02817
02823 static
UClassID getStaticClassID();
02824
02830 virtual UClassID getDynamicClassID() const;
02831
02832
02833
02834
02835
02836 protected:
02841 virtual int32_t getLength() const;
02842
02848 virtual UChar getCharAt(int32_t offset) const;
02849
02855 virtual UChar32 getChar32At(int32_t offset) const;
02856
02857 private:
02858
02859 inline int8_t
02860 doCompare(int32_t start,
02861 int32_t length,
02862 const UnicodeString& srcText,
02863 int32_t srcStart,
02864 int32_t srcLength) const;
02865
02866 int8_t doCompare(int32_t start,
02867 int32_t length,
02868 const UChar *srcChars,
02869 int32_t srcStart,
02870 int32_t srcLength) const;
02871
02872 inline int8_t
02873 doCompareCodePointOrder(int32_t start,
02874 int32_t length,
02875 const UnicodeString& srcText,
02876 int32_t srcStart,
02877 int32_t srcLength) const;
02878
02879 int8_t doCompareCodePointOrder(int32_t start,
02880 int32_t length,
02881 const UChar *srcChars,
02882 int32_t srcStart,
02883 int32_t srcLength) const;
02884
02885 inline int8_t
02886 doCaseCompare(int32_t start,
02887 int32_t length,
02888 const UnicodeString &srcText,
02889 int32_t srcStart,
02890 int32_t srcLength,
02891 uint32_t options) const;
02892
02893 int8_t
02894 doCaseCompare(int32_t start,
02895 int32_t length,
02896 const UChar *srcChars,
02897 int32_t srcStart,
02898 int32_t srcLength,
02899 uint32_t options) const;
02900
02901 int32_t doIndexOf(UChar c,
02902 int32_t start,
02903 int32_t length) const;
02904
02905 int32_t doIndexOf(UChar32 c,
02906 int32_t start,
02907 int32_t length) const;
02908
02909 int32_t doLastIndexOf(UChar c,
02910 int32_t start,
02911 int32_t length) const;
02912
02913 int32_t doLastIndexOf(UChar32 c,
02914 int32_t start,
02915 int32_t length) const;
02916
02917
void doExtract(int32_t start,
02918 int32_t length,
02919 UChar *dst,
02920 int32_t dstStart) const;
02921
02922 inline
void doExtract(int32_t start,
02923 int32_t length,
02924 UnicodeString& target) const;
02925
02926 inline UChar doCharAt(int32_t offset) const;
02927
02928 UnicodeString& doReplace(int32_t start,
02929 int32_t length,
02930 const UnicodeString& srcText,
02931 int32_t srcStart,
02932 int32_t srcLength);
02933
02934 UnicodeString& doReplace(int32_t start,
02935 int32_t length,
02936 const UChar *srcChars,
02937 int32_t srcStart,
02938 int32_t srcLength);
02939
02940 UnicodeString& doReverse(int32_t start,
02941 int32_t length);
02942
02943
02944 int32_t doHashCode(
void) const;
02945
02946
02947 inline UChar* getArrayStart(
void);
02948 inline const UChar* getArrayStart(
void) const;
02949
02950
02951
02952
02953
02954 UBool allocate(int32_t capacity);
02955
02956
02957
void releaseArray(
void);
02958
02959
02960
void unBogus();
02961
02962
02963 UnicodeString ©From(const UnicodeString &src, UBool fastCopy=FALSE);
02964
02965
02966 inline
void pinIndex(int32_t& start) const;
02967 inline
void pinIndices(int32_t& start,
02968 int32_t& length) const;
02969
02970
02971 int32_t doExtract(int32_t start, int32_t length,
02972
char *dest, int32_t destCapacity,
02973 UConverter *cnv,
02974 UErrorCode &errorCode) const;
02975
02976
02977
02978
02979
02980
02981
02982
02983
02984
02985
02986
void doCodepageCreate(const
char *codepageData,
02987 int32_t dataLength,
02988 const
char *codepage);
02989
02990
02991
02992
02993
02994
void
02995 doCodepageCreate(const
char *codepageData,
02996 int32_t dataLength,
02997 UConverter *converter,
02998 UErrorCode &status);
02999
03000
03001
03002
03003
03004
03005
03006
03007
03008
03009
03010 UBool cloneArrayIfNeeded(int32_t newCapacity = -1,
03011 int32_t growCapacity = -1,
03012 UBool doCopyArray = TRUE,
03013 int32_t **pBufferToDelete = 0,
03014 UBool forceClone = FALSE);
03015
03016
03017 UnicodeString &
03018 caseMap(
BreakIterator *titleIter,
03019 const
Locale& locale,
03020 uint32_t options,
03021 int32_t toWhichCase);
03022
03023
03024
void addRef(
void);
03025 int32_t removeRef(
void);
03026 int32_t refCount(
void) const;
03027
03028
03029 enum {
03030 US_STACKBUF_SIZE=7,
03031 kInvalidUChar=0xffff,
03032 kGrowSize=128,
03033 kInvalidHashCode=0,
03034 kEmptyHashCode=1,
03035
03036
03037 kIsBogus=1,
03038 kUsingStackBuffer=2,
03039 kRefCounted=4,
03040 kBufferIsReadonly=8,
03041 kOpenGetBuffer=16,
03042
03043
03044
03045 kShortString=kUsingStackBuffer,
03046 kLongString=kRefCounted,
03047 kReadonlyAlias=kBufferIsReadonly,
03048 kWritableAlias=0
03049 };
03050
03051
friend class StringCharacterIterator;
03052
friend class StringThreadTest;
03053
03054
03055
03056
03057
03058
03059
03060
03061
03062
03063
03064
03065
03066
int32_t fLength;
03067
int32_t fCapacity;
03068
UChar *fArray;
03069
uint16_t fFlags;
03070
UChar fStackBuffer [ US_STACKBUF_SIZE ];
03071
03072 };
03073
03082
U_COMMON_API UnicodeString
03083
operator+ (
const UnicodeString &s1,
const UnicodeString &s2);
03084
03085
U_NAMESPACE_END
03086
03087
03088
03089
03090
03091
03096
inline void
03097
uprv_arrayCopy(
const U_NAMESPACE_QUALIFIER UnicodeString *src, U_NAMESPACE_QUALIFIER UnicodeString *dst, int32_t count)
03098 {
while(count-- > 0) *dst++ = *src++; }
03099
03104
inline void
03105
uprv_arrayCopy(
const U_NAMESPACE_QUALIFIER UnicodeString *src, int32_t srcStart,
03106 U_NAMESPACE_QUALIFIER UnicodeString *dst, int32_t dstStart, int32_t count)
03107 {
uprv_arrayCopy(src+srcStart, dst+dstStart, count); }
03108
03109
U_NAMESPACE_BEGIN
03110
03111
03112
03113
03114
03115
03116
03117
03118
03119
inline void
03120 UnicodeString::pinIndex(int32_t& start)
const
03121
{
03122
03123
if(start < 0) {
03124 start = 0;
03125 }
else if(start > fLength) {
03126 start = fLength;
03127 }
03128 }
03129
03130
inline void
03131 UnicodeString::pinIndices(int32_t& start,
03132 int32_t& _length)
const
03133
{
03134
03135
if(start < 0) {
03136 start = 0;
03137 }
else if(start > fLength) {
03138 start = fLength;
03139 }
03140
if(_length < 0) {
03141 _length = 0;
03142 }
else if(_length > (fLength - start)) {
03143 _length = (fLength - start);
03144 }
03145 }
03146
03147
inline UChar*
03148 UnicodeString::getArrayStart()
03149 {
return fArray; }
03150
03151
inline const UChar*
03152 UnicodeString::getArrayStart()
const
03153
{
return fArray; }
03154
03155
03156
03157
03158
inline int32_t
03159
UnicodeString::length()
const
03160
{
return fLength; }
03161
03162
inline int32_t
03163
UnicodeString::getCapacity()
const
03164
{
return fCapacity; }
03165
03166
inline int32_t
03167
UnicodeString::hashCode()
const
03168
{
return doHashCode(); }
03169
03170
inline UBool
03171
UnicodeString::isBogus()
const
03172
{
return (
UBool)(fFlags & kIsBogus); }
03173
03174
inline const UChar *
03175
UnicodeString::getBuffer()
const {
03176
if(!(fFlags&(kIsBogus|kOpenGetBuffer))) {
03177
return fArray;
03178 }
else {
03179
return 0;
03180 }
03181 }
03182
03183
03184
03185
03186
inline int8_t
03187 UnicodeString::doCompare(int32_t start,
03188 int32_t length,
03189
const UnicodeString& srcText,
03190 int32_t srcStart,
03191 int32_t srcLength)
const
03192
{
03193
if(srcText.
isBogus()) {
03194
return (
int8_t)!
isBogus();
03195 }
else {
03196 srcText.
pinIndices(srcStart, srcLength);
03197
return doCompare(start, length, srcText.
fArray, srcStart, srcLength);
03198 }
03199 }
03200
03201
inline UBool
03202 UnicodeString::operator== (
const UnicodeString& text)
const
03203
{
03204
if(
isBogus()) {
03205
return text.
isBogus();
03206 }
else {
03207
return
03208 !text.
isBogus() &&
03209 fLength == text.
fLength &&
03210 doCompare(0, fLength, text, 0, text.
fLength) == 0;
03211 }
03212 }
03213
03214
inline UBool
03215 UnicodeString::operator!= (
const UnicodeString& text)
const
03216
{
return (!
operator==(text)); }
03217
03218
inline UBool
03219 UnicodeString::operator> (
const UnicodeString& text)
const
03220
{
return doCompare(0, fLength, text, 0, text.
fLength) == 1; }
03221
03222
inline UBool
03223 UnicodeString::operator< (
const UnicodeString& text)
const
03224
{
return doCompare(0, fLength, text, 0, text.
fLength) == -1; }
03225
03226
inline UBool
03227 UnicodeString::operator>= (
const UnicodeString& text)
const
03228
{
return doCompare(0, fLength, text, 0, text.
fLength) != -1; }
03229
03230
inline UBool
03231 UnicodeString::operator<= (
const UnicodeString& text)
const
03232
{
return doCompare(0, fLength, text, 0, text.
fLength) != 1; }
03233
03234
inline int8_t
03235
UnicodeString::compare(
const UnicodeString& text)
const
03236
{
return doCompare(0, fLength, text, 0, text.
fLength); }
03237
03238
inline int8_t
03239
UnicodeString::compare(int32_t start,
03240 int32_t _length,
03241
const UnicodeString& srcText)
const
03242
{
return doCompare(start, _length, srcText, 0, srcText.
fLength); }
03243
03244
inline int8_t
03245
UnicodeString::compare(
const UChar *srcChars,
03246 int32_t srcLength)
const
03247
{
return doCompare(0, fLength, srcChars, 0, srcLength); }
03248
03249
inline int8_t
03250
UnicodeString::compare(int32_t start,
03251 int32_t _length,
03252
const UnicodeString& srcText,
03253 int32_t srcStart,
03254 int32_t srcLength)
const
03255
{
return doCompare(start, _length, srcText, srcStart, srcLength); }
03256
03257
inline int8_t
03258
UnicodeString::compare(int32_t start,
03259 int32_t _length,
03260
const UChar *srcChars)
const
03261
{
return doCompare(start, _length, srcChars, 0, _length); }
03262
03263
inline int8_t
03264
UnicodeString::compare(int32_t start,
03265 int32_t _length,
03266
const UChar *srcChars,
03267 int32_t srcStart,
03268 int32_t srcLength)
const
03269
{
return doCompare(start, _length, srcChars, srcStart, srcLength); }
03270
03271
inline int8_t
03272
UnicodeString::compareBetween(int32_t start,
03273 int32_t limit,
03274 const UnicodeString& srcText,
03275 int32_t srcStart,
03276 int32_t srcLimit)
const
03277
{
return doCompare(start, limit - start,
03278 srcText, srcStart, srcLimit - srcStart); }
03279
03280
inline int8_t
03281 UnicodeString::doCompareCodePointOrder(int32_t start,
03282 int32_t length,
03283
const UnicodeString& srcText,
03284 int32_t srcStart,
03285 int32_t srcLength)
const
03286
{
03287
if(srcText.
isBogus()) {
03288
return (
int8_t)!
isBogus();
03289 }
else {
03290 srcText.
pinIndices(srcStart, srcLength);
03291
return doCompareCodePointOrder(start,
length, srcText.
fArray, srcStart, srcLength);
03292 }
03293 }
03294
03295
inline int8_t
03296 UnicodeString::compareCodePointOrder(
const UnicodeString& text)
const
03297
{
return doCompareCodePointOrder(0, fLength, text, 0, text.
fLength); }
03298
03299
inline int8_t
03300
UnicodeString::compareCodePointOrder(int32_t start,
03301 int32_t _length,
03302
const UnicodeString& srcText)
const
03303
{
return doCompareCodePointOrder(start, _length, srcText, 0, srcText.
fLength); }
03304
03305
inline int8_t
03306
UnicodeString::compareCodePointOrder(
const UChar *srcChars,
03307 int32_t srcLength)
const
03308
{
return doCompareCodePointOrder(0, fLength, srcChars, 0, srcLength); }
03309
03310
inline int8_t
03311
UnicodeString::compareCodePointOrder(int32_t start,
03312 int32_t _length,
03313
const UnicodeString& srcText,
03314 int32_t srcStart,
03315 int32_t srcLength)
const
03316
{
return doCompareCodePointOrder(start, _length, srcText, srcStart, srcLength); }
03317
03318
inline int8_t
03319
UnicodeString::compareCodePointOrder(int32_t start,
03320 int32_t _length,
03321
const UChar *srcChars)
const
03322
{
return doCompareCodePointOrder(start, _length, srcChars, 0, _length); }
03323
03324
inline int8_t
03325
UnicodeString::compareCodePointOrder(int32_t start,
03326 int32_t _length,
03327
const UChar *srcChars,
03328 int32_t srcStart,
03329 int32_t srcLength)
const
03330
{
return doCompareCodePointOrder(start, _length, srcChars, srcStart, srcLength); }
03331
03332
inline int8_t
03333
UnicodeString::compareCodePointOrderBetween(int32_t start,
03334 int32_t limit,
03335
const UnicodeString& srcText,
03336 int32_t srcStart,
03337 int32_t srcLimit)
const
03338 {
return doCompareCodePointOrder(start, limit - start,
03339 srcText, srcStart, srcLimit - srcStart); }
03340
03341
inline int8_t
03342 UnicodeString::doCaseCompare(int32_t start,
03343 int32_t length,
03344
const UnicodeString &srcText,
03345 int32_t srcStart,
03346 int32_t srcLength,
03347 uint32_t options)
const
03348
{
03349
if(srcText.
isBogus()) {
03350 return (
int8_t)!
isBogus();
03351 }
else {
03352 srcText.
pinIndices(srcStart, srcLength);
03353
return doCaseCompare(start, length, srcText.
fArray, srcStart, srcLength, options);
03354 }
03355 }
03356
03357
inline int8_t
03358
UnicodeString::caseCompare(
const UnicodeString &text, uint32_t options)
const {
03359
return doCaseCompare(0, fLength, text, 0, text.
fLength, options);
03360 }
03361
03362
inline int8_t
03363
UnicodeString::caseCompare(int32_t start,
03364 int32_t _length,
03365
const UnicodeString &srcText,
03366 uint32_t options)
const {
03367
return doCaseCompare(start, _length, srcText, 0, srcText.
fLength, options);
03368 }
03369
03370
inline int8_t
03371
UnicodeString::caseCompare(
const UChar *srcChars,
03372 int32_t srcLength,
03373 uint32_t options)
const {
03374
return doCaseCompare(0, fLength, srcChars, 0, srcLength, options);
03375 }
03376
03377
inline int8_t
03378
UnicodeString::caseCompare(int32_t start,
03379 int32_t _length,
03380
const UnicodeString &srcText,
03381 int32_t srcStart,
03382 int32_t srcLength,
03383 uint32_t options)
const {
03384
return doCaseCompare(start, _length, srcText, srcStart, srcLength, options);
03385 }
03386
03387
inline int8_t
03388 UnicodeString::caseCompare(int32_t start,
03389 int32_t _length,
03390
const UChar *srcChars,
03391 uint32_t options)
const {
03392
return doCaseCompare(start, _length, srcChars, 0, _length, options);
03393 }
03394
03395
inline int8_t
03396
UnicodeString::caseCompare(int32_t start,
03397 int32_t _length,
03398 const UChar *srcChars,
03399 int32_t srcStart,
03400 int32_t srcLength,
03401 uint32_t options)
const {
03402 return doCaseCompare(start, _length, srcChars, srcStart, srcLength, options);
03403 }
03404
03405
inline int8_t
03406 UnicodeString::caseCompareBetween(int32_t start,
03407 int32_t limit,
03408
const UnicodeString &srcText,
03409 int32_t srcStart,
03410 int32_t srcLimit,
03411 uint32_t options)
const {
03412
return doCaseCompare(start, limit - start, srcText, srcStart, srcLimit - srcStart, options);
03413 }
03414
03415
inline int32_t
03416
UnicodeString::indexOf(
const UnicodeString& srcText,
03417 int32_t srcStart,
03418 int32_t srcLength,
03419 int32_t start,
03420 int32_t _length)
const
03421
{
03422
if(!srcText.
isBogus()) {
03423 srcText.
pinIndices(srcStart, srcLength);
03424 if(srcLength > 0) {
03425
return indexOf(srcText.
getArrayStart(), srcStart, srcLength, start, _length);
03426 }
03427 }
03428
return -1;
03429 }
03430
03431
inline int32_t
03432 UnicodeString::indexOf(
const UnicodeString& text)
const
03433
{
return indexOf(text, 0, text.
fLength, 0, fLength); }
03434
03435
inline int32_t
03436
UnicodeString::indexOf(
const UnicodeString& text,
03437 int32_t start)
const {
03438 pinIndex(start);
03439
return indexOf(text, 0, text.
fLength, start, fLength - start);
03440 }
03441
03442
inline int32_t
03443 UnicodeString::indexOf(
const UnicodeString& text,
03444 int32_t start,
03445 int32_t _length)
const
03446
{
return indexOf(text, 0, text.
fLength, start, _length); }
03447
03448
inline int32_t
03449 UnicodeString::indexOf(
const UChar *srcChars,
03450 int32_t srcLength,
03451 int32_t start)
const {
03452 pinIndex(start);
03453
return indexOf(srcChars, 0, srcLength, start, fLength - start);
03454 }
03455
03456
inline int32_t
03457 UnicodeString::indexOf(
const UChar *srcChars,
03458 int32_t srcLength,
03459 int32_t start,
03460 int32_t _length)
const
03461
{
return indexOf(srcChars, 0, srcLength, start, _length); }
03462
03463
inline int32_t
03464
UnicodeString::indexOf(UChar c,
03465 int32_t start,
03466 int32_t _length)
const
03467
{
return doIndexOf(c, start, _length); }
03468
03469
inline int32_t
03470
UnicodeString::indexOf(UChar32 c,
03471 int32_t start,
03472 int32_t _length)
const
03473
{
return doIndexOf(c, start, _length); }
03474
03475 inline int32_t
03476
UnicodeString::indexOf(UChar c)
const
03477
{
return doIndexOf(c, 0, fLength); }
03478
03479 inline int32_t
03480
UnicodeString::indexOf(UChar32 c)
const
03481
{
return indexOf(c, 0, fLength); }
03482
03483
inline int32_t
03484 UnicodeString::indexOf(UChar c,
03485 int32_t start)
const {
03486 pinIndex(start);
03487
return doIndexOf(c, start, fLength - start);
03488 }
03489
03490 inline int32_t
03491
UnicodeString::indexOf(UChar32 c,
03492 int32_t start)
const {
03493 pinIndex(start);
03494
return indexOf(c, start, fLength - start);
03495 }
03496
03497
inline int32_t
03498 UnicodeString::lastIndexOf(
const UChar *srcChars,
03499 int32_t srcLength,
03500 int32_t start,
03501 int32_t _length)
const
03502
{
return lastIndexOf(srcChars, 0, srcLength, start, _length); }
03503
03504 inline int32_t
03505
UnicodeString::lastIndexOf(
const UChar *srcChars,
03506 int32_t srcLength,
03507 int32_t start)
const {
03508 pinIndex(start);
03509
return lastIndexOf(srcChars, 0, srcLength, start, fLength - start);
03510 }
03511
03512 inline int32_t
03513
UnicodeString::lastIndexOf(
const UnicodeString& srcText,
03514 int32_t srcStart,
03515 int32_t srcLength,
03516 int32_t start,
03517 int32_t _length)
const
03518
{
03519
if(!srcText.
isBogus()) {
03520 srcText.
pinIndices(srcStart, srcLength);
03521
if(srcLength > 0) {
03522
return lastIndexOf(srcText.
getArrayStart(), srcStart, srcLength, start, _length);
03523 }
03524 }
03525
return -1;
03526 }
03527
03528
inline int32_t
03529 UnicodeString::lastIndexOf(
const UnicodeString& text,
03530 int32_t start,
03531 int32_t _length)
const
03532
{
return lastIndexOf(text, 0, text.
fLength, start, _length); }
03533
03534
inline int32_t
03535
UnicodeString::lastIndexOf(
const UnicodeString& text,
03536 int32_t start)
const {
03537 pinIndex(start);
03538
return lastIndexOf(text, 0, text.
fLength, start, fLength - start);
03539 }
03540
03541
inline int32_t
03542 UnicodeString::lastIndexOf(
const UnicodeString& text)
const
03543
{
return lastIndexOf(text, 0, text.
fLength, 0, fLength); }
03544
03545
inline int32_t
03546 UnicodeString::lastIndexOf(UChar c,
03547 int32_t start,
03548 int32_t _length)
const
03549
{
return doLastIndexOf(c, start, _length); }
03550
03551
inline int32_t
03552
UnicodeString::lastIndexOf(UChar32 c,
03553 int32_t start,
03554 int32_t _length)
const {
03555
return doLastIndexOf(c, start, _length);
03556 }
03557
03558
inline int32_t
03559
UnicodeString::lastIndexOf(UChar c)
const
03560
{
return doLastIndexOf(c, 0, fLength); }
03561
03562
inline int32_t
03563 UnicodeString::lastIndexOf(UChar32 c)
const {
03564
return lastIndexOf(c, 0, fLength);
03565 }
03566
03567 inline int32_t
03568
UnicodeString::lastIndexOf(UChar c,
03569 int32_t start)
const {
03570 pinIndex(start);
03571
return doLastIndexOf(c, start, fLength - start);
03572 }
03573
03574
inline int32_t
03575 UnicodeString::lastIndexOf(UChar32 c,
03576 int32_t start)
const {
03577 pinIndex(start);
03578
return lastIndexOf(c, start, fLength - start);
03579 }
03580
03581
inline UBool
03582 UnicodeString::startsWith(
const UnicodeString& text)
const
03583
{
return compare(0, text.
fLength, text, 0, text.
fLength) == 0; }
03584
03585 inline UBool
03586
UnicodeString::startsWith(
const UnicodeString& srcText,
03587 int32_t srcStart,
03588 int32_t srcLength)
const
03589
{
return doCompare(0, srcLength, srcText, srcStart, srcLength) == 0; }
03590
03591
inline UBool
03592 UnicodeString::startsWith(
const UChar *srcChars,
03593 int32_t srcLength)
const
03594
{
return doCompare(0, srcLength, srcChars, 0, srcLength) == 0; }
03595
03596
inline UBool
03597
UnicodeString::startsWith(
const UChar *srcChars,
03598 int32_t srcStart,
03599 int32_t srcLength)
const
03600
{
return doCompare(0, srcLength, srcChars, srcStart, srcLength) == 0;}
03601
03602
inline UBool
03603 UnicodeString::endsWith(
const UnicodeString& text)
const
03604
{
return doCompare(fLength - text.
fLength, text.
fLength,
03605 text, 0, text.
fLength) == 0; }
03606
03607
inline UBool
03608
UnicodeString::endsWith(
const UnicodeString& srcText,
03609 int32_t srcStart,
03610 int32_t srcLength)
const {
03611 srcText.
pinIndices(srcStart, srcLength);
03612
return doCompare(fLength - srcLength, srcLength,
03613 srcText, srcStart, srcLength) == 0;
03614 }
03615
03616
inline UBool
03617
UnicodeString::endsWith(
const UChar *srcChars,
03618 int32_t srcLength)
const {
03619
if(srcLength < 0) {
03620 srcLength =
u_strlen(srcChars);
03621 }
03622 return doCompare(fLength - srcLength, srcLength,
03623 srcChars, 0, srcLength) == 0;
03624 }
03625
03626
inline UBool
03627 UnicodeString::endsWith(
const UChar *srcChars,
03628 int32_t srcStart,
03629 int32_t srcLength)
const {
03630
if(srcLength < 0) {
03631 srcLength =
u_strlen(srcChars + srcStart);
03632 }
03633
return doCompare(fLength - srcLength, srcLength,
03634 srcChars, srcStart, srcLength) == 0;
03635 }
03636
03637
03638
03639
03640
inline UnicodeString&
03641
UnicodeString::replace(int32_t start,
03642 int32_t _length,
03643 const UnicodeString& srcText)
03644 {
return doReplace(start, _length, srcText, 0, srcText.
fLength); }
03645
03646
inline UnicodeString&
03647 UnicodeString::replace(int32_t start,
03648 int32_t _length,
03649 const UnicodeString& srcText,
03650 int32_t srcStart,
03651 int32_t srcLength)
03652 {
return doReplace(start, _length, srcText, srcStart, srcLength); }
03653
03654
inline UnicodeString&
03655 UnicodeString::replace(int32_t start,
03656 int32_t _length,
03657
const UChar *srcChars,
03658 int32_t srcLength)
03659 {
return doReplace(start, _length, srcChars, 0, srcLength); }
03660
03661
inline UnicodeString&
03662 UnicodeString::replace(int32_t start,
03663 int32_t _length,
03664
const UChar *srcChars,
03665 int32_t srcStart,
03666 int32_t srcLength)
03667 {
return doReplace(start, _length, srcChars, srcStart, srcLength); }
03668
03669
inline UnicodeString&
03670 UnicodeString::replace(int32_t start,
03671 int32_t _length,
03672 UChar srcChar)
03673 {
return doReplace(start, _length, &srcChar, 0, 1); }
03674
03675
inline UnicodeString&
03676 UnicodeString::replace(int32_t start,
03677 int32_t _length,
03678 UChar32 srcChar) {
03679
UChar buffer[
U16_MAX_LENGTH];
03680
int32_t count = 0;
03681
UBool isError =
FALSE;
03682
U16_APPEND(buffer, count,
U16_MAX_LENGTH, srcChar, isError);
03683
return doReplace(start, _length, buffer, 0, count);
03684 }
03685
03686
inline UnicodeString&
03687 UnicodeString::replaceBetween(int32_t start,
03688 int32_t limit,
03689
const UnicodeString& srcText)
03690 {
return doReplace(start, limit - start, srcText, 0, srcText.
fLength); }
03691
03692 inline UnicodeString&
03693
UnicodeString::replaceBetween(int32_t start,
03694 int32_t limit,
03695
const UnicodeString& srcText,
03696 int32_t srcStart,
03697 int32_t srcLimit)
03698 {
return doReplace(start, limit - start, srcText, srcStart, srcLimit - srcStart); }
03699
03700
inline UnicodeString&
03701 UnicodeString::findAndReplace(
const UnicodeString& oldText,
03702
const UnicodeString& newText)
03703 {
return findAndReplace(0, fLength, oldText, 0, oldText.
fLength,
03704 newText, 0, newText.
fLength); }
03705
03706
inline UnicodeString&
03707
UnicodeString::findAndReplace(int32_t start,
03708 int32_t _length,
03709
const UnicodeString& oldText,
03710
const UnicodeString& newText)
03711 {
return findAndReplace(start, _length, oldText, 0, oldText.
fLength,
03712 newText, 0, newText.
fLength); }
03713
03714
03715
03716
03717
inline void
03718 UnicodeString::doExtract(int32_t start,
03719 int32_t _length,
03720 UnicodeString& target)
const
03721 { target.
replace(0, target.
fLength, *
this, start, _length); }
03722
03723
inline void
03724 UnicodeString::extract(int32_t start,
03725 int32_t _length,
03726 UChar *target,
03727 int32_t targetStart)
const
03728
{ doExtract(start, _length, target, targetStart); }
03729
03730
inline void
03731 UnicodeString::extract(int32_t start,
03732 int32_t _length,
03733 UnicodeString& target)
const
03734
{ doExtract(start, _length, target); }
03735
03736
inline int32_t
03737 UnicodeString::extract(int32_t start,
03738 int32_t _length,
03739
char *dst,
03740
const char *codepage)
const
03741
03742 {
03743
03744
return extract(start, _length, dst, dst!=0 ? 0xffffffff : 0, codepage);
03745 }
03746
03747 inline void
03748
UnicodeString::extractBetween(int32_t start,
03749 int32_t limit,
03750 UChar *dst,
03751 int32_t dstStart)
const {
03752 pinIndex(start);
03753 pinIndex(limit);
03754 doExtract(start, limit - start, dst, dstStart);
03755 }
03756
03757
inline UChar
03758 UnicodeString::doCharAt(int32_t offset)
const
03759
{
03760
if((
uint32_t)offset < (
uint32_t)fLength) {
03761 return fArray[offset];
03762 }
else {
03763
return kInvalidUChar;
03764 }
03765 }
03766
03767
inline UChar
03768 UnicodeString::charAt(int32_t offset)
const
03769
{
return doCharAt(offset); }
03770
03771 inline UChar
03772 UnicodeString::operator[] (int32_t offset)
const
03773
{
return doCharAt(offset); }
03774
03775
inline UChar32
03776 UnicodeString::char32At(int32_t offset)
const
03777
{
03778
if((
uint32_t)offset < (
uint32_t)fLength) {
03779
UChar32 c;
03780
U16_GET(fArray, 0, offset, fLength, c);
03781
return c;
03782 }
else {
03783
return kInvalidUChar;
03784 }
03785 }
03786
03787 inline int32_t
03788
UnicodeString::getChar32Start(int32_t offset)
const {
03789
if((
uint32_t)offset < (
uint32_t)fLength) {
03790
U16_SET_CP_START(fArray, 0, offset);
03791
return offset;
03792 }
else {
03793
return 0;
03794 }
03795 }
03796
03797
inline int32_t
03798
UnicodeString::getChar32Limit(int32_t offset)
const {
03799
if((
uint32_t)offset < (
uint32_t)fLength) {
03800
U16_SET_CP_LIMIT(fArray, 0, offset, fLength);
03801
return offset;
03802 }
else {
03803
return fLength;
03804 }
03805 }
03806
03807
inline UBool
03808
UnicodeString::isEmpty()
const {
03809
return fLength == 0;
03810 }
03811
03812
03813
03814
03815
inline const UChar *
03816
UnicodeString::getTerminatedBuffer() {
03817
if(fFlags&(kIsBogus|kOpenGetBuffer)) {
03818
return 0;
03819 }
else if(fLength<fCapacity && fArray[fLength]==0) {
03820 return fArray;
03821 }
else if(cloneArrayIfNeeded(fLength+1)) {
03822 fArray[fLength]=0;
03823
return fArray;
03824 }
else {
03825
return 0;
03826 }
03827 }
03828
03829
inline UnicodeString&
03830 UnicodeString::operator= (UChar ch)
03831 {
return doReplace(0, fLength, &ch, 0, 1); }
03832
03833
inline UnicodeString&
03834 UnicodeString::operator= (UChar32 ch)
03835 {
return replace(0, fLength, ch); }
03836
03837
inline UnicodeString&
03838 UnicodeString::setTo(
const UnicodeString& srcText,
03839 int32_t srcStart,
03840 int32_t srcLength)
03841 {
03842 unBogus();
03843
return doReplace(0, fLength, srcText, srcStart, srcLength);
03844 }
03845
03846
inline UnicodeString&
03847 UnicodeString::setTo(
const UnicodeString& srcText,
03848 int32_t srcStart)
03849 {
03850 unBogus();
03851 srcText.
pinIndex(srcStart);
03852
return doReplace(0, fLength, srcText, srcStart, srcText.
fLength - srcStart);
03853 }
03854
03855 inline UnicodeString&
03856
UnicodeString::setTo(
const UnicodeString& srcText)
03857 {
03858 unBogus();
03859
return doReplace(0, fLength, srcText, 0, srcText.
fLength);
03860 }
03861
03862
inline UnicodeString&
03863 UnicodeString::setTo(
const UChar *srcChars,
03864 int32_t srcLength)
03865 {
03866 unBogus();
03867
return doReplace(0, fLength, srcChars, 0, srcLength);
03868 }
03869
03870
inline UnicodeString&
03871 UnicodeString::setTo(UChar srcChar)
03872 {
03873 unBogus();
03874
return doReplace(0, fLength, &srcChar, 0, 1);
03875 }
03876
03877
inline UnicodeString&
03878 UnicodeString::setTo(UChar32 srcChar)
03879 {
03880 unBogus();
03881
return replace(0, fLength, srcChar);
03882 }
03883
03884
inline UnicodeString&
03885 UnicodeString::operator+= (UChar ch)
03886 {
return doReplace(fLength, 0, &ch, 0, 1); }
03887
03888
inline UnicodeString&
03889 UnicodeString::operator+= (UChar32 ch) {
03890
UChar buffer[
U16_MAX_LENGTH];
03891
int32_t _length = 0;
03892
UBool isError =
FALSE;
03893
U16_APPEND(buffer, _length, U16_MAX_LENGTH, ch, isError);
03894
return doReplace(fLength, 0, buffer, 0, _length);
03895 }
03896
03897
inline UnicodeString&
03898 UnicodeString::operator+= (
const UnicodeString& srcText)
03899 {
return doReplace(fLength, 0, srcText, 0, srcText.
fLength); }
03900
03901
inline UnicodeString&
03902
UnicodeString::append(
const UnicodeString& srcText,
03903 int32_t srcStart,
03904 int32_t srcLength)
03905 {
return doReplace(fLength, 0, srcText, srcStart, srcLength); }
03906
03907
inline UnicodeString&
03908 UnicodeString::append(
const UnicodeString& srcText)
03909 {
return doReplace(fLength, 0, srcText, 0, srcText.
fLength); }
03910
03911
inline UnicodeString&
03912
UnicodeString::append(
const UChar *srcChars,
03913 int32_t srcStart,
03914 int32_t srcLength)
03915 {
return doReplace(fLength, 0, srcChars, srcStart, srcLength); }
03916
03917
inline UnicodeString&
03918
UnicodeString::append(
const UChar *srcChars,
03919 int32_t srcLength)
03920 {
return doReplace(fLength, 0, srcChars, 0, srcLength); }
03921
03922
inline UnicodeString&
03923 UnicodeString::append(UChar srcChar)
03924 {
return doReplace(fLength, 0, &srcChar, 0, 1); }
03925
03926
inline UnicodeString&
03927 UnicodeString::append(UChar32 srcChar) {
03928
UChar buffer[
U16_MAX_LENGTH];
03929
int32_t _length = 0;
03930
UBool isError =
FALSE;
03931
U16_APPEND(buffer, _length,
U16_MAX_LENGTH, srcChar, isError);
03932
return doReplace(fLength, 0, buffer, 0, _length);
03933 }
03934
03935
inline UnicodeString&
03936 UnicodeString::insert(int32_t start,
03937
const UnicodeString& srcText,
03938 int32_t srcStart,
03939 int32_t srcLength)
03940 {
return doReplace(start, 0, srcText, srcStart, srcLength); }
03941
03942
inline UnicodeString&
03943
UnicodeString::insert(int32_t start,
03944
const UnicodeString& srcText)
03945 {
return doReplace(start, 0, srcText, 0, srcText.
fLength); }
03946
03947 inline UnicodeString&
03948
UnicodeString::insert(int32_t start,
03949
const UChar *srcChars,
03950 int32_t srcStart,
03951 int32_t srcLength)
03952 {
return doReplace(start, 0, srcChars, srcStart, srcLength); }
03953
03954
inline UnicodeString&
03955 UnicodeString::insert(int32_t start,
03956
const UChar *srcChars,
03957 int32_t srcLength)
03958 {
return doReplace(start, 0, srcChars, 0, srcLength); }
03959
03960
inline UnicodeString&
03961 UnicodeString::insert(int32_t start,
03962 UChar srcChar)
03963 {
return doReplace(start, 0, &srcChar, 0, 1); }
03964
03965
inline UnicodeString&
03966
UnicodeString::insert(int32_t start,
03967 UChar32 srcChar)
03968 {
return replace(start, 0, srcChar); }
03969
03970
03971
inline UnicodeString&
03972
UnicodeString::remove()
03973 {
03974
03975
if(
isBogus()) {
03976 unBogus();
03977 }
else {
03978 fLength = 0;
03979 }
03980
return *
this;
03981 }
03982
03983
inline UnicodeString&
03984
UnicodeString::remove(int32_t start,
03985 int32_t _length)
03986 {
03987 if(start <= 0 && _length ==
INT32_MAX) {
03988
03989
return remove();
03990 }
else {
03991
return doReplace(start, _length, NULL, 0, 0);
03992 }
03993 }
03994
03995 inline UnicodeString&
03996
UnicodeString::removeBetween(int32_t start,
03997 int32_t limit)
03998 {
return doReplace(start, limit - start,
NULL, 0, 0); }
03999
04000
inline UBool
04001 UnicodeString::truncate(int32_t targetLength)
04002 {
04003
if(
isBogus() && targetLength == 0) {
04004
04005 unBogus();
04006
return FALSE;
04007 }
else if((
uint32_t)targetLength < (
uint32_t)fLength) {
04008 fLength = targetLength;
04009 return TRUE;
04010 }
else {
04011
return FALSE;
04012 }
04013 }
04014
04015
inline UnicodeString&
04016
UnicodeString::reverse()
04017 {
return doReverse(0, fLength); }
04018
04019
inline UnicodeString&
04020
UnicodeString::reverse(int32_t start,
04021 int32_t _length)
04022 {
return doReverse(start, _length); }
04023
04024
U_NAMESPACE_END
04025
04026 #endif