Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields   Globals  

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

Generated on Mon Mar 4 21:29:24 2002 for ICU 2.0 by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002