unistr.h

Go to the documentation of this file.
00001 /*
00002 **********************************************************************
00003 *   Copyright (C) 1998-2006, International Business Machines
00004 *   Corporation and others.  All Rights Reserved.
00005 **********************************************************************
00006 *
00007 * File unistr.h
00008 *
00009 * Modification History:
00010 *
00011 *   Date        Name        Description
00012 *   09/25/98    stephen     Creation.
00013 *   11/11/98    stephen     Changed per 11/9 code review.
00014 *   04/20/99    stephen     Overhauled per 4/16 code review.
00015 *   11/18/99    aliu        Made to inherit from Replaceable.  Added method
00016 *                           handleReplaceBetween(); other methods unchanged.
00017 *   06/25/01    grhoten     Remove dependency on iostream.
00018 ******************************************************************************
00019 */
00020 
00021 #ifndef UNISTR_H
00022 #define UNISTR_H
00023 
00029 #include "unicode/rep.h"
00030 
00031 struct UConverter;          // unicode/ucnv.h
00032 class  StringThreadTest;
00033 
00034 #ifndef U_COMPARE_CODE_POINT_ORDER
00035 /* see also ustring.h and unorm.h */
00041 #define U_COMPARE_CODE_POINT_ORDER  0x8000
00042 #endif
00043 
00044 #ifndef USTRING_H
00045 
00048 U_STABLE int32_t U_EXPORT2
00049 u_strlen(const UChar *s);
00050 #endif
00051 
00052 U_NAMESPACE_BEGIN
00053 
00054 class Locale;               // unicode/locid.h
00055 class StringCharacterIterator;
00056 class BreakIterator;        // unicode/brkiter.h
00057 
00058 /* The <iostream> include has been moved to unicode/ustream.h */
00059 
00070 #define US_INV UnicodeString::kInvariant
00071 
00089 #if U_SIZEOF_WCHAR_T==U_SIZEOF_UCHAR && (U_CHARSET_FAMILY==U_ASCII_FAMILY || (U_SIZEOF_UCHAR == 2 && defined(U_WCHAR_IS_UTF16)))
00090 #   define UNICODE_STRING(cs, _length) UnicodeString(TRUE, (const UChar *)L ## cs, _length)
00091 #elif U_SIZEOF_UCHAR==1 && U_CHARSET_FAMILY==U_ASCII_FAMILY
00092 #   define UNICODE_STRING(cs, _length) UnicodeString(TRUE, (const UChar *)cs, _length)
00093 #else
00094 #   define UNICODE_STRING(cs, _length) UnicodeString(cs, _length, US_INV)
00095 #endif
00096 
00110 #if U_SIZEOF_WCHAR_T==U_SIZEOF_UCHAR && (U_CHARSET_FAMILY==U_ASCII_FAMILY || (U_SIZEOF_UCHAR == 2 && defined(U_WCHAR_IS_UTF16)))
00111 #   define UNICODE_STRING_SIMPLE(cs) UnicodeString(TRUE, (const UChar *)L ## cs, -1)
00112 #elif U_SIZEOF_UCHAR==1 && U_CHARSET_FAMILY==U_ASCII_FAMILY
00113 #   define UNICODE_STRING_SIMPLE(cs) UnicodeString(TRUE, (const UChar *)cs, -1)
00114 #else
00115 #   define UNICODE_STRING_SIMPLE(cs) UnicodeString(cs, -1, US_INV)
00116 #endif
00117 
00187 class U_COMMON_API UnicodeString : public Replaceable
00188 {
00189 public:
00190 
00199   enum EInvariant {
00204     kInvariant
00205   };
00206 
00207   //========================================
00208   // Read-only operations
00209   //========================================
00210 
00211   /* Comparison - bitwise only - for international comparison use collation */
00212 
00220   inline UBool operator== (const UnicodeString& text) const;
00221 
00229   inline UBool operator!= (const UnicodeString& text) const;
00230 
00238   inline UBool operator> (const UnicodeString& text) const;
00239 
00247   inline UBool operator< (const UnicodeString& text) const;
00248 
00256   inline UBool operator>= (const UnicodeString& text) const;
00257 
00265   inline UBool operator<= (const UnicodeString& text) const;
00266 
00278   inline int8_t compare(const UnicodeString& text) const;
00279 
00294   inline int8_t compare(int32_t start,
00295          int32_t length,
00296          const UnicodeString& text) const;
00297 
00315    inline int8_t compare(int32_t start,
00316          int32_t length,
00317          const UnicodeString& srcText,
00318          int32_t srcStart,
00319          int32_t srcLength) const;
00320 
00333   inline int8_t compare(const UChar *srcChars,
00334          int32_t srcLength) const;
00335 
00350   inline int8_t compare(int32_t start,
00351          int32_t length,
00352          const UChar *srcChars) const;
00353 
00371   inline int8_t compare(int32_t start,
00372          int32_t length,
00373          const UChar *srcChars,
00374          int32_t srcStart,
00375          int32_t srcLength) const;
00376 
00394   inline int8_t compareBetween(int32_t start,
00395             int32_t limit,
00396             const UnicodeString& srcText,
00397             int32_t srcStart,
00398             int32_t srcLimit) const;
00399 
00417   inline int8_t compareCodePointOrder(const UnicodeString& text) const;
00418 
00438   inline int8_t compareCodePointOrder(int32_t start,
00439                                       int32_t length,
00440                                       const UnicodeString& srcText) const;
00441 
00463    inline int8_t compareCodePointOrder(int32_t start,
00464                                        int32_t length,
00465                                        const UnicodeString& srcText,
00466                                        int32_t srcStart,
00467                                        int32_t srcLength) const;
00468 
00487   inline int8_t compareCodePointOrder(const UChar *srcChars,
00488                                       int32_t srcLength) const;
00489 
00509   inline int8_t compareCodePointOrder(int32_t start,
00510                                       int32_t length,
00511                                       const UChar *srcChars) const;
00512 
00534   inline int8_t compareCodePointOrder(int32_t start,
00535                                       int32_t length,
00536                                       const UChar *srcChars,
00537                                       int32_t srcStart,
00538                                       int32_t srcLength) const;
00539 
00561   inline int8_t compareCodePointOrderBetween(int32_t start,
00562                                              int32_t limit,
00563                                              const UnicodeString& srcText,
00564                                              int32_t srcStart,
00565                                              int32_t srcLimit) const;
00566 
00585   inline int8_t caseCompare(const UnicodeString& text, uint32_t options) const;
00586 
00607   inline int8_t caseCompare(int32_t start,
00608          int32_t length,
00609          const UnicodeString& srcText,
00610          uint32_t options) const;
00611 
00634   inline int8_t caseCompare(int32_t start,
00635          int32_t length,
00636          const UnicodeString& srcText,
00637          int32_t srcStart,
00638          int32_t srcLength,
00639          uint32_t options) const;
00640 
00660   inline int8_t caseCompare(const UChar *srcChars,
00661          int32_t srcLength,
00662          uint32_t options) const;
00663 
00684   inline int8_t caseCompare(int32_t start,
00685          int32_t length,
00686          const UChar *srcChars,
00687          uint32_t options) const;
00688 
00711   inline int8_t caseCompare(int32_t start,
00712          int32_t length,
00713          const UChar *srcChars,
00714          int32_t srcStart,
00715          int32_t srcLength,
00716          uint32_t options) const;
00717 
00740   inline int8_t caseCompareBetween(int32_t start,
00741             int32_t limit,
00742             const UnicodeString& srcText,
00743             int32_t srcStart,
00744             int32_t srcLimit,
00745             uint32_t options) const;
00746 
00754   inline UBool startsWith(const UnicodeString& text) const;
00755 
00766   inline UBool startsWith(const UnicodeString& srcText,
00767             int32_t srcStart,
00768             int32_t srcLength) const;
00769 
00778   inline UBool startsWith(const UChar *srcChars,
00779             int32_t srcLength) const;
00780 
00790   inline UBool startsWith(const UChar *srcChars,
00791             int32_t srcStart,
00792             int32_t srcLength) const;
00793 
00801   inline UBool endsWith(const UnicodeString& text) const;
00802 
00813   inline UBool endsWith(const UnicodeString& srcText,
00814           int32_t srcStart,
00815           int32_t srcLength) const;
00816 
00825   inline UBool endsWith(const UChar *srcChars,
00826           int32_t srcLength) const;
00827 
00838   inline UBool endsWith(const UChar *srcChars,
00839           int32_t srcStart,
00840           int32_t srcLength) const;
00841 
00842 
00843   /* Searching - bitwise only */
00844 
00853   inline int32_t indexOf(const UnicodeString& text) const;
00854 
00864   inline int32_t indexOf(const UnicodeString& text,
00865               int32_t start) const;
00866 
00878   inline int32_t indexOf(const UnicodeString& text,
00879               int32_t start,
00880               int32_t length) const;
00881 
00898   inline int32_t indexOf(const UnicodeString& srcText,
00899               int32_t srcStart,
00900               int32_t srcLength,
00901               int32_t start,
00902               int32_t length) const;
00903 
00915   inline int32_t indexOf(const UChar *srcChars,
00916               int32_t srcLength,
00917               int32_t start) const;
00918 
00931   inline int32_t indexOf(const UChar *srcChars,
00932               int32_t srcLength,
00933               int32_t start,
00934               int32_t length) const;
00935 
00952   int32_t indexOf(const UChar *srcChars,
00953               int32_t srcStart,
00954               int32_t srcLength,
00955               int32_t start,
00956               int32_t length) const;
00957 
00965   inline int32_t indexOf(UChar c) const;
00966 
00975   inline int32_t indexOf(UChar32 c) const;
00976 
00985   inline int32_t indexOf(UChar c,
00986               int32_t start) const;
00987 
00997   inline int32_t indexOf(UChar32 c,
00998               int32_t start) const;
00999 
01010   inline int32_t indexOf(UChar c,
01011               int32_t start,
01012               int32_t length) const;
01013 
01025   inline int32_t indexOf(UChar32 c,
01026               int32_t start,
01027               int32_t length) const;
01028 
01037   inline int32_t lastIndexOf(const UnicodeString& text) const;
01038 
01048   inline int32_t lastIndexOf(const UnicodeString& text,
01049               int32_t start) const;
01050 
01062   inline int32_t lastIndexOf(const UnicodeString& text,
01063               int32_t start,
01064               int32_t length) const;
01065 
01082   inline int32_t lastIndexOf(const UnicodeString& srcText,
01083               int32_t srcStart,
01084               int32_t srcLength,
01085               int32_t start,
01086               int32_t length) const;
01087 
01098   inline int32_t lastIndexOf(const UChar *srcChars,
01099               int32_t srcLength,
01100               int32_t start) const;
01101 
01114   inline int32_t lastIndexOf(const UChar *srcChars,
01115               int32_t srcLength,
01116               int32_t start,
01117               int32_t length) const;
01118 
01135   int32_t lastIndexOf(const UChar *srcChars,
01136               int32_t srcStart,
01137               int32_t srcLength,
01138               int32_t start,
01139               int32_t length) const;
01140 
01148   inline int32_t lastIndexOf(UChar c) const;
01149 
01158   inline int32_t lastIndexOf(UChar32 c) const;
01159 
01168   inline int32_t lastIndexOf(UChar c,
01169               int32_t start) const;
01170 
01180   inline int32_t lastIndexOf(UChar32 c,
01181               int32_t start) const;
01182 
01193   inline int32_t lastIndexOf(UChar c,
01194               int32_t start,
01195               int32_t length) const;
01196 
01208   inline int32_t lastIndexOf(UChar32 c,
01209               int32_t start,
01210               int32_t length) const;
01211 
01212 
01213   /* Character access */
01214 
01223   inline UChar charAt(int32_t offset) const;
01224 
01232   inline UChar operator[] (int32_t offset) const;
01233 
01245   inline UChar32 char32At(int32_t offset) const;
01246 
01262   inline int32_t getChar32Start(int32_t offset) const;
01263 
01280   inline int32_t getChar32Limit(int32_t offset) const;
01281 
01332   int32_t moveIndex32(int32_t index, int32_t delta) const;
01333 
01334   /* Substring extraction */
01335 
01351   inline void extract(int32_t start,
01352            int32_t length,
01353            UChar *dst,
01354            int32_t dstStart = 0) const;
01355 
01377   int32_t
01378   extract(UChar *dest, int32_t destCapacity,
01379           UErrorCode &errorCode) const;
01380 
01391   inline void extract(int32_t start,
01392            int32_t length,
01393            UnicodeString& target) const;
01394 
01406   inline void extractBetween(int32_t start,
01407               int32_t limit,
01408               UChar *dst,
01409               int32_t dstStart = 0) const;
01410 
01420   virtual void extractBetween(int32_t start,
01421               int32_t limit,
01422               UnicodeString& target) const;
01423 
01445   int32_t extract(int32_t start,
01446            int32_t startLength,
01447            char *target,
01448            int32_t targetCapacity,
01449            enum EInvariant inv) const;
01450 
01451 #if !UCONFIG_NO_CONVERSION
01452 
01478   inline int32_t extract(int32_t start,
01479                  int32_t startLength,
01480                  char *target,
01481                  const char *codepage = 0) const;
01482 
01512   int32_t extract(int32_t start,
01513            int32_t startLength,
01514            char *target,
01515            uint32_t targetLength,
01516            const char *codepage = 0) const;
01517 
01535   int32_t extract(char *dest, int32_t destCapacity,
01536                   UConverter *cnv,
01537                   UErrorCode &errorCode) const;
01538 
01539 #endif
01540 
01541   /* Length operations */
01542 
01551   inline int32_t length(void) const;
01552 
01566   int32_t
01567   countChar32(int32_t start=0, int32_t length=INT32_MAX) const;
01568 
01592   UBool
01593   hasMoreChar32Than(int32_t start, int32_t length, int32_t number) const;
01594 
01600   inline UBool isEmpty(void) const;
01601 
01611   inline int32_t getCapacity(void) const;
01612 
01613   /* Other operations */
01614 
01620   inline int32_t hashCode(void) const;
01621 
01633   inline UBool isBogus(void) const;
01634 
01635 
01636   //========================================
01637   // Write operations
01638   //========================================
01639 
01640   /* Assignment operations */
01641 
01649   UnicodeString &operator=(const UnicodeString &srcText);
01650 
01671   UnicodeString &fastCopyFrom(const UnicodeString &src);
01672 
01680   inline UnicodeString& operator= (UChar ch);
01681 
01689   inline UnicodeString& operator= (UChar32 ch);
01690 
01702   inline UnicodeString& setTo(const UnicodeString& srcText,
01703                int32_t srcStart);
01704 
01718   inline UnicodeString& setTo(const UnicodeString& srcText,
01719                int32_t srcStart,
01720                int32_t srcLength);
01721 
01730   inline UnicodeString& setTo(const UnicodeString& srcText);
01731 
01740   inline UnicodeString& setTo(const UChar *srcChars,
01741                int32_t srcLength);
01742 
01751   UnicodeString& setTo(UChar srcChar);
01752 
01761   UnicodeString& setTo(UChar32 srcChar);
01762 
01783   UnicodeString &setTo(UBool isTerminated,
01784                        const UChar *text,
01785                        int32_t textLength);
01786 
01806   UnicodeString &setTo(UChar *buffer,
01807                        int32_t buffLength,
01808                        int32_t buffCapacity);
01809 
01850   void setToBogus();
01851 
01859   UnicodeString& setCharAt(int32_t offset,
01860                UChar ch);
01861 
01862 
01863   /* Append operations */
01864 
01872  inline  UnicodeString& operator+= (UChar ch);
01873 
01881  inline  UnicodeString& operator+= (UChar32 ch);
01882 
01891   inline UnicodeString& operator+= (const UnicodeString& srcText);
01892 
01907   inline UnicodeString& append(const UnicodeString& srcText,
01908             int32_t srcStart,
01909             int32_t srcLength);
01910 
01918   inline UnicodeString& append(const UnicodeString& srcText);
01919 
01933   inline UnicodeString& append(const UChar *srcChars,
01934             int32_t srcStart,
01935             int32_t srcLength);
01936 
01945   inline UnicodeString& append(const UChar *srcChars,
01946             int32_t srcLength);
01947 
01954   inline UnicodeString& append(UChar srcChar);
01955 
01962   inline UnicodeString& append(UChar32 srcChar);
01963 
01964 
01965   /* Insert operations */
01966 
01980   inline UnicodeString& insert(int32_t start,
01981             const UnicodeString& srcText,
01982             int32_t srcStart,
01983             int32_t srcLength);
01984 
01993   inline UnicodeString& insert(int32_t start,
01994             const UnicodeString& srcText);
01995 
02009   inline UnicodeString& insert(int32_t start,
02010             const UChar *srcChars,
02011             int32_t srcStart,
02012             int32_t srcLength);
02013 
02023   inline UnicodeString& insert(int32_t start,
02024             const UChar *srcChars,
02025             int32_t srcLength);
02026 
02035   inline UnicodeString& insert(int32_t start,
02036             UChar srcChar);
02037 
02046   inline UnicodeString& insert(int32_t start,
02047             UChar32 srcChar);
02048 
02049 
02050   /* Replace operations */
02051 
02069   UnicodeString& replace(int32_t start,
02070              int32_t length,
02071              const UnicodeString& srcText,
02072              int32_t srcStart,
02073              int32_t srcLength);
02074 
02087   UnicodeString& replace(int32_t start,
02088              int32_t length,
02089              const UnicodeString& srcText);
02090 
02108   UnicodeString& replace(int32_t start,
02109              int32_t length,
02110              const UChar *srcChars,
02111              int32_t srcStart,
02112              int32_t srcLength);
02113 
02126   inline UnicodeString& replace(int32_t start,
02127              int32_t length,
02128              const UChar *srcChars,
02129              int32_t srcLength);
02130 
02142   inline UnicodeString& replace(int32_t start,
02143              int32_t length,
02144              UChar srcChar);
02145 
02157   inline UnicodeString& replace(int32_t start,
02158              int32_t length,
02159              UChar32 srcChar);
02160 
02170   inline UnicodeString& replaceBetween(int32_t start,
02171                 int32_t limit,
02172                 const UnicodeString& srcText);
02173 
02188   inline UnicodeString& replaceBetween(int32_t start,
02189                 int32_t limit,
02190                 const UnicodeString& srcText,
02191                 int32_t srcStart,
02192                 int32_t srcLimit);
02193 
02204   virtual void handleReplaceBetween(int32_t start,
02205                                     int32_t limit,
02206                                     const UnicodeString& text);
02207 
02213   virtual UBool hasMetaData() const;
02214 
02230   virtual void copy(int32_t start, int32_t limit, int32_t dest);
02231 
02232   /* Search and replace operations */
02233 
02242   inline UnicodeString& findAndReplace(const UnicodeString& oldText,
02243                 const UnicodeString& newText);
02244 
02256   inline UnicodeString& findAndReplace(int32_t start,
02257                 int32_t length,
02258                 const UnicodeString& oldText,
02259                 const UnicodeString& newText);
02260 
02278   UnicodeString& findAndReplace(int32_t start,
02279                 int32_t length,
02280                 const UnicodeString& oldText,
02281                 int32_t oldStart,
02282                 int32_t oldLength,
02283                 const UnicodeString& newText,
02284                 int32_t newStart,
02285                 int32_t newLength);
02286 
02287 
02288   /* Remove operations */
02289 
02295   inline UnicodeString& remove(void);
02296 
02305   inline UnicodeString& remove(int32_t start,
02306                                int32_t length = (int32_t)INT32_MAX);
02307 
02316   inline UnicodeString& removeBetween(int32_t start,
02317                                       int32_t limit = (int32_t)INT32_MAX);
02318 
02319 
02320   /* Length operations */
02321 
02333   UBool padLeading(int32_t targetLength,
02334                     UChar padChar = 0x0020);
02335 
02347   UBool padTrailing(int32_t targetLength,
02348                      UChar padChar = 0x0020);
02349 
02356   inline UBool truncate(int32_t targetLength);
02357 
02363   UnicodeString& trim(void);
02364 
02365 
02366   /* Miscellaneous operations */
02367 
02373   inline UnicodeString& reverse(void);
02374 
02383   inline UnicodeString& reverse(int32_t start,
02384              int32_t length);
02385 
02392   UnicodeString& toUpper(void);
02393 
02401   UnicodeString& toUpper(const Locale& locale);
02402 
02409   UnicodeString& toLower(void);
02410 
02418   UnicodeString& toLower(const Locale& locale);
02419 
02420 #if !UCONFIG_NO_BREAK_ITERATION
02421 
02448   UnicodeString &toTitle(BreakIterator *titleIter);
02449 
02477   UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale);
02478 
02479 #endif
02480 
02492   UnicodeString &foldCase(uint32_t options=0 /*U_FOLD_CASE_DEFAULT*/);
02493 
02494   //========================================
02495   // Access to the internal buffer
02496   //========================================
02497 
02541   UChar *getBuffer(int32_t minCapacity);
02542 
02563   void releaseBuffer(int32_t newLength=-1);
02564 
02595   inline const UChar *getBuffer() const;
02596 
02630   inline const UChar *getTerminatedBuffer();
02631 
02632   //========================================
02633   // Constructors
02634   //========================================
02635 
02639   UnicodeString();
02640 
02652   UnicodeString(int32_t capacity, UChar32 c, int32_t count);
02653 
02659   UnicodeString(UChar ch);
02660 
02666   UnicodeString(UChar32 ch);
02667 
02674   UnicodeString(const UChar *text);
02675 
02683   UnicodeString(const UChar *text,
02684         int32_t textLength);
02685 
02705   UnicodeString(UBool isTerminated,
02706                 const UChar *text,
02707                 int32_t textLength);
02708 
02727   UnicodeString(UChar *buffer, int32_t buffLength, int32_t buffCapacity);
02728 
02729 #if !UCONFIG_NO_CONVERSION
02730 
02748   UnicodeString(const char *codepageData,
02749         const char *codepage = 0);
02750 
02768   UnicodeString(const char *codepageData,
02769         int32_t dataLength,
02770         const char *codepage = 0);
02771 
02793   UnicodeString(
02794         const char *src, int32_t srcLength,
02795         UConverter *cnv,
02796         UErrorCode &errorCode);
02797 
02798 #endif
02799 
02824   UnicodeString(const char *src, int32_t length, enum EInvariant inv);
02825 
02826 
02832   UnicodeString(const UnicodeString& that);
02833 
02840   UnicodeString(const UnicodeString& src, int32_t srcStart);
02841 
02849   UnicodeString(const UnicodeString& src, int32_t srcStart, int32_t srcLength);
02850 
02867   virtual Replaceable *clone() const;
02868 
02872   virtual ~UnicodeString();
02873 
02874 
02875   /* Miscellaneous operations */
02876 
02911   UnicodeString unescape() const;
02912 
02932   UChar32 unescapeAt(int32_t &offset) const;
02933 
02939   static UClassID U_EXPORT2 getStaticClassID();
02940 
02946   virtual UClassID getDynamicClassID() const;
02947 
02948   //========================================
02949   // Implementation methods
02950   //========================================
02951 
02952 protected:
02957   virtual int32_t getLength() const;
02958 
02964   virtual UChar getCharAt(int32_t offset) const;
02965 
02971   virtual UChar32 getChar32At(int32_t offset) const;
02972 
02973 private:
02974 
02975   inline int8_t
02976   doCompare(int32_t start,
02977            int32_t length,
02978            const UnicodeString& srcText,
02979            int32_t srcStart,
02980            int32_t srcLength) const;
02981 
02982   int8_t doCompare(int32_t start,
02983            int32_t length,
02984            const UChar *srcChars,
02985            int32_t srcStart,
02986            int32_t srcLength) const;
02987 
02988   inline int8_t
02989   doCompareCodePointOrder(int32_t start,
02990                           int32_t length,
02991                           const UnicodeString& srcText,
02992                           int32_t srcStart,
02993                           int32_t srcLength) const;
02994 
02995   int8_t doCompareCodePointOrder(int32_t start,
02996                                  int32_t length,
02997                                  const UChar *srcChars,
02998                                  int32_t srcStart,
02999                                  int32_t srcLength) const;
03000 
03001   inline int8_t
03002   doCaseCompare(int32_t start,
03003                 int32_t length,
03004                 const UnicodeString &srcText,
03005                 int32_t srcStart,
03006                 int32_t srcLength,
03007                 uint32_t options) const;
03008 
03009   int8_t
03010   doCaseCompare(int32_t start,
03011                 int32_t length,
03012                 const UChar *srcChars,
03013                 int32_t srcStart,
03014                 int32_t srcLength,
03015                 uint32_t options) const;
03016 
03017   int32_t doIndexOf(UChar c,
03018             int32_t start,
03019             int32_t length) const;
03020 
03021   int32_t doIndexOf(UChar32 c,
03022                         int32_t start,
03023                         int32_t length) const;
03024 
03025   int32_t doLastIndexOf(UChar c,
03026                 int32_t start,
03027                 int32_t length) const;
03028 
03029   int32_t doLastIndexOf(UChar32 c,
03030                             int32_t start,
03031                             int32_t length) const;
03032 
03033   void doExtract(int32_t start,
03034          int32_t length,
03035          UChar *dst,
03036          int32_t dstStart) const;
03037 
03038   inline void doExtract(int32_t start,
03039          int32_t length,
03040          UnicodeString& target) const;
03041 
03042   inline UChar doCharAt(int32_t offset)  const;
03043 
03044   UnicodeString& doReplace(int32_t start,
03045                int32_t length,
03046                const UnicodeString& srcText,
03047                int32_t srcStart,
03048                int32_t srcLength);
03049 
03050   UnicodeString& doReplace(int32_t start,
03051                int32_t length,
03052                const UChar *srcChars,
03053                int32_t srcStart,
03054                int32_t srcLength);
03055 
03056   UnicodeString& doReverse(int32_t start,
03057                int32_t length);
03058 
03059   // calculate hash code
03060   int32_t doHashCode(void) const;
03061 
03062   // get pointer to start of array
03063   inline UChar* getArrayStart(void);
03064   inline const UChar* getArrayStart(void) const;
03065 
03066   // allocate the array; result may be fStackBuffer
03067   // sets refCount to 1 if appropriate
03068   // sets fArray, fCapacity, and fFlags
03069   // returns boolean for success or failure
03070   UBool allocate(int32_t capacity);
03071 
03072   // release the array if owned
03073   void releaseArray(void);
03074 
03075   // turn a bogus string into an empty one
03076   void unBogus();
03077 
03078   // implements assigment operator, copy constructor, and fastCopyFrom()
03079   UnicodeString &copyFrom(const UnicodeString &src, UBool fastCopy=FALSE);
03080 
03081   // Pin start and limit to acceptable values.
03082   inline void pinIndex(int32_t& start) const;
03083   inline void pinIndices(int32_t& start,
03084                          int32_t& length) const;
03085 
03086 #if !UCONFIG_NO_CONVERSION
03087 
03088   /* Internal extract() using UConverter. */
03089   int32_t doExtract(int32_t start, int32_t length,
03090                     char *dest, int32_t destCapacity,
03091                     UConverter *cnv,
03092                     UErrorCode &errorCode) const;
03093 
03094   /*
03095    * Real constructor for converting from codepage data.
03096    * It assumes that it is called with !fRefCounted.
03097    *
03098    * If <code>codepage==0</code>, then the default converter
03099    * is used for the platform encoding.
03100    * If <code>codepage</code> is an empty string (<code>""</code>),
03101    * then a simple conversion is performed on the codepage-invariant
03102    * subset ("invariant characters") of the platform encoding. See utypes.h.
03103    */
03104   void doCodepageCreate(const char *codepageData,
03105                         int32_t dataLength,
03106                         const char *codepage);
03107 
03108   /*
03109    * Worker function for creating a UnicodeString from
03110    * a codepage string using a UConverter.
03111    */
03112   void
03113   doCodepageCreate(const char *codepageData,
03114                    int32_t dataLength,
03115                    UConverter *converter,
03116                    UErrorCode &status);
03117 
03118 #endif
03119 
03120   /*
03121    * This function is called when write access to the array
03122    * is necessary.
03123    *
03124    * We need to make a copy of the array if
03125    * the buffer is read-only, or
03126    * the buffer is refCounted (shared), and refCount>1, or
03127    * the buffer is too small.
03128    *
03129    * Return FALSE if memory could not be allocated.
03130    */
03131   UBool cloneArrayIfNeeded(int32_t newCapacity = -1,
03132                             int32_t growCapacity = -1,
03133                             UBool doCopyArray = TRUE,
03134                             int32_t **pBufferToDelete = 0,
03135                             UBool forceClone = FALSE);
03136 
03137   // common function for case mappings
03138   UnicodeString &
03139   caseMap(BreakIterator *titleIter,
03140           const char *locale,
03141           uint32_t options,
03142           int32_t toWhichCase);
03143 
03144   // ref counting
03145   void addRef(void);
03146   int32_t removeRef(void);
03147   int32_t refCount(void) const;
03148 
03149   // constants
03150   enum {
03151     US_STACKBUF_SIZE=7, // Size of stack buffer for small strings
03152     kInvalidUChar=0xffff, // invalid UChar index
03153     kGrowSize=128, // grow size for this buffer
03154     kInvalidHashCode=0, // invalid hash code
03155     kEmptyHashCode=1, // hash code for empty string
03156 
03157     // bit flag values for fFlags
03158     kIsBogus=1,         // this string is bogus, i.e., not valid or NULL
03159     kUsingStackBuffer=2,// fArray==fStackBuffer
03160     kRefCounted=4,      // there is a refCount field before the characters in fArray
03161     kBufferIsReadonly=8,// do not write to this buffer
03162     kOpenGetBuffer=16,  // getBuffer(minCapacity) was called (is "open"),
03163                         // and releaseBuffer(newLength) must be called
03164 
03165     // combined values for convenience
03166     kShortString=kUsingStackBuffer,
03167     kLongString=kRefCounted,
03168     kReadonlyAlias=kBufferIsReadonly,
03169     kWritableAlias=0
03170   };
03171 
03172   friend class StringCharacterIterator;
03173   friend class StringThreadTest;
03174 
03175   /*
03176    * The following are all the class fields that are stored
03177    * in each UnicodeString object.
03178    * Note that UnicodeString has virtual functions,
03179    * therefore there is an implicit vtable pointer
03180    * as the first real field.
03181    * The fields should be aligned such that no padding is
03182    * necessary, mostly by having larger types first.
03183    * On 32-bit machines, the size should be 32 bytes,
03184    * on 64-bit machines (8-byte pointers), it should be 40 bytes.
03185    */
03186   // (implicit) *vtable;
03187   int32_t   fLength;        // number of characters in fArray
03188   int32_t   fCapacity;      // sizeof fArray
03189   UChar     *fArray;        // the Unicode data
03190   uint16_t  fFlags;         // bit flags: see constants above
03191   UChar     fStackBuffer [ US_STACKBUF_SIZE ]; // buffer for small strings
03192 
03193 };
03194 
03203 U_COMMON_API UnicodeString U_EXPORT2
03204 operator+ (const UnicodeString &s1, const UnicodeString &s2);
03205 
03206 //========================================
03207 // Inline members
03208 //========================================
03209 
03210 //========================================
03211 // Privates
03212 //========================================
03213 
03214 inline void
03215 UnicodeString::pinIndex(int32_t& start) const
03216 {
03217   // pin index
03218   if(start < 0) {
03219     start = 0;
03220   } else if(start > fLength) {
03221     start = fLength;
03222   }
03223 }
03224 
03225 inline void
03226 UnicodeString::pinIndices(int32_t& start,
03227                           int32_t& _length) const
03228 {
03229   // pin indices
03230   if(start < 0) {
03231     start = 0;
03232   } else if(start > fLength) {
03233     start = fLength;
03234   }
03235   if(_length < 0) {
03236     _length = 0;
03237   } else if(_length > (fLength - start)) {
03238     _length = (fLength - start);
03239   }
03240 }
03241 
03242 inline UChar*
03243 UnicodeString::getArrayStart()
03244 { return fArray; }
03245 
03246 inline const UChar*
03247 UnicodeString::getArrayStart() const
03248 { return fArray; }
03249 
03250 //========================================
03251 // Read-only implementation methods
03252 //========================================
03253 inline int32_t
03254 UnicodeString::length() const
03255 { return fLength; }
03256 
03257 inline int32_t
03258 UnicodeString::getCapacity() const
03259 { return fCapacity; }
03260 
03261 inline int32_t
03262 UnicodeString::hashCode() const
03263 { return doHashCode(); }
03264 
03265 inline UBool
03266 UnicodeString::isBogus() const
03267 { return (UBool)(fFlags & kIsBogus); }
03268 
03269 inline const UChar *
03270 UnicodeString::getBuffer() const {
03271   if(!(fFlags&(kIsBogus|kOpenGetBuffer))) {
03272     return fArray;
03273   } else {
03274     return 0;
03275   }
03276 }
03277 
03278 //========================================
03279 // Read-only alias methods
03280 //========================================
03281 inline int8_t
03282 UnicodeString::doCompare(int32_t start,
03283               int32_t length,
03284               const UnicodeString& srcText,
03285               int32_t srcStart,
03286               int32_t srcLength) const
03287 {
03288   if(srcText.isBogus()) {
03289     return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
03290   } else {
03291     srcText.pinIndices(srcStart, srcLength);
03292     return doCompare(start, length, srcText.fArray, srcStart, srcLength);
03293   }
03294 }
03295 
03296 inline UBool
03297 UnicodeString::operator== (const UnicodeString& text) const
03298 {
03299   if(isBogus()) {
03300     return text.isBogus();
03301   } else {
03302     return
03303       !text.isBogus() &&
03304       fLength == text.fLength &&
03305       doCompare(0, fLength, text, 0, text.fLength) == 0;
03306   }
03307 }
03308 
03309 inline UBool
03310 UnicodeString::operator!= (const UnicodeString& text) const
03311 { return (! operator==(text)); }
03312 
03313 inline UBool
03314 UnicodeString::operator> (const UnicodeString& text) const
03315 { return doCompare(0, fLength, text, 0, text.fLength) == 1; }
03316 
03317 inline UBool
03318 UnicodeString::operator< (const UnicodeString& text) const
03319 { return doCompare(0, fLength, text, 0, text.fLength) == -1; }
03320 
03321 inline UBool
03322 UnicodeString::operator>= (const UnicodeString& text) const
03323 { return doCompare(0, fLength, text, 0, text.fLength) != -1; }
03324 
03325 inline UBool
03326 UnicodeString::operator<= (const UnicodeString& text) const
03327 { return doCompare(0, fLength, text, 0, text.fLength) != 1; }
03328 
03329 inline int8_t
03330 UnicodeString::compare(const UnicodeString& text) const
03331 { return doCompare(0, fLength, text, 0, text.fLength); }
03332 
03333 inline int8_t
03334 UnicodeString::compare(int32_t start,
03335                int32_t _length,
03336                const UnicodeString& srcText) const
03337 { return doCompare(start, _length, srcText, 0, srcText.fLength); }
03338 
03339 inline int8_t
03340 UnicodeString::compare(const UChar *srcChars,
03341                int32_t srcLength) const
03342 { return doCompare(0, fLength, srcChars, 0, srcLength); }
03343 
03344 inline int8_t
03345 UnicodeString::compare(int32_t start,
03346                int32_t _length,
03347                const UnicodeString& srcText,
03348                int32_t srcStart,
03349                int32_t srcLength) const
03350 { return doCompare(start, _length, srcText, srcStart, srcLength); }
03351 
03352 inline int8_t
03353 UnicodeString::compare(int32_t start,
03354                int32_t _length,
03355                const UChar *srcChars) const
03356 { return doCompare(start, _length, srcChars, 0, _length); }
03357 
03358 inline int8_t
03359 UnicodeString::compare(int32_t start,
03360                int32_t _length,
03361                const UChar *srcChars,
03362                int32_t srcStart,
03363                int32_t srcLength) const
03364 { return doCompare(start, _length, srcChars, srcStart, srcLength); }
03365 
03366 inline int8_t
03367 UnicodeString::compareBetween(int32_t start,
03368                   int32_t limit,
03369                   const UnicodeString& srcText,
03370                   int32_t srcStart,
03371                   int32_t srcLimit) const
03372 { return doCompare(start, limit - start,
03373            srcText, srcStart, srcLimit - srcStart); }
03374 
03375 inline int8_t
03376 UnicodeString::doCompareCodePointOrder(int32_t start,
03377                                        int32_t length,
03378                                        const UnicodeString& srcText,
03379                                        int32_t srcStart,
03380                                        int32_t srcLength) const
03381 {
03382   if(srcText.isBogus()) {
03383     return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
03384   } else {
03385     srcText.pinIndices(srcStart, srcLength);
03386     return doCompareCodePointOrder(start, length, srcText.fArray, srcStart, srcLength);
03387   }
03388 }
03389 
03390 inline int8_t
03391 UnicodeString::compareCodePointOrder(const UnicodeString& text) const
03392 { return doCompareCodePointOrder(0, fLength, text, 0, text.fLength); }
03393 
03394 inline int8_t
03395 UnicodeString::compareCodePointOrder(int32_t start,
03396                                      int32_t _length,
03397                                      const UnicodeString& srcText) const
03398 { return doCompareCodePointOrder(start, _length, srcText, 0, srcText.fLength); }
03399 
03400 inline int8_t
03401 UnicodeString::compareCodePointOrder(const UChar *srcChars,
03402                                      int32_t srcLength) const
03403 { return doCompareCodePointOrder(0, fLength, srcChars, 0, srcLength); }
03404 
03405 inline int8_t
03406 UnicodeString::compareCodePointOrder(int32_t start,
03407                                      int32_t _length,
03408                                      const UnicodeString& srcText,
03409                                      int32_t srcStart,
03410                                      int32_t srcLength) const
03411 { return doCompareCodePointOrder(start, _length, srcText, srcStart, srcLength); }
03412 
03413 inline int8_t
03414 UnicodeString::compareCodePointOrder(int32_t start,
03415                                      int32_t _length,
03416                                      const UChar *srcChars) const
03417 { return doCompareCodePointOrder(start, _length, srcChars, 0, _length); }
03418 
03419 inline int8_t
03420 UnicodeString::compareCodePointOrder(int32_t start,
03421                                      int32_t _length,
03422                                      const UChar *srcChars,
03423                                      int32_t srcStart,
03424                                      int32_t srcLength) const
03425 { return doCompareCodePointOrder(start, _length, srcChars, srcStart, srcLength); }
03426 
03427 inline int8_t
03428 UnicodeString::compareCodePointOrderBetween(int32_t start,
03429                                             int32_t limit,
03430                                             const UnicodeString& srcText,
03431                                             int32_t srcStart,
03432                                             int32_t srcLimit) const
03433 { return doCompareCodePointOrder(start, limit - start,
03434            srcText, srcStart, srcLimit - srcStart); }
03435 
03436 inline int8_t
03437 UnicodeString::doCaseCompare(int32_t start,
03438                              int32_t length,
03439                              const UnicodeString &srcText,
03440                              int32_t srcStart,
03441                              int32_t srcLength,
03442                              uint32_t options) const
03443 {
03444   if(srcText.isBogus()) {
03445     return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
03446   } else {
03447     srcText.pinIndices(srcStart, srcLength);
03448     return doCaseCompare(start, length, srcText.fArray, srcStart, srcLength, options);
03449   }
03450 }
03451 
03452 inline int8_t
03453 UnicodeString::caseCompare(const UnicodeString &text, uint32_t options) const {
03454   return doCaseCompare(0, fLength, text, 0, text.fLength, options);
03455 }
03456 
03457 inline int8_t
03458 UnicodeString::caseCompare(int32_t start,
03459                            int32_t _length,
03460                            const UnicodeString &srcText,
03461                            uint32_t options) const {
03462   return doCaseCompare(start, _length, srcText, 0, srcText.fLength, options);
03463 }
03464 
03465 inline int8_t
03466 UnicodeString::caseCompare(const UChar *srcChars,
03467                            int32_t srcLength,
03468                            uint32_t options) const {
03469   return doCaseCompare(0, fLength, srcChars, 0, srcLength, options);
03470 }
03471 
03472 inline int8_t
03473 UnicodeString::caseCompare(int32_t start,
03474                            int32_t _length,
03475                            const UnicodeString &srcText,
03476                            int32_t srcStart,
03477                            int32_t srcLength,
03478                            uint32_t options) const {
03479   return doCaseCompare(start, _length, srcText, srcStart, srcLength, options);
03480 }
03481 
03482 inline int8_t
03483 UnicodeString::caseCompare(int32_t start,
03484                            int32_t _length,
03485                            const UChar *srcChars,
03486                            uint32_t options) const {
03487   return doCaseCompare(start, _length, srcChars, 0, _length, options);
03488 }
03489 
03490 inline int8_t
03491 UnicodeString::caseCompare(int32_t start,
03492                            int32_t _length,
03493                            const UChar *srcChars,
03494                            int32_t srcStart,
03495                            int32_t srcLength,
03496                            uint32_t options) const {
03497   return doCaseCompare(start, _length, srcChars, srcStart, srcLength, options);
03498 }
03499 
03500 inline int8_t
03501 UnicodeString::caseCompareBetween(int32_t start,
03502                                   int32_t limit,
03503                                   const UnicodeString &srcText,
03504                                   int32_t srcStart,
03505                                   int32_t srcLimit,
03506                                   uint32_t options) const {
03507   return doCaseCompare(start, limit - start, srcText, srcStart, srcLimit - srcStart, options);
03508 }
03509 
03510 inline int32_t
03511 UnicodeString::indexOf(const UnicodeString& srcText,
03512                int32_t srcStart,
03513                int32_t srcLength,
03514                int32_t start,
03515                int32_t _length) const
03516 {
03517   if(!srcText.isBogus()) {
03518     srcText.pinIndices(srcStart, srcLength);
03519     if(srcLength > 0) {
03520       return indexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
03521     }
03522   }
03523   return -1;
03524 }
03525 
03526 inline int32_t
03527 UnicodeString::indexOf(const UnicodeString& text) const
03528 { return indexOf(text, 0, text.fLength, 0, fLength); }
03529 
03530 inline int32_t
03531 UnicodeString::indexOf(const UnicodeString& text,
03532                int32_t start) const {
03533   pinIndex(start);
03534   return indexOf(text, 0, text.fLength, start, fLength - start);
03535 }
03536 
03537 inline int32_t
03538 UnicodeString::indexOf(const UnicodeString& text,
03539                int32_t start,
03540                int32_t _length) const
03541 { return indexOf(text, 0, text.fLength, start, _length); }
03542 
03543 inline int32_t
03544 UnicodeString::indexOf(const UChar *srcChars,
03545                int32_t srcLength,
03546                int32_t start) const {
03547   pinIndex(start);
03548   return indexOf(srcChars, 0, srcLength, start, fLength - start);
03549 }
03550 
03551 inline int32_t
03552 UnicodeString::indexOf(const UChar *srcChars,
03553                int32_t srcLength,
03554                int32_t start,
03555                int32_t _length) const
03556 { return indexOf(srcChars, 0, srcLength, start, _length); }
03557 
03558 inline int32_t
03559 UnicodeString::indexOf(UChar c,
03560                int32_t start,
03561                int32_t _length) const
03562 { return doIndexOf(c, start, _length); }
03563 
03564 inline int32_t
03565 UnicodeString::indexOf(UChar32 c,
03566                int32_t start,
03567                int32_t _length) const
03568 { return doIndexOf(c, start, _length); }
03569 
03570 inline int32_t
03571 UnicodeString::indexOf(UChar c) const
03572 { return doIndexOf(c, 0, fLength); }
03573 
03574 inline int32_t
03575 UnicodeString::indexOf(UChar32 c) const
03576 { return indexOf(c, 0, fLength); }
03577 
03578 inline int32_t
03579 UnicodeString::indexOf(UChar c,
03580                int32_t start) const {
03581   pinIndex(start);
03582   return doIndexOf(c, start, fLength - start);
03583 }
03584 
03585 inline int32_t
03586 UnicodeString::indexOf(UChar32 c,
03587                int32_t start) const {
03588   pinIndex(start);
03589   return indexOf(c, start, fLength - start);
03590 }
03591 
03592 inline int32_t
03593 UnicodeString::lastIndexOf(const UChar *srcChars,
03594                int32_t srcLength,
03595                int32_t start,
03596                int32_t _length) const
03597 { return lastIndexOf(srcChars, 0, srcLength, start, _length); }
03598 
03599 inline int32_t
03600 UnicodeString::lastIndexOf(const UChar *srcChars,
03601                int32_t srcLength,
03602                int32_t start) const {
03603   pinIndex(start);
03604   return lastIndexOf(srcChars, 0, srcLength, start, fLength - start);
03605 }
03606 
03607 inline int32_t
03608 UnicodeString::lastIndexOf(const UnicodeString& srcText,
03609                int32_t srcStart,
03610                int32_t srcLength,
03611                int32_t start,
03612                int32_t _length) const
03613 {
03614   if(!srcText.isBogus()) {
03615     srcText.pinIndices(srcStart, srcLength);
03616     if(srcLength > 0) {
03617       return lastIndexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
03618     }
03619   }
03620   return -1;
03621 }
03622 
03623 inline int32_t
03624 UnicodeString::lastIndexOf(const UnicodeString& text,
03625                int32_t start,
03626                int32_t _length) const
03627 { return lastIndexOf(text, 0, text.fLength, start, _length); }
03628 
03629 inline int32_t
03630 UnicodeString::lastIndexOf(const UnicodeString& text,
03631                int32_t start) const {
03632   pinIndex(start);
03633   return lastIndexOf(text, 0, text.fLength, start, fLength - start);
03634 }
03635 
03636 inline int32_t
03637 UnicodeString::lastIndexOf(const UnicodeString& text) const
03638 { return lastIndexOf(text, 0, text.fLength, 0, fLength); }
03639 
03640 inline int32_t
03641 UnicodeString::lastIndexOf(UChar c,
03642                int32_t start,
03643                int32_t _length) const
03644 { return doLastIndexOf(c, start, _length); }
03645 
03646 inline int32_t
03647 UnicodeString::lastIndexOf(UChar32 c,
03648                int32_t start,
03649                int32_t _length) const {
03650   return doLastIndexOf(c, start, _length);
03651 }
03652 
03653 inline int32_t
03654 UnicodeString::lastIndexOf(UChar c) const
03655 { return doLastIndexOf(c, 0, fLength); }
03656 
03657 inline int32_t
03658 UnicodeString::lastIndexOf(UChar32 c) const {
03659   return lastIndexOf(c, 0, fLength);
03660 }
03661 
03662 inline int32_t
03663 UnicodeString::lastIndexOf(UChar c,
03664                int32_t start) const {
03665   pinIndex(start);
03666   return doLastIndexOf(c, start, fLength - start);
03667 }
03668 
03669 inline int32_t
03670 UnicodeString::lastIndexOf(UChar32 c,
03671                int32_t start) const {
03672   pinIndex(start);
03673   return lastIndexOf(c, start, fLength - start);
03674 }
03675 
03676 inline UBool
03677 UnicodeString::startsWith(const UnicodeString& text) const
03678 { return compare(0, text.fLength, text, 0, text.fLength) == 0; }
03679 
03680 inline UBool
03681 UnicodeString::startsWith(const UnicodeString& srcText,
03682               int32_t srcStart,
03683               int32_t srcLength) const
03684 { return doCompare(0, srcLength, srcText, srcStart, srcLength) == 0; }
03685 
03686 inline UBool
03687 UnicodeString::startsWith(const UChar *srcChars,
03688               int32_t srcLength) const
03689 { return doCompare(0, srcLength, srcChars, 0, srcLength) == 0; }
03690 
03691 inline UBool
03692 UnicodeString::startsWith(const UChar *srcChars,
03693               int32_t srcStart,
03694               int32_t srcLength) const
03695 { return doCompare(0, srcLength, srcChars, srcStart, srcLength) == 0;}
03696 
03697 inline UBool
03698 UnicodeString::endsWith(const UnicodeString& text) const
03699 { return doCompare(fLength - text.fLength, text.fLength,
03700            text, 0, text.fLength) == 0; }
03701 
03702 inline UBool
03703 UnicodeString::endsWith(const UnicodeString& srcText,
03704             int32_t srcStart,
03705             int32_t srcLength) const {
03706   srcText.pinIndices(srcStart, srcLength);
03707   return doCompare(fLength - srcLength, srcLength,
03708                    srcText, srcStart, srcLength) == 0;
03709 }
03710 
03711 inline UBool
03712 UnicodeString::endsWith(const UChar *srcChars,
03713             int32_t srcLength) const {
03714   if(srcLength < 0) {
03715     srcLength = u_strlen(srcChars);
03716   }
03717   return doCompare(fLength - srcLength, srcLength,
03718                    srcChars, 0, srcLength) == 0;
03719 }
03720 
03721 inline UBool
03722 UnicodeString::endsWith(const UChar *srcChars,
03723             int32_t srcStart,
03724             int32_t srcLength) const {
03725   if(srcLength < 0) {
03726     srcLength = u_strlen(srcChars + srcStart);
03727   }
03728   return doCompare(fLength - srcLength, srcLength,
03729                    srcChars, srcStart, srcLength) == 0;
03730 }
03731 
03732 //========================================
03733 // replace
03734 //========================================
03735 inline UnicodeString&
03736 UnicodeString::replace(int32_t start,
03737                int32_t _length,
03738                const UnicodeString& srcText)
03739 { return doReplace(start, _length, srcText, 0, srcText.fLength); }
03740 
03741 inline UnicodeString&
03742 UnicodeString::replace(int32_t start,
03743                int32_t _length,
03744                const UnicodeString& srcText,
03745                int32_t srcStart,
03746                int32_t srcLength)
03747 { return doReplace(start, _length, srcText, srcStart, srcLength); }
03748 
03749 inline UnicodeString&
03750 UnicodeString::replace(int32_t start,
03751                int32_t _length,
03752                const UChar *srcChars,
03753                int32_t srcLength)
03754 { return doReplace(start, _length, srcChars, 0, srcLength); }
03755 
03756 inline UnicodeString&
03757 UnicodeString::replace(int32_t start,
03758                int32_t _length,
03759                const UChar *srcChars,
03760                int32_t srcStart,
03761                int32_t srcLength)
03762 { return doReplace(start, _length, srcChars, srcStart, srcLength); }
03763 
03764 inline UnicodeString&
03765 UnicodeString::replace(int32_t start,
03766                int32_t _length,
03767                UChar srcChar)
03768 { return doReplace(start, _length, &srcChar, 0, 1); }
03769 
03770 inline UnicodeString&
03771 UnicodeString::replace(int32_t start,
03772                int32_t _length,
03773                UChar32 srcChar) {
03774   UChar buffer[U16_MAX_LENGTH];
03775   int32_t count = 0;
03776   UBool isError = FALSE;
03777   U16_APPEND(buffer, count, U16_MAX_LENGTH, srcChar, isError);
03778   return doReplace(start, _length, buffer, 0, count);
03779 }
03780 
03781 inline UnicodeString&
03782 UnicodeString::replaceBetween(int32_t start,
03783                   int32_t limit,
03784                   const UnicodeString& srcText)
03785 { return doReplace(start, limit - start, srcText, 0, srcText.fLength); }
03786 
03787 inline UnicodeString&
03788 UnicodeString::replaceBetween(int32_t start,
03789                   int32_t limit,
03790                   const UnicodeString& srcText,
03791                   int32_t srcStart,
03792                   int32_t srcLimit)
03793 { return doReplace(start, limit - start, srcText, srcStart, srcLimit - srcStart); }
03794 
03795 inline UnicodeString&
03796 UnicodeString::findAndReplace(const UnicodeString& oldText,
03797                   const UnicodeString& newText)
03798 { return findAndReplace(0, fLength, oldText, 0, oldText.fLength,
03799             newText, 0, newText.fLength); }
03800 
03801 inline UnicodeString&
03802 UnicodeString::findAndReplace(int32_t start,
03803                   int32_t _length,
03804                   const UnicodeString& oldText,
03805                   const UnicodeString& newText)
03806 { return findAndReplace(start, _length, oldText, 0, oldText.fLength,
03807             newText, 0, newText.fLength); }
03808 
03809 // ============================
03810 // extract
03811 // ============================
03812 inline void
03813 UnicodeString::doExtract(int32_t start,
03814              int32_t _length,
03815              UnicodeString& target) const
03816 { target.replace(0, target.fLength, *this, start, _length); }
03817 
03818 inline void
03819 UnicodeString::extract(int32_t start,
03820                int32_t _length,
03821                UChar *target,
03822                int32_t targetStart) const
03823 { doExtract(start, _length, target, targetStart); }
03824 
03825 inline void
03826 UnicodeString::extract(int32_t start,
03827                int32_t _length,
03828                UnicodeString& target) const
03829 { doExtract(start, _length, target); }
03830 
03831 #if !UCONFIG_NO_CONVERSION
03832 
03833 inline int32_t
03834 UnicodeString::extract(int32_t start,
03835                int32_t _length,
03836                char *dst,
03837                const char *codepage) const
03838 
03839 {
03840   // This dstSize value will be checked explicitly
03841   return extract(start, _length, dst, dst!=0 ? 0xffffffff : 0, codepage);
03842 }
03843 
03844 #endif
03845 
03846 inline void
03847 UnicodeString::extractBetween(int32_t start,
03848                   int32_t limit,
03849                   UChar *dst,
03850                   int32_t dstStart) const {
03851   pinIndex(start);
03852   pinIndex(limit);
03853   doExtract(start, limit - start, dst, dstStart);
03854 }
03855 
03856 inline UChar
03857 UnicodeString::doCharAt(int32_t offset) const
03858 {
03859   if((uint32_t)offset < (uint32_t)fLength) {
03860     return fArray[offset];
03861   } else {
03862     return kInvalidUChar;
03863   }
03864 }
03865 
03866 inline UChar
03867 UnicodeString::charAt(int32_t offset) const
03868 { return doCharAt(offset); }
03869 
03870 inline UChar
03871 UnicodeString::operator[] (int32_t offset) const
03872 { return doCharAt(offset); }
03873 
03874 inline UChar32
03875 UnicodeString::char32At(int32_t offset) const
03876 {
03877   if((uint32_t)offset < (uint32_t)fLength) {
03878     UChar32 c;
03879     U16_GET(fArray, 0, offset, fLength, c);
03880     return c;
03881   } else {
03882     return kInvalidUChar;
03883   }
03884 }
03885 
03886 inline int32_t
03887 UnicodeString::getChar32Start(int32_t offset) const {
03888   if((uint32_t)offset < (uint32_t)fLength) {
03889     U16_SET_CP_START(fArray, 0, offset);
03890     return offset;
03891   } else {
03892     return 0;
03893   }
03894 }
03895 
03896 inline int32_t
03897 UnicodeString::getChar32Limit(int32_t offset) const {
03898   if((uint32_t)offset < (uint32_t)fLength) {
03899     U16_SET_CP_LIMIT(fArray, 0, offset, fLength);
03900     return offset;
03901   } else {
03902     return fLength;
03903   }
03904 }
03905 
03906 inline UBool
03907 UnicodeString::isEmpty() const {
03908   return fLength == 0;
03909 }
03910 
03911 //========================================
03912 // Write implementation methods
03913 //========================================
03914 inline const UChar *
03915 UnicodeString::getTerminatedBuffer() {
03916   if(fFlags&(kIsBogus|kOpenGetBuffer)) {
03917     return 0;
03918   } else if(fLength<fCapacity && fArray[fLength]==0) {
03919     return fArray;
03920   } else if(cloneArrayIfNeeded(fLength+1)) {
03921     fArray[fLength]=0;
03922     return fArray;
03923   } else {
03924     return 0;
03925   }
03926 }
03927 
03928 inline UnicodeString&
03929 UnicodeString::operator= (UChar ch)
03930 { return doReplace(0, fLength, &ch, 0, 1); }
03931 
03932 inline UnicodeString&
03933 UnicodeString::operator= (UChar32 ch)
03934 { return replace(0, fLength, ch); }
03935 
03936 inline UnicodeString&
03937 UnicodeString::setTo(const UnicodeString& srcText,
03938              int32_t srcStart,
03939              int32_t srcLength)
03940 {
03941   unBogus();
03942   return doReplace(0, fLength, srcText, srcStart, srcLength);
03943 }
03944 
03945 inline UnicodeString&
03946 UnicodeString::setTo(const UnicodeString& srcText,
03947              int32_t srcStart)
03948 {
03949   unBogus();
03950   srcText.pinIndex(srcStart);
03951   return doReplace(0, fLength, srcText, srcStart, srcText.fLength - srcStart);
03952 }
03953 
03954 inline UnicodeString&
03955 UnicodeString::setTo(const UnicodeString& srcText)
03956 {
03957   unBogus();
03958   return doReplace(0, fLength, srcText, 0, srcText.fLength);
03959 }
03960 
03961 inline UnicodeString&
03962 UnicodeString::setTo(const UChar *srcChars,
03963              int32_t srcLength)
03964 {
03965   unBogus();
03966   return doReplace(0, fLength, srcChars, 0, srcLength);
03967 }
03968 
03969 inline UnicodeString&
03970 UnicodeString::setTo(UChar srcChar)
03971 {
03972   unBogus();
03973   return doReplace(0, fLength, &srcChar, 0, 1);
03974 }
03975 
03976 inline UnicodeString&
03977 UnicodeString::setTo(UChar32 srcChar)
03978 {
03979   unBogus();
03980   return replace(0, fLength, srcChar);
03981 }
03982 
03983 inline UnicodeString&
03984 UnicodeString::append(const UnicodeString& srcText,
03985               int32_t srcStart,
03986               int32_t srcLength)
03987 { return doReplace(fLength, 0, srcText, srcStart, srcLength); }
03988 
03989 inline UnicodeString&
03990 UnicodeString::append(const UnicodeString& srcText)
03991 { return doReplace(fLength, 0, srcText, 0, srcText.fLength); }
03992 
03993 inline UnicodeString&
03994 UnicodeString::append(const UChar *srcChars,
03995               int32_t srcStart,
03996               int32_t srcLength)
03997 { return doReplace(fLength, 0, srcChars, srcStart, srcLength); }
03998 
03999 inline UnicodeString&
04000 UnicodeString::append(const UChar *srcChars,
04001               int32_t srcLength)
04002 { return doReplace(fLength, 0, srcChars, 0, srcLength); }
04003 
04004 inline UnicodeString&
04005 UnicodeString::append(UChar srcChar)
04006 { return doReplace(fLength, 0, &srcChar, 0, 1); }
04007 
04008 inline UnicodeString&
04009 UnicodeString::append(UChar32 srcChar) {
04010   UChar buffer[U16_MAX_LENGTH];
04011   int32_t _length = 0;
04012   UBool isError = FALSE;
04013   U16_APPEND(buffer, _length, U16_MAX_LENGTH, srcChar, isError);
04014   return doReplace(fLength, 0, buffer, 0, _length);
04015 }
04016 
04017 inline UnicodeString&
04018 UnicodeString::operator+= (UChar ch)
04019 { return doReplace(fLength, 0, &ch, 0, 1); }
04020 
04021 inline UnicodeString&
04022 UnicodeString::operator+= (UChar32 ch) {
04023   return append(ch);
04024 }
04025 
04026 inline UnicodeString&
04027 UnicodeString::operator+= (const UnicodeString& srcText)
04028 { return doReplace(fLength, 0, srcText, 0, srcText.fLength); }
04029 
04030 inline UnicodeString&
04031 UnicodeString::insert(int32_t start,
04032               const UnicodeString& srcText,
04033               int32_t srcStart,
04034               int32_t srcLength)
04035 { return doReplace(start, 0, srcText, srcStart, srcLength); }
04036 
04037 inline UnicodeString&
04038 UnicodeString::insert(int32_t start,
04039               const UnicodeString& srcText)
04040 { return doReplace(start, 0, srcText, 0, srcText.fLength); }
04041 
04042 inline UnicodeString&
04043 UnicodeString::insert(int32_t start,
04044               const UChar *srcChars,
04045               int32_t srcStart,
04046               int32_t srcLength)
04047 { return doReplace(start, 0, srcChars, srcStart, srcLength); }
04048 
04049 inline UnicodeString&
04050 UnicodeString::insert(int32_t start,
04051               const UChar *srcChars,
04052               int32_t srcLength)
04053 { return doReplace(start, 0, srcChars, 0, srcLength); }
04054 
04055 inline UnicodeString&
04056 UnicodeString::insert(int32_t start,
04057               UChar srcChar)
04058 { return doReplace(start, 0, &srcChar, 0, 1); }
04059 
04060 inline UnicodeString&
04061 UnicodeString::insert(int32_t start,
04062               UChar32 srcChar)
04063 { return replace(start, 0, srcChar); }
04064 
04065 
04066 inline UnicodeString&
04067 UnicodeString::remove()
04068 {
04069   // remove() of a bogus string makes the string empty and non-bogus
04070   if(isBogus()) {
04071     unBogus();
04072   } else {
04073     fLength = 0;
04074   }
04075   return *this;
04076 }
04077 
04078 inline UnicodeString&
04079 UnicodeString::remove(int32_t start,
04080              int32_t _length)
04081 {
04082     if(start <= 0 && _length == INT32_MAX) {
04083         // remove(guaranteed everything) of a bogus string makes the string empty and non-bogus
04084         return remove();
04085     }
04086     return doReplace(start, _length, NULL, 0, 0);
04087 }
04088 
04089 inline UnicodeString&
04090 UnicodeString::removeBetween(int32_t start,
04091                 int32_t limit)
04092 { return doReplace(start, limit - start, NULL, 0, 0); }
04093 
04094 inline UBool
04095 UnicodeString::truncate(int32_t targetLength)
04096 {
04097   if(isBogus() && targetLength == 0) {
04098     // truncate(0) of a bogus string makes the string empty and non-bogus
04099     unBogus();
04100     return FALSE;
04101   } else if((uint32_t)targetLength < (uint32_t)fLength) {
04102     fLength = targetLength;
04103     return TRUE;
04104   } else {
04105     return FALSE;
04106   }
04107 }
04108 
04109 inline UnicodeString&
04110 UnicodeString::reverse()
04111 { return doReverse(0, fLength); }
04112 
04113 inline UnicodeString&
04114 UnicodeString::reverse(int32_t start,
04115                int32_t _length)
04116 { return doReverse(start, _length); }
04117 
04118 U_NAMESPACE_END
04119 
04120 #endif

Generated on Mon Aug 13 07:17:24 2007 for ICU 3.6 by  doxygen 1.5.2