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