Main Page   Class Hierarchy   Compound List   File List   Header Files   Sources   Compound Members   File Members  

unistr.h

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 
00113 class U_COMMON_API UnicodeString : public Replaceable
00114 {
00115 public:
00116 
00117   //========================================
00118   // Read-only operations
00119   //========================================
00120   
00121   /* Comparison - bitwise only - for international comparison use collation */
00122   
00130   inline UBool operator== (const UnicodeString& text) const;
00131   
00139   inline UBool operator!= (const UnicodeString& text) const;
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 
00188   inline int8_t compare(const UnicodeString& text) const;
00189 
00204   inline int8_t compare(UTextOffset start,
00205          int32_t length,
00206          const UnicodeString& srcText) const;
00207 
00225    inline int8_t compare(UTextOffset start,
00226          int32_t length,
00227          const UnicodeString& srcText,
00228          UTextOffset srcStart,
00229          int32_t srcLength) const;
00230 
00243   inline int8_t compare(const UChar *srcChars,
00244          int32_t srcLength) const;
00245 
00260   inline int8_t compare(UTextOffset start,
00261          int32_t length,
00262          const UChar *srcChars) const;
00263 
00281   inline int8_t compare(UTextOffset start,
00282          int32_t length,
00283          const UChar *srcChars,
00284          UTextOffset srcStart,
00285          int32_t srcLength) const;
00286 
00304   inline int8_t compareBetween(UTextOffset start,
00305             UTextOffset limit,
00306             const UnicodeString& srcText,
00307             UTextOffset srcStart,
00308             UTextOffset srcLimit) const;
00309 
00317   inline UBool startsWith(const UnicodeString& text) const;
00318 
00329   inline UBool startsWith(const UnicodeString& srcText,
00330             UTextOffset srcStart,
00331             int32_t srcLength) const;
00332   
00341   inline UBool startsWith(const UChar *srcChars,
00342             int32_t srcLength) const;
00343  
00354   inline UBool startsWith(const UChar *srcChars,
00355             UTextOffset srcStart,
00356             int32_t srcLength) const;
00357 
00365   inline UBool endsWith(const UnicodeString& text) const;
00366 
00377   inline UBool endsWith(const UnicodeString& srcText,
00378           UTextOffset srcStart,
00379           int32_t srcLength) const;
00380 
00389   inline UBool endsWith(const UChar *srcChars,
00390           int32_t srcLength) const;
00391  
00402   inline UBool endsWith(const UChar *srcChars,
00403           UTextOffset srcStart,
00404           int32_t srcLength) const;
00405 
00406  
00407   /* Searching - bitwise only */
00408 
00417   inline UTextOffset indexOf(const UnicodeString& text) const;
00418 
00428   inline UTextOffset indexOf(const UnicodeString& text,
00429               UTextOffset start) const;
00430 
00442   inline UTextOffset indexOf(const UnicodeString& text,
00443               UTextOffset start,
00444               int32_t length) const;
00445 
00462   inline UTextOffset indexOf(const UnicodeString& srcText,
00463               UTextOffset srcStart,
00464               int32_t srcLength,
00465               UTextOffset start,
00466               int32_t length) const;
00467 
00479   inline UTextOffset indexOf(const UChar *srcChars,
00480               int32_t srcLength,
00481               UTextOffset start) const;
00482 
00495   inline UTextOffset indexOf(const UChar *srcChars,
00496               int32_t srcLength,
00497               UTextOffset start,
00498               int32_t length) const;
00499  
00516   UTextOffset indexOf(const UChar *srcChars,
00517               UTextOffset srcStart,
00518               int32_t srcLength,
00519               UTextOffset start,
00520               int32_t length) const;
00521 
00529   inline UTextOffset indexOf(UChar c) const;
00530 
00538   inline UTextOffset indexOf(UChar32 c) const;
00539 
00548   inline UTextOffset indexOf(UChar c,
00549               UTextOffset start) const;
00550 
00559   inline UTextOffset indexOf(UChar32 c,
00560               UTextOffset start) const;
00561 
00572   inline UTextOffset indexOf(UChar c,
00573               UTextOffset start,
00574               int32_t length) const;
00575 
00586   inline UTextOffset indexOf(UChar32 c,
00587               UTextOffset start,
00588               int32_t length) const;
00589 
00598   inline UTextOffset lastIndexOf(const UnicodeString& text) const;
00599 
00609   inline UTextOffset lastIndexOf(const UnicodeString& text,
00610               UTextOffset start) const;
00611 
00623   inline UTextOffset lastIndexOf(const UnicodeString& text,
00624               UTextOffset start,
00625               int32_t length) const;
00626 
00643   inline UTextOffset lastIndexOf(const UnicodeString& srcText,
00644               UTextOffset srcStart,
00645               int32_t srcLength,
00646               UTextOffset start,
00647               int32_t length) const;
00648 
00659   inline UTextOffset lastIndexOf(const UChar *srcChars,
00660               int32_t srcLength,
00661               UTextOffset start) const;
00662 
00675   inline UTextOffset lastIndexOf(const UChar *srcChars,
00676               int32_t srcLength,
00677               UTextOffset start,
00678               int32_t length) const;
00679  
00696   UTextOffset lastIndexOf(const UChar *srcChars,
00697               UTextOffset srcStart,
00698               int32_t srcLength,
00699               UTextOffset start,
00700               int32_t length) const;
00701 
00709   inline UTextOffset lastIndexOf(UChar c) const;
00710 
00718   inline UTextOffset lastIndexOf(UChar32 c) const;
00719 
00728   inline UTextOffset lastIndexOf(UChar c,
00729               UTextOffset start) const;
00730 
00739   inline UTextOffset lastIndexOf(UChar32 c,
00740               UTextOffset start) const;
00741 
00752   inline UTextOffset lastIndexOf(UChar c,
00753               UTextOffset start,
00754               int32_t length) const;
00755 
00766   inline UTextOffset lastIndexOf(UChar32 c,
00767               UTextOffset start,
00768               int32_t length) const;
00769 
00770 
00771   /* Character access */
00772 
00779   inline UChar charAt(UTextOffset offset) const;
00780 
00787   inline UChar operator [] (UTextOffset offset) const;
00788 
00798   inline UChar32 char32At(UTextOffset offset) const;
00799 
00813   inline UTextOffset getCharStart(UTextOffset offset);
00814 
00829   inline UTextOffset getCharLimit(UTextOffset offset);
00830 
00831   /* Substring extraction */
00832 
00848   inline void extract(UTextOffset start, 
00849            int32_t length, 
00850            UChar *dst, 
00851            UTextOffset dstStart = 0) const;
00852   
00863   inline void extract(UTextOffset start,
00864            int32_t length,
00865            UnicodeString& target) const;
00866 
00878   inline void extractBetween(UTextOffset start, 
00879               UTextOffset limit, 
00880               UChar *dst, 
00881               UTextOffset dstStart = 0) const;
00882 
00892   inline void extractBetween(UTextOffset start,
00893               UTextOffset limit,
00894               UnicodeString& target) const;
00895 
00911   int32_t extract(UTextOffset start,
00912            int32_t length,
00913            char *dst,
00914            const char *codepage = 0) const;
00915   
00916 
00917   /* Length operations */
00918 
00925   inline int32_t  length(void) const;
00926 
00932   inline UBool empty(void) const;
00933 
00934  
00935   /* Other operations */
00936 
00942   inline int32_t hashCode(void) const;
00943 
00949   inline UBool isBogus(void) const;
00950 
00951   
00952   //========================================
00953   // Write operations
00954   //========================================
00955 
00956   /* Assignment operations */
00957 
00965    UnicodeString& operator= (const UnicodeString& srcText);
00966 
00974   inline UnicodeString& operator= (UChar ch);
00975 
00983   inline UnicodeString& operator= (UChar32 ch);
00984 
00998   inline UnicodeString& setTo(const UnicodeString& srcText, 
00999                UTextOffset srcStart, 
01000                int32_t srcLength);
01001 
01010   inline UnicodeString& setTo(const UnicodeString& srcText);
01011 
01020   inline UnicodeString& setTo(const UChar *srcChars,
01021                int32_t srcLength);
01022 
01031   UnicodeString& setTo(UChar srcChar);
01032 
01041   UnicodeString& setTo(UChar32 srcChar);
01042 
01062   UnicodeString &setTo(UBool isTerminated,
01063                        const UChar *text,
01064                        int32_t textLength);
01065 
01084   UnicodeString &setTo(UChar *buffer,
01085                        int32_t buffLength,
01086                        int32_t buffCapacity);
01087 
01095   UnicodeString& setCharAt(UTextOffset offset, 
01096                UChar ch);
01097 
01098 
01099   /* Append operations */
01100 
01108  inline  UnicodeString& operator+= (UChar ch);
01109 
01117  inline  UnicodeString& operator+= (UChar32 ch);
01118 
01127   inline UnicodeString& operator+= (const UnicodeString& srcText);
01128 
01143   inline UnicodeString& append(const UnicodeString& srcText, 
01144             UTextOffset srcStart, 
01145             int32_t srcLength);
01146 
01154   inline UnicodeString& append(const UnicodeString& srcText);
01155 
01169   inline UnicodeString& append(const UChar *srcChars, 
01170             UTextOffset srcStart, 
01171             int32_t srcLength);
01172 
01181   inline UnicodeString& append(const UChar *srcChars,
01182             int32_t srcLength);
01183 
01190   inline UnicodeString& append(UChar srcChar);
01191 
01198   inline UnicodeString& append(UChar32 srcChar);
01199 
01200 
01201   /* Insert operations */
01202 
01216   inline UnicodeString& insert(UTextOffset start, 
01217             const UnicodeString& srcText, 
01218             UTextOffset srcStart, 
01219             int32_t srcLength);
01220 
01229   inline UnicodeString& insert(UTextOffset start, 
01230             const UnicodeString& srcText);
01231 
01245   inline UnicodeString& insert(UTextOffset start, 
01246             const UChar *srcChars, 
01247             UTextOffset srcStart, 
01248             int32_t srcLength);
01249 
01259   inline UnicodeString& insert(UTextOffset start, 
01260             const UChar *srcChars,
01261             int32_t srcLength);
01262 
01271   inline UnicodeString& insert(UTextOffset start, 
01272             UChar srcChar);
01273 
01282   inline UnicodeString& insert(UTextOffset start, 
01283             UChar32 srcChar);
01284 
01285 
01286   /* Replace operations */
01287 
01305   UnicodeString& replace(UTextOffset start, 
01306              int32_t length, 
01307              const UnicodeString& srcText, 
01308              UTextOffset srcStart, 
01309              int32_t srcLength);
01310 
01323   UnicodeString& replace(UTextOffset start, 
01324              int32_t length, 
01325              const UnicodeString& srcText);
01326 
01344   UnicodeString& replace(UTextOffset start, 
01345              int32_t length, 
01346              const UChar *srcChars, 
01347              UTextOffset srcStart, 
01348              int32_t srcLength);
01349 
01362   inline UnicodeString& replace(UTextOffset start, 
01363              int32_t length, 
01364              const UChar *srcChars,
01365              int32_t srcLength);
01366 
01378   inline UnicodeString& replace(UTextOffset start, 
01379              int32_t length, 
01380              UChar srcChar);
01381 
01393   inline UnicodeString& replace(UTextOffset start, 
01394              int32_t length, 
01395              UChar32 srcChar);
01396 
01406   inline UnicodeString& replaceBetween(UTextOffset start, 
01407                 UTextOffset limit, 
01408                 const UnicodeString& srcText);
01409 
01424   inline UnicodeString& replaceBetween(UTextOffset start, 
01425                 UTextOffset limit, 
01426                 const UnicodeString& srcText, 
01427                 UTextOffset srcStart, 
01428                 UTextOffset srcLimit);
01429 
01440   virtual void handleReplaceBetween(UTextOffset start,
01441                                     UTextOffset limit,
01442                                     const UnicodeString& text);
01443 
01458   virtual void copy(int32_t start, int32_t limit, int32_t dest);
01459 
01460   /* Search and replace operations */
01461 
01470   inline UnicodeString& findAndReplace(const UnicodeString& oldText,
01471                 const UnicodeString& newText);
01472 
01484   inline UnicodeString& findAndReplace(UTextOffset start,
01485                 int32_t length,
01486                 const UnicodeString& oldText,
01487                 const UnicodeString& newText);
01488 
01506   UnicodeString& findAndReplace(UTextOffset start,
01507                 int32_t length,
01508                 const UnicodeString& oldText,
01509                 UTextOffset oldStart,
01510                 int32_t oldLength,
01511                 const UnicodeString& newText,
01512                 UTextOffset newStart,
01513                 int32_t newLength);
01514 
01515 
01516   /* Remove operations */
01517 
01523   inline UnicodeString& remove(void);
01524 
01533   inline UnicodeString& remove(UTextOffset start, 
01534                                int32_t length = INT32_MAX);
01535 
01544   inline UnicodeString& removeBetween(UTextOffset start,
01545                                       UTextOffset limit = INT32_MAX);
01546 
01547 
01548   /* Length operations */
01549 
01561   UBool padLeading(int32_t targetLength,
01562                     UChar padChar = 0x0020);
01563 
01575   UBool padTrailing(int32_t targetLength,
01576                      UChar padChar = 0x0020);
01577 
01584   inline UBool truncate(int32_t targetLength);
01585 
01591   UnicodeString& trim(void);
01592 
01593 
01594   /* Miscellaneous operations */
01595 
01601   inline UnicodeString& reverse(void);
01602 
01611   inline UnicodeString& reverse(UTextOffset start,
01612              int32_t length);
01613 
01620   UnicodeString& toUpper(void);
01621 
01629   UnicodeString& toUpper(const Locale& locale);
01630 
01637   UnicodeString& toLower(void);
01638 
01646   UnicodeString& toLower(const Locale& locale);
01647 
01648 
01649   //========================================
01650   // Constructors
01651   //========================================
01652 
01656   UnicodeString();
01657 
01669   UnicodeString(int32_t capacity, UChar32 c, int32_t count);
01670 
01676   UnicodeString(UChar ch);
01677 
01683   UnicodeString(UChar32 ch);
01684 
01691   UnicodeString(const UChar *text);
01692 
01700   UnicodeString(const UChar *text,
01701         int32_t textLength);
01702 
01722   UnicodeString(UBool isTerminated,
01723                 const UChar *text,
01724                 int32_t textLength);
01725 
01744   UnicodeString(UChar *buffer, int32_t buffLength, int32_t buffCapacity);
01745 
01757   UnicodeString(const char *codepageData,
01758         const char *codepage = 0);
01759 
01772   UnicodeString(const char *codepageData,
01773         int32_t dataLength,
01774         const char *codepage = 0);
01775 
01781   UnicodeString(const UnicodeString& that);
01782 
01786   ~UnicodeString();
01787 
01788 
01789   /* Miscellaneous operations */
01790 
01813   int32_t numDisplayCells(UTextOffset start = 0,
01814               int32_t length = INT32_MAX,
01815               UBool asian = TRUE) const;
01816 
01817 
01818   UCharReference operator[] (UTextOffset pos);
01819 
01852   UnicodeString unescape() const;
01853 
01872   UChar32 unescapeAt(int32_t &offset) const;
01873 
01874   //========================================
01875   // Implementation methods
01876   //========================================
01877   
01878 private:
01879 
01880   inline int8_t
01881   doCompare(UTextOffset start,
01882            int32_t length,
01883            const UnicodeString& srcText,
01884            UTextOffset srcStart,
01885            int32_t srcLength) const;
01886   
01887   int8_t doCompare(UTextOffset start,
01888            int32_t length,
01889            const UChar *srcChars,
01890            UTextOffset srcStart,
01891            int32_t srcLength) const;
01892 
01893   UTextOffset doIndexOf(UChar c,
01894             UTextOffset start,
01895             int32_t length) const;
01896 
01897   UTextOffset doLastIndexOf(UChar c,
01898                 UTextOffset start,
01899                 int32_t length) const;
01900 
01901   void doExtract(UTextOffset start, 
01902          int32_t length, 
01903          UChar *dst, 
01904          UTextOffset dstStart) const;
01905   
01906   inline void doExtract(UTextOffset start,
01907          int32_t length,
01908          UnicodeString& target) const;
01909   
01910   inline UChar doCharAt(UTextOffset offset)  const;
01911 
01912   UnicodeString& doReplace(UTextOffset start, 
01913                int32_t length, 
01914                const UnicodeString& srcText, 
01915                UTextOffset srcStart, 
01916                int32_t srcLength);
01917 
01918   UnicodeString& doReplace(UTextOffset start, 
01919                int32_t length, 
01920                const UChar *srcChars, 
01921                UTextOffset srcStart, 
01922                int32_t srcLength);
01923 
01924   UnicodeString& doReverse(UTextOffset start,
01925                int32_t length);
01926 
01927   // calculate hash code
01928   int32_t doHashCode(void) const;
01929   
01930   // get pointer to start of array
01931   inline UChar* getArrayStart(void);
01932   inline const UChar* getArrayStart(void) const;
01933 
01934   // get the "real" capacity of the array, adjusted for ref count
01935   inline int32_t getCapacity(void) const;
01936 
01937   // allocate the array; result may be fStackBuffer
01938   // sets refCount to 1 if appropriate
01939   // sets fArray, fCapacity, and fFlags
01940   // returns boolean for success or failure
01941   UBool allocate(int32_t capacity);
01942 
01943   // release the array if owned
01944   inline void releaseArray();
01945 
01946   // utility method to get around lack of exception handling
01947   void setToBogus(void);
01948 
01949   // Pin start and limit to acceptable values.
01950   inline void pinIndices(UTextOffset& start,
01951                          int32_t& length) const;
01952 
01953   /*
01954    * Real constructor for converting from codepage data.
01955    * It assumes that it is called with !fRefCounted.
01956    *
01957    * If <code>codepage==0</code>, then the default converter
01958    * is used for the platform encoding.
01959    * If <code>codepage</code> is an empty string (<code>""</code>),
01960    * then a simple conversion is performed on the codepage-invariant
01961    * subset ("invariant characters") of the platform encoding. See utypes.h.
01962    */
01963   void doCodepageCreate(const char *codepageData,
01964                         int32_t dataLength,
01965                         const char *codepage);
01966 
01967   /*
01968    * This function is called when write access to the array
01969    * is necessary.
01970    *
01971    * We need to make a copy of the array if
01972    * the buffer is read-only, or
01973    * the buffer is refCounted (shared), and refCount>1, or
01974    * the buffer is too small.
01975    *
01976    * Return FALSE if memory could not be allocated.
01977    */
01978   UBool cloneArrayIfNeeded(int32_t newCapacity = -1,
01979                             int32_t growCapacity = -1,
01980                             UBool doCopyArray = TRUE,
01981                             int32_t **pBufferToDelete = 0);
01982 
01983   // ref counting
01984   inline int32_t addRef(void);
01985   inline int32_t removeRef(void);
01986   inline int32_t refCount(void) const;
01987   inline int32_t setRefCount(int32_t count);
01988 
01989   // constants
01990   enum {
01991 #if UTF_SIZE==8
01992     US_STACKBUF_SIZE=14, // Size of stack buffer for small strings
01993 #elif UTF_SIZE==16
01994     US_STACKBUF_SIZE=7, // Size of stack buffer for small strings
01995 #else // UTF_SIZE==32
01996     US_STACKBUF_SIZE=3, // Size of stack buffer for small strings
01997 #endif
01998     kInvalidUChar=0xffff, // invalid UChar index
01999     kGrowSize=128, // grow size for this buffer
02000     kInvalidHashCode=0, // invalid hash code
02001     kEmptyHashCode=1, // hash code for empty string
02002 
02003     // bit flag values for fFlags
02004     kIsBogus=1, // this string is bogus, i.e., not valid
02005     kUsingStackBuffer=2, // fArray==fStackBuffer
02006     kRefCounted=4, // there is a refCount field before the characters in fArray
02007     kBufferIsReadonly=8, // do not write to this buffer
02008 
02009     // combined values for convenience
02010     kShortString=kUsingStackBuffer,
02011     kLongString=kRefCounted,
02012     kReadonlyAlias=kBufferIsReadonly,
02013     kWriteableAlias=0
02014   };
02015 
02016   // statics
02017 
02018   // default converter cache
02019   static UConverter* getDefaultConverter(UErrorCode& status);
02020   static void releaseDefaultConverter(UConverter *converter);
02021 
02022   static UConverter *fgDefaultConverter;
02023 
02024   friend class UnicodeStringStreamer;
02025   friend class UnicodeConverter;
02026 
02027 #if U_IOSTREAM_SOURCE >= 199711
02028   friend U_COMMON_API std::ostream &operator<<(std::ostream& stream, const UnicodeString& s);
02029 #elif U_IOSTREAM_SOURCE >= 198506
02030   friend U_COMMON_API ostream &operator<<(ostream& stream, const UnicodeString& s);
02031 #endif
02032 
02033   friend class StringCharacterIterator;
02034 
02035   /*
02036    * The following are all the class fields that are stored
02037    * in each UnicodeString object.
02038    * Note that UnicodeString has virtual functions,
02039    * therefore there is an implicit vtable pointer
02040    * as the first real field.
02041    * The fields should be aligned such that no padding is
02042    * necessary, mostly by having larger types first.
02043    * On 32-bit machines, the size should be 32 bytes,
02044    * on 64-bit machines (8-byte pointers), it should be 40 bytes.
02045    */
02046   // (implicit) *vtable;
02047   UChar     *fArray;        // the Unicode data
02048   int32_t   fLength;        // number characters in fArray
02049   int32_t   fCapacity;      // sizeof fArray
02050   uint16_t  fFlags;         // bit flags: see constants above
02051 #if UTF_SIZE==32
02052   uint16_t  fPadding;       // padding to align the fStackBuffer for UTF-32
02053 #endif
02054   UChar     fStackBuffer [ US_STACKBUF_SIZE ]; // buffer for small strings
02055 
02056 public:
02057 
02058   //========================================
02059   // Deprecated API
02060   //========================================
02061 
02062   /* size() -> length()
02063    * @deprecated */
02064   inline int32_t size(void) const;
02065 
02066   // parameters reordered for consistency
02067    /* @deprecated */
02068   inline UnicodeString& findAndReplace(const UnicodeString& oldText,
02069                 const UnicodeString& newText,
02070                 UTextOffset start,
02071                 int32_t length);
02072 
02073    /* @deprecated */
02074   inline void* operator new(size_t size);
02075    /* @deprecated */
02076   inline void* operator new(size_t size, void *location);
02077    /* @deprecated */
02078   inline void operator delete(void *location);
02079 
02080   //========================================
02081   // Non-public API - will be removed!
02082   //========================================
02083   /* @deprecated */
02084   const UChar* getUChars() const;
02085 };
02086 
02087 //========================================
02088 // Array copying
02089 //========================================
02090 // Copy an array of UnicodeString OBJECTS (not pointers).
02091 inline void 
02092 uprv_arrayCopy(const UnicodeString *src, UnicodeString *dst, int32_t count)
02093 { while(count-- > 0) *dst++ = *src++; }
02094 
02095 inline void 
02096 uprv_arrayCopy(const UnicodeString *src, int32_t srcStart, 
02097         UnicodeString *dst, int32_t dstStart, int32_t count)
02098 { uprv_arrayCopy(src+srcStart, dst+dstStart, count); }
02099 
02100 
02101 //========================================
02102 // Inline members
02103 //========================================
02104 
02105 //========================================
02106 // Read-only alias methods
02107 //========================================
02108 inline UBool
02109 UnicodeString::operator== (const UnicodeString& text) const
02110 {
02111   if(isBogus()) {
02112     return text.isBogus();
02113   } else {
02114     return
02115       !text.isBogus() &&
02116       fLength == text.fLength &&
02117       doCompare(0, fLength, text, 0, text.fLength) == 0;
02118   }
02119 }
02120 
02121 inline UBool
02122 UnicodeString::operator!= (const UnicodeString& text) const
02123 { return (! operator==(text)); }
02124 
02125 inline UBool
02126 UnicodeString::operator> (const UnicodeString& text) const
02127 { return doCompare(0, fLength, text, 0, text.fLength) == 1; }
02128 
02129 inline UBool
02130 UnicodeString::operator< (const UnicodeString& text) const
02131 { return doCompare(0, fLength, text, 0, text.fLength) == -1; }
02132 
02133 inline UBool
02134 UnicodeString::operator>= (const UnicodeString& text) const
02135 { return doCompare(0, fLength, text, 0, text.fLength) != -1; }
02136 
02137 inline UBool
02138 UnicodeString::operator<= (const UnicodeString& text) const
02139 { return doCompare(0, fLength, text, 0, text.fLength) != 1; }
02140 
02141 inline int8_t 
02142 UnicodeString::compare(const UnicodeString& text) const
02143 { return doCompare(0, fLength, text, 0, text.fLength); }
02144 
02145 inline int8_t 
02146 UnicodeString::compare(UTextOffset start,
02147                int32_t length,
02148                const UnicodeString& srcText) const
02149 { return doCompare(start, length, srcText, 0, srcText.fLength); }
02150 
02151 inline int8_t 
02152 UnicodeString::compare(const UChar *srcChars,
02153                int32_t srcLength) const
02154 { return doCompare(0, fLength, srcChars, 0, srcLength); }
02155 
02156 inline int8_t 
02157 UnicodeString::compare(UTextOffset start,
02158                int32_t length,
02159                const UnicodeString& srcText,
02160                UTextOffset srcStart,
02161                int32_t srcLength) const
02162 { return doCompare(start, length, srcText, srcStart, srcLength); }
02163 
02164 inline int8_t
02165 UnicodeString::compare(UTextOffset start,
02166                int32_t length,
02167                const UChar *srcChars) const
02168 { return doCompare(start, length, srcChars, 0, length); }
02169 
02170 inline int8_t 
02171 UnicodeString::compare(UTextOffset start,
02172                int32_t length,
02173                const UChar *srcChars,
02174                UTextOffset srcStart,
02175                int32_t srcLength) const
02176 { return doCompare(start, length, srcChars, srcStart, srcLength); }
02177 
02178 inline int8_t
02179 UnicodeString::compareBetween(UTextOffset start,
02180                   UTextOffset limit,
02181                   const UnicodeString& srcText,
02182                   UTextOffset srcStart,
02183                   UTextOffset srcLimit) const
02184 { return doCompare(start, limit - start, 
02185            srcText, srcStart, srcLimit - srcStart); }
02186 
02187 inline int8_t
02188 UnicodeString::doCompare(UTextOffset start,
02189               int32_t length,
02190               const UnicodeString& srcText,
02191               UTextOffset srcStart,
02192               int32_t srcLength) const
02193 {
02194   const UChar *srcChars;
02195   if(!srcText.isBogus()) {
02196     srcText.pinIndices(srcStart, srcLength);
02197     srcChars=srcText.getArrayStart();
02198   } else {
02199     srcChars=0;
02200   }
02201   return doCompare(start, length, srcChars, srcStart, srcLength);
02202 }
02203 
02204 inline UTextOffset 
02205 UnicodeString::indexOf(const UnicodeString& text) const
02206 { return indexOf(text, 0, text.fLength, 0, fLength); }
02207 
02208 inline UTextOffset 
02209 UnicodeString::indexOf(const UnicodeString& text,
02210                UTextOffset start) const
02211 { return indexOf(text, 0, text.fLength, start, fLength - start); }
02212 
02213 inline UTextOffset 
02214 UnicodeString::indexOf(const UnicodeString& text,
02215                UTextOffset start,
02216                int32_t length) const
02217 { return indexOf(text, 0, text.fLength, start, length); }
02218 
02219 inline UTextOffset 
02220 UnicodeString::indexOf(const UnicodeString& srcText,
02221                UTextOffset srcStart,
02222                int32_t srcLength,
02223                UTextOffset start,
02224                int32_t length) const
02225 {
02226   if(!srcText.isBogus()) {
02227     srcText.pinIndices(srcStart, srcLength);
02228     if(srcLength > 0) {
02229       return indexOf(srcText.getArrayStart(), srcStart, srcLength, start, length);
02230     }
02231   }
02232   return -1;
02233 }
02234 
02235 inline UTextOffset 
02236 UnicodeString::indexOf(const UChar *srcChars,
02237                int32_t srcLength,
02238                UTextOffset start) const
02239 { return indexOf(srcChars, 0, srcLength, start, fLength - start); }
02240 
02241 inline UTextOffset 
02242 UnicodeString::indexOf(const UChar *srcChars,
02243                int32_t srcLength,
02244                UTextOffset start,
02245                int32_t length) const
02246 { return indexOf(srcChars, 0, srcLength, start, length); }
02247 
02248 inline UTextOffset 
02249 UnicodeString::indexOf(UChar c) const
02250 { return doIndexOf(c, 0, fLength); }
02251 
02252 inline UTextOffset 
02253 UnicodeString::indexOf(UChar32 c) const {
02254   if(!UTF_NEED_MULTIPLE_UCHAR(c)) {
02255     return doIndexOf((UChar)c, 0, fLength);
02256   } else {
02257     UChar buffer[UTF_MAX_CHAR_LENGTH];
02258     int32_t length = 0;
02259     UTF_APPEND_CHAR_UNSAFE(buffer, length, c);
02260     return indexOf(buffer, length, 0);
02261   }
02262 }
02263 
02264 inline UTextOffset 
02265 UnicodeString::indexOf(UChar c,
02266                UTextOffset start) const
02267 { return doIndexOf(c, start, fLength - start); }
02268 
02269 inline UTextOffset 
02270 UnicodeString::indexOf(UChar32 c,
02271                UTextOffset start) const {
02272   if(!UTF_NEED_MULTIPLE_UCHAR(c)) {
02273     return doIndexOf((UChar)c, start, fLength - start);
02274   } else {
02275     UChar buffer[UTF_MAX_CHAR_LENGTH];
02276     int32_t length = 0;
02277     UTF_APPEND_CHAR_UNSAFE(buffer, length, c);
02278     return indexOf(buffer, length, start);
02279   }
02280 }
02281 
02282 inline UTextOffset 
02283 UnicodeString::indexOf(UChar c,
02284                UTextOffset start,
02285                int32_t length) const
02286 { return doIndexOf(c, start, length); }
02287 
02288 inline UTextOffset 
02289 UnicodeString::indexOf(UChar32 c,
02290                UTextOffset start,
02291                int32_t length) const {
02292   if(!UTF_NEED_MULTIPLE_UCHAR(c)) {
02293     return doIndexOf((UChar)c, start, length);
02294   } else {
02295     UChar buffer[UTF_MAX_CHAR_LENGTH];
02296     int32_t cLength = 0;
02297     UTF_APPEND_CHAR_UNSAFE(buffer, cLength, c);
02298     return indexOf(buffer, cLength, start, length);
02299   }
02300 }
02301 
02302 inline UTextOffset 
02303 UnicodeString::lastIndexOf(const UnicodeString& text) const
02304 { return lastIndexOf(text, 0, text.fLength, 0, fLength); }
02305 
02306 inline UTextOffset 
02307 UnicodeString::lastIndexOf(const UnicodeString& text,
02308                UTextOffset start) const
02309 { return lastIndexOf(text, 0, text.fLength, start, fLength - start); }
02310 
02311 inline UTextOffset 
02312 UnicodeString::lastIndexOf(const UnicodeString& text,
02313                UTextOffset start,
02314                int32_t length) const
02315 { return lastIndexOf(text, 0, text.fLength, start, length); }
02316 
02317 inline UTextOffset 
02318 UnicodeString::lastIndexOf(const UnicodeString& srcText,
02319                UTextOffset srcStart,
02320                int32_t srcLength,
02321                UTextOffset start,
02322                int32_t length) const
02323 {
02324   if(!srcText.isBogus()) {
02325     srcText.pinIndices(srcStart, srcLength);
02326     if(srcLength > 0) {
02327       return lastIndexOf(srcText.getArrayStart(), srcStart, srcLength, start, length);
02328     }
02329   }
02330   return -1;
02331 }
02332 
02333 inline UTextOffset 
02334 UnicodeString::lastIndexOf(const UChar *srcChars,
02335                int32_t srcLength,
02336                UTextOffset start) const
02337 { return lastIndexOf(srcChars, 0, srcLength, start, fLength - start); }
02338 
02339 inline UTextOffset 
02340 UnicodeString::lastIndexOf(const UChar *srcChars,
02341                int32_t srcLength,
02342                UTextOffset start,
02343                int32_t length) const
02344 { return lastIndexOf(srcChars, 0, srcLength, start, length); }
02345 
02346 inline UTextOffset 
02347 UnicodeString::lastIndexOf(UChar c) const
02348 { return doLastIndexOf(c, 0, fLength); }
02349 
02350 inline UTextOffset 
02351 UnicodeString::lastIndexOf(UChar32 c) const {
02352   if(!UTF_NEED_MULTIPLE_UCHAR(c)) {
02353     return doLastIndexOf((UChar)c, 0, fLength);
02354   } else {
02355     UChar buffer[UTF_MAX_CHAR_LENGTH];
02356     int32_t count = 0;
02357     UTF_APPEND_CHAR_UNSAFE(buffer, count, c);
02358     return lastIndexOf(buffer, count, 0);
02359   }
02360 }
02361 
02362 inline UTextOffset 
02363 UnicodeString::lastIndexOf(UChar c,
02364                UTextOffset start) const
02365 { return doLastIndexOf(c, start, fLength - start); }
02366 
02367 inline UTextOffset 
02368 UnicodeString::lastIndexOf(UChar32 c,
02369                UTextOffset start) const {
02370   if(!UTF_NEED_MULTIPLE_UCHAR(c)) {
02371     return doLastIndexOf((UChar)c, start, fLength - start);
02372   } else {
02373     UChar buffer[UTF_MAX_CHAR_LENGTH];
02374     int32_t count = 0;
02375     UTF_APPEND_CHAR_UNSAFE(buffer, count, c);
02376     return lastIndexOf(buffer, count, start);
02377   }
02378 }
02379 
02380 inline UTextOffset 
02381 UnicodeString::lastIndexOf(UChar c,
02382                UTextOffset start,
02383                int32_t length) const
02384 { return doLastIndexOf(c, start, length); }
02385 
02386 inline UTextOffset 
02387 UnicodeString::lastIndexOf(UChar32 c,
02388                UTextOffset start,
02389                int32_t length) const {
02390   if(!UTF_NEED_MULTIPLE_UCHAR(c)) {
02391     return doLastIndexOf((UChar)c, start, length);
02392   } else {
02393     UChar buffer[UTF_MAX_CHAR_LENGTH];
02394     int32_t count = 0;
02395     UTF_APPEND_CHAR_UNSAFE(buffer, count, c);
02396     return lastIndexOf(buffer, count, start, length);
02397   }
02398 }
02399 
02400 inline UBool 
02401 UnicodeString::startsWith(const UnicodeString& text) const
02402 { return compare(0, text.fLength, text, 0, text.fLength) == 0; }
02403 
02404 inline UBool 
02405 UnicodeString::startsWith(const UnicodeString& srcText,
02406               UTextOffset srcStart,
02407               int32_t srcLength) const
02408 { return doCompare(0, srcLength, srcText, srcStart, srcLength) == 0; }
02409 
02410 inline UBool 
02411 UnicodeString::startsWith(const UChar *srcChars,
02412               int32_t srcLength) const
02413 { return doCompare(0, srcLength, srcChars, 0, srcLength) == 0; }
02414 
02415 inline UBool 
02416 UnicodeString::startsWith(const UChar *srcChars,
02417               UTextOffset srcStart,
02418               int32_t srcLength) const
02419 { return doCompare(0, srcLength, srcChars, srcStart, srcLength) == 0;}
02420 
02421 inline UBool 
02422 UnicodeString::endsWith(const UnicodeString& text) const
02423 { return doCompare(fLength - text.fLength, text.fLength, 
02424            text, 0, text.fLength) == 0; }
02425 
02426 inline UBool 
02427 UnicodeString::endsWith(const UnicodeString& srcText,
02428             UTextOffset srcStart,
02429             int32_t srcLength) const
02430 { return doCompare(fLength - srcLength, srcLength, 
02431            srcText, srcStart, srcLength) == 0; }
02432 
02433 inline UBool 
02434 UnicodeString::endsWith(const UChar *srcChars,
02435             int32_t srcLength) const
02436 { return doCompare(fLength - srcLength, srcLength, 
02437            srcChars, 0, srcLength) == 0; }
02438 
02439 inline UBool 
02440 UnicodeString::endsWith(const UChar *srcChars,
02441             UTextOffset srcStart,
02442             int32_t srcLength) const
02443 { return doCompare(fLength - srcLength, srcLength, 
02444            srcChars, srcStart, srcLength) == 0;}
02445 //========================================
02446 // replace
02447 //========================================
02448 inline UnicodeString& 
02449 UnicodeString::replace(UTextOffset start, 
02450                int32_t length, 
02451                const UnicodeString& srcText) 
02452 { return doReplace(start, length, srcText, 0, srcText.fLength); }
02453 
02454 inline UnicodeString& 
02455 UnicodeString::replace(UTextOffset start, 
02456                int32_t length, 
02457                const UnicodeString& srcText, 
02458                UTextOffset srcStart, 
02459                int32_t srcLength)
02460 { return doReplace(start, length, srcText, srcStart, srcLength); }
02461 
02462 inline UnicodeString& 
02463 UnicodeString::replace(UTextOffset start, 
02464                int32_t length, 
02465                const UChar *srcChars,
02466                int32_t srcLength)
02467 { return doReplace(start, length, srcChars, 0, srcLength); }
02468 
02469 inline UnicodeString& 
02470 UnicodeString::replace(UTextOffset start, 
02471                int32_t length, 
02472                const UChar *srcChars, 
02473                UTextOffset srcStart, 
02474                int32_t srcLength)
02475 { return doReplace(start, length, srcChars, srcStart, srcLength); }
02476 
02477 inline UnicodeString& 
02478 UnicodeString::replace(UTextOffset start, 
02479                int32_t length, 
02480                UChar srcChar)
02481 { return doReplace(start, length, &srcChar, 0, 1); }
02482 
02483 inline UnicodeString&
02484 UnicodeString::replace(UTextOffset start, 
02485                int32_t length, 
02486                UChar32 srcChar) {
02487   UChar buffer[UTF_MAX_CHAR_LENGTH];
02488   int32_t count = 0;
02489   UTF_APPEND_CHAR_UNSAFE(buffer, count, srcChar);
02490   return doReplace(start, length, buffer, 0, count);
02491 }
02492 
02493 inline UnicodeString& 
02494 UnicodeString::replaceBetween(UTextOffset start, 
02495                   UTextOffset limit, 
02496                   const UnicodeString& srcText)
02497 { return doReplace(start, limit - start, srcText, 0, srcText.fLength); }
02498 
02499 inline UnicodeString&
02500 UnicodeString::replaceBetween(UTextOffset start, 
02501                   UTextOffset limit, 
02502                   const UnicodeString& srcText, 
02503                   UTextOffset srcStart, 
02504                   UTextOffset srcLimit)
02505 { return doReplace(start, limit - start, srcText, srcStart, srcLimit - srcStart); }
02506 
02507 inline UnicodeString& 
02508 UnicodeString::findAndReplace(const UnicodeString& oldText,
02509                   const UnicodeString& newText)
02510 { return findAndReplace(0, fLength, oldText, 0, oldText.fLength, 
02511             newText, 0, newText.fLength); }
02512 
02513 inline UnicodeString& 
02514 UnicodeString::findAndReplace(UTextOffset start,
02515                   int32_t length,
02516                   const UnicodeString& oldText,
02517                   const UnicodeString& newText)
02518 { return findAndReplace(start, length, oldText, 0, oldText.fLength, 
02519             newText, 0, newText.fLength); }
02520 
02521 // ============================
02522 // extract
02523 // ============================
02524 inline void
02525 UnicodeString::doExtract(UTextOffset start,
02526              int32_t length,
02527              UnicodeString& target) const
02528 { target.replace(0, target.fLength, *this, start, length); }
02529 
02530 inline void  
02531 UnicodeString::extract(UTextOffset start, 
02532                int32_t length, 
02533                UChar *dst, 
02534                UTextOffset dstStart) const
02535 { doExtract(start, length, dst, dstStart); }
02536 
02537 inline void 
02538 UnicodeString::extract(UTextOffset start,
02539                int32_t length,
02540                UnicodeString& target) const
02541 { doExtract(start, length, target); }
02542 
02543 inline void  
02544 UnicodeString::extractBetween(UTextOffset start, 
02545                   UTextOffset limit, 
02546                   UChar *dst, 
02547                   UTextOffset dstStart) const
02548 { doExtract(start, limit - start, dst, dstStart); }
02549 
02550 inline void 
02551 UnicodeString::extractBetween(UTextOffset start,
02552                   UTextOffset limit,
02553                   UnicodeString& target) const
02554 { doExtract(start, limit - start, target); }
02555 
02556 inline UChar
02557 UnicodeString::doCharAt(UTextOffset offset) const
02558 {
02559   if((uint32_t)offset < (uint32_t)fLength) {
02560     return fArray[offset];
02561   } else {
02562     return kInvalidUChar;
02563   }
02564 }
02565 
02566 inline UChar
02567 UnicodeString::charAt(UTextOffset offset) const
02568 { return doCharAt(offset); }
02569 
02570 inline UChar
02571 UnicodeString::operator[] (UTextOffset offset) const
02572 { return doCharAt(offset); }
02573 
02574 inline UChar32
02575 UnicodeString::char32At(UTextOffset offset) const
02576 {
02577   if((uint32_t)offset < (uint32_t)fLength) {
02578     UChar32 c;
02579     UTF_GET_CHAR(fArray, 0, offset, fLength, c);
02580     return c;
02581   } else {
02582     return kInvalidUChar;
02583   }
02584 }
02585 
02586 inline UTextOffset
02587 UnicodeString::getCharStart(UTextOffset offset) {
02588   if((uint32_t)offset < (uint32_t)fLength) {
02589     UTF_SET_CHAR_START(fArray, 0, offset);
02590     return offset;
02591   } else {
02592     return 0;
02593   }
02594 }
02595 
02596 inline UTextOffset
02597 UnicodeString::getCharLimit(UTextOffset offset) {
02598   if((uint32_t)offset < (uint32_t)fLength) {
02599     UTF_SET_CHAR_LIMIT(fArray, 0, offset, fLength);
02600     return offset;
02601   } else {
02602     return fLength;
02603   }
02604 }
02605 
02606 inline UBool
02607 UnicodeString::empty() const
02608 { return fLength == 0; }
02609 
02610 //========================================
02611 // Read-only implementation methods
02612 //========================================
02613 inline int32_t  
02614 UnicodeString::length() const
02615 { return fLength; }
02616 
02617 inline int32_t 
02618 UnicodeString::hashCode() const
02619 { return doHashCode(); }
02620 
02621 //========================================
02622 // Write alias methods
02623 //========================================
02624 inline UnicodeString& 
02625 UnicodeString::operator= (UChar ch) 
02626 { return doReplace(0, fLength, &ch, 0, 1); }
02627 
02628 inline UnicodeString& 
02629 UnicodeString::operator= (UChar32 ch) 
02630 { return replace(0, fLength, ch); }
02631 
02632 inline UnicodeString& 
02633 UnicodeString::setTo(const UnicodeString& srcText, 
02634              UTextOffset srcStart, 
02635              int32_t srcLength)
02636 { return doReplace(0, fLength, srcText, srcStart, srcLength); }
02637 
02638 inline UnicodeString& 
02639 UnicodeString::setTo(const UnicodeString& srcText)
02640 { return doReplace(0, fLength, srcText, 0, srcText.fLength); }
02641 
02642 inline UnicodeString& 
02643 UnicodeString::setTo(const UChar *srcChars,
02644              int32_t srcLength)
02645 { return doReplace(0, fLength, srcChars, 0, srcLength); }
02646 
02647 inline UnicodeString& 
02648 UnicodeString::setTo(UChar srcChar)
02649 { return doReplace(0, fLength, &srcChar, 0, 1); }
02650 
02651 inline UnicodeString& 
02652 UnicodeString::setTo(UChar32 srcChar)
02653 { return replace(0, fLength, srcChar); }
02654 
02655 inline UnicodeString& 
02656 UnicodeString::operator+= (UChar ch)
02657 { return doReplace(fLength, 0, &ch, 0, 1); }
02658 
02659 inline UnicodeString& 
02660 UnicodeString::operator+= (UChar32 ch) {
02661   UChar buffer[UTF_MAX_CHAR_LENGTH];
02662   int32_t length = 0;
02663   UTF_APPEND_CHAR_UNSAFE(buffer, length, ch);
02664   return doReplace(fLength, 0, buffer, 0, length);
02665 }
02666 
02667 inline UnicodeString& 
02668 UnicodeString::operator+= (const UnicodeString& srcText)
02669 { return doReplace(fLength, 0, srcText, 0, srcText.fLength); }
02670 
02671 inline UnicodeString& 
02672 UnicodeString::append(const UnicodeString& srcText, 
02673               UTextOffset srcStart, 
02674               int32_t srcLength)
02675 { return doReplace(fLength, 0, srcText, srcStart, srcLength); }
02676 
02677 inline UnicodeString& 
02678 UnicodeString::append(const UnicodeString& srcText)
02679 { return doReplace(fLength, 0, srcText, 0, srcText.fLength); }
02680 
02681 inline UnicodeString& 
02682 UnicodeString::append(const UChar *srcChars, 
02683               UTextOffset srcStart, 
02684               int32_t srcLength)
02685 { return doReplace(fLength, 0, srcChars, srcStart, srcLength); }
02686 
02687 inline UnicodeString& 
02688 UnicodeString::append(const UChar *srcChars,
02689               int32_t srcLength)
02690 { return doReplace(fLength, 0, srcChars, 0, srcLength); }
02691 
02692 inline UnicodeString& 
02693 UnicodeString::append(UChar srcChar)
02694 { return doReplace(fLength, 0, &srcChar, 0, 1); }
02695 
02696 inline UnicodeString& 
02697 UnicodeString::append(UChar32 srcChar) {
02698   UChar buffer[UTF_MAX_CHAR_LENGTH];
02699   int32_t length = 0;
02700   UTF_APPEND_CHAR_UNSAFE(buffer, length, srcChar);
02701   return doReplace(fLength, 0, buffer, 0, length);
02702 }
02703 
02704 inline UnicodeString& 
02705 UnicodeString::insert(UTextOffset start, 
02706               const UnicodeString& srcText, 
02707               UTextOffset srcStart, 
02708               int32_t srcLength)
02709 { return doReplace(start, 0, srcText, srcStart, srcLength); }
02710 
02711 inline UnicodeString& 
02712 UnicodeString::insert(UTextOffset start, 
02713               const UnicodeString& srcText)
02714 { return doReplace(start, 0, srcText, 0, srcText.fLength); }
02715 
02716 inline UnicodeString& 
02717 UnicodeString::insert(UTextOffset start, 
02718               const UChar *srcChars, 
02719               UTextOffset srcStart, 
02720               int32_t srcLength)
02721 { return doReplace(start, 0, srcChars, srcStart, srcLength); }
02722 
02723 inline UnicodeString& 
02724 UnicodeString::insert(UTextOffset start, 
02725               const UChar *srcChars,
02726               int32_t srcLength)
02727 { return doReplace(start, 0, srcChars, 0, srcLength); }
02728 
02729 inline UnicodeString& 
02730 UnicodeString::insert(UTextOffset start, 
02731               UChar srcChar)
02732 { return doReplace(start, 0, &srcChar, 0, 1); }
02733 
02734 inline UnicodeString& 
02735 UnicodeString::insert(UTextOffset start, 
02736               UChar32 srcChar)
02737 { return replace(start, 0, srcChar); }
02738 
02739 
02740 inline UnicodeString& 
02741 UnicodeString::remove(UTextOffset start, 
02742              int32_t length)
02743 { return doReplace(start, length, 0, 0, 0); }
02744 
02745 inline UnicodeString& 
02746 UnicodeString::remove()
02747 { return doReplace(0, fLength, 0, 0, 0); }
02748 
02749 inline UnicodeString& 
02750 UnicodeString::removeBetween(UTextOffset start,
02751                 UTextOffset limit)
02752 { return doReplace(start, limit - start, 0, 0, 0); }
02753 
02754 inline UBool 
02755 UnicodeString::truncate(int32_t targetLength)
02756 {
02757   if((uint32_t)targetLength < (uint32_t)fLength) {
02758     fLength = targetLength;
02759     return TRUE;
02760   } else {
02761     return FALSE;
02762   }
02763 }
02764 
02765 inline UnicodeString& 
02766 UnicodeString::reverse()
02767 { return doReverse(0, fLength); }
02768 
02769 inline UnicodeString& 
02770 UnicodeString::reverse(UTextOffset start,
02771                int32_t length)
02772 { return doReverse(start, length); }
02773 
02774 
02775 //========================================
02776 // Write implementation methods
02777 //========================================
02778 inline UBool 
02779 UnicodeString::isBogus() const
02780 { return (UBool)(fFlags & kIsBogus); }
02781 
02782 
02783 //========================================
02784 // Privates
02785 //========================================
02786 
02787 inline void
02788 UnicodeString::pinIndices(UTextOffset& start,
02789                           int32_t& length) const
02790 {
02791   // pin indices
02792   if(start < 0) {
02793     start = 0;
02794   } else if(start > fLength) {
02795     start = fLength;
02796   }
02797   if(length < 0) {
02798     length = 0;
02799   } else if(length > (fLength - start)) {
02800     length = (fLength - start);
02801   }
02802 }
02803 
02804 inline UChar* 
02805 UnicodeString::getArrayStart()
02806 { return fArray; }
02807 
02808 inline const UChar* 
02809 UnicodeString::getArrayStart() const
02810 { return fArray; }
02811 
02812 inline int32_t 
02813 UnicodeString::getCapacity() const
02814 { return fCapacity; }
02815 
02816 inline void
02817 UnicodeString::releaseArray() {
02818   if((fFlags & kRefCounted) && removeRef() == 0) {
02819     delete [] ((int32_t *)fArray - 1);
02820   }
02821 }
02822 
02823 inline int32_t
02824 UnicodeString::addRef()
02825 { return ++*((int32_t *)fArray - 1); }
02826 
02827 inline int32_t
02828 UnicodeString::removeRef()
02829 { return --*((int32_t *)fArray - 1); }
02830 
02831 inline int32_t
02832 UnicodeString::refCount() const
02833 { return *((int32_t *)fArray - 1); }
02834 
02835 inline int32_t
02836 UnicodeString::setRefCount(int32_t count)
02837 { return (*((int32_t *)fArray - 1) = count); }
02838 
02839 
02840 // deprecated API - remove later
02841 inline int32_t
02842 UnicodeString::size() const
02843 { return fLength; }
02844 
02845 inline UnicodeString& 
02846 UnicodeString::findAndReplace(const UnicodeString& oldText,
02847                   const UnicodeString& newText,
02848                   UTextOffset start,
02849                   int32_t length)
02850 { return findAndReplace(start, length, oldText, newText); }
02851 
02852 inline void*
02853 UnicodeString::operator new(size_t size)
02854 { return ::operator new(size); }
02855 
02856 inline void* 
02857 UnicodeString::operator new(size_t, 
02858               void *location)
02859 { return location; }
02860 
02861 inline void
02862 UnicodeString::operator delete(void *location)
02863 { ::operator delete(location); }
02864 
02865 
02866 //========================================
02867 // Static members
02868 //========================================
02869 
02870 //========================================
02871 // class UCharReference
02872 //========================================
02873 class UCharReference
02874 {
02875 public:
02876   UCharReference();
02877   inline UCharReference(UnicodeString *string,
02878          UTextOffset pos);
02879   inline UCharReference(const UCharReference& that);
02880   ~UCharReference();
02881 
02882   inline UCharReference& operator= (const UCharReference& that);
02883   inline UCharReference& operator= (UChar c);
02884 
02885   inline operator UChar();
02886 
02887 private:
02888   UnicodeString *fString;
02889   UTextOffset fPos;
02890 };
02891 
02892 
02893 //========================================
02894 // Inline members
02895 //========================================
02896 inline
02897 UCharReference::UCharReference(UnicodeString *string, 
02898                    UTextOffset pos)
02899   : fString(string), fPos(pos)
02900 {}
02901 
02902 inline
02903 UCharReference::UCharReference(const UCharReference& that)
02904 { this->operator=(that); }
02905 
02906 inline
02907 UCharReference::~UCharReference()
02908 {}
02909 
02910 inline UCharReference&
02911 UCharReference::operator= (const UCharReference& that)
02912 { fString->setCharAt(fPos, that.fString->charAt(that.fPos)); return *this; }
02913 
02914 inline UCharReference& 
02915 UCharReference::operator= (UChar c)
02916 { fString->setCharAt(fPos, c); return *this; }
02917 
02918 inline
02919 UCharReference::operator UChar()
02920 { return fString->charAt(fPos); }
02921 
02922 #endif

Generated at Wed Aug 16 16:05:39 2000 for ICU1.6 by doxygen 1.0.0 written by Dimitri van Heesch, © 1997-1999