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

unistr.h

00001 /*
00002 **********************************************************************
00003 *   Copyright (C) 1998-2001, International Business Machines
00004 *   Corporation and others.  All Rights Reserved.
00005 **********************************************************************
00006 *
00007 * File unistr.h
00008 *
00009 * Modification History:
00010 *
00011 *   Date        Name        Description
00012 *   09/25/98    stephen     Creation.
00013 *   11/11/98    stephen     Changed per 11/9 code review.
00014 *   04/20/99    stephen     Overhauled per 4/16 code review.
00015 *   11/18/99    aliu        Made to inherit from Replaceable.  Added method
00016 *                           handleReplaceBetween(); other methods unchanged.
00017 *   06/25/01    grhoten     Remove dependency on iostream.
00018 ******************************************************************************
00019 */
00020 
00021 #ifndef UNISTR_H
00022 #define UNISTR_H
00023 
00024 #include "unicode/utypes.h"
00025 #include "unicode/rep.h"
00026 
00027 struct UConverter;          // unicode/ucnv.h
00028 class  StringThreadTest;
00029 
00030 U_NAMESPACE_BEGIN
00031 
00032 class Locale;               // unicode/locid.h
00033 class UCharReference;
00034 class UnicodeConverter;     // unicode/convert.h
00035 class StringCharacterIterator;
00036 class BreakIterator;        // unicode/brkiter.h
00037 
00038 /* The <iostream> include has been moved to unicode/ustream.h */
00039 
00057 #if U_SIZEOF_WCHAR_T==U_SIZEOF_UCHAR && U_CHARSET_FAMILY==U_ASCII_FAMILY
00058 #   define UNICODE_STRING(cs, length) UnicodeString(TRUE, (const UChar *)L ## cs, length)
00059 #elif U_SIZEOF_UCHAR==1 && U_CHARSET_FAMILY==U_ASCII_FAMILY
00060 #   define UNICODE_STRING(cs, length) UnicodeString(TRUE, (const UChar *)cs, length)
00061 #else
00062 #   define UNICODE_STRING(cs, length) UnicodeString(cs, length, "")
00063 #endif
00064 
00078 #if U_SIZEOF_WCHAR_T==U_SIZEOF_UCHAR && U_CHARSET_FAMILY==U_ASCII_FAMILY
00079 #   define UNICODE_STRING_SIMPLE(cs) UnicodeString((const UChar *)L ## cs)
00080 #elif U_SIZEOF_UCHAR==1 && U_CHARSET_FAMILY==U_ASCII_FAMILY
00081 #   define UNICODE_STRING_SIMPLE(cs) UnicodeString((const UChar *)cs)
00082 #else
00083 #   define UNICODE_STRING_SIMPLE(cs) UnicodeString(cs, "")
00084 #endif
00085 
00145 class U_COMMON_API UnicodeString : public Replaceable
00146 {
00147 public:
00148 
00149   //========================================
00150   // Read-only operations
00151   //========================================
00152 
00153   /* Comparison - bitwise only - for international comparison use collation */
00154 
00162   inline UBool operator== (const UnicodeString& text) const;
00163 
00171   inline UBool operator!= (const UnicodeString& text) const;
00172 
00180   inline UBool operator> (const UnicodeString& text) const;
00181 
00189   inline UBool operator< (const UnicodeString& text) const;
00190 
00198   inline UBool operator>= (const UnicodeString& text) const;
00199 
00207   inline UBool operator<= (const UnicodeString& text) const;
00208 
00220   inline int8_t compare(const UnicodeString& text) const;
00221 
00236   inline int8_t compare(int32_t start,
00237          int32_t length,
00238          const UnicodeString& srcText) const;
00239 
00257    inline int8_t compare(int32_t start,
00258          int32_t length,
00259          const UnicodeString& srcText,
00260          int32_t srcStart,
00261          int32_t srcLength) const;
00262 
00275   inline int8_t compare(const UChar *srcChars,
00276          int32_t srcLength) const;
00277 
00292   inline int8_t compare(int32_t start,
00293          int32_t length,
00294          const UChar *srcChars) const;
00295 
00313   inline int8_t compare(int32_t start,
00314          int32_t length,
00315          const UChar *srcChars,
00316          int32_t srcStart,
00317          int32_t srcLength) const;
00318 
00336   inline int8_t compareBetween(int32_t start,
00337             int32_t limit,
00338             const UnicodeString& srcText,
00339             int32_t srcStart,
00340             int32_t srcLimit) const;
00341 
00359   inline int8_t compareCodePointOrder(const UnicodeString& text) const;
00360 
00380   inline int8_t compareCodePointOrder(int32_t start,
00381                                       int32_t length,
00382                                       const UnicodeString& srcText) const;
00383 
00405    inline int8_t compareCodePointOrder(int32_t start,
00406                                        int32_t length,
00407                                        const UnicodeString& srcText,
00408                                        int32_t srcStart,
00409                                        int32_t srcLength) const;
00410 
00429   inline int8_t compareCodePointOrder(const UChar *srcChars,
00430                                       int32_t srcLength) const;
00431 
00451   inline int8_t compareCodePointOrder(int32_t start,
00452                                       int32_t length,
00453                                       const UChar *srcChars) const;
00454 
00476   inline int8_t compareCodePointOrder(int32_t start,
00477                                       int32_t length,
00478                                       const UChar *srcChars,
00479                                       int32_t srcStart,
00480                                       int32_t srcLength) const;
00481 
00503   inline int8_t compareCodePointOrderBetween(int32_t start,
00504                                              int32_t limit,
00505                                              const UnicodeString& srcText,
00506                                              int32_t srcStart,
00507                                              int32_t srcLimit) const;
00508 
00518   inline int8_t caseCompare(const UnicodeString& text, uint32_t options) const;
00519 
00531   inline int8_t caseCompare(int32_t start,
00532          int32_t length,
00533          const UnicodeString& srcText,
00534          uint32_t options) const;
00535 
00549   inline int8_t caseCompare(int32_t start,
00550          int32_t length,
00551          const UnicodeString& srcText,
00552          int32_t srcStart,
00553          int32_t srcLength,
00554          uint32_t options) const;
00555 
00566   inline int8_t caseCompare(const UChar *srcChars,
00567          int32_t srcLength,
00568          uint32_t options) const;
00569 
00581   inline int8_t caseCompare(int32_t start,
00582          int32_t length,
00583          const UChar *srcChars,
00584          uint32_t options) const;
00585 
00599   inline int8_t caseCompare(int32_t start,
00600          int32_t length,
00601          const UChar *srcChars,
00602          int32_t srcStart,
00603          int32_t srcLength,
00604          uint32_t options) const;
00605 
00619   inline int8_t caseCompareBetween(int32_t start,
00620             int32_t limit,
00621             const UnicodeString& srcText,
00622             int32_t srcStart,
00623             int32_t srcLimit,
00624             uint32_t options) const;
00625 
00633   inline UBool startsWith(const UnicodeString& text) const;
00634 
00645   inline UBool startsWith(const UnicodeString& srcText,
00646             int32_t srcStart,
00647             int32_t srcLength) const;
00648 
00657   inline UBool startsWith(const UChar *srcChars,
00658             int32_t srcLength) const;
00659 
00669   inline UBool startsWith(const UChar *srcChars,
00670             int32_t srcStart,
00671             int32_t srcLength) const;
00672 
00680   inline UBool endsWith(const UnicodeString& text) const;
00681 
00692   inline UBool endsWith(const UnicodeString& srcText,
00693           int32_t srcStart,
00694           int32_t srcLength) const;
00695 
00704   inline UBool endsWith(const UChar *srcChars,
00705           int32_t srcLength) const;
00706 
00717   inline UBool endsWith(const UChar *srcChars,
00718           int32_t srcStart,
00719           int32_t srcLength) const;
00720 
00721 
00722   /* Searching - bitwise only */
00723 
00732   inline int32_t indexOf(const UnicodeString& text) const;
00733 
00743   inline int32_t indexOf(const UnicodeString& text,
00744               int32_t start) const;
00745 
00757   inline int32_t indexOf(const UnicodeString& text,
00758               int32_t start,
00759               int32_t length) const;
00760 
00777   inline int32_t indexOf(const UnicodeString& srcText,
00778               int32_t srcStart,
00779               int32_t srcLength,
00780               int32_t start,
00781               int32_t length) const;
00782 
00794   inline int32_t indexOf(const UChar *srcChars,
00795               int32_t srcLength,
00796               int32_t start) const;
00797 
00810   inline int32_t indexOf(const UChar *srcChars,
00811               int32_t srcLength,
00812               int32_t start,
00813               int32_t length) const;
00814  
00831   int32_t indexOf(const UChar *srcChars,
00832               int32_t srcStart,
00833               int32_t srcLength,
00834               int32_t start,
00835               int32_t length) const;
00836 
00844   inline int32_t indexOf(UChar c) const;
00845 
00867   inline int32_t indexOf(UChar32 c) const;
00868 
00877   inline int32_t indexOf(UChar c,
00878               int32_t start) const;
00879 
00902   inline int32_t indexOf(UChar32 c,
00903               int32_t start) const;
00904 
00915   inline int32_t indexOf(UChar c,
00916               int32_t start,
00917               int32_t length) const;
00918 
00943   inline int32_t indexOf(UChar32 c,
00944               int32_t start,
00945               int32_t length) const;
00946 
00955   inline int32_t lastIndexOf(const UnicodeString& text) const;
00956 
00966   inline int32_t lastIndexOf(const UnicodeString& text,
00967               int32_t start) const;
00968 
00980   inline int32_t lastIndexOf(const UnicodeString& text,
00981               int32_t start,
00982               int32_t length) const;
00983 
01000   inline int32_t lastIndexOf(const UnicodeString& srcText,
01001               int32_t srcStart,
01002               int32_t srcLength,
01003               int32_t start,
01004               int32_t length) const;
01005 
01016   inline int32_t lastIndexOf(const UChar *srcChars,
01017               int32_t srcLength,
01018               int32_t start) const;
01019 
01032   inline int32_t lastIndexOf(const UChar *srcChars,
01033               int32_t srcLength,
01034               int32_t start,
01035               int32_t length) const;
01036  
01053   int32_t lastIndexOf(const UChar *srcChars,
01054               int32_t srcStart,
01055               int32_t srcLength,
01056               int32_t start,
01057               int32_t length) const;
01058 
01066   inline int32_t lastIndexOf(UChar c) const;
01067 
01089   inline int32_t lastIndexOf(UChar32 c) const;
01090 
01099   inline int32_t lastIndexOf(UChar c,
01100               int32_t start) const;
01101 
01124   inline int32_t lastIndexOf(UChar32 c,
01125               int32_t start) const;
01126 
01137   inline int32_t lastIndexOf(UChar c,
01138               int32_t start,
01139               int32_t length) const;
01140 
01165   inline int32_t lastIndexOf(UChar32 c,
01166               int32_t start,
01167               int32_t length) const;
01168 
01169 
01170   /* Character access */
01171 
01178   inline UChar charAt(int32_t offset) const;
01179 
01186   inline UChar operator [] (int32_t offset) const;
01187 
01197   inline UChar32 char32At(int32_t offset) const;
01198 
01213   inline int32_t getChar32Start(int32_t offset) const;
01214 
01235   inline int32_t getCharStart(int32_t offset) const;
01236 
01252   inline int32_t getChar32Limit(int32_t offset) const;
01253 
01275   inline int32_t getCharLimit(int32_t offset) const;
01276 
01318   int32_t moveIndex32(int32_t index, int32_t delta) const;
01319 
01320   /* Substring extraction */
01321 
01337   inline void extract(int32_t start, 
01338            int32_t length, 
01339            UChar *dst, 
01340            int32_t dstStart = 0) const;
01341 
01363   int32_t
01364   extract(UChar *dest, int32_t destCapacity,
01365           UErrorCode &errorCode) const;
01366 
01377   inline void extract(int32_t start,
01378            int32_t length,
01379            UnicodeString& target) const;
01380 
01392   inline void extractBetween(int32_t start, 
01393               int32_t limit, 
01394               UChar *dst, 
01395               int32_t dstStart = 0) const;
01396 
01406   virtual void extractBetween(int32_t start,
01407               int32_t limit,
01408               UnicodeString& target) const;
01409 
01430   inline int32_t extract(int32_t start,
01431                  int32_t startLength,
01432                  char *target,
01433                  const char *codepage = 0) const;
01434 
01459   int32_t extract(int32_t start,
01460            int32_t startLength,
01461            char *target,
01462            uint32_t targetLength,
01463            const char *codepage = 0) const;
01464 
01482   int32_t extract(char *dest, int32_t destCapacity,
01483                   UConverter *cnv,
01484                   UErrorCode &errorCode) const;
01485 
01486   /* Length operations */
01487 
01494   inline int32_t  length(void) const;
01495 
01508   int32_t
01509   countChar32(int32_t start=0, int32_t length=0x7fffffff) const;
01510 
01516   inline UBool isEmpty(void) const;
01517 
01527   inline UBool empty(void) const;
01528 
01538   inline int32_t getCapacity(void) const;
01539 
01540   /* Other operations */
01541 
01547   inline int32_t hashCode(void) const;
01548 
01555   inline UBool isBogus(void) const;
01556 
01557 
01558   //========================================
01559   // Write operations
01560   //========================================
01561 
01562   /* Assignment operations */
01563 
01571    UnicodeString& operator= (const UnicodeString& srcText);
01572 
01580   inline UnicodeString& operator= (UChar ch);
01581 
01589   inline UnicodeString& operator= (UChar32 ch);
01590 
01604   inline UnicodeString& setTo(const UnicodeString& srcText, 
01605                int32_t srcStart, 
01606                int32_t srcLength);
01607 
01616   inline UnicodeString& setTo(const UnicodeString& srcText);
01617 
01626   inline UnicodeString& setTo(const UChar *srcChars,
01627                int32_t srcLength);
01628 
01637   UnicodeString& setTo(UChar srcChar);
01638 
01647   UnicodeString& setTo(UChar32 srcChar);
01648 
01668   UnicodeString &setTo(UBool isTerminated,
01669                        const UChar *text,
01670                        int32_t textLength);
01671 
01690   UnicodeString &setTo(UChar *buffer,
01691                        int32_t buffLength,
01692                        int32_t buffCapacity);
01693 
01715   void setToBogus();
01716 
01724   UnicodeString& setCharAt(int32_t offset, 
01725                UChar ch);
01726 
01727 
01728   /* Append operations */
01729 
01737  inline  UnicodeString& operator+= (UChar ch);
01738 
01746  inline  UnicodeString& operator+= (UChar32 ch);
01747 
01756   inline UnicodeString& operator+= (const UnicodeString& srcText);
01757 
01772   inline UnicodeString& append(const UnicodeString& srcText, 
01773             int32_t srcStart, 
01774             int32_t srcLength);
01775 
01783   inline UnicodeString& append(const UnicodeString& srcText);
01784 
01798   inline UnicodeString& append(const UChar *srcChars, 
01799             int32_t srcStart, 
01800             int32_t srcLength);
01801 
01810   inline UnicodeString& append(const UChar *srcChars,
01811             int32_t srcLength);
01812 
01819   inline UnicodeString& append(UChar srcChar);
01820 
01827   inline UnicodeString& append(UChar32 srcChar);
01828 
01829 
01830   /* Insert operations */
01831 
01845   inline UnicodeString& insert(int32_t start, 
01846             const UnicodeString& srcText, 
01847             int32_t srcStart, 
01848             int32_t srcLength);
01849 
01858   inline UnicodeString& insert(int32_t start, 
01859             const UnicodeString& srcText);
01860 
01874   inline UnicodeString& insert(int32_t start, 
01875             const UChar *srcChars, 
01876             int32_t srcStart, 
01877             int32_t srcLength);
01878 
01888   inline UnicodeString& insert(int32_t start, 
01889             const UChar *srcChars,
01890             int32_t srcLength);
01891 
01900   inline UnicodeString& insert(int32_t start, 
01901             UChar srcChar);
01902 
01911   inline UnicodeString& insert(int32_t start, 
01912             UChar32 srcChar);
01913 
01914 
01915   /* Replace operations */
01916 
01934   UnicodeString& replace(int32_t start, 
01935              int32_t length, 
01936              const UnicodeString& srcText, 
01937              int32_t srcStart, 
01938              int32_t srcLength);
01939 
01952   UnicodeString& replace(int32_t start, 
01953              int32_t length, 
01954              const UnicodeString& srcText);
01955 
01973   UnicodeString& replace(int32_t start, 
01974              int32_t length, 
01975              const UChar *srcChars, 
01976              int32_t srcStart, 
01977              int32_t srcLength);
01978 
01991   inline UnicodeString& replace(int32_t start, 
01992              int32_t length, 
01993              const UChar *srcChars,
01994              int32_t srcLength);
01995 
02007   inline UnicodeString& replace(int32_t start, 
02008              int32_t length, 
02009              UChar srcChar);
02010 
02022   inline UnicodeString& replace(int32_t start, 
02023              int32_t length, 
02024              UChar32 srcChar);
02025 
02035   inline UnicodeString& replaceBetween(int32_t start, 
02036                 int32_t limit, 
02037                 const UnicodeString& srcText);
02038 
02053   inline UnicodeString& replaceBetween(int32_t start, 
02054                 int32_t limit, 
02055                 const UnicodeString& srcText, 
02056                 int32_t srcStart, 
02057                 int32_t srcLimit);
02058 
02069   virtual void handleReplaceBetween(int32_t start,
02070                                     int32_t limit,
02071                                     const UnicodeString& text);
02072 
02088   virtual void copy(int32_t start, int32_t limit, int32_t dest);
02089 
02090   /* Search and replace operations */
02091 
02100   inline UnicodeString& findAndReplace(const UnicodeString& oldText,
02101                 const UnicodeString& newText);
02102 
02114   inline UnicodeString& findAndReplace(int32_t start,
02115                 int32_t length,
02116                 const UnicodeString& oldText,
02117                 const UnicodeString& newText);
02118 
02136   UnicodeString& findAndReplace(int32_t start,
02137                 int32_t length,
02138                 const UnicodeString& oldText,
02139                 int32_t oldStart,
02140                 int32_t oldLength,
02141                 const UnicodeString& newText,
02142                 int32_t newStart,
02143                 int32_t newLength);
02144 
02145 
02146   /* Remove operations */
02147 
02153   inline UnicodeString& remove(void);
02154 
02163   inline UnicodeString& remove(int32_t start, 
02164                                int32_t length = (int32_t)INT32_MAX);
02165 
02174   inline UnicodeString& removeBetween(int32_t start,
02175                                       int32_t limit = (int32_t)INT32_MAX);
02176 
02177 
02178   /* Length operations */
02179 
02191   UBool padLeading(int32_t targetLength,
02192                     UChar padChar = 0x0020);
02193 
02205   UBool padTrailing(int32_t targetLength,
02206                      UChar padChar = 0x0020);
02207 
02214   inline UBool truncate(int32_t targetLength);
02215 
02221   UnicodeString& trim(void);
02222 
02223 
02224   /* Miscellaneous operations */
02225 
02231   inline UnicodeString& reverse(void);
02232 
02241   inline UnicodeString& reverse(int32_t start,
02242              int32_t length);
02243 
02250   UnicodeString& toUpper(void);
02251 
02259   UnicodeString& toUpper(const Locale& locale);
02260 
02267   UnicodeString& toLower(void);
02268 
02276   UnicodeString& toLower(const Locale& locale);
02277 
02303   UnicodeString &toTitle(BreakIterator *titleIter);
02304 
02331   UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale);
02332 
02344   UnicodeString &foldCase(uint32_t options=0 /*U_FOLD_CASE_DEFAULT*/);
02345 
02346   //========================================
02347   // Access to the internal buffer
02348   //========================================
02349 
02389   UChar *getBuffer(int32_t minCapacity);
02390 
02411   void releaseBuffer(int32_t newLength=-1);
02412 
02441   inline const UChar *getBuffer() const;
02442 
02443   //========================================
02444   // Constructors
02445   //========================================
02446 
02450   UnicodeString();
02451 
02463   UnicodeString(int32_t capacity, UChar32 c, int32_t count);
02464 
02470   UnicodeString(UChar ch);
02471 
02477   UnicodeString(UChar32 ch);
02478 
02485   UnicodeString(const UChar *text);
02486 
02494   UnicodeString(const UChar *text,
02495         int32_t textLength);
02496 
02516   UnicodeString(UBool isTerminated,
02517                 const UChar *text,
02518                 int32_t textLength);
02519 
02538   UnicodeString(UChar *buffer, int32_t buffLength, int32_t buffCapacity);
02539 
02551   UnicodeString(const char *codepageData,
02552         const char *codepage = 0);
02553 
02566   UnicodeString(const char *codepageData,
02567         int32_t dataLength,
02568         const char *codepage = 0);
02569 
02591   UnicodeString(
02592         const char *src, int32_t srcLength,
02593         UConverter *cnv,
02594         UErrorCode &errorCode);
02595 
02596 
02602   UnicodeString(const UnicodeString& that);
02603 
02607   ~UnicodeString();
02608 
02609 
02610   /* Miscellaneous operations */
02611 
02634   int32_t numDisplayCells(int32_t start = 0,
02635               int32_t length = INT32_MAX,
02636               UBool asian = TRUE) const;
02637 
02645   UCharReference operator[] (int32_t pos);
02646 
02680   UnicodeString unescape() const;
02681 
02701   UChar32 unescapeAt(int32_t &offset) const;
02702 
02703   //========================================
02704   // Implementation methods
02705   //========================================
02706 
02707 protected:
02711   virtual int32_t getLength() const;
02712 
02717   virtual UChar getCharAt(int32_t offset) const;
02718 
02723   virtual UChar32 getChar32At(int32_t offset) const;
02724 
02725 private:
02726 
02727   inline int8_t
02728   doCompare(int32_t start,
02729            int32_t length,
02730            const UnicodeString& srcText,
02731            int32_t srcStart,
02732            int32_t srcLength) const;
02733 
02734   int8_t doCompare(int32_t start,
02735            int32_t length,
02736            const UChar *srcChars,
02737            int32_t srcStart,
02738            int32_t srcLength) const;
02739 
02740   inline int8_t
02741   doCompareCodePointOrder(int32_t start,
02742                           int32_t length,
02743                           const UnicodeString& srcText,
02744                           int32_t srcStart,
02745                           int32_t srcLength) const;
02746 
02747   int8_t doCompareCodePointOrder(int32_t start,
02748                                  int32_t length,
02749                                  const UChar *srcChars,
02750                                  int32_t srcStart,
02751                                  int32_t srcLength) const;
02752 
02753   inline int8_t
02754   doCaseCompare(int32_t start,
02755                 int32_t length,
02756                 const UnicodeString &srcText,
02757                 int32_t srcStart,
02758                 int32_t srcLength,
02759                 uint32_t options) const;
02760 
02761   int8_t
02762   doCaseCompare(int32_t start,
02763                 int32_t length,
02764                 const UChar *srcChars,
02765                 int32_t srcStart,
02766                 int32_t srcLength,
02767                 uint32_t options) const;
02768 
02769   int32_t doIndexOf(UChar c,
02770             int32_t start,
02771             int32_t length) const;
02772 
02773   // only for c>=0xd800
02774   int32_t doIndexOf(UChar32 c,
02775                         int32_t start,
02776                         int32_t length) const;
02777 
02778   int32_t doLastIndexOf(UChar c,
02779                 int32_t start,
02780                 int32_t length) const;
02781 
02782   // only for c>=0xd800
02783   int32_t doLastIndexOf(UChar32 c,
02784                             int32_t start,
02785                             int32_t length) const;
02786 
02787   void doExtract(int32_t start, 
02788          int32_t length, 
02789          UChar *dst, 
02790          int32_t dstStart) const;
02791 
02792   inline void doExtract(int32_t start,
02793          int32_t length,
02794          UnicodeString& target) const;
02795 
02796   inline UChar doCharAt(int32_t offset)  const;
02797 
02798   UnicodeString& doReplace(int32_t start, 
02799                int32_t length, 
02800                const UnicodeString& srcText, 
02801                int32_t srcStart, 
02802                int32_t srcLength);
02803 
02804   UnicodeString& doReplace(int32_t start, 
02805                int32_t length, 
02806                const UChar *srcChars, 
02807                int32_t srcStart, 
02808                int32_t srcLength);
02809 
02810   UnicodeString& doReverse(int32_t start,
02811                int32_t length);
02812 
02813   // calculate hash code
02814   int32_t doHashCode(void) const;
02815 
02816   // get pointer to start of array
02817   inline UChar* getArrayStart(void);
02818   inline const UChar* getArrayStart(void) const;
02819 
02820   // allocate the array; result may be fStackBuffer
02821   // sets refCount to 1 if appropriate
02822   // sets fArray, fCapacity, and fFlags
02823   // returns boolean for success or failure
02824   UBool allocate(int32_t capacity);
02825 
02826   // release the array if owned
02827   void releaseArray(void);
02828 
02829   // Pin start and limit to acceptable values.
02830   inline void pinIndices(int32_t& start,
02831                          int32_t& length) const;
02832 
02833   /* Internal extract() using UConverter. */
02834   int32_t doExtract(int32_t start, int32_t length,
02835                     char *dest, int32_t destCapacity,
02836                     UConverter *cnv,
02837                     UErrorCode &errorCode) const;
02838 
02839   /*
02840    * Real constructor for converting from codepage data.
02841    * It assumes that it is called with !fRefCounted.
02842    *
02843    * If <code>codepage==0</code>, then the default converter
02844    * is used for the platform encoding.
02845    * If <code>codepage</code> is an empty string (<code>""</code>),
02846    * then a simple conversion is performed on the codepage-invariant
02847    * subset ("invariant characters") of the platform encoding. See utypes.h.
02848    */
02849   void doCodepageCreate(const char *codepageData,
02850                         int32_t dataLength,
02851                         const char *codepage);
02852 
02853   /*
02854    * Worker function for creating a UnicodeString from
02855    * a codepage string using a UConverter.
02856    */
02857   void
02858   doCodepageCreate(const char *codepageData,
02859                    int32_t dataLength,
02860                    UConverter *converter,
02861                    UErrorCode &status);
02862   /*
02863    * This function is called when write access to the array
02864    * is necessary.
02865    *
02866    * We need to make a copy of the array if
02867    * the buffer is read-only, or
02868    * the buffer is refCounted (shared), and refCount>1, or
02869    * the buffer is too small.
02870    *
02871    * Return FALSE if memory could not be allocated.
02872    */
02873   UBool cloneArrayIfNeeded(int32_t newCapacity = -1,
02874                             int32_t growCapacity = -1,
02875                             UBool doCopyArray = TRUE,
02876                             int32_t **pBufferToDelete = 0,
02877                             UBool forceClone = FALSE);
02878 
02879   // common function for case mappings
02880   UnicodeString &
02881   caseMap(BreakIterator *titleIter,
02882           const Locale& locale,
02883           uint32_t options,
02884           int32_t toWhichCase);
02885 
02886   // ref counting
02887   void addRef(void);
02888   int32_t removeRef(void);
02889   int32_t refCount(void) const;
02890   int32_t setRefCount(int32_t count);
02891 
02892   // constants
02893   enum {
02894 #if UTF_SIZE==8
02895     US_STACKBUF_SIZE=14, // Size of stack buffer for small strings
02896 #elif UTF_SIZE==16
02897     US_STACKBUF_SIZE=7, // Size of stack buffer for small strings
02898 #else // UTF_SIZE==32
02899     US_STACKBUF_SIZE=3, // Size of stack buffer for small strings
02900 #endif
02901     kInvalidUChar=0xffff, // invalid UChar index
02902     kGrowSize=128, // grow size for this buffer
02903     kInvalidHashCode=0, // invalid hash code
02904     kEmptyHashCode=1, // hash code for empty string
02905 
02906     // bit flag values for fFlags
02907     kIsBogus=1,         // this string is bogus, i.e., not valid
02908     kUsingStackBuffer=2,// fArray==fStackBuffer
02909     kRefCounted=4,      // there is a refCount field before the characters in fArray
02910     kBufferIsReadonly=8,// do not write to this buffer
02911     kOpenGetBuffer=16,  // getBuffer(minCapacity) was called (is "open"),
02912                         // and releaseBuffer(newLength) must be called
02913 
02914     // combined values for convenience
02915     kShortString=kUsingStackBuffer,
02916     kLongString=kRefCounted,
02917     kReadonlyAlias=kBufferIsReadonly,
02918     kWritableAlias=0
02919   };
02920 
02921   friend class UnicodeConverter;
02922 
02923   friend class StringCharacterIterator;
02924   friend class StringThreadTest;
02925 
02926   /*
02927    * The following are all the class fields that are stored
02928    * in each UnicodeString object.
02929    * Note that UnicodeString has virtual functions,
02930    * therefore there is an implicit vtable pointer
02931    * as the first real field.
02932    * The fields should be aligned such that no padding is
02933    * necessary, mostly by having larger types first.
02934    * On 32-bit machines, the size should be 32 bytes,
02935    * on 64-bit machines (8-byte pointers), it should be 40 bytes.
02936    */
02937   // (implicit) *vtable;
02938   int32_t   fLength;        // number of characters in fArray
02939   int32_t   fCapacity;      // sizeof fArray
02940   UChar     *fArray;        // the Unicode data
02941   uint16_t  fFlags;         // bit flags: see constants above
02942 #if UTF_SIZE==32
02943   uint16_t  fPadding;       // padding to align the fStackBuffer for UTF-32
02944 #endif
02945   UChar     fStackBuffer [ US_STACKBUF_SIZE ]; // buffer for small strings
02946 };
02947 
02948 U_NAMESPACE_END
02949 
02950 //========================================
02951 // Array copying
02952 //========================================
02953 // Copy an array of UnicodeString OBJECTS (not pointers).
02954 inline void 
02955 uprv_arrayCopy(const U_NAMESPACE_QUALIFIER UnicodeString *src, U_NAMESPACE_QUALIFIER UnicodeString *dst, int32_t count)
02956 { while(count-- > 0) *dst++ = *src++; }
02957 
02958 inline void 
02959 uprv_arrayCopy(const U_NAMESPACE_QUALIFIER UnicodeString *src, int32_t srcStart, 
02960         U_NAMESPACE_QUALIFIER UnicodeString *dst, int32_t dstStart, int32_t count)
02961 { uprv_arrayCopy(src+srcStart, dst+dstStart, count); }
02962 
02963 U_NAMESPACE_BEGIN
02964 //========================================
02965 // Inline members
02966 //========================================
02967 
02968 //========================================
02969 // Read-only alias methods
02970 //========================================
02971 inline UBool
02972 UnicodeString::operator== (const UnicodeString& text) const
02973 {
02974   if(isBogus()) {
02975     return text.isBogus();
02976   } else {
02977     return
02978       !text.isBogus() &&
02979       fLength == text.fLength &&
02980       doCompare(0, fLength, text, 0, text.fLength) == 0;
02981   }
02982 }
02983 
02984 inline UBool
02985 UnicodeString::operator!= (const UnicodeString& text) const
02986 { return (! operator==(text)); }
02987 
02988 inline UBool
02989 UnicodeString::operator> (const UnicodeString& text) const
02990 { return doCompare(0, fLength, text, 0, text.fLength) == 1; }
02991 
02992 inline UBool
02993 UnicodeString::operator< (const UnicodeString& text) const
02994 { return doCompare(0, fLength, text, 0, text.fLength) == -1; }
02995 
02996 inline UBool
02997 UnicodeString::operator>= (const UnicodeString& text) const
02998 { return doCompare(0, fLength, text, 0, text.fLength) != -1; }
02999 
03000 inline UBool
03001 UnicodeString::operator<= (const UnicodeString& text) const
03002 { return doCompare(0, fLength, text, 0, text.fLength) != 1; }
03003 
03004 inline int8_t 
03005 UnicodeString::compare(const UnicodeString& text) const
03006 { return doCompare(0, fLength, text, 0, text.fLength); }
03007 
03008 inline int8_t 
03009 UnicodeString::compare(int32_t start,
03010                int32_t length,
03011                const UnicodeString& srcText) const
03012 { return doCompare(start, length, srcText, 0, srcText.fLength); }
03013 
03014 inline int8_t 
03015 UnicodeString::compare(const UChar *srcChars,
03016                int32_t srcLength) const
03017 { return doCompare(0, fLength, srcChars, 0, srcLength); }
03018 
03019 inline int8_t 
03020 UnicodeString::compare(int32_t start,
03021                int32_t length,
03022                const UnicodeString& srcText,
03023                int32_t srcStart,
03024                int32_t srcLength) const
03025 { return doCompare(start, length, srcText, srcStart, srcLength); }
03026 
03027 inline int8_t
03028 UnicodeString::compare(int32_t start,
03029                int32_t length,
03030                const UChar *srcChars) const
03031 { return doCompare(start, length, srcChars, 0, length); }
03032 
03033 inline int8_t 
03034 UnicodeString::compare(int32_t start,
03035                int32_t length,
03036                const UChar *srcChars,
03037                int32_t srcStart,
03038                int32_t srcLength) const
03039 { return doCompare(start, length, srcChars, srcStart, srcLength); }
03040 
03041 inline int8_t
03042 UnicodeString::compareBetween(int32_t start,
03043                   int32_t limit,
03044                   const UnicodeString& srcText,
03045                   int32_t srcStart,
03046                   int32_t srcLimit) const
03047 { return doCompare(start, limit - start, 
03048            srcText, srcStart, srcLimit - srcStart); }
03049 
03050 inline int8_t
03051 UnicodeString::doCompare(int32_t start,
03052               int32_t length,
03053               const UnicodeString& srcText,
03054               int32_t srcStart,
03055               int32_t srcLength) const
03056 {
03057   const UChar *srcChars;
03058   if(!srcText.isBogus()) {
03059     srcText.pinIndices(srcStart, srcLength);
03060     srcChars=srcText.getArrayStart();
03061   } else {
03062     srcChars=0;
03063   }
03064   return doCompare(start, length, srcChars, srcStart, srcLength);
03065 }
03066 
03067 inline int8_t 
03068 UnicodeString::compareCodePointOrder(const UnicodeString& text) const
03069 { return doCompareCodePointOrder(0, fLength, text, 0, text.fLength); }
03070 
03071 inline int8_t 
03072 UnicodeString::compareCodePointOrder(int32_t start,
03073                                      int32_t length,
03074                                      const UnicodeString& srcText) const
03075 { return doCompareCodePointOrder(start, length, srcText, 0, srcText.fLength); }
03076 
03077 inline int8_t 
03078 UnicodeString::compareCodePointOrder(const UChar *srcChars,
03079                                      int32_t srcLength) const
03080 { return doCompareCodePointOrder(0, fLength, srcChars, 0, srcLength); }
03081 
03082 inline int8_t 
03083 UnicodeString::compareCodePointOrder(int32_t start,
03084                                      int32_t length,
03085                                      const UnicodeString& srcText,
03086                                      int32_t srcStart,
03087                                      int32_t srcLength) const
03088 { return doCompareCodePointOrder(start, length, srcText, srcStart, srcLength); }
03089 
03090 inline int8_t
03091 UnicodeString::compareCodePointOrder(int32_t start,
03092                                      int32_t length,
03093                                      const UChar *srcChars) const
03094 { return doCompareCodePointOrder(start, length, srcChars, 0, length); }
03095 
03096 inline int8_t 
03097 UnicodeString::compareCodePointOrder(int32_t start,
03098                                      int32_t length,
03099                                      const UChar *srcChars,
03100                                      int32_t srcStart,
03101                                      int32_t srcLength) const
03102 { return doCompareCodePointOrder(start, length, srcChars, srcStart, srcLength); }
03103 
03104 inline int8_t
03105 UnicodeString::compareCodePointOrderBetween(int32_t start,
03106                                             int32_t limit,
03107                                             const UnicodeString& srcText,
03108                                             int32_t srcStart,
03109                                             int32_t srcLimit) const
03110 { return doCompareCodePointOrder(start, limit - start, 
03111            srcText, srcStart, srcLimit - srcStart); }
03112 
03113 inline int8_t
03114 UnicodeString::doCompareCodePointOrder(int32_t start,
03115                                        int32_t length,
03116                                        const UnicodeString& srcText,
03117                                        int32_t srcStart,
03118                                        int32_t srcLength) const
03119 {
03120   const UChar *srcChars;
03121   if(!srcText.isBogus()) {
03122     srcText.pinIndices(srcStart, srcLength);
03123     srcChars=srcText.getArrayStart();
03124   } else {
03125     srcChars=0;
03126   }
03127   return doCompareCodePointOrder(start, length, srcChars, srcStart, srcLength);
03128 }
03129 
03130 inline int8_t 
03131 UnicodeString::caseCompare(const UnicodeString &text, uint32_t options) const {
03132   return doCaseCompare(0, fLength, text, 0, text.fLength, options);
03133 }
03134 
03135 inline int8_t 
03136 UnicodeString::caseCompare(int32_t start,
03137                            int32_t length,
03138                            const UnicodeString &srcText,
03139                            uint32_t options) const {
03140   return doCaseCompare(start, length, srcText, 0, srcText.fLength, options);
03141 }
03142 
03143 inline int8_t 
03144 UnicodeString::caseCompare(const UChar *srcChars,
03145                            int32_t srcLength,
03146                            uint32_t options) const {
03147   return doCaseCompare(0, fLength, srcChars, 0, srcLength, options);
03148 }
03149 
03150 inline int8_t 
03151 UnicodeString::caseCompare(int32_t start,
03152                            int32_t length,
03153                            const UnicodeString &srcText,
03154                            int32_t srcStart,
03155                            int32_t srcLength,
03156                            uint32_t options) const {
03157   return doCaseCompare(start, length, srcText, srcStart, srcLength, options);
03158 }
03159 
03160 inline int8_t
03161 UnicodeString::caseCompare(int32_t start,
03162                            int32_t length,
03163                            const UChar *srcChars,
03164                            uint32_t options) const {
03165   return doCaseCompare(start, length, srcChars, 0, length, options);
03166 }
03167 
03168 inline int8_t 
03169 UnicodeString::caseCompare(int32_t start,
03170                            int32_t length,
03171                            const UChar *srcChars,
03172                            int32_t srcStart,
03173                            int32_t srcLength,
03174                            uint32_t options) const {
03175   return doCaseCompare(start, length, srcChars, srcStart, srcLength, options);
03176 }
03177 
03178 inline int8_t
03179 UnicodeString::caseCompareBetween(int32_t start,
03180                                   int32_t limit,
03181                                   const UnicodeString &srcText,
03182                                   int32_t srcStart,
03183                                   int32_t srcLimit,
03184                                   uint32_t options) const {
03185   return doCaseCompare(start, limit - start, srcText, srcStart, srcLimit - srcStart, options);
03186 }
03187 
03188 inline int8_t
03189 UnicodeString::doCaseCompare(int32_t start,
03190                              int32_t length,
03191                              const UnicodeString &srcText,
03192                              int32_t srcStart,
03193                              int32_t srcLength,
03194                              uint32_t options) const
03195 {
03196   const UChar *srcChars;
03197   if(!srcText.isBogus()) {
03198     srcText.pinIndices(srcStart, srcLength);
03199     srcChars=srcText.getArrayStart();
03200   } else {
03201     srcChars=0;
03202   }
03203   return doCaseCompare(start, length, srcChars, srcStart, srcLength, options);
03204 }
03205 
03206 inline int32_t 
03207 UnicodeString::indexOf(const UnicodeString& text) const
03208 { return indexOf(text, 0, text.fLength, 0, fLength); }
03209 
03210 inline int32_t 
03211 UnicodeString::indexOf(const UnicodeString& text,
03212                int32_t start) const
03213 { return indexOf(text, 0, text.fLength, start, fLength - start); }
03214 
03215 inline int32_t 
03216 UnicodeString::indexOf(const UnicodeString& text,
03217                int32_t start,
03218                int32_t length) const
03219 { return indexOf(text, 0, text.fLength, start, length); }
03220 
03221 inline int32_t 
03222 UnicodeString::indexOf(const UnicodeString& srcText,
03223                int32_t srcStart,
03224                int32_t srcLength,
03225                int32_t start,
03226                int32_t length) const
03227 {
03228   if(!srcText.isBogus()) {
03229     srcText.pinIndices(srcStart, srcLength);
03230     if(srcLength > 0) {
03231       return indexOf(srcText.getArrayStart(), srcStart, srcLength, start, length);
03232     }
03233   }
03234   return -1;
03235 }
03236 
03237 inline int32_t 
03238 UnicodeString::indexOf(const UChar *srcChars,
03239                int32_t srcLength,
03240                int32_t start) const
03241 { return indexOf(srcChars, 0, srcLength, start, fLength - start); }
03242 
03243 inline int32_t 
03244 UnicodeString::indexOf(const UChar *srcChars,
03245                int32_t srcLength,
03246                int32_t start,
03247                int32_t length) const
03248 { return indexOf(srcChars, 0, srcLength, start, length); }
03249 
03250 inline int32_t 
03251 UnicodeString::indexOf(UChar c) const
03252 { return doIndexOf(c, 0, fLength); }
03253 
03254 inline int32_t 
03255 UnicodeString::indexOf(UChar32 c) const {
03256   return indexOf(c, 0, fLength);
03257 }
03258 
03259 inline int32_t 
03260 UnicodeString::indexOf(UChar c,
03261                int32_t start) const
03262 { return doIndexOf(c, start, fLength - start); }
03263 
03264 inline int32_t 
03265 UnicodeString::indexOf(UChar32 c,
03266                int32_t start) const {
03267   return indexOf(c, start, fLength - start);
03268 }
03269 
03270 inline int32_t 
03271 UnicodeString::indexOf(UChar c,
03272                int32_t start,
03273                int32_t length) const
03274 { return doIndexOf(c, start, length); }
03275 
03276 inline int32_t 
03277 UnicodeString::indexOf(UChar32 c,
03278                int32_t start,
03279                int32_t length) const {
03280   if((uint32_t)c<0xd800) {
03281     return doIndexOf((UChar)c, start, length);
03282   } else {
03283     return doIndexOf(c, start, length);
03284   }
03285 }
03286 
03287 inline int32_t 
03288 UnicodeString::lastIndexOf(const UnicodeString& text) const
03289 { return lastIndexOf(text, 0, text.fLength, 0, fLength); }
03290 
03291 inline int32_t 
03292 UnicodeString::lastIndexOf(const UnicodeString& text,
03293                int32_t start) const
03294 { return lastIndexOf(text, 0, text.fLength, start, fLength - start); }
03295 
03296 inline int32_t 
03297 UnicodeString::lastIndexOf(const UnicodeString& text,
03298                int32_t start,
03299                int32_t length) const
03300 { return lastIndexOf(text, 0, text.fLength, start, length); }
03301 
03302 inline int32_t 
03303 UnicodeString::lastIndexOf(const UnicodeString& srcText,
03304                int32_t srcStart,
03305                int32_t srcLength,
03306                int32_t start,
03307                int32_t length) const
03308 {
03309   if(!srcText.isBogus()) {
03310     srcText.pinIndices(srcStart, srcLength);
03311     if(srcLength > 0) {
03312       return lastIndexOf(srcText.getArrayStart(), srcStart, srcLength, start, length);
03313     }
03314   }
03315   return -1;
03316 }
03317 
03318 inline int32_t 
03319 UnicodeString::lastIndexOf(const UChar *srcChars,
03320                int32_t srcLength,
03321                int32_t start) const
03322 { return lastIndexOf(srcChars, 0, srcLength, start, fLength - start); }
03323 
03324 inline int32_t 
03325 UnicodeString::lastIndexOf(const UChar *srcChars,
03326                int32_t srcLength,
03327                int32_t start,
03328                int32_t length) const
03329 { return lastIndexOf(srcChars, 0, srcLength, start, length); }
03330 
03331 inline int32_t 
03332 UnicodeString::lastIndexOf(UChar c) const
03333 { return doLastIndexOf(c, 0, fLength); }
03334 
03335 inline int32_t 
03336 UnicodeString::lastIndexOf(UChar32 c) const {
03337   return lastIndexOf(c, 0, fLength);
03338 }
03339 
03340 inline int32_t 
03341 UnicodeString::lastIndexOf(UChar c,
03342                int32_t start) const
03343 { return doLastIndexOf(c, start, fLength - start); }
03344 
03345 inline int32_t 
03346 UnicodeString::lastIndexOf(UChar32 c,
03347                int32_t start) const {
03348   return lastIndexOf(c, start, fLength - start);
03349 }
03350 
03351 inline int32_t 
03352 UnicodeString::lastIndexOf(UChar c,
03353                int32_t start,
03354                int32_t length) const
03355 { return doLastIndexOf(c, start, length); }
03356 
03357 inline int32_t 
03358 UnicodeString::lastIndexOf(UChar32 c,
03359                int32_t start,
03360                int32_t length) const {
03361   if((uint32_t)c<0xd800) {
03362     return doLastIndexOf((UChar)c, start, length);
03363   } else {
03364     return doLastIndexOf(c, start, length);
03365   }
03366 }
03367 
03368 inline UBool 
03369 UnicodeString::startsWith(const UnicodeString& text) const
03370 { return compare(0, text.fLength, text, 0, text.fLength) == 0; }
03371 
03372 inline UBool 
03373 UnicodeString::startsWith(const UnicodeString& srcText,
03374               int32_t srcStart,
03375               int32_t srcLength) const
03376 { return doCompare(0, srcLength, srcText, srcStart, srcLength) == 0; }
03377 
03378 inline UBool 
03379 UnicodeString::startsWith(const UChar *srcChars,
03380               int32_t srcLength) const
03381 { return doCompare(0, srcLength, srcChars, 0, srcLength) == 0; }
03382 
03383 inline UBool 
03384 UnicodeString::startsWith(const UChar *srcChars,
03385               int32_t srcStart,
03386               int32_t srcLength) const
03387 { return doCompare(0, srcLength, srcChars, srcStart, srcLength) == 0;}
03388 
03389 inline UBool 
03390 UnicodeString::endsWith(const UnicodeString& text) const
03391 { return doCompare(fLength - text.fLength, text.fLength, 
03392            text, 0, text.fLength) == 0; }
03393 
03394 inline UBool 
03395 UnicodeString::endsWith(const UnicodeString& srcText,
03396             int32_t srcStart,
03397             int32_t srcLength) const
03398 { return doCompare(fLength - srcLength, srcLength, 
03399            srcText, srcStart, srcLength) == 0; }
03400 
03401 inline UBool 
03402 UnicodeString::endsWith(const UChar *srcChars,
03403             int32_t srcLength) const
03404 { return doCompare(fLength - srcLength, srcLength, 
03405            srcChars, 0, srcLength) == 0; }
03406 
03407 inline UBool 
03408 UnicodeString::endsWith(const UChar *srcChars,
03409             int32_t srcStart,
03410             int32_t srcLength) const
03411 { return doCompare(fLength - srcLength, srcLength, 
03412            srcChars, srcStart, srcLength) == 0;}
03413 //========================================
03414 // replace
03415 //========================================
03416 inline UnicodeString& 
03417 UnicodeString::replace(int32_t start, 
03418                int32_t length, 
03419                const UnicodeString& srcText) 
03420 { return doReplace(start, length, srcText, 0, srcText.fLength); }
03421 
03422 inline UnicodeString& 
03423 UnicodeString::replace(int32_t start, 
03424                int32_t length, 
03425                const UnicodeString& srcText, 
03426                int32_t srcStart, 
03427                int32_t srcLength)
03428 { return doReplace(start, length, srcText, srcStart, srcLength); }
03429 
03430 inline UnicodeString& 
03431 UnicodeString::replace(int32_t start, 
03432                int32_t length, 
03433                const UChar *srcChars,
03434                int32_t srcLength)
03435 { return doReplace(start, length, srcChars, 0, srcLength); }
03436 
03437 inline UnicodeString& 
03438 UnicodeString::replace(int32_t start, 
03439                int32_t length, 
03440                const UChar *srcChars, 
03441                int32_t srcStart, 
03442                int32_t srcLength)
03443 { return doReplace(start, length, srcChars, srcStart, srcLength); }
03444 
03445 inline UnicodeString& 
03446 UnicodeString::replace(int32_t start, 
03447                int32_t length, 
03448                UChar srcChar)
03449 { return doReplace(start, length, &srcChar, 0, 1); }
03450 
03451 inline UnicodeString&
03452 UnicodeString::replace(int32_t start, 
03453                int32_t length, 
03454                UChar32 srcChar) {
03455   UChar buffer[UTF_MAX_CHAR_LENGTH];
03456   int32_t count = 0;
03457   UTF_APPEND_CHAR_UNSAFE(buffer, count, srcChar);
03458   return doReplace(start, length, buffer, 0, count);
03459 }
03460 
03461 inline UnicodeString& 
03462 UnicodeString::replaceBetween(int32_t start, 
03463                   int32_t limit, 
03464                   const UnicodeString& srcText)
03465 { return doReplace(start, limit - start, srcText, 0, srcText.fLength); }
03466 
03467 inline UnicodeString&
03468 UnicodeString::replaceBetween(int32_t start, 
03469                   int32_t limit, 
03470                   const UnicodeString& srcText, 
03471                   int32_t srcStart, 
03472                   int32_t srcLimit)
03473 { return doReplace(start, limit - start, srcText, srcStart, srcLimit - srcStart); }
03474 
03475 inline UnicodeString& 
03476 UnicodeString::findAndReplace(const UnicodeString& oldText,
03477                   const UnicodeString& newText)
03478 { return findAndReplace(0, fLength, oldText, 0, oldText.fLength, 
03479             newText, 0, newText.fLength); }
03480 
03481 inline UnicodeString& 
03482 UnicodeString::findAndReplace(int32_t start,
03483                   int32_t length,
03484                   const UnicodeString& oldText,
03485                   const UnicodeString& newText)
03486 { return findAndReplace(start, length, oldText, 0, oldText.fLength, 
03487             newText, 0, newText.fLength); }
03488 
03489 // ============================
03490 // extract
03491 // ============================
03492 inline void
03493 UnicodeString::doExtract(int32_t start,
03494              int32_t length,
03495              UnicodeString& target) const
03496 { target.replace(0, target.fLength, *this, start, length); }
03497 
03498 inline void  
03499 UnicodeString::extract(int32_t start, 
03500                int32_t length, 
03501                UChar *target, 
03502                int32_t targetStart) const
03503 { doExtract(start, length, target, targetStart); }
03504 
03505 inline void 
03506 UnicodeString::extract(int32_t start,
03507                int32_t length,
03508                UnicodeString& target) const
03509 { doExtract(start, length, target); }
03510 
03511 inline int32_t
03512 UnicodeString::extract(int32_t start,
03513                int32_t length,
03514                char *dst,
03515                const char *codepage) const
03516 
03517 {
03518   // This dstSize value will be checked explicitly
03519   return extract(start, length, dst, dst!=0 ? 0xffffffff : 0, codepage);
03520 }
03521 
03522 inline void  
03523 UnicodeString::extractBetween(int32_t start, 
03524                   int32_t limit, 
03525                   UChar *dst, 
03526                   int32_t dstStart) const
03527 { doExtract(start, limit - start, dst, dstStart); }
03528 
03529 inline UChar
03530 UnicodeString::doCharAt(int32_t offset) const
03531 {
03532   if((uint32_t)offset < (uint32_t)fLength) {
03533     return fArray[offset];
03534   } else {
03535     return kInvalidUChar;
03536   }
03537 }
03538 
03539 inline UChar
03540 UnicodeString::charAt(int32_t offset) const
03541 { return doCharAt(offset); }
03542 
03543 inline UChar
03544 UnicodeString::operator[] (int32_t offset) const
03545 { return doCharAt(offset); }
03546 
03547 inline UChar32
03548 UnicodeString::char32At(int32_t offset) const
03549 {
03550   if((uint32_t)offset < (uint32_t)fLength) {
03551     UChar32 c;
03552     UTF_GET_CHAR(fArray, 0, offset, fLength, c);
03553     return c;
03554   } else {
03555     return kInvalidUChar;
03556   }
03557 }
03558 
03559 inline int32_t
03560 UnicodeString::getChar32Start(int32_t offset) const {
03561   if((uint32_t)offset < (uint32_t)fLength) {
03562     UTF_SET_CHAR_START(fArray, 0, offset);
03563     return offset;
03564   } else {
03565     return 0;
03566   }
03567 }
03568 
03569 inline int32_t
03570 UnicodeString::getChar32Limit(int32_t offset) const {
03571   if((uint32_t)offset < (uint32_t)fLength) {
03572     UTF_SET_CHAR_LIMIT(fArray, 0, offset, fLength);
03573     return offset;
03574   } else {
03575     return fLength;
03576   }
03577 }
03578 
03579 inline int32_t
03580 UnicodeString::getCharStart(int32_t offset) const {
03581   return getChar32Start(offset);
03582 }
03583 
03584 inline int32_t
03585 UnicodeString::getCharLimit(int32_t offset) const {
03586   return getChar32Limit(offset);
03587 }
03588 
03589 inline UBool
03590 UnicodeString::isEmpty() const {
03591   return fLength == 0;
03592 }
03593 
03594 inline UBool
03595 UnicodeString::empty() const {
03596   return isEmpty();
03597 }
03598 
03599 //========================================
03600 // Read-only implementation methods
03601 //========================================
03602 inline int32_t  
03603 UnicodeString::length() const
03604 { return fLength; }
03605 
03606 inline int32_t 
03607 UnicodeString::hashCode() const
03608 { return doHashCode(); }
03609 
03610 inline const UChar *
03611 UnicodeString::getBuffer() const {
03612   if(!(fFlags&(kIsBogus|kOpenGetBuffer))) {
03613     return fArray;
03614   } else {
03615     return 0;
03616   }
03617 }
03618 
03619 //========================================
03620 // Write alias methods
03621 //========================================
03622 inline UnicodeString& 
03623 UnicodeString::operator= (UChar ch) 
03624 { return doReplace(0, fLength, &ch, 0, 1); }
03625 
03626 inline UnicodeString& 
03627 UnicodeString::operator= (UChar32 ch) 
03628 { return replace(0, fLength, ch); }
03629 
03630 inline UnicodeString& 
03631 UnicodeString::setTo(const UnicodeString& srcText, 
03632              int32_t srcStart, 
03633              int32_t srcLength)
03634 { return doReplace(0, fLength, srcText, srcStart, srcLength); }
03635 
03636 inline UnicodeString& 
03637 UnicodeString::setTo(const UnicodeString& srcText)
03638 { return doReplace(0, fLength, srcText, 0, srcText.fLength); }
03639 
03640 inline UnicodeString& 
03641 UnicodeString::setTo(const UChar *srcChars,
03642              int32_t srcLength)
03643 { return doReplace(0, fLength, srcChars, 0, srcLength); }
03644 
03645 inline UnicodeString& 
03646 UnicodeString::setTo(UChar srcChar)
03647 { return doReplace(0, fLength, &srcChar, 0, 1); }
03648 
03649 inline UnicodeString& 
03650 UnicodeString::setTo(UChar32 srcChar)
03651 { return replace(0, fLength, srcChar); }
03652 
03653 inline UnicodeString& 
03654 UnicodeString::operator+= (UChar ch)
03655 { return doReplace(fLength, 0, &ch, 0, 1); }
03656 
03657 inline UnicodeString& 
03658 UnicodeString::operator+= (UChar32 ch) {
03659   UChar buffer[UTF_MAX_CHAR_LENGTH];
03660   int32_t length = 0;
03661   UTF_APPEND_CHAR_UNSAFE(buffer, length, ch);
03662   return doReplace(fLength, 0, buffer, 0, length);
03663 }
03664 
03665 inline UnicodeString& 
03666 UnicodeString::operator+= (const UnicodeString& srcText)
03667 { return doReplace(fLength, 0, srcText, 0, srcText.fLength); }
03668 
03669 inline UnicodeString& 
03670 UnicodeString::append(const UnicodeString& srcText, 
03671               int32_t srcStart, 
03672               int32_t srcLength)
03673 { return doReplace(fLength, 0, srcText, srcStart, srcLength); }
03674 
03675 inline UnicodeString& 
03676 UnicodeString::append(const UnicodeString& srcText)
03677 { return doReplace(fLength, 0, srcText, 0, srcText.fLength); }
03678 
03679 inline UnicodeString& 
03680 UnicodeString::append(const UChar *srcChars, 
03681               int32_t srcStart, 
03682               int32_t srcLength)
03683 { return doReplace(fLength, 0, srcChars, srcStart, srcLength); }
03684 
03685 inline UnicodeString& 
03686 UnicodeString::append(const UChar *srcChars,
03687               int32_t srcLength)
03688 { return doReplace(fLength, 0, srcChars, 0, srcLength); }
03689 
03690 inline UnicodeString& 
03691 UnicodeString::append(UChar srcChar)
03692 { return doReplace(fLength, 0, &srcChar, 0, 1); }
03693 
03694 inline UnicodeString& 
03695 UnicodeString::append(UChar32 srcChar) {
03696   UChar buffer[UTF_MAX_CHAR_LENGTH];
03697   int32_t length = 0;
03698   UTF_APPEND_CHAR_UNSAFE(buffer, length, srcChar);
03699   return doReplace(fLength, 0, buffer, 0, length);
03700 }
03701 
03702 inline UnicodeString& 
03703 UnicodeString::insert(int32_t start, 
03704               const UnicodeString& srcText, 
03705               int32_t srcStart, 
03706               int32_t srcLength)
03707 { return doReplace(start, 0, srcText, srcStart, srcLength); }
03708 
03709 inline UnicodeString& 
03710 UnicodeString::insert(int32_t start, 
03711               const UnicodeString& srcText)
03712 { return doReplace(start, 0, srcText, 0, srcText.fLength); }
03713 
03714 inline UnicodeString& 
03715 UnicodeString::insert(int32_t start, 
03716               const UChar *srcChars, 
03717               int32_t srcStart, 
03718               int32_t srcLength)
03719 { return doReplace(start, 0, srcChars, srcStart, srcLength); }
03720 
03721 inline UnicodeString& 
03722 UnicodeString::insert(int32_t start, 
03723               const UChar *srcChars,
03724               int32_t srcLength)
03725 { return doReplace(start, 0, srcChars, 0, srcLength); }
03726 
03727 inline UnicodeString& 
03728 UnicodeString::insert(int32_t start, 
03729               UChar srcChar)
03730 { return doReplace(start, 0, &srcChar, 0, 1); }
03731 
03732 inline UnicodeString& 
03733 UnicodeString::insert(int32_t start, 
03734               UChar32 srcChar)
03735 { return replace(start, 0, srcChar); }
03736 
03737 
03738 inline UnicodeString& 
03739 UnicodeString::remove(int32_t start, 
03740              int32_t length)
03741 { return doReplace(start, length, NULL, 0, 0); }
03742 
03743 inline UnicodeString& 
03744 UnicodeString::remove()
03745 { return doReplace(0, fLength, 0, 0, 0); }
03746 
03747 inline UnicodeString& 
03748 UnicodeString::removeBetween(int32_t start,
03749                 int32_t limit)
03750 { return doReplace(start, limit - start, NULL, 0, 0); }
03751 
03752 inline UBool 
03753 UnicodeString::truncate(int32_t targetLength)
03754 {
03755   if((uint32_t)targetLength < (uint32_t)fLength) {
03756     fLength = targetLength;
03757     return TRUE;
03758   } else {
03759     return FALSE;
03760   }
03761 }
03762 
03763 inline UnicodeString& 
03764 UnicodeString::reverse()
03765 { return doReverse(0, fLength); }
03766 
03767 inline UnicodeString& 
03768 UnicodeString::reverse(int32_t start,
03769                int32_t length)
03770 { return doReverse(start, length); }
03771 
03772 
03773 //========================================
03774 // Write implementation methods
03775 //========================================
03776 inline UBool 
03777 UnicodeString::isBogus() const
03778 { return (UBool)(fFlags & kIsBogus); }
03779 
03780 
03781 //========================================
03782 // Privates
03783 //========================================
03784 
03785 inline void
03786 UnicodeString::pinIndices(int32_t& start,
03787                           int32_t& length) const
03788 {
03789   // pin indices
03790   if(start < 0) {
03791     start = 0;
03792   } else if(start > fLength) {
03793     start = fLength;
03794   }
03795   if(length < 0) {
03796     length = 0;
03797   } else if(length > (fLength - start)) {
03798     length = (fLength - start);
03799   }
03800 }
03801 
03802 inline UChar* 
03803 UnicodeString::getArrayStart()
03804 { return fArray; }
03805 
03806 inline const UChar* 
03807 UnicodeString::getArrayStart() const
03808 { return fArray; }
03809 
03810 inline int32_t 
03811 UnicodeString::getCapacity() const
03812 { return fCapacity; }
03813 
03814 U_NAMESPACE_END
03815 
03816 //========================================
03817 // Static members
03818 //========================================
03819 U_NAMESPACE_BEGIN
03820 
03821 //========================================
03822 // class UCharReference
03823 //========================================
03824 class U_COMMON_API UCharReference
03825 {
03826 public:
03827   UCharReference();
03828   inline UCharReference(UnicodeString *string,
03829          int32_t pos);
03830   inline UCharReference(const UCharReference& that);
03831   ~UCharReference();
03832 
03833   inline UCharReference& operator= (const UCharReference& that);
03834   inline UCharReference& operator= (UChar c);
03835 
03836   inline operator UChar();
03837 
03838 private:
03839   UnicodeString *fString;
03840   int32_t fPos;
03841 };
03842 
03843 
03844 //========================================
03845 // Inline members
03846 //========================================
03847 inline
03848 UCharReference::UCharReference(UnicodeString *string, 
03849                    int32_t pos)
03850   : fString(string), fPos(pos)
03851 {}
03852 
03853 inline
03854 UCharReference::UCharReference(const UCharReference& that)
03855 { this->operator=(that); }
03856 
03857 inline
03858 UCharReference::~UCharReference()
03859 {}
03860 
03861 inline UCharReference&
03862 UCharReference::operator= (const UCharReference& that)
03863 { fString->setCharAt(fPos, that.fString->charAt(that.fPos)); return *this; }
03864 
03865 inline UCharReference& 
03866 UCharReference::operator= (UChar c)
03867 { fString->setCharAt(fPos, c); return *this; }
03868 
03869 inline
03870 UCharReference::operator UChar()
03871 { return fString->charAt(fPos); }
03872 
03873 U_NAMESPACE_END
03874 
03875 #endif

Generated on Sun Jan 18 22:55:41 2004 for ICU 2.1 by doxygen 1.3.4