Home | History | Annotate | Download | only in unicode
      1 // Copyright (C) 2016 and later: Unicode, Inc. and others.
      2 // License & terms of use: http://www.unicode.org/copyright.html
      3 /*
      4 **********************************************************************
      5 *   Copyright (C) 1998-2016, International Business Machines
      6 *   Corporation and others.  All Rights Reserved.
      7 **********************************************************************
      8 *
      9 * File unistr.h
     10 *
     11 * Modification History:
     12 *
     13 *   Date        Name        Description
     14 *   09/25/98    stephen     Creation.
     15 *   11/11/98    stephen     Changed per 11/9 code review.
     16 *   04/20/99    stephen     Overhauled per 4/16 code review.
     17 *   11/18/99    aliu        Made to inherit from Replaceable.  Added method
     18 *                           handleReplaceBetween(); other methods unchanged.
     19 *   06/25/01    grhoten     Remove dependency on iostream.
     20 ******************************************************************************
     21 */
     22 
     23 #ifndef UNISTR_H
     24 #define UNISTR_H
     25 
     26 /**
     27  * \file
     28  * \brief C++ API: Unicode String
     29  */
     30 
     31 #include "unicode/utypes.h"
     32 #include "unicode/rep.h"
     33 #include "unicode/std_string.h"
     34 #include "unicode/stringpiece.h"
     35 #include "unicode/bytestream.h"
     36 #include "unicode/ucasemap.h"
     37 
     38 struct UConverter;          // unicode/ucnv.h
     39 
     40 #ifndef U_COMPARE_CODE_POINT_ORDER
     41 /* see also ustring.h and unorm.h */
     42 /**
     43  * Option bit for u_strCaseCompare, u_strcasecmp, unorm_compare, etc:
     44  * Compare strings in code point order instead of code unit order.
     45  * @stable ICU 2.2
     46  */
     47 #define U_COMPARE_CODE_POINT_ORDER  0x8000
     48 #endif
     49 
     50 #ifndef USTRING_H
     51 /**
     52  * \ingroup ustring_ustrlen
     53  */
     54 U_STABLE int32_t U_EXPORT2
     55 u_strlen(const UChar *s);
     56 #endif
     57 
     58 /**
     59  * \def U_STRING_CASE_MAPPER_DEFINED
     60  * @internal
     61  */
     62 #ifndef U_STRING_CASE_MAPPER_DEFINED
     63 #define U_STRING_CASE_MAPPER_DEFINED
     64 
     65 /**
     66  * Internal string case mapping function type.
     67  * @internal
     68  */
     69 typedef int32_t U_CALLCONV
     70 UStringCaseMapper(const UCaseMap *csm,
     71                   UChar *dest, int32_t destCapacity,
     72                   const UChar *src, int32_t srcLength,
     73                   UErrorCode *pErrorCode);
     74 
     75 #endif
     76 
     77 U_NAMESPACE_BEGIN
     78 
     79 #if !UCONFIG_NO_BREAK_ITERATION
     80 class BreakIterator;        // unicode/brkiter.h
     81 #endif
     82 class Locale;               // unicode/locid.h
     83 class StringCharacterIterator;
     84 class UnicodeStringAppendable;  // unicode/appendable.h
     85 
     86 /* The <iostream> include has been moved to unicode/ustream.h */
     87 
     88 /**
     89  * Constant to be used in the UnicodeString(char *, int32_t, EInvariant) constructor
     90  * which constructs a Unicode string from an invariant-character char * string.
     91  * About invariant characters see utypes.h.
     92  * This constructor has no runtime dependency on conversion code and is
     93  * therefore recommended over ones taking a charset name string
     94  * (where the empty string "" indicates invariant-character conversion).
     95  *
     96  * @stable ICU 3.2
     97  */
     98 #define US_INV icu::UnicodeString::kInvariant
     99 
    100 /**
    101  * Unicode String literals in C++.
    102  * Dependent on the platform properties, different UnicodeString
    103  * constructors should be used to create a UnicodeString object from
    104  * a string literal.
    105  * The macros are defined for maximum performance.
    106  * They work only for strings that contain "invariant characters", i.e.,
    107  * only latin letters, digits, and some punctuation.
    108  * See utypes.h for details.
    109  *
    110  * The string parameter must be a C string literal.
    111  * The length of the string, not including the terminating
    112  * <code>NUL</code>, must be specified as a constant.
    113  * The U_STRING_DECL macro should be invoked exactly once for one
    114  * such string variable before it is used.
    115  * @stable ICU 2.0
    116  */
    117 #if defined(U_DECLARE_UTF16)
    118 #   define UNICODE_STRING(cs, _length) icu::UnicodeString(TRUE, (const UChar *)U_DECLARE_UTF16(cs), _length)
    119 #elif U_SIZEOF_WCHAR_T==U_SIZEOF_UCHAR && (U_CHARSET_FAMILY==U_ASCII_FAMILY || (U_SIZEOF_UCHAR == 2 && defined(U_WCHAR_IS_UTF16)))
    120 #   define UNICODE_STRING(cs, _length) icu::UnicodeString(TRUE, (const UChar *)L ## cs, _length)
    121 #elif U_SIZEOF_UCHAR==1 && U_CHARSET_FAMILY==U_ASCII_FAMILY
    122 #   define UNICODE_STRING(cs, _length) icu::UnicodeString(TRUE, (const UChar *)cs, _length)
    123 #else
    124 #   define UNICODE_STRING(cs, _length) icu::UnicodeString(cs, _length, US_INV)
    125 #endif
    126 
    127 /**
    128  * Unicode String literals in C++.
    129  * Dependent on the platform properties, different UnicodeString
    130  * constructors should be used to create a UnicodeString object from
    131  * a string literal.
    132  * The macros are defined for improved performance.
    133  * They work only for strings that contain "invariant characters", i.e.,
    134  * only latin letters, digits, and some punctuation.
    135  * See utypes.h for details.
    136  *
    137  * The string parameter must be a C string literal.
    138  * @stable ICU 2.0
    139  */
    140 #define UNICODE_STRING_SIMPLE(cs) UNICODE_STRING(cs, -1)
    141 
    142 /**
    143  * \def UNISTR_FROM_CHAR_EXPLICIT
    144  * This can be defined to be empty or "explicit".
    145  * If explicit, then the UnicodeString(UChar) and UnicodeString(UChar32)
    146  * constructors are marked as explicit, preventing their inadvertent use.
    147  * @stable ICU 49
    148  */
    149 #ifndef UNISTR_FROM_CHAR_EXPLICIT
    150 # if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION)
    151     // Auto-"explicit" in ICU library code.
    152 #   define UNISTR_FROM_CHAR_EXPLICIT explicit
    153 # else
    154     // Empty by default for source code compatibility.
    155 #   define UNISTR_FROM_CHAR_EXPLICIT
    156 # endif
    157 #endif
    158 
    159 /**
    160  * \def UNISTR_FROM_STRING_EXPLICIT
    161  * This can be defined to be empty or "explicit".
    162  * If explicit, then the UnicodeString(const char *) and UnicodeString(const UChar *)
    163  * constructors are marked as explicit, preventing their inadvertent use.
    164  *
    165  * In particular, this helps prevent accidentally depending on ICU conversion code
    166  * by passing a string literal into an API with a const UnicodeString & parameter.
    167  * @stable ICU 49
    168  */
    169 #ifndef UNISTR_FROM_STRING_EXPLICIT
    170 # if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION)
    171     // Auto-"explicit" in ICU library code.
    172 #   define UNISTR_FROM_STRING_EXPLICIT explicit
    173 # else
    174     // Empty by default for source code compatibility.
    175 #   define UNISTR_FROM_STRING_EXPLICIT
    176 # endif
    177 #endif
    178 
    179 /**
    180  * \def UNISTR_OBJECT_SIZE
    181  * Desired sizeof(UnicodeString) in bytes.
    182  * It should be a multiple of sizeof(pointer) to avoid unusable space for padding.
    183  * The object size may want to be a multiple of 16 bytes,
    184  * which is a common granularity for heap allocation.
    185  *
    186  * Any space inside the object beyond sizeof(vtable pointer) + 2
    187  * is available for storing short strings inside the object.
    188  * The bigger the object, the longer a string that can be stored inside the object,
    189  * without additional heap allocation.
    190  *
    191  * Depending on a platform's pointer size, pointer alignment requirements,
    192  * and struct padding, the compiler will usually round up sizeof(UnicodeString)
    193  * to 4 * sizeof(pointer) (or 3 * sizeof(pointer) for P128 data models),
    194  * to hold the fields for heap-allocated strings.
    195  * Such a minimum size also ensures that the object is easily large enough
    196  * to hold at least 2 UChars, for one supplementary code point (U16_MAX_LENGTH).
    197  *
    198  * sizeof(UnicodeString) >= 48 should work for all known platforms.
    199  *
    200  * For example, on a 64-bit machine where sizeof(vtable pointer) is 8,
    201  * sizeof(UnicodeString) = 64 would leave space for
    202  * (64 - sizeof(vtable pointer) - 2) / U_SIZEOF_UCHAR = (64 - 8 - 2) / 2 = 27
    203  * UChars stored inside the object.
    204  *
    205  * The minimum object size on a 64-bit machine would be
    206  * 4 * sizeof(pointer) = 4 * 8 = 32 bytes,
    207  * and the internal buffer would hold up to 11 UChars in that case.
    208  *
    209  * @see U16_MAX_LENGTH
    210  * @stable ICU 56
    211  */
    212 #ifndef UNISTR_OBJECT_SIZE
    213 # define UNISTR_OBJECT_SIZE 64
    214 #endif
    215 
    216 /**
    217  * UnicodeString is a string class that stores Unicode characters directly and provides
    218  * similar functionality as the Java String and StringBuffer/StringBuilder classes.
    219  * It is a concrete implementation of the abstract class Replaceable (for transliteration).
    220  *
    221  * A UnicodeString may also "alias" an external array of characters
    222  * (that is, point to it, rather than own the array)
    223  * whose lifetime must then at least match the lifetime of the aliasing object.
    224  * This aliasing may be preserved when returning a UnicodeString by value,
    225  * depending on the compiler and the function implementation,
    226  * via Return Value Optimization (RVO) or the move assignment operator.
    227  * (However, the copy assignment operator does not preserve aliasing.)
    228  * For details see the description of storage models at the end of the class API docs
    229  * and in the User Guide chapter linked from there.
    230  *
    231  * The UnicodeString class is not suitable for subclassing.
    232  *
    233  * <p>For an overview of Unicode strings in C and C++ see the
    234  * <a href="http://userguide.icu-project.org/strings#TOC-Strings-in-C-C-">User Guide Strings chapter</a>.</p>
    235  *
    236  * <p>In ICU, a Unicode string consists of 16-bit Unicode <em>code units</em>.
    237  * A Unicode character may be stored with either one code unit
    238  * (the most common case) or with a matched pair of special code units
    239  * ("surrogates"). The data type for code units is UChar.
    240  * For single-character handling, a Unicode character code <em>point</em> is a value
    241  * in the range 0..0x10ffff. ICU uses the UChar32 type for code points.</p>
    242  *
    243  * <p>Indexes and offsets into and lengths of strings always count code units, not code points.
    244  * This is the same as with multi-byte char* strings in traditional string handling.
    245  * Operations on partial strings typically do not test for code point boundaries.
    246  * If necessary, the user needs to take care of such boundaries by testing for the code unit
    247  * values or by using functions like
    248  * UnicodeString::getChar32Start() and UnicodeString::getChar32Limit()
    249  * (or, in C, the equivalent macros U16_SET_CP_START() and U16_SET_CP_LIMIT(), see utf.h).</p>
    250  *
    251  * UnicodeString methods are more lenient with regard to input parameter values
    252  * than other ICU APIs. In particular:
    253  * - If indexes are out of bounds for a UnicodeString object
    254  *   (<0 or >length()) then they are "pinned" to the nearest boundary.
    255  * - If primitive string pointer values (e.g., const UChar * or char *)
    256  *   for input strings are NULL, then those input string parameters are treated
    257  *   as if they pointed to an empty string.
    258  *   However, this is <em>not</em> the case for char * parameters for charset names
    259  *   or other IDs.
    260  * - Most UnicodeString methods do not take a UErrorCode parameter because
    261  *   there are usually very few opportunities for failure other than a shortage
    262  *   of memory, error codes in low-level C++ string methods would be inconvenient,
    263  *   and the error code as the last parameter (ICU convention) would prevent
    264  *   the use of default parameter values.
    265  *   Instead, such methods set the UnicodeString into a "bogus" state
    266  *   (see isBogus()) if an error occurs.
    267  *
    268  * In string comparisons, two UnicodeString objects that are both "bogus"
    269  * compare equal (to be transitive and prevent endless loops in sorting),
    270  * and a "bogus" string compares less than any non-"bogus" one.
    271  *
    272  * Const UnicodeString methods are thread-safe. Multiple threads can use
    273  * const methods on the same UnicodeString object simultaneously,
    274  * but non-const methods must not be called concurrently (in multiple threads)
    275  * with any other (const or non-const) methods.
    276  *
    277  * Similarly, const UnicodeString & parameters are thread-safe.
    278  * One object may be passed in as such a parameter concurrently in multiple threads.
    279  * This includes the const UnicodeString & parameters for
    280  * copy construction, assignment, and cloning.
    281  *
    282  * <p>UnicodeString uses several storage methods.
    283  * String contents can be stored inside the UnicodeString object itself,
    284  * in an allocated and shared buffer, or in an outside buffer that is "aliased".
    285  * Most of this is done transparently, but careful aliasing in particular provides
    286  * significant performance improvements.
    287  * Also, the internal buffer is accessible via special functions.
    288  * For details see the
    289  * <a href="http://userguide.icu-project.org/strings#TOC-Maximizing-Performance-with-the-UnicodeString-Storage-Model">User Guide Strings chapter</a>.</p>
    290  *
    291  * @see utf.h
    292  * @see CharacterIterator
    293  * @stable ICU 2.0
    294  */
    295 class U_COMMON_API UnicodeString : public Replaceable
    296 {
    297 public:
    298 
    299   /**
    300    * Constant to be used in the UnicodeString(char *, int32_t, EInvariant) constructor
    301    * which constructs a Unicode string from an invariant-character char * string.
    302    * Use the macro US_INV instead of the full qualification for this value.
    303    *
    304    * @see US_INV
    305    * @stable ICU 3.2
    306    */
    307   enum EInvariant {
    308     /**
    309      * @see EInvariant
    310      * @stable ICU 3.2
    311      */
    312     kInvariant
    313   };
    314 
    315   //========================================
    316   // Read-only operations
    317   //========================================
    318 
    319   /* Comparison - bitwise only - for international comparison use collation */
    320 
    321   /**
    322    * Equality operator. Performs only bitwise comparison.
    323    * @param text The UnicodeString to compare to this one.
    324    * @return TRUE if <TT>text</TT> contains the same characters as this one,
    325    * FALSE otherwise.
    326    * @stable ICU 2.0
    327    */
    328   inline UBool operator== (const UnicodeString& text) const;
    329 
    330   /**
    331    * Inequality operator. Performs only bitwise comparison.
    332    * @param text The UnicodeString to compare to this one.
    333    * @return FALSE if <TT>text</TT> contains the same characters as this one,
    334    * TRUE otherwise.
    335    * @stable ICU 2.0
    336    */
    337   inline UBool operator!= (const UnicodeString& text) const;
    338 
    339   /**
    340    * Greater than operator. Performs only bitwise comparison.
    341    * @param text The UnicodeString to compare to this one.
    342    * @return TRUE if the characters in this are bitwise
    343    * greater than the characters in <code>text</code>, FALSE otherwise
    344    * @stable ICU 2.0
    345    */
    346   inline UBool operator> (const UnicodeString& text) const;
    347 
    348   /**
    349    * Less than operator. Performs only bitwise comparison.
    350    * @param text The UnicodeString to compare to this one.
    351    * @return TRUE if the characters in this are bitwise
    352    * less than the characters in <code>text</code>, FALSE otherwise
    353    * @stable ICU 2.0
    354    */
    355   inline UBool operator< (const UnicodeString& text) const;
    356 
    357   /**
    358    * Greater than or equal operator. Performs only bitwise comparison.
    359    * @param text The UnicodeString to compare to this one.
    360    * @return TRUE if the characters in this are bitwise
    361    * greater than or equal to the characters in <code>text</code>, FALSE otherwise
    362    * @stable ICU 2.0
    363    */
    364   inline UBool operator>= (const UnicodeString& text) const;
    365 
    366   /**
    367    * Less than or equal operator. Performs only bitwise comparison.
    368    * @param text The UnicodeString to compare to this one.
    369    * @return TRUE if the characters in this are bitwise
    370    * less than or equal to the characters in <code>text</code>, FALSE otherwise
    371    * @stable ICU 2.0
    372    */
    373   inline UBool operator<= (const UnicodeString& text) const;
    374 
    375   /**
    376    * Compare the characters bitwise in this UnicodeString to
    377    * the characters in <code>text</code>.
    378    * @param text The UnicodeString to compare to this one.
    379    * @return The result of bitwise character comparison: 0 if this
    380    * contains the same characters as <code>text</code>, -1 if the characters in
    381    * this are bitwise less than the characters in <code>text</code>, +1 if the
    382    * characters in this are bitwise greater than the characters
    383    * in <code>text</code>.
    384    * @stable ICU 2.0
    385    */
    386   inline int8_t compare(const UnicodeString& text) const;
    387 
    388   /**
    389    * Compare the characters bitwise in the range
    390    * [<TT>start</TT>, <TT>start + length</TT>) with the characters
    391    * in the <b>entire string</b> <TT>text</TT>.
    392    * (The parameters "start" and "length" are not applied to the other text "text".)
    393    * @param start the offset at which the compare operation begins
    394    * @param length the number of characters of text to compare.
    395    * @param text the other text to be compared against this string.
    396    * @return The result of bitwise character comparison: 0 if this
    397    * contains the same characters as <code>text</code>, -1 if the characters in
    398    * this are bitwise less than the characters in <code>text</code>, +1 if the
    399    * characters in this are bitwise greater than the characters
    400    * in <code>text</code>.
    401    * @stable ICU 2.0
    402    */
    403   inline int8_t compare(int32_t start,
    404          int32_t length,
    405          const UnicodeString& text) const;
    406 
    407   /**
    408    * Compare the characters bitwise in the range
    409    * [<TT>start</TT>, <TT>start + length</TT>) with the characters
    410    * in <TT>srcText</TT> in the range
    411    * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
    412    * @param start the offset at which the compare operation begins
    413    * @param length the number of characters in this to compare.
    414    * @param srcText the text to be compared
    415    * @param srcStart the offset into <TT>srcText</TT> to start comparison
    416    * @param srcLength the number of characters in <TT>src</TT> to compare
    417    * @return The result of bitwise character comparison: 0 if this
    418    * contains the same characters as <code>srcText</code>, -1 if the characters in
    419    * this are bitwise less than the characters in <code>srcText</code>, +1 if the
    420    * characters in this are bitwise greater than the characters
    421    * in <code>srcText</code>.
    422    * @stable ICU 2.0
    423    */
    424    inline int8_t compare(int32_t start,
    425          int32_t length,
    426          const UnicodeString& srcText,
    427          int32_t srcStart,
    428          int32_t srcLength) const;
    429 
    430   /**
    431    * Compare the characters bitwise in this UnicodeString with the first
    432    * <TT>srcLength</TT> characters in <TT>srcChars</TT>.
    433    * @param srcChars The characters to compare to this UnicodeString.
    434    * @param srcLength the number of characters in <TT>srcChars</TT> to compare
    435    * @return The result of bitwise character comparison: 0 if this
    436    * contains the same characters as <code>srcChars</code>, -1 if the characters in
    437    * this are bitwise less than the characters in <code>srcChars</code>, +1 if the
    438    * characters in this are bitwise greater than the characters
    439    * in <code>srcChars</code>.
    440    * @stable ICU 2.0
    441    */
    442   inline int8_t compare(const UChar *srcChars,
    443          int32_t srcLength) const;
    444 
    445   /**
    446    * Compare the characters bitwise in the range
    447    * [<TT>start</TT>, <TT>start + length</TT>) with the first
    448    * <TT>length</TT> characters in <TT>srcChars</TT>
    449    * @param start the offset at which the compare operation begins
    450    * @param length the number of characters to compare.
    451    * @param srcChars the characters to be compared
    452    * @return The result of bitwise character comparison: 0 if this
    453    * contains the same characters as <code>srcChars</code>, -1 if the characters in
    454    * this are bitwise less than the characters in <code>srcChars</code>, +1 if the
    455    * characters in this are bitwise greater than the characters
    456    * in <code>srcChars</code>.
    457    * @stable ICU 2.0
    458    */
    459   inline int8_t compare(int32_t start,
    460          int32_t length,
    461          const UChar *srcChars) const;
    462 
    463   /**
    464    * Compare the characters bitwise in the range
    465    * [<TT>start</TT>, <TT>start + length</TT>) with the characters
    466    * in <TT>srcChars</TT> in the range
    467    * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
    468    * @param start the offset at which the compare operation begins
    469    * @param length the number of characters in this to compare
    470    * @param srcChars the characters to be compared
    471    * @param srcStart the offset into <TT>srcChars</TT> to start comparison
    472    * @param srcLength the number of characters in <TT>srcChars</TT> to compare
    473    * @return The result of bitwise character comparison: 0 if this
    474    * contains the same characters as <code>srcChars</code>, -1 if the characters in
    475    * this are bitwise less than the characters in <code>srcChars</code>, +1 if the
    476    * characters in this are bitwise greater than the characters
    477    * in <code>srcChars</code>.
    478    * @stable ICU 2.0
    479    */
    480   inline int8_t compare(int32_t start,
    481          int32_t length,
    482          const UChar *srcChars,
    483          int32_t srcStart,
    484          int32_t srcLength) const;
    485 
    486   /**
    487    * Compare the characters bitwise in the range
    488    * [<TT>start</TT>, <TT>limit</TT>) with the characters
    489    * in <TT>srcText</TT> in the range
    490    * [<TT>srcStart</TT>, <TT>srcLimit</TT>).
    491    * @param start the offset at which the compare operation begins
    492    * @param limit the offset immediately following the compare operation
    493    * @param srcText the text to be compared
    494    * @param srcStart the offset into <TT>srcText</TT> to start comparison
    495    * @param srcLimit the offset into <TT>srcText</TT> to limit comparison
    496    * @return The result of bitwise character comparison: 0 if this
    497    * contains the same characters as <code>srcText</code>, -1 if the characters in
    498    * this are bitwise less than the characters in <code>srcText</code>, +1 if the
    499    * characters in this are bitwise greater than the characters
    500    * in <code>srcText</code>.
    501    * @stable ICU 2.0
    502    */
    503   inline int8_t compareBetween(int32_t start,
    504             int32_t limit,
    505             const UnicodeString& srcText,
    506             int32_t srcStart,
    507             int32_t srcLimit) const;
    508 
    509   /**
    510    * Compare two Unicode strings in code point order.
    511    * The result may be different from the results of compare(), operator<, etc.
    512    * if supplementary characters are present:
    513    *
    514    * In UTF-16, supplementary characters (with code points U+10000 and above) are
    515    * stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff,
    516    * which means that they compare as less than some other BMP characters like U+feff.
    517    * This function compares Unicode strings in code point order.
    518    * If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.
    519    *
    520    * @param text Another string to compare this one to.
    521    * @return a negative/zero/positive integer corresponding to whether
    522    * this string is less than/equal to/greater than the second one
    523    * in code point order
    524    * @stable ICU 2.0
    525    */
    526   inline int8_t compareCodePointOrder(const UnicodeString& text) const;
    527 
    528   /**
    529    * Compare two Unicode strings in code point order.
    530    * The result may be different from the results of compare(), operator<, etc.
    531    * if supplementary characters are present:
    532    *
    533    * In UTF-16, supplementary characters (with code points U+10000 and above) are
    534    * stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff,
    535    * which means that they compare as less than some other BMP characters like U+feff.
    536    * This function compares Unicode strings in code point order.
    537    * If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.
    538    *
    539    * @param start The start offset in this string at which the compare operation begins.
    540    * @param length The number of code units from this string to compare.
    541    * @param srcText Another string to compare this one to.
    542    * @return a negative/zero/positive integer corresponding to whether
    543    * this string is less than/equal to/greater than the second one
    544    * in code point order
    545    * @stable ICU 2.0
    546    */
    547   inline int8_t compareCodePointOrder(int32_t start,
    548                                       int32_t length,
    549                                       const UnicodeString& srcText) const;
    550 
    551   /**
    552    * Compare two Unicode strings in code point order.
    553    * The result may be different from the results of compare(), operator<, etc.
    554    * if supplementary characters are present:
    555    *
    556    * In UTF-16, supplementary characters (with code points U+10000 and above) are
    557    * stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff,
    558    * which means that they compare as less than some other BMP characters like U+feff.
    559    * This function compares Unicode strings in code point order.
    560    * If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.
    561    *
    562    * @param start The start offset in this string at which the compare operation begins.
    563    * @param length The number of code units from this string to compare.
    564    * @param srcText Another string to compare this one to.
    565    * @param srcStart The start offset in that string at which the compare operation begins.
    566    * @param srcLength The number of code units from that string to compare.
    567    * @return a negative/zero/positive integer corresponding to whether
    568    * this string is less than/equal to/greater than the second one
    569    * in code point order
    570    * @stable ICU 2.0
    571    */
    572    inline int8_t compareCodePointOrder(int32_t start,
    573                                        int32_t length,
    574                                        const UnicodeString& srcText,
    575                                        int32_t srcStart,
    576                                        int32_t srcLength) const;
    577 
    578   /**
    579    * Compare two Unicode strings in code point order.
    580    * The result may be different from the results of compare(), operator<, etc.
    581    * if supplementary characters are present:
    582    *
    583    * In UTF-16, supplementary characters (with code points U+10000 and above) are
    584    * stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff,
    585    * which means that they compare as less than some other BMP characters like U+feff.
    586    * This function compares Unicode strings in code point order.
    587    * If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.
    588    *
    589    * @param srcChars A pointer to another string to compare this one to.
    590    * @param srcLength The number of code units from that string to compare.
    591    * @return a negative/zero/positive integer corresponding to whether
    592    * this string is less than/equal to/greater than the second one
    593    * in code point order
    594    * @stable ICU 2.0
    595    */
    596   inline int8_t compareCodePointOrder(const UChar *srcChars,
    597                                       int32_t srcLength) const;
    598 
    599   /**
    600    * Compare two Unicode strings in code point order.
    601    * The result may be different from the results of compare(), operator<, etc.
    602    * if supplementary characters are present:
    603    *
    604    * In UTF-16, supplementary characters (with code points U+10000 and above) are
    605    * stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff,
    606    * which means that they compare as less than some other BMP characters like U+feff.
    607    * This function compares Unicode strings in code point order.
    608    * If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.
    609    *
    610    * @param start The start offset in this string at which the compare operation begins.
    611    * @param length The number of code units from this string to compare.
    612    * @param srcChars A pointer to another string to compare this one to.
    613    * @return a negative/zero/positive integer corresponding to whether
    614    * this string is less than/equal to/greater than the second one
    615    * in code point order
    616    * @stable ICU 2.0
    617    */
    618   inline int8_t compareCodePointOrder(int32_t start,
    619                                       int32_t length,
    620                                       const UChar *srcChars) const;
    621 
    622   /**
    623    * Compare two Unicode strings in code point order.
    624    * The result may be different from the results of compare(), operator<, etc.
    625    * if supplementary characters are present:
    626    *
    627    * In UTF-16, supplementary characters (with code points U+10000 and above) are
    628    * stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff,
    629    * which means that they compare as less than some other BMP characters like U+feff.
    630    * This function compares Unicode strings in code point order.
    631    * If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.
    632    *
    633    * @param start The start offset in this string at which the compare operation begins.
    634    * @param length The number of code units from this string to compare.
    635    * @param srcChars A pointer to another string to compare this one to.
    636    * @param srcStart The start offset in that string at which the compare operation begins.
    637    * @param srcLength The number of code units from that string to compare.
    638    * @return a negative/zero/positive integer corresponding to whether
    639    * this string is less than/equal to/greater than the second one
    640    * in code point order
    641    * @stable ICU 2.0
    642    */
    643   inline int8_t compareCodePointOrder(int32_t start,
    644                                       int32_t length,
    645                                       const UChar *srcChars,
    646                                       int32_t srcStart,
    647                                       int32_t srcLength) const;
    648 
    649   /**
    650    * Compare two Unicode strings in code point order.
    651    * The result may be different from the results of compare(), operator<, etc.
    652    * if supplementary characters are present:
    653    *
    654    * In UTF-16, supplementary characters (with code points U+10000 and above) are
    655    * stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff,
    656    * which means that they compare as less than some other BMP characters like U+feff.
    657    * This function compares Unicode strings in code point order.
    658    * If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.
    659    *
    660    * @param start The start offset in this string at which the compare operation begins.
    661    * @param limit The offset after the last code unit from this string to compare.
    662    * @param srcText Another string to compare this one to.
    663    * @param srcStart The start offset in that string at which the compare operation begins.
    664    * @param srcLimit The offset after the last code unit from that string to compare.
    665    * @return a negative/zero/positive integer corresponding to whether
    666    * this string is less than/equal to/greater than the second one
    667    * in code point order
    668    * @stable ICU 2.0
    669    */
    670   inline int8_t compareCodePointOrderBetween(int32_t start,
    671                                              int32_t limit,
    672                                              const UnicodeString& srcText,
    673                                              int32_t srcStart,
    674                                              int32_t srcLimit) const;
    675 
    676   /**
    677    * Compare two strings case-insensitively using full case folding.
    678    * This is equivalent to this->foldCase(options).compare(text.foldCase(options)).
    679    *
    680    * @param text Another string to compare this one to.
    681    * @param options A bit set of options:
    682    *   - U_FOLD_CASE_DEFAULT or 0 is used for default options:
    683    *     Comparison in code unit order with default case folding.
    684    *
    685    *   - U_COMPARE_CODE_POINT_ORDER
    686    *     Set to choose code point order instead of code unit order
    687    *     (see u_strCompare for details).
    688    *
    689    *   - U_FOLD_CASE_EXCLUDE_SPECIAL_I
    690    *
    691    * @return A negative, zero, or positive integer indicating the comparison result.
    692    * @stable ICU 2.0
    693    */
    694   inline int8_t caseCompare(const UnicodeString& text, uint32_t options) const;
    695 
    696   /**
    697    * Compare two strings case-insensitively using full case folding.
    698    * This is equivalent to this->foldCase(options).compare(srcText.foldCase(options)).
    699    *
    700    * @param start The start offset in this string at which the compare operation begins.
    701    * @param length The number of code units from this string to compare.
    702    * @param srcText Another string to compare this one to.
    703    * @param options A bit set of options:
    704    *   - U_FOLD_CASE_DEFAULT or 0 is used for default options:
    705    *     Comparison in code unit order with default case folding.
    706    *
    707    *   - U_COMPARE_CODE_POINT_ORDER
    708    *     Set to choose code point order instead of code unit order
    709    *     (see u_strCompare for details).
    710    *
    711    *   - U_FOLD_CASE_EXCLUDE_SPECIAL_I
    712    *
    713    * @return A negative, zero, or positive integer indicating the comparison result.
    714    * @stable ICU 2.0
    715    */
    716   inline int8_t caseCompare(int32_t start,
    717          int32_t length,
    718          const UnicodeString& srcText,
    719          uint32_t options) const;
    720 
    721   /**
    722    * Compare two strings case-insensitively using full case folding.
    723    * This is equivalent to this->foldCase(options).compare(srcText.foldCase(options)).
    724    *
    725    * @param start The start offset in this string at which the compare operation begins.
    726    * @param length The number of code units from this string to compare.
    727    * @param srcText Another string to compare this one to.
    728    * @param srcStart The start offset in that string at which the compare operation begins.
    729    * @param srcLength The number of code units from that string to compare.
    730    * @param options A bit set of options:
    731    *   - U_FOLD_CASE_DEFAULT or 0 is used for default options:
    732    *     Comparison in code unit order with default case folding.
    733    *
    734    *   - U_COMPARE_CODE_POINT_ORDER
    735    *     Set to choose code point order instead of code unit order
    736    *     (see u_strCompare for details).
    737    *
    738    *   - U_FOLD_CASE_EXCLUDE_SPECIAL_I
    739    *
    740    * @return A negative, zero, or positive integer indicating the comparison result.
    741    * @stable ICU 2.0
    742    */
    743   inline int8_t caseCompare(int32_t start,
    744          int32_t length,
    745          const UnicodeString& srcText,
    746          int32_t srcStart,
    747          int32_t srcLength,
    748          uint32_t options) const;
    749 
    750   /**
    751    * Compare two strings case-insensitively using full case folding.
    752    * This is equivalent to this->foldCase(options).compare(srcChars.foldCase(options)).
    753    *
    754    * @param srcChars A pointer to another string to compare this one to.
    755    * @param srcLength The number of code units from that string to compare.
    756    * @param options A bit set of options:
    757    *   - U_FOLD_CASE_DEFAULT or 0 is used for default options:
    758    *     Comparison in code unit order with default case folding.
    759    *
    760    *   - U_COMPARE_CODE_POINT_ORDER
    761    *     Set to choose code point order instead of code unit order
    762    *     (see u_strCompare for details).
    763    *
    764    *   - U_FOLD_CASE_EXCLUDE_SPECIAL_I
    765    *
    766    * @return A negative, zero, or positive integer indicating the comparison result.
    767    * @stable ICU 2.0
    768    */
    769   inline int8_t caseCompare(const UChar *srcChars,
    770          int32_t srcLength,
    771          uint32_t options) const;
    772 
    773   /**
    774    * Compare two strings case-insensitively using full case folding.
    775    * This is equivalent to this->foldCase(options).compare(srcChars.foldCase(options)).
    776    *
    777    * @param start The start offset in this string at which the compare operation begins.
    778    * @param length The number of code units from this string to compare.
    779    * @param srcChars A pointer to another string to compare this one to.
    780    * @param options A bit set of options:
    781    *   - U_FOLD_CASE_DEFAULT or 0 is used for default options:
    782    *     Comparison in code unit order with default case folding.
    783    *
    784    *   - U_COMPARE_CODE_POINT_ORDER
    785    *     Set to choose code point order instead of code unit order
    786    *     (see u_strCompare for details).
    787    *
    788    *   - U_FOLD_CASE_EXCLUDE_SPECIAL_I
    789    *
    790    * @return A negative, zero, or positive integer indicating the comparison result.
    791    * @stable ICU 2.0
    792    */
    793   inline int8_t caseCompare(int32_t start,
    794          int32_t length,
    795          const UChar *srcChars,
    796          uint32_t options) const;
    797 
    798   /**
    799    * Compare two strings case-insensitively using full case folding.
    800    * This is equivalent to this->foldCase(options).compare(srcChars.foldCase(options)).
    801    *
    802    * @param start The start offset in this string at which the compare operation begins.
    803    * @param length The number of code units from this string to compare.
    804    * @param srcChars A pointer to another string to compare this one to.
    805    * @param srcStart The start offset in that string at which the compare operation begins.
    806    * @param srcLength The number of code units from that string to compare.
    807    * @param options A bit set of options:
    808    *   - U_FOLD_CASE_DEFAULT or 0 is used for default options:
    809    *     Comparison in code unit order with default case folding.
    810    *
    811    *   - U_COMPARE_CODE_POINT_ORDER
    812    *     Set to choose code point order instead of code unit order
    813    *     (see u_strCompare for details).
    814    *
    815    *   - U_FOLD_CASE_EXCLUDE_SPECIAL_I
    816    *
    817    * @return A negative, zero, or positive integer indicating the comparison result.
    818    * @stable ICU 2.0
    819    */
    820   inline int8_t caseCompare(int32_t start,
    821          int32_t length,
    822          const UChar *srcChars,
    823          int32_t srcStart,
    824          int32_t srcLength,
    825          uint32_t options) const;
    826 
    827   /**
    828    * Compare two strings case-insensitively using full case folding.
    829    * This is equivalent to this->foldCase(options).compareBetween(text.foldCase(options)).
    830    *
    831    * @param start The start offset in this string at which the compare operation begins.
    832    * @param limit The offset after the last code unit from this string to compare.
    833    * @param srcText Another string to compare this one to.
    834    * @param srcStart The start offset in that string at which the compare operation begins.
    835    * @param srcLimit The offset after the last code unit from that string to compare.
    836    * @param options A bit set of options:
    837    *   - U_FOLD_CASE_DEFAULT or 0 is used for default options:
    838    *     Comparison in code unit order with default case folding.
    839    *
    840    *   - U_COMPARE_CODE_POINT_ORDER
    841    *     Set to choose code point order instead of code unit order
    842    *     (see u_strCompare for details).
    843    *
    844    *   - U_FOLD_CASE_EXCLUDE_SPECIAL_I
    845    *
    846    * @return A negative, zero, or positive integer indicating the comparison result.
    847    * @stable ICU 2.0
    848    */
    849   inline int8_t caseCompareBetween(int32_t start,
    850             int32_t limit,
    851             const UnicodeString& srcText,
    852             int32_t srcStart,
    853             int32_t srcLimit,
    854             uint32_t options) const;
    855 
    856   /**
    857    * Determine if this starts with the characters in <TT>text</TT>
    858    * @param text The text to match.
    859    * @return TRUE if this starts with the characters in <TT>text</TT>,
    860    * FALSE otherwise
    861    * @stable ICU 2.0
    862    */
    863   inline UBool startsWith(const UnicodeString& text) const;
    864 
    865   /**
    866    * Determine if this starts with the characters in <TT>srcText</TT>
    867    * in the range [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
    868    * @param srcText The text to match.
    869    * @param srcStart the offset into <TT>srcText</TT> to start matching
    870    * @param srcLength the number of characters in <TT>srcText</TT> to match
    871    * @return TRUE if this starts with the characters in <TT>text</TT>,
    872    * FALSE otherwise
    873    * @stable ICU 2.0
    874    */
    875   inline UBool startsWith(const UnicodeString& srcText,
    876             int32_t srcStart,
    877             int32_t srcLength) const;
    878 
    879   /**
    880    * Determine if this starts with the characters in <TT>srcChars</TT>
    881    * @param srcChars The characters to match.
    882    * @param srcLength the number of characters in <TT>srcChars</TT>
    883    * @return TRUE if this starts with the characters in <TT>srcChars</TT>,
    884    * FALSE otherwise
    885    * @stable ICU 2.0
    886    */
    887   inline UBool startsWith(const UChar *srcChars,
    888             int32_t srcLength) const;
    889 
    890   /**
    891    * Determine if this ends with the characters in <TT>srcChars</TT>
    892    * in the range  [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
    893    * @param srcChars The characters to match.
    894    * @param srcStart the offset into <TT>srcText</TT> to start matching
    895    * @param srcLength the number of characters in <TT>srcChars</TT> to match
    896    * @return TRUE if this ends with the characters in <TT>srcChars</TT>, FALSE otherwise
    897    * @stable ICU 2.0
    898    */
    899   inline UBool startsWith(const UChar *srcChars,
    900             int32_t srcStart,
    901             int32_t srcLength) const;
    902 
    903   /**
    904    * Determine if this ends with the characters in <TT>text</TT>
    905    * @param text The text to match.
    906    * @return TRUE if this ends with the characters in <TT>text</TT>,
    907    * FALSE otherwise
    908    * @stable ICU 2.0
    909    */
    910   inline UBool endsWith(const UnicodeString& text) const;
    911 
    912   /**
    913    * Determine if this ends with the characters in <TT>srcText</TT>
    914    * in the range [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
    915    * @param srcText The text to match.
    916    * @param srcStart the offset into <TT>srcText</TT> to start matching
    917    * @param srcLength the number of characters in <TT>srcText</TT> to match
    918    * @return TRUE if this ends with the characters in <TT>text</TT>,
    919    * FALSE otherwise
    920    * @stable ICU 2.0
    921    */
    922   inline UBool endsWith(const UnicodeString& srcText,
    923           int32_t srcStart,
    924           int32_t srcLength) const;
    925 
    926   /**
    927    * Determine if this ends with the characters in <TT>srcChars</TT>
    928    * @param srcChars The characters to match.
    929    * @param srcLength the number of characters in <TT>srcChars</TT>
    930    * @return TRUE if this ends with the characters in <TT>srcChars</TT>,
    931    * FALSE otherwise
    932    * @stable ICU 2.0
    933    */
    934   inline UBool endsWith(const UChar *srcChars,
    935           int32_t srcLength) const;
    936 
    937   /**
    938    * Determine if this ends with the characters in <TT>srcChars</TT>
    939    * in the range  [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
    940    * @param srcChars The characters to match.
    941    * @param srcStart the offset into <TT>srcText</TT> to start matching
    942    * @param srcLength the number of characters in <TT>srcChars</TT> to match
    943    * @return TRUE if this ends with the characters in <TT>srcChars</TT>,
    944    * FALSE otherwise
    945    * @stable ICU 2.0
    946    */
    947   inline UBool endsWith(const UChar *srcChars,
    948           int32_t srcStart,
    949           int32_t srcLength) const;
    950 
    951 
    952   /* Searching - bitwise only */
    953 
    954   /**
    955    * Locate in this the first occurrence of the characters in <TT>text</TT>,
    956    * using bitwise comparison.
    957    * @param text The text to search for.
    958    * @return The offset into this of the start of <TT>text</TT>,
    959    * or -1 if not found.
    960    * @stable ICU 2.0
    961    */
    962   inline int32_t indexOf(const UnicodeString& text) const;
    963 
    964   /**
    965    * Locate in this the first occurrence of the characters in <TT>text</TT>
    966    * starting at offset <TT>start</TT>, using bitwise comparison.
    967    * @param text The text to search for.
    968    * @param start The offset at which searching will start.
    969    * @return The offset into this of the start of <TT>text</TT>,
    970    * or -1 if not found.
    971    * @stable ICU 2.0
    972    */
    973   inline int32_t indexOf(const UnicodeString& text,
    974               int32_t start) const;
    975 
    976   /**
    977    * Locate in this the first occurrence in the range
    978    * [<TT>start</TT>, <TT>start + length</TT>) of the characters
    979    * in <TT>text</TT>, using bitwise comparison.
    980    * @param text The text to search for.
    981    * @param start The offset at which searching will start.
    982    * @param length The number of characters to search
    983    * @return The offset into this of the start of <TT>text</TT>,
    984    * or -1 if not found.
    985    * @stable ICU 2.0
    986    */
    987   inline int32_t indexOf(const UnicodeString& text,
    988               int32_t start,
    989               int32_t length) const;
    990 
    991   /**
    992    * Locate in this the first occurrence in the range
    993    * [<TT>start</TT>, <TT>start + length</TT>) of the characters
    994    *  in <TT>srcText</TT> in the range
    995    * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>),
    996    * using bitwise comparison.
    997    * @param srcText The text to search for.
    998    * @param srcStart the offset into <TT>srcText</TT> at which
    999    * to start matching
   1000    * @param srcLength the number of characters in <TT>srcText</TT> to match
   1001    * @param start the offset into this at which to start matching
   1002    * @param length the number of characters in this to search
   1003    * @return The offset into this of the start of <TT>text</TT>,
   1004    * or -1 if not found.
   1005    * @stable ICU 2.0
   1006    */
   1007   inline int32_t indexOf(const UnicodeString& srcText,
   1008               int32_t srcStart,
   1009               int32_t srcLength,
   1010               int32_t start,
   1011               int32_t length) const;
   1012 
   1013   /**
   1014    * Locate in this the first occurrence of the characters in
   1015    * <TT>srcChars</TT>
   1016    * starting at offset <TT>start</TT>, using bitwise comparison.
   1017    * @param srcChars The text to search for.
   1018    * @param srcLength the number of characters in <TT>srcChars</TT> to match
   1019    * @param start the offset into this at which to start matching
   1020    * @return The offset into this of the start of <TT>text</TT>,
   1021    * or -1 if not found.
   1022    * @stable ICU 2.0
   1023    */
   1024   inline int32_t indexOf(const UChar *srcChars,
   1025               int32_t srcLength,
   1026               int32_t start) const;
   1027 
   1028   /**
   1029    * Locate in this the first occurrence in the range
   1030    * [<TT>start</TT>, <TT>start + length</TT>) of the characters
   1031    * in <TT>srcChars</TT>, using bitwise comparison.
   1032    * @param srcChars The text to search for.
   1033    * @param srcLength the number of characters in <TT>srcChars</TT>
   1034    * @param start The offset at which searching will start.
   1035    * @param length The number of characters to search
   1036    * @return The offset into this of the start of <TT>srcChars</TT>,
   1037    * or -1 if not found.
   1038    * @stable ICU 2.0
   1039    */
   1040   inline int32_t indexOf(const UChar *srcChars,
   1041               int32_t srcLength,
   1042               int32_t start,
   1043               int32_t length) const;
   1044 
   1045   /**
   1046    * Locate in this the first occurrence in the range
   1047    * [<TT>start</TT>, <TT>start + length</TT>) of the characters
   1048    * in <TT>srcChars</TT> in the range
   1049    * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>),
   1050    * using bitwise comparison.
   1051    * @param srcChars The text to search for.
   1052    * @param srcStart the offset into <TT>srcChars</TT> at which
   1053    * to start matching
   1054    * @param srcLength the number of characters in <TT>srcChars</TT> to match
   1055    * @param start the offset into this at which to start matching
   1056    * @param length the number of characters in this to search
   1057    * @return The offset into this of the start of <TT>text</TT>,
   1058    * or -1 if not found.
   1059    * @stable ICU 2.0
   1060    */
   1061   int32_t indexOf(const UChar *srcChars,
   1062               int32_t srcStart,
   1063               int32_t srcLength,
   1064               int32_t start,
   1065               int32_t length) const;
   1066 
   1067   /**
   1068    * Locate in this the first occurrence of the BMP code point <code>c</code>,
   1069    * using bitwise comparison.
   1070    * @param c The code unit to search for.
   1071    * @return The offset into this of <TT>c</TT>, or -1 if not found.
   1072    * @stable ICU 2.0
   1073    */
   1074   inline int32_t indexOf(UChar c) const;
   1075 
   1076   /**
   1077    * Locate in this the first occurrence of the code point <TT>c</TT>,
   1078    * using bitwise comparison.
   1079    *
   1080    * @param c The code point to search for.
   1081    * @return The offset into this of <TT>c</TT>, or -1 if not found.
   1082    * @stable ICU 2.0
   1083    */
   1084   inline int32_t indexOf(UChar32 c) const;
   1085 
   1086   /**
   1087    * Locate in this the first occurrence of the BMP code point <code>c</code>,
   1088    * starting at offset <TT>start</TT>, using bitwise comparison.
   1089    * @param c The code unit to search for.
   1090    * @param start The offset at which searching will start.
   1091    * @return The offset into this of <TT>c</TT>, or -1 if not found.
   1092    * @stable ICU 2.0
   1093    */
   1094   inline int32_t indexOf(UChar c,
   1095               int32_t start) const;
   1096 
   1097   /**
   1098    * Locate in this the first occurrence of the code point <TT>c</TT>
   1099    * starting at offset <TT>start</TT>, using bitwise comparison.
   1100    *
   1101    * @param c The code point to search for.
   1102    * @param start The offset at which searching will start.
   1103    * @return The offset into this of <TT>c</TT>, or -1 if not found.
   1104    * @stable ICU 2.0
   1105    */
   1106   inline int32_t indexOf(UChar32 c,
   1107               int32_t start) const;
   1108 
   1109   /**
   1110    * Locate in this the first occurrence of the BMP code point <code>c</code>
   1111    * in the range [<TT>start</TT>, <TT>start + length</TT>),
   1112    * using bitwise comparison.
   1113    * @param c The code unit to search for.
   1114    * @param start the offset into this at which to start matching
   1115    * @param length the number of characters in this to search
   1116    * @return The offset into this of <TT>c</TT>, or -1 if not found.
   1117    * @stable ICU 2.0
   1118    */
   1119   inline int32_t indexOf(UChar c,
   1120               int32_t start,
   1121               int32_t length) const;
   1122 
   1123   /**
   1124    * Locate in this the first occurrence of the code point <TT>c</TT>
   1125    * in the range [<TT>start</TT>, <TT>start + length</TT>),
   1126    * using bitwise comparison.
   1127    *
   1128    * @param c The code point to search for.
   1129    * @param start the offset into this at which to start matching
   1130    * @param length the number of characters in this to search
   1131    * @return The offset into this of <TT>c</TT>, or -1 if not found.
   1132    * @stable ICU 2.0
   1133    */
   1134   inline int32_t indexOf(UChar32 c,
   1135               int32_t start,
   1136               int32_t length) const;
   1137 
   1138   /**
   1139    * Locate in this the last occurrence of the characters in <TT>text</TT>,
   1140    * using bitwise comparison.
   1141    * @param text The text to search for.
   1142    * @return The offset into this of the start of <TT>text</TT>,
   1143    * or -1 if not found.
   1144    * @stable ICU 2.0
   1145    */
   1146   inline int32_t lastIndexOf(const UnicodeString& text) const;
   1147 
   1148   /**
   1149    * Locate in this the last occurrence of the characters in <TT>text</TT>
   1150    * starting at offset <TT>start</TT>, using bitwise comparison.
   1151    * @param text The text to search for.
   1152    * @param start The offset at which searching will start.
   1153    * @return The offset into this of the start of <TT>text</TT>,
   1154    * or -1 if not found.
   1155    * @stable ICU 2.0
   1156    */
   1157   inline int32_t lastIndexOf(const UnicodeString& text,
   1158               int32_t start) const;
   1159 
   1160   /**
   1161    * Locate in this the last occurrence in the range
   1162    * [<TT>start</TT>, <TT>start + length</TT>) of the characters
   1163    * in <TT>text</TT>, using bitwise comparison.
   1164    * @param text The text to search for.
   1165    * @param start The offset at which searching will start.
   1166    * @param length The number of characters to search
   1167    * @return The offset into this of the start of <TT>text</TT>,
   1168    * or -1 if not found.
   1169    * @stable ICU 2.0
   1170    */
   1171   inline int32_t lastIndexOf(const UnicodeString& text,
   1172               int32_t start,
   1173               int32_t length) const;
   1174 
   1175   /**
   1176    * Locate in this the last occurrence in the range
   1177    * [<TT>start</TT>, <TT>start + length</TT>) of the characters
   1178    * in <TT>srcText</TT> in the range
   1179    * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>),
   1180    * using bitwise comparison.
   1181    * @param srcText The text to search for.
   1182    * @param srcStart the offset into <TT>srcText</TT> at which
   1183    * to start matching
   1184    * @param srcLength the number of characters in <TT>srcText</TT> to match
   1185    * @param start the offset into this at which to start matching
   1186    * @param length the number of characters in this to search
   1187    * @return The offset into this of the start of <TT>text</TT>,
   1188    * or -1 if not found.
   1189    * @stable ICU 2.0
   1190    */
   1191   inline int32_t lastIndexOf(const UnicodeString& srcText,
   1192               int32_t srcStart,
   1193               int32_t srcLength,
   1194               int32_t start,
   1195               int32_t length) const;
   1196 
   1197   /**
   1198    * Locate in this the last occurrence of the characters in <TT>srcChars</TT>
   1199    * starting at offset <TT>start</TT>, using bitwise comparison.
   1200    * @param srcChars The text to search for.
   1201    * @param srcLength the number of characters in <TT>srcChars</TT> to match
   1202    * @param start the offset into this at which to start matching
   1203    * @return The offset into this of the start of <TT>text</TT>,
   1204    * or -1 if not found.
   1205    * @stable ICU 2.0
   1206    */
   1207   inline int32_t lastIndexOf(const UChar *srcChars,
   1208               int32_t srcLength,
   1209               int32_t start) const;
   1210 
   1211   /**
   1212    * Locate in this the last occurrence in the range
   1213    * [<TT>start</TT>, <TT>start + length</TT>) of the characters
   1214    * in <TT>srcChars</TT>, using bitwise comparison.
   1215    * @param srcChars The text to search for.
   1216    * @param srcLength the number of characters in <TT>srcChars</TT>
   1217    * @param start The offset at which searching will start.
   1218    * @param length The number of characters to search
   1219    * @return The offset into this of the start of <TT>srcChars</TT>,
   1220    * or -1 if not found.
   1221    * @stable ICU 2.0
   1222    */
   1223   inline int32_t lastIndexOf(const UChar *srcChars,
   1224               int32_t srcLength,
   1225               int32_t start,
   1226               int32_t length) const;
   1227 
   1228   /**
   1229    * Locate in this the last occurrence in the range
   1230    * [<TT>start</TT>, <TT>start + length</TT>) of the characters
   1231    * in <TT>srcChars</TT> in the range
   1232    * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>),
   1233    * using bitwise comparison.
   1234    * @param srcChars The text to search for.
   1235    * @param srcStart the offset into <TT>srcChars</TT> at which
   1236    * to start matching
   1237    * @param srcLength the number of characters in <TT>srcChars</TT> to match
   1238    * @param start the offset into this at which to start matching
   1239    * @param length the number of characters in this to search
   1240    * @return The offset into this of the start of <TT>text</TT>,
   1241    * or -1 if not found.
   1242    * @stable ICU 2.0
   1243    */
   1244   int32_t lastIndexOf(const UChar *srcChars,
   1245               int32_t srcStart,
   1246               int32_t srcLength,
   1247               int32_t start,
   1248               int32_t length) const;
   1249 
   1250   /**
   1251    * Locate in this the last occurrence of the BMP code point <code>c</code>,
   1252    * using bitwise comparison.
   1253    * @param c The code unit to search for.
   1254    * @return The offset into this of <TT>c</TT>, or -1 if not found.
   1255    * @stable ICU 2.0
   1256    */
   1257   inline int32_t lastIndexOf(UChar c) const;
   1258 
   1259   /**
   1260    * Locate in this the last occurrence of the code point <TT>c</TT>,
   1261    * using bitwise comparison.
   1262    *
   1263    * @param c The code point to search for.
   1264    * @return The offset into this of <TT>c</TT>, or -1 if not found.
   1265    * @stable ICU 2.0
   1266    */
   1267   inline int32_t lastIndexOf(UChar32 c) const;
   1268 
   1269   /**
   1270    * Locate in this the last occurrence of the BMP code point <code>c</code>
   1271    * starting at offset <TT>start</TT>, using bitwise comparison.
   1272    * @param c The code unit to search for.
   1273    * @param start The offset at which searching will start.
   1274    * @return The offset into this of <TT>c</TT>, or -1 if not found.
   1275    * @stable ICU 2.0
   1276    */
   1277   inline int32_t lastIndexOf(UChar c,
   1278               int32_t start) const;
   1279 
   1280   /**
   1281    * Locate in this the last occurrence of the code point <TT>c</TT>
   1282    * starting at offset <TT>start</TT>, using bitwise comparison.
   1283    *
   1284    * @param c The code point to search for.
   1285    * @param start The offset at which searching will start.
   1286    * @return The offset into this of <TT>c</TT>, or -1 if not found.
   1287    * @stable ICU 2.0
   1288    */
   1289   inline int32_t lastIndexOf(UChar32 c,
   1290               int32_t start) const;
   1291 
   1292   /**
   1293    * Locate in this the last occurrence of the BMP code point <code>c</code>
   1294    * in the range [<TT>start</TT>, <TT>start + length</TT>),
   1295    * using bitwise comparison.
   1296    * @param c The code unit to search for.
   1297    * @param start the offset into this at which to start matching
   1298    * @param length the number of characters in this to search
   1299    * @return The offset into this of <TT>c</TT>, or -1 if not found.
   1300    * @stable ICU 2.0
   1301    */
   1302   inline int32_t lastIndexOf(UChar c,
   1303               int32_t start,
   1304               int32_t length) const;
   1305 
   1306   /**
   1307    * Locate in this the last occurrence of the code point <TT>c</TT>
   1308    * in the range [<TT>start</TT>, <TT>start + length</TT>),
   1309    * using bitwise comparison.
   1310    *
   1311    * @param c The code point to search for.
   1312    * @param start the offset into this at which to start matching
   1313    * @param length the number of characters in this to search
   1314    * @return The offset into this of <TT>c</TT>, or -1 if not found.
   1315    * @stable ICU 2.0
   1316    */
   1317   inline int32_t lastIndexOf(UChar32 c,
   1318               int32_t start,
   1319               int32_t length) const;
   1320 
   1321 
   1322   /* Character access */
   1323 
   1324   /**
   1325    * Return the code unit at offset <tt>offset</tt>.
   1326    * If the offset is not valid (0..length()-1) then U+ffff is returned.
   1327    * @param offset a valid offset into the text
   1328    * @return the code unit at offset <tt>offset</tt>
   1329    *         or 0xffff if the offset is not valid for this string
   1330    * @stable ICU 2.0
   1331    */
   1332   inline UChar charAt(int32_t offset) const;
   1333 
   1334   /**
   1335    * Return the code unit at offset <tt>offset</tt>.
   1336    * If the offset is not valid (0..length()-1) then U+ffff is returned.
   1337    * @param offset a valid offset into the text
   1338    * @return the code unit at offset <tt>offset</tt>
   1339    * @stable ICU 2.0
   1340    */
   1341   inline UChar operator[] (int32_t offset) const;
   1342 
   1343   /**
   1344    * Return the code point that contains the code unit
   1345    * at offset <tt>offset</tt>.
   1346    * If the offset is not valid (0..length()-1) then U+ffff is returned.
   1347    * @param offset a valid offset into the text
   1348    * that indicates the text offset of any of the code units
   1349    * that will be assembled into a code point (21-bit value) and returned
   1350    * @return the code point of text at <tt>offset</tt>
   1351    *         or 0xffff if the offset is not valid for this string
   1352    * @stable ICU 2.0
   1353    */
   1354   UChar32 char32At(int32_t offset) const;
   1355 
   1356   /**
   1357    * Adjust a random-access offset so that
   1358    * it points to the beginning of a Unicode character.
   1359    * The offset that is passed in points to
   1360    * any code unit of a code point,
   1361    * while the returned offset will point to the first code unit
   1362    * of the same code point.
   1363    * In UTF-16, if the input offset points to a second surrogate
   1364    * of a surrogate pair, then the returned offset will point
   1365    * to the first surrogate.
   1366    * @param offset a valid offset into one code point of the text
   1367    * @return offset of the first code unit of the same code point
   1368    * @see U16_SET_CP_START
   1369    * @stable ICU 2.0
   1370    */
   1371   int32_t getChar32Start(int32_t offset) const;
   1372 
   1373   /**
   1374    * Adjust a random-access offset so that
   1375    * it points behind a Unicode character.
   1376    * The offset that is passed in points behind
   1377    * any code unit of a code point,
   1378    * while the returned offset will point behind the last code unit
   1379    * of the same code point.
   1380    * In UTF-16, if the input offset points behind the first surrogate
   1381    * (i.e., to the second surrogate)
   1382    * of a surrogate pair, then the returned offset will point
   1383    * behind the second surrogate (i.e., to the first surrogate).
   1384    * @param offset a valid offset after any code unit of a code point of the text
   1385    * @return offset of the first code unit after the same code point
   1386    * @see U16_SET_CP_LIMIT
   1387    * @stable ICU 2.0
   1388    */
   1389   int32_t getChar32Limit(int32_t offset) const;
   1390 
   1391   /**
   1392    * Move the code unit index along the string by delta code points.
   1393    * Interpret the input index as a code unit-based offset into the string,
   1394    * move the index forward or backward by delta code points, and
   1395    * return the resulting index.
   1396    * The input index should point to the first code unit of a code point,
   1397    * if there is more than one.
   1398    *
   1399    * Both input and output indexes are code unit-based as for all
   1400    * string indexes/offsets in ICU (and other libraries, like MBCS char*).
   1401    * If delta<0 then the index is moved backward (toward the start of the string).
   1402    * If delta>0 then the index is moved forward (toward the end of the string).
   1403    *
   1404    * This behaves like CharacterIterator::move32(delta, kCurrent).
   1405    *
   1406    * Behavior for out-of-bounds indexes:
   1407    * <code>moveIndex32</code> pins the input index to 0..length(), i.e.,
   1408    * if the input index<0 then it is pinned to 0;
   1409    * if it is index>length() then it is pinned to length().
   1410    * Afterwards, the index is moved by <code>delta</code> code points
   1411    * forward or backward,
   1412    * but no further backward than to 0 and no further forward than to length().
   1413    * The resulting index return value will be in between 0 and length(), inclusively.
   1414    *
   1415    * Examples:
   1416    * <pre>
   1417    * // s has code points 'a' U+10000 'b' U+10ffff U+2029
   1418    * UnicodeString s=UNICODE_STRING("a\\U00010000b\\U0010ffff\\u2029", 31).unescape();
   1419    *
   1420    * // initial index: position of U+10000
   1421    * int32_t index=1;
   1422    *
   1423    * // the following examples will all result in index==4, position of U+10ffff
   1424    *
   1425    * // skip 2 code points from some position in the string
   1426    * index=s.moveIndex32(index, 2); // skips U+10000 and 'b'
   1427    *
   1428    * // go to the 3rd code point from the start of s (0-based)
   1429    * index=s.moveIndex32(0, 3); // skips 'a', U+10000, and 'b'
   1430    *
   1431    * // go to the next-to-last code point of s
   1432    * index=s.moveIndex32(s.length(), -2); // backward-skips U+2029 and U+10ffff
   1433    * </pre>
   1434    *
   1435    * @param index input code unit index
   1436    * @param delta (signed) code point count to move the index forward or backward
   1437    *        in the string
   1438    * @return the resulting code unit index
   1439    * @stable ICU 2.0
   1440    */
   1441   int32_t moveIndex32(int32_t index, int32_t delta) const;
   1442 
   1443   /* Substring extraction */
   1444 
   1445   /**
   1446    * Copy the characters in the range
   1447    * [<tt>start</tt>, <tt>start + length</tt>) into the array <tt>dst</tt>,
   1448    * beginning at <tt>dstStart</tt>.
   1449    * If the string aliases to <code>dst</code> itself as an external buffer,
   1450    * then extract() will not copy the contents.
   1451    *
   1452    * @param start offset of first character which will be copied into the array
   1453    * @param length the number of characters to extract
   1454    * @param dst array in which to copy characters.  The length of <tt>dst</tt>
   1455    * must be at least (<tt>dstStart + length</tt>).
   1456    * @param dstStart the offset in <TT>dst</TT> where the first character
   1457    * will be extracted
   1458    * @stable ICU 2.0
   1459    */
   1460   inline void extract(int32_t start,
   1461            int32_t length,
   1462            UChar *dst,
   1463            int32_t dstStart = 0) const;
   1464 
   1465   /**
   1466    * Copy the contents of the string into dest.
   1467    * This is a convenience function that
   1468    * checks if there is enough space in dest,
   1469    * extracts the entire string if possible,
   1470    * and NUL-terminates dest if possible.
   1471    *
   1472    * If the string fits into dest but cannot be NUL-terminated
   1473    * (length()==destCapacity) then the error code is set to U_STRING_NOT_TERMINATED_WARNING.
   1474    * If the string itself does not fit into dest
   1475    * (length()>destCapacity) then the error code is set to U_BUFFER_OVERFLOW_ERROR.
   1476    *
   1477    * If the string aliases to <code>dest</code> itself as an external buffer,
   1478    * then extract() will not copy the contents.
   1479    *
   1480    * @param dest Destination string buffer.
   1481    * @param destCapacity Number of UChars available at dest.
   1482    * @param errorCode ICU error code.
   1483    * @return length()
   1484    * @stable ICU 2.0
   1485    */
   1486   int32_t
   1487   extract(UChar *dest, int32_t destCapacity,
   1488           UErrorCode &errorCode) const;
   1489 
   1490   /**
   1491    * Copy the characters in the range
   1492    * [<tt>start</tt>, <tt>start + length</tt>) into the  UnicodeString
   1493    * <tt>target</tt>.
   1494    * @param start offset of first character which will be copied
   1495    * @param length the number of characters to extract
   1496    * @param target UnicodeString into which to copy characters.
   1497    * @return A reference to <TT>target</TT>
   1498    * @stable ICU 2.0
   1499    */
   1500   inline void extract(int32_t start,
   1501            int32_t length,
   1502            UnicodeString& target) const;
   1503 
   1504   /**
   1505    * Copy the characters in the range [<tt>start</tt>, <tt>limit</tt>)
   1506    * into the array <tt>dst</tt>, beginning at <tt>dstStart</tt>.
   1507    * @param start offset of first character which will be copied into the array
   1508    * @param limit offset immediately following the last character to be copied
   1509    * @param dst array in which to copy characters.  The length of <tt>dst</tt>
   1510    * must be at least (<tt>dstStart + (limit - start)</tt>).
   1511    * @param dstStart the offset in <TT>dst</TT> where the first character
   1512    * will be extracted
   1513    * @stable ICU 2.0
   1514    */
   1515   inline void extractBetween(int32_t start,
   1516               int32_t limit,
   1517               UChar *dst,
   1518               int32_t dstStart = 0) const;
   1519 
   1520   /**
   1521    * Copy the characters in the range [<tt>start</tt>, <tt>limit</tt>)
   1522    * into the UnicodeString <tt>target</tt>.  Replaceable API.
   1523    * @param start offset of first character which will be copied
   1524    * @param limit offset immediately following the last character to be copied
   1525    * @param target UnicodeString into which to copy characters.
   1526    * @return A reference to <TT>target</TT>
   1527    * @stable ICU 2.0
   1528    */
   1529   virtual void extractBetween(int32_t start,
   1530               int32_t limit,
   1531               UnicodeString& target) const;
   1532 
   1533   /**
   1534    * Copy the characters in the range
   1535    * [<tt>start</TT>, <tt>start + startLength</TT>) into an array of characters.
   1536    * All characters must be invariant (see utypes.h).
   1537    * Use US_INV as the last, signature-distinguishing parameter.
   1538    *
   1539    * This function does not write any more than <code>targetCapacity</code>
   1540    * characters but returns the length of the entire output string
   1541    * so that one can allocate a larger buffer and call the function again
   1542    * if necessary.
   1543    * The output string is NUL-terminated if possible.
   1544    *
   1545    * @param start offset of first character which will be copied
   1546    * @param startLength the number of characters to extract
   1547    * @param target the target buffer for extraction, can be NULL
   1548    *               if targetLength is 0
   1549    * @param targetCapacity the length of the target buffer
   1550    * @param inv Signature-distinguishing paramater, use US_INV.
   1551    * @return the output string length, not including the terminating NUL
   1552    * @stable ICU 3.2
   1553    */
   1554   int32_t extract(int32_t start,
   1555            int32_t startLength,
   1556            char *target,
   1557            int32_t targetCapacity,
   1558            enum EInvariant inv) const;
   1559 
   1560 #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
   1561 
   1562   /**
   1563    * Copy the characters in the range
   1564    * [<tt>start</TT>, <tt>start + length</TT>) into an array of characters
   1565    * in the platform's default codepage.
   1566    * This function does not write any more than <code>targetLength</code>
   1567    * characters but returns the length of the entire output string
   1568    * so that one can allocate a larger buffer and call the function again
   1569    * if necessary.
   1570    * The output string is NUL-terminated if possible.
   1571    *
   1572    * @param start offset of first character which will be copied
   1573    * @param startLength the number of characters to extract
   1574    * @param target the target buffer for extraction
   1575    * @param targetLength the length of the target buffer
   1576    * If <TT>target</TT> is NULL, then the number of bytes required for
   1577    * <TT>target</TT> is returned.
   1578    * @return the output string length, not including the terminating NUL
   1579    * @stable ICU 2.0
   1580    */
   1581   int32_t extract(int32_t start,
   1582            int32_t startLength,
   1583            char *target,
   1584            uint32_t targetLength) const;
   1585 
   1586 #endif
   1587 
   1588 #if !UCONFIG_NO_CONVERSION
   1589 
   1590   /**
   1591    * Copy the characters in the range
   1592    * [<tt>start</TT>, <tt>start + length</TT>) into an array of characters
   1593    * in a specified codepage.
   1594    * The output string is NUL-terminated.
   1595    *
   1596    * Recommendation: For invariant-character strings use
   1597    * extract(int32_t start, int32_t length, char *target, int32_t targetCapacity, enum EInvariant inv) const
   1598    * because it avoids object code dependencies of UnicodeString on
   1599    * the conversion code.
   1600    *
   1601    * @param start offset of first character which will be copied
   1602    * @param startLength the number of characters to extract
   1603    * @param target the target buffer for extraction
   1604    * @param codepage the desired codepage for the characters.  0 has
   1605    * the special meaning of the default codepage
   1606    * If <code>codepage</code> is an empty string (<code>""</code>),
   1607    * then a simple conversion is performed on the codepage-invariant
   1608    * subset ("invariant characters") of the platform encoding. See utypes.h.
   1609    * If <TT>target</TT> is NULL, then the number of bytes required for
   1610    * <TT>target</TT> is returned. It is assumed that the target is big enough
   1611    * to fit all of the characters.
   1612    * @return the output string length, not including the terminating NUL
   1613    * @stable ICU 2.0
   1614    */
   1615   inline int32_t extract(int32_t start,
   1616                  int32_t startLength,
   1617                  char *target,
   1618                  const char *codepage = 0) const;
   1619 
   1620   /**
   1621    * Copy the characters in the range
   1622    * [<tt>start</TT>, <tt>start + length</TT>) into an array of characters
   1623    * in a specified codepage.
   1624    * This function does not write any more than <code>targetLength</code>
   1625    * characters but returns the length of the entire output string
   1626    * so that one can allocate a larger buffer and call the function again
   1627    * if necessary.
   1628    * The output string is NUL-terminated if possible.
   1629    *
   1630    * Recommendation: For invariant-character strings use
   1631    * extract(int32_t start, int32_t length, char *target, int32_t targetCapacity, enum EInvariant inv) const
   1632    * because it avoids object code dependencies of UnicodeString on
   1633    * the conversion code.
   1634    *
   1635    * @param start offset of first character which will be copied
   1636    * @param startLength the number of characters to extract
   1637    * @param target the target buffer for extraction
   1638    * @param targetLength the length of the target buffer
   1639    * @param codepage the desired codepage for the characters.  0 has
   1640    * the special meaning of the default codepage
   1641    * If <code>codepage</code> is an empty string (<code>""</code>),
   1642    * then a simple conversion is performed on the codepage-invariant
   1643    * subset ("invariant characters") of the platform encoding. See utypes.h.
   1644    * If <TT>target</TT> is NULL, then the number of bytes required for
   1645    * <TT>target</TT> is returned.
   1646    * @return the output string length, not including the terminating NUL
   1647    * @stable ICU 2.0
   1648    */
   1649   int32_t extract(int32_t start,
   1650            int32_t startLength,
   1651            char *target,
   1652            uint32_t targetLength,
   1653            const char *codepage) const;
   1654 
   1655   /**
   1656    * Convert the UnicodeString into a codepage string using an existing UConverter.
   1657    * The output string is NUL-terminated if possible.
   1658    *
   1659    * This function avoids the overhead of opening and closing a converter if
   1660    * multiple strings are extracted.
   1661    *
   1662    * @param dest destination string buffer, can be NULL if destCapacity==0
   1663    * @param destCapacity the number of chars available at dest
   1664    * @param cnv the converter object to be used (ucnv_resetFromUnicode() will be called),
   1665    *        or NULL for the default converter
   1666    * @param errorCode normal ICU error code
   1667    * @return the length of the output string, not counting the terminating NUL;
   1668    *         if the length is greater than destCapacity, then the string will not fit
   1669    *         and a buffer of the indicated length would need to be passed in
   1670    * @stable ICU 2.0
   1671    */
   1672   int32_t extract(char *dest, int32_t destCapacity,
   1673                   UConverter *cnv,
   1674                   UErrorCode &errorCode) const;
   1675 
   1676 #endif
   1677 
   1678   /**
   1679    * Create a temporary substring for the specified range.
   1680    * Unlike the substring constructor and setTo() functions,
   1681    * the object returned here will be a read-only alias (using getBuffer())
   1682    * rather than copying the text.
   1683    * As a result, this substring operation is much faster but requires
   1684    * that the original string not be modified or deleted during the lifetime
   1685    * of the returned substring object.
   1686    * @param start offset of the first character visible in the substring
   1687    * @param length length of the substring
   1688    * @return a read-only alias UnicodeString object for the substring
   1689    * @stable ICU 4.4
   1690    */
   1691   UnicodeString tempSubString(int32_t start=0, int32_t length=INT32_MAX) const;
   1692 
   1693   /**
   1694    * Create a temporary substring for the specified range.
   1695    * Same as tempSubString(start, length) except that the substring range
   1696    * is specified as a (start, limit) pair (with an exclusive limit index)
   1697    * rather than a (start, length) pair.
   1698    * @param start offset of the first character visible in the substring
   1699    * @param limit offset immediately following the last character visible in the substring
   1700    * @return a read-only alias UnicodeString object for the substring
   1701    * @stable ICU 4.4
   1702    */
   1703   inline UnicodeString tempSubStringBetween(int32_t start, int32_t limit=INT32_MAX) const;
   1704 
   1705   /**
   1706    * Convert the UnicodeString to UTF-8 and write the result
   1707    * to a ByteSink. This is called by toUTF8String().
   1708    * Unpaired surrogates are replaced with U+FFFD.
   1709    * Calls u_strToUTF8WithSub().
   1710    *
   1711    * @param sink A ByteSink to which the UTF-8 version of the string is written.
   1712    *             sink.Flush() is called at the end.
   1713    * @stable ICU 4.2
   1714    * @see toUTF8String
   1715    */
   1716   void toUTF8(ByteSink &sink) const;
   1717 
   1718 #if U_HAVE_STD_STRING
   1719 
   1720   /**
   1721    * Convert the UnicodeString to UTF-8 and append the result
   1722    * to a standard string.
   1723    * Unpaired surrogates are replaced with U+FFFD.
   1724    * Calls toUTF8().
   1725    *
   1726    * @param result A standard string (or a compatible object)
   1727    *        to which the UTF-8 version of the string is appended.
   1728    * @return The string object.
   1729    * @stable ICU 4.2
   1730    * @see toUTF8
   1731    */
   1732   template<typename StringClass>
   1733   StringClass &toUTF8String(StringClass &result) const {
   1734     StringByteSink<StringClass> sbs(&result);
   1735     toUTF8(sbs);
   1736     return result;
   1737   }
   1738 
   1739 #endif
   1740 
   1741   /**
   1742    * Convert the UnicodeString to UTF-32.
   1743    * Unpaired surrogates are replaced with U+FFFD.
   1744    * Calls u_strToUTF32WithSub().
   1745    *
   1746    * @param utf32 destination string buffer, can be NULL if capacity==0
   1747    * @param capacity the number of UChar32s available at utf32
   1748    * @param errorCode Standard ICU error code. Its input value must
   1749    *                  pass the U_SUCCESS() test, or else the function returns
   1750    *                  immediately. Check for U_FAILURE() on output or use with
   1751    *                  function chaining. (See User Guide for details.)
   1752    * @return The length of the UTF-32 string.
   1753    * @see fromUTF32
   1754    * @stable ICU 4.2
   1755    */
   1756   int32_t toUTF32(UChar32 *utf32, int32_t capacity, UErrorCode &errorCode) const;
   1757 
   1758   /* Length operations */
   1759 
   1760   /**
   1761    * Return the length of the UnicodeString object.
   1762    * The length is the number of UChar code units are in the UnicodeString.
   1763    * If you want the number of code points, please use countChar32().
   1764    * @return the length of the UnicodeString object
   1765    * @see countChar32
   1766    * @stable ICU 2.0
   1767    */
   1768   inline int32_t length(void) const;
   1769 
   1770   /**
   1771    * Count Unicode code points in the length UChar code units of the string.
   1772    * A code point may occupy either one or two UChar code units.
   1773    * Counting code points involves reading all code units.
   1774    *
   1775    * This functions is basically the inverse of moveIndex32().
   1776    *
   1777    * @param start the index of the first code unit to check
   1778    * @param length the number of UChar code units to check
   1779    * @return the number of code points in the specified code units
   1780    * @see length
   1781    * @stable ICU 2.0
   1782    */
   1783   int32_t
   1784   countChar32(int32_t start=0, int32_t length=INT32_MAX) const;
   1785 
   1786   /**
   1787    * Check if the length UChar code units of the string
   1788    * contain more Unicode code points than a certain number.
   1789    * This is more efficient than counting all code points in this part of the string
   1790    * and comparing that number with a threshold.
   1791    * This function may not need to scan the string at all if the length
   1792    * falls within a certain range, and
   1793    * never needs to count more than 'number+1' code points.
   1794    * Logically equivalent to (countChar32(start, length)>number).
   1795    * A Unicode code point may occupy either one or two UChar code units.
   1796    *
   1797    * @param start the index of the first code unit to check (0 for the entire string)
   1798    * @param length the number of UChar code units to check
   1799    *               (use INT32_MAX for the entire string; remember that start/length
   1800    *                values are pinned)
   1801    * @param number The number of code points in the (sub)string is compared against
   1802    *               the 'number' parameter.
   1803    * @return Boolean value for whether the string contains more Unicode code points
   1804    *         than 'number'. Same as (u_countChar32(s, length)>number).
   1805    * @see countChar32
   1806    * @see u_strHasMoreChar32Than
   1807    * @stable ICU 2.4
   1808    */
   1809   UBool
   1810   hasMoreChar32Than(int32_t start, int32_t length, int32_t number) const;
   1811 
   1812   /**
   1813    * Determine if this string is empty.
   1814    * @return TRUE if this string contains 0 characters, FALSE otherwise.
   1815    * @stable ICU 2.0
   1816    */
   1817   inline UBool isEmpty(void) const;
   1818 
   1819   /**
   1820    * Return the capacity of the internal buffer of the UnicodeString object.
   1821    * This is useful together with the getBuffer functions.
   1822    * See there for details.
   1823    *
   1824    * @return the number of UChars available in the internal buffer
   1825    * @see getBuffer
   1826    * @stable ICU 2.0
   1827    */
   1828   inline int32_t getCapacity(void) const;
   1829 
   1830   /* Other operations */
   1831 
   1832   /**
   1833    * Generate a hash code for this object.
   1834    * @return The hash code of this UnicodeString.
   1835    * @stable ICU 2.0
   1836    */
   1837   inline int32_t hashCode(void) const;
   1838 
   1839   /**
   1840    * Determine if this object contains a valid string.
   1841    * A bogus string has no value. It is different from an empty string,
   1842    * although in both cases isEmpty() returns TRUE and length() returns 0.
   1843    * setToBogus() and isBogus() can be used to indicate that no string value is available.
   1844    * For a bogus string, getBuffer() and getTerminatedBuffer() return NULL, and
   1845    * length() returns 0.
   1846    *
   1847    * @return TRUE if the string is bogus/invalid, FALSE otherwise
   1848    * @see setToBogus()
   1849    * @stable ICU 2.0
   1850    */
   1851   inline UBool isBogus(void) const;
   1852 
   1853 
   1854   //========================================
   1855   // Write operations
   1856   //========================================
   1857 
   1858   /* Assignment operations */
   1859 
   1860   /**
   1861    * Assignment operator.  Replace the characters in this UnicodeString
   1862    * with the characters from <TT>srcText</TT>.
   1863    *
   1864    * Starting with ICU 2.4, the assignment operator and the copy constructor
   1865    * allocate a new buffer and copy the buffer contents even for readonly aliases.
   1866    * By contrast, the fastCopyFrom() function implements the old,
   1867    * more efficient but less safe behavior
   1868    * of making this string also a readonly alias to the same buffer.
   1869    *
   1870    * If the source object has an "open" buffer from getBuffer(minCapacity),
   1871    * then the copy is an empty string.
   1872    *
   1873    * @param srcText The text containing the characters to replace
   1874    * @return a reference to this
   1875    * @stable ICU 2.0
   1876    * @see fastCopyFrom
   1877    */
   1878   UnicodeString &operator=(const UnicodeString &srcText);
   1879 
   1880   /**
   1881    * Almost the same as the assignment operator.
   1882    * Replace the characters in this UnicodeString
   1883    * with the characters from <code>srcText</code>.
   1884    *
   1885    * This function works the same as the assignment operator
   1886    * for all strings except for ones that are readonly aliases.
   1887    *
   1888    * Starting with ICU 2.4, the assignment operator and the copy constructor
   1889    * allocate a new buffer and copy the buffer contents even for readonly aliases.
   1890    * This function implements the old, more efficient but less safe behavior
   1891    * of making this string also a readonly alias to the same buffer.
   1892    *
   1893    * The fastCopyFrom function must be used only if it is known that the lifetime of
   1894    * this UnicodeString does not exceed the lifetime of the aliased buffer
   1895    * including its contents, for example for strings from resource bundles
   1896    * or aliases to string constants.
   1897    *
   1898    * If the source object has an "open" buffer from getBuffer(minCapacity),
   1899    * then the copy is an empty string.
   1900    *
   1901    * @param src The text containing the characters to replace.
   1902    * @return a reference to this
   1903    * @stable ICU 2.4
   1904    */
   1905   UnicodeString &fastCopyFrom(const UnicodeString &src);
   1906 
   1907 #if U_HAVE_RVALUE_REFERENCES
   1908   /**
   1909    * Move assignment operator, might leave src in bogus state.
   1910    * This string will have the same contents and state that the source string had.
   1911    * The behavior is undefined if *this and src are the same object.
   1912    * @param src source string
   1913    * @return *this
   1914    * @stable ICU 56
   1915    */
   1916   UnicodeString &operator=(UnicodeString &&src) U_NOEXCEPT {
   1917     return moveFrom(src);
   1918   }
   1919 #endif
   1920   // do not use #ifndef U_HIDE_DRAFT_API for moveFrom, needed by non-draft API
   1921   /**
   1922    * Move assignment, might leave src in bogus state.
   1923    * This string will have the same contents and state that the source string had.
   1924    * The behavior is undefined if *this and src are the same object.
   1925    *
   1926    * Can be called explicitly, does not need C++11 support.
   1927    * @param src source string
   1928    * @return *this
   1929    * @draft ICU 56
   1930    */
   1931   UnicodeString &moveFrom(UnicodeString &src) U_NOEXCEPT;
   1932 
   1933   /**
   1934    * Swap strings.
   1935    * @param other other string
   1936    * @stable ICU 56
   1937    */
   1938   void swap(UnicodeString &other) U_NOEXCEPT;
   1939 
   1940   /**
   1941    * Non-member UnicodeString swap function.
   1942    * @param s1 will get s2's contents and state
   1943    * @param s2 will get s1's contents and state
   1944    * @stable ICU 56
   1945    */
   1946   friend U_COMMON_API inline void U_EXPORT2
   1947   swap(UnicodeString &s1, UnicodeString &s2) U_NOEXCEPT {
   1948     s1.swap(s2);
   1949   }
   1950 
   1951   /**
   1952    * Assignment operator.  Replace the characters in this UnicodeString
   1953    * with the code unit <TT>ch</TT>.
   1954    * @param ch the code unit to replace
   1955    * @return a reference to this
   1956    * @stable ICU 2.0
   1957    */
   1958   inline UnicodeString& operator= (UChar ch);
   1959 
   1960   /**
   1961    * Assignment operator.  Replace the characters in this UnicodeString
   1962    * with the code point <TT>ch</TT>.
   1963    * @param ch the code point to replace
   1964    * @return a reference to this
   1965    * @stable ICU 2.0
   1966    */
   1967   inline UnicodeString& operator= (UChar32 ch);
   1968 
   1969   /**
   1970    * Set the text in the UnicodeString object to the characters
   1971    * in <TT>srcText</TT> in the range
   1972    * [<TT>srcStart</TT>, <TT>srcText.length()</TT>).
   1973    * <TT>srcText</TT> is not modified.
   1974    * @param srcText the source for the new characters
   1975    * @param srcStart the offset into <TT>srcText</TT> where new characters
   1976    * will be obtained
   1977    * @return a reference to this
   1978    * @stable ICU 2.2
   1979    */
   1980   inline UnicodeString& setTo(const UnicodeString& srcText,
   1981                int32_t srcStart);
   1982 
   1983   /**
   1984    * Set the text in the UnicodeString object to the characters
   1985    * in <TT>srcText</TT> in the range
   1986    * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
   1987    * <TT>srcText</TT> is not modified.
   1988    * @param srcText the source for the new characters
   1989    * @param srcStart the offset into <TT>srcText</TT> where new characters
   1990    * will be obtained
   1991    * @param srcLength the number of characters in <TT>srcText</TT> in the
   1992    * replace string.
   1993    * @return a reference to this
   1994    * @stable ICU 2.0
   1995    */
   1996   inline UnicodeString& setTo(const UnicodeString& srcText,
   1997                int32_t srcStart,
   1998                int32_t srcLength);
   1999 
   2000   /**
   2001    * Set the text in the UnicodeString object to the characters in
   2002    * <TT>srcText</TT>.
   2003    * <TT>srcText</TT> is not modified.
   2004    * @param srcText the source for the new characters
   2005    * @return a reference to this
   2006    * @stable ICU 2.0
   2007    */
   2008   inline UnicodeString& setTo(const UnicodeString& srcText);
   2009 
   2010   /**
   2011    * Set the characters in the UnicodeString object to the characters
   2012    * in <TT>srcChars</TT>. <TT>srcChars</TT> is not modified.
   2013    * @param srcChars the source for the new characters
   2014    * @param srcLength the number of Unicode characters in srcChars.
   2015    * @return a reference to this
   2016    * @stable ICU 2.0
   2017    */
   2018   inline UnicodeString& setTo(const UChar *srcChars,
   2019                int32_t srcLength);
   2020 
   2021   /**
   2022    * Set the characters in the UnicodeString object to the code unit
   2023    * <TT>srcChar</TT>.
   2024    * @param srcChar the code unit which becomes the UnicodeString's character
   2025    * content
   2026    * @return a reference to this
   2027    * @stable ICU 2.0
   2028    */
   2029   UnicodeString& setTo(UChar srcChar);
   2030 
   2031   /**
   2032    * Set the characters in the UnicodeString object to the code point
   2033    * <TT>srcChar</TT>.
   2034    * @param srcChar the code point which becomes the UnicodeString's character
   2035    * content
   2036    * @return a reference to this
   2037    * @stable ICU 2.0
   2038    */
   2039   UnicodeString& setTo(UChar32 srcChar);
   2040 
   2041   /**
   2042    * Aliasing setTo() function, analogous to the readonly-aliasing UChar* constructor.
   2043    * The text will be used for the UnicodeString object, but
   2044    * it will not be released when the UnicodeString is destroyed.
   2045    * This has copy-on-write semantics:
   2046    * When the string is modified, then the buffer is first copied into
   2047    * newly allocated memory.
   2048    * The aliased buffer is never modified.
   2049    *
   2050    * In an assignment to another UnicodeString, when using the copy constructor
   2051    * or the assignment operator, the text will be copied.
   2052    * When using fastCopyFrom(), the text will be aliased again,
   2053    * so that both strings then alias the same readonly-text.
   2054    *
   2055    * @param isTerminated specifies if <code>text</code> is <code>NUL</code>-terminated.
   2056    *                     This must be true if <code>textLength==-1</code>.
   2057    * @param text The characters to alias for the UnicodeString.
   2058    * @param textLength The number of Unicode characters in <code>text</code> to alias.
   2059    *                   If -1, then this constructor will determine the length
   2060    *                   by calling <code>u_strlen()</code>.
   2061    * @return a reference to this
   2062    * @stable ICU 2.0
   2063    */
   2064   UnicodeString &setTo(UBool isTerminated,
   2065                        const UChar *text,
   2066                        int32_t textLength);
   2067 
   2068   /**
   2069    * Aliasing setTo() function, analogous to the writable-aliasing UChar* constructor.
   2070    * The text will be used for the UnicodeString object, but
   2071    * it will not be released when the UnicodeString is destroyed.
   2072    * This has write-through semantics:
   2073    * For as long as the capacity of the buffer is sufficient, write operations
   2074    * will directly affect the buffer. When more capacity is necessary, then
   2075    * a new buffer will be allocated and the contents copied as with regularly
   2076    * constructed strings.
   2077    * In an assignment to another UnicodeString, the buffer will be copied.
   2078    * The extract(UChar *dst) function detects whether the dst pointer is the same
   2079    * as the string buffer itself and will in this case not copy the contents.
   2080    *
   2081    * @param buffer The characters to alias for the UnicodeString.
   2082    * @param buffLength The number of Unicode characters in <code>buffer</code> to alias.
   2083    * @param buffCapacity The size of <code>buffer</code> in UChars.
   2084    * @return a reference to this
   2085    * @stable ICU 2.0
   2086    */
   2087   UnicodeString &setTo(UChar *buffer,
   2088                        int32_t buffLength,
   2089                        int32_t buffCapacity);
   2090 
   2091   /**
   2092    * Make this UnicodeString object invalid.
   2093    * The string will test TRUE with isBogus().
   2094    *
   2095    * A bogus string has no value. It is different from an empty string.
   2096    * It can be used to indicate that no string value is available.
   2097    * getBuffer() and getTerminatedBuffer() return NULL, and
   2098    * length() returns 0.
   2099    *
   2100    * This utility function is used throughout the UnicodeString
   2101    * implementation to indicate that a UnicodeString operation failed,
   2102    * and may be used in other functions,
   2103    * especially but not exclusively when such functions do not
   2104    * take a UErrorCode for simplicity.
   2105    *
   2106    * The following methods, and no others, will clear a string object's bogus flag:
   2107    * - remove()
   2108    * - remove(0, INT32_MAX)
   2109    * - truncate(0)
   2110    * - operator=() (assignment operator)
   2111    * - setTo(...)
   2112    *
   2113    * The simplest ways to turn a bogus string into an empty one
   2114    * is to use the remove() function.
   2115    * Examples for other functions that are equivalent to "set to empty string":
   2116    * \code
   2117    * if(s.isBogus()) {
   2118    *   s.remove();           // set to an empty string (remove all), or
   2119    *   s.remove(0, INT32_MAX); // set to an empty string (remove all), or
   2120    *   s.truncate(0);        // set to an empty string (complete truncation), or
   2121    *   s=UnicodeString();    // assign an empty string, or
   2122    *   s.setTo((UChar32)-1); // set to a pseudo code point that is out of range, or
   2123    *   static const UChar nul=0;
   2124    *   s.setTo(&nul, 0);     // set to an empty C Unicode string
   2125    * }
   2126    * \endcode
   2127    *
   2128    * @see isBogus()
   2129    * @stable ICU 2.0
   2130    */
   2131   void setToBogus();
   2132 
   2133   /**
   2134    * Set the character at the specified offset to the specified character.
   2135    * @param offset A valid offset into the text of the character to set
   2136    * @param ch The new character
   2137    * @return A reference to this
   2138    * @stable ICU 2.0
   2139    */
   2140   UnicodeString& setCharAt(int32_t offset,
   2141                UChar ch);
   2142 
   2143 
   2144   /* Append operations */
   2145 
   2146   /**
   2147    * Append operator. Append the code unit <TT>ch</TT> to the UnicodeString
   2148    * object.
   2149    * @param ch the code unit to be appended
   2150    * @return a reference to this
   2151    * @stable ICU 2.0
   2152    */
   2153  inline  UnicodeString& operator+= (UChar ch);
   2154 
   2155   /**
   2156    * Append operator. Append the code point <TT>ch</TT> to the UnicodeString
   2157    * object.
   2158    * @param ch the code point to be appended
   2159    * @return a reference to this
   2160    * @stable ICU 2.0
   2161    */
   2162  inline  UnicodeString& operator+= (UChar32 ch);
   2163 
   2164   /**
   2165    * Append operator. Append the characters in <TT>srcText</TT> to the
   2166    * UnicodeString object. <TT>srcText</TT> is not modified.
   2167    * @param srcText the source for the new characters
   2168    * @return a reference to this
   2169    * @stable ICU 2.0
   2170    */
   2171   inline UnicodeString& operator+= (const UnicodeString& srcText);
   2172 
   2173   /**
   2174    * Append the characters
   2175    * in <TT>srcText</TT> in the range
   2176    * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>) to the
   2177    * UnicodeString object at offset <TT>start</TT>. <TT>srcText</TT>
   2178    * is not modified.
   2179    * @param srcText the source for the new characters
   2180    * @param srcStart the offset into <TT>srcText</TT> where new characters
   2181    * will be obtained
   2182    * @param srcLength the number of characters in <TT>srcText</TT> in
   2183    * the append string
   2184    * @return a reference to this
   2185    * @stable ICU 2.0
   2186    */
   2187   inline UnicodeString& append(const UnicodeString& srcText,
   2188             int32_t srcStart,
   2189             int32_t srcLength);
   2190 
   2191   /**
   2192    * Append the characters in <TT>srcText</TT> to the UnicodeString object.
   2193    * <TT>srcText</TT> is not modified.
   2194    * @param srcText the source for the new characters
   2195    * @return a reference to this
   2196    * @stable ICU 2.0
   2197    */
   2198   inline UnicodeString& append(const UnicodeString& srcText);
   2199 
   2200   /**
   2201    * Append the characters in <TT>srcChars</TT> in the range
   2202    * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>) to the UnicodeString
   2203    * object at offset
   2204    * <TT>start</TT>. <TT>srcChars</TT> is not modified.
   2205    * @param srcChars the source for the new characters
   2206    * @param srcStart the offset into <TT>srcChars</TT> where new characters
   2207    * will be obtained
   2208    * @param srcLength the number of characters in <TT>srcChars</TT> in
   2209    *                  the append string; can be -1 if <TT>srcChars</TT> is NUL-terminated
   2210    * @return a reference to this
   2211    * @stable ICU 2.0
   2212    */
   2213   inline UnicodeString& append(const UChar *srcChars,
   2214             int32_t srcStart,
   2215             int32_t srcLength);
   2216 
   2217   /**
   2218    * Append the characters in <TT>srcChars</TT> to the UnicodeString object
   2219    * at offset <TT>start</TT>. <TT>srcChars</TT> is not modified.
   2220    * @param srcChars the source for the new characters
   2221    * @param srcLength the number of Unicode characters in <TT>srcChars</TT>;
   2222    *                  can be -1 if <TT>srcChars</TT> is NUL-terminated
   2223    * @return a reference to this
   2224    * @stable ICU 2.0
   2225    */
   2226   inline UnicodeString& append(const UChar *srcChars,
   2227             int32_t srcLength);
   2228 
   2229   /**
   2230    * Append the code unit <TT>srcChar</TT> to the UnicodeString object.
   2231    * @param srcChar the code unit to append
   2232    * @return a reference to this
   2233    * @stable ICU 2.0
   2234    */
   2235   inline UnicodeString& append(UChar srcChar);
   2236 
   2237   /**
   2238    * Append the code point <TT>srcChar</TT> to the UnicodeString object.
   2239    * @param srcChar the code point to append
   2240    * @return a reference to this
   2241    * @stable ICU 2.0
   2242    */
   2243   UnicodeString& append(UChar32 srcChar);
   2244 
   2245 
   2246   /* Insert operations */
   2247 
   2248   /**
   2249    * Insert the characters in <TT>srcText</TT> in the range
   2250    * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>) into the UnicodeString
   2251    * object at offset <TT>start</TT>. <TT>srcText</TT> is not modified.
   2252    * @param start the offset where the insertion begins
   2253    * @param srcText the source for the new characters
   2254    * @param srcStart the offset into <TT>srcText</TT> where new characters
   2255    * will be obtained
   2256    * @param srcLength the number of characters in <TT>srcText</TT> in
   2257    * the insert string
   2258    * @return a reference to this
   2259    * @stable ICU 2.0
   2260    */
   2261   inline UnicodeString& insert(int32_t start,
   2262             const UnicodeString& srcText,
   2263             int32_t srcStart,
   2264             int32_t srcLength);
   2265 
   2266   /**
   2267    * Insert the characters in <TT>srcText</TT> into the UnicodeString object
   2268    * at offset <TT>start</TT>. <TT>srcText</TT> is not modified.
   2269    * @param start the offset where the insertion begins
   2270    * @param srcText the source for the new characters
   2271    * @return a reference to this
   2272    * @stable ICU 2.0
   2273    */
   2274   inline UnicodeString& insert(int32_t start,
   2275             const UnicodeString& srcText);
   2276 
   2277   /**
   2278    * Insert the characters in <TT>srcChars</TT> in the range
   2279    * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>) into the UnicodeString
   2280    *  object at offset <TT>start</TT>. <TT>srcChars</TT> is not modified.
   2281    * @param start the offset at which the insertion begins
   2282    * @param srcChars the source for the new characters
   2283    * @param srcStart the offset into <TT>srcChars</TT> where new characters
   2284    * will be obtained
   2285    * @param srcLength the number of characters in <TT>srcChars</TT>
   2286    * in the insert string
   2287    * @return a reference to this
   2288    * @stable ICU 2.0
   2289    */
   2290   inline UnicodeString& insert(int32_t start,
   2291             const UChar *srcChars,
   2292             int32_t srcStart,
   2293             int32_t srcLength);
   2294 
   2295   /**
   2296    * Insert the characters in <TT>srcChars</TT> into the UnicodeString object
   2297    * at offset <TT>start</TT>. <TT>srcChars</TT> is not modified.
   2298    * @param start the offset where the insertion begins
   2299    * @param srcChars the source for the new characters
   2300    * @param srcLength the number of Unicode characters in srcChars.
   2301    * @return a reference to this
   2302    * @stable ICU 2.0
   2303    */
   2304   inline UnicodeString& insert(int32_t start,
   2305             const UChar *srcChars,
   2306             int32_t srcLength);
   2307 
   2308   /**
   2309    * Insert the code unit <TT>srcChar</TT> into the UnicodeString object at
   2310    * offset <TT>start</TT>.
   2311    * @param start the offset at which the insertion occurs
   2312    * @param srcChar the code unit to insert
   2313    * @return a reference to this
   2314    * @stable ICU 2.0
   2315    */
   2316   inline UnicodeString& insert(int32_t start,
   2317             UChar srcChar);
   2318 
   2319   /**
   2320    * Insert the code point <TT>srcChar</TT> into the UnicodeString object at
   2321    * offset <TT>start</TT>.
   2322    * @param start the offset at which the insertion occurs
   2323    * @param srcChar the code point to insert
   2324    * @return a reference to this
   2325    * @stable ICU 2.0
   2326    */
   2327   inline UnicodeString& insert(int32_t start,
   2328             UChar32 srcChar);
   2329 
   2330 
   2331   /* Replace operations */
   2332 
   2333   /**
   2334    * Replace the characters in the range
   2335    * [<TT>start</TT>, <TT>start + length</TT>) with the characters in
   2336    * <TT>srcText</TT> in the range
   2337    * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
   2338    * <TT>srcText</TT> is not modified.
   2339    * @param start the offset at which the replace operation begins
   2340    * @param length the number of characters to replace. The character at
   2341    * <TT>start + length</TT> is not modified.
   2342    * @param srcText the source for the new characters
   2343    * @param srcStart the offset into <TT>srcText</TT> where new characters
   2344    * will be obtained
   2345    * @param srcLength the number of characters in <TT>srcText</TT> in
   2346    * the replace string
   2347    * @return a reference to this
   2348    * @stable ICU 2.0
   2349    */
   2350   UnicodeString& replace(int32_t start,
   2351              int32_t length,
   2352              const UnicodeString& srcText,
   2353              int32_t srcStart,
   2354              int32_t srcLength);
   2355 
   2356   /**
   2357    * Replace the characters in the range
   2358    * [<TT>start</TT>, <TT>start + length</TT>)
   2359    * with the characters in <TT>srcText</TT>.  <TT>srcText</TT> is
   2360    *  not modified.
   2361    * @param start the offset at which the replace operation begins
   2362    * @param length the number of characters to replace. The character at
   2363    * <TT>start + length</TT> is not modified.
   2364    * @param srcText the source for the new characters
   2365    * @return a reference to this
   2366    * @stable ICU 2.0
   2367    */
   2368   UnicodeString& replace(int32_t start,
   2369              int32_t length,
   2370              const UnicodeString& srcText);
   2371 
   2372   /**
   2373    * Replace the characters in the range
   2374    * [<TT>start</TT>, <TT>start + length</TT>) with the characters in
   2375    * <TT>srcChars</TT> in the range
   2376    * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>). <TT>srcChars</TT>
   2377    * is not modified.
   2378    * @param start the offset at which the replace operation begins
   2379    * @param length the number of characters to replace.  The character at
   2380    * <TT>start + length</TT> is not modified.
   2381    * @param srcChars the source for the new characters
   2382    * @param srcStart the offset into <TT>srcChars</TT> where new characters
   2383    * will be obtained
   2384    * @param srcLength the number of characters in <TT>srcChars</TT>
   2385    * in the replace string
   2386    * @return a reference to this
   2387    * @stable ICU 2.0
   2388    */
   2389   UnicodeString& replace(int32_t start,
   2390              int32_t length,
   2391              const UChar *srcChars,
   2392              int32_t srcStart,
   2393              int32_t srcLength);
   2394 
   2395   /**
   2396    * Replace the characters in the range
   2397    * [<TT>start</TT>, <TT>start + length</TT>) with the characters in
   2398    * <TT>srcChars</TT>.  <TT>srcChars</TT> is not modified.
   2399    * @param start the offset at which the replace operation begins
   2400    * @param length number of characters to replace.  The character at
   2401    * <TT>start + length</TT> is not modified.
   2402    * @param srcChars the source for the new characters
   2403    * @param srcLength the number of Unicode characters in srcChars
   2404    * @return a reference to this
   2405    * @stable ICU 2.0
   2406    */
   2407   inline UnicodeString& replace(int32_t start,
   2408              int32_t length,
   2409              const UChar *srcChars,
   2410              int32_t srcLength);
   2411 
   2412   /**
   2413    * Replace the characters in the range
   2414    * [<TT>start</TT>, <TT>start + length</TT>) with the code unit
   2415    * <TT>srcChar</TT>.
   2416    * @param start the offset at which the replace operation begins
   2417    * @param length the number of characters to replace.  The character at
   2418    * <TT>start + length</TT> is not modified.
   2419    * @param srcChar the new code unit
   2420    * @return a reference to this
   2421    * @stable ICU 2.0
   2422    */
   2423   inline UnicodeString& replace(int32_t start,
   2424              int32_t length,
   2425              UChar srcChar);
   2426 
   2427   /**
   2428    * Replace the characters in the range
   2429    * [<TT>start</TT>, <TT>start + length</TT>) with the code point
   2430    * <TT>srcChar</TT>.
   2431    * @param start the offset at which the replace operation begins
   2432    * @param length the number of characters to replace.  The character at
   2433    * <TT>start + length</TT> is not modified.
   2434    * @param srcChar the new code point
   2435    * @return a reference to this
   2436    * @stable ICU 2.0
   2437    */
   2438   UnicodeString& replace(int32_t start, int32_t length, UChar32 srcChar);
   2439 
   2440   /**
   2441    * Replace the characters in the range [<TT>start</TT>, <TT>limit</TT>)
   2442    * with the characters in <TT>srcText</TT>. <TT>srcText</TT> is not modified.
   2443    * @param start the offset at which the replace operation begins
   2444    * @param limit the offset immediately following the replace range
   2445    * @param srcText the source for the new characters
   2446    * @return a reference to this
   2447    * @stable ICU 2.0
   2448    */
   2449   inline UnicodeString& replaceBetween(int32_t start,
   2450                 int32_t limit,
   2451                 const UnicodeString& srcText);
   2452 
   2453   /**
   2454    * Replace the characters in the range [<TT>start</TT>, <TT>limit</TT>)
   2455    * with the characters in <TT>srcText</TT> in the range
   2456    * [<TT>srcStart</TT>, <TT>srcLimit</TT>). <TT>srcText</TT> is not modified.
   2457    * @param start the offset at which the replace operation begins
   2458    * @param limit the offset immediately following the replace range
   2459    * @param srcText the source for the new characters
   2460    * @param srcStart the offset into <TT>srcChars</TT> where new characters
   2461    * will be obtained
   2462    * @param srcLimit the offset immediately following the range to copy
   2463    * in <TT>srcText</TT>
   2464    * @return a reference to this
   2465    * @stable ICU 2.0
   2466    */
   2467   inline UnicodeString& replaceBetween(int32_t start,
   2468                 int32_t limit,
   2469                 const UnicodeString& srcText,
   2470                 int32_t srcStart,
   2471                 int32_t srcLimit);
   2472 
   2473   /**
   2474    * Replace a substring of this object with the given text.
   2475    * @param start the beginning index, inclusive; <code>0 <= start
   2476    * <= limit</code>.
   2477    * @param limit the ending index, exclusive; <code>start <= limit
   2478    * <= length()</code>.
   2479    * @param text the text to replace characters <code>start</code>
   2480    * to <code>limit - 1</code>
   2481    * @stable ICU 2.0
   2482    */
   2483   virtual void handleReplaceBetween(int32_t start,
   2484                                     int32_t limit,
   2485                                     const UnicodeString& text);
   2486 
   2487   /**
   2488    * Replaceable API
   2489    * @return TRUE if it has MetaData
   2490    * @stable ICU 2.4
   2491    */
   2492   virtual UBool hasMetaData() const;
   2493 
   2494   /**
   2495    * Copy a substring of this object, retaining attribute (out-of-band)
   2496    * information.  This method is used to duplicate or reorder substrings.
   2497    * The destination index must not overlap the source range.
   2498    *
   2499    * @param start the beginning index, inclusive; <code>0 <= start <=
   2500    * limit</code>.
   2501    * @param limit the ending index, exclusive; <code>start <= limit <=
   2502    * length()</code>.
   2503    * @param dest the destination index.  The characters from
   2504    * <code>start..limit-1</code> will be copied to <code>dest</code>.
   2505    * Implementations of this method may assume that <code>dest <= start ||
   2506    * dest >= limit</code>.
   2507    * @stable ICU 2.0
   2508    */
   2509   virtual void copy(int32_t start, int32_t limit, int32_t dest);
   2510 
   2511   /* Search and replace operations */
   2512 
   2513   /**
   2514    * Replace all occurrences of characters in oldText with the characters
   2515    * in newText
   2516    * @param oldText the text containing the search text
   2517    * @param newText the text containing the replacement text
   2518    * @return a reference to this
   2519    * @stable ICU 2.0
   2520    */
   2521   inline UnicodeString& findAndReplace(const UnicodeString& oldText,
   2522                 const UnicodeString& newText);
   2523 
   2524   /**
   2525    * Replace all occurrences of characters in oldText with characters
   2526    * in newText
   2527    * in the range [<TT>start</TT>, <TT>start + length</TT>).
   2528    * @param start the start of the range in which replace will performed
   2529    * @param length the length of the range in which replace will be performed
   2530    * @param oldText the text containing the search text
   2531    * @param newText the text containing the replacement text
   2532    * @return a reference to this
   2533    * @stable ICU 2.0
   2534    */
   2535   inline UnicodeString& findAndReplace(int32_t start,
   2536                 int32_t length,
   2537                 const UnicodeString& oldText,
   2538                 const UnicodeString& newText);
   2539 
   2540   /**
   2541    * Replace all occurrences of characters in oldText in the range
   2542    * [<TT>oldStart</TT>, <TT>oldStart + oldLength</TT>) with the characters
   2543    * in newText in the range
   2544    * [<TT>newStart</TT>, <TT>newStart + newLength</TT>)
   2545    * in the range [<TT>start</TT>, <TT>start + length</TT>).
   2546    * @param start the start of the range in which replace will performed
   2547    * @param length the length of the range in which replace will be performed
   2548    * @param oldText the text containing the search text
   2549    * @param oldStart the start of the search range in <TT>oldText</TT>
   2550    * @param oldLength the length of the search range in <TT>oldText</TT>
   2551    * @param newText the text containing the replacement text
   2552    * @param newStart the start of the replacement range in <TT>newText</TT>
   2553    * @param newLength the length of the replacement range in <TT>newText</TT>
   2554    * @return a reference to this
   2555    * @stable ICU 2.0
   2556    */
   2557   UnicodeString& findAndReplace(int32_t start,
   2558                 int32_t length,
   2559                 const UnicodeString& oldText,
   2560                 int32_t oldStart,
   2561                 int32_t oldLength,
   2562                 const UnicodeString& newText,
   2563                 int32_t newStart,
   2564                 int32_t newLength);
   2565 
   2566 
   2567   /* Remove operations */
   2568 
   2569   /**
   2570    * Remove all characters from the UnicodeString object.
   2571    * @return a reference to this
   2572    * @stable ICU 2.0
   2573    */
   2574   inline UnicodeString& remove(void);
   2575 
   2576   /**
   2577    * Remove the characters in the range
   2578    * [<TT>start</TT>, <TT>start + length</TT>) from the UnicodeString object.
   2579    * @param start the offset of the first character to remove
   2580    * @param length the number of characters to remove
   2581    * @return a reference to this
   2582    * @stable ICU 2.0
   2583    */
   2584   inline UnicodeString& remove(int32_t start,
   2585                                int32_t length = (int32_t)INT32_MAX);
   2586 
   2587   /**
   2588    * Remove the characters in the range
   2589    * [<TT>start</TT>, <TT>limit</TT>) from the UnicodeString object.
   2590    * @param start the offset of the first character to remove
   2591    * @param limit the offset immediately following the range to remove
   2592    * @return a reference to this
   2593    * @stable ICU 2.0
   2594    */
   2595   inline UnicodeString& removeBetween(int32_t start,
   2596                                       int32_t limit = (int32_t)INT32_MAX);
   2597 
   2598   /**
   2599    * Retain only the characters in the range
   2600    * [<code>start</code>, <code>limit</code>) from the UnicodeString object.
   2601    * Removes characters before <code>start</code> and at and after <code>limit</code>.
   2602    * @param start the offset of the first character to retain
   2603    * @param limit the offset immediately following the range to retain
   2604    * @return a reference to this
   2605    * @stable ICU 4.4
   2606    */
   2607   inline UnicodeString &retainBetween(int32_t start, int32_t limit = INT32_MAX);
   2608 
   2609   /* Length operations */
   2610 
   2611   /**
   2612    * Pad the start of this UnicodeString with the character <TT>padChar</TT>.
   2613    * If the length of this UnicodeString is less than targetLength,
   2614    * length() - targetLength copies of padChar will be added to the
   2615    * beginning of this UnicodeString.
   2616    * @param targetLength the desired length of the string
   2617    * @param padChar the character to use for padding. Defaults to
   2618    * space (U+0020)
   2619    * @return TRUE if the text was padded, FALSE otherwise.
   2620    * @stable ICU 2.0
   2621    */
   2622   UBool padLeading(int32_t targetLength,
   2623                     UChar padChar = 0x0020);
   2624 
   2625   /**
   2626    * Pad the end of this UnicodeString with the character <TT>padChar</TT>.
   2627    * If the length of this UnicodeString is less than targetLength,
   2628    * length() - targetLength copies of padChar will be added to the
   2629    * end of this UnicodeString.
   2630    * @param targetLength the desired length of the string
   2631    * @param padChar the character to use for padding. Defaults to
   2632    * space (U+0020)
   2633    * @return TRUE if the text was padded, FALSE otherwise.
   2634    * @stable ICU 2.0
   2635    */
   2636   UBool padTrailing(int32_t targetLength,
   2637                      UChar padChar = 0x0020);
   2638 
   2639   /**
   2640    * Truncate this UnicodeString to the <TT>targetLength</TT>.
   2641    * @param targetLength the desired length of this UnicodeString.
   2642    * @return TRUE if the text was truncated, FALSE otherwise
   2643    * @stable ICU 2.0
   2644    */
   2645   inline UBool truncate(int32_t targetLength);
   2646 
   2647   /**
   2648    * Trims leading and trailing whitespace from this UnicodeString.
   2649    * @return a reference to this
   2650    * @stable ICU 2.0
   2651    */
   2652   UnicodeString& trim(void);
   2653 
   2654 
   2655   /* Miscellaneous operations */
   2656 
   2657   /**
   2658    * Reverse this UnicodeString in place.
   2659    * @return a reference to this
   2660    * @stable ICU 2.0
   2661    */
   2662   inline UnicodeString& reverse(void);
   2663 
   2664   /**
   2665    * Reverse the range [<TT>start</TT>, <TT>start + length</TT>) in
   2666    * this UnicodeString.
   2667    * @param start the start of the range to reverse
   2668    * @param length the number of characters to to reverse
   2669    * @return a reference to this
   2670    * @stable ICU 2.0
   2671    */
   2672   inline UnicodeString& reverse(int32_t start,
   2673              int32_t length);
   2674 
   2675   /**
   2676    * Convert the characters in this to UPPER CASE following the conventions of
   2677    * the default locale.
   2678    * @return A reference to this.
   2679    * @stable ICU 2.0
   2680    */
   2681   UnicodeString& toUpper(void);
   2682 
   2683   /**
   2684    * Convert the characters in this to UPPER CASE following the conventions of
   2685    * a specific locale.
   2686    * @param locale The locale containing the conventions to use.
   2687    * @return A reference to this.
   2688    * @stable ICU 2.0
   2689    */
   2690   UnicodeString& toUpper(const Locale& locale);
   2691 
   2692   /**
   2693    * Convert the characters in this to lower case following the conventions of
   2694    * the default locale.
   2695    * @return A reference to this.
   2696    * @stable ICU 2.0
   2697    */
   2698   UnicodeString& toLower(void);
   2699 
   2700   /**
   2701    * Convert the characters in this to lower case following the conventions of
   2702    * a specific locale.
   2703    * @param locale The locale containing the conventions to use.
   2704    * @return A reference to this.
   2705    * @stable ICU 2.0
   2706    */
   2707   UnicodeString& toLower(const Locale& locale);
   2708 
   2709 #if !UCONFIG_NO_BREAK_ITERATION
   2710 
   2711   /**
   2712    * Titlecase this string, convenience function using the default locale.
   2713    *
   2714    * Casing is locale-dependent and context-sensitive.
   2715    * Titlecasing uses a break iterator to find the first characters of words
   2716    * that are to be titlecased. It titlecases those characters and lowercases
   2717    * all others.
   2718    *
   2719    * The titlecase break iterator can be provided to customize for arbitrary
   2720    * styles, using rules and dictionaries beyond the standard iterators.
   2721    * It may be more efficient to always provide an iterator to avoid
   2722    * opening and closing one for each string.
   2723    * The standard titlecase iterator for the root locale implements the
   2724    * algorithm of Unicode TR 21.
   2725    *
   2726    * This function uses only the setText(), first() and next() methods of the
   2727    * provided break iterator.
   2728    *
   2729    * @param titleIter A break iterator to find the first characters of words
   2730    *                  that are to be titlecased.
   2731    *                  If none is provided (0), then a standard titlecase
   2732    *                  break iterator is opened.
   2733    *                  Otherwise the provided iterator is set to the string's text.
   2734    * @return A reference to this.
   2735    * @stable ICU 2.1
   2736    */
   2737   UnicodeString &toTitle(BreakIterator *titleIter);
   2738 
   2739   /**
   2740    * Titlecase this string.
   2741    *
   2742    * Casing is locale-dependent and context-sensitive.
   2743    * Titlecasing uses a break iterator to find the first characters of words
   2744    * that are to be titlecased. It titlecases those characters and lowercases
   2745    * all others.
   2746    *
   2747    * The titlecase break iterator can be provided to customize for arbitrary
   2748    * styles, using rules and dictionaries beyond the standard iterators.
   2749    * It may be more efficient to always provide an iterator to avoid
   2750    * opening and closing one for each string.
   2751    * The standard titlecase iterator for the root locale implements the
   2752    * algorithm of Unicode TR 21.
   2753    *
   2754    * This function uses only the setText(), first() and next() methods of the
   2755    * provided break iterator.
   2756    *
   2757    * @param titleIter A break iterator to find the first characters of words
   2758    *                  that are to be titlecased.
   2759    *                  If none is provided (0), then a standard titlecase
   2760    *                  break iterator is opened.
   2761    *                  Otherwise the provided iterator is set to the string's text.
   2762    * @param locale    The locale to consider.
   2763    * @return A reference to this.
   2764    * @stable ICU 2.1
   2765    */
   2766   UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale);
   2767 
   2768   /**
   2769    * Titlecase this string, with options.
   2770    *
   2771    * Casing is locale-dependent and context-sensitive.
   2772    * Titlecasing uses a break iterator to find the first characters of words
   2773    * that are to be titlecased. It titlecases those characters and lowercases
   2774    * all others. (This can be modified with options.)
   2775    *
   2776    * The titlecase break iterator can be provided to customize for arbitrary
   2777    * styles, using rules and dictionaries beyond the standard iterators.
   2778    * It may be more efficient to always provide an iterator to avoid
   2779    * opening and closing one for each string.
   2780    * The standard titlecase iterator for the root locale implements the
   2781    * algorithm of Unicode TR 21.
   2782    *
   2783    * This function uses only the setText(), first() and next() methods of the
   2784    * provided break iterator.
   2785    *
   2786    * @param titleIter A break iterator to find the first characters of words
   2787    *                  that are to be titlecased.
   2788    *                  If none is provided (0), then a standard titlecase
   2789    *                  break iterator is opened.
   2790    *                  Otherwise the provided iterator is set to the string's text.
   2791    * @param locale    The locale to consider.
   2792    * @param options Options bit set, see ucasemap_open().
   2793    * @return A reference to this.
   2794    * @see U_TITLECASE_NO_LOWERCASE
   2795    * @see U_TITLECASE_NO_BREAK_ADJUSTMENT
   2796    * @see ucasemap_open
   2797    * @stable ICU 3.8
   2798    */
   2799   UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale, uint32_t options);
   2800 
   2801 #endif
   2802 
   2803   /**
   2804    * Case-folds the characters in this string.
   2805    *
   2806    * Case-folding is locale-independent and not context-sensitive,
   2807    * but there is an option for whether to include or exclude mappings for dotted I
   2808    * and dotless i that are marked with 'T' in CaseFolding.txt.
   2809    *
   2810    * The result may be longer or shorter than the original.
   2811    *
   2812    * @param options Either U_FOLD_CASE_DEFAULT or U_FOLD_CASE_EXCLUDE_SPECIAL_I
   2813    * @return A reference to this.
   2814    * @stable ICU 2.0
   2815    */
   2816   UnicodeString &foldCase(uint32_t options=0 /*U_FOLD_CASE_DEFAULT*/);
   2817 
   2818   //========================================
   2819   // Access to the internal buffer
   2820   //========================================
   2821 
   2822   /**
   2823    * Get a read/write pointer to the internal buffer.
   2824    * The buffer is guaranteed to be large enough for at least minCapacity UChars,
   2825    * writable, and is still owned by the UnicodeString object.
   2826    * Calls to getBuffer(minCapacity) must not be nested, and
   2827    * must be matched with calls to releaseBuffer(newLength).
   2828    * If the string buffer was read-only or shared,
   2829    * then it will be reallocated and copied.
   2830    *
   2831    * An attempted nested call will return 0, and will not further modify the
   2832    * state of the UnicodeString object.
   2833    * It also returns 0 if the string is bogus.
   2834    *
   2835    * The actual capacity of the string buffer may be larger than minCapacity.
   2836    * getCapacity() returns the actual capacity.
   2837    * For many operations, the full capacity should be used to avoid reallocations.
   2838    *
   2839    * While the buffer is "open" between getBuffer(minCapacity)
   2840    * and releaseBuffer(newLength), the following applies:
   2841    * - The string length is set to 0.
   2842    * - Any read API call on the UnicodeString object will behave like on a 0-length string.
   2843    * - Any write API call on the UnicodeString object is disallowed and will have no effect.
   2844    * - You can read from and write to the returned buffer.
   2845    * - The previous string contents will still be in the buffer;
   2846    *   if you want to use it, then you need to call length() before getBuffer(minCapacity).
   2847    *   If the length() was greater than minCapacity, then any contents after minCapacity
   2848    *   may be lost.
   2849    *   The buffer contents is not NUL-terminated by getBuffer().
   2850    *   If length()<getCapacity() then you can terminate it by writing a NUL
   2851    *   at index length().
   2852    * - You must call releaseBuffer(newLength) before and in order to
   2853    *   return to normal UnicodeString operation.
   2854    *
   2855    * @param minCapacity the minimum number of UChars that are to be available
   2856    *        in the buffer, starting at the returned pointer;
   2857    *        default to the current string capacity if minCapacity==-1
   2858    * @return a writable pointer to the internal string buffer,
   2859    *         or 0 if an error occurs (nested calls, out of memory)
   2860    *
   2861    * @see releaseBuffer
   2862    * @see getTerminatedBuffer()
   2863    * @stable ICU 2.0
   2864    */
   2865   UChar *getBuffer(int32_t minCapacity);
   2866 
   2867   /**
   2868    * Release a read/write buffer on a UnicodeString object with an
   2869    * "open" getBuffer(minCapacity).
   2870    * This function must be called in a matched pair with getBuffer(minCapacity).
   2871    * releaseBuffer(newLength) must be called if and only if a getBuffer(minCapacity) is "open".
   2872    *
   2873    * It will set the string length to newLength, at most to the current capacity.
   2874    * If newLength==-1 then it will set the length according to the
   2875    * first NUL in the buffer, or to the capacity if there is no NUL.
   2876    *
   2877    * After calling releaseBuffer(newLength) the UnicodeString is back to normal operation.
   2878    *
   2879    * @param newLength the new length of the UnicodeString object;
   2880    *        defaults to the current capacity if newLength is greater than that;
   2881    *        if newLength==-1, it defaults to u_strlen(buffer) but not more than
   2882    *        the current capacity of the string
   2883    *
   2884    * @see getBuffer(int32_t minCapacity)
   2885    * @stable ICU 2.0
   2886    */
   2887   void releaseBuffer(int32_t newLength=-1);
   2888 
   2889   /**
   2890    * Get a read-only pointer to the internal buffer.
   2891    * This can be called at any time on a valid UnicodeString.
   2892    *
   2893    * It returns 0 if the string is bogus, or
   2894    * during an "open" getBuffer(minCapacity).
   2895    *
   2896    * It can be called as many times as desired.
   2897    * The pointer that it returns will remain valid until the UnicodeString object is modified,
   2898    * at which time the pointer is semantically invalidated and must not be used any more.
   2899    *
   2900    * The capacity of the buffer can be determined with getCapacity().
   2901    * The part after length() may or may not be initialized and valid,
   2902    * depending on the history of the UnicodeString object.
   2903    *
   2904    * The buffer contents is (probably) not NUL-terminated.
   2905    * You can check if it is with
   2906    * <code>(s.length()<s.getCapacity() && buffer[s.length()]==0)</code>.
   2907    * (See getTerminatedBuffer().)
   2908    *
   2909    * The buffer may reside in read-only memory. Its contents must not
   2910    * be modified.
   2911    *
   2912    * @return a read-only pointer to the internal string buffer,
   2913    *         or 0 if the string is empty or bogus
   2914    *
   2915    * @see getBuffer(int32_t minCapacity)
   2916    * @see getTerminatedBuffer()
   2917    * @stable ICU 2.0
   2918    */
   2919   inline const UChar *getBuffer() const;
   2920 
   2921   /**
   2922    * Get a read-only pointer to the internal buffer,
   2923    * making sure that it is NUL-terminated.
   2924    * This can be called at any time on a valid UnicodeString.
   2925    *
   2926    * It returns 0 if the string is bogus, or
   2927    * during an "open" getBuffer(minCapacity), or if the buffer cannot
   2928    * be NUL-terminated (because memory allocation failed).
   2929    *
   2930    * It can be called as many times as desired.
   2931    * The pointer that it returns will remain valid until the UnicodeString object is modified,
   2932    * at which time the pointer is semantically invalidated and must not be used any more.
   2933    *
   2934    * The capacity of the buffer can be determined with getCapacity().
   2935    * The part after length()+1 may or may not be initialized and valid,
   2936    * depending on the history of the UnicodeString object.
   2937    *
   2938    * The buffer contents is guaranteed to be NUL-terminated.
   2939    * getTerminatedBuffer() may reallocate the buffer if a terminating NUL
   2940    * is written.
   2941    * For this reason, this function is not const, unlike getBuffer().
   2942    * Note that a UnicodeString may also contain NUL characters as part of its contents.
   2943    *
   2944    * The buffer may reside in read-only memory. Its contents must not
   2945    * be modified.
   2946    *
   2947    * @return a read-only pointer to the internal string buffer,
   2948    *         or 0 if the string is empty or bogus
   2949    *
   2950    * @see getBuffer(int32_t minCapacity)
   2951    * @see getBuffer()
   2952    * @stable ICU 2.2
   2953    */
   2954   const UChar *getTerminatedBuffer();
   2955 
   2956   //========================================
   2957   // Constructors
   2958   //========================================
   2959 
   2960   /** Construct an empty UnicodeString.
   2961    * @stable ICU 2.0
   2962    */
   2963   inline UnicodeString();
   2964 
   2965   /**
   2966    * Construct a UnicodeString with capacity to hold <TT>capacity</TT> UChars
   2967    * @param capacity the number of UChars this UnicodeString should hold
   2968    * before a resize is necessary; if count is greater than 0 and count
   2969    * code points c take up more space than capacity, then capacity is adjusted
   2970    * accordingly.
   2971    * @param c is used to initially fill the string
   2972    * @param count specifies how many code points c are to be written in the
   2973    *              string
   2974    * @stable ICU 2.0
   2975    */
   2976   UnicodeString(int32_t capacity, UChar32 c, int32_t count);
   2977 
   2978   /**
   2979    * Single UChar (code unit) constructor.
   2980    *
   2981    * It is recommended to mark this constructor "explicit" by
   2982    * <code>-DUNISTR_FROM_CHAR_EXPLICIT=explicit</code>
   2983    * on the compiler command line or similar.
   2984    * @param ch the character to place in the UnicodeString
   2985    * @stable ICU 2.0
   2986    */
   2987   UNISTR_FROM_CHAR_EXPLICIT UnicodeString(UChar ch);
   2988 
   2989   /**
   2990    * Single UChar32 (code point) constructor.
   2991    *
   2992    * It is recommended to mark this constructor "explicit" by
   2993    * <code>-DUNISTR_FROM_CHAR_EXPLICIT=explicit</code>
   2994    * on the compiler command line or similar.
   2995    * @param ch the character to place in the UnicodeString
   2996    * @stable ICU 2.0
   2997    */
   2998   UNISTR_FROM_CHAR_EXPLICIT UnicodeString(UChar32 ch);
   2999 
   3000   /**
   3001    * UChar* constructor.
   3002    *
   3003    * It is recommended to mark this constructor "explicit" by
   3004    * <code>-DUNISTR_FROM_STRING_EXPLICIT=explicit</code>
   3005    * on the compiler command line or similar.
   3006    * @param text The characters to place in the UnicodeString.  <TT>text</TT>
   3007    * must be NULL (U+0000) terminated.
   3008    * @stable ICU 2.0
   3009    */
   3010   UNISTR_FROM_STRING_EXPLICIT UnicodeString(const UChar *text);
   3011 
   3012   /**
   3013    * UChar* constructor.
   3014    * @param text The characters to place in the UnicodeString.
   3015    * @param textLength The number of Unicode characters in <TT>text</TT>
   3016    * to copy.
   3017    * @stable ICU 2.0
   3018    */
   3019   UnicodeString(const UChar *text,
   3020         int32_t textLength);
   3021 
   3022   /**
   3023    * Readonly-aliasing UChar* constructor.
   3024    * The text will be used for the UnicodeString object, but
   3025    * it will not be released when the UnicodeString is destroyed.
   3026    * This has copy-on-write semantics:
   3027    * When the string is modified, then the buffer is first copied into
   3028    * newly allocated memory.
   3029    * The aliased buffer is never modified.
   3030    *
   3031    * In an assignment to another UnicodeString, when using the copy constructor
   3032    * or the assignment operator, the text will be copied.
   3033    * When using fastCopyFrom(), the text will be aliased again,
   3034    * so that both strings then alias the same readonly-text.
   3035    *
   3036    * @param isTerminated specifies if <code>text</code> is <code>NUL</code>-terminated.
   3037    *                     This must be true if <code>textLength==-1</code>.
   3038    * @param text The characters to alias for the UnicodeString.
   3039    * @param textLength The number of Unicode characters in <code>text</code> to alias.
   3040    *                   If -1, then this constructor will determine the length
   3041    *                   by calling <code>u_strlen()</code>.
   3042    * @stable ICU 2.0
   3043    */
   3044   UnicodeString(UBool isTerminated,
   3045                 const UChar *text,
   3046                 int32_t textLength);
   3047 
   3048   /**
   3049    * Writable-aliasing UChar* constructor.
   3050    * The text will be used for the UnicodeString object, but
   3051    * it will not be released when the UnicodeString is destroyed.
   3052    * This has write-through semantics:
   3053    * For as long as the capacity of the buffer is sufficient, write operations
   3054    * will directly affect the buffer. When more capacity is necessary, then
   3055    * a new buffer will be allocated and the contents copied as with regularly
   3056    * constructed strings.
   3057    * In an assignment to another UnicodeString, the buffer will be copied.
   3058    * The extract(UChar *dst) function detects whether the dst pointer is the same
   3059    * as the string buffer itself and will in this case not copy the contents.
   3060    *
   3061    * @param buffer The characters to alias for the UnicodeString.
   3062    * @param buffLength The number of Unicode characters in <code>buffer</code> to alias.
   3063    * @param buffCapacity The size of <code>buffer</code> in UChars.
   3064    * @stable ICU 2.0
   3065    */
   3066   UnicodeString(UChar *buffer, int32_t buffLength, int32_t buffCapacity);
   3067 
   3068 #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
   3069 
   3070   /**
   3071    * char* constructor.
   3072    * Uses the default converter (and thus depends on the ICU conversion code)
   3073    * unless U_CHARSET_IS_UTF8 is set to 1.
   3074    *
   3075    * For ASCII (really "invariant character") strings it is more efficient to use
   3076    * the constructor that takes a US_INV (for its enum EInvariant).
   3077    * For ASCII (invariant-character) string literals, see UNICODE_STRING and
   3078    * UNICODE_STRING_SIMPLE.
   3079    *
   3080    * It is recommended to mark this constructor "explicit" by
   3081    * <code>-DUNISTR_FROM_STRING_EXPLICIT=explicit</code>
   3082    * on the compiler command line or similar.
   3083    * @param codepageData an array of bytes, null-terminated,
   3084    *                     in the platform's default codepage.
   3085    * @stable ICU 2.0
   3086    * @see UNICODE_STRING
   3087    * @see UNICODE_STRING_SIMPLE
   3088    */
   3089   UNISTR_FROM_STRING_EXPLICIT UnicodeString(const char *codepageData);
   3090 
   3091   /**
   3092    * char* constructor.
   3093    * Uses the default converter (and thus depends on the ICU conversion code)
   3094    * unless U_CHARSET_IS_UTF8 is set to 1.
   3095    * @param codepageData an array of bytes in the platform's default codepage.
   3096    * @param dataLength The number of bytes in <TT>codepageData</TT>.
   3097    * @stable ICU 2.0
   3098    */
   3099   UnicodeString(const char *codepageData, int32_t dataLength);
   3100 
   3101 #endif
   3102 
   3103 #if !UCONFIG_NO_CONVERSION
   3104 
   3105   /**
   3106    * char* constructor.
   3107    * @param codepageData an array of bytes, null-terminated
   3108    * @param codepage the encoding of <TT>codepageData</TT>.  The special
   3109    * value 0 for <TT>codepage</TT> indicates that the text is in the
   3110    * platform's default codepage.
   3111    *
   3112    * If <code>codepage</code> is an empty string (<code>""</code>),
   3113    * then a simple conversion is performed on the codepage-invariant
   3114    * subset ("invariant characters") of the platform encoding. See utypes.h.
   3115    * Recommendation: For invariant-character strings use the constructor
   3116    * UnicodeString(const char *src, int32_t length, enum EInvariant inv)
   3117    * because it avoids object code dependencies of UnicodeString on
   3118    * the conversion code.
   3119    *
   3120    * @stable ICU 2.0
   3121    */
   3122   UnicodeString(const char *codepageData, const char *codepage);
   3123 
   3124   /**
   3125    * char* constructor.
   3126    * @param codepageData an array of bytes.
   3127    * @param dataLength The number of bytes in <TT>codepageData</TT>.
   3128    * @param codepage the encoding of <TT>codepageData</TT>.  The special
   3129    * value 0 for <TT>codepage</TT> indicates that the text is in the
   3130    * platform's default codepage.
   3131    * If <code>codepage</code> is an empty string (<code>""</code>),
   3132    * then a simple conversion is performed on the codepage-invariant
   3133    * subset ("invariant characters") of the platform encoding. See utypes.h.
   3134    * Recommendation: For invariant-character strings use the constructor
   3135    * UnicodeString(const char *src, int32_t length, enum EInvariant inv)
   3136    * because it avoids object code dependencies of UnicodeString on
   3137    * the conversion code.
   3138    *
   3139    * @stable ICU 2.0
   3140    */
   3141   UnicodeString(const char *codepageData, int32_t dataLength, const char *codepage);
   3142 
   3143   /**
   3144    * char * / UConverter constructor.
   3145    * This constructor uses an existing UConverter object to
   3146    * convert the codepage string to Unicode and construct a UnicodeString
   3147    * from that.
   3148    *
   3149    * The converter is reset at first.
   3150    * If the error code indicates a failure before this constructor is called,
   3151    * or if an error occurs during conversion or construction,
   3152    * then the string will be bogus.
   3153    *
   3154    * This function avoids the overhead of opening and closing a converter if
   3155    * multiple strings are constructed.
   3156    *
   3157    * @param src input codepage string
   3158    * @param srcLength length of the input string, can be -1 for NUL-terminated strings
   3159    * @param cnv converter object (ucnv_resetToUnicode() will be called),
   3160    *        can be NULL for the default converter
   3161    * @param errorCode normal ICU error code
   3162    * @stable ICU 2.0
   3163    */
   3164   UnicodeString(
   3165         const char *src, int32_t srcLength,
   3166         UConverter *cnv,
   3167         UErrorCode &errorCode);
   3168 
   3169 #endif
   3170 
   3171   /**
   3172    * Constructs a Unicode string from an invariant-character char * string.
   3173    * About invariant characters see utypes.h.
   3174    * This constructor has no runtime dependency on conversion code and is
   3175    * therefore recommended over ones taking a charset name string
   3176    * (where the empty string "" indicates invariant-character conversion).
   3177    *
   3178    * Use the macro US_INV as the third, signature-distinguishing parameter.
   3179    *
   3180    * For example:
   3181    * \code
   3182    * void fn(const char *s) {
   3183    *   UnicodeString ustr(s, -1, US_INV);
   3184    *   // use ustr ...
   3185    * }
   3186    * \endcode
   3187    *
   3188    * @param src String using only invariant characters.
   3189    * @param length Length of src, or -1 if NUL-terminated.
   3190    * @param inv Signature-distinguishing paramater, use US_INV.
   3191    *
   3192    * @see US_INV
   3193    * @stable ICU 3.2
   3194    */
   3195   UnicodeString(const char *src, int32_t length, enum EInvariant inv);
   3196 
   3197 
   3198   /**
   3199    * Copy constructor.
   3200    *
   3201    * Starting with ICU 2.4, the assignment operator and the copy constructor
   3202    * allocate a new buffer and copy the buffer contents even for readonly aliases.
   3203    * By contrast, the fastCopyFrom() function implements the old,
   3204    * more efficient but less safe behavior
   3205    * of making this string also a readonly alias to the same buffer.
   3206    *
   3207    * If the source object has an "open" buffer from getBuffer(minCapacity),
   3208    * then the copy is an empty string.
   3209    *
   3210    * @param that The UnicodeString object to copy.
   3211    * @stable ICU 2.0
   3212    * @see fastCopyFrom
   3213    */
   3214   UnicodeString(const UnicodeString& that);
   3215 
   3216 #if U_HAVE_RVALUE_REFERENCES
   3217   /**
   3218    * Move constructor, might leave src in bogus state.
   3219    * This string will have the same contents and state that the source string had.
   3220    * @param src source string
   3221    * @stable ICU 56
   3222    */
   3223   UnicodeString(UnicodeString &&src) U_NOEXCEPT;
   3224 #endif
   3225 
   3226   /**
   3227    * 'Substring' constructor from tail of source string.
   3228    * @param src The UnicodeString object to copy.
   3229    * @param srcStart The offset into <tt>src</tt> at which to start copying.
   3230    * @stable ICU 2.2
   3231    */
   3232   UnicodeString(const UnicodeString& src, int32_t srcStart);
   3233 
   3234   /**
   3235    * 'Substring' constructor from subrange of source string.
   3236    * @param src The UnicodeString object to copy.
   3237    * @param srcStart The offset into <tt>src</tt> at which to start copying.
   3238    * @param srcLength The number of characters from <tt>src</tt> to copy.
   3239    * @stable ICU 2.2
   3240    */
   3241   UnicodeString(const UnicodeString& src, int32_t srcStart, int32_t srcLength);
   3242 
   3243   /**
   3244    * Clone this object, an instance of a subclass of Replaceable.
   3245    * Clones can be used concurrently in multiple threads.
   3246    * If a subclass does not implement clone(), or if an error occurs,
   3247    * then NULL is returned.
   3248    * The clone functions in all subclasses return a pointer to a Replaceable
   3249    * because some compilers do not support covariant (same-as-this)
   3250    * return types; cast to the appropriate subclass if necessary.
   3251    * The caller must delete the clone.
   3252    *
   3253    * @return a clone of this object
   3254    *
   3255    * @see Replaceable::clone
   3256    * @see getDynamicClassID
   3257    * @stable ICU 2.6
   3258    */
   3259   virtual Replaceable *clone() const;
   3260 
   3261   /** Destructor.
   3262    * @stable ICU 2.0
   3263    */
   3264   virtual ~UnicodeString();
   3265 
   3266   /**
   3267    * Create a UnicodeString from a UTF-8 string.
   3268    * Illegal input is replaced with U+FFFD. Otherwise, errors result in a bogus string.
   3269    * Calls u_strFromUTF8WithSub().
   3270    *
   3271    * @param utf8 UTF-8 input string.
   3272    *             Note that a StringPiece can be implicitly constructed
   3273    *             from a std::string or a NUL-terminated const char * string.
   3274    * @return A UnicodeString with equivalent UTF-16 contents.
   3275    * @see toUTF8
   3276    * @see toUTF8String
   3277    * @stable ICU 4.2
   3278    */
   3279   static UnicodeString fromUTF8(StringPiece utf8);
   3280 
   3281   /**
   3282    * Create a UnicodeString from a UTF-32 string.
   3283    * Illegal input is replaced with U+FFFD. Otherwise, errors result in a bogus string.
   3284    * Calls u_strFromUTF32WithSub().
   3285    *
   3286    * @param utf32 UTF-32 input string. Must not be NULL.
   3287    * @param length Length of the input string, or -1 if NUL-terminated.
   3288    * @return A UnicodeString with equivalent UTF-16 contents.
   3289    * @see toUTF32
   3290    * @stable ICU 4.2
   3291    */
   3292   static UnicodeString fromUTF32(const UChar32 *utf32, int32_t length);
   3293 
   3294   /* Miscellaneous operations */
   3295 
   3296   /**
   3297    * Unescape a string of characters and return a string containing
   3298    * the result.  The following escape sequences are recognized:
   3299    *
   3300    * \\uhhhh       4 hex digits; h in [0-9A-Fa-f]
   3301    * \\Uhhhhhhhh   8 hex digits
   3302    * \\xhh         1-2 hex digits
   3303    * \\ooo         1-3 octal digits; o in [0-7]
   3304    * \\cX          control-X; X is masked with 0x1F
   3305    *
   3306    * as well as the standard ANSI C escapes:
   3307    *
   3308    * \\a => U+0007, \\b => U+0008, \\t => U+0009, \\n => U+000A,
   3309    * \\v => U+000B, \\f => U+000C, \\r => U+000D, \\e => U+001B,
   3310    * \\&quot; => U+0022, \\' => U+0027, \\? => U+003F, \\\\ => U+005C
   3311    *
   3312    * Anything else following a backslash is generically escaped.  For
   3313    * example, "[a\\-z]" returns "[a-z]".
   3314    *
   3315    * If an escape sequence is ill-formed, this method returns an empty
   3316    * string.  An example of an ill-formed sequence is "\\u" followed by
   3317    * fewer than 4 hex digits.
   3318    *
   3319    * This function is similar to u_unescape() but not identical to it.
   3320    * The latter takes a source char*, so it does escape recognition
   3321    * and also invariant conversion.
   3322    *
   3323    * @return a string with backslash escapes interpreted, or an
   3324    * empty string on error.
   3325    * @see UnicodeString#unescapeAt()
   3326    * @see u_unescape()
   3327    * @see u_unescapeAt()
   3328    * @stable ICU 2.0
   3329    */
   3330   UnicodeString unescape() const;
   3331 
   3332   /**
   3333    * Unescape a single escape sequence and return the represented
   3334    * character.  See unescape() for a listing of the recognized escape
   3335    * sequences.  The character at offset-1 is assumed (without
   3336    * checking) to be a backslash.  If the escape sequence is
   3337    * ill-formed, or the offset is out of range, U_SENTINEL=-1 is
   3338    * returned.
   3339    *
   3340    * @param offset an input output parameter.  On input, it is the
   3341    * offset into this string where the escape sequence is located,
   3342    * after the initial backslash.  On output, it is advanced after the
   3343    * last character parsed.  On error, it is not advanced at all.
   3344    * @return the character represented by the escape sequence at
   3345    * offset, or U_SENTINEL=-1 on error.
   3346    * @see UnicodeString#unescape()
   3347    * @see u_unescape()
   3348    * @see u_unescapeAt()
   3349    * @stable ICU 2.0
   3350    */
   3351   UChar32 unescapeAt(int32_t &offset) const;
   3352 
   3353   /**
   3354    * ICU "poor man's RTTI", returns a UClassID for this class.
   3355    *
   3356    * @stable ICU 2.2
   3357    */
   3358   static UClassID U_EXPORT2 getStaticClassID();
   3359 
   3360   /**
   3361    * ICU "poor man's RTTI", returns a UClassID for the actual class.
   3362    *
   3363    * @stable ICU 2.2
   3364    */
   3365   virtual UClassID getDynamicClassID() const;
   3366 
   3367   //========================================
   3368   // Implementation methods
   3369   //========================================
   3370 
   3371 protected:
   3372   /**
   3373    * Implement Replaceable::getLength() (see jitterbug 1027).
   3374    * @stable ICU 2.4
   3375    */
   3376   virtual int32_t getLength() const;
   3377 
   3378   /**
   3379    * The change in Replaceable to use virtual getCharAt() allows
   3380    * UnicodeString::charAt() to be inline again (see jitterbug 709).
   3381    * @stable ICU 2.4
   3382    */
   3383   virtual UChar getCharAt(int32_t offset) const;
   3384 
   3385   /**
   3386    * The change in Replaceable to use virtual getChar32At() allows
   3387    * UnicodeString::char32At() to be inline again (see jitterbug 709).
   3388    * @stable ICU 2.4
   3389    */
   3390   virtual UChar32 getChar32At(int32_t offset) const;
   3391 
   3392 private:
   3393   // For char* constructors. Could be made public.
   3394   UnicodeString &setToUTF8(StringPiece utf8);
   3395   // For extract(char*).
   3396   // We could make a toUTF8(target, capacity, errorCode) public but not
   3397   // this version: New API will be cleaner if we make callers create substrings
   3398   // rather than having start+length on every method,
   3399   // and it should take a UErrorCode&.
   3400   int32_t
   3401   toUTF8(int32_t start, int32_t len,
   3402          char *target, int32_t capacity) const;
   3403 
   3404   /**
   3405    * Internal string contents comparison, called by operator==.
   3406    * Requires: this & text not bogus and have same lengths.
   3407    */
   3408   UBool doEquals(const UnicodeString &text, int32_t len) const;
   3409 
   3410   inline int8_t
   3411   doCompare(int32_t start,
   3412            int32_t length,
   3413            const UnicodeString& srcText,
   3414            int32_t srcStart,
   3415            int32_t srcLength) const;
   3416 
   3417   int8_t doCompare(int32_t start,
   3418            int32_t length,
   3419            const UChar *srcChars,
   3420            int32_t srcStart,
   3421            int32_t srcLength) const;
   3422 
   3423   inline int8_t
   3424   doCompareCodePointOrder(int32_t start,
   3425                           int32_t length,
   3426                           const UnicodeString& srcText,
   3427                           int32_t srcStart,
   3428                           int32_t srcLength) const;
   3429 
   3430   int8_t doCompareCodePointOrder(int32_t start,
   3431                                  int32_t length,
   3432                                  const UChar *srcChars,
   3433                                  int32_t srcStart,
   3434                                  int32_t srcLength) const;
   3435 
   3436   inline int8_t
   3437   doCaseCompare(int32_t start,
   3438                 int32_t length,
   3439                 const UnicodeString &srcText,
   3440                 int32_t srcStart,
   3441                 int32_t srcLength,
   3442                 uint32_t options) const;
   3443 
   3444   int8_t
   3445   doCaseCompare(int32_t start,
   3446                 int32_t length,
   3447                 const UChar *srcChars,
   3448                 int32_t srcStart,
   3449                 int32_t srcLength,
   3450                 uint32_t options) const;
   3451 
   3452   int32_t doIndexOf(UChar c,
   3453             int32_t start,
   3454             int32_t length) const;
   3455 
   3456   int32_t doIndexOf(UChar32 c,
   3457                         int32_t start,
   3458                         int32_t length) const;
   3459 
   3460   int32_t doLastIndexOf(UChar c,
   3461                 int32_t start,
   3462                 int32_t length) const;
   3463 
   3464   int32_t doLastIndexOf(UChar32 c,
   3465                             int32_t start,
   3466                             int32_t length) const;
   3467 
   3468   void doExtract(int32_t start,
   3469          int32_t length,
   3470          UChar *dst,
   3471          int32_t dstStart) const;
   3472 
   3473   inline void doExtract(int32_t start,
   3474          int32_t length,
   3475          UnicodeString& target) const;
   3476 
   3477   inline UChar doCharAt(int32_t offset)  const;
   3478 
   3479   UnicodeString& doReplace(int32_t start,
   3480                int32_t length,
   3481                const UnicodeString& srcText,
   3482                int32_t srcStart,
   3483                int32_t srcLength);
   3484 
   3485   UnicodeString& doReplace(int32_t start,
   3486                int32_t length,
   3487                const UChar *srcChars,
   3488                int32_t srcStart,
   3489                int32_t srcLength);
   3490 
   3491   UnicodeString& doAppend(const UnicodeString& src, int32_t srcStart, int32_t srcLength);
   3492   UnicodeString& doAppend(const UChar *srcChars, int32_t srcStart, int32_t srcLength);
   3493 
   3494   UnicodeString& doReverse(int32_t start,
   3495                int32_t length);
   3496 
   3497   // calculate hash code
   3498   int32_t doHashCode(void) const;
   3499 
   3500   // get pointer to start of array
   3501   // these do not check for kOpenGetBuffer, unlike the public getBuffer() function
   3502   inline UChar* getArrayStart(void);
   3503   inline const UChar* getArrayStart(void) const;
   3504 
   3505   inline UBool hasShortLength() const;
   3506   inline int32_t getShortLength() const;
   3507 
   3508   // A UnicodeString object (not necessarily its current buffer)
   3509   // is writable unless it isBogus() or it has an "open" getBuffer(minCapacity).
   3510   inline UBool isWritable() const;
   3511 
   3512   // Is the current buffer writable?
   3513   inline UBool isBufferWritable() const;
   3514 
   3515   // None of the following does releaseArray().
   3516   inline void setZeroLength();
   3517   inline void setShortLength(int32_t len);
   3518   inline void setLength(int32_t len);
   3519   inline void setToEmpty();
   3520   inline void setArray(UChar *array, int32_t len, int32_t capacity); // sets length but not flags
   3521 
   3522   // allocate the array; result may be the stack buffer
   3523   // sets refCount to 1 if appropriate
   3524   // sets fArray, fCapacity, and flags
   3525   // sets length to 0
   3526   // returns boolean for success or failure
   3527   UBool allocate(int32_t capacity);
   3528 
   3529   // release the array if owned
   3530   void releaseArray(void);
   3531 
   3532   // turn a bogus string into an empty one
   3533   void unBogus();
   3534 
   3535   // implements assigment operator, copy constructor, and fastCopyFrom()
   3536   UnicodeString &copyFrom(const UnicodeString &src, UBool fastCopy=FALSE);
   3537 
   3538   // Copies just the fields without memory management.
   3539   void copyFieldsFrom(UnicodeString &src, UBool setSrcToBogus) U_NOEXCEPT;
   3540 
   3541   // Pin start and limit to acceptable values.
   3542   inline void pinIndex(int32_t& start) const;
   3543   inline void pinIndices(int32_t& start,
   3544                          int32_t& length) const;
   3545 
   3546 #if !UCONFIG_NO_CONVERSION
   3547 
   3548   /* Internal extract() using UConverter. */
   3549   int32_t doExtract(int32_t start, int32_t length,
   3550                     char *dest, int32_t destCapacity,
   3551                     UConverter *cnv,
   3552                     UErrorCode &errorCode) const;
   3553 
   3554   /*
   3555    * Real constructor for converting from codepage data.
   3556    * It assumes that it is called with !fRefCounted.
   3557    *
   3558    * If <code>codepage==0</code>, then the default converter
   3559    * is used for the platform encoding.
   3560    * If <code>codepage</code> is an empty string (<code>""</code>),
   3561    * then a simple conversion is performed on the codepage-invariant
   3562    * subset ("invariant characters") of the platform encoding. See utypes.h.
   3563    */
   3564   void doCodepageCreate(const char *codepageData,
   3565                         int32_t dataLength,
   3566                         const char *codepage);
   3567 
   3568   /*
   3569    * Worker function for creating a UnicodeString from
   3570    * a codepage string using a UConverter.
   3571    */
   3572   void
   3573   doCodepageCreate(const char *codepageData,
   3574                    int32_t dataLength,
   3575                    UConverter *converter,
   3576                    UErrorCode &status);
   3577 
   3578 #endif
   3579 
   3580   /*
   3581    * This function is called when write access to the array
   3582    * is necessary.
   3583    *
   3584    * We need to make a copy of the array if
   3585    * the buffer is read-only, or
   3586    * the buffer is refCounted (shared), and refCount>1, or
   3587    * the buffer is too small.
   3588    *
   3589    * Return FALSE if memory could not be allocated.
   3590    */
   3591   UBool cloneArrayIfNeeded(int32_t newCapacity = -1,
   3592                             int32_t growCapacity = -1,
   3593                             UBool doCopyArray = TRUE,
   3594                             int32_t **pBufferToDelete = 0,
   3595                             UBool forceClone = FALSE);
   3596 
   3597   /**
   3598    * Common function for UnicodeString case mappings.
   3599    * The stringCaseMapper has the same type UStringCaseMapper
   3600    * as in ustr_imp.h for ustrcase_map().
   3601    */
   3602   UnicodeString &
   3603   caseMap(const UCaseMap *csm, UStringCaseMapper *stringCaseMapper);
   3604 
   3605   // ref counting
   3606   void addRef(void);
   3607   int32_t removeRef(void);
   3608   int32_t refCount(void) const;
   3609 
   3610   // constants
   3611   enum {
   3612     /**
   3613      * Size of stack buffer for short strings.
   3614      * Must be at least U16_MAX_LENGTH for the single-code point constructor to work.
   3615      * @see UNISTR_OBJECT_SIZE
   3616      */
   3617     US_STACKBUF_SIZE=(int32_t)(UNISTR_OBJECT_SIZE-sizeof(void *)-2)/U_SIZEOF_UCHAR,
   3618     kInvalidUChar=0xffff, // U+FFFF returned by charAt(invalid index)
   3619     kInvalidHashCode=0, // invalid hash code
   3620     kEmptyHashCode=1, // hash code for empty string
   3621 
   3622     // bit flag values for fLengthAndFlags
   3623     kIsBogus=1,         // this string is bogus, i.e., not valid or NULL
   3624     kUsingStackBuffer=2,// using fUnion.fStackFields instead of fUnion.fFields
   3625     kRefCounted=4,      // there is a refCount field before the characters in fArray
   3626     kBufferIsReadonly=8,// do not write to this buffer
   3627     kOpenGetBuffer=16,  // getBuffer(minCapacity) was called (is "open"),
   3628                         // and releaseBuffer(newLength) must be called
   3629     kAllStorageFlags=0x1f,
   3630 
   3631     kLengthShift=5,     // remaining 11 bits for non-negative short length, or negative if long
   3632     kLength1=1<<kLengthShift,
   3633     kMaxShortLength=0x3ff,  // max non-negative short length (leaves top bit 0)
   3634     kLengthIsLarge=0xffe0,  // short length < 0, real length is in fUnion.fFields.fLength
   3635 
   3636     // combined values for convenience
   3637     kShortString=kUsingStackBuffer,
   3638     kLongString=kRefCounted,
   3639     kReadonlyAlias=kBufferIsReadonly,
   3640     kWritableAlias=0
   3641   };
   3642 
   3643   friend class UnicodeStringAppendable;
   3644 
   3645   union StackBufferOrFields;        // forward declaration necessary before friend declaration
   3646   friend union StackBufferOrFields; // make US_STACKBUF_SIZE visible inside fUnion
   3647 
   3648   /*
   3649    * The following are all the class fields that are stored
   3650    * in each UnicodeString object.
   3651    * Note that UnicodeString has virtual functions,
   3652    * therefore there is an implicit vtable pointer
   3653    * as the first real field.
   3654    * The fields should be aligned such that no padding is necessary.
   3655    * On 32-bit machines, the size should be 32 bytes,
   3656    * on 64-bit machines (8-byte pointers), it should be 40 bytes.
   3657    *
   3658    * We use a hack to achieve this.
   3659    *
   3660    * With at least some compilers, each of the following is forced to
   3661    * a multiple of sizeof(pointer) [the largest field base unit here is a data pointer],
   3662    * rounded up with additional padding if the fields do not already fit that requirement:
   3663    * - sizeof(class UnicodeString)
   3664    * - offsetof(UnicodeString, fUnion)
   3665    * - sizeof(fUnion)
   3666    * - sizeof(fStackFields)
   3667    *
   3668    * We optimize for the longest possible internal buffer for short strings.
   3669    * fUnion.fStackFields begins with 2 bytes for storage flags
   3670    * and the length of relatively short strings,
   3671    * followed by the buffer for short string contents.
   3672    * There is no padding inside fStackFields.
   3673    *
   3674    * Heap-allocated and aliased strings use fUnion.fFields.
   3675    * Both fStackFields and fFields must begin with the same fields for flags and short length,
   3676    * that is, those must have the same memory offsets inside the object,
   3677    * because the flags must be inspected in order to decide which half of fUnion is being used.
   3678    * We assume that the compiler does not reorder the fields.
   3679    *
   3680    * (Padding at the end of fFields is ok:
   3681    * As long as it is no larger than fStackFields, it is not wasted space.)
   3682    *
   3683    * For some of the history of the UnicodeString class fields layout, see
   3684    * - ICU ticket #11551 "longer UnicodeString contents in stack buffer"
   3685    * - ICU ticket #11336 "UnicodeString: recombine stack buffer arrays"
   3686    * - ICU ticket #8322 "why is sizeof(UnicodeString)==48?"
   3687    */
   3688   // (implicit) *vtable;
   3689   union StackBufferOrFields {
   3690     // fStackFields is used iff (fLengthAndFlags&kUsingStackBuffer) else fFields is used.
   3691     // Each struct of the union must begin with fLengthAndFlags.
   3692     struct {
   3693       int16_t fLengthAndFlags;          // bit fields: see constants above
   3694       UChar fBuffer[US_STACKBUF_SIZE];  // buffer for short strings
   3695     } fStackFields;
   3696     struct {
   3697       int16_t fLengthAndFlags;          // bit fields: see constants above
   3698       int32_t fLength;    // number of characters in fArray if >127; else undefined
   3699       int32_t fCapacity;  // capacity of fArray (in UChars)
   3700       // array pointer last to minimize padding for machines with P128 data model
   3701       // or pointer sizes that are not a power of 2
   3702       UChar   *fArray;    // the Unicode data
   3703     } fFields;
   3704   } fUnion;
   3705 };
   3706 
   3707 /**
   3708  * Create a new UnicodeString with the concatenation of two others.
   3709  *
   3710  * @param s1 The first string to be copied to the new one.
   3711  * @param s2 The second string to be copied to the new one, after s1.
   3712  * @return UnicodeString(s1).append(s2)
   3713  * @stable ICU 2.8
   3714  */
   3715 U_COMMON_API UnicodeString U_EXPORT2
   3716 operator+ (const UnicodeString &s1, const UnicodeString &s2);
   3717 
   3718 //========================================
   3719 // Inline members
   3720 //========================================
   3721 
   3722 //========================================
   3723 // Privates
   3724 //========================================
   3725 
   3726 inline void
   3727 UnicodeString::pinIndex(int32_t& start) const
   3728 {
   3729   // pin index
   3730   if(start < 0) {
   3731     start = 0;
   3732   } else if(start > length()) {
   3733     start = length();
   3734   }
   3735 }
   3736 
   3737 inline void
   3738 UnicodeString::pinIndices(int32_t& start,
   3739                           int32_t& _length) const
   3740 {
   3741   // pin indices
   3742   int32_t len = length();
   3743   if(start < 0) {
   3744     start = 0;
   3745   } else if(start > len) {
   3746     start = len;
   3747   }
   3748   if(_length < 0) {
   3749     _length = 0;
   3750   } else if(_length > (len - start)) {
   3751     _length = (len - start);
   3752   }
   3753 }
   3754 
   3755 inline UChar*
   3756 UnicodeString::getArrayStart() {
   3757   return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
   3758     fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
   3759 }
   3760 
   3761 inline const UChar*
   3762 UnicodeString::getArrayStart() const {
   3763   return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
   3764     fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
   3765 }
   3766 
   3767 //========================================
   3768 // Default constructor
   3769 //========================================
   3770 
   3771 inline
   3772 UnicodeString::UnicodeString() {
   3773   fUnion.fStackFields.fLengthAndFlags=kShortString;
   3774 }
   3775 
   3776 //========================================
   3777 // Read-only implementation methods
   3778 //========================================
   3779 inline UBool
   3780 UnicodeString::hasShortLength() const {
   3781   return fUnion.fFields.fLengthAndFlags>=0;
   3782 }
   3783 
   3784 inline int32_t
   3785 UnicodeString::getShortLength() const {
   3786   // fLengthAndFlags must be non-negative -> short length >= 0
   3787   // and arithmetic or logical shift does not matter.
   3788   return fUnion.fFields.fLengthAndFlags>>kLengthShift;
   3789 }
   3790 
   3791 inline int32_t
   3792 UnicodeString::length() const {
   3793   return hasShortLength() ? getShortLength() : fUnion.fFields.fLength;
   3794 }
   3795 
   3796 inline int32_t
   3797 UnicodeString::getCapacity() const {
   3798   return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
   3799     US_STACKBUF_SIZE : fUnion.fFields.fCapacity;
   3800 }
   3801 
   3802 inline int32_t
   3803 UnicodeString::hashCode() const
   3804 { return doHashCode(); }
   3805 
   3806 inline UBool
   3807 UnicodeString::isBogus() const
   3808 { return (UBool)(fUnion.fFields.fLengthAndFlags & kIsBogus); }
   3809 
   3810 inline UBool
   3811 UnicodeString::isWritable() const
   3812 { return (UBool)!(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus)); }
   3813 
   3814 inline UBool
   3815 UnicodeString::isBufferWritable() const
   3816 {
   3817   return (UBool)(
   3818       !(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus|kBufferIsReadonly)) &&
   3819       (!(fUnion.fFields.fLengthAndFlags&kRefCounted) || refCount()==1));
   3820 }
   3821 
   3822 inline const UChar *
   3823 UnicodeString::getBuffer() const {
   3824   if(fUnion.fFields.fLengthAndFlags&(kIsBogus|kOpenGetBuffer)) {
   3825     return 0;
   3826   } else if(fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) {
   3827     return fUnion.fStackFields.fBuffer;
   3828   } else {
   3829     return fUnion.fFields.fArray;
   3830   }
   3831 }
   3832 
   3833 //========================================
   3834 // Read-only alias methods
   3835 //========================================
   3836 inline int8_t
   3837 UnicodeString::doCompare(int32_t start,
   3838               int32_t thisLength,
   3839               const UnicodeString& srcText,
   3840               int32_t srcStart,
   3841               int32_t srcLength) const
   3842 {
   3843   if(srcText.isBogus()) {
   3844     return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
   3845   } else {
   3846     srcText.pinIndices(srcStart, srcLength);
   3847     return doCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
   3848   }
   3849 }
   3850 
   3851 inline UBool
   3852 UnicodeString::operator== (const UnicodeString& text) const
   3853 {
   3854   if(isBogus()) {
   3855     return text.isBogus();
   3856   } else {
   3857     int32_t len = length(), textLength = text.length();
   3858     return !text.isBogus() && len == textLength && doEquals(text, len);
   3859   }
   3860 }
   3861 
   3862 inline UBool
   3863 UnicodeString::operator!= (const UnicodeString& text) const
   3864 { return (! operator==(text)); }
   3865 
   3866 inline UBool
   3867 UnicodeString::operator> (const UnicodeString& text) const
   3868 { return doCompare(0, length(), text, 0, text.length()) == 1; }
   3869 
   3870 inline UBool
   3871 UnicodeString::operator< (const UnicodeString& text) const
   3872 { return doCompare(0, length(), text, 0, text.length()) == -1; }
   3873 
   3874 inline UBool
   3875 UnicodeString::operator>= (const UnicodeString& text) const
   3876 { return doCompare(0, length(), text, 0, text.length()) != -1; }
   3877 
   3878 inline UBool
   3879 UnicodeString::operator<= (const UnicodeString& text) const
   3880 { return doCompare(0, length(), text, 0, text.length()) != 1; }
   3881 
   3882 inline int8_t
   3883 UnicodeString::compare(const UnicodeString& text) const
   3884 { return doCompare(0, length(), text, 0, text.length()); }
   3885 
   3886 inline int8_t
   3887 UnicodeString::compare(int32_t start,
   3888                int32_t _length,
   3889                const UnicodeString& srcText) const
   3890 { return doCompare(start, _length, srcText, 0, srcText.length()); }
   3891 
   3892 inline int8_t
   3893 UnicodeString::compare(const UChar *srcChars,
   3894                int32_t srcLength) const
   3895 { return doCompare(0, length(), srcChars, 0, srcLength); }
   3896 
   3897 inline int8_t
   3898 UnicodeString::compare(int32_t start,
   3899                int32_t _length,
   3900                const UnicodeString& srcText,
   3901                int32_t srcStart,
   3902                int32_t srcLength) const
   3903 { return doCompare(start, _length, srcText, srcStart, srcLength); }
   3904 
   3905 inline int8_t
   3906 UnicodeString::compare(int32_t start,
   3907                int32_t _length,
   3908                const UChar *srcChars) const
   3909 { return doCompare(start, _length, srcChars, 0, _length); }
   3910 
   3911 inline int8_t
   3912 UnicodeString::compare(int32_t start,
   3913                int32_t _length,
   3914                const UChar *srcChars,
   3915                int32_t srcStart,
   3916                int32_t srcLength) const
   3917 { return doCompare(start, _length, srcChars, srcStart, srcLength); }
   3918 
   3919 inline int8_t
   3920 UnicodeString::compareBetween(int32_t start,
   3921                   int32_t limit,
   3922                   const UnicodeString& srcText,
   3923                   int32_t srcStart,
   3924                   int32_t srcLimit) const
   3925 { return doCompare(start, limit - start,
   3926            srcText, srcStart, srcLimit - srcStart); }
   3927 
   3928 inline int8_t
   3929 UnicodeString::doCompareCodePointOrder(int32_t start,
   3930                                        int32_t thisLength,
   3931                                        const UnicodeString& srcText,
   3932                                        int32_t srcStart,
   3933                                        int32_t srcLength) const
   3934 {
   3935   if(srcText.isBogus()) {
   3936     return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
   3937   } else {
   3938     srcText.pinIndices(srcStart, srcLength);
   3939     return doCompareCodePointOrder(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
   3940   }
   3941 }
   3942 
   3943 inline int8_t
   3944 UnicodeString::compareCodePointOrder(const UnicodeString& text) const
   3945 { return doCompareCodePointOrder(0, length(), text, 0, text.length()); }
   3946 
   3947 inline int8_t
   3948 UnicodeString::compareCodePointOrder(int32_t start,
   3949                                      int32_t _length,
   3950                                      const UnicodeString& srcText) const
   3951 { return doCompareCodePointOrder(start, _length, srcText, 0, srcText.length()); }
   3952 
   3953 inline int8_t
   3954 UnicodeString::compareCodePointOrder(const UChar *srcChars,
   3955                                      int32_t srcLength) const
   3956 { return doCompareCodePointOrder(0, length(), srcChars, 0, srcLength); }
   3957 
   3958 inline int8_t
   3959 UnicodeString::compareCodePointOrder(int32_t start,
   3960                                      int32_t _length,
   3961                                      const UnicodeString& srcText,
   3962                                      int32_t srcStart,
   3963                                      int32_t srcLength) const
   3964 { return doCompareCodePointOrder(start, _length, srcText, srcStart, srcLength); }
   3965 
   3966 inline int8_t
   3967 UnicodeString::compareCodePointOrder(int32_t start,
   3968                                      int32_t _length,
   3969                                      const UChar *srcChars) const
   3970 { return doCompareCodePointOrder(start, _length, srcChars, 0, _length); }
   3971 
   3972 inline int8_t
   3973 UnicodeString::compareCodePointOrder(int32_t start,
   3974                                      int32_t _length,
   3975                                      const UChar *srcChars,
   3976                                      int32_t srcStart,
   3977                                      int32_t srcLength) const
   3978 { return doCompareCodePointOrder(start, _length, srcChars, srcStart, srcLength); }
   3979 
   3980 inline int8_t
   3981 UnicodeString::compareCodePointOrderBetween(int32_t start,
   3982                                             int32_t limit,
   3983                                             const UnicodeString& srcText,
   3984                                             int32_t srcStart,
   3985                                             int32_t srcLimit) const
   3986 { return doCompareCodePointOrder(start, limit - start,
   3987            srcText, srcStart, srcLimit - srcStart); }
   3988 
   3989 inline int8_t
   3990 UnicodeString::doCaseCompare(int32_t start,
   3991                              int32_t thisLength,
   3992                              const UnicodeString &srcText,
   3993                              int32_t srcStart,
   3994                              int32_t srcLength,
   3995                              uint32_t options) const
   3996 {
   3997   if(srcText.isBogus()) {
   3998     return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
   3999   } else {
   4000     srcText.pinIndices(srcStart, srcLength);
   4001     return doCaseCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength, options);
   4002   }
   4003 }
   4004 
   4005 inline int8_t
   4006 UnicodeString::caseCompare(const UnicodeString &text, uint32_t options) const {
   4007   return doCaseCompare(0, length(), text, 0, text.length(), options);
   4008 }
   4009 
   4010 inline int8_t
   4011 UnicodeString::caseCompare(int32_t start,
   4012                            int32_t _length,
   4013                            const UnicodeString &srcText,
   4014                            uint32_t options) const {
   4015   return doCaseCompare(start, _length, srcText, 0, srcText.length(), options);
   4016 }
   4017 
   4018 inline int8_t
   4019 UnicodeString::caseCompare(const UChar *srcChars,
   4020                            int32_t srcLength,
   4021                            uint32_t options) const {
   4022   return doCaseCompare(0, length(), srcChars, 0, srcLength, options);
   4023 }
   4024 
   4025 inline int8_t
   4026 UnicodeString::caseCompare(int32_t start,
   4027                            int32_t _length,
   4028                            const UnicodeString &srcText,
   4029                            int32_t srcStart,
   4030                            int32_t srcLength,
   4031                            uint32_t options) const {
   4032   return doCaseCompare(start, _length, srcText, srcStart, srcLength, options);
   4033 }
   4034 
   4035 inline int8_t
   4036 UnicodeString::caseCompare(int32_t start,
   4037                            int32_t _length,
   4038                            const UChar *srcChars,
   4039                            uint32_t options) const {
   4040   return doCaseCompare(start, _length, srcChars, 0, _length, options);
   4041 }
   4042 
   4043 inline int8_t
   4044 UnicodeString::caseCompare(int32_t start,
   4045                            int32_t _length,
   4046                            const UChar *srcChars,
   4047                            int32_t srcStart,
   4048                            int32_t srcLength,
   4049                            uint32_t options) const {
   4050   return doCaseCompare(start, _length, srcChars, srcStart, srcLength, options);
   4051 }
   4052 
   4053 inline int8_t
   4054 UnicodeString::caseCompareBetween(int32_t start,
   4055                                   int32_t limit,
   4056                                   const UnicodeString &srcText,
   4057                                   int32_t srcStart,
   4058                                   int32_t srcLimit,
   4059                                   uint32_t options) const {
   4060   return doCaseCompare(start, limit - start, srcText, srcStart, srcLimit - srcStart, options);
   4061 }
   4062 
   4063 inline int32_t
   4064 UnicodeString::indexOf(const UnicodeString& srcText,
   4065                int32_t srcStart,
   4066                int32_t srcLength,
   4067                int32_t start,
   4068                int32_t _length) const
   4069 {
   4070   if(!srcText.isBogus()) {
   4071     srcText.pinIndices(srcStart, srcLength);
   4072     if(srcLength > 0) {
   4073       return indexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
   4074     }
   4075   }
   4076   return -1;
   4077 }
   4078 
   4079 inline int32_t
   4080 UnicodeString::indexOf(const UnicodeString& text) const
   4081 { return indexOf(text, 0, text.length(), 0, length()); }
   4082 
   4083 inline int32_t
   4084 UnicodeString::indexOf(const UnicodeString& text,
   4085                int32_t start) const {
   4086   pinIndex(start);
   4087   return indexOf(text, 0, text.length(), start, length() - start);
   4088 }
   4089 
   4090 inline int32_t
   4091 UnicodeString::indexOf(const UnicodeString& text,
   4092                int32_t start,
   4093                int32_t _length) const
   4094 { return indexOf(text, 0, text.length(), start, _length); }
   4095 
   4096 inline int32_t
   4097 UnicodeString::indexOf(const UChar *srcChars,
   4098                int32_t srcLength,
   4099                int32_t start) const {
   4100   pinIndex(start);
   4101   return indexOf(srcChars, 0, srcLength, start, length() - start);
   4102 }
   4103 
   4104 inline int32_t
   4105 UnicodeString::indexOf(const UChar *srcChars,
   4106                int32_t srcLength,
   4107                int32_t start,
   4108                int32_t _length) const
   4109 { return indexOf(srcChars, 0, srcLength, start, _length); }
   4110 
   4111 inline int32_t
   4112 UnicodeString::indexOf(UChar c,
   4113                int32_t start,
   4114                int32_t _length) const
   4115 { return doIndexOf(c, start, _length); }
   4116 
   4117 inline int32_t
   4118 UnicodeString::indexOf(UChar32 c,
   4119                int32_t start,
   4120                int32_t _length) const
   4121 { return doIndexOf(c, start, _length); }
   4122 
   4123 inline int32_t
   4124 UnicodeString::indexOf(UChar c) const
   4125 { return doIndexOf(c, 0, length()); }
   4126 
   4127 inline int32_t
   4128 UnicodeString::indexOf(UChar32 c) const
   4129 { return indexOf(c, 0, length()); }
   4130 
   4131 inline int32_t
   4132 UnicodeString::indexOf(UChar c,
   4133                int32_t start) const {
   4134   pinIndex(start);
   4135   return doIndexOf(c, start, length() - start);
   4136 }
   4137 
   4138 inline int32_t
   4139 UnicodeString::indexOf(UChar32 c,
   4140                int32_t start) const {
   4141   pinIndex(start);
   4142   return indexOf(c, start, length() - start);
   4143 }
   4144 
   4145 inline int32_t
   4146 UnicodeString::lastIndexOf(const UChar *srcChars,
   4147                int32_t srcLength,
   4148                int32_t start,
   4149                int32_t _length) const
   4150 { return lastIndexOf(srcChars, 0, srcLength, start, _length); }
   4151 
   4152 inline int32_t
   4153 UnicodeString::lastIndexOf(const UChar *srcChars,
   4154                int32_t srcLength,
   4155                int32_t start) const {
   4156   pinIndex(start);
   4157   return lastIndexOf(srcChars, 0, srcLength, start, length() - start);
   4158 }
   4159 
   4160 inline int32_t
   4161 UnicodeString::lastIndexOf(const UnicodeString& srcText,
   4162                int32_t srcStart,
   4163                int32_t srcLength,
   4164                int32_t start,
   4165                int32_t _length) const
   4166 {
   4167   if(!srcText.isBogus()) {
   4168     srcText.pinIndices(srcStart, srcLength);
   4169     if(srcLength > 0) {
   4170       return lastIndexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
   4171     }
   4172   }
   4173   return -1;
   4174 }
   4175 
   4176 inline int32_t
   4177 UnicodeString::lastIndexOf(const UnicodeString& text,
   4178                int32_t start,
   4179                int32_t _length) const
   4180 { return lastIndexOf(text, 0, text.length(), start, _length); }
   4181 
   4182 inline int32_t
   4183 UnicodeString::lastIndexOf(const UnicodeString& text,
   4184                int32_t start) const {
   4185   pinIndex(start);
   4186   return lastIndexOf(text, 0, text.length(), start, length() - start);
   4187 }
   4188 
   4189 inline int32_t
   4190 UnicodeString::lastIndexOf(const UnicodeString& text) const
   4191 { return lastIndexOf(text, 0, text.length(), 0, length()); }
   4192 
   4193 inline int32_t
   4194 UnicodeString::lastIndexOf(UChar c,
   4195                int32_t start,
   4196                int32_t _length) const
   4197 { return doLastIndexOf(c, start, _length); }
   4198 
   4199 inline int32_t
   4200 UnicodeString::lastIndexOf(UChar32 c,
   4201                int32_t start,
   4202                int32_t _length) const {
   4203   return doLastIndexOf(c, start, _length);
   4204 }
   4205 
   4206 inline int32_t
   4207 UnicodeString::lastIndexOf(UChar c) const
   4208 { return doLastIndexOf(c, 0, length()); }
   4209 
   4210 inline int32_t
   4211 UnicodeString::lastIndexOf(UChar32 c) const {
   4212   return lastIndexOf(c, 0, length());
   4213 }
   4214 
   4215 inline int32_t
   4216 UnicodeString::lastIndexOf(UChar c,
   4217                int32_t start) const {
   4218   pinIndex(start);
   4219   return doLastIndexOf(c, start, length() - start);
   4220 }
   4221 
   4222 inline int32_t
   4223 UnicodeString::lastIndexOf(UChar32 c,
   4224                int32_t start) const {
   4225   pinIndex(start);
   4226   return lastIndexOf(c, start, length() - start);
   4227 }
   4228 
   4229 inline UBool
   4230 UnicodeString::startsWith(const UnicodeString& text) const
   4231 { return compare(0, text.length(), text, 0, text.length()) == 0; }
   4232 
   4233 inline UBool
   4234 UnicodeString::startsWith(const UnicodeString& srcText,
   4235               int32_t srcStart,
   4236               int32_t srcLength) const
   4237 { return doCompare(0, srcLength, srcText, srcStart, srcLength) == 0; }
   4238 
   4239 inline UBool
   4240 UnicodeString::startsWith(const UChar *srcChars, int32_t srcLength) const {
   4241   if(srcLength < 0) {
   4242     srcLength = u_strlen(srcChars);
   4243   }
   4244   return doCompare(0, srcLength, srcChars, 0, srcLength) == 0;
   4245 }
   4246 
   4247 inline UBool
   4248 UnicodeString::startsWith(const UChar *srcChars, int32_t srcStart, int32_t srcLength) const {
   4249   if(srcLength < 0) {
   4250     srcLength = u_strlen(srcChars);
   4251   }
   4252   return doCompare(0, srcLength, srcChars, srcStart, srcLength) == 0;
   4253 }
   4254 
   4255 inline UBool
   4256 UnicodeString::endsWith(const UnicodeString& text) const
   4257 { return doCompare(length() - text.length(), text.length(),
   4258            text, 0, text.length()) == 0; }
   4259 
   4260 inline UBool
   4261 UnicodeString::endsWith(const UnicodeString& srcText,
   4262             int32_t srcStart,
   4263             int32_t srcLength) const {
   4264   srcText.pinIndices(srcStart, srcLength);
   4265   return doCompare(length() - srcLength, srcLength,
   4266                    srcText, srcStart, srcLength) == 0;
   4267 }
   4268 
   4269 inline UBool
   4270 UnicodeString::endsWith(const UChar *srcChars,
   4271             int32_t srcLength) const {
   4272   if(srcLength < 0) {
   4273     srcLength = u_strlen(srcChars);
   4274   }
   4275   return doCompare(length() - srcLength, srcLength,
   4276                    srcChars, 0, srcLength) == 0;
   4277 }
   4278 
   4279 inline UBool
   4280 UnicodeString::endsWith(const UChar *srcChars,
   4281             int32_t srcStart,
   4282             int32_t srcLength) const {
   4283   if(srcLength < 0) {
   4284     srcLength = u_strlen(srcChars + srcStart);
   4285   }
   4286   return doCompare(length() - srcLength, srcLength,
   4287                    srcChars, srcStart, srcLength) == 0;
   4288 }
   4289 
   4290 //========================================
   4291 // replace
   4292 //========================================
   4293 inline UnicodeString&
   4294 UnicodeString::replace(int32_t start,
   4295                int32_t _length,
   4296                const UnicodeString& srcText)
   4297 { return doReplace(start, _length, srcText, 0, srcText.length()); }
   4298 
   4299 inline UnicodeString&
   4300 UnicodeString::replace(int32_t start,
   4301                int32_t _length,
   4302                const UnicodeString& srcText,
   4303                int32_t srcStart,
   4304                int32_t srcLength)
   4305 { return doReplace(start, _length, srcText, srcStart, srcLength); }
   4306 
   4307 inline UnicodeString&
   4308 UnicodeString::replace(int32_t start,
   4309                int32_t _length,
   4310                const UChar *srcChars,
   4311                int32_t srcLength)
   4312 { return doReplace(start, _length, srcChars, 0, srcLength); }
   4313 
   4314 inline UnicodeString&
   4315 UnicodeString::replace(int32_t start,
   4316                int32_t _length,
   4317                const UChar *srcChars,
   4318                int32_t srcStart,
   4319                int32_t srcLength)
   4320 { return doReplace(start, _length, srcChars, srcStart, srcLength); }
   4321 
   4322 inline UnicodeString&
   4323 UnicodeString::replace(int32_t start,
   4324                int32_t _length,
   4325                UChar srcChar)
   4326 { return doReplace(start, _length, &srcChar, 0, 1); }
   4327 
   4328 inline UnicodeString&
   4329 UnicodeString::replaceBetween(int32_t start,
   4330                   int32_t limit,
   4331                   const UnicodeString& srcText)
   4332 { return doReplace(start, limit - start, srcText, 0, srcText.length()); }
   4333 
   4334 inline UnicodeString&
   4335 UnicodeString::replaceBetween(int32_t start,
   4336                   int32_t limit,
   4337                   const UnicodeString& srcText,
   4338                   int32_t srcStart,
   4339                   int32_t srcLimit)
   4340 { return doReplace(start, limit - start, srcText, srcStart, srcLimit - srcStart); }
   4341 
   4342 inline UnicodeString&
   4343 UnicodeString::findAndReplace(const UnicodeString& oldText,
   4344                   const UnicodeString& newText)
   4345 { return findAndReplace(0, length(), oldText, 0, oldText.length(),
   4346             newText, 0, newText.length()); }
   4347 
   4348 inline UnicodeString&
   4349 UnicodeString::findAndReplace(int32_t start,
   4350                   int32_t _length,
   4351                   const UnicodeString& oldText,
   4352                   const UnicodeString& newText)
   4353 { return findAndReplace(start, _length, oldText, 0, oldText.length(),
   4354             newText, 0, newText.length()); }
   4355 
   4356 // ============================
   4357 // extract
   4358 // ============================
   4359 inline void
   4360 UnicodeString::doExtract(int32_t start,
   4361              int32_t _length,
   4362              UnicodeString& target) const
   4363 { target.replace(0, target.length(), *this, start, _length); }
   4364 
   4365 inline void
   4366 UnicodeString::extract(int32_t start,
   4367                int32_t _length,
   4368                UChar *target,
   4369                int32_t targetStart) const
   4370 { doExtract(start, _length, target, targetStart); }
   4371 
   4372 inline void
   4373 UnicodeString::extract(int32_t start,
   4374                int32_t _length,
   4375                UnicodeString& target) const
   4376 { doExtract(start, _length, target); }
   4377 
   4378 #if !UCONFIG_NO_CONVERSION
   4379 
   4380 inline int32_t
   4381 UnicodeString::extract(int32_t start,
   4382                int32_t _length,
   4383                char *dst,
   4384                const char *codepage) const
   4385 
   4386 {
   4387   // This dstSize value will be checked explicitly
   4388   return extract(start, _length, dst, dst!=0 ? 0xffffffff : 0, codepage);
   4389 }
   4390 
   4391 #endif
   4392 
   4393 inline void
   4394 UnicodeString::extractBetween(int32_t start,
   4395                   int32_t limit,
   4396                   UChar *dst,
   4397                   int32_t dstStart) const {
   4398   pinIndex(start);
   4399   pinIndex(limit);
   4400   doExtract(start, limit - start, dst, dstStart);
   4401 }
   4402 
   4403 inline UnicodeString
   4404 UnicodeString::tempSubStringBetween(int32_t start, int32_t limit) const {
   4405     return tempSubString(start, limit - start);
   4406 }
   4407 
   4408 inline UChar
   4409 UnicodeString::doCharAt(int32_t offset) const
   4410 {
   4411   if((uint32_t)offset < (uint32_t)length()) {
   4412     return getArrayStart()[offset];
   4413   } else {
   4414     return kInvalidUChar;
   4415   }
   4416 }
   4417 
   4418 inline UChar
   4419 UnicodeString::charAt(int32_t offset) const
   4420 { return doCharAt(offset); }
   4421 
   4422 inline UChar
   4423 UnicodeString::operator[] (int32_t offset) const
   4424 { return doCharAt(offset); }
   4425 
   4426 inline UBool
   4427 UnicodeString::isEmpty() const {
   4428   // Arithmetic or logical right shift does not matter: only testing for 0.
   4429   return (fUnion.fFields.fLengthAndFlags>>kLengthShift) == 0;
   4430 }
   4431 
   4432 //========================================
   4433 // Write implementation methods
   4434 //========================================
   4435 inline void
   4436 UnicodeString::setZeroLength() {
   4437   fUnion.fFields.fLengthAndFlags &= kAllStorageFlags;
   4438 }
   4439 
   4440 inline void
   4441 UnicodeString::setShortLength(int32_t len) {
   4442   // requires 0 <= len <= kMaxShortLength
   4443   fUnion.fFields.fLengthAndFlags =
   4444     (int16_t)((fUnion.fFields.fLengthAndFlags & kAllStorageFlags) | (len << kLengthShift));
   4445 }
   4446 
   4447 inline void
   4448 UnicodeString::setLength(int32_t len) {
   4449   if(len <= kMaxShortLength) {
   4450     setShortLength(len);
   4451   } else {
   4452     fUnion.fFields.fLengthAndFlags |= kLengthIsLarge;
   4453     fUnion.fFields.fLength = len;
   4454   }
   4455 }
   4456 
   4457 inline void
   4458 UnicodeString::setToEmpty() {
   4459   fUnion.fFields.fLengthAndFlags = kShortString;
   4460 }
   4461 
   4462 inline void
   4463 UnicodeString::setArray(UChar *array, int32_t len, int32_t capacity) {
   4464   setLength(len);
   4465   fUnion.fFields.fArray = array;
   4466   fUnion.fFields.fCapacity = capacity;
   4467 }
   4468 
   4469 inline UnicodeString&
   4470 UnicodeString::operator= (UChar ch)
   4471 { return doReplace(0, length(), &ch, 0, 1); }
   4472 
   4473 inline UnicodeString&
   4474 UnicodeString::operator= (UChar32 ch)
   4475 { return replace(0, length(), ch); }
   4476 
   4477 inline UnicodeString&
   4478 UnicodeString::setTo(const UnicodeString& srcText,
   4479              int32_t srcStart,
   4480              int32_t srcLength)
   4481 {
   4482   unBogus();
   4483   return doReplace(0, length(), srcText, srcStart, srcLength);
   4484 }
   4485 
   4486 inline UnicodeString&
   4487 UnicodeString::setTo(const UnicodeString& srcText,
   4488              int32_t srcStart)
   4489 {
   4490   unBogus();
   4491   srcText.pinIndex(srcStart);
   4492   return doReplace(0, length(), srcText, srcStart, srcText.length() - srcStart);
   4493 }
   4494 
   4495 inline UnicodeString&
   4496 UnicodeString::setTo(const UnicodeString& srcText)
   4497 {
   4498   return copyFrom(srcText);
   4499 }
   4500 
   4501 inline UnicodeString&
   4502 UnicodeString::setTo(const UChar *srcChars,
   4503              int32_t srcLength)
   4504 {
   4505   unBogus();
   4506   return doReplace(0, length(), srcChars, 0, srcLength);
   4507 }
   4508 
   4509 inline UnicodeString&
   4510 UnicodeString::setTo(UChar srcChar)
   4511 {
   4512   unBogus();
   4513   return doReplace(0, length(), &srcChar, 0, 1);
   4514 }
   4515 
   4516 inline UnicodeString&
   4517 UnicodeString::setTo(UChar32 srcChar)
   4518 {
   4519   unBogus();
   4520   return replace(0, length(), srcChar);
   4521 }
   4522 
   4523 inline UnicodeString&
   4524 UnicodeString::append(const UnicodeString& srcText,
   4525               int32_t srcStart,
   4526               int32_t srcLength)
   4527 { return doAppend(srcText, srcStart, srcLength); }
   4528 
   4529 inline UnicodeString&
   4530 UnicodeString::append(const UnicodeString& srcText)
   4531 { return doAppend(srcText, 0, srcText.length()); }
   4532 
   4533 inline UnicodeString&
   4534 UnicodeString::append(const UChar *srcChars,
   4535               int32_t srcStart,
   4536               int32_t srcLength)
   4537 { return doAppend(srcChars, srcStart, srcLength); }
   4538 
   4539 inline UnicodeString&
   4540 UnicodeString::append(const UChar *srcChars,
   4541               int32_t srcLength)
   4542 { return doAppend(srcChars, 0, srcLength); }
   4543 
   4544 inline UnicodeString&
   4545 UnicodeString::append(UChar srcChar)
   4546 { return doAppend(&srcChar, 0, 1); }
   4547 
   4548 inline UnicodeString&
   4549 UnicodeString::operator+= (UChar ch)
   4550 { return doAppend(&ch, 0, 1); }
   4551 
   4552 inline UnicodeString&
   4553 UnicodeString::operator+= (UChar32 ch) {
   4554   return append(ch);
   4555 }
   4556 
   4557 inline UnicodeString&
   4558 UnicodeString::operator+= (const UnicodeString& srcText)
   4559 { return doAppend(srcText, 0, srcText.length()); }
   4560 
   4561 inline UnicodeString&
   4562 UnicodeString::insert(int32_t start,
   4563               const UnicodeString& srcText,
   4564               int32_t srcStart,
   4565               int32_t srcLength)
   4566 { return doReplace(start, 0, srcText, srcStart, srcLength); }
   4567 
   4568 inline UnicodeString&
   4569 UnicodeString::insert(int32_t start,
   4570               const UnicodeString& srcText)
   4571 { return doReplace(start, 0, srcText, 0, srcText.length()); }
   4572 
   4573 inline UnicodeString&
   4574 UnicodeString::insert(int32_t start,
   4575               const UChar *srcChars,
   4576               int32_t srcStart,
   4577               int32_t srcLength)
   4578 { return doReplace(start, 0, srcChars, srcStart, srcLength); }
   4579 
   4580 inline UnicodeString&
   4581 UnicodeString::insert(int32_t start,
   4582               const UChar *srcChars,
   4583               int32_t srcLength)
   4584 { return doReplace(start, 0, srcChars, 0, srcLength); }
   4585 
   4586 inline UnicodeString&
   4587 UnicodeString::insert(int32_t start,
   4588               UChar srcChar)
   4589 { return doReplace(start, 0, &srcChar, 0, 1); }
   4590 
   4591 inline UnicodeString&
   4592 UnicodeString::insert(int32_t start,
   4593               UChar32 srcChar)
   4594 { return replace(start, 0, srcChar); }
   4595 
   4596 
   4597 inline UnicodeString&
   4598 UnicodeString::remove()
   4599 {
   4600   // remove() of a bogus string makes the string empty and non-bogus
   4601   if(isBogus()) {
   4602     setToEmpty();
   4603   } else {
   4604     setZeroLength();
   4605   }
   4606   return *this;
   4607 }
   4608 
   4609 inline UnicodeString&
   4610 UnicodeString::remove(int32_t start,
   4611              int32_t _length)
   4612 {
   4613     if(start <= 0 && _length == INT32_MAX) {
   4614         // remove(guaranteed everything) of a bogus string makes the string empty and non-bogus
   4615         return remove();
   4616     }
   4617     return doReplace(start, _length, NULL, 0, 0);
   4618 }
   4619 
   4620 inline UnicodeString&
   4621 UnicodeString::removeBetween(int32_t start,
   4622                 int32_t limit)
   4623 { return doReplace(start, limit - start, NULL, 0, 0); }
   4624 
   4625 inline UnicodeString &
   4626 UnicodeString::retainBetween(int32_t start, int32_t limit) {
   4627   truncate(limit);
   4628   return doReplace(0, start, NULL, 0, 0);
   4629 }
   4630 
   4631 inline UBool
   4632 UnicodeString::truncate(int32_t targetLength)
   4633 {
   4634   if(isBogus() && targetLength == 0) {
   4635     // truncate(0) of a bogus string makes the string empty and non-bogus
   4636     unBogus();
   4637     return FALSE;
   4638   } else if((uint32_t)targetLength < (uint32_t)length()) {
   4639     setLength(targetLength);
   4640     return TRUE;
   4641   } else {
   4642     return FALSE;
   4643   }
   4644 }
   4645 
   4646 inline UnicodeString&
   4647 UnicodeString::reverse()
   4648 { return doReverse(0, length()); }
   4649 
   4650 inline UnicodeString&
   4651 UnicodeString::reverse(int32_t start,
   4652                int32_t _length)
   4653 { return doReverse(start, _length); }
   4654 
   4655 U_NAMESPACE_END
   4656 
   4657 #endif
   4658