Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

unistr.h

00001 /*
00002 **********************************************************************
00003 *   Copyright (C) 1998-2003, 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_CAPI 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 
00070 #if U_SIZEOF_WCHAR_T==U_SIZEOF_UCHAR && U_CHARSET_FAMILY==U_ASCII_FAMILY
00071 #   define UNICODE_STRING(cs, _length) UnicodeString(TRUE, (const UChar *)L ## cs, _length)
00072 #elif U_SIZEOF_UCHAR==1 && U_CHARSET_FAMILY==U_ASCII_FAMILY
00073 #   define UNICODE_STRING(cs, _length) UnicodeString(TRUE, (const UChar *)cs, _length)
00074 #else
00075 #   define UNICODE_STRING(cs, _length) UnicodeString(cs, _length, "")
00076 #endif
00077 
00091 #if U_SIZEOF_WCHAR_T==U_SIZEOF_UCHAR && U_CHARSET_FAMILY==U_ASCII_FAMILY
00092 #   define UNICODE_STRING_SIMPLE(cs) UnicodeString(TRUE, (const UChar *)L ## cs, -1)
00093 #elif U_SIZEOF_UCHAR==1 && U_CHARSET_FAMILY==U_ASCII_FAMILY
00094 #   define UNICODE_STRING_SIMPLE(cs) UnicodeString(TRUE, (const UChar *)cs, -1)
00095 #else
00096 #   define UNICODE_STRING_SIMPLE(cs) UnicodeString(cs, "")
00097 #endif
00098 
00169 class U_COMMON_API UnicodeString : public Replaceable
00170 {
00171 public:
00172 
00173   //========================================
00174   // Read-only operations
00175   //========================================
00176 
00177   /* Comparison - bitwise only - for international comparison use collation */
00178 
00186   inline UBool operator== (const UnicodeString& text) const;
00187 
00195   inline UBool operator!= (const UnicodeString& text) const;
00196 
00204   inline UBool operator> (const UnicodeString& text) const;
00205 
00213   inline UBool operator< (const UnicodeString& text) const;
00214 
00222   inline UBool operator>= (const UnicodeString& text) const;
00223 
00231   inline UBool operator<= (const UnicodeString& text) const;
00232 
00244   inline int8_t compare(const UnicodeString& text) const;
00245 
00260   inline int8_t compare(int32_t start,
00261          int32_t length,
00262          const UnicodeString& srcText) const;
00263 
00281    inline int8_t compare(int32_t start,
00282          int32_t length,
00283          const UnicodeString& srcText,
00284          int32_t srcStart,
00285          int32_t srcLength) const;
00286 
00299   inline int8_t compare(const UChar *srcChars,
00300          int32_t srcLength) const;
00301 
00316   inline int8_t compare(int32_t start,
00317          int32_t length,
00318          const UChar *srcChars) const;
00319 
00337   inline int8_t compare(int32_t start,
00338          int32_t length,
00339          const UChar *srcChars,
00340          int32_t srcStart,
00341          int32_t srcLength) const;
00342 
00360   inline int8_t compareBetween(int32_t start,
00361             int32_t limit,
00362             const UnicodeString& srcText,
00363             int32_t srcStart,
00364             int32_t srcLimit) const;
00365 
00383   inline int8_t compareCodePointOrder(const UnicodeString& text) const;
00384 
00404   inline int8_t compareCodePointOrder(int32_t start,
00405                                       int32_t length,
00406                                       const UnicodeString& srcText) const;
00407 
00429    inline int8_t compareCodePointOrder(int32_t start,
00430                                        int32_t length,
00431                                        const UnicodeString& srcText,
00432                                        int32_t srcStart,
00433                                        int32_t srcLength) const;
00434 
00453   inline int8_t compareCodePointOrder(const UChar *srcChars,
00454                                       int32_t srcLength) const;
00455 
00475   inline int8_t compareCodePointOrder(int32_t start,
00476                                       int32_t length,
00477                                       const UChar *srcChars) const;
00478 
00500   inline int8_t compareCodePointOrder(int32_t start,
00501                                       int32_t length,
00502                                       const UChar *srcChars,
00503                                       int32_t srcStart,
00504                                       int32_t srcLength) const;
00505 
00527   inline int8_t compareCodePointOrderBetween(int32_t start,
00528                                              int32_t limit,
00529                                              const UnicodeString& srcText,
00530                                              int32_t srcStart,
00531                                              int32_t srcLimit) const;
00532 
00551   inline int8_t caseCompare(const UnicodeString& text, uint32_t options) const;
00552 
00573   inline int8_t caseCompare(int32_t start,
00574          int32_t length,
00575          const UnicodeString& srcText,
00576          uint32_t options) const;
00577 
00600   inline int8_t caseCompare(int32_t start,
00601          int32_t length,
00602          const UnicodeString& srcText,
00603          int32_t srcStart,
00604          int32_t srcLength,
00605          uint32_t options) const;
00606 
00626   inline int8_t caseCompare(const UChar *srcChars,
00627          int32_t srcLength,
00628          uint32_t options) const;
00629 
00650   inline int8_t caseCompare(int32_t start,
00651          int32_t length,
00652          const UChar *srcChars,
00653          uint32_t options) const;
00654 
00677   inline int8_t caseCompare(int32_t start,
00678          int32_t length,
00679          const UChar *srcChars,
00680          int32_t srcStart,
00681          int32_t srcLength,
00682          uint32_t options) const;
00683 
00706   inline int8_t caseCompareBetween(int32_t start,
00707             int32_t limit,
00708             const UnicodeString& srcText,
00709             int32_t srcStart,
00710             int32_t srcLimit,
00711             uint32_t options) const;
00712 
00720   inline UBool startsWith(const UnicodeString& text) const;
00721 
00732   inline UBool startsWith(const UnicodeString& srcText,
00733             int32_t srcStart,
00734             int32_t srcLength) const;
00735 
00744   inline UBool startsWith(const UChar *srcChars,
00745             int32_t srcLength) const;
00746 
00756   inline UBool startsWith(const UChar *srcChars,
00757             int32_t srcStart,
00758             int32_t srcLength) const;
00759 
00767   inline UBool endsWith(const UnicodeString& text) const;
00768 
00779   inline UBool endsWith(const UnicodeString& srcText,
00780           int32_t srcStart,
00781           int32_t srcLength) const;
00782 
00791   inline UBool endsWith(const UChar *srcChars,
00792           int32_t srcLength) const;
00793 
00804   inline UBool endsWith(const UChar *srcChars,
00805           int32_t srcStart,
00806           int32_t srcLength) const;
00807 
00808 
00809   /* Searching - bitwise only */
00810 
00819   inline int32_t indexOf(const UnicodeString& text) const;
00820 
00830   inline int32_t indexOf(const UnicodeString& text,
00831               int32_t start) const;
00832 
00844   inline int32_t indexOf(const UnicodeString& text,
00845               int32_t start,
00846               int32_t length) const;
00847 
00864   inline int32_t indexOf(const UnicodeString& srcText,
00865               int32_t srcStart,
00866               int32_t srcLength,
00867               int32_t start,
00868               int32_t length) const;
00869 
00881   inline int32_t indexOf(const UChar *srcChars,
00882               int32_t srcLength,
00883               int32_t start) const;
00884 
00897   inline int32_t indexOf(const UChar *srcChars,
00898               int32_t srcLength,
00899               int32_t start,
00900               int32_t length) const;
00901  
00918   int32_t indexOf(const UChar *srcChars,
00919               int32_t srcStart,
00920               int32_t srcLength,
00921               int32_t start,
00922               int32_t length) const;
00923 
00931   inline int32_t indexOf(UChar c) const;
00932 
00941   inline int32_t indexOf(UChar32 c) const;
00942 
00951   inline int32_t indexOf(UChar c,
00952               int32_t start) const;
00953 
00963   inline int32_t indexOf(UChar32 c,
00964               int32_t start) const;
00965 
00976   inline int32_t indexOf(UChar c,
00977               int32_t start,
00978               int32_t length) const;
00979 
00991   inline int32_t indexOf(UChar32 c,
00992               int32_t start,
00993               int32_t length) const;
00994 
01003   inline int32_t lastIndexOf(const UnicodeString& text) const;
01004 
01014   inline int32_t lastIndexOf(const UnicodeString& text,
01015               int32_t start) const;
01016 
01028   inline int32_t lastIndexOf(const UnicodeString& text,
01029               int32_t start,
01030               int32_t length) const;
01031 
01048   inline int32_t lastIndexOf(const UnicodeString& srcText,
01049               int32_t srcStart,
01050               int32_t srcLength,
01051               int32_t start,
01052               int32_t length) const;
01053 
01064   inline int32_t lastIndexOf(const UChar *srcChars,
01065               int32_t srcLength,
01066               int32_t start) const;
01067 
01080   inline int32_t lastIndexOf(const UChar *srcChars,
01081               int32_t srcLength,
01082               int32_t start,
01083               int32_t length) const;
01084  
01101   int32_t lastIndexOf(const UChar *srcChars,
01102               int32_t srcStart,
01103               int32_t srcLength,
01104               int32_t start,
01105               int32_t length) const;
01106 
01114   inline int32_t lastIndexOf(UChar c) const;
01115 
01124   inline int32_t lastIndexOf(UChar32 c) const;
01125 
01134   inline int32_t lastIndexOf(UChar c,
01135               int32_t start) const;
01136 
01146   inline int32_t lastIndexOf(UChar32 c,
01147               int32_t start) const;
01148 
01159   inline int32_t lastIndexOf(UChar c,
01160               int32_t start,
01161               int32_t length) const;
01162 
01174   inline int32_t lastIndexOf(UChar32 c,
01175               int32_t start,
01176               int32_t length) const;
01177 
01178 
01179   /* Character access */
01180 
01189   inline UChar charAt(int32_t offset) const;
01190 
01198   inline UChar operator[] (int32_t offset) const;
01199 
01211   inline UChar32 char32At(int32_t offset) const;
01212 
01228   inline int32_t getChar32Start(int32_t offset) const;
01229 
01246   inline int32_t getChar32Limit(int32_t offset) const;
01247 
01298   int32_t moveIndex32(int32_t index, int32_t delta) const;
01299 
01300   /* Substring extraction */
01301 
01317   inline void extract(int32_t start, 
01318            int32_t length, 
01319            UChar *dst, 
01320            int32_t dstStart = 0) const;
01321 
01343   int32_t
01344   extract(UChar *dest, int32_t destCapacity,
01345           UErrorCode &errorCode) const;
01346 
01357   inline void extract(int32_t start,
01358            int32_t length,
01359            UnicodeString& target) const;
01360 
01372   inline void extractBetween(int32_t start, 
01373               int32_t limit, 
01374               UChar *dst, 
01375               int32_t dstStart = 0) const;
01376 
01386   virtual void extractBetween(int32_t start,
01387               int32_t limit,
01388               UnicodeString& target) const;
01389 
01410   inline int32_t extract(int32_t start,
01411                  int32_t startLength,
01412                  char *target,
01413                  const char *codepage = 0) const;
01414 
01439   int32_t extract(int32_t start,
01440            int32_t startLength,
01441            char *target,
01442            uint32_t targetLength,
01443            const char *codepage = 0) const;
01444 
01462   int32_t extract(char *dest, int32_t destCapacity,
01463                   UConverter *cnv,
01464                   UErrorCode &errorCode) const;
01465 
01466   /* Length operations */
01467 
01476   inline int32_t length(void) const;
01477 
01491   int32_t
01492   countChar32(int32_t start=0, int32_t length=INT32_MAX) const;
01493 
01517   UBool
01518   hasMoreChar32Than(int32_t start, int32_t length, int32_t number) const;
01519 
01525   inline UBool isEmpty(void) const;
01526 
01536   inline int32_t getCapacity(void) const;
01537 
01538   /* Other operations */
01539 
01545   inline int32_t hashCode(void) const;
01546 
01558   inline UBool isBogus(void) const;
01559 
01560 
01561   //========================================
01562   // Write operations
01563   //========================================
01564 
01565   /* Assignment operations */
01566 
01574   UnicodeString &operator=(const UnicodeString &srcText);
01575 
01596   UnicodeString &fastCopyFrom(const UnicodeString &src);
01597 
01605   inline UnicodeString& operator= (UChar ch);
01606 
01614   inline UnicodeString& operator= (UChar32 ch);
01615 
01627   inline UnicodeString& setTo(const UnicodeString& srcText, 
01628                int32_t srcStart);
01629 
01643   inline UnicodeString& setTo(const UnicodeString& srcText, 
01644                int32_t srcStart, 
01645                int32_t srcLength);
01646 
01655   inline UnicodeString& setTo(const UnicodeString& srcText);
01656 
01665   inline UnicodeString& setTo(const UChar *srcChars,
01666                int32_t srcLength);
01667 
01676   UnicodeString& setTo(UChar srcChar);
01677 
01686   UnicodeString& setTo(UChar32 srcChar);
01687 
01708   UnicodeString &setTo(UBool isTerminated,
01709                        const UChar *text,
01710                        int32_t textLength);
01711 
01731   UnicodeString &setTo(UChar *buffer,
01732                        int32_t buffLength,
01733                        int32_t buffCapacity);
01734 
01775   void setToBogus();
01776 
01784   UnicodeString& setCharAt(int32_t offset, 
01785                UChar ch);
01786 
01787 
01788   /* Append operations */
01789 
01797  inline  UnicodeString& operator+= (UChar ch);
01798 
01806  inline  UnicodeString& operator+= (UChar32 ch);
01807 
01816   inline UnicodeString& operator+= (const UnicodeString& srcText);
01817 
01832   inline UnicodeString& append(const UnicodeString& srcText, 
01833             int32_t srcStart, 
01834             int32_t srcLength);
01835 
01843   inline UnicodeString& append(const UnicodeString& srcText);
01844 
01858   inline UnicodeString& append(const UChar *srcChars, 
01859             int32_t srcStart, 
01860             int32_t srcLength);
01861 
01870   inline UnicodeString& append(const UChar *srcChars,
01871             int32_t srcLength);
01872 
01879   inline UnicodeString& append(UChar srcChar);
01880 
01887   inline UnicodeString& append(UChar32 srcChar);
01888 
01889 
01890   /* Insert operations */
01891 
01905   inline UnicodeString& insert(int32_t start, 
01906             const UnicodeString& srcText, 
01907             int32_t srcStart, 
01908             int32_t srcLength);
01909 
01918   inline UnicodeString& insert(int32_t start, 
01919             const UnicodeString& srcText);
01920 
01934   inline UnicodeString& insert(int32_t start, 
01935             const UChar *srcChars, 
01936             int32_t srcStart, 
01937             int32_t srcLength);
01938 
01948   inline UnicodeString& insert(int32_t start, 
01949             const UChar *srcChars,
01950             int32_t srcLength);
01951 
01960   inline UnicodeString& insert(int32_t start, 
01961             UChar srcChar);
01962 
01971   inline UnicodeString& insert(int32_t start, 
01972             UChar32 srcChar);
01973 
01974 
01975   /* Replace operations */
01976 
01994   UnicodeString& replace(int32_t start, 
01995              int32_t length, 
01996              const UnicodeString& srcText, 
01997              int32_t srcStart, 
01998              int32_t srcLength);
01999 
02012   UnicodeString& replace(int32_t start, 
02013              int32_t length, 
02014              const UnicodeString& srcText);
02015 
02033   UnicodeString& replace(int32_t start, 
02034              int32_t length, 
02035              const UChar *srcChars, 
02036              int32_t srcStart, 
02037              int32_t srcLength);
02038 
02051   inline UnicodeString& replace(int32_t start, 
02052              int32_t length, 
02053              const UChar *srcChars,
02054              int32_t srcLength);
02055 
02067   inline UnicodeString& replace(int32_t start, 
02068              int32_t length, 
02069              UChar srcChar);
02070 
02082   inline UnicodeString& replace(int32_t start, 
02083              int32_t length, 
02084              UChar32 srcChar);
02085 
02095   inline UnicodeString& replaceBetween(int32_t start, 
02096                 int32_t limit, 
02097                 const UnicodeString& srcText);
02098 
02113   inline UnicodeString& replaceBetween(int32_t start, 
02114                 int32_t limit, 
02115                 const UnicodeString& srcText, 
02116                 int32_t srcStart, 
02117                 int32_t srcLimit);
02118 
02129   virtual void handleReplaceBetween(int32_t start,
02130                                     int32_t limit,
02131                                     const UnicodeString& text);
02132 
02138   virtual UBool hasMetaData() const;
02139   
02155   virtual void copy(int32_t start, int32_t limit, int32_t dest);
02156 
02157   /* Search and replace operations */
02158 
02167   inline UnicodeString& findAndReplace(const UnicodeString& oldText,
02168                 const UnicodeString& newText);
02169 
02181   inline UnicodeString& findAndReplace(int32_t start,
02182                 int32_t length,
02183                 const UnicodeString& oldText,
02184                 const UnicodeString& newText);
02185 
02203   UnicodeString& findAndReplace(int32_t start,
02204                 int32_t length,
02205                 const UnicodeString& oldText,
02206                 int32_t oldStart,
02207                 int32_t oldLength,
02208                 const UnicodeString& newText,
02209                 int32_t newStart,
02210                 int32_t newLength);
02211 
02212 
02213   /* Remove operations */
02214 
02220   inline UnicodeString& remove(void);
02221 
02230   inline UnicodeString& remove(int32_t start, 
02231                                int32_t length = (int32_t)INT32_MAX);
02232 
02241   inline UnicodeString& removeBetween(int32_t start,
02242                                       int32_t limit = (int32_t)INT32_MAX);
02243 
02244 
02245   /* Length operations */
02246 
02258   UBool padLeading(int32_t targetLength,
02259                     UChar padChar = 0x0020);
02260 
02272   UBool padTrailing(int32_t targetLength,
02273                      UChar padChar = 0x0020);
02274 
02281   inline UBool truncate(int32_t targetLength);
02282 
02288   UnicodeString& trim(void);
02289 
02290 
02291   /* Miscellaneous operations */
02292 
02298   inline UnicodeString& reverse(void);
02299 
02308   inline UnicodeString& reverse(int32_t start,
02309              int32_t length);
02310 
02317   UnicodeString& toUpper(void);
02318 
02326   UnicodeString& toUpper(const Locale& locale);
02327 
02334   UnicodeString& toLower(void);
02335 
02343   UnicodeString& toLower(const Locale& locale);
02344 
02345 #if !UCONFIG_NO_BREAK_ITERATION
02346 
02373   UnicodeString &toTitle(BreakIterator *titleIter);
02374 
02402   UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale);
02403 
02404 #endif
02405 
02417   UnicodeString &foldCase(uint32_t options=0 /*U_FOLD_CASE_DEFAULT*/);
02418 
02419   //========================================
02420   // Access to the internal buffer
02421   //========================================
02422 
02466   UChar *getBuffer(int32_t minCapacity);
02467 
02488   void releaseBuffer(int32_t newLength=-1);
02489 
02520   inline const UChar *getBuffer() const;
02521 
02555   inline const UChar *getTerminatedBuffer();
02556 
02557   //========================================
02558   // Constructors
02559   //========================================
02560 
02564   UnicodeString();
02565 
02577   UnicodeString(int32_t capacity, UChar32 c, int32_t count);
02578 
02584   UnicodeString(UChar ch);
02585 
02591   UnicodeString(UChar32 ch);
02592 
02599   UnicodeString(const UChar *text);
02600 
02608   UnicodeString(const UChar *text,
02609         int32_t textLength);
02610 
02630   UnicodeString(UBool isTerminated,
02631                 const UChar *text,
02632                 int32_t textLength);
02633 
02652   UnicodeString(UChar *buffer, int32_t buffLength, int32_t buffCapacity);
02653 
02665   UnicodeString(const char *codepageData,
02666         const char *codepage = 0);
02667 
02680   UnicodeString(const char *codepageData,
02681         int32_t dataLength,
02682         const char *codepage = 0);
02683 
02705   UnicodeString(
02706         const char *src, int32_t srcLength,
02707         UConverter *cnv,
02708         UErrorCode &errorCode);
02709 
02710 
02716   UnicodeString(const UnicodeString& that);
02717 
02724   UnicodeString(const UnicodeString& src, int32_t srcStart);
02725 
02733   UnicodeString(const UnicodeString& src, int32_t srcStart, int32_t srcLength);
02734 
02751   virtual Replaceable *clone() const;
02752 
02756   ~UnicodeString();
02757 
02758 
02759   /* Miscellaneous operations */
02760 
02795   UnicodeString unescape() const;
02796 
02816   UChar32 unescapeAt(int32_t &offset) const;
02817 
02823   static UClassID getStaticClassID();
02824 
02830   virtual UClassID getDynamicClassID() const;
02831 
02832   //========================================
02833   // Implementation methods
02834   //========================================
02835 
02836 protected:
02841   virtual int32_t getLength() const;
02842 
02848   virtual UChar getCharAt(int32_t offset) const;
02849 
02855   virtual UChar32 getChar32At(int32_t offset) const;
02856 
02857 private:
02858 
02859   inline int8_t
02860   doCompare(int32_t start,
02861            int32_t length,
02862            const UnicodeString& srcText,
02863            int32_t srcStart,
02864            int32_t srcLength) const;
02865 
02866   int8_t doCompare(int32_t start,
02867            int32_t length,
02868            const UChar *srcChars,
02869            int32_t srcStart,
02870            int32_t srcLength) const;
02871 
02872   inline int8_t
02873   doCompareCodePointOrder(int32_t start,
02874                           int32_t length,
02875                           const UnicodeString& srcText,
02876                           int32_t srcStart,
02877                           int32_t srcLength) const;
02878 
02879   int8_t doCompareCodePointOrder(int32_t start,
02880                                  int32_t length,
02881                                  const UChar *srcChars,
02882                                  int32_t srcStart,
02883                                  int32_t srcLength) const;
02884 
02885   inline int8_t
02886   doCaseCompare(int32_t start,
02887                 int32_t length,
02888                 const UnicodeString &srcText,
02889                 int32_t srcStart,
02890                 int32_t srcLength,
02891                 uint32_t options) const;
02892 
02893   int8_t
02894   doCaseCompare(int32_t start,
02895                 int32_t length,
02896                 const UChar *srcChars,
02897                 int32_t srcStart,
02898                 int32_t srcLength,
02899                 uint32_t options) const;
02900 
02901   int32_t doIndexOf(UChar c,
02902             int32_t start,
02903             int32_t length) const;
02904 
02905   int32_t doIndexOf(UChar32 c,
02906                         int32_t start,
02907                         int32_t length) const;
02908 
02909   int32_t doLastIndexOf(UChar c,
02910                 int32_t start,
02911                 int32_t length) const;
02912 
02913   int32_t doLastIndexOf(UChar32 c,
02914                             int32_t start,
02915                             int32_t length) const;
02916 
02917   void doExtract(int32_t start, 
02918          int32_t length, 
02919          UChar *dst, 
02920          int32_t dstStart) const;
02921 
02922   inline void doExtract(int32_t start,
02923          int32_t length,
02924          UnicodeString& target) const;
02925 
02926   inline UChar doCharAt(int32_t offset)  const;
02927 
02928   UnicodeString& doReplace(int32_t start, 
02929                int32_t length, 
02930                const UnicodeString& srcText, 
02931                int32_t srcStart, 
02932                int32_t srcLength);
02933 
02934   UnicodeString& doReplace(int32_t start, 
02935                int32_t length, 
02936                const UChar *srcChars, 
02937                int32_t srcStart, 
02938                int32_t srcLength);
02939 
02940   UnicodeString& doReverse(int32_t start,
02941                int32_t length);
02942 
02943   // calculate hash code
02944   int32_t doHashCode(void) const;
02945 
02946   // get pointer to start of array
02947   inline UChar* getArrayStart(void);
02948   inline const UChar* getArrayStart(void) const;
02949 
02950   // allocate the array; result may be fStackBuffer
02951   // sets refCount to 1 if appropriate
02952   // sets fArray, fCapacity, and fFlags
02953   // returns boolean for success or failure
02954   UBool allocate(int32_t capacity);
02955 
02956   // release the array if owned
02957   void releaseArray(void);
02958 
02959   // turn a bogus string into an empty one
02960   void unBogus();
02961 
02962   // implements assigment operator, copy constructor, and fastCopyFrom()
02963   UnicodeString &copyFrom(const UnicodeString &src, UBool fastCopy=FALSE);
02964 
02965   // Pin start and limit to acceptable values.
02966   inline void pinIndex(int32_t& start) const;
02967   inline void pinIndices(int32_t& start,
02968                          int32_t& length) const;
02969 
02970   /* Internal extract() using UConverter. */
02971   int32_t doExtract(int32_t start, int32_t length,
02972                     char *dest, int32_t destCapacity,
02973                     UConverter *cnv,
02974                     UErrorCode &errorCode) const;
02975 
02976   /*
02977    * Real constructor for converting from codepage data.
02978    * It assumes that it is called with !fRefCounted.
02979    *
02980    * If <code>codepage==0</code>, then the default converter
02981    * is used for the platform encoding.
02982    * If <code>codepage</code> is an empty string (<code>""</code>),
02983    * then a simple conversion is performed on the codepage-invariant
02984    * subset ("invariant characters") of the platform encoding. See utypes.h.
02985    */
02986   void doCodepageCreate(const char *codepageData,
02987                         int32_t dataLength,
02988                         const char *codepage);
02989 
02990   /*
02991    * Worker function for creating a UnicodeString from
02992    * a codepage string using a UConverter.
02993    */
02994   void
02995   doCodepageCreate(const char *codepageData,
02996                    int32_t dataLength,
02997                    UConverter *converter,
02998                    UErrorCode &status);
02999   /*
03000    * This function is called when write access to the array
03001    * is necessary.
03002    *
03003    * We need to make a copy of the array if
03004    * the buffer is read-only, or
03005    * the buffer is refCounted (shared), and refCount>1, or
03006    * the buffer is too small.
03007    *
03008    * Return FALSE if memory could not be allocated.
03009    */
03010   UBool cloneArrayIfNeeded(int32_t newCapacity = -1,
03011                             int32_t growCapacity = -1,
03012                             UBool doCopyArray = TRUE,
03013                             int32_t **pBufferToDelete = 0,
03014                             UBool forceClone = FALSE);
03015 
03016   // common function for case mappings
03017   UnicodeString &
03018   caseMap(BreakIterator *titleIter,
03019           const Locale& locale,
03020           uint32_t options,
03021           int32_t toWhichCase);
03022 
03023   // ref counting
03024   void addRef(void);
03025   int32_t removeRef(void);
03026   int32_t refCount(void) const;
03027 
03028   // constants
03029   enum {
03030     US_STACKBUF_SIZE=7, // Size of stack buffer for small strings
03031     kInvalidUChar=0xffff, // invalid UChar index
03032     kGrowSize=128, // grow size for this buffer
03033     kInvalidHashCode=0, // invalid hash code
03034     kEmptyHashCode=1, // hash code for empty string
03035 
03036     // bit flag values for fFlags
03037     kIsBogus=1,         // this string is bogus, i.e., not valid or NULL
03038     kUsingStackBuffer=2,// fArray==fStackBuffer
03039     kRefCounted=4,      // there is a refCount field before the characters in fArray
03040     kBufferIsReadonly=8,// do not write to this buffer
03041     kOpenGetBuffer=16,  // getBuffer(minCapacity) was called (is "open"),
03042                         // and releaseBuffer(newLength) must be called
03043 
03044     // combined values for convenience
03045     kShortString=kUsingStackBuffer,
03046     kLongString=kRefCounted,
03047     kReadonlyAlias=kBufferIsReadonly,
03048     kWritableAlias=0
03049   };
03050 
03051   friend class StringCharacterIterator;
03052   friend class StringThreadTest;
03053 
03054   /*
03055    * The following are all the class fields that are stored
03056    * in each UnicodeString object.
03057    * Note that UnicodeString has virtual functions,
03058    * therefore there is an implicit vtable pointer
03059    * as the first real field.
03060    * The fields should be aligned such that no padding is
03061    * necessary, mostly by having larger types first.
03062    * On 32-bit machines, the size should be 32 bytes,
03063    * on 64-bit machines (8-byte pointers), it should be 40 bytes.
03064    */
03065   // (implicit) *vtable;
03066   int32_t   fLength;        // number of characters in fArray
03067   int32_t   fCapacity;      // sizeof fArray
03068   UChar     *fArray;        // the Unicode data
03069   uint16_t  fFlags;         // bit flags: see constants above
03070   UChar     fStackBuffer [ US_STACKBUF_SIZE ]; // buffer for small strings
03071 
03072 };
03073 
03082 U_COMMON_API UnicodeString
03083 operator+ (const UnicodeString &s1, const UnicodeString &s2);
03084 
03085 U_NAMESPACE_END
03086 
03087 // inline implementations -------------------------------------------------- ***
03088 
03089 //========================================
03090 // Array copying
03091 //========================================
03096 inline void 
03097 uprv_arrayCopy(const U_NAMESPACE_QUALIFIER UnicodeString *src, U_NAMESPACE_QUALIFIER UnicodeString *dst, int32_t count)
03098 { while(count-- > 0) *dst++ = *src++; }
03099 
03104 inline void 
03105 uprv_arrayCopy(const U_NAMESPACE_QUALIFIER UnicodeString *src, int32_t srcStart, 
03106         U_NAMESPACE_QUALIFIER UnicodeString *dst, int32_t dstStart, int32_t count)
03107 { uprv_arrayCopy(src+srcStart, dst+dstStart, count); }
03108 
03109 U_NAMESPACE_BEGIN
03110 
03111 //========================================
03112 // Inline members
03113 //========================================
03114 
03115 //========================================
03116 // Privates
03117 //========================================
03118 
03119 inline void
03120 UnicodeString::pinIndex(int32_t& start) const
03121 {
03122   // pin index
03123   if(start < 0) {
03124     start = 0;
03125   } else if(start > fLength) {
03126     start = fLength;
03127   }
03128 }
03129 
03130 inline void
03131 UnicodeString::pinIndices(int32_t& start,
03132                           int32_t& _length) const
03133 {
03134   // pin indices
03135   if(start < 0) {
03136     start = 0;
03137   } else if(start > fLength) {
03138     start = fLength;
03139   }
03140   if(_length < 0) {
03141     _length = 0;
03142   } else if(_length > (fLength - start)) {
03143     _length = (fLength - start);
03144   }
03145 }
03146 
03147 inline UChar* 
03148 UnicodeString::getArrayStart()
03149 { return fArray; }
03150 
03151 inline const UChar* 
03152 UnicodeString::getArrayStart() const
03153 { return fArray; }
03154 
03155 //========================================
03156 // Read-only implementation methods
03157 //========================================
03158 inline int32_t  
03159 UnicodeString::length() const
03160 { return fLength; }
03161 
03162 inline int32_t 
03163 UnicodeString::getCapacity() const
03164 { return fCapacity; }
03165 
03166 inline int32_t 
03167 UnicodeString::hashCode() const
03168 { return doHashCode(); }
03169 
03170 inline UBool 
03171 UnicodeString::isBogus() const
03172 { return (UBool)(fFlags & kIsBogus); }
03173 
03174 inline const UChar *
03175 UnicodeString::getBuffer() const {
03176   if(!(fFlags&(kIsBogus|kOpenGetBuffer))) {
03177     return fArray;
03178   } else {
03179     return 0;
03180   }
03181 }
03182 
03183 //========================================
03184 // Read-only alias methods
03185 //========================================
03186 inline int8_t
03187 UnicodeString::doCompare(int32_t start,
03188               int32_t length,
03189               const UnicodeString& srcText,
03190               int32_t srcStart,
03191               int32_t srcLength) const
03192 {
03193   if(srcText.isBogus()) {
03194     return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
03195   } else {
03196     srcText.pinIndices(srcStart, srcLength);
03197     return doCompare(start, length, srcText.fArray, srcStart, srcLength);
03198   }
03199 }
03200 
03201 inline UBool
03202 UnicodeString::operator== (const UnicodeString& text) const
03203 {
03204   if(isBogus()) {
03205     return text.isBogus();
03206   } else {
03207     return
03208       !text.isBogus() &&
03209       fLength == text.fLength &&
03210       doCompare(0, fLength, text, 0, text.fLength) == 0;
03211   }
03212 }
03213 
03214 inline UBool
03215 UnicodeString::operator!= (const UnicodeString& text) const
03216 { return (! operator==(text)); }
03217 
03218 inline UBool
03219 UnicodeString::operator> (const UnicodeString& text) const
03220 { return doCompare(0, fLength, text, 0, text.fLength) == 1; }
03221 
03222 inline UBool
03223 UnicodeString::operator< (const UnicodeString& text) const
03224 { return doCompare(0, fLength, text, 0, text.fLength) == -1; }
03225 
03226 inline UBool
03227 UnicodeString::operator>= (const UnicodeString& text) const
03228 { return doCompare(0, fLength, text, 0, text.fLength) != -1; }
03229 
03230 inline UBool
03231 UnicodeString::operator<= (const UnicodeString& text) const
03232 { return doCompare(0, fLength, text, 0, text.fLength) != 1; }
03233 
03234 inline int8_t 
03235 UnicodeString::compare(const UnicodeString& text) const
03236 { return doCompare(0, fLength, text, 0, text.fLength); }
03237 
03238 inline int8_t 
03239 UnicodeString::compare(int32_t start,
03240                int32_t _length,
03241                const UnicodeString& srcText) const
03242 { return doCompare(start, _length, srcText, 0, srcText.fLength); }
03243 
03244 inline int8_t 
03245 UnicodeString::compare(const UChar *srcChars,
03246                int32_t srcLength) const
03247 { return doCompare(0, fLength, srcChars, 0, srcLength); }
03248 
03249 inline int8_t 
03250 UnicodeString::compare(int32_t start,
03251                int32_t _length,
03252                const UnicodeString& srcText,
03253                int32_t srcStart,
03254                int32_t srcLength) const
03255 { return doCompare(start, _length, srcText, srcStart, srcLength); }
03256 
03257 inline int8_t
03258 UnicodeString::compare(int32_t start,
03259                int32_t _length,
03260                const UChar *srcChars) const
03261 { return doCompare(start, _length, srcChars, 0, _length); }
03262 
03263 inline int8_t 
03264 UnicodeString::compare(int32_t start,
03265                int32_t _length,
03266                const UChar *srcChars,
03267                int32_t srcStart,
03268                int32_t srcLength) const
03269 { return doCompare(start, _length, srcChars, srcStart, srcLength); }
03270 
03271 inline int8_t
03272 UnicodeString::compareBetween(int32_t start,
03273                   int32_t limit,
03274                   const UnicodeString& srcText,
03275                   int32_t srcStart,
03276                   int32_t srcLimit) const
03277 { return doCompare(start, limit - start, 
03278            srcText, srcStart, srcLimit - srcStart); }
03279 
03280 inline int8_t
03281 UnicodeString::doCompareCodePointOrder(int32_t start,
03282                                        int32_t length,
03283                                        const UnicodeString& srcText,
03284                                        int32_t srcStart,
03285                                        int32_t srcLength) const
03286 {
03287   if(srcText.isBogus()) {
03288     return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
03289   } else {
03290     srcText.pinIndices(srcStart, srcLength);
03291     return doCompareCodePointOrder(start, length, srcText.fArray, srcStart, srcLength);
03292   }
03293 }
03294 
03295 inline int8_t 
03296 UnicodeString::compareCodePointOrder(const UnicodeString& text) const
03297 { return doCompareCodePointOrder(0, fLength, text, 0, text.fLength); }
03298 
03299 inline int8_t 
03300 UnicodeString::compareCodePointOrder(int32_t start,
03301                                      int32_t _length,
03302                                      const UnicodeString& srcText) const
03303 { return doCompareCodePointOrder(start, _length, srcText, 0, srcText.fLength); }
03304 
03305 inline int8_t 
03306 UnicodeString::compareCodePointOrder(const UChar *srcChars,
03307                                      int32_t srcLength) const
03308 { return doCompareCodePointOrder(0, fLength, srcChars, 0, srcLength); }
03309 
03310 inline int8_t 
03311 UnicodeString::compareCodePointOrder(int32_t start,
03312                                      int32_t _length,
03313                                      const UnicodeString& srcText,
03314                                      int32_t srcStart,
03315                                      int32_t srcLength) const
03316 { return doCompareCodePointOrder(start, _length, srcText, srcStart, srcLength); }
03317 
03318 inline int8_t
03319 UnicodeString::compareCodePointOrder(int32_t start,
03320                                      int32_t _length,
03321                                      const UChar *srcChars) const
03322 { return doCompareCodePointOrder(start, _length, srcChars, 0, _length); }
03323 
03324 inline int8_t 
03325 UnicodeString::compareCodePointOrder(int32_t start,
03326                                      int32_t _length,
03327                                      const UChar *srcChars,
03328                                      int32_t srcStart,
03329                                      int32_t srcLength) const
03330 { return doCompareCodePointOrder(start, _length, srcChars, srcStart, srcLength); }
03331 
03332 inline int8_t
03333 UnicodeString::compareCodePointOrderBetween(int32_t start,
03334                                             int32_t limit,
03335                                             const UnicodeString& srcText,
03336                                             int32_t srcStart,
03337                                             int32_t srcLimit) const
03338 { return doCompareCodePointOrder(start, limit - start, 
03339            srcText, srcStart, srcLimit - srcStart); }
03340 
03341 inline int8_t
03342 UnicodeString::doCaseCompare(int32_t start,
03343                              int32_t length,
03344                              const UnicodeString &srcText,
03345                              int32_t srcStart,
03346                              int32_t srcLength,
03347                              uint32_t options) const
03348 {
03349   if(srcText.isBogus()) {
03350     return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
03351   } else {
03352     srcText.pinIndices(srcStart, srcLength);
03353     return doCaseCompare(start, length, srcText.fArray, srcStart, srcLength, options);
03354   }
03355 }
03356 
03357 inline int8_t 
03358 UnicodeString::caseCompare(const UnicodeString &text, uint32_t options) const {
03359   return doCaseCompare(0, fLength, text, 0, text.fLength, options);
03360 }
03361 
03362 inline int8_t 
03363 UnicodeString::caseCompare(int32_t start,
03364                            int32_t _length,
03365                            const UnicodeString &srcText,
03366                            uint32_t options) const {
03367   return doCaseCompare(start, _length, srcText, 0, srcText.fLength, options);
03368 }
03369 
03370 inline int8_t 
03371 UnicodeString::caseCompare(const UChar *srcChars,
03372                            int32_t srcLength,
03373                            uint32_t options) const {
03374   return doCaseCompare(0, fLength, srcChars, 0, srcLength, options);
03375 }
03376 
03377 inline int8_t 
03378 UnicodeString::caseCompare(int32_t start,
03379                            int32_t _length,
03380                            const UnicodeString &srcText,
03381                            int32_t srcStart,
03382                            int32_t srcLength,
03383                            uint32_t options) const {
03384   return doCaseCompare(start, _length, srcText, srcStart, srcLength, options);
03385 }
03386 
03387 inline int8_t
03388 UnicodeString::caseCompare(int32_t start,
03389                            int32_t _length,
03390                            const UChar *srcChars,
03391                            uint32_t options) const {
03392   return doCaseCompare(start, _length, srcChars, 0, _length, options);
03393 }
03394 
03395 inline int8_t 
03396 UnicodeString::caseCompare(int32_t start,
03397                            int32_t _length,
03398                            const UChar *srcChars,
03399                            int32_t srcStart,
03400                            int32_t srcLength,
03401                            uint32_t options) const {
03402   return doCaseCompare(start, _length, srcChars, srcStart, srcLength, options);
03403 }
03404 
03405 inline int8_t
03406 UnicodeString::caseCompareBetween(int32_t start,
03407                                   int32_t limit,
03408                                   const UnicodeString &srcText,
03409                                   int32_t srcStart,
03410                                   int32_t srcLimit,
03411                                   uint32_t options) const {
03412   return doCaseCompare(start, limit - start, srcText, srcStart, srcLimit - srcStart, options);
03413 }
03414 
03415 inline int32_t 
03416 UnicodeString::indexOf(const UnicodeString& srcText,
03417                int32_t srcStart,
03418                int32_t srcLength,
03419                int32_t start,
03420                int32_t _length) const
03421 {
03422   if(!srcText.isBogus()) {
03423     srcText.pinIndices(srcStart, srcLength);
03424     if(srcLength > 0) {
03425       return indexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
03426     }
03427   }
03428   return -1;
03429 }
03430 
03431 inline int32_t 
03432 UnicodeString::indexOf(const UnicodeString& text) const
03433 { return indexOf(text, 0, text.fLength, 0, fLength); }
03434 
03435 inline int32_t 
03436 UnicodeString::indexOf(const UnicodeString& text,
03437                int32_t start) const {
03438   pinIndex(start);
03439   return indexOf(text, 0, text.fLength, start, fLength - start);
03440 }
03441 
03442 inline int32_t 
03443 UnicodeString::indexOf(const UnicodeString& text,
03444                int32_t start,
03445                int32_t _length) const
03446 { return indexOf(text, 0, text.fLength, start, _length); }
03447 
03448 inline int32_t 
03449 UnicodeString::indexOf(const UChar *srcChars,
03450                int32_t srcLength,
03451                int32_t start) const {
03452   pinIndex(start);
03453   return indexOf(srcChars, 0, srcLength, start, fLength - start);
03454 }
03455 
03456 inline int32_t 
03457 UnicodeString::indexOf(const UChar *srcChars,
03458                int32_t srcLength,
03459                int32_t start,
03460                int32_t _length) const
03461 { return indexOf(srcChars, 0, srcLength, start, _length); }
03462 
03463 inline int32_t 
03464 UnicodeString::indexOf(UChar c,
03465                int32_t start,
03466                int32_t _length) const
03467 { return doIndexOf(c, start, _length); }
03468 
03469 inline int32_t 
03470 UnicodeString::indexOf(UChar32 c,
03471                int32_t start,
03472                int32_t _length) const
03473 { return doIndexOf(c, start, _length); }
03474 
03475 inline int32_t 
03476 UnicodeString::indexOf(UChar c) const
03477 { return doIndexOf(c, 0, fLength); }
03478 
03479 inline int32_t 
03480 UnicodeString::indexOf(UChar32 c) const
03481 { return indexOf(c, 0, fLength); }
03482 
03483 inline int32_t 
03484 UnicodeString::indexOf(UChar c,
03485                int32_t start) const {
03486   pinIndex(start);
03487   return doIndexOf(c, start, fLength - start);
03488 }
03489 
03490 inline int32_t 
03491 UnicodeString::indexOf(UChar32 c,
03492                int32_t start) const {
03493   pinIndex(start);
03494   return indexOf(c, start, fLength - start);
03495 }
03496 
03497 inline int32_t 
03498 UnicodeString::lastIndexOf(const UChar *srcChars,
03499                int32_t srcLength,
03500                int32_t start,
03501                int32_t _length) const
03502 { return lastIndexOf(srcChars, 0, srcLength, start, _length); }
03503 
03504 inline int32_t 
03505 UnicodeString::lastIndexOf(const UChar *srcChars,
03506                int32_t srcLength,
03507                int32_t start) const {
03508   pinIndex(start);
03509   return lastIndexOf(srcChars, 0, srcLength, start, fLength - start);
03510 }
03511 
03512 inline int32_t 
03513 UnicodeString::lastIndexOf(const UnicodeString& srcText,
03514                int32_t srcStart,
03515                int32_t srcLength,
03516                int32_t start,
03517                int32_t _length) const
03518 {
03519   if(!srcText.isBogus()) {
03520     srcText.pinIndices(srcStart, srcLength);
03521     if(srcLength > 0) {
03522       return lastIndexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
03523     }
03524   }
03525   return -1;
03526 }
03527 
03528 inline int32_t 
03529 UnicodeString::lastIndexOf(const UnicodeString& text,
03530                int32_t start,
03531                int32_t _length) const
03532 { return lastIndexOf(text, 0, text.fLength, start, _length); }
03533 
03534 inline int32_t 
03535 UnicodeString::lastIndexOf(const UnicodeString& text,
03536                int32_t start) const {
03537   pinIndex(start);
03538   return lastIndexOf(text, 0, text.fLength, start, fLength - start);
03539 }
03540 
03541 inline int32_t 
03542 UnicodeString::lastIndexOf(const UnicodeString& text) const
03543 { return lastIndexOf(text, 0, text.fLength, 0, fLength); }
03544 
03545 inline int32_t 
03546 UnicodeString::lastIndexOf(UChar c,
03547                int32_t start,
03548                int32_t _length) const
03549 { return doLastIndexOf(c, start, _length); }
03550 
03551 inline int32_t 
03552 UnicodeString::lastIndexOf(UChar32 c,
03553                int32_t start,
03554                int32_t _length) const {
03555   return doLastIndexOf(c, start, _length);
03556 }
03557 
03558 inline int32_t 
03559 UnicodeString::lastIndexOf(UChar c) const
03560 { return doLastIndexOf(c, 0, fLength); }
03561 
03562 inline int32_t 
03563 UnicodeString::lastIndexOf(UChar32 c) const {
03564   return lastIndexOf(c, 0, fLength);
03565 }
03566 
03567 inline int32_t 
03568 UnicodeString::lastIndexOf(UChar c,
03569                int32_t start) const {
03570   pinIndex(start);
03571   return doLastIndexOf(c, start, fLength - start);
03572 }
03573 
03574 inline int32_t 
03575 UnicodeString::lastIndexOf(UChar32 c,
03576                int32_t start) const {
03577   pinIndex(start);
03578   return lastIndexOf(c, start, fLength - start);
03579 }
03580 
03581 inline UBool 
03582 UnicodeString::startsWith(const UnicodeString& text) const
03583 { return compare(0, text.fLength, text, 0, text.fLength) == 0; }
03584 
03585 inline UBool 
03586 UnicodeString::startsWith(const UnicodeString& srcText,
03587               int32_t srcStart,
03588               int32_t srcLength) const
03589 { return doCompare(0, srcLength, srcText, srcStart, srcLength) == 0; }
03590 
03591 inline UBool 
03592 UnicodeString::startsWith(const UChar *srcChars,
03593               int32_t srcLength) const
03594 { return doCompare(0, srcLength, srcChars, 0, srcLength) == 0; }
03595 
03596 inline UBool 
03597 UnicodeString::startsWith(const UChar *srcChars,
03598               int32_t srcStart,
03599               int32_t srcLength) const
03600 { return doCompare(0, srcLength, srcChars, srcStart, srcLength) == 0;}
03601 
03602 inline UBool 
03603 UnicodeString::endsWith(const UnicodeString& text) const
03604 { return doCompare(fLength - text.fLength, text.fLength, 
03605            text, 0, text.fLength) == 0; }
03606 
03607 inline UBool 
03608 UnicodeString::endsWith(const UnicodeString& srcText,
03609             int32_t srcStart,
03610             int32_t srcLength) const {
03611   srcText.pinIndices(srcStart, srcLength);
03612   return doCompare(fLength - srcLength, srcLength, 
03613                    srcText, srcStart, srcLength) == 0;
03614 }
03615 
03616 inline UBool 
03617 UnicodeString::endsWith(const UChar *srcChars,
03618             int32_t srcLength) const {
03619   if(srcLength < 0) {
03620     srcLength = u_strlen(srcChars);
03621   }
03622   return doCompare(fLength - srcLength, srcLength, 
03623                    srcChars, 0, srcLength) == 0;
03624 }
03625 
03626 inline UBool 
03627 UnicodeString::endsWith(const UChar *srcChars,
03628             int32_t srcStart,
03629             int32_t srcLength) const {
03630   if(srcLength < 0) {
03631     srcLength = u_strlen(srcChars + srcStart);
03632   }
03633   return doCompare(fLength - srcLength, srcLength, 
03634                    srcChars, srcStart, srcLength) == 0;
03635 }
03636 
03637 //========================================
03638 // replace
03639 //========================================
03640 inline UnicodeString& 
03641 UnicodeString::replace(int32_t start, 
03642                int32_t _length, 
03643                const UnicodeString& srcText) 
03644 { return doReplace(start, _length, srcText, 0, srcText.fLength); }
03645 
03646 inline UnicodeString& 
03647 UnicodeString::replace(int32_t start, 
03648                int32_t _length, 
03649                const UnicodeString& srcText, 
03650                int32_t srcStart, 
03651                int32_t srcLength)
03652 { return doReplace(start, _length, srcText, srcStart, srcLength); }
03653 
03654 inline UnicodeString& 
03655 UnicodeString::replace(int32_t start, 
03656                int32_t _length, 
03657                const UChar *srcChars,
03658                int32_t srcLength)
03659 { return doReplace(start, _length, srcChars, 0, srcLength); }
03660 
03661 inline UnicodeString& 
03662 UnicodeString::replace(int32_t start, 
03663                int32_t _length, 
03664                const UChar *srcChars, 
03665                int32_t srcStart, 
03666                int32_t srcLength)
03667 { return doReplace(start, _length, srcChars, srcStart, srcLength); }
03668 
03669 inline UnicodeString& 
03670 UnicodeString::replace(int32_t start, 
03671                int32_t _length, 
03672                UChar srcChar)
03673 { return doReplace(start, _length, &srcChar, 0, 1); }
03674 
03675 inline UnicodeString&
03676 UnicodeString::replace(int32_t start, 
03677                int32_t _length, 
03678                UChar32 srcChar) {
03679   UChar buffer[U16_MAX_LENGTH];
03680   int32_t count = 0;
03681   UBool isError = FALSE;
03682   U16_APPEND(buffer, count, U16_MAX_LENGTH, srcChar, isError);
03683   return doReplace(start, _length, buffer, 0, count);
03684 }
03685 
03686 inline UnicodeString& 
03687 UnicodeString::replaceBetween(int32_t start, 
03688                   int32_t limit, 
03689                   const UnicodeString& srcText)
03690 { return doReplace(start, limit - start, srcText, 0, srcText.fLength); }
03691 
03692 inline UnicodeString&
03693 UnicodeString::replaceBetween(int32_t start, 
03694                   int32_t limit, 
03695                   const UnicodeString& srcText, 
03696                   int32_t srcStart, 
03697                   int32_t srcLimit)
03698 { return doReplace(start, limit - start, srcText, srcStart, srcLimit - srcStart); }
03699 
03700 inline UnicodeString& 
03701 UnicodeString::findAndReplace(const UnicodeString& oldText,
03702                   const UnicodeString& newText)
03703 { return findAndReplace(0, fLength, oldText, 0, oldText.fLength, 
03704             newText, 0, newText.fLength); }
03705 
03706 inline UnicodeString& 
03707 UnicodeString::findAndReplace(int32_t start,
03708                   int32_t _length,
03709                   const UnicodeString& oldText,
03710                   const UnicodeString& newText)
03711 { return findAndReplace(start, _length, oldText, 0, oldText.fLength, 
03712             newText, 0, newText.fLength); }
03713 
03714 // ============================
03715 // extract
03716 // ============================
03717 inline void
03718 UnicodeString::doExtract(int32_t start,
03719              int32_t _length,
03720              UnicodeString& target) const
03721 { target.replace(0, target.fLength, *this, start, _length); }
03722 
03723 inline void  
03724 UnicodeString::extract(int32_t start, 
03725                int32_t _length, 
03726                UChar *target, 
03727                int32_t targetStart) const
03728 { doExtract(start, _length, target, targetStart); }
03729 
03730 inline void 
03731 UnicodeString::extract(int32_t start,
03732                int32_t _length,
03733                UnicodeString& target) const
03734 { doExtract(start, _length, target); }
03735 
03736 inline int32_t
03737 UnicodeString::extract(int32_t start,
03738                int32_t _length,
03739                char *dst,
03740                const char *codepage) const
03741 
03742 {
03743   // This dstSize value will be checked explicitly
03744   return extract(start, _length, dst, dst!=0 ? 0xffffffff : 0, codepage);
03745 }
03746 
03747 inline void  
03748 UnicodeString::extractBetween(int32_t start, 
03749                   int32_t limit, 
03750                   UChar *dst, 
03751                   int32_t dstStart) const
03752 { doExtract(start, limit - start, dst, dstStart); }
03753 
03754 inline UChar
03755 UnicodeString::doCharAt(int32_t offset) const
03756 {
03757   if((uint32_t)offset < (uint32_t)fLength) {
03758     return fArray[offset];
03759   } else {
03760     return kInvalidUChar;
03761   }
03762 }
03763 
03764 inline UChar
03765 UnicodeString::charAt(int32_t offset) const
03766 { return doCharAt(offset); }
03767 
03768 inline UChar
03769 UnicodeString::operator[] (int32_t offset) const
03770 { return doCharAt(offset); }
03771 
03772 inline UChar32
03773 UnicodeString::char32At(int32_t offset) const
03774 {
03775   if((uint32_t)offset < (uint32_t)fLength) {
03776     UChar32 c;
03777     U16_GET(fArray, 0, offset, fLength, c);
03778     return c;
03779   } else {
03780     return kInvalidUChar;
03781   }
03782 }
03783 
03784 inline int32_t
03785 UnicodeString::getChar32Start(int32_t offset) const {
03786   if((uint32_t)offset < (uint32_t)fLength) {
03787     U16_SET_CP_START(fArray, 0, offset);
03788     return offset;
03789   } else {
03790     return 0;
03791   }
03792 }
03793 
03794 inline int32_t
03795 UnicodeString::getChar32Limit(int32_t offset) const {
03796   if((uint32_t)offset < (uint32_t)fLength) {
03797     U16_SET_CP_LIMIT(fArray, 0, offset, fLength);
03798     return offset;
03799   } else {
03800     return fLength;
03801   }
03802 }
03803 
03804 inline UBool
03805 UnicodeString::isEmpty() const {
03806   return fLength == 0;
03807 }
03808 
03809 //========================================
03810 // Write implementation methods
03811 //========================================
03812 inline const UChar *
03813 UnicodeString::getTerminatedBuffer() {
03814   if(fFlags&(kIsBogus|kOpenGetBuffer)) {
03815     return 0;
03816   } else if(fLength<fCapacity && fArray[fLength]==0) {
03817     return fArray;
03818   } else if(cloneArrayIfNeeded(fLength+1)) {
03819     fArray[fLength]=0;
03820     return fArray;
03821   } else {
03822     return 0;
03823   }
03824 }
03825 
03826 inline UnicodeString& 
03827 UnicodeString::operator= (UChar ch) 
03828 { return doReplace(0, fLength, &ch, 0, 1); }
03829 
03830 inline UnicodeString& 
03831 UnicodeString::operator= (UChar32 ch) 
03832 { return replace(0, fLength, ch); }
03833 
03834 inline UnicodeString& 
03835 UnicodeString::setTo(const UnicodeString& srcText, 
03836              int32_t srcStart, 
03837              int32_t srcLength)
03838 {
03839   unBogus();
03840   return doReplace(0, fLength, srcText, srcStart, srcLength);
03841 }
03842 
03843 inline UnicodeString& 
03844 UnicodeString::setTo(const UnicodeString& srcText, 
03845              int32_t srcStart)
03846 {
03847   unBogus();
03848   srcText.pinIndex(srcStart);
03849   return doReplace(0, fLength, srcText, srcStart, srcText.fLength - srcStart);
03850 }
03851 
03852 inline UnicodeString& 
03853 UnicodeString::setTo(const UnicodeString& srcText)
03854 {
03855   unBogus();
03856   return doReplace(0, fLength, srcText, 0, srcText.fLength);
03857 }
03858 
03859 inline UnicodeString& 
03860 UnicodeString::setTo(const UChar *srcChars,
03861              int32_t srcLength)
03862 {
03863   unBogus();
03864   return doReplace(0, fLength, srcChars, 0, srcLength);
03865 }
03866 
03867 inline UnicodeString& 
03868 UnicodeString::setTo(UChar srcChar)
03869 {
03870   unBogus();
03871   return doReplace(0, fLength, &srcChar, 0, 1);
03872 }
03873 
03874 inline UnicodeString& 
03875 UnicodeString::setTo(UChar32 srcChar)
03876 {
03877   unBogus();
03878   return replace(0, fLength, srcChar);
03879 }
03880 
03881 inline UnicodeString& 
03882 UnicodeString::operator+= (UChar ch)
03883 { return doReplace(fLength, 0, &ch, 0, 1); }
03884 
03885 inline UnicodeString& 
03886 UnicodeString::operator+= (UChar32 ch) {
03887   UChar buffer[U16_MAX_LENGTH];
03888   int32_t _length = 0;
03889   UBool isError = FALSE;
03890   U16_APPEND(buffer, _length, U16_MAX_LENGTH, ch, isError);
03891   return doReplace(fLength, 0, buffer, 0, _length);
03892 }
03893 
03894 inline UnicodeString& 
03895 UnicodeString::operator+= (const UnicodeString& srcText)
03896 { return doReplace(fLength, 0, srcText, 0, srcText.fLength); }
03897 
03898 inline UnicodeString& 
03899 UnicodeString::append(const UnicodeString& srcText, 
03900               int32_t srcStart, 
03901               int32_t srcLength)
03902 { return doReplace(fLength, 0, srcText, srcStart, srcLength); }
03903 
03904 inline UnicodeString& 
03905 UnicodeString::append(const UnicodeString& srcText)
03906 { return doReplace(fLength, 0, srcText, 0, srcText.fLength); }
03907 
03908 inline UnicodeString& 
03909 UnicodeString::append(const UChar *srcChars, 
03910               int32_t srcStart, 
03911               int32_t srcLength)
03912 { return doReplace(fLength, 0, srcChars, srcStart, srcLength); }
03913 
03914 inline UnicodeString& 
03915 UnicodeString::append(const UChar *srcChars,
03916               int32_t srcLength)
03917 { return doReplace(fLength, 0, srcChars, 0, srcLength); }
03918 
03919 inline UnicodeString& 
03920 UnicodeString::append(UChar srcChar)
03921 { return doReplace(fLength, 0, &srcChar, 0, 1); }
03922 
03923 inline UnicodeString& 
03924 UnicodeString::append(UChar32 srcChar) {
03925   UChar buffer[U16_MAX_LENGTH];
03926   int32_t _length = 0;
03927   UBool isError = FALSE;
03928   U16_APPEND(buffer, _length, U16_MAX_LENGTH, srcChar, isError);
03929   return doReplace(fLength, 0, buffer, 0, _length);
03930 }
03931 
03932 inline UnicodeString& 
03933 UnicodeString::insert(int32_t start, 
03934               const UnicodeString& srcText, 
03935               int32_t srcStart, 
03936               int32_t srcLength)
03937 { return doReplace(start, 0, srcText, srcStart, srcLength); }
03938 
03939 inline UnicodeString& 
03940 UnicodeString::insert(int32_t start, 
03941               const UnicodeString& srcText)
03942 { return doReplace(start, 0, srcText, 0, srcText.fLength); }
03943 
03944 inline UnicodeString& 
03945 UnicodeString::insert(int32_t start, 
03946               const UChar *srcChars, 
03947               int32_t srcStart, 
03948               int32_t srcLength)
03949 { return doReplace(start, 0, srcChars, srcStart, srcLength); }
03950 
03951 inline UnicodeString& 
03952 UnicodeString::insert(int32_t start, 
03953               const UChar *srcChars,
03954               int32_t srcLength)
03955 { return doReplace(start, 0, srcChars, 0, srcLength); }
03956 
03957 inline UnicodeString& 
03958 UnicodeString::insert(int32_t start, 
03959               UChar srcChar)
03960 { return doReplace(start, 0, &srcChar, 0, 1); }
03961 
03962 inline UnicodeString& 
03963 UnicodeString::insert(int32_t start, 
03964               UChar32 srcChar)
03965 { return replace(start, 0, srcChar); }
03966 
03967 
03968 inline UnicodeString& 
03969 UnicodeString::remove()
03970 {
03971   // remove() of a bogus string makes the string empty and non-bogus
03972   if(isBogus()) {
03973     unBogus();
03974   } else {
03975     fLength = 0;
03976   }
03977   return *this;
03978 }
03979 
03980 inline UnicodeString& 
03981 UnicodeString::remove(int32_t start, 
03982              int32_t _length)
03983 {
03984   if(start <= 0 && _length == INT32_MAX) {
03985     // remove(guaranteed everything) of a bogus string makes the string empty and non-bogus
03986     return remove();
03987   } else {
03988     return doReplace(start, _length, NULL, 0, 0);
03989   }
03990 }
03991 
03992 inline UnicodeString& 
03993 UnicodeString::removeBetween(int32_t start,
03994                 int32_t limit)
03995 { return doReplace(start, limit - start, NULL, 0, 0); }
03996 
03997 inline UBool 
03998 UnicodeString::truncate(int32_t targetLength)
03999 {
04000   if(isBogus() && targetLength == 0) {
04001     // truncate(0) of a bogus string makes the string empty and non-bogus
04002     unBogus();
04003     return FALSE;
04004   } else if((uint32_t)targetLength < (uint32_t)fLength) {
04005     fLength = targetLength;
04006     return TRUE;
04007   } else {
04008     return FALSE;
04009   }
04010 }
04011 
04012 inline UnicodeString& 
04013 UnicodeString::reverse()
04014 { return doReverse(0, fLength); }
04015 
04016 inline UnicodeString& 
04017 UnicodeString::reverse(int32_t start,
04018                int32_t _length)
04019 { return doReverse(start, _length); }
04020 
04021 U_NAMESPACE_END
04022 
04023 #endif

Generated on Wed May 18 17:29:14 2005 for ICU 2.8 by  doxygen 1.4.2