1 // Copyright (C) 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 **********************************************************************
5 * Copyright (C) 1998-2016, International Business Machines
6 * Corporation and others. All Rights Reserved.
7 **********************************************************************
11 * Modification History:
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 ******************************************************************************
28 * \brief C++ API: Unicode String
31 #include "unicode/utypes.h"
32 #include "unicode/rep.h"
33 #include "unicode/std_string.h"
34 #include "unicode/stringpiece.h"
35 #include "unicode/bytestream.h"
36 #include "unicode/ucasemap.h"
38 struct UConverter; // unicode/ucnv.h
40 #ifndef U_COMPARE_CODE_POINT_ORDER
41 /* see also ustring.h and unorm.h */
43 * Option bit for u_strCaseCompare, u_strcasecmp, unorm_compare, etc:
44 * Compare strings in code point order instead of code unit order.
47 #define U_COMPARE_CODE_POINT_ORDER 0x8000
52 * \ingroup ustring_ustrlen
54 U_STABLE int32_t U_EXPORT2
55 u_strlen(const UChar *s);
59 * \def U_STRING_CASE_MAPPER_DEFINED
62 #ifndef U_STRING_CASE_MAPPER_DEFINED
63 #define U_STRING_CASE_MAPPER_DEFINED
66 * Internal string case mapping function type.
69 typedef int32_t U_CALLCONV
70 UStringCaseMapper(const UCaseMap *csm,
71 UChar *dest, int32_t destCapacity,
72 const UChar *src, int32_t srcLength,
73 UErrorCode *pErrorCode);
79 #if !UCONFIG_NO_BREAK_ITERATION
80 class BreakIterator; // unicode/brkiter.h
82 class Locale; // unicode/locid.h
83 class StringCharacterIterator;
84 class UnicodeStringAppendable; // unicode/appendable.h
86 /* The <iostream> include has been moved to unicode/ustream.h */
89 * Constant to be used in the UnicodeString(char *, int32_t, EInvariant) constructor
90 * which constructs a Unicode string from an invariant-character char * string.
91 * About invariant characters see utypes.h.
92 * This constructor has no runtime dependency on conversion code and is
93 * therefore recommended over ones taking a charset name string
94 * (where the empty string "" indicates invariant-character conversion).
98 #define US_INV icu::UnicodeString::kInvariant
101 * Unicode String literals in C++.
102 * Dependent on the platform properties, different UnicodeString
103 * constructors should be used to create a UnicodeString object from
105 * The macros are defined for maximum performance.
106 * They work only for strings that contain "invariant characters", i.e.,
107 * only latin letters, digits, and some punctuation.
108 * See utypes.h for details.
110 * The string parameter must be a C string literal.
111 * The length of the string, not including the terminating
112 * <code>NUL</code>, must be specified as a constant.
113 * The U_STRING_DECL macro should be invoked exactly once for one
114 * such string variable before it is used.
117 #if defined(U_DECLARE_UTF16)
118 # define UNICODE_STRING(cs, _length) icu::UnicodeString(TRUE, (const UChar *)U_DECLARE_UTF16(cs), _length)
119 #elif U_SIZEOF_WCHAR_T==U_SIZEOF_UCHAR && (U_CHARSET_FAMILY==U_ASCII_FAMILY || (U_SIZEOF_UCHAR == 2 && defined(U_WCHAR_IS_UTF16)))
120 # define UNICODE_STRING(cs, _length) icu::UnicodeString(TRUE, (const UChar *)L ## cs, _length)
121 #elif U_SIZEOF_UCHAR==1 && U_CHARSET_FAMILY==U_ASCII_FAMILY
122 # define UNICODE_STRING(cs, _length) icu::UnicodeString(TRUE, (const UChar *)cs, _length)
124 # define UNICODE_STRING(cs, _length) icu::UnicodeString(cs, _length, US_INV)
128 * Unicode String literals in C++.
129 * Dependent on the platform properties, different UnicodeString
130 * constructors should be used to create a UnicodeString object from
132 * The macros are defined for improved performance.
133 * They work only for strings that contain "invariant characters", i.e.,
134 * only latin letters, digits, and some punctuation.
135 * See utypes.h for details.
137 * The string parameter must be a C string literal.
140 #define UNICODE_STRING_SIMPLE(cs) UNICODE_STRING(cs, -1)
143 * \def UNISTR_FROM_CHAR_EXPLICIT
144 * This can be defined to be empty or "explicit".
145 * If explicit, then the UnicodeString(UChar) and UnicodeString(UChar32)
146 * constructors are marked as explicit, preventing their inadvertent use.
149 #ifndef UNISTR_FROM_CHAR_EXPLICIT
150 # if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION)
151 // Auto-"explicit" in ICU library code.
152 # define UNISTR_FROM_CHAR_EXPLICIT explicit
154 // Empty by default for source code compatibility.
155 # define UNISTR_FROM_CHAR_EXPLICIT
160 * \def UNISTR_FROM_STRING_EXPLICIT
161 * This can be defined to be empty or "explicit".
162 * If explicit, then the UnicodeString(const char *) and UnicodeString(const UChar *)
163 * constructors are marked as explicit, preventing their inadvertent use.
165 * In particular, this helps prevent accidentally depending on ICU conversion code
166 * by passing a string literal into an API with a const UnicodeString & parameter.
169 #ifndef UNISTR_FROM_STRING_EXPLICIT
170 # if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION)
171 // Auto-"explicit" in ICU library code.
172 # define UNISTR_FROM_STRING_EXPLICIT explicit
174 // Empty by default for source code compatibility.
175 # define UNISTR_FROM_STRING_EXPLICIT
180 * \def UNISTR_OBJECT_SIZE
181 * Desired sizeof(UnicodeString) in bytes.
182 * It should be a multiple of sizeof(pointer) to avoid unusable space for padding.
183 * The object size may want to be a multiple of 16 bytes,
184 * which is a common granularity for heap allocation.
186 * Any space inside the object beyond sizeof(vtable pointer) + 2
187 * is available for storing short strings inside the object.
188 * The bigger the object, the longer a string that can be stored inside the object,
189 * without additional heap allocation.
191 * Depending on a platform's pointer size, pointer alignment requirements,
192 * and struct padding, the compiler will usually round up sizeof(UnicodeString)
193 * to 4 * sizeof(pointer) (or 3 * sizeof(pointer) for P128 data models),
194 * to hold the fields for heap-allocated strings.
195 * Such a minimum size also ensures that the object is easily large enough
196 * to hold at least 2 UChars, for one supplementary code point (U16_MAX_LENGTH).
198 * sizeof(UnicodeString) >= 48 should work for all known platforms.
200 * For example, on a 64-bit machine where sizeof(vtable pointer) is 8,
201 * sizeof(UnicodeString) = 64 would leave space for
202 * (64 - sizeof(vtable pointer) - 2) / U_SIZEOF_UCHAR = (64 - 8 - 2) / 2 = 27
203 * UChars stored inside the object.
205 * The minimum object size on a 64-bit machine would be
206 * 4 * sizeof(pointer) = 4 * 8 = 32 bytes,
207 * and the internal buffer would hold up to 11 UChars in that case.
209 * @see U16_MAX_LENGTH
212 #ifndef UNISTR_OBJECT_SIZE
213 # define UNISTR_OBJECT_SIZE 64
217 * UnicodeString is a string class that stores Unicode characters directly and provides
218 * similar functionality as the Java String and StringBuffer/StringBuilder classes.
219 * It is a concrete implementation of the abstract class Replaceable (for transliteration).
221 * A UnicodeString may also "alias" an external array of characters
222 * (that is, point to it, rather than own the array)
223 * whose lifetime must then at least match the lifetime of the aliasing object.
224 * This aliasing may be preserved when returning a UnicodeString by value,
225 * depending on the compiler and the function implementation,
226 * via Return Value Optimization (RVO) or the move assignment operator.
227 * (However, the copy assignment operator does not preserve aliasing.)
228 * For details see the description of storage models at the end of the class API docs
229 * and in the User Guide chapter linked from there.
231 * The UnicodeString class is not suitable for subclassing.
233 * <p>For an overview of Unicode strings in C and C++ see the
234 * <a href="http://userguide.icu-project.org/strings#TOC-Strings-in-C-C-">User Guide Strings chapter</a>.</p>
236 * <p>In ICU, a Unicode string consists of 16-bit Unicode <em>code units</em>.
237 * A Unicode character may be stored with either one code unit
238 * (the most common case) or with a matched pair of special code units
239 * ("surrogates"). The data type for code units is UChar.
240 * For single-character handling, a Unicode character code <em>point</em> is a value
241 * in the range 0..0x10ffff. ICU uses the UChar32 type for code points.</p>
243 * <p>Indexes and offsets into and lengths of strings always count code units, not code points.
244 * This is the same as with multi-byte char* strings in traditional string handling.
245 * Operations on partial strings typically do not test for code point boundaries.
246 * If necessary, the user needs to take care of such boundaries by testing for the code unit
247 * values or by using functions like
248 * UnicodeString::getChar32Start() and UnicodeString::getChar32Limit()
249 * (or, in C, the equivalent macros U16_SET_CP_START() and U16_SET_CP_LIMIT(), see utf.h).</p>
251 * UnicodeString methods are more lenient with regard to input parameter values
252 * than other ICU APIs. In particular:
253 * - If indexes are out of bounds for a UnicodeString object
254 * (<0 or >length()) then they are "pinned" to the nearest boundary.
255 * - If primitive string pointer values (e.g., const UChar * or char *)
256 * for input strings are NULL, then those input string parameters are treated
257 * as if they pointed to an empty string.
258 * However, this is <em>not</em> the case for char * parameters for charset names
260 * - Most UnicodeString methods do not take a UErrorCode parameter because
261 * there are usually very few opportunities for failure other than a shortage
262 * of memory, error codes in low-level C++ string methods would be inconvenient,
263 * and the error code as the last parameter (ICU convention) would prevent
264 * the use of default parameter values.
265 * Instead, such methods set the UnicodeString into a "bogus" state
266 * (see isBogus()) if an error occurs.
268 * In string comparisons, two UnicodeString objects that are both "bogus"
269 * compare equal (to be transitive and prevent endless loops in sorting),
270 * and a "bogus" string compares less than any non-"bogus" one.
272 * Const UnicodeString methods are thread-safe. Multiple threads can use
273 * const methods on the same UnicodeString object simultaneously,
274 * but non-const methods must not be called concurrently (in multiple threads)
275 * with any other (const or non-const) methods.
277 * Similarly, const UnicodeString & parameters are thread-safe.
278 * One object may be passed in as such a parameter concurrently in multiple threads.
279 * This includes the const UnicodeString & parameters for
280 * copy construction, assignment, and cloning.
282 * <p>UnicodeString uses several storage methods.
283 * String contents can be stored inside the UnicodeString object itself,
284 * in an allocated and shared buffer, or in an outside buffer that is "aliased".
285 * Most of this is done transparently, but careful aliasing in particular provides
286 * significant performance improvements.
287 * Also, the internal buffer is accessible via special functions.
288 * For details see the
289 * <a href="http://userguide.icu-project.org/strings#TOC-Maximizing-Performance-with-the-UnicodeString-Storage-Model">User Guide Strings chapter</a>.</p>
292 * @see CharacterIterator
295 class U_COMMON_API UnicodeString : public Replaceable
300 * Constant to be used in the UnicodeString(char *, int32_t, EInvariant) constructor
301 * which constructs a Unicode string from an invariant-character char * string.
302 * Use the macro US_INV instead of the full qualification for this value.
315 //========================================
316 // Read-only operations
317 //========================================
319 /* Comparison - bitwise only - for international comparison use collation */
322 * Equality operator. Performs only bitwise comparison.
323 * @param text The UnicodeString to compare to this one.
324 * @return TRUE if <TT>text</TT> contains the same characters as this one,
328 inline UBool operator== (const UnicodeString& text) const;
331 * Inequality operator. Performs only bitwise comparison.
332 * @param text The UnicodeString to compare to this one.
333 * @return FALSE if <TT>text</TT> contains the same characters as this one,
337 inline UBool operator!= (const UnicodeString& text) const;
340 * Greater than operator. Performs only bitwise comparison.
341 * @param text The UnicodeString to compare to this one.
342 * @return TRUE if the characters in this are bitwise
343 * greater than the characters in <code>text</code>, FALSE otherwise
346 inline UBool operator> (const UnicodeString& text) const;
349 * Less than operator. Performs only bitwise comparison.
350 * @param text The UnicodeString to compare to this one.
351 * @return TRUE if the characters in this are bitwise
352 * less than the characters in <code>text</code>, FALSE otherwise
355 inline UBool operator< (const UnicodeString& text) const;
358 * Greater than or equal operator. Performs only bitwise comparison.
359 * @param text The UnicodeString to compare to this one.
360 * @return TRUE if the characters in this are bitwise
361 * greater than or equal to the characters in <code>text</code>, FALSE otherwise
364 inline UBool operator>= (const UnicodeString& text) const;
367 * Less than or equal operator. Performs only bitwise comparison.
368 * @param text The UnicodeString to compare to this one.
369 * @return TRUE if the characters in this are bitwise
370 * less than or equal to the characters in <code>text</code>, FALSE otherwise
373 inline UBool operator<= (const UnicodeString& text) const;
376 * Compare the characters bitwise in this UnicodeString to
377 * the characters in <code>text</code>.
378 * @param text The UnicodeString to compare to this one.
379 * @return The result of bitwise character comparison: 0 if this
380 * contains the same characters as <code>text</code>, -1 if the characters in
381 * this are bitwise less than the characters in <code>text</code>, +1 if the
382 * characters in this are bitwise greater than the characters
383 * in <code>text</code>.
386 inline int8_t compare(const UnicodeString& text) const;
389 * Compare the characters bitwise in the range
390 * [<TT>start</TT>, <TT>start + length</TT>) with the characters
391 * in the <b>entire string</b> <TT>text</TT>.
392 * (The parameters "start" and "length" are not applied to the other text "text".)
393 * @param start the offset at which the compare operation begins
394 * @param length the number of characters of text to compare.
395 * @param text the other text to be compared against this string.
396 * @return The result of bitwise character comparison: 0 if this
397 * contains the same characters as <code>text</code>, -1 if the characters in
398 * this are bitwise less than the characters in <code>text</code>, +1 if the
399 * characters in this are bitwise greater than the characters
400 * in <code>text</code>.
403 inline int8_t compare(int32_t start,
405 const UnicodeString& text) const;
408 * Compare the characters bitwise in the range
409 * [<TT>start</TT>, <TT>start + length</TT>) with the characters
410 * in <TT>srcText</TT> in the range
411 * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
412 * @param start the offset at which the compare operation begins
413 * @param length the number of characters in this to compare.
414 * @param srcText the text to be compared
415 * @param srcStart the offset into <TT>srcText</TT> to start comparison
416 * @param srcLength the number of characters in <TT>src</TT> to compare
417 * @return The result of bitwise character comparison: 0 if this
418 * contains the same characters as <code>srcText</code>, -1 if the characters in
419 * this are bitwise less than the characters in <code>srcText</code>, +1 if the
420 * characters in this are bitwise greater than the characters
421 * in <code>srcText</code>.
424 inline int8_t compare(int32_t start,
426 const UnicodeString& srcText,
428 int32_t srcLength) const;
431 * Compare the characters bitwise in this UnicodeString with the first
432 * <TT>srcLength</TT> characters in <TT>srcChars</TT>.
433 * @param srcChars The characters to compare to this UnicodeString.
434 * @param srcLength the number of characters in <TT>srcChars</TT> to compare
435 * @return The result of bitwise character comparison: 0 if this
436 * contains the same characters as <code>srcChars</code>, -1 if the characters in
437 * this are bitwise less than the characters in <code>srcChars</code>, +1 if the
438 * characters in this are bitwise greater than the characters
439 * in <code>srcChars</code>.
442 inline int8_t compare(const UChar *srcChars,
443 int32_t srcLength) const;
446 * Compare the characters bitwise in the range
447 * [<TT>start</TT>, <TT>start + length</TT>) with the first
448 * <TT>length</TT> characters in <TT>srcChars</TT>
449 * @param start the offset at which the compare operation begins
450 * @param length the number of characters to compare.
451 * @param srcChars the characters to be compared
452 * @return The result of bitwise character comparison: 0 if this
453 * contains the same characters as <code>srcChars</code>, -1 if the characters in
454 * this are bitwise less than the characters in <code>srcChars</code>, +1 if the
455 * characters in this are bitwise greater than the characters
456 * in <code>srcChars</code>.
459 inline int8_t compare(int32_t start,
461 const UChar *srcChars) const;
464 * Compare the characters bitwise in the range
465 * [<TT>start</TT>, <TT>start + length</TT>) with the characters
466 * in <TT>srcChars</TT> in the range
467 * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
468 * @param start the offset at which the compare operation begins
469 * @param length the number of characters in this to compare
470 * @param srcChars the characters to be compared
471 * @param srcStart the offset into <TT>srcChars</TT> to start comparison
472 * @param srcLength the number of characters in <TT>srcChars</TT> to compare
473 * @return The result of bitwise character comparison: 0 if this
474 * contains the same characters as <code>srcChars</code>, -1 if the characters in
475 * this are bitwise less than the characters in <code>srcChars</code>, +1 if the
476 * characters in this are bitwise greater than the characters
477 * in <code>srcChars</code>.
480 inline int8_t compare(int32_t start,
482 const UChar *srcChars,
484 int32_t srcLength) const;
487 * Compare the characters bitwise in the range
488 * [<TT>start</TT>, <TT>limit</TT>) with the characters
489 * in <TT>srcText</TT> in the range
490 * [<TT>srcStart</TT>, <TT>srcLimit</TT>).
491 * @param start the offset at which the compare operation begins
492 * @param limit the offset immediately following the compare operation
493 * @param srcText the text to be compared
494 * @param srcStart the offset into <TT>srcText</TT> to start comparison
495 * @param srcLimit the offset into <TT>srcText</TT> to limit comparison
496 * @return The result of bitwise character comparison: 0 if this
497 * contains the same characters as <code>srcText</code>, -1 if the characters in
498 * this are bitwise less than the characters in <code>srcText</code>, +1 if the
499 * characters in this are bitwise greater than the characters
500 * in <code>srcText</code>.
503 inline int8_t compareBetween(int32_t start,
505 const UnicodeString& srcText,
507 int32_t srcLimit) const;
510 * Compare two Unicode strings in code point order.
511 * The result may be different from the results of compare(), operator<, etc.
512 * if supplementary characters are present:
514 * In UTF-16, supplementary characters (with code points U+10000 and above) are
515 * stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff,
516 * which means that they compare as less than some other BMP characters like U+feff.
517 * This function compares Unicode strings in code point order.
518 * If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.
520 * @param text Another string to compare this one to.
521 * @return a negative/zero/positive integer corresponding to whether
522 * this string is less than/equal to/greater than the second one
523 * in code point order
526 inline int8_t compareCodePointOrder(const UnicodeString& text) const;
529 * Compare two Unicode strings in code point order.
530 * The result may be different from the results of compare(), operator<, etc.
531 * if supplementary characters are present:
533 * In UTF-16, supplementary characters (with code points U+10000 and above) are
534 * stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff,
535 * which means that they compare as less than some other BMP characters like U+feff.
536 * This function compares Unicode strings in code point order.
537 * If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.
539 * @param start The start offset in this string at which the compare operation begins.
540 * @param length The number of code units from this string to compare.
541 * @param srcText Another string to compare this one to.
542 * @return a negative/zero/positive integer corresponding to whether
543 * this string is less than/equal to/greater than the second one
544 * in code point order
547 inline int8_t compareCodePointOrder(int32_t start,
549 const UnicodeString& srcText) const;
552 * Compare two Unicode strings in code point order.
553 * The result may be different from the results of compare(), operator<, etc.
554 * if supplementary characters are present:
556 * In UTF-16, supplementary characters (with code points U+10000 and above) are
557 * stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff,
558 * which means that they compare as less than some other BMP characters like U+feff.
559 * This function compares Unicode strings in code point order.
560 * If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.
562 * @param start The start offset in this string at which the compare operation begins.
563 * @param length The number of code units from this string to compare.
564 * @param srcText Another string to compare this one to.
565 * @param srcStart The start offset in that string at which the compare operation begins.
566 * @param srcLength The number of code units from that string to compare.
567 * @return a negative/zero/positive integer corresponding to whether
568 * this string is less than/equal to/greater than the second one
569 * in code point order
572 inline int8_t compareCodePointOrder(int32_t start,
574 const UnicodeString& srcText,
576 int32_t srcLength) const;
579 * Compare two Unicode strings in code point order.
580 * The result may be different from the results of compare(), operator<, etc.
581 * if supplementary characters are present:
583 * In UTF-16, supplementary characters (with code points U+10000 and above) are
584 * stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff,
585 * which means that they compare as less than some other BMP characters like U+feff.
586 * This function compares Unicode strings in code point order.
587 * If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.
589 * @param srcChars A pointer to another string to compare this one to.
590 * @param srcLength The number of code units from that string to compare.
591 * @return a negative/zero/positive integer corresponding to whether
592 * this string is less than/equal to/greater than the second one
593 * in code point order
596 inline int8_t compareCodePointOrder(const UChar *srcChars,
597 int32_t srcLength) const;
600 * Compare two Unicode strings in code point order.
601 * The result may be different from the results of compare(), operator<, etc.
602 * if supplementary characters are present:
604 * In UTF-16, supplementary characters (with code points U+10000 and above) are
605 * stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff,
606 * which means that they compare as less than some other BMP characters like U+feff.
607 * This function compares Unicode strings in code point order.
608 * If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.
610 * @param start The start offset in this string at which the compare operation begins.
611 * @param length The number of code units from this string to compare.
612 * @param srcChars A pointer to another string to compare this one to.
613 * @return a negative/zero/positive integer corresponding to whether
614 * this string is less than/equal to/greater than the second one
615 * in code point order
618 inline int8_t compareCodePointOrder(int32_t start,
620 const UChar *srcChars) const;
623 * Compare two Unicode strings in code point order.
624 * The result may be different from the results of compare(), operator<, etc.
625 * if supplementary characters are present:
627 * In UTF-16, supplementary characters (with code points U+10000 and above) are
628 * stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff,
629 * which means that they compare as less than some other BMP characters like U+feff.
630 * This function compares Unicode strings in code point order.
631 * If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.
633 * @param start The start offset in this string at which the compare operation begins.
634 * @param length The number of code units from this string to compare.
635 * @param srcChars A pointer to another string to compare this one to.
636 * @param srcStart The start offset in that string at which the compare operation begins.
637 * @param srcLength The number of code units from that string to compare.
638 * @return a negative/zero/positive integer corresponding to whether
639 * this string is less than/equal to/greater than the second one
640 * in code point order
643 inline int8_t compareCodePointOrder(int32_t start,
645 const UChar *srcChars,
647 int32_t srcLength) const;
650 * Compare two Unicode strings in code point order.
651 * The result may be different from the results of compare(), operator<, etc.
652 * if supplementary characters are present:
654 * In UTF-16, supplementary characters (with code points U+10000 and above) are
655 * stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff,
656 * which means that they compare as less than some other BMP characters like U+feff.
657 * This function compares Unicode strings in code point order.
658 * If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.
660 * @param start The start offset in this string at which the compare operation begins.
661 * @param limit The offset after the last code unit from this string to compare.
662 * @param srcText Another string to compare this one to.
663 * @param srcStart The start offset in that string at which the compare operation begins.
664 * @param srcLimit The offset after the last code unit from that string to compare.
665 * @return a negative/zero/positive integer corresponding to whether
666 * this string is less than/equal to/greater than the second one
667 * in code point order
670 inline int8_t compareCodePointOrderBetween(int32_t start,
672 const UnicodeString& srcText,
674 int32_t srcLimit) const;
677 * Compare two strings case-insensitively using full case folding.
678 * This is equivalent to this->foldCase(options).compare(text.foldCase(options)).
680 * @param text Another string to compare this one to.
681 * @param options A bit set of options:
682 * - U_FOLD_CASE_DEFAULT or 0 is used for default options:
683 * Comparison in code unit order with default case folding.
685 * - U_COMPARE_CODE_POINT_ORDER
686 * Set to choose code point order instead of code unit order
687 * (see u_strCompare for details).
689 * - U_FOLD_CASE_EXCLUDE_SPECIAL_I
691 * @return A negative, zero, or positive integer indicating the comparison result.
694 inline int8_t caseCompare(const UnicodeString& text, uint32_t options) const;
697 * Compare two strings case-insensitively using full case folding.
698 * This is equivalent to this->foldCase(options).compare(srcText.foldCase(options)).
700 * @param start The start offset in this string at which the compare operation begins.
701 * @param length The number of code units from this string to compare.
702 * @param srcText Another string to compare this one to.
703 * @param options A bit set of options:
704 * - U_FOLD_CASE_DEFAULT or 0 is used for default options:
705 * Comparison in code unit order with default case folding.
707 * - U_COMPARE_CODE_POINT_ORDER
708 * Set to choose code point order instead of code unit order
709 * (see u_strCompare for details).
711 * - U_FOLD_CASE_EXCLUDE_SPECIAL_I
713 * @return A negative, zero, or positive integer indicating the comparison result.
716 inline int8_t caseCompare(int32_t start,
718 const UnicodeString& srcText,
719 uint32_t options) const;
722 * Compare two strings case-insensitively using full case folding.
723 * This is equivalent to this->foldCase(options).compare(srcText.foldCase(options)).
725 * @param start The start offset in this string at which the compare operation begins.
726 * @param length The number of code units from this string to compare.
727 * @param srcText Another string to compare this one to.
728 * @param srcStart The start offset in that string at which the compare operation begins.
729 * @param srcLength The number of code units from that string to compare.
730 * @param options A bit set of options:
731 * - U_FOLD_CASE_DEFAULT or 0 is used for default options:
732 * Comparison in code unit order with default case folding.
734 * - U_COMPARE_CODE_POINT_ORDER
735 * Set to choose code point order instead of code unit order
736 * (see u_strCompare for details).
738 * - U_FOLD_CASE_EXCLUDE_SPECIAL_I
740 * @return A negative, zero, or positive integer indicating the comparison result.
743 inline int8_t caseCompare(int32_t start,
745 const UnicodeString& srcText,
748 uint32_t options) const;
751 * Compare two strings case-insensitively using full case folding.
752 * This is equivalent to this->foldCase(options).compare(srcChars.foldCase(options)).
754 * @param srcChars A pointer to another string to compare this one to.
755 * @param srcLength The number of code units from that string to compare.
756 * @param options A bit set of options:
757 * - U_FOLD_CASE_DEFAULT or 0 is used for default options:
758 * Comparison in code unit order with default case folding.
760 * - U_COMPARE_CODE_POINT_ORDER
761 * Set to choose code point order instead of code unit order
762 * (see u_strCompare for details).
764 * - U_FOLD_CASE_EXCLUDE_SPECIAL_I
766 * @return A negative, zero, or positive integer indicating the comparison result.
769 inline int8_t caseCompare(const UChar *srcChars,
771 uint32_t options) const;
774 * Compare two strings case-insensitively using full case folding.
775 * This is equivalent to this->foldCase(options).compare(srcChars.foldCase(options)).
777 * @param start The start offset in this string at which the compare operation begins.
778 * @param length The number of code units from this string to compare.
779 * @param srcChars A pointer to another string to compare this one to.
780 * @param options A bit set of options:
781 * - U_FOLD_CASE_DEFAULT or 0 is used for default options:
782 * Comparison in code unit order with default case folding.
784 * - U_COMPARE_CODE_POINT_ORDER
785 * Set to choose code point order instead of code unit order
786 * (see u_strCompare for details).
788 * - U_FOLD_CASE_EXCLUDE_SPECIAL_I
790 * @return A negative, zero, or positive integer indicating the comparison result.
793 inline int8_t caseCompare(int32_t start,
795 const UChar *srcChars,
796 uint32_t options) const;
799 * Compare two strings case-insensitively using full case folding.
800 * This is equivalent to this->foldCase(options).compare(srcChars.foldCase(options)).
802 * @param start The start offset in this string at which the compare operation begins.
803 * @param length The number of code units from this string to compare.
804 * @param srcChars A pointer to another string to compare this one to.
805 * @param srcStart The start offset in that string at which the compare operation begins.
806 * @param srcLength The number of code units from that string to compare.
807 * @param options A bit set of options:
808 * - U_FOLD_CASE_DEFAULT or 0 is used for default options:
809 * Comparison in code unit order with default case folding.
811 * - U_COMPARE_CODE_POINT_ORDER
812 * Set to choose code point order instead of code unit order
813 * (see u_strCompare for details).
815 * - U_FOLD_CASE_EXCLUDE_SPECIAL_I
817 * @return A negative, zero, or positive integer indicating the comparison result.
820 inline int8_t caseCompare(int32_t start,
822 const UChar *srcChars,
825 uint32_t options) const;
828 * Compare two strings case-insensitively using full case folding.
829 * This is equivalent to this->foldCase(options).compareBetween(text.foldCase(options)).
831 * @param start The start offset in this string at which the compare operation begins.
832 * @param limit The offset after the last code unit from this string to compare.
833 * @param srcText Another string to compare this one to.
834 * @param srcStart The start offset in that string at which the compare operation begins.
835 * @param srcLimit The offset after the last code unit from that string to compare.
836 * @param options A bit set of options:
837 * - U_FOLD_CASE_DEFAULT or 0 is used for default options:
838 * Comparison in code unit order with default case folding.
840 * - U_COMPARE_CODE_POINT_ORDER
841 * Set to choose code point order instead of code unit order
842 * (see u_strCompare for details).
844 * - U_FOLD_CASE_EXCLUDE_SPECIAL_I
846 * @return A negative, zero, or positive integer indicating the comparison result.
849 inline int8_t caseCompareBetween(int32_t start,
851 const UnicodeString& srcText,
854 uint32_t options) const;
857 * Determine if this starts with the characters in <TT>text</TT>
858 * @param text The text to match.
859 * @return TRUE if this starts with the characters in <TT>text</TT>,
863 inline UBool startsWith(const UnicodeString& text) const;
866 * Determine if this starts with the characters in <TT>srcText</TT>
867 * in the range [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
868 * @param srcText The text to match.
869 * @param srcStart the offset into <TT>srcText</TT> to start matching
870 * @param srcLength the number of characters in <TT>srcText</TT> to match
871 * @return TRUE if this starts with the characters in <TT>text</TT>,
875 inline UBool startsWith(const UnicodeString& srcText,
877 int32_t srcLength) const;
880 * Determine if this starts with the characters in <TT>srcChars</TT>
881 * @param srcChars The characters to match.
882 * @param srcLength the number of characters in <TT>srcChars</TT>
883 * @return TRUE if this starts with the characters in <TT>srcChars</TT>,
887 inline UBool startsWith(const UChar *srcChars,
888 int32_t srcLength) const;
891 * Determine if this ends with the characters in <TT>srcChars</TT>
892 * in the range [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
893 * @param srcChars The characters to match.
894 * @param srcStart the offset into <TT>srcText</TT> to start matching
895 * @param srcLength the number of characters in <TT>srcChars</TT> to match
896 * @return TRUE if this ends with the characters in <TT>srcChars</TT>, FALSE otherwise
899 inline UBool startsWith(const UChar *srcChars,
901 int32_t srcLength) const;
904 * Determine if this ends with the characters in <TT>text</TT>
905 * @param text The text to match.
906 * @return TRUE if this ends with the characters in <TT>text</TT>,
910 inline UBool endsWith(const UnicodeString& text) const;
913 * Determine if this ends with the characters in <TT>srcText</TT>
914 * in the range [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
915 * @param srcText The text to match.
916 * @param srcStart the offset into <TT>srcText</TT> to start matching
917 * @param srcLength the number of characters in <TT>srcText</TT> to match
918 * @return TRUE if this ends with the characters in <TT>text</TT>,
922 inline UBool endsWith(const UnicodeString& srcText,
924 int32_t srcLength) const;
927 * Determine if this ends with the characters in <TT>srcChars</TT>
928 * @param srcChars The characters to match.
929 * @param srcLength the number of characters in <TT>srcChars</TT>
930 * @return TRUE if this ends with the characters in <TT>srcChars</TT>,
934 inline UBool endsWith(const UChar *srcChars,
935 int32_t srcLength) const;
938 * Determine if this ends with the characters in <TT>srcChars</TT>
939 * in the range [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
940 * @param srcChars The characters to match.
941 * @param srcStart the offset into <TT>srcText</TT> to start matching
942 * @param srcLength the number of characters in <TT>srcChars</TT> to match
943 * @return TRUE if this ends with the characters in <TT>srcChars</TT>,
947 inline UBool endsWith(const UChar *srcChars,
949 int32_t srcLength) const;
952 /* Searching - bitwise only */
955 * Locate in this the first occurrence of the characters in <TT>text</TT>,
956 * using bitwise comparison.
957 * @param text The text to search for.
958 * @return The offset into this of the start of <TT>text</TT>,
959 * or -1 if not found.
962 inline int32_t indexOf(const UnicodeString& text) const;
965 * Locate in this the first occurrence of the characters in <TT>text</TT>
966 * starting at offset <TT>start</TT>, using bitwise comparison.
967 * @param text The text to search for.
968 * @param start The offset at which searching will start.
969 * @return The offset into this of the start of <TT>text</TT>,
970 * or -1 if not found.
973 inline int32_t indexOf(const UnicodeString& text,
974 int32_t start) const;
977 * Locate in this the first occurrence in the range
978 * [<TT>start</TT>, <TT>start + length</TT>) of the characters
979 * in <TT>text</TT>, using bitwise comparison.
980 * @param text The text to search for.
981 * @param start The offset at which searching will start.
982 * @param length The number of characters to search
983 * @return The offset into this of the start of <TT>text</TT>,
984 * or -1 if not found.
987 inline int32_t indexOf(const UnicodeString& text,
989 int32_t length) const;
992 * Locate in this the first occurrence in the range
993 * [<TT>start</TT>, <TT>start + length</TT>) of the characters
994 * in <TT>srcText</TT> in the range
995 * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>),
996 * using bitwise comparison.
997 * @param srcText The text to search for.
998 * @param srcStart the offset into <TT>srcText</TT> at which
1000 * @param srcLength the number of characters in <TT>srcText</TT> to match
1001 * @param start the offset into this at which to start matching
1002 * @param length the number of characters in this to search
1003 * @return The offset into this of the start of <TT>text</TT>,
1004 * or -1 if not found.
1007 inline int32_t indexOf(const UnicodeString& srcText,
1011 int32_t length) const;
1014 * Locate in this the first occurrence of the characters in
1016 * starting at offset <TT>start</TT>, using bitwise comparison.
1017 * @param srcChars The text to search for.
1018 * @param srcLength the number of characters in <TT>srcChars</TT> to match
1019 * @param start the offset into this at which to start matching
1020 * @return The offset into this of the start of <TT>text</TT>,
1021 * or -1 if not found.
1024 inline int32_t indexOf(const UChar *srcChars,
1026 int32_t start) const;
1029 * Locate in this the first occurrence in the range
1030 * [<TT>start</TT>, <TT>start + length</TT>) of the characters
1031 * in <TT>srcChars</TT>, using bitwise comparison.
1032 * @param srcChars The text to search for.
1033 * @param srcLength the number of characters in <TT>srcChars</TT>
1034 * @param start The offset at which searching will start.
1035 * @param length The number of characters to search
1036 * @return The offset into this of the start of <TT>srcChars</TT>,
1037 * or -1 if not found.
1040 inline int32_t indexOf(const UChar *srcChars,
1043 int32_t length) const;
1046 * Locate in this the first occurrence in the range
1047 * [<TT>start</TT>, <TT>start + length</TT>) of the characters
1048 * in <TT>srcChars</TT> in the range
1049 * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>),
1050 * using bitwise comparison.
1051 * @param srcChars The text to search for.
1052 * @param srcStart the offset into <TT>srcChars</TT> at which
1054 * @param srcLength the number of characters in <TT>srcChars</TT> to match
1055 * @param start the offset into this at which to start matching
1056 * @param length the number of characters in this to search
1057 * @return The offset into this of the start of <TT>text</TT>,
1058 * or -1 if not found.
1061 int32_t indexOf(const UChar *srcChars,
1065 int32_t length) const;
1068 * Locate in this the first occurrence of the BMP code point <code>c</code>,
1069 * using bitwise comparison.
1070 * @param c The code unit to search for.
1071 * @return The offset into this of <TT>c</TT>, or -1 if not found.
1074 inline int32_t indexOf(UChar c) const;
1077 * Locate in this the first occurrence of the code point <TT>c</TT>,
1078 * using bitwise comparison.
1080 * @param c The code point to search for.
1081 * @return The offset into this of <TT>c</TT>, or -1 if not found.
1084 inline int32_t indexOf(UChar32 c) const;
1087 * Locate in this the first occurrence of the BMP code point <code>c</code>,
1088 * starting at offset <TT>start</TT>, using bitwise comparison.
1089 * @param c The code unit to search for.
1090 * @param start The offset at which searching will start.
1091 * @return The offset into this of <TT>c</TT>, or -1 if not found.
1094 inline int32_t indexOf(UChar c,
1095 int32_t start) const;
1098 * Locate in this the first occurrence of the code point <TT>c</TT>
1099 * starting at offset <TT>start</TT>, using bitwise comparison.
1101 * @param c The code point to search for.
1102 * @param start The offset at which searching will start.
1103 * @return The offset into this of <TT>c</TT>, or -1 if not found.
1106 inline int32_t indexOf(UChar32 c,
1107 int32_t start) const;
1110 * Locate in this the first occurrence of the BMP code point <code>c</code>
1111 * in the range [<TT>start</TT>, <TT>start + length</TT>),
1112 * using bitwise comparison.
1113 * @param c The code unit to search for.
1114 * @param start the offset into this at which to start matching
1115 * @param length the number of characters in this to search
1116 * @return The offset into this of <TT>c</TT>, or -1 if not found.
1119 inline int32_t indexOf(UChar c,
1121 int32_t length) const;
1124 * Locate in this the first occurrence of the code point <TT>c</TT>
1125 * in the range [<TT>start</TT>, <TT>start + length</TT>),
1126 * using bitwise comparison.
1128 * @param c The code point to search for.
1129 * @param start the offset into this at which to start matching
1130 * @param length the number of characters in this to search
1131 * @return The offset into this of <TT>c</TT>, or -1 if not found.
1134 inline int32_t indexOf(UChar32 c,
1136 int32_t length) const;
1139 * Locate in this the last occurrence of the characters in <TT>text</TT>,
1140 * using bitwise comparison.
1141 * @param text The text to search for.
1142 * @return The offset into this of the start of <TT>text</TT>,
1143 * or -1 if not found.
1146 inline int32_t lastIndexOf(const UnicodeString& text) const;
1149 * Locate in this the last occurrence of the characters in <TT>text</TT>
1150 * starting at offset <TT>start</TT>, using bitwise comparison.
1151 * @param text The text to search for.
1152 * @param start The offset at which searching will start.
1153 * @return The offset into this of the start of <TT>text</TT>,
1154 * or -1 if not found.
1157 inline int32_t lastIndexOf(const UnicodeString& text,
1158 int32_t start) const;
1161 * Locate in this the last occurrence in the range
1162 * [<TT>start</TT>, <TT>start + length</TT>) of the characters
1163 * in <TT>text</TT>, using bitwise comparison.
1164 * @param text The text to search for.
1165 * @param start The offset at which searching will start.
1166 * @param length The number of characters to search
1167 * @return The offset into this of the start of <TT>text</TT>,
1168 * or -1 if not found.
1171 inline int32_t lastIndexOf(const UnicodeString& text,
1173 int32_t length) const;
1176 * Locate in this the last occurrence in the range
1177 * [<TT>start</TT>, <TT>start + length</TT>) of the characters
1178 * in <TT>srcText</TT> in the range
1179 * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>),
1180 * using bitwise comparison.
1181 * @param srcText The text to search for.
1182 * @param srcStart the offset into <TT>srcText</TT> at which
1184 * @param srcLength the number of characters in <TT>srcText</TT> to match
1185 * @param start the offset into this at which to start matching
1186 * @param length the number of characters in this to search
1187 * @return The offset into this of the start of <TT>text</TT>,
1188 * or -1 if not found.
1191 inline int32_t lastIndexOf(const UnicodeString& srcText,
1195 int32_t length) const;
1198 * Locate in this the last occurrence of the characters in <TT>srcChars</TT>
1199 * starting at offset <TT>start</TT>, using bitwise comparison.
1200 * @param srcChars The text to search for.
1201 * @param srcLength the number of characters in <TT>srcChars</TT> to match
1202 * @param start the offset into this at which to start matching
1203 * @return The offset into this of the start of <TT>text</TT>,
1204 * or -1 if not found.
1207 inline int32_t lastIndexOf(const UChar *srcChars,
1209 int32_t start) const;
1212 * Locate in this the last occurrence in the range
1213 * [<TT>start</TT>, <TT>start + length</TT>) of the characters
1214 * in <TT>srcChars</TT>, using bitwise comparison.
1215 * @param srcChars The text to search for.
1216 * @param srcLength the number of characters in <TT>srcChars</TT>
1217 * @param start The offset at which searching will start.
1218 * @param length The number of characters to search
1219 * @return The offset into this of the start of <TT>srcChars</TT>,
1220 * or -1 if not found.
1223 inline int32_t lastIndexOf(const UChar *srcChars,
1226 int32_t length) const;
1229 * Locate in this the last occurrence in the range
1230 * [<TT>start</TT>, <TT>start + length</TT>) of the characters
1231 * in <TT>srcChars</TT> in the range
1232 * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>),
1233 * using bitwise comparison.
1234 * @param srcChars The text to search for.
1235 * @param srcStart the offset into <TT>srcChars</TT> at which
1237 * @param srcLength the number of characters in <TT>srcChars</TT> to match
1238 * @param start the offset into this at which to start matching
1239 * @param length the number of characters in this to search
1240 * @return The offset into this of the start of <TT>text</TT>,
1241 * or -1 if not found.
1244 int32_t lastIndexOf(const UChar *srcChars,
1248 int32_t length) const;
1251 * Locate in this the last occurrence of the BMP code point <code>c</code>,
1252 * using bitwise comparison.
1253 * @param c The code unit to search for.
1254 * @return The offset into this of <TT>c</TT>, or -1 if not found.
1257 inline int32_t lastIndexOf(UChar c) const;
1260 * Locate in this the last occurrence of the code point <TT>c</TT>,
1261 * using bitwise comparison.
1263 * @param c The code point to search for.
1264 * @return The offset into this of <TT>c</TT>, or -1 if not found.
1267 inline int32_t lastIndexOf(UChar32 c) const;
1270 * Locate in this the last occurrence of the BMP code point <code>c</code>
1271 * starting at offset <TT>start</TT>, using bitwise comparison.
1272 * @param c The code unit to search for.
1273 * @param start The offset at which searching will start.
1274 * @return The offset into this of <TT>c</TT>, or -1 if not found.
1277 inline int32_t lastIndexOf(UChar c,
1278 int32_t start) const;
1281 * Locate in this the last occurrence of the code point <TT>c</TT>
1282 * starting at offset <TT>start</TT>, using bitwise comparison.
1284 * @param c The code point to search for.
1285 * @param start The offset at which searching will start.
1286 * @return The offset into this of <TT>c</TT>, or -1 if not found.
1289 inline int32_t lastIndexOf(UChar32 c,
1290 int32_t start) const;
1293 * Locate in this the last occurrence of the BMP code point <code>c</code>
1294 * in the range [<TT>start</TT>, <TT>start + length</TT>),
1295 * using bitwise comparison.
1296 * @param c The code unit to search for.
1297 * @param start the offset into this at which to start matching
1298 * @param length the number of characters in this to search
1299 * @return The offset into this of <TT>c</TT>, or -1 if not found.
1302 inline int32_t lastIndexOf(UChar c,
1304 int32_t length) const;
1307 * Locate in this the last occurrence of the code point <TT>c</TT>
1308 * in the range [<TT>start</TT>, <TT>start + length</TT>),
1309 * using bitwise comparison.
1311 * @param c The code point to search for.
1312 * @param start the offset into this at which to start matching
1313 * @param length the number of characters in this to search
1314 * @return The offset into this of <TT>c</TT>, or -1 if not found.
1317 inline int32_t lastIndexOf(UChar32 c,
1319 int32_t length) const;
1322 /* Character access */
1325 * Return the code unit at offset <tt>offset</tt>.
1326 * If the offset is not valid (0..length()-1) then U+ffff is returned.
1327 * @param offset a valid offset into the text
1328 * @return the code unit at offset <tt>offset</tt>
1329 * or 0xffff if the offset is not valid for this string
1332 inline UChar charAt(int32_t offset) const;
1335 * Return the code unit at offset <tt>offset</tt>.
1336 * If the offset is not valid (0..length()-1) then U+ffff is returned.
1337 * @param offset a valid offset into the text
1338 * @return the code unit at offset <tt>offset</tt>
1341 inline UChar operator[] (int32_t offset) const;
1344 * Return the code point that contains the code unit
1345 * at offset <tt>offset</tt>.
1346 * If the offset is not valid (0..length()-1) then U+ffff is returned.
1347 * @param offset a valid offset into the text
1348 * that indicates the text offset of any of the code units
1349 * that will be assembled into a code point (21-bit value) and returned
1350 * @return the code point of text at <tt>offset</tt>
1351 * or 0xffff if the offset is not valid for this string
1354 UChar32 char32At(int32_t offset) const;
1357 * Adjust a random-access offset so that
1358 * it points to the beginning of a Unicode character.
1359 * The offset that is passed in points to
1360 * any code unit of a code point,
1361 * while the returned offset will point to the first code unit
1362 * of the same code point.
1363 * In UTF-16, if the input offset points to a second surrogate
1364 * of a surrogate pair, then the returned offset will point
1365 * to the first surrogate.
1366 * @param offset a valid offset into one code point of the text
1367 * @return offset of the first code unit of the same code point
1368 * @see U16_SET_CP_START
1371 int32_t getChar32Start(int32_t offset) const;
1374 * Adjust a random-access offset so that
1375 * it points behind a Unicode character.
1376 * The offset that is passed in points behind
1377 * any code unit of a code point,
1378 * while the returned offset will point behind the last code unit
1379 * of the same code point.
1380 * In UTF-16, if the input offset points behind the first surrogate
1381 * (i.e., to the second surrogate)
1382 * of a surrogate pair, then the returned offset will point
1383 * behind the second surrogate (i.e., to the first surrogate).
1384 * @param offset a valid offset after any code unit of a code point of the text
1385 * @return offset of the first code unit after the same code point
1386 * @see U16_SET_CP_LIMIT
1389 int32_t getChar32Limit(int32_t offset) const;
1392 * Move the code unit index along the string by delta code points.
1393 * Interpret the input index as a code unit-based offset into the string,
1394 * move the index forward or backward by delta code points, and
1395 * return the resulting index.
1396 * The input index should point to the first code unit of a code point,
1397 * if there is more than one.
1399 * Both input and output indexes are code unit-based as for all
1400 * string indexes/offsets in ICU (and other libraries, like MBCS char*).
1401 * If delta<0 then the index is moved backward (toward the start of the string).
1402 * If delta>0 then the index is moved forward (toward the end of the string).
1404 * This behaves like CharacterIterator::move32(delta, kCurrent).
1406 * Behavior for out-of-bounds indexes:
1407 * <code>moveIndex32</code> pins the input index to 0..length(), i.e.,
1408 * if the input index<0 then it is pinned to 0;
1409 * if it is index>length() then it is pinned to length().
1410 * Afterwards, the index is moved by <code>delta</code> code points
1411 * forward or backward,
1412 * but no further backward than to 0 and no further forward than to length().
1413 * The resulting index return value will be in between 0 and length(), inclusively.
1417 * // s has code points 'a' U+10000 'b' U+10ffff U+2029
1418 * UnicodeString s=UNICODE_STRING("a\\U00010000b\\U0010ffff\\u2029", 31).unescape();
1420 * // initial index: position of U+10000
1423 * // the following examples will all result in index==4, position of U+10ffff
1425 * // skip 2 code points from some position in the string
1426 * index=s.moveIndex32(index, 2); // skips U+10000 and 'b'
1428 * // go to the 3rd code point from the start of s (0-based)
1429 * index=s.moveIndex32(0, 3); // skips 'a', U+10000, and 'b'
1431 * // go to the next-to-last code point of s
1432 * index=s.moveIndex32(s.length(), -2); // backward-skips U+2029 and U+10ffff
1435 * @param index input code unit index
1436 * @param delta (signed) code point count to move the index forward or backward
1438 * @return the resulting code unit index
1441 int32_t moveIndex32(int32_t index, int32_t delta) const;
1443 /* Substring extraction */
1446 * Copy the characters in the range
1447 * [<tt>start</tt>, <tt>start + length</tt>) into the array <tt>dst</tt>,
1448 * beginning at <tt>dstStart</tt>.
1449 * If the string aliases to <code>dst</code> itself as an external buffer,
1450 * then extract() will not copy the contents.
1452 * @param start offset of first character which will be copied into the array
1453 * @param length the number of characters to extract
1454 * @param dst array in which to copy characters. The length of <tt>dst</tt>
1455 * must be at least (<tt>dstStart + length</tt>).
1456 * @param dstStart the offset in <TT>dst</TT> where the first character
1460 inline void extract(int32_t start,
1463 int32_t dstStart = 0) const;
1466 * Copy the contents of the string into dest.
1467 * This is a convenience function that
1468 * checks if there is enough space in dest,
1469 * extracts the entire string if possible,
1470 * and NUL-terminates dest if possible.
1472 * If the string fits into dest but cannot be NUL-terminated
1473 * (length()==destCapacity) then the error code is set to U_STRING_NOT_TERMINATED_WARNING.
1474 * If the string itself does not fit into dest
1475 * (length()>destCapacity) then the error code is set to U_BUFFER_OVERFLOW_ERROR.
1477 * If the string aliases to <code>dest</code> itself as an external buffer,
1478 * then extract() will not copy the contents.
1480 * @param dest Destination string buffer.
1481 * @param destCapacity Number of UChars available at dest.
1482 * @param errorCode ICU error code.
1487 extract(UChar *dest, int32_t destCapacity,
1488 UErrorCode &errorCode) const;
1491 * Copy the characters in the range
1492 * [<tt>start</tt>, <tt>start + length</tt>) into the UnicodeString
1494 * @param start offset of first character which will be copied
1495 * @param length the number of characters to extract
1496 * @param target UnicodeString into which to copy characters.
1497 * @return A reference to <TT>target</TT>
1500 inline void extract(int32_t start,
1502 UnicodeString& target) const;
1505 * Copy the characters in the range [<tt>start</tt>, <tt>limit</tt>)
1506 * into the array <tt>dst</tt>, beginning at <tt>dstStart</tt>.
1507 * @param start offset of first character which will be copied into the array
1508 * @param limit offset immediately following the last character to be copied
1509 * @param dst array in which to copy characters. The length of <tt>dst</tt>
1510 * must be at least (<tt>dstStart + (limit - start)</tt>).
1511 * @param dstStart the offset in <TT>dst</TT> where the first character
1515 inline void extractBetween(int32_t start,
1518 int32_t dstStart = 0) const;
1521 * Copy the characters in the range [<tt>start</tt>, <tt>limit</tt>)
1522 * into the UnicodeString <tt>target</tt>. Replaceable API.
1523 * @param start offset of first character which will be copied
1524 * @param limit offset immediately following the last character to be copied
1525 * @param target UnicodeString into which to copy characters.
1526 * @return A reference to <TT>target</TT>
1529 virtual void extractBetween(int32_t start,
1531 UnicodeString& target) const;
1534 * Copy the characters in the range
1535 * [<tt>start</TT>, <tt>start + startLength</TT>) into an array of characters.
1536 * All characters must be invariant (see utypes.h).
1537 * Use US_INV as the last, signature-distinguishing parameter.
1539 * This function does not write any more than <code>targetCapacity</code>
1540 * characters but returns the length of the entire output string
1541 * so that one can allocate a larger buffer and call the function again
1543 * The output string is NUL-terminated if possible.
1545 * @param start offset of first character which will be copied
1546 * @param startLength the number of characters to extract
1547 * @param target the target buffer for extraction, can be NULL
1548 * if targetLength is 0
1549 * @param targetCapacity the length of the target buffer
1550 * @param inv Signature-distinguishing paramater, use US_INV.
1551 * @return the output string length, not including the terminating NUL
1554 int32_t extract(int32_t start,
1555 int32_t startLength,
1557 int32_t targetCapacity,
1558 enum EInvariant inv) const;
1560 #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
1563 * Copy the characters in the range
1564 * [<tt>start</TT>, <tt>start + length</TT>) into an array of characters
1565 * in the platform's default codepage.
1566 * This function does not write any more than <code>targetLength</code>
1567 * characters but returns the length of the entire output string
1568 * so that one can allocate a larger buffer and call the function again
1570 * The output string is NUL-terminated if possible.
1572 * @param start offset of first character which will be copied
1573 * @param startLength the number of characters to extract
1574 * @param target the target buffer for extraction
1575 * @param targetLength the length of the target buffer
1576 * If <TT>target</TT> is NULL, then the number of bytes required for
1577 * <TT>target</TT> is returned.
1578 * @return the output string length, not including the terminating NUL
1581 int32_t extract(int32_t start,
1582 int32_t startLength,
1584 uint32_t targetLength) const;
1588 #if !UCONFIG_NO_CONVERSION
1591 * Copy the characters in the range
1592 * [<tt>start</TT>, <tt>start + length</TT>) into an array of characters
1593 * in a specified codepage.
1594 * The output string is NUL-terminated.
1596 * Recommendation: For invariant-character strings use
1597 * extract(int32_t start, int32_t length, char *target, int32_t targetCapacity, enum EInvariant inv) const
1598 * because it avoids object code dependencies of UnicodeString on
1599 * the conversion code.
1601 * @param start offset of first character which will be copied
1602 * @param startLength the number of characters to extract
1603 * @param target the target buffer for extraction
1604 * @param codepage the desired codepage for the characters. 0 has
1605 * the special meaning of the default codepage
1606 * If <code>codepage</code> is an empty string (<code>""</code>),
1607 * then a simple conversion is performed on the codepage-invariant
1608 * subset ("invariant characters") of the platform encoding. See utypes.h.
1609 * If <TT>target</TT> is NULL, then the number of bytes required for
1610 * <TT>target</TT> is returned. It is assumed that the target is big enough
1611 * to fit all of the characters.
1612 * @return the output string length, not including the terminating NUL
1615 inline int32_t extract(int32_t start,
1616 int32_t startLength,
1618 const char *codepage = 0) const;
1621 * Copy the characters in the range
1622 * [<tt>start</TT>, <tt>start + length</TT>) into an array of characters
1623 * in a specified codepage.
1624 * This function does not write any more than <code>targetLength</code>
1625 * characters but returns the length of the entire output string
1626 * so that one can allocate a larger buffer and call the function again
1628 * The output string is NUL-terminated if possible.
1630 * Recommendation: For invariant-character strings use
1631 * extract(int32_t start, int32_t length, char *target, int32_t targetCapacity, enum EInvariant inv) const
1632 * because it avoids object code dependencies of UnicodeString on
1633 * the conversion code.
1635 * @param start offset of first character which will be copied
1636 * @param startLength the number of characters to extract
1637 * @param target the target buffer for extraction
1638 * @param targetLength the length of the target buffer
1639 * @param codepage the desired codepage for the characters. 0 has
1640 * the special meaning of the default codepage
1641 * If <code>codepage</code> is an empty string (<code>""</code>),
1642 * then a simple conversion is performed on the codepage-invariant
1643 * subset ("invariant characters") of the platform encoding. See utypes.h.
1644 * If <TT>target</TT> is NULL, then the number of bytes required for
1645 * <TT>target</TT> is returned.
1646 * @return the output string length, not including the terminating NUL
1649 int32_t extract(int32_t start,
1650 int32_t startLength,
1652 uint32_t targetLength,
1653 const char *codepage) const;
1656 * Convert the UnicodeString into a codepage string using an existing UConverter.
1657 * The output string is NUL-terminated if possible.
1659 * This function avoids the overhead of opening and closing a converter if
1660 * multiple strings are extracted.
1662 * @param dest destination string buffer, can be NULL if destCapacity==0
1663 * @param destCapacity the number of chars available at dest
1664 * @param cnv the converter object to be used (ucnv_resetFromUnicode() will be called),
1665 * or NULL for the default converter
1666 * @param errorCode normal ICU error code
1667 * @return the length of the output string, not counting the terminating NUL;
1668 * if the length is greater than destCapacity, then the string will not fit
1669 * and a buffer of the indicated length would need to be passed in
1672 int32_t extract(char *dest, int32_t destCapacity,
1674 UErrorCode &errorCode) const;
1679 * Create a temporary substring for the specified range.
1680 * Unlike the substring constructor and setTo() functions,
1681 * the object returned here will be a read-only alias (using getBuffer())
1682 * rather than copying the text.
1683 * As a result, this substring operation is much faster but requires
1684 * that the original string not be modified or deleted during the lifetime
1685 * of the returned substring object.
1686 * @param start offset of the first character visible in the substring
1687 * @param length length of the substring
1688 * @return a read-only alias UnicodeString object for the substring
1691 UnicodeString tempSubString(int32_t start=0, int32_t length=INT32_MAX) const;
1694 * Create a temporary substring for the specified range.
1695 * Same as tempSubString(start, length) except that the substring range
1696 * is specified as a (start, limit) pair (with an exclusive limit index)
1697 * rather than a (start, length) pair.
1698 * @param start offset of the first character visible in the substring
1699 * @param limit offset immediately following the last character visible in the substring
1700 * @return a read-only alias UnicodeString object for the substring
1703 inline UnicodeString tempSubStringBetween(int32_t start, int32_t limit=INT32_MAX) const;
1706 * Convert the UnicodeString to UTF-8 and write the result
1707 * to a ByteSink. This is called by toUTF8String().
1708 * Unpaired surrogates are replaced with U+FFFD.
1709 * Calls u_strToUTF8WithSub().
1711 * @param sink A ByteSink to which the UTF-8 version of the string is written.
1712 * sink.Flush() is called at the end.
1716 void toUTF8(ByteSink &sink) const;
1718 #if U_HAVE_STD_STRING
1721 * Convert the UnicodeString to UTF-8 and append the result
1722 * to a standard string.
1723 * Unpaired surrogates are replaced with U+FFFD.
1726 * @param result A standard string (or a compatible object)
1727 * to which the UTF-8 version of the string is appended.
1728 * @return The string object.
1732 template<typename StringClass>
1733 StringClass &toUTF8String(StringClass &result) const {
1734 StringByteSink<StringClass> sbs(&result);
1742 * Convert the UnicodeString to UTF-32.
1743 * Unpaired surrogates are replaced with U+FFFD.
1744 * Calls u_strToUTF32WithSub().
1746 * @param utf32 destination string buffer, can be NULL if capacity==0
1747 * @param capacity the number of UChar32s available at utf32
1748 * @param errorCode Standard ICU error code. Its input value must
1749 * pass the U_SUCCESS() test, or else the function returns
1750 * immediately. Check for U_FAILURE() on output or use with
1751 * function chaining. (See User Guide for details.)
1752 * @return The length of the UTF-32 string.
1756 int32_t toUTF32(UChar32 *utf32, int32_t capacity, UErrorCode &errorCode) const;
1758 /* Length operations */
1761 * Return the length of the UnicodeString object.
1762 * The length is the number of UChar code units are in the UnicodeString.
1763 * If you want the number of code points, please use countChar32().
1764 * @return the length of the UnicodeString object
1768 inline int32_t length(void) const;
1771 * Count Unicode code points in the length UChar code units of the string.
1772 * A code point may occupy either one or two UChar code units.
1773 * Counting code points involves reading all code units.
1775 * This functions is basically the inverse of moveIndex32().
1777 * @param start the index of the first code unit to check
1778 * @param length the number of UChar code units to check
1779 * @return the number of code points in the specified code units
1784 countChar32(int32_t start=0, int32_t length=INT32_MAX) const;
1787 * Check if the length UChar code units of the string
1788 * contain more Unicode code points than a certain number.
1789 * This is more efficient than counting all code points in this part of the string
1790 * and comparing that number with a threshold.
1791 * This function may not need to scan the string at all if the length
1792 * falls within a certain range, and
1793 * never needs to count more than 'number+1' code points.
1794 * Logically equivalent to (countChar32(start, length)>number).
1795 * A Unicode code point may occupy either one or two UChar code units.
1797 * @param start the index of the first code unit to check (0 for the entire string)
1798 * @param length the number of UChar code units to check
1799 * (use INT32_MAX for the entire string; remember that start/length
1800 * values are pinned)
1801 * @param number The number of code points in the (sub)string is compared against
1802 * the 'number' parameter.
1803 * @return Boolean value for whether the string contains more Unicode code points
1804 * than 'number'. Same as (u_countChar32(s, length)>number).
1806 * @see u_strHasMoreChar32Than
1810 hasMoreChar32Than(int32_t start, int32_t length, int32_t number) const;
1813 * Determine if this string is empty.
1814 * @return TRUE if this string contains 0 characters, FALSE otherwise.
1817 inline UBool isEmpty(void) const;
1820 * Return the capacity of the internal buffer of the UnicodeString object.
1821 * This is useful together with the getBuffer functions.
1822 * See there for details.
1824 * @return the number of UChars available in the internal buffer
1828 inline int32_t getCapacity(void) const;
1830 /* Other operations */
1833 * Generate a hash code for this object.
1834 * @return The hash code of this UnicodeString.
1837 inline int32_t hashCode(void) const;
1840 * Determine if this object contains a valid string.
1841 * A bogus string has no value. It is different from an empty string,
1842 * although in both cases isEmpty() returns TRUE and length() returns 0.
1843 * setToBogus() and isBogus() can be used to indicate that no string value is available.
1844 * For a bogus string, getBuffer() and getTerminatedBuffer() return NULL, and
1845 * length() returns 0.
1847 * @return TRUE if the string is bogus/invalid, FALSE otherwise
1851 inline UBool isBogus(void) const;
1854 //========================================
1856 //========================================
1858 /* Assignment operations */
1861 * Assignment operator. Replace the characters in this UnicodeString
1862 * with the characters from <TT>srcText</TT>.
1864 * Starting with ICU 2.4, the assignment operator and the copy constructor
1865 * allocate a new buffer and copy the buffer contents even for readonly aliases.
1866 * By contrast, the fastCopyFrom() function implements the old,
1867 * more efficient but less safe behavior
1868 * of making this string also a readonly alias to the same buffer.
1870 * If the source object has an "open" buffer from getBuffer(minCapacity),
1871 * then the copy is an empty string.
1873 * @param srcText The text containing the characters to replace
1874 * @return a reference to this
1878 UnicodeString &operator=(const UnicodeString &srcText);
1881 * Almost the same as the assignment operator.
1882 * Replace the characters in this UnicodeString
1883 * with the characters from <code>srcText</code>.
1885 * This function works the same as the assignment operator
1886 * for all strings except for ones that are readonly aliases.
1888 * Starting with ICU 2.4, the assignment operator and the copy constructor
1889 * allocate a new buffer and copy the buffer contents even for readonly aliases.
1890 * This function implements the old, more efficient but less safe behavior
1891 * of making this string also a readonly alias to the same buffer.
1893 * The fastCopyFrom function must be used only if it is known that the lifetime of
1894 * this UnicodeString does not exceed the lifetime of the aliased buffer
1895 * including its contents, for example for strings from resource bundles
1896 * or aliases to string constants.
1898 * If the source object has an "open" buffer from getBuffer(minCapacity),
1899 * then the copy is an empty string.
1901 * @param src The text containing the characters to replace.
1902 * @return a reference to this
1905 UnicodeString &fastCopyFrom(const UnicodeString &src);
1907 #if U_HAVE_RVALUE_REFERENCES
1909 * Move assignment operator, might leave src in bogus state.
1910 * This string will have the same contents and state that the source string had.
1911 * The behavior is undefined if *this and src are the same object.
1912 * @param src source string
1916 UnicodeString &operator=(UnicodeString &&src) U_NOEXCEPT {
1917 return moveFrom(src);
1920 // do not use #ifndef U_HIDE_DRAFT_API for moveFrom, needed by non-draft API
1922 * Move assignment, might leave src in bogus state.
1923 * This string will have the same contents and state that the source string had.
1924 * The behavior is undefined if *this and src are the same object.
1926 * Can be called explicitly, does not need C++11 support.
1927 * @param src source string
1931 UnicodeString &moveFrom(UnicodeString &src) U_NOEXCEPT;
1935 * @param other other string
1938 void swap(UnicodeString &other) U_NOEXCEPT;
1941 * Non-member UnicodeString swap function.
1942 * @param s1 will get s2's contents and state
1943 * @param s2 will get s1's contents and state
1946 friend U_COMMON_API inline void U_EXPORT2
1947 swap(UnicodeString &s1, UnicodeString &s2) U_NOEXCEPT {
1952 * Assignment operator. Replace the characters in this UnicodeString
1953 * with the code unit <TT>ch</TT>.
1954 * @param ch the code unit to replace
1955 * @return a reference to this
1958 inline UnicodeString& operator= (UChar ch);
1961 * Assignment operator. Replace the characters in this UnicodeString
1962 * with the code point <TT>ch</TT>.
1963 * @param ch the code point to replace
1964 * @return a reference to this
1967 inline UnicodeString& operator= (UChar32 ch);
1970 * Set the text in the UnicodeString object to the characters
1971 * in <TT>srcText</TT> in the range
1972 * [<TT>srcStart</TT>, <TT>srcText.length()</TT>).
1973 * <TT>srcText</TT> is not modified.
1974 * @param srcText the source for the new characters
1975 * @param srcStart the offset into <TT>srcText</TT> where new characters
1977 * @return a reference to this
1980 inline UnicodeString& setTo(const UnicodeString& srcText,
1984 * Set the text in the UnicodeString object to the characters
1985 * in <TT>srcText</TT> in the range
1986 * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
1987 * <TT>srcText</TT> is not modified.
1988 * @param srcText the source for the new characters
1989 * @param srcStart the offset into <TT>srcText</TT> where new characters
1991 * @param srcLength the number of characters in <TT>srcText</TT> in the
1993 * @return a reference to this
1996 inline UnicodeString& setTo(const UnicodeString& srcText,
2001 * Set the text in the UnicodeString object to the characters in
2003 * <TT>srcText</TT> is not modified.
2004 * @param srcText the source for the new characters
2005 * @return a reference to this
2008 inline UnicodeString& setTo(const UnicodeString& srcText);
2011 * Set the characters in the UnicodeString object to the characters
2012 * in <TT>srcChars</TT>. <TT>srcChars</TT> is not modified.
2013 * @param srcChars the source for the new characters
2014 * @param srcLength the number of Unicode characters in srcChars.
2015 * @return a reference to this
2018 inline UnicodeString& setTo(const UChar *srcChars,
2022 * Set the characters in the UnicodeString object to the code unit
2024 * @param srcChar the code unit which becomes the UnicodeString's character
2026 * @return a reference to this
2029 UnicodeString& setTo(UChar srcChar);
2032 * Set the characters in the UnicodeString object to the code point
2034 * @param srcChar the code point which becomes the UnicodeString's character
2036 * @return a reference to this
2039 UnicodeString& setTo(UChar32 srcChar);
2042 * Aliasing setTo() function, analogous to the readonly-aliasing UChar* constructor.
2043 * The text will be used for the UnicodeString object, but
2044 * it will not be released when the UnicodeString is destroyed.
2045 * This has copy-on-write semantics:
2046 * When the string is modified, then the buffer is first copied into
2047 * newly allocated memory.
2048 * The aliased buffer is never modified.
2050 * In an assignment to another UnicodeString, when using the copy constructor
2051 * or the assignment operator, the text will be copied.
2052 * When using fastCopyFrom(), the text will be aliased again,
2053 * so that both strings then alias the same readonly-text.
2055 * @param isTerminated specifies if <code>text</code> is <code>NUL</code>-terminated.
2056 * This must be true if <code>textLength==-1</code>.
2057 * @param text The characters to alias for the UnicodeString.
2058 * @param textLength The number of Unicode characters in <code>text</code> to alias.
2059 * If -1, then this constructor will determine the length
2060 * by calling <code>u_strlen()</code>.
2061 * @return a reference to this
2064 UnicodeString &setTo(UBool isTerminated,
2066 int32_t textLength);
2069 * Aliasing setTo() function, analogous to the writable-aliasing UChar* constructor.
2070 * The text will be used for the UnicodeString object, but
2071 * it will not be released when the UnicodeString is destroyed.
2072 * This has write-through semantics:
2073 * For as long as the capacity of the buffer is sufficient, write operations
2074 * will directly affect the buffer. When more capacity is necessary, then
2075 * a new buffer will be allocated and the contents copied as with regularly
2076 * constructed strings.
2077 * In an assignment to another UnicodeString, the buffer will be copied.
2078 * The extract(UChar *dst) function detects whether the dst pointer is the same
2079 * as the string buffer itself and will in this case not copy the contents.
2081 * @param buffer The characters to alias for the UnicodeString.
2082 * @param buffLength The number of Unicode characters in <code>buffer</code> to alias.
2083 * @param buffCapacity The size of <code>buffer</code> in UChars.
2084 * @return a reference to this
2087 UnicodeString &setTo(UChar *buffer,
2089 int32_t buffCapacity);
2092 * Make this UnicodeString object invalid.
2093 * The string will test TRUE with isBogus().
2095 * A bogus string has no value. It is different from an empty string.
2096 * It can be used to indicate that no string value is available.
2097 * getBuffer() and getTerminatedBuffer() return NULL, and
2098 * length() returns 0.
2100 * This utility function is used throughout the UnicodeString
2101 * implementation to indicate that a UnicodeString operation failed,
2102 * and may be used in other functions,
2103 * especially but not exclusively when such functions do not
2104 * take a UErrorCode for simplicity.
2106 * The following methods, and no others, will clear a string object's bogus flag:
2108 * - remove(0, INT32_MAX)
2110 * - operator=() (assignment operator)
2113 * The simplest ways to turn a bogus string into an empty one
2114 * is to use the remove() function.
2115 * Examples for other functions that are equivalent to "set to empty string":
2118 * s.remove(); // set to an empty string (remove all), or
2119 * s.remove(0, INT32_MAX); // set to an empty string (remove all), or
2120 * s.truncate(0); // set to an empty string (complete truncation), or
2121 * s=UnicodeString(); // assign an empty string, or
2122 * s.setTo((UChar32)-1); // set to a pseudo code point that is out of range, or
2123 * static const UChar nul=0;
2124 * s.setTo(&nul, 0); // set to an empty C Unicode string
2134 * Set the character at the specified offset to the specified character.
2135 * @param offset A valid offset into the text of the character to set
2136 * @param ch The new character
2137 * @return A reference to this
2140 UnicodeString& setCharAt(int32_t offset,
2144 /* Append operations */
2147 * Append operator. Append the code unit <TT>ch</TT> to the UnicodeString
2149 * @param ch the code unit to be appended
2150 * @return a reference to this
2153 inline UnicodeString& operator+= (UChar ch);
2156 * Append operator. Append the code point <TT>ch</TT> to the UnicodeString
2158 * @param ch the code point to be appended
2159 * @return a reference to this
2162 inline UnicodeString& operator+= (UChar32 ch);
2165 * Append operator. Append the characters in <TT>srcText</TT> to the
2166 * UnicodeString object. <TT>srcText</TT> is not modified.
2167 * @param srcText the source for the new characters
2168 * @return a reference to this
2171 inline UnicodeString& operator+= (const UnicodeString& srcText);
2174 * Append the characters
2175 * in <TT>srcText</TT> in the range
2176 * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>) to the
2177 * UnicodeString object at offset <TT>start</TT>. <TT>srcText</TT>
2179 * @param srcText the source for the new characters
2180 * @param srcStart the offset into <TT>srcText</TT> where new characters
2182 * @param srcLength the number of characters in <TT>srcText</TT> in
2184 * @return a reference to this
2187 inline UnicodeString& append(const UnicodeString& srcText,
2192 * Append the characters in <TT>srcText</TT> to the UnicodeString object.
2193 * <TT>srcText</TT> is not modified.
2194 * @param srcText the source for the new characters
2195 * @return a reference to this
2198 inline UnicodeString& append(const UnicodeString& srcText);
2201 * Append the characters in <TT>srcChars</TT> in the range
2202 * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>) to the UnicodeString
2204 * <TT>start</TT>. <TT>srcChars</TT> is not modified.
2205 * @param srcChars the source for the new characters
2206 * @param srcStart the offset into <TT>srcChars</TT> where new characters
2208 * @param srcLength the number of characters in <TT>srcChars</TT> in
2209 * the append string; can be -1 if <TT>srcChars</TT> is NUL-terminated
2210 * @return a reference to this
2213 inline UnicodeString& append(const UChar *srcChars,
2218 * Append the characters in <TT>srcChars</TT> to the UnicodeString object
2219 * at offset <TT>start</TT>. <TT>srcChars</TT> is not modified.
2220 * @param srcChars the source for the new characters
2221 * @param srcLength the number of Unicode characters in <TT>srcChars</TT>;
2222 * can be -1 if <TT>srcChars</TT> is NUL-terminated
2223 * @return a reference to this
2226 inline UnicodeString& append(const UChar *srcChars,
2230 * Append the code unit <TT>srcChar</TT> to the UnicodeString object.
2231 * @param srcChar the code unit to append
2232 * @return a reference to this
2235 inline UnicodeString& append(UChar srcChar);
2238 * Append the code point <TT>srcChar</TT> to the UnicodeString object.
2239 * @param srcChar the code point to append
2240 * @return a reference to this
2243 UnicodeString& append(UChar32 srcChar);
2246 /* Insert operations */
2249 * Insert the characters in <TT>srcText</TT> in the range
2250 * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>) into the UnicodeString
2251 * object at offset <TT>start</TT>. <TT>srcText</TT> is not modified.
2252 * @param start the offset where the insertion begins
2253 * @param srcText the source for the new characters
2254 * @param srcStart the offset into <TT>srcText</TT> where new characters
2256 * @param srcLength the number of characters in <TT>srcText</TT> in
2258 * @return a reference to this
2261 inline UnicodeString& insert(int32_t start,
2262 const UnicodeString& srcText,
2267 * Insert the characters in <TT>srcText</TT> into the UnicodeString object
2268 * at offset <TT>start</TT>. <TT>srcText</TT> is not modified.
2269 * @param start the offset where the insertion begins
2270 * @param srcText the source for the new characters
2271 * @return a reference to this
2274 inline UnicodeString& insert(int32_t start,
2275 const UnicodeString& srcText);
2278 * Insert the characters in <TT>srcChars</TT> in the range
2279 * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>) into the UnicodeString
2280 * object at offset <TT>start</TT>. <TT>srcChars</TT> is not modified.
2281 * @param start the offset at which the insertion begins
2282 * @param srcChars the source for the new characters
2283 * @param srcStart the offset into <TT>srcChars</TT> where new characters
2285 * @param srcLength the number of characters in <TT>srcChars</TT>
2286 * in the insert string
2287 * @return a reference to this
2290 inline UnicodeString& insert(int32_t start,
2291 const UChar *srcChars,
2296 * Insert the characters in <TT>srcChars</TT> into the UnicodeString object
2297 * at offset <TT>start</TT>. <TT>srcChars</TT> is not modified.
2298 * @param start the offset where the insertion begins
2299 * @param srcChars the source for the new characters
2300 * @param srcLength the number of Unicode characters in srcChars.
2301 * @return a reference to this
2304 inline UnicodeString& insert(int32_t start,
2305 const UChar *srcChars,
2309 * Insert the code unit <TT>srcChar</TT> into the UnicodeString object at
2310 * offset <TT>start</TT>.
2311 * @param start the offset at which the insertion occurs
2312 * @param srcChar the code unit to insert
2313 * @return a reference to this
2316 inline UnicodeString& insert(int32_t start,
2320 * Insert the code point <TT>srcChar</TT> into the UnicodeString object at
2321 * offset <TT>start</TT>.
2322 * @param start the offset at which the insertion occurs
2323 * @param srcChar the code point to insert
2324 * @return a reference to this
2327 inline UnicodeString& insert(int32_t start,
2331 /* Replace operations */
2334 * Replace the characters in the range
2335 * [<TT>start</TT>, <TT>start + length</TT>) with the characters in
2336 * <TT>srcText</TT> in the range
2337 * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
2338 * <TT>srcText</TT> is not modified.
2339 * @param start the offset at which the replace operation begins
2340 * @param length the number of characters to replace. The character at
2341 * <TT>start + length</TT> is not modified.
2342 * @param srcText the source for the new characters
2343 * @param srcStart the offset into <TT>srcText</TT> where new characters
2345 * @param srcLength the number of characters in <TT>srcText</TT> in
2346 * the replace string
2347 * @return a reference to this
2350 UnicodeString& replace(int32_t start,
2352 const UnicodeString& srcText,
2357 * Replace the characters in the range
2358 * [<TT>start</TT>, <TT>start + length</TT>)
2359 * with the characters in <TT>srcText</TT>. <TT>srcText</TT> is
2361 * @param start the offset at which the replace operation begins
2362 * @param length the number of characters to replace. The character at
2363 * <TT>start + length</TT> is not modified.
2364 * @param srcText the source for the new characters
2365 * @return a reference to this
2368 UnicodeString& replace(int32_t start,
2370 const UnicodeString& srcText);
2373 * Replace the characters in the range
2374 * [<TT>start</TT>, <TT>start + length</TT>) with the characters in
2375 * <TT>srcChars</TT> in the range
2376 * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>). <TT>srcChars</TT>
2378 * @param start the offset at which the replace operation begins
2379 * @param length the number of characters to replace. The character at
2380 * <TT>start + length</TT> is not modified.
2381 * @param srcChars the source for the new characters
2382 * @param srcStart the offset into <TT>srcChars</TT> where new characters
2384 * @param srcLength the number of characters in <TT>srcChars</TT>
2385 * in the replace string
2386 * @return a reference to this
2389 UnicodeString& replace(int32_t start,
2391 const UChar *srcChars,
2396 * Replace the characters in the range
2397 * [<TT>start</TT>, <TT>start + length</TT>) with the characters in
2398 * <TT>srcChars</TT>. <TT>srcChars</TT> is not modified.
2399 * @param start the offset at which the replace operation begins
2400 * @param length number of characters to replace. The character at
2401 * <TT>start + length</TT> is not modified.
2402 * @param srcChars the source for the new characters
2403 * @param srcLength the number of Unicode characters in srcChars
2404 * @return a reference to this
2407 inline UnicodeString& replace(int32_t start,
2409 const UChar *srcChars,
2413 * Replace the characters in the range
2414 * [<TT>start</TT>, <TT>start + length</TT>) with the code unit
2416 * @param start the offset at which the replace operation begins
2417 * @param length the number of characters to replace. The character at
2418 * <TT>start + length</TT> is not modified.
2419 * @param srcChar the new code unit
2420 * @return a reference to this
2423 inline UnicodeString& replace(int32_t start,
2428 * Replace the characters in the range
2429 * [<TT>start</TT>, <TT>start + length</TT>) with the code point
2431 * @param start the offset at which the replace operation begins
2432 * @param length the number of characters to replace. The character at
2433 * <TT>start + length</TT> is not modified.
2434 * @param srcChar the new code point
2435 * @return a reference to this
2438 UnicodeString& replace(int32_t start, int32_t length, UChar32 srcChar);
2441 * Replace the characters in the range [<TT>start</TT>, <TT>limit</TT>)
2442 * with the characters in <TT>srcText</TT>. <TT>srcText</TT> is not modified.
2443 * @param start the offset at which the replace operation begins
2444 * @param limit the offset immediately following the replace range
2445 * @param srcText the source for the new characters
2446 * @return a reference to this
2449 inline UnicodeString& replaceBetween(int32_t start,
2451 const UnicodeString& srcText);
2454 * Replace the characters in the range [<TT>start</TT>, <TT>limit</TT>)
2455 * with the characters in <TT>srcText</TT> in the range
2456 * [<TT>srcStart</TT>, <TT>srcLimit</TT>). <TT>srcText</TT> is not modified.
2457 * @param start the offset at which the replace operation begins
2458 * @param limit the offset immediately following the replace range
2459 * @param srcText the source for the new characters
2460 * @param srcStart the offset into <TT>srcChars</TT> where new characters
2462 * @param srcLimit the offset immediately following the range to copy
2463 * in <TT>srcText</TT>
2464 * @return a reference to this
2467 inline UnicodeString& replaceBetween(int32_t start,
2469 const UnicodeString& srcText,
2474 * Replace a substring of this object with the given text.
2475 * @param start the beginning index, inclusive; <code>0 <= start
2477 * @param limit the ending index, exclusive; <code>start <= limit
2478 * <= length()</code>.
2479 * @param text the text to replace characters <code>start</code>
2480 * to <code>limit - 1</code>
2483 virtual void handleReplaceBetween(int32_t start,
2485 const UnicodeString& text);
2489 * @return TRUE if it has MetaData
2492 virtual UBool hasMetaData() const;
2495 * Copy a substring of this object, retaining attribute (out-of-band)
2496 * information. This method is used to duplicate or reorder substrings.
2497 * The destination index must not overlap the source range.
2499 * @param start the beginning index, inclusive; <code>0 <= start <=
2501 * @param limit the ending index, exclusive; <code>start <= limit <=
2503 * @param dest the destination index. The characters from
2504 * <code>start..limit-1</code> will be copied to <code>dest</code>.
2505 * Implementations of this method may assume that <code>dest <= start ||
2506 * dest >= limit</code>.
2509 virtual void copy(int32_t start, int32_t limit, int32_t dest);
2511 /* Search and replace operations */
2514 * Replace all occurrences of characters in oldText with the characters
2516 * @param oldText the text containing the search text
2517 * @param newText the text containing the replacement text
2518 * @return a reference to this
2521 inline UnicodeString& findAndReplace(const UnicodeString& oldText,
2522 const UnicodeString& newText);
2525 * Replace all occurrences of characters in oldText with characters
2527 * in the range [<TT>start</TT>, <TT>start + length</TT>).
2528 * @param start the start of the range in which replace will performed
2529 * @param length the length of the range in which replace will be performed
2530 * @param oldText the text containing the search text
2531 * @param newText the text containing the replacement text
2532 * @return a reference to this
2535 inline UnicodeString& findAndReplace(int32_t start,
2537 const UnicodeString& oldText,
2538 const UnicodeString& newText);
2541 * Replace all occurrences of characters in oldText in the range
2542 * [<TT>oldStart</TT>, <TT>oldStart + oldLength</TT>) with the characters
2543 * in newText in the range
2544 * [<TT>newStart</TT>, <TT>newStart + newLength</TT>)
2545 * in the range [<TT>start</TT>, <TT>start + length</TT>).
2546 * @param start the start of the range in which replace will performed
2547 * @param length the length of the range in which replace will be performed
2548 * @param oldText the text containing the search text
2549 * @param oldStart the start of the search range in <TT>oldText</TT>
2550 * @param oldLength the length of the search range in <TT>oldText</TT>
2551 * @param newText the text containing the replacement text
2552 * @param newStart the start of the replacement range in <TT>newText</TT>
2553 * @param newLength the length of the replacement range in <TT>newText</TT>
2554 * @return a reference to this
2557 UnicodeString& findAndReplace(int32_t start,
2559 const UnicodeString& oldText,
2562 const UnicodeString& newText,
2567 /* Remove operations */
2570 * Remove all characters from the UnicodeString object.
2571 * @return a reference to this
2574 inline UnicodeString& remove(void);
2577 * Remove the characters in the range
2578 * [<TT>start</TT>, <TT>start + length</TT>) from the UnicodeString object.
2579 * @param start the offset of the first character to remove
2580 * @param length the number of characters to remove
2581 * @return a reference to this
2584 inline UnicodeString& remove(int32_t start,
2585 int32_t length = (int32_t)INT32_MAX);
2588 * Remove the characters in the range
2589 * [<TT>start</TT>, <TT>limit</TT>) from the UnicodeString object.
2590 * @param start the offset of the first character to remove
2591 * @param limit the offset immediately following the range to remove
2592 * @return a reference to this
2595 inline UnicodeString& removeBetween(int32_t start,
2596 int32_t limit = (int32_t)INT32_MAX);
2599 * Retain only the characters in the range
2600 * [<code>start</code>, <code>limit</code>) from the UnicodeString object.
2601 * Removes characters before <code>start</code> and at and after <code>limit</code>.
2602 * @param start the offset of the first character to retain
2603 * @param limit the offset immediately following the range to retain
2604 * @return a reference to this
2607 inline UnicodeString &retainBetween(int32_t start, int32_t limit = INT32_MAX);
2609 /* Length operations */
2612 * Pad the start of this UnicodeString with the character <TT>padChar</TT>.
2613 * If the length of this UnicodeString is less than targetLength,
2614 * length() - targetLength copies of padChar will be added to the
2615 * beginning of this UnicodeString.
2616 * @param targetLength the desired length of the string
2617 * @param padChar the character to use for padding. Defaults to
2619 * @return TRUE if the text was padded, FALSE otherwise.
2622 UBool padLeading(int32_t targetLength,
2623 UChar padChar = 0x0020);
2626 * Pad the end of this UnicodeString with the character <TT>padChar</TT>.
2627 * If the length of this UnicodeString is less than targetLength,
2628 * length() - targetLength copies of padChar will be added to the
2629 * end of this UnicodeString.
2630 * @param targetLength the desired length of the string
2631 * @param padChar the character to use for padding. Defaults to
2633 * @return TRUE if the text was padded, FALSE otherwise.
2636 UBool padTrailing(int32_t targetLength,
2637 UChar padChar = 0x0020);
2640 * Truncate this UnicodeString to the <TT>targetLength</TT>.
2641 * @param targetLength the desired length of this UnicodeString.
2642 * @return TRUE if the text was truncated, FALSE otherwise
2645 inline UBool truncate(int32_t targetLength);
2648 * Trims leading and trailing whitespace from this UnicodeString.
2649 * @return a reference to this
2652 UnicodeString& trim(void);
2655 /* Miscellaneous operations */
2658 * Reverse this UnicodeString in place.
2659 * @return a reference to this
2662 inline UnicodeString& reverse(void);
2665 * Reverse the range [<TT>start</TT>, <TT>start + length</TT>) in
2666 * this UnicodeString.
2667 * @param start the start of the range to reverse
2668 * @param length the number of characters to to reverse
2669 * @return a reference to this
2672 inline UnicodeString& reverse(int32_t start,
2676 * Convert the characters in this to UPPER CASE following the conventions of
2677 * the default locale.
2678 * @return A reference to this.
2681 UnicodeString& toUpper(void);
2684 * Convert the characters in this to UPPER CASE following the conventions of
2685 * a specific locale.
2686 * @param locale The locale containing the conventions to use.
2687 * @return A reference to this.
2690 UnicodeString& toUpper(const Locale& locale);
2693 * Convert the characters in this to lower case following the conventions of
2694 * the default locale.
2695 * @return A reference to this.
2698 UnicodeString& toLower(void);
2701 * Convert the characters in this to lower case following the conventions of
2702 * a specific locale.
2703 * @param locale The locale containing the conventions to use.
2704 * @return A reference to this.
2707 UnicodeString& toLower(const Locale& locale);
2709 #if !UCONFIG_NO_BREAK_ITERATION
2712 * Titlecase this string, convenience function using the default locale.
2714 * Casing is locale-dependent and context-sensitive.
2715 * Titlecasing uses a break iterator to find the first characters of words
2716 * that are to be titlecased. It titlecases those characters and lowercases
2719 * The titlecase break iterator can be provided to customize for arbitrary
2720 * styles, using rules and dictionaries beyond the standard iterators.
2721 * It may be more efficient to always provide an iterator to avoid
2722 * opening and closing one for each string.
2723 * The standard titlecase iterator for the root locale implements the
2724 * algorithm of Unicode TR 21.
2726 * This function uses only the setText(), first() and next() methods of the
2727 * provided break iterator.
2729 * @param titleIter A break iterator to find the first characters of words
2730 * that are to be titlecased.
2731 * If none is provided (0), then a standard titlecase
2732 * break iterator is opened.
2733 * Otherwise the provided iterator is set to the string's text.
2734 * @return A reference to this.
2737 UnicodeString &toTitle(BreakIterator *titleIter);
2740 * Titlecase this string.
2742 * Casing is locale-dependent and context-sensitive.
2743 * Titlecasing uses a break iterator to find the first characters of words
2744 * that are to be titlecased. It titlecases those characters and lowercases
2747 * The titlecase break iterator can be provided to customize for arbitrary
2748 * styles, using rules and dictionaries beyond the standard iterators.
2749 * It may be more efficient to always provide an iterator to avoid
2750 * opening and closing one for each string.
2751 * The standard titlecase iterator for the root locale implements the
2752 * algorithm of Unicode TR 21.
2754 * This function uses only the setText(), first() and next() methods of the
2755 * provided break iterator.
2757 * @param titleIter A break iterator to find the first characters of words
2758 * that are to be titlecased.
2759 * If none is provided (0), then a standard titlecase
2760 * break iterator is opened.
2761 * Otherwise the provided iterator is set to the string's text.
2762 * @param locale The locale to consider.
2763 * @return A reference to this.
2766 UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale);
2769 * Titlecase this string, with options.
2771 * Casing is locale-dependent and context-sensitive.
2772 * Titlecasing uses a break iterator to find the first characters of words
2773 * that are to be titlecased. It titlecases those characters and lowercases
2774 * all others. (This can be modified with options.)
2776 * The titlecase break iterator can be provided to customize for arbitrary
2777 * styles, using rules and dictionaries beyond the standard iterators.
2778 * It may be more efficient to always provide an iterator to avoid
2779 * opening and closing one for each string.
2780 * The standard titlecase iterator for the root locale implements the
2781 * algorithm of Unicode TR 21.
2783 * This function uses only the setText(), first() and next() methods of the
2784 * provided break iterator.
2786 * @param titleIter A break iterator to find the first characters of words
2787 * that are to be titlecased.
2788 * If none is provided (0), then a standard titlecase
2789 * break iterator is opened.
2790 * Otherwise the provided iterator is set to the string's text.
2791 * @param locale The locale to consider.
2792 * @param options Options bit set, see ucasemap_open().
2793 * @return A reference to this.
2794 * @see U_TITLECASE_NO_LOWERCASE
2795 * @see U_TITLECASE_NO_BREAK_ADJUSTMENT
2796 * @see ucasemap_open
2799 UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale, uint32_t options);
2804 * Case-folds the characters in this string.
2806 * Case-folding is locale-independent and not context-sensitive,
2807 * but there is an option for whether to include or exclude mappings for dotted I
2808 * and dotless i that are marked with 'T' in CaseFolding.txt.
2810 * The result may be longer or shorter than the original.
2812 * @param options Either U_FOLD_CASE_DEFAULT or U_FOLD_CASE_EXCLUDE_SPECIAL_I
2813 * @return A reference to this.
2816 UnicodeString &foldCase(uint32_t options=0 /*U_FOLD_CASE_DEFAULT*/);
2818 //========================================
2819 // Access to the internal buffer
2820 //========================================
2823 * Get a read/write pointer to the internal buffer.
2824 * The buffer is guaranteed to be large enough for at least minCapacity UChars,
2825 * writable, and is still owned by the UnicodeString object.
2826 * Calls to getBuffer(minCapacity) must not be nested, and
2827 * must be matched with calls to releaseBuffer(newLength).
2828 * If the string buffer was read-only or shared,
2829 * then it will be reallocated and copied.
2831 * An attempted nested call will return 0, and will not further modify the
2832 * state of the UnicodeString object.
2833 * It also returns 0 if the string is bogus.
2835 * The actual capacity of the string buffer may be larger than minCapacity.
2836 * getCapacity() returns the actual capacity.
2837 * For many operations, the full capacity should be used to avoid reallocations.
2839 * While the buffer is "open" between getBuffer(minCapacity)
2840 * and releaseBuffer(newLength), the following applies:
2841 * - The string length is set to 0.
2842 * - Any read API call on the UnicodeString object will behave like on a 0-length string.
2843 * - Any write API call on the UnicodeString object is disallowed and will have no effect.
2844 * - You can read from and write to the returned buffer.
2845 * - The previous string contents will still be in the buffer;
2846 * if you want to use it, then you need to call length() before getBuffer(minCapacity).
2847 * If the length() was greater than minCapacity, then any contents after minCapacity
2849 * The buffer contents is not NUL-terminated by getBuffer().
2850 * If length()<getCapacity() then you can terminate it by writing a NUL
2851 * at index length().
2852 * - You must call releaseBuffer(newLength) before and in order to
2853 * return to normal UnicodeString operation.
2855 * @param minCapacity the minimum number of UChars that are to be available
2856 * in the buffer, starting at the returned pointer;
2857 * default to the current string capacity if minCapacity==-1
2858 * @return a writable pointer to the internal string buffer,
2859 * or 0 if an error occurs (nested calls, out of memory)
2861 * @see releaseBuffer
2862 * @see getTerminatedBuffer()
2865 UChar *getBuffer(int32_t minCapacity);
2868 * Release a read/write buffer on a UnicodeString object with an
2869 * "open" getBuffer(minCapacity).
2870 * This function must be called in a matched pair with getBuffer(minCapacity).
2871 * releaseBuffer(newLength) must be called if and only if a getBuffer(minCapacity) is "open".
2873 * It will set the string length to newLength, at most to the current capacity.
2874 * If newLength==-1 then it will set the length according to the
2875 * first NUL in the buffer, or to the capacity if there is no NUL.
2877 * After calling releaseBuffer(newLength) the UnicodeString is back to normal operation.
2879 * @param newLength the new length of the UnicodeString object;
2880 * defaults to the current capacity if newLength is greater than that;
2881 * if newLength==-1, it defaults to u_strlen(buffer) but not more than
2882 * the current capacity of the string
2884 * @see getBuffer(int32_t minCapacity)
2887 void releaseBuffer(int32_t newLength=-1);
2890 * Get a read-only pointer to the internal buffer.
2891 * This can be called at any time on a valid UnicodeString.
2893 * It returns 0 if the string is bogus, or
2894 * during an "open" getBuffer(minCapacity).
2896 * It can be called as many times as desired.
2897 * The pointer that it returns will remain valid until the UnicodeString object is modified,
2898 * at which time the pointer is semantically invalidated and must not be used any more.
2900 * The capacity of the buffer can be determined with getCapacity().
2901 * The part after length() may or may not be initialized and valid,
2902 * depending on the history of the UnicodeString object.
2904 * The buffer contents is (probably) not NUL-terminated.
2905 * You can check if it is with
2906 * <code>(s.length()<s.getCapacity() && buffer[s.length()]==0)</code>.
2907 * (See getTerminatedBuffer().)
2909 * The buffer may reside in read-only memory. Its contents must not
2912 * @return a read-only pointer to the internal string buffer,
2913 * or 0 if the string is empty or bogus
2915 * @see getBuffer(int32_t minCapacity)
2916 * @see getTerminatedBuffer()
2919 inline const UChar *getBuffer() const;
2922 * Get a read-only pointer to the internal buffer,
2923 * making sure that it is NUL-terminated.
2924 * This can be called at any time on a valid UnicodeString.
2926 * It returns 0 if the string is bogus, or
2927 * during an "open" getBuffer(minCapacity), or if the buffer cannot
2928 * be NUL-terminated (because memory allocation failed).
2930 * It can be called as many times as desired.
2931 * The pointer that it returns will remain valid until the UnicodeString object is modified,
2932 * at which time the pointer is semantically invalidated and must not be used any more.
2934 * The capacity of the buffer can be determined with getCapacity().
2935 * The part after length()+1 may or may not be initialized and valid,
2936 * depending on the history of the UnicodeString object.
2938 * The buffer contents is guaranteed to be NUL-terminated.
2939 * getTerminatedBuffer() may reallocate the buffer if a terminating NUL
2941 * For this reason, this function is not const, unlike getBuffer().
2942 * Note that a UnicodeString may also contain NUL characters as part of its contents.
2944 * The buffer may reside in read-only memory. Its contents must not
2947 * @return a read-only pointer to the internal string buffer,
2948 * or 0 if the string is empty or bogus
2950 * @see getBuffer(int32_t minCapacity)
2954 const UChar *getTerminatedBuffer();
2956 //========================================
2958 //========================================
2960 /** Construct an empty UnicodeString.
2963 inline UnicodeString();
2966 * Construct a UnicodeString with capacity to hold <TT>capacity</TT> UChars
2967 * @param capacity the number of UChars this UnicodeString should hold
2968 * before a resize is necessary; if count is greater than 0 and count
2969 * code points c take up more space than capacity, then capacity is adjusted
2971 * @param c is used to initially fill the string
2972 * @param count specifies how many code points c are to be written in the
2976 UnicodeString(int32_t capacity, UChar32 c, int32_t count);
2979 * Single UChar (code unit) constructor.
2981 * It is recommended to mark this constructor "explicit" by
2982 * <code>-DUNISTR_FROM_CHAR_EXPLICIT=explicit</code>
2983 * on the compiler command line or similar.
2984 * @param ch the character to place in the UnicodeString
2987 UNISTR_FROM_CHAR_EXPLICIT UnicodeString(UChar ch);
2990 * Single UChar32 (code point) constructor.
2992 * It is recommended to mark this constructor "explicit" by
2993 * <code>-DUNISTR_FROM_CHAR_EXPLICIT=explicit</code>
2994 * on the compiler command line or similar.
2995 * @param ch the character to place in the UnicodeString
2998 UNISTR_FROM_CHAR_EXPLICIT UnicodeString(UChar32 ch);
3001 * UChar* constructor.
3003 * It is recommended to mark this constructor "explicit" by
3004 * <code>-DUNISTR_FROM_STRING_EXPLICIT=explicit</code>
3005 * on the compiler command line or similar.
3006 * @param text The characters to place in the UnicodeString. <TT>text</TT>
3007 * must be NULL (U+0000) terminated.
3010 UNISTR_FROM_STRING_EXPLICIT UnicodeString(const UChar *text);
3013 * UChar* constructor.
3014 * @param text The characters to place in the UnicodeString.
3015 * @param textLength The number of Unicode characters in <TT>text</TT>
3019 UnicodeString(const UChar *text,
3020 int32_t textLength);
3023 * Readonly-aliasing UChar* constructor.
3024 * The text will be used for the UnicodeString object, but
3025 * it will not be released when the UnicodeString is destroyed.
3026 * This has copy-on-write semantics:
3027 * When the string is modified, then the buffer is first copied into
3028 * newly allocated memory.
3029 * The aliased buffer is never modified.
3031 * In an assignment to another UnicodeString, when using the copy constructor
3032 * or the assignment operator, the text will be copied.
3033 * When using fastCopyFrom(), the text will be aliased again,
3034 * so that both strings then alias the same readonly-text.
3036 * @param isTerminated specifies if <code>text</code> is <code>NUL</code>-terminated.
3037 * This must be true if <code>textLength==-1</code>.
3038 * @param text The characters to alias for the UnicodeString.
3039 * @param textLength The number of Unicode characters in <code>text</code> to alias.
3040 * If -1, then this constructor will determine the length
3041 * by calling <code>u_strlen()</code>.
3044 UnicodeString(UBool isTerminated,
3046 int32_t textLength);
3049 * Writable-aliasing UChar* constructor.
3050 * The text will be used for the UnicodeString object, but
3051 * it will not be released when the UnicodeString is destroyed.
3052 * This has write-through semantics:
3053 * For as long as the capacity of the buffer is sufficient, write operations
3054 * will directly affect the buffer. When more capacity is necessary, then
3055 * a new buffer will be allocated and the contents copied as with regularly
3056 * constructed strings.
3057 * In an assignment to another UnicodeString, the buffer will be copied.
3058 * The extract(UChar *dst) function detects whether the dst pointer is the same
3059 * as the string buffer itself and will in this case not copy the contents.
3061 * @param buffer The characters to alias for the UnicodeString.
3062 * @param buffLength The number of Unicode characters in <code>buffer</code> to alias.
3063 * @param buffCapacity The size of <code>buffer</code> in UChars.
3066 UnicodeString(UChar *buffer, int32_t buffLength, int32_t buffCapacity);
3068 #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
3071 * char* constructor.
3072 * Uses the default converter (and thus depends on the ICU conversion code)
3073 * unless U_CHARSET_IS_UTF8 is set to 1.
3075 * For ASCII (really "invariant character") strings it is more efficient to use
3076 * the constructor that takes a US_INV (for its enum EInvariant).
3077 * For ASCII (invariant-character) string literals, see UNICODE_STRING and
3078 * UNICODE_STRING_SIMPLE.
3080 * It is recommended to mark this constructor "explicit" by
3081 * <code>-DUNISTR_FROM_STRING_EXPLICIT=explicit</code>
3082 * on the compiler command line or similar.
3083 * @param codepageData an array of bytes, null-terminated,
3084 * in the platform's default codepage.
3086 * @see UNICODE_STRING
3087 * @see UNICODE_STRING_SIMPLE
3089 UNISTR_FROM_STRING_EXPLICIT UnicodeString(const char *codepageData);
3092 * char* constructor.
3093 * Uses the default converter (and thus depends on the ICU conversion code)
3094 * unless U_CHARSET_IS_UTF8 is set to 1.
3095 * @param codepageData an array of bytes in the platform's default codepage.
3096 * @param dataLength The number of bytes in <TT>codepageData</TT>.
3099 UnicodeString(const char *codepageData, int32_t dataLength);
3103 #if !UCONFIG_NO_CONVERSION
3106 * char* constructor.
3107 * @param codepageData an array of bytes, null-terminated
3108 * @param codepage the encoding of <TT>codepageData</TT>. The special
3109 * value 0 for <TT>codepage</TT> indicates that the text is in the
3110 * platform's default codepage.
3112 * If <code>codepage</code> is an empty string (<code>""</code>),
3113 * then a simple conversion is performed on the codepage-invariant
3114 * subset ("invariant characters") of the platform encoding. See utypes.h.
3115 * Recommendation: For invariant-character strings use the constructor
3116 * UnicodeString(const char *src, int32_t length, enum EInvariant inv)
3117 * because it avoids object code dependencies of UnicodeString on
3118 * the conversion code.
3122 UnicodeString(const char *codepageData, const char *codepage);
3125 * char* constructor.
3126 * @param codepageData an array of bytes.
3127 * @param dataLength The number of bytes in <TT>codepageData</TT>.
3128 * @param codepage the encoding of <TT>codepageData</TT>. The special
3129 * value 0 for <TT>codepage</TT> indicates that the text is in the
3130 * platform's default codepage.
3131 * If <code>codepage</code> is an empty string (<code>""</code>),
3132 * then a simple conversion is performed on the codepage-invariant
3133 * subset ("invariant characters") of the platform encoding. See utypes.h.
3134 * Recommendation: For invariant-character strings use the constructor
3135 * UnicodeString(const char *src, int32_t length, enum EInvariant inv)
3136 * because it avoids object code dependencies of UnicodeString on
3137 * the conversion code.
3141 UnicodeString(const char *codepageData, int32_t dataLength, const char *codepage);
3144 * char * / UConverter constructor.
3145 * This constructor uses an existing UConverter object to
3146 * convert the codepage string to Unicode and construct a UnicodeString
3149 * The converter is reset at first.
3150 * If the error code indicates a failure before this constructor is called,
3151 * or if an error occurs during conversion or construction,
3152 * then the string will be bogus.
3154 * This function avoids the overhead of opening and closing a converter if
3155 * multiple strings are constructed.
3157 * @param src input codepage string
3158 * @param srcLength length of the input string, can be -1 for NUL-terminated strings
3159 * @param cnv converter object (ucnv_resetToUnicode() will be called),
3160 * can be NULL for the default converter
3161 * @param errorCode normal ICU error code
3165 const char *src, int32_t srcLength,
3167 UErrorCode &errorCode);
3172 * Constructs a Unicode string from an invariant-character char * string.
3173 * About invariant characters see utypes.h.
3174 * This constructor has no runtime dependency on conversion code and is
3175 * therefore recommended over ones taking a charset name string
3176 * (where the empty string "" indicates invariant-character conversion).
3178 * Use the macro US_INV as the third, signature-distinguishing parameter.
3182 * void fn(const char *s) {
3183 * UnicodeString ustr(s, -1, US_INV);
3188 * @param src String using only invariant characters.
3189 * @param length Length of src, or -1 if NUL-terminated.
3190 * @param inv Signature-distinguishing paramater, use US_INV.
3195 UnicodeString(const char *src, int32_t length, enum EInvariant inv);
3201 * Starting with ICU 2.4, the assignment operator and the copy constructor
3202 * allocate a new buffer and copy the buffer contents even for readonly aliases.
3203 * By contrast, the fastCopyFrom() function implements the old,
3204 * more efficient but less safe behavior
3205 * of making this string also a readonly alias to the same buffer.
3207 * If the source object has an "open" buffer from getBuffer(minCapacity),
3208 * then the copy is an empty string.
3210 * @param that The UnicodeString object to copy.
3214 UnicodeString(const UnicodeString& that);
3216 #if U_HAVE_RVALUE_REFERENCES
3218 * Move constructor, might leave src in bogus state.
3219 * This string will have the same contents and state that the source string had.
3220 * @param src source string
3223 UnicodeString(UnicodeString &&src) U_NOEXCEPT;
3227 * 'Substring' constructor from tail of source string.
3228 * @param src The UnicodeString object to copy.
3229 * @param srcStart The offset into <tt>src</tt> at which to start copying.
3232 UnicodeString(const UnicodeString& src, int32_t srcStart);
3235 * 'Substring' constructor from subrange of source string.
3236 * @param src The UnicodeString object to copy.
3237 * @param srcStart The offset into <tt>src</tt> at which to start copying.
3238 * @param srcLength The number of characters from <tt>src</tt> to copy.
3241 UnicodeString(const UnicodeString& src, int32_t srcStart, int32_t srcLength);
3244 * Clone this object, an instance of a subclass of Replaceable.
3245 * Clones can be used concurrently in multiple threads.
3246 * If a subclass does not implement clone(), or if an error occurs,
3247 * then NULL is returned.
3248 * The clone functions in all subclasses return a pointer to a Replaceable
3249 * because some compilers do not support covariant (same-as-this)
3250 * return types; cast to the appropriate subclass if necessary.
3251 * The caller must delete the clone.
3253 * @return a clone of this object
3255 * @see Replaceable::clone
3256 * @see getDynamicClassID
3259 virtual Replaceable *clone() const;
3264 virtual ~UnicodeString();
3267 * Create a UnicodeString from a UTF-8 string.
3268 * Illegal input is replaced with U+FFFD. Otherwise, errors result in a bogus string.
3269 * Calls u_strFromUTF8WithSub().
3271 * @param utf8 UTF-8 input string.
3272 * Note that a StringPiece can be implicitly constructed
3273 * from a std::string or a NUL-terminated const char * string.
3274 * @return A UnicodeString with equivalent UTF-16 contents.
3279 static UnicodeString fromUTF8(StringPiece utf8);
3282 * Create a UnicodeString from a UTF-32 string.
3283 * Illegal input is replaced with U+FFFD. Otherwise, errors result in a bogus string.
3284 * Calls u_strFromUTF32WithSub().
3286 * @param utf32 UTF-32 input string. Must not be NULL.
3287 * @param length Length of the input string, or -1 if NUL-terminated.
3288 * @return A UnicodeString with equivalent UTF-16 contents.
3292 static UnicodeString fromUTF32(const UChar32 *utf32, int32_t length);
3294 /* Miscellaneous operations */
3297 * Unescape a string of characters and return a string containing
3298 * the result. The following escape sequences are recognized:
3300 * \\uhhhh 4 hex digits; h in [0-9A-Fa-f]
3301 * \\Uhhhhhhhh 8 hex digits
3302 * \\xhh 1-2 hex digits
3303 * \\ooo 1-3 octal digits; o in [0-7]
3304 * \\cX control-X; X is masked with 0x1F
3306 * as well as the standard ANSI C escapes:
3308 * \\a => U+0007, \\b => U+0008, \\t => U+0009, \\n => U+000A,
3309 * \\v => U+000B, \\f => U+000C, \\r => U+000D, \\e => U+001B,
3310 * \\" => U+0022, \\' => U+0027, \\? => U+003F, \\\\ => U+005C
3312 * Anything else following a backslash is generically escaped. For
3313 * example, "[a\\-z]" returns "[a-z]".
3315 * If an escape sequence is ill-formed, this method returns an empty
3316 * string. An example of an ill-formed sequence is "\\u" followed by
3317 * fewer than 4 hex digits.
3319 * This function is similar to u_unescape() but not identical to it.
3320 * The latter takes a source char*, so it does escape recognition
3321 * and also invariant conversion.
3323 * @return a string with backslash escapes interpreted, or an
3324 * empty string on error.
3325 * @see UnicodeString#unescapeAt()
3327 * @see u_unescapeAt()
3330 UnicodeString unescape() const;
3333 * Unescape a single escape sequence and return the represented
3334 * character. See unescape() for a listing of the recognized escape
3335 * sequences. The character at offset-1 is assumed (without
3336 * checking) to be a backslash. If the escape sequence is
3337 * ill-formed, or the offset is out of range, U_SENTINEL=-1 is
3340 * @param offset an input output parameter. On input, it is the
3341 * offset into this string where the escape sequence is located,
3342 * after the initial backslash. On output, it is advanced after the
3343 * last character parsed. On error, it is not advanced at all.
3344 * @return the character represented by the escape sequence at
3345 * offset, or U_SENTINEL=-1 on error.
3346 * @see UnicodeString#unescape()
3348 * @see u_unescapeAt()
3351 UChar32 unescapeAt(int32_t &offset) const;
3354 * ICU "poor man's RTTI", returns a UClassID for this class.
3358 static UClassID U_EXPORT2 getStaticClassID();
3361 * ICU "poor man's RTTI", returns a UClassID for the actual class.
3365 virtual UClassID getDynamicClassID() const;
3367 //========================================
3368 // Implementation methods
3369 //========================================
3373 * Implement Replaceable::getLength() (see jitterbug 1027).
3376 virtual int32_t getLength() const;
3379 * The change in Replaceable to use virtual getCharAt() allows
3380 * UnicodeString::charAt() to be inline again (see jitterbug 709).
3383 virtual UChar getCharAt(int32_t offset) const;
3386 * The change in Replaceable to use virtual getChar32At() allows
3387 * UnicodeString::char32At() to be inline again (see jitterbug 709).
3390 virtual UChar32 getChar32At(int32_t offset) const;
3393 // For char* constructors. Could be made public.
3394 UnicodeString &setToUTF8(StringPiece utf8);
3395 // For extract(char*).
3396 // We could make a toUTF8(target, capacity, errorCode) public but not
3397 // this version: New API will be cleaner if we make callers create substrings
3398 // rather than having start+length on every method,
3399 // and it should take a UErrorCode&.
3401 toUTF8(int32_t start, int32_t len,
3402 char *target, int32_t capacity) const;
3405 * Internal string contents comparison, called by operator==.
3406 * Requires: this & text not bogus and have same lengths.
3408 UBool doEquals(const UnicodeString &text, int32_t len) const;
3411 doCompare(int32_t start,
3413 const UnicodeString& srcText,
3415 int32_t srcLength) const;
3417 int8_t doCompare(int32_t start,
3419 const UChar *srcChars,
3421 int32_t srcLength) const;
3424 doCompareCodePointOrder(int32_t start,
3426 const UnicodeString& srcText,
3428 int32_t srcLength) const;
3430 int8_t doCompareCodePointOrder(int32_t start,
3432 const UChar *srcChars,
3434 int32_t srcLength) const;
3437 doCaseCompare(int32_t start,
3439 const UnicodeString &srcText,
3442 uint32_t options) const;
3445 doCaseCompare(int32_t start,
3447 const UChar *srcChars,
3450 uint32_t options) const;
3452 int32_t doIndexOf(UChar c,
3454 int32_t length) const;
3456 int32_t doIndexOf(UChar32 c,
3458 int32_t length) const;
3460 int32_t doLastIndexOf(UChar c,
3462 int32_t length) const;
3464 int32_t doLastIndexOf(UChar32 c,
3466 int32_t length) const;
3468 void doExtract(int32_t start,
3471 int32_t dstStart) const;
3473 inline void doExtract(int32_t start,
3475 UnicodeString& target) const;
3477 inline UChar doCharAt(int32_t offset) const;
3479 UnicodeString& doReplace(int32_t start,
3481 const UnicodeString& srcText,
3485 UnicodeString& doReplace(int32_t start,
3487 const UChar *srcChars,
3491 UnicodeString& doAppend(const UnicodeString& src, int32_t srcStart, int32_t srcLength);
3492 UnicodeString& doAppend(const UChar *srcChars, int32_t srcStart, int32_t srcLength);
3494 UnicodeString& doReverse(int32_t start,
3497 // calculate hash code
3498 int32_t doHashCode(void) const;
3500 // get pointer to start of array
3501 // these do not check for kOpenGetBuffer, unlike the public getBuffer() function
3502 inline UChar* getArrayStart(void);
3503 inline const UChar* getArrayStart(void) const;
3505 inline UBool hasShortLength() const;
3506 inline int32_t getShortLength() const;
3508 // A UnicodeString object (not necessarily its current buffer)
3509 // is writable unless it isBogus() or it has an "open" getBuffer(minCapacity).
3510 inline UBool isWritable() const;
3512 // Is the current buffer writable?
3513 inline UBool isBufferWritable() const;
3515 // None of the following does releaseArray().
3516 inline void setZeroLength();
3517 inline void setShortLength(int32_t len);
3518 inline void setLength(int32_t len);
3519 inline void setToEmpty();
3520 inline void setArray(UChar *array, int32_t len, int32_t capacity); // sets length but not flags
3522 // allocate the array; result may be the stack buffer
3523 // sets refCount to 1 if appropriate
3524 // sets fArray, fCapacity, and flags
3526 // returns boolean for success or failure
3527 UBool allocate(int32_t capacity);
3529 // release the array if owned
3530 void releaseArray(void);
3532 // turn a bogus string into an empty one
3535 // implements assigment operator, copy constructor, and fastCopyFrom()
3536 UnicodeString ©From(const UnicodeString &src, UBool fastCopy=FALSE);
3538 // Copies just the fields without memory management.
3539 void copyFieldsFrom(UnicodeString &src, UBool setSrcToBogus) U_NOEXCEPT;
3541 // Pin start and limit to acceptable values.
3542 inline void pinIndex(int32_t& start) const;
3543 inline void pinIndices(int32_t& start,
3544 int32_t& length) const;
3546 #if !UCONFIG_NO_CONVERSION
3548 /* Internal extract() using UConverter. */
3549 int32_t doExtract(int32_t start, int32_t length,
3550 char *dest, int32_t destCapacity,
3552 UErrorCode &errorCode) const;
3555 * Real constructor for converting from codepage data.
3556 * It assumes that it is called with !fRefCounted.
3558 * If <code>codepage==0</code>, then the default converter
3559 * is used for the platform encoding.
3560 * If <code>codepage</code> is an empty string (<code>""</code>),
3561 * then a simple conversion is performed on the codepage-invariant
3562 * subset ("invariant characters") of the platform encoding. See utypes.h.
3564 void doCodepageCreate(const char *codepageData,
3566 const char *codepage);
3569 * Worker function for creating a UnicodeString from
3570 * a codepage string using a UConverter.
3573 doCodepageCreate(const char *codepageData,
3575 UConverter *converter,
3576 UErrorCode &status);
3581 * This function is called when write access to the array
3584 * We need to make a copy of the array if
3585 * the buffer is read-only, or
3586 * the buffer is refCounted (shared), and refCount>1, or
3587 * the buffer is too small.
3589 * Return FALSE if memory could not be allocated.
3591 UBool cloneArrayIfNeeded(int32_t newCapacity = -1,
3592 int32_t growCapacity = -1,
3593 UBool doCopyArray = TRUE,
3594 int32_t **pBufferToDelete = 0,
3595 UBool forceClone = FALSE);
3598 * Common function for UnicodeString case mappings.
3599 * The stringCaseMapper has the same type UStringCaseMapper
3600 * as in ustr_imp.h for ustrcase_map().
3603 caseMap(const UCaseMap *csm, UStringCaseMapper *stringCaseMapper);
3607 int32_t removeRef(void);
3608 int32_t refCount(void) const;
3613 * Size of stack buffer for short strings.
3614 * Must be at least U16_MAX_LENGTH for the single-code point constructor to work.
3615 * @see UNISTR_OBJECT_SIZE
3617 US_STACKBUF_SIZE=(int32_t)(UNISTR_OBJECT_SIZE-sizeof(void *)-2)/U_SIZEOF_UCHAR,
3618 kInvalidUChar=0xffff, // U+FFFF returned by charAt(invalid index)
3619 kInvalidHashCode=0, // invalid hash code
3620 kEmptyHashCode=1, // hash code for empty string
3622 // bit flag values for fLengthAndFlags
3623 kIsBogus=1, // this string is bogus, i.e., not valid or NULL
3624 kUsingStackBuffer=2,// using fUnion.fStackFields instead of fUnion.fFields
3625 kRefCounted=4, // there is a refCount field before the characters in fArray
3626 kBufferIsReadonly=8,// do not write to this buffer
3627 kOpenGetBuffer=16, // getBuffer(minCapacity) was called (is "open"),
3628 // and releaseBuffer(newLength) must be called
3629 kAllStorageFlags=0x1f,
3631 kLengthShift=5, // remaining 11 bits for non-negative short length, or negative if long
3632 kLength1=1<<kLengthShift,
3633 kMaxShortLength=0x3ff, // max non-negative short length (leaves top bit 0)
3634 kLengthIsLarge=0xffe0, // short length < 0, real length is in fUnion.fFields.fLength
3636 // combined values for convenience
3637 kShortString=kUsingStackBuffer,
3638 kLongString=kRefCounted,
3639 kReadonlyAlias=kBufferIsReadonly,
3643 friend class UnicodeStringAppendable;
3645 union StackBufferOrFields; // forward declaration necessary before friend declaration
3646 friend union StackBufferOrFields; // make US_STACKBUF_SIZE visible inside fUnion
3649 * The following are all the class fields that are stored
3650 * in each UnicodeString object.
3651 * Note that UnicodeString has virtual functions,
3652 * therefore there is an implicit vtable pointer
3653 * as the first real field.
3654 * The fields should be aligned such that no padding is necessary.
3655 * On 32-bit machines, the size should be 32 bytes,
3656 * on 64-bit machines (8-byte pointers), it should be 40 bytes.
3658 * We use a hack to achieve this.
3660 * With at least some compilers, each of the following is forced to
3661 * a multiple of sizeof(pointer) [the largest field base unit here is a data pointer],
3662 * rounded up with additional padding if the fields do not already fit that requirement:
3663 * - sizeof(class UnicodeString)
3664 * - offsetof(UnicodeString, fUnion)
3666 * - sizeof(fStackFields)
3668 * We optimize for the longest possible internal buffer for short strings.
3669 * fUnion.fStackFields begins with 2 bytes for storage flags
3670 * and the length of relatively short strings,
3671 * followed by the buffer for short string contents.
3672 * There is no padding inside fStackFields.
3674 * Heap-allocated and aliased strings use fUnion.fFields.
3675 * Both fStackFields and fFields must begin with the same fields for flags and short length,
3676 * that is, those must have the same memory offsets inside the object,
3677 * because the flags must be inspected in order to decide which half of fUnion is being used.
3678 * We assume that the compiler does not reorder the fields.
3680 * (Padding at the end of fFields is ok:
3681 * As long as it is no larger than fStackFields, it is not wasted space.)
3683 * For some of the history of the UnicodeString class fields layout, see
3684 * - ICU ticket #11551 "longer UnicodeString contents in stack buffer"
3685 * - ICU ticket #11336 "UnicodeString: recombine stack buffer arrays"
3686 * - ICU ticket #8322 "why is sizeof(UnicodeString)==48?"
3688 // (implicit) *vtable;
3689 union StackBufferOrFields {
3690 // fStackFields is used iff (fLengthAndFlags&kUsingStackBuffer) else fFields is used.
3691 // Each struct of the union must begin with fLengthAndFlags.
3693 int16_t fLengthAndFlags; // bit fields: see constants above
3694 UChar fBuffer[US_STACKBUF_SIZE]; // buffer for short strings
3697 int16_t fLengthAndFlags; // bit fields: see constants above
3698 int32_t fLength; // number of characters in fArray if >127; else undefined
3699 int32_t fCapacity; // capacity of fArray (in UChars)
3700 // array pointer last to minimize padding for machines with P128 data model
3701 // or pointer sizes that are not a power of 2
3702 UChar *fArray; // the Unicode data
3708 * Create a new UnicodeString with the concatenation of two others.
3710 * @param s1 The first string to be copied to the new one.
3711 * @param s2 The second string to be copied to the new one, after s1.
3712 * @return UnicodeString(s1).append(s2)
3715 U_COMMON_API UnicodeString U_EXPORT2
3716 operator+ (const UnicodeString &s1, const UnicodeString &s2);
3718 //========================================
3720 //========================================
3722 //========================================
3724 //========================================
3727 UnicodeString::pinIndex(int32_t& start) const
3732 } else if(start > length()) {
3738 UnicodeString::pinIndices(int32_t& start,
3739 int32_t& _length) const
3742 int32_t len = length();
3745 } else if(start > len) {
3750 } else if(_length > (len - start)) {
3751 _length = (len - start);
3756 UnicodeString::getArrayStart() {
3757 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3758 fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
3762 UnicodeString::getArrayStart() const {
3763 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3764 fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
3767 //========================================
3768 // Default constructor
3769 //========================================
3772 UnicodeString::UnicodeString() {
3773 fUnion.fStackFields.fLengthAndFlags=kShortString;
3776 //========================================
3777 // Read-only implementation methods
3778 //========================================
3780 UnicodeString::hasShortLength() const {
3781 return fUnion.fFields.fLengthAndFlags>=0;
3785 UnicodeString::getShortLength() const {
3786 // fLengthAndFlags must be non-negative -> short length >= 0
3787 // and arithmetic or logical shift does not matter.
3788 return fUnion.fFields.fLengthAndFlags>>kLengthShift;
3792 UnicodeString::length() const {
3793 return hasShortLength() ? getShortLength() : fUnion.fFields.fLength;
3797 UnicodeString::getCapacity() const {
3798 return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
3799 US_STACKBUF_SIZE : fUnion.fFields.fCapacity;
3803 UnicodeString::hashCode() const
3804 { return doHashCode(); }
3807 UnicodeString::isBogus() const
3808 { return (UBool)(fUnion.fFields.fLengthAndFlags & kIsBogus); }
3811 UnicodeString::isWritable() const
3812 { return (UBool)!(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus)); }
3815 UnicodeString::isBufferWritable() const
3818 !(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus|kBufferIsReadonly)) &&
3819 (!(fUnion.fFields.fLengthAndFlags&kRefCounted) || refCount()==1));
3822 inline const UChar *
3823 UnicodeString::getBuffer() const {
3824 if(fUnion.fFields.fLengthAndFlags&(kIsBogus|kOpenGetBuffer)) {
3826 } else if(fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) {
3827 return fUnion.fStackFields.fBuffer;
3829 return fUnion.fFields.fArray;
3833 //========================================
3834 // Read-only alias methods
3835 //========================================
3837 UnicodeString::doCompare(int32_t start,
3839 const UnicodeString& srcText,
3841 int32_t srcLength) const
3843 if(srcText.isBogus()) {
3844 return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
3846 srcText.pinIndices(srcStart, srcLength);
3847 return doCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
3852 UnicodeString::operator== (const UnicodeString& text) const
3855 return text.isBogus();
3857 int32_t len = length(), textLength = text.length();
3858 return !text.isBogus() && len == textLength && doEquals(text, len);
3863 UnicodeString::operator!= (const UnicodeString& text) const
3864 { return (! operator==(text)); }
3867 UnicodeString::operator> (const UnicodeString& text) const
3868 { return doCompare(0, length(), text, 0, text.length()) == 1; }
3871 UnicodeString::operator< (const UnicodeString& text) const
3872 { return doCompare(0, length(), text, 0, text.length()) == -1; }
3875 UnicodeString::operator>= (const UnicodeString& text) const
3876 { return doCompare(0, length(), text, 0, text.length()) != -1; }
3879 UnicodeString::operator<= (const UnicodeString& text) const
3880 { return doCompare(0, length(), text, 0, text.length()) != 1; }
3883 UnicodeString::compare(const UnicodeString& text) const
3884 { return doCompare(0, length(), text, 0, text.length()); }
3887 UnicodeString::compare(int32_t start,
3889 const UnicodeString& srcText) const
3890 { return doCompare(start, _length, srcText, 0, srcText.length()); }
3893 UnicodeString::compare(const UChar *srcChars,
3894 int32_t srcLength) const
3895 { return doCompare(0, length(), srcChars, 0, srcLength); }
3898 UnicodeString::compare(int32_t start,
3900 const UnicodeString& srcText,
3902 int32_t srcLength) const
3903 { return doCompare(start, _length, srcText, srcStart, srcLength); }
3906 UnicodeString::compare(int32_t start,
3908 const UChar *srcChars) const
3909 { return doCompare(start, _length, srcChars, 0, _length); }
3912 UnicodeString::compare(int32_t start,
3914 const UChar *srcChars,
3916 int32_t srcLength) const
3917 { return doCompare(start, _length, srcChars, srcStart, srcLength); }
3920 UnicodeString::compareBetween(int32_t start,
3922 const UnicodeString& srcText,
3924 int32_t srcLimit) const
3925 { return doCompare(start, limit - start,
3926 srcText, srcStart, srcLimit - srcStart); }
3929 UnicodeString::doCompareCodePointOrder(int32_t start,
3931 const UnicodeString& srcText,
3933 int32_t srcLength) const
3935 if(srcText.isBogus()) {
3936 return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
3938 srcText.pinIndices(srcStart, srcLength);
3939 return doCompareCodePointOrder(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
3944 UnicodeString::compareCodePointOrder(const UnicodeString& text) const
3945 { return doCompareCodePointOrder(0, length(), text, 0, text.length()); }
3948 UnicodeString::compareCodePointOrder(int32_t start,
3950 const UnicodeString& srcText) const
3951 { return doCompareCodePointOrder(start, _length, srcText, 0, srcText.length()); }
3954 UnicodeString::compareCodePointOrder(const UChar *srcChars,
3955 int32_t srcLength) const
3956 { return doCompareCodePointOrder(0, length(), srcChars, 0, srcLength); }
3959 UnicodeString::compareCodePointOrder(int32_t start,
3961 const UnicodeString& srcText,
3963 int32_t srcLength) const
3964 { return doCompareCodePointOrder(start, _length, srcText, srcStart, srcLength); }
3967 UnicodeString::compareCodePointOrder(int32_t start,
3969 const UChar *srcChars) const
3970 { return doCompareCodePointOrder(start, _length, srcChars, 0, _length); }
3973 UnicodeString::compareCodePointOrder(int32_t start,
3975 const UChar *srcChars,
3977 int32_t srcLength) const
3978 { return doCompareCodePointOrder(start, _length, srcChars, srcStart, srcLength); }
3981 UnicodeString::compareCodePointOrderBetween(int32_t start,
3983 const UnicodeString& srcText,
3985 int32_t srcLimit) const
3986 { return doCompareCodePointOrder(start, limit - start,
3987 srcText, srcStart, srcLimit - srcStart); }
3990 UnicodeString::doCaseCompare(int32_t start,
3992 const UnicodeString &srcText,
3995 uint32_t options) const
3997 if(srcText.isBogus()) {
3998 return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
4000 srcText.pinIndices(srcStart, srcLength);
4001 return doCaseCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength, options);
4006 UnicodeString::caseCompare(const UnicodeString &text, uint32_t options) const {
4007 return doCaseCompare(0, length(), text, 0, text.length(), options);
4011 UnicodeString::caseCompare(int32_t start,
4013 const UnicodeString &srcText,
4014 uint32_t options) const {
4015 return doCaseCompare(start, _length, srcText, 0, srcText.length(), options);
4019 UnicodeString::caseCompare(const UChar *srcChars,
4021 uint32_t options) const {
4022 return doCaseCompare(0, length(), srcChars, 0, srcLength, options);
4026 UnicodeString::caseCompare(int32_t start,
4028 const UnicodeString &srcText,
4031 uint32_t options) const {
4032 return doCaseCompare(start, _length, srcText, srcStart, srcLength, options);
4036 UnicodeString::caseCompare(int32_t start,
4038 const UChar *srcChars,
4039 uint32_t options) const {
4040 return doCaseCompare(start, _length, srcChars, 0, _length, options);
4044 UnicodeString::caseCompare(int32_t start,
4046 const UChar *srcChars,
4049 uint32_t options) const {
4050 return doCaseCompare(start, _length, srcChars, srcStart, srcLength, options);
4054 UnicodeString::caseCompareBetween(int32_t start,
4056 const UnicodeString &srcText,
4059 uint32_t options) const {
4060 return doCaseCompare(start, limit - start, srcText, srcStart, srcLimit - srcStart, options);
4064 UnicodeString::indexOf(const UnicodeString& srcText,
4068 int32_t _length) const
4070 if(!srcText.isBogus()) {
4071 srcText.pinIndices(srcStart, srcLength);
4073 return indexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
4080 UnicodeString::indexOf(const UnicodeString& text) const
4081 { return indexOf(text, 0, text.length(), 0, length()); }
4084 UnicodeString::indexOf(const UnicodeString& text,
4085 int32_t start) const {
4087 return indexOf(text, 0, text.length(), start, length() - start);
4091 UnicodeString::indexOf(const UnicodeString& text,
4093 int32_t _length) const
4094 { return indexOf(text, 0, text.length(), start, _length); }
4097 UnicodeString::indexOf(const UChar *srcChars,
4099 int32_t start) const {
4101 return indexOf(srcChars, 0, srcLength, start, length() - start);
4105 UnicodeString::indexOf(const UChar *srcChars,
4108 int32_t _length) const
4109 { return indexOf(srcChars, 0, srcLength, start, _length); }
4112 UnicodeString::indexOf(UChar c,
4114 int32_t _length) const
4115 { return doIndexOf(c, start, _length); }
4118 UnicodeString::indexOf(UChar32 c,
4120 int32_t _length) const
4121 { return doIndexOf(c, start, _length); }
4124 UnicodeString::indexOf(UChar c) const
4125 { return doIndexOf(c, 0, length()); }
4128 UnicodeString::indexOf(UChar32 c) const
4129 { return indexOf(c, 0, length()); }
4132 UnicodeString::indexOf(UChar c,
4133 int32_t start) const {
4135 return doIndexOf(c, start, length() - start);
4139 UnicodeString::indexOf(UChar32 c,
4140 int32_t start) const {
4142 return indexOf(c, start, length() - start);
4146 UnicodeString::lastIndexOf(const UChar *srcChars,
4149 int32_t _length) const
4150 { return lastIndexOf(srcChars, 0, srcLength, start, _length); }
4153 UnicodeString::lastIndexOf(const UChar *srcChars,
4155 int32_t start) const {
4157 return lastIndexOf(srcChars, 0, srcLength, start, length() - start);
4161 UnicodeString::lastIndexOf(const UnicodeString& srcText,
4165 int32_t _length) const
4167 if(!srcText.isBogus()) {
4168 srcText.pinIndices(srcStart, srcLength);
4170 return lastIndexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
4177 UnicodeString::lastIndexOf(const UnicodeString& text,
4179 int32_t _length) const
4180 { return lastIndexOf(text, 0, text.length(), start, _length); }
4183 UnicodeString::lastIndexOf(const UnicodeString& text,
4184 int32_t start) const {
4186 return lastIndexOf(text, 0, text.length(), start, length() - start);
4190 UnicodeString::lastIndexOf(const UnicodeString& text) const
4191 { return lastIndexOf(text, 0, text.length(), 0, length()); }
4194 UnicodeString::lastIndexOf(UChar c,
4196 int32_t _length) const
4197 { return doLastIndexOf(c, start, _length); }
4200 UnicodeString::lastIndexOf(UChar32 c,
4202 int32_t _length) const {
4203 return doLastIndexOf(c, start, _length);
4207 UnicodeString::lastIndexOf(UChar c) const
4208 { return doLastIndexOf(c, 0, length()); }
4211 UnicodeString::lastIndexOf(UChar32 c) const {
4212 return lastIndexOf(c, 0, length());
4216 UnicodeString::lastIndexOf(UChar c,
4217 int32_t start) const {
4219 return doLastIndexOf(c, start, length() - start);
4223 UnicodeString::lastIndexOf(UChar32 c,
4224 int32_t start) const {
4226 return lastIndexOf(c, start, length() - start);
4230 UnicodeString::startsWith(const UnicodeString& text) const
4231 { return compare(0, text.length(), text, 0, text.length()) == 0; }
4234 UnicodeString::startsWith(const UnicodeString& srcText,
4236 int32_t srcLength) const
4237 { return doCompare(0, srcLength, srcText, srcStart, srcLength) == 0; }
4240 UnicodeString::startsWith(const UChar *srcChars, int32_t srcLength) const {
4242 srcLength = u_strlen(srcChars);
4244 return doCompare(0, srcLength, srcChars, 0, srcLength) == 0;
4248 UnicodeString::startsWith(const UChar *srcChars, int32_t srcStart, int32_t srcLength) const {
4250 srcLength = u_strlen(srcChars);
4252 return doCompare(0, srcLength, srcChars, srcStart, srcLength) == 0;
4256 UnicodeString::endsWith(const UnicodeString& text) const
4257 { return doCompare(length() - text.length(), text.length(),
4258 text, 0, text.length()) == 0; }
4261 UnicodeString::endsWith(const UnicodeString& srcText,
4263 int32_t srcLength) const {
4264 srcText.pinIndices(srcStart, srcLength);
4265 return doCompare(length() - srcLength, srcLength,
4266 srcText, srcStart, srcLength) == 0;
4270 UnicodeString::endsWith(const UChar *srcChars,
4271 int32_t srcLength) const {
4273 srcLength = u_strlen(srcChars);
4275 return doCompare(length() - srcLength, srcLength,
4276 srcChars, 0, srcLength) == 0;
4280 UnicodeString::endsWith(const UChar *srcChars,
4282 int32_t srcLength) const {
4284 srcLength = u_strlen(srcChars + srcStart);
4286 return doCompare(length() - srcLength, srcLength,
4287 srcChars, srcStart, srcLength) == 0;
4290 //========================================
4292 //========================================
4293 inline UnicodeString&
4294 UnicodeString::replace(int32_t start,
4296 const UnicodeString& srcText)
4297 { return doReplace(start, _length, srcText, 0, srcText.length()); }
4299 inline UnicodeString&
4300 UnicodeString::replace(int32_t start,
4302 const UnicodeString& srcText,
4305 { return doReplace(start, _length, srcText, srcStart, srcLength); }
4307 inline UnicodeString&
4308 UnicodeString::replace(int32_t start,
4310 const UChar *srcChars,
4312 { return doReplace(start, _length, srcChars, 0, srcLength); }
4314 inline UnicodeString&
4315 UnicodeString::replace(int32_t start,
4317 const UChar *srcChars,
4320 { return doReplace(start, _length, srcChars, srcStart, srcLength); }
4322 inline UnicodeString&
4323 UnicodeString::replace(int32_t start,
4326 { return doReplace(start, _length, &srcChar, 0, 1); }
4328 inline UnicodeString&
4329 UnicodeString::replaceBetween(int32_t start,
4331 const UnicodeString& srcText)
4332 { return doReplace(start, limit - start, srcText, 0, srcText.length()); }
4334 inline UnicodeString&
4335 UnicodeString::replaceBetween(int32_t start,
4337 const UnicodeString& srcText,
4340 { return doReplace(start, limit - start, srcText, srcStart, srcLimit - srcStart); }
4342 inline UnicodeString&
4343 UnicodeString::findAndReplace(const UnicodeString& oldText,
4344 const UnicodeString& newText)
4345 { return findAndReplace(0, length(), oldText, 0, oldText.length(),
4346 newText, 0, newText.length()); }
4348 inline UnicodeString&
4349 UnicodeString::findAndReplace(int32_t start,
4351 const UnicodeString& oldText,
4352 const UnicodeString& newText)
4353 { return findAndReplace(start, _length, oldText, 0, oldText.length(),
4354 newText, 0, newText.length()); }
4356 // ============================
4358 // ============================
4360 UnicodeString::doExtract(int32_t start,
4362 UnicodeString& target) const
4363 { target.replace(0, target.length(), *this, start, _length); }
4366 UnicodeString::extract(int32_t start,
4369 int32_t targetStart) const
4370 { doExtract(start, _length, target, targetStart); }
4373 UnicodeString::extract(int32_t start,
4375 UnicodeString& target) const
4376 { doExtract(start, _length, target); }
4378 #if !UCONFIG_NO_CONVERSION
4381 UnicodeString::extract(int32_t start,
4384 const char *codepage) const
4387 // This dstSize value will be checked explicitly
4388 return extract(start, _length, dst, dst!=0 ? 0xffffffff : 0, codepage);
4394 UnicodeString::extractBetween(int32_t start,
4397 int32_t dstStart) const {
4400 doExtract(start, limit - start, dst, dstStart);
4403 inline UnicodeString
4404 UnicodeString::tempSubStringBetween(int32_t start, int32_t limit) const {
4405 return tempSubString(start, limit - start);
4409 UnicodeString::doCharAt(int32_t offset) const
4411 if((uint32_t)offset < (uint32_t)length()) {
4412 return getArrayStart()[offset];
4414 return kInvalidUChar;
4419 UnicodeString::charAt(int32_t offset) const
4420 { return doCharAt(offset); }
4423 UnicodeString::operator[] (int32_t offset) const
4424 { return doCharAt(offset); }
4427 UnicodeString::isEmpty() const {
4428 // Arithmetic or logical right shift does not matter: only testing for 0.
4429 return (fUnion.fFields.fLengthAndFlags>>kLengthShift) == 0;
4432 //========================================
4433 // Write implementation methods
4434 //========================================
4436 UnicodeString::setZeroLength() {
4437 fUnion.fFields.fLengthAndFlags &= kAllStorageFlags;
4441 UnicodeString::setShortLength(int32_t len) {
4442 // requires 0 <= len <= kMaxShortLength
4443 fUnion.fFields.fLengthAndFlags =
4444 (int16_t)((fUnion.fFields.fLengthAndFlags & kAllStorageFlags) | (len << kLengthShift));
4448 UnicodeString::setLength(int32_t len) {
4449 if(len <= kMaxShortLength) {
4450 setShortLength(len);
4452 fUnion.fFields.fLengthAndFlags |= kLengthIsLarge;
4453 fUnion.fFields.fLength = len;
4458 UnicodeString::setToEmpty() {
4459 fUnion.fFields.fLengthAndFlags = kShortString;
4463 UnicodeString::setArray(UChar *array, int32_t len, int32_t capacity) {
4465 fUnion.fFields.fArray = array;
4466 fUnion.fFields.fCapacity = capacity;
4469 inline UnicodeString&
4470 UnicodeString::operator= (UChar ch)
4471 { return doReplace(0, length(), &ch, 0, 1); }
4473 inline UnicodeString&
4474 UnicodeString::operator= (UChar32 ch)
4475 { return replace(0, length(), ch); }
4477 inline UnicodeString&
4478 UnicodeString::setTo(const UnicodeString& srcText,
4483 return doReplace(0, length(), srcText, srcStart, srcLength);
4486 inline UnicodeString&
4487 UnicodeString::setTo(const UnicodeString& srcText,
4491 srcText.pinIndex(srcStart);
4492 return doReplace(0, length(), srcText, srcStart, srcText.length() - srcStart);
4495 inline UnicodeString&
4496 UnicodeString::setTo(const UnicodeString& srcText)
4498 return copyFrom(srcText);
4501 inline UnicodeString&
4502 UnicodeString::setTo(const UChar *srcChars,
4506 return doReplace(0, length(), srcChars, 0, srcLength);
4509 inline UnicodeString&
4510 UnicodeString::setTo(UChar srcChar)
4513 return doReplace(0, length(), &srcChar, 0, 1);
4516 inline UnicodeString&
4517 UnicodeString::setTo(UChar32 srcChar)
4520 return replace(0, length(), srcChar);
4523 inline UnicodeString&
4524 UnicodeString::append(const UnicodeString& srcText,
4527 { return doAppend(srcText, srcStart, srcLength); }
4529 inline UnicodeString&
4530 UnicodeString::append(const UnicodeString& srcText)
4531 { return doAppend(srcText, 0, srcText.length()); }
4533 inline UnicodeString&
4534 UnicodeString::append(const UChar *srcChars,
4537 { return doAppend(srcChars, srcStart, srcLength); }
4539 inline UnicodeString&
4540 UnicodeString::append(const UChar *srcChars,
4542 { return doAppend(srcChars, 0, srcLength); }
4544 inline UnicodeString&
4545 UnicodeString::append(UChar srcChar)
4546 { return doAppend(&srcChar, 0, 1); }
4548 inline UnicodeString&
4549 UnicodeString::operator+= (UChar ch)
4550 { return doAppend(&ch, 0, 1); }
4552 inline UnicodeString&
4553 UnicodeString::operator+= (UChar32 ch) {
4557 inline UnicodeString&
4558 UnicodeString::operator+= (const UnicodeString& srcText)
4559 { return doAppend(srcText, 0, srcText.length()); }
4561 inline UnicodeString&
4562 UnicodeString::insert(int32_t start,
4563 const UnicodeString& srcText,
4566 { return doReplace(start, 0, srcText, srcStart, srcLength); }
4568 inline UnicodeString&
4569 UnicodeString::insert(int32_t start,
4570 const UnicodeString& srcText)
4571 { return doReplace(start, 0, srcText, 0, srcText.length()); }
4573 inline UnicodeString&
4574 UnicodeString::insert(int32_t start,
4575 const UChar *srcChars,
4578 { return doReplace(start, 0, srcChars, srcStart, srcLength); }
4580 inline UnicodeString&
4581 UnicodeString::insert(int32_t start,
4582 const UChar *srcChars,
4584 { return doReplace(start, 0, srcChars, 0, srcLength); }
4586 inline UnicodeString&
4587 UnicodeString::insert(int32_t start,
4589 { return doReplace(start, 0, &srcChar, 0, 1); }
4591 inline UnicodeString&
4592 UnicodeString::insert(int32_t start,
4594 { return replace(start, 0, srcChar); }
4597 inline UnicodeString&
4598 UnicodeString::remove()
4600 // remove() of a bogus string makes the string empty and non-bogus
4609 inline UnicodeString&
4610 UnicodeString::remove(int32_t start,
4613 if(start <= 0 && _length == INT32_MAX) {
4614 // remove(guaranteed everything) of a bogus string makes the string empty and non-bogus
4617 return doReplace(start, _length, NULL, 0, 0);
4620 inline UnicodeString&
4621 UnicodeString::removeBetween(int32_t start,
4623 { return doReplace(start, limit - start, NULL, 0, 0); }
4625 inline UnicodeString &
4626 UnicodeString::retainBetween(int32_t start, int32_t limit) {
4628 return doReplace(0, start, NULL, 0, 0);
4632 UnicodeString::truncate(int32_t targetLength)
4634 if(isBogus() && targetLength == 0) {
4635 // truncate(0) of a bogus string makes the string empty and non-bogus
4638 } else if((uint32_t)targetLength < (uint32_t)length()) {
4639 setLength(targetLength);
4646 inline UnicodeString&
4647 UnicodeString::reverse()
4648 { return doReverse(0, length()); }
4650 inline UnicodeString&
4651 UnicodeString::reverse(int32_t start,
4653 { return doReverse(start, _length); }