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

unistr.h

Go to the documentation of this file.
00001 /*
00002 **********************************************************************
00003 *   Copyright (C) 1998-2002, International Business Machines
00004 *   Corporation and others.  All Rights Reserved.
00005 **********************************************************************
00006 *
00007 * File unistr.h
00008 *
00009 * Modification History:
00010 *
00011 *   Date        Name        Description
00012 *   09/25/98    stephen     Creation.
00013 *   11/11/98    stephen     Changed per 11/9 code review.
00014 *   04/20/99    stephen     Overhauled per 4/16 code review.
00015 *   11/18/99    aliu        Made to inherit from Replaceable.  Added method
00016 *                           handleReplaceBetween(); other methods unchanged.
00017 *   06/25/01    grhoten     Remove dependency on iostream.
00018 ******************************************************************************
00019 */
00020 
00021 #ifndef UNISTR_H
00022 #define UNISTR_H
00023 
00024 #include "unicode/utypes.h"
00025 #include "unicode/uobject.h"
00026 #include "unicode/rep.h"
00027 
00028 struct UConverter;          // unicode/ucnv.h
00029 class  StringThreadTest;
00030 
00031 #ifndef U_COMPARE_CODE_POINT_ORDER
00032 /* see also ustring.h and unorm.h */
00038 #define U_COMPARE_CODE_POINT_ORDER  0x8000
00039 #endif
00040 
00041 U_NAMESPACE_BEGIN
00042 
00043 class Locale;               // unicode/locid.h
00044 class UCharReference;
00045 class UnicodeConverter;     // unicode/convert.h
00046 class StringCharacterIterator;
00047 class BreakIterator;        // unicode/brkiter.h
00048 
00049 /* The <iostream> include has been moved to unicode/ustream.h */
00050 
00068 #if U_SIZEOF_WCHAR_T==U_SIZEOF_UCHAR && U_CHARSET_FAMILY==U_ASCII_FAMILY
00069 #   define UNICODE_STRING(cs, length) UnicodeString(TRUE, (const UChar *)L ## cs, length)
00070 #elif U_SIZEOF_UCHAR==1 && U_CHARSET_FAMILY==U_ASCII_FAMILY
00071 #   define UNICODE_STRING(cs, length) UnicodeString(TRUE, (const UChar *)cs, length)
00072 #else
00073 #   define UNICODE_STRING(cs, length) UnicodeString(cs, length, "")
00074 #endif
00075 
00089 #if U_SIZEOF_WCHAR_T==U_SIZEOF_UCHAR && U_CHARSET_FAMILY==U_ASCII_FAMILY
00090 #   define UNICODE_STRING_SIMPLE(cs) UnicodeString((const UChar *)L ## cs)
00091 #elif U_SIZEOF_UCHAR==1 && U_CHARSET_FAMILY==U_ASCII_FAMILY
00092 #   define UNICODE_STRING_SIMPLE(cs) UnicodeString((const UChar *)cs)
00093 #else
00094 #   define UNICODE_STRING_SIMPLE(cs) UnicodeString(cs, "")
00095 #endif
00096 
00156 class U_COMMON_API UnicodeString : public Replaceable
00157 {
00158 public:
00159 
00160   //========================================
00161   // Read-only operations
00162   //========================================
00163 
00164   /* Comparison - bitwise only - for international comparison use collation */
00165 
00173   inline UBool operator== (const UnicodeString& text) const;
00174 
00182   inline UBool operator!= (const UnicodeString& text) const;
00183 
00191   inline UBool operator> (const UnicodeString& text) const;
00192 
00200   inline UBool operator< (const UnicodeString& text) const;
00201 
00209   inline UBool operator>= (const UnicodeString& text) const;
00210 
00218   inline UBool operator<= (const UnicodeString& text) const;
00219 
00231   inline int8_t compare(const UnicodeString& text) const;
00232 
00247   inline int8_t compare(int32_t start,
00248          int32_t length,
00249          const UnicodeString& srcText) const;
00250 
00268    inline int8_t compare(int32_t start,
00269          int32_t length,
00270          const UnicodeString& srcText,
00271          int32_t srcStart,
00272          int32_t srcLength) const;
00273 
00286   inline int8_t compare(const UChar *srcChars,
00287          int32_t srcLength) const;
00288 
00303   inline int8_t compare(int32_t start,
00304          int32_t length,
00305          const UChar *srcChars) const;
00306 
00324   inline int8_t compare(int32_t start,
00325          int32_t length,
00326          const UChar *srcChars,
00327          int32_t srcStart,
00328          int32_t srcLength) const;
00329 
00347   inline int8_t compareBetween(int32_t start,
00348             int32_t limit,
00349             const UnicodeString& srcText,
00350             int32_t srcStart,
00351             int32_t srcLimit) const;
00352 
00370   inline int8_t compareCodePointOrder(const UnicodeString& text) const;
00371 
00391   inline int8_t compareCodePointOrder(int32_t start,
00392                                       int32_t length,
00393                                       const UnicodeString& srcText) const;
00394 
00416    inline int8_t compareCodePointOrder(int32_t start,
00417                                        int32_t length,
00418                                        const UnicodeString& srcText,
00419                                        int32_t srcStart,
00420                                        int32_t srcLength) const;
00421 
00440   inline int8_t compareCodePointOrder(const UChar *srcChars,
00441                                       int32_t srcLength) const;
00442 
00462   inline int8_t compareCodePointOrder(int32_t start,
00463                                       int32_t length,
00464                                       const UChar *srcChars) const;
00465 
00487   inline int8_t compareCodePointOrder(int32_t start,
00488                                       int32_t length,
00489                                       const UChar *srcChars,
00490                                       int32_t srcStart,
00491                                       int32_t srcLength) const;
00492 
00514   inline int8_t compareCodePointOrderBetween(int32_t start,
00515                                              int32_t limit,
00516                                              const UnicodeString& srcText,
00517                                              int32_t srcStart,
00518                                              int32_t srcLimit) const;
00519 
00538   inline int8_t caseCompare(const UnicodeString& text, uint32_t options) const;
00539 
00560   inline int8_t caseCompare(int32_t start,
00561          int32_t length,
00562          const UnicodeString& srcText,
00563          uint32_t options) const;
00564 
00587   inline int8_t caseCompare(int32_t start,
00588          int32_t length,
00589          const UnicodeString& srcText,
00590          int32_t srcStart,
00591          int32_t srcLength,
00592          uint32_t options) const;
00593 
00613   inline int8_t caseCompare(const UChar *srcChars,
00614          int32_t srcLength,
00615          uint32_t options) const;
00616 
00637   inline int8_t caseCompare(int32_t start,
00638          int32_t length,
00639          const UChar *srcChars,
00640          uint32_t options) const;
00641 
00664   inline int8_t caseCompare(int32_t start,
00665          int32_t length,
00666          const UChar *srcChars,
00667          int32_t srcStart,
00668          int32_t srcLength,
00669          uint32_t options) const;
00670 
00693   inline int8_t caseCompareBetween(int32_t start,
00694             int32_t limit,
00695             const UnicodeString& srcText,
00696             int32_t srcStart,
00697             int32_t srcLimit,
00698             uint32_t options) const;
00699 
00707   inline UBool startsWith(const UnicodeString& text) const;
00708 
00719   inline UBool startsWith(const UnicodeString& srcText,
00720             int32_t srcStart,
00721             int32_t srcLength) const;
00722 
00731   inline UBool startsWith(const UChar *srcChars,
00732             int32_t srcLength) const;
00733 
00743   inline UBool startsWith(const UChar *srcChars,
00744             int32_t srcStart,
00745             int32_t srcLength) const;
00746 
00754   inline UBool endsWith(const UnicodeString& text) const;
00755 
00766   inline UBool endsWith(const UnicodeString& srcText,
00767           int32_t srcStart,
00768           int32_t srcLength) const;
00769 
00778   inline UBool endsWith(const UChar *srcChars,
00779           int32_t srcLength) const;
00780 
00791   inline UBool endsWith(const UChar *srcChars,
00792           int32_t srcStart,
00793           int32_t srcLength) const;
00794 
00795 
00796   /* Searching - bitwise only */
00797 
00806   inline int32_t indexOf(const UnicodeString& text) const;
00807 
00817   inline int32_t indexOf(const UnicodeString& text,
00818               int32_t start) const;
00819 
00831   inline int32_t indexOf(const UnicodeString& text,
00832               int32_t start,
00833               int32_t length) const;
00834 
00851   inline int32_t indexOf(const UnicodeString& srcText,
00852               int32_t srcStart,
00853               int32_t srcLength,
00854               int32_t start,
00855               int32_t length) const;
00856 
00868   inline int32_t indexOf(const UChar *srcChars,
00869               int32_t srcLength,
00870               int32_t start) const;
00871 
00884   inline int32_t indexOf(const UChar *srcChars,
00885               int32_t srcLength,
00886               int32_t start,
00887               int32_t length) const;
00888  
00905   int32_t indexOf(const UChar *srcChars,
00906               int32_t srcStart,
00907               int32_t srcLength,
00908               int32_t start,
00909               int32_t length) const;
00910 
00918   inline int32_t indexOf(UChar c) const;
00919 
00941   inline int32_t indexOf(UChar32 c) const;
00942 
00951   inline int32_t indexOf(UChar c,
00952               int32_t start) const;
00953 
00976   inline int32_t indexOf(UChar32 c,
00977               int32_t start) const;
00978 
00989   inline int32_t indexOf(UChar c,
00990               int32_t start,
00991               int32_t length) const;
00992 
01017   inline int32_t indexOf(UChar32 c,
01018               int32_t start,
01019               int32_t length) const;
01020 
01029   inline int32_t lastIndexOf(const UnicodeString& text) const;
01030 
01040   inline int32_t lastIndexOf(const UnicodeString& text,
01041               int32_t start) const;
01042 
01054   inline int32_t lastIndexOf(const UnicodeString& text,
01055               int32_t start,
01056               int32_t length) const;
01057 
01074   inline int32_t lastIndexOf(const UnicodeString& srcText,
01075               int32_t srcStart,
01076               int32_t srcLength,
01077               int32_t start,
01078               int32_t length) const;
01079 
01090   inline int32_t lastIndexOf(const UChar *srcChars,
01091               int32_t srcLength,
01092               int32_t start) const;
01093 
01106   inline int32_t lastIndexOf(const UChar *srcChars,
01107               int32_t srcLength,
01108               int32_t start,
01109               int32_t length) const;
01110  
01127   int32_t lastIndexOf(const UChar *srcChars,
01128               int32_t srcStart,
01129               int32_t srcLength,
01130               int32_t start,
01131               int32_t length) const;
01132 
01140   inline int32_t lastIndexOf(UChar c) const;
01141 
01163   inline int32_t lastIndexOf(UChar32 c) const;
01164 
01173   inline int32_t lastIndexOf(UChar c,
01174               int32_t start) const;
01175 
01198   inline int32_t lastIndexOf(UChar32 c,
01199               int32_t start) const;
01200 
01211   inline int32_t lastIndexOf(UChar c,
01212               int32_t start,
01213               int32_t length) const;
01214 
01239   inline int32_t lastIndexOf(UChar32 c,
01240               int32_t start,
01241               int32_t length) const;
01242 
01243 
01244   /* Character access */
01245 
01252   inline UChar charAt(int32_t offset) const;
01253 
01260   inline UChar operator [] (int32_t offset) const;
01261 
01271   inline UChar32 char32At(int32_t offset) const;
01272 
01287   inline int32_t getChar32Start(int32_t offset) const;
01288 
01309   inline int32_t getCharStart(int32_t offset) const;
01310 
01326   inline int32_t getChar32Limit(int32_t offset) const;
01327 
01349   inline int32_t getCharLimit(int32_t offset) const;
01350 
01392   int32_t moveIndex32(int32_t index, int32_t delta) const;
01393 
01394   /* Substring extraction */
01395 
01411   inline void extract(int32_t start, 
01412            int32_t length, 
01413            UChar *dst, 
01414            int32_t dstStart = 0) const;
01415 
01437   int32_t
01438   extract(UChar *dest, int32_t destCapacity,
01439           UErrorCode &errorCode) const;
01440 
01451   inline void extract(int32_t start,
01452            int32_t length,
01453            UnicodeString& target) const;
01454 
01466   inline void extractBetween(int32_t start, 
01467               int32_t limit, 
01468               UChar *dst, 
01469               int32_t dstStart = 0) const;
01470 
01480   virtual void extractBetween(int32_t start,
01481               int32_t limit,
01482               UnicodeString& target) const;
01483 
01504   inline int32_t extract(int32_t start,
01505                  int32_t startLength,
01506                  char *target,
01507                  const char *codepage = 0) const;
01508 
01533   int32_t extract(int32_t start,
01534            int32_t startLength,
01535            char *target,
01536            uint32_t targetLength,
01537            const char *codepage = 0) const;
01538 
01556   int32_t extract(char *dest, int32_t destCapacity,
01557                   UConverter *cnv,
01558                   UErrorCode &errorCode) const;
01559 
01560   /* Length operations */
01561 
01568   inline int32_t  length(void) const;
01569 
01582   int32_t
01583   countChar32(int32_t start=0, int32_t length=0x7fffffff) const;
01584 
01590   inline UBool isEmpty(void) const;
01591 
01601   inline UBool empty(void) const;
01602 
01612   inline int32_t getCapacity(void) const;
01613 
01614   /* Other operations */
01615 
01621   inline int32_t hashCode(void) const;
01622 
01629   inline UBool isBogus(void) const;
01630 
01631 
01632   //========================================
01633   // Write operations
01634   //========================================
01635 
01636   /* Assignment operations */
01637 
01645    UnicodeString& operator= (const UnicodeString& srcText);
01646 
01654   inline UnicodeString& operator= (UChar ch);
01655 
01663   inline UnicodeString& operator= (UChar32 ch);
01664 
01676   inline UnicodeString& setTo(const UnicodeString& srcText, 
01677                int32_t srcStart);
01678 
01692   inline UnicodeString& setTo(const UnicodeString& srcText, 
01693                int32_t srcStart, 
01694                int32_t srcLength);
01695 
01704   inline UnicodeString& setTo(const UnicodeString& srcText);
01705 
01714   inline UnicodeString& setTo(const UChar *srcChars,
01715                int32_t srcLength);
01716 
01725   UnicodeString& setTo(UChar srcChar);
01726 
01735   UnicodeString& setTo(UChar32 srcChar);
01736 
01757   UnicodeString &setTo(UBool isTerminated,
01758                        const UChar *text,
01759                        int32_t textLength);
01760 
01780   UnicodeString &setTo(UChar *buffer,
01781                        int32_t buffLength,
01782                        int32_t buffCapacity);
01783 
01805   void setToBogus();
01806 
01814   UnicodeString& setCharAt(int32_t offset, 
01815                UChar ch);
01816 
01817 
01818   /* Append operations */
01819 
01827  inline  UnicodeString& operator+= (UChar ch);
01828 
01836  inline  UnicodeString& operator+= (UChar32 ch);
01837 
01846   inline UnicodeString& operator+= (const UnicodeString& srcText);
01847 
01862   inline UnicodeString& append(const UnicodeString& srcText, 
01863             int32_t srcStart, 
01864             int32_t srcLength);
01865 
01873   inline UnicodeString& append(const UnicodeString& srcText);
01874 
01888   inline UnicodeString& append(const UChar *srcChars, 
01889             int32_t srcStart, 
01890             int32_t srcLength);
01891 
01900   inline UnicodeString& append(const UChar *srcChars,
01901             int32_t srcLength);
01902 
01909   inline UnicodeString& append(UChar srcChar);
01910 
01917   inline UnicodeString& append(UChar32 srcChar);
01918 
01919 
01920   /* Insert operations */
01921 
01935   inline UnicodeString& insert(int32_t start, 
01936             const UnicodeString& srcText, 
01937             int32_t srcStart, 
01938             int32_t srcLength);
01939 
01948   inline UnicodeString& insert(int32_t start, 
01949             const UnicodeString& srcText);
01950 
01964   inline UnicodeString& insert(int32_t start, 
01965             const UChar *srcChars, 
01966             int32_t srcStart, 
01967             int32_t srcLength);
01968 
01978   inline UnicodeString& insert(int32_t start, 
01979             const UChar *srcChars,
01980             int32_t srcLength);
01981 
01990   inline UnicodeString& insert(int32_t start, 
01991             UChar srcChar);
01992 
02001   inline UnicodeString& insert(int32_t start, 
02002             UChar32 srcChar);
02003 
02004 
02005   /* Replace operations */
02006 
02024   UnicodeString& replace(int32_t start, 
02025              int32_t length, 
02026              const UnicodeString& srcText, 
02027              int32_t srcStart, 
02028              int32_t srcLength);
02029 
02042   UnicodeString& replace(int32_t start, 
02043              int32_t length, 
02044              const UnicodeString& srcText);
02045 
02063   UnicodeString& replace(int32_t start, 
02064              int32_t length, 
02065              const UChar *srcChars, 
02066              int32_t srcStart, 
02067              int32_t srcLength);
02068 
02081   inline UnicodeString& replace(int32_t start, 
02082              int32_t length, 
02083              const UChar *srcChars,
02084              int32_t srcLength);
02085 
02097   inline UnicodeString& replace(int32_t start, 
02098              int32_t length, 
02099              UChar srcChar);
02100 
02112   inline UnicodeString& replace(int32_t start, 
02113              int32_t length, 
02114              UChar32 srcChar);
02115 
02125   inline UnicodeString& replaceBetween(int32_t start, 
02126                 int32_t limit, 
02127                 const UnicodeString& srcText);
02128 
02143   inline UnicodeString& replaceBetween(int32_t start, 
02144                 int32_t limit, 
02145                 const UnicodeString& srcText, 
02146                 int32_t srcStart, 
02147                 int32_t srcLimit);
02148 
02159   virtual void handleReplaceBetween(int32_t start,
02160                                     int32_t limit,
02161                                     const UnicodeString& text);
02162 
02167   virtual UBool hasMetaData() const;
02168   
02184   virtual void copy(int32_t start, int32_t limit, int32_t dest);
02185 
02186   /* Search and replace operations */
02187 
02196   inline UnicodeString& findAndReplace(const UnicodeString& oldText,
02197                 const UnicodeString& newText);
02198 
02210   inline UnicodeString& findAndReplace(int32_t start,
02211                 int32_t length,
02212                 const UnicodeString& oldText,
02213                 const UnicodeString& newText);
02214 
02232   UnicodeString& findAndReplace(int32_t start,
02233                 int32_t length,
02234                 const UnicodeString& oldText,
02235                 int32_t oldStart,
02236                 int32_t oldLength,
02237                 const UnicodeString& newText,
02238                 int32_t newStart,
02239                 int32_t newLength);
02240 
02241 
02242   /* Remove operations */
02243 
02249   inline UnicodeString& remove(void);
02250 
02259   inline UnicodeString& remove(int32_t start, 
02260                                int32_t length = (int32_t)INT32_MAX);
02261 
02270   inline UnicodeString& removeBetween(int32_t start,
02271                                       int32_t limit = (int32_t)INT32_MAX);
02272 
02273 
02274   /* Length operations */
02275 
02287   UBool padLeading(int32_t targetLength,
02288                     UChar padChar = 0x0020);
02289 
02301   UBool padTrailing(int32_t targetLength,
02302                      UChar padChar = 0x0020);
02303 
02310   inline UBool truncate(int32_t targetLength);
02311 
02317   UnicodeString& trim(void);
02318 
02319 
02320   /* Miscellaneous operations */
02321 
02327   inline UnicodeString& reverse(void);
02328 
02337   inline UnicodeString& reverse(int32_t start,
02338              int32_t length);
02339 
02346   UnicodeString& toUpper(void);
02347 
02355   UnicodeString& toUpper(const Locale& locale);
02356 
02363   UnicodeString& toLower(void);
02364 
02372   UnicodeString& toLower(const Locale& locale);
02373 
02399   UnicodeString &toTitle(BreakIterator *titleIter);
02400 
02427   UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale);
02428 
02440   UnicodeString &foldCase(uint32_t options=0 /*U_FOLD_CASE_DEFAULT*/);
02441 
02442   //========================================
02443   // Access to the internal buffer
02444   //========================================
02445 
02488   UChar *getBuffer(int32_t minCapacity);
02489 
02510   void releaseBuffer(int32_t newLength=-1);
02511 
02542   inline const UChar *getBuffer() const;
02543 
02577   inline const UChar *getTerminatedBuffer();
02578 
02579   //========================================
02580   // Constructors
02581   //========================================
02582 
02586   UnicodeString();
02587 
02599   UnicodeString(int32_t capacity, UChar32 c, int32_t count);
02600 
02606   UnicodeString(UChar ch);
02607 
02613   UnicodeString(UChar32 ch);
02614 
02621   UnicodeString(const UChar *text);
02622 
02630   UnicodeString(const UChar *text,
02631         int32_t textLength);
02632 
02652   UnicodeString(UBool isTerminated,
02653                 const UChar *text,
02654                 int32_t textLength);
02655 
02674   UnicodeString(UChar *buffer, int32_t buffLength, int32_t buffCapacity);
02675 
02687   UnicodeString(const char *codepageData,
02688         const char *codepage = 0);
02689 
02702   UnicodeString(const char *codepageData,
02703         int32_t dataLength,
02704         const char *codepage = 0);
02705 
02727   UnicodeString(
02728         const char *src, int32_t srcLength,
02729         UConverter *cnv,
02730         UErrorCode &errorCode);
02731 
02732 
02738   UnicodeString(const UnicodeString& that);
02739 
02746   UnicodeString(const UnicodeString& src, int32_t srcStart);
02747 
02755   UnicodeString(const UnicodeString& src, int32_t srcStart, int32_t srcLength);
02756 
02760   ~UnicodeString();
02761 
02762 
02763   /* Miscellaneous operations */
02764 
02787   int32_t numDisplayCells(int32_t start = 0,
02788               int32_t length = INT32_MAX,
02789               UBool asian = TRUE) const;
02790 
02798   UCharReference operator[] (int32_t pos);
02799 
02833   UnicodeString unescape() const;
02834 
02854   UChar32 unescapeAt(int32_t &offset) const;
02855 
02861   virtual inline UClassID getDynamicClassID() const { return getStaticClassID(); }
02862 
02868   static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; }
02869 
02870   //========================================
02871   // Implementation methods
02872   //========================================
02873 
02874 protected:
02878   virtual int32_t getLength() const;
02879 
02884   virtual UChar getCharAt(int32_t offset) const;
02885 
02890   virtual UChar32 getChar32At(int32_t offset) const;
02891 
02892 private:
02893 
02894   inline int8_t
02895   doCompare(int32_t start,
02896            int32_t length,
02897            const UnicodeString& srcText,
02898            int32_t srcStart,
02899            int32_t srcLength) const;
02900 
02901   int8_t doCompare(int32_t start,
02902            int32_t length,
02903            const UChar *srcChars,
02904            int32_t srcStart,
02905            int32_t srcLength) const;
02906 
02907   inline int8_t
02908   doCompareCodePointOrder(int32_t start,
02909                           int32_t length,
02910                           const UnicodeString& srcText,
02911                           int32_t srcStart,
02912                           int32_t srcLength) const;
02913 
02914   int8_t doCompareCodePointOrder(int32_t start,
02915                                  int32_t length,
02916                                  const UChar *srcChars,
02917                                  int32_t srcStart,
02918                                  int32_t srcLength) const;
02919 
02920   inline int8_t
02921   doCaseCompare(int32_t start,
02922                 int32_t length,
02923                 const UnicodeString &srcText,
02924                 int32_t srcStart,
02925                 int32_t srcLength,
02926                 uint32_t options) const;
02927 
02928   int8_t
02929   doCaseCompare(int32_t start,
02930                 int32_t length,
02931                 const UChar *srcChars,
02932                 int32_t srcStart,
02933                 int32_t srcLength,
02934                 uint32_t options) const;
02935 
02936   int32_t doIndexOf(UChar c,
02937             int32_t start,
02938             int32_t length) const;
02939 
02940   // only for c>=0xd800
02941   int32_t doIndexOf(UChar32 c,
02942                         int32_t start,
02943                         int32_t length) const;
02944 
02945   int32_t doLastIndexOf(UChar c,
02946                 int32_t start,
02947                 int32_t length) const;
02948 
02949   // only for c>=0xd800
02950   int32_t doLastIndexOf(UChar32 c,
02951                             int32_t start,
02952                             int32_t length) const;
02953 
02954   void doExtract(int32_t start, 
02955          int32_t length, 
02956          UChar *dst, 
02957          int32_t dstStart) const;
02958 
02959   inline void doExtract(int32_t start,
02960          int32_t length,
02961          UnicodeString& target) const;
02962 
02963   inline UChar doCharAt(int32_t offset)  const;
02964 
02965   UnicodeString& doReplace(int32_t start, 
02966                int32_t length, 
02967                const UnicodeString& srcText, 
02968                int32_t srcStart, 
02969                int32_t srcLength);
02970 
02971   UnicodeString& doReplace(int32_t start, 
02972                int32_t length, 
02973                const UChar *srcChars, 
02974                int32_t srcStart, 
02975                int32_t srcLength);
02976 
02977   UnicodeString& doReverse(int32_t start,
02978                int32_t length);
02979 
02980   // calculate hash code
02981   int32_t doHashCode(void) const;
02982 
02983   // get pointer to start of array
02984   inline UChar* getArrayStart(void);
02985   inline const UChar* getArrayStart(void) const;
02986 
02987   // allocate the array; result may be fStackBuffer
02988   // sets refCount to 1 if appropriate
02989   // sets fArray, fCapacity, and fFlags
02990   // returns boolean for success or failure
02991   UBool allocate(int32_t capacity);
02992 
02993   // release the array if owned
02994   void releaseArray(void);
02995 
02996   // Pin start and limit to acceptable values.
02997   inline void pinIndices(int32_t& start,
02998                          int32_t& length) const;
02999 
03000   /* Internal extract() using UConverter. */
03001   int32_t doExtract(int32_t start, int32_t length,
03002                     char *dest, int32_t destCapacity,
03003                     UConverter *cnv,
03004                     UErrorCode &errorCode) const;
03005 
03006   /*
03007    * Real constructor for converting from codepage data.
03008    * It assumes that it is called with !fRefCounted.
03009    *
03010    * If <code>codepage==0</code>, then the default converter
03011    * is used for the platform encoding.
03012    * If <code>codepage</code> is an empty string (<code>""</code>),
03013    * then a simple conversion is performed on the codepage-invariant
03014    * subset ("invariant characters") of the platform encoding. See utypes.h.
03015    */
03016   void doCodepageCreate(const char *codepageData,
03017                         int32_t dataLength,
03018                         const char *codepage);
03019 
03020   /*
03021    * Worker function for creating a UnicodeString from
03022    * a codepage string using a UConverter.
03023    */
03024   void
03025   doCodepageCreate(const char *codepageData,
03026                    int32_t dataLength,
03027                    UConverter *converter,
03028                    UErrorCode &status);
03029   /*
03030    * This function is called when write access to the array
03031    * is necessary.
03032    *
03033    * We need to make a copy of the array if
03034    * the buffer is read-only, or
03035    * the buffer is refCounted (shared), and refCount>1, or
03036    * the buffer is too small.
03037    *
03038    * Return FALSE if memory could not be allocated.
03039    */
03040   UBool cloneArrayIfNeeded(int32_t newCapacity = -1,
03041                             int32_t growCapacity = -1,
03042                             UBool doCopyArray = TRUE,
03043                             int32_t **pBufferToDelete = 0,
03044                             UBool forceClone = FALSE);
03045 
03046   // common function for case mappings
03047   UnicodeString &
03048   caseMap(BreakIterator *titleIter,
03049           const Locale& locale,
03050           uint32_t options,
03051           int32_t toWhichCase);
03052 
03053   // ref counting
03054   void addRef(void);
03055   int32_t removeRef(void);
03056   int32_t refCount(void) const;
03057   int32_t setRefCount(int32_t count);
03058 
03059   // constants
03060   enum {
03061 #if UTF_SIZE==8
03062     US_STACKBUF_SIZE=14, // Size of stack buffer for small strings
03063 #elif UTF_SIZE==16
03064     US_STACKBUF_SIZE=7, // Size of stack buffer for small strings
03065 #else // UTF_SIZE==32
03066     US_STACKBUF_SIZE=3, // Size of stack buffer for small strings
03067 #endif
03068     kInvalidUChar=0xffff, // invalid UChar index
03069     kGrowSize=128, // grow size for this buffer
03070     kInvalidHashCode=0, // invalid hash code
03071     kEmptyHashCode=1, // hash code for empty string
03072 
03073     // bit flag values for fFlags
03074     kIsBogus=1,         // this string is bogus, i.e., not valid
03075     kUsingStackBuffer=2,// fArray==fStackBuffer
03076     kRefCounted=4,      // there is a refCount field before the characters in fArray
03077     kBufferIsReadonly=8,// do not write to this buffer
03078     kOpenGetBuffer=16,  // getBuffer(minCapacity) was called (is "open"),
03079                         // and releaseBuffer(newLength) must be called
03080 
03081     // combined values for convenience
03082     kShortString=kUsingStackBuffer,
03083     kLongString=kRefCounted,
03084     kReadonlyAlias=kBufferIsReadonly,
03085     kWritableAlias=0
03086   };
03087 
03088   friend class UnicodeConverter;
03089 
03090   friend class StringCharacterIterator;
03091   friend class StringThreadTest;
03092 
03093   /*
03094    * The following are all the class fields that are stored
03095    * in each UnicodeString object.
03096    * Note that UnicodeString has virtual functions,
03097    * therefore there is an implicit vtable pointer
03098    * as the first real field.
03099    * The fields should be aligned such that no padding is
03100    * necessary, mostly by having larger types first.
03101    * On 32-bit machines, the size should be 32 bytes,
03102    * on 64-bit machines (8-byte pointers), it should be 40 bytes.
03103    */
03104   // (implicit) *vtable;
03105   int32_t   fLength;        // number of characters in fArray
03106   int32_t   fCapacity;      // sizeof fArray
03107   UChar     *fArray;        // the Unicode data
03108   uint16_t  fFlags;         // bit flags: see constants above
03109 #if UTF_SIZE==32
03110   uint16_t  fPadding;       // padding to align the fStackBuffer for UTF-32
03111 #endif
03112   UChar     fStackBuffer [ US_STACKBUF_SIZE ]; // buffer for small strings
03113 
03118   static const char fgClassID;
03119 };
03120 
03121 U_NAMESPACE_END
03122 
03123 //========================================
03124 // Array copying
03125 //========================================
03126 // Copy an array of UnicodeString OBJECTS (not pointers).
03127 inline void 
03128 uprv_arrayCopy(const U_NAMESPACE_QUALIFIER UnicodeString *src, U_NAMESPACE_QUALIFIER UnicodeString *dst, int32_t count)
03129 { while(count-- > 0) *dst++ = *src++; }
03130 
03131 inline void 
03132 uprv_arrayCopy(const U_NAMESPACE_QUALIFIER UnicodeString *src, int32_t srcStart, 
03133         U_NAMESPACE_QUALIFIER UnicodeString *dst, int32_t dstStart, int32_t count)
03134 { uprv_arrayCopy(src+srcStart, dst+dstStart, count); }
03135 
03136 U_NAMESPACE_BEGIN
03137 //========================================
03138 // Inline members
03139 //========================================
03140 
03141 //========================================
03142 // Read-only alias methods
03143 //========================================
03144 inline UBool
03145 UnicodeString::operator== (const UnicodeString& text) const
03146 {
03147   if(isBogus()) {
03148     return text.isBogus();
03149   } else {
03150     return
03151       !text.isBogus() &&
03152       fLength == text.fLength &&
03153       doCompare(0, fLength, text, 0, text.fLength) == 0;
03154   }
03155 }
03156 
03157 inline UBool
03158 UnicodeString::operator!= (const UnicodeString& text) const
03159 { return (! operator==(text)); }
03160 
03161 inline UBool
03162 UnicodeString::operator> (const UnicodeString& text) const
03163 { return doCompare(0, fLength, text, 0, text.fLength) == 1; }
03164 
03165 inline UBool
03166 UnicodeString::operator< (const UnicodeString& text) const
03167 { return doCompare(0, fLength, text, 0, text.fLength) == -1; }
03168 
03169 inline UBool
03170 UnicodeString::operator>= (const UnicodeString& text) const
03171 { return doCompare(0, fLength, text, 0, text.fLength) != -1; }
03172 
03173 inline UBool
03174 UnicodeString::operator<= (const UnicodeString& text) const
03175 { return doCompare(0, fLength, text, 0, text.fLength) != 1; }
03176 
03177 inline int8_t 
03178 UnicodeString::compare(const UnicodeString& text) const
03179 { return doCompare(0, fLength, text, 0, text.fLength); }
03180 
03181 inline int8_t 
03182 UnicodeString::compare(int32_t start,
03183                int32_t length,
03184                const UnicodeString& srcText) const
03185 { return doCompare(start, length, srcText, 0, srcText.fLength); }
03186 
03187 inline int8_t 
03188 UnicodeString::compare(const UChar *srcChars,
03189                int32_t srcLength) const
03190 { return doCompare(0, fLength, srcChars, 0, srcLength); }
03191 
03192 inline int8_t 
03193 UnicodeString::compare(int32_t start,
03194                int32_t length,
03195                const UnicodeString& srcText,
03196                int32_t srcStart,
03197                int32_t srcLength) const
03198 { return doCompare(start, length, srcText, srcStart, srcLength); }
03199 
03200 inline int8_t
03201 UnicodeString::compare(int32_t start,
03202                int32_t length,
03203                const UChar *srcChars) const
03204 { return doCompare(start, length, srcChars, 0, length); }
03205 
03206 inline int8_t 
03207 UnicodeString::compare(int32_t start,
03208                int32_t length,
03209                const UChar *srcChars,
03210                int32_t srcStart,
03211                int32_t srcLength) const
03212 { return doCompare(start, length, srcChars, srcStart, srcLength); }
03213 
03214 inline int8_t
03215 UnicodeString::compareBetween(int32_t start,
03216                   int32_t limit,
03217                   const UnicodeString& srcText,
03218                   int32_t srcStart,
03219                   int32_t srcLimit) const
03220 { return doCompare(start, limit - start, 
03221            srcText, srcStart, srcLimit - srcStart); }
03222 
03223 inline int8_t
03224 UnicodeString::doCompare(int32_t start,
03225               int32_t length,
03226               const UnicodeString& srcText,
03227               int32_t srcStart,
03228               int32_t srcLength) const
03229 {
03230   const UChar *srcChars;
03231   if(!srcText.isBogus()) {
03232     srcText.pinIndices(srcStart, srcLength);
03233     srcChars=srcText.getArrayStart();
03234   } else {
03235     srcChars=0;
03236   }
03237   return doCompare(start, length, srcChars, srcStart, srcLength);
03238 }
03239 
03240 inline int8_t 
03241 UnicodeString::compareCodePointOrder(const UnicodeString& text) const
03242 { return doCompareCodePointOrder(0, fLength, text, 0, text.fLength); }
03243 
03244 inline int8_t 
03245 UnicodeString::compareCodePointOrder(int32_t start,
03246                                      int32_t length,
03247                                      const UnicodeString& srcText) const
03248 { return doCompareCodePointOrder(start, length, srcText, 0, srcText.fLength); }
03249 
03250 inline int8_t 
03251 UnicodeString::compareCodePointOrder(const UChar *srcChars,
03252                                      int32_t srcLength) const
03253 { return doCompareCodePointOrder(0, fLength, srcChars, 0, srcLength); }
03254 
03255 inline int8_t 
03256 UnicodeString::compareCodePointOrder(int32_t start,
03257                                      int32_t length,
03258                                      const UnicodeString& srcText,
03259                                      int32_t srcStart,
03260                                      int32_t srcLength) const
03261 { return doCompareCodePointOrder(start, length, srcText, srcStart, srcLength); }
03262 
03263 inline int8_t
03264 UnicodeString::compareCodePointOrder(int32_t start,
03265                                      int32_t length,
03266                                      const UChar *srcChars) const
03267 { return doCompareCodePointOrder(start, length, srcChars, 0, length); }
03268 
03269 inline int8_t 
03270 UnicodeString::compareCodePointOrder(int32_t start,
03271                                      int32_t length,
03272                                      const UChar *srcChars,
03273                                      int32_t srcStart,
03274                                      int32_t srcLength) const
03275 { return doCompareCodePointOrder(start, length, srcChars, srcStart, srcLength); }
03276 
03277 inline int8_t
03278 UnicodeString::compareCodePointOrderBetween(int32_t start,
03279                                             int32_t limit,
03280                                             const UnicodeString& srcText,
03281                                             int32_t srcStart,
03282                                             int32_t srcLimit) const
03283 { return doCompareCodePointOrder(start, limit - start, 
03284            srcText, srcStart, srcLimit - srcStart); }
03285 
03286 inline int8_t
03287 UnicodeString::doCompareCodePointOrder(int32_t start,
03288                                        int32_t length,
03289                                        const UnicodeString& srcText,
03290                                        int32_t srcStart,
03291                                        int32_t srcLength) const
03292 {
03293   const UChar *srcChars;
03294   if(!srcText.isBogus()) {
03295     srcText.pinIndices(srcStart, srcLength);
03296     srcChars=srcText.getArrayStart();
03297   } else {
03298     srcChars=0;
03299   }
03300   return doCompareCodePointOrder(start, length, srcChars, srcStart, srcLength);
03301 }
03302 
03303 inline int8_t 
03304 UnicodeString::caseCompare(const UnicodeString &text, uint32_t options) const {
03305   return doCaseCompare(0, fLength, text, 0, text.fLength, options);
03306 }
03307 
03308 inline int8_t 
03309 UnicodeString::caseCompare(int32_t start,
03310                            int32_t length,
03311                            const UnicodeString &srcText,
03312                            uint32_t options) const {
03313   return doCaseCompare(start, length, srcText, 0, srcText.fLength, options);
03314 }
03315 
03316 inline int8_t 
03317 UnicodeString::caseCompare(const UChar *srcChars,
03318                            int32_t srcLength,
03319                            uint32_t options) const {
03320   return doCaseCompare(0, fLength, srcChars, 0, srcLength, options);
03321 }
03322 
03323 inline int8_t 
03324 UnicodeString::caseCompare(int32_t start,
03325                            int32_t length,
03326                            const UnicodeString &srcText,
03327                            int32_t srcStart,
03328                            int32_t srcLength,
03329                            uint32_t options) const {
03330   return doCaseCompare(start, length, srcText, srcStart, srcLength, options);
03331 }
03332 
03333 inline int8_t
03334 UnicodeString::caseCompare(int32_t start,
03335                            int32_t length,
03336                            const UChar *srcChars,
03337                            uint32_t options) const {
03338   return doCaseCompare(start, length, srcChars, 0, length, options);
03339 }
03340 
03341 inline int8_t 
03342 UnicodeString::caseCompare(int32_t start,
03343                            int32_t length,
03344                            const UChar *srcChars,
03345                            int32_t srcStart,
03346                            int32_t srcLength,
03347                            uint32_t options) const {
03348   return doCaseCompare(start, length, srcChars, srcStart, srcLength, options);
03349 }
03350 
03351 inline int8_t
03352 UnicodeString::caseCompareBetween(int32_t start,
03353                                   int32_t limit,
03354                                   const UnicodeString &srcText,
03355                                   int32_t srcStart,
03356                                   int32_t srcLimit,
03357                                   uint32_t options) const {
03358   return doCaseCompare(start, limit - start, srcText, srcStart, srcLimit - srcStart, options);
03359 }
03360 
03361 inline int8_t
03362 UnicodeString::doCaseCompare(int32_t start,
03363                              int32_t length,
03364                              const UnicodeString &srcText,
03365                              int32_t srcStart,
03366                              int32_t srcLength,
03367                              uint32_t options) const
03368 {
03369   const UChar *srcChars;
03370   if(!srcText.isBogus()) {
03371     srcText.pinIndices(srcStart, srcLength);
03372     srcChars=srcText.getArrayStart();
03373   } else {
03374     srcChars=0;
03375   }
03376   return doCaseCompare(start, length, srcChars, srcStart, srcLength, options);
03377 }
03378 
03379 inline int32_t 
03380 UnicodeString::indexOf(const UnicodeString& text) const
03381 { return indexOf(text, 0, text.fLength, 0, fLength); }
03382 
03383 inline int32_t 
03384 UnicodeString::indexOf(const UnicodeString& text,
03385                int32_t start) const
03386 { return indexOf(text, 0, text.fLength, start, fLength - start); }
03387 
03388 inline int32_t 
03389 UnicodeString::indexOf(const UnicodeString& text,
03390                int32_t start,
03391                int32_t length) const
03392 { return indexOf(text, 0, text.fLength, start, length); }
03393 
03394 inline int32_t 
03395 UnicodeString::indexOf(const UnicodeString& srcText,
03396                int32_t srcStart,
03397                int32_t srcLength,
03398                int32_t start,
03399                int32_t length) const
03400 {
03401   if(!srcText.isBogus()) {
03402     srcText.pinIndices(srcStart, srcLength);
03403     if(srcLength > 0) {
03404       return indexOf(srcText.getArrayStart(), srcStart, srcLength, start, length);
03405     }
03406   }
03407   return -1;
03408 }
03409 
03410 inline int32_t 
03411 UnicodeString::indexOf(const UChar *srcChars,
03412                int32_t srcLength,
03413                int32_t start) const
03414 { return indexOf(srcChars, 0, srcLength, start, fLength - start); }
03415 
03416 inline int32_t 
03417 UnicodeString::indexOf(const UChar *srcChars,
03418                int32_t srcLength,
03419                int32_t start,
03420                int32_t length) const
03421 { return indexOf(srcChars, 0, srcLength, start, length); }
03422 
03423 inline int32_t 
03424 UnicodeString::indexOf(UChar c) const
03425 { return doIndexOf(c, 0, fLength); }
03426 
03427 inline int32_t 
03428 UnicodeString::indexOf(UChar32 c) const {
03429   return indexOf(c, 0, fLength);
03430 }
03431 
03432 inline int32_t 
03433 UnicodeString::indexOf(UChar c,
03434                int32_t start) const
03435 { return doIndexOf(c, start, fLength - start); }
03436 
03437 inline int32_t 
03438 UnicodeString::indexOf(UChar32 c,
03439                int32_t start) const {
03440   return indexOf(c, start, fLength - start);
03441 }
03442 
03443 inline int32_t 
03444 UnicodeString::indexOf(UChar c,
03445                int32_t start,
03446                int32_t length) const
03447 { return doIndexOf(c, start, length); }
03448 
03449 inline int32_t 
03450 UnicodeString::indexOf(UChar32 c,
03451                int32_t start,
03452                int32_t length) const {
03453   if((uint32_t)c<0xd800) {
03454     return doIndexOf((UChar)c, start, length);
03455   } else {
03456     return doIndexOf(c, start, length);
03457   }
03458 }
03459 
03460 inline int32_t 
03461 UnicodeString::lastIndexOf(const UnicodeString& text) const
03462 { return lastIndexOf(text, 0, text.fLength, 0, fLength); }
03463 
03464 inline int32_t 
03465 UnicodeString::lastIndexOf(const UnicodeString& text,
03466                int32_t start) const
03467 { return lastIndexOf(text, 0, text.fLength, start, fLength - start); }
03468 
03469 inline int32_t 
03470 UnicodeString::lastIndexOf(const UnicodeString& text,
03471                int32_t start,
03472                int32_t length) const
03473 { return lastIndexOf(text, 0, text.fLength, start, length); }
03474 
03475 inline int32_t 
03476 UnicodeString::lastIndexOf(const UnicodeString& srcText,
03477                int32_t srcStart,
03478                int32_t srcLength,
03479                int32_t start,
03480                int32_t length) const
03481 {
03482   if(!srcText.isBogus()) {
03483     srcText.pinIndices(srcStart, srcLength);
03484     if(srcLength > 0) {
03485       return lastIndexOf(srcText.getArrayStart(), srcStart, srcLength, start, length);
03486     }
03487   }
03488   return -1;
03489 }
03490 
03491 inline int32_t 
03492 UnicodeString::lastIndexOf(const UChar *srcChars,
03493                int32_t srcLength,
03494                int32_t start) const
03495 { return lastIndexOf(srcChars, 0, srcLength, start, fLength - start); }
03496 
03497 inline int32_t 
03498 UnicodeString::lastIndexOf(const UChar *srcChars,
03499                int32_t srcLength,
03500                int32_t start,
03501                int32_t length) const
03502 { return lastIndexOf(srcChars, 0, srcLength, start, length); }
03503 
03504 inline int32_t 
03505 UnicodeString::lastIndexOf(UChar c) const
03506 { return doLastIndexOf(c, 0, fLength); }
03507 
03508 inline int32_t 
03509 UnicodeString::lastIndexOf(UChar32 c) const {
03510   return lastIndexOf(c, 0, fLength);
03511 }
03512 
03513 inline int32_t 
03514 UnicodeString::lastIndexOf(UChar c,
03515                int32_t start) const
03516 { return doLastIndexOf(c, start, fLength - start); }
03517 
03518 inline int32_t 
03519 UnicodeString::lastIndexOf(UChar32 c,
03520                int32_t start) const {
03521   return lastIndexOf(c, start, fLength - start);
03522 }
03523 
03524 inline int32_t 
03525 UnicodeString::lastIndexOf(UChar c,
03526                int32_t start,
03527                int32_t length) const
03528 { return doLastIndexOf(c, start, length); }
03529 
03530 inline int32_t 
03531 UnicodeString::lastIndexOf(UChar32 c,
03532                int32_t start,
03533                int32_t length) const {
03534   if((uint32_t)c<0xd800) {
03535     return doLastIndexOf((UChar)c, start, length);
03536   } else {
03537     return doLastIndexOf(c, start, length);
03538   }
03539 }
03540 
03541 inline UBool 
03542 UnicodeString::startsWith(const UnicodeString& text) const
03543 { return compare(0, text.fLength, text, 0, text.fLength) == 0; }
03544 
03545 inline UBool 
03546 UnicodeString::startsWith(const UnicodeString& srcText,
03547               int32_t srcStart,
03548               int32_t srcLength) const
03549 { return doCompare(0, srcLength, srcText, srcStart, srcLength) == 0; }
03550 
03551 inline UBool 
03552 UnicodeString::startsWith(const UChar *srcChars,
03553               int32_t srcLength) const
03554 { return doCompare(0, srcLength, srcChars, 0, srcLength) == 0; }
03555 
03556 inline UBool 
03557 UnicodeString::startsWith(const UChar *srcChars,
03558               int32_t srcStart,
03559               int32_t srcLength) const
03560 { return doCompare(0, srcLength, srcChars, srcStart, srcLength) == 0;}
03561 
03562 inline UBool 
03563 UnicodeString::endsWith(const UnicodeString& text) const
03564 { return doCompare(fLength - text.fLength, text.fLength, 
03565            text, 0, text.fLength) == 0; }
03566 
03567 inline UBool 
03568 UnicodeString::endsWith(const UnicodeString& srcText,
03569             int32_t srcStart,
03570             int32_t srcLength) const
03571 { return doCompare(fLength - srcLength, srcLength, 
03572            srcText, srcStart, srcLength) == 0; }
03573 
03574 inline UBool 
03575 UnicodeString::endsWith(const UChar *srcChars,
03576             int32_t srcLength) const
03577 { return doCompare(fLength - srcLength, srcLength, 
03578            srcChars, 0, srcLength) == 0; }
03579 
03580 inline UBool 
03581 UnicodeString::endsWith(const UChar *srcChars,
03582             int32_t srcStart,
03583             int32_t srcLength) const
03584 { return doCompare(fLength - srcLength, srcLength, 
03585            srcChars, srcStart, srcLength) == 0;}
03586 //========================================
03587 // replace
03588 //========================================
03589 inline UnicodeString& 
03590 UnicodeString::replace(int32_t start, 
03591                int32_t length, 
03592                const UnicodeString& srcText) 
03593 { return doReplace(start, length, srcText, 0, srcText.fLength); }
03594 
03595 inline UnicodeString& 
03596 UnicodeString::replace(int32_t start, 
03597                int32_t length, 
03598                const UnicodeString& srcText, 
03599                int32_t srcStart, 
03600                int32_t srcLength)
03601 { return doReplace(start, length, srcText, srcStart, srcLength); }
03602 
03603 inline UnicodeString& 
03604 UnicodeString::replace(int32_t start, 
03605                int32_t length, 
03606                const UChar *srcChars,
03607                int32_t srcLength)
03608 { return doReplace(start, length, srcChars, 0, srcLength); }
03609 
03610 inline UnicodeString& 
03611 UnicodeString::replace(int32_t start, 
03612                int32_t length, 
03613                const UChar *srcChars, 
03614                int32_t srcStart, 
03615                int32_t srcLength)
03616 { return doReplace(start, length, srcChars, srcStart, srcLength); }
03617 
03618 inline UnicodeString& 
03619 UnicodeString::replace(int32_t start, 
03620                int32_t length, 
03621                UChar srcChar)
03622 { return doReplace(start, length, &srcChar, 0, 1); }
03623 
03624 inline UnicodeString&
03625 UnicodeString::replace(int32_t start, 
03626                int32_t length, 
03627                UChar32 srcChar) {
03628   UChar buffer[UTF_MAX_CHAR_LENGTH];
03629   int32_t count = 0;
03630   UTF_APPEND_CHAR_UNSAFE(buffer, count, srcChar);
03631   return doReplace(start, length, buffer, 0, count);
03632 }
03633 
03634 inline UnicodeString& 
03635 UnicodeString::replaceBetween(int32_t start, 
03636                   int32_t limit, 
03637                   const UnicodeString& srcText)
03638 { return doReplace(start, limit - start, srcText, 0, srcText.fLength); }
03639 
03640 inline UnicodeString&
03641 UnicodeString::replaceBetween(int32_t start, 
03642                   int32_t limit, 
03643                   const UnicodeString& srcText, 
03644                   int32_t srcStart, 
03645                   int32_t srcLimit)
03646 { return doReplace(start, limit - start, srcText, srcStart, srcLimit - srcStart); }
03647 
03648 inline UnicodeString& 
03649 UnicodeString::findAndReplace(const UnicodeString& oldText,
03650                   const UnicodeString& newText)
03651 { return findAndReplace(0, fLength, oldText, 0, oldText.fLength, 
03652             newText, 0, newText.fLength); }
03653 
03654 inline UnicodeString& 
03655 UnicodeString::findAndReplace(int32_t start,
03656                   int32_t length,
03657                   const UnicodeString& oldText,
03658                   const UnicodeString& newText)
03659 { return findAndReplace(start, length, oldText, 0, oldText.fLength, 
03660             newText, 0, newText.fLength); }
03661 
03662 // ============================
03663 // extract
03664 // ============================
03665 inline void
03666 UnicodeString::doExtract(int32_t start,
03667              int32_t length,
03668              UnicodeString& target) const
03669 { target.replace(0, target.fLength, *this, start, length); }
03670 
03671 inline void  
03672 UnicodeString::extract(int32_t start, 
03673                int32_t length, 
03674                UChar *target, 
03675                int32_t targetStart) const
03676 { doExtract(start, length, target, targetStart); }
03677 
03678 inline void 
03679 UnicodeString::extract(int32_t start,
03680                int32_t length,
03681                UnicodeString& target) const
03682 { doExtract(start, length, target); }
03683 
03684 inline int32_t
03685 UnicodeString::extract(int32_t start,
03686                int32_t length,
03687                char *dst,
03688                const char *codepage) const
03689 
03690 {
03691   // This dstSize value will be checked explicitly
03692   return extract(start, length, dst, dst!=0 ? 0xffffffff : 0, codepage);
03693 }
03694 
03695 inline void  
03696 UnicodeString::extractBetween(int32_t start, 
03697                   int32_t limit, 
03698                   UChar *dst, 
03699                   int32_t dstStart) const
03700 { doExtract(start, limit - start, dst, dstStart); }
03701 
03702 inline UChar
03703 UnicodeString::doCharAt(int32_t offset) const
03704 {
03705   if((uint32_t)offset < (uint32_t)fLength) {
03706     return fArray[offset];
03707   } else {
03708     return kInvalidUChar;
03709   }
03710 }
03711 
03712 inline UChar
03713 UnicodeString::charAt(int32_t offset) const
03714 { return doCharAt(offset); }
03715 
03716 inline UChar
03717 UnicodeString::operator[] (int32_t offset) const
03718 { return doCharAt(offset); }
03719 
03720 inline UChar32
03721 UnicodeString::char32At(int32_t offset) const
03722 {
03723   if((uint32_t)offset < (uint32_t)fLength) {
03724     UChar32 c;
03725     UTF_GET_CHAR(fArray, 0, offset, fLength, c);
03726     return c;
03727   } else {
03728     return kInvalidUChar;
03729   }
03730 }
03731 
03732 inline int32_t
03733 UnicodeString::getChar32Start(int32_t offset) const {
03734   if((uint32_t)offset < (uint32_t)fLength) {
03735     UTF_SET_CHAR_START(fArray, 0, offset);
03736     return offset;
03737   } else {
03738     return 0;
03739   }
03740 }
03741 
03742 inline int32_t
03743 UnicodeString::getChar32Limit(int32_t offset) const {
03744   if((uint32_t)offset < (uint32_t)fLength) {
03745     UTF_SET_CHAR_LIMIT(fArray, 0, offset, fLength);
03746     return offset;
03747   } else {
03748     return fLength;
03749   }
03750 }
03751 
03752 inline int32_t
03753 UnicodeString::getCharStart(int32_t offset) const {
03754   return getChar32Start(offset);
03755 }
03756 
03757 inline int32_t
03758 UnicodeString::getCharLimit(int32_t offset) const {
03759   return getChar32Limit(offset);
03760 }
03761 
03762 inline UBool
03763 UnicodeString::isEmpty() const {
03764   return fLength == 0;
03765 }
03766 
03767 inline UBool
03768 UnicodeString::empty() const {
03769   return isEmpty();
03770 }
03771 
03772 //========================================
03773 // Read-only implementation methods
03774 //========================================
03775 inline int32_t  
03776 UnicodeString::length() const
03777 { return fLength; }
03778 
03779 inline int32_t 
03780 UnicodeString::getCapacity() const
03781 { return fCapacity; }
03782 
03783 inline int32_t 
03784 UnicodeString::hashCode() const
03785 { return doHashCode(); }
03786 
03787 inline UBool 
03788 UnicodeString::isBogus() const
03789 { return (UBool)(fFlags & kIsBogus); }
03790 
03791 inline const UChar *
03792 UnicodeString::getBuffer() const {
03793   if(!(fFlags&(kIsBogus|kOpenGetBuffer))) {
03794     return fArray;
03795   } else {
03796     return 0;
03797   }
03798 }
03799 
03800 //========================================
03801 // Write implementation methods
03802 //========================================
03803 inline const UChar *
03804 UnicodeString::getTerminatedBuffer() {
03805   if(fFlags&(kIsBogus|kOpenGetBuffer)) {
03806     return 0;
03807   } else if(fLength<fCapacity && fArray[fLength]==0) {
03808     return fArray;
03809   } else if(cloneArrayIfNeeded(fLength+1)) {
03810     fArray[fLength]=0;
03811     return fArray;
03812   } else {
03813     return 0;
03814   }
03815 }
03816 
03817 inline UnicodeString& 
03818 UnicodeString::operator= (UChar ch) 
03819 { return doReplace(0, fLength, &ch, 0, 1); }
03820 
03821 inline UnicodeString& 
03822 UnicodeString::operator= (UChar32 ch) 
03823 { return replace(0, fLength, ch); }
03824 
03825 inline UnicodeString& 
03826 UnicodeString::setTo(const UnicodeString& srcText, 
03827              int32_t srcStart, 
03828              int32_t srcLength)
03829 { return doReplace(0, fLength, srcText, srcStart, srcLength); }
03830 
03831 inline UnicodeString& 
03832 UnicodeString::setTo(const UnicodeString& srcText, 
03833              int32_t srcStart)
03834 { return doReplace(0, fLength, srcText, srcStart, srcText.fLength - srcStart); }
03835 
03836 inline UnicodeString& 
03837 UnicodeString::setTo(const UnicodeString& srcText)
03838 { return doReplace(0, fLength, srcText, 0, srcText.fLength); }
03839 
03840 inline UnicodeString& 
03841 UnicodeString::setTo(const UChar *srcChars,
03842              int32_t srcLength)
03843 { return doReplace(0, fLength, srcChars, 0, srcLength); }
03844 
03845 inline UnicodeString& 
03846 UnicodeString::setTo(UChar srcChar)
03847 { return doReplace(0, fLength, &srcChar, 0, 1); }
03848 
03849 inline UnicodeString& 
03850 UnicodeString::setTo(UChar32 srcChar)
03851 { return replace(0, fLength, srcChar); }
03852 
03853 inline UnicodeString& 
03854 UnicodeString::operator+= (UChar ch)
03855 { return doReplace(fLength, 0, &ch, 0, 1); }
03856 
03857 inline UnicodeString& 
03858 UnicodeString::operator+= (UChar32 ch) {
03859   UChar buffer[UTF_MAX_CHAR_LENGTH];
03860   int32_t length = 0;
03861   UTF_APPEND_CHAR_UNSAFE(buffer, length, ch);
03862   return doReplace(fLength, 0, buffer, 0, length);
03863 }
03864 
03865 inline UnicodeString& 
03866 UnicodeString::operator+= (const UnicodeString& srcText)
03867 { return doReplace(fLength, 0, srcText, 0, srcText.fLength); }
03868 
03869 inline UnicodeString& 
03870 UnicodeString::append(const UnicodeString& srcText, 
03871               int32_t srcStart, 
03872               int32_t srcLength)
03873 { return doReplace(fLength, 0, srcText, srcStart, srcLength); }
03874 
03875 inline UnicodeString& 
03876 UnicodeString::append(const UnicodeString& srcText)
03877 { return doReplace(fLength, 0, srcText, 0, srcText.fLength); }
03878 
03879 inline UnicodeString& 
03880 UnicodeString::append(const UChar *srcChars, 
03881               int32_t srcStart, 
03882               int32_t srcLength)
03883 { return doReplace(fLength, 0, srcChars, srcStart, srcLength); }
03884 
03885 inline UnicodeString& 
03886 UnicodeString::append(const UChar *srcChars,
03887               int32_t srcLength)
03888 { return doReplace(fLength, 0, srcChars, 0, srcLength); }
03889 
03890 inline UnicodeString& 
03891 UnicodeString::append(UChar srcChar)
03892 { return doReplace(fLength, 0, &srcChar, 0, 1); }
03893 
03894 inline UnicodeString& 
03895 UnicodeString::append(UChar32 srcChar) {
03896   UChar buffer[UTF_MAX_CHAR_LENGTH];
03897   int32_t length = 0;
03898   UTF_APPEND_CHAR_UNSAFE(buffer, length, srcChar);
03899   return doReplace(fLength, 0, buffer, 0, length);
03900 }
03901 
03902 inline UnicodeString& 
03903 UnicodeString::insert(int32_t start, 
03904               const UnicodeString& srcText, 
03905               int32_t srcStart, 
03906               int32_t srcLength)
03907 { return doReplace(start, 0, srcText, srcStart, srcLength); }
03908 
03909 inline UnicodeString& 
03910 UnicodeString::insert(int32_t start, 
03911               const UnicodeString& srcText)
03912 { return doReplace(start, 0, srcText, 0, srcText.fLength); }
03913 
03914 inline UnicodeString& 
03915 UnicodeString::insert(int32_t start, 
03916               const UChar *srcChars, 
03917               int32_t srcStart, 
03918               int32_t srcLength)
03919 { return doReplace(start, 0, srcChars, srcStart, srcLength); }
03920 
03921 inline UnicodeString& 
03922 UnicodeString::insert(int32_t start, 
03923               const UChar *srcChars,
03924               int32_t srcLength)
03925 { return doReplace(start, 0, srcChars, 0, srcLength); }
03926 
03927 inline UnicodeString& 
03928 UnicodeString::insert(int32_t start, 
03929               UChar srcChar)
03930 { return doReplace(start, 0, &srcChar, 0, 1); }
03931 
03932 inline UnicodeString& 
03933 UnicodeString::insert(int32_t start, 
03934               UChar32 srcChar)
03935 { return replace(start, 0, srcChar); }
03936 
03937 
03938 inline UnicodeString& 
03939 UnicodeString::remove(int32_t start, 
03940              int32_t length)
03941 { return doReplace(start, length, NULL, 0, 0); }
03942 
03943 inline UnicodeString& 
03944 UnicodeString::remove()
03945 { return doReplace(0, fLength, 0, 0, 0); }
03946 
03947 inline UnicodeString& 
03948 UnicodeString::removeBetween(int32_t start,
03949                 int32_t limit)
03950 { return doReplace(start, limit - start, NULL, 0, 0); }
03951 
03952 inline UBool 
03953 UnicodeString::truncate(int32_t targetLength)
03954 {
03955   if((uint32_t)targetLength < (uint32_t)fLength) {
03956     fLength = targetLength;
03957     return TRUE;
03958   } else {
03959     return FALSE;
03960   }
03961 }
03962 
03963 inline UnicodeString& 
03964 UnicodeString::reverse()
03965 { return doReverse(0, fLength); }
03966 
03967 inline UnicodeString& 
03968 UnicodeString::reverse(int32_t start,
03969                int32_t length)
03970 { return doReverse(start, length); }
03971 
03972 
03973 //========================================
03974 // Privates
03975 //========================================
03976 
03977 inline void
03978 UnicodeString::pinIndices(int32_t& start,
03979                           int32_t& length) const
03980 {
03981   // pin indices
03982   if(start < 0) {
03983     start = 0;
03984   } else if(start > fLength) {
03985     start = fLength;
03986   }
03987   if(length < 0) {
03988     length = 0;
03989   } else if(length > (fLength - start)) {
03990     length = (fLength - start);
03991   }
03992 }
03993 
03994 inline UChar* 
03995 UnicodeString::getArrayStart()
03996 { return fArray; }
03997 
03998 inline const UChar* 
03999 UnicodeString::getArrayStart() const
04000 { return fArray; }
04001 
04002 
04003 //========================================
04004 // class UCharReference
04005 //========================================
04006 
04012 class U_COMMON_API UCharReference : public UObject {
04013 public:
04014   UCharReference();
04015   inline UCharReference(UnicodeString *string,
04016          int32_t pos);
04017   inline UCharReference(const UCharReference& that);
04018   ~UCharReference();
04019 
04020   inline UCharReference& operator= (const UCharReference& that);
04021   inline UCharReference& operator= (UChar c);
04022 
04023   inline operator UChar();
04024 
04030   virtual inline UClassID getDynamicClassID() const { return getStaticClassID(); }
04031 
04037   static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; }
04038 
04039 private:
04040   UnicodeString *fString;
04041   int32_t fPos;
04042 
04047   static const char fgClassID;
04048 };
04049 
04050 
04051 //========================================
04052 // Inline members
04053 //========================================
04054 inline
04055 UCharReference::UCharReference(UnicodeString *string, 
04056                    int32_t pos)
04057   : UObject(), fString(string), fPos(pos)
04058 {}
04059 
04060 inline
04061 UCharReference::UCharReference(const UCharReference& that)
04062 : UObject(that)
04063 { this->operator=(that); }
04064 
04065 inline
04066 UCharReference::~UCharReference()
04067 {}
04068 
04069 inline UCharReference&
04070 UCharReference::operator= (const UCharReference& that)
04071 { fString->setCharAt(fPos, that.fString->charAt(that.fPos)); return *this; }
04072 
04073 inline UCharReference& 
04074 UCharReference::operator= (UChar c)
04075 { fString->setCharAt(fPos, c); return *this; }
04076 
04077 inline
04078 UCharReference::operator UChar()
04079 { return fString->charAt(fPos); }
04080 
04081 U_NAMESPACE_END
04082 
04083 #endif

Generated on Thu Aug 15 14:13:33 2002 for ICU 2.2 by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001