unistr.h

Go to the documentation of this file.
00001 /*
00002 **********************************************************************
00003 *   Copyright (C) 1998-2005, 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 
00029 #include "unicode/rep.h"
00030 
00031 struct UConverter;          // unicode/ucnv.h
00032 class  StringThreadTest;
00033 
00034 #ifndef U_COMPARE_CODE_POINT_ORDER
00035 /* see also ustring.h and unorm.h */
00041 #define U_COMPARE_CODE_POINT_ORDER  0x8000
00042 #endif
00043 
00044 #ifndef USTRING_H
00045 /* see ustring.h */
00046 U_STABLE int32_t U_EXPORT2
00047 u_strlen(const UChar *s);
00048 #endif
00049 
00050 U_NAMESPACE_BEGIN
00051 
00052 class Locale;               // unicode/locid.h
00053 class StringCharacterIterator;
00054 class BreakIterator;        // unicode/brkiter.h
00055 
00056 /* The <iostream> include has been moved to unicode/ustream.h */
00057 
00068 #define US_INV UnicodeString::kInvariant
00069 
00087 #if U_SIZEOF_WCHAR_T==U_SIZEOF_UCHAR && (U_CHARSET_FAMILY==U_ASCII_FAMILY || (U_SIZEOF_UCHAR == 2 && defined(U_WCHAR_IS_UTF16)))
00088 #   define UNICODE_STRING(cs, _length) UnicodeString(TRUE, (const UChar *)L ## cs, _length)
00089 #elif U_SIZEOF_UCHAR==1 && U_CHARSET_FAMILY==U_ASCII_FAMILY
00090 #   define UNICODE_STRING(cs, _length) UnicodeString(TRUE, (const UChar *)cs, _length)
00091 #else
00092 #   define UNICODE_STRING(cs, _length) UnicodeString(cs, _length, US_INV)
00093 #endif
00094 
00108 #if U_SIZEOF_WCHAR_T==U_SIZEOF_UCHAR && (U_CHARSET_FAMILY==U_ASCII_FAMILY || (U_SIZEOF_UCHAR == 2 && defined(U_WCHAR_IS_UTF16)))
00109 #   define UNICODE_STRING_SIMPLE(cs) UnicodeString(TRUE, (const UChar *)L ## cs, -1)
00110 #elif U_SIZEOF_UCHAR==1 && U_CHARSET_FAMILY==U_ASCII_FAMILY
00111 #   define UNICODE_STRING_SIMPLE(cs) UnicodeString(TRUE, (const UChar *)cs, -1)
00112 #else
00113 #   define UNICODE_STRING_SIMPLE(cs) UnicodeString(cs, -1, US_INV)
00114 #endif
00115 
00185 class U_COMMON_API UnicodeString : public Replaceable
00186 {
00187 public:
00188 
00197   enum EInvariant {
00202     kInvariant
00203   };
00204 
00205   //========================================
00206   // Read-only operations
00207   //========================================
00208 
00209   /* Comparison - bitwise only - for international comparison use collation */
00210 
00218   inline UBool operator== (const UnicodeString& text) const;
00219 
00227   inline UBool operator!= (const UnicodeString& text) const;
00228 
00236   inline UBool operator> (const UnicodeString& text) const;
00237 
00245   inline UBool operator< (const UnicodeString& text) const;
00246 
00254   inline UBool operator>= (const UnicodeString& text) const;
00255 
00263   inline UBool operator<= (const UnicodeString& text) const;
00264 
00276   inline int8_t compare(const UnicodeString& text) const;
00277 
00292   inline int8_t compare(int32_t start,
00293          int32_t length,
00294          const UnicodeString& text) const;
00295 
00313    inline int8_t compare(int32_t start,
00314          int32_t length,
00315          const UnicodeString& srcText,
00316          int32_t srcStart,
00317          int32_t srcLength) const;
00318 
00331   inline int8_t compare(const UChar *srcChars,
00332          int32_t srcLength) const;
00333 
00348   inline int8_t compare(int32_t start,
00349          int32_t length,
00350          const UChar *srcChars) const;
00351 
00369   inline int8_t compare(int32_t start,
00370          int32_t length,
00371          const UChar *srcChars,
00372          int32_t srcStart,
00373          int32_t srcLength) const;
00374 
00392   inline int8_t compareBetween(int32_t start,
00393             int32_t limit,
00394             const UnicodeString& srcText,
00395             int32_t srcStart,
00396             int32_t srcLimit) const;
00397 
00415   inline int8_t compareCodePointOrder(const UnicodeString& text) const;
00416 
00436   inline int8_t compareCodePointOrder(int32_t start,
00437                                       int32_t length,
00438                                       const UnicodeString& srcText) const;
00439 
00461    inline int8_t compareCodePointOrder(int32_t start,
00462                                        int32_t length,
00463                                        const UnicodeString& srcText,
00464                                        int32_t srcStart,
00465                                        int32_t srcLength) const;
00466 
00485   inline int8_t compareCodePointOrder(const UChar *srcChars,
00486                                       int32_t srcLength) const;
00487 
00507   inline int8_t compareCodePointOrder(int32_t start,
00508                                       int32_t length,
00509                                       const UChar *srcChars) const;
00510 
00532   inline int8_t compareCodePointOrder(int32_t start,
00533                                       int32_t length,
00534                                       const UChar *srcChars,
00535                                       int32_t srcStart,
00536                                       int32_t srcLength) const;
00537 
00559   inline int8_t compareCodePointOrderBetween(int32_t start,
00560                                              int32_t limit,
00561                                              const UnicodeString& srcText,
00562                                              int32_t srcStart,
00563                                              int32_t srcLimit) const;
00564 
00583   inline int8_t caseCompare(const UnicodeString& text, uint32_t options) const;
00584 
00605   inline int8_t caseCompare(int32_t start,
00606          int32_t length,
00607          const UnicodeString& srcText,
00608          uint32_t options) const;
00609 
00632   inline int8_t caseCompare(int32_t start,
00633          int32_t length,
00634          const UnicodeString& srcText,
00635          int32_t srcStart,
00636          int32_t srcLength,
00637          uint32_t options) const;
00638 
00658   inline int8_t caseCompare(const UChar *srcChars,
00659          int32_t srcLength,
00660          uint32_t options) const;
00661 
00682   inline int8_t caseCompare(int32_t start,
00683          int32_t length,
00684          const UChar *srcChars,
00685          uint32_t options) const;
00686 
00709   inline int8_t caseCompare(int32_t start,
00710          int32_t length,
00711          const UChar *srcChars,
00712          int32_t srcStart,
00713          int32_t srcLength,
00714          uint32_t options) const;
00715 
00738   inline int8_t caseCompareBetween(int32_t start,
00739             int32_t limit,
00740             const UnicodeString& srcText,
00741             int32_t srcStart,
00742             int32_t srcLimit,
00743             uint32_t options) const;
00744 
00752   inline UBool startsWith(const UnicodeString& text) const;
00753 
00764   inline UBool startsWith(const UnicodeString& srcText,
00765             int32_t srcStart,
00766             int32_t srcLength) const;
00767 
00776   inline UBool startsWith(const UChar *srcChars,
00777             int32_t srcLength) const;
00778 
00788   inline UBool startsWith(const UChar *srcChars,
00789             int32_t srcStart,
00790             int32_t srcLength) const;
00791 
00799   inline UBool endsWith(const UnicodeString& text) const;
00800 
00811   inline UBool endsWith(const UnicodeString& srcText,
00812           int32_t srcStart,
00813           int32_t srcLength) const;
00814 
00823   inline UBool endsWith(const UChar *srcChars,
00824           int32_t srcLength) const;
00825 
00836   inline UBool endsWith(const UChar *srcChars,
00837           int32_t srcStart,
00838           int32_t srcLength) const;
00839 
00840 
00841   /* Searching - bitwise only */
00842 
00851   inline int32_t indexOf(const UnicodeString& text) const;
00852 
00862   inline int32_t indexOf(const UnicodeString& text,
00863               int32_t start) const;
00864 
00876   inline int32_t indexOf(const UnicodeString& text,
00877               int32_t start,
00878               int32_t length) const;
00879 
00896   inline int32_t indexOf(const UnicodeString& srcText,
00897               int32_t srcStart,
00898               int32_t srcLength,
00899               int32_t start,
00900               int32_t length) const;
00901 
00913   inline int32_t indexOf(const UChar *srcChars,
00914               int32_t srcLength,
00915               int32_t start) const;
00916 
00929   inline int32_t indexOf(const UChar *srcChars,
00930               int32_t srcLength,
00931               int32_t start,
00932               int32_t length) const;
00933 
00950   int32_t indexOf(const UChar *srcChars,
00951               int32_t srcStart,
00952               int32_t srcLength,
00953               int32_t start,
00954               int32_t length) const;
00955 
00963   inline int32_t indexOf(UChar c) const;
00964 
00973   inline int32_t indexOf(UChar32 c) const;
00974 
00983   inline int32_t indexOf(UChar c,
00984               int32_t start) const;
00985 
00995   inline int32_t indexOf(UChar32 c,
00996               int32_t start) const;
00997 
01008   inline int32_t indexOf(UChar c,
01009               int32_t start,
01010               int32_t length) const;
01011 
01023   inline int32_t indexOf(UChar32 c,
01024               int32_t start,
01025               int32_t length) const;
01026 
01035   inline int32_t lastIndexOf(const UnicodeString& text) const;
01036 
01046   inline int32_t lastIndexOf(const UnicodeString& text,
01047               int32_t start) const;
01048 
01060   inline int32_t lastIndexOf(const UnicodeString& text,
01061               int32_t start,
01062               int32_t length) const;
01063 
01080   inline int32_t lastIndexOf(const UnicodeString& srcText,
01081               int32_t srcStart,
01082               int32_t srcLength,
01083               int32_t start,
01084               int32_t length) const;
01085 
01096   inline int32_t lastIndexOf(const UChar *srcChars,
01097               int32_t srcLength,
01098               int32_t start) const;
01099 
01112   inline int32_t lastIndexOf(const UChar *srcChars,
01113               int32_t srcLength,
01114               int32_t start,
01115               int32_t length) const;
01116 
01133   int32_t lastIndexOf(const UChar *srcChars,
01134               int32_t srcStart,
01135               int32_t srcLength,
01136               int32_t start,
01137               int32_t length) const;
01138 
01146   inline int32_t lastIndexOf(UChar c) const;
01147 
01156   inline int32_t lastIndexOf(UChar32 c) const;
01157 
01166   inline int32_t lastIndexOf(UChar c,
01167               int32_t start) const;
01168 
01178   inline int32_t lastIndexOf(UChar32 c,
01179               int32_t start) const;
01180 
01191   inline int32_t lastIndexOf(UChar c,
01192               int32_t start,
01193               int32_t length) const;
01194 
01206   inline int32_t lastIndexOf(UChar32 c,
01207               int32_t start,
01208               int32_t length) const;
01209 
01210 
01211   /* Character access */
01212 
01221   inline UChar charAt(int32_t offset) const;
01222 
01230   inline UChar operator[] (int32_t offset) const;
01231 
01243   inline UChar32 char32At(int32_t offset) const;
01244 
01260   inline int32_t getChar32Start(int32_t offset) const;
01261 
01278   inline int32_t getChar32Limit(int32_t offset) const;
01279 
01330   int32_t moveIndex32(int32_t index, int32_t delta) const;
01331 
01332   /* Substring extraction */
01333 
01349   inline void extract(int32_t start,
01350            int32_t length,
01351            UChar *dst,
01352            int32_t dstStart = 0) const;
01353 
01375   int32_t
01376   extract(UChar *dest, int32_t destCapacity,
01377           UErrorCode &errorCode) const;
01378 
01389   inline void extract(int32_t start,
01390            int32_t length,
01391            UnicodeString& target) const;
01392 
01404   inline void extractBetween(int32_t start,
01405               int32_t limit,
01406               UChar *dst,
01407               int32_t dstStart = 0) const;
01408 
01418   virtual void extractBetween(int32_t start,
01419               int32_t limit,
01420               UnicodeString& target) const;
01421 
01443   int32_t extract(int32_t start,
01444            int32_t startLength,
01445            char *target,
01446            int32_t targetCapacity,
01447            enum EInvariant inv) const;
01448 
01449 #if !UCONFIG_NO_CONVERSION
01450 
01476   inline int32_t extract(int32_t start,
01477                  int32_t startLength,
01478                  char *target,
01479                  const char *codepage = 0) const;
01480 
01510   int32_t extract(int32_t start,
01511            int32_t startLength,
01512            char *target,
01513            uint32_t targetLength,
01514            const char *codepage = 0) const;
01515 
01533   int32_t extract(char *dest, int32_t destCapacity,
01534                   UConverter *cnv,
01535                   UErrorCode &errorCode) const;
01536 
01537 #endif
01538 
01539   /* Length operations */
01540 
01549   inline int32_t length(void) const;
01550 
01564   int32_t
01565   countChar32(int32_t start=0, int32_t length=INT32_MAX) const;
01566 
01590   UBool
01591   hasMoreChar32Than(int32_t start, int32_t length, int32_t number) const;
01592 
01598   inline UBool isEmpty(void) const;
01599 
01609   inline int32_t getCapacity(void) const;
01610 
01611   /* Other operations */
01612 
01618   inline int32_t hashCode(void) const;
01619 
01631   inline UBool isBogus(void) const;
01632 
01633 
01634   //========================================
01635   // Write operations
01636   //========================================
01637 
01638   /* Assignment operations */
01639 
01647   UnicodeString &operator=(const UnicodeString &srcText);
01648 
01669   UnicodeString &fastCopyFrom(const UnicodeString &src);
01670 
01678   inline UnicodeString& operator= (UChar ch);
01679 
01687   inline UnicodeString& operator= (UChar32 ch);
01688 
01700   inline UnicodeString& setTo(const UnicodeString& srcText,
01701                int32_t srcStart);
01702 
01716   inline UnicodeString& setTo(const UnicodeString& srcText,
01717                int32_t srcStart,
01718                int32_t srcLength);
01719 
01728   inline UnicodeString& setTo(const UnicodeString& srcText);
01729 
01738   inline UnicodeString& setTo(const UChar *srcChars,
01739                int32_t srcLength);
01740 
01749   UnicodeString& setTo(UChar srcChar);
01750 
01759   UnicodeString& setTo(UChar32 srcChar);
01760 
01781   UnicodeString &setTo(UBool isTerminated,
01782                        const UChar *text,
01783                        int32_t textLength);
01784 
01804   UnicodeString &setTo(UChar *buffer,
01805                        int32_t buffLength,
01806                        int32_t buffCapacity);
01807 
01848   void setToBogus();
01849 
01857   UnicodeString& setCharAt(int32_t offset,
01858                UChar ch);
01859 
01860 
01861   /* Append operations */
01862 
01870  inline  UnicodeString& operator+= (UChar ch);
01871 
01879  inline  UnicodeString& operator+= (UChar32 ch);
01880 
01889   inline UnicodeString& operator+= (const UnicodeString& srcText);
01890 
01905   inline UnicodeString& append(const UnicodeString& srcText,
01906             int32_t srcStart,
01907             int32_t srcLength);
01908 
01916   inline UnicodeString& append(const UnicodeString& srcText);
01917 
01931   inline UnicodeString& append(const UChar *srcChars,
01932             int32_t srcStart,
01933             int32_t srcLength);
01934 
01943   inline UnicodeString& append(const UChar *srcChars,
01944             int32_t srcLength);
01945 
01952   inline UnicodeString& append(UChar srcChar);
01953 
01960   inline UnicodeString& append(UChar32 srcChar);
01961 
01962 
01963   /* Insert operations */
01964 
01978   inline UnicodeString& insert(int32_t start,
01979             const UnicodeString& srcText,
01980             int32_t srcStart,
01981             int32_t srcLength);
01982 
01991   inline UnicodeString& insert(int32_t start,
01992             const UnicodeString& srcText);
01993 
02007   inline UnicodeString& insert(int32_t start,
02008             const UChar *srcChars,
02009             int32_t srcStart,
02010             int32_t srcLength);
02011 
02021   inline UnicodeString& insert(int32_t start,
02022             const UChar *srcChars,
02023             int32_t srcLength);
02024 
02033   inline UnicodeString& insert(int32_t start,
02034             UChar srcChar);
02035 
02044   inline UnicodeString& insert(int32_t start,
02045             UChar32 srcChar);
02046 
02047 
02048   /* Replace operations */
02049 
02067   UnicodeString& replace(int32_t start,
02068              int32_t length,
02069              const UnicodeString& srcText,
02070              int32_t srcStart,
02071              int32_t srcLength);
02072 
02085   UnicodeString& replace(int32_t start,
02086              int32_t length,
02087              const UnicodeString& srcText);
02088 
02106   UnicodeString& replace(int32_t start,
02107              int32_t length,
02108              const UChar *srcChars,
02109              int32_t srcStart,
02110              int32_t srcLength);
02111 
02124   inline UnicodeString& replace(int32_t start,
02125              int32_t length,
02126              const UChar *srcChars,
02127              int32_t srcLength);
02128 
02140   inline UnicodeString& replace(int32_t start,
02141              int32_t length,
02142              UChar srcChar);
02143 
02155   inline UnicodeString& replace(int32_t start,
02156              int32_t length,
02157              UChar32 srcChar);
02158 
02168   inline UnicodeString& replaceBetween(int32_t start,
02169                 int32_t limit,
02170                 const UnicodeString& srcText);
02171 
02186   inline UnicodeString& replaceBetween(int32_t start,
02187                 int32_t limit,
02188                 const UnicodeString& srcText,
02189                 int32_t srcStart,
02190                 int32_t srcLimit);
02191 
02202   virtual void handleReplaceBetween(int32_t start,
02203                                     int32_t limit,
02204                                     const UnicodeString& text);
02205 
02211   virtual UBool hasMetaData() const;
02212 
02228   virtual void copy(int32_t start, int32_t limit, int32_t dest);
02229 
02230   /* Search and replace operations */
02231 
02240   inline UnicodeString& findAndReplace(const UnicodeString& oldText,
02241                 const UnicodeString& newText);
02242 
02254   inline UnicodeString& findAndReplace(int32_t start,
02255                 int32_t length,
02256                 const UnicodeString& oldText,
02257                 const UnicodeString& newText);
02258 
02276   UnicodeString& findAndReplace(int32_t start,
02277                 int32_t length,
02278                 const UnicodeString& oldText,
02279                 int32_t oldStart,
02280                 int32_t oldLength,
02281                 const UnicodeString& newText,
02282                 int32_t newStart,
02283                 int32_t newLength);
02284 
02285 
02286   /* Remove operations */
02287 
02293   inline UnicodeString& remove(void);
02294 
02303   inline UnicodeString& remove(int32_t start,
02304                                int32_t length = (int32_t)INT32_MAX);
02305 
02314   inline UnicodeString& removeBetween(int32_t start,
02315                                       int32_t limit = (int32_t)INT32_MAX);
02316 
02317 
02318   /* Length operations */
02319 
02331   UBool padLeading(int32_t targetLength,
02332                     UChar padChar = 0x0020);
02333 
02345   UBool padTrailing(int32_t targetLength,
02346                      UChar padChar = 0x0020);
02347 
02354   inline UBool truncate(int32_t targetLength);
02355 
02361   UnicodeString& trim(void);
02362 
02363 
02364   /* Miscellaneous operations */
02365 
02371   inline UnicodeString& reverse(void);
02372 
02381   inline UnicodeString& reverse(int32_t start,
02382              int32_t length);
02383 
02390   UnicodeString& toUpper(void);
02391 
02399   UnicodeString& toUpper(const Locale& locale);
02400 
02407   UnicodeString& toLower(void);
02408 
02416   UnicodeString& toLower(const Locale& locale);
02417 
02418 #if !UCONFIG_NO_BREAK_ITERATION
02419 
02446   UnicodeString &toTitle(BreakIterator *titleIter);
02447 
02475   UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale);
02476 
02477 #endif
02478 
02490   UnicodeString &foldCase(uint32_t options=0 /*U_FOLD_CASE_DEFAULT*/);
02491 
02492   //========================================
02493   // Access to the internal buffer
02494   //========================================
02495 
02539   UChar *getBuffer(int32_t minCapacity);
02540 
02561   void releaseBuffer(int32_t newLength=-1);
02562 
02593   inline const UChar *getBuffer() const;
02594 
02628   inline const UChar *getTerminatedBuffer();
02629 
02630   //========================================
02631   // Constructors
02632   //========================================
02633 
02637   UnicodeString();
02638 
02650   UnicodeString(int32_t capacity, UChar32 c, int32_t count);
02651 
02657   UnicodeString(UChar ch);
02658 
02664   UnicodeString(UChar32 ch);
02665 
02672   UnicodeString(const UChar *text);
02673 
02681   UnicodeString(const UChar *text,
02682         int32_t textLength);
02683 
02703   UnicodeString(UBool isTerminated,
02704                 const UChar *text,
02705                 int32_t textLength);
02706 
02725   UnicodeString(UChar *buffer, int32_t buffLength, int32_t buffCapacity);
02726 
02727 #if !UCONFIG_NO_CONVERSION
02728 
02746   UnicodeString(const char *codepageData,
02747         const char *codepage = 0);
02748 
02766   UnicodeString(const char *codepageData,
02767         int32_t dataLength,
02768         const char *codepage = 0);
02769 
02791   UnicodeString(
02792         const char *src, int32_t srcLength,
02793         UConverter *cnv,
02794         UErrorCode &errorCode);
02795 
02796 #endif
02797 
02822   UnicodeString(const char *src, int32_t length, enum EInvariant inv);
02823 
02824 
02830   UnicodeString(const UnicodeString& that);
02831 
02838   UnicodeString(const UnicodeString& src, int32_t srcStart);
02839 
02847   UnicodeString(const UnicodeString& src, int32_t srcStart, int32_t srcLength);
02848 
02865   virtual Replaceable *clone() const;
02866 
02870   virtual ~UnicodeString();
02871 
02872 
02873   /* Miscellaneous operations */
02874 
02909   UnicodeString unescape() const;
02910 
02930   UChar32 unescapeAt(int32_t &offset) const;
02931 
02937   static UClassID U_EXPORT2 getStaticClassID();
02938 
02944   virtual UClassID getDynamicClassID() const;
02945 
02946   //========================================
02947   // Implementation methods
02948   //========================================
02949 
02950 protected:
02955   virtual int32_t getLength() const;
02956 
02962   virtual UChar getCharAt(int32_t offset) const;
02963 
02969   virtual UChar32 getChar32At(int32_t offset) const;
02970 
02971 private:
02972 
02973   inline int8_t
02974   doCompare(int32_t start,
02975            int32_t length,
02976            const UnicodeString& srcText,
02977            int32_t srcStart,
02978            int32_t srcLength) const;
02979 
02980   int8_t doCompare(int32_t start,
02981            int32_t length,
02982            const UChar *srcChars,
02983            int32_t srcStart,
02984            int32_t srcLength) const;
02985 
02986   inline int8_t
02987   doCompareCodePointOrder(int32_t start,
02988                           int32_t length,
02989                           const UnicodeString& srcText,
02990                           int32_t srcStart,
02991                           int32_t srcLength) const;
02992 
02993   int8_t doCompareCodePointOrder(int32_t start,
02994                                  int32_t length,
02995                                  const UChar *srcChars,
02996                                  int32_t srcStart,
02997                                  int32_t srcLength) const;
02998 
02999   inline int8_t
03000   doCaseCompare(int32_t start,
03001                 int32_t length,
03002                 const UnicodeString &srcText,
03003                 int32_t srcStart,
03004                 int32_t srcLength,
03005                 uint32_t options) const;
03006 
03007   int8_t
03008   doCaseCompare(int32_t start,
03009                 int32_t length,
03010                 const UChar *srcChars,
03011                 int32_t srcStart,
03012                 int32_t srcLength,
03013                 uint32_t options) const;
03014 
03015   int32_t doIndexOf(UChar c,
03016             int32_t start,
03017             int32_t length) const;
03018 
03019   int32_t doIndexOf(UChar32 c,
03020                         int32_t start,
03021                         int32_t length) const;
03022 
03023   int32_t doLastIndexOf(UChar c,
03024                 int32_t start,
03025                 int32_t length) const;
03026 
03027   int32_t doLastIndexOf(UChar32 c,
03028                             int32_t start,
03029                             int32_t length) const;
03030 
03031   void doExtract(int32_t start,
03032          int32_t length,
03033          UChar *dst,
03034          int32_t dstStart) const;
03035 
03036   inline void doExtract(int32_t start,
03037          int32_t length,
03038          UnicodeString& target) const;
03039 
03040   inline UChar doCharAt(int32_t offset)  const;
03041 
03042   UnicodeString& doReplace(int32_t start,
03043                int32_t length,
03044                const UnicodeString& srcText,
03045                int32_t srcStart,
03046                int32_t srcLength);
03047 
03048   UnicodeString& doReplace(int32_t start,
03049                int32_t length,
03050                const UChar *srcChars,
03051                int32_t srcStart,
03052                int32_t srcLength);
03053 
03054   UnicodeString& doReverse(int32_t start,
03055                int32_t length);
03056 
03057   // calculate hash code
03058   int32_t doHashCode(void) const;
03059 
03060   // get pointer to start of array
03061   inline UChar* getArrayStart(void);
03062   inline const UChar* getArrayStart(void) const;
03063 
03064   // allocate the array; result may be fStackBuffer
03065   // sets refCount to 1 if appropriate
03066   // sets fArray, fCapacity, and fFlags
03067   // returns boolean for success or failure
03068   UBool allocate(int32_t capacity);
03069 
03070   // release the array if owned
03071   void releaseArray(void);
03072 
03073   // turn a bogus string into an empty one
03074   void unBogus();
03075 
03076   // implements assigment operator, copy constructor, and fastCopyFrom()
03077   UnicodeString &copyFrom(const UnicodeString &src, UBool fastCopy=FALSE);
03078 
03079   // Pin start and limit to acceptable values.
03080   inline void pinIndex(int32_t& start) const;
03081   inline void pinIndices(int32_t& start,
03082                          int32_t& length) const;
03083 
03084 #if !UCONFIG_NO_CONVERSION
03085 
03086   /* Internal extract() using UConverter. */
03087   int32_t doExtract(int32_t start, int32_t length,
03088                     char *dest, int32_t destCapacity,
03089                     UConverter *cnv,
03090                     UErrorCode &errorCode) const;
03091 
03092   /*
03093    * Real constructor for converting from codepage data.
03094    * It assumes that it is called with !fRefCounted.
03095    *
03096    * If <code>codepage==0</code>, then the default converter
03097    * is used for the platform encoding.
03098    * If <code>codepage</code> is an empty string (<code>""</code>),
03099    * then a simple conversion is performed on the codepage-invariant
03100    * subset ("invariant characters") of the platform encoding. See utypes.h.
03101    */
03102   void doCodepageCreate(const char *codepageData,
03103                         int32_t dataLength,
03104                         const char *codepage);
03105 
03106   /*
03107    * Worker function for creating a UnicodeString from
03108    * a codepage string using a UConverter.
03109    */
03110   void
03111   doCodepageCreate(const char *codepageData,
03112                    int32_t dataLength,
03113                    UConverter *converter,
03114                    UErrorCode &status);
03115 
03116 #endif
03117 
03118   /*
03119    * This function is called when write access to the array
03120    * is necessary.
03121    *
03122    * We need to make a copy of the array if
03123    * the buffer is read-only, or
03124    * the buffer is refCounted (shared), and refCount>1, or
03125    * the buffer is too small.
03126    *
03127    * Return FALSE if memory could not be allocated.
03128    */
03129   UBool cloneArrayIfNeeded(int32_t newCapacity = -1,
03130                             int32_t growCapacity = -1,
03131                             UBool doCopyArray = TRUE,
03132                             int32_t **pBufferToDelete = 0,
03133                             UBool forceClone = FALSE);
03134 
03135   // common function for case mappings
03136   UnicodeString &
03137   caseMap(BreakIterator *titleIter,
03138           const char *locale,
03139           uint32_t options,
03140           int32_t toWhichCase);
03141 
03142   // ref counting
03143   void addRef(void);
03144   int32_t removeRef(void);
03145   int32_t refCount(void) const;
03146 
03147   // constants
03148   enum {
03149     US_STACKBUF_SIZE=7, // Size of stack buffer for small strings
03150     kInvalidUChar=0xffff, // invalid UChar index
03151     kGrowSize=128, // grow size for this buffer
03152     kInvalidHashCode=0, // invalid hash code
03153     kEmptyHashCode=1, // hash code for empty string
03154 
03155     // bit flag values for fFlags
03156     kIsBogus=1,         // this string is bogus, i.e., not valid or NULL
03157     kUsingStackBuffer=2,// fArray==fStackBuffer
03158     kRefCounted=4,      // there is a refCount field before the characters in fArray
03159     kBufferIsReadonly=8,// do not write to this buffer
03160     kOpenGetBuffer=16,  // getBuffer(minCapacity) was called (is "open"),
03161                         // and releaseBuffer(newLength) must be called
03162 
03163     // combined values for convenience
03164     kShortString=kUsingStackBuffer,
03165     kLongString=kRefCounted,
03166     kReadonlyAlias=kBufferIsReadonly,
03167     kWritableAlias=0
03168   };
03169 
03170   friend class StringCharacterIterator;
03171   friend class StringThreadTest;
03172 
03173   /*
03174    * The following are all the class fields that are stored
03175    * in each UnicodeString object.
03176    * Note that UnicodeString has virtual functions,
03177    * therefore there is an implicit vtable pointer
03178    * as the first real field.
03179    * The fields should be aligned such that no padding is
03180    * necessary, mostly by having larger types first.
03181    * On 32-bit machines, the size should be 32 bytes,
03182    * on 64-bit machines (8-byte pointers), it should be 40 bytes.
03183    */
03184   // (implicit) *vtable;
03185   int32_t   fLength;        // number of characters in fArray
03186   int32_t   fCapacity;      // sizeof fArray
03187   UChar     *fArray;        // the Unicode data
03188   uint16_t  fFlags;         // bit flags: see constants above
03189   UChar     fStackBuffer [ US_STACKBUF_SIZE ]; // buffer for small strings
03190 
03191 };
03192 
03201 U_COMMON_API UnicodeString U_EXPORT2
03202 operator+ (const UnicodeString &s1, const UnicodeString &s2);
03203 
03204 U_NAMESPACE_END
03205 
03206 // inline implementations -------------------------------------------------- ***
03207 
03208 //========================================
03209 // Array copying
03210 //========================================
03215 inline void
03216 uprv_arrayCopy(const U_NAMESPACE_QUALIFIER UnicodeString *src, U_NAMESPACE_QUALIFIER UnicodeString *dst, int32_t count)
03217 { while(count-- > 0) *dst++ = *src++; }
03218 
03223 inline void
03224 uprv_arrayCopy(const U_NAMESPACE_QUALIFIER UnicodeString *src, int32_t srcStart,
03225         U_NAMESPACE_QUALIFIER UnicodeString *dst, int32_t dstStart, int32_t count)
03226 { uprv_arrayCopy(src+srcStart, dst+dstStart, count); }
03227 
03228 U_NAMESPACE_BEGIN
03229 
03230 //========================================
03231 // Inline members
03232 //========================================
03233 
03234 //========================================
03235 // Privates
03236 //========================================
03237 
03238 inline void
03239 UnicodeString::pinIndex(int32_t& start) const
03240 {
03241   // pin index
03242   if(start < 0) {
03243     start = 0;
03244   } else if(start > fLength) {
03245     start = fLength;
03246   }
03247 }
03248 
03249 inline void
03250 UnicodeString::pinIndices(int32_t& start,
03251                           int32_t& _length) const
03252 {
03253   // pin indices
03254   if(start < 0) {
03255     start = 0;
03256   } else if(start > fLength) {
03257     start = fLength;
03258   }
03259   if(_length < 0) {
03260     _length = 0;
03261   } else if(_length > (fLength - start)) {
03262     _length = (fLength - start);
03263   }
03264 }
03265 
03266 inline UChar*
03267 UnicodeString::getArrayStart()
03268 { return fArray; }
03269 
03270 inline const UChar*
03271 UnicodeString::getArrayStart() const
03272 { return fArray; }
03273 
03274 //========================================
03275 // Read-only implementation methods
03276 //========================================
03277 inline int32_t
03278 UnicodeString::length() const
03279 { return fLength; }
03280 
03281 inline int32_t
03282 UnicodeString::getCapacity() const
03283 { return fCapacity; }
03284 
03285 inline int32_t
03286 UnicodeString::hashCode() const
03287 { return doHashCode(); }
03288 
03289 inline UBool
03290 UnicodeString::isBogus() const
03291 { return (UBool)(fFlags & kIsBogus); }
03292 
03293 inline const UChar *
03294 UnicodeString::getBuffer() const {
03295   if(!(fFlags&(kIsBogus|kOpenGetBuffer))) {
03296     return fArray;
03297   } else {
03298     return 0;
03299   }
03300 }
03301 
03302 //========================================
03303 // Read-only alias methods
03304 //========================================
03305 inline int8_t
03306 UnicodeString::doCompare(int32_t start,
03307               int32_t length,
03308               const UnicodeString& srcText,
03309               int32_t srcStart,
03310               int32_t srcLength) const
03311 {
03312   if(srcText.isBogus()) {
03313     return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
03314   } else {
03315     srcText.pinIndices(srcStart, srcLength);
03316     return doCompare(start, length, srcText.fArray, srcStart, srcLength);
03317   }
03318 }
03319 
03320 inline UBool
03321 UnicodeString::operator== (const UnicodeString& text) const
03322 {
03323   if(isBogus()) {
03324     return text.isBogus();
03325   } else {
03326     return
03327       !text.isBogus() &&
03328       fLength == text.fLength &&
03329       doCompare(0, fLength, text, 0, text.fLength) == 0;
03330   }
03331 }
03332 
03333 inline UBool
03334 UnicodeString::operator!= (const UnicodeString& text) const
03335 { return (! operator==(text)); }
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 UBool
03350 UnicodeString::operator<= (const UnicodeString& text) const
03351 { return doCompare(0, fLength, text, 0, text.fLength) != 1; }
03352 
03353 inline int8_t
03354 UnicodeString::compare(const UnicodeString& text) const
03355 { return doCompare(0, fLength, text, 0, text.fLength); }
03356 
03357 inline int8_t
03358 UnicodeString::compare(int32_t start,
03359                int32_t _length,
03360                const UnicodeString& srcText) const
03361 { return doCompare(start, _length, srcText, 0, srcText.fLength); }
03362 
03363 inline int8_t
03364 UnicodeString::compare(const UChar *srcChars,
03365                int32_t srcLength) const
03366 { return doCompare(0, fLength, srcChars, 0, srcLength); }
03367 
03368 inline int8_t
03369 UnicodeString::compare(int32_t start,
03370                int32_t _length,
03371                const UnicodeString& srcText,
03372                int32_t srcStart,
03373                int32_t srcLength) const
03374 { return doCompare(start, _length, srcText, srcStart, srcLength); }
03375 
03376 inline int8_t
03377 UnicodeString::compare(int32_t start,
03378                int32_t _length,
03379                const UChar *srcChars) const
03380 { return doCompare(start, _length, srcChars, 0, _length); }
03381 
03382 inline int8_t
03383 UnicodeString::compare(int32_t start,
03384                int32_t _length,
03385                const UChar *srcChars,
03386                int32_t srcStart,
03387                int32_t srcLength) const
03388 { return doCompare(start, _length, srcChars, srcStart, srcLength); }
03389 
03390 inline int8_t
03391 UnicodeString::compareBetween(int32_t start,
03392                   int32_t limit,
03393                   const UnicodeString& srcText,
03394                   int32_t srcStart,
03395                   int32_t srcLimit) const
03396 { return doCompare(start, limit - start,
03397            srcText, srcStart, srcLimit - srcStart); }
03398 
03399 inline int8_t
03400 UnicodeString::doCompareCodePointOrder(int32_t start,
03401                                        int32_t length,
03402                                        const UnicodeString& srcText,
03403                                        int32_t srcStart,
03404                                        int32_t srcLength) const
03405 {
03406   if(srcText.isBogus()) {
03407     return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
03408   } else {
03409     srcText.pinIndices(srcStart, srcLength);
03410     return doCompareCodePointOrder(start, length, srcText.fArray, srcStart, srcLength);
03411   }
03412 }
03413 
03414 inline int8_t
03415 UnicodeString::compareCodePointOrder(const UnicodeString& text) const
03416 { return doCompareCodePointOrder(0, fLength, text, 0, text.fLength); }
03417 
03418 inline int8_t
03419 UnicodeString::compareCodePointOrder(int32_t start,
03420                                      int32_t _length,
03421                                      const UnicodeString& srcText) const
03422 { return doCompareCodePointOrder(start, _length, srcText, 0, srcText.fLength); }
03423 
03424 inline int8_t
03425 UnicodeString::compareCodePointOrder(const UChar *srcChars,
03426                                      int32_t srcLength) const
03427 { return doCompareCodePointOrder(0, fLength, srcChars, 0, srcLength); }
03428 
03429 inline int8_t
03430 UnicodeString::compareCodePointOrder(int32_t start,
03431                                      int32_t _length,
03432                                      const UnicodeString& srcText,
03433                                      int32_t srcStart,
03434                                      int32_t srcLength) const
03435 { return doCompareCodePointOrder(start, _length, srcText, srcStart, srcLength); }
03436 
03437 inline int8_t
03438 UnicodeString::compareCodePointOrder(int32_t start,
03439                                      int32_t _length,
03440                                      const UChar *srcChars) const
03441 { return doCompareCodePointOrder(start, _length, srcChars, 0, _length); }
03442 
03443 inline int8_t
03444 UnicodeString::compareCodePointOrder(int32_t start,
03445                                      int32_t _length,
03446                                      const UChar *srcChars,
03447                                      int32_t srcStart,
03448                                      int32_t srcLength) const
03449 { return doCompareCodePointOrder(start, _length, srcChars, srcStart, srcLength); }
03450 
03451 inline int8_t
03452 UnicodeString::compareCodePointOrderBetween(int32_t start,
03453                                             int32_t limit,
03454                                             const UnicodeString& srcText,
03455                                             int32_t srcStart,
03456                                             int32_t srcLimit) const
03457 { return doCompareCodePointOrder(start, limit - start,
03458            srcText, srcStart, srcLimit - srcStart); }
03459 
03460 inline int8_t
03461 UnicodeString::doCaseCompare(int32_t start,
03462                              int32_t length,
03463                              const UnicodeString &srcText,
03464                              int32_t srcStart,
03465                              int32_t srcLength,
03466                              uint32_t options) const
03467 {
03468   if(srcText.isBogus()) {
03469     return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
03470   } else {
03471     srcText.pinIndices(srcStart, srcLength);
03472     return doCaseCompare(start, length, srcText.fArray, srcStart, srcLength, options);
03473   }
03474 }
03475 
03476 inline int8_t
03477 UnicodeString::caseCompare(const UnicodeString &text, uint32_t options) const {
03478   return doCaseCompare(0, fLength, text, 0, text.fLength, options);
03479 }
03480 
03481 inline int8_t
03482 UnicodeString::caseCompare(int32_t start,
03483                            int32_t _length,
03484                            const UnicodeString &srcText,
03485                            uint32_t options) const {
03486   return doCaseCompare(start, _length, srcText, 0, srcText.fLength, options);
03487 }
03488 
03489 inline int8_t
03490 UnicodeString::caseCompare(const UChar *srcChars,
03491                            int32_t srcLength,
03492                            uint32_t options) const {
03493   return doCaseCompare(0, fLength, srcChars, 0, srcLength, options);
03494 }
03495 
03496 inline int8_t
03497 UnicodeString::caseCompare(int32_t start,
03498                            int32_t _length,
03499                            const UnicodeString &srcText,
03500                            int32_t srcStart,
03501                            int32_t srcLength,
03502                            uint32_t options) const {
03503   return doCaseCompare(start, _length, srcText, srcStart, srcLength, options);
03504 }
03505 
03506 inline int8_t
03507 UnicodeString::caseCompare(int32_t start,
03508                            int32_t _length,
03509                            const UChar *srcChars,
03510                            uint32_t options) const {
03511   return doCaseCompare(start, _length, srcChars, 0, _length, options);
03512 }
03513 
03514 inline int8_t
03515 UnicodeString::caseCompare(int32_t start,
03516                            int32_t _length,
03517                            const UChar *srcChars,
03518                            int32_t srcStart,
03519                            int32_t srcLength,
03520                            uint32_t options) const {
03521   return doCaseCompare(start, _length, srcChars, srcStart, srcLength, options);
03522 }
03523 
03524 inline int8_t
03525 UnicodeString::caseCompareBetween(int32_t start,
03526                                   int32_t limit,
03527                                   const UnicodeString &srcText,
03528                                   int32_t srcStart,
03529                                   int32_t srcLimit,
03530                                   uint32_t options) const {
03531   return doCaseCompare(start, limit - start, srcText, srcStart, srcLimit - srcStart, options);
03532 }
03533 
03534 inline int32_t
03535 UnicodeString::indexOf(const UnicodeString& srcText,
03536                int32_t srcStart,
03537                int32_t srcLength,
03538                int32_t start,
03539                int32_t _length) const
03540 {
03541   if(!srcText.isBogus()) {
03542     srcText.pinIndices(srcStart, srcLength);
03543     if(srcLength > 0) {
03544       return indexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
03545     }
03546   }
03547   return -1;
03548 }
03549 
03550 inline int32_t
03551 UnicodeString::indexOf(const UnicodeString& text) const
03552 { return indexOf(text, 0, text.fLength, 0, fLength); }
03553 
03554 inline int32_t
03555 UnicodeString::indexOf(const UnicodeString& text,
03556                int32_t start) const {
03557   pinIndex(start);
03558   return indexOf(text, 0, text.fLength, start, fLength - start);
03559 }
03560 
03561 inline int32_t
03562 UnicodeString::indexOf(const UnicodeString& text,
03563                int32_t start,
03564                int32_t _length) const
03565 { return indexOf(text, 0, text.fLength, start, _length); }
03566 
03567 inline int32_t
03568 UnicodeString::indexOf(const UChar *srcChars,
03569                int32_t srcLength,
03570                int32_t start) const {
03571   pinIndex(start);
03572   return indexOf(srcChars, 0, srcLength, start, fLength - start);
03573 }
03574 
03575 inline int32_t
03576 UnicodeString::indexOf(const UChar *srcChars,
03577                int32_t srcLength,
03578                int32_t start,
03579                int32_t _length) const
03580 { return indexOf(srcChars, 0, srcLength, start, _length); }
03581 
03582 inline int32_t
03583 UnicodeString::indexOf(UChar c,
03584                int32_t start,
03585                int32_t _length) const
03586 { return doIndexOf(c, start, _length); }
03587 
03588 inline int32_t
03589 UnicodeString::indexOf(UChar32 c,
03590                int32_t start,
03591                int32_t _length) const
03592 { return doIndexOf(c, start, _length); }
03593 
03594 inline int32_t
03595 UnicodeString::indexOf(UChar c) const
03596 { return doIndexOf(c, 0, fLength); }
03597 
03598 inline int32_t
03599 UnicodeString::indexOf(UChar32 c) const
03600 { return indexOf(c, 0, fLength); }
03601 
03602 inline int32_t
03603 UnicodeString::indexOf(UChar c,
03604                int32_t start) const {
03605   pinIndex(start);
03606   return doIndexOf(c, start, fLength - start);
03607 }
03608 
03609 inline int32_t
03610 UnicodeString::indexOf(UChar32 c,
03611                int32_t start) const {
03612   pinIndex(start);
03613   return indexOf(c, start, fLength - start);
03614 }
03615 
03616 inline int32_t
03617 UnicodeString::lastIndexOf(const UChar *srcChars,
03618                int32_t srcLength,
03619                int32_t start,
03620                int32_t _length) const
03621 { return lastIndexOf(srcChars, 0, srcLength, start, _length); }
03622 
03623 inline int32_t
03624 UnicodeString::lastIndexOf(const UChar *srcChars,
03625                int32_t srcLength,
03626                int32_t start) const {
03627   pinIndex(start);
03628   return lastIndexOf(srcChars, 0, srcLength, start, fLength - start);
03629 }
03630 
03631 inline int32_t
03632 UnicodeString::lastIndexOf(const UnicodeString& srcText,
03633                int32_t srcStart,
03634                int32_t srcLength,
03635                int32_t start,
03636                int32_t _length) const
03637 {
03638   if(!srcText.isBogus()) {
03639     srcText.pinIndices(srcStart, srcLength);
03640     if(srcLength > 0) {
03641       return lastIndexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
03642     }
03643   }
03644   return -1;
03645 }
03646 
03647 inline int32_t
03648 UnicodeString::lastIndexOf(const UnicodeString& text,
03649                int32_t start,
03650                int32_t _length) const
03651 { return lastIndexOf(text, 0, text.fLength, start, _length); }
03652 
03653 inline int32_t
03654 UnicodeString::lastIndexOf(const UnicodeString& text,
03655                int32_t start) const {
03656   pinIndex(start);
03657   return lastIndexOf(text, 0, text.fLength, start, fLength - start);
03658 }
03659 
03660 inline int32_t
03661 UnicodeString::lastIndexOf(const UnicodeString& text) const
03662 { return lastIndexOf(text, 0, text.fLength, 0, fLength); }
03663 
03664 inline int32_t
03665 UnicodeString::lastIndexOf(UChar c,
03666                int32_t start,
03667                int32_t _length) const
03668 { return doLastIndexOf(c, start, _length); }
03669 
03670 inline int32_t
03671 UnicodeString::lastIndexOf(UChar32 c,
03672                int32_t start,
03673                int32_t _length) const {
03674   return doLastIndexOf(c, start, _length);
03675 }
03676 
03677 inline int32_t
03678 UnicodeString::lastIndexOf(UChar c) const
03679 { return doLastIndexOf(c, 0, fLength); }
03680 
03681 inline int32_t
03682 UnicodeString::lastIndexOf(UChar32 c) const {
03683   return lastIndexOf(c, 0, fLength);
03684 }
03685 
03686 inline int32_t
03687 UnicodeString::lastIndexOf(UChar c,
03688                int32_t start) const {
03689   pinIndex(start);
03690   return doLastIndexOf(c, start, fLength - start);
03691 }
03692 
03693 inline int32_t
03694 UnicodeString::lastIndexOf(UChar32 c,
03695                int32_t start) const {
03696   pinIndex(start);
03697   return lastIndexOf(c, start, fLength - start);
03698 }
03699 
03700 inline UBool
03701 UnicodeString::startsWith(const UnicodeString& text) const
03702 { return compare(0, text.fLength, text, 0, text.fLength) == 0; }
03703 
03704 inline UBool
03705 UnicodeString::startsWith(const UnicodeString& srcText,
03706               int32_t srcStart,
03707               int32_t srcLength) const
03708 { return doCompare(0, srcLength, srcText, srcStart, srcLength) == 0; }
03709 
03710 inline UBool
03711 UnicodeString::startsWith(const UChar *srcChars,
03712               int32_t srcLength) const
03713 { return doCompare(0, srcLength, srcChars, 0, srcLength) == 0; }
03714 
03715 inline UBool
03716 UnicodeString::startsWith(const UChar *srcChars,
03717               int32_t srcStart,
03718               int32_t srcLength) const
03719 { return doCompare(0, srcLength, srcChars, srcStart, srcLength) == 0;}
03720 
03721 inline UBool
03722 UnicodeString::endsWith(const UnicodeString& text) const
03723 { return doCompare(fLength - text.fLength, text.fLength,
03724            text, 0, text.fLength) == 0; }
03725 
03726 inline UBool
03727 UnicodeString::endsWith(const UnicodeString& srcText,
03728             int32_t srcStart,
03729             int32_t srcLength) const {
03730   srcText.pinIndices(srcStart, srcLength);
03731   return doCompare(fLength - srcLength, srcLength,
03732                    srcText, srcStart, srcLength) == 0;
03733 }
03734 
03735 inline UBool
03736 UnicodeString::endsWith(const UChar *srcChars,
03737             int32_t srcLength) const {
03738   if(srcLength < 0) {
03739     srcLength = u_strlen(srcChars);
03740   }
03741   return doCompare(fLength - srcLength, srcLength,
03742                    srcChars, 0, srcLength) == 0;
03743 }
03744 
03745 inline UBool
03746 UnicodeString::endsWith(const UChar *srcChars,
03747             int32_t srcStart,
03748             int32_t srcLength) const {
03749   if(srcLength < 0) {
03750     srcLength = u_strlen(srcChars + srcStart);
03751   }
03752   return doCompare(fLength - srcLength, srcLength,
03753                    srcChars, srcStart, srcLength) == 0;
03754 }
03755 
03756 //========================================
03757 // replace
03758 //========================================
03759 inline UnicodeString&
03760 UnicodeString::replace(int32_t start,
03761                int32_t _length,
03762                const UnicodeString& srcText)
03763 { return doReplace(start, _length, srcText, 0, srcText.fLength); }
03764 
03765 inline UnicodeString&
03766 UnicodeString::replace(int32_t start,
03767                int32_t _length,
03768                const UnicodeString& srcText,
03769                int32_t srcStart,
03770                int32_t srcLength)
03771 { return doReplace(start, _length, srcText, srcStart, srcLength); }
03772 
03773 inline UnicodeString&
03774 UnicodeString::replace(int32_t start,
03775                int32_t _length,
03776                const UChar *srcChars,
03777                int32_t srcLength)
03778 { return doReplace(start, _length, srcChars, 0, srcLength); }
03779 
03780 inline UnicodeString&
03781 UnicodeString::replace(int32_t start,
03782                int32_t _length,
03783                const UChar *srcChars,
03784                int32_t srcStart,
03785                int32_t srcLength)
03786 { return doReplace(start, _length, srcChars, srcStart, srcLength); }
03787 
03788 inline UnicodeString&
03789 UnicodeString::replace(int32_t start,
03790                int32_t _length,
03791                UChar srcChar)
03792 { return doReplace(start, _length, &srcChar, 0, 1); }
03793 
03794 inline UnicodeString&
03795 UnicodeString::replace(int32_t start,
03796                int32_t _length,
03797                UChar32 srcChar) {
03798   UChar buffer[U16_MAX_LENGTH];
03799   int32_t count = 0;
03800   UBool isError = FALSE;
03801   U16_APPEND(buffer, count, U16_MAX_LENGTH, srcChar, isError);
03802   return doReplace(start, _length, buffer, 0, count);
03803 }
03804 
03805 inline UnicodeString&
03806 UnicodeString::replaceBetween(int32_t start,
03807                   int32_t limit,
03808                   const UnicodeString& srcText)
03809 { return doReplace(start, limit - start, srcText, 0, srcText.fLength); }
03810 
03811 inline UnicodeString&
03812 UnicodeString::replaceBetween(int32_t start,
03813                   int32_t limit,
03814                   const UnicodeString& srcText,
03815                   int32_t srcStart,
03816                   int32_t srcLimit)
03817 { return doReplace(start, limit - start, srcText, srcStart, srcLimit - srcStart); }
03818 
03819 inline UnicodeString&
03820 UnicodeString::findAndReplace(const UnicodeString& oldText,
03821                   const UnicodeString& newText)
03822 { return findAndReplace(0, fLength, oldText, 0, oldText.fLength,
03823             newText, 0, newText.fLength); }
03824 
03825 inline UnicodeString&
03826 UnicodeString::findAndReplace(int32_t start,
03827                   int32_t _length,
03828                   const UnicodeString& oldText,
03829                   const UnicodeString& newText)
03830 { return findAndReplace(start, _length, oldText, 0, oldText.fLength,
03831             newText, 0, newText.fLength); }
03832 
03833 // ============================
03834 // extract
03835 // ============================
03836 inline void
03837 UnicodeString::doExtract(int32_t start,
03838              int32_t _length,
03839              UnicodeString& target) const
03840 { target.replace(0, target.fLength, *this, start, _length); }
03841 
03842 inline void
03843 UnicodeString::extract(int32_t start,
03844                int32_t _length,
03845                UChar *target,
03846                int32_t targetStart) const
03847 { doExtract(start, _length, target, targetStart); }
03848 
03849 inline void
03850 UnicodeString::extract(int32_t start,
03851                int32_t _length,
03852                UnicodeString& target) const
03853 { doExtract(start, _length, target); }
03854 
03855 #if !UCONFIG_NO_CONVERSION
03856 
03857 inline int32_t
03858 UnicodeString::extract(int32_t start,
03859                int32_t _length,
03860                char *dst,
03861                const char *codepage) const
03862 
03863 {
03864   // This dstSize value will be checked explicitly
03865   return extract(start, _length, dst, dst!=0 ? 0xffffffff : 0, codepage);
03866 }
03867 
03868 #endif
03869 
03870 inline void
03871 UnicodeString::extractBetween(int32_t start,
03872                   int32_t limit,
03873                   UChar *dst,
03874                   int32_t dstStart) const {
03875   pinIndex(start);
03876   pinIndex(limit);
03877   doExtract(start, limit - start, dst, dstStart);
03878 }
03879 
03880 inline UChar
03881 UnicodeString::doCharAt(int32_t offset) const
03882 {
03883   if((uint32_t)offset < (uint32_t)fLength) {
03884     return fArray[offset];
03885   } else {
03886     return kInvalidUChar;
03887   }
03888 }
03889 
03890 inline UChar
03891 UnicodeString::charAt(int32_t offset) const
03892 { return doCharAt(offset); }
03893 
03894 inline UChar
03895 UnicodeString::operator[] (int32_t offset) const
03896 { return doCharAt(offset); }
03897 
03898 inline UChar32
03899 UnicodeString::char32At(int32_t offset) const
03900 {
03901   if((uint32_t)offset < (uint32_t)fLength) {
03902     UChar32 c;
03903     U16_GET(fArray, 0, offset, fLength, c);
03904     return c;
03905   } else {
03906     return kInvalidUChar;
03907   }
03908 }
03909 
03910 inline int32_t
03911 UnicodeString::getChar32Start(int32_t offset) const {
03912   if((uint32_t)offset < (uint32_t)fLength) {
03913     U16_SET_CP_START(fArray, 0, offset);
03914     return offset;
03915   } else {
03916     return 0;
03917   }
03918 }
03919 
03920 inline int32_t
03921 UnicodeString::getChar32Limit(int32_t offset) const {
03922   if((uint32_t)offset < (uint32_t)fLength) {
03923     U16_SET_CP_LIMIT(fArray, 0, offset, fLength);
03924     return offset;
03925   } else {
03926     return fLength;
03927   }
03928 }
03929 
03930 inline UBool
03931 UnicodeString::isEmpty() const {
03932   return fLength == 0;
03933 }
03934 
03935 //========================================
03936 // Write implementation methods
03937 //========================================
03938 inline const UChar *
03939 UnicodeString::getTerminatedBuffer() {
03940   if(fFlags&(kIsBogus|kOpenGetBuffer)) {
03941     return 0;
03942   } else if(fLength<fCapacity && fArray[fLength]==0) {
03943     return fArray;
03944   } else if(cloneArrayIfNeeded(fLength+1)) {
03945     fArray[fLength]=0;
03946     return fArray;
03947   } else {
03948     return 0;
03949   }
03950 }
03951 
03952 inline UnicodeString&
03953 UnicodeString::operator= (UChar ch)
03954 { return doReplace(0, fLength, &ch, 0, 1); }
03955 
03956 inline UnicodeString&
03957 UnicodeString::operator= (UChar32 ch)
03958 { return replace(0, fLength, ch); }
03959 
03960 inline UnicodeString&
03961 UnicodeString::setTo(const UnicodeString& srcText,
03962              int32_t srcStart,
03963              int32_t srcLength)
03964 {
03965   unBogus();
03966   return doReplace(0, fLength, srcText, srcStart, srcLength);
03967 }
03968 
03969 inline UnicodeString&
03970 UnicodeString::setTo(const UnicodeString& srcText,
03971              int32_t srcStart)
03972 {
03973   unBogus();
03974   srcText.pinIndex(srcStart);
03975   return doReplace(0, fLength, srcText, srcStart, srcText.fLength - srcStart);
03976 }
03977 
03978 inline UnicodeString&
03979 UnicodeString::setTo(const UnicodeString& srcText)
03980 {
03981   unBogus();
03982   return doReplace(0, fLength, srcText, 0, srcText.fLength);
03983 }
03984 
03985 inline UnicodeString&
03986 UnicodeString::setTo(const UChar *srcChars,
03987              int32_t srcLength)
03988 {
03989   unBogus();
03990   return doReplace(0, fLength, srcChars, 0, srcLength);
03991 }
03992 
03993 inline UnicodeString&
03994 UnicodeString::setTo(UChar srcChar)
03995 {
03996   unBogus();
03997   return doReplace(0, fLength, &srcChar, 0, 1);
03998 }
03999 
04000 inline UnicodeString&
04001 UnicodeString::setTo(UChar32 srcChar)
04002 {
04003   unBogus();
04004   return replace(0, fLength, srcChar);
04005 }
04006 
04007 inline UnicodeString&
04008 UnicodeString::operator+= (UChar ch)
04009 { return doReplace(fLength, 0, &ch, 0, 1); }
04010 
04011 inline UnicodeString&
04012 UnicodeString::operator+= (UChar32 ch) {
04013   UChar buffer[U16_MAX_LENGTH];
04014   int32_t _length = 0;
04015   UBool isError = FALSE;
04016   U16_APPEND(buffer, _length, U16_MAX_LENGTH, ch, isError);
04017   return doReplace(fLength, 0, buffer, 0, _length);
04018 }
04019 
04020 inline UnicodeString&
04021 UnicodeString::operator+= (const UnicodeString& srcText)
04022 { return doReplace(fLength, 0, srcText, 0, srcText.fLength); }
04023 
04024 inline UnicodeString&
04025 UnicodeString::append(const UnicodeString& srcText,
04026               int32_t srcStart,
04027               int32_t srcLength)
04028 { return doReplace(fLength, 0, srcText, srcStart, srcLength); }
04029 
04030 inline UnicodeString&
04031 UnicodeString::append(const UnicodeString& srcText)
04032 { return doReplace(fLength, 0, srcText, 0, srcText.fLength); }
04033 
04034 inline UnicodeString&
04035 UnicodeString::append(const UChar *srcChars,
04036               int32_t srcStart,
04037               int32_t srcLength)
04038 { return doReplace(fLength, 0, srcChars, srcStart, srcLength); }
04039 
04040 inline UnicodeString&
04041 UnicodeString::append(const UChar *srcChars,
04042               int32_t srcLength)
04043 { return doReplace(fLength, 0, srcChars, 0, srcLength); }
04044 
04045 inline UnicodeString&
04046 UnicodeString::append(UChar srcChar)
04047 { return doReplace(fLength, 0, &srcChar, 0, 1); }
04048 
04049 inline UnicodeString&
04050 UnicodeString::append(UChar32 srcChar) {
04051   UChar buffer[U16_MAX_LENGTH];
04052   int32_t _length = 0;
04053   UBool isError = FALSE;
04054   U16_APPEND(buffer, _length, U16_MAX_LENGTH, srcChar, isError);
04055   return doReplace(fLength, 0, buffer, 0, _length);
04056 }
04057 
04058 inline UnicodeString&
04059 UnicodeString::insert(int32_t start,
04060               const UnicodeString& srcText,
04061               int32_t srcStart,
04062               int32_t srcLength)
04063 { return doReplace(start, 0, srcText, srcStart, srcLength); }
04064 
04065 inline UnicodeString&
04066 UnicodeString::insert(int32_t start,
04067               const UnicodeString& srcText)
04068 { return doReplace(start, 0, srcText, 0, srcText.fLength); }
04069 
04070 inline UnicodeString&
04071 UnicodeString::insert(int32_t start,
04072               const UChar *srcChars,
04073               int32_t srcStart,
04074               int32_t srcLength)
04075 { return doReplace(start, 0, srcChars, srcStart, srcLength); }
04076 
04077 inline UnicodeString&
04078 UnicodeString::insert(int32_t start,
04079               const UChar *srcChars,
04080               int32_t srcLength)
04081 { return doReplace(start, 0, srcChars, 0, srcLength); }
04082 
04083 inline UnicodeString&
04084 UnicodeString::insert(int32_t start,
04085               UChar srcChar)
04086 { return doReplace(start, 0, &srcChar, 0, 1); }
04087 
04088 inline UnicodeString&
04089 UnicodeString::insert(int32_t start,
04090               UChar32 srcChar)
04091 { return replace(start, 0, srcChar); }
04092 
04093 
04094 inline UnicodeString&
04095 UnicodeString::remove()
04096 {
04097   // remove() of a bogus string makes the string empty and non-bogus
04098   if(isBogus()) {
04099     unBogus();
04100   } else {
04101     fLength = 0;
04102   }
04103   return *this;
04104 }
04105 
04106 inline UnicodeString&
04107 UnicodeString::remove(int32_t start,
04108              int32_t _length)
04109 {
04110   if(start <= 0 && _length == INT32_MAX) {
04111     // remove(guaranteed everything) of a bogus string makes the string empty and non-bogus
04112     return remove();
04113   } else {
04114     return doReplace(start, _length, NULL, 0, 0);
04115   }
04116 }
04117 
04118 inline UnicodeString&
04119 UnicodeString::removeBetween(int32_t start,
04120                 int32_t limit)
04121 { return doReplace(start, limit - start, NULL, 0, 0); }
04122 
04123 inline UBool
04124 UnicodeString::truncate(int32_t targetLength)
04125 {
04126   if(isBogus() && targetLength == 0) {
04127     // truncate(0) of a bogus string makes the string empty and non-bogus
04128     unBogus();
04129     return FALSE;
04130   } else if((uint32_t)targetLength < (uint32_t)fLength) {
04131     fLength = targetLength;
04132     return TRUE;
04133   } else {
04134     return FALSE;
04135   }
04136 }
04137 
04138 inline UnicodeString&
04139 UnicodeString::reverse()
04140 { return doReverse(0, fLength); }
04141 
04142 inline UnicodeString&
04143 UnicodeString::reverse(int32_t start,
04144                int32_t _length)
04145 { return doReverse(start, _length); }
04146 
04147 U_NAMESPACE_END
04148 
04149 #endif

Generated on Tue Sep 13 11:08:16 2005 for ICU 3.4 by  doxygen 1.4.4