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/rep.h"
00026
00027
00028
00029 struct UConverter;
00030
00031 U_NAMESPACE_BEGIN
00032
00033 class Locale;
00034 class UCharReference;
00035 class UnicodeConverter;
00036 class StringCharacterIterator;
00037 class SearchIterator;
00038 class StringSearch;
00039
00040
00041
00059 #if U_SIZEOF_WCHAR_T==U_SIZEOF_UCHAR && U_CHARSET_FAMILY==U_ASCII_FAMILY
00060 # define UNICODE_STRING(cs, length) UnicodeString(TRUE, (UChar *)L ## cs, length)
00061 #elif U_SIZEOF_UCHAR==1 && U_CHARSET_FAMILY==U_ASCII_FAMILY
00062 # define UNICODE_STRING(cs, length) UnicodeString(TRUE, (UChar *)cs, length)
00063 #else
00064 # define UNICODE_STRING(cs, length) UnicodeString(cs, length, "")
00065 #endif
00066
00126 class U_COMMON_API UnicodeString : public Replaceable
00127 {
00128 public:
00129
00130
00131
00132
00133
00134
00135
00143 inline UBool operator== (const UnicodeString& text) const;
00144
00152 inline UBool operator!= (const UnicodeString& text) const;
00153
00161 inline UBool operator> (const UnicodeString& text) const;
00162
00170 inline UBool operator< (const UnicodeString& text) const;
00171
00179 inline UBool operator>= (const UnicodeString& text) const;
00180
00188 inline UBool operator<= (const UnicodeString& text) const;
00189
00201 inline int8_t compare(const UnicodeString& text) const;
00202
00217 inline int8_t compare(UTextOffset start,
00218 int32_t length,
00219 const UnicodeString& srcText) const;
00220
00238 inline int8_t compare(UTextOffset start,
00239 int32_t length,
00240 const UnicodeString& srcText,
00241 UTextOffset srcStart,
00242 int32_t srcLength) const;
00243
00256 inline int8_t compare(const UChar *srcChars,
00257 int32_t srcLength) const;
00258
00273 inline int8_t compare(UTextOffset start,
00274 int32_t length,
00275 const UChar *srcChars) const;
00276
00294 inline int8_t compare(UTextOffset start,
00295 int32_t length,
00296 const UChar *srcChars,
00297 UTextOffset srcStart,
00298 int32_t srcLength) const;
00299
00317 inline int8_t compareBetween(UTextOffset start,
00318 UTextOffset limit,
00319 const UnicodeString& srcText,
00320 UTextOffset srcStart,
00321 UTextOffset srcLimit) const;
00322
00340 inline int8_t compareCodePointOrder(const UnicodeString& text) const;
00341
00361 inline int8_t compareCodePointOrder(UTextOffset start,
00362 int32_t length,
00363 const UnicodeString& srcText) const;
00364
00386 inline int8_t compareCodePointOrder(UTextOffset start,
00387 int32_t length,
00388 const UnicodeString& srcText,
00389 UTextOffset srcStart,
00390 int32_t srcLength) const;
00391
00410 inline int8_t compareCodePointOrder(const UChar *srcChars,
00411 int32_t srcLength) const;
00412
00432 inline int8_t compareCodePointOrder(UTextOffset start,
00433 int32_t length,
00434 const UChar *srcChars) const;
00435
00457 inline int8_t compareCodePointOrder(UTextOffset start,
00458 int32_t length,
00459 const UChar *srcChars,
00460 UTextOffset srcStart,
00461 int32_t srcLength) const;
00462
00484 inline int8_t compareCodePointOrderBetween(UTextOffset start,
00485 UTextOffset limit,
00486 const UnicodeString& srcText,
00487 UTextOffset srcStart,
00488 UTextOffset srcLimit) const;
00489
00499 inline int8_t caseCompare(const UnicodeString& text, uint32_t options) const;
00500
00512 inline int8_t caseCompare(UTextOffset start,
00513 int32_t length,
00514 const UnicodeString& srcText,
00515 uint32_t options) const;
00516
00530 inline int8_t caseCompare(UTextOffset start,
00531 int32_t length,
00532 const UnicodeString& srcText,
00533 UTextOffset srcStart,
00534 int32_t srcLength,
00535 uint32_t options) const;
00536
00547 inline int8_t caseCompare(const UChar *srcChars,
00548 int32_t srcLength,
00549 uint32_t options) const;
00550
00562 inline int8_t caseCompare(UTextOffset start,
00563 int32_t length,
00564 const UChar *srcChars,
00565 uint32_t options) const;
00566
00580 inline int8_t caseCompare(UTextOffset start,
00581 int32_t length,
00582 const UChar *srcChars,
00583 UTextOffset srcStart,
00584 int32_t srcLength,
00585 uint32_t options) const;
00586
00600 inline int8_t caseCompareBetween(UTextOffset start,
00601 UTextOffset limit,
00602 const UnicodeString& srcText,
00603 UTextOffset srcStart,
00604 UTextOffset srcLimit,
00605 uint32_t options) const;
00606
00614 inline UBool startsWith(const UnicodeString& text) const;
00615
00626 inline UBool startsWith(const UnicodeString& srcText,
00627 UTextOffset srcStart,
00628 int32_t srcLength) const;
00629
00638 inline UBool startsWith(const UChar *srcChars,
00639 int32_t srcLength) const;
00640
00650 inline UBool startsWith(const UChar *srcChars,
00651 UTextOffset srcStart,
00652 int32_t srcLength) const;
00653
00661 inline UBool endsWith(const UnicodeString& text) const;
00662
00673 inline UBool endsWith(const UnicodeString& srcText,
00674 UTextOffset srcStart,
00675 int32_t srcLength) const;
00676
00685 inline UBool endsWith(const UChar *srcChars,
00686 int32_t srcLength) const;
00687
00698 inline UBool endsWith(const UChar *srcChars,
00699 UTextOffset srcStart,
00700 int32_t srcLength) const;
00701
00702
00703
00704
00713 inline UTextOffset indexOf(const UnicodeString& text) const;
00714
00724 inline UTextOffset indexOf(const UnicodeString& text,
00725 UTextOffset start) const;
00726
00738 inline UTextOffset indexOf(const UnicodeString& text,
00739 UTextOffset start,
00740 int32_t length) const;
00741
00758 inline UTextOffset indexOf(const UnicodeString& srcText,
00759 UTextOffset srcStart,
00760 int32_t srcLength,
00761 UTextOffset start,
00762 int32_t length) const;
00763
00775 inline UTextOffset indexOf(const UChar *srcChars,
00776 int32_t srcLength,
00777 UTextOffset start) const;
00778
00791 inline UTextOffset indexOf(const UChar *srcChars,
00792 int32_t srcLength,
00793 UTextOffset start,
00794 int32_t length) const;
00795
00812 UTextOffset indexOf(const UChar *srcChars,
00813 UTextOffset srcStart,
00814 int32_t srcLength,
00815 UTextOffset start,
00816 int32_t length) const;
00817
00825 inline UTextOffset indexOf(UChar c) const;
00826
00834 inline UTextOffset indexOf(UChar32 c) const;
00835
00844 inline UTextOffset indexOf(UChar c,
00845 UTextOffset start) const;
00846
00855 inline UTextOffset indexOf(UChar32 c,
00856 UTextOffset start) const;
00857
00868 inline UTextOffset indexOf(UChar c,
00869 UTextOffset start,
00870 int32_t length) const;
00871
00882 inline UTextOffset indexOf(UChar32 c,
00883 UTextOffset start,
00884 int32_t length) const;
00885
00894 inline UTextOffset lastIndexOf(const UnicodeString& text) const;
00895
00905 inline UTextOffset lastIndexOf(const UnicodeString& text,
00906 UTextOffset start) const;
00907
00919 inline UTextOffset lastIndexOf(const UnicodeString& text,
00920 UTextOffset start,
00921 int32_t length) const;
00922
00939 inline UTextOffset lastIndexOf(const UnicodeString& srcText,
00940 UTextOffset srcStart,
00941 int32_t srcLength,
00942 UTextOffset start,
00943 int32_t length) const;
00944
00955 inline UTextOffset lastIndexOf(const UChar *srcChars,
00956 int32_t srcLength,
00957 UTextOffset start) const;
00958
00971 inline UTextOffset lastIndexOf(const UChar *srcChars,
00972 int32_t srcLength,
00973 UTextOffset start,
00974 int32_t length) const;
00975
00992 UTextOffset lastIndexOf(const UChar *srcChars,
00993 UTextOffset srcStart,
00994 int32_t srcLength,
00995 UTextOffset start,
00996 int32_t length) const;
00997
01005 inline UTextOffset lastIndexOf(UChar c) const;
01006
01014 inline UTextOffset lastIndexOf(UChar32 c) const;
01015
01024 inline UTextOffset lastIndexOf(UChar c,
01025 UTextOffset start) const;
01026
01035 inline UTextOffset lastIndexOf(UChar32 c,
01036 UTextOffset start) const;
01037
01048 inline UTextOffset lastIndexOf(UChar c,
01049 UTextOffset start,
01050 int32_t length) const;
01051
01062 inline UTextOffset lastIndexOf(UChar32 c,
01063 UTextOffset start,
01064 int32_t length) const;
01065
01066
01067
01068
01075 inline UChar charAt(UTextOffset offset) const;
01076
01083 inline UChar operator [] (UTextOffset offset) const;
01084
01094 inline UChar32 char32At(UTextOffset offset) const;
01095
01110 inline UTextOffset getChar32Start(UTextOffset offset) const;
01111
01132 inline UTextOffset getCharStart(UTextOffset offset) const;
01133
01149 inline UTextOffset getChar32Limit(UTextOffset offset) const;
01150
01172 inline UTextOffset getCharLimit(UTextOffset offset) const;
01173
01215 UTextOffset moveIndex32(UTextOffset index, int32_t delta) const;
01216
01217
01218
01234 inline void extract(UTextOffset start,
01235 int32_t length,
01236 UChar *dst,
01237 UTextOffset dstStart = 0) const;
01238
01260 int32_t
01261 extract(UChar *dest, int32_t destCapacity,
01262 UErrorCode &errorCode) const;
01263
01274 inline void extract(UTextOffset start,
01275 int32_t length,
01276 UnicodeString& target) const;
01277
01289 inline void extractBetween(UTextOffset start,
01290 UTextOffset limit,
01291 UChar *dst,
01292 UTextOffset dstStart = 0) const;
01293
01303 inline void extractBetween(UTextOffset start,
01304 UTextOffset limit,
01305 UnicodeString& target) const;
01306
01327 inline int32_t extract(UTextOffset start,
01328 int32_t startLength,
01329 char *target,
01330 const char *codepage = 0) const;
01331
01356 int32_t extract(UTextOffset start,
01357 int32_t startLength,
01358 char *target,
01359 uint32_t targetLength,
01360 const char *codepage = 0) const;
01361
01379 int32_t extract(char *dest, int32_t destCapacity,
01380 UConverter *cnv,
01381 UErrorCode &errorCode) const;
01382
01383
01384
01391 inline int32_t length(void) const;
01392
01405 int32_t
01406 countChar32(UTextOffset start=0, int32_t length=0x7fffffff) const;
01407
01413 inline UBool isEmpty(void) const;
01414
01424 inline UBool empty(void) const;
01425
01435 inline int32_t getCapacity(void) const;
01436
01437
01438
01444 inline int32_t hashCode(void) const;
01445
01452 inline UBool isBogus(void) const;
01453
01454
01455
01456
01457
01458
01459
01460
01468 UnicodeString& operator= (const UnicodeString& srcText);
01469
01477 inline UnicodeString& operator= (UChar ch);
01478
01486 inline UnicodeString& operator= (UChar32 ch);
01487
01501 inline UnicodeString& setTo(const UnicodeString& srcText,
01502 UTextOffset srcStart,
01503 int32_t srcLength);
01504
01513 inline UnicodeString& setTo(const UnicodeString& srcText);
01514
01523 inline UnicodeString& setTo(const UChar *srcChars,
01524 int32_t srcLength);
01525
01534 UnicodeString& setTo(UChar srcChar);
01535
01544 UnicodeString& setTo(UChar32 srcChar);
01545
01565 UnicodeString &setTo(UBool isTerminated,
01566 const UChar *text,
01567 int32_t textLength);
01568
01587 UnicodeString &setTo(UChar *buffer,
01588 int32_t buffLength,
01589 int32_t buffCapacity);
01590
01612 void setToBogus();
01613
01621 UnicodeString& setCharAt(UTextOffset offset,
01622 UChar ch);
01623
01624
01625
01626
01634 inline UnicodeString& operator+= (UChar ch);
01635
01643 inline UnicodeString& operator+= (UChar32 ch);
01644
01653 inline UnicodeString& operator+= (const UnicodeString& srcText);
01654
01669 inline UnicodeString& append(const UnicodeString& srcText,
01670 UTextOffset srcStart,
01671 int32_t srcLength);
01672
01680 inline UnicodeString& append(const UnicodeString& srcText);
01681
01695 inline UnicodeString& append(const UChar *srcChars,
01696 UTextOffset srcStart,
01697 int32_t srcLength);
01698
01707 inline UnicodeString& append(const UChar *srcChars,
01708 int32_t srcLength);
01709
01716 inline UnicodeString& append(UChar srcChar);
01717
01724 inline UnicodeString& append(UChar32 srcChar);
01725
01726
01727
01728
01742 inline UnicodeString& insert(UTextOffset start,
01743 const UnicodeString& srcText,
01744 UTextOffset srcStart,
01745 int32_t srcLength);
01746
01755 inline UnicodeString& insert(UTextOffset start,
01756 const UnicodeString& srcText);
01757
01771 inline UnicodeString& insert(UTextOffset start,
01772 const UChar *srcChars,
01773 UTextOffset srcStart,
01774 int32_t srcLength);
01775
01785 inline UnicodeString& insert(UTextOffset start,
01786 const UChar *srcChars,
01787 int32_t srcLength);
01788
01797 inline UnicodeString& insert(UTextOffset start,
01798 UChar srcChar);
01799
01808 inline UnicodeString& insert(UTextOffset start,
01809 UChar32 srcChar);
01810
01811
01812
01813
01831 UnicodeString& replace(UTextOffset start,
01832 int32_t length,
01833 const UnicodeString& srcText,
01834 UTextOffset srcStart,
01835 int32_t srcLength);
01836
01849 UnicodeString& replace(UTextOffset start,
01850 int32_t length,
01851 const UnicodeString& srcText);
01852
01870 UnicodeString& replace(UTextOffset start,
01871 int32_t length,
01872 const UChar *srcChars,
01873 UTextOffset srcStart,
01874 int32_t srcLength);
01875
01888 inline UnicodeString& replace(UTextOffset start,
01889 int32_t length,
01890 const UChar *srcChars,
01891 int32_t srcLength);
01892
01904 inline UnicodeString& replace(UTextOffset start,
01905 int32_t length,
01906 UChar srcChar);
01907
01919 inline UnicodeString& replace(UTextOffset start,
01920 int32_t length,
01921 UChar32 srcChar);
01922
01932 inline UnicodeString& replaceBetween(UTextOffset start,
01933 UTextOffset limit,
01934 const UnicodeString& srcText);
01935
01950 inline UnicodeString& replaceBetween(UTextOffset start,
01951 UTextOffset limit,
01952 const UnicodeString& srcText,
01953 UTextOffset srcStart,
01954 UTextOffset srcLimit);
01955
01966 virtual void handleReplaceBetween(UTextOffset start,
01967 UTextOffset limit,
01968 const UnicodeString& text);
01969
01985 virtual void copy(int32_t start, int32_t limit, int32_t dest);
01986
01987
01988
01997 inline UnicodeString& findAndReplace(const UnicodeString& oldText,
01998 const UnicodeString& newText);
01999
02011 inline UnicodeString& findAndReplace(UTextOffset start,
02012 int32_t length,
02013 const UnicodeString& oldText,
02014 const UnicodeString& newText);
02015
02033 UnicodeString& findAndReplace(UTextOffset start,
02034 int32_t length,
02035 const UnicodeString& oldText,
02036 UTextOffset oldStart,
02037 int32_t oldLength,
02038 const UnicodeString& newText,
02039 UTextOffset newStart,
02040 int32_t newLength);
02041
02042
02043
02044
02050 inline UnicodeString& remove(void);
02051
02060 inline UnicodeString& remove(UTextOffset start,
02061 int32_t length = (int32_t)INT32_MAX);
02062
02071 inline UnicodeString& removeBetween(UTextOffset start,
02072 UTextOffset limit = (int32_t)INT32_MAX);
02073
02074
02075
02076
02088 UBool padLeading(int32_t targetLength,
02089 UChar padChar = 0x0020);
02090
02102 UBool padTrailing(int32_t targetLength,
02103 UChar padChar = 0x0020);
02104
02111 inline UBool truncate(int32_t targetLength);
02112
02118 UnicodeString& trim(void);
02119
02120
02121
02122
02128 inline UnicodeString& reverse(void);
02129
02138 inline UnicodeString& reverse(UTextOffset start,
02139 int32_t length);
02140
02147 UnicodeString& toUpper(void);
02148
02156 UnicodeString& toUpper(const Locale& locale);
02157
02164 UnicodeString& toLower(void);
02165
02173 UnicodeString& toLower(const Locale& locale);
02174
02186 UnicodeString &foldCase(uint32_t options=0 );
02187
02188
02189
02190
02191
02231 UChar *getBuffer(int32_t minCapacity);
02232
02253 void releaseBuffer(int32_t newLength=-1);
02254
02283 inline const UChar *getBuffer() const;
02284
02285
02286
02287
02288
02292 UnicodeString();
02293
02305 UnicodeString(int32_t capacity, UChar32 c, int32_t count);
02306
02312 UnicodeString(UChar ch);
02313
02319 UnicodeString(UChar32 ch);
02320
02327 UnicodeString(const UChar *text);
02328
02336 UnicodeString(const UChar *text,
02337 int32_t textLength);
02338
02358 UnicodeString(UBool isTerminated,
02359 const UChar *text,
02360 int32_t textLength);
02361
02380 UnicodeString(UChar *buffer, int32_t buffLength, int32_t buffCapacity);
02381
02393 UnicodeString(const char *codepageData,
02394 const char *codepage = 0);
02395
02408 UnicodeString(const char *codepageData,
02409 int32_t dataLength,
02410 const char *codepage = 0);
02411
02433 UnicodeString(
02434 const char *src, int32_t srcLength,
02435 UConverter *cnv,
02436 UErrorCode &errorCode);
02437
02438
02444 UnicodeString(const UnicodeString& that);
02445
02449 ~UnicodeString();
02450
02451
02452
02453
02476 int32_t numDisplayCells(UTextOffset start = 0,
02477 int32_t length = INT32_MAX,
02478 UBool asian = TRUE) const;
02479
02487 UCharReference operator[] (UTextOffset pos);
02488
02522 UnicodeString unescape() const;
02523
02543 UChar32 unescapeAt(int32_t &offset) const;
02544
02545
02546
02547
02548
02549 protected:
02553 virtual int32_t getLength() const;
02554
02559 virtual UChar getCharAt(UTextOffset offset) const;
02560
02565 virtual UChar32 getChar32At(UTextOffset offset) const;
02566
02567 private:
02568
02569 inline int8_t
02570 doCompare(UTextOffset start,
02571 int32_t length,
02572 const UnicodeString& srcText,
02573 UTextOffset srcStart,
02574 int32_t srcLength) const;
02575
02576 int8_t doCompare(UTextOffset start,
02577 int32_t length,
02578 const UChar *srcChars,
02579 UTextOffset srcStart,
02580 int32_t srcLength) const;
02581
02582 inline int8_t
02583 doCompareCodePointOrder(UTextOffset start,
02584 int32_t length,
02585 const UnicodeString& srcText,
02586 UTextOffset srcStart,
02587 int32_t srcLength) const;
02588
02589 int8_t doCompareCodePointOrder(UTextOffset start,
02590 int32_t length,
02591 const UChar *srcChars,
02592 UTextOffset srcStart,
02593 int32_t srcLength) const;
02594
02595 inline int8_t
02596 doCaseCompare(UTextOffset start,
02597 int32_t length,
02598 const UnicodeString &srcText,
02599 UTextOffset srcStart,
02600 int32_t srcLength,
02601 uint32_t options) const;
02602
02603 int8_t
02604 doCaseCompare(UTextOffset start,
02605 int32_t length,
02606 const UChar *srcChars,
02607 UTextOffset srcStart,
02608 int32_t srcLength,
02609 uint32_t options) const;
02610
02611 UTextOffset doIndexOf(UChar c,
02612 UTextOffset start,
02613 int32_t length) const;
02614
02615 UTextOffset doLastIndexOf(UChar c,
02616 UTextOffset start,
02617 int32_t length) const;
02618
02619 void doExtract(UTextOffset start,
02620 int32_t length,
02621 UChar *dst,
02622 UTextOffset dstStart) const;
02623
02624 inline void doExtract(UTextOffset start,
02625 int32_t length,
02626 UnicodeString& target) const;
02627
02628 inline UChar doCharAt(UTextOffset offset) const;
02629
02630 UnicodeString& doReplace(UTextOffset start,
02631 int32_t length,
02632 const UnicodeString& srcText,
02633 UTextOffset srcStart,
02634 int32_t srcLength);
02635
02636 UnicodeString& doReplace(UTextOffset start,
02637 int32_t length,
02638 const UChar *srcChars,
02639 UTextOffset srcStart,
02640 int32_t srcLength);
02641
02642 UnicodeString& doReverse(UTextOffset start,
02643 int32_t length);
02644
02645
02646 int32_t doHashCode(void) const;
02647
02648
02649 inline UChar* getArrayStart(void);
02650 inline const UChar* getArrayStart(void) const;
02651
02652
02653
02654
02655
02656 UBool allocate(int32_t capacity);
02657
02658
02659 inline void releaseArray();
02660
02661
02662 inline void pinIndices(UTextOffset& start,
02663 int32_t& length) const;
02664
02665
02666 int32_t doExtract(UTextOffset start, int32_t length,
02667 char *dest, int32_t destCapacity,
02668 UConverter *cnv,
02669 UErrorCode &errorCode) const;
02670
02671
02672
02673
02674
02675
02676
02677
02678
02679
02680
02681 void doCodepageCreate(const char *codepageData,
02682 int32_t dataLength,
02683 const char *codepage);
02684
02685
02686
02687
02688
02689 void
02690 doCodepageCreate(const char *codepageData,
02691 int32_t dataLength,
02692 UConverter *converter,
02693 UErrorCode &status);
02694
02695
02696
02697
02698
02699
02700
02701
02702
02703
02704
02705 UBool cloneArrayIfNeeded(int32_t newCapacity = -1,
02706 int32_t growCapacity = -1,
02707 UBool doCopyArray = TRUE,
02708 int32_t **pBufferToDelete = 0,
02709 UBool forceClone = FALSE);
02710
02711
02712 static UBool U_CALLCONV
02713 growBuffer(void *context,
02714 UChar **buffer, int32_t *pCapacity, int32_t reqCapacity,
02715 int32_t length);
02716
02717
02718 UnicodeString &
02719 caseMap(const Locale& locale,
02720 uint32_t options,
02721 int32_t toWhichCase);
02722
02723
02724 inline int32_t addRef(void);
02725 inline int32_t removeRef(void);
02726 inline int32_t refCount(void) const;
02727 inline int32_t setRefCount(int32_t count);
02728
02729
02730 enum {
02731 #if UTF_SIZE==8
02732 US_STACKBUF_SIZE=14,
02733 #elif UTF_SIZE==16
02734 US_STACKBUF_SIZE=7,
02735 #else // UTF_SIZE==32
02736 US_STACKBUF_SIZE=3,
02737 #endif
02738 kInvalidUChar=0xffff,
02739 kGrowSize=128,
02740 kInvalidHashCode=0,
02741 kEmptyHashCode=1,
02742
02743
02744 kIsBogus=1,
02745 kUsingStackBuffer=2,
02746 kRefCounted=4,
02747 kBufferIsReadonly=8,
02748 kOpenGetBuffer=16,
02749
02750
02751
02752 kShortString=kUsingStackBuffer,
02753 kLongString=kRefCounted,
02754 kReadonlyAlias=kBufferIsReadonly,
02755 kWritableAlias=0
02756 };
02757
02758 friend class UnicodeConverter;
02759
02760 friend class StringCharacterIterator;
02761 friend class SearchIterator;
02762 friend class StringSearch;
02763
02764
02765
02766
02767
02768
02769
02770
02771
02772
02773
02774
02775
02776 int32_t fLength;
02777 int32_t fCapacity;
02778 UChar *fArray;
02779 uint16_t fFlags;
02780 #if UTF_SIZE==32
02781 uint16_t fPadding;
02782 #endif
02783 UChar fStackBuffer [ US_STACKBUF_SIZE ];
02784 };
02785
02786 U_NAMESPACE_END
02787
02788
02789
02790
02791
02792 inline void
02793 uprv_arrayCopy(const U_NAMESPACE_QUALIFIER UnicodeString *src, U_NAMESPACE_QUALIFIER UnicodeString *dst, int32_t count)
02794 { while(count-- > 0) *dst++ = *src++; }
02795
02796 inline void
02797 uprv_arrayCopy(const U_NAMESPACE_QUALIFIER UnicodeString *src, int32_t srcStart,
02798 U_NAMESPACE_QUALIFIER UnicodeString *dst, int32_t dstStart, int32_t count)
02799 { uprv_arrayCopy(src+srcStart, dst+dstStart, count); }
02800
02801 U_NAMESPACE_BEGIN
02802
02803
02804
02805
02806
02807
02808
02809 inline UBool
02810 UnicodeString::operator== (const UnicodeString& text) const
02811 {
02812 if(isBogus()) {
02813 return text.isBogus();
02814 } else {
02815 return
02816 !text.isBogus() &&
02817 fLength == text.fLength &&
02818 doCompare(0, fLength, text, 0, text.fLength) == 0;
02819 }
02820 }
02821
02822 inline UBool
02823 UnicodeString::operator!= (const UnicodeString& text) const
02824 { return (! operator==(text)); }
02825
02826 inline UBool
02827 UnicodeString::operator> (const UnicodeString& text) const
02828 { return doCompare(0, fLength, text, 0, text.fLength) == 1; }
02829
02830 inline UBool
02831 UnicodeString::operator< (const UnicodeString& text) const
02832 { return doCompare(0, fLength, text, 0, text.fLength) == -1; }
02833
02834 inline UBool
02835 UnicodeString::operator>= (const UnicodeString& text) const
02836 { return doCompare(0, fLength, text, 0, text.fLength) != -1; }
02837
02838 inline UBool
02839 UnicodeString::operator<= (const UnicodeString& text) const
02840 { return doCompare(0, fLength, text, 0, text.fLength) != 1; }
02841
02842 inline int8_t
02843 UnicodeString::compare(const UnicodeString& text) const
02844 { return doCompare(0, fLength, text, 0, text.fLength); }
02845
02846 inline int8_t
02847 UnicodeString::compare(UTextOffset start,
02848 int32_t length,
02849 const UnicodeString& srcText) const
02850 { return doCompare(start, length, srcText, 0, srcText.fLength); }
02851
02852 inline int8_t
02853 UnicodeString::compare(const UChar *srcChars,
02854 int32_t srcLength) const
02855 { return doCompare(0, fLength, srcChars, 0, srcLength); }
02856
02857 inline int8_t
02858 UnicodeString::compare(UTextOffset start,
02859 int32_t length,
02860 const UnicodeString& srcText,
02861 UTextOffset srcStart,
02862 int32_t srcLength) const
02863 { return doCompare(start, length, srcText, srcStart, srcLength); }
02864
02865 inline int8_t
02866 UnicodeString::compare(UTextOffset start,
02867 int32_t length,
02868 const UChar *srcChars) const
02869 { return doCompare(start, length, srcChars, 0, length); }
02870
02871 inline int8_t
02872 UnicodeString::compare(UTextOffset start,
02873 int32_t length,
02874 const UChar *srcChars,
02875 UTextOffset srcStart,
02876 int32_t srcLength) const
02877 { return doCompare(start, length, srcChars, srcStart, srcLength); }
02878
02879 inline int8_t
02880 UnicodeString::compareBetween(UTextOffset start,
02881 UTextOffset limit,
02882 const UnicodeString& srcText,
02883 UTextOffset srcStart,
02884 UTextOffset srcLimit) const
02885 { return doCompare(start, limit - start,
02886 srcText, srcStart, srcLimit - srcStart); }
02887
02888 inline int8_t
02889 UnicodeString::doCompare(UTextOffset start,
02890 int32_t length,
02891 const UnicodeString& srcText,
02892 UTextOffset srcStart,
02893 int32_t srcLength) const
02894 {
02895 const UChar *srcChars;
02896 if(!srcText.isBogus()) {
02897 srcText.pinIndices(srcStart, srcLength);
02898 srcChars=srcText.getArrayStart();
02899 } else {
02900 srcChars=0;
02901 }
02902 return doCompare(start, length, srcChars, srcStart, srcLength);
02903 }
02904
02905 inline int8_t
02906 UnicodeString::compareCodePointOrder(const UnicodeString& text) const
02907 { return doCompareCodePointOrder(0, fLength, text, 0, text.fLength); }
02908
02909 inline int8_t
02910 UnicodeString::compareCodePointOrder(UTextOffset start,
02911 int32_t length,
02912 const UnicodeString& srcText) const
02913 { return doCompareCodePointOrder(start, length, srcText, 0, srcText.fLength); }
02914
02915 inline int8_t
02916 UnicodeString::compareCodePointOrder(const UChar *srcChars,
02917 int32_t srcLength) const
02918 { return doCompareCodePointOrder(0, fLength, srcChars, 0, srcLength); }
02919
02920 inline int8_t
02921 UnicodeString::compareCodePointOrder(UTextOffset start,
02922 int32_t length,
02923 const UnicodeString& srcText,
02924 UTextOffset srcStart,
02925 int32_t srcLength) const
02926 { return doCompareCodePointOrder(start, length, srcText, srcStart, srcLength); }
02927
02928 inline int8_t
02929 UnicodeString::compareCodePointOrder(UTextOffset start,
02930 int32_t length,
02931 const UChar *srcChars) const
02932 { return doCompareCodePointOrder(start, length, srcChars, 0, length); }
02933
02934 inline int8_t
02935 UnicodeString::compareCodePointOrder(UTextOffset start,
02936 int32_t length,
02937 const UChar *srcChars,
02938 UTextOffset srcStart,
02939 int32_t srcLength) const
02940 { return doCompareCodePointOrder(start, length, srcChars, srcStart, srcLength); }
02941
02942 inline int8_t
02943 UnicodeString::compareCodePointOrderBetween(UTextOffset start,
02944 UTextOffset limit,
02945 const UnicodeString& srcText,
02946 UTextOffset srcStart,
02947 UTextOffset srcLimit) const
02948 { return doCompareCodePointOrder(start, limit - start,
02949 srcText, srcStart, srcLimit - srcStart); }
02950
02951 inline int8_t
02952 UnicodeString::doCompareCodePointOrder(UTextOffset start,
02953 int32_t length,
02954 const UnicodeString& srcText,
02955 UTextOffset srcStart,
02956 int32_t srcLength) const
02957 {
02958 const UChar *srcChars;
02959 if(!srcText.isBogus()) {
02960 srcText.pinIndices(srcStart, srcLength);
02961 srcChars=srcText.getArrayStart();
02962 } else {
02963 srcChars=0;
02964 }
02965 return doCompareCodePointOrder(start, length, srcChars, srcStart, srcLength);
02966 }
02967
02968 inline int8_t
02969 UnicodeString::caseCompare(const UnicodeString &text, uint32_t options) const {
02970 return doCaseCompare(0, fLength, text, 0, text.fLength, options);
02971 }
02972
02973 inline int8_t
02974 UnicodeString::caseCompare(UTextOffset start,
02975 int32_t length,
02976 const UnicodeString &srcText,
02977 uint32_t options) const {
02978 return doCaseCompare(start, length, srcText, 0, srcText.fLength, options);
02979 }
02980
02981 inline int8_t
02982 UnicodeString::caseCompare(const UChar *srcChars,
02983 int32_t srcLength,
02984 uint32_t options) const {
02985 return doCaseCompare(0, fLength, srcChars, 0, srcLength, options);
02986 }
02987
02988 inline int8_t
02989 UnicodeString::caseCompare(UTextOffset start,
02990 int32_t length,
02991 const UnicodeString &srcText,
02992 UTextOffset srcStart,
02993 int32_t srcLength,
02994 uint32_t options) const {
02995 return doCaseCompare(start, length, srcText, srcStart, srcLength, options);
02996 }
02997
02998 inline int8_t
02999 UnicodeString::caseCompare(UTextOffset start,
03000 int32_t length,
03001 const UChar *srcChars,
03002 uint32_t options) const {
03003 return doCaseCompare(start, length, srcChars, 0, length, options);
03004 }
03005
03006 inline int8_t
03007 UnicodeString::caseCompare(UTextOffset start,
03008 int32_t length,
03009 const UChar *srcChars,
03010 UTextOffset srcStart,
03011 int32_t srcLength,
03012 uint32_t options) const {
03013 return doCaseCompare(start, length, srcChars, srcStart, srcLength, options);
03014 }
03015
03016 inline int8_t
03017 UnicodeString::caseCompareBetween(UTextOffset start,
03018 UTextOffset limit,
03019 const UnicodeString &srcText,
03020 UTextOffset srcStart,
03021 UTextOffset srcLimit,
03022 uint32_t options) const {
03023 return doCaseCompare(start, limit - start, srcText, srcStart, srcLimit - srcStart, options);
03024 }
03025
03026 inline int8_t
03027 UnicodeString::doCaseCompare(UTextOffset start,
03028 int32_t length,
03029 const UnicodeString &srcText,
03030 UTextOffset srcStart,
03031 int32_t srcLength,
03032 uint32_t options) const
03033 {
03034 const UChar *srcChars;
03035 if(!srcText.isBogus()) {
03036 srcText.pinIndices(srcStart, srcLength);
03037 srcChars=srcText.getArrayStart();
03038 } else {
03039 srcChars=0;
03040 }
03041 return doCaseCompare(start, length, srcChars, srcStart, srcLength, options);
03042 }
03043
03044 inline UTextOffset
03045 UnicodeString::indexOf(const UnicodeString& text) const
03046 { return indexOf(text, 0, text.fLength, 0, fLength); }
03047
03048 inline UTextOffset
03049 UnicodeString::indexOf(const UnicodeString& text,
03050 UTextOffset start) const
03051 { return indexOf(text, 0, text.fLength, start, fLength - start); }
03052
03053 inline UTextOffset
03054 UnicodeString::indexOf(const UnicodeString& text,
03055 UTextOffset start,
03056 int32_t length) const
03057 { return indexOf(text, 0, text.fLength, start, length); }
03058
03059 inline UTextOffset
03060 UnicodeString::indexOf(const UnicodeString& srcText,
03061 UTextOffset srcStart,
03062 int32_t srcLength,
03063 UTextOffset start,
03064 int32_t length) const
03065 {
03066 if(!srcText.isBogus()) {
03067 srcText.pinIndices(srcStart, srcLength);
03068 if(srcLength > 0) {
03069 return indexOf(srcText.getArrayStart(), srcStart, srcLength, start, length);
03070 }
03071 }
03072 return -1;
03073 }
03074
03075 inline UTextOffset
03076 UnicodeString::indexOf(const UChar *srcChars,
03077 int32_t srcLength,
03078 UTextOffset start) const
03079 { return indexOf(srcChars, 0, srcLength, start, fLength - start); }
03080
03081 inline UTextOffset
03082 UnicodeString::indexOf(const UChar *srcChars,
03083 int32_t srcLength,
03084 UTextOffset start,
03085 int32_t length) const
03086 { return indexOf(srcChars, 0, srcLength, start, length); }
03087
03088 inline UTextOffset
03089 UnicodeString::indexOf(UChar c) const
03090 { return doIndexOf(c, 0, fLength); }
03091
03092 inline UTextOffset
03093 UnicodeString::indexOf(UChar32 c) const {
03094 if(!UTF_NEED_MULTIPLE_UCHAR(c)) {
03095 return doIndexOf((UChar)c, 0, fLength);
03096 } else {
03097 UChar buffer[UTF_MAX_CHAR_LENGTH];
03098 int32_t length = 0;
03099 UTF_APPEND_CHAR_UNSAFE(buffer, length, c);
03100 return indexOf(buffer, length, 0);
03101 }
03102 }
03103
03104 inline UTextOffset
03105 UnicodeString::indexOf(UChar c,
03106 UTextOffset start) const
03107 { return doIndexOf(c, start, fLength - start); }
03108
03109 inline UTextOffset
03110 UnicodeString::indexOf(UChar32 c,
03111 UTextOffset start) const {
03112 if(!UTF_NEED_MULTIPLE_UCHAR(c)) {
03113 return doIndexOf((UChar)c, start, fLength - start);
03114 } else {
03115 UChar buffer[UTF_MAX_CHAR_LENGTH];
03116 int32_t length = 0;
03117 UTF_APPEND_CHAR_UNSAFE(buffer, length, c);
03118 return indexOf(buffer, length, start);
03119 }
03120 }
03121
03122 inline UTextOffset
03123 UnicodeString::indexOf(UChar c,
03124 UTextOffset start,
03125 int32_t length) const
03126 { return doIndexOf(c, start, length); }
03127
03128 inline UTextOffset
03129 UnicodeString::indexOf(UChar32 c,
03130 UTextOffset start,
03131 int32_t length) const {
03132 if(!UTF_NEED_MULTIPLE_UCHAR(c)) {
03133 return doIndexOf((UChar)c, start, length);
03134 } else {
03135 UChar buffer[UTF_MAX_CHAR_LENGTH];
03136 int32_t cLength = 0;
03137 UTF_APPEND_CHAR_UNSAFE(buffer, cLength, c);
03138 return indexOf(buffer, cLength, start, length);
03139 }
03140 }
03141
03142 inline UTextOffset
03143 UnicodeString::lastIndexOf(const UnicodeString& text) const
03144 { return lastIndexOf(text, 0, text.fLength, 0, fLength); }
03145
03146 inline UTextOffset
03147 UnicodeString::lastIndexOf(const UnicodeString& text,
03148 UTextOffset start) const
03149 { return lastIndexOf(text, 0, text.fLength, start, fLength - start); }
03150
03151 inline UTextOffset
03152 UnicodeString::lastIndexOf(const UnicodeString& text,
03153 UTextOffset start,
03154 int32_t length) const
03155 { return lastIndexOf(text, 0, text.fLength, start, length); }
03156
03157 inline UTextOffset
03158 UnicodeString::lastIndexOf(const UnicodeString& srcText,
03159 UTextOffset srcStart,
03160 int32_t srcLength,
03161 UTextOffset start,
03162 int32_t length) const
03163 {
03164 if(!srcText.isBogus()) {
03165 srcText.pinIndices(srcStart, srcLength);
03166 if(srcLength > 0) {
03167 return lastIndexOf(srcText.getArrayStart(), srcStart, srcLength, start, length);
03168 }
03169 }
03170 return -1;
03171 }
03172
03173 inline UTextOffset
03174 UnicodeString::lastIndexOf(const UChar *srcChars,
03175 int32_t srcLength,
03176 UTextOffset start) const
03177 { return lastIndexOf(srcChars, 0, srcLength, start, fLength - start); }
03178
03179 inline UTextOffset
03180 UnicodeString::lastIndexOf(const UChar *srcChars,
03181 int32_t srcLength,
03182 UTextOffset start,
03183 int32_t length) const
03184 { return lastIndexOf(srcChars, 0, srcLength, start, length); }
03185
03186 inline UTextOffset
03187 UnicodeString::lastIndexOf(UChar c) const
03188 { return doLastIndexOf(c, 0, fLength); }
03189
03190 inline UTextOffset
03191 UnicodeString::lastIndexOf(UChar32 c) const {
03192 if(!UTF_NEED_MULTIPLE_UCHAR(c)) {
03193 return doLastIndexOf((UChar)c, 0, fLength);
03194 } else {
03195 UChar buffer[UTF_MAX_CHAR_LENGTH];
03196 int32_t count = 0;
03197 UTF_APPEND_CHAR_UNSAFE(buffer, count, c);
03198 return lastIndexOf(buffer, count, 0);
03199 }
03200 }
03201
03202 inline UTextOffset
03203 UnicodeString::lastIndexOf(UChar c,
03204 UTextOffset start) const
03205 { return doLastIndexOf(c, start, fLength - start); }
03206
03207 inline UTextOffset
03208 UnicodeString::lastIndexOf(UChar32 c,
03209 UTextOffset start) const {
03210 if(!UTF_NEED_MULTIPLE_UCHAR(c)) {
03211 return doLastIndexOf((UChar)c, start, fLength - start);
03212 } else {
03213 UChar buffer[UTF_MAX_CHAR_LENGTH];
03214 int32_t count = 0;
03215 UTF_APPEND_CHAR_UNSAFE(buffer, count, c);
03216 return lastIndexOf(buffer, count, start);
03217 }
03218 }
03219
03220 inline UTextOffset
03221 UnicodeString::lastIndexOf(UChar c,
03222 UTextOffset start,
03223 int32_t length) const
03224 { return doLastIndexOf(c, start, length); }
03225
03226 inline UTextOffset
03227 UnicodeString::lastIndexOf(UChar32 c,
03228 UTextOffset start,
03229 int32_t length) const {
03230 if(!UTF_NEED_MULTIPLE_UCHAR(c)) {
03231 return doLastIndexOf((UChar)c, start, length);
03232 } else {
03233 UChar buffer[UTF_MAX_CHAR_LENGTH];
03234 int32_t count = 0;
03235 UTF_APPEND_CHAR_UNSAFE(buffer, count, c);
03236 return lastIndexOf(buffer, count, start, length);
03237 }
03238 }
03239
03240 inline UBool
03241 UnicodeString::startsWith(const UnicodeString& text) const
03242 { return compare(0, text.fLength, text, 0, text.fLength) == 0; }
03243
03244 inline UBool
03245 UnicodeString::startsWith(const UnicodeString& srcText,
03246 UTextOffset srcStart,
03247 int32_t srcLength) const
03248 { return doCompare(0, srcLength, srcText, srcStart, srcLength) == 0; }
03249
03250 inline UBool
03251 UnicodeString::startsWith(const UChar *srcChars,
03252 int32_t srcLength) const
03253 { return doCompare(0, srcLength, srcChars, 0, srcLength) == 0; }
03254
03255 inline UBool
03256 UnicodeString::startsWith(const UChar *srcChars,
03257 UTextOffset srcStart,
03258 int32_t srcLength) const
03259 { return doCompare(0, srcLength, srcChars, srcStart, srcLength) == 0;}
03260
03261 inline UBool
03262 UnicodeString::endsWith(const UnicodeString& text) const
03263 { return doCompare(fLength - text.fLength, text.fLength,
03264 text, 0, text.fLength) == 0; }
03265
03266 inline UBool
03267 UnicodeString::endsWith(const UnicodeString& srcText,
03268 UTextOffset srcStart,
03269 int32_t srcLength) const
03270 { return doCompare(fLength - srcLength, srcLength,
03271 srcText, srcStart, srcLength) == 0; }
03272
03273 inline UBool
03274 UnicodeString::endsWith(const UChar *srcChars,
03275 int32_t srcLength) const
03276 { return doCompare(fLength - srcLength, srcLength,
03277 srcChars, 0, srcLength) == 0; }
03278
03279 inline UBool
03280 UnicodeString::endsWith(const UChar *srcChars,
03281 UTextOffset srcStart,
03282 int32_t srcLength) const
03283 { return doCompare(fLength - srcLength, srcLength,
03284 srcChars, srcStart, srcLength) == 0;}
03285
03286
03287
03288 inline UnicodeString&
03289 UnicodeString::replace(UTextOffset start,
03290 int32_t length,
03291 const UnicodeString& srcText)
03292 { return doReplace(start, length, srcText, 0, srcText.fLength); }
03293
03294 inline UnicodeString&
03295 UnicodeString::replace(UTextOffset start,
03296 int32_t length,
03297 const UnicodeString& srcText,
03298 UTextOffset srcStart,
03299 int32_t srcLength)
03300 { return doReplace(start, length, srcText, srcStart, srcLength); }
03301
03302 inline UnicodeString&
03303 UnicodeString::replace(UTextOffset start,
03304 int32_t length,
03305 const UChar *srcChars,
03306 int32_t srcLength)
03307 { return doReplace(start, length, srcChars, 0, srcLength); }
03308
03309 inline UnicodeString&
03310 UnicodeString::replace(UTextOffset start,
03311 int32_t length,
03312 const UChar *srcChars,
03313 UTextOffset srcStart,
03314 int32_t srcLength)
03315 { return doReplace(start, length, srcChars, srcStart, srcLength); }
03316
03317 inline UnicodeString&
03318 UnicodeString::replace(UTextOffset start,
03319 int32_t length,
03320 UChar srcChar)
03321 { return doReplace(start, length, &srcChar, 0, 1); }
03322
03323 inline UnicodeString&
03324 UnicodeString::replace(UTextOffset start,
03325 int32_t length,
03326 UChar32 srcChar) {
03327 UChar buffer[UTF_MAX_CHAR_LENGTH];
03328 int32_t count = 0;
03329 UTF_APPEND_CHAR_UNSAFE(buffer, count, srcChar);
03330 return doReplace(start, length, buffer, 0, count);
03331 }
03332
03333 inline UnicodeString&
03334 UnicodeString::replaceBetween(UTextOffset start,
03335 UTextOffset limit,
03336 const UnicodeString& srcText)
03337 { return doReplace(start, limit - start, srcText, 0, srcText.fLength); }
03338
03339 inline UnicodeString&
03340 UnicodeString::replaceBetween(UTextOffset start,
03341 UTextOffset limit,
03342 const UnicodeString& srcText,
03343 UTextOffset srcStart,
03344 UTextOffset srcLimit)
03345 { return doReplace(start, limit - start, srcText, srcStart, srcLimit - srcStart); }
03346
03347 inline UnicodeString&
03348 UnicodeString::findAndReplace(const UnicodeString& oldText,
03349 const UnicodeString& newText)
03350 { return findAndReplace(0, fLength, oldText, 0, oldText.fLength,
03351 newText, 0, newText.fLength); }
03352
03353 inline UnicodeString&
03354 UnicodeString::findAndReplace(UTextOffset start,
03355 int32_t length,
03356 const UnicodeString& oldText,
03357 const UnicodeString& newText)
03358 { return findAndReplace(start, length, oldText, 0, oldText.fLength,
03359 newText, 0, newText.fLength); }
03360
03361
03362
03363
03364 inline void
03365 UnicodeString::doExtract(UTextOffset start,
03366 int32_t length,
03367 UnicodeString& target) const
03368 { target.replace(0, target.fLength, *this, start, length); }
03369
03370 inline void
03371 UnicodeString::extract(UTextOffset start,
03372 int32_t length,
03373 UChar *target,
03374 UTextOffset targetStart) const
03375 { doExtract(start, length, target, targetStart); }
03376
03377 inline void
03378 UnicodeString::extract(UTextOffset start,
03379 int32_t length,
03380 UnicodeString& target) const
03381 { doExtract(start, length, target); }
03382
03383 inline int32_t
03384 UnicodeString::extract(UTextOffset start,
03385 int32_t length,
03386 char *dst,
03387 const char *codepage) const
03388
03389 {
03390
03391 return extract(start, length, dst, dst!=0 ? 0xffffffff : 0, codepage);
03392 }
03393
03394 inline void
03395 UnicodeString::extractBetween(UTextOffset start,
03396 UTextOffset limit,
03397 UChar *dst,
03398 UTextOffset dstStart) const
03399 { doExtract(start, limit - start, dst, dstStart); }
03400
03401 inline void
03402 UnicodeString::extractBetween(UTextOffset start,
03403 UTextOffset limit,
03404 UnicodeString& target) const
03405 { doExtract(start, limit - start, target); }
03406
03407 inline UChar
03408 UnicodeString::doCharAt(UTextOffset offset) const
03409 {
03410 if((uint32_t)offset < (uint32_t)fLength) {
03411 return fArray[offset];
03412 } else {
03413 return kInvalidUChar;
03414 }
03415 }
03416
03417 inline UChar
03418 UnicodeString::charAt(UTextOffset offset) const
03419 { return doCharAt(offset); }
03420
03421 inline UChar
03422 UnicodeString::operator[] (UTextOffset offset) const
03423 { return doCharAt(offset); }
03424
03425 inline UChar32
03426 UnicodeString::char32At(UTextOffset offset) const
03427 {
03428 if((uint32_t)offset < (uint32_t)fLength) {
03429 UChar32 c;
03430 UTF_GET_CHAR(fArray, 0, offset, fLength, c);
03431 return c;
03432 } else {
03433 return kInvalidUChar;
03434 }
03435 }
03436
03437 inline UTextOffset
03438 UnicodeString::getChar32Start(UTextOffset offset) const {
03439 if((uint32_t)offset < (uint32_t)fLength) {
03440 UTF_SET_CHAR_START(fArray, 0, offset);
03441 return offset;
03442 } else {
03443 return 0;
03444 }
03445 }
03446
03447 inline UTextOffset
03448 UnicodeString::getChar32Limit(UTextOffset offset) const {
03449 if((uint32_t)offset < (uint32_t)fLength) {
03450 UTF_SET_CHAR_LIMIT(fArray, 0, offset, fLength);
03451 return offset;
03452 } else {
03453 return fLength;
03454 }
03455 }
03456
03457 inline UTextOffset
03458 UnicodeString::getCharStart(UTextOffset offset) const {
03459 return getChar32Start(offset);
03460 }
03461
03462 inline UTextOffset
03463 UnicodeString::getCharLimit(UTextOffset offset) const {
03464 return getChar32Limit(offset);
03465 }
03466
03467 inline UBool
03468 UnicodeString::isEmpty() const {
03469 return fLength == 0;
03470 }
03471
03472 inline UBool
03473 UnicodeString::empty() const {
03474 return isEmpty();
03475 }
03476
03477
03478
03479
03480 inline int32_t
03481 UnicodeString::length() const
03482 { return fLength; }
03483
03484 inline int32_t
03485 UnicodeString::hashCode() const
03486 { return doHashCode(); }
03487
03488 inline const UChar *
03489 UnicodeString::getBuffer() const {
03490 if(!(fFlags&(kIsBogus|kOpenGetBuffer))) {
03491 return fArray;
03492 } else {
03493 return 0;
03494 }
03495 }
03496
03497
03498
03499
03500 inline UnicodeString&
03501 UnicodeString::operator= (UChar ch)
03502 { return doReplace(0, fLength, &ch, 0, 1); }
03503
03504 inline UnicodeString&
03505 UnicodeString::operator= (UChar32 ch)
03506 { return replace(0, fLength, ch); }
03507
03508 inline UnicodeString&
03509 UnicodeString::setTo(const UnicodeString& srcText,
03510 UTextOffset srcStart,
03511 int32_t srcLength)
03512 { return doReplace(0, fLength, srcText, srcStart, srcLength); }
03513
03514 inline UnicodeString&
03515 UnicodeString::setTo(const UnicodeString& srcText)
03516 { return doReplace(0, fLength, srcText, 0, srcText.fLength); }
03517
03518 inline UnicodeString&
03519 UnicodeString::setTo(const UChar *srcChars,
03520 int32_t srcLength)
03521 { return doReplace(0, fLength, srcChars, 0, srcLength); }
03522
03523 inline UnicodeString&
03524 UnicodeString::setTo(UChar srcChar)
03525 { return doReplace(0, fLength, &srcChar, 0, 1); }
03526
03527 inline UnicodeString&
03528 UnicodeString::setTo(UChar32 srcChar)
03529 { return replace(0, fLength, srcChar); }
03530
03531 inline UnicodeString&
03532 UnicodeString::operator+= (UChar ch)
03533 { return doReplace(fLength, 0, &ch, 0, 1); }
03534
03535 inline UnicodeString&
03536 UnicodeString::operator+= (UChar32 ch) {
03537 UChar buffer[UTF_MAX_CHAR_LENGTH];
03538 int32_t length = 0;
03539 UTF_APPEND_CHAR_UNSAFE(buffer, length, ch);
03540 return doReplace(fLength, 0, buffer, 0, length);
03541 }
03542
03543 inline UnicodeString&
03544 UnicodeString::operator+= (const UnicodeString& srcText)
03545 { return doReplace(fLength, 0, srcText, 0, srcText.fLength); }
03546
03547 inline UnicodeString&
03548 UnicodeString::append(const UnicodeString& srcText,
03549 UTextOffset srcStart,
03550 int32_t srcLength)
03551 { return doReplace(fLength, 0, srcText, srcStart, srcLength); }
03552
03553 inline UnicodeString&
03554 UnicodeString::append(const UnicodeString& srcText)
03555 { return doReplace(fLength, 0, srcText, 0, srcText.fLength); }
03556
03557 inline UnicodeString&
03558 UnicodeString::append(const UChar *srcChars,
03559 UTextOffset srcStart,
03560 int32_t srcLength)
03561 { return doReplace(fLength, 0, srcChars, srcStart, srcLength); }
03562
03563 inline UnicodeString&
03564 UnicodeString::append(const UChar *srcChars,
03565 int32_t srcLength)
03566 { return doReplace(fLength, 0, srcChars, 0, srcLength); }
03567
03568 inline UnicodeString&
03569 UnicodeString::append(UChar srcChar)
03570 { return doReplace(fLength, 0, &srcChar, 0, 1); }
03571
03572 inline UnicodeString&
03573 UnicodeString::append(UChar32 srcChar) {
03574 UChar buffer[UTF_MAX_CHAR_LENGTH];
03575 int32_t length = 0;
03576 UTF_APPEND_CHAR_UNSAFE(buffer, length, srcChar);
03577 return doReplace(fLength, 0, buffer, 0, length);
03578 }
03579
03580 inline UnicodeString&
03581 UnicodeString::insert(UTextOffset start,
03582 const UnicodeString& srcText,
03583 UTextOffset srcStart,
03584 int32_t srcLength)
03585 { return doReplace(start, 0, srcText, srcStart, srcLength); }
03586
03587 inline UnicodeString&
03588 UnicodeString::insert(UTextOffset start,
03589 const UnicodeString& srcText)
03590 { return doReplace(start, 0, srcText, 0, srcText.fLength); }
03591
03592 inline UnicodeString&
03593 UnicodeString::insert(UTextOffset start,
03594 const UChar *srcChars,
03595 UTextOffset srcStart,
03596 int32_t srcLength)
03597 { return doReplace(start, 0, srcChars, srcStart, srcLength); }
03598
03599 inline UnicodeString&
03600 UnicodeString::insert(UTextOffset start,
03601 const UChar *srcChars,
03602 int32_t srcLength)
03603 { return doReplace(start, 0, srcChars, 0, srcLength); }
03604
03605 inline UnicodeString&
03606 UnicodeString::insert(UTextOffset start,
03607 UChar srcChar)
03608 { return doReplace(start, 0, &srcChar, 0, 1); }
03609
03610 inline UnicodeString&
03611 UnicodeString::insert(UTextOffset start,
03612 UChar32 srcChar)
03613 { return replace(start, 0, srcChar); }
03614
03615
03616 inline UnicodeString&
03617 UnicodeString::remove(UTextOffset start,
03618 int32_t length)
03619 { return doReplace(start, length, NULL, 0, 0); }
03620
03621 inline UnicodeString&
03622 UnicodeString::remove()
03623 { return doReplace(0, fLength, 0, 0, 0); }
03624
03625 inline UnicodeString&
03626 UnicodeString::removeBetween(UTextOffset start,
03627 UTextOffset limit)
03628 { return doReplace(start, limit - start, NULL, 0, 0); }
03629
03630 inline UBool
03631 UnicodeString::truncate(int32_t targetLength)
03632 {
03633 if((uint32_t)targetLength < (uint32_t)fLength) {
03634 fLength = targetLength;
03635 return TRUE;
03636 } else {
03637 return FALSE;
03638 }
03639 }
03640
03641 inline UnicodeString&
03642 UnicodeString::reverse()
03643 { return doReverse(0, fLength); }
03644
03645 inline UnicodeString&
03646 UnicodeString::reverse(UTextOffset start,
03647 int32_t length)
03648 { return doReverse(start, length); }
03649
03650
03651
03652
03653
03654 inline UBool
03655 UnicodeString::isBogus() const
03656 { return (UBool)(fFlags & kIsBogus); }
03657
03658
03659
03660
03661
03662
03663 inline void
03664 UnicodeString::pinIndices(UTextOffset& start,
03665 int32_t& length) const
03666 {
03667
03668 if(start < 0) {
03669 start = 0;
03670 } else if(start > fLength) {
03671 start = fLength;
03672 }
03673 if(length < 0) {
03674 length = 0;
03675 } else if(length > (fLength - start)) {
03676 length = (fLength - start);
03677 }
03678 }
03679
03680 inline UChar*
03681 UnicodeString::getArrayStart()
03682 { return fArray; }
03683
03684 inline const UChar*
03685 UnicodeString::getArrayStart() const
03686 { return fArray; }
03687
03688 inline int32_t
03689 UnicodeString::getCapacity() const
03690 { return fCapacity; }
03691
03692 inline void
03693 UnicodeString::releaseArray() {
03694 if((fFlags & kRefCounted) && removeRef() == 0) {
03695 delete [] ((int32_t *)fArray - 1);
03696 }
03697 }
03698
03699 inline int32_t
03700 UnicodeString::addRef()
03701 { return ++*((int32_t *)fArray - 1); }
03702
03703 inline int32_t
03704 UnicodeString::removeRef()
03705 { return --*((int32_t *)fArray - 1); }
03706
03707 inline int32_t
03708 UnicodeString::refCount() const
03709 { return *((int32_t *)fArray - 1); }
03710
03711 inline int32_t
03712 UnicodeString::setRefCount(int32_t count)
03713 { return (*((int32_t *)fArray - 1) = count); }
03714
03715 U_NAMESPACE_END
03716
03717
03718
03719
03720 U_NAMESPACE_BEGIN
03721
03722
03723
03724
03725 class U_COMMON_API UCharReference
03726 {
03727 public:
03728 UCharReference();
03729 inline UCharReference(UnicodeString *string,
03730 UTextOffset pos);
03731 inline UCharReference(const UCharReference& that);
03732 ~UCharReference();
03733
03734 inline UCharReference& operator= (const UCharReference& that);
03735 inline UCharReference& operator= (UChar c);
03736
03737 inline operator UChar();
03738
03739 private:
03740 UnicodeString *fString;
03741 UTextOffset fPos;
03742 };
03743
03744
03745
03746
03747
03748 inline
03749 UCharReference::UCharReference(UnicodeString *string,
03750 UTextOffset pos)
03751 : fString(string), fPos(pos)
03752 {}
03753
03754 inline
03755 UCharReference::UCharReference(const UCharReference& that)
03756 { this->operator=(that); }
03757
03758 inline
03759 UCharReference::~UCharReference()
03760 {}
03761
03762 inline UCharReference&
03763 UCharReference::operator= (const UCharReference& that)
03764 { fString->setCharAt(fPos, that.fString->charAt(that.fPos)); return *this; }
03765
03766 inline UCharReference&
03767 UCharReference::operator= (UChar c)
03768 { fString->setCharAt(fPos, c); return *this; }
03769
03770 inline
03771 UCharReference::operator UChar()
03772 { return fString->charAt(fPos); }
03773
03774 U_NAMESPACE_END
03775
03776 #endif