unistr.h

00001 /*
00002 **********************************************************************
00003 *   Copyright (C) 1998-2004, 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/rep.h"
00025 
00026 struct UConverter;          // unicode/ucnv.h
00027 class  StringThreadTest;
00028 
00029 #ifndef U_COMPARE_CODE_POINT_ORDER
00030 /* see also ustring.h and unorm.h */
00036 #define U_COMPARE_CODE_POINT_ORDER  0x8000
00037 #endif
00038 
00039 #ifndef USTRING_H
00040 /* see ustring.h */
00041 U_STABLE int32_t U_EXPORT2
00042 u_strlen(const UChar *s);
00043 #endif
00044 
00045 U_NAMESPACE_BEGIN
00046 
00047 class Locale;               // unicode/locid.h
00048 class StringCharacterIterator;
00049 class BreakIterator;        // unicode/brkiter.h
00050 
00051 /* The <iostream> include has been moved to unicode/ustream.h */
00052 
00063 #define US_INV UnicodeString::kInvariant
00064 
00082 #if U_SIZEOF_WCHAR_T==U_SIZEOF_UCHAR && U_CHARSET_FAMILY==U_ASCII_FAMILY
00083 #   define UNICODE_STRING(cs, _length) UnicodeString(TRUE, (const UChar *)L ## cs, _length)
00084 #elif U_SIZEOF_UCHAR==1 && U_CHARSET_FAMILY==U_ASCII_FAMILY
00085 #   define UNICODE_STRING(cs, _length) UnicodeString(TRUE, (const UChar *)cs, _length)
00086 #else
00087 #   define UNICODE_STRING(cs, _length) UnicodeString(cs, _length, US_INV)
00088 #endif
00089 
00103 #if U_SIZEOF_WCHAR_T==U_SIZEOF_UCHAR && U_CHARSET_FAMILY==U_ASCII_FAMILY
00104 #   define UNICODE_STRING_SIMPLE(cs) UnicodeString(TRUE, (const UChar *)L ## cs, -1)
00105 #elif U_SIZEOF_UCHAR==1 && U_CHARSET_FAMILY==U_ASCII_FAMILY
00106 #   define UNICODE_STRING_SIMPLE(cs) UnicodeString(TRUE, (const UChar *)cs, -1)
00107 #else
00108 #   define UNICODE_STRING_SIMPLE(cs) UnicodeString(cs, -1, US_INV)
00109 #endif
00110 
00181 class U_COMMON_API UnicodeString : public Replaceable
00182 {
00183 public:
00184 
00193   enum EInvariant {
00198     kInvariant
00199   };
00200 
00201   //========================================
00202   // Read-only operations
00203   //========================================
00204 
00205   /* Comparison - bitwise only - for international comparison use collation */
00206 
00214   inline UBool operator== (const UnicodeString& text) const;
00215 
00223   inline UBool operator!= (const UnicodeString& text) const;
00224 
00232   inline UBool operator> (const UnicodeString& text) const;
00233 
00241   inline UBool operator< (const UnicodeString& text) const;
00242 
00250   inline UBool operator>= (const UnicodeString& text) const;
00251 
00259   inline UBool operator<= (const UnicodeString& text) const;
00260 
00272   inline int8_t compare(const UnicodeString& text) const;
00273 
00288   inline int8_t compare(int32_t start,
00289          int32_t length,
00290          const UnicodeString& text) const;
00291 
00309    inline int8_t compare(int32_t start,
00310          int32_t length,
00311          const UnicodeString& srcText,
00312          int32_t srcStart,
00313          int32_t srcLength) const;
00314 
00327   inline int8_t compare(const UChar *srcChars,
00328          int32_t srcLength) const;
00329 
00344   inline int8_t compare(int32_t start,
00345          int32_t length,
00346          const UChar *srcChars) const;
00347 
00365   inline int8_t compare(int32_t start,
00366          int32_t length,
00367          const UChar *srcChars,
00368          int32_t srcStart,
00369          int32_t srcLength) const;
00370 
00388   inline int8_t compareBetween(int32_t start,
00389             int32_t limit,
00390             const UnicodeString& srcText,
00391             int32_t srcStart,
00392             int32_t srcLimit) const;
00393 
00411   inline int8_t compareCodePointOrder(const UnicodeString& text) const;
00412 
00432   inline int8_t compareCodePointOrder(int32_t start,
00433                                       int32_t length,
00434                                       const UnicodeString& srcText) const;
00435 
00457    inline int8_t compareCodePointOrder(int32_t start,
00458                                        int32_t length,
00459                                        const UnicodeString& srcText,
00460                                        int32_t srcStart,
00461                                        int32_t srcLength) const;
00462 
00481   inline int8_t compareCodePointOrder(const UChar *srcChars,
00482                                       int32_t srcLength) const;
00483 
00503   inline int8_t compareCodePointOrder(int32_t start,
00504                                       int32_t length,
00505                                       const UChar *srcChars) const;
00506 
00528   inline int8_t compareCodePointOrder(int32_t start,
00529                                       int32_t length,
00530                                       const UChar *srcChars,
00531                                       int32_t srcStart,
00532                                       int32_t srcLength) const;
00533 
00555   inline int8_t compareCodePointOrderBetween(int32_t start,
00556                                              int32_t limit,
00557                                              const UnicodeString& srcText,
00558                                              int32_t srcStart,
00559                                              int32_t srcLimit) const;
00560 
00579   inline int8_t caseCompare(const UnicodeString& text, uint32_t options) const;
00580 
00601   inline int8_t caseCompare(int32_t start,
00602          int32_t length,
00603          const UnicodeString& srcText,
00604          uint32_t options) const;
00605 
00628   inline int8_t caseCompare(int32_t start,
00629          int32_t length,
00630          const UnicodeString& srcText,
00631          int32_t srcStart,
00632          int32_t srcLength,
00633          uint32_t options) const;
00634 
00654   inline int8_t caseCompare(const UChar *srcChars,
00655          int32_t srcLength,
00656          uint32_t options) const;
00657 
00678   inline int8_t caseCompare(int32_t start,
00679          int32_t length,
00680          const UChar *srcChars,
00681          uint32_t options) const;
00682 
00705   inline int8_t caseCompare(int32_t start,
00706          int32_t length,
00707          const UChar *srcChars,
00708          int32_t srcStart,
00709          int32_t srcLength,
00710          uint32_t options) const;
00711 
00734   inline int8_t caseCompareBetween(int32_t start,
00735             int32_t limit,
00736             const UnicodeString& srcText,
00737             int32_t srcStart,
00738             int32_t srcLimit,
00739             uint32_t options) const;
00740 
00748   inline UBool startsWith(const UnicodeString& text) const;
00749 
00760   inline UBool startsWith(const UnicodeString& srcText,
00761             int32_t srcStart,
00762             int32_t srcLength) const;
00763 
00772   inline UBool startsWith(const UChar *srcChars,
00773             int32_t srcLength) const;
00774 
00784   inline UBool startsWith(const UChar *srcChars,
00785             int32_t srcStart,
00786             int32_t srcLength) const;
00787 
00795   inline UBool endsWith(const UnicodeString& text) const;
00796 
00807   inline UBool endsWith(const UnicodeString& srcText,
00808           int32_t srcStart,
00809           int32_t srcLength) const;
00810 
00819   inline UBool endsWith(const UChar *srcChars,
00820           int32_t srcLength) const;
00821 
00832   inline UBool endsWith(const UChar *srcChars,
00833           int32_t srcStart,
00834           int32_t srcLength) const;
00835 
00836 
00837   /* Searching - bitwise only */
00838 
00847   inline int32_t indexOf(const UnicodeString& text) const;
00848 
00858   inline int32_t indexOf(const UnicodeString& text,
00859               int32_t start) const;
00860 
00872   inline int32_t indexOf(const UnicodeString& text,
00873               int32_t start,
00874               int32_t length) const;
00875 
00892   inline int32_t indexOf(const UnicodeString& srcText,
00893               int32_t srcStart,
00894               int32_t srcLength,
00895               int32_t start,
00896               int32_t length) const;
00897 
00909   inline int32_t indexOf(const UChar *srcChars,
00910               int32_t srcLength,
00911               int32_t start) const;
00912 
00925   inline int32_t indexOf(const UChar *srcChars,
00926               int32_t srcLength,
00927               int32_t start,
00928               int32_t length) const;
00929 
00946   int32_t indexOf(const UChar *srcChars,
00947               int32_t srcStart,
00948               int32_t srcLength,
00949               int32_t start,
00950               int32_t length) const;
00951 
00959   inline int32_t indexOf(UChar c) const;
00960 
00969   inline int32_t indexOf(UChar32 c) const;
00970 
00979   inline int32_t indexOf(UChar c,
00980               int32_t start) const;
00981 
00991   inline int32_t indexOf(UChar32 c,
00992               int32_t start) const;
00993 
01004   inline int32_t indexOf(UChar c,
01005               int32_t start,
01006               int32_t length) const;
01007 
01019   inline int32_t indexOf(UChar32 c,
01020               int32_t start,
01021               int32_t length) const;
01022 
01031   inline int32_t lastIndexOf(const UnicodeString& text) const;
01032 
01042   inline int32_t lastIndexOf(const UnicodeString& text,
01043               int32_t start) const;
01044 
01056   inline int32_t lastIndexOf(const UnicodeString& text,
01057               int32_t start,
01058               int32_t length) const;
01059 
01076   inline int32_t lastIndexOf(const UnicodeString& srcText,
01077               int32_t srcStart,
01078               int32_t srcLength,
01079               int32_t start,
01080               int32_t length) const;
01081 
01092   inline int32_t lastIndexOf(const UChar *srcChars,
01093               int32_t srcLength,
01094               int32_t start) const;
01095 
01108   inline int32_t lastIndexOf(const UChar *srcChars,
01109               int32_t srcLength,
01110               int32_t start,
01111               int32_t length) const;
01112 
01129   int32_t lastIndexOf(const UChar *srcChars,
01130               int32_t srcStart,
01131               int32_t srcLength,
01132               int32_t start,
01133               int32_t length) const;
01134 
01142   inline int32_t lastIndexOf(UChar c) const;
01143 
01152   inline int32_t lastIndexOf(UChar32 c) const;
01153 
01162   inline int32_t lastIndexOf(UChar c,
01163               int32_t start) const;
01164 
01174   inline int32_t lastIndexOf(UChar32 c,
01175               int32_t start) const;
01176 
01187   inline int32_t lastIndexOf(UChar c,
01188               int32_t start,
01189               int32_t length) const;
01190 
01202   inline int32_t lastIndexOf(UChar32 c,
01203               int32_t start,
01204               int32_t length) const;
01205 
01206 
01207   /* Character access */
01208 
01217   inline UChar charAt(int32_t offset) const;
01218 
01226   inline UChar operator[] (int32_t offset) const;
01227 
01239   inline UChar32 char32At(int32_t offset) const;
01240 
01256   inline int32_t getChar32Start(int32_t offset) const;
01257 
01274   inline int32_t getChar32Limit(int32_t offset) const;
01275 
01326   int32_t moveIndex32(int32_t index, int32_t delta) const;
01327 
01328   /* Substring extraction */
01329 
01345   inline void extract(int32_t start,
01346            int32_t length,
01347            UChar *dst,
01348            int32_t dstStart = 0) const;
01349 
01371   int32_t
01372   extract(UChar *dest, int32_t destCapacity,
01373           UErrorCode &errorCode) const;
01374 
01385   inline void extract(int32_t start,
01386            int32_t length,
01387            UnicodeString& target) const;
01388 
01400   inline void extractBetween(int32_t start,
01401               int32_t limit,
01402               UChar *dst,
01403               int32_t dstStart = 0) const;
01404 
01414   virtual void extractBetween(int32_t start,
01415               int32_t limit,
01416               UnicodeString& target) const;
01417 
01439   int32_t extract(int32_t start,
01440            int32_t startLength,
01441            char *target,
01442            int32_t targetCapacity,
01443            enum EInvariant inv) const;
01444 
01445 #if !UCONFIG_NO_CONVERSION
01446 
01472   inline int32_t extract(int32_t start,
01473                  int32_t startLength,
01474                  char *target,
01475                  const char *codepage = 0) const;
01476 
01506   int32_t extract(int32_t start,
01507            int32_t startLength,
01508            char *target,
01509            uint32_t targetLength,
01510            const char *codepage = 0) const;
01511 
01529   int32_t extract(char *dest, int32_t destCapacity,
01530                   UConverter *cnv,
01531                   UErrorCode &errorCode) const;
01532 
01533 #endif
01534 
01535   /* Length operations */
01536 
01545   inline int32_t length(void) const;
01546 
01560   int32_t
01561   countChar32(int32_t start=0, int32_t length=INT32_MAX) const;
01562 
01586   UBool
01587   hasMoreChar32Than(int32_t start, int32_t length, int32_t number) const;
01588 
01594   inline UBool isEmpty(void) const;
01595 
01605   inline int32_t getCapacity(void) const;
01606 
01607   /* Other operations */
01608 
01614   inline int32_t hashCode(void) const;
01615 
01627   inline UBool isBogus(void) const;
01628 
01629 
01630   //========================================
01631   // Write operations
01632   //========================================
01633 
01634   /* Assignment operations */
01635 
01643   UnicodeString &operator=(const UnicodeString &srcText);
01644 
01665   UnicodeString &fastCopyFrom(const UnicodeString &src);
01666 
01674   inline UnicodeString& operator= (UChar ch);
01675 
01683   inline UnicodeString& operator= (UChar32 ch);
01684 
01696   inline UnicodeString& setTo(const UnicodeString& srcText,
01697                int32_t srcStart);
01698 
01712   inline UnicodeString& setTo(const UnicodeString& srcText,
01713                int32_t srcStart,
01714                int32_t srcLength);
01715 
01724   inline UnicodeString& setTo(const UnicodeString& srcText);
01725 
01734   inline UnicodeString& setTo(const UChar *srcChars,
01735                int32_t srcLength);
01736 
01745   UnicodeString& setTo(UChar srcChar);
01746 
01755   UnicodeString& setTo(UChar32 srcChar);
01756 
01777   UnicodeString &setTo(UBool isTerminated,
01778                        const UChar *text,
01779                        int32_t textLength);
01780 
01800   UnicodeString &setTo(UChar *buffer,
01801                        int32_t buffLength,
01802                        int32_t buffCapacity);
01803 
01844   void setToBogus();
01845 
01853   UnicodeString& setCharAt(int32_t offset,
01854                UChar ch);
01855 
01856 
01857   /* Append operations */
01858 
01866  inline  UnicodeString& operator+= (UChar ch);
01867 
01875  inline  UnicodeString& operator+= (UChar32 ch);
01876 
01885   inline UnicodeString& operator+= (const UnicodeString& srcText);
01886 
01901   inline UnicodeString& append(const UnicodeString& srcText,
01902             int32_t srcStart,
01903             int32_t srcLength);
01904 
01912   inline UnicodeString& append(const UnicodeString& srcText);
01913 
01927   inline UnicodeString& append(const UChar *srcChars,
01928             int32_t srcStart,
01929             int32_t srcLength);
01930 
01939   inline UnicodeString& append(const UChar *srcChars,
01940             int32_t srcLength);
01941 
01948   inline UnicodeString& append(UChar srcChar);
01949 
01956   inline UnicodeString& append(UChar32 srcChar);
01957 
01958 
01959   /* Insert operations */
01960 
01974   inline UnicodeString& insert(int32_t start,
01975             const UnicodeString& srcText,
01976             int32_t srcStart,
01977             int32_t srcLength);
01978 
01987   inline UnicodeString& insert(int32_t start,
01988             const UnicodeString& srcText);
01989 
02003   inline UnicodeString& insert(int32_t start,
02004             const UChar *srcChars,
02005             int32_t srcStart,
02006             int32_t srcLength);
02007 
02017   inline UnicodeString& insert(int32_t start,
02018             const UChar *srcChars,
02019             int32_t srcLength);
02020 
02029   inline UnicodeString& insert(int32_t start,
02030             UChar srcChar);
02031 
02040   inline UnicodeString& insert(int32_t start,
02041             UChar32 srcChar);
02042 
02043 
02044   /* Replace operations */
02045 
02063   UnicodeString& replace(int32_t start,
02064              int32_t length,
02065              const UnicodeString& srcText,
02066              int32_t srcStart,
02067              int32_t srcLength);
02068 
02081   UnicodeString& replace(int32_t start,
02082              int32_t length,
02083              const UnicodeString& srcText);
02084 
02102   UnicodeString& replace(int32_t start,
02103              int32_t length,
02104              const UChar *srcChars,
02105              int32_t srcStart,
02106              int32_t srcLength);
02107 
02120   inline UnicodeString& replace(int32_t start,
02121              int32_t length,
02122              const UChar *srcChars,
02123              int32_t srcLength);
02124 
02136   inline UnicodeString& replace(int32_t start,
02137              int32_t length,
02138              UChar srcChar);
02139 
02151   inline UnicodeString& replace(int32_t start,
02152              int32_t length,
02153              UChar32 srcChar);
02154 
02164   inline UnicodeString& replaceBetween(int32_t start,
02165                 int32_t limit,
02166                 const UnicodeString& srcText);
02167 
02182   inline UnicodeString& replaceBetween(int32_t start,
02183                 int32_t limit,
02184                 const UnicodeString& srcText,
02185                 int32_t srcStart,
02186                 int32_t srcLimit);
02187 
02198   virtual void handleReplaceBetween(int32_t start,
02199                                     int32_t limit,
02200                                     const UnicodeString& text);
02201 
02207   virtual UBool hasMetaData() const;
02208 
02224   virtual void copy(int32_t start, int32_t limit, int32_t dest);
02225 
02226   /* Search and replace operations */
02227 
02236   inline UnicodeString& findAndReplace(const UnicodeString& oldText,
02237                 const UnicodeString& newText);
02238 
02250   inline UnicodeString& findAndReplace(int32_t start,
02251                 int32_t length,
02252                 const UnicodeString& oldText,
02253                 const UnicodeString& newText);
02254 
02272   UnicodeString& findAndReplace(int32_t start,
02273                 int32_t length,
02274                 const UnicodeString& oldText,
02275                 int32_t oldStart,
02276                 int32_t oldLength,
02277                 const UnicodeString& newText,
02278                 int32_t newStart,
02279                 int32_t newLength);
02280 
02281 
02282   /* Remove operations */
02283 
02289   inline UnicodeString& remove(void);
02290 
02299   inline UnicodeString& remove(int32_t start,
02300                                int32_t length = (int32_t)INT32_MAX);
02301 
02310   inline UnicodeString& removeBetween(int32_t start,
02311                                       int32_t limit = (int32_t)INT32_MAX);
02312 
02313 
02314   /* Length operations */
02315 
02327   UBool padLeading(int32_t targetLength,
02328                     UChar padChar = 0x0020);
02329 
02341   UBool padTrailing(int32_t targetLength,
02342                      UChar padChar = 0x0020);
02343 
02350   inline UBool truncate(int32_t targetLength);
02351 
02357   UnicodeString& trim(void);
02358 
02359 
02360   /* Miscellaneous operations */
02361 
02367   inline UnicodeString& reverse(void);
02368 
02377   inline UnicodeString& reverse(int32_t start,
02378              int32_t length);
02379 
02386   UnicodeString& toUpper(void);
02387 
02395   UnicodeString& toUpper(const Locale& locale);
02396 
02403   UnicodeString& toLower(void);
02404 
02412   UnicodeString& toLower(const Locale& locale);
02413 
02414 #if !UCONFIG_NO_BREAK_ITERATION
02415 
02442   UnicodeString &toTitle(BreakIterator *titleIter);
02443 
02471   UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale);
02472 
02473 #endif
02474 
02486   UnicodeString &foldCase(uint32_t options=0 /*U_FOLD_CASE_DEFAULT*/);
02487 
02488   //========================================
02489   // Access to the internal buffer
02490   //========================================
02491 
02535   UChar *getBuffer(int32_t minCapacity);
02536 
02557   void releaseBuffer(int32_t newLength=-1);
02558 
02589   inline const UChar *getBuffer() const;
02590 
02624   inline const UChar *getTerminatedBuffer();
02625 
02626   //========================================
02627   // Constructors
02628   //========================================
02629 
02633   UnicodeString();
02634 
02646   UnicodeString(int32_t capacity, UChar32 c, int32_t count);
02647 
02653   UnicodeString(UChar ch);
02654 
02660   UnicodeString(UChar32 ch);
02661 
02668   UnicodeString(const UChar *text);
02669 
02677   UnicodeString(const UChar *text,
02678         int32_t textLength);
02679 
02699   UnicodeString(UBool isTerminated,
02700                 const UChar *text,
02701                 int32_t textLength);
02702 
02721   UnicodeString(UChar *buffer, int32_t buffLength, int32_t buffCapacity);
02722 
02723 #if !UCONFIG_NO_CONVERSION
02724 
02742   UnicodeString(const char *codepageData,
02743         const char *codepage = 0);
02744 
02762   UnicodeString(const char *codepageData,
02763         int32_t dataLength,
02764         const char *codepage = 0);
02765 
02787   UnicodeString(
02788         const char *src, int32_t srcLength,
02789         UConverter *cnv,
02790         UErrorCode &errorCode);
02791 
02792 #endif
02793 
02818   UnicodeString(const char *src, int32_t length, enum EInvariant inv);
02819 
02820 
02826   UnicodeString(const UnicodeString& that);
02827 
02834   UnicodeString(const UnicodeString& src, int32_t srcStart);
02835 
02843   UnicodeString(const UnicodeString& src, int32_t srcStart, int32_t srcLength);
02844 
02861   virtual Replaceable *clone() const;
02862 
02866   virtual ~UnicodeString();
02867 
02868 
02869   /* Miscellaneous operations */
02870 
02905   UnicodeString unescape() const;
02906 
02926   UChar32 unescapeAt(int32_t &offset) const;
02927 
02933   static UClassID U_EXPORT2 getStaticClassID();
02934 
02940   virtual UClassID getDynamicClassID() const;
02941 
02942   //========================================
02943   // Implementation methods
02944   //========================================
02945 
02946 protected:
02951   virtual int32_t getLength() const;
02952 
02958   virtual UChar getCharAt(int32_t offset) const;
02959 
02965   virtual UChar32 getChar32At(int32_t offset) const;
02966 
02967 private:
02968 
02969   inline int8_t
02970   doCompare(int32_t start,
02971            int32_t length,
02972            const UnicodeString& srcText,
02973            int32_t srcStart,
02974            int32_t srcLength) const;
02975 
02976   int8_t doCompare(int32_t start,
02977            int32_t length,
02978            const UChar *srcChars,
02979            int32_t srcStart,
02980            int32_t srcLength) const;
02981 
02982   inline int8_t
02983   doCompareCodePointOrder(int32_t start,
02984                           int32_t length,
02985                           const UnicodeString& srcText,
02986                           int32_t srcStart,
02987                           int32_t srcLength) const;
02988 
02989   int8_t doCompareCodePointOrder(int32_t start,
02990                                  int32_t length,
02991                                  const UChar *srcChars,
02992                                  int32_t srcStart,
02993                                  int32_t srcLength) const;
02994 
02995   inline int8_t
02996   doCaseCompare(int32_t start,
02997                 int32_t length,
02998                 const UnicodeString &srcText,
02999                 int32_t srcStart,
03000                 int32_t srcLength,
03001                 uint32_t options) const;
03002 
03003   int8_t
03004   doCaseCompare(int32_t start,
03005                 int32_t length,
03006                 const UChar *srcChars,
03007                 int32_t srcStart,
03008                 int32_t srcLength,
03009                 uint32_t options) const;
03010 
03011   int32_t doIndexOf(UChar c,
03012             int32_t start,
03013             int32_t length) const;
03014 
03015   int32_t doIndexOf(UChar32 c,
03016                         int32_t start,
03017                         int32_t length) const;
03018 
03019   int32_t doLastIndexOf(UChar c,
03020                 int32_t start,
03021                 int32_t length) const;
03022 
03023   int32_t doLastIndexOf(UChar32 c,
03024                             int32_t start,
03025                             int32_t length) const;
03026 
03027   void doExtract(int32_t start,
03028          int32_t length,
03029          UChar *dst,
03030          int32_t dstStart) const;
03031 
03032   inline void doExtract(int32_t start,
03033          int32_t length,
03034          UnicodeString& target) const;
03035 
03036   inline UChar doCharAt(int32_t offset)  const;
03037 
03038   UnicodeString& doReplace(int32_t start,
03039                int32_t length,
03040                const UnicodeString& srcText,
03041                int32_t srcStart,
03042                int32_t srcLength);
03043 
03044   UnicodeString& doReplace(int32_t start,
03045                int32_t length,
03046                const UChar *srcChars,
03047                int32_t srcStart,
03048                int32_t srcLength);
03049 
03050   UnicodeString& doReverse(int32_t start,
03051                int32_t length);
03052 
03053   // calculate hash code
03054   int32_t doHashCode(void) const;
03055 
03056   // get pointer to start of array
03057   inline UChar* getArrayStart(void);
03058   inline const UChar* getArrayStart(void) const;
03059 
03060   // allocate the array; result may be fStackBuffer
03061   // sets refCount to 1 if appropriate
03062   // sets fArray, fCapacity, and fFlags
03063   // returns boolean for success or failure
03064   UBool allocate(int32_t capacity);
03065 
03066   // release the array if owned
03067   void releaseArray(void);
03068 
03069   // turn a bogus string into an empty one
03070   void unBogus();
03071 
03072   // implements assigment operator, copy constructor, and fastCopyFrom()
03073   UnicodeString &copyFrom(const UnicodeString &src, UBool fastCopy=FALSE);
03074 
03075   // Pin start and limit to acceptable values.
03076   inline void pinIndex(int32_t& start) const;
03077   inline void pinIndices(int32_t& start,
03078                          int32_t& length) const;
03079 
03080 #if !UCONFIG_NO_CONVERSION
03081 
03082   /* Internal extract() using UConverter. */
03083   int32_t doExtract(int32_t start, int32_t length,
03084                     char *dest, int32_t destCapacity,
03085                     UConverter *cnv,
03086                     UErrorCode &errorCode) const;
03087 
03088   /*
03089    * Real constructor for converting from codepage data.
03090    * It assumes that it is called with !fRefCounted.
03091    *
03092    * If <code>codepage==0</code>, then the default converter
03093    * is used for the platform encoding.
03094    * If <code>codepage</code> is an empty string (<code>""</code>),
03095    * then a simple conversion is performed on the codepage-invariant
03096    * subset ("invariant characters") of the platform encoding. See utypes.h.
03097    */
03098   void doCodepageCreate(const char *codepageData,
03099                         int32_t dataLength,
03100                         const char *codepage);
03101 
03102   /*
03103    * Worker function for creating a UnicodeString from
03104    * a codepage string using a UConverter.
03105    */
03106   void
03107   doCodepageCreate(const char *codepageData,
03108                    int32_t dataLength,
03109                    UConverter *converter,
03110                    UErrorCode &status);
03111 
03112 #endif
03113 
03114   /*
03115    * This function is called when write access to the array
03116    * is necessary.
03117    *
03118    * We need to make a copy of the array if
03119    * the buffer is read-only, or
03120    * the buffer is refCounted (shared), and refCount>1, or
03121    * the buffer is too small.
03122    *
03123    * Return FALSE if memory could not be allocated.
03124    */
03125   UBool cloneArrayIfNeeded(int32_t newCapacity = -1,
03126                             int32_t growCapacity = -1,
03127                             UBool doCopyArray = TRUE,
03128                             int32_t **pBufferToDelete = 0,
03129                             UBool forceClone = FALSE);
03130 
03131   // common function for case mappings
03132   UnicodeString &
03133   caseMap(BreakIterator *titleIter,
03134           const char *locale,
03135           uint32_t options,
03136           int32_t toWhichCase);
03137 
03138   // ref counting
03139   void addRef(void);
03140   int32_t removeRef(void);
03141   int32_t refCount(void) const;
03142 
03143   // constants
03144   enum {
03145     US_STACKBUF_SIZE=7, // Size of stack buffer for small strings
03146     kInvalidUChar=0xffff, // invalid UChar index
03147     kGrowSize=128, // grow size for this buffer
03148     kInvalidHashCode=0, // invalid hash code
03149     kEmptyHashCode=1, // hash code for empty string
03150 
03151     // bit flag values for fFlags
03152     kIsBogus=1,         // this string is bogus, i.e., not valid or NULL
03153     kUsingStackBuffer=2,// fArray==fStackBuffer
03154     kRefCounted=4,      // there is a refCount field before the characters in fArray
03155     kBufferIsReadonly=8,// do not write to this buffer
03156     kOpenGetBuffer=16,  // getBuffer(minCapacity) was called (is "open"),
03157                         // and releaseBuffer(newLength) must be called
03158 
03159     // combined values for convenience
03160     kShortString=kUsingStackBuffer,
03161     kLongString=kRefCounted,
03162     kReadonlyAlias=kBufferIsReadonly,
03163     kWritableAlias=0
03164   };
03165 
03166   friend class StringCharacterIterator;
03167   friend class StringThreadTest;
03168 
03169   /*
03170    * The following are all the class fields that are stored
03171    * in each UnicodeString object.
03172    * Note that UnicodeString has virtual functions,
03173    * therefore there is an implicit vtable pointer
03174    * as the first real field.
03175    * The fields should be aligned such that no padding is
03176    * necessary, mostly by having larger types first.
03177    * On 32-bit machines, the size should be 32 bytes,
03178    * on 64-bit machines (8-byte pointers), it should be 40 bytes.
03179    */
03180   // (implicit) *vtable;
03181   int32_t   fLength;        // number of characters in fArray
03182   int32_t   fCapacity;      // sizeof fArray
03183   UChar     *fArray;        // the Unicode data
03184   uint16_t  fFlags;         // bit flags: see constants above
03185   UChar     fStackBuffer [ US_STACKBUF_SIZE ]; // buffer for small strings
03186 
03187 };
03188 
03197 U_COMMON_API UnicodeString U_EXPORT2
03198 operator+ (const UnicodeString &s1, const UnicodeString &s2);
03199 
03200 U_NAMESPACE_END
03201 
03202 // inline implementations -------------------------------------------------- ***
03203 
03204 //========================================
03205 // Array copying
03206 //========================================
03211 inline void
03212 uprv_arrayCopy(const U_NAMESPACE_QUALIFIER UnicodeString *src, U_NAMESPACE_QUALIFIER UnicodeString *dst, int32_t count)
03213 { while(count-- > 0) *dst++ = *src++; }
03214 
03219 inline void
03220 uprv_arrayCopy(const U_NAMESPACE_QUALIFIER UnicodeString *src, int32_t srcStart,
03221         U_NAMESPACE_QUALIFIER UnicodeString *dst, int32_t dstStart, int32_t count)
03222 { uprv_arrayCopy(src+srcStart, dst+dstStart, count); }
03223 
03224 U_NAMESPACE_BEGIN
03225 
03226 //========================================
03227 // Inline members
03228 //========================================
03229 
03230 //========================================
03231 // Privates
03232 //========================================
03233 
03234 inline void
03235 UnicodeString::pinIndex(int32_t& start) const
03236 {
03237   // pin index
03238   if(start < 0) {
03239     start = 0;
03240   } else if(start > fLength) {
03241     start = fLength;
03242   }
03243 }
03244 
03245 inline void
03246 UnicodeString::pinIndices(int32_t& start,
03247                           int32_t& _length) const
03248 {
03249   // pin indices
03250   if(start < 0) {
03251     start = 0;
03252   } else if(start > fLength) {
03253     start = fLength;
03254   }
03255   if(_length < 0) {
03256     _length = 0;
03257   } else if(_length > (fLength - start)) {
03258     _length = (fLength - start);
03259   }
03260 }
03261 
03262 inline UChar*
03263 UnicodeString::getArrayStart()
03264 { return fArray; }
03265 
03266 inline const UChar*
03267 UnicodeString::getArrayStart() const
03268 { return fArray; }
03269 
03270 //========================================
03271 // Read-only implementation methods
03272 //========================================
03273 inline int32_t
03274 UnicodeString::length() const
03275 { return fLength; }
03276 
03277 inline int32_t
03278 UnicodeString::getCapacity() const
03279 { return fCapacity; }
03280 
03281 inline int32_t
03282 UnicodeString::hashCode() const
03283 { return doHashCode(); }
03284 
03285 inline UBool
03286 UnicodeString::isBogus() const
03287 { return (UBool)(fFlags & kIsBogus); }
03288 
03289 inline const UChar *
03290 UnicodeString::getBuffer() const {
03291   if(!(fFlags&(kIsBogus|kOpenGetBuffer))) {
03292     return fArray;
03293   } else {
03294     return 0;
03295   }
03296 }
03297 
03298 //========================================
03299 // Read-only alias methods
03300 //========================================
03301 inline int8_t
03302 UnicodeString::doCompare(int32_t start,
03303               int32_t length,
03304               const UnicodeString& srcText,
03305               int32_t srcStart,
03306               int32_t srcLength) const
03307 {
03308   if(srcText.isBogus()) {
03309     return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
03310   } else {
03311     srcText.pinIndices(srcStart, srcLength);
03312     return doCompare(start, length, srcText.fArray, srcStart, srcLength);
03313   }
03314 }
03315 
03316 inline UBool
03317 UnicodeString::operator== (const UnicodeString& text) const
03318 {
03319   if(isBogus()) {
03320     return text.isBogus();
03321   } else {
03322     return
03323       !text.isBogus() &&
03324       fLength == text.fLength &&
03325       doCompare(0, fLength, text, 0, text.fLength) == 0;
03326   }
03327 }
03328 
03329 inline UBool
03330 UnicodeString::operator!= (const UnicodeString& text) const
03331 { return (! operator==(text)); }
03332 
03333 inline UBool
03334 UnicodeString::operator> (const UnicodeString& text) const
03335 { return doCompare(0, fLength, text, 0, text.fLength) == 1; }
03336 
03337 inline UBool
03338 UnicodeString::operator< (const UnicodeString& text) const
03339 { return doCompare(0, fLength, text, 0, text.fLength) == -1; }
03340 
03341 inline UBool
03342 UnicodeString::operator>= (const UnicodeString& text) const
03343 { return doCompare(0, fLength, text, 0, text.fLength) != -1; }
03344 
03345 inline UBool
03346 UnicodeString::operator<= (const UnicodeString& text) const
03347 { return doCompare(0, fLength, text, 0, text.fLength) != 1; }
03348 
03349 inline int8_t
03350 UnicodeString::compare(const UnicodeString& text) const
03351 { return doCompare(0, fLength, text, 0, text.fLength); }
03352 
03353 inline int8_t
03354 UnicodeString::compare(int32_t start,
03355                int32_t _length,
03356                const UnicodeString& srcText) const
03357 { return doCompare(start, _length, srcText, 0, srcText.fLength); }
03358 
03359 inline int8_t
03360 UnicodeString::compare(const UChar *srcChars,
03361                int32_t srcLength) const
03362 { return doCompare(0, fLength, srcChars, 0, srcLength); }
03363 
03364 inline int8_t
03365 UnicodeString::compare(int32_t start,
03366                int32_t _length,
03367                const UnicodeString& srcText,
03368                int32_t srcStart,
03369                int32_t srcLength) const
03370 { return doCompare(start, _length, srcText, srcStart, srcLength); }
03371 
03372 inline int8_t
03373 UnicodeString::compare(int32_t start,
03374                int32_t _length,
03375                const UChar *srcChars) const
03376 { return doCompare(start, _length, srcChars, 0, _length); }
03377 
03378 inline int8_t
03379 UnicodeString::compare(int32_t start,
03380                int32_t _length,
03381                const UChar *srcChars,
03382                int32_t srcStart,
03383                int32_t srcLength) const
03384 { return doCompare(start, _length, srcChars, srcStart, srcLength); }
03385 
03386 inline int8_t
03387 UnicodeString::compareBetween(int32_t start,
03388                   int32_t limit,
03389                   const UnicodeString& srcText,
03390                   int32_t srcStart,
03391                   int32_t srcLimit) const
03392 { return doCompare(start, limit - start,
03393            srcText, srcStart, srcLimit - srcStart); }
03394 
03395 inline int8_t
03396 UnicodeString::doCompareCodePointOrder(int32_t start,
03397                                        int32_t length,
03398                                        const UnicodeString& srcText,
03399                                        int32_t srcStart,
03400                                        int32_t srcLength) const
03401 {
03402   if(srcText.isBogus()) {
03403     return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
03404   } else {
03405     srcText.pinIndices(srcStart, srcLength);
03406     return doCompareCodePointOrder(start, length, srcText.fArray, srcStart, srcLength);
03407   }
03408 }
03409 
03410 inline int8_t
03411 UnicodeString::compareCodePointOrder(const UnicodeString& text) const
03412 { return doCompareCodePointOrder(0, fLength, text, 0, text.fLength); }
03413 
03414 inline int8_t
03415 UnicodeString::compareCodePointOrder(int32_t start,
03416                                      int32_t _length,
03417                                      const UnicodeString& srcText) const
03418 { return doCompareCodePointOrder(start, _length, srcText, 0, srcText.fLength); }
03419 
03420 inline int8_t
03421 UnicodeString::compareCodePointOrder(const UChar *srcChars,
03422                                      int32_t srcLength) const
03423 { return doCompareCodePointOrder(0, fLength, srcChars, 0, srcLength); }
03424 
03425 inline int8_t
03426 UnicodeString::compareCodePointOrder(int32_t start,
03427                                      int32_t _length,
03428                                      const UnicodeString& srcText,
03429                                      int32_t srcStart,
03430                                      int32_t srcLength) const
03431 { return doCompareCodePointOrder(start, _length, srcText, srcStart, srcLength); }
03432 
03433 inline int8_t
03434 UnicodeString::compareCodePointOrder(int32_t start,
03435                                      int32_t _length,
03436                                      const UChar *srcChars) const
03437 { return doCompareCodePointOrder(start, _length, srcChars, 0, _length); }
03438 
03439 inline int8_t
03440 UnicodeString::compareCodePointOrder(int32_t start,
03441                                      int32_t _length,
03442                                      const UChar *srcChars,
03443                                      int32_t srcStart,
03444                                      int32_t srcLength) const
03445 { return doCompareCodePointOrder(start, _length, srcChars, srcStart, srcLength); }
03446 
03447 inline int8_t
03448 UnicodeString::compareCodePointOrderBetween(int32_t start,
03449                                             int32_t limit,
03450                                             const UnicodeString& srcText,
03451                                             int32_t srcStart,
03452                                             int32_t srcLimit) const
03453 { return doCompareCodePointOrder(start, limit - start,
03454            srcText, srcStart, srcLimit - srcStart); }
03455 
03456 inline int8_t
03457 UnicodeString::doCaseCompare(int32_t start,
03458                              int32_t length,
03459                              const UnicodeString &srcText,
03460                              int32_t srcStart,
03461                              int32_t srcLength,
03462                              uint32_t options) const
03463 {
03464   if(srcText.isBogus()) {
03465     return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
03466   } else {
03467     srcText.pinIndices(srcStart, srcLength);
03468     return doCaseCompare(start, length, srcText.fArray, srcStart, srcLength, options);
03469   }
03470 }
03471 
03472 inline int8_t
03473 UnicodeString::caseCompare(const UnicodeString &text, uint32_t options) const {
03474   return doCaseCompare(0, fLength, text, 0, text.fLength, options);
03475 }
03476 
03477 inline int8_t
03478 UnicodeString::caseCompare(int32_t start,
03479                            int32_t _length,
03480                            const UnicodeString &srcText,
03481                            uint32_t options) const {
03482   return doCaseCompare(start, _length, srcText, 0, srcText.fLength, options);
03483 }
03484 
03485 inline int8_t
03486 UnicodeString::caseCompare(const UChar *srcChars,
03487                            int32_t srcLength,
03488                            uint32_t options) const {
03489   return doCaseCompare(0, fLength, srcChars, 0, srcLength, options);
03490 }
03491 
03492 inline int8_t
03493 UnicodeString::caseCompare(int32_t start,
03494                            int32_t _length,
03495                            const UnicodeString &srcText,
03496                            int32_t srcStart,
03497                            int32_t srcLength,
03498                            uint32_t options) const {
03499   return doCaseCompare(start, _length, srcText, srcStart, srcLength, options);
03500 }
03501 
03502 inline int8_t
03503 UnicodeString::caseCompare(int32_t start,
03504                            int32_t _length,
03505                            const UChar *srcChars,
03506                            uint32_t options) const {
03507   return doCaseCompare(start, _length, srcChars, 0, _length, options);
03508 }
03509 
03510 inline int8_t
03511 UnicodeString::caseCompare(int32_t start,
03512                            int32_t _length,
03513                            const UChar *srcChars,
03514                            int32_t srcStart,
03515                            int32_t srcLength,
03516                            uint32_t options) const {
03517   return doCaseCompare(start, _length, srcChars, srcStart, srcLength, options);
03518 }
03519 
03520 inline int8_t
03521 UnicodeString::caseCompareBetween(int32_t start,
03522                                   int32_t limit,
03523                                   const UnicodeString &srcText,
03524                                   int32_t srcStart,
03525                                   int32_t srcLimit,
03526                                   uint32_t options) const {
03527   return doCaseCompare(start, limit - start, srcText, srcStart, srcLimit - srcStart, options);
03528 }
03529 
03530 inline int32_t
03531 UnicodeString::indexOf(const UnicodeString& srcText,
03532                int32_t srcStart,
03533                int32_t srcLength,
03534                int32_t start,
03535                int32_t _length) const
03536 {
03537   if(!srcText.isBogus()) {
03538     srcText.pinIndices(srcStart, srcLength);
03539     if(srcLength > 0) {
03540       return indexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
03541     }
03542   }
03543   return -1;
03544 }
03545 
03546 inline int32_t
03547 UnicodeString::indexOf(const UnicodeString& text) const
03548 { return indexOf(text, 0, text.fLength, 0, fLength); }
03549 
03550 inline int32_t
03551 UnicodeString::indexOf(const UnicodeString& text,
03552                int32_t start) const {
03553   pinIndex(start);
03554   return indexOf(text, 0, text.fLength, start, fLength - start);
03555 }
03556 
03557 inline int32_t
03558 UnicodeString::indexOf(const UnicodeString& text,
03559                int32_t start,
03560                int32_t _length) const
03561 { return indexOf(text, 0, text.fLength, start, _length); }
03562 
03563 inline int32_t
03564 UnicodeString::indexOf(const UChar *srcChars,
03565                int32_t srcLength,
03566                int32_t start) const {
03567   pinIndex(start);
03568   return indexOf(srcChars, 0, srcLength, start, fLength - start);
03569 }
03570 
03571 inline int32_t
03572 UnicodeString::indexOf(const UChar *srcChars,
03573                int32_t srcLength,
03574                int32_t start,
03575                int32_t _length) const
03576 { return indexOf(srcChars, 0, srcLength, start, _length); }
03577 
03578 inline int32_t
03579 UnicodeString::indexOf(UChar c,
03580                int32_t start,
03581                int32_t _length) const
03582 { return doIndexOf(c, start, _length); }
03583 
03584 inline int32_t
03585 UnicodeString::indexOf(UChar32 c,
03586                int32_t start,
03587                int32_t _length) const
03588 { return doIndexOf(c, start, _length); }
03589 
03590 inline int32_t
03591 UnicodeString::indexOf(UChar c) const
03592 { return doIndexOf(c, 0, fLength); }
03593 
03594 inline int32_t
03595 UnicodeString::indexOf(UChar32 c) const
03596 { return indexOf(c, 0, fLength); }
03597 
03598 inline int32_t
03599 UnicodeString::indexOf(UChar c,
03600                int32_t start) const {
03601   pinIndex(start);
03602   return doIndexOf(c, start, fLength - start);
03603 }
03604 
03605 inline int32_t
03606 UnicodeString::indexOf(UChar32 c,
03607                int32_t start) const {
03608   pinIndex(start);
03609   return indexOf(c, start, fLength - start);
03610 }
03611 
03612 inline int32_t
03613 UnicodeString::lastIndexOf(const UChar *srcChars,
03614                int32_t srcLength,
03615                int32_t start,
03616                int32_t _length) const
03617 { return lastIndexOf(srcChars, 0, srcLength, start, _length); }
03618 
03619 inline int32_t
03620 UnicodeString::lastIndexOf(const UChar *srcChars,
03621                int32_t srcLength,
03622                int32_t start) const {
03623   pinIndex(start);
03624   return lastIndexOf(srcChars, 0, srcLength, start, fLength - start);
03625 }
03626 
03627 inline int32_t
03628 UnicodeString::lastIndexOf(const UnicodeString& srcText,
03629                int32_t srcStart,
03630                int32_t srcLength,
03631                int32_t start,
03632                int32_t _length) const
03633 {
03634   if(!srcText.isBogus()) {
03635     srcText.pinIndices(srcStart, srcLength);
03636     if(srcLength > 0) {
03637       return lastIndexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
03638     }
03639   }
03640   return -1;
03641 }
03642 
03643 inline int32_t
03644 UnicodeString::lastIndexOf(const UnicodeString& text,
03645                int32_t start,
03646                int32_t _length) const
03647 { return lastIndexOf(text, 0, text.fLength, start, _length); }
03648 
03649 inline int32_t
03650 UnicodeString::lastIndexOf(const UnicodeString& text,
03651                int32_t start) const {
03652   pinIndex(start);
03653   return lastIndexOf(text, 0, text.fLength, start, fLength - start);
03654 }
03655 
03656 inline int32_t
03657 UnicodeString::lastIndexOf(const UnicodeString& text) const
03658 { return lastIndexOf(text, 0, text.fLength, 0, fLength); }
03659 
03660 inline int32_t
03661 UnicodeString::lastIndexOf(UChar c,
03662                int32_t start,
03663                int32_t _length) const
03664 { return doLastIndexOf(c, start, _length); }
03665 
03666 inline int32_t
03667 UnicodeString::lastIndexOf(UChar32 c,
03668                int32_t start,
03669                int32_t _length) const {
03670   return doLastIndexOf(c, start, _length);
03671 }
03672 
03673 inline int32_t
03674 UnicodeString::lastIndexOf(UChar c) const
03675 { return doLastIndexOf(c, 0, fLength); }
03676 
03677 inline int32_t
03678 UnicodeString::lastIndexOf(UChar32 c) const {
03679   return lastIndexOf(c, 0, fLength);
03680 }
03681 
03682 inline int32_t
03683 UnicodeString::lastIndexOf(UChar c,
03684                int32_t start) const {
03685   pinIndex(start);
03686   return doLastIndexOf(c, start, fLength - start);
03687 }
03688 
03689 inline int32_t
03690 UnicodeString::lastIndexOf(UChar32 c,
03691                int32_t start) const {
03692   pinIndex(start);
03693   return lastIndexOf(c, start, fLength - start);
03694 }
03695 
03696 inline UBool
03697 UnicodeString::startsWith(const UnicodeString& text) const
03698 { return compare(0, text.fLength, text, 0, text.fLength) == 0; }
03699 
03700 inline UBool
03701 UnicodeString::startsWith(const UnicodeString& srcText,
03702               int32_t srcStart,
03703               int32_t srcLength) const
03704 { return doCompare(0, srcLength, srcText, srcStart, srcLength) == 0; }
03705 
03706 inline UBool
03707 UnicodeString::startsWith(const UChar *srcChars,
03708               int32_t srcLength) const
03709 { return doCompare(0, srcLength, srcChars, 0, srcLength) == 0; }
03710 
03711 inline UBool
03712 UnicodeString::startsWith(const UChar *srcChars,
03713               int32_t srcStart,
03714               int32_t srcLength) const
03715 { return doCompare(0, srcLength, srcChars, srcStart, srcLength) == 0;}
03716 
03717 inline UBool
03718 UnicodeString::endsWith(const UnicodeString& text) const
03719 { return doCompare(fLength - text.fLength, text.fLength,
03720            text, 0, text.fLength) == 0; }
03721 
03722 inline UBool
03723 UnicodeString::endsWith(const UnicodeString& srcText,
03724             int32_t srcStart,
03725             int32_t srcLength) const {
03726   srcText.pinIndices(srcStart, srcLength);
03727   return doCompare(fLength - srcLength, srcLength,
03728                    srcText, srcStart, srcLength) == 0;
03729 }
03730 
03731 inline UBool
03732 UnicodeString::endsWith(const UChar *srcChars,
03733             int32_t srcLength) const {
03734   if(srcLength < 0) {
03735     srcLength = u_strlen(srcChars);
03736   }
03737   return doCompare(fLength - srcLength, srcLength,
03738                    srcChars, 0, srcLength) == 0;
03739 }
03740 
03741 inline UBool
03742 UnicodeString::endsWith(const UChar *srcChars,
03743             int32_t srcStart,
03744             int32_t srcLength) const {
03745   if(srcLength < 0) {
03746     srcLength = u_strlen(srcChars + srcStart);
03747   }
03748   return doCompare(fLength - srcLength, srcLength,
03749                    srcChars, srcStart, srcLength) == 0;
03750 }
03751 
03752 //========================================
03753 // replace
03754 //========================================
03755 inline UnicodeString&
03756 UnicodeString::replace(int32_t start,
03757                int32_t _length,
03758                const UnicodeString& srcText)
03759 { return doReplace(start, _length, srcText, 0, srcText.fLength); }
03760 
03761 inline UnicodeString&
03762 UnicodeString::replace(int32_t start,
03763                int32_t _length,
03764                const UnicodeString& srcText,
03765                int32_t srcStart,
03766                int32_t srcLength)
03767 { return doReplace(start, _length, srcText, srcStart, srcLength); }
03768 
03769 inline UnicodeString&
03770 UnicodeString::replace(int32_t start,
03771                int32_t _length,
03772                const UChar *srcChars,
03773                int32_t srcLength)
03774 { return doReplace(start, _length, srcChars, 0, srcLength); }
03775 
03776 inline UnicodeString&
03777 UnicodeString::replace(int32_t start,
03778                int32_t _length,
03779                const UChar *srcChars,
03780                int32_t srcStart,
03781                int32_t srcLength)
03782 { return doReplace(start, _length, srcChars, srcStart, srcLength); }
03783 
03784 inline UnicodeString&
03785 UnicodeString::replace(int32_t start,
03786                int32_t _length,
03787                UChar srcChar)
03788 { return doReplace(start, _length, &srcChar, 0, 1); }
03789 
03790 inline UnicodeString&
03791 UnicodeString::replace(int32_t start,
03792                int32_t _length,
03793                UChar32 srcChar) {
03794   UChar buffer[U16_MAX_LENGTH];
03795   int32_t count = 0;
03796   UBool isError = FALSE;
03797   U16_APPEND(buffer, count, U16_MAX_LENGTH, srcChar, isError);
03798   return doReplace(start, _length, buffer, 0, count);
03799 }
03800 
03801 inline UnicodeString&
03802 UnicodeString::replaceBetween(int32_t start,
03803                   int32_t limit,
03804                   const UnicodeString& srcText)
03805 { return doReplace(start, limit - start, srcText, 0, srcText.fLength); }
03806 
03807 inline UnicodeString&
03808 UnicodeString::replaceBetween(int32_t start,
03809                   int32_t limit,
03810                   const UnicodeString& srcText,
03811                   int32_t srcStart,
03812                   int32_t srcLimit)
03813 { return doReplace(start, limit - start, srcText, srcStart, srcLimit - srcStart); }
03814 
03815 inline UnicodeString&
03816 UnicodeString::findAndReplace(const UnicodeString& oldText,
03817                   const UnicodeString& newText)
03818 { return findAndReplace(0, fLength, oldText, 0, oldText.fLength,
03819             newText, 0, newText.fLength); }
03820 
03821 inline UnicodeString&
03822 UnicodeString::findAndReplace(int32_t start,
03823                   int32_t _length,
03824                   const UnicodeString& oldText,
03825                   const UnicodeString& newText)
03826 { return findAndReplace(start, _length, oldText, 0, oldText.fLength,
03827             newText, 0, newText.fLength); }
03828 
03829 // ============================
03830 // extract
03831 // ============================
03832 inline void
03833 UnicodeString::doExtract(int32_t start,
03834              int32_t _length,
03835              UnicodeString& target) const
03836 { target.replace(0, target.fLength, *this, start, _length); }
03837 
03838 inline void
03839 UnicodeString::extract(int32_t start,
03840                int32_t _length,
03841                UChar *target,
03842                int32_t targetStart) const
03843 { doExtract(start, _length, target, targetStart); }
03844 
03845 inline void
03846 UnicodeString::extract(int32_t start,
03847                int32_t _length,
03848                UnicodeString& target) const
03849 { doExtract(start, _length, target); }
03850 
03851 #if !UCONFIG_NO_CONVERSION
03852 
03853 inline int32_t
03854 UnicodeString::extract(int32_t start,
03855                int32_t _length,
03856                char *dst,
03857                const char *codepage) const
03858 
03859 {
03860   // This dstSize value will be checked explicitly
03861   return extract(start, _length, dst, dst!=0 ? 0xffffffff : 0, codepage);
03862 }
03863 
03864 #endif
03865 
03866 inline void
03867 UnicodeString::extractBetween(int32_t start,
03868                   int32_t limit,
03869                   UChar *dst,
03870                   int32_t dstStart) const {
03871   pinIndex(start);
03872   pinIndex(limit);
03873   doExtract(start, limit - start, dst, dstStart);
03874 }
03875 
03876 inline UChar
03877 UnicodeString::doCharAt(int32_t offset) const
03878 {
03879   if((uint32_t)offset < (uint32_t)fLength) {
03880     return fArray[offset];
03881   } else {
03882     return kInvalidUChar;
03883   }
03884 }
03885 
03886 inline UChar
03887 UnicodeString::charAt(int32_t offset) const
03888 { return doCharAt(offset); }
03889 
03890 inline UChar
03891 UnicodeString::operator[] (int32_t offset) const
03892 { return doCharAt(offset); }
03893 
03894 inline UChar32
03895 UnicodeString::char32At(int32_t offset) const
03896 {
03897   if((uint32_t)offset < (uint32_t)fLength) {
03898     UChar32 c;
03899     U16_GET(fArray, 0, offset, fLength, c);
03900     return c;
03901   } else {
03902     return kInvalidUChar;
03903   }
03904 }
03905 
03906 inline int32_t
03907 UnicodeString::getChar32Start(int32_t offset) const {
03908   if((uint32_t)offset < (uint32_t)fLength) {
03909     U16_SET_CP_START(fArray, 0, offset);
03910     return offset;
03911   } else {
03912     return 0;
03913   }
03914 }
03915 
03916 inline int32_t
03917 UnicodeString::getChar32Limit(int32_t offset) const {
03918   if((uint32_t)offset < (uint32_t)fLength) {
03919     U16_SET_CP_LIMIT(fArray, 0, offset, fLength);
03920     return offset;
03921   } else {
03922     return fLength;
03923   }
03924 }
03925 
03926 inline UBool
03927 UnicodeString::isEmpty() const {
03928   return fLength == 0;
03929 }
03930 
03931 //========================================
03932 // Write implementation methods
03933 //========================================
03934 inline const UChar *
03935 UnicodeString::getTerminatedBuffer() {
03936   if(fFlags&(kIsBogus|kOpenGetBuffer)) {
03937     return 0;
03938   } else if(fLength<fCapacity && fArray[fLength]==0) {
03939     return fArray;
03940   } else if(cloneArrayIfNeeded(fLength+1)) {
03941     fArray[fLength]=0;
03942     return fArray;
03943   } else {
03944     return 0;
03945   }
03946 }
03947 
03948 inline UnicodeString&
03949 UnicodeString::operator= (UChar ch)
03950 { return doReplace(0, fLength, &ch, 0, 1); }
03951 
03952 inline UnicodeString&
03953 UnicodeString::operator= (UChar32 ch)
03954 { return replace(0, fLength, ch); }
03955 
03956 inline UnicodeString&
03957 UnicodeString::setTo(const UnicodeString& srcText,
03958              int32_t srcStart,
03959              int32_t srcLength)
03960 {
03961   unBogus();
03962   return doReplace(0, fLength, srcText, srcStart, srcLength);
03963 }
03964 
03965 inline UnicodeString&
03966 UnicodeString::setTo(const UnicodeString& srcText,
03967              int32_t srcStart)
03968 {
03969   unBogus();
03970   srcText.pinIndex(srcStart);
03971   return doReplace(0, fLength, srcText, srcStart, srcText.fLength - srcStart);
03972 }
03973 
03974 inline UnicodeString&
03975 UnicodeString::setTo(const UnicodeString& srcText)
03976 {
03977   unBogus();
03978   return doReplace(0, fLength, srcText, 0, srcText.fLength);
03979 }
03980 
03981 inline UnicodeString&
03982 UnicodeString::setTo(const UChar *srcChars,
03983              int32_t srcLength)
03984 {
03985   unBogus();
03986   return doReplace(0, fLength, srcChars, 0, srcLength);
03987 }
03988 
03989 inline UnicodeString&
03990 UnicodeString::setTo(UChar srcChar)
03991 {
03992   unBogus();
03993   return doReplace(0, fLength, &srcChar, 0, 1);
03994 }
03995 
03996 inline UnicodeString&
03997 UnicodeString::setTo(UChar32 srcChar)
03998 {
03999   unBogus();
04000   return replace(0, fLength, srcChar);
04001 }
04002 
04003 inline UnicodeString&
04004 UnicodeString::operator+= (UChar ch)
04005 { return doReplace(fLength, 0, &ch, 0, 1); }
04006 
04007 inline UnicodeString&
04008 UnicodeString::operator+= (UChar32 ch) {
04009   UChar buffer[U16_MAX_LENGTH];
04010   int32_t _length = 0;
04011   UBool isError = FALSE;
04012   U16_APPEND(buffer, _length, U16_MAX_LENGTH, ch, isError);
04013   return doReplace(fLength, 0, buffer, 0, _length);
04014 }
04015 
04016 inline UnicodeString&
04017 UnicodeString::operator+= (const UnicodeString& srcText)
04018 { return doReplace(fLength, 0, srcText, 0, srcText.fLength); }
04019 
04020 inline UnicodeString&
04021 UnicodeString::append(const UnicodeString& srcText,
04022               int32_t srcStart,
04023               int32_t srcLength)
04024 { return doReplace(fLength, 0, srcText, srcStart, srcLength); }
04025 
04026 inline UnicodeString&
04027 UnicodeString::append(const UnicodeString& srcText)
04028 { return doReplace(fLength, 0, srcText, 0, srcText.fLength); }
04029 
04030 inline UnicodeString&
04031 UnicodeString::append(const UChar *srcChars,
04032               int32_t srcStart,
04033               int32_t srcLength)
04034 { return doReplace(fLength, 0, srcChars, srcStart, srcLength); }
04035 
04036 inline UnicodeString&
04037 UnicodeString::append(const UChar *srcChars,
04038               int32_t srcLength)
04039 { return doReplace(fLength, 0, srcChars, 0, srcLength); }
04040 
04041 inline UnicodeString&
04042 UnicodeString::append(UChar srcChar)
04043 { return doReplace(fLength, 0, &srcChar, 0, 1); }
04044 
04045 inline UnicodeString&
04046 UnicodeString::append(UChar32 srcChar) {
04047   UChar buffer[U16_MAX_LENGTH];
04048   int32_t _length = 0;
04049   UBool isError = FALSE;
04050   U16_APPEND(buffer, _length, U16_MAX_LENGTH, srcChar, isError);
04051   return doReplace(fLength, 0, buffer, 0, _length);
04052 }
04053 
04054 inline UnicodeString&
04055 UnicodeString::insert(int32_t start,
04056               const UnicodeString& srcText,
04057               int32_t srcStart,
04058               int32_t srcLength)
04059 { return doReplace(start, 0, srcText, srcStart, srcLength); }
04060 
04061 inline UnicodeString&
04062 UnicodeString::insert(int32_t start,
04063               const UnicodeString& srcText)
04064 { return doReplace(start, 0, srcText, 0, srcText.fLength); }
04065 
04066 inline UnicodeString&
04067 UnicodeString::insert(int32_t start,
04068               const UChar *srcChars,
04069               int32_t srcStart,
04070               int32_t srcLength)
04071 { return doReplace(start, 0, srcChars, srcStart, srcLength); }
04072 
04073 inline UnicodeString&
04074 UnicodeString::insert(int32_t start,
04075               const UChar *srcChars,
04076               int32_t srcLength)
04077 { return doReplace(start, 0, srcChars, 0, srcLength); }
04078 
04079 inline UnicodeString&
04080 UnicodeString::insert(int32_t start,
04081               UChar srcChar)
04082 { return doReplace(start, 0, &srcChar, 0, 1); }
04083 
04084 inline UnicodeString&
04085 UnicodeString::insert(int32_t start,
04086               UChar32 srcChar)
04087 { return replace(start, 0, srcChar); }
04088 
04089 
04090 inline UnicodeString&
04091 UnicodeString::remove()
04092 {
04093   // remove() of a bogus string makes the string empty and non-bogus
04094   if(isBogus()) {
04095     unBogus();
04096   } else {
04097     fLength = 0;
04098   }
04099   return *this;
04100 }
04101 
04102 inline UnicodeString&
04103 UnicodeString::remove(int32_t start,
04104              int32_t _length)
04105 {
04106   if(start <= 0 && _length == INT32_MAX) {
04107     // remove(guaranteed everything) of a bogus string makes the string empty and non-bogus
04108     return remove();
04109   } else {
04110     return doReplace(start, _length, NULL, 0, 0);
04111   }
04112 }
04113 
04114 inline UnicodeString&
04115 UnicodeString::removeBetween(int32_t start,
04116                 int32_t limit)
04117 { return doReplace(start, limit - start, NULL, 0, 0); }
04118 
04119 inline UBool
04120 UnicodeString::truncate(int32_t targetLength)
04121 {
04122   if(isBogus() && targetLength == 0) {
04123     // truncate(0) of a bogus string makes the string empty and non-bogus
04124     unBogus();
04125     return FALSE;
04126   } else if((uint32_t)targetLength < (uint32_t)fLength) {
04127     fLength = targetLength;
04128     return TRUE;
04129   } else {
04130     return FALSE;
04131   }
04132 }
04133 
04134 inline UnicodeString&
04135 UnicodeString::reverse()
04136 { return doReverse(0, fLength); }
04137 
04138 inline UnicodeString&
04139 UnicodeString::reverse(int32_t start,
04140                int32_t _length)
04141 { return doReverse(start, _length); }
04142 
04143 U_NAMESPACE_END
04144 
04145 #endif

Generated on Tue Nov 16 10:03:07 2004 for ICU 3.2 by  doxygen 1.3.9.1