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