Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

unistr.h

Go to the documentation of this file.
00001 /*
00002 **********************************************************************
00003 *   Copyright (C) 1998-2001, 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 ******************************************************************************
00018 */
00019 
00020 #ifndef UNISTR_H
00021 #define UNISTR_H
00022 
00023 #include "unicode/utypes.h"
00024 #include "unicode/rep.h"
00025 #include "unicode/uchar.h"
00026 
00027 class Locale;               // unicode/locid.h
00028 class UCharReference;
00029 class UnicodeStringStreamer;// unicode/unistrm.h
00030 class UnicodeConverter;     // unicode/convert.h
00031 struct UConverter;          // unicode/ucnv.h
00032 
00033 // for unistrm.h
00040 #if U_IOSTREAM_SOURCE >= 199711
00041 #include <iostream>
00042 U_COMMON_API std::ostream &operator<<(std::ostream& stream, const UnicodeString& s);
00043 #elif U_IOSTREAM_SOURCE >= 198506
00044 #include <iostream.h>
00045 U_COMMON_API ostream &operator<<(ostream& stream, const UnicodeString& s);
00046 #endif
00047 
00064 #if U_SIZEOF_WCHAR_T==U_SIZEOF_UCHAR && U_CHARSET_FAMILY==U_ASCII_FAMILY
00065 #   define UNICODE_STRING(cs, length) UnicodeString(TRUE, (UChar *)L ## cs, length)
00066 #elif U_SIZEOF_UCHAR==1 && U_CHARSET_FAMILY==U_ASCII_FAMILY
00067 #   define UNICODE_STRING(cs, length) UnicodeString(TRUE, (UChar *)cs, length)
00068 #else
00069 #   define UNICODE_STRING(cs, length) UnicodeString(cs, length, "")
00070 #endif
00071 
00129 class U_COMMON_API UnicodeString : public Replaceable
00130 {
00131 public:
00132 
00133   //========================================
00134   // Read-only operations
00135   //========================================
00136 
00137   /* Comparison - bitwise only - for international comparison use collation */
00138 
00146   inline UBool operator== (const UnicodeString& text) const;
00147 
00155   inline UBool operator!= (const UnicodeString& text) const;
00156 
00164   inline UBool operator> (const UnicodeString& text) const;
00165 
00173   inline UBool operator< (const UnicodeString& text) const;
00174 
00182   inline UBool operator>= (const UnicodeString& text) const;
00183 
00191   inline UBool operator<= (const UnicodeString& text) const;
00192 
00204   inline int8_t compare(const UnicodeString& text) const;
00205 
00220   inline int8_t compare(UTextOffset start,
00221          int32_t length,
00222          const UnicodeString& srcText) const;
00223 
00241    inline int8_t compare(UTextOffset start,
00242          int32_t length,
00243          const UnicodeString& srcText,
00244          UTextOffset srcStart,
00245          int32_t srcLength) const;
00246 
00259   inline int8_t compare(const UChar *srcChars,
00260          int32_t srcLength) const;
00261 
00276   inline int8_t compare(UTextOffset start,
00277          int32_t length,
00278          const UChar *srcChars) const;
00279 
00297   inline int8_t compare(UTextOffset start,
00298          int32_t length,
00299          const UChar *srcChars,
00300          UTextOffset srcStart,
00301          int32_t srcLength) const;
00302 
00320   inline int8_t compareBetween(UTextOffset start,
00321             UTextOffset limit,
00322             const UnicodeString& srcText,
00323             UTextOffset srcStart,
00324             UTextOffset srcLimit) const;
00325 
00343   inline int8_t compareCodePointOrder(const UnicodeString& text) const;
00344 
00364   inline int8_t compareCodePointOrder(UTextOffset start,
00365                                       int32_t length,
00366                                       const UnicodeString& srcText) const;
00367 
00389    inline int8_t compareCodePointOrder(UTextOffset start,
00390                                        int32_t length,
00391                                        const UnicodeString& srcText,
00392                                        UTextOffset srcStart,
00393                                        int32_t srcLength) const;
00394 
00413   inline int8_t compareCodePointOrder(const UChar *srcChars,
00414                                       int32_t srcLength) const;
00415 
00435   inline int8_t compareCodePointOrder(UTextOffset start,
00436                                       int32_t length,
00437                                       const UChar *srcChars) const;
00438 
00460   inline int8_t compareCodePointOrder(UTextOffset start,
00461                                       int32_t length,
00462                                       const UChar *srcChars,
00463                                       UTextOffset srcStart,
00464                                       int32_t srcLength) const;
00465 
00487   inline int8_t compareCodePointOrderBetween(UTextOffset start,
00488                                              UTextOffset limit,
00489                                              const UnicodeString& srcText,
00490                                              UTextOffset srcStart,
00491                                              UTextOffset srcLimit) const;
00492 
00502   inline int8_t caseCompare(const UnicodeString& text, uint32_t options) const;
00503 
00515   inline int8_t caseCompare(UTextOffset start,
00516          int32_t length,
00517          const UnicodeString& srcText,
00518          uint32_t options) const;
00519 
00533   inline int8_t caseCompare(UTextOffset start,
00534          int32_t length,
00535          const UnicodeString& srcText,
00536          UTextOffset srcStart,
00537          int32_t srcLength,
00538          uint32_t options) const;
00539 
00550   inline int8_t caseCompare(const UChar *srcChars,
00551          int32_t srcLength,
00552          uint32_t options) const;
00553 
00565   inline int8_t caseCompare(UTextOffset start,
00566          int32_t length,
00567          const UChar *srcChars,
00568          uint32_t options) const;
00569 
00583   inline int8_t caseCompare(UTextOffset start,
00584          int32_t length,
00585          const UChar *srcChars,
00586          UTextOffset srcStart,
00587          int32_t srcLength,
00588          uint32_t options) const;
00589 
00603   inline int8_t caseCompareBetween(UTextOffset start,
00604             UTextOffset limit,
00605             const UnicodeString& srcText,
00606             UTextOffset srcStart,
00607             UTextOffset srcLimit,
00608             uint32_t options) const;
00609 
00617   inline UBool startsWith(const UnicodeString& text) const;
00618 
00629   inline UBool startsWith(const UnicodeString& srcText,
00630             UTextOffset srcStart,
00631             int32_t srcLength) const;
00632 
00641   inline UBool startsWith(const UChar *srcChars,
00642             int32_t srcLength) const;
00643 
00654   inline UBool startsWith(const UChar *srcChars,
00655             UTextOffset srcStart,
00656             int32_t srcLength) const;
00657 
00665   inline UBool endsWith(const UnicodeString& text) const;
00666 
00677   inline UBool endsWith(const UnicodeString& srcText,
00678           UTextOffset srcStart,
00679           int32_t srcLength) const;
00680 
00689   inline UBool endsWith(const UChar *srcChars,
00690           int32_t srcLength) const;
00691 
00702   inline UBool endsWith(const UChar *srcChars,
00703           UTextOffset srcStart,
00704           int32_t srcLength) const;
00705 
00706 
00707   /* Searching - bitwise only */
00708 
00717   inline UTextOffset indexOf(const UnicodeString& text) const;
00718 
00728   inline UTextOffset indexOf(const UnicodeString& text,
00729               UTextOffset start) const;
00730 
00742   inline UTextOffset indexOf(const UnicodeString& text,
00743               UTextOffset start,
00744               int32_t length) const;
00745 
00762   inline UTextOffset indexOf(const UnicodeString& srcText,
00763               UTextOffset srcStart,
00764               int32_t srcLength,
00765               UTextOffset start,
00766               int32_t length) const;
00767 
00779   inline UTextOffset indexOf(const UChar *srcChars,
00780               int32_t srcLength,
00781               UTextOffset start) const;
00782 
00795   inline UTextOffset indexOf(const UChar *srcChars,
00796               int32_t srcLength,
00797               UTextOffset start,
00798               int32_t length) const;
00799  
00816   UTextOffset indexOf(const UChar *srcChars,
00817               UTextOffset srcStart,
00818               int32_t srcLength,
00819               UTextOffset start,
00820               int32_t length) const;
00821 
00829   inline UTextOffset indexOf(UChar c) const;
00830 
00838   inline UTextOffset indexOf(UChar32 c) const;
00839 
00848   inline UTextOffset indexOf(UChar c,
00849               UTextOffset start) const;
00850 
00859   inline UTextOffset indexOf(UChar32 c,
00860               UTextOffset start) const;
00861 
00872   inline UTextOffset indexOf(UChar c,
00873               UTextOffset start,
00874               int32_t length) const;
00875 
00886   inline UTextOffset indexOf(UChar32 c,
00887               UTextOffset start,
00888               int32_t length) const;
00889 
00898   inline UTextOffset lastIndexOf(const UnicodeString& text) const;
00899 
00909   inline UTextOffset lastIndexOf(const UnicodeString& text,
00910               UTextOffset start) const;
00911 
00923   inline UTextOffset lastIndexOf(const UnicodeString& text,
00924               UTextOffset start,
00925               int32_t length) const;
00926 
00943   inline UTextOffset lastIndexOf(const UnicodeString& srcText,
00944               UTextOffset srcStart,
00945               int32_t srcLength,
00946               UTextOffset start,
00947               int32_t length) const;
00948 
00959   inline UTextOffset lastIndexOf(const UChar *srcChars,
00960               int32_t srcLength,
00961               UTextOffset start) const;
00962 
00975   inline UTextOffset lastIndexOf(const UChar *srcChars,
00976               int32_t srcLength,
00977               UTextOffset start,
00978               int32_t length) const;
00979  
00996   UTextOffset lastIndexOf(const UChar *srcChars,
00997               UTextOffset srcStart,
00998               int32_t srcLength,
00999               UTextOffset start,
01000               int32_t length) const;
01001 
01009   inline UTextOffset lastIndexOf(UChar c) const;
01010 
01018   inline UTextOffset lastIndexOf(UChar32 c) const;
01019 
01028   inline UTextOffset lastIndexOf(UChar c,
01029               UTextOffset start) const;
01030 
01039   inline UTextOffset lastIndexOf(UChar32 c,
01040               UTextOffset start) const;
01041 
01052   inline UTextOffset lastIndexOf(UChar c,
01053               UTextOffset start,
01054               int32_t length) const;
01055 
01066   inline UTextOffset lastIndexOf(UChar32 c,
01067               UTextOffset start,
01068               int32_t length) const;
01069 
01070 
01071   /* Character access */
01072 
01079   inline UChar charAt(UTextOffset offset) const;
01080 
01087   inline UChar operator [] (UTextOffset offset) const;
01088 
01098   inline UChar32 char32At(UTextOffset offset) const;
01099 
01113   inline UTextOffset getCharStart(UTextOffset offset);
01114 
01129   inline UTextOffset getCharLimit(UTextOffset offset);
01130 
01131   /* Substring extraction */
01132 
01148   inline void extract(UTextOffset start, 
01149            int32_t length, 
01150            UChar *dst, 
01151            UTextOffset dstStart = 0) const;
01152 
01163   inline void extract(UTextOffset start,
01164            int32_t length,
01165            UnicodeString& target) const;
01166 
01178   inline void extractBetween(UTextOffset start, 
01179               UTextOffset limit, 
01180               UChar *dst, 
01181               UTextOffset dstStart = 0) const;
01182 
01192   inline void extractBetween(UTextOffset start,
01193               UTextOffset limit,
01194               UnicodeString& target) const;
01195 
01214   inline int32_t extract(UTextOffset start,
01215                  int32_t startLength,
01216                  char *target,
01217                  const char *codepage = 0) const;
01218 
01237   int32_t extract(UTextOffset start,
01238            int32_t startLength,
01239            char *target,
01240            uint32_t targetLength,
01241            const char *codepage = 0) const;
01242 
01243   /* Length operations */
01244 
01251   inline int32_t  length(void) const;
01252 
01258   inline UBool empty(void) const;
01259 
01260 
01261   /* Other operations */
01262 
01268   inline int32_t hashCode(void) const;
01269 
01275   inline UBool isBogus(void) const;
01276 
01277 
01278   //========================================
01279   // Write operations
01280   //========================================
01281 
01282   /* Assignment operations */
01283 
01291    UnicodeString& operator= (const UnicodeString& srcText);
01292 
01300   inline UnicodeString& operator= (UChar ch);
01301 
01309   inline UnicodeString& operator= (UChar32 ch);
01310 
01324   inline UnicodeString& setTo(const UnicodeString& srcText, 
01325                UTextOffset srcStart, 
01326                int32_t srcLength);
01327 
01336   inline UnicodeString& setTo(const UnicodeString& srcText);
01337 
01346   inline UnicodeString& setTo(const UChar *srcChars,
01347                int32_t srcLength);
01348 
01357   UnicodeString& setTo(UChar srcChar);
01358 
01367   UnicodeString& setTo(UChar32 srcChar);
01368 
01388   UnicodeString &setTo(UBool isTerminated,
01389                        const UChar *text,
01390                        int32_t textLength);
01391 
01410   UnicodeString &setTo(UChar *buffer,
01411                        int32_t buffLength,
01412                        int32_t buffCapacity);
01413 
01421   UnicodeString& setCharAt(UTextOffset offset, 
01422                UChar ch);
01423 
01424 
01425   /* Append operations */
01426 
01434  inline  UnicodeString& operator+= (UChar ch);
01435 
01443  inline  UnicodeString& operator+= (UChar32 ch);
01444 
01453   inline UnicodeString& operator+= (const UnicodeString& srcText);
01454 
01469   inline UnicodeString& append(const UnicodeString& srcText, 
01470             UTextOffset srcStart, 
01471             int32_t srcLength);
01472 
01480   inline UnicodeString& append(const UnicodeString& srcText);
01481 
01495   inline UnicodeString& append(const UChar *srcChars, 
01496             UTextOffset srcStart, 
01497             int32_t srcLength);
01498 
01507   inline UnicodeString& append(const UChar *srcChars,
01508             int32_t srcLength);
01509 
01516   inline UnicodeString& append(UChar srcChar);
01517 
01524   inline UnicodeString& append(UChar32 srcChar);
01525 
01526 
01527   /* Insert operations */
01528 
01542   inline UnicodeString& insert(UTextOffset start, 
01543             const UnicodeString& srcText, 
01544             UTextOffset srcStart, 
01545             int32_t srcLength);
01546 
01555   inline UnicodeString& insert(UTextOffset start, 
01556             const UnicodeString& srcText);
01557 
01571   inline UnicodeString& insert(UTextOffset start, 
01572             const UChar *srcChars, 
01573             UTextOffset srcStart, 
01574             int32_t srcLength);
01575 
01585   inline UnicodeString& insert(UTextOffset start, 
01586             const UChar *srcChars,
01587             int32_t srcLength);
01588 
01597   inline UnicodeString& insert(UTextOffset start, 
01598             UChar srcChar);
01599 
01608   inline UnicodeString& insert(UTextOffset start, 
01609             UChar32 srcChar);
01610 
01611 
01612   /* Replace operations */
01613 
01631   UnicodeString& replace(UTextOffset start, 
01632              int32_t length, 
01633              const UnicodeString& srcText, 
01634              UTextOffset srcStart, 
01635              int32_t srcLength);
01636 
01649   UnicodeString& replace(UTextOffset start, 
01650              int32_t length, 
01651              const UnicodeString& srcText);
01652 
01670   UnicodeString& replace(UTextOffset start, 
01671              int32_t length, 
01672              const UChar *srcChars, 
01673              UTextOffset srcStart, 
01674              int32_t srcLength);
01675 
01688   inline UnicodeString& replace(UTextOffset start, 
01689              int32_t length, 
01690              const UChar *srcChars,
01691              int32_t srcLength);
01692 
01704   inline UnicodeString& replace(UTextOffset start, 
01705              int32_t length, 
01706              UChar srcChar);
01707 
01719   inline UnicodeString& replace(UTextOffset start, 
01720              int32_t length, 
01721              UChar32 srcChar);
01722 
01732   inline UnicodeString& replaceBetween(UTextOffset start, 
01733                 UTextOffset limit, 
01734                 const UnicodeString& srcText);
01735 
01750   inline UnicodeString& replaceBetween(UTextOffset start, 
01751                 UTextOffset limit, 
01752                 const UnicodeString& srcText, 
01753                 UTextOffset srcStart, 
01754                 UTextOffset srcLimit);
01755 
01766   virtual void handleReplaceBetween(UTextOffset start,
01767                                     UTextOffset limit,
01768                                     const UnicodeString& text);
01769 
01784   virtual void copy(int32_t start, int32_t limit, int32_t dest);
01785 
01786   /* Search and replace operations */
01787 
01796   inline UnicodeString& findAndReplace(const UnicodeString& oldText,
01797                 const UnicodeString& newText);
01798 
01810   inline UnicodeString& findAndReplace(UTextOffset start,
01811                 int32_t length,
01812                 const UnicodeString& oldText,
01813                 const UnicodeString& newText);
01814 
01832   UnicodeString& findAndReplace(UTextOffset start,
01833                 int32_t length,
01834                 const UnicodeString& oldText,
01835                 UTextOffset oldStart,
01836                 int32_t oldLength,
01837                 const UnicodeString& newText,
01838                 UTextOffset newStart,
01839                 int32_t newLength);
01840 
01841 
01842   /* Remove operations */
01843 
01849   inline UnicodeString& remove(void);
01850 
01859   inline UnicodeString& remove(UTextOffset start, 
01860                                int32_t length = INT32_MAX);
01861 
01870   inline UnicodeString& removeBetween(UTextOffset start,
01871                                       UTextOffset limit = INT32_MAX);
01872 
01873 
01874   /* Length operations */
01875 
01887   UBool padLeading(int32_t targetLength,
01888                     UChar padChar = 0x0020);
01889 
01901   UBool padTrailing(int32_t targetLength,
01902                      UChar padChar = 0x0020);
01903 
01910   inline UBool truncate(int32_t targetLength);
01911 
01917   UnicodeString& trim(void);
01918 
01919 
01920   /* Miscellaneous operations */
01921 
01927   inline UnicodeString& reverse(void);
01928 
01937   inline UnicodeString& reverse(UTextOffset start,
01938              int32_t length);
01939 
01946   UnicodeString& toUpper(void);
01947 
01955   UnicodeString& toUpper(const Locale& locale);
01956 
01963   UnicodeString& toLower(void);
01964 
01972   UnicodeString& toLower(const Locale& locale);
01973 
01985   UnicodeString &foldCase(uint32_t options=U_FOLD_CASE_DEFAULT);
01986 
01987 
01988   //========================================
01989   // Constructors
01990   //========================================
01991 
01995   UnicodeString();
01996 
02008   UnicodeString(int32_t capacity, UChar32 c, int32_t count);
02009 
02015   UnicodeString(UChar ch);
02016 
02022   UnicodeString(UChar32 ch);
02023 
02030   UnicodeString(const UChar *text);
02031 
02039   UnicodeString(const UChar *text,
02040         int32_t textLength);
02041 
02061   UnicodeString(UBool isTerminated,
02062                 const UChar *text,
02063                 int32_t textLength);
02064 
02083   UnicodeString(UChar *buffer, int32_t buffLength, int32_t buffCapacity);
02084 
02096   UnicodeString(const char *codepageData,
02097         const char *codepage = 0);
02098 
02111   UnicodeString(const char *codepageData,
02112         int32_t dataLength,
02113         const char *codepage = 0);
02114 
02120   UnicodeString(const UnicodeString& that);
02121 
02125   ~UnicodeString();
02126 
02127 
02128   /* Miscellaneous operations */
02129 
02152   int32_t numDisplayCells(UTextOffset start = 0,
02153               int32_t length = INT32_MAX,
02154               UBool asian = TRUE) const;
02155 
02156 
02157   UCharReference operator[] (UTextOffset pos);
02158 
02191   UnicodeString unescape() const;
02192 
02211   UChar32 unescapeAt(int32_t &offset) const;
02212 
02213   //========================================
02214   // Implementation methods
02215   //========================================
02216 
02217 protected:
02222   virtual UChar getCharAt(UTextOffset offset) const;
02223 
02228   virtual UChar32 getChar32At(UTextOffset offset) const;
02229 
02230 private:
02231 
02232   inline int8_t
02233   doCompare(UTextOffset start,
02234            int32_t length,
02235            const UnicodeString& srcText,
02236            UTextOffset srcStart,
02237            int32_t srcLength) const;
02238 
02239   int8_t doCompare(UTextOffset start,
02240            int32_t length,
02241            const UChar *srcChars,
02242            UTextOffset srcStart,
02243            int32_t srcLength) const;
02244 
02245   inline int8_t
02246   doCompareCodePointOrder(UTextOffset start,
02247                           int32_t length,
02248                           const UnicodeString& srcText,
02249                           UTextOffset srcStart,
02250                           int32_t srcLength) const;
02251 
02252   int8_t doCompareCodePointOrder(UTextOffset start,
02253                                  int32_t length,
02254                                  const UChar *srcChars,
02255                                  UTextOffset srcStart,
02256                                  int32_t srcLength) const;
02257 
02258   inline int8_t
02259   doCaseCompare(UTextOffset start,
02260                 int32_t length,
02261                 const UnicodeString &srcText,
02262                 UTextOffset srcStart,
02263                 int32_t srcLength,
02264                 uint32_t options) const;
02265 
02266   int8_t
02267   doCaseCompare(UTextOffset start,
02268                 int32_t length,
02269                 const UChar *srcChars,
02270                 UTextOffset srcStart,
02271                 int32_t srcLength,
02272                 uint32_t options) const;
02273 
02274   UTextOffset doIndexOf(UChar c,
02275             UTextOffset start,
02276             int32_t length) const;
02277 
02278   UTextOffset doLastIndexOf(UChar c,
02279                 UTextOffset start,
02280                 int32_t length) const;
02281 
02282   void doExtract(UTextOffset start, 
02283          int32_t length, 
02284          UChar *dst, 
02285          UTextOffset dstStart) const;
02286 
02287   inline void doExtract(UTextOffset start,
02288          int32_t length,
02289          UnicodeString& target) const;
02290 
02291   inline UChar doCharAt(UTextOffset offset)  const;
02292 
02293   UnicodeString& doReplace(UTextOffset start, 
02294                int32_t length, 
02295                const UnicodeString& srcText, 
02296                UTextOffset srcStart, 
02297                int32_t srcLength);
02298 
02299   UnicodeString& doReplace(UTextOffset start, 
02300                int32_t length, 
02301                const UChar *srcChars, 
02302                UTextOffset srcStart, 
02303                int32_t srcLength);
02304 
02305   UnicodeString& doReverse(UTextOffset start,
02306                int32_t length);
02307 
02308   // calculate hash code
02309   int32_t doHashCode(void) const;
02310 
02311   // get pointer to start of array
02312   inline UChar* getArrayStart(void);
02313   inline const UChar* getArrayStart(void) const;
02314 
02315   // get the "real" capacity of the array, adjusted for ref count
02316   inline int32_t getCapacity(void) const;
02317 
02318   // allocate the array; result may be fStackBuffer
02319   // sets refCount to 1 if appropriate
02320   // sets fArray, fCapacity, and fFlags
02321   // returns boolean for success or failure
02322   UBool allocate(int32_t capacity);
02323 
02324   // release the array if owned
02325   inline void releaseArray();
02326 
02327   // utility method to get around lack of exception handling
02328   void setToBogus(void);
02329 
02330   // Pin start and limit to acceptable values.
02331   inline void pinIndices(UTextOffset& start,
02332                          int32_t& length) const;
02333 
02334   /*
02335    * Real constructor for converting from codepage data.
02336    * It assumes that it is called with !fRefCounted.
02337    *
02338    * If <code>codepage==0</code>, then the default converter
02339    * is used for the platform encoding.
02340    * If <code>codepage</code> is an empty string (<code>""</code>),
02341    * then a simple conversion is performed on the codepage-invariant
02342    * subset ("invariant characters") of the platform encoding. See utypes.h.
02343    */
02344   void doCodepageCreate(const char *codepageData,
02345                         int32_t dataLength,
02346                         const char *codepage);
02347 
02348   /*
02349    * This function is called when write access to the array
02350    * is necessary.
02351    *
02352    * We need to make a copy of the array if
02353    * the buffer is read-only, or
02354    * the buffer is refCounted (shared), and refCount>1, or
02355    * the buffer is too small.
02356    *
02357    * Return FALSE if memory could not be allocated.
02358    */
02359   UBool cloneArrayIfNeeded(int32_t newCapacity = -1,
02360                             int32_t growCapacity = -1,
02361                             UBool doCopyArray = TRUE,
02362                             int32_t **pBufferToDelete = 0,
02363                             UBool forceClone = FALSE);
02364 
02365   // GrowBuffer function for string case mapping
02366   static UBool U_CALLCONV
02367   growBuffer(void *context,
02368              UChar **buffer, int32_t *pCapacity, int32_t reqCapacity,
02369              int32_t length);
02370 
02371   // common function for case mappings
02372   UnicodeString &
02373   caseMap(const Locale& locale,
02374           uint32_t options,
02375           int32_t toWhichCase);
02376 
02377   // ref counting
02378   inline int32_t addRef(void);
02379   inline int32_t removeRef(void);
02380   inline int32_t refCount(void) const;
02381   inline int32_t setRefCount(int32_t count);
02382 
02383   // constants
02384   enum {
02385 #if UTF_SIZE==8
02386     US_STACKBUF_SIZE=14, // Size of stack buffer for small strings
02387 #elif UTF_SIZE==16
02388     US_STACKBUF_SIZE=7, // Size of stack buffer for small strings
02389 #else // UTF_SIZE==32
02390     US_STACKBUF_SIZE=3, // Size of stack buffer for small strings
02391 #endif
02392     kInvalidUChar=0xffff, // invalid UChar index
02393     kGrowSize=128, // grow size for this buffer
02394     kInvalidHashCode=0, // invalid hash code
02395     kEmptyHashCode=1, // hash code for empty string
02396 
02397     // bit flag values for fFlags
02398     kIsBogus=1, // this string is bogus, i.e., not valid
02399     kUsingStackBuffer=2, // fArray==fStackBuffer
02400     kRefCounted=4, // there is a refCount field before the characters in fArray
02401     kBufferIsReadonly=8, // do not write to this buffer
02402 
02403     // combined values for convenience
02404     kShortString=kUsingStackBuffer,
02405     kLongString=kRefCounted,
02406     kReadonlyAlias=kBufferIsReadonly,
02407     kWriteableAlias=0
02408   };
02409 
02410   // statics
02411 
02412   // default converter cache
02413   static UConverter* getDefaultConverter(UErrorCode& status);
02414   static void releaseDefaultConverter(UConverter *converter);
02415 
02416   static UConverter *fgDefaultConverter;
02417 
02418   friend class UnicodeStringStreamer;
02419   friend class UnicodeConverter;
02420 
02421 #if U_IOSTREAM_SOURCE >= 199711
02422   friend U_COMMON_API std::ostream &operator<<(std::ostream& stream, const UnicodeString& s);
02423 #elif U_IOSTREAM_SOURCE >= 198506
02424   friend U_COMMON_API ostream &operator<<(ostream& stream, const UnicodeString& s);
02425 #endif
02426 
02427   friend class StringCharacterIterator;
02428 
02429   /*
02430    * The following are all the class fields that are stored
02431    * in each UnicodeString object.
02432    * Note that UnicodeString has virtual functions,
02433    * therefore there is an implicit vtable pointer
02434    * as the first real field.
02435    * The fields should be aligned such that no padding is
02436    * necessary, mostly by having larger types first.
02437    * On 32-bit machines, the size should be 32 bytes,
02438    * on 64-bit machines (8-byte pointers), it should be 40 bytes.
02439    */
02440   // (implicit) *vtable;
02441   // fLength is moved into the superclass Replaceable (jitterbug 709)
02442   // int32_t   fLength;        // number characters in fArray
02443   int32_t   fCapacity;      // sizeof fArray
02444   UChar     *fArray;        // the Unicode data
02445   uint16_t  fFlags;         // bit flags: see constants above
02446 #if UTF_SIZE==32
02447   uint16_t  fPadding;       // padding to align the fStackBuffer for UTF-32
02448 #endif
02449   UChar     fStackBuffer [ US_STACKBUF_SIZE ]; // buffer for small strings
02450 
02451 public:
02452 
02453 #ifdef ICU_UNICODESTRING_USE_DEPRECATES
02454   //========================================
02455   // Deprecated API
02456   //========================================
02457 
02458   /* size() -> length()
02459    * @deprecated Remove after 2000-dec-31. Use length() instead. */
02460   inline int32_t size(void) const;
02461 
02462   // parameters reordered for consistency
02463    /* @deprecated To be removed in first release in 2001. Use the other versions of this function */
02464   inline UnicodeString& findAndReplace(const UnicodeString& oldText,
02465                 const UnicodeString& newText,
02466                 UTextOffset start,
02467                 int32_t length);
02468 
02469    /* @deprecated Remove after 2000-dec-31. There is no replacement. */
02470   inline void* operator new(size_t size);
02471    /* @deprecated Remove after 2000-dec-31. There is no replacement. */
02472   inline void* operator new(size_t size, void *location);
02473    /* @deprecated Remove after 2000-dec-31. There is no replacement. */
02474   inline void operator delete(void *location);
02475 #endif
02476 
02477   //========================================
02478   // Non-public API - will be removed!
02479   //========================================
02480   /* @deprecated Remove after 2000-dec-31. There is no public replacement. */
02481   const UChar* getUChars() const;
02482 };
02483 
02484 //========================================
02485 // Array copying
02486 //========================================
02487 // Copy an array of UnicodeString OBJECTS (not pointers).
02488 inline void 
02489 uprv_arrayCopy(const UnicodeString *src, UnicodeString *dst, int32_t count)
02490 { while(count-- > 0) *dst++ = *src++; }
02491 
02492 inline void 
02493 uprv_arrayCopy(const UnicodeString *src, int32_t srcStart, 
02494         UnicodeString *dst, int32_t dstStart, int32_t count)
02495 { uprv_arrayCopy(src+srcStart, dst+dstStart, count); }
02496 
02497 
02498 //========================================
02499 // Inline members
02500 //========================================
02501 
02502 //========================================
02503 // Read-only alias methods
02504 //========================================
02505 inline UBool
02506 UnicodeString::operator== (const UnicodeString& text) const
02507 {
02508   if(isBogus()) {
02509     return text.isBogus();
02510   } else {
02511     return
02512       !text.isBogus() &&
02513       fLength == text.fLength &&
02514       doCompare(0, fLength, text, 0, text.fLength) == 0;
02515   }
02516 }
02517 
02518 inline UBool
02519 UnicodeString::operator!= (const UnicodeString& text) const
02520 { return (! operator==(text)); }
02521 
02522 inline UBool
02523 UnicodeString::operator> (const UnicodeString& text) const
02524 { return doCompare(0, fLength, text, 0, text.fLength) == 1; }
02525 
02526 inline UBool
02527 UnicodeString::operator< (const UnicodeString& text) const
02528 { return doCompare(0, fLength, text, 0, text.fLength) == -1; }
02529 
02530 inline UBool
02531 UnicodeString::operator>= (const UnicodeString& text) const
02532 { return doCompare(0, fLength, text, 0, text.fLength) != -1; }
02533 
02534 inline UBool
02535 UnicodeString::operator<= (const UnicodeString& text) const
02536 { return doCompare(0, fLength, text, 0, text.fLength) != 1; }
02537 
02538 inline int8_t 
02539 UnicodeString::compare(const UnicodeString& text) const
02540 { return doCompare(0, fLength, text, 0, text.fLength); }
02541 
02542 inline int8_t 
02543 UnicodeString::compare(UTextOffset start,
02544                int32_t length,
02545                const UnicodeString& srcText) const
02546 { return doCompare(start, length, srcText, 0, srcText.fLength); }
02547 
02548 inline int8_t 
02549 UnicodeString::compare(const UChar *srcChars,
02550                int32_t srcLength) const
02551 { return doCompare(0, fLength, srcChars, 0, srcLength); }
02552 
02553 inline int8_t 
02554 UnicodeString::compare(UTextOffset start,
02555                int32_t length,
02556                const UnicodeString& srcText,
02557                UTextOffset srcStart,
02558                int32_t srcLength) const
02559 { return doCompare(start, length, srcText, srcStart, srcLength); }
02560 
02561 inline int8_t
02562 UnicodeString::compare(UTextOffset start,
02563                int32_t length,
02564                const UChar *srcChars) const
02565 { return doCompare(start, length, srcChars, 0, length); }
02566 
02567 inline int8_t 
02568 UnicodeString::compare(UTextOffset start,
02569                int32_t length,
02570                const UChar *srcChars,
02571                UTextOffset srcStart,
02572                int32_t srcLength) const
02573 { return doCompare(start, length, srcChars, srcStart, srcLength); }
02574 
02575 inline int8_t
02576 UnicodeString::compareBetween(UTextOffset start,
02577                   UTextOffset limit,
02578                   const UnicodeString& srcText,
02579                   UTextOffset srcStart,
02580                   UTextOffset srcLimit) const
02581 { return doCompare(start, limit - start, 
02582            srcText, srcStart, srcLimit - srcStart); }
02583 
02584 inline int8_t
02585 UnicodeString::doCompare(UTextOffset start,
02586               int32_t length,
02587               const UnicodeString& srcText,
02588               UTextOffset srcStart,
02589               int32_t srcLength) const
02590 {
02591   const UChar *srcChars;
02592   if(!srcText.isBogus()) {
02593     srcText.pinIndices(srcStart, srcLength);
02594     srcChars=srcText.getArrayStart();
02595   } else {
02596     srcChars=0;
02597   }
02598   return doCompare(start, length, srcChars, srcStart, srcLength);
02599 }
02600 
02601 inline int8_t 
02602 UnicodeString::compareCodePointOrder(const UnicodeString& text) const
02603 { return doCompareCodePointOrder(0, fLength, text, 0, text.fLength); }
02604 
02605 inline int8_t 
02606 UnicodeString::compareCodePointOrder(UTextOffset start,
02607                                      int32_t length,
02608                                      const UnicodeString& srcText) const
02609 { return doCompareCodePointOrder(start, length, srcText, 0, srcText.fLength); }
02610 
02611 inline int8_t 
02612 UnicodeString::compareCodePointOrder(const UChar *srcChars,
02613                                      int32_t srcLength) const
02614 { return doCompareCodePointOrder(0, fLength, srcChars, 0, srcLength); }
02615 
02616 inline int8_t 
02617 UnicodeString::compareCodePointOrder(UTextOffset start,
02618                                      int32_t length,
02619                                      const UnicodeString& srcText,
02620                                      UTextOffset srcStart,
02621                                      int32_t srcLength) const
02622 { return doCompareCodePointOrder(start, length, srcText, srcStart, srcLength); }
02623 
02624 inline int8_t
02625 UnicodeString::compareCodePointOrder(UTextOffset start,
02626                                      int32_t length,
02627                                      const UChar *srcChars) const
02628 { return doCompareCodePointOrder(start, length, srcChars, 0, length); }
02629 
02630 inline int8_t 
02631 UnicodeString::compareCodePointOrder(UTextOffset start,
02632                                      int32_t length,
02633                                      const UChar *srcChars,
02634                                      UTextOffset srcStart,
02635                                      int32_t srcLength) const
02636 { return doCompareCodePointOrder(start, length, srcChars, srcStart, srcLength); }
02637 
02638 inline int8_t
02639 UnicodeString::compareCodePointOrderBetween(UTextOffset start,
02640                                             UTextOffset limit,
02641                                             const UnicodeString& srcText,
02642                                             UTextOffset srcStart,
02643                                             UTextOffset srcLimit) const
02644 { return doCompareCodePointOrder(start, limit - start, 
02645            srcText, srcStart, srcLimit - srcStart); }
02646 
02647 inline int8_t
02648 UnicodeString::doCompareCodePointOrder(UTextOffset start,
02649                                        int32_t length,
02650                                        const UnicodeString& srcText,
02651                                        UTextOffset srcStart,
02652                                        int32_t srcLength) const
02653 {
02654   const UChar *srcChars;
02655   if(!srcText.isBogus()) {
02656     srcText.pinIndices(srcStart, srcLength);
02657     srcChars=srcText.getArrayStart();
02658   } else {
02659     srcChars=0;
02660   }
02661   return doCompareCodePointOrder(start, length, srcChars, srcStart, srcLength);
02662 }
02663 
02664 inline int8_t 
02665 UnicodeString::caseCompare(const UnicodeString &text, uint32_t options) const {
02666   return doCaseCompare(0, fLength, text, 0, text.fLength, options);
02667 }
02668 
02669 inline int8_t 
02670 UnicodeString::caseCompare(UTextOffset start,
02671                            int32_t length,
02672                            const UnicodeString &srcText,
02673                            uint32_t options) const {
02674   return doCaseCompare(start, length, srcText, 0, srcText.fLength, options);
02675 }
02676 
02677 inline int8_t 
02678 UnicodeString::caseCompare(const UChar *srcChars,
02679                            int32_t srcLength,
02680                            uint32_t options) const {
02681   return doCaseCompare(0, fLength, srcChars, 0, srcLength, options);
02682 }
02683 
02684 inline int8_t 
02685 UnicodeString::caseCompare(UTextOffset start,
02686                            int32_t length,
02687                            const UnicodeString &srcText,
02688                            UTextOffset srcStart,
02689                            int32_t srcLength,
02690                            uint32_t options) const {
02691   return doCaseCompare(start, length, srcText, srcStart, srcLength, options);
02692 }
02693 
02694 inline int8_t
02695 UnicodeString::caseCompare(UTextOffset start,
02696                            int32_t length,
02697                            const UChar *srcChars,
02698                            uint32_t options) const {
02699   return doCaseCompare(start, length, srcChars, 0, length, options);
02700 }
02701 
02702 inline int8_t 
02703 UnicodeString::caseCompare(UTextOffset start,
02704                            int32_t length,
02705                            const UChar *srcChars,
02706                            UTextOffset srcStart,
02707                            int32_t srcLength,
02708                            uint32_t options) const {
02709   return doCaseCompare(start, length, srcChars, srcStart, srcLength, options);
02710 }
02711 
02712 inline int8_t
02713 UnicodeString::caseCompareBetween(UTextOffset start,
02714                                   UTextOffset limit,
02715                                   const UnicodeString &srcText,
02716                                   UTextOffset srcStart,
02717                                   UTextOffset srcLimit,
02718                                   uint32_t options) const {
02719   return doCaseCompare(start, limit - start, srcText, srcStart, srcLimit - srcStart, options);
02720 }
02721 
02722 inline int8_t
02723 UnicodeString::doCaseCompare(UTextOffset start,
02724                              int32_t length,
02725                              const UnicodeString &srcText,
02726                              UTextOffset srcStart,
02727                              int32_t srcLength,
02728                              uint32_t options) const
02729 {
02730   const UChar *srcChars;
02731   if(!srcText.isBogus()) {
02732     srcText.pinIndices(srcStart, srcLength);
02733     srcChars=srcText.getArrayStart();
02734   } else {
02735     srcChars=0;
02736   }
02737   return doCaseCompare(start, length, srcChars, srcStart, srcLength, options);
02738 }
02739 
02740 inline UTextOffset 
02741 UnicodeString::indexOf(const UnicodeString& text) const
02742 { return indexOf(text, 0, text.fLength, 0, fLength); }
02743 
02744 inline UTextOffset 
02745 UnicodeString::indexOf(const UnicodeString& text,
02746                UTextOffset start) const
02747 { return indexOf(text, 0, text.fLength, start, fLength - start); }
02748 
02749 inline UTextOffset 
02750 UnicodeString::indexOf(const UnicodeString& text,
02751                UTextOffset start,
02752                int32_t length) const
02753 { return indexOf(text, 0, text.fLength, start, length); }
02754 
02755 inline UTextOffset 
02756 UnicodeString::indexOf(const UnicodeString& srcText,
02757                UTextOffset srcStart,
02758                int32_t srcLength,
02759                UTextOffset start,
02760                int32_t length) const
02761 {
02762   if(!srcText.isBogus()) {
02763     srcText.pinIndices(srcStart, srcLength);
02764     if(srcLength > 0) {
02765       return indexOf(srcText.getArrayStart(), srcStart, srcLength, start, length);
02766     }
02767   }
02768   return -1;
02769 }
02770 
02771 inline UTextOffset 
02772 UnicodeString::indexOf(const UChar *srcChars,
02773                int32_t srcLength,
02774                UTextOffset start) const
02775 { return indexOf(srcChars, 0, srcLength, start, fLength - start); }
02776 
02777 inline UTextOffset 
02778 UnicodeString::indexOf(const UChar *srcChars,
02779                int32_t srcLength,
02780                UTextOffset start,
02781                int32_t length) const
02782 { return indexOf(srcChars, 0, srcLength, start, length); }
02783 
02784 inline UTextOffset 
02785 UnicodeString::indexOf(UChar c) const
02786 { return doIndexOf(c, 0, fLength); }
02787 
02788 inline UTextOffset 
02789 UnicodeString::indexOf(UChar32 c) const {
02790   if(!UTF_NEED_MULTIPLE_UCHAR(c)) {
02791     return doIndexOf((UChar)c, 0, fLength);
02792   } else {
02793     UChar buffer[UTF_MAX_CHAR_LENGTH];
02794     int32_t length = 0;
02795     UTF_APPEND_CHAR_UNSAFE(buffer, length, c);
02796     return indexOf(buffer, length, 0);
02797   }
02798 }
02799 
02800 inline UTextOffset 
02801 UnicodeString::indexOf(UChar c,
02802                UTextOffset start) const
02803 { return doIndexOf(c, start, fLength - start); }
02804 
02805 inline UTextOffset 
02806 UnicodeString::indexOf(UChar32 c,
02807                UTextOffset start) const {
02808   if(!UTF_NEED_MULTIPLE_UCHAR(c)) {
02809     return doIndexOf((UChar)c, start, fLength - start);
02810   } else {
02811     UChar buffer[UTF_MAX_CHAR_LENGTH];
02812     int32_t length = 0;
02813     UTF_APPEND_CHAR_UNSAFE(buffer, length, c);
02814     return indexOf(buffer, length, start);
02815   }
02816 }
02817 
02818 inline UTextOffset 
02819 UnicodeString::indexOf(UChar c,
02820                UTextOffset start,
02821                int32_t length) const
02822 { return doIndexOf(c, start, length); }
02823 
02824 inline UTextOffset 
02825 UnicodeString::indexOf(UChar32 c,
02826                UTextOffset start,
02827                int32_t length) const {
02828   if(!UTF_NEED_MULTIPLE_UCHAR(c)) {
02829     return doIndexOf((UChar)c, start, length);
02830   } else {
02831     UChar buffer[UTF_MAX_CHAR_LENGTH];
02832     int32_t cLength = 0;
02833     UTF_APPEND_CHAR_UNSAFE(buffer, cLength, c);
02834     return indexOf(buffer, cLength, start, length);
02835   }
02836 }
02837 
02838 inline UTextOffset 
02839 UnicodeString::lastIndexOf(const UnicodeString& text) const
02840 { return lastIndexOf(text, 0, text.fLength, 0, fLength); }
02841 
02842 inline UTextOffset 
02843 UnicodeString::lastIndexOf(const UnicodeString& text,
02844                UTextOffset start) const
02845 { return lastIndexOf(text, 0, text.fLength, start, fLength - start); }
02846 
02847 inline UTextOffset 
02848 UnicodeString::lastIndexOf(const UnicodeString& text,
02849                UTextOffset start,
02850                int32_t length) const
02851 { return lastIndexOf(text, 0, text.fLength, start, length); }
02852 
02853 inline UTextOffset 
02854 UnicodeString::lastIndexOf(const UnicodeString& srcText,
02855                UTextOffset srcStart,
02856                int32_t srcLength,
02857                UTextOffset start,
02858                int32_t length) const
02859 {
02860   if(!srcText.isBogus()) {
02861     srcText.pinIndices(srcStart, srcLength);
02862     if(srcLength > 0) {
02863       return lastIndexOf(srcText.getArrayStart(), srcStart, srcLength, start, length);
02864     }
02865   }
02866   return -1;
02867 }
02868 
02869 inline UTextOffset 
02870 UnicodeString::lastIndexOf(const UChar *srcChars,
02871                int32_t srcLength,
02872                UTextOffset start) const
02873 { return lastIndexOf(srcChars, 0, srcLength, start, fLength - start); }
02874 
02875 inline UTextOffset 
02876 UnicodeString::lastIndexOf(const UChar *srcChars,
02877                int32_t srcLength,
02878                UTextOffset start,
02879                int32_t length) const
02880 { return lastIndexOf(srcChars, 0, srcLength, start, length); }
02881 
02882 inline UTextOffset 
02883 UnicodeString::lastIndexOf(UChar c) const
02884 { return doLastIndexOf(c, 0, fLength); }
02885 
02886 inline UTextOffset 
02887 UnicodeString::lastIndexOf(UChar32 c) const {
02888   if(!UTF_NEED_MULTIPLE_UCHAR(c)) {
02889     return doLastIndexOf((UChar)c, 0, fLength);
02890   } else {
02891     UChar buffer[UTF_MAX_CHAR_LENGTH];
02892     int32_t count = 0;
02893     UTF_APPEND_CHAR_UNSAFE(buffer, count, c);
02894     return lastIndexOf(buffer, count, 0);
02895   }
02896 }
02897 
02898 inline UTextOffset 
02899 UnicodeString::lastIndexOf(UChar c,
02900                UTextOffset start) const
02901 { return doLastIndexOf(c, start, fLength - start); }
02902 
02903 inline UTextOffset 
02904 UnicodeString::lastIndexOf(UChar32 c,
02905                UTextOffset start) const {
02906   if(!UTF_NEED_MULTIPLE_UCHAR(c)) {
02907     return doLastIndexOf((UChar)c, start, fLength - start);
02908   } else {
02909     UChar buffer[UTF_MAX_CHAR_LENGTH];
02910     int32_t count = 0;
02911     UTF_APPEND_CHAR_UNSAFE(buffer, count, c);
02912     return lastIndexOf(buffer, count, start);
02913   }
02914 }
02915 
02916 inline UTextOffset 
02917 UnicodeString::lastIndexOf(UChar c,
02918                UTextOffset start,
02919                int32_t length) const
02920 { return doLastIndexOf(c, start, length); }
02921 
02922 inline UTextOffset 
02923 UnicodeString::lastIndexOf(UChar32 c,
02924                UTextOffset start,
02925                int32_t length) const {
02926   if(!UTF_NEED_MULTIPLE_UCHAR(c)) {
02927     return doLastIndexOf((UChar)c, start, length);
02928   } else {
02929     UChar buffer[UTF_MAX_CHAR_LENGTH];
02930     int32_t count = 0;
02931     UTF_APPEND_CHAR_UNSAFE(buffer, count, c);
02932     return lastIndexOf(buffer, count, start, length);
02933   }
02934 }
02935 
02936 inline UBool 
02937 UnicodeString::startsWith(const UnicodeString& text) const
02938 { return compare(0, text.fLength, text, 0, text.fLength) == 0; }
02939 
02940 inline UBool 
02941 UnicodeString::startsWith(const UnicodeString& srcText,
02942               UTextOffset srcStart,
02943               int32_t srcLength) const
02944 { return doCompare(0, srcLength, srcText, srcStart, srcLength) == 0; }
02945 
02946 inline UBool 
02947 UnicodeString::startsWith(const UChar *srcChars,
02948               int32_t srcLength) const
02949 { return doCompare(0, srcLength, srcChars, 0, srcLength) == 0; }
02950 
02951 inline UBool 
02952 UnicodeString::startsWith(const UChar *srcChars,
02953               UTextOffset srcStart,
02954               int32_t srcLength) const
02955 { return doCompare(0, srcLength, srcChars, srcStart, srcLength) == 0;}
02956 
02957 inline UBool 
02958 UnicodeString::endsWith(const UnicodeString& text) const
02959 { return doCompare(fLength - text.fLength, text.fLength, 
02960            text, 0, text.fLength) == 0; }
02961 
02962 inline UBool 
02963 UnicodeString::endsWith(const UnicodeString& srcText,
02964             UTextOffset srcStart,
02965             int32_t srcLength) const
02966 { return doCompare(fLength - srcLength, srcLength, 
02967            srcText, srcStart, srcLength) == 0; }
02968 
02969 inline UBool 
02970 UnicodeString::endsWith(const UChar *srcChars,
02971             int32_t srcLength) const
02972 { return doCompare(fLength - srcLength, srcLength, 
02973            srcChars, 0, srcLength) == 0; }
02974 
02975 inline UBool 
02976 UnicodeString::endsWith(const UChar *srcChars,
02977             UTextOffset srcStart,
02978             int32_t srcLength) const
02979 { return doCompare(fLength - srcLength, srcLength, 
02980            srcChars, srcStart, srcLength) == 0;}
02981 //========================================
02982 // replace
02983 //========================================
02984 inline UnicodeString& 
02985 UnicodeString::replace(UTextOffset start, 
02986                int32_t length, 
02987                const UnicodeString& srcText) 
02988 { return doReplace(start, length, srcText, 0, srcText.fLength); }
02989 
02990 inline UnicodeString& 
02991 UnicodeString::replace(UTextOffset start, 
02992                int32_t length, 
02993                const UnicodeString& srcText, 
02994                UTextOffset srcStart, 
02995                int32_t srcLength)
02996 { return doReplace(start, length, srcText, srcStart, srcLength); }
02997 
02998 inline UnicodeString& 
02999 UnicodeString::replace(UTextOffset start, 
03000                int32_t length, 
03001                const UChar *srcChars,
03002                int32_t srcLength)
03003 { return doReplace(start, length, srcChars, 0, srcLength); }
03004 
03005 inline UnicodeString& 
03006 UnicodeString::replace(UTextOffset start, 
03007                int32_t length, 
03008                const UChar *srcChars, 
03009                UTextOffset srcStart, 
03010                int32_t srcLength)
03011 { return doReplace(start, length, srcChars, srcStart, srcLength); }
03012 
03013 inline UnicodeString& 
03014 UnicodeString::replace(UTextOffset start, 
03015                int32_t length, 
03016                UChar srcChar)
03017 { return doReplace(start, length, &srcChar, 0, 1); }
03018 
03019 inline UnicodeString&
03020 UnicodeString::replace(UTextOffset start, 
03021                int32_t length, 
03022                UChar32 srcChar) {
03023   UChar buffer[UTF_MAX_CHAR_LENGTH];
03024   int32_t count = 0;
03025   UTF_APPEND_CHAR_UNSAFE(buffer, count, srcChar);
03026   return doReplace(start, length, buffer, 0, count);
03027 }
03028 
03029 inline UnicodeString& 
03030 UnicodeString::replaceBetween(UTextOffset start, 
03031                   UTextOffset limit, 
03032                   const UnicodeString& srcText)
03033 { return doReplace(start, limit - start, srcText, 0, srcText.fLength); }
03034 
03035 inline UnicodeString&
03036 UnicodeString::replaceBetween(UTextOffset start, 
03037                   UTextOffset limit, 
03038                   const UnicodeString& srcText, 
03039                   UTextOffset srcStart, 
03040                   UTextOffset srcLimit)
03041 { return doReplace(start, limit - start, srcText, srcStart, srcLimit - srcStart); }
03042 
03043 inline UnicodeString& 
03044 UnicodeString::findAndReplace(const UnicodeString& oldText,
03045                   const UnicodeString& newText)
03046 { return findAndReplace(0, fLength, oldText, 0, oldText.fLength, 
03047             newText, 0, newText.fLength); }
03048 
03049 inline UnicodeString& 
03050 UnicodeString::findAndReplace(UTextOffset start,
03051                   int32_t length,
03052                   const UnicodeString& oldText,
03053                   const UnicodeString& newText)
03054 { return findAndReplace(start, length, oldText, 0, oldText.fLength, 
03055             newText, 0, newText.fLength); }
03056 
03057 // ============================
03058 // extract
03059 // ============================
03060 inline void
03061 UnicodeString::doExtract(UTextOffset start,
03062              int32_t length,
03063              UnicodeString& target) const
03064 { target.replace(0, target.fLength, *this, start, length); }
03065 
03066 inline void  
03067 UnicodeString::extract(UTextOffset start, 
03068                int32_t length, 
03069                UChar *target, 
03070                UTextOffset targetStart) const
03071 { doExtract(start, length, target, targetStart); }
03072 
03073 inline void 
03074 UnicodeString::extract(UTextOffset start,
03075                int32_t length,
03076                UnicodeString& target) const
03077 { doExtract(start, length, target); }
03078 
03079 inline int32_t
03080 UnicodeString::extract(UTextOffset start,
03081                int32_t length,
03082                char *dst,
03083                const char *codepage) const
03084 // This dstSize value will be checked explicitly
03085 {return extract(start, length, dst, 0xffffffff, codepage);}
03086 
03087 inline void  
03088 UnicodeString::extractBetween(UTextOffset start, 
03089                   UTextOffset limit, 
03090                   UChar *dst, 
03091                   UTextOffset dstStart) const
03092 { doExtract(start, limit - start, dst, dstStart); }
03093 
03094 inline void 
03095 UnicodeString::extractBetween(UTextOffset start,
03096                   UTextOffset limit,
03097                   UnicodeString& target) const
03098 { doExtract(start, limit - start, target); }
03099 
03100 inline UChar
03101 UnicodeString::doCharAt(UTextOffset offset) const
03102 {
03103   if((uint32_t)offset < (uint32_t)fLength) {
03104     return fArray[offset];
03105   } else {
03106     return kInvalidUChar;
03107   }
03108 }
03109 
03110 inline UChar
03111 UnicodeString::charAt(UTextOffset offset) const
03112 { return doCharAt(offset); }
03113 
03114 inline UChar
03115 UnicodeString::operator[] (UTextOffset offset) const
03116 { return doCharAt(offset); }
03117 
03118 inline UChar32
03119 UnicodeString::char32At(UTextOffset offset) const
03120 {
03121   if((uint32_t)offset < (uint32_t)fLength) {
03122     UChar32 c;
03123     UTF_GET_CHAR(fArray, 0, offset, fLength, c);
03124     return c;
03125   } else {
03126     return kInvalidUChar;
03127   }
03128 }
03129 
03130 inline UTextOffset
03131 UnicodeString::getCharStart(UTextOffset offset) {
03132   if((uint32_t)offset < (uint32_t)fLength) {
03133     UTF_SET_CHAR_START(fArray, 0, offset);
03134     return offset;
03135   } else {
03136     return 0;
03137   }
03138 }
03139 
03140 inline UTextOffset
03141 UnicodeString::getCharLimit(UTextOffset offset) {
03142   if((uint32_t)offset < (uint32_t)fLength) {
03143     UTF_SET_CHAR_LIMIT(fArray, 0, offset, fLength);
03144     return offset;
03145   } else {
03146     return fLength;
03147   }
03148 }
03149 
03150 inline UBool
03151 UnicodeString::empty() const
03152 { return fLength == 0; }
03153 
03154 //========================================
03155 // Read-only implementation methods
03156 //========================================
03157 inline int32_t  
03158 UnicodeString::length() const
03159 { return fLength; }
03160 
03161 inline int32_t 
03162 UnicodeString::hashCode() const
03163 { return doHashCode(); }
03164 
03165 //========================================
03166 // Write alias methods
03167 //========================================
03168 inline UnicodeString& 
03169 UnicodeString::operator= (UChar ch) 
03170 { return doReplace(0, fLength, &ch, 0, 1); }
03171 
03172 inline UnicodeString& 
03173 UnicodeString::operator= (UChar32 ch) 
03174 { return replace(0, fLength, ch); }
03175 
03176 inline UnicodeString& 
03177 UnicodeString::setTo(const UnicodeString& srcText, 
03178              UTextOffset srcStart, 
03179              int32_t srcLength)
03180 { return doReplace(0, fLength, srcText, srcStart, srcLength); }
03181 
03182 inline UnicodeString& 
03183 UnicodeString::setTo(const UnicodeString& srcText)
03184 { return doReplace(0, fLength, srcText, 0, srcText.fLength); }
03185 
03186 inline UnicodeString& 
03187 UnicodeString::setTo(const UChar *srcChars,
03188              int32_t srcLength)
03189 { return doReplace(0, fLength, srcChars, 0, srcLength); }
03190 
03191 inline UnicodeString& 
03192 UnicodeString::setTo(UChar srcChar)
03193 { return doReplace(0, fLength, &srcChar, 0, 1); }
03194 
03195 inline UnicodeString& 
03196 UnicodeString::setTo(UChar32 srcChar)
03197 { return replace(0, fLength, srcChar); }
03198 
03199 inline UnicodeString& 
03200 UnicodeString::operator+= (UChar ch)
03201 { return doReplace(fLength, 0, &ch, 0, 1); }
03202 
03203 inline UnicodeString& 
03204 UnicodeString::operator+= (UChar32 ch) {
03205   UChar buffer[UTF_MAX_CHAR_LENGTH];
03206   int32_t length = 0;
03207   UTF_APPEND_CHAR_UNSAFE(buffer, length, ch);
03208   return doReplace(fLength, 0, buffer, 0, length);
03209 }
03210 
03211 inline UnicodeString& 
03212 UnicodeString::operator+= (const UnicodeString& srcText)
03213 { return doReplace(fLength, 0, srcText, 0, srcText.fLength); }
03214 
03215 inline UnicodeString& 
03216 UnicodeString::append(const UnicodeString& srcText, 
03217               UTextOffset srcStart, 
03218               int32_t srcLength)
03219 { return doReplace(fLength, 0, srcText, srcStart, srcLength); }
03220 
03221 inline UnicodeString& 
03222 UnicodeString::append(const UnicodeString& srcText)
03223 { return doReplace(fLength, 0, srcText, 0, srcText.fLength); }
03224 
03225 inline UnicodeString& 
03226 UnicodeString::append(const UChar *srcChars, 
03227               UTextOffset srcStart, 
03228               int32_t srcLength)
03229 { return doReplace(fLength, 0, srcChars, srcStart, srcLength); }
03230 
03231 inline UnicodeString& 
03232 UnicodeString::append(const UChar *srcChars,
03233               int32_t srcLength)
03234 { return doReplace(fLength, 0, srcChars, 0, srcLength); }
03235 
03236 inline UnicodeString& 
03237 UnicodeString::append(UChar srcChar)
03238 { return doReplace(fLength, 0, &srcChar, 0, 1); }
03239 
03240 inline UnicodeString& 
03241 UnicodeString::append(UChar32 srcChar) {
03242   UChar buffer[UTF_MAX_CHAR_LENGTH];
03243   int32_t length = 0;
03244   UTF_APPEND_CHAR_UNSAFE(buffer, length, srcChar);
03245   return doReplace(fLength, 0, buffer, 0, length);
03246 }
03247 
03248 inline UnicodeString& 
03249 UnicodeString::insert(UTextOffset start, 
03250               const UnicodeString& srcText, 
03251               UTextOffset srcStart, 
03252               int32_t srcLength)
03253 { return doReplace(start, 0, srcText, srcStart, srcLength); }
03254 
03255 inline UnicodeString& 
03256 UnicodeString::insert(UTextOffset start, 
03257               const UnicodeString& srcText)
03258 { return doReplace(start, 0, srcText, 0, srcText.fLength); }
03259 
03260 inline UnicodeString& 
03261 UnicodeString::insert(UTextOffset start, 
03262               const UChar *srcChars, 
03263               UTextOffset srcStart, 
03264               int32_t srcLength)
03265 { return doReplace(start, 0, srcChars, srcStart, srcLength); }
03266 
03267 inline UnicodeString& 
03268 UnicodeString::insert(UTextOffset start, 
03269               const UChar *srcChars,
03270               int32_t srcLength)
03271 { return doReplace(start, 0, srcChars, 0, srcLength); }
03272 
03273 inline UnicodeString& 
03274 UnicodeString::insert(UTextOffset start, 
03275               UChar srcChar)
03276 { return doReplace(start, 0, &srcChar, 0, 1); }
03277 
03278 inline UnicodeString& 
03279 UnicodeString::insert(UTextOffset start, 
03280               UChar32 srcChar)
03281 { return replace(start, 0, srcChar); }
03282 
03283 
03284 inline UnicodeString& 
03285 UnicodeString::remove(UTextOffset start, 
03286              int32_t length)
03287 { return doReplace(start, length, NULL, 0, 0); }
03288 
03289 inline UnicodeString& 
03290 UnicodeString::remove()
03291 { return doReplace(0, fLength, 0, 0, 0); }
03292 
03293 inline UnicodeString& 
03294 UnicodeString::removeBetween(UTextOffset start,
03295                 UTextOffset limit)
03296 { return doReplace(start, limit - start, NULL, 0, 0); }
03297 
03298 inline UBool 
03299 UnicodeString::truncate(int32_t targetLength)
03300 {
03301   if((uint32_t)targetLength < (uint32_t)fLength) {
03302     fLength = targetLength;
03303     return TRUE;
03304   } else {
03305     return FALSE;
03306   }
03307 }
03308 
03309 inline UnicodeString& 
03310 UnicodeString::reverse()
03311 { return doReverse(0, fLength); }
03312 
03313 inline UnicodeString& 
03314 UnicodeString::reverse(UTextOffset start,
03315                int32_t length)
03316 { return doReverse(start, length); }
03317 
03318 
03319 //========================================
03320 // Write implementation methods
03321 //========================================
03322 inline UBool 
03323 UnicodeString::isBogus() const
03324 { return (UBool)(fFlags & kIsBogus); }
03325 
03326 
03327 //========================================
03328 // Privates
03329 //========================================
03330 
03331 inline void
03332 UnicodeString::pinIndices(UTextOffset& start,
03333                           int32_t& length) const
03334 {
03335   // pin indices
03336   if(start < 0) {
03337     start = 0;
03338   } else if(start > fLength) {
03339     start = fLength;
03340   }
03341   if(length < 0) {
03342     length = 0;
03343   } else if(length > (fLength - start)) {
03344     length = (fLength - start);
03345   }
03346 }
03347 
03348 inline UChar* 
03349 UnicodeString::getArrayStart()
03350 { return fArray; }
03351 
03352 inline const UChar* 
03353 UnicodeString::getArrayStart() const
03354 { return fArray; }
03355 
03356 inline int32_t 
03357 UnicodeString::getCapacity() const
03358 { return fCapacity; }
03359 
03360 inline void
03361 UnicodeString::releaseArray() {
03362   if((fFlags & kRefCounted) && removeRef() == 0) {
03363     delete [] ((int32_t *)fArray - 1);
03364   }
03365 }
03366 
03367 inline int32_t
03368 UnicodeString::addRef()
03369 { return ++*((int32_t *)fArray - 1); }
03370 
03371 inline int32_t
03372 UnicodeString::removeRef()
03373 { return --*((int32_t *)fArray - 1); }
03374 
03375 inline int32_t
03376 UnicodeString::refCount() const
03377 { return *((int32_t *)fArray - 1); }
03378 
03379 inline int32_t
03380 UnicodeString::setRefCount(int32_t count)
03381 { return (*((int32_t *)fArray - 1) = count); }
03382 
03383 #ifdef ICU_UNICODESTRING_USE_DEPRECATES
03384 
03385 // deprecated API - remove later
03386 inline int32_t
03387 UnicodeString::size() const
03388 { return fLength; }
03389 
03390 inline UnicodeString& 
03391 UnicodeString::findAndReplace(const UnicodeString& oldText,
03392                   const UnicodeString& newText,
03393                   UTextOffset start,
03394                   int32_t length)
03395 { return findAndReplace(start, length, oldText, newText); }
03396 
03397 inline void*
03398 UnicodeString::operator new(size_t size)
03399 { return ::operator new(size); }
03400 
03401 inline void* 
03402 UnicodeString::operator new(size_t, 
03403               void *location)
03404 { return location; }
03405 
03406 inline void
03407 UnicodeString::operator delete(void *location)
03408 { ::operator delete(location); }
03409 
03410 #endif
03411 
03412 //========================================
03413 // Static members
03414 //========================================
03415 
03416 //========================================
03417 // class UCharReference
03418 //========================================
03419 class UCharReference
03420 {
03421 public:
03422   UCharReference();
03423   inline UCharReference(UnicodeString *string,
03424          UTextOffset pos);
03425   inline UCharReference(const UCharReference& that);
03426   ~UCharReference();
03427 
03428   inline UCharReference& operator= (const UCharReference& that);
03429   inline UCharReference& operator= (UChar c);
03430 
03431   inline operator UChar();
03432 
03433 private:
03434   UnicodeString *fString;
03435   UTextOffset fPos;
03436 };
03437 
03438 
03439 //========================================
03440 // Inline members
03441 //========================================
03442 inline
03443 UCharReference::UCharReference(UnicodeString *string, 
03444                    UTextOffset pos)
03445   : fString(string), fPos(pos)
03446 {}
03447 
03448 inline
03449 UCharReference::UCharReference(const UCharReference& that)
03450 { this->operator=(that); }
03451 
03452 inline
03453 UCharReference::~UCharReference()
03454 {}
03455 
03456 inline UCharReference&
03457 UCharReference::operator= (const UCharReference& that)
03458 { fString->setCharAt(fPos, that.fString->charAt(that.fPos)); return *this; }
03459 
03460 inline UCharReference& 
03461 UCharReference::operator= (UChar c)
03462 { fString->setCharAt(fPos, c); return *this; }
03463 
03464 inline
03465 UCharReference::operator UChar()
03466 { return fString->charAt(fPos); }
03467 
03468 #endif

Generated at Thu Mar 22 16:12:42 2001 for ICU 1.8 by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000