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 #ifndef USTRING_H
00042 /* see ustring.h */
00043 U_CAPI int32_t U_EXPORT2
00044 u_strlen(const UChar *s);
00045 #endif
00046 
00047 U_NAMESPACE_BEGIN
00048 
00049 class Locale;               // unicode/locid.h
00050 class UCharReference;
00051 class StringCharacterIterator;
00052 class BreakIterator;        // unicode/brkiter.h
00053 
00054 #ifdef ICU_UNICODECONVERTER_USE_DEPRECATES
00055 class UnicodeConverter;     // unicode/convert.h
00056 #endif
00057 
00058 /* The <iostream> include has been moved to unicode/ustream.h */
00059 
00077 #if U_SIZEOF_WCHAR_T==U_SIZEOF_UCHAR && U_CHARSET_FAMILY==U_ASCII_FAMILY
00078 #   define UNICODE_STRING(cs, length) UnicodeString(TRUE, (const UChar *)L ## cs, length)
00079 #elif U_SIZEOF_UCHAR==1 && U_CHARSET_FAMILY==U_ASCII_FAMILY
00080 #   define UNICODE_STRING(cs, length) UnicodeString(TRUE, (const UChar *)cs, length)
00081 #else
00082 #   define UNICODE_STRING(cs, length) UnicodeString(cs, length, "")
00083 #endif
00084 
00098 #if U_SIZEOF_WCHAR_T==U_SIZEOF_UCHAR && U_CHARSET_FAMILY==U_ASCII_FAMILY
00099 #   define UNICODE_STRING_SIMPLE(cs) UnicodeString(TRUE, (const UChar *)L ## cs, -1)
00100 #elif U_SIZEOF_UCHAR==1 && U_CHARSET_FAMILY==U_ASCII_FAMILY
00101 #   define UNICODE_STRING_SIMPLE(cs) UnicodeString(TRUE, (const UChar *)cs, -1)
00102 #else
00103 #   define UNICODE_STRING_SIMPLE(cs) UnicodeString(cs, "")
00104 #endif
00105 
00145 class U_COMMON_API UnicodeString : public Replaceable
00146 {
00147 public:
00148 
00149   //========================================
00150   // Read-only operations
00151   //========================================
00152 
00153   /* Comparison - bitwise only - for international comparison use collation */
00154 
00162   inline UBool operator== (const UnicodeString& text) const;
00163 
00171   inline UBool operator!= (const UnicodeString& text) const;
00172 
00180   inline UBool operator> (const UnicodeString& text) const;
00181 
00189   inline UBool operator< (const UnicodeString& text) const;
00190 
00198   inline UBool operator>= (const UnicodeString& text) const;
00199 
00207   inline UBool operator<= (const UnicodeString& text) const;
00208 
00220   inline int8_t compare(const UnicodeString& text) const;
00221 
00236   inline int8_t compare(int32_t start,
00237          int32_t length,
00238          const UnicodeString& srcText) const;
00239 
00257    inline int8_t compare(int32_t start,
00258          int32_t length,
00259          const UnicodeString& srcText,
00260          int32_t srcStart,
00261          int32_t srcLength) const;
00262 
00275   inline int8_t compare(const UChar *srcChars,
00276          int32_t srcLength) const;
00277 
00292   inline int8_t compare(int32_t start,
00293          int32_t length,
00294          const UChar *srcChars) const;
00295 
00313   inline int8_t compare(int32_t start,
00314          int32_t length,
00315          const UChar *srcChars,
00316          int32_t srcStart,
00317          int32_t srcLength) const;
00318 
00336   inline int8_t compareBetween(int32_t start,
00337             int32_t limit,
00338             const UnicodeString& srcText,
00339             int32_t srcStart,
00340             int32_t srcLimit) const;
00341 
00359   inline int8_t compareCodePointOrder(const UnicodeString& text) const;
00360 
00380   inline int8_t compareCodePointOrder(int32_t start,
00381                                       int32_t length,
00382                                       const UnicodeString& srcText) const;
00383 
00405    inline int8_t compareCodePointOrder(int32_t start,
00406                                        int32_t length,
00407                                        const UnicodeString& srcText,
00408                                        int32_t srcStart,
00409                                        int32_t srcLength) const;
00410 
00429   inline int8_t compareCodePointOrder(const UChar *srcChars,
00430                                       int32_t srcLength) const;
00431 
00451   inline int8_t compareCodePointOrder(int32_t start,
00452                                       int32_t length,
00453                                       const UChar *srcChars) const;
00454 
00476   inline int8_t compareCodePointOrder(int32_t start,
00477                                       int32_t length,
00478                                       const UChar *srcChars,
00479                                       int32_t srcStart,
00480                                       int32_t srcLength) const;
00481 
00503   inline int8_t compareCodePointOrderBetween(int32_t start,
00504                                              int32_t limit,
00505                                              const UnicodeString& srcText,
00506                                              int32_t srcStart,
00507                                              int32_t srcLimit) const;
00508 
00527   inline int8_t caseCompare(const UnicodeString& text, uint32_t options) const;
00528 
00549   inline int8_t caseCompare(int32_t start,
00550          int32_t length,
00551          const UnicodeString& srcText,
00552          uint32_t options) const;
00553 
00576   inline int8_t caseCompare(int32_t start,
00577          int32_t length,
00578          const UnicodeString& srcText,
00579          int32_t srcStart,
00580          int32_t srcLength,
00581          uint32_t options) const;
00582 
00602   inline int8_t caseCompare(const UChar *srcChars,
00603          int32_t srcLength,
00604          uint32_t options) const;
00605 
00626   inline int8_t caseCompare(int32_t start,
00627          int32_t length,
00628          const UChar *srcChars,
00629          uint32_t options) const;
00630 
00653   inline int8_t caseCompare(int32_t start,
00654          int32_t length,
00655          const UChar *srcChars,
00656          int32_t srcStart,
00657          int32_t srcLength,
00658          uint32_t options) const;
00659 
00682   inline int8_t caseCompareBetween(int32_t start,
00683             int32_t limit,
00684             const UnicodeString& srcText,
00685             int32_t srcStart,
00686             int32_t srcLimit,
00687             uint32_t options) const;
00688 
00696   inline UBool startsWith(const UnicodeString& text) const;
00697 
00708   inline UBool startsWith(const UnicodeString& srcText,
00709             int32_t srcStart,
00710             int32_t srcLength) const;
00711 
00720   inline UBool startsWith(const UChar *srcChars,
00721             int32_t srcLength) const;
00722 
00732   inline UBool startsWith(const UChar *srcChars,
00733             int32_t srcStart,
00734             int32_t srcLength) const;
00735 
00743   inline UBool endsWith(const UnicodeString& text) const;
00744 
00755   inline UBool endsWith(const UnicodeString& srcText,
00756           int32_t srcStart,
00757           int32_t srcLength) const;
00758 
00767   inline UBool endsWith(const UChar *srcChars,
00768           int32_t srcLength) const;
00769 
00780   inline UBool endsWith(const UChar *srcChars,
00781           int32_t srcStart,
00782           int32_t srcLength) const;
00783 
00784 
00785   /* Searching - bitwise only */
00786 
00795   inline int32_t indexOf(const UnicodeString& text) const;
00796 
00806   inline int32_t indexOf(const UnicodeString& text,
00807               int32_t start) const;
00808 
00820   inline int32_t indexOf(const UnicodeString& text,
00821               int32_t start,
00822               int32_t length) const;
00823 
00840   inline int32_t indexOf(const UnicodeString& srcText,
00841               int32_t srcStart,
00842               int32_t srcLength,
00843               int32_t start,
00844               int32_t length) const;
00845 
00857   inline int32_t indexOf(const UChar *srcChars,
00858               int32_t srcLength,
00859               int32_t start) const;
00860 
00873   inline int32_t indexOf(const UChar *srcChars,
00874               int32_t srcLength,
00875               int32_t start,
00876               int32_t length) const;
00877  
00894   int32_t indexOf(const UChar *srcChars,
00895               int32_t srcStart,
00896               int32_t srcLength,
00897               int32_t start,
00898               int32_t length) const;
00899 
00907   inline int32_t indexOf(UChar c) const;
00908 
00917   inline int32_t indexOf(UChar32 c) const;
00918 
00927   inline int32_t indexOf(UChar c,
00928               int32_t start) const;
00929 
00939   inline int32_t indexOf(UChar32 c,
00940               int32_t start) const;
00941 
00952   inline int32_t indexOf(UChar c,
00953               int32_t start,
00954               int32_t length) const;
00955 
00967   inline int32_t indexOf(UChar32 c,
00968               int32_t start,
00969               int32_t length) const;
00970 
00979   inline int32_t lastIndexOf(const UnicodeString& text) const;
00980 
00990   inline int32_t lastIndexOf(const UnicodeString& text,
00991               int32_t start) const;
00992 
01004   inline int32_t lastIndexOf(const UnicodeString& text,
01005               int32_t start,
01006               int32_t length) const;
01007 
01024   inline int32_t lastIndexOf(const UnicodeString& srcText,
01025               int32_t srcStart,
01026               int32_t srcLength,
01027               int32_t start,
01028               int32_t length) const;
01029 
01040   inline int32_t lastIndexOf(const UChar *srcChars,
01041               int32_t srcLength,
01042               int32_t start) const;
01043 
01056   inline int32_t lastIndexOf(const UChar *srcChars,
01057               int32_t srcLength,
01058               int32_t start,
01059               int32_t length) const;
01060  
01077   int32_t lastIndexOf(const UChar *srcChars,
01078               int32_t srcStart,
01079               int32_t srcLength,
01080               int32_t start,
01081               int32_t length) const;
01082 
01090   inline int32_t lastIndexOf(UChar c) const;
01091 
01100   inline int32_t lastIndexOf(UChar32 c) const;
01101 
01110   inline int32_t lastIndexOf(UChar c,
01111               int32_t start) const;
01112 
01122   inline int32_t lastIndexOf(UChar32 c,
01123               int32_t start) const;
01124 
01135   inline int32_t lastIndexOf(UChar c,
01136               int32_t start,
01137               int32_t length) const;
01138 
01150   inline int32_t lastIndexOf(UChar32 c,
01151               int32_t start,
01152               int32_t length) const;
01153 
01154 
01155   /* Character access */
01156 
01165   inline UChar charAt(int32_t offset) const;
01166 
01174   inline UChar operator[] (int32_t offset) const;
01175 
01187   inline UChar32 char32At(int32_t offset) const;
01188 
01204   inline int32_t getChar32Start(int32_t offset) const;
01205 
01222   inline int32_t getChar32Limit(int32_t offset) const;
01223 
01224 #ifdef ICU_UNICODESTRING_USE_DEPRECATES
01246   inline int32_t getCharStart(int32_t offset) const;
01247 
01270   inline int32_t getCharLimit(int32_t offset) const;
01271 
01281   inline UBool empty(void) const;
01282 #endif
01283 
01334   int32_t moveIndex32(int32_t index, int32_t delta) const;
01335 
01336   /* Substring extraction */
01337 
01353   inline void extract(int32_t start, 
01354            int32_t length, 
01355            UChar *dst, 
01356            int32_t dstStart = 0) const;
01357 
01379   int32_t
01380   extract(UChar *dest, int32_t destCapacity,
01381           UErrorCode &errorCode) const;
01382 
01393   inline void extract(int32_t start,
01394            int32_t length,
01395            UnicodeString& target) const;
01396 
01408   inline void extractBetween(int32_t start, 
01409               int32_t limit, 
01410               UChar *dst, 
01411               int32_t dstStart = 0) const;
01412 
01422   virtual void extractBetween(int32_t start,
01423               int32_t limit,
01424               UnicodeString& target) const;
01425 
01446   inline int32_t extract(int32_t start,
01447                  int32_t startLength,
01448                  char *target,
01449                  const char *codepage = 0) const;
01450 
01475   int32_t extract(int32_t start,
01476            int32_t startLength,
01477            char *target,
01478            uint32_t targetLength,
01479            const char *codepage = 0) const;
01480 
01498   int32_t extract(char *dest, int32_t destCapacity,
01499                   UConverter *cnv,
01500                   UErrorCode &errorCode) const;
01501 
01502   /* Length operations */
01503 
01510   inline int32_t length(void) const;
01511 
01524   int32_t
01525   countChar32(int32_t start=0, int32_t length=INT32_MAX) const;
01526 
01550   UBool
01551   hasMoreChar32Than(int32_t start, int32_t length, int32_t number) const;
01552 
01558   inline UBool isEmpty(void) const;
01559 
01569   inline int32_t getCapacity(void) const;
01570 
01571   /* Other operations */
01572 
01578   inline int32_t hashCode(void) const;
01579 
01591   inline UBool isBogus(void) const;
01592 
01593 
01594   //========================================
01595   // Write operations
01596   //========================================
01597 
01598   /* Assignment operations */
01599 
01607   UnicodeString &operator=(const UnicodeString &srcText);
01608 
01629   UnicodeString &fastCopyFrom(const UnicodeString &src);
01630 
01638   inline UnicodeString& operator= (UChar ch);
01639 
01647   inline UnicodeString& operator= (UChar32 ch);
01648 
01660   inline UnicodeString& setTo(const UnicodeString& srcText, 
01661                int32_t srcStart);
01662 
01676   inline UnicodeString& setTo(const UnicodeString& srcText, 
01677                int32_t srcStart, 
01678                int32_t srcLength);
01679 
01688   inline UnicodeString& setTo(const UnicodeString& srcText);
01689 
01698   inline UnicodeString& setTo(const UChar *srcChars,
01699                int32_t srcLength);
01700 
01709   UnicodeString& setTo(UChar srcChar);
01710 
01719   UnicodeString& setTo(UChar32 srcChar);
01720 
01741   UnicodeString &setTo(UBool isTerminated,
01742                        const UChar *text,
01743                        int32_t textLength);
01744 
01764   UnicodeString &setTo(UChar *buffer,
01765                        int32_t buffLength,
01766                        int32_t buffCapacity);
01767 
01808   void setToBogus();
01809 
01817   UnicodeString& setCharAt(int32_t offset, 
01818                UChar ch);
01819 
01820 
01821   /* Append operations */
01822 
01830  inline  UnicodeString& operator+= (UChar ch);
01831 
01839  inline  UnicodeString& operator+= (UChar32 ch);
01840 
01849   inline UnicodeString& operator+= (const UnicodeString& srcText);
01850 
01865   inline UnicodeString& append(const UnicodeString& srcText, 
01866             int32_t srcStart, 
01867             int32_t srcLength);
01868 
01876   inline UnicodeString& append(const UnicodeString& srcText);
01877 
01891   inline UnicodeString& append(const UChar *srcChars, 
01892             int32_t srcStart, 
01893             int32_t srcLength);
01894 
01903   inline UnicodeString& append(const UChar *srcChars,
01904             int32_t srcLength);
01905 
01912   inline UnicodeString& append(UChar srcChar);
01913 
01920   inline UnicodeString& append(UChar32 srcChar);
01921 
01922 
01923   /* Insert operations */
01924 
01938   inline UnicodeString& insert(int32_t start, 
01939             const UnicodeString& srcText, 
01940             int32_t srcStart, 
01941             int32_t srcLength);
01942 
01951   inline UnicodeString& insert(int32_t start, 
01952             const UnicodeString& srcText);
01953 
01967   inline UnicodeString& insert(int32_t start, 
01968             const UChar *srcChars, 
01969             int32_t srcStart, 
01970             int32_t srcLength);
01971 
01981   inline UnicodeString& insert(int32_t start, 
01982             const UChar *srcChars,
01983             int32_t srcLength);
01984 
01993   inline UnicodeString& insert(int32_t start, 
01994             UChar srcChar);
01995 
02004   inline UnicodeString& insert(int32_t start, 
02005             UChar32 srcChar);
02006 
02007 
02008   /* Replace operations */
02009 
02027   UnicodeString& replace(int32_t start, 
02028              int32_t length, 
02029              const UnicodeString& srcText, 
02030              int32_t srcStart, 
02031              int32_t srcLength);
02032 
02045   UnicodeString& replace(int32_t start, 
02046              int32_t length, 
02047              const UnicodeString& srcText);
02048 
02066   UnicodeString& replace(int32_t start, 
02067              int32_t length, 
02068              const UChar *srcChars, 
02069              int32_t srcStart, 
02070              int32_t srcLength);
02071 
02084   inline UnicodeString& replace(int32_t start, 
02085              int32_t length, 
02086              const UChar *srcChars,
02087              int32_t srcLength);
02088 
02100   inline UnicodeString& replace(int32_t start, 
02101              int32_t length, 
02102              UChar srcChar);
02103 
02115   inline UnicodeString& replace(int32_t start, 
02116              int32_t length, 
02117              UChar32 srcChar);
02118 
02128   inline UnicodeString& replaceBetween(int32_t start, 
02129                 int32_t limit, 
02130                 const UnicodeString& srcText);
02131 
02146   inline UnicodeString& replaceBetween(int32_t start, 
02147                 int32_t limit, 
02148                 const UnicodeString& srcText, 
02149                 int32_t srcStart, 
02150                 int32_t srcLimit);
02151 
02162   virtual void handleReplaceBetween(int32_t start,
02163                                     int32_t limit,
02164                                     const UnicodeString& text);
02165 
02171   virtual UBool hasMetaData() const;
02172   
02188   virtual void copy(int32_t start, int32_t limit, int32_t dest);
02189 
02190   /* Search and replace operations */
02191 
02200   inline UnicodeString& findAndReplace(const UnicodeString& oldText,
02201                 const UnicodeString& newText);
02202 
02214   inline UnicodeString& findAndReplace(int32_t start,
02215                 int32_t length,
02216                 const UnicodeString& oldText,
02217                 const UnicodeString& newText);
02218 
02236   UnicodeString& findAndReplace(int32_t start,
02237                 int32_t length,
02238                 const UnicodeString& oldText,
02239                 int32_t oldStart,
02240                 int32_t oldLength,
02241                 const UnicodeString& newText,
02242                 int32_t newStart,
02243                 int32_t newLength);
02244 
02245 
02246   /* Remove operations */
02247 
02253   inline UnicodeString& remove(void);
02254 
02263   inline UnicodeString& remove(int32_t start, 
02264                                int32_t length = (int32_t)INT32_MAX);
02265 
02274   inline UnicodeString& removeBetween(int32_t start,
02275                                       int32_t limit = (int32_t)INT32_MAX);
02276 
02277 
02278   /* Length operations */
02279 
02291   UBool padLeading(int32_t targetLength,
02292                     UChar padChar = 0x0020);
02293 
02305   UBool padTrailing(int32_t targetLength,
02306                      UChar padChar = 0x0020);
02307 
02314   inline UBool truncate(int32_t targetLength);
02315 
02321   UnicodeString& trim(void);
02322 
02323 
02324   /* Miscellaneous operations */
02325 
02331   inline UnicodeString& reverse(void);
02332 
02341   inline UnicodeString& reverse(int32_t start,
02342              int32_t length);
02343 
02350   UnicodeString& toUpper(void);
02351 
02359   UnicodeString& toUpper(const Locale& locale);
02360 
02367   UnicodeString& toLower(void);
02368 
02376   UnicodeString& toLower(const Locale& locale);
02377 
02378 #if !UCONFIG_NO_BREAK_ITERATION
02379 
02405   UnicodeString &toTitle(BreakIterator *titleIter);
02406 
02433   UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale);
02434 
02435 #endif
02436 
02448   UnicodeString &foldCase(uint32_t options=0 /*U_FOLD_CASE_DEFAULT*/);
02449 
02450   //========================================
02451   // Access to the internal buffer
02452   //========================================
02453 
02497   UChar *getBuffer(int32_t minCapacity);
02498 
02519   void releaseBuffer(int32_t newLength=-1);
02520 
02551   inline const UChar *getBuffer() const;
02552 
02586   inline const UChar *getTerminatedBuffer();
02587 
02588   //========================================
02589   // Constructors
02590   //========================================
02591 
02595   UnicodeString();
02596 
02608   UnicodeString(int32_t capacity, UChar32 c, int32_t count);
02609 
02615   UnicodeString(UChar ch);
02616 
02622   UnicodeString(UChar32 ch);
02623 
02630   UnicodeString(const UChar *text);
02631 
02639   UnicodeString(const UChar *text,
02640         int32_t textLength);
02641 
02661   UnicodeString(UBool isTerminated,
02662                 const UChar *text,
02663                 int32_t textLength);
02664 
02683   UnicodeString(UChar *buffer, int32_t buffLength, int32_t buffCapacity);
02684 
02696   UnicodeString(const char *codepageData,
02697         const char *codepage = 0);
02698 
02711   UnicodeString(const char *codepageData,
02712         int32_t dataLength,
02713         const char *codepage = 0);
02714 
02736   UnicodeString(
02737         const char *src, int32_t srcLength,
02738         UConverter *cnv,
02739         UErrorCode &errorCode);
02740 
02741 
02747   UnicodeString(const UnicodeString& that);
02748 
02755   UnicodeString(const UnicodeString& src, int32_t srcStart);
02756 
02764   UnicodeString(const UnicodeString& src, int32_t srcStart, int32_t srcLength);
02765 
02769   ~UnicodeString();
02770 
02771 
02772   /* Miscellaneous operations */
02773 
02796   int32_t numDisplayCells(int32_t start = 0,
02797               int32_t length = INT32_MAX,
02798               UBool asian = TRUE) const;
02799 
02800 #ifdef U_USE_DEPRECATED_UCHAR_REFERENCE
02813   UCharReference operator[] (int32_t pos);
02814 #endif
02815 
02850   UnicodeString unescape() const;
02851 
02871   UChar32 unescapeAt(int32_t &offset) const;
02872 
02878   virtual inline UClassID getDynamicClassID() const { return getStaticClassID(); }
02879 
02885   static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; }
02886 
02887   //========================================
02888   // Implementation methods
02889   //========================================
02890 
02891 protected:
02896   virtual int32_t getLength() const;
02897 
02903   virtual UChar getCharAt(int32_t offset) const;
02904 
02910   virtual UChar32 getChar32At(int32_t offset) const;
02911 
02912 private:
02913 
02914   inline int8_t
02915   doCompare(int32_t start,
02916            int32_t length,
02917            const UnicodeString& srcText,
02918            int32_t srcStart,
02919            int32_t srcLength) const;
02920 
02921   int8_t doCompare(int32_t start,
02922            int32_t length,
02923            const UChar *srcChars,
02924            int32_t srcStart,
02925            int32_t srcLength) const;
02926 
02927   inline int8_t
02928   doCompareCodePointOrder(int32_t start,
02929                           int32_t length,
02930                           const UnicodeString& srcText,
02931                           int32_t srcStart,
02932                           int32_t srcLength) const;
02933 
02934   int8_t doCompareCodePointOrder(int32_t start,
02935                                  int32_t length,
02936                                  const UChar *srcChars,
02937                                  int32_t srcStart,
02938                                  int32_t srcLength) const;
02939 
02940   inline int8_t
02941   doCaseCompare(int32_t start,
02942                 int32_t length,
02943                 const UnicodeString &srcText,
02944                 int32_t srcStart,
02945                 int32_t srcLength,
02946                 uint32_t options) const;
02947 
02948   int8_t
02949   doCaseCompare(int32_t start,
02950                 int32_t length,
02951                 const UChar *srcChars,
02952                 int32_t srcStart,
02953                 int32_t srcLength,
02954                 uint32_t options) const;
02955 
02956   int32_t doIndexOf(UChar c,
02957             int32_t start,
02958             int32_t length) const;
02959 
02960   int32_t doIndexOf(UChar32 c,
02961                         int32_t start,
02962                         int32_t length) const;
02963 
02964   int32_t doLastIndexOf(UChar c,
02965                 int32_t start,
02966                 int32_t length) const;
02967 
02968   int32_t doLastIndexOf(UChar32 c,
02969                             int32_t start,
02970                             int32_t length) const;
02971 
02972   void doExtract(int32_t start, 
02973          int32_t length, 
02974          UChar *dst, 
02975          int32_t dstStart) const;
02976 
02977   inline void doExtract(int32_t start,
02978          int32_t length,
02979          UnicodeString& target) const;
02980 
02981   inline UChar doCharAt(int32_t offset)  const;
02982 
02983   UnicodeString& doReplace(int32_t start, 
02984                int32_t length, 
02985                const UnicodeString& srcText, 
02986                int32_t srcStart, 
02987                int32_t srcLength);
02988 
02989   UnicodeString& doReplace(int32_t start, 
02990                int32_t length, 
02991                const UChar *srcChars, 
02992                int32_t srcStart, 
02993                int32_t srcLength);
02994 
02995   UnicodeString& doReverse(int32_t start,
02996                int32_t length);
02997 
02998   // calculate hash code
02999   int32_t doHashCode(void) const;
03000 
03001   // get pointer to start of array
03002   inline UChar* getArrayStart(void);
03003   inline const UChar* getArrayStart(void) const;
03004 
03005   // allocate the array; result may be fStackBuffer
03006   // sets refCount to 1 if appropriate
03007   // sets fArray, fCapacity, and fFlags
03008   // returns boolean for success or failure
03009   UBool allocate(int32_t capacity);
03010 
03011   // release the array if owned
03012   void releaseArray(void);
03013 
03014   // turn a bogus string into an empty one
03015   void unBogus();
03016 
03017   // implements assigment operator, copy constructor, and fastCopyFrom()
03018   UnicodeString &copyFrom(const UnicodeString &src, UBool fastCopy=FALSE);
03019 
03020   // Pin start and limit to acceptable values.
03021   inline void pinIndex(int32_t& start) const;
03022   inline void pinIndices(int32_t& start,
03023                          int32_t& length) const;
03024 
03025   /* Internal extract() using UConverter. */
03026   int32_t doExtract(int32_t start, int32_t length,
03027                     char *dest, int32_t destCapacity,
03028                     UConverter *cnv,
03029                     UErrorCode &errorCode) const;
03030 
03031   /*
03032    * Real constructor for converting from codepage data.
03033    * It assumes that it is called with !fRefCounted.
03034    *
03035    * If <code>codepage==0</code>, then the default converter
03036    * is used for the platform encoding.
03037    * If <code>codepage</code> is an empty string (<code>""</code>),
03038    * then a simple conversion is performed on the codepage-invariant
03039    * subset ("invariant characters") of the platform encoding. See utypes.h.
03040    */
03041   void doCodepageCreate(const char *codepageData,
03042                         int32_t dataLength,
03043                         const char *codepage);
03044 
03045   /*
03046    * Worker function for creating a UnicodeString from
03047    * a codepage string using a UConverter.
03048    */
03049   void
03050   doCodepageCreate(const char *codepageData,
03051                    int32_t dataLength,
03052                    UConverter *converter,
03053                    UErrorCode &status);
03054   /*
03055    * This function is called when write access to the array
03056    * is necessary.
03057    *
03058    * We need to make a copy of the array if
03059    * the buffer is read-only, or
03060    * the buffer is refCounted (shared), and refCount>1, or
03061    * the buffer is too small.
03062    *
03063    * Return FALSE if memory could not be allocated.
03064    */
03065   UBool cloneArrayIfNeeded(int32_t newCapacity = -1,
03066                             int32_t growCapacity = -1,
03067                             UBool doCopyArray = TRUE,
03068                             int32_t **pBufferToDelete = 0,
03069                             UBool forceClone = FALSE);
03070 
03071   // common function for case mappings
03072   UnicodeString &
03073   caseMap(BreakIterator *titleIter,
03074           const Locale& locale,
03075           uint32_t options,
03076           int32_t toWhichCase);
03077 
03078   // ref counting
03079   void addRef(void);
03080   int32_t removeRef(void);
03081   int32_t refCount(void) const;
03082 
03083   // constants
03084   enum {
03085     US_STACKBUF_SIZE=7, // Size of stack buffer for small strings
03086     kInvalidUChar=0xffff, // invalid UChar index
03087     kGrowSize=128, // grow size for this buffer
03088     kInvalidHashCode=0, // invalid hash code
03089     kEmptyHashCode=1, // hash code for empty string
03090 
03091     // bit flag values for fFlags
03092     kIsBogus=1,         // this string is bogus, i.e., not valid or NULL
03093     kUsingStackBuffer=2,// fArray==fStackBuffer
03094     kRefCounted=4,      // there is a refCount field before the characters in fArray
03095     kBufferIsReadonly=8,// do not write to this buffer
03096     kOpenGetBuffer=16,  // getBuffer(minCapacity) was called (is "open"),
03097                         // and releaseBuffer(newLength) must be called
03098 
03099     // combined values for convenience
03100     kShortString=kUsingStackBuffer,
03101     kLongString=kRefCounted,
03102     kReadonlyAlias=kBufferIsReadonly,
03103     kWritableAlias=0
03104   };
03105 
03106 #ifdef ICU_UNICODECONVERTER_USE_DEPRECATES
03107   friend class UnicodeConverter;
03108 #endif
03109 
03110   friend class StringCharacterIterator;
03111   friend class StringThreadTest;
03112 
03113   /*
03114    * The following are all the class fields that are stored
03115    * in each UnicodeString object.
03116    * Note that UnicodeString has virtual functions,
03117    * therefore there is an implicit vtable pointer
03118    * as the first real field.
03119    * The fields should be aligned such that no padding is
03120    * necessary, mostly by having larger types first.
03121    * On 32-bit machines, the size should be 32 bytes,
03122    * on 64-bit machines (8-byte pointers), it should be 40 bytes.
03123    */
03124   // (implicit) *vtable;
03125   int32_t   fLength;        // number of characters in fArray
03126   int32_t   fCapacity;      // sizeof fArray
03127   UChar     *fArray;        // the Unicode data
03128   uint16_t  fFlags;         // bit flags: see constants above
03129   UChar     fStackBuffer [ US_STACKBUF_SIZE ]; // buffer for small strings
03130 
03135   static const char fgClassID;
03136 };
03137 
03138 U_NAMESPACE_END
03139 
03140 //========================================
03141 // Array copying
03142 //========================================
03147 inline void 
03148 uprv_arrayCopy(const U_NAMESPACE_QUALIFIER UnicodeString *src, U_NAMESPACE_QUALIFIER UnicodeString *dst, int32_t count)
03149 { while(count-- > 0) *dst++ = *src++; }
03150 
03155 inline void 
03156 uprv_arrayCopy(const U_NAMESPACE_QUALIFIER UnicodeString *src, int32_t srcStart, 
03157         U_NAMESPACE_QUALIFIER UnicodeString *dst, int32_t dstStart, int32_t count)
03158 { uprv_arrayCopy(src+srcStart, dst+dstStart, count); }
03159 
03160 U_NAMESPACE_BEGIN
03161 //========================================
03162 // Inline members
03163 //========================================
03164 
03165 //========================================
03166 // Read-only alias methods
03167 //========================================
03168 inline UBool
03169 UnicodeString::operator== (const UnicodeString& text) const
03170 {
03171   if(isBogus()) {
03172     return text.isBogus();
03173   } else {
03174     return
03175       !text.isBogus() &&
03176       fLength == text.fLength &&
03177       doCompare(0, fLength, text, 0, text.fLength) == 0;
03178   }
03179 }
03180 
03181 inline UBool
03182 UnicodeString::operator!= (const UnicodeString& text) const
03183 { return (! operator==(text)); }
03184 
03185 inline UBool
03186 UnicodeString::operator> (const UnicodeString& text) const
03187 { return doCompare(0, fLength, text, 0, text.fLength) == 1; }
03188 
03189 inline UBool
03190 UnicodeString::operator< (const UnicodeString& text) const
03191 { return doCompare(0, fLength, text, 0, text.fLength) == -1; }
03192 
03193 inline UBool
03194 UnicodeString::operator>= (const UnicodeString& text) const
03195 { return doCompare(0, fLength, text, 0, text.fLength) != -1; }
03196 
03197 inline UBool
03198 UnicodeString::operator<= (const UnicodeString& text) const
03199 { return doCompare(0, fLength, text, 0, text.fLength) != 1; }
03200 
03201 inline int8_t 
03202 UnicodeString::compare(const UnicodeString& text) const
03203 { return doCompare(0, fLength, text, 0, text.fLength); }
03204 
03205 inline int8_t 
03206 UnicodeString::compare(int32_t start,
03207                int32_t length,
03208                const UnicodeString& srcText) const
03209 { return doCompare(start, length, srcText, 0, srcText.fLength); }
03210 
03211 inline int8_t 
03212 UnicodeString::compare(const UChar *srcChars,
03213                int32_t srcLength) const
03214 { return doCompare(0, fLength, srcChars, 0, srcLength); }
03215 
03216 inline int8_t 
03217 UnicodeString::compare(int32_t start,
03218                int32_t length,
03219                const UnicodeString& srcText,
03220                int32_t srcStart,
03221                int32_t srcLength) const
03222 { return doCompare(start, length, srcText, srcStart, srcLength); }
03223 
03224 inline int8_t
03225 UnicodeString::compare(int32_t start,
03226                int32_t length,
03227                const UChar *srcChars) const
03228 { return doCompare(start, length, srcChars, 0, length); }
03229 
03230 inline int8_t 
03231 UnicodeString::compare(int32_t start,
03232                int32_t length,
03233                const UChar *srcChars,
03234                int32_t srcStart,
03235                int32_t srcLength) const
03236 { return doCompare(start, length, srcChars, srcStart, srcLength); }
03237 
03238 inline int8_t
03239 UnicodeString::compareBetween(int32_t start,
03240                   int32_t limit,
03241                   const UnicodeString& srcText,
03242                   int32_t srcStart,
03243                   int32_t srcLimit) const
03244 { return doCompare(start, limit - start, 
03245            srcText, srcStart, srcLimit - srcStart); }
03246 
03247 inline int8_t
03248 UnicodeString::doCompare(int32_t start,
03249               int32_t length,
03250               const UnicodeString& srcText,
03251               int32_t srcStart,
03252               int32_t srcLength) const
03253 {
03254   const UChar *srcChars;
03255   if(!srcText.isBogus()) {
03256     srcText.pinIndices(srcStart, srcLength);
03257     srcChars=srcText.getArrayStart();
03258   } else {
03259     srcChars=0;
03260   }
03261   return doCompare(start, length, srcChars, srcStart, srcLength);
03262 }
03263 
03264 inline int8_t 
03265 UnicodeString::compareCodePointOrder(const UnicodeString& text) const
03266 { return doCompareCodePointOrder(0, fLength, text, 0, text.fLength); }
03267 
03268 inline int8_t 
03269 UnicodeString::compareCodePointOrder(int32_t start,
03270                                      int32_t length,
03271                                      const UnicodeString& srcText) const
03272 { return doCompareCodePointOrder(start, length, srcText, 0, srcText.fLength); }
03273 
03274 inline int8_t 
03275 UnicodeString::compareCodePointOrder(const UChar *srcChars,
03276                                      int32_t srcLength) const
03277 { return doCompareCodePointOrder(0, fLength, srcChars, 0, srcLength); }
03278 
03279 inline int8_t 
03280 UnicodeString::compareCodePointOrder(int32_t start,
03281                                      int32_t length,
03282                                      const UnicodeString& srcText,
03283                                      int32_t srcStart,
03284                                      int32_t srcLength) const
03285 { return doCompareCodePointOrder(start, length, srcText, srcStart, srcLength); }
03286 
03287 inline int8_t
03288 UnicodeString::compareCodePointOrder(int32_t start,
03289                                      int32_t length,
03290                                      const UChar *srcChars) const
03291 { return doCompareCodePointOrder(start, length, srcChars, 0, length); }
03292 
03293 inline int8_t 
03294 UnicodeString::compareCodePointOrder(int32_t start,
03295                                      int32_t length,
03296                                      const UChar *srcChars,
03297                                      int32_t srcStart,
03298                                      int32_t srcLength) const
03299 { return doCompareCodePointOrder(start, length, srcChars, srcStart, srcLength); }
03300 
03301 inline int8_t
03302 UnicodeString::compareCodePointOrderBetween(int32_t start,
03303                                             int32_t limit,
03304                                             const UnicodeString& srcText,
03305                                             int32_t srcStart,
03306                                             int32_t srcLimit) const
03307 { return doCompareCodePointOrder(start, limit - start, 
03308            srcText, srcStart, srcLimit - srcStart); }
03309 
03310 inline int8_t
03311 UnicodeString::doCompareCodePointOrder(int32_t start,
03312                                        int32_t length,
03313                                        const UnicodeString& srcText,
03314                                        int32_t srcStart,
03315                                        int32_t srcLength) const
03316 {
03317   const UChar *srcChars;
03318   if(!srcText.isBogus()) {
03319     srcText.pinIndices(srcStart, srcLength);
03320     srcChars=srcText.getArrayStart();
03321   } else {
03322     srcChars=0;
03323   }
03324   return doCompareCodePointOrder(start, length, srcChars, srcStart, srcLength);
03325 }
03326 
03327 inline int8_t 
03328 UnicodeString::caseCompare(const UnicodeString &text, uint32_t options) const {
03329   return doCaseCompare(0, fLength, text, 0, text.fLength, options);
03330 }
03331 
03332 inline int8_t 
03333 UnicodeString::caseCompare(int32_t start,
03334                            int32_t length,
03335                            const UnicodeString &srcText,
03336                            uint32_t options) const {
03337   return doCaseCompare(start, length, srcText, 0, srcText.fLength, options);
03338 }
03339 
03340 inline int8_t 
03341 UnicodeString::caseCompare(const UChar *srcChars,
03342                            int32_t srcLength,
03343                            uint32_t options) const {
03344   return doCaseCompare(0, fLength, srcChars, 0, srcLength, options);
03345 }
03346 
03347 inline int8_t 
03348 UnicodeString::caseCompare(int32_t start,
03349                            int32_t length,
03350                            const UnicodeString &srcText,
03351                            int32_t srcStart,
03352                            int32_t srcLength,
03353                            uint32_t options) const {
03354   return doCaseCompare(start, length, srcText, srcStart, srcLength, options);
03355 }
03356 
03357 inline int8_t
03358 UnicodeString::caseCompare(int32_t start,
03359                            int32_t length,
03360                            const UChar *srcChars,
03361                            uint32_t options) const {
03362   return doCaseCompare(start, length, srcChars, 0, length, options);
03363 }
03364 
03365 inline int8_t 
03366 UnicodeString::caseCompare(int32_t start,
03367                            int32_t length,
03368                            const UChar *srcChars,
03369                            int32_t srcStart,
03370                            int32_t srcLength,
03371                            uint32_t options) const {
03372   return doCaseCompare(start, length, srcChars, srcStart, srcLength, options);
03373 }
03374 
03375 inline int8_t
03376 UnicodeString::caseCompareBetween(int32_t start,
03377                                   int32_t limit,
03378                                   const UnicodeString &srcText,
03379                                   int32_t srcStart,
03380                                   int32_t srcLimit,
03381                                   uint32_t options) const {
03382   return doCaseCompare(start, limit - start, srcText, srcStart, srcLimit - srcStart, options);
03383 }
03384 
03385 inline int8_t
03386 UnicodeString::doCaseCompare(int32_t start,
03387                              int32_t length,
03388                              const UnicodeString &srcText,
03389                              int32_t srcStart,
03390                              int32_t srcLength,
03391                              uint32_t options) const
03392 {
03393   const UChar *srcChars;
03394   if(!srcText.isBogus()) {
03395     srcText.pinIndices(srcStart, srcLength);
03396     srcChars=srcText.getArrayStart();
03397   } else {
03398     srcChars=0;
03399   }
03400   return doCaseCompare(start, length, srcChars, srcStart, srcLength, options);
03401 }
03402 
03403 inline int32_t 
03404 UnicodeString::indexOf(const UnicodeString& text) const
03405 { return indexOf(text, 0, text.fLength, 0, fLength); }
03406 
03407 inline int32_t 
03408 UnicodeString::indexOf(const UnicodeString& text,
03409                int32_t start) const {
03410   pinIndex(start);
03411   return indexOf(text, 0, text.fLength, start, fLength - start);
03412 }
03413 
03414 inline int32_t 
03415 UnicodeString::indexOf(const UnicodeString& text,
03416                int32_t start,
03417                int32_t length) const
03418 { return indexOf(text, 0, text.fLength, start, length); }
03419 
03420 inline int32_t 
03421 UnicodeString::indexOf(const UnicodeString& srcText,
03422                int32_t srcStart,
03423                int32_t srcLength,
03424                int32_t start,
03425                int32_t length) const
03426 {
03427   if(!srcText.isBogus()) {
03428     srcText.pinIndices(srcStart, srcLength);
03429     if(srcLength > 0) {
03430       return indexOf(srcText.getArrayStart(), srcStart, srcLength, start, length);
03431     }
03432   }
03433   return -1;
03434 }
03435 
03436 inline int32_t 
03437 UnicodeString::indexOf(const UChar *srcChars,
03438                int32_t srcLength,
03439                int32_t start) const {
03440   pinIndex(start);
03441   return indexOf(srcChars, 0, srcLength, start, fLength - start);
03442 }
03443 
03444 inline int32_t 
03445 UnicodeString::indexOf(const UChar *srcChars,
03446                int32_t srcLength,
03447                int32_t start,
03448                int32_t length) const
03449 { return indexOf(srcChars, 0, srcLength, start, length); }
03450 
03451 inline int32_t 
03452 UnicodeString::indexOf(UChar c) const
03453 { return doIndexOf(c, 0, fLength); }
03454 
03455 inline int32_t 
03456 UnicodeString::indexOf(UChar32 c) const {
03457   return indexOf(c, 0, fLength);
03458 }
03459 
03460 inline int32_t 
03461 UnicodeString::indexOf(UChar c,
03462                int32_t start) const {
03463   pinIndex(start);
03464   return doIndexOf(c, start, fLength - start);
03465 }
03466 
03467 inline int32_t 
03468 UnicodeString::indexOf(UChar32 c,
03469                int32_t start) const {
03470   pinIndex(start);
03471   return indexOf(c, start, fLength - start);
03472 }
03473 
03474 inline int32_t 
03475 UnicodeString::indexOf(UChar c,
03476                int32_t start,
03477                int32_t length) const
03478 { return doIndexOf(c, start, length); }
03479 
03480 inline int32_t 
03481 UnicodeString::indexOf(UChar32 c,
03482                int32_t start,
03483                int32_t length) const {
03484   return doIndexOf(c, start, length);
03485 }
03486 
03487 inline int32_t 
03488 UnicodeString::lastIndexOf(const UnicodeString& text) const
03489 { return lastIndexOf(text, 0, text.fLength, 0, fLength); }
03490 
03491 inline int32_t 
03492 UnicodeString::lastIndexOf(const UnicodeString& text,
03493                int32_t start) const {
03494   pinIndex(start);
03495   return lastIndexOf(text, 0, text.fLength, start, fLength - start);
03496 }
03497 
03498 inline int32_t 
03499 UnicodeString::lastIndexOf(const UnicodeString& text,
03500                int32_t start,
03501                int32_t length) const
03502 { return lastIndexOf(text, 0, text.fLength, start, length); }
03503 
03504 inline int32_t 
03505 UnicodeString::lastIndexOf(const UnicodeString& srcText,
03506                int32_t srcStart,
03507                int32_t srcLength,
03508                int32_t start,
03509                int32_t length) const
03510 {
03511   if(!srcText.isBogus()) {
03512     srcText.pinIndices(srcStart, srcLength);
03513     if(srcLength > 0) {
03514       return lastIndexOf(srcText.getArrayStart(), srcStart, srcLength, start, length);
03515     }
03516   }
03517   return -1;
03518 }
03519 
03520 inline int32_t 
03521 UnicodeString::lastIndexOf(const UChar *srcChars,
03522                int32_t srcLength,
03523                int32_t start) const {
03524   pinIndex(start);
03525   return lastIndexOf(srcChars, 0, srcLength, start, fLength - start);
03526 }
03527 
03528 inline int32_t 
03529 UnicodeString::lastIndexOf(const UChar *srcChars,
03530                int32_t srcLength,
03531                int32_t start,
03532                int32_t length) const
03533 { return lastIndexOf(srcChars, 0, srcLength, start, length); }
03534 
03535 inline int32_t 
03536 UnicodeString::lastIndexOf(UChar c) const
03537 { return doLastIndexOf(c, 0, fLength); }
03538 
03539 inline int32_t 
03540 UnicodeString::lastIndexOf(UChar32 c) const {
03541   return lastIndexOf(c, 0, fLength);
03542 }
03543 
03544 inline int32_t 
03545 UnicodeString::lastIndexOf(UChar c,
03546                int32_t start) const {
03547   pinIndex(start);
03548   return doLastIndexOf(c, start, fLength - start);
03549 }
03550 
03551 inline int32_t 
03552 UnicodeString::lastIndexOf(UChar32 c,
03553                int32_t start) const {
03554   pinIndex(start);
03555   return lastIndexOf(c, start, fLength - start);
03556 }
03557 
03558 inline int32_t 
03559 UnicodeString::lastIndexOf(UChar c,
03560                int32_t start,
03561                int32_t length) const
03562 { return doLastIndexOf(c, start, length); }
03563 
03564 inline int32_t 
03565 UnicodeString::lastIndexOf(UChar32 c,
03566                int32_t start,
03567                int32_t length) const {
03568   return doLastIndexOf(c, start, length);
03569 }
03570 
03571 inline UBool 
03572 UnicodeString::startsWith(const UnicodeString& text) const
03573 { return compare(0, text.fLength, text, 0, text.fLength) == 0; }
03574 
03575 inline UBool 
03576 UnicodeString::startsWith(const UnicodeString& srcText,
03577               int32_t srcStart,
03578               int32_t srcLength) const
03579 { return doCompare(0, srcLength, srcText, srcStart, srcLength) == 0; }
03580 
03581 inline UBool 
03582 UnicodeString::startsWith(const UChar *srcChars,
03583               int32_t srcLength) const
03584 { return doCompare(0, srcLength, srcChars, 0, srcLength) == 0; }
03585 
03586 inline UBool 
03587 UnicodeString::startsWith(const UChar *srcChars,
03588               int32_t srcStart,
03589               int32_t srcLength) const
03590 { return doCompare(0, srcLength, srcChars, srcStart, srcLength) == 0;}
03591 
03592 inline UBool 
03593 UnicodeString::endsWith(const UnicodeString& text) const
03594 { return doCompare(fLength - text.fLength, text.fLength, 
03595            text, 0, text.fLength) == 0; }
03596 
03597 inline UBool 
03598 UnicodeString::endsWith(const UnicodeString& srcText,
03599             int32_t srcStart,
03600             int32_t srcLength) const {
03601   srcText.pinIndices(srcStart, srcLength);
03602   return doCompare(fLength - srcLength, srcLength, 
03603                    srcText, srcStart, srcLength) == 0;
03604 }
03605 
03606 inline UBool 
03607 UnicodeString::endsWith(const UChar *srcChars,
03608             int32_t srcLength) const {
03609   if(srcLength < 0) {
03610     srcLength = u_strlen(srcChars);
03611   }
03612   return doCompare(fLength - srcLength, srcLength, 
03613                    srcChars, 0, srcLength) == 0;
03614 }
03615 
03616 inline UBool 
03617 UnicodeString::endsWith(const UChar *srcChars,
03618             int32_t srcStart,
03619             int32_t srcLength) const {
03620   if(srcLength < 0) {
03621     srcLength = u_strlen(srcChars + srcStart);
03622   }
03623   return doCompare(fLength - srcLength, srcLength, 
03624                    srcChars, srcStart, srcLength) == 0;
03625 }
03626 
03627 //========================================
03628 // replace
03629 //========================================
03630 inline UnicodeString& 
03631 UnicodeString::replace(int32_t start, 
03632                int32_t length, 
03633                const UnicodeString& srcText) 
03634 { return doReplace(start, length, srcText, 0, srcText.fLength); }
03635 
03636 inline UnicodeString& 
03637 UnicodeString::replace(int32_t start, 
03638                int32_t length, 
03639                const UnicodeString& srcText, 
03640                int32_t srcStart, 
03641                int32_t srcLength)
03642 { return doReplace(start, length, srcText, srcStart, srcLength); }
03643 
03644 inline UnicodeString& 
03645 UnicodeString::replace(int32_t start, 
03646                int32_t length, 
03647                const UChar *srcChars,
03648                int32_t srcLength)
03649 { return doReplace(start, length, srcChars, 0, srcLength); }
03650 
03651 inline UnicodeString& 
03652 UnicodeString::replace(int32_t start, 
03653                int32_t length, 
03654                const UChar *srcChars, 
03655                int32_t srcStart, 
03656                int32_t srcLength)
03657 { return doReplace(start, length, srcChars, srcStart, srcLength); }
03658 
03659 inline UnicodeString& 
03660 UnicodeString::replace(int32_t start, 
03661                int32_t length, 
03662                UChar srcChar)
03663 { return doReplace(start, length, &srcChar, 0, 1); }
03664 
03665 inline UnicodeString&
03666 UnicodeString::replace(int32_t start, 
03667                int32_t length, 
03668                UChar32 srcChar) {
03669   UChar buffer[U16_MAX_LENGTH];
03670   int32_t count = 0;
03671   UBool isError = FALSE;
03672   U16_APPEND(buffer, count, U16_MAX_LENGTH, srcChar, isError);
03673   return doReplace(start, length, buffer, 0, count);
03674 }
03675 
03676 inline UnicodeString& 
03677 UnicodeString::replaceBetween(int32_t start, 
03678                   int32_t limit, 
03679                   const UnicodeString& srcText)
03680 { return doReplace(start, limit - start, srcText, 0, srcText.fLength); }
03681 
03682 inline UnicodeString&
03683 UnicodeString::replaceBetween(int32_t start, 
03684                   int32_t limit, 
03685                   const UnicodeString& srcText, 
03686                   int32_t srcStart, 
03687                   int32_t srcLimit)
03688 { return doReplace(start, limit - start, srcText, srcStart, srcLimit - srcStart); }
03689 
03690 inline UnicodeString& 
03691 UnicodeString::findAndReplace(const UnicodeString& oldText,
03692                   const UnicodeString& newText)
03693 { return findAndReplace(0, fLength, oldText, 0, oldText.fLength, 
03694             newText, 0, newText.fLength); }
03695 
03696 inline UnicodeString& 
03697 UnicodeString::findAndReplace(int32_t start,
03698                   int32_t length,
03699                   const UnicodeString& oldText,
03700                   const UnicodeString& newText)
03701 { return findAndReplace(start, length, oldText, 0, oldText.fLength, 
03702             newText, 0, newText.fLength); }
03703 
03704 // ============================
03705 // extract
03706 // ============================
03707 inline void
03708 UnicodeString::doExtract(int32_t start,
03709              int32_t length,
03710              UnicodeString& target) const
03711 { target.replace(0, target.fLength, *this, start, length); }
03712 
03713 inline void  
03714 UnicodeString::extract(int32_t start, 
03715                int32_t length, 
03716                UChar *target, 
03717                int32_t targetStart) const
03718 { doExtract(start, length, target, targetStart); }
03719 
03720 inline void 
03721 UnicodeString::extract(int32_t start,
03722                int32_t length,
03723                UnicodeString& target) const
03724 { doExtract(start, length, target); }
03725 
03726 inline int32_t
03727 UnicodeString::extract(int32_t start,
03728                int32_t length,
03729                char *dst,
03730                const char *codepage) const
03731 
03732 {
03733   // This dstSize value will be checked explicitly
03734   return extract(start, length, dst, dst!=0 ? 0xffffffff : 0, codepage);
03735 }
03736 
03737 inline void  
03738 UnicodeString::extractBetween(int32_t start, 
03739                   int32_t limit, 
03740                   UChar *dst, 
03741                   int32_t dstStart) const
03742 { doExtract(start, limit - start, dst, dstStart); }
03743 
03744 inline UChar
03745 UnicodeString::doCharAt(int32_t offset) const
03746 {
03747   if((uint32_t)offset < (uint32_t)fLength) {
03748     return fArray[offset];
03749   } else {
03750     return kInvalidUChar;
03751   }
03752 }
03753 
03754 inline UChar
03755 UnicodeString::charAt(int32_t offset) const
03756 { return doCharAt(offset); }
03757 
03758 inline UChar
03759 UnicodeString::operator[] (int32_t offset) const
03760 { return doCharAt(offset); }
03761 
03762 inline UChar32
03763 UnicodeString::char32At(int32_t offset) const
03764 {
03765   if((uint32_t)offset < (uint32_t)fLength) {
03766     UChar32 c;
03767     U16_GET(fArray, 0, offset, fLength, c);
03768     return c;
03769   } else {
03770     return kInvalidUChar;
03771   }
03772 }
03773 
03774 inline int32_t
03775 UnicodeString::getChar32Start(int32_t offset) const {
03776   if((uint32_t)offset < (uint32_t)fLength) {
03777     U16_SET_CP_START(fArray, 0, offset);
03778     return offset;
03779   } else {
03780     return 0;
03781   }
03782 }
03783 
03784 inline int32_t
03785 UnicodeString::getChar32Limit(int32_t offset) const {
03786   if((uint32_t)offset < (uint32_t)fLength) {
03787     U16_SET_CP_LIMIT(fArray, 0, offset, fLength);
03788     return offset;
03789   } else {
03790     return fLength;
03791   }
03792 }
03793 
03794 inline UBool
03795 UnicodeString::isEmpty() const {
03796   return fLength == 0;
03797 }
03798 
03799 #ifdef ICU_UNICODESTRING_USE_DEPRECATES
03800 inline int32_t
03801 UnicodeString::getCharStart(int32_t offset) const {
03802   return getChar32Start(offset);
03803 }
03804 
03805 inline int32_t
03806 UnicodeString::getCharLimit(int32_t offset) const {
03807   return getChar32Limit(offset);
03808 }
03809 
03810 inline UBool
03811 UnicodeString::empty() const {
03812   return isEmpty();
03813 }
03814 #endif
03815 
03816 //========================================
03817 // Read-only implementation methods
03818 //========================================
03819 inline int32_t  
03820 UnicodeString::length() const
03821 { return fLength; }
03822 
03823 inline int32_t 
03824 UnicodeString::getCapacity() const
03825 { return fCapacity; }
03826 
03827 inline int32_t 
03828 UnicodeString::hashCode() const
03829 { return doHashCode(); }
03830 
03831 inline UBool 
03832 UnicodeString::isBogus() const
03833 { return (UBool)(fFlags & kIsBogus); }
03834 
03835 inline const UChar *
03836 UnicodeString::getBuffer() const {
03837   if(!(fFlags&(kIsBogus|kOpenGetBuffer))) {
03838     return fArray;
03839   } else {
03840     return 0;
03841   }
03842 }
03843 
03844 //========================================
03845 // Write implementation methods
03846 //========================================
03847 inline const UChar *
03848 UnicodeString::getTerminatedBuffer() {
03849   if(fFlags&(kIsBogus|kOpenGetBuffer)) {
03850     return 0;
03851   } else if(fLength<fCapacity && fArray[fLength]==0) {
03852     return fArray;
03853   } else if(cloneArrayIfNeeded(fLength+1)) {
03854     fArray[fLength]=0;
03855     return fArray;
03856   } else {
03857     return 0;
03858   }
03859 }
03860 
03861 inline UnicodeString& 
03862 UnicodeString::operator= (UChar ch) 
03863 { return doReplace(0, fLength, &ch, 0, 1); }
03864 
03865 inline UnicodeString& 
03866 UnicodeString::operator= (UChar32 ch) 
03867 { return replace(0, fLength, ch); }
03868 
03869 inline UnicodeString& 
03870 UnicodeString::setTo(const UnicodeString& srcText, 
03871              int32_t srcStart, 
03872              int32_t srcLength)
03873 {
03874   unBogus();
03875   return doReplace(0, fLength, srcText, srcStart, srcLength);
03876 }
03877 
03878 inline UnicodeString& 
03879 UnicodeString::setTo(const UnicodeString& srcText, 
03880              int32_t srcStart)
03881 {
03882   unBogus();
03883   srcText.pinIndex(srcStart);
03884   return doReplace(0, fLength, srcText, srcStart, srcText.fLength - srcStart);
03885 }
03886 
03887 inline UnicodeString& 
03888 UnicodeString::setTo(const UnicodeString& srcText)
03889 {
03890   unBogus();
03891   return doReplace(0, fLength, srcText, 0, srcText.fLength);
03892 }
03893 
03894 inline UnicodeString& 
03895 UnicodeString::setTo(const UChar *srcChars,
03896              int32_t srcLength)
03897 {
03898   unBogus();
03899   return doReplace(0, fLength, srcChars, 0, srcLength);
03900 }
03901 
03902 inline UnicodeString& 
03903 UnicodeString::setTo(UChar srcChar)
03904 {
03905   unBogus();
03906   return doReplace(0, fLength, &srcChar, 0, 1);
03907 }
03908 
03909 inline UnicodeString& 
03910 UnicodeString::setTo(UChar32 srcChar)
03911 {
03912   unBogus();
03913   return replace(0, fLength, srcChar);
03914 }
03915 
03916 inline UnicodeString& 
03917 UnicodeString::operator+= (UChar ch)
03918 { return doReplace(fLength, 0, &ch, 0, 1); }
03919 
03920 inline UnicodeString& 
03921 UnicodeString::operator+= (UChar32 ch) {
03922   UChar buffer[U16_MAX_LENGTH];
03923   int32_t length = 0;
03924   UBool isError = FALSE;
03925   U16_APPEND(buffer, length, U16_MAX_LENGTH, ch, isError);
03926   return doReplace(fLength, 0, buffer, 0, length);
03927 }
03928 
03929 inline UnicodeString& 
03930 UnicodeString::operator+= (const UnicodeString& srcText)
03931 { return doReplace(fLength, 0, srcText, 0, srcText.fLength); }
03932 
03933 inline UnicodeString& 
03934 UnicodeString::append(const UnicodeString& srcText, 
03935               int32_t srcStart, 
03936               int32_t srcLength)
03937 { return doReplace(fLength, 0, srcText, srcStart, srcLength); }
03938 
03939 inline UnicodeString& 
03940 UnicodeString::append(const UnicodeString& srcText)
03941 { return doReplace(fLength, 0, srcText, 0, srcText.fLength); }
03942 
03943 inline UnicodeString& 
03944 UnicodeString::append(const UChar *srcChars, 
03945               int32_t srcStart, 
03946               int32_t srcLength)
03947 { return doReplace(fLength, 0, srcChars, srcStart, srcLength); }
03948 
03949 inline UnicodeString& 
03950 UnicodeString::append(const UChar *srcChars,
03951               int32_t srcLength)
03952 { return doReplace(fLength, 0, srcChars, 0, srcLength); }
03953 
03954 inline UnicodeString& 
03955 UnicodeString::append(UChar srcChar)
03956 { return doReplace(fLength, 0, &srcChar, 0, 1); }
03957 
03958 inline UnicodeString& 
03959 UnicodeString::append(UChar32 srcChar) {
03960   UChar buffer[U16_MAX_LENGTH];
03961   int32_t length = 0;
03962   UBool isError = FALSE;
03963   U16_APPEND(buffer, length, U16_MAX_LENGTH, srcChar, isError);
03964   return doReplace(fLength, 0, buffer, 0, length);
03965 }
03966 
03967 inline UnicodeString& 
03968 UnicodeString::insert(int32_t start, 
03969               const UnicodeString& srcText, 
03970               int32_t srcStart, 
03971               int32_t srcLength)
03972 { return doReplace(start, 0, srcText, srcStart, srcLength); }
03973 
03974 inline UnicodeString& 
03975 UnicodeString::insert(int32_t start, 
03976               const UnicodeString& srcText)
03977 { return doReplace(start, 0, srcText, 0, srcText.fLength); }
03978 
03979 inline UnicodeString& 
03980 UnicodeString::insert(int32_t start, 
03981               const UChar *srcChars, 
03982               int32_t srcStart, 
03983               int32_t srcLength)
03984 { return doReplace(start, 0, srcChars, srcStart, srcLength); }
03985 
03986 inline UnicodeString& 
03987 UnicodeString::insert(int32_t start, 
03988               const UChar *srcChars,
03989               int32_t srcLength)
03990 { return doReplace(start, 0, srcChars, 0, srcLength); }
03991 
03992 inline UnicodeString& 
03993 UnicodeString::insert(int32_t start, 
03994               UChar srcChar)
03995 { return doReplace(start, 0, &srcChar, 0, 1); }
03996 
03997 inline UnicodeString& 
03998 UnicodeString::insert(int32_t start, 
03999               UChar32 srcChar)
04000 { return replace(start, 0, srcChar); }
04001 
04002 
04003 inline UnicodeString& 
04004 UnicodeString::remove(int32_t start, 
04005              int32_t length)
04006 {
04007   if(start <= 0 && length == INT32_MAX) {
04008     // remove(guaranteed everything) of a bogus string makes the string empty and non-bogus
04009     return remove();
04010   } else {
04011     return doReplace(start, length, NULL, 0, 0);
04012   }
04013 }
04014 
04015 inline UnicodeString& 
04016 UnicodeString::remove()
04017 {
04018   // remove() of a bogus string makes the string empty and non-bogus
04019   if(isBogus()) {
04020     unBogus();
04021   } else {
04022     fLength = 0;
04023   }
04024   return *this;
04025 }
04026 
04027 inline UnicodeString& 
04028 UnicodeString::removeBetween(int32_t start,
04029                 int32_t limit)
04030 { return doReplace(start, limit - start, NULL, 0, 0); }
04031 
04032 inline UBool 
04033 UnicodeString::truncate(int32_t targetLength)
04034 {
04035   if(isBogus() && targetLength == 0) {
04036     // truncate(0) of a bogus string makes the string empty and non-bogus
04037     unBogus();
04038     return FALSE;
04039   } else if((uint32_t)targetLength < (uint32_t)fLength) {
04040     fLength = targetLength;
04041     return TRUE;
04042   } else {
04043     return FALSE;
04044   }
04045 }
04046 
04047 inline UnicodeString& 
04048 UnicodeString::reverse()
04049 { return doReverse(0, fLength); }
04050 
04051 inline UnicodeString& 
04052 UnicodeString::reverse(int32_t start,
04053                int32_t length)
04054 { return doReverse(start, length); }
04055 
04056 
04057 //========================================
04058 // Privates
04059 //========================================
04060 
04061 inline void
04062 UnicodeString::pinIndex(int32_t& start) const
04063 {
04064   // pin index
04065   if(start < 0) {
04066     start = 0;
04067   } else if(start > fLength) {
04068     start = fLength;
04069   }
04070 }
04071 
04072 inline void
04073 UnicodeString::pinIndices(int32_t& start,
04074                           int32_t& length) const
04075 {
04076   // pin indices
04077   if(start < 0) {
04078     start = 0;
04079   } else if(start > fLength) {
04080     start = fLength;
04081   }
04082   if(length < 0) {
04083     length = 0;
04084   } else if(length > (fLength - start)) {
04085     length = (fLength - start);
04086   }
04087 }
04088 
04089 inline UChar* 
04090 UnicodeString::getArrayStart()
04091 { return fArray; }
04092 
04093 inline const UChar* 
04094 UnicodeString::getArrayStart() const
04095 { return fArray; }
04096 
04097 #ifdef U_USE_DEPRECATED_UCHAR_REFERENCE
04098 
04099 //========================================
04100 // class UCharReference
04101 //========================================
04102 
04108 class U_COMMON_API UCharReference : public UObject {
04109 public:
04110   UCharReference();
04111   inline UCharReference(UnicodeString *string,
04112          int32_t pos);
04113   inline UCharReference(const UCharReference& that);
04114   ~UCharReference();
04115 
04116   inline UCharReference& operator= (const UCharReference& that);
04117   inline UCharReference& operator= (UChar c);
04118 
04119   inline operator UChar();
04120 
04126   virtual inline UClassID getDynamicClassID() const { return getStaticClassID(); }
04127 
04133   static inline UClassID getStaticClassID() { return (UClassID)&fgClassID; }
04134 
04135 private:
04136   UnicodeString *fString;
04137   int32_t fPos;
04138 
04143   static const char fgClassID;
04144 };
04145 
04146 
04147 //========================================
04148 // Inline members
04149 //========================================
04150 inline
04151 UCharReference::UCharReference(UnicodeString *string, 
04152                    int32_t pos)
04153   : UObject(), fString(string), fPos(pos)
04154 {}
04155 
04156 inline
04157 UCharReference::UCharReference(const UCharReference& that)
04158 : UObject(that)
04159 { this->operator=(that); }
04160 
04161 inline
04162 UCharReference::~UCharReference()
04163 {}
04164 
04165 inline UCharReference&
04166 UCharReference::operator= (const UCharReference& that)
04167 { fString->setCharAt(fPos, that.fString->charAt(that.fPos)); return *this; }
04168 
04169 inline UCharReference& 
04170 UCharReference::operator= (UChar c)
04171 { fString->setCharAt(fPos, c); return *this; }
04172 
04173 inline
04174 UCharReference::operator UChar()
04175 { return fString->charAt(fPos); }
04176 
04177 #endif
04178 
04179 U_NAMESPACE_END
04180 
04181 #endif

Generated on Wed Dec 18 16:50:02 2002 for ICU 2.4 by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001