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-1999, 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 <limits.h>
00024 
00025 #include "unicode/utypes.h"
00026 #include "unicode/unicode.h"
00027 #include "unicode/ucnv.h"
00028 #include "unicode/rep.h"
00029 
00030 class Locale;
00031 class UCharReference;
00032 class UnicodeStringStreamer;
00033 class UnicodeConverter;
00034 
00035 // for unistrm.h
00042 #if U_IOSTREAM_SOURCE >= 199711
00043 #include <iostream>
00044 U_COMMON_API std::ostream &operator<<(std::ostream& stream, const UnicodeString& s);
00045 #elif U_IOSTREAM_SOURCE >= 198506
00046 #include <iostream.h>
00047 U_COMMON_API ostream &operator<<(ostream& stream, const UnicodeString& s);
00048 #endif
00049 
00066 #if U_SIZEOF_WCHAR_T==U_SIZEOF_UCHAR && U_CHARSET_FAMILY==U_ASCII_FAMILY
00067 #   define UNICODE_STRING(cs, length) UnicodeString(TRUE, (UChar *)L ## cs, length)
00068 #elif U_SIZEOF_UCHAR==1 && U_CHARSET_FAMILY==U_ASCII_FAMILY
00069 #   define UNICODE_STRING(cs, length) UnicodeString(TRUE, (UChar *)cs, length)
00070 #else
00071 #   define UNICODE_STRING(cs, length) UnicodeString(cs, length, "")
00072 #endif
00073 
00131 class U_COMMON_API UnicodeString : public Replaceable
00132 {
00133 public:
00134 
00135   //========================================
00136   // Read-only operations
00137   //========================================
00138   
00139   /* Comparison - bitwise only - for international comparison use collation */
00140   
00148   inline UBool operator== (const UnicodeString& text) const;
00149   
00157   inline UBool operator!= (const UnicodeString& text) const;
00158 
00166   inline UBool operator> (const UnicodeString& text) const;
00167 
00175   inline UBool operator< (const UnicodeString& text) const;
00176 
00184   inline UBool operator>= (const UnicodeString& text) const;
00185 
00193   inline UBool operator<= (const UnicodeString& text) const;
00194 
00206   inline int8_t compare(const UnicodeString& text) const;
00207 
00222   inline int8_t compare(UTextOffset start,
00223          int32_t length,
00224          const UnicodeString& srcText) const;
00225 
00243    inline int8_t compare(UTextOffset start,
00244          int32_t length,
00245          const UnicodeString& srcText,
00246          UTextOffset srcStart,
00247          int32_t srcLength) const;
00248 
00261   inline int8_t compare(const UChar *srcChars,
00262          int32_t srcLength) const;
00263 
00278   inline int8_t compare(UTextOffset start,
00279          int32_t length,
00280          const UChar *srcChars) const;
00281 
00299   inline int8_t compare(UTextOffset start,
00300          int32_t length,
00301          const UChar *srcChars,
00302          UTextOffset srcStart,
00303          int32_t srcLength) const;
00304 
00322   inline int8_t compareBetween(UTextOffset start,
00323             UTextOffset limit,
00324             const UnicodeString& srcText,
00325             UTextOffset srcStart,
00326             UTextOffset srcLimit) const;
00327 
00335   inline UBool startsWith(const UnicodeString& text) const;
00336 
00347   inline UBool startsWith(const UnicodeString& srcText,
00348             UTextOffset srcStart,
00349             int32_t srcLength) const;
00350   
00359   inline UBool startsWith(const UChar *srcChars,
00360             int32_t srcLength) const;
00361  
00372   inline UBool startsWith(const UChar *srcChars,
00373             UTextOffset srcStart,
00374             int32_t srcLength) const;
00375 
00383   inline UBool endsWith(const UnicodeString& text) const;
00384 
00395   inline UBool endsWith(const UnicodeString& srcText,
00396           UTextOffset srcStart,
00397           int32_t srcLength) const;
00398 
00407   inline UBool endsWith(const UChar *srcChars,
00408           int32_t srcLength) const;
00409  
00420   inline UBool endsWith(const UChar *srcChars,
00421           UTextOffset srcStart,
00422           int32_t srcLength) const;
00423 
00424  
00425   /* Searching - bitwise only */
00426 
00435   inline UTextOffset indexOf(const UnicodeString& text) const;
00436 
00446   inline UTextOffset indexOf(const UnicodeString& text,
00447               UTextOffset start) const;
00448 
00460   inline UTextOffset indexOf(const UnicodeString& text,
00461               UTextOffset start,
00462               int32_t length) const;
00463 
00480   inline UTextOffset indexOf(const UnicodeString& srcText,
00481               UTextOffset srcStart,
00482               int32_t srcLength,
00483               UTextOffset start,
00484               int32_t length) const;
00485 
00497   inline UTextOffset indexOf(const UChar *srcChars,
00498               int32_t srcLength,
00499               UTextOffset start) const;
00500 
00513   inline UTextOffset indexOf(const UChar *srcChars,
00514               int32_t srcLength,
00515               UTextOffset start,
00516               int32_t length) const;
00517  
00534   UTextOffset indexOf(const UChar *srcChars,
00535               UTextOffset srcStart,
00536               int32_t srcLength,
00537               UTextOffset start,
00538               int32_t length) const;
00539 
00547   inline UTextOffset indexOf(UChar c) const;
00548 
00556   inline UTextOffset indexOf(UChar32 c) const;
00557 
00566   inline UTextOffset indexOf(UChar c,
00567               UTextOffset start) const;
00568 
00577   inline UTextOffset indexOf(UChar32 c,
00578               UTextOffset start) const;
00579 
00590   inline UTextOffset indexOf(UChar c,
00591               UTextOffset start,
00592               int32_t length) const;
00593 
00604   inline UTextOffset indexOf(UChar32 c,
00605               UTextOffset start,
00606               int32_t length) const;
00607 
00616   inline UTextOffset lastIndexOf(const UnicodeString& text) const;
00617 
00627   inline UTextOffset lastIndexOf(const UnicodeString& text,
00628               UTextOffset start) const;
00629 
00641   inline UTextOffset lastIndexOf(const UnicodeString& text,
00642               UTextOffset start,
00643               int32_t length) const;
00644 
00661   inline UTextOffset lastIndexOf(const UnicodeString& srcText,
00662               UTextOffset srcStart,
00663               int32_t srcLength,
00664               UTextOffset start,
00665               int32_t length) const;
00666 
00677   inline UTextOffset lastIndexOf(const UChar *srcChars,
00678               int32_t srcLength,
00679               UTextOffset start) const;
00680 
00693   inline UTextOffset lastIndexOf(const UChar *srcChars,
00694               int32_t srcLength,
00695               UTextOffset start,
00696               int32_t length) const;
00697  
00714   UTextOffset lastIndexOf(const UChar *srcChars,
00715               UTextOffset srcStart,
00716               int32_t srcLength,
00717               UTextOffset start,
00718               int32_t length) const;
00719 
00727   inline UTextOffset lastIndexOf(UChar c) const;
00728 
00736   inline UTextOffset lastIndexOf(UChar32 c) const;
00737 
00746   inline UTextOffset lastIndexOf(UChar c,
00747               UTextOffset start) const;
00748 
00757   inline UTextOffset lastIndexOf(UChar32 c,
00758               UTextOffset start) const;
00759 
00770   inline UTextOffset lastIndexOf(UChar c,
00771               UTextOffset start,
00772               int32_t length) const;
00773 
00784   inline UTextOffset lastIndexOf(UChar32 c,
00785               UTextOffset start,
00786               int32_t length) const;
00787 
00788 
00789   /* Character access */
00790 
00797   inline UChar charAt(UTextOffset offset) const;
00798 
00805   inline UChar operator [] (UTextOffset offset) const;
00806 
00816   inline UChar32 char32At(UTextOffset offset) const;
00817 
00831   inline UTextOffset getCharStart(UTextOffset offset);
00832 
00847   inline UTextOffset getCharLimit(UTextOffset offset);
00848 
00849   /* Substring extraction */
00850 
00866   inline void extract(UTextOffset start, 
00867            int32_t length, 
00868            UChar *dst, 
00869            UTextOffset dstStart = 0) const;
00870   
00881   inline void extract(UTextOffset start,
00882            int32_t length,
00883            UnicodeString& target) const;
00884 
00896   inline void extractBetween(UTextOffset start, 
00897               UTextOffset limit, 
00898               UChar *dst, 
00899               UTextOffset dstStart = 0) const;
00900 
00910   inline void extractBetween(UTextOffset start,
00911               UTextOffset limit,
00912               UnicodeString& target) const;
00913 
00932   inline int32_t extract(UTextOffset start,
00933                  int32_t startLength,
00934                  char *target,
00935                  const char *codepage = 0) const;
00936 
00955   int32_t extract(UTextOffset start,
00956            int32_t startLength,
00957            char *target,
00958            uint32_t targetLength,
00959            const char *codepage = 0) const;
00960 
00961   /* Length operations */
00962 
00969   inline int32_t  length(void) const;
00970 
00976   inline UBool empty(void) const;
00977 
00978 
00979   /* Other operations */
00980 
00986   inline int32_t hashCode(void) const;
00987 
00993   inline UBool isBogus(void) const;
00994 
00995   
00996   //========================================
00997   // Write operations
00998   //========================================
00999 
01000   /* Assignment operations */
01001 
01009    UnicodeString& operator= (const UnicodeString& srcText);
01010 
01018   inline UnicodeString& operator= (UChar ch);
01019 
01027   inline UnicodeString& operator= (UChar32 ch);
01028 
01042   inline UnicodeString& setTo(const UnicodeString& srcText, 
01043                UTextOffset srcStart, 
01044                int32_t srcLength);
01045 
01054   inline UnicodeString& setTo(const UnicodeString& srcText);
01055 
01064   inline UnicodeString& setTo(const UChar *srcChars,
01065                int32_t srcLength);
01066 
01075   UnicodeString& setTo(UChar srcChar);
01076 
01085   UnicodeString& setTo(UChar32 srcChar);
01086 
01106   UnicodeString &setTo(UBool isTerminated,
01107                        const UChar *text,
01108                        int32_t textLength);
01109 
01128   UnicodeString &setTo(UChar *buffer,
01129                        int32_t buffLength,
01130                        int32_t buffCapacity);
01131 
01139   UnicodeString& setCharAt(UTextOffset offset, 
01140                UChar ch);
01141 
01142 
01143   /* Append operations */
01144 
01152  inline  UnicodeString& operator+= (UChar ch);
01153 
01161  inline  UnicodeString& operator+= (UChar32 ch);
01162 
01171   inline UnicodeString& operator+= (const UnicodeString& srcText);
01172 
01187   inline UnicodeString& append(const UnicodeString& srcText, 
01188             UTextOffset srcStart, 
01189             int32_t srcLength);
01190 
01198   inline UnicodeString& append(const UnicodeString& srcText);
01199 
01213   inline UnicodeString& append(const UChar *srcChars, 
01214             UTextOffset srcStart, 
01215             int32_t srcLength);
01216 
01225   inline UnicodeString& append(const UChar *srcChars,
01226             int32_t srcLength);
01227 
01234   inline UnicodeString& append(UChar srcChar);
01235 
01242   inline UnicodeString& append(UChar32 srcChar);
01243 
01244 
01245   /* Insert operations */
01246 
01260   inline UnicodeString& insert(UTextOffset start, 
01261             const UnicodeString& srcText, 
01262             UTextOffset srcStart, 
01263             int32_t srcLength);
01264 
01273   inline UnicodeString& insert(UTextOffset start, 
01274             const UnicodeString& srcText);
01275 
01289   inline UnicodeString& insert(UTextOffset start, 
01290             const UChar *srcChars, 
01291             UTextOffset srcStart, 
01292             int32_t srcLength);
01293 
01303   inline UnicodeString& insert(UTextOffset start, 
01304             const UChar *srcChars,
01305             int32_t srcLength);
01306 
01315   inline UnicodeString& insert(UTextOffset start, 
01316             UChar srcChar);
01317 
01326   inline UnicodeString& insert(UTextOffset start, 
01327             UChar32 srcChar);
01328 
01329 
01330   /* Replace operations */
01331 
01349   UnicodeString& replace(UTextOffset start, 
01350              int32_t length, 
01351              const UnicodeString& srcText, 
01352              UTextOffset srcStart, 
01353              int32_t srcLength);
01354 
01367   UnicodeString& replace(UTextOffset start, 
01368              int32_t length, 
01369              const UnicodeString& srcText);
01370 
01388   UnicodeString& replace(UTextOffset start, 
01389              int32_t length, 
01390              const UChar *srcChars, 
01391              UTextOffset srcStart, 
01392              int32_t srcLength);
01393 
01406   inline UnicodeString& replace(UTextOffset start, 
01407              int32_t length, 
01408              const UChar *srcChars,
01409              int32_t srcLength);
01410 
01422   inline UnicodeString& replace(UTextOffset start, 
01423              int32_t length, 
01424              UChar srcChar);
01425 
01437   inline UnicodeString& replace(UTextOffset start, 
01438              int32_t length, 
01439              UChar32 srcChar);
01440 
01450   inline UnicodeString& replaceBetween(UTextOffset start, 
01451                 UTextOffset limit, 
01452                 const UnicodeString& srcText);
01453 
01468   inline UnicodeString& replaceBetween(UTextOffset start, 
01469                 UTextOffset limit, 
01470                 const UnicodeString& srcText, 
01471                 UTextOffset srcStart, 
01472                 UTextOffset srcLimit);
01473 
01484   virtual void handleReplaceBetween(UTextOffset start,
01485                                     UTextOffset limit,
01486                                     const UnicodeString& text);
01487 
01502   virtual void copy(int32_t start, int32_t limit, int32_t dest);
01503 
01504   /* Search and replace operations */
01505 
01514   inline UnicodeString& findAndReplace(const UnicodeString& oldText,
01515                 const UnicodeString& newText);
01516 
01528   inline UnicodeString& findAndReplace(UTextOffset start,
01529                 int32_t length,
01530                 const UnicodeString& oldText,
01531                 const UnicodeString& newText);
01532 
01550   UnicodeString& findAndReplace(UTextOffset start,
01551                 int32_t length,
01552                 const UnicodeString& oldText,
01553                 UTextOffset oldStart,
01554                 int32_t oldLength,
01555                 const UnicodeString& newText,
01556                 UTextOffset newStart,
01557                 int32_t newLength);
01558 
01559 
01560   /* Remove operations */
01561 
01567   inline UnicodeString& remove(void);
01568 
01577   inline UnicodeString& remove(UTextOffset start, 
01578                                int32_t length = INT32_MAX);
01579 
01588   inline UnicodeString& removeBetween(UTextOffset start,
01589                                       UTextOffset limit = INT32_MAX);
01590 
01591 
01592   /* Length operations */
01593 
01605   UBool padLeading(int32_t targetLength,
01606                     UChar padChar = 0x0020);
01607 
01619   UBool padTrailing(int32_t targetLength,
01620                      UChar padChar = 0x0020);
01621 
01628   inline UBool truncate(int32_t targetLength);
01629 
01635   UnicodeString& trim(void);
01636 
01637 
01638   /* Miscellaneous operations */
01639 
01645   inline UnicodeString& reverse(void);
01646 
01655   inline UnicodeString& reverse(UTextOffset start,
01656              int32_t length);
01657 
01664   UnicodeString& toUpper(void);
01665 
01673   UnicodeString& toUpper(const Locale& locale);
01674 
01681   UnicodeString& toLower(void);
01682 
01690   UnicodeString& toLower(const Locale& locale);
01691 
01692 
01693   //========================================
01694   // Constructors
01695   //========================================
01696 
01700   UnicodeString();
01701 
01713   UnicodeString(int32_t capacity, UChar32 c, int32_t count);
01714 
01720   UnicodeString(UChar ch);
01721 
01727   UnicodeString(UChar32 ch);
01728 
01735   UnicodeString(const UChar *text);
01736 
01744   UnicodeString(const UChar *text,
01745         int32_t textLength);
01746 
01766   UnicodeString(UBool isTerminated,
01767                 const UChar *text,
01768                 int32_t textLength);
01769 
01788   UnicodeString(UChar *buffer, int32_t buffLength, int32_t buffCapacity);
01789 
01801   UnicodeString(const char *codepageData,
01802         const char *codepage = 0);
01803 
01816   UnicodeString(const char *codepageData,
01817         int32_t dataLength,
01818         const char *codepage = 0);
01819 
01825   UnicodeString(const UnicodeString& that);
01826 
01830   ~UnicodeString();
01831 
01832 
01833   /* Miscellaneous operations */
01834 
01857   int32_t numDisplayCells(UTextOffset start = 0,
01858               int32_t length = INT32_MAX,
01859               UBool asian = TRUE) const;
01860 
01861 
01862   UCharReference operator[] (UTextOffset pos);
01863 
01896   UnicodeString unescape() const;
01897 
01916   UChar32 unescapeAt(int32_t &offset) const;
01917 
01918   //========================================
01919   // Implementation methods
01920   //========================================
01921   
01922 private:
01923 
01924   inline int8_t
01925   doCompare(UTextOffset start,
01926            int32_t length,
01927            const UnicodeString& srcText,
01928            UTextOffset srcStart,
01929            int32_t srcLength) const;
01930   
01931   int8_t doCompare(UTextOffset start,
01932            int32_t length,
01933            const UChar *srcChars,
01934            UTextOffset srcStart,
01935            int32_t srcLength) const;
01936 
01937   UTextOffset doIndexOf(UChar c,
01938             UTextOffset start,
01939             int32_t length) const;
01940 
01941   UTextOffset doLastIndexOf(UChar c,
01942                 UTextOffset start,
01943                 int32_t length) const;
01944 
01945   void doExtract(UTextOffset start, 
01946          int32_t length, 
01947          UChar *dst, 
01948          UTextOffset dstStart) const;
01949   
01950   inline void doExtract(UTextOffset start,
01951          int32_t length,
01952          UnicodeString& target) const;
01953   
01954   inline UChar doCharAt(UTextOffset offset)  const;
01955 
01956   UnicodeString& doReplace(UTextOffset start, 
01957                int32_t length, 
01958                const UnicodeString& srcText, 
01959                UTextOffset srcStart, 
01960                int32_t srcLength);
01961 
01962   UnicodeString& doReplace(UTextOffset start, 
01963                int32_t length, 
01964                const UChar *srcChars, 
01965                UTextOffset srcStart, 
01966                int32_t srcLength);
01967 
01968   UnicodeString& doReverse(UTextOffset start,
01969                int32_t length);
01970 
01971   // calculate hash code
01972   int32_t doHashCode(void) const;
01973   
01974   // get pointer to start of array
01975   inline UChar* getArrayStart(void);
01976   inline const UChar* getArrayStart(void) const;
01977 
01978   // get the "real" capacity of the array, adjusted for ref count
01979   inline int32_t getCapacity(void) const;
01980 
01981   // allocate the array; result may be fStackBuffer
01982   // sets refCount to 1 if appropriate
01983   // sets fArray, fCapacity, and fFlags
01984   // returns boolean for success or failure
01985   UBool allocate(int32_t capacity);
01986 
01987   // release the array if owned
01988   inline void releaseArray();
01989 
01990   // utility method to get around lack of exception handling
01991   void setToBogus(void);
01992 
01993   // Pin start and limit to acceptable values.
01994   inline void pinIndices(UTextOffset& start,
01995                          int32_t& length) const;
01996 
01997   /*
01998    * Real constructor for converting from codepage data.
01999    * It assumes that it is called with !fRefCounted.
02000    *
02001    * If <code>codepage==0</code>, then the default converter
02002    * is used for the platform encoding.
02003    * If <code>codepage</code> is an empty string (<code>""</code>),
02004    * then a simple conversion is performed on the codepage-invariant
02005    * subset ("invariant characters") of the platform encoding. See utypes.h.
02006    */
02007   void doCodepageCreate(const char *codepageData,
02008                         int32_t dataLength,
02009                         const char *codepage);
02010 
02011   /*
02012    * This function is called when write access to the array
02013    * is necessary.
02014    *
02015    * We need to make a copy of the array if
02016    * the buffer is read-only, or
02017    * the buffer is refCounted (shared), and refCount>1, or
02018    * the buffer is too small.
02019    *
02020    * Return FALSE if memory could not be allocated.
02021    */
02022   UBool cloneArrayIfNeeded(int32_t newCapacity = -1,
02023                             int32_t growCapacity = -1,
02024                             UBool doCopyArray = TRUE,
02025                             int32_t **pBufferToDelete = 0);
02026 
02027   // ref counting
02028   inline int32_t addRef(void);
02029   inline int32_t removeRef(void);
02030   inline int32_t refCount(void) const;
02031   inline int32_t setRefCount(int32_t count);
02032 
02033   // constants
02034   enum {
02035 #if UTF_SIZE==8
02036     US_STACKBUF_SIZE=14, // Size of stack buffer for small strings
02037 #elif UTF_SIZE==16
02038     US_STACKBUF_SIZE=7, // Size of stack buffer for small strings
02039 #else // UTF_SIZE==32
02040     US_STACKBUF_SIZE=3, // Size of stack buffer for small strings
02041 #endif
02042     kInvalidUChar=0xffff, // invalid UChar index
02043     kGrowSize=128, // grow size for this buffer
02044     kInvalidHashCode=0, // invalid hash code
02045     kEmptyHashCode=1, // hash code for empty string
02046 
02047     // bit flag values for fFlags
02048     kIsBogus=1, // this string is bogus, i.e., not valid
02049     kUsingStackBuffer=2, // fArray==fStackBuffer
02050     kRefCounted=4, // there is a refCount field before the characters in fArray
02051     kBufferIsReadonly=8, // do not write to this buffer
02052 
02053     // combined values for convenience
02054     kShortString=kUsingStackBuffer,
02055     kLongString=kRefCounted,
02056     kReadonlyAlias=kBufferIsReadonly,
02057     kWriteableAlias=0
02058   };
02059 
02060   // statics
02061 
02062   // default converter cache
02063   static UConverter* getDefaultConverter(UErrorCode& status);
02064   static void releaseDefaultConverter(UConverter *converter);
02065 
02066   static UConverter *fgDefaultConverter;
02067 
02068   friend class UnicodeStringStreamer;
02069   friend class UnicodeConverter;
02070 
02071 #if U_IOSTREAM_SOURCE >= 199711
02072   friend U_COMMON_API std::ostream &operator<<(std::ostream& stream, const UnicodeString& s);
02073 #elif U_IOSTREAM_SOURCE >= 198506
02074   friend U_COMMON_API ostream &operator<<(ostream& stream, const UnicodeString& s);
02075 #endif
02076 
02077   friend class StringCharacterIterator;
02078 
02079   /*
02080    * The following are all the class fields that are stored
02081    * in each UnicodeString object.
02082    * Note that UnicodeString has virtual functions,
02083    * therefore there is an implicit vtable pointer
02084    * as the first real field.
02085    * The fields should be aligned such that no padding is
02086    * necessary, mostly by having larger types first.
02087    * On 32-bit machines, the size should be 32 bytes,
02088    * on 64-bit machines (8-byte pointers), it should be 40 bytes.
02089    */
02090   // (implicit) *vtable;
02091   UChar     *fArray;        // the Unicode data
02092   int32_t   fLength;        // number characters in fArray
02093   int32_t   fCapacity;      // sizeof fArray
02094   uint16_t  fFlags;         // bit flags: see constants above
02095 #if UTF_SIZE==32
02096   uint16_t  fPadding;       // padding to align the fStackBuffer for UTF-32
02097 #endif
02098   UChar     fStackBuffer [ US_STACKBUF_SIZE ]; // buffer for small strings
02099 
02100 public:
02101 
02102   //========================================
02103   // Deprecated API
02104   //========================================
02105 
02106   /* size() -> length()
02107    * @deprecated Remove after 2000-dec-31. Use length() instead. */
02108   inline int32_t size(void) const;
02109 
02110   // parameters reordered for consistency
02111    /* @deprecated To be removed in first release in 2001. Use the other versions of this function */
02112   inline UnicodeString& findAndReplace(const UnicodeString& oldText,
02113                 const UnicodeString& newText,
02114                 UTextOffset start,
02115                 int32_t length);
02116 
02117    /* @deprecated Remove after 2000-dec-31. There is no replacement. */
02118   inline void* operator new(size_t size);
02119    /* @deprecated Remove after 2000-dec-31. There is no replacement. */
02120   inline void* operator new(size_t size, void *location);
02121    /* @deprecated Remove after 2000-dec-31. There is no replacement. */
02122   inline void operator delete(void *location);
02123 
02124   //========================================
02125   // Non-public API - will be removed!
02126   //========================================
02127   /* @deprecated Remove after 2000-dec-31. There is no public replacement. */
02128   const UChar* getUChars() const;
02129 };
02130 
02131 //========================================
02132 // Array copying
02133 //========================================
02134 // Copy an array of UnicodeString OBJECTS (not pointers).
02135 inline void 
02136 uprv_arrayCopy(const UnicodeString *src, UnicodeString *dst, int32_t count)
02137 { while(count-- > 0) *dst++ = *src++; }
02138 
02139 inline void 
02140 uprv_arrayCopy(const UnicodeString *src, int32_t srcStart, 
02141         UnicodeString *dst, int32_t dstStart, int32_t count)
02142 { uprv_arrayCopy(src+srcStart, dst+dstStart, count); }
02143 
02144 
02145 //========================================
02146 // Inline members
02147 //========================================
02148 
02149 //========================================
02150 // Read-only alias methods
02151 //========================================
02152 inline UBool
02153 UnicodeString::operator== (const UnicodeString& text) const
02154 {
02155   if(isBogus()) {
02156     return text.isBogus();
02157   } else {
02158     return
02159       !text.isBogus() &&
02160       fLength == text.fLength &&
02161       doCompare(0, fLength, text, 0, text.fLength) == 0;
02162   }
02163 }
02164 
02165 inline UBool
02166 UnicodeString::operator!= (const UnicodeString& text) const
02167 { return (! operator==(text)); }
02168 
02169 inline UBool
02170 UnicodeString::operator> (const UnicodeString& text) const
02171 { return doCompare(0, fLength, text, 0, text.fLength) == 1; }
02172 
02173 inline UBool
02174 UnicodeString::operator< (const UnicodeString& text) const
02175 { return doCompare(0, fLength, text, 0, text.fLength) == -1; }
02176 
02177 inline UBool
02178 UnicodeString::operator>= (const UnicodeString& text) const
02179 { return doCompare(0, fLength, text, 0, text.fLength) != -1; }
02180 
02181 inline UBool
02182 UnicodeString::operator<= (const UnicodeString& text) const
02183 { return doCompare(0, fLength, text, 0, text.fLength) != 1; }
02184 
02185 inline int8_t 
02186 UnicodeString::compare(const UnicodeString& text) const
02187 { return doCompare(0, fLength, text, 0, text.fLength); }
02188 
02189 inline int8_t 
02190 UnicodeString::compare(UTextOffset start,
02191                int32_t length,
02192                const UnicodeString& srcText) const
02193 { return doCompare(start, length, srcText, 0, srcText.fLength); }
02194 
02195 inline int8_t 
02196 UnicodeString::compare(const UChar *srcChars,
02197                int32_t srcLength) const
02198 { return doCompare(0, fLength, srcChars, 0, srcLength); }
02199 
02200 inline int8_t 
02201 UnicodeString::compare(UTextOffset start,
02202                int32_t length,
02203                const UnicodeString& srcText,
02204                UTextOffset srcStart,
02205                int32_t srcLength) const
02206 { return doCompare(start, length, srcText, srcStart, srcLength); }
02207 
02208 inline int8_t
02209 UnicodeString::compare(UTextOffset start,
02210                int32_t length,
02211                const UChar *srcChars) const
02212 { return doCompare(start, length, srcChars, 0, length); }
02213 
02214 inline int8_t 
02215 UnicodeString::compare(UTextOffset start,
02216                int32_t length,
02217                const UChar *srcChars,
02218                UTextOffset srcStart,
02219                int32_t srcLength) const
02220 { return doCompare(start, length, srcChars, srcStart, srcLength); }
02221 
02222 inline int8_t
02223 UnicodeString::compareBetween(UTextOffset start,
02224                   UTextOffset limit,
02225                   const UnicodeString& srcText,
02226                   UTextOffset srcStart,
02227                   UTextOffset srcLimit) const
02228 { return doCompare(start, limit - start, 
02229            srcText, srcStart, srcLimit - srcStart); }
02230 
02231 inline int8_t
02232 UnicodeString::doCompare(UTextOffset start,
02233               int32_t length,
02234               const UnicodeString& srcText,
02235               UTextOffset srcStart,
02236               int32_t srcLength) const
02237 {
02238   const UChar *srcChars;
02239   if(!srcText.isBogus()) {
02240     srcText.pinIndices(srcStart, srcLength);
02241     srcChars=srcText.getArrayStart();
02242   } else {
02243     srcChars=0;
02244   }
02245   return doCompare(start, length, srcChars, srcStart, srcLength);
02246 }
02247 
02248 inline UTextOffset 
02249 UnicodeString::indexOf(const UnicodeString& text) const
02250 { return indexOf(text, 0, text.fLength, 0, fLength); }
02251 
02252 inline UTextOffset 
02253 UnicodeString::indexOf(const UnicodeString& text,
02254                UTextOffset start) const
02255 { return indexOf(text, 0, text.fLength, start, fLength - start); }
02256 
02257 inline UTextOffset 
02258 UnicodeString::indexOf(const UnicodeString& text,
02259                UTextOffset start,
02260                int32_t length) const
02261 { return indexOf(text, 0, text.fLength, start, length); }
02262 
02263 inline UTextOffset 
02264 UnicodeString::indexOf(const UnicodeString& srcText,
02265                UTextOffset srcStart,
02266                int32_t srcLength,
02267                UTextOffset start,
02268                int32_t length) const
02269 {
02270   if(!srcText.isBogus()) {
02271     srcText.pinIndices(srcStart, srcLength);
02272     if(srcLength > 0) {
02273       return indexOf(srcText.getArrayStart(), srcStart, srcLength, start, length);
02274     }
02275   }
02276   return -1;
02277 }
02278 
02279 inline UTextOffset 
02280 UnicodeString::indexOf(const UChar *srcChars,
02281                int32_t srcLength,
02282                UTextOffset start) const
02283 { return indexOf(srcChars, 0, srcLength, start, fLength - start); }
02284 
02285 inline UTextOffset 
02286 UnicodeString::indexOf(const UChar *srcChars,
02287                int32_t srcLength,
02288                UTextOffset start,
02289                int32_t length) const
02290 { return indexOf(srcChars, 0, srcLength, start, length); }
02291 
02292 inline UTextOffset 
02293 UnicodeString::indexOf(UChar c) const
02294 { return doIndexOf(c, 0, fLength); }
02295 
02296 inline UTextOffset 
02297 UnicodeString::indexOf(UChar32 c) const {
02298   if(!UTF_NEED_MULTIPLE_UCHAR(c)) {
02299     return doIndexOf((UChar)c, 0, fLength);
02300   } else {
02301     UChar buffer[UTF_MAX_CHAR_LENGTH];
02302     int32_t length = 0;
02303     UTF_APPEND_CHAR_UNSAFE(buffer, length, c);
02304     return indexOf(buffer, length, 0);
02305   }
02306 }
02307 
02308 inline UTextOffset 
02309 UnicodeString::indexOf(UChar c,
02310                UTextOffset start) const
02311 { return doIndexOf(c, start, fLength - start); }
02312 
02313 inline UTextOffset 
02314 UnicodeString::indexOf(UChar32 c,
02315                UTextOffset start) const {
02316   if(!UTF_NEED_MULTIPLE_UCHAR(c)) {
02317     return doIndexOf((UChar)c, start, fLength - start);
02318   } else {
02319     UChar buffer[UTF_MAX_CHAR_LENGTH];
02320     int32_t length = 0;
02321     UTF_APPEND_CHAR_UNSAFE(buffer, length, c);
02322     return indexOf(buffer, length, start);
02323   }
02324 }
02325 
02326 inline UTextOffset 
02327 UnicodeString::indexOf(UChar c,
02328                UTextOffset start,
02329                int32_t length) const
02330 { return doIndexOf(c, start, length); }
02331 
02332 inline UTextOffset 
02333 UnicodeString::indexOf(UChar32 c,
02334                UTextOffset start,
02335                int32_t length) const {
02336   if(!UTF_NEED_MULTIPLE_UCHAR(c)) {
02337     return doIndexOf((UChar)c, start, length);
02338   } else {
02339     UChar buffer[UTF_MAX_CHAR_LENGTH];
02340     int32_t cLength = 0;
02341     UTF_APPEND_CHAR_UNSAFE(buffer, cLength, c);
02342     return indexOf(buffer, cLength, start, length);
02343   }
02344 }
02345 
02346 inline UTextOffset 
02347 UnicodeString::lastIndexOf(const UnicodeString& text) const
02348 { return lastIndexOf(text, 0, text.fLength, 0, fLength); }
02349 
02350 inline UTextOffset 
02351 UnicodeString::lastIndexOf(const UnicodeString& text,
02352                UTextOffset start) const
02353 { return lastIndexOf(text, 0, text.fLength, start, fLength - start); }
02354 
02355 inline UTextOffset 
02356 UnicodeString::lastIndexOf(const UnicodeString& text,
02357                UTextOffset start,
02358                int32_t length) const
02359 { return lastIndexOf(text, 0, text.fLength, start, length); }
02360 
02361 inline UTextOffset 
02362 UnicodeString::lastIndexOf(const UnicodeString& srcText,
02363                UTextOffset srcStart,
02364                int32_t srcLength,
02365                UTextOffset start,
02366                int32_t length) const
02367 {
02368   if(!srcText.isBogus()) {
02369     srcText.pinIndices(srcStart, srcLength);
02370     if(srcLength > 0) {
02371       return lastIndexOf(srcText.getArrayStart(), srcStart, srcLength, start, length);
02372     }
02373   }
02374   return -1;
02375 }
02376 
02377 inline UTextOffset 
02378 UnicodeString::lastIndexOf(const UChar *srcChars,
02379                int32_t srcLength,
02380                UTextOffset start) const
02381 { return lastIndexOf(srcChars, 0, srcLength, start, fLength - start); }
02382 
02383 inline UTextOffset 
02384 UnicodeString::lastIndexOf(const UChar *srcChars,
02385                int32_t srcLength,
02386                UTextOffset start,
02387                int32_t length) const
02388 { return lastIndexOf(srcChars, 0, srcLength, start, length); }
02389 
02390 inline UTextOffset 
02391 UnicodeString::lastIndexOf(UChar c) const
02392 { return doLastIndexOf(c, 0, fLength); }
02393 
02394 inline UTextOffset 
02395 UnicodeString::lastIndexOf(UChar32 c) const {
02396   if(!UTF_NEED_MULTIPLE_UCHAR(c)) {
02397     return doLastIndexOf((UChar)c, 0, fLength);
02398   } else {
02399     UChar buffer[UTF_MAX_CHAR_LENGTH];
02400     int32_t count = 0;
02401     UTF_APPEND_CHAR_UNSAFE(buffer, count, c);
02402     return lastIndexOf(buffer, count, 0);
02403   }
02404 }
02405 
02406 inline UTextOffset 
02407 UnicodeString::lastIndexOf(UChar c,
02408                UTextOffset start) const
02409 { return doLastIndexOf(c, start, fLength - start); }
02410 
02411 inline UTextOffset 
02412 UnicodeString::lastIndexOf(UChar32 c,
02413                UTextOffset start) const {
02414   if(!UTF_NEED_MULTIPLE_UCHAR(c)) {
02415     return doLastIndexOf((UChar)c, start, fLength - start);
02416   } else {
02417     UChar buffer[UTF_MAX_CHAR_LENGTH];
02418     int32_t count = 0;
02419     UTF_APPEND_CHAR_UNSAFE(buffer, count, c);
02420     return lastIndexOf(buffer, count, start);
02421   }
02422 }
02423 
02424 inline UTextOffset 
02425 UnicodeString::lastIndexOf(UChar c,
02426                UTextOffset start,
02427                int32_t length) const
02428 { return doLastIndexOf(c, start, length); }
02429 
02430 inline UTextOffset 
02431 UnicodeString::lastIndexOf(UChar32 c,
02432                UTextOffset start,
02433                int32_t length) const {
02434   if(!UTF_NEED_MULTIPLE_UCHAR(c)) {
02435     return doLastIndexOf((UChar)c, start, length);
02436   } else {
02437     UChar buffer[UTF_MAX_CHAR_LENGTH];
02438     int32_t count = 0;
02439     UTF_APPEND_CHAR_UNSAFE(buffer, count, c);
02440     return lastIndexOf(buffer, count, start, length);
02441   }
02442 }
02443 
02444 inline UBool 
02445 UnicodeString::startsWith(const UnicodeString& text) const
02446 { return compare(0, text.fLength, text, 0, text.fLength) == 0; }
02447 
02448 inline UBool 
02449 UnicodeString::startsWith(const UnicodeString& srcText,
02450               UTextOffset srcStart,
02451               int32_t srcLength) const
02452 { return doCompare(0, srcLength, srcText, srcStart, srcLength) == 0; }
02453 
02454 inline UBool 
02455 UnicodeString::startsWith(const UChar *srcChars,
02456               int32_t srcLength) const
02457 { return doCompare(0, srcLength, srcChars, 0, srcLength) == 0; }
02458 
02459 inline UBool 
02460 UnicodeString::startsWith(const UChar *srcChars,
02461               UTextOffset srcStart,
02462               int32_t srcLength) const
02463 { return doCompare(0, srcLength, srcChars, srcStart, srcLength) == 0;}
02464 
02465 inline UBool 
02466 UnicodeString::endsWith(const UnicodeString& text) const
02467 { return doCompare(fLength - text.fLength, text.fLength, 
02468            text, 0, text.fLength) == 0; }
02469 
02470 inline UBool 
02471 UnicodeString::endsWith(const UnicodeString& srcText,
02472             UTextOffset srcStart,
02473             int32_t srcLength) const
02474 { return doCompare(fLength - srcLength, srcLength, 
02475            srcText, srcStart, srcLength) == 0; }
02476 
02477 inline UBool 
02478 UnicodeString::endsWith(const UChar *srcChars,
02479             int32_t srcLength) const
02480 { return doCompare(fLength - srcLength, srcLength, 
02481            srcChars, 0, srcLength) == 0; }
02482 
02483 inline UBool 
02484 UnicodeString::endsWith(const UChar *srcChars,
02485             UTextOffset srcStart,
02486             int32_t srcLength) const
02487 { return doCompare(fLength - srcLength, srcLength, 
02488            srcChars, srcStart, srcLength) == 0;}
02489 //========================================
02490 // replace
02491 //========================================
02492 inline UnicodeString& 
02493 UnicodeString::replace(UTextOffset start, 
02494                int32_t length, 
02495                const UnicodeString& srcText) 
02496 { return doReplace(start, length, srcText, 0, srcText.fLength); }
02497 
02498 inline UnicodeString& 
02499 UnicodeString::replace(UTextOffset start, 
02500                int32_t length, 
02501                const UnicodeString& srcText, 
02502                UTextOffset srcStart, 
02503                int32_t srcLength)
02504 { return doReplace(start, length, srcText, srcStart, srcLength); }
02505 
02506 inline UnicodeString& 
02507 UnicodeString::replace(UTextOffset start, 
02508                int32_t length, 
02509                const UChar *srcChars,
02510                int32_t srcLength)
02511 { return doReplace(start, length, srcChars, 0, srcLength); }
02512 
02513 inline UnicodeString& 
02514 UnicodeString::replace(UTextOffset start, 
02515                int32_t length, 
02516                const UChar *srcChars, 
02517                UTextOffset srcStart, 
02518                int32_t srcLength)
02519 { return doReplace(start, length, srcChars, srcStart, srcLength); }
02520 
02521 inline UnicodeString& 
02522 UnicodeString::replace(UTextOffset start, 
02523                int32_t length, 
02524                UChar srcChar)
02525 { return doReplace(start, length, &srcChar, 0, 1); }
02526 
02527 inline UnicodeString&
02528 UnicodeString::replace(UTextOffset start, 
02529                int32_t length, 
02530                UChar32 srcChar) {
02531   UChar buffer[UTF_MAX_CHAR_LENGTH];
02532   int32_t count = 0;
02533   UTF_APPEND_CHAR_UNSAFE(buffer, count, srcChar);
02534   return doReplace(start, length, buffer, 0, count);
02535 }
02536 
02537 inline UnicodeString& 
02538 UnicodeString::replaceBetween(UTextOffset start, 
02539                   UTextOffset limit, 
02540                   const UnicodeString& srcText)
02541 { return doReplace(start, limit - start, srcText, 0, srcText.fLength); }
02542 
02543 inline UnicodeString&
02544 UnicodeString::replaceBetween(UTextOffset start, 
02545                   UTextOffset limit, 
02546                   const UnicodeString& srcText, 
02547                   UTextOffset srcStart, 
02548                   UTextOffset srcLimit)
02549 { return doReplace(start, limit - start, srcText, srcStart, srcLimit - srcStart); }
02550 
02551 inline UnicodeString& 
02552 UnicodeString::findAndReplace(const UnicodeString& oldText,
02553                   const UnicodeString& newText)
02554 { return findAndReplace(0, fLength, oldText, 0, oldText.fLength, 
02555             newText, 0, newText.fLength); }
02556 
02557 inline UnicodeString& 
02558 UnicodeString::findAndReplace(UTextOffset start,
02559                   int32_t length,
02560                   const UnicodeString& oldText,
02561                   const UnicodeString& newText)
02562 { return findAndReplace(start, length, oldText, 0, oldText.fLength, 
02563             newText, 0, newText.fLength); }
02564 
02565 // ============================
02566 // extract
02567 // ============================
02568 inline void
02569 UnicodeString::doExtract(UTextOffset start,
02570              int32_t length,
02571              UnicodeString& target) const
02572 { target.replace(0, target.fLength, *this, start, length); }
02573 
02574 inline void  
02575 UnicodeString::extract(UTextOffset start, 
02576                int32_t length, 
02577                UChar *target, 
02578                UTextOffset targetStart) const
02579 { doExtract(start, length, target, targetStart); }
02580 
02581 inline void 
02582 UnicodeString::extract(UTextOffset start,
02583                int32_t length,
02584                UnicodeString& target) const
02585 { doExtract(start, length, target); }
02586 
02587 inline int32_t
02588 UnicodeString::extract(UTextOffset start,
02589                int32_t length,
02590                char *dst,
02591                const char *codepage) const
02592 // This dstSize value should prevent pointer overflow
02593 {return extract(start, length, dst, 0x0FFFFFFF, codepage);}
02594 
02595 inline void  
02596 UnicodeString::extractBetween(UTextOffset start, 
02597                   UTextOffset limit, 
02598                   UChar *dst, 
02599                   UTextOffset dstStart) const
02600 { doExtract(start, limit - start, dst, dstStart); }
02601 
02602 inline void 
02603 UnicodeString::extractBetween(UTextOffset start,
02604                   UTextOffset limit,
02605                   UnicodeString& target) const
02606 { doExtract(start, limit - start, target); }
02607 
02608 inline UChar
02609 UnicodeString::doCharAt(UTextOffset offset) const
02610 {
02611   if((uint32_t)offset < (uint32_t)fLength) {
02612     return fArray[offset];
02613   } else {
02614     return kInvalidUChar;
02615   }
02616 }
02617 
02618 inline UChar
02619 UnicodeString::charAt(UTextOffset offset) const
02620 { return doCharAt(offset); }
02621 
02622 inline UChar
02623 UnicodeString::operator[] (UTextOffset offset) const
02624 { return doCharAt(offset); }
02625 
02626 inline UChar32
02627 UnicodeString::char32At(UTextOffset offset) const
02628 {
02629   if((uint32_t)offset < (uint32_t)fLength) {
02630     UChar32 c;
02631     UTF_GET_CHAR(fArray, 0, offset, fLength, c);
02632     return c;
02633   } else {
02634     return kInvalidUChar;
02635   }
02636 }
02637 
02638 inline UTextOffset
02639 UnicodeString::getCharStart(UTextOffset offset) {
02640   if((uint32_t)offset < (uint32_t)fLength) {
02641     UTF_SET_CHAR_START(fArray, 0, offset);
02642     return offset;
02643   } else {
02644     return 0;
02645   }
02646 }
02647 
02648 inline UTextOffset
02649 UnicodeString::getCharLimit(UTextOffset offset) {
02650   if((uint32_t)offset < (uint32_t)fLength) {
02651     UTF_SET_CHAR_LIMIT(fArray, 0, offset, fLength);
02652     return offset;
02653   } else {
02654     return fLength;
02655   }
02656 }
02657 
02658 inline UBool
02659 UnicodeString::empty() const
02660 { return fLength == 0; }
02661 
02662 //========================================
02663 // Read-only implementation methods
02664 //========================================
02665 inline int32_t  
02666 UnicodeString::length() const
02667 { return fLength; }
02668 
02669 inline int32_t 
02670 UnicodeString::hashCode() const
02671 { return doHashCode(); }
02672 
02673 //========================================
02674 // Write alias methods
02675 //========================================
02676 inline UnicodeString& 
02677 UnicodeString::operator= (UChar ch) 
02678 { return doReplace(0, fLength, &ch, 0, 1); }
02679 
02680 inline UnicodeString& 
02681 UnicodeString::operator= (UChar32 ch) 
02682 { return replace(0, fLength, ch); }
02683 
02684 inline UnicodeString& 
02685 UnicodeString::setTo(const UnicodeString& srcText, 
02686              UTextOffset srcStart, 
02687              int32_t srcLength)
02688 { return doReplace(0, fLength, srcText, srcStart, srcLength); }
02689 
02690 inline UnicodeString& 
02691 UnicodeString::setTo(const UnicodeString& srcText)
02692 { return doReplace(0, fLength, srcText, 0, srcText.fLength); }
02693 
02694 inline UnicodeString& 
02695 UnicodeString::setTo(const UChar *srcChars,
02696              int32_t srcLength)
02697 { return doReplace(0, fLength, srcChars, 0, srcLength); }
02698 
02699 inline UnicodeString& 
02700 UnicodeString::setTo(UChar srcChar)
02701 { return doReplace(0, fLength, &srcChar, 0, 1); }
02702 
02703 inline UnicodeString& 
02704 UnicodeString::setTo(UChar32 srcChar)
02705 { return replace(0, fLength, srcChar); }
02706 
02707 inline UnicodeString& 
02708 UnicodeString::operator+= (UChar ch)
02709 { return doReplace(fLength, 0, &ch, 0, 1); }
02710 
02711 inline UnicodeString& 
02712 UnicodeString::operator+= (UChar32 ch) {
02713   UChar buffer[UTF_MAX_CHAR_LENGTH];
02714   int32_t length = 0;
02715   UTF_APPEND_CHAR_UNSAFE(buffer, length, ch);
02716   return doReplace(fLength, 0, buffer, 0, length);
02717 }
02718 
02719 inline UnicodeString& 
02720 UnicodeString::operator+= (const UnicodeString& srcText)
02721 { return doReplace(fLength, 0, srcText, 0, srcText.fLength); }
02722 
02723 inline UnicodeString& 
02724 UnicodeString::append(const UnicodeString& srcText, 
02725               UTextOffset srcStart, 
02726               int32_t srcLength)
02727 { return doReplace(fLength, 0, srcText, srcStart, srcLength); }
02728 
02729 inline UnicodeString& 
02730 UnicodeString::append(const UnicodeString& srcText)
02731 { return doReplace(fLength, 0, srcText, 0, srcText.fLength); }
02732 
02733 inline UnicodeString& 
02734 UnicodeString::append(const UChar *srcChars, 
02735               UTextOffset srcStart, 
02736               int32_t srcLength)
02737 { return doReplace(fLength, 0, srcChars, srcStart, srcLength); }
02738 
02739 inline UnicodeString& 
02740 UnicodeString::append(const UChar *srcChars,
02741               int32_t srcLength)
02742 { return doReplace(fLength, 0, srcChars, 0, srcLength); }
02743 
02744 inline UnicodeString& 
02745 UnicodeString::append(UChar srcChar)
02746 { return doReplace(fLength, 0, &srcChar, 0, 1); }
02747 
02748 inline UnicodeString& 
02749 UnicodeString::append(UChar32 srcChar) {
02750   UChar buffer[UTF_MAX_CHAR_LENGTH];
02751   int32_t length = 0;
02752   UTF_APPEND_CHAR_UNSAFE(buffer, length, srcChar);
02753   return doReplace(fLength, 0, buffer, 0, length);
02754 }
02755 
02756 inline UnicodeString& 
02757 UnicodeString::insert(UTextOffset start, 
02758               const UnicodeString& srcText, 
02759               UTextOffset srcStart, 
02760               int32_t srcLength)
02761 { return doReplace(start, 0, srcText, srcStart, srcLength); }
02762 
02763 inline UnicodeString& 
02764 UnicodeString::insert(UTextOffset start, 
02765               const UnicodeString& srcText)
02766 { return doReplace(start, 0, srcText, 0, srcText.fLength); }
02767 
02768 inline UnicodeString& 
02769 UnicodeString::insert(UTextOffset start, 
02770               const UChar *srcChars, 
02771               UTextOffset srcStart, 
02772               int32_t srcLength)
02773 { return doReplace(start, 0, srcChars, srcStart, srcLength); }
02774 
02775 inline UnicodeString& 
02776 UnicodeString::insert(UTextOffset start, 
02777               const UChar *srcChars,
02778               int32_t srcLength)
02779 { return doReplace(start, 0, srcChars, 0, srcLength); }
02780 
02781 inline UnicodeString& 
02782 UnicodeString::insert(UTextOffset start, 
02783               UChar srcChar)
02784 { return doReplace(start, 0, &srcChar, 0, 1); }
02785 
02786 inline UnicodeString& 
02787 UnicodeString::insert(UTextOffset start, 
02788               UChar32 srcChar)
02789 { return replace(start, 0, srcChar); }
02790 
02791 
02792 inline UnicodeString& 
02793 UnicodeString::remove(UTextOffset start, 
02794              int32_t length)
02795 { return doReplace(start, length, NULL, 0, 0); }
02796 
02797 inline UnicodeString& 
02798 UnicodeString::remove()
02799 { return doReplace(0, fLength, 0, 0, 0); }
02800 
02801 inline UnicodeString& 
02802 UnicodeString::removeBetween(UTextOffset start,
02803                 UTextOffset limit)
02804 { return doReplace(start, limit - start, NULL, 0, 0); }
02805 
02806 inline UBool 
02807 UnicodeString::truncate(int32_t targetLength)
02808 {
02809   if((uint32_t)targetLength < (uint32_t)fLength) {
02810     fLength = targetLength;
02811     return TRUE;
02812   } else {
02813     return FALSE;
02814   }
02815 }
02816 
02817 inline UnicodeString& 
02818 UnicodeString::reverse()
02819 { return doReverse(0, fLength); }
02820 
02821 inline UnicodeString& 
02822 UnicodeString::reverse(UTextOffset start,
02823                int32_t length)
02824 { return doReverse(start, length); }
02825 
02826 
02827 //========================================
02828 // Write implementation methods
02829 //========================================
02830 inline UBool 
02831 UnicodeString::isBogus() const
02832 { return (UBool)(fFlags & kIsBogus); }
02833 
02834 
02835 //========================================
02836 // Privates
02837 //========================================
02838 
02839 inline void
02840 UnicodeString::pinIndices(UTextOffset& start,
02841                           int32_t& length) const
02842 {
02843   // pin indices
02844   if(start < 0) {
02845     start = 0;
02846   } else if(start > fLength) {
02847     start = fLength;
02848   }
02849   if(length < 0) {
02850     length = 0;
02851   } else if(length > (fLength - start)) {
02852     length = (fLength - start);
02853   }
02854 }
02855 
02856 inline UChar* 
02857 UnicodeString::getArrayStart()
02858 { return fArray; }
02859 
02860 inline const UChar* 
02861 UnicodeString::getArrayStart() const
02862 { return fArray; }
02863 
02864 inline int32_t 
02865 UnicodeString::getCapacity() const
02866 { return fCapacity; }
02867 
02868 inline void
02869 UnicodeString::releaseArray() {
02870   if((fFlags & kRefCounted) && removeRef() == 0) {
02871     delete [] ((int32_t *)fArray - 1);
02872   }
02873 }
02874 
02875 inline int32_t
02876 UnicodeString::addRef()
02877 { return ++*((int32_t *)fArray - 1); }
02878 
02879 inline int32_t
02880 UnicodeString::removeRef()
02881 { return --*((int32_t *)fArray - 1); }
02882 
02883 inline int32_t
02884 UnicodeString::refCount() const
02885 { return *((int32_t *)fArray - 1); }
02886 
02887 inline int32_t
02888 UnicodeString::setRefCount(int32_t count)
02889 { return (*((int32_t *)fArray - 1) = count); }
02890 
02891 
02892 // deprecated API - remove later
02893 inline int32_t
02894 UnicodeString::size() const
02895 { return fLength; }
02896 
02897 inline UnicodeString& 
02898 UnicodeString::findAndReplace(const UnicodeString& oldText,
02899                   const UnicodeString& newText,
02900                   UTextOffset start,
02901                   int32_t length)
02902 { return findAndReplace(start, length, oldText, newText); }
02903 
02904 inline void*
02905 UnicodeString::operator new(size_t size)
02906 { return ::operator new(size); }
02907 
02908 inline void* 
02909 UnicodeString::operator new(size_t, 
02910               void *location)
02911 { return location; }
02912 
02913 inline void
02914 UnicodeString::operator delete(void *location)
02915 { ::operator delete(location); }
02916 
02917 
02918 //========================================
02919 // Static members
02920 //========================================
02921 
02922 //========================================
02923 // class UCharReference
02924 //========================================
02925 class UCharReference
02926 {
02927 public:
02928   UCharReference();
02929   inline UCharReference(UnicodeString *string,
02930          UTextOffset pos);
02931   inline UCharReference(const UCharReference& that);
02932   ~UCharReference();
02933 
02934   inline UCharReference& operator= (const UCharReference& that);
02935   inline UCharReference& operator= (UChar c);
02936 
02937   inline operator UChar();
02938 
02939 private:
02940   UnicodeString *fString;
02941   UTextOffset fPos;
02942 };
02943 
02944 
02945 //========================================
02946 // Inline members
02947 //========================================
02948 inline
02949 UCharReference::UCharReference(UnicodeString *string, 
02950                    UTextOffset pos)
02951   : fString(string), fPos(pos)
02952 {}
02953 
02954 inline
02955 UCharReference::UCharReference(const UCharReference& that)
02956 { this->operator=(that); }
02957 
02958 inline
02959 UCharReference::~UCharReference()
02960 {}
02961 
02962 inline UCharReference&
02963 UCharReference::operator= (const UCharReference& that)
02964 { fString->setCharAt(fPos, that.fString->charAt(that.fPos)); return *this; }
02965 
02966 inline UCharReference& 
02967 UCharReference::operator= (UChar c)
02968 { fString->setCharAt(fPos, c); return *this; }
02969 
02970 inline
02971 UCharReference::operator UChar()
02972 { return fString->charAt(fPos); }
02973 
02974 #endif

Generated at Fri Dec 15 12:12:38 2000 for ICU 1.7 by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000