ICU 73.2  73.2
unistr.h
Go to the documentation of this file.
00001 // © 2016 and later: Unicode, Inc. and others.
00002 // License & terms of use: http://www.unicode.org/copyright.html
00003 /*
00004 **********************************************************************
00005 *   Copyright (C) 1998-2016, International Business Machines
00006 *   Corporation and others.  All Rights Reserved.
00007 **********************************************************************
00008 *
00009 * File unistr.h
00010 *
00011 * Modification History:
00012 *
00013 *   Date        Name        Description
00014 *   09/25/98    stephen     Creation.
00015 *   11/11/98    stephen     Changed per 11/9 code review.
00016 *   04/20/99    stephen     Overhauled per 4/16 code review.
00017 *   11/18/99    aliu        Made to inherit from Replaceable.  Added method
00018 *                           handleReplaceBetween(); other methods unchanged.
00019 *   06/25/01    grhoten     Remove dependency on iostream.
00020 ******************************************************************************
00021 */
00022 
00023 #ifndef UNISTR_H
00024 #define UNISTR_H
00025 
00031 #include "unicode/utypes.h"
00032 
00033 #if U_SHOW_CPLUSPLUS_API
00034 
00035 #include <cstddef>
00036 #include "unicode/char16ptr.h"
00037 #include "unicode/rep.h"
00038 #include "unicode/std_string.h"
00039 #include "unicode/stringpiece.h"
00040 #include "unicode/bytestream.h"
00041 
00042 struct UConverter;          // unicode/ucnv.h
00043 
00044 #ifndef USTRING_H
00045 
00050 U_CAPI int32_t U_EXPORT2 u_strlen(const UChar *s);
00051 #endif
00052 
00053 U_NAMESPACE_BEGIN
00054 
00055 #if !UCONFIG_NO_BREAK_ITERATION
00056 class BreakIterator;        // unicode/brkiter.h
00057 #endif
00058 class Edits;
00059 
00060 U_NAMESPACE_END
00061 
00062 // Not #ifndef U_HIDE_INTERNAL_API because UnicodeString needs the UStringCaseMapper.
00069 typedef int32_t U_CALLCONV
00070 UStringCaseMapper(int32_t caseLocale, uint32_t options,
00071 #if !UCONFIG_NO_BREAK_ITERATION
00072                   icu::BreakIterator *iter,
00073 #endif
00074                   char16_t *dest, int32_t destCapacity,
00075                   const char16_t *src, int32_t srcLength,
00076                   icu::Edits *edits,
00077                   UErrorCode &errorCode);
00078 
00079 U_NAMESPACE_BEGIN
00080 
00081 class Locale;               // unicode/locid.h
00082 class StringCharacterIterator;
00083 class UnicodeStringAppendable;  // unicode/appendable.h
00084 
00085 /* The <iostream> include has been moved to unicode/ustream.h */
00086 
00097 #define US_INV icu::UnicodeString::kInvariant
00098 
00116 #if !U_CHAR16_IS_TYPEDEF
00117 # define UNICODE_STRING(cs, _length) icu::UnicodeString(true, u ## cs, _length)
00118 #else
00119 # define UNICODE_STRING(cs, _length) icu::UnicodeString(true, (const char16_t*)u ## cs, _length)
00120 #endif
00121 
00135 #define UNICODE_STRING_SIMPLE(cs) UNICODE_STRING(cs, -1)
00136 
00144 #ifndef UNISTR_FROM_CHAR_EXPLICIT
00145 # if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION)
00146     // Auto-"explicit" in ICU library code.
00147 #   define UNISTR_FROM_CHAR_EXPLICIT explicit
00148 # else
00149     // Empty by default for source code compatibility.
00150 #   define UNISTR_FROM_CHAR_EXPLICIT
00151 # endif
00152 #endif
00153 
00164 #ifndef UNISTR_FROM_STRING_EXPLICIT
00165 # if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION)
00166     // Auto-"explicit" in ICU library code.
00167 #   define UNISTR_FROM_STRING_EXPLICIT explicit
00168 # else
00169     // Empty by default for source code compatibility.
00170 #   define UNISTR_FROM_STRING_EXPLICIT
00171 # endif
00172 #endif
00173 
00207 #ifndef UNISTR_OBJECT_SIZE
00208 # define UNISTR_OBJECT_SIZE 64
00209 #endif
00210 
00295 class U_COMMON_API UnicodeString : public Replaceable
00296 {
00297 public:
00298 
00307   enum EInvariant {
00312     kInvariant
00313   };
00314 
00315   //========================================
00316   // Read-only operations
00317   //========================================
00318 
00319   /* Comparison - bitwise only - for international comparison use collation */
00320 
00328   inline bool operator== (const UnicodeString& text) const;
00329 
00337   inline bool operator!= (const UnicodeString& text) const;
00338 
00346   inline UBool operator> (const UnicodeString& text) const;
00347 
00355   inline UBool operator< (const UnicodeString& text) const;
00356 
00364   inline UBool operator>= (const UnicodeString& text) const;
00365 
00373   inline UBool operator<= (const UnicodeString& text) const;
00374 
00386   inline int8_t compare(const UnicodeString& text) const;
00387 
00403   inline int8_t compare(int32_t start,
00404          int32_t length,
00405          const UnicodeString& text) const;
00406 
00424    inline int8_t compare(int32_t start,
00425          int32_t length,
00426          const UnicodeString& srcText,
00427          int32_t srcStart,
00428          int32_t srcLength) const;
00429 
00442   inline int8_t compare(ConstChar16Ptr srcChars,
00443          int32_t srcLength) const;
00444 
00459   inline int8_t compare(int32_t start,
00460          int32_t length,
00461          const char16_t *srcChars) const;
00462 
00480   inline int8_t compare(int32_t start,
00481          int32_t length,
00482          const char16_t *srcChars,
00483          int32_t srcStart,
00484          int32_t srcLength) const;
00485 
00503   inline int8_t compareBetween(int32_t start,
00504             int32_t limit,
00505             const UnicodeString& srcText,
00506             int32_t srcStart,
00507             int32_t srcLimit) const;
00508 
00526   inline int8_t compareCodePointOrder(const UnicodeString& text) const;
00527 
00547   inline int8_t compareCodePointOrder(int32_t start,
00548                                       int32_t length,
00549                                       const UnicodeString& srcText) const;
00550 
00572    inline int8_t compareCodePointOrder(int32_t start,
00573                                        int32_t length,
00574                                        const UnicodeString& srcText,
00575                                        int32_t srcStart,
00576                                        int32_t srcLength) const;
00577 
00596   inline int8_t compareCodePointOrder(ConstChar16Ptr srcChars,
00597                                       int32_t srcLength) const;
00598 
00618   inline int8_t compareCodePointOrder(int32_t start,
00619                                       int32_t length,
00620                                       const char16_t *srcChars) const;
00621 
00643   inline int8_t compareCodePointOrder(int32_t start,
00644                                       int32_t length,
00645                                       const char16_t *srcChars,
00646                                       int32_t srcStart,
00647                                       int32_t srcLength) const;
00648 
00670   inline int8_t compareCodePointOrderBetween(int32_t start,
00671                                              int32_t limit,
00672                                              const UnicodeString& srcText,
00673                                              int32_t srcStart,
00674                                              int32_t srcLimit) const;
00675 
00694   inline int8_t caseCompare(const UnicodeString& text, uint32_t options) const;
00695 
00716   inline int8_t caseCompare(int32_t start,
00717          int32_t length,
00718          const UnicodeString& srcText,
00719          uint32_t options) const;
00720 
00743   inline int8_t caseCompare(int32_t start,
00744          int32_t length,
00745          const UnicodeString& srcText,
00746          int32_t srcStart,
00747          int32_t srcLength,
00748          uint32_t options) const;
00749 
00769   inline int8_t caseCompare(ConstChar16Ptr srcChars,
00770          int32_t srcLength,
00771          uint32_t options) const;
00772 
00793   inline int8_t caseCompare(int32_t start,
00794          int32_t length,
00795          const char16_t *srcChars,
00796          uint32_t options) const;
00797 
00820   inline int8_t caseCompare(int32_t start,
00821          int32_t length,
00822          const char16_t *srcChars,
00823          int32_t srcStart,
00824          int32_t srcLength,
00825          uint32_t options) const;
00826 
00849   inline int8_t caseCompareBetween(int32_t start,
00850             int32_t limit,
00851             const UnicodeString& srcText,
00852             int32_t srcStart,
00853             int32_t srcLimit,
00854             uint32_t options) const;
00855 
00863   inline UBool startsWith(const UnicodeString& text) const;
00864 
00875   inline UBool startsWith(const UnicodeString& srcText,
00876             int32_t srcStart,
00877             int32_t srcLength) const;
00878 
00887   inline UBool startsWith(ConstChar16Ptr srcChars,
00888             int32_t srcLength) const;
00889 
00899   inline UBool startsWith(const char16_t *srcChars,
00900             int32_t srcStart,
00901             int32_t srcLength) const;
00902 
00910   inline UBool endsWith(const UnicodeString& text) const;
00911 
00922   inline UBool endsWith(const UnicodeString& srcText,
00923           int32_t srcStart,
00924           int32_t srcLength) const;
00925 
00934   inline UBool endsWith(ConstChar16Ptr srcChars,
00935           int32_t srcLength) const;
00936 
00947   inline UBool endsWith(const char16_t *srcChars,
00948           int32_t srcStart,
00949           int32_t srcLength) const;
00950 
00951 
00952   /* Searching - bitwise only */
00953 
00962   inline int32_t indexOf(const UnicodeString& text) const;
00963 
00973   inline int32_t indexOf(const UnicodeString& text,
00974               int32_t start) const;
00975 
00987   inline int32_t indexOf(const UnicodeString& text,
00988               int32_t start,
00989               int32_t length) const;
00990 
01007   inline int32_t indexOf(const UnicodeString& srcText,
01008               int32_t srcStart,
01009               int32_t srcLength,
01010               int32_t start,
01011               int32_t length) const;
01012 
01024   inline int32_t indexOf(const char16_t *srcChars,
01025               int32_t srcLength,
01026               int32_t start) const;
01027 
01040   inline int32_t indexOf(ConstChar16Ptr srcChars,
01041               int32_t srcLength,
01042               int32_t start,
01043               int32_t length) const;
01044 
01061   int32_t indexOf(const char16_t *srcChars,
01062               int32_t srcStart,
01063               int32_t srcLength,
01064               int32_t start,
01065               int32_t length) const;
01066 
01074   inline int32_t indexOf(char16_t c) const;
01075 
01084   inline int32_t indexOf(UChar32 c) const;
01085 
01094   inline int32_t indexOf(char16_t c,
01095               int32_t start) const;
01096 
01106   inline int32_t indexOf(UChar32 c,
01107               int32_t start) const;
01108 
01119   inline int32_t indexOf(char16_t c,
01120               int32_t start,
01121               int32_t length) const;
01122 
01134   inline int32_t indexOf(UChar32 c,
01135               int32_t start,
01136               int32_t length) const;
01137 
01146   inline int32_t lastIndexOf(const UnicodeString& text) const;
01147 
01157   inline int32_t lastIndexOf(const UnicodeString& text,
01158               int32_t start) const;
01159 
01171   inline int32_t lastIndexOf(const UnicodeString& text,
01172               int32_t start,
01173               int32_t length) const;
01174 
01191   inline int32_t lastIndexOf(const UnicodeString& srcText,
01192               int32_t srcStart,
01193               int32_t srcLength,
01194               int32_t start,
01195               int32_t length) const;
01196 
01207   inline int32_t lastIndexOf(const char16_t *srcChars,
01208               int32_t srcLength,
01209               int32_t start) const;
01210 
01223   inline int32_t lastIndexOf(ConstChar16Ptr srcChars,
01224               int32_t srcLength,
01225               int32_t start,
01226               int32_t length) const;
01227 
01244   int32_t lastIndexOf(const char16_t *srcChars,
01245               int32_t srcStart,
01246               int32_t srcLength,
01247               int32_t start,
01248               int32_t length) const;
01249 
01257   inline int32_t lastIndexOf(char16_t c) const;
01258 
01267   inline int32_t lastIndexOf(UChar32 c) const;
01268 
01277   inline int32_t lastIndexOf(char16_t c,
01278               int32_t start) const;
01279 
01289   inline int32_t lastIndexOf(UChar32 c,
01290               int32_t start) const;
01291 
01302   inline int32_t lastIndexOf(char16_t c,
01303               int32_t start,
01304               int32_t length) const;
01305 
01317   inline int32_t lastIndexOf(UChar32 c,
01318               int32_t start,
01319               int32_t length) const;
01320 
01321 
01322   /* Character access */
01323 
01332   inline char16_t charAt(int32_t offset) const;
01333 
01341   inline char16_t operator[] (int32_t offset) const;
01342 
01354   UChar32 char32At(int32_t offset) const;
01355 
01371   int32_t getChar32Start(int32_t offset) const;
01372 
01389   int32_t getChar32Limit(int32_t offset) const;
01390 
01441   int32_t moveIndex32(int32_t index, int32_t delta) const;
01442 
01443   /* Substring extraction */
01444 
01460   inline void extract(int32_t start,
01461            int32_t length,
01462            Char16Ptr dst,
01463            int32_t dstStart = 0) const;
01464 
01486   int32_t
01487   extract(Char16Ptr dest, int32_t destCapacity,
01488           UErrorCode &errorCode) const;
01489 
01499   inline void extract(int32_t start,
01500            int32_t length,
01501            UnicodeString& target) const;
01502 
01514   inline void extractBetween(int32_t start,
01515               int32_t limit,
01516               char16_t *dst,
01517               int32_t dstStart = 0) const;
01518 
01527   virtual void extractBetween(int32_t start,
01528               int32_t limit,
01529               UnicodeString& target) const override;
01530 
01552   int32_t extract(int32_t start,
01553            int32_t startLength,
01554            char *target,
01555            int32_t targetCapacity,
01556            enum EInvariant inv) const;
01557 
01558 #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
01559 
01579   int32_t extract(int32_t start,
01580            int32_t startLength,
01581            char *target,
01582            uint32_t targetLength) const;
01583 
01584 #endif
01585 
01586 #if !UCONFIG_NO_CONVERSION
01587 
01613   inline int32_t extract(int32_t start,
01614                  int32_t startLength,
01615                  char *target,
01616                  const char *codepage = 0) const;
01617 
01647   int32_t extract(int32_t start,
01648            int32_t startLength,
01649            char *target,
01650            uint32_t targetLength,
01651            const char *codepage) const;
01652 
01670   int32_t extract(char *dest, int32_t destCapacity,
01671                   UConverter *cnv,
01672                   UErrorCode &errorCode) const;
01673 
01674 #endif
01675 
01689   UnicodeString tempSubString(int32_t start=0, int32_t length=INT32_MAX) const;
01690 
01701   inline UnicodeString tempSubStringBetween(int32_t start, int32_t limit=INT32_MAX) const;
01702 
01714   void toUTF8(ByteSink &sink) const;
01715 
01728   template<typename StringClass>
01729   StringClass &toUTF8String(StringClass &result) const {
01730     StringByteSink<StringClass> sbs(&result, length());
01731     toUTF8(sbs);
01732     return result;
01733   }
01734 
01750   int32_t toUTF32(UChar32 *utf32, int32_t capacity, UErrorCode &errorCode) const;
01751 
01752   /* Length operations */
01753 
01762   inline int32_t length(void) const;
01763 
01777   int32_t
01778   countChar32(int32_t start=0, int32_t length=INT32_MAX) const;
01779 
01803   UBool
01804   hasMoreChar32Than(int32_t start, int32_t length, int32_t number) const;
01805 
01811   inline UBool isEmpty(void) const;
01812 
01822   inline int32_t getCapacity(void) const;
01823 
01824   /* Other operations */
01825 
01831   inline int32_t hashCode(void) const;
01832 
01845   inline UBool isBogus(void) const;
01846 
01847 
01848   //========================================
01849   // Write operations
01850   //========================================
01851 
01852   /* Assignment operations */
01853 
01872   UnicodeString &operator=(const UnicodeString &srcText);
01873 
01899   UnicodeString &fastCopyFrom(const UnicodeString &src);
01900 
01909   UnicodeString &operator=(UnicodeString &&src) noexcept;
01910 
01916   void swap(UnicodeString &other) noexcept;
01917 
01924   friend inline void U_EXPORT2
01925   swap(UnicodeString &s1, UnicodeString &s2) noexcept {
01926     s1.swap(s2);
01927   }
01928 
01936   inline UnicodeString& operator= (char16_t ch);
01937 
01945   inline UnicodeString& operator= (UChar32 ch);
01946 
01958   inline UnicodeString& setTo(const UnicodeString& srcText,
01959                int32_t srcStart);
01960 
01974   inline UnicodeString& setTo(const UnicodeString& srcText,
01975                int32_t srcStart,
01976                int32_t srcLength);
01977 
01986   inline UnicodeString& setTo(const UnicodeString& srcText);
01987 
01996   inline UnicodeString& setTo(const char16_t *srcChars,
01997                int32_t srcLength);
01998 
02007   inline UnicodeString& setTo(char16_t srcChar);
02008 
02017   inline UnicodeString& setTo(UChar32 srcChar);
02018 
02042   UnicodeString &setTo(UBool isTerminated,
02043                        ConstChar16Ptr text,
02044                        int32_t textLength);
02045 
02065   UnicodeString &setTo(char16_t *buffer,
02066                        int32_t buffLength,
02067                        int32_t buffCapacity);
02068 
02108   void setToBogus();
02109 
02117   UnicodeString& setCharAt(int32_t offset,
02118                char16_t ch);
02119 
02120 
02121   /* Append operations */
02122 
02130  inline  UnicodeString& operator+= (char16_t ch);
02131 
02139  inline  UnicodeString& operator+= (UChar32 ch);
02140 
02148   inline UnicodeString& operator+= (const UnicodeString& srcText);
02149 
02164   inline UnicodeString& append(const UnicodeString& srcText,
02165             int32_t srcStart,
02166             int32_t srcLength);
02167 
02175   inline UnicodeString& append(const UnicodeString& srcText);
02176 
02190   inline UnicodeString& append(const char16_t *srcChars,
02191             int32_t srcStart,
02192             int32_t srcLength);
02193 
02203   inline UnicodeString& append(ConstChar16Ptr srcChars,
02204             int32_t srcLength);
02205 
02212   inline UnicodeString& append(char16_t srcChar);
02213 
02220   UnicodeString& append(UChar32 srcChar);
02221 
02222 
02223   /* Insert operations */
02224 
02238   inline UnicodeString& insert(int32_t start,
02239             const UnicodeString& srcText,
02240             int32_t srcStart,
02241             int32_t srcLength);
02242 
02251   inline UnicodeString& insert(int32_t start,
02252             const UnicodeString& srcText);
02253 
02267   inline UnicodeString& insert(int32_t start,
02268             const char16_t *srcChars,
02269             int32_t srcStart,
02270             int32_t srcLength);
02271 
02281   inline UnicodeString& insert(int32_t start,
02282             ConstChar16Ptr srcChars,
02283             int32_t srcLength);
02284 
02293   inline UnicodeString& insert(int32_t start,
02294             char16_t srcChar);
02295 
02304   inline UnicodeString& insert(int32_t start,
02305             UChar32 srcChar);
02306 
02307 
02308   /* Replace operations */
02309 
02327   inline UnicodeString& replace(int32_t start,
02328              int32_t length,
02329              const UnicodeString& srcText,
02330              int32_t srcStart,
02331              int32_t srcLength);
02332 
02345   inline UnicodeString& replace(int32_t start,
02346              int32_t length,
02347              const UnicodeString& srcText);
02348 
02366   inline UnicodeString& replace(int32_t start,
02367              int32_t length,
02368              const char16_t *srcChars,
02369              int32_t srcStart,
02370              int32_t srcLength);
02371 
02384   inline UnicodeString& replace(int32_t start,
02385              int32_t length,
02386              ConstChar16Ptr srcChars,
02387              int32_t srcLength);
02388 
02400   inline UnicodeString& replace(int32_t start,
02401              int32_t length,
02402              char16_t srcChar);
02403 
02415   UnicodeString& replace(int32_t start, int32_t length, UChar32 srcChar);
02416 
02426   inline UnicodeString& replaceBetween(int32_t start,
02427                 int32_t limit,
02428                 const UnicodeString& srcText);
02429 
02444   inline UnicodeString& replaceBetween(int32_t start,
02445                 int32_t limit,
02446                 const UnicodeString& srcText,
02447                 int32_t srcStart,
02448                 int32_t srcLimit);
02449 
02457   virtual void handleReplaceBetween(int32_t start,
02458                                     int32_t limit,
02459                                     const UnicodeString& text) override;
02460 
02466   virtual UBool hasMetaData() const override;
02467 
02481   virtual void copy(int32_t start, int32_t limit, int32_t dest) override;
02482 
02483   /* Search and replace operations */
02484 
02493   inline UnicodeString& findAndReplace(const UnicodeString& oldText,
02494                 const UnicodeString& newText);
02495 
02507   inline UnicodeString& findAndReplace(int32_t start,
02508                 int32_t length,
02509                 const UnicodeString& oldText,
02510                 const UnicodeString& newText);
02511 
02529   UnicodeString& findAndReplace(int32_t start,
02530                 int32_t length,
02531                 const UnicodeString& oldText,
02532                 int32_t oldStart,
02533                 int32_t oldLength,
02534                 const UnicodeString& newText,
02535                 int32_t newStart,
02536                 int32_t newLength);
02537 
02538 
02539   /* Remove operations */
02540 
02549   inline UnicodeString& remove();
02550 
02559   inline UnicodeString& remove(int32_t start,
02560                                int32_t length = (int32_t)INT32_MAX);
02561 
02570   inline UnicodeString& removeBetween(int32_t start,
02571                                       int32_t limit = (int32_t)INT32_MAX);
02572 
02582   inline UnicodeString &retainBetween(int32_t start, int32_t limit = INT32_MAX);
02583 
02584   /* Length operations */
02585 
02597   UBool padLeading(int32_t targetLength,
02598                     char16_t padChar = 0x0020);
02599 
02611   UBool padTrailing(int32_t targetLength,
02612                      char16_t padChar = 0x0020);
02613 
02620   inline UBool truncate(int32_t targetLength);
02621 
02627   UnicodeString& trim(void);
02628 
02629 
02630   /* Miscellaneous operations */
02631 
02637   inline UnicodeString& reverse(void);
02638 
02647   inline UnicodeString& reverse(int32_t start,
02648              int32_t length);
02649 
02656   UnicodeString& toUpper(void);
02657 
02665   UnicodeString& toUpper(const Locale& locale);
02666 
02673   UnicodeString& toLower(void);
02674 
02682   UnicodeString& toLower(const Locale& locale);
02683 
02684 #if !UCONFIG_NO_BREAK_ITERATION
02685 
02712   UnicodeString &toTitle(BreakIterator *titleIter);
02713 
02741   UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale);
02742 
02773   UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale, uint32_t options);
02774 
02775 #endif
02776 
02790   UnicodeString &foldCase(uint32_t options=0 /*U_FOLD_CASE_DEFAULT*/);
02791 
02792   //========================================
02793   // Access to the internal buffer
02794   //========================================
02795 
02839   char16_t *getBuffer(int32_t minCapacity);
02840 
02861   void releaseBuffer(int32_t newLength=-1);
02862 
02893   inline const char16_t *getBuffer() const;
02894 
02928   const char16_t *getTerminatedBuffer();
02929 
02930   //========================================
02931   // Constructors
02932   //========================================
02933 
02937   inline UnicodeString();
02938 
02950   UnicodeString(int32_t capacity, UChar32 c, int32_t count);
02951 
02961   UNISTR_FROM_CHAR_EXPLICIT UnicodeString(char16_t ch);
02962 
02972   UNISTR_FROM_CHAR_EXPLICIT UnicodeString(UChar32 ch);
02973 
02984   UNISTR_FROM_STRING_EXPLICIT UnicodeString(const char16_t *text);
02985 
02986 #if !U_CHAR16_IS_TYPEDEF
02987 
02997   UNISTR_FROM_STRING_EXPLICIT UnicodeString(const uint16_t *text) :
02998       UnicodeString(ConstChar16Ptr(text)) {}
02999 #endif
03000 
03001 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
03002 
03013   UNISTR_FROM_STRING_EXPLICIT UnicodeString(const wchar_t *text) :
03014       UnicodeString(ConstChar16Ptr(text)) {}
03015 #endif
03016 
03027   UNISTR_FROM_STRING_EXPLICIT inline UnicodeString(const std::nullptr_t text);
03028 
03036   UnicodeString(const char16_t *text,
03037         int32_t textLength);
03038 
03039 #if !U_CHAR16_IS_TYPEDEF
03040 
03047   UnicodeString(const uint16_t *text, int32_t textLength) :
03048       UnicodeString(ConstChar16Ptr(text), textLength) {}
03049 #endif
03050 
03051 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
03052 
03060   UnicodeString(const wchar_t *text, int32_t textLength) :
03061       UnicodeString(ConstChar16Ptr(text), textLength) {}
03062 #endif
03063 
03071   inline UnicodeString(const std::nullptr_t text, int32_t textLength);
03072 
03095   UnicodeString(UBool isTerminated,
03096                 ConstChar16Ptr text,
03097                 int32_t textLength);
03098 
03117   UnicodeString(char16_t *buffer, int32_t buffLength, int32_t buffCapacity);
03118 
03119 #if !U_CHAR16_IS_TYPEDEF
03120 
03128   UnicodeString(uint16_t *buffer, int32_t buffLength, int32_t buffCapacity) :
03129       UnicodeString(Char16Ptr(buffer), buffLength, buffCapacity) {}
03130 #endif
03131 
03132 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
03133 
03142   UnicodeString(wchar_t *buffer, int32_t buffLength, int32_t buffCapacity) :
03143       UnicodeString(Char16Ptr(buffer), buffLength, buffCapacity) {}
03144 #endif
03145 
03154   inline UnicodeString(std::nullptr_t buffer, int32_t buffLength, int32_t buffCapacity);
03155 
03156 #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
03157 
03177   UNISTR_FROM_STRING_EXPLICIT UnicodeString(const char *codepageData);
03178 
03187   UnicodeString(const char *codepageData, int32_t dataLength);
03188 
03189 #endif
03190 
03191 #if !UCONFIG_NO_CONVERSION
03192 
03210   UnicodeString(const char *codepageData, const char *codepage);
03211 
03229   UnicodeString(const char *codepageData, int32_t dataLength, const char *codepage);
03230 
03252   UnicodeString(
03253         const char *src, int32_t srcLength,
03254         UConverter *cnv,
03255         UErrorCode &errorCode);
03256 
03257 #endif
03258 
03282   UnicodeString(const char *src, int32_t textLength, enum EInvariant inv);
03283 
03284 
03301   UnicodeString(const UnicodeString& that);
03302 
03309   UnicodeString(UnicodeString &&src) noexcept;
03310 
03317   UnicodeString(const UnicodeString& src, int32_t srcStart);
03318 
03326   UnicodeString(const UnicodeString& src, int32_t srcStart, int32_t srcLength);
03327 
03341   virtual UnicodeString *clone() const override;
03342 
03346   virtual ~UnicodeString();
03347 
03361   static UnicodeString fromUTF8(StringPiece utf8);
03362 
03374   static UnicodeString fromUTF32(const UChar32 *utf32, int32_t length);
03375 
03376   /* Miscellaneous operations */
03377 
03412   UnicodeString unescape() const;
03413 
03433   UChar32 unescapeAt(int32_t &offset) const;
03434 
03440   static UClassID U_EXPORT2 getStaticClassID();
03441 
03447   virtual UClassID getDynamicClassID() const override;
03448 
03449   //========================================
03450   // Implementation methods
03451   //========================================
03452 
03453 protected:
03458   virtual int32_t getLength() const override;
03459 
03465   virtual char16_t getCharAt(int32_t offset) const override;
03466 
03472   virtual UChar32 getChar32At(int32_t offset) const override;
03473 
03474 private:
03475   // For char* constructors. Could be made public.
03476   UnicodeString &setToUTF8(StringPiece utf8);
03477   // For extract(char*).
03478   // We could make a toUTF8(target, capacity, errorCode) public but not
03479   // this version: New API will be cleaner if we make callers create substrings
03480   // rather than having start+length on every method,
03481   // and it should take a UErrorCode&.
03482   int32_t
03483   toUTF8(int32_t start, int32_t len,
03484          char *target, int32_t capacity) const;
03485 
03490   UBool doEquals(const UnicodeString &text, int32_t len) const;
03491 
03492   inline UBool
03493   doEqualsSubstring(int32_t start,
03494            int32_t length,
03495            const UnicodeString& srcText,
03496            int32_t srcStart,
03497            int32_t srcLength) const;
03498 
03499   UBool doEqualsSubstring(int32_t start,
03500            int32_t length,
03501            const char16_t *srcChars,
03502            int32_t srcStart,
03503            int32_t srcLength) const;
03504 
03505   inline int8_t
03506   doCompare(int32_t start,
03507            int32_t length,
03508            const UnicodeString& srcText,
03509            int32_t srcStart,
03510            int32_t srcLength) const;
03511 
03512   int8_t doCompare(int32_t start,
03513            int32_t length,
03514            const char16_t *srcChars,
03515            int32_t srcStart,
03516            int32_t srcLength) const;
03517 
03518   inline int8_t
03519   doCompareCodePointOrder(int32_t start,
03520                           int32_t length,
03521                           const UnicodeString& srcText,
03522                           int32_t srcStart,
03523                           int32_t srcLength) const;
03524 
03525   int8_t doCompareCodePointOrder(int32_t start,
03526                                  int32_t length,
03527                                  const char16_t *srcChars,
03528                                  int32_t srcStart,
03529                                  int32_t srcLength) const;
03530 
03531   inline int8_t
03532   doCaseCompare(int32_t start,
03533                 int32_t length,
03534                 const UnicodeString &srcText,
03535                 int32_t srcStart,
03536                 int32_t srcLength,
03537                 uint32_t options) const;
03538 
03539   int8_t
03540   doCaseCompare(int32_t start,
03541                 int32_t length,
03542                 const char16_t *srcChars,
03543                 int32_t srcStart,
03544                 int32_t srcLength,
03545                 uint32_t options) const;
03546 
03547   int32_t doIndexOf(char16_t c,
03548             int32_t start,
03549             int32_t length) const;
03550 
03551   int32_t doIndexOf(UChar32 c,
03552                         int32_t start,
03553                         int32_t length) const;
03554 
03555   int32_t doLastIndexOf(char16_t c,
03556                 int32_t start,
03557                 int32_t length) const;
03558 
03559   int32_t doLastIndexOf(UChar32 c,
03560                             int32_t start,
03561                             int32_t length) const;
03562 
03563   void doExtract(int32_t start,
03564          int32_t length,
03565          char16_t *dst,
03566          int32_t dstStart) const;
03567 
03568   inline void doExtract(int32_t start,
03569          int32_t length,
03570          UnicodeString& target) const;
03571 
03572   inline char16_t doCharAt(int32_t offset)  const;
03573 
03574   UnicodeString& doReplace(int32_t start,
03575                int32_t length,
03576                const UnicodeString& srcText,
03577                int32_t srcStart,
03578                int32_t srcLength);
03579 
03580   UnicodeString& doReplace(int32_t start,
03581                int32_t length,
03582                const char16_t *srcChars,
03583                int32_t srcStart,
03584                int32_t srcLength);
03585 
03586   UnicodeString& doAppend(const UnicodeString& src, int32_t srcStart, int32_t srcLength);
03587   UnicodeString& doAppend(const char16_t *srcChars, int32_t srcStart, int32_t srcLength);
03588 
03589   UnicodeString& doReverse(int32_t start,
03590                int32_t length);
03591 
03592   // calculate hash code
03593   int32_t doHashCode(void) const;
03594 
03595   // get pointer to start of array
03596   // these do not check for kOpenGetBuffer, unlike the public getBuffer() function
03597   inline char16_t* getArrayStart(void);
03598   inline const char16_t* getArrayStart(void) const;
03599 
03600   inline UBool hasShortLength() const;
03601   inline int32_t getShortLength() const;
03602 
03603   // A UnicodeString object (not necessarily its current buffer)
03604   // is writable unless it isBogus() or it has an "open" getBuffer(minCapacity).
03605   inline UBool isWritable() const;
03606 
03607   // Is the current buffer writable?
03608   inline UBool isBufferWritable() const;
03609 
03610   // None of the following does releaseArray().
03611   inline void setZeroLength();
03612   inline void setShortLength(int32_t len);
03613   inline void setLength(int32_t len);
03614   inline void setToEmpty();
03615   inline void setArray(char16_t *array, int32_t len, int32_t capacity); // sets length but not flags
03616 
03617   // allocate the array; result may be the stack buffer
03618   // sets refCount to 1 if appropriate
03619   // sets fArray, fCapacity, and flags
03620   // sets length to 0
03621   // returns boolean for success or failure
03622   UBool allocate(int32_t capacity);
03623 
03624   // release the array if owned
03625   void releaseArray(void);
03626 
03627   // turn a bogus string into an empty one
03628   void unBogus();
03629 
03630   // implements assignment operator, copy constructor, and fastCopyFrom()
03631   UnicodeString &copyFrom(const UnicodeString &src, UBool fastCopy=false);
03632 
03633   // Copies just the fields without memory management.
03634   void copyFieldsFrom(UnicodeString &src, UBool setSrcToBogus) noexcept;
03635 
03636   // Pin start and limit to acceptable values.
03637   inline void pinIndex(int32_t& start) const;
03638   inline void pinIndices(int32_t& start,
03639                          int32_t& length) const;
03640 
03641 #if !UCONFIG_NO_CONVERSION
03642 
03643   /* Internal extract() using UConverter. */
03644   int32_t doExtract(int32_t start, int32_t length,
03645                     char *dest, int32_t destCapacity,
03646                     UConverter *cnv,
03647                     UErrorCode &errorCode) const;
03648 
03649   /*
03650    * Real constructor for converting from codepage data.
03651    * It assumes that it is called with !fRefCounted.
03652    *
03653    * If `codepage==0`, then the default converter
03654    * is used for the platform encoding.
03655    * If `codepage` is an empty string (`""`),
03656    * then a simple conversion is performed on the codepage-invariant
03657    * subset ("invariant characters") of the platform encoding. See utypes.h.
03658    */
03659   void doCodepageCreate(const char *codepageData,
03660                         int32_t dataLength,
03661                         const char *codepage);
03662 
03663   /*
03664    * Worker function for creating a UnicodeString from
03665    * a codepage string using a UConverter.
03666    */
03667   void
03668   doCodepageCreate(const char *codepageData,
03669                    int32_t dataLength,
03670                    UConverter *converter,
03671                    UErrorCode &status);
03672 
03673 #endif
03674 
03675   /*
03676    * This function is called when write access to the array
03677    * is necessary.
03678    *
03679    * We need to make a copy of the array if
03680    * the buffer is read-only, or
03681    * the buffer is refCounted (shared), and refCount>1, or
03682    * the buffer is too small.
03683    *
03684    * Return false if memory could not be allocated.
03685    */
03686   UBool cloneArrayIfNeeded(int32_t newCapacity = -1,
03687                             int32_t growCapacity = -1,
03688                             UBool doCopyArray = true,
03689                             int32_t **pBufferToDelete = 0,
03690                             UBool forceClone = false);
03691 
03697   UnicodeString &
03698   caseMap(int32_t caseLocale, uint32_t options,
03699 #if !UCONFIG_NO_BREAK_ITERATION
03700           BreakIterator *iter,
03701 #endif
03702           UStringCaseMapper *stringCaseMapper);
03703 
03704   // ref counting
03705   void addRef(void);
03706   int32_t removeRef(void);
03707   int32_t refCount(void) const;
03708 
03709   // constants
03710   enum {
03716     US_STACKBUF_SIZE=(int32_t)(UNISTR_OBJECT_SIZE-sizeof(void *)-2)/U_SIZEOF_UCHAR,
03717     kInvalidUChar=0xffff, // U+FFFF returned by charAt(invalid index)
03718     kInvalidHashCode=0, // invalid hash code
03719     kEmptyHashCode=1, // hash code for empty string
03720 
03721     // bit flag values for fLengthAndFlags
03722     kIsBogus=1,         // this string is bogus, i.e., not valid or nullptr
03723     kUsingStackBuffer=2,// using fUnion.fStackFields instead of fUnion.fFields
03724     kRefCounted=4,      // there is a refCount field before the characters in fArray
03725     kBufferIsReadonly=8,// do not write to this buffer
03726     kOpenGetBuffer=16,  // getBuffer(minCapacity) was called (is "open"),
03727                         // and releaseBuffer(newLength) must be called
03728     kAllStorageFlags=0x1f,
03729 
03730     kLengthShift=5,     // remaining 11 bits for non-negative short length, or negative if long
03731     kLength1=1<<kLengthShift,
03732     kMaxShortLength=0x3ff,  // max non-negative short length (leaves top bit 0)
03733     kLengthIsLarge=0xffe0,  // short length < 0, real length is in fUnion.fFields.fLength
03734 
03735     // combined values for convenience
03736     kShortString=kUsingStackBuffer,
03737     kLongString=kRefCounted,
03738     kReadonlyAlias=kBufferIsReadonly,
03739     kWritableAlias=0
03740   };
03741 
03742   friend class UnicodeStringAppendable;
03743 
03744   union StackBufferOrFields;        // forward declaration necessary before friend declaration
03745   friend union StackBufferOrFields; // make US_STACKBUF_SIZE visible inside fUnion
03746 
03747   /*
03748    * The following are all the class fields that are stored
03749    * in each UnicodeString object.
03750    * Note that UnicodeString has virtual functions,
03751    * therefore there is an implicit vtable pointer
03752    * as the first real field.
03753    * The fields should be aligned such that no padding is necessary.
03754    * On 32-bit machines, the size should be 32 bytes,
03755    * on 64-bit machines (8-byte pointers), it should be 40 bytes.
03756    *
03757    * We use a hack to achieve this.
03758    *
03759    * With at least some compilers, each of the following is forced to
03760    * a multiple of sizeof(pointer) [the largest field base unit here is a data pointer],
03761    * rounded up with additional padding if the fields do not already fit that requirement:
03762    * - sizeof(class UnicodeString)
03763    * - offsetof(UnicodeString, fUnion)
03764    * - sizeof(fUnion)
03765    * - sizeof(fStackFields)
03766    *
03767    * We optimize for the longest possible internal buffer for short strings.
03768    * fUnion.fStackFields begins with 2 bytes for storage flags
03769    * and the length of relatively short strings,
03770    * followed by the buffer for short string contents.
03771    * There is no padding inside fStackFields.
03772    *
03773    * Heap-allocated and aliased strings use fUnion.fFields.
03774    * Both fStackFields and fFields must begin with the same fields for flags and short length,
03775    * that is, those must have the same memory offsets inside the object,
03776    * because the flags must be inspected in order to decide which half of fUnion is being used.
03777    * We assume that the compiler does not reorder the fields.
03778    *
03779    * (Padding at the end of fFields is ok:
03780    * As long as it is no larger than fStackFields, it is not wasted space.)
03781    *
03782    * For some of the history of the UnicodeString class fields layout, see
03783    * - ICU ticket #11551 "longer UnicodeString contents in stack buffer"
03784    * - ICU ticket #11336 "UnicodeString: recombine stack buffer arrays"
03785    * - ICU ticket #8322 "why is sizeof(UnicodeString)==48?"
03786    */
03787   // (implicit) *vtable;
03788   union StackBufferOrFields {
03789     // fStackFields is used iff (fLengthAndFlags&kUsingStackBuffer) else fFields is used.
03790     // Each struct of the union must begin with fLengthAndFlags.
03791     struct {
03792       int16_t fLengthAndFlags;          // bit fields: see constants above
03793       char16_t fBuffer[US_STACKBUF_SIZE];  // buffer for short strings
03794     } fStackFields;
03795     struct {
03796       int16_t fLengthAndFlags;          // bit fields: see constants above
03797       int32_t fLength;    // number of characters in fArray if >127; else undefined
03798       int32_t fCapacity;  // capacity of fArray (in char16_ts)
03799       // array pointer last to minimize padding for machines with P128 data model
03800       // or pointer sizes that are not a power of 2
03801       char16_t   *fArray;    // the Unicode data
03802     } fFields;
03803   } fUnion;
03804 };
03805 
03814 U_COMMON_API UnicodeString U_EXPORT2
03815 operator+ (const UnicodeString &s1, const UnicodeString &s2);
03816 
03817 //========================================
03818 // Inline members
03819 //========================================
03820 
03821 //========================================
03822 // Privates
03823 //========================================
03824 
03825 inline void
03826 UnicodeString::pinIndex(int32_t& start) const
03827 {
03828   // pin index
03829   if(start < 0) {
03830     start = 0;
03831   } else if(start > length()) {
03832     start = length();
03833   }
03834 }
03835 
03836 inline void
03837 UnicodeString::pinIndices(int32_t& start,
03838                           int32_t& _length) const
03839 {
03840   // pin indices
03841   int32_t len = length();
03842   if(start < 0) {
03843     start = 0;
03844   } else if(start > len) {
03845     start = len;
03846   }
03847   if(_length < 0) {
03848     _length = 0;
03849   } else if(_length > (len - start)) {
03850     _length = (len - start);
03851   }
03852 }
03853 
03854 inline char16_t*
03855 UnicodeString::getArrayStart() {
03856   return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
03857     fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
03858 }
03859 
03860 inline const char16_t*
03861 UnicodeString::getArrayStart() const {
03862   return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
03863     fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
03864 }
03865 
03866 //========================================
03867 // Default constructor
03868 //========================================
03869 
03870 inline
03871 UnicodeString::UnicodeString() {
03872   fUnion.fStackFields.fLengthAndFlags=kShortString;
03873 }
03874 
03875 inline UnicodeString::UnicodeString(const std::nullptr_t /*text*/) {
03876   fUnion.fStackFields.fLengthAndFlags=kShortString;
03877 }
03878 
03879 inline UnicodeString::UnicodeString(const std::nullptr_t /*text*/, int32_t /*length*/) {
03880   fUnion.fStackFields.fLengthAndFlags=kShortString;
03881 }
03882 
03883 inline UnicodeString::UnicodeString(std::nullptr_t /*buffer*/, int32_t /*buffLength*/, int32_t /*buffCapacity*/) {
03884   fUnion.fStackFields.fLengthAndFlags=kShortString;
03885 }
03886 
03887 //========================================
03888 // Read-only implementation methods
03889 //========================================
03890 inline UBool
03891 UnicodeString::hasShortLength() const {
03892   return fUnion.fFields.fLengthAndFlags>=0;
03893 }
03894 
03895 inline int32_t
03896 UnicodeString::getShortLength() const {
03897   // fLengthAndFlags must be non-negative -> short length >= 0
03898   // and arithmetic or logical shift does not matter.
03899   return fUnion.fFields.fLengthAndFlags>>kLengthShift;
03900 }
03901 
03902 inline int32_t
03903 UnicodeString::length() const {
03904   return hasShortLength() ? getShortLength() : fUnion.fFields.fLength;
03905 }
03906 
03907 inline int32_t
03908 UnicodeString::getCapacity() const {
03909   return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
03910     US_STACKBUF_SIZE : fUnion.fFields.fCapacity;
03911 }
03912 
03913 inline int32_t
03914 UnicodeString::hashCode() const
03915 { return doHashCode(); }
03916 
03917 inline UBool
03918 UnicodeString::isBogus() const
03919 { return (UBool)(fUnion.fFields.fLengthAndFlags & kIsBogus); }
03920 
03921 inline UBool
03922 UnicodeString::isWritable() const
03923 { return (UBool)!(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus)); }
03924 
03925 inline UBool
03926 UnicodeString::isBufferWritable() const
03927 {
03928   return (UBool)(
03929       !(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus|kBufferIsReadonly)) &&
03930       (!(fUnion.fFields.fLengthAndFlags&kRefCounted) || refCount()==1));
03931 }
03932 
03933 inline const char16_t *
03934 UnicodeString::getBuffer() const {
03935   if(fUnion.fFields.fLengthAndFlags&(kIsBogus|kOpenGetBuffer)) {
03936     return nullptr;
03937   } else if(fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) {
03938     return fUnion.fStackFields.fBuffer;
03939   } else {
03940     return fUnion.fFields.fArray;
03941   }
03942 }
03943 
03944 //========================================
03945 // Read-only alias methods
03946 //========================================
03947 inline int8_t
03948 UnicodeString::doCompare(int32_t start,
03949               int32_t thisLength,
03950               const UnicodeString& srcText,
03951               int32_t srcStart,
03952               int32_t srcLength) const
03953 {
03954   if(srcText.isBogus()) {
03955     return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
03956   } else {
03957     srcText.pinIndices(srcStart, srcLength);
03958     return doCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
03959   }
03960 }
03961 
03962 inline UBool
03963 UnicodeString::doEqualsSubstring(int32_t start,
03964               int32_t thisLength,
03965               const UnicodeString& srcText,
03966               int32_t srcStart,
03967               int32_t srcLength) const
03968 {
03969   if(srcText.isBogus()) {
03970     return isBogus();
03971   } else {
03972     srcText.pinIndices(srcStart, srcLength);
03973     return !isBogus() && doEqualsSubstring(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
03974   }
03975 }
03976 
03977 inline bool
03978 UnicodeString::operator== (const UnicodeString& text) const
03979 {
03980   if(isBogus()) {
03981     return text.isBogus();
03982   } else {
03983     int32_t len = length(), textLength = text.length();
03984     return !text.isBogus() && len == textLength && doEquals(text, len);
03985   }
03986 }
03987 
03988 inline bool
03989 UnicodeString::operator!= (const UnicodeString& text) const
03990 { return (! operator==(text)); }
03991 
03992 inline UBool
03993 UnicodeString::operator> (const UnicodeString& text) const
03994 { return doCompare(0, length(), text, 0, text.length()) == 1; }
03995 
03996 inline UBool
03997 UnicodeString::operator< (const UnicodeString& text) const
03998 { return doCompare(0, length(), text, 0, text.length()) == -1; }
03999 
04000 inline UBool
04001 UnicodeString::operator>= (const UnicodeString& text) const
04002 { return doCompare(0, length(), text, 0, text.length()) != -1; }
04003 
04004 inline UBool
04005 UnicodeString::operator<= (const UnicodeString& text) const
04006 { return doCompare(0, length(), text, 0, text.length()) != 1; }
04007 
04008 inline int8_t
04009 UnicodeString::compare(const UnicodeString& text) const
04010 { return doCompare(0, length(), text, 0, text.length()); }
04011 
04012 inline int8_t
04013 UnicodeString::compare(int32_t start,
04014                int32_t _length,
04015                const UnicodeString& srcText) const
04016 { return doCompare(start, _length, srcText, 0, srcText.length()); }
04017 
04018 inline int8_t
04019 UnicodeString::compare(ConstChar16Ptr srcChars,
04020                int32_t srcLength) const
04021 { return doCompare(0, length(), srcChars, 0, srcLength); }
04022 
04023 inline int8_t
04024 UnicodeString::compare(int32_t start,
04025                int32_t _length,
04026                const UnicodeString& srcText,
04027                int32_t srcStart,
04028                int32_t srcLength) const
04029 { return doCompare(start, _length, srcText, srcStart, srcLength); }
04030 
04031 inline int8_t
04032 UnicodeString::compare(int32_t start,
04033                int32_t _length,
04034                const char16_t *srcChars) const
04035 { return doCompare(start, _length, srcChars, 0, _length); }
04036 
04037 inline int8_t
04038 UnicodeString::compare(int32_t start,
04039                int32_t _length,
04040                const char16_t *srcChars,
04041                int32_t srcStart,
04042                int32_t srcLength) const
04043 { return doCompare(start, _length, srcChars, srcStart, srcLength); }
04044 
04045 inline int8_t
04046 UnicodeString::compareBetween(int32_t start,
04047                   int32_t limit,
04048                   const UnicodeString& srcText,
04049                   int32_t srcStart,
04050                   int32_t srcLimit) const
04051 { return doCompare(start, limit - start,
04052            srcText, srcStart, srcLimit - srcStart); }
04053 
04054 inline int8_t
04055 UnicodeString::doCompareCodePointOrder(int32_t start,
04056                                        int32_t thisLength,
04057                                        const UnicodeString& srcText,
04058                                        int32_t srcStart,
04059                                        int32_t srcLength) const
04060 {
04061   if(srcText.isBogus()) {
04062     return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
04063   } else {
04064     srcText.pinIndices(srcStart, srcLength);
04065     return doCompareCodePointOrder(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
04066   }
04067 }
04068 
04069 inline int8_t
04070 UnicodeString::compareCodePointOrder(const UnicodeString& text) const
04071 { return doCompareCodePointOrder(0, length(), text, 0, text.length()); }
04072 
04073 inline int8_t
04074 UnicodeString::compareCodePointOrder(int32_t start,
04075                                      int32_t _length,
04076                                      const UnicodeString& srcText) const
04077 { return doCompareCodePointOrder(start, _length, srcText, 0, srcText.length()); }
04078 
04079 inline int8_t
04080 UnicodeString::compareCodePointOrder(ConstChar16Ptr srcChars,
04081                                      int32_t srcLength) const
04082 { return doCompareCodePointOrder(0, length(), srcChars, 0, srcLength); }
04083 
04084 inline int8_t
04085 UnicodeString::compareCodePointOrder(int32_t start,
04086                                      int32_t _length,
04087                                      const UnicodeString& srcText,
04088                                      int32_t srcStart,
04089                                      int32_t srcLength) const
04090 { return doCompareCodePointOrder(start, _length, srcText, srcStart, srcLength); }
04091 
04092 inline int8_t
04093 UnicodeString::compareCodePointOrder(int32_t start,
04094                                      int32_t _length,
04095                                      const char16_t *srcChars) const
04096 { return doCompareCodePointOrder(start, _length, srcChars, 0, _length); }
04097 
04098 inline int8_t
04099 UnicodeString::compareCodePointOrder(int32_t start,
04100                                      int32_t _length,
04101                                      const char16_t *srcChars,
04102                                      int32_t srcStart,
04103                                      int32_t srcLength) const
04104 { return doCompareCodePointOrder(start, _length, srcChars, srcStart, srcLength); }
04105 
04106 inline int8_t
04107 UnicodeString::compareCodePointOrderBetween(int32_t start,
04108                                             int32_t limit,
04109                                             const UnicodeString& srcText,
04110                                             int32_t srcStart,
04111                                             int32_t srcLimit) const
04112 { return doCompareCodePointOrder(start, limit - start,
04113            srcText, srcStart, srcLimit - srcStart); }
04114 
04115 inline int8_t
04116 UnicodeString::doCaseCompare(int32_t start,
04117                              int32_t thisLength,
04118                              const UnicodeString &srcText,
04119                              int32_t srcStart,
04120                              int32_t srcLength,
04121                              uint32_t options) const
04122 {
04123   if(srcText.isBogus()) {
04124     return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
04125   } else {
04126     srcText.pinIndices(srcStart, srcLength);
04127     return doCaseCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength, options);
04128   }
04129 }
04130 
04131 inline int8_t
04132 UnicodeString::caseCompare(const UnicodeString &text, uint32_t options) const {
04133   return doCaseCompare(0, length(), text, 0, text.length(), options);
04134 }
04135 
04136 inline int8_t
04137 UnicodeString::caseCompare(int32_t start,
04138                            int32_t _length,
04139                            const UnicodeString &srcText,
04140                            uint32_t options) const {
04141   return doCaseCompare(start, _length, srcText, 0, srcText.length(), options);
04142 }
04143 
04144 inline int8_t
04145 UnicodeString::caseCompare(ConstChar16Ptr srcChars,
04146                            int32_t srcLength,
04147                            uint32_t options) const {
04148   return doCaseCompare(0, length(), srcChars, 0, srcLength, options);
04149 }
04150 
04151 inline int8_t
04152 UnicodeString::caseCompare(int32_t start,
04153                            int32_t _length,
04154                            const UnicodeString &srcText,
04155                            int32_t srcStart,
04156                            int32_t srcLength,
04157                            uint32_t options) const {
04158   return doCaseCompare(start, _length, srcText, srcStart, srcLength, options);
04159 }
04160 
04161 inline int8_t
04162 UnicodeString::caseCompare(int32_t start,
04163                            int32_t _length,
04164                            const char16_t *srcChars,
04165                            uint32_t options) const {
04166   return doCaseCompare(start, _length, srcChars, 0, _length, options);
04167 }
04168 
04169 inline int8_t
04170 UnicodeString::caseCompare(int32_t start,
04171                            int32_t _length,
04172                            const char16_t *srcChars,
04173                            int32_t srcStart,
04174                            int32_t srcLength,
04175                            uint32_t options) const {
04176   return doCaseCompare(start, _length, srcChars, srcStart, srcLength, options);
04177 }
04178 
04179 inline int8_t
04180 UnicodeString::caseCompareBetween(int32_t start,
04181                                   int32_t limit,
04182                                   const UnicodeString &srcText,
04183                                   int32_t srcStart,
04184                                   int32_t srcLimit,
04185                                   uint32_t options) const {
04186   return doCaseCompare(start, limit - start, srcText, srcStart, srcLimit - srcStart, options);
04187 }
04188 
04189 inline int32_t
04190 UnicodeString::indexOf(const UnicodeString& srcText,
04191                int32_t srcStart,
04192                int32_t srcLength,
04193                int32_t start,
04194                int32_t _length) const
04195 {
04196   if(!srcText.isBogus()) {
04197     srcText.pinIndices(srcStart, srcLength);
04198     if(srcLength > 0) {
04199       return indexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
04200     }
04201   }
04202   return -1;
04203 }
04204 
04205 inline int32_t
04206 UnicodeString::indexOf(const UnicodeString& text) const
04207 { return indexOf(text, 0, text.length(), 0, length()); }
04208 
04209 inline int32_t
04210 UnicodeString::indexOf(const UnicodeString& text,
04211                int32_t start) const {
04212   pinIndex(start);
04213   return indexOf(text, 0, text.length(), start, length() - start);
04214 }
04215 
04216 inline int32_t
04217 UnicodeString::indexOf(const UnicodeString& text,
04218                int32_t start,
04219                int32_t _length) const
04220 { return indexOf(text, 0, text.length(), start, _length); }
04221 
04222 inline int32_t
04223 UnicodeString::indexOf(const char16_t *srcChars,
04224                int32_t srcLength,
04225                int32_t start) const {
04226   pinIndex(start);
04227   return indexOf(srcChars, 0, srcLength, start, length() - start);
04228 }
04229 
04230 inline int32_t
04231 UnicodeString::indexOf(ConstChar16Ptr srcChars,
04232                int32_t srcLength,
04233                int32_t start,
04234                int32_t _length) const
04235 { return indexOf(srcChars, 0, srcLength, start, _length); }
04236 
04237 inline int32_t
04238 UnicodeString::indexOf(char16_t c,
04239                int32_t start,
04240                int32_t _length) const
04241 { return doIndexOf(c, start, _length); }
04242 
04243 inline int32_t
04244 UnicodeString::indexOf(UChar32 c,
04245                int32_t start,
04246                int32_t _length) const
04247 { return doIndexOf(c, start, _length); }
04248 
04249 inline int32_t
04250 UnicodeString::indexOf(char16_t c) const
04251 { return doIndexOf(c, 0, length()); }
04252 
04253 inline int32_t
04254 UnicodeString::indexOf(UChar32 c) const
04255 { return indexOf(c, 0, length()); }
04256 
04257 inline int32_t
04258 UnicodeString::indexOf(char16_t c,
04259                int32_t start) const {
04260   pinIndex(start);
04261   return doIndexOf(c, start, length() - start);
04262 }
04263 
04264 inline int32_t
04265 UnicodeString::indexOf(UChar32 c,
04266                int32_t start) const {
04267   pinIndex(start);
04268   return indexOf(c, start, length() - start);
04269 }
04270 
04271 inline int32_t
04272 UnicodeString::lastIndexOf(ConstChar16Ptr srcChars,
04273                int32_t srcLength,
04274                int32_t start,
04275                int32_t _length) const
04276 { return lastIndexOf(srcChars, 0, srcLength, start, _length); }
04277 
04278 inline int32_t
04279 UnicodeString::lastIndexOf(const char16_t *srcChars,
04280                int32_t srcLength,
04281                int32_t start) const {
04282   pinIndex(start);
04283   return lastIndexOf(srcChars, 0, srcLength, start, length() - start);
04284 }
04285 
04286 inline int32_t
04287 UnicodeString::lastIndexOf(const UnicodeString& srcText,
04288                int32_t srcStart,
04289                int32_t srcLength,
04290                int32_t start,
04291                int32_t _length) const
04292 {
04293   if(!srcText.isBogus()) {
04294     srcText.pinIndices(srcStart, srcLength);
04295     if(srcLength > 0) {
04296       return lastIndexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
04297     }
04298   }
04299   return -1;
04300 }
04301 
04302 inline int32_t
04303 UnicodeString::lastIndexOf(const UnicodeString& text,
04304                int32_t start,
04305                int32_t _length) const
04306 { return lastIndexOf(text, 0, text.length(), start, _length); }
04307 
04308 inline int32_t
04309 UnicodeString::lastIndexOf(const UnicodeString& text,
04310                int32_t start) const {
04311   pinIndex(start);
04312   return lastIndexOf(text, 0, text.length(), start, length() - start);
04313 }
04314 
04315 inline int32_t
04316 UnicodeString::lastIndexOf(const UnicodeString& text) const
04317 { return lastIndexOf(text, 0, text.length(), 0, length()); }
04318 
04319 inline int32_t
04320 UnicodeString::lastIndexOf(char16_t c,
04321                int32_t start,
04322                int32_t _length) const
04323 { return doLastIndexOf(c, start, _length); }
04324 
04325 inline int32_t
04326 UnicodeString::lastIndexOf(UChar32 c,
04327                int32_t start,
04328                int32_t _length) const {
04329   return doLastIndexOf(c, start, _length);
04330 }
04331 
04332 inline int32_t
04333 UnicodeString::lastIndexOf(char16_t c) const
04334 { return doLastIndexOf(c, 0, length()); }
04335 
04336 inline int32_t
04337 UnicodeString::lastIndexOf(UChar32 c) const {
04338   return lastIndexOf(c, 0, length());
04339 }
04340 
04341 inline int32_t
04342 UnicodeString::lastIndexOf(char16_t c,
04343                int32_t start) const {
04344   pinIndex(start);
04345   return doLastIndexOf(c, start, length() - start);
04346 }
04347 
04348 inline int32_t
04349 UnicodeString::lastIndexOf(UChar32 c,
04350                int32_t start) const {
04351   pinIndex(start);
04352   return lastIndexOf(c, start, length() - start);
04353 }
04354 
04355 inline UBool
04356 UnicodeString::startsWith(const UnicodeString& text) const
04357 { return doEqualsSubstring(0, text.length(), text, 0, text.length()); }
04358 
04359 inline UBool
04360 UnicodeString::startsWith(const UnicodeString& srcText,
04361               int32_t srcStart,
04362               int32_t srcLength) const
04363 { return doEqualsSubstring(0, srcLength, srcText, srcStart, srcLength); }
04364 
04365 inline UBool
04366 UnicodeString::startsWith(ConstChar16Ptr srcChars, int32_t srcLength) const {
04367   if(srcLength < 0) {
04368     srcLength = u_strlen(toUCharPtr(srcChars));
04369   }
04370   return doEqualsSubstring(0, srcLength, srcChars, 0, srcLength);
04371 }
04372 
04373 inline UBool
04374 UnicodeString::startsWith(const char16_t *srcChars, int32_t srcStart, int32_t srcLength) const {
04375   if(srcLength < 0) {
04376     srcLength = u_strlen(toUCharPtr(srcChars));
04377   }
04378   return doEqualsSubstring(0, srcLength, srcChars, srcStart, srcLength);
04379 }
04380 
04381 inline UBool
04382 UnicodeString::endsWith(const UnicodeString& text) const
04383 { return doEqualsSubstring(length() - text.length(), text.length(),
04384            text, 0, text.length()); }
04385 
04386 inline UBool
04387 UnicodeString::endsWith(const UnicodeString& srcText,
04388             int32_t srcStart,
04389             int32_t srcLength) const {
04390   srcText.pinIndices(srcStart, srcLength);
04391   return doEqualsSubstring(length() - srcLength, srcLength,
04392                    srcText, srcStart, srcLength);
04393 }
04394 
04395 inline UBool
04396 UnicodeString::endsWith(ConstChar16Ptr srcChars,
04397             int32_t srcLength) const {
04398   if(srcLength < 0) {
04399     srcLength = u_strlen(toUCharPtr(srcChars));
04400   }
04401   return doEqualsSubstring(length() - srcLength, srcLength, srcChars, 0, srcLength);
04402 }
04403 
04404 inline UBool
04405 UnicodeString::endsWith(const char16_t *srcChars,
04406             int32_t srcStart,
04407             int32_t srcLength) const {
04408   if(srcLength < 0) {
04409     srcLength = u_strlen(toUCharPtr(srcChars + srcStart));
04410   }
04411   return doEqualsSubstring(length() - srcLength, srcLength,
04412                    srcChars, srcStart, srcLength);
04413 }
04414 
04415 //========================================
04416 // replace
04417 //========================================
04418 inline UnicodeString&
04419 UnicodeString::replace(int32_t start,
04420                int32_t _length,
04421                const UnicodeString& srcText)
04422 { return doReplace(start, _length, srcText, 0, srcText.length()); }
04423 
04424 inline UnicodeString&
04425 UnicodeString::replace(int32_t start,
04426                int32_t _length,
04427                const UnicodeString& srcText,
04428                int32_t srcStart,
04429                int32_t srcLength)
04430 { return doReplace(start, _length, srcText, srcStart, srcLength); }
04431 
04432 inline UnicodeString&
04433 UnicodeString::replace(int32_t start,
04434                int32_t _length,
04435                ConstChar16Ptr srcChars,
04436                int32_t srcLength)
04437 { return doReplace(start, _length, srcChars, 0, srcLength); }
04438 
04439 inline UnicodeString&
04440 UnicodeString::replace(int32_t start,
04441                int32_t _length,
04442                const char16_t *srcChars,
04443                int32_t srcStart,
04444                int32_t srcLength)
04445 { return doReplace(start, _length, srcChars, srcStart, srcLength); }
04446 
04447 inline UnicodeString&
04448 UnicodeString::replace(int32_t start,
04449                int32_t _length,
04450                char16_t srcChar)
04451 { return doReplace(start, _length, &srcChar, 0, 1); }
04452 
04453 inline UnicodeString&
04454 UnicodeString::replaceBetween(int32_t start,
04455                   int32_t limit,
04456                   const UnicodeString& srcText)
04457 { return doReplace(start, limit - start, srcText, 0, srcText.length()); }
04458 
04459 inline UnicodeString&
04460 UnicodeString::replaceBetween(int32_t start,
04461                   int32_t limit,
04462                   const UnicodeString& srcText,
04463                   int32_t srcStart,
04464                   int32_t srcLimit)
04465 { return doReplace(start, limit - start, srcText, srcStart, srcLimit - srcStart); }
04466 
04467 inline UnicodeString&
04468 UnicodeString::findAndReplace(const UnicodeString& oldText,
04469                   const UnicodeString& newText)
04470 { return findAndReplace(0, length(), oldText, 0, oldText.length(),
04471             newText, 0, newText.length()); }
04472 
04473 inline UnicodeString&
04474 UnicodeString::findAndReplace(int32_t start,
04475                   int32_t _length,
04476                   const UnicodeString& oldText,
04477                   const UnicodeString& newText)
04478 { return findAndReplace(start, _length, oldText, 0, oldText.length(),
04479             newText, 0, newText.length()); }
04480 
04481 // ============================
04482 // extract
04483 // ============================
04484 inline void
04485 UnicodeString::doExtract(int32_t start,
04486              int32_t _length,
04487              UnicodeString& target) const
04488 { target.replace(0, target.length(), *this, start, _length); }
04489 
04490 inline void
04491 UnicodeString::extract(int32_t start,
04492                int32_t _length,
04493                Char16Ptr target,
04494                int32_t targetStart) const
04495 { doExtract(start, _length, target, targetStart); }
04496 
04497 inline void
04498 UnicodeString::extract(int32_t start,
04499                int32_t _length,
04500                UnicodeString& target) const
04501 { doExtract(start, _length, target); }
04502 
04503 #if !UCONFIG_NO_CONVERSION
04504 
04505 inline int32_t
04506 UnicodeString::extract(int32_t start,
04507                int32_t _length,
04508                char *dst,
04509                const char *codepage) const
04510 
04511 {
04512   // This dstSize value will be checked explicitly
04513   return extract(start, _length, dst, dst!=0 ? 0xffffffff : 0, codepage);
04514 }
04515 
04516 #endif
04517 
04518 inline void
04519 UnicodeString::extractBetween(int32_t start,
04520                   int32_t limit,
04521                   char16_t *dst,
04522                   int32_t dstStart) const {
04523   pinIndex(start);
04524   pinIndex(limit);
04525   doExtract(start, limit - start, dst, dstStart);
04526 }
04527 
04528 inline UnicodeString
04529 UnicodeString::tempSubStringBetween(int32_t start, int32_t limit) const {
04530     return tempSubString(start, limit - start);
04531 }
04532 
04533 inline char16_t
04534 UnicodeString::doCharAt(int32_t offset) const
04535 {
04536   if((uint32_t)offset < (uint32_t)length()) {
04537     return getArrayStart()[offset];
04538   } else {
04539     return kInvalidUChar;
04540   }
04541 }
04542 
04543 inline char16_t
04544 UnicodeString::charAt(int32_t offset) const
04545 { return doCharAt(offset); }
04546 
04547 inline char16_t
04548 UnicodeString::operator[] (int32_t offset) const
04549 { return doCharAt(offset); }
04550 
04551 inline UBool
04552 UnicodeString::isEmpty() const {
04553   // Arithmetic or logical right shift does not matter: only testing for 0.
04554   return (fUnion.fFields.fLengthAndFlags>>kLengthShift) == 0;
04555 }
04556 
04557 //========================================
04558 // Write implementation methods
04559 //========================================
04560 inline void
04561 UnicodeString::setZeroLength() {
04562   fUnion.fFields.fLengthAndFlags &= kAllStorageFlags;
04563 }
04564 
04565 inline void
04566 UnicodeString::setShortLength(int32_t len) {
04567   // requires 0 <= len <= kMaxShortLength
04568   fUnion.fFields.fLengthAndFlags =
04569     (int16_t)((fUnion.fFields.fLengthAndFlags & kAllStorageFlags) | (len << kLengthShift));
04570 }
04571 
04572 inline void
04573 UnicodeString::setLength(int32_t len) {
04574   if(len <= kMaxShortLength) {
04575     setShortLength(len);
04576   } else {
04577     fUnion.fFields.fLengthAndFlags |= kLengthIsLarge;
04578     fUnion.fFields.fLength = len;
04579   }
04580 }
04581 
04582 inline void
04583 UnicodeString::setToEmpty() {
04584   fUnion.fFields.fLengthAndFlags = kShortString;
04585 }
04586 
04587 inline void
04588 UnicodeString::setArray(char16_t *array, int32_t len, int32_t capacity) {
04589   setLength(len);
04590   fUnion.fFields.fArray = array;
04591   fUnion.fFields.fCapacity = capacity;
04592 }
04593 
04594 inline UnicodeString&
04595 UnicodeString::operator= (char16_t ch)
04596 { return doReplace(0, length(), &ch, 0, 1); }
04597 
04598 inline UnicodeString&
04599 UnicodeString::operator= (UChar32 ch)
04600 { return replace(0, length(), ch); }
04601 
04602 inline UnicodeString&
04603 UnicodeString::setTo(const UnicodeString& srcText,
04604              int32_t srcStart,
04605              int32_t srcLength)
04606 {
04607   unBogus();
04608   return doReplace(0, length(), srcText, srcStart, srcLength);
04609 }
04610 
04611 inline UnicodeString&
04612 UnicodeString::setTo(const UnicodeString& srcText,
04613              int32_t srcStart)
04614 {
04615   unBogus();
04616   srcText.pinIndex(srcStart);
04617   return doReplace(0, length(), srcText, srcStart, srcText.length() - srcStart);
04618 }
04619 
04620 inline UnicodeString&
04621 UnicodeString::setTo(const UnicodeString& srcText)
04622 {
04623   return copyFrom(srcText);
04624 }
04625 
04626 inline UnicodeString&
04627 UnicodeString::setTo(const char16_t *srcChars,
04628              int32_t srcLength)
04629 {
04630   unBogus();
04631   return doReplace(0, length(), srcChars, 0, srcLength);
04632 }
04633 
04634 inline UnicodeString&
04635 UnicodeString::setTo(char16_t srcChar)
04636 {
04637   unBogus();
04638   return doReplace(0, length(), &srcChar, 0, 1);
04639 }
04640 
04641 inline UnicodeString&
04642 UnicodeString::setTo(UChar32 srcChar)
04643 {
04644   unBogus();
04645   return replace(0, length(), srcChar);
04646 }
04647 
04648 inline UnicodeString&
04649 UnicodeString::append(const UnicodeString& srcText,
04650               int32_t srcStart,
04651               int32_t srcLength)
04652 { return doAppend(srcText, srcStart, srcLength); }
04653 
04654 inline UnicodeString&
04655 UnicodeString::append(const UnicodeString& srcText)
04656 { return doAppend(srcText, 0, srcText.length()); }
04657 
04658 inline UnicodeString&
04659 UnicodeString::append(const char16_t *srcChars,
04660               int32_t srcStart,
04661               int32_t srcLength)
04662 { return doAppend(srcChars, srcStart, srcLength); }
04663 
04664 inline UnicodeString&
04665 UnicodeString::append(ConstChar16Ptr srcChars,
04666               int32_t srcLength)
04667 { return doAppend(srcChars, 0, srcLength); }
04668 
04669 inline UnicodeString&
04670 UnicodeString::append(char16_t srcChar)
04671 { return doAppend(&srcChar, 0, 1); }
04672 
04673 inline UnicodeString&
04674 UnicodeString::operator+= (char16_t ch)
04675 { return doAppend(&ch, 0, 1); }
04676 
04677 inline UnicodeString&
04678 UnicodeString::operator+= (UChar32 ch) {
04679   return append(ch);
04680 }
04681 
04682 inline UnicodeString&
04683 UnicodeString::operator+= (const UnicodeString& srcText)
04684 { return doAppend(srcText, 0, srcText.length()); }
04685 
04686 inline UnicodeString&
04687 UnicodeString::insert(int32_t start,
04688               const UnicodeString& srcText,
04689               int32_t srcStart,
04690               int32_t srcLength)
04691 { return doReplace(start, 0, srcText, srcStart, srcLength); }
04692 
04693 inline UnicodeString&
04694 UnicodeString::insert(int32_t start,
04695               const UnicodeString& srcText)
04696 { return doReplace(start, 0, srcText, 0, srcText.length()); }
04697 
04698 inline UnicodeString&
04699 UnicodeString::insert(int32_t start,
04700               const char16_t *srcChars,
04701               int32_t srcStart,
04702               int32_t srcLength)
04703 { return doReplace(start, 0, srcChars, srcStart, srcLength); }
04704 
04705 inline UnicodeString&
04706 UnicodeString::insert(int32_t start,
04707               ConstChar16Ptr srcChars,
04708               int32_t srcLength)
04709 { return doReplace(start, 0, srcChars, 0, srcLength); }
04710 
04711 inline UnicodeString&
04712 UnicodeString::insert(int32_t start,
04713               char16_t srcChar)
04714 { return doReplace(start, 0, &srcChar, 0, 1); }
04715 
04716 inline UnicodeString&
04717 UnicodeString::insert(int32_t start,
04718               UChar32 srcChar)
04719 { return replace(start, 0, srcChar); }
04720 
04721 
04722 inline UnicodeString&
04723 UnicodeString::remove()
04724 {
04725   // remove() of a bogus string makes the string empty and non-bogus
04726   if(isBogus()) {
04727     setToEmpty();
04728   } else {
04729     setZeroLength();
04730   }
04731   return *this;
04732 }
04733 
04734 inline UnicodeString&
04735 UnicodeString::remove(int32_t start,
04736              int32_t _length)
04737 {
04738     if(start <= 0 && _length == INT32_MAX) {
04739         // remove(guaranteed everything) of a bogus string makes the string empty and non-bogus
04740         return remove();
04741     }
04742     return doReplace(start, _length, nullptr, 0, 0);
04743 }
04744 
04745 inline UnicodeString&
04746 UnicodeString::removeBetween(int32_t start,
04747                 int32_t limit)
04748 { return doReplace(start, limit - start, nullptr, 0, 0); }
04749 
04750 inline UnicodeString &
04751 UnicodeString::retainBetween(int32_t start, int32_t limit) {
04752   truncate(limit);
04753   return doReplace(0, start, nullptr, 0, 0);
04754 }
04755 
04756 inline UBool
04757 UnicodeString::truncate(int32_t targetLength)
04758 {
04759   if(isBogus() && targetLength == 0) {
04760     // truncate(0) of a bogus string makes the string empty and non-bogus
04761     unBogus();
04762     return false;
04763   } else if((uint32_t)targetLength < (uint32_t)length()) {
04764     setLength(targetLength);
04765     return true;
04766   } else {
04767     return false;
04768   }
04769 }
04770 
04771 inline UnicodeString&
04772 UnicodeString::reverse()
04773 { return doReverse(0, length()); }
04774 
04775 inline UnicodeString&
04776 UnicodeString::reverse(int32_t start,
04777                int32_t _length)
04778 { return doReverse(start, _length); }
04779 
04780 U_NAMESPACE_END
04781 
04782 #endif /* U_SHOW_CPLUSPLUS_API */
04783 
04784 #endif