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 UnicodeConverterCPP;
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 
01820   //========================================
01821   // Implementation methods
01822   //========================================
01823   
01824 private:
01825 
01826   inline int8_t
01827   doCompare(UTextOffset start,
01828            int32_t length,
01829            const UnicodeString& srcText,
01830            UTextOffset srcStart,
01831            int32_t srcLength) const;
01832   
01833   int8_t doCompare(UTextOffset start,
01834            int32_t length,
01835            const UChar *srcChars,
01836            UTextOffset srcStart,
01837            int32_t srcLength) const;
01838 
01839   UTextOffset doIndexOf(UChar c,
01840             UTextOffset start,
01841             int32_t length) const;
01842 
01843   UTextOffset doLastIndexOf(UChar c,
01844                 UTextOffset start,
01845                 int32_t length) const;
01846 
01847   void doExtract(UTextOffset start, 
01848          int32_t length, 
01849          UChar *dst, 
01850          UTextOffset dstStart) const;
01851   
01852   inline void doExtract(UTextOffset start,
01853          int32_t length,
01854          UnicodeString& target) const;
01855   
01856   inline UChar doCharAt(UTextOffset offset)  const;
01857 
01858   UnicodeString& doReplace(UTextOffset start, 
01859                int32_t length, 
01860                const UnicodeString& srcText, 
01861                UTextOffset srcStart, 
01862                int32_t srcLength);
01863 
01864   UnicodeString& doReplace(UTextOffset start, 
01865                int32_t length, 
01866                const UChar *srcChars, 
01867                UTextOffset srcStart, 
01868                int32_t srcLength);
01869 
01870   UnicodeString& doReverse(UTextOffset start,
01871                int32_t length);
01872 
01873   // calculate hash code
01874   int32_t doHashCode(void) const;
01875   
01876   // get pointer to start of array
01877   inline UChar* getArrayStart(void);
01878   inline const UChar* getArrayStart(void) const;
01879 
01880   // get the "real" capacity of the array, adjusted for ref count
01881   inline int32_t getCapacity(void) const;
01882 
01883   // allocate the array; result may be fStackBuffer
01884   // sets refCount to 1 if appropriate
01885   // sets fArray, fCapacity, and fFlags
01886   // returns boolean for success or failure
01887   UBool allocate(int32_t capacity);
01888 
01889   // release the array if owned
01890   inline void releaseArray();
01891 
01892   // utility method to get around lack of exception handling
01893   void setToBogus(void);
01894 
01895   // Pin start and limit to acceptable values.
01896   inline void pinIndices(UTextOffset& start,
01897                          int32_t& length) const;
01898 
01899   /*
01900    * Real constructor for converting from codepage data.
01901    * It assumes that it is called with !fRefCounted.
01902    *
01903    * If <code>codepage==0</code>, then the default converter
01904    * is used for the platform encoding.
01905    * If <code>codepage</code> is an empty string (<code>""</code>),
01906    * then a simple conversion is performed on the codepage-invariant
01907    * subset ("invariant characters") of the platform encoding. See utypes.h.
01908    */
01909   void doCodepageCreate(const char *codepageData,
01910                         int32_t dataLength,
01911                         const char *codepage);
01912 
01913   /*
01914    * This function is called when write access to the array
01915    * is necessary.
01916    *
01917    * We need to make a copy of the array if
01918    * the buffer is read-only, or
01919    * the buffer is refCounted (shared), and refCount>1, or
01920    * the buffer is too small.
01921    *
01922    * Return FALSE if memory could not be allocated.
01923    */
01924   UBool cloneArrayIfNeeded(int32_t newCapacity = -1,
01925                             int32_t growCapacity = -1,
01926                             UBool doCopyArray = TRUE,
01927                             int32_t **pBufferToDelete = 0);
01928 
01929   // ref counting
01930   inline int32_t addRef(void);
01931   inline int32_t removeRef(void);
01932   inline int32_t refCount(void) const;
01933   inline int32_t setRefCount(int32_t count);
01934 
01935   // constants
01936   enum {
01937 #if UTF_SIZE==8
01938     US_STACKBUF_SIZE=14, // Size of stack buffer for small strings
01939 #elif UTF_SIZE==16
01940     US_STACKBUF_SIZE=7, // Size of stack buffer for small strings
01941 #else // UTF_SIZE==32
01942     US_STACKBUF_SIZE=3, // Size of stack buffer for small strings
01943 #endif
01944     kInvalidUChar=0xffff, // invalid UChar index
01945     kGrowSize=128, // grow size for this buffer
01946     kInvalidHashCode=0, // invalid hash code
01947     kEmptyHashCode=1, // hash code for empty string
01948 
01949     // bit flag values for fFlags
01950     kIsBogus=1, // this string is bogus, i.e., not valid
01951     kUsingStackBuffer=2, // fArray==fStackBuffer
01952     kRefCounted=4, // there is a refCount field before the characters in fArray
01953     kBufferIsReadonly=8, // do not write to this buffer
01954 
01955     // combined values for convenience
01956     kShortString=kUsingStackBuffer,
01957     kLongString=kRefCounted,
01958     kReadonlyAlias=kBufferIsReadonly,
01959     kWriteableAlias=0
01960   };
01961 
01962   // statics
01963 
01964   // default converter cache
01965   static UConverter* getDefaultConverter(UErrorCode& status);
01966   static void releaseDefaultConverter(UConverter *converter);
01967 
01968   static UConverter *fgDefaultConverter;
01969 
01970   friend class UnicodeStringStreamer;
01971   friend class UnicodeConverterCPP;
01972 #if U_IOSTREAM_SOURCE >= 199711
01973   friend U_COMMON_API std::ostream &operator<<(std::ostream& stream, const UnicodeString& s);
01974 #elif U_IOSTREAM_SOURCE >= 198506
01975   friend U_COMMON_API ostream &operator<<(ostream& stream, const UnicodeString& s);
01976 #endif
01977 
01978   friend class StringCharacterIterator;
01979 
01980   /*
01981    * The following are all the class fields that are stored
01982    * in each UnicodeString object.
01983    * Note that UnicodeString has virtual functions,
01984    * therefore there is an implicit vtable pointer
01985    * as the first real field.
01986    * The fields should be aligned such that no padding is
01987    * necessary, mostly by having larger types first.
01988    * On 32-bit machines, the size should be 32 bytes,
01989    * on 64-bit machines (8-byte pointers), it should be 40 bytes.
01990    */
01991   // (implicit) *vtable;
01992   UChar     *fArray;        // the Unicode data
01993   int32_t   fLength;        // number characters in fArray
01994   int32_t   fCapacity;      // sizeof fArray
01995   uint16_t  fFlags;         // bit flags: see constants above
01996 #if UTF_SIZE==32
01997   uint16_t  fPadding;       // padding to align the fStackBuffer for UTF-32
01998 #endif
01999   UChar     fStackBuffer [ US_STACKBUF_SIZE ]; // buffer for small strings
02000 
02001 public:
02002 
02003   //========================================
02004   // Deprecated API
02005   //========================================
02006 
02007   /* size() -> length()
02008    * @deprecated */
02009   inline int32_t size(void) const;
02010 
02011   // parameters reordered for consistency
02012    /* @deprecated */
02013   inline UnicodeString& findAndReplace(const UnicodeString& oldText,
02014                 const UnicodeString& newText,
02015                 UTextOffset start,
02016                 int32_t length);
02017 
02018    /* @deprecated */
02019   inline void* operator new(size_t size);
02020    /* @deprecated */
02021   inline void* operator new(size_t size, void *location);
02022    /* @deprecated */
02023   inline void operator delete(void *location);
02024 
02025   //========================================
02026   // Non-public API - will be removed!
02027   //========================================
02028   /* @deprecated */
02029   const UChar* getUChars() const;
02030 };
02031 
02032 //========================================
02033 // Array copying
02034 //========================================
02035 // Copy an array of UnicodeString OBJECTS (not pointers).
02036 inline void 
02037 uprv_arrayCopy(const UnicodeString *src, UnicodeString *dst, int32_t count)
02038 { while(count-- > 0) *dst++ = *src++; }
02039 
02040 inline void 
02041 uprv_arrayCopy(const UnicodeString *src, int32_t srcStart, 
02042         UnicodeString *dst, int32_t dstStart, int32_t count)
02043 { uprv_arrayCopy(src+srcStart, dst+dstStart, count); }
02044 
02045 
02046 //========================================
02047 // Inline members
02048 //========================================
02049 
02050 //========================================
02051 // Read-only alias methods
02052 //========================================
02053 inline UBool
02054 UnicodeString::operator== (const UnicodeString& text) const
02055 {
02056   if(isBogus()) {
02057     return text.isBogus();
02058   } else {
02059     return
02060       !text.isBogus() &&
02061       fLength == text.fLength &&
02062       doCompare(0, fLength, text, 0, text.fLength) == 0;
02063   }
02064 }
02065 
02066 inline UBool
02067 UnicodeString::operator!= (const UnicodeString& text) const
02068 { return (! operator==(text)); }
02069 
02070 inline UBool
02071 UnicodeString::operator> (const UnicodeString& text) const
02072 { return doCompare(0, fLength, text, 0, text.fLength) == 1; }
02073 
02074 inline UBool
02075 UnicodeString::operator< (const UnicodeString& text) const
02076 { return doCompare(0, fLength, text, 0, text.fLength) == -1; }
02077 
02078 inline UBool
02079 UnicodeString::operator>= (const UnicodeString& text) const
02080 { return doCompare(0, fLength, text, 0, text.fLength) != -1; }
02081 
02082 inline UBool
02083 UnicodeString::operator<= (const UnicodeString& text) const
02084 { return doCompare(0, fLength, text, 0, text.fLength) != 1; }
02085 
02086 inline int8_t 
02087 UnicodeString::compare(const UnicodeString& text) const
02088 { return doCompare(0, fLength, text, 0, text.fLength); }
02089 
02090 inline int8_t 
02091 UnicodeString::compare(UTextOffset start,
02092                int32_t length,
02093                const UnicodeString& srcText) const
02094 { return doCompare(start, length, srcText, 0, srcText.fLength); }
02095 
02096 inline int8_t 
02097 UnicodeString::compare(const UChar *srcChars,
02098                int32_t srcLength) const
02099 { return doCompare(0, fLength, srcChars, 0, srcLength); }
02100 
02101 inline int8_t 
02102 UnicodeString::compare(UTextOffset start,
02103                int32_t length,
02104                const UnicodeString& srcText,
02105                UTextOffset srcStart,
02106                int32_t srcLength) const
02107 { return doCompare(start, length, srcText, srcStart, srcLength); }
02108 
02109 inline int8_t
02110 UnicodeString::compare(UTextOffset start,
02111                int32_t length,
02112                const UChar *srcChars) const
02113 { return doCompare(start, length, srcChars, 0, length); }
02114 
02115 inline int8_t 
02116 UnicodeString::compare(UTextOffset start,
02117                int32_t length,
02118                const UChar *srcChars,
02119                UTextOffset srcStart,
02120                int32_t srcLength) const
02121 { return doCompare(start, length, srcChars, srcStart, srcLength); }
02122 
02123 inline int8_t
02124 UnicodeString::compareBetween(UTextOffset start,
02125                   UTextOffset limit,
02126                   const UnicodeString& srcText,
02127                   UTextOffset srcStart,
02128                   UTextOffset srcLimit) const
02129 { return doCompare(start, limit - start, 
02130            srcText, srcStart, srcLimit - srcStart); }
02131 
02132 inline int8_t
02133 UnicodeString::doCompare(UTextOffset start,
02134               int32_t length,
02135               const UnicodeString& srcText,
02136               UTextOffset srcStart,
02137               int32_t srcLength) const
02138 {
02139   const UChar *srcChars;
02140   if(!srcText.isBogus()) {
02141     srcText.pinIndices(srcStart, srcLength);
02142     srcChars=srcText.getArrayStart();
02143   } else {
02144     srcChars=0;
02145   }
02146   return doCompare(start, length, srcChars, srcStart, srcLength);
02147 }
02148 
02149 inline UTextOffset 
02150 UnicodeString::indexOf(const UnicodeString& text) const
02151 { return indexOf(text, 0, text.fLength, 0, fLength); }
02152 
02153 inline UTextOffset 
02154 UnicodeString::indexOf(const UnicodeString& text,
02155                UTextOffset start) const
02156 { return indexOf(text, 0, text.fLength, start, fLength - start); }
02157 
02158 inline UTextOffset 
02159 UnicodeString::indexOf(const UnicodeString& text,
02160                UTextOffset start,
02161                int32_t length) const
02162 { return indexOf(text, 0, text.fLength, start, length); }
02163 
02164 inline UTextOffset 
02165 UnicodeString::indexOf(const UnicodeString& srcText,
02166                UTextOffset srcStart,
02167                int32_t srcLength,
02168                UTextOffset start,
02169                int32_t length) const
02170 {
02171   if(!srcText.isBogus()) {
02172     srcText.pinIndices(srcStart, srcLength);
02173     if(srcLength > 0) {
02174       return indexOf(srcText.getArrayStart(), srcStart, srcLength, start, length);
02175     }
02176   }
02177   return -1;
02178 }
02179 
02180 inline UTextOffset 
02181 UnicodeString::indexOf(const UChar *srcChars,
02182                int32_t srcLength,
02183                UTextOffset start) const
02184 { return indexOf(srcChars, 0, srcLength, start, fLength - start); }
02185 
02186 inline UTextOffset 
02187 UnicodeString::indexOf(const UChar *srcChars,
02188                int32_t srcLength,
02189                UTextOffset start,
02190                int32_t length) const
02191 { return indexOf(srcChars, 0, srcLength, start, length); }
02192 
02193 inline UTextOffset 
02194 UnicodeString::indexOf(UChar c) const
02195 { return doIndexOf(c, 0, fLength); }
02196 
02197 inline UTextOffset 
02198 UnicodeString::indexOf(UChar32 c) const {
02199   if(!UTF_NEED_MULTIPLE_UCHAR(c)) {
02200     return doIndexOf((UChar)c, 0, fLength);
02201   } else {
02202     UChar buffer[UTF_MAX_CHAR_LENGTH];
02203     int32_t length = 0;
02204     UTF_APPEND_CHAR_UNSAFE(buffer, length, c);
02205     return indexOf(buffer, length, 0);
02206   }
02207 }
02208 
02209 inline UTextOffset 
02210 UnicodeString::indexOf(UChar c,
02211                UTextOffset start) const
02212 { return doIndexOf(c, start, fLength - start); }
02213 
02214 inline UTextOffset 
02215 UnicodeString::indexOf(UChar32 c,
02216                UTextOffset start) const {
02217   if(!UTF_NEED_MULTIPLE_UCHAR(c)) {
02218     return doIndexOf((UChar)c, start, fLength - start);
02219   } else {
02220     UChar buffer[UTF_MAX_CHAR_LENGTH];
02221     int32_t length = 0;
02222     UTF_APPEND_CHAR_UNSAFE(buffer, length, c);
02223     return indexOf(buffer, length, start);
02224   }
02225 }
02226 
02227 inline UTextOffset 
02228 UnicodeString::indexOf(UChar c,
02229                UTextOffset start,
02230                int32_t length) const
02231 { return doIndexOf(c, start, length); }
02232 
02233 inline UTextOffset 
02234 UnicodeString::indexOf(UChar32 c,
02235                UTextOffset start,
02236                int32_t length) const {
02237   if(!UTF_NEED_MULTIPLE_UCHAR(c)) {
02238     return doIndexOf((UChar)c, start, length);
02239   } else {
02240     UChar buffer[UTF_MAX_CHAR_LENGTH];
02241     int32_t cLength = 0;
02242     UTF_APPEND_CHAR_UNSAFE(buffer, cLength, c);
02243     return indexOf(buffer, cLength, start, length);
02244   }
02245 }
02246 
02247 inline UTextOffset 
02248 UnicodeString::lastIndexOf(const UnicodeString& text) const
02249 { return lastIndexOf(text, 0, text.fLength, 0, fLength); }
02250 
02251 inline UTextOffset 
02252 UnicodeString::lastIndexOf(const UnicodeString& text,
02253                UTextOffset start) const
02254 { return lastIndexOf(text, 0, text.fLength, start, fLength - start); }
02255 
02256 inline UTextOffset 
02257 UnicodeString::lastIndexOf(const UnicodeString& text,
02258                UTextOffset start,
02259                int32_t length) const
02260 { return lastIndexOf(text, 0, text.fLength, start, length); }
02261 
02262 inline UTextOffset 
02263 UnicodeString::lastIndexOf(const UnicodeString& srcText,
02264                UTextOffset srcStart,
02265                int32_t srcLength,
02266                UTextOffset start,
02267                int32_t length) const
02268 {
02269   if(!srcText.isBogus()) {
02270     srcText.pinIndices(srcStart, srcLength);
02271     if(srcLength > 0) {
02272       return lastIndexOf(srcText.getArrayStart(), srcStart, srcLength, start, length);
02273     }
02274   }
02275   return -1;
02276 }
02277 
02278 inline UTextOffset 
02279 UnicodeString::lastIndexOf(const UChar *srcChars,
02280                int32_t srcLength,
02281                UTextOffset start) const
02282 { return lastIndexOf(srcChars, 0, srcLength, start, fLength - start); }
02283 
02284 inline UTextOffset 
02285 UnicodeString::lastIndexOf(const UChar *srcChars,
02286                int32_t srcLength,
02287                UTextOffset start,
02288                int32_t length) const
02289 { return lastIndexOf(srcChars, 0, srcLength, start, length); }
02290 
02291 inline UTextOffset 
02292 UnicodeString::lastIndexOf(UChar c) const
02293 { return doLastIndexOf(c, 0, fLength); }
02294 
02295 inline UTextOffset 
02296 UnicodeString::lastIndexOf(UChar32 c) const {
02297   if(!UTF_NEED_MULTIPLE_UCHAR(c)) {
02298     return doLastIndexOf((UChar)c, 0, fLength);
02299   } else {
02300     UChar buffer[UTF_MAX_CHAR_LENGTH];
02301     int32_t count = 0;
02302     UTF_APPEND_CHAR_UNSAFE(buffer, count, c);
02303     return lastIndexOf(buffer, count, 0);
02304   }
02305 }
02306 
02307 inline UTextOffset 
02308 UnicodeString::lastIndexOf(UChar c,
02309                UTextOffset start) const
02310 { return doLastIndexOf(c, start, fLength - start); }
02311 
02312 inline UTextOffset 
02313 UnicodeString::lastIndexOf(UChar32 c,
02314                UTextOffset start) const {
02315   if(!UTF_NEED_MULTIPLE_UCHAR(c)) {
02316     return doLastIndexOf((UChar)c, start, fLength - start);
02317   } else {
02318     UChar buffer[UTF_MAX_CHAR_LENGTH];
02319     int32_t count = 0;
02320     UTF_APPEND_CHAR_UNSAFE(buffer, count, c);
02321     return lastIndexOf(buffer, count, start);
02322   }
02323 }
02324 
02325 inline UTextOffset 
02326 UnicodeString::lastIndexOf(UChar c,
02327                UTextOffset start,
02328                int32_t length) const
02329 { return doLastIndexOf(c, start, length); }
02330 
02331 inline UTextOffset 
02332 UnicodeString::lastIndexOf(UChar32 c,
02333                UTextOffset start,
02334                int32_t length) const {
02335   if(!UTF_NEED_MULTIPLE_UCHAR(c)) {
02336     return doLastIndexOf((UChar)c, start, length);
02337   } else {
02338     UChar buffer[UTF_MAX_CHAR_LENGTH];
02339     int32_t count = 0;
02340     UTF_APPEND_CHAR_UNSAFE(buffer, count, c);
02341     return lastIndexOf(buffer, count, start, length);
02342   }
02343 }
02344 
02345 inline UBool 
02346 UnicodeString::startsWith(const UnicodeString& text) const
02347 { return compare(0, text.fLength, text, 0, text.fLength) == 0; }
02348 
02349 inline UBool 
02350 UnicodeString::startsWith(const UnicodeString& srcText,
02351               UTextOffset srcStart,
02352               int32_t srcLength) const
02353 { return doCompare(0, srcLength, srcText, srcStart, srcLength) == 0; }
02354 
02355 inline UBool 
02356 UnicodeString::startsWith(const UChar *srcChars,
02357               int32_t srcLength) const
02358 { return doCompare(0, srcLength, srcChars, 0, srcLength) == 0; }
02359 
02360 inline UBool 
02361 UnicodeString::startsWith(const UChar *srcChars,
02362               UTextOffset srcStart,
02363               int32_t srcLength) const
02364 { return doCompare(0, srcLength, srcChars, srcStart, srcLength) == 0;}
02365 
02366 inline UBool 
02367 UnicodeString::endsWith(const UnicodeString& text) const
02368 { return doCompare(fLength - text.fLength, text.fLength, 
02369            text, 0, text.fLength) == 0; }
02370 
02371 inline UBool 
02372 UnicodeString::endsWith(const UnicodeString& srcText,
02373             UTextOffset srcStart,
02374             int32_t srcLength) const
02375 { return doCompare(fLength - srcLength, srcLength, 
02376            srcText, srcStart, srcLength) == 0; }
02377 
02378 inline UBool 
02379 UnicodeString::endsWith(const UChar *srcChars,
02380             int32_t srcLength) const
02381 { return doCompare(fLength - srcLength, srcLength, 
02382            srcChars, 0, srcLength) == 0; }
02383 
02384 inline UBool 
02385 UnicodeString::endsWith(const UChar *srcChars,
02386             UTextOffset srcStart,
02387             int32_t srcLength) const
02388 { return doCompare(fLength - srcLength, srcLength, 
02389            srcChars, srcStart, srcLength) == 0;}
02390 //========================================
02391 // replace
02392 //========================================
02393 inline UnicodeString& 
02394 UnicodeString::replace(UTextOffset start, 
02395                int32_t length, 
02396                const UnicodeString& srcText) 
02397 { return doReplace(start, length, srcText, 0, srcText.fLength); }
02398 
02399 inline UnicodeString& 
02400 UnicodeString::replace(UTextOffset start, 
02401                int32_t length, 
02402                const UnicodeString& srcText, 
02403                UTextOffset srcStart, 
02404                int32_t srcLength)
02405 { return doReplace(start, length, srcText, srcStart, srcLength); }
02406 
02407 inline UnicodeString& 
02408 UnicodeString::replace(UTextOffset start, 
02409                int32_t length, 
02410                const UChar *srcChars,
02411                int32_t srcLength)
02412 { return doReplace(start, length, srcChars, 0, srcLength); }
02413 
02414 inline UnicodeString& 
02415 UnicodeString::replace(UTextOffset start, 
02416                int32_t length, 
02417                const UChar *srcChars, 
02418                UTextOffset srcStart, 
02419                int32_t srcLength)
02420 { return doReplace(start, length, srcChars, srcStart, srcLength); }
02421 
02422 inline UnicodeString& 
02423 UnicodeString::replace(UTextOffset start, 
02424                int32_t length, 
02425                UChar srcChar)
02426 { return doReplace(start, length, &srcChar, 0, 1); }
02427 
02428 inline UnicodeString&
02429 UnicodeString::replace(UTextOffset start, 
02430                int32_t length, 
02431                UChar32 srcChar) {
02432   UChar buffer[UTF_MAX_CHAR_LENGTH];
02433   int32_t count = 0;
02434   UTF_APPEND_CHAR_UNSAFE(buffer, count, srcChar);
02435   return doReplace(start, length, buffer, 0, count);
02436 }
02437 
02438 inline UnicodeString& 
02439 UnicodeString::replaceBetween(UTextOffset start, 
02440                   UTextOffset limit, 
02441                   const UnicodeString& srcText)
02442 { return doReplace(start, limit - start, srcText, 0, srcText.fLength); }
02443 
02444 inline UnicodeString&
02445 UnicodeString::replaceBetween(UTextOffset start, 
02446                   UTextOffset limit, 
02447                   const UnicodeString& srcText, 
02448                   UTextOffset srcStart, 
02449                   UTextOffset srcLimit)
02450 { return doReplace(start, limit - start, srcText, srcStart, srcLimit - srcStart); }
02451 
02452 inline UnicodeString& 
02453 UnicodeString::findAndReplace(const UnicodeString& oldText,
02454                   const UnicodeString& newText)
02455 { return findAndReplace(0, fLength, oldText, 0, oldText.fLength, 
02456             newText, 0, newText.fLength); }
02457 
02458 inline UnicodeString& 
02459 UnicodeString::findAndReplace(UTextOffset start,
02460                   int32_t length,
02461                   const UnicodeString& oldText,
02462                   const UnicodeString& newText)
02463 { return findAndReplace(start, length, oldText, 0, oldText.fLength, 
02464             newText, 0, newText.fLength); }
02465 
02466 // ============================
02467 // extract
02468 // ============================
02469 inline void
02470 UnicodeString::doExtract(UTextOffset start,
02471              int32_t length,
02472              UnicodeString& target) const
02473 { target.replace(0, target.fLength, *this, start, length); }
02474 
02475 inline void  
02476 UnicodeString::extract(UTextOffset start, 
02477                int32_t length, 
02478                UChar *dst, 
02479                UTextOffset dstStart) const
02480 { doExtract(start, length, dst, dstStart); }
02481 
02482 inline void 
02483 UnicodeString::extract(UTextOffset start,
02484                int32_t length,
02485                UnicodeString& target) const
02486 { doExtract(start, length, target); }
02487 
02488 inline void  
02489 UnicodeString::extractBetween(UTextOffset start, 
02490                   UTextOffset limit, 
02491                   UChar *dst, 
02492                   UTextOffset dstStart) const
02493 { doExtract(start, limit - start, dst, dstStart); }
02494 
02495 inline void 
02496 UnicodeString::extractBetween(UTextOffset start,
02497                   UTextOffset limit,
02498                   UnicodeString& target) const
02499 { doExtract(start, limit - start, target); }
02500 
02501 inline UChar
02502 UnicodeString::doCharAt(UTextOffset offset) const
02503 {
02504   if((uint32_t)offset < (uint32_t)fLength) {
02505     return fArray[offset];
02506   } else {
02507     return kInvalidUChar;
02508   }
02509 }
02510 
02511 inline UChar
02512 UnicodeString::charAt(UTextOffset offset) const
02513 { return doCharAt(offset); }
02514 
02515 inline UChar
02516 UnicodeString::operator[] (UTextOffset offset) const
02517 { return doCharAt(offset); }
02518 
02519 inline UChar32
02520 UnicodeString::char32At(UTextOffset offset) const
02521 {
02522   if((uint32_t)offset < (uint32_t)fLength) {
02523     UChar32 c;
02524     UTF_GET_CHAR(fArray, 0, offset, fLength, c);
02525     return c;
02526   } else {
02527     return kInvalidUChar;
02528   }
02529 }
02530 
02531 inline UTextOffset
02532 UnicodeString::getCharStart(UTextOffset offset) {
02533   if((uint32_t)offset < (uint32_t)fLength) {
02534     UTF_SET_CHAR_START(fArray, 0, offset);
02535     return offset;
02536   } else {
02537     return 0;
02538   }
02539 }
02540 
02541 inline UTextOffset
02542 UnicodeString::getCharLimit(UTextOffset offset) {
02543   if((uint32_t)offset < (uint32_t)fLength) {
02544     UTF_SET_CHAR_LIMIT(fArray, 0, offset, fLength);
02545     return offset;
02546   } else {
02547     return fLength;
02548   }
02549 }
02550 
02551 inline UBool
02552 UnicodeString::empty() const
02553 { return fLength == 0; }
02554 
02555 //========================================
02556 // Read-only implementation methods
02557 //========================================
02558 inline int32_t  
02559 UnicodeString::length() const
02560 { return fLength; }
02561 
02562 inline int32_t 
02563 UnicodeString::hashCode() const
02564 { return doHashCode(); }
02565 
02566 //========================================
02567 // Write alias methods
02568 //========================================
02569 inline UnicodeString& 
02570 UnicodeString::operator= (UChar ch) 
02571 { return doReplace(0, fLength, &ch, 0, 1); }
02572 
02573 inline UnicodeString& 
02574 UnicodeString::operator= (UChar32 ch) 
02575 { return replace(0, fLength, ch); }
02576 
02577 inline UnicodeString& 
02578 UnicodeString::setTo(const UnicodeString& srcText, 
02579              UTextOffset srcStart, 
02580              int32_t srcLength)
02581 { return doReplace(0, fLength, srcText, srcStart, srcLength); }
02582 
02583 inline UnicodeString& 
02584 UnicodeString::setTo(const UnicodeString& srcText)
02585 { return doReplace(0, fLength, srcText, 0, srcText.fLength); }
02586 
02587 inline UnicodeString& 
02588 UnicodeString::setTo(const UChar *srcChars,
02589              int32_t srcLength)
02590 { return doReplace(0, fLength, srcChars, 0, srcLength); }
02591 
02592 inline UnicodeString& 
02593 UnicodeString::setTo(UChar srcChar)
02594 { return doReplace(0, fLength, &srcChar, 0, 1); }
02595 
02596 inline UnicodeString& 
02597 UnicodeString::setTo(UChar32 srcChar)
02598 { return replace(0, fLength, srcChar); }
02599 
02600 inline UnicodeString& 
02601 UnicodeString::operator+= (UChar ch)
02602 { return doReplace(fLength, 0, &ch, 0, 1); }
02603 
02604 inline UnicodeString& 
02605 UnicodeString::operator+= (UChar32 ch) {
02606   UChar buffer[UTF_MAX_CHAR_LENGTH];
02607   int32_t length = 0;
02608   UTF_APPEND_CHAR_UNSAFE(buffer, length, ch);
02609   return doReplace(fLength, 0, buffer, 0, length);
02610 }
02611 
02612 inline UnicodeString& 
02613 UnicodeString::operator+= (const UnicodeString& srcText)
02614 { return doReplace(fLength, 0, srcText, 0, srcText.fLength); }
02615 
02616 inline UnicodeString& 
02617 UnicodeString::append(const UnicodeString& srcText, 
02618               UTextOffset srcStart, 
02619               int32_t srcLength)
02620 { return doReplace(fLength, 0, srcText, srcStart, srcLength); }
02621 
02622 inline UnicodeString& 
02623 UnicodeString::append(const UnicodeString& srcText)
02624 { return doReplace(fLength, 0, srcText, 0, srcText.fLength); }
02625 
02626 inline UnicodeString& 
02627 UnicodeString::append(const UChar *srcChars, 
02628               UTextOffset srcStart, 
02629               int32_t srcLength)
02630 { return doReplace(fLength, 0, srcChars, srcStart, srcLength); }
02631 
02632 inline UnicodeString& 
02633 UnicodeString::append(const UChar *srcChars,
02634               int32_t srcLength)
02635 { return doReplace(fLength, 0, srcChars, 0, srcLength); }
02636 
02637 inline UnicodeString& 
02638 UnicodeString::append(UChar srcChar)
02639 { return doReplace(fLength, 0, &srcChar, 0, 1); }
02640 
02641 inline UnicodeString& 
02642 UnicodeString::append(UChar32 srcChar) {
02643   UChar buffer[UTF_MAX_CHAR_LENGTH];
02644   int32_t length = 0;
02645   UTF_APPEND_CHAR_UNSAFE(buffer, length, srcChar);
02646   return doReplace(fLength, 0, buffer, 0, length);
02647 }
02648 
02649 inline UnicodeString& 
02650 UnicodeString::insert(UTextOffset start, 
02651               const UnicodeString& srcText, 
02652               UTextOffset srcStart, 
02653               int32_t srcLength)
02654 { return doReplace(start, 0, srcText, srcStart, srcLength); }
02655 
02656 inline UnicodeString& 
02657 UnicodeString::insert(UTextOffset start, 
02658               const UnicodeString& srcText)
02659 { return doReplace(start, 0, srcText, 0, srcText.fLength); }
02660 
02661 inline UnicodeString& 
02662 UnicodeString::insert(UTextOffset start, 
02663               const UChar *srcChars, 
02664               UTextOffset srcStart, 
02665               int32_t srcLength)
02666 { return doReplace(start, 0, srcChars, srcStart, srcLength); }
02667 
02668 inline UnicodeString& 
02669 UnicodeString::insert(UTextOffset start, 
02670               const UChar *srcChars,
02671               int32_t srcLength)
02672 { return doReplace(start, 0, srcChars, 0, srcLength); }
02673 
02674 inline UnicodeString& 
02675 UnicodeString::insert(UTextOffset start, 
02676               UChar srcChar)
02677 { return doReplace(start, 0, &srcChar, 0, 1); }
02678 
02679 inline UnicodeString& 
02680 UnicodeString::insert(UTextOffset start, 
02681               UChar32 srcChar)
02682 { return replace(start, 0, srcChar); }
02683 
02684 
02685 inline UnicodeString& 
02686 UnicodeString::remove(UTextOffset start, 
02687              int32_t length)
02688 { return doReplace(start, length, 0, 0, 0); }
02689 
02690 inline UnicodeString& 
02691 UnicodeString::remove()
02692 { return doReplace(0, fLength, 0, 0, 0); }
02693 
02694 inline UnicodeString& 
02695 UnicodeString::removeBetween(UTextOffset start,
02696                 UTextOffset limit)
02697 { return doReplace(start, limit - start, 0, 0, 0); }
02698 
02699 inline UBool 
02700 UnicodeString::truncate(int32_t targetLength)
02701 {
02702   if((uint32_t)targetLength < (uint32_t)fLength) {
02703     fLength = targetLength;
02704     return TRUE;
02705   } else {
02706     return FALSE;
02707   }
02708 }
02709 
02710 inline UnicodeString& 
02711 UnicodeString::reverse()
02712 { return doReverse(0, fLength); }
02713 
02714 inline UnicodeString& 
02715 UnicodeString::reverse(UTextOffset start,
02716                int32_t length)
02717 { return doReverse(start, length); }
02718 
02719 
02720 //========================================
02721 // Write implementation methods
02722 //========================================
02723 inline UBool 
02724 UnicodeString::isBogus() const
02725 { return fFlags & kIsBogus; }
02726 
02727 
02728 //========================================
02729 // Privates
02730 //========================================
02731 
02732 inline void
02733 UnicodeString::pinIndices(UTextOffset& start,
02734                           int32_t& length) const
02735 {
02736   // pin indices
02737   if(start < 0) {
02738     start = 0;
02739   } else if(start > fLength) {
02740     start = fLength;
02741   }
02742   if(length < 0) {
02743     length = 0;
02744   } else if(length > (fLength - start)) {
02745     length = (fLength - start);
02746   }
02747 }
02748 
02749 inline UChar* 
02750 UnicodeString::getArrayStart()
02751 { return fArray; }
02752 
02753 inline const UChar* 
02754 UnicodeString::getArrayStart() const
02755 { return fArray; }
02756 
02757 inline int32_t 
02758 UnicodeString::getCapacity() const
02759 { return fCapacity; }
02760 
02761 inline void
02762 UnicodeString::releaseArray() {
02763   if((fFlags & kRefCounted) && removeRef() == 0) {
02764     delete [] ((int32_t *)fArray - 1);
02765   }
02766 }
02767 
02768 inline int32_t
02769 UnicodeString::addRef()
02770 { return ++*((int32_t *)fArray - 1); }
02771 
02772 inline int32_t
02773 UnicodeString::removeRef()
02774 { return --*((int32_t *)fArray - 1); }
02775 
02776 inline int32_t
02777 UnicodeString::refCount() const
02778 { return *((int32_t *)fArray - 1); }
02779 
02780 inline int32_t
02781 UnicodeString::setRefCount(int32_t count)
02782 { return (*((int32_t *)fArray - 1) = count); }
02783 
02784 
02785 // deprecated API - remove later
02786 inline int32_t
02787 UnicodeString::size() const
02788 { return fLength; }
02789 
02790 inline UnicodeString& 
02791 UnicodeString::findAndReplace(const UnicodeString& oldText,
02792                   const UnicodeString& newText,
02793                   UTextOffset start,
02794                   int32_t length)
02795 { return findAndReplace(start, length, oldText, newText); }
02796 
02797 inline void*
02798 UnicodeString::operator new(size_t size)
02799 { return ::operator new(size); }
02800 
02801 inline void* 
02802 UnicodeString::operator new(size_t, 
02803               void *location)
02804 { return location; }
02805 
02806 inline void
02807 UnicodeString::operator delete(void *location)
02808 { ::operator delete(location); }
02809 
02810 
02811 //========================================
02812 // Static members
02813 //========================================
02814 
02815 //========================================
02816 // class UCharReference
02817 //========================================
02818 class UCharReference
02819 {
02820 public:
02821   UCharReference();
02822   inline UCharReference(UnicodeString *string,
02823          UTextOffset pos);
02824   inline UCharReference(const UCharReference& that);
02825   ~UCharReference();
02826 
02827   inline UCharReference& operator= (const UCharReference& that);
02828   inline UCharReference& operator= (UChar c);
02829 
02830   inline operator UChar();
02831 
02832 private:
02833   UnicodeString *fString;
02834   UTextOffset fPos;
02835 };
02836 
02837 
02838 //========================================
02839 // Inline members
02840 //========================================
02841 inline
02842 UCharReference::UCharReference(UnicodeString *string, 
02843                    UTextOffset pos)
02844   : fString(string), fPos(pos)
02845 {}
02846 
02847 inline
02848 UCharReference::UCharReference(const UCharReference& that)
02849 { this->operator=(that); }
02850 
02851 inline
02852 UCharReference::~UCharReference()
02853 {}
02854 
02855 inline UCharReference&
02856 UCharReference::operator= (const UCharReference& that)
02857 { fString->setCharAt(fPos, that.fString->charAt(that.fPos)); return *this; }
02858 
02859 inline UCharReference& 
02860 UCharReference::operator= (UChar c)
02861 { fString->setCharAt(fPos, c); return *this; }
02862 
02863 inline
02864 UCharReference::operator UChar()
02865 { return fString->charAt(fPos); }
02866 
02867 #endif

Generated at Mon Jun 5 12:53:09 2000 for ICU1.5 by doxygen 1.0.0 written by Dimitri van Heesch, © 1997-1999