2 **********************************************************************
3 * Copyright (C) 1998-2016, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
9 * Modification History:
11 * Date Name Description
12 * 09/25/98 stephen Creation.
13 * 11/11/98 stephen Changed per 11/9 code review.
14 * 04/20/99 stephen Overhauled per 4/16 code review.
15 * 11/18/99 aliu Made to inherit from Replaceable. Added method
16 * handleReplaceBetween(); other methods unchanged.
17 * 06/25/01 grhoten Remove dependency on iostream.
18 ******************************************************************************
26 * \brief C++ API: Unicode String
29 #include "unicode/utypes.h"
30 #include "unicode/rep.h"
31 #include "unicode/std_string.h"
32 #include "unicode/stringpiece.h"
33 #include "unicode/bytestream.h"
34 #include "unicode/ucasemap.h"
36 struct UConverter
; // unicode/ucnv.h
38 #ifndef U_COMPARE_CODE_POINT_ORDER
39 /* see also ustring.h and unorm.h */
41 * Option bit for u_strCaseCompare, u_strcasecmp, unorm_compare, etc:
42 * Compare strings in code point order instead of code unit order.
45 #define U_COMPARE_CODE_POINT_ORDER 0x8000
50 * \ingroup ustring_ustrlen
52 U_STABLE
int32_t U_EXPORT2
53 u_strlen(const UChar
*s
);
57 * \def U_STRING_CASE_MAPPER_DEFINED
60 #ifndef U_STRING_CASE_MAPPER_DEFINED
61 #define U_STRING_CASE_MAPPER_DEFINED
64 * Internal string case mapping function type.
67 typedef int32_t U_CALLCONV
68 UStringCaseMapper(const UCaseMap
*csm
,
69 UChar
*dest
, int32_t destCapacity
,
70 const UChar
*src
, int32_t srcLength
,
71 UErrorCode
*pErrorCode
);
77 class BreakIterator
; // unicode/brkiter.h
78 class Locale
; // unicode/locid.h
79 class StringCharacterIterator
;
80 class UnicodeStringAppendable
; // unicode/appendable.h
82 /* The <iostream> include has been moved to unicode/ustream.h */
85 * Constant to be used in the UnicodeString(char *, int32_t, EInvariant) constructor
86 * which constructs a Unicode string from an invariant-character char * string.
87 * About invariant characters see utypes.h.
88 * This constructor has no runtime dependency on conversion code and is
89 * therefore recommended over ones taking a charset name string
90 * (where the empty string "" indicates invariant-character conversion).
94 #define US_INV icu::UnicodeString::kInvariant
97 * Unicode String literals in C++.
98 * Dependent on the platform properties, different UnicodeString
99 * constructors should be used to create a UnicodeString object from
101 * The macros are defined for maximum performance.
102 * They work only for strings that contain "invariant characters", i.e.,
103 * only latin letters, digits, and some punctuation.
104 * See utypes.h for details.
106 * The string parameter must be a C string literal.
107 * The length of the string, not including the terminating
108 * <code>NUL</code>, must be specified as a constant.
109 * The U_STRING_DECL macro should be invoked exactly once for one
110 * such string variable before it is used.
113 #if defined(U_DECLARE_UTF16)
114 # define UNICODE_STRING(cs, _length) icu::UnicodeString(TRUE, (const UChar *)U_DECLARE_UTF16(cs), _length)
115 #elif U_SIZEOF_WCHAR_T==U_SIZEOF_UCHAR && (U_CHARSET_FAMILY==U_ASCII_FAMILY || (U_SIZEOF_UCHAR == 2 && defined(U_WCHAR_IS_UTF16)))
116 # define UNICODE_STRING(cs, _length) icu::UnicodeString(TRUE, (const UChar *)L ## cs, _length)
117 #elif U_SIZEOF_UCHAR==1 && U_CHARSET_FAMILY==U_ASCII_FAMILY
118 # define UNICODE_STRING(cs, _length) icu::UnicodeString(TRUE, (const UChar *)cs, _length)
120 # define UNICODE_STRING(cs, _length) icu::UnicodeString(cs, _length, US_INV)
124 * Unicode String literals in C++.
125 * Dependent on the platform properties, different UnicodeString
126 * constructors should be used to create a UnicodeString object from
128 * The macros are defined for improved performance.
129 * They work only for strings that contain "invariant characters", i.e.,
130 * only latin letters, digits, and some punctuation.
131 * See utypes.h for details.
133 * The string parameter must be a C string literal.
136 #define UNICODE_STRING_SIMPLE(cs) UNICODE_STRING(cs, -1)
139 * \def UNISTR_FROM_CHAR_EXPLICIT
140 * This can be defined to be empty or "explicit".
141 * If explicit, then the UnicodeString(UChar) and UnicodeString(UChar32)
142 * constructors are marked as explicit, preventing their inadvertent use.
145 #ifndef UNISTR_FROM_CHAR_EXPLICIT
146 # if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION)
147 // Auto-"explicit" in ICU library code.
148 # define UNISTR_FROM_CHAR_EXPLICIT explicit
150 // Empty by default for source code compatibility.
151 # define UNISTR_FROM_CHAR_EXPLICIT
156 * \def UNISTR_FROM_STRING_EXPLICIT
157 * This can be defined to be empty or "explicit".
158 * If explicit, then the UnicodeString(const char *) and UnicodeString(const UChar *)
159 * constructors are marked as explicit, preventing their inadvertent use.
161 * In particular, this helps prevent accidentally depending on ICU conversion code
162 * by passing a string literal into an API with a const UnicodeString & parameter.
165 #ifndef UNISTR_FROM_STRING_EXPLICIT
166 # if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION)
167 // Auto-"explicit" in ICU library code.
168 # define UNISTR_FROM_STRING_EXPLICIT explicit
170 // Empty by default for source code compatibility.
171 # define UNISTR_FROM_STRING_EXPLICIT
175 /* Cannot make the following #ifndef U_HIDE_DRAFT_API,
176 it is used to construct other non-internal constants */
178 * \def UNISTR_OBJECT_SIZE
179 * Desired sizeof(UnicodeString) in bytes.
180 * It should be a multiple of sizeof(pointer) to avoid unusable space for padding.
181 * The object size may want to be a multiple of 16 bytes,
182 * which is a common granularity for heap allocation.
184 * Any space inside the object beyond sizeof(vtable pointer) + 2
185 * is available for storing short strings inside the object.
186 * The bigger the object, the longer a string that can be stored inside the object,
187 * without additional heap allocation.
189 * Depending on a platform's pointer size, pointer alignment requirements,
190 * and struct padding, the compiler will usually round up sizeof(UnicodeString)
191 * to 4 * sizeof(pointer) (or 3 * sizeof(pointer) for P128 data models),
192 * to hold the fields for heap-allocated strings.
193 * Such a minimum size also ensures that the object is easily large enough
194 * to hold at least 2 UChars, for one supplementary code point (U16_MAX_LENGTH).
196 * sizeof(UnicodeString) >= 48 should work for all known platforms.
198 * For example, on a 64-bit machine where sizeof(vtable pointer) is 8,
199 * sizeof(UnicodeString) = 64 would leave space for
200 * (64 - sizeof(vtable pointer) - 2) / U_SIZEOF_UCHAR = (64 - 8 - 2) / 2 = 27
201 * UChars stored inside the object.
203 * The minimum object size on a 64-bit machine would be
204 * 4 * sizeof(pointer) = 4 * 8 = 32 bytes,
205 * and the internal buffer would hold up to 11 UChars in that case.
207 * @see U16_MAX_LENGTH
210 #ifndef UNISTR_OBJECT_SIZE
211 # define UNISTR_OBJECT_SIZE 64
215 * UnicodeString is a string class that stores Unicode characters directly and provides
216 * similar functionality as the Java String and StringBuffer/StringBuilder classes.
217 * It is a concrete implementation of the abstract class Replaceable (for transliteration).
219 * A UnicodeString may also "alias" an external array of characters
220 * (that is, point to it, rather than own the array)
221 * whose lifetime must then at least match the lifetime of the aliasing object.
222 * This aliasing may be preserved when returning a UnicodeString by value,
223 * depending on the compiler and the function implementation,
224 * via Return Value Optimization (RVO) or the move assignment operator.
225 * (However, the copy assignment operator does not preserve aliasing.)
226 * For details see the description of storage models at the end of the class API docs
227 * and in the User Guide chapter linked from there.
229 * The UnicodeString class is not suitable for subclassing.
231 * <p>For an overview of Unicode strings in C and C++ see the
232 * <a href="http://userguide.icu-project.org/strings#TOC-Strings-in-C-C-">User Guide Strings chapter</a>.</p>
234 * <p>In ICU, a Unicode string consists of 16-bit Unicode <em>code units</em>.
235 * A Unicode character may be stored with either one code unit
236 * (the most common case) or with a matched pair of special code units
237 * ("surrogates"). The data type for code units is UChar.
238 * For single-character handling, a Unicode character code <em>point</em> is a value
239 * in the range 0..0x10ffff. ICU uses the UChar32 type for code points.</p>
241 * <p>Indexes and offsets into and lengths of strings always count code units, not code points.
242 * This is the same as with multi-byte char* strings in traditional string handling.
243 * Operations on partial strings typically do not test for code point boundaries.
244 * If necessary, the user needs to take care of such boundaries by testing for the code unit
245 * values or by using functions like
246 * UnicodeString::getChar32Start() and UnicodeString::getChar32Limit()
247 * (or, in C, the equivalent macros U16_SET_CP_START() and U16_SET_CP_LIMIT(), see utf.h).</p>
249 * UnicodeString methods are more lenient with regard to input parameter values
250 * than other ICU APIs. In particular:
251 * - If indexes are out of bounds for a UnicodeString object
252 * (<0 or >length()) then they are "pinned" to the nearest boundary.
253 * - If primitive string pointer values (e.g., const UChar * or char *)
254 * for input strings are NULL, then those input string parameters are treated
255 * as if they pointed to an empty string.
256 * However, this is <em>not</em> the case for char * parameters for charset names
258 * - Most UnicodeString methods do not take a UErrorCode parameter because
259 * there are usually very few opportunities for failure other than a shortage
260 * of memory, error codes in low-level C++ string methods would be inconvenient,
261 * and the error code as the last parameter (ICU convention) would prevent
262 * the use of default parameter values.
263 * Instead, such methods set the UnicodeString into a "bogus" state
264 * (see isBogus()) if an error occurs.
266 * In string comparisons, two UnicodeString objects that are both "bogus"
267 * compare equal (to be transitive and prevent endless loops in sorting),
268 * and a "bogus" string compares less than any non-"bogus" one.
270 * Const UnicodeString methods are thread-safe. Multiple threads can use
271 * const methods on the same UnicodeString object simultaneously,
272 * but non-const methods must not be called concurrently (in multiple threads)
273 * with any other (const or non-const) methods.
275 * Similarly, const UnicodeString & parameters are thread-safe.
276 * One object may be passed in as such a parameter concurrently in multiple threads.
277 * This includes the const UnicodeString & parameters for
278 * copy construction, assignment, and cloning.
280 * <p>UnicodeString uses several storage methods.
281 * String contents can be stored inside the UnicodeString object itself,
282 * in an allocated and shared buffer, or in an outside buffer that is "aliased".
283 * Most of this is done transparently, but careful aliasing in particular provides
284 * significant performance improvements.
285 * Also, the internal buffer is accessible via special functions.
286 * For details see the
287 * <a href="http://userguide.icu-project.org/strings#TOC-Maximizing-Performance-with-the-UnicodeString-Storage-Model">User Guide Strings chapter</a>.</p>
290 * @see CharacterIterator
293 class U_COMMON_API UnicodeString
: public Replaceable
298 * Constant to be used in the UnicodeString(char *, int32_t, EInvariant) constructor
299 * which constructs a Unicode string from an invariant-character char * string.
300 * Use the macro US_INV instead of the full qualification for this value.
313 //========================================
314 // Read-only operations
315 //========================================
317 /* Comparison - bitwise only - for international comparison use collation */
320 * Equality operator. Performs only bitwise comparison.
321 * @param text The UnicodeString to compare to this one.
322 * @return TRUE if <TT>text</TT> contains the same characters as this one,
326 inline UBool
operator== (const UnicodeString
& text
) const;
329 * Inequality operator. Performs only bitwise comparison.
330 * @param text The UnicodeString to compare to this one.
331 * @return FALSE if <TT>text</TT> contains the same characters as this one,
335 inline UBool
operator!= (const UnicodeString
& text
) const;
338 * Greater than operator. Performs only bitwise comparison.
339 * @param text The UnicodeString to compare to this one.
340 * @return TRUE if the characters in this are bitwise
341 * greater than the characters in <code>text</code>, FALSE otherwise
344 inline UBool
operator> (const UnicodeString
& text
) const;
347 * Less than operator. Performs only bitwise comparison.
348 * @param text The UnicodeString to compare to this one.
349 * @return TRUE if the characters in this are bitwise
350 * less than the characters in <code>text</code>, FALSE otherwise
353 inline UBool
operator< (const UnicodeString
& text
) const;
356 * Greater than or equal operator. Performs only bitwise comparison.
357 * @param text The UnicodeString to compare to this one.
358 * @return TRUE if the characters in this are bitwise
359 * greater than or equal to the characters in <code>text</code>, FALSE otherwise
362 inline UBool
operator>= (const UnicodeString
& text
) const;
365 * Less than or equal operator. Performs only bitwise comparison.
366 * @param text The UnicodeString to compare to this one.
367 * @return TRUE if the characters in this are bitwise
368 * less than or equal to the characters in <code>text</code>, FALSE otherwise
371 inline UBool
operator<= (const UnicodeString
& text
) const;
374 * Compare the characters bitwise in this UnicodeString to
375 * the characters in <code>text</code>.
376 * @param text The UnicodeString to compare to this one.
377 * @return The result of bitwise character comparison: 0 if this
378 * contains the same characters as <code>text</code>, -1 if the characters in
379 * this are bitwise less than the characters in <code>text</code>, +1 if the
380 * characters in this are bitwise greater than the characters
381 * in <code>text</code>.
384 inline int8_t compare(const UnicodeString
& text
) const;
387 * Compare the characters bitwise in the range
388 * [<TT>start</TT>, <TT>start + length</TT>) with the characters
389 * in the <b>entire string</b> <TT>text</TT>.
390 * (The parameters "start" and "length" are not applied to the other text "text".)
391 * @param start the offset at which the compare operation begins
392 * @param length the number of characters of text to compare.
393 * @param text the other text to be compared against this string.
394 * @return The result of bitwise character comparison: 0 if this
395 * contains the same characters as <code>text</code>, -1 if the characters in
396 * this are bitwise less than the characters in <code>text</code>, +1 if the
397 * characters in this are bitwise greater than the characters
398 * in <code>text</code>.
401 inline int8_t compare(int32_t start
,
403 const UnicodeString
& text
) const;
406 * Compare the characters bitwise in the range
407 * [<TT>start</TT>, <TT>start + length</TT>) with the characters
408 * in <TT>srcText</TT> in the range
409 * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
410 * @param start the offset at which the compare operation begins
411 * @param length the number of characters in this to compare.
412 * @param srcText the text to be compared
413 * @param srcStart the offset into <TT>srcText</TT> to start comparison
414 * @param srcLength the number of characters in <TT>src</TT> to compare
415 * @return The result of bitwise character comparison: 0 if this
416 * contains the same characters as <code>srcText</code>, -1 if the characters in
417 * this are bitwise less than the characters in <code>srcText</code>, +1 if the
418 * characters in this are bitwise greater than the characters
419 * in <code>srcText</code>.
422 inline int8_t compare(int32_t start
,
424 const UnicodeString
& srcText
,
426 int32_t srcLength
) const;
429 * Compare the characters bitwise in this UnicodeString with the first
430 * <TT>srcLength</TT> characters in <TT>srcChars</TT>.
431 * @param srcChars The characters to compare to this UnicodeString.
432 * @param srcLength the number of characters in <TT>srcChars</TT> to compare
433 * @return The result of bitwise character comparison: 0 if this
434 * contains the same characters as <code>srcChars</code>, -1 if the characters in
435 * this are bitwise less than the characters in <code>srcChars</code>, +1 if the
436 * characters in this are bitwise greater than the characters
437 * in <code>srcChars</code>.
440 inline int8_t compare(const UChar
*srcChars
,
441 int32_t srcLength
) const;
444 * Compare the characters bitwise in the range
445 * [<TT>start</TT>, <TT>start + length</TT>) with the first
446 * <TT>length</TT> characters in <TT>srcChars</TT>
447 * @param start the offset at which the compare operation begins
448 * @param length the number of characters to compare.
449 * @param srcChars the characters to be compared
450 * @return The result of bitwise character comparison: 0 if this
451 * contains the same characters as <code>srcChars</code>, -1 if the characters in
452 * this are bitwise less than the characters in <code>srcChars</code>, +1 if the
453 * characters in this are bitwise greater than the characters
454 * in <code>srcChars</code>.
457 inline int8_t compare(int32_t start
,
459 const UChar
*srcChars
) const;
462 * Compare the characters bitwise in the range
463 * [<TT>start</TT>, <TT>start + length</TT>) with the characters
464 * in <TT>srcChars</TT> in the range
465 * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
466 * @param start the offset at which the compare operation begins
467 * @param length the number of characters in this to compare
468 * @param srcChars the characters to be compared
469 * @param srcStart the offset into <TT>srcChars</TT> to start comparison
470 * @param srcLength the number of characters in <TT>srcChars</TT> to compare
471 * @return The result of bitwise character comparison: 0 if this
472 * contains the same characters as <code>srcChars</code>, -1 if the characters in
473 * this are bitwise less than the characters in <code>srcChars</code>, +1 if the
474 * characters in this are bitwise greater than the characters
475 * in <code>srcChars</code>.
478 inline int8_t compare(int32_t start
,
480 const UChar
*srcChars
,
482 int32_t srcLength
) const;
485 * Compare the characters bitwise in the range
486 * [<TT>start</TT>, <TT>limit</TT>) with the characters
487 * in <TT>srcText</TT> in the range
488 * [<TT>srcStart</TT>, <TT>srcLimit</TT>).
489 * @param start the offset at which the compare operation begins
490 * @param limit the offset immediately following the compare operation
491 * @param srcText the text to be compared
492 * @param srcStart the offset into <TT>srcText</TT> to start comparison
493 * @param srcLimit the offset into <TT>srcText</TT> to limit comparison
494 * @return The result of bitwise character comparison: 0 if this
495 * contains the same characters as <code>srcText</code>, -1 if the characters in
496 * this are bitwise less than the characters in <code>srcText</code>, +1 if the
497 * characters in this are bitwise greater than the characters
498 * in <code>srcText</code>.
501 inline int8_t compareBetween(int32_t start
,
503 const UnicodeString
& srcText
,
505 int32_t srcLimit
) const;
508 * Compare two Unicode strings in code point order.
509 * The result may be different from the results of compare(), operator<, etc.
510 * if supplementary characters are present:
512 * In UTF-16, supplementary characters (with code points U+10000 and above) are
513 * stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff,
514 * which means that they compare as less than some other BMP characters like U+feff.
515 * This function compares Unicode strings in code point order.
516 * If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.
518 * @param text Another string to compare this one to.
519 * @return a negative/zero/positive integer corresponding to whether
520 * this string is less than/equal to/greater than the second one
521 * in code point order
524 inline int8_t compareCodePointOrder(const UnicodeString
& text
) const;
527 * Compare two Unicode strings in code point order.
528 * The result may be different from the results of compare(), operator<, etc.
529 * if supplementary characters are present:
531 * In UTF-16, supplementary characters (with code points U+10000 and above) are
532 * stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff,
533 * which means that they compare as less than some other BMP characters like U+feff.
534 * This function compares Unicode strings in code point order.
535 * If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.
537 * @param start The start offset in this string at which the compare operation begins.
538 * @param length The number of code units from this string to compare.
539 * @param srcText Another string to compare this one to.
540 * @return a negative/zero/positive integer corresponding to whether
541 * this string is less than/equal to/greater than the second one
542 * in code point order
545 inline int8_t compareCodePointOrder(int32_t start
,
547 const UnicodeString
& srcText
) const;
550 * Compare two Unicode strings in code point order.
551 * The result may be different from the results of compare(), operator<, etc.
552 * if supplementary characters are present:
554 * In UTF-16, supplementary characters (with code points U+10000 and above) are
555 * stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff,
556 * which means that they compare as less than some other BMP characters like U+feff.
557 * This function compares Unicode strings in code point order.
558 * If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.
560 * @param start The start offset in this string at which the compare operation begins.
561 * @param length The number of code units from this string to compare.
562 * @param srcText Another string to compare this one to.
563 * @param srcStart The start offset in that string at which the compare operation begins.
564 * @param srcLength The number of code units from that string to compare.
565 * @return a negative/zero/positive integer corresponding to whether
566 * this string is less than/equal to/greater than the second one
567 * in code point order
570 inline int8_t compareCodePointOrder(int32_t start
,
572 const UnicodeString
& srcText
,
574 int32_t srcLength
) const;
577 * Compare two Unicode strings in code point order.
578 * The result may be different from the results of compare(), operator<, etc.
579 * if supplementary characters are present:
581 * In UTF-16, supplementary characters (with code points U+10000 and above) are
582 * stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff,
583 * which means that they compare as less than some other BMP characters like U+feff.
584 * This function compares Unicode strings in code point order.
585 * If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.
587 * @param srcChars A pointer to another string to compare this one to.
588 * @param srcLength The number of code units from that string to compare.
589 * @return a negative/zero/positive integer corresponding to whether
590 * this string is less than/equal to/greater than the second one
591 * in code point order
594 inline int8_t compareCodePointOrder(const UChar
*srcChars
,
595 int32_t srcLength
) const;
598 * Compare two Unicode strings in code point order.
599 * The result may be different from the results of compare(), operator<, etc.
600 * if supplementary characters are present:
602 * In UTF-16, supplementary characters (with code points U+10000 and above) are
603 * stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff,
604 * which means that they compare as less than some other BMP characters like U+feff.
605 * This function compares Unicode strings in code point order.
606 * If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.
608 * @param start The start offset in this string at which the compare operation begins.
609 * @param length The number of code units from this string to compare.
610 * @param srcChars A pointer to another string to compare this one to.
611 * @return a negative/zero/positive integer corresponding to whether
612 * this string is less than/equal to/greater than the second one
613 * in code point order
616 inline int8_t compareCodePointOrder(int32_t start
,
618 const UChar
*srcChars
) const;
621 * Compare two Unicode strings in code point order.
622 * The result may be different from the results of compare(), operator<, etc.
623 * if supplementary characters are present:
625 * In UTF-16, supplementary characters (with code points U+10000 and above) are
626 * stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff,
627 * which means that they compare as less than some other BMP characters like U+feff.
628 * This function compares Unicode strings in code point order.
629 * If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.
631 * @param start The start offset in this string at which the compare operation begins.
632 * @param length The number of code units from this string to compare.
633 * @param srcChars A pointer to another string to compare this one to.
634 * @param srcStart The start offset in that string at which the compare operation begins.
635 * @param srcLength The number of code units from that string to compare.
636 * @return a negative/zero/positive integer corresponding to whether
637 * this string is less than/equal to/greater than the second one
638 * in code point order
641 inline int8_t compareCodePointOrder(int32_t start
,
643 const UChar
*srcChars
,
645 int32_t srcLength
) const;
648 * Compare two Unicode strings in code point order.
649 * The result may be different from the results of compare(), operator<, etc.
650 * if supplementary characters are present:
652 * In UTF-16, supplementary characters (with code points U+10000 and above) are
653 * stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff,
654 * which means that they compare as less than some other BMP characters like U+feff.
655 * This function compares Unicode strings in code point order.
656 * If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.
658 * @param start The start offset in this string at which the compare operation begins.
659 * @param limit The offset after the last code unit from this string to compare.
660 * @param srcText Another string to compare this one to.
661 * @param srcStart The start offset in that string at which the compare operation begins.
662 * @param srcLimit The offset after the last code unit from that string to compare.
663 * @return a negative/zero/positive integer corresponding to whether
664 * this string is less than/equal to/greater than the second one
665 * in code point order
668 inline int8_t compareCodePointOrderBetween(int32_t start
,
670 const UnicodeString
& srcText
,
672 int32_t srcLimit
) const;
675 * Compare two strings case-insensitively using full case folding.
676 * This is equivalent to this->foldCase(options).compare(text.foldCase(options)).
678 * @param text Another string to compare this one to.
679 * @param options A bit set of options:
680 * - U_FOLD_CASE_DEFAULT or 0 is used for default options:
681 * Comparison in code unit order with default case folding.
683 * - U_COMPARE_CODE_POINT_ORDER
684 * Set to choose code point order instead of code unit order
685 * (see u_strCompare for details).
687 * - U_FOLD_CASE_EXCLUDE_SPECIAL_I
689 * @return A negative, zero, or positive integer indicating the comparison result.
692 inline int8_t caseCompare(const UnicodeString
& text
, uint32_t options
) const;
695 * Compare two strings case-insensitively using full case folding.
696 * This is equivalent to this->foldCase(options).compare(srcText.foldCase(options)).
698 * @param start The start offset in this string at which the compare operation begins.
699 * @param length The number of code units from this string to compare.
700 * @param srcText Another string to compare this one to.
701 * @param options A bit set of options:
702 * - U_FOLD_CASE_DEFAULT or 0 is used for default options:
703 * Comparison in code unit order with default case folding.
705 * - U_COMPARE_CODE_POINT_ORDER
706 * Set to choose code point order instead of code unit order
707 * (see u_strCompare for details).
709 * - U_FOLD_CASE_EXCLUDE_SPECIAL_I
711 * @return A negative, zero, or positive integer indicating the comparison result.
714 inline int8_t caseCompare(int32_t start
,
716 const UnicodeString
& srcText
,
717 uint32_t options
) const;
720 * Compare two strings case-insensitively using full case folding.
721 * This is equivalent to this->foldCase(options).compare(srcText.foldCase(options)).
723 * @param start The start offset in this string at which the compare operation begins.
724 * @param length The number of code units from this string to compare.
725 * @param srcText Another string to compare this one to.
726 * @param srcStart The start offset in that string at which the compare operation begins.
727 * @param srcLength The number of code units from that string to compare.
728 * @param options A bit set of options:
729 * - U_FOLD_CASE_DEFAULT or 0 is used for default options:
730 * Comparison in code unit order with default case folding.
732 * - U_COMPARE_CODE_POINT_ORDER
733 * Set to choose code point order instead of code unit order
734 * (see u_strCompare for details).
736 * - U_FOLD_CASE_EXCLUDE_SPECIAL_I
738 * @return A negative, zero, or positive integer indicating the comparison result.
741 inline int8_t caseCompare(int32_t start
,
743 const UnicodeString
& srcText
,
746 uint32_t options
) const;
749 * Compare two strings case-insensitively using full case folding.
750 * This is equivalent to this->foldCase(options).compare(srcChars.foldCase(options)).
752 * @param srcChars A pointer to another string to compare this one to.
753 * @param srcLength The number of code units from that string to compare.
754 * @param options A bit set of options:
755 * - U_FOLD_CASE_DEFAULT or 0 is used for default options:
756 * Comparison in code unit order with default case folding.
758 * - U_COMPARE_CODE_POINT_ORDER
759 * Set to choose code point order instead of code unit order
760 * (see u_strCompare for details).
762 * - U_FOLD_CASE_EXCLUDE_SPECIAL_I
764 * @return A negative, zero, or positive integer indicating the comparison result.
767 inline int8_t caseCompare(const UChar
*srcChars
,
769 uint32_t options
) const;
772 * Compare two strings case-insensitively using full case folding.
773 * This is equivalent to this->foldCase(options).compare(srcChars.foldCase(options)).
775 * @param start The start offset in this string at which the compare operation begins.
776 * @param length The number of code units from this string to compare.
777 * @param srcChars A pointer to another string to compare this one to.
778 * @param options A bit set of options:
779 * - U_FOLD_CASE_DEFAULT or 0 is used for default options:
780 * Comparison in code unit order with default case folding.
782 * - U_COMPARE_CODE_POINT_ORDER
783 * Set to choose code point order instead of code unit order
784 * (see u_strCompare for details).
786 * - U_FOLD_CASE_EXCLUDE_SPECIAL_I
788 * @return A negative, zero, or positive integer indicating the comparison result.
791 inline int8_t caseCompare(int32_t start
,
793 const UChar
*srcChars
,
794 uint32_t options
) const;
797 * Compare two strings case-insensitively using full case folding.
798 * This is equivalent to this->foldCase(options).compare(srcChars.foldCase(options)).
800 * @param start The start offset in this string at which the compare operation begins.
801 * @param length The number of code units from this string to compare.
802 * @param srcChars A pointer to another string to compare this one to.
803 * @param srcStart The start offset in that string at which the compare operation begins.
804 * @param srcLength The number of code units from that string to compare.
805 * @param options A bit set of options:
806 * - U_FOLD_CASE_DEFAULT or 0 is used for default options:
807 * Comparison in code unit order with default case folding.
809 * - U_COMPARE_CODE_POINT_ORDER
810 * Set to choose code point order instead of code unit order
811 * (see u_strCompare for details).
813 * - U_FOLD_CASE_EXCLUDE_SPECIAL_I
815 * @return A negative, zero, or positive integer indicating the comparison result.
818 inline int8_t caseCompare(int32_t start
,
820 const UChar
*srcChars
,
823 uint32_t options
) const;
826 * Compare two strings case-insensitively using full case folding.
827 * This is equivalent to this->foldCase(options).compareBetween(text.foldCase(options)).
829 * @param start The start offset in this string at which the compare operation begins.
830 * @param limit The offset after the last code unit from this string to compare.
831 * @param srcText Another string to compare this one to.
832 * @param srcStart The start offset in that string at which the compare operation begins.
833 * @param srcLimit The offset after the last code unit from that string to compare.
834 * @param options A bit set of options:
835 * - U_FOLD_CASE_DEFAULT or 0 is used for default options:
836 * Comparison in code unit order with default case folding.
838 * - U_COMPARE_CODE_POINT_ORDER
839 * Set to choose code point order instead of code unit order
840 * (see u_strCompare for details).
842 * - U_FOLD_CASE_EXCLUDE_SPECIAL_I
844 * @return A negative, zero, or positive integer indicating the comparison result.
847 inline int8_t caseCompareBetween(int32_t start
,
849 const UnicodeString
& srcText
,
852 uint32_t options
) const;
855 * Determine if this starts with the characters in <TT>text</TT>
856 * @param text The text to match.
857 * @return TRUE if this starts with the characters in <TT>text</TT>,
861 inline UBool
startsWith(const UnicodeString
& text
) const;
864 * Determine if this starts with the characters in <TT>srcText</TT>
865 * in the range [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
866 * @param srcText The text to match.
867 * @param srcStart the offset into <TT>srcText</TT> to start matching
868 * @param srcLength the number of characters in <TT>srcText</TT> to match
869 * @return TRUE if this starts with the characters in <TT>text</TT>,
873 inline UBool
startsWith(const UnicodeString
& srcText
,
875 int32_t srcLength
) const;
878 * Determine if this starts with the characters in <TT>srcChars</TT>
879 * @param srcChars The characters to match.
880 * @param srcLength the number of characters in <TT>srcChars</TT>
881 * @return TRUE if this starts with the characters in <TT>srcChars</TT>,
885 inline UBool
startsWith(const UChar
*srcChars
,
886 int32_t srcLength
) const;
889 * Determine if this ends with the characters in <TT>srcChars</TT>
890 * in the range [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
891 * @param srcChars The characters to match.
892 * @param srcStart the offset into <TT>srcText</TT> to start matching
893 * @param srcLength the number of characters in <TT>srcChars</TT> to match
894 * @return TRUE if this ends with the characters in <TT>srcChars</TT>, FALSE otherwise
897 inline UBool
startsWith(const UChar
*srcChars
,
899 int32_t srcLength
) const;
902 * Determine if this ends with the characters in <TT>text</TT>
903 * @param text The text to match.
904 * @return TRUE if this ends with the characters in <TT>text</TT>,
908 inline UBool
endsWith(const UnicodeString
& text
) const;
911 * Determine if this ends with the characters in <TT>srcText</TT>
912 * in the range [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
913 * @param srcText The text to match.
914 * @param srcStart the offset into <TT>srcText</TT> to start matching
915 * @param srcLength the number of characters in <TT>srcText</TT> to match
916 * @return TRUE if this ends with the characters in <TT>text</TT>,
920 inline UBool
endsWith(const UnicodeString
& srcText
,
922 int32_t srcLength
) const;
925 * Determine if this ends with the characters in <TT>srcChars</TT>
926 * @param srcChars The characters to match.
927 * @param srcLength the number of characters in <TT>srcChars</TT>
928 * @return TRUE if this ends with the characters in <TT>srcChars</TT>,
932 inline UBool
endsWith(const UChar
*srcChars
,
933 int32_t srcLength
) const;
936 * Determine if this ends with the characters in <TT>srcChars</TT>
937 * in the range [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
938 * @param srcChars The characters to match.
939 * @param srcStart the offset into <TT>srcText</TT> to start matching
940 * @param srcLength the number of characters in <TT>srcChars</TT> to match
941 * @return TRUE if this ends with the characters in <TT>srcChars</TT>,
945 inline UBool
endsWith(const UChar
*srcChars
,
947 int32_t srcLength
) const;
950 /* Searching - bitwise only */
953 * Locate in this the first occurrence of the characters in <TT>text</TT>,
954 * using bitwise comparison.
955 * @param text The text to search for.
956 * @return The offset into this of the start of <TT>text</TT>,
957 * or -1 if not found.
960 inline int32_t indexOf(const UnicodeString
& text
) const;
963 * Locate in this the first occurrence of the characters in <TT>text</TT>
964 * starting at offset <TT>start</TT>, using bitwise comparison.
965 * @param text The text to search for.
966 * @param start The offset at which searching will start.
967 * @return The offset into this of the start of <TT>text</TT>,
968 * or -1 if not found.
971 inline int32_t indexOf(const UnicodeString
& text
,
972 int32_t start
) const;
975 * Locate in this the first occurrence in the range
976 * [<TT>start</TT>, <TT>start + length</TT>) of the characters
977 * in <TT>text</TT>, using bitwise comparison.
978 * @param text The text to search for.
979 * @param start The offset at which searching will start.
980 * @param length The number of characters to search
981 * @return The offset into this of the start of <TT>text</TT>,
982 * or -1 if not found.
985 inline int32_t indexOf(const UnicodeString
& text
,
987 int32_t length
) const;
990 * Locate in this the first occurrence in the range
991 * [<TT>start</TT>, <TT>start + length</TT>) of the characters
992 * in <TT>srcText</TT> in the range
993 * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>),
994 * using bitwise comparison.
995 * @param srcText The text to search for.
996 * @param srcStart the offset into <TT>srcText</TT> at which
998 * @param srcLength the number of characters in <TT>srcText</TT> to match
999 * @param start the offset into this at which to start matching
1000 * @param length the number of characters in this to search
1001 * @return The offset into this of the start of <TT>text</TT>,
1002 * or -1 if not found.
1005 inline int32_t indexOf(const UnicodeString
& srcText
,
1009 int32_t length
) const;
1012 * Locate in this the first occurrence of the characters in
1014 * starting at offset <TT>start</TT>, using bitwise comparison.
1015 * @param srcChars The text to search for.
1016 * @param srcLength the number of characters in <TT>srcChars</TT> to match
1017 * @param start the offset into this at which to start matching
1018 * @return The offset into this of the start of <TT>text</TT>,
1019 * or -1 if not found.
1022 inline int32_t indexOf(const UChar
*srcChars
,
1024 int32_t start
) const;
1027 * Locate in this the first occurrence in the range
1028 * [<TT>start</TT>, <TT>start + length</TT>) of the characters
1029 * in <TT>srcChars</TT>, using bitwise comparison.
1030 * @param srcChars The text to search for.
1031 * @param srcLength the number of characters in <TT>srcChars</TT>
1032 * @param start The offset at which searching will start.
1033 * @param length The number of characters to search
1034 * @return The offset into this of the start of <TT>srcChars</TT>,
1035 * or -1 if not found.
1038 inline int32_t indexOf(const UChar
*srcChars
,
1041 int32_t length
) const;
1044 * Locate in this the first occurrence in the range
1045 * [<TT>start</TT>, <TT>start + length</TT>) of the characters
1046 * in <TT>srcChars</TT> in the range
1047 * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>),
1048 * using bitwise comparison.
1049 * @param srcChars The text to search for.
1050 * @param srcStart the offset into <TT>srcChars</TT> at which
1052 * @param srcLength the number of characters in <TT>srcChars</TT> to match
1053 * @param start the offset into this at which to start matching
1054 * @param length the number of characters in this to search
1055 * @return The offset into this of the start of <TT>text</TT>,
1056 * or -1 if not found.
1059 int32_t indexOf(const UChar
*srcChars
,
1063 int32_t length
) const;
1066 * Locate in this the first occurrence of the BMP code point <code>c</code>,
1067 * using bitwise comparison.
1068 * @param c The code unit to search for.
1069 * @return The offset into this of <TT>c</TT>, or -1 if not found.
1072 inline int32_t indexOf(UChar c
) const;
1075 * Locate in this the first occurrence of the code point <TT>c</TT>,
1076 * using bitwise comparison.
1078 * @param c The code point to search for.
1079 * @return The offset into this of <TT>c</TT>, or -1 if not found.
1082 inline int32_t indexOf(UChar32 c
) const;
1085 * Locate in this the first occurrence of the BMP code point <code>c</code>,
1086 * starting at offset <TT>start</TT>, using bitwise comparison.
1087 * @param c The code unit to search for.
1088 * @param start The offset at which searching will start.
1089 * @return The offset into this of <TT>c</TT>, or -1 if not found.
1092 inline int32_t indexOf(UChar c
,
1093 int32_t start
) const;
1096 * Locate in this the first occurrence of the code point <TT>c</TT>
1097 * starting at offset <TT>start</TT>, using bitwise comparison.
1099 * @param c The code point to search for.
1100 * @param start The offset at which searching will start.
1101 * @return The offset into this of <TT>c</TT>, or -1 if not found.
1104 inline int32_t indexOf(UChar32 c
,
1105 int32_t start
) const;
1108 * Locate in this the first occurrence of the BMP code point <code>c</code>
1109 * in the range [<TT>start</TT>, <TT>start + length</TT>),
1110 * using bitwise comparison.
1111 * @param c The code unit to search for.
1112 * @param start the offset into this at which to start matching
1113 * @param length the number of characters in this to search
1114 * @return The offset into this of <TT>c</TT>, or -1 if not found.
1117 inline int32_t indexOf(UChar c
,
1119 int32_t length
) const;
1122 * Locate in this the first occurrence of the code point <TT>c</TT>
1123 * in the range [<TT>start</TT>, <TT>start + length</TT>),
1124 * using bitwise comparison.
1126 * @param c The code point to search for.
1127 * @param start the offset into this at which to start matching
1128 * @param length the number of characters in this to search
1129 * @return The offset into this of <TT>c</TT>, or -1 if not found.
1132 inline int32_t indexOf(UChar32 c
,
1134 int32_t length
) const;
1137 * Locate in this the last occurrence of the characters in <TT>text</TT>,
1138 * using bitwise comparison.
1139 * @param text The text to search for.
1140 * @return The offset into this of the start of <TT>text</TT>,
1141 * or -1 if not found.
1144 inline int32_t lastIndexOf(const UnicodeString
& text
) const;
1147 * Locate in this the last occurrence of the characters in <TT>text</TT>
1148 * starting at offset <TT>start</TT>, using bitwise comparison.
1149 * @param text The text to search for.
1150 * @param start The offset at which searching will start.
1151 * @return The offset into this of the start of <TT>text</TT>,
1152 * or -1 if not found.
1155 inline int32_t lastIndexOf(const UnicodeString
& text
,
1156 int32_t start
) const;
1159 * Locate in this the last occurrence in the range
1160 * [<TT>start</TT>, <TT>start + length</TT>) of the characters
1161 * in <TT>text</TT>, using bitwise comparison.
1162 * @param text The text to search for.
1163 * @param start The offset at which searching will start.
1164 * @param length The number of characters to search
1165 * @return The offset into this of the start of <TT>text</TT>,
1166 * or -1 if not found.
1169 inline int32_t lastIndexOf(const UnicodeString
& text
,
1171 int32_t length
) const;
1174 * Locate in this the last occurrence in the range
1175 * [<TT>start</TT>, <TT>start + length</TT>) of the characters
1176 * in <TT>srcText</TT> in the range
1177 * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>),
1178 * using bitwise comparison.
1179 * @param srcText The text to search for.
1180 * @param srcStart the offset into <TT>srcText</TT> at which
1182 * @param srcLength the number of characters in <TT>srcText</TT> to match
1183 * @param start the offset into this at which to start matching
1184 * @param length the number of characters in this to search
1185 * @return The offset into this of the start of <TT>text</TT>,
1186 * or -1 if not found.
1189 inline int32_t lastIndexOf(const UnicodeString
& srcText
,
1193 int32_t length
) const;
1196 * Locate in this the last occurrence of the characters in <TT>srcChars</TT>
1197 * starting at offset <TT>start</TT>, using bitwise comparison.
1198 * @param srcChars The text to search for.
1199 * @param srcLength the number of characters in <TT>srcChars</TT> to match
1200 * @param start the offset into this at which to start matching
1201 * @return The offset into this of the start of <TT>text</TT>,
1202 * or -1 if not found.
1205 inline int32_t lastIndexOf(const UChar
*srcChars
,
1207 int32_t start
) const;
1210 * Locate in this the last occurrence in the range
1211 * [<TT>start</TT>, <TT>start + length</TT>) of the characters
1212 * in <TT>srcChars</TT>, using bitwise comparison.
1213 * @param srcChars The text to search for.
1214 * @param srcLength the number of characters in <TT>srcChars</TT>
1215 * @param start The offset at which searching will start.
1216 * @param length The number of characters to search
1217 * @return The offset into this of the start of <TT>srcChars</TT>,
1218 * or -1 if not found.
1221 inline int32_t lastIndexOf(const UChar
*srcChars
,
1224 int32_t length
) const;
1227 * Locate in this the last occurrence in the range
1228 * [<TT>start</TT>, <TT>start + length</TT>) of the characters
1229 * in <TT>srcChars</TT> in the range
1230 * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>),
1231 * using bitwise comparison.
1232 * @param srcChars The text to search for.
1233 * @param srcStart the offset into <TT>srcChars</TT> at which
1235 * @param srcLength the number of characters in <TT>srcChars</TT> to match
1236 * @param start the offset into this at which to start matching
1237 * @param length the number of characters in this to search
1238 * @return The offset into this of the start of <TT>text</TT>,
1239 * or -1 if not found.
1242 int32_t lastIndexOf(const UChar
*srcChars
,
1246 int32_t length
) const;
1249 * Locate in this the last occurrence of the BMP code point <code>c</code>,
1250 * using bitwise comparison.
1251 * @param c The code unit to search for.
1252 * @return The offset into this of <TT>c</TT>, or -1 if not found.
1255 inline int32_t lastIndexOf(UChar c
) const;
1258 * Locate in this the last occurrence of the code point <TT>c</TT>,
1259 * using bitwise comparison.
1261 * @param c The code point to search for.
1262 * @return The offset into this of <TT>c</TT>, or -1 if not found.
1265 inline int32_t lastIndexOf(UChar32 c
) const;
1268 * Locate in this the last occurrence of the BMP code point <code>c</code>
1269 * starting at offset <TT>start</TT>, using bitwise comparison.
1270 * @param c The code unit to search for.
1271 * @param start The offset at which searching will start.
1272 * @return The offset into this of <TT>c</TT>, or -1 if not found.
1275 inline int32_t lastIndexOf(UChar c
,
1276 int32_t start
) const;
1279 * Locate in this the last occurrence of the code point <TT>c</TT>
1280 * starting at offset <TT>start</TT>, using bitwise comparison.
1282 * @param c The code point to search for.
1283 * @param start The offset at which searching will start.
1284 * @return The offset into this of <TT>c</TT>, or -1 if not found.
1287 inline int32_t lastIndexOf(UChar32 c
,
1288 int32_t start
) const;
1291 * Locate in this the last occurrence of the BMP code point <code>c</code>
1292 * in the range [<TT>start</TT>, <TT>start + length</TT>),
1293 * using bitwise comparison.
1294 * @param c The code unit to search for.
1295 * @param start the offset into this at which to start matching
1296 * @param length the number of characters in this to search
1297 * @return The offset into this of <TT>c</TT>, or -1 if not found.
1300 inline int32_t lastIndexOf(UChar c
,
1302 int32_t length
) const;
1305 * Locate in this the last occurrence of the code point <TT>c</TT>
1306 * in the range [<TT>start</TT>, <TT>start + length</TT>),
1307 * using bitwise comparison.
1309 * @param c The code point to search for.
1310 * @param start the offset into this at which to start matching
1311 * @param length the number of characters in this to search
1312 * @return The offset into this of <TT>c</TT>, or -1 if not found.
1315 inline int32_t lastIndexOf(UChar32 c
,
1317 int32_t length
) const;
1320 /* Character access */
1323 * Return the code unit at offset <tt>offset</tt>.
1324 * If the offset is not valid (0..length()-1) then U+ffff is returned.
1325 * @param offset a valid offset into the text
1326 * @return the code unit at offset <tt>offset</tt>
1327 * or 0xffff if the offset is not valid for this string
1330 inline UChar
charAt(int32_t offset
) const;
1333 * Return the code unit at offset <tt>offset</tt>.
1334 * If the offset is not valid (0..length()-1) then U+ffff is returned.
1335 * @param offset a valid offset into the text
1336 * @return the code unit at offset <tt>offset</tt>
1339 inline UChar
operator[] (int32_t offset
) const;
1342 * Return the code point that contains the code unit
1343 * at offset <tt>offset</tt>.
1344 * If the offset is not valid (0..length()-1) then U+ffff is returned.
1345 * @param offset a valid offset into the text
1346 * that indicates the text offset of any of the code units
1347 * that will be assembled into a code point (21-bit value) and returned
1348 * @return the code point of text at <tt>offset</tt>
1349 * or 0xffff if the offset is not valid for this string
1352 UChar32
char32At(int32_t offset
) const;
1355 * Adjust a random-access offset so that
1356 * it points to the beginning of a Unicode character.
1357 * The offset that is passed in points to
1358 * any code unit of a code point,
1359 * while the returned offset will point to the first code unit
1360 * of the same code point.
1361 * In UTF-16, if the input offset points to a second surrogate
1362 * of a surrogate pair, then the returned offset will point
1363 * to the first surrogate.
1364 * @param offset a valid offset into one code point of the text
1365 * @return offset of the first code unit of the same code point
1366 * @see U16_SET_CP_START
1369 int32_t getChar32Start(int32_t offset
) const;
1372 * Adjust a random-access offset so that
1373 * it points behind a Unicode character.
1374 * The offset that is passed in points behind
1375 * any code unit of a code point,
1376 * while the returned offset will point behind the last code unit
1377 * of the same code point.
1378 * In UTF-16, if the input offset points behind the first surrogate
1379 * (i.e., to the second surrogate)
1380 * of a surrogate pair, then the returned offset will point
1381 * behind the second surrogate (i.e., to the first surrogate).
1382 * @param offset a valid offset after any code unit of a code point of the text
1383 * @return offset of the first code unit after the same code point
1384 * @see U16_SET_CP_LIMIT
1387 int32_t getChar32Limit(int32_t offset
) const;
1390 * Move the code unit index along the string by delta code points.
1391 * Interpret the input index as a code unit-based offset into the string,
1392 * move the index forward or backward by delta code points, and
1393 * return the resulting index.
1394 * The input index should point to the first code unit of a code point,
1395 * if there is more than one.
1397 * Both input and output indexes are code unit-based as for all
1398 * string indexes/offsets in ICU (and other libraries, like MBCS char*).
1399 * If delta<0 then the index is moved backward (toward the start of the string).
1400 * If delta>0 then the index is moved forward (toward the end of the string).
1402 * This behaves like CharacterIterator::move32(delta, kCurrent).
1404 * Behavior for out-of-bounds indexes:
1405 * <code>moveIndex32</code> pins the input index to 0..length(), i.e.,
1406 * if the input index<0 then it is pinned to 0;
1407 * if it is index>length() then it is pinned to length().
1408 * Afterwards, the index is moved by <code>delta</code> code points
1409 * forward or backward,
1410 * but no further backward than to 0 and no further forward than to length().
1411 * The resulting index return value will be in between 0 and length(), inclusively.
1415 * // s has code points 'a' U+10000 'b' U+10ffff U+2029
1416 * UnicodeString s=UNICODE_STRING("a\\U00010000b\\U0010ffff\\u2029", 31).unescape();
1418 * // initial index: position of U+10000
1421 * // the following examples will all result in index==4, position of U+10ffff
1423 * // skip 2 code points from some position in the string
1424 * index=s.moveIndex32(index, 2); // skips U+10000 and 'b'
1426 * // go to the 3rd code point from the start of s (0-based)
1427 * index=s.moveIndex32(0, 3); // skips 'a', U+10000, and 'b'
1429 * // go to the next-to-last code point of s
1430 * index=s.moveIndex32(s.length(), -2); // backward-skips U+2029 and U+10ffff
1433 * @param index input code unit index
1434 * @param delta (signed) code point count to move the index forward or backward
1436 * @return the resulting code unit index
1439 int32_t moveIndex32(int32_t index
, int32_t delta
) const;
1441 /* Substring extraction */
1444 * Copy the characters in the range
1445 * [<tt>start</tt>, <tt>start + length</tt>) into the array <tt>dst</tt>,
1446 * beginning at <tt>dstStart</tt>.
1447 * If the string aliases to <code>dst</code> itself as an external buffer,
1448 * then extract() will not copy the contents.
1450 * @param start offset of first character which will be copied into the array
1451 * @param length the number of characters to extract
1452 * @param dst array in which to copy characters. The length of <tt>dst</tt>
1453 * must be at least (<tt>dstStart + length</tt>).
1454 * @param dstStart the offset in <TT>dst</TT> where the first character
1458 inline void extract(int32_t start
,
1461 int32_t dstStart
= 0) const;
1464 * Copy the contents of the string into dest.
1465 * This is a convenience function that
1466 * checks if there is enough space in dest,
1467 * extracts the entire string if possible,
1468 * and NUL-terminates dest if possible.
1470 * If the string fits into dest but cannot be NUL-terminated
1471 * (length()==destCapacity) then the error code is set to U_STRING_NOT_TERMINATED_WARNING.
1472 * If the string itself does not fit into dest
1473 * (length()>destCapacity) then the error code is set to U_BUFFER_OVERFLOW_ERROR.
1475 * If the string aliases to <code>dest</code> itself as an external buffer,
1476 * then extract() will not copy the contents.
1478 * @param dest Destination string buffer.
1479 * @param destCapacity Number of UChars available at dest.
1480 * @param errorCode ICU error code.
1485 extract(UChar
*dest
, int32_t destCapacity
,
1486 UErrorCode
&errorCode
) const;
1489 * Copy the characters in the range
1490 * [<tt>start</tt>, <tt>start + length</tt>) into the UnicodeString
1492 * @param start offset of first character which will be copied
1493 * @param length the number of characters to extract
1494 * @param target UnicodeString into which to copy characters.
1495 * @return A reference to <TT>target</TT>
1498 inline void extract(int32_t start
,
1500 UnicodeString
& target
) const;
1503 * Copy the characters in the range [<tt>start</tt>, <tt>limit</tt>)
1504 * into the array <tt>dst</tt>, beginning at <tt>dstStart</tt>.
1505 * @param start offset of first character which will be copied into the array
1506 * @param limit offset immediately following the last character to be copied
1507 * @param dst array in which to copy characters. The length of <tt>dst</tt>
1508 * must be at least (<tt>dstStart + (limit - start)</tt>).
1509 * @param dstStart the offset in <TT>dst</TT> where the first character
1513 inline void extractBetween(int32_t start
,
1516 int32_t dstStart
= 0) const;
1519 * Copy the characters in the range [<tt>start</tt>, <tt>limit</tt>)
1520 * into the UnicodeString <tt>target</tt>. Replaceable API.
1521 * @param start offset of first character which will be copied
1522 * @param limit offset immediately following the last character to be copied
1523 * @param target UnicodeString into which to copy characters.
1524 * @return A reference to <TT>target</TT>
1527 virtual void extractBetween(int32_t start
,
1529 UnicodeString
& target
) const;
1532 * Copy the characters in the range
1533 * [<tt>start</TT>, <tt>start + startLength</TT>) into an array of characters.
1534 * All characters must be invariant (see utypes.h).
1535 * Use US_INV as the last, signature-distinguishing parameter.
1537 * This function does not write any more than <code>targetCapacity</code>
1538 * characters but returns the length of the entire output string
1539 * so that one can allocate a larger buffer and call the function again
1541 * The output string is NUL-terminated if possible.
1543 * @param start offset of first character which will be copied
1544 * @param startLength the number of characters to extract
1545 * @param target the target buffer for extraction, can be NULL
1546 * if targetLength is 0
1547 * @param targetCapacity the length of the target buffer
1548 * @param inv Signature-distinguishing paramater, use US_INV.
1549 * @return the output string length, not including the terminating NUL
1552 int32_t extract(int32_t start
,
1553 int32_t startLength
,
1555 int32_t targetCapacity
,
1556 enum EInvariant inv
) const;
1558 #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
1561 * Copy the characters in the range
1562 * [<tt>start</TT>, <tt>start + length</TT>) into an array of characters
1563 * in the platform's default codepage.
1564 * This function does not write any more than <code>targetLength</code>
1565 * characters but returns the length of the entire output string
1566 * so that one can allocate a larger buffer and call the function again
1568 * The output string is NUL-terminated if possible.
1570 * @param start offset of first character which will be copied
1571 * @param startLength the number of characters to extract
1572 * @param target the target buffer for extraction
1573 * @param targetLength the length of the target buffer
1574 * If <TT>target</TT> is NULL, then the number of bytes required for
1575 * <TT>target</TT> is returned.
1576 * @return the output string length, not including the terminating NUL
1579 int32_t extract(int32_t start
,
1580 int32_t startLength
,
1582 uint32_t targetLength
) const;
1586 #if !UCONFIG_NO_CONVERSION
1589 * Copy the characters in the range
1590 * [<tt>start</TT>, <tt>start + length</TT>) into an array of characters
1591 * in a specified codepage.
1592 * The output string is NUL-terminated.
1594 * Recommendation: For invariant-character strings use
1595 * extract(int32_t start, int32_t length, char *target, int32_t targetCapacity, enum EInvariant inv) const
1596 * because it avoids object code dependencies of UnicodeString on
1597 * the conversion code.
1599 * @param start offset of first character which will be copied
1600 * @param startLength the number of characters to extract
1601 * @param target the target buffer for extraction
1602 * @param codepage the desired codepage for the characters. 0 has
1603 * the special meaning of the default codepage
1604 * If <code>codepage</code> is an empty string (<code>""</code>),
1605 * then a simple conversion is performed on the codepage-invariant
1606 * subset ("invariant characters") of the platform encoding. See utypes.h.
1607 * If <TT>target</TT> is NULL, then the number of bytes required for
1608 * <TT>target</TT> is returned. It is assumed that the target is big enough
1609 * to fit all of the characters.
1610 * @return the output string length, not including the terminating NUL
1613 inline int32_t extract(int32_t start
,
1614 int32_t startLength
,
1616 const char *codepage
= 0) const;
1619 * Copy the characters in the range
1620 * [<tt>start</TT>, <tt>start + length</TT>) into an array of characters
1621 * in a specified codepage.
1622 * This function does not write any more than <code>targetLength</code>
1623 * characters but returns the length of the entire output string
1624 * so that one can allocate a larger buffer and call the function again
1626 * The output string is NUL-terminated if possible.
1628 * Recommendation: For invariant-character strings use
1629 * extract(int32_t start, int32_t length, char *target, int32_t targetCapacity, enum EInvariant inv) const
1630 * because it avoids object code dependencies of UnicodeString on
1631 * the conversion code.
1633 * @param start offset of first character which will be copied
1634 * @param startLength the number of characters to extract
1635 * @param target the target buffer for extraction
1636 * @param targetLength the length of the target buffer
1637 * @param codepage the desired codepage for the characters. 0 has
1638 * the special meaning of the default codepage
1639 * If <code>codepage</code> is an empty string (<code>""</code>),
1640 * then a simple conversion is performed on the codepage-invariant
1641 * subset ("invariant characters") of the platform encoding. See utypes.h.
1642 * If <TT>target</TT> is NULL, then the number of bytes required for
1643 * <TT>target</TT> is returned.
1644 * @return the output string length, not including the terminating NUL
1647 int32_t extract(int32_t start
,
1648 int32_t startLength
,
1650 uint32_t targetLength
,
1651 const char *codepage
) const;
1654 * Convert the UnicodeString into a codepage string using an existing UConverter.
1655 * The output string is NUL-terminated if possible.
1657 * This function avoids the overhead of opening and closing a converter if
1658 * multiple strings are extracted.
1660 * @param dest destination string buffer, can be NULL if destCapacity==0
1661 * @param destCapacity the number of chars available at dest
1662 * @param cnv the converter object to be used (ucnv_resetFromUnicode() will be called),
1663 * or NULL for the default converter
1664 * @param errorCode normal ICU error code
1665 * @return the length of the output string, not counting the terminating NUL;
1666 * if the length is greater than destCapacity, then the string will not fit
1667 * and a buffer of the indicated length would need to be passed in
1670 int32_t extract(char *dest
, int32_t destCapacity
,
1672 UErrorCode
&errorCode
) const;
1677 * Create a temporary substring for the specified range.
1678 * Unlike the substring constructor and setTo() functions,
1679 * the object returned here will be a read-only alias (using getBuffer())
1680 * rather than copying the text.
1681 * As a result, this substring operation is much faster but requires
1682 * that the original string not be modified or deleted during the lifetime
1683 * of the returned substring object.
1684 * @param start offset of the first character visible in the substring
1685 * @param length length of the substring
1686 * @return a read-only alias UnicodeString object for the substring
1689 UnicodeString
tempSubString(int32_t start
=0, int32_t length
=INT32_MAX
) const;
1692 * Create a temporary substring for the specified range.
1693 * Same as tempSubString(start, length) except that the substring range
1694 * is specified as a (start, limit) pair (with an exclusive limit index)
1695 * rather than a (start, length) pair.
1696 * @param start offset of the first character visible in the substring
1697 * @param limit offset immediately following the last character visible in the substring
1698 * @return a read-only alias UnicodeString object for the substring
1701 inline UnicodeString
tempSubStringBetween(int32_t start
, int32_t limit
=INT32_MAX
) const;
1704 * Convert the UnicodeString to UTF-8 and write the result
1705 * to a ByteSink. This is called by toUTF8String().
1706 * Unpaired surrogates are replaced with U+FFFD.
1707 * Calls u_strToUTF8WithSub().
1709 * @param sink A ByteSink to which the UTF-8 version of the string is written.
1710 * sink.Flush() is called at the end.
1714 void toUTF8(ByteSink
&sink
) const;
1716 #if U_HAVE_STD_STRING
1719 * Convert the UnicodeString to UTF-8 and append the result
1720 * to a standard string.
1721 * Unpaired surrogates are replaced with U+FFFD.
1724 * @param result A standard string (or a compatible object)
1725 * to which the UTF-8 version of the string is appended.
1726 * @return The string object.
1730 template<typename StringClass
>
1731 StringClass
&toUTF8String(StringClass
&result
) const {
1732 StringByteSink
<StringClass
> sbs(&result
);
1740 * Convert the UnicodeString to UTF-32.
1741 * Unpaired surrogates are replaced with U+FFFD.
1742 * Calls u_strToUTF32WithSub().
1744 * @param utf32 destination string buffer, can be NULL if capacity==0
1745 * @param capacity the number of UChar32s available at utf32
1746 * @param errorCode Standard ICU error code. Its input value must
1747 * pass the U_SUCCESS() test, or else the function returns
1748 * immediately. Check for U_FAILURE() on output or use with
1749 * function chaining. (See User Guide for details.)
1750 * @return The length of the UTF-32 string.
1754 int32_t toUTF32(UChar32
*utf32
, int32_t capacity
, UErrorCode
&errorCode
) const;
1756 /* Length operations */
1759 * Return the length of the UnicodeString object.
1760 * The length is the number of UChar code units are in the UnicodeString.
1761 * If you want the number of code points, please use countChar32().
1762 * @return the length of the UnicodeString object
1766 inline int32_t length(void) const;
1769 * Count Unicode code points in the length UChar code units of the string.
1770 * A code point may occupy either one or two UChar code units.
1771 * Counting code points involves reading all code units.
1773 * This functions is basically the inverse of moveIndex32().
1775 * @param start the index of the first code unit to check
1776 * @param length the number of UChar code units to check
1777 * @return the number of code points in the specified code units
1782 countChar32(int32_t start
=0, int32_t length
=INT32_MAX
) const;
1785 * Check if the length UChar code units of the string
1786 * contain more Unicode code points than a certain number.
1787 * This is more efficient than counting all code points in this part of the string
1788 * and comparing that number with a threshold.
1789 * This function may not need to scan the string at all if the length
1790 * falls within a certain range, and
1791 * never needs to count more than 'number+1' code points.
1792 * Logically equivalent to (countChar32(start, length)>number).
1793 * A Unicode code point may occupy either one or two UChar code units.
1795 * @param start the index of the first code unit to check (0 for the entire string)
1796 * @param length the number of UChar code units to check
1797 * (use INT32_MAX for the entire string; remember that start/length
1798 * values are pinned)
1799 * @param number The number of code points in the (sub)string is compared against
1800 * the 'number' parameter.
1801 * @return Boolean value for whether the string contains more Unicode code points
1802 * than 'number'. Same as (u_countChar32(s, length)>number).
1804 * @see u_strHasMoreChar32Than
1808 hasMoreChar32Than(int32_t start
, int32_t length
, int32_t number
) const;
1811 * Determine if this string is empty.
1812 * @return TRUE if this string contains 0 characters, FALSE otherwise.
1815 inline UBool
isEmpty(void) const;
1818 * Return the capacity of the internal buffer of the UnicodeString object.
1819 * This is useful together with the getBuffer functions.
1820 * See there for details.
1822 * @return the number of UChars available in the internal buffer
1826 inline int32_t getCapacity(void) const;
1828 /* Other operations */
1831 * Generate a hash code for this object.
1832 * @return The hash code of this UnicodeString.
1835 inline int32_t hashCode(void) const;
1838 * Determine if this object contains a valid string.
1839 * A bogus string has no value. It is different from an empty string,
1840 * although in both cases isEmpty() returns TRUE and length() returns 0.
1841 * setToBogus() and isBogus() can be used to indicate that no string value is available.
1842 * For a bogus string, getBuffer() and getTerminatedBuffer() return NULL, and
1843 * length() returns 0.
1845 * @return TRUE if the string is bogus/invalid, FALSE otherwise
1849 inline UBool
isBogus(void) const;
1852 //========================================
1854 //========================================
1856 /* Assignment operations */
1859 * Assignment operator. Replace the characters in this UnicodeString
1860 * with the characters from <TT>srcText</TT>.
1862 * Starting with ICU 2.4, the assignment operator and the copy constructor
1863 * allocate a new buffer and copy the buffer contents even for readonly aliases.
1864 * By contrast, the fastCopyFrom() function implements the old,
1865 * more efficient but less safe behavior
1866 * of making this string also a readonly alias to the same buffer.
1868 * If the source object has an "open" buffer from getBuffer(minCapacity),
1869 * then the copy is an empty string.
1871 * @param srcText The text containing the characters to replace
1872 * @return a reference to this
1876 UnicodeString
&operator=(const UnicodeString
&srcText
);
1879 * Almost the same as the assignment operator.
1880 * Replace the characters in this UnicodeString
1881 * with the characters from <code>srcText</code>.
1883 * This function works the same as the assignment operator
1884 * for all strings except for ones that are readonly aliases.
1886 * Starting with ICU 2.4, the assignment operator and the copy constructor
1887 * allocate a new buffer and copy the buffer contents even for readonly aliases.
1888 * This function implements the old, more efficient but less safe behavior
1889 * of making this string also a readonly alias to the same buffer.
1891 * The fastCopyFrom function must be used only if it is known that the lifetime of
1892 * this UnicodeString does not exceed the lifetime of the aliased buffer
1893 * including its contents, for example for strings from resource bundles
1894 * or aliases to string constants.
1896 * If the source object has an "open" buffer from getBuffer(minCapacity),
1897 * then the copy is an empty string.
1899 * @param src The text containing the characters to replace.
1900 * @return a reference to this
1903 UnicodeString
&fastCopyFrom(const UnicodeString
&src
);
1905 #ifndef U_HIDE_DRAFT_API
1906 #if U_HAVE_RVALUE_REFERENCES
1908 * Move assignment operator, might leave src in bogus state.
1909 * This string will have the same contents and state that the source string had.
1910 * The behavior is undefined if *this and src are the same object.
1911 * @param src source string
1915 UnicodeString
&operator=(UnicodeString
&&src
) U_NOEXCEPT
{
1916 return moveFrom(src
);
1920 * Move assignment, might leave src in bogus state.
1921 * This string will have the same contents and state that the source string had.
1922 * The behavior is undefined if *this and src are the same object.
1924 * Can be called explicitly, does not need C++11 support.
1925 * @param src source string
1929 UnicodeString
&moveFrom(UnicodeString
&src
) U_NOEXCEPT
;
1933 * @param other other string
1936 void swap(UnicodeString
&other
) U_NOEXCEPT
;
1937 #endif /* U_HIDE_DRAFT_API */
1940 * Non-member UnicodeString swap function.
1941 * @param s1 will get s2's contents and state
1942 * @param s2 will get s1's contents and state
1945 friend U_COMMON_API
inline void U_EXPORT2
1946 swap(UnicodeString
&s1
, UnicodeString
&s2
) U_NOEXCEPT
{
1951 * Assignment operator. Replace the characters in this UnicodeString
1952 * with the code unit <TT>ch</TT>.
1953 * @param ch the code unit to replace
1954 * @return a reference to this
1957 inline UnicodeString
& operator= (UChar ch
);
1960 * Assignment operator. Replace the characters in this UnicodeString
1961 * with the code point <TT>ch</TT>.
1962 * @param ch the code point to replace
1963 * @return a reference to this
1966 inline UnicodeString
& operator= (UChar32 ch
);
1969 * Set the text in the UnicodeString object to the characters
1970 * in <TT>srcText</TT> in the range
1971 * [<TT>srcStart</TT>, <TT>srcText.length()</TT>).
1972 * <TT>srcText</TT> is not modified.
1973 * @param srcText the source for the new characters
1974 * @param srcStart the offset into <TT>srcText</TT> where new characters
1976 * @return a reference to this
1979 inline UnicodeString
& setTo(const UnicodeString
& srcText
,
1983 * Set the text in the UnicodeString object to the characters
1984 * in <TT>srcText</TT> in the range
1985 * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
1986 * <TT>srcText</TT> is not modified.
1987 * @param srcText the source for the new characters
1988 * @param srcStart the offset into <TT>srcText</TT> where new characters
1990 * @param srcLength the number of characters in <TT>srcText</TT> in the
1992 * @return a reference to this
1995 inline UnicodeString
& setTo(const UnicodeString
& srcText
,
2000 * Set the text in the UnicodeString object to the characters in
2002 * <TT>srcText</TT> is not modified.
2003 * @param srcText the source for the new characters
2004 * @return a reference to this
2007 inline UnicodeString
& setTo(const UnicodeString
& srcText
);
2010 * Set the characters in the UnicodeString object to the characters
2011 * in <TT>srcChars</TT>. <TT>srcChars</TT> is not modified.
2012 * @param srcChars the source for the new characters
2013 * @param srcLength the number of Unicode characters in srcChars.
2014 * @return a reference to this
2017 inline UnicodeString
& setTo(const UChar
*srcChars
,
2021 * Set the characters in the UnicodeString object to the code unit
2023 * @param srcChar the code unit which becomes the UnicodeString's character
2025 * @return a reference to this
2028 UnicodeString
& setTo(UChar srcChar
);
2031 * Set the characters in the UnicodeString object to the code point
2033 * @param srcChar the code point which becomes the UnicodeString's character
2035 * @return a reference to this
2038 UnicodeString
& setTo(UChar32 srcChar
);
2041 * Aliasing setTo() function, analogous to the readonly-aliasing UChar* constructor.
2042 * The text will be used for the UnicodeString object, but
2043 * it will not be released when the UnicodeString is destroyed.
2044 * This has copy-on-write semantics:
2045 * When the string is modified, then the buffer is first copied into
2046 * newly allocated memory.
2047 * The aliased buffer is never modified.
2049 * In an assignment to another UnicodeString, when using the copy constructor
2050 * or the assignment operator, the text will be copied.
2051 * When using fastCopyFrom(), the text will be aliased again,
2052 * so that both strings then alias the same readonly-text.
2054 * @param isTerminated specifies if <code>text</code> is <code>NUL</code>-terminated.
2055 * This must be true if <code>textLength==-1</code>.
2056 * @param text The characters to alias for the UnicodeString.
2057 * @param textLength The number of Unicode characters in <code>text</code> to alias.
2058 * If -1, then this constructor will determine the length
2059 * by calling <code>u_strlen()</code>.
2060 * @return a reference to this
2063 UnicodeString
&setTo(UBool isTerminated
,
2065 int32_t textLength
);
2068 * Aliasing setTo() function, analogous to the writable-aliasing UChar* constructor.
2069 * The text will be used for the UnicodeString object, but
2070 * it will not be released when the UnicodeString is destroyed.
2071 * This has write-through semantics:
2072 * For as long as the capacity of the buffer is sufficient, write operations
2073 * will directly affect the buffer. When more capacity is necessary, then
2074 * a new buffer will be allocated and the contents copied as with regularly
2075 * constructed strings.
2076 * In an assignment to another UnicodeString, the buffer will be copied.
2077 * The extract(UChar *dst) function detects whether the dst pointer is the same
2078 * as the string buffer itself and will in this case not copy the contents.
2080 * @param buffer The characters to alias for the UnicodeString.
2081 * @param buffLength The number of Unicode characters in <code>buffer</code> to alias.
2082 * @param buffCapacity The size of <code>buffer</code> in UChars.
2083 * @return a reference to this
2086 UnicodeString
&setTo(UChar
*buffer
,
2088 int32_t buffCapacity
);
2091 * Make this UnicodeString object invalid.
2092 * The string will test TRUE with isBogus().
2094 * A bogus string has no value. It is different from an empty string.
2095 * It can be used to indicate that no string value is available.
2096 * getBuffer() and getTerminatedBuffer() return NULL, and
2097 * length() returns 0.
2099 * This utility function is used throughout the UnicodeString
2100 * implementation to indicate that a UnicodeString operation failed,
2101 * and may be used in other functions,
2102 * especially but not exclusively when such functions do not
2103 * take a UErrorCode for simplicity.
2105 * The following methods, and no others, will clear a string object's bogus flag:
2107 * - remove(0, INT32_MAX)
2109 * - operator=() (assignment operator)
2112 * The simplest ways to turn a bogus string into an empty one
2113 * is to use the remove() function.
2114 * Examples for other functions that are equivalent to "set to empty string":
2117 * s.remove(); // set to an empty string (remove all), or
2118 * s.remove(0, INT32_MAX); // set to an empty string (remove all), or
2119 * s.truncate(0); // set to an empty string (complete truncation), or
2120 * s=UnicodeString(); // assign an empty string, or
2121 * s.setTo((UChar32)-1); // set to a pseudo code point that is out of range, or
2122 * static const UChar nul=0;
2123 * s.setTo(&nul, 0); // set to an empty C Unicode string
2133 * Set the character at the specified offset to the specified character.
2134 * @param offset A valid offset into the text of the character to set
2135 * @param ch The new character
2136 * @return A reference to this
2139 UnicodeString
& setCharAt(int32_t offset
,
2143 /* Append operations */
2146 * Append operator. Append the code unit <TT>ch</TT> to the UnicodeString
2148 * @param ch the code unit to be appended
2149 * @return a reference to this
2152 inline UnicodeString
& operator+= (UChar ch
);
2155 * Append operator. Append the code point <TT>ch</TT> to the UnicodeString
2157 * @param ch the code point to be appended
2158 * @return a reference to this
2161 inline UnicodeString
& operator+= (UChar32 ch
);
2164 * Append operator. Append the characters in <TT>srcText</TT> to the
2165 * UnicodeString object. <TT>srcText</TT> is not modified.
2166 * @param srcText the source for the new characters
2167 * @return a reference to this
2170 inline UnicodeString
& operator+= (const UnicodeString
& srcText
);
2173 * Append the characters
2174 * in <TT>srcText</TT> in the range
2175 * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>) to the
2176 * UnicodeString object at offset <TT>start</TT>. <TT>srcText</TT>
2178 * @param srcText the source for the new characters
2179 * @param srcStart the offset into <TT>srcText</TT> where new characters
2181 * @param srcLength the number of characters in <TT>srcText</TT> in
2183 * @return a reference to this
2186 inline UnicodeString
& append(const UnicodeString
& srcText
,
2191 * Append the characters in <TT>srcText</TT> to the UnicodeString object.
2192 * <TT>srcText</TT> is not modified.
2193 * @param srcText the source for the new characters
2194 * @return a reference to this
2197 inline UnicodeString
& append(const UnicodeString
& srcText
);
2200 * Append the characters in <TT>srcChars</TT> in the range
2201 * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>) to the UnicodeString
2203 * <TT>start</TT>. <TT>srcChars</TT> is not modified.
2204 * @param srcChars the source for the new characters
2205 * @param srcStart the offset into <TT>srcChars</TT> where new characters
2207 * @param srcLength the number of characters in <TT>srcChars</TT> in
2208 * the append string; can be -1 if <TT>srcChars</TT> is NUL-terminated
2209 * @return a reference to this
2212 inline UnicodeString
& append(const UChar
*srcChars
,
2217 * Append the characters in <TT>srcChars</TT> to the UnicodeString object
2218 * at offset <TT>start</TT>. <TT>srcChars</TT> is not modified.
2219 * @param srcChars the source for the new characters
2220 * @param srcLength the number of Unicode characters in <TT>srcChars</TT>;
2221 * can be -1 if <TT>srcChars</TT> is NUL-terminated
2222 * @return a reference to this
2225 inline UnicodeString
& append(const UChar
*srcChars
,
2229 * Append the code unit <TT>srcChar</TT> to the UnicodeString object.
2230 * @param srcChar the code unit to append
2231 * @return a reference to this
2234 inline UnicodeString
& append(UChar srcChar
);
2237 * Append the code point <TT>srcChar</TT> to the UnicodeString object.
2238 * @param srcChar the code point to append
2239 * @return a reference to this
2242 UnicodeString
& append(UChar32 srcChar
);
2245 /* Insert operations */
2248 * Insert the characters in <TT>srcText</TT> in the range
2249 * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>) into the UnicodeString
2250 * object at offset <TT>start</TT>. <TT>srcText</TT> is not modified.
2251 * @param start the offset where the insertion begins
2252 * @param srcText the source for the new characters
2253 * @param srcStart the offset into <TT>srcText</TT> where new characters
2255 * @param srcLength the number of characters in <TT>srcText</TT> in
2257 * @return a reference to this
2260 inline UnicodeString
& insert(int32_t start
,
2261 const UnicodeString
& srcText
,
2266 * Insert the characters in <TT>srcText</TT> into the UnicodeString object
2267 * at offset <TT>start</TT>. <TT>srcText</TT> is not modified.
2268 * @param start the offset where the insertion begins
2269 * @param srcText the source for the new characters
2270 * @return a reference to this
2273 inline UnicodeString
& insert(int32_t start
,
2274 const UnicodeString
& srcText
);
2277 * Insert the characters in <TT>srcChars</TT> in the range
2278 * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>) into the UnicodeString
2279 * object at offset <TT>start</TT>. <TT>srcChars</TT> is not modified.
2280 * @param start the offset at which the insertion begins
2281 * @param srcChars the source for the new characters
2282 * @param srcStart the offset into <TT>srcChars</TT> where new characters
2284 * @param srcLength the number of characters in <TT>srcChars</TT>
2285 * in the insert string
2286 * @return a reference to this
2289 inline UnicodeString
& insert(int32_t start
,
2290 const UChar
*srcChars
,
2295 * Insert the characters in <TT>srcChars</TT> into the UnicodeString object
2296 * at offset <TT>start</TT>. <TT>srcChars</TT> is not modified.
2297 * @param start the offset where the insertion begins
2298 * @param srcChars the source for the new characters
2299 * @param srcLength the number of Unicode characters in srcChars.
2300 * @return a reference to this
2303 inline UnicodeString
& insert(int32_t start
,
2304 const UChar
*srcChars
,
2308 * Insert the code unit <TT>srcChar</TT> into the UnicodeString object at
2309 * offset <TT>start</TT>.
2310 * @param start the offset at which the insertion occurs
2311 * @param srcChar the code unit to insert
2312 * @return a reference to this
2315 inline UnicodeString
& insert(int32_t start
,
2319 * Insert the code point <TT>srcChar</TT> into the UnicodeString object at
2320 * offset <TT>start</TT>.
2321 * @param start the offset at which the insertion occurs
2322 * @param srcChar the code point to insert
2323 * @return a reference to this
2326 inline UnicodeString
& insert(int32_t start
,
2330 /* Replace operations */
2333 * Replace the characters in the range
2334 * [<TT>start</TT>, <TT>start + length</TT>) with the characters in
2335 * <TT>srcText</TT> in the range
2336 * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
2337 * <TT>srcText</TT> is not modified.
2338 * @param start the offset at which the replace operation begins
2339 * @param length the number of characters to replace. The character at
2340 * <TT>start + length</TT> is not modified.
2341 * @param srcText the source for the new characters
2342 * @param srcStart the offset into <TT>srcText</TT> where new characters
2344 * @param srcLength the number of characters in <TT>srcText</TT> in
2345 * the replace string
2346 * @return a reference to this
2349 UnicodeString
& replace(int32_t start
,
2351 const UnicodeString
& srcText
,
2356 * Replace the characters in the range
2357 * [<TT>start</TT>, <TT>start + length</TT>)
2358 * with the characters in <TT>srcText</TT>. <TT>srcText</TT> is
2360 * @param start the offset at which the replace operation begins
2361 * @param length the number of characters to replace. The character at
2362 * <TT>start + length</TT> is not modified.
2363 * @param srcText the source for the new characters
2364 * @return a reference to this
2367 UnicodeString
& replace(int32_t start
,
2369 const UnicodeString
& srcText
);
2372 * Replace the characters in the range
2373 * [<TT>start</TT>, <TT>start + length</TT>) with the characters in
2374 * <TT>srcChars</TT> in the range
2375 * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>). <TT>srcChars</TT>
2377 * @param start the offset at which the replace operation begins
2378 * @param length the number of characters to replace. The character at
2379 * <TT>start + length</TT> is not modified.
2380 * @param srcChars the source for the new characters
2381 * @param srcStart the offset into <TT>srcChars</TT> where new characters
2383 * @param srcLength the number of characters in <TT>srcChars</TT>
2384 * in the replace string
2385 * @return a reference to this
2388 UnicodeString
& replace(int32_t start
,
2390 const UChar
*srcChars
,
2395 * Replace the characters in the range
2396 * [<TT>start</TT>, <TT>start + length</TT>) with the characters in
2397 * <TT>srcChars</TT>. <TT>srcChars</TT> is not modified.
2398 * @param start the offset at which the replace operation begins
2399 * @param length number of characters to replace. The character at
2400 * <TT>start + length</TT> is not modified.
2401 * @param srcChars the source for the new characters
2402 * @param srcLength the number of Unicode characters in srcChars
2403 * @return a reference to this
2406 inline UnicodeString
& replace(int32_t start
,
2408 const UChar
*srcChars
,
2412 * Replace the characters in the range
2413 * [<TT>start</TT>, <TT>start + length</TT>) with the code unit
2415 * @param start the offset at which the replace operation begins
2416 * @param length the number of characters to replace. The character at
2417 * <TT>start + length</TT> is not modified.
2418 * @param srcChar the new code unit
2419 * @return a reference to this
2422 inline UnicodeString
& replace(int32_t start
,
2427 * Replace the characters in the range
2428 * [<TT>start</TT>, <TT>start + length</TT>) with the code point
2430 * @param start the offset at which the replace operation begins
2431 * @param length the number of characters to replace. The character at
2432 * <TT>start + length</TT> is not modified.
2433 * @param srcChar the new code point
2434 * @return a reference to this
2437 UnicodeString
& replace(int32_t start
, int32_t length
, UChar32 srcChar
);
2440 * Replace the characters in the range [<TT>start</TT>, <TT>limit</TT>)
2441 * with the characters in <TT>srcText</TT>. <TT>srcText</TT> is not modified.
2442 * @param start the offset at which the replace operation begins
2443 * @param limit the offset immediately following the replace range
2444 * @param srcText the source for the new characters
2445 * @return a reference to this
2448 inline UnicodeString
& replaceBetween(int32_t start
,
2450 const UnicodeString
& srcText
);
2453 * Replace the characters in the range [<TT>start</TT>, <TT>limit</TT>)
2454 * with the characters in <TT>srcText</TT> in the range
2455 * [<TT>srcStart</TT>, <TT>srcLimit</TT>). <TT>srcText</TT> is not modified.
2456 * @param start the offset at which the replace operation begins
2457 * @param limit the offset immediately following the replace range
2458 * @param srcText the source for the new characters
2459 * @param srcStart the offset into <TT>srcChars</TT> where new characters
2461 * @param srcLimit the offset immediately following the range to copy
2462 * in <TT>srcText</TT>
2463 * @return a reference to this
2466 inline UnicodeString
& replaceBetween(int32_t start
,
2468 const UnicodeString
& srcText
,
2473 * Replace a substring of this object with the given text.
2474 * @param start the beginning index, inclusive; <code>0 <= start
2476 * @param limit the ending index, exclusive; <code>start <= limit
2477 * <= length()</code>.
2478 * @param text the text to replace characters <code>start</code>
2479 * to <code>limit - 1</code>
2482 virtual void handleReplaceBetween(int32_t start
,
2484 const UnicodeString
& text
);
2488 * @return TRUE if it has MetaData
2491 virtual UBool
hasMetaData() const;
2494 * Copy a substring of this object, retaining attribute (out-of-band)
2495 * information. This method is used to duplicate or reorder substrings.
2496 * The destination index must not overlap the source range.
2498 * @param start the beginning index, inclusive; <code>0 <= start <=
2500 * @param limit the ending index, exclusive; <code>start <= limit <=
2502 * @param dest the destination index. The characters from
2503 * <code>start..limit-1</code> will be copied to <code>dest</code>.
2504 * Implementations of this method may assume that <code>dest <= start ||
2505 * dest >= limit</code>.
2508 virtual void copy(int32_t start
, int32_t limit
, int32_t dest
);
2510 /* Search and replace operations */
2513 * Replace all occurrences of characters in oldText with the characters
2515 * @param oldText the text containing the search text
2516 * @param newText the text containing the replacement text
2517 * @return a reference to this
2520 inline UnicodeString
& findAndReplace(const UnicodeString
& oldText
,
2521 const UnicodeString
& newText
);
2524 * Replace all occurrences of characters in oldText with characters
2526 * in the range [<TT>start</TT>, <TT>start + length</TT>).
2527 * @param start the start of the range in which replace will performed
2528 * @param length the length of the range in which replace will be performed
2529 * @param oldText the text containing the search text
2530 * @param newText the text containing the replacement text
2531 * @return a reference to this
2534 inline UnicodeString
& findAndReplace(int32_t start
,
2536 const UnicodeString
& oldText
,
2537 const UnicodeString
& newText
);
2540 * Replace all occurrences of characters in oldText in the range
2541 * [<TT>oldStart</TT>, <TT>oldStart + oldLength</TT>) with the characters
2542 * in newText in the range
2543 * [<TT>newStart</TT>, <TT>newStart + newLength</TT>)
2544 * in the range [<TT>start</TT>, <TT>start + length</TT>).
2545 * @param start the start of the range in which replace will performed
2546 * @param length the length of the range in which replace will be performed
2547 * @param oldText the text containing the search text
2548 * @param oldStart the start of the search range in <TT>oldText</TT>
2549 * @param oldLength the length of the search range in <TT>oldText</TT>
2550 * @param newText the text containing the replacement text
2551 * @param newStart the start of the replacement range in <TT>newText</TT>
2552 * @param newLength the length of the replacement range in <TT>newText</TT>
2553 * @return a reference to this
2556 UnicodeString
& findAndReplace(int32_t start
,
2558 const UnicodeString
& oldText
,
2561 const UnicodeString
& newText
,
2566 /* Remove operations */
2569 * Remove all characters from the UnicodeString object.
2570 * @return a reference to this
2573 inline UnicodeString
& remove(void);
2576 * Remove the characters in the range
2577 * [<TT>start</TT>, <TT>start + length</TT>) from the UnicodeString object.
2578 * @param start the offset of the first character to remove
2579 * @param length the number of characters to remove
2580 * @return a reference to this
2583 inline UnicodeString
& remove(int32_t start
,
2584 int32_t length
= (int32_t)INT32_MAX
);
2587 * Remove the characters in the range
2588 * [<TT>start</TT>, <TT>limit</TT>) from the UnicodeString object.
2589 * @param start the offset of the first character to remove
2590 * @param limit the offset immediately following the range to remove
2591 * @return a reference to this
2594 inline UnicodeString
& removeBetween(int32_t start
,
2595 int32_t limit
= (int32_t)INT32_MAX
);
2598 * Retain only the characters in the range
2599 * [<code>start</code>, <code>limit</code>) from the UnicodeString object.
2600 * Removes characters before <code>start</code> and at and after <code>limit</code>.
2601 * @param start the offset of the first character to retain
2602 * @param limit the offset immediately following the range to retain
2603 * @return a reference to this
2606 inline UnicodeString
&retainBetween(int32_t start
, int32_t limit
= INT32_MAX
);
2608 /* Length operations */
2611 * Pad the start of this UnicodeString with the character <TT>padChar</TT>.
2612 * If the length of this UnicodeString is less than targetLength,
2613 * length() - targetLength copies of padChar will be added to the
2614 * beginning of this UnicodeString.
2615 * @param targetLength the desired length of the string
2616 * @param padChar the character to use for padding. Defaults to
2618 * @return TRUE if the text was padded, FALSE otherwise.
2621 UBool
padLeading(int32_t targetLength
,
2622 UChar padChar
= 0x0020);
2625 * Pad the end of this UnicodeString with the character <TT>padChar</TT>.
2626 * If the length of this UnicodeString is less than targetLength,
2627 * length() - targetLength copies of padChar will be added to the
2628 * end of this UnicodeString.
2629 * @param targetLength the desired length of the string
2630 * @param padChar the character to use for padding. Defaults to
2632 * @return TRUE if the text was padded, FALSE otherwise.
2635 UBool
padTrailing(int32_t targetLength
,
2636 UChar padChar
= 0x0020);
2639 * Truncate this UnicodeString to the <TT>targetLength</TT>.
2640 * @param targetLength the desired length of this UnicodeString.
2641 * @return TRUE if the text was truncated, FALSE otherwise
2644 inline UBool
truncate(int32_t targetLength
);
2647 * Trims leading and trailing whitespace from this UnicodeString.
2648 * @return a reference to this
2651 UnicodeString
& trim(void);
2654 /* Miscellaneous operations */
2657 * Reverse this UnicodeString in place.
2658 * @return a reference to this
2661 inline UnicodeString
& reverse(void);
2664 * Reverse the range [<TT>start</TT>, <TT>start + length</TT>) in
2665 * this UnicodeString.
2666 * @param start the start of the range to reverse
2667 * @param length the number of characters to to reverse
2668 * @return a reference to this
2671 inline UnicodeString
& reverse(int32_t start
,
2675 * Convert the characters in this to UPPER CASE following the conventions of
2676 * the default locale.
2677 * @return A reference to this.
2680 UnicodeString
& toUpper(void);
2683 * Convert the characters in this to UPPER CASE following the conventions of
2684 * a specific locale.
2685 * @param locale The locale containing the conventions to use.
2686 * @return A reference to this.
2689 UnicodeString
& toUpper(const Locale
& locale
);
2692 * Convert the characters in this to lower case following the conventions of
2693 * the default locale.
2694 * @return A reference to this.
2697 UnicodeString
& toLower(void);
2700 * Convert the characters in this to lower case following the conventions of
2701 * a specific locale.
2702 * @param locale The locale containing the conventions to use.
2703 * @return A reference to this.
2706 UnicodeString
& toLower(const Locale
& locale
);
2708 #if !UCONFIG_NO_BREAK_ITERATION
2711 * Titlecase this string, convenience function using the default locale.
2713 * Casing is locale-dependent and context-sensitive.
2714 * Titlecasing uses a break iterator to find the first characters of words
2715 * that are to be titlecased. It titlecases those characters and lowercases
2718 * The titlecase break iterator can be provided to customize for arbitrary
2719 * styles, using rules and dictionaries beyond the standard iterators.
2720 * It may be more efficient to always provide an iterator to avoid
2721 * opening and closing one for each string.
2722 * The standard titlecase iterator for the root locale implements the
2723 * algorithm of Unicode TR 21.
2725 * This function uses only the setText(), first() and next() methods of the
2726 * provided break iterator.
2728 * @param titleIter A break iterator to find the first characters of words
2729 * that are to be titlecased.
2730 * If none is provided (0), then a standard titlecase
2731 * break iterator is opened.
2732 * Otherwise the provided iterator is set to the string's text.
2733 * @return A reference to this.
2736 UnicodeString
&toTitle(BreakIterator
*titleIter
);
2739 * Titlecase this string.
2741 * Casing is locale-dependent and context-sensitive.
2742 * Titlecasing uses a break iterator to find the first characters of words
2743 * that are to be titlecased. It titlecases those characters and lowercases
2746 * The titlecase break iterator can be provided to customize for arbitrary
2747 * styles, using rules and dictionaries beyond the standard iterators.
2748 * It may be more efficient to always provide an iterator to avoid
2749 * opening and closing one for each string.
2750 * The standard titlecase iterator for the root locale implements the
2751 * algorithm of Unicode TR 21.
2753 * This function uses only the setText(), first() and next() methods of the
2754 * provided break iterator.
2756 * @param titleIter A break iterator to find the first characters of words
2757 * that are to be titlecased.
2758 * If none is provided (0), then a standard titlecase
2759 * break iterator is opened.
2760 * Otherwise the provided iterator is set to the string's text.
2761 * @param locale The locale to consider.
2762 * @return A reference to this.
2765 UnicodeString
&toTitle(BreakIterator
*titleIter
, const Locale
&locale
);
2768 * Titlecase this string, with options.
2770 * Casing is locale-dependent and context-sensitive.
2771 * Titlecasing uses a break iterator to find the first characters of words
2772 * that are to be titlecased. It titlecases those characters and lowercases
2773 * all others. (This can be modified with options.)
2775 * The titlecase break iterator can be provided to customize for arbitrary
2776 * styles, using rules and dictionaries beyond the standard iterators.
2777 * It may be more efficient to always provide an iterator to avoid
2778 * opening and closing one for each string.
2779 * The standard titlecase iterator for the root locale implements the
2780 * algorithm of Unicode TR 21.
2782 * This function uses only the setText(), first() and next() methods of the
2783 * provided break iterator.
2785 * @param titleIter A break iterator to find the first characters of words
2786 * that are to be titlecased.
2787 * If none is provided (0), then a standard titlecase
2788 * break iterator is opened.
2789 * Otherwise the provided iterator is set to the string's text.
2790 * @param locale The locale to consider.
2791 * @param options Options bit set, see ucasemap_open().
2792 * @return A reference to this.
2793 * @see U_TITLECASE_NO_LOWERCASE
2794 * @see U_TITLECASE_NO_BREAK_ADJUSTMENT
2795 * @see ucasemap_open
2798 UnicodeString
&toTitle(BreakIterator
*titleIter
, const Locale
&locale
, uint32_t options
);
2803 * Case-folds the characters in this string.
2805 * Case-folding is locale-independent and not context-sensitive,
2806 * but there is an option for whether to include or exclude mappings for dotted I
2807 * and dotless i that are marked with 'T' in CaseFolding.txt.
2809 * The result may be longer or shorter than the original.
2811 * @param options Either U_FOLD_CASE_DEFAULT or U_FOLD_CASE_EXCLUDE_SPECIAL_I
2812 * @return A reference to this.
2815 UnicodeString
&foldCase(uint32_t options
=0 /*U_FOLD_CASE_DEFAULT*/);
2817 //========================================
2818 // Access to the internal buffer
2819 //========================================
2822 * Get a read/write pointer to the internal buffer.
2823 * The buffer is guaranteed to be large enough for at least minCapacity UChars,
2824 * writable, and is still owned by the UnicodeString object.
2825 * Calls to getBuffer(minCapacity) must not be nested, and
2826 * must be matched with calls to releaseBuffer(newLength).
2827 * If the string buffer was read-only or shared,
2828 * then it will be reallocated and copied.
2830 * An attempted nested call will return 0, and will not further modify the
2831 * state of the UnicodeString object.
2832 * It also returns 0 if the string is bogus.
2834 * The actual capacity of the string buffer may be larger than minCapacity.
2835 * getCapacity() returns the actual capacity.
2836 * For many operations, the full capacity should be used to avoid reallocations.
2838 * While the buffer is "open" between getBuffer(minCapacity)
2839 * and releaseBuffer(newLength), the following applies:
2840 * - The string length is set to 0.
2841 * - Any read API call on the UnicodeString object will behave like on a 0-length string.
2842 * - Any write API call on the UnicodeString object is disallowed and will have no effect.
2843 * - You can read from and write to the returned buffer.
2844 * - The previous string contents will still be in the buffer;
2845 * if you want to use it, then you need to call length() before getBuffer(minCapacity).
2846 * If the length() was greater than minCapacity, then any contents after minCapacity
2848 * The buffer contents is not NUL-terminated by getBuffer().
2849 * If length()<getCapacity() then you can terminate it by writing a NUL
2850 * at index length().
2851 * - You must call releaseBuffer(newLength) before and in order to
2852 * return to normal UnicodeString operation.
2854 * @param minCapacity the minimum number of UChars that are to be available
2855 * in the buffer, starting at the returned pointer;
2856 * default to the current string capacity if minCapacity==-1
2857 * @return a writable pointer to the internal string buffer,
2858 * or 0 if an error occurs (nested calls, out of memory)
2860 * @see releaseBuffer
2861 * @see getTerminatedBuffer()
2864 UChar
*getBuffer(int32_t minCapacity
);
2867 * Release a read/write buffer on a UnicodeString object with an
2868 * "open" getBuffer(minCapacity).
2869 * This function must be called in a matched pair with getBuffer(minCapacity).
2870 * releaseBuffer(newLength) must be called if and only if a getBuffer(minCapacity) is "open".
2872 * It will set the string length to newLength, at most to the current capacity.
2873 * If newLength==-1 then it will set the length according to the
2874 * first NUL in the buffer, or to the capacity if there is no NUL.
2876 * After calling releaseBuffer(newLength) the UnicodeString is back to normal operation.
2878 * @param newLength the new length of the UnicodeString object;
2879 * defaults to the current capacity if newLength is greater than that;
2880 * if newLength==-1, it defaults to u_strlen(buffer) but not more than
2881 * the current capacity of the string
2883 * @see getBuffer(int32_t minCapacity)
2886 void releaseBuffer(int32_t newLength
=-1);
2889 * Get a read-only pointer to the internal buffer.
2890 * This can be called at any time on a valid UnicodeString.
2892 * It returns 0 if the string is bogus, or
2893 * during an "open" getBuffer(minCapacity).
2895 * It can be called as many times as desired.
2896 * The pointer that it returns will remain valid until the UnicodeString object is modified,
2897 * at which time the pointer is semantically invalidated and must not be used any more.
2899 * The capacity of the buffer can be determined with getCapacity().
2900 * The part after length() may or may not be initialized and valid,
2901 * depending on the history of the UnicodeString object.
2903 * The buffer contents is (probably) not NUL-terminated.
2904 * You can check if it is with
2905 * <code>(s.length()<s.getCapacity() && buffer[s.length()]==0)</code>.
2906 * (See getTerminatedBuffer().)
2908 * The buffer may reside in read-only memory. Its contents must not
2911 * @return a read-only pointer to the internal string buffer,
2912 * or 0 if the string is empty or bogus
2914 * @see getBuffer(int32_t minCapacity)
2915 * @see getTerminatedBuffer()
2918 inline const UChar
*getBuffer() const;
2921 * Get a read-only pointer to the internal buffer,
2922 * making sure that it is NUL-terminated.
2923 * This can be called at any time on a valid UnicodeString.
2925 * It returns 0 if the string is bogus, or
2926 * during an "open" getBuffer(minCapacity), or if the buffer cannot
2927 * be NUL-terminated (because memory allocation failed).
2929 * It can be called as many times as desired.
2930 * The pointer that it returns will remain valid until the UnicodeString object is modified,
2931 * at which time the pointer is semantically invalidated and must not be used any more.
2933 * The capacity of the buffer can be determined with getCapacity().
2934 * The part after length()+1 may or may not be initialized and valid,
2935 * depending on the history of the UnicodeString object.
2937 * The buffer contents is guaranteed to be NUL-terminated.
2938 * getTerminatedBuffer() may reallocate the buffer if a terminating NUL
2940 * For this reason, this function is not const, unlike getBuffer().
2941 * Note that a UnicodeString may also contain NUL characters as part of its contents.
2943 * The buffer may reside in read-only memory. Its contents must not
2946 * @return a read-only pointer to the internal string buffer,
2947 * or 0 if the string is empty or bogus
2949 * @see getBuffer(int32_t minCapacity)
2953 const UChar
*getTerminatedBuffer();
2955 //========================================
2957 //========================================
2959 /** Construct an empty UnicodeString.
2962 inline UnicodeString();
2965 * Construct a UnicodeString with capacity to hold <TT>capacity</TT> UChars
2966 * @param capacity the number of UChars this UnicodeString should hold
2967 * before a resize is necessary; if count is greater than 0 and count
2968 * code points c take up more space than capacity, then capacity is adjusted
2970 * @param c is used to initially fill the string
2971 * @param count specifies how many code points c are to be written in the
2975 UnicodeString(int32_t capacity
, UChar32 c
, int32_t count
);
2978 * Single UChar (code unit) constructor.
2980 * It is recommended to mark this constructor "explicit" by
2981 * <code>-DUNISTR_FROM_CHAR_EXPLICIT=explicit</code>
2982 * on the compiler command line or similar.
2983 * @param ch the character to place in the UnicodeString
2986 UNISTR_FROM_CHAR_EXPLICIT
UnicodeString(UChar ch
);
2989 * Single UChar32 (code point) constructor.
2991 * It is recommended to mark this constructor "explicit" by
2992 * <code>-DUNISTR_FROM_CHAR_EXPLICIT=explicit</code>
2993 * on the compiler command line or similar.
2994 * @param ch the character to place in the UnicodeString
2997 UNISTR_FROM_CHAR_EXPLICIT
UnicodeString(UChar32 ch
);
3000 * UChar* constructor.
3002 * It is recommended to mark this constructor "explicit" by
3003 * <code>-DUNISTR_FROM_STRING_EXPLICIT=explicit</code>
3004 * on the compiler command line or similar.
3005 * @param text The characters to place in the UnicodeString. <TT>text</TT>
3006 * must be NULL (U+0000) terminated.
3009 UNISTR_FROM_STRING_EXPLICIT
UnicodeString(const UChar
*text
);
3012 * UChar* constructor.
3013 * @param text The characters to place in the UnicodeString.
3014 * @param textLength The number of Unicode characters in <TT>text</TT>
3018 UnicodeString(const UChar
*text
,
3019 int32_t textLength
);
3022 * Readonly-aliasing UChar* constructor.
3023 * The text will be used for the UnicodeString object, but
3024 * it will not be released when the UnicodeString is destroyed.
3025 * This has copy-on-write semantics:
3026 * When the string is modified, then the buffer is first copied into
3027 * newly allocated memory.
3028 * The aliased buffer is never modified.
3030 * In an assignment to another UnicodeString, when using the copy constructor
3031 * or the assignment operator, the text will be copied.
3032 * When using fastCopyFrom(), the text will be aliased again,
3033 * so that both strings then alias the same readonly-text.
3035 * @param isTerminated specifies if <code>text</code> is <code>NUL</code>-terminated.
3036 * This must be true if <code>textLength==-1</code>.
3037 * @param text The characters to alias for the UnicodeString.
3038 * @param textLength The number of Unicode characters in <code>text</code> to alias.
3039 * If -1, then this constructor will determine the length
3040 * by calling <code>u_strlen()</code>.
3043 UnicodeString(UBool isTerminated
,
3045 int32_t textLength
);
3048 * Writable-aliasing UChar* constructor.
3049 * The text will be used for the UnicodeString object, but
3050 * it will not be released when the UnicodeString is destroyed.
3051 * This has write-through semantics:
3052 * For as long as the capacity of the buffer is sufficient, write operations
3053 * will directly affect the buffer. When more capacity is necessary, then
3054 * a new buffer will be allocated and the contents copied as with regularly
3055 * constructed strings.
3056 * In an assignment to another UnicodeString, the buffer will be copied.
3057 * The extract(UChar *dst) function detects whether the dst pointer is the same
3058 * as the string buffer itself and will in this case not copy the contents.
3060 * @param buffer The characters to alias for the UnicodeString.
3061 * @param buffLength The number of Unicode characters in <code>buffer</code> to alias.
3062 * @param buffCapacity The size of <code>buffer</code> in UChars.
3065 UnicodeString(UChar
*buffer
, int32_t buffLength
, int32_t buffCapacity
);
3067 #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
3070 * char* constructor.
3071 * Uses the default converter (and thus depends on the ICU conversion code)
3072 * unless U_CHARSET_IS_UTF8 is set to 1.
3074 * For ASCII (really "invariant character") strings it is more efficient to use
3075 * the constructor that takes a US_INV (for its enum EInvariant).
3076 * For ASCII (invariant-character) string literals, see UNICODE_STRING and
3077 * UNICODE_STRING_SIMPLE.
3079 * It is recommended to mark this constructor "explicit" by
3080 * <code>-DUNISTR_FROM_STRING_EXPLICIT=explicit</code>
3081 * on the compiler command line or similar.
3082 * @param codepageData an array of bytes, null-terminated,
3083 * in the platform's default codepage.
3085 * @see UNICODE_STRING
3086 * @see UNICODE_STRING_SIMPLE
3088 UNISTR_FROM_STRING_EXPLICIT
UnicodeString(const char *codepageData
);
3091 * char* constructor.
3092 * Uses the default converter (and thus depends on the ICU conversion code)
3093 * unless U_CHARSET_IS_UTF8 is set to 1.
3094 * @param codepageData an array of bytes in the platform's default codepage.
3095 * @param dataLength The number of bytes in <TT>codepageData</TT>.
3098 UnicodeString(const char *codepageData
, int32_t dataLength
);
3102 #if !UCONFIG_NO_CONVERSION
3105 * char* constructor.
3106 * @param codepageData an array of bytes, null-terminated
3107 * @param codepage the encoding of <TT>codepageData</TT>. The special
3108 * value 0 for <TT>codepage</TT> indicates that the text is in the
3109 * platform's default codepage.
3111 * If <code>codepage</code> is an empty string (<code>""</code>),
3112 * then a simple conversion is performed on the codepage-invariant
3113 * subset ("invariant characters") of the platform encoding. See utypes.h.
3114 * Recommendation: For invariant-character strings use the constructor
3115 * UnicodeString(const char *src, int32_t length, enum EInvariant inv)
3116 * because it avoids object code dependencies of UnicodeString on
3117 * the conversion code.
3121 UnicodeString(const char *codepageData
, const char *codepage
);
3124 * char* constructor.
3125 * @param codepageData an array of bytes.
3126 * @param dataLength The number of bytes in <TT>codepageData</TT>.
3127 * @param codepage the encoding of <TT>codepageData</TT>. The special
3128 * value 0 for <TT>codepage</TT> indicates that the text is in the
3129 * platform's default codepage.
3130 * If <code>codepage</code> is an empty string (<code>""</code>),
3131 * then a simple conversion is performed on the codepage-invariant
3132 * subset ("invariant characters") of the platform encoding. See utypes.h.
3133 * Recommendation: For invariant-character strings use the constructor
3134 * UnicodeString(const char *src, int32_t length, enum EInvariant inv)
3135 * because it avoids object code dependencies of UnicodeString on
3136 * the conversion code.
3140 UnicodeString(const char *codepageData
, int32_t dataLength
, const char *codepage
);
3143 * char * / UConverter constructor.
3144 * This constructor uses an existing UConverter object to
3145 * convert the codepage string to Unicode and construct a UnicodeString
3148 * The converter is reset at first.
3149 * If the error code indicates a failure before this constructor is called,
3150 * or if an error occurs during conversion or construction,
3151 * then the string will be bogus.
3153 * This function avoids the overhead of opening and closing a converter if
3154 * multiple strings are constructed.
3156 * @param src input codepage string
3157 * @param srcLength length of the input string, can be -1 for NUL-terminated strings
3158 * @param cnv converter object (ucnv_resetToUnicode() will be called),
3159 * can be NULL for the default converter
3160 * @param errorCode normal ICU error code
3164 const char *src
, int32_t srcLength
,
3166 UErrorCode
&errorCode
);
3171 * Constructs a Unicode string from an invariant-character char * string.
3172 * About invariant characters see utypes.h.
3173 * This constructor has no runtime dependency on conversion code and is
3174 * therefore recommended over ones taking a charset name string
3175 * (where the empty string "" indicates invariant-character conversion).
3177 * Use the macro US_INV as the third, signature-distinguishing parameter.
3181 * void fn(const char *s) {
3182 * UnicodeString ustr(s, -1, US_INV);
3187 * @param src String using only invariant characters.
3188 * @param length Length of src, or -1 if NUL-terminated.
3189 * @param inv Signature-distinguishing paramater, use US_INV.
3194 UnicodeString(const char *src
, int32_t length
, enum EInvariant inv
);
3200 * Starting with ICU 2.4, the assignment operator and the copy constructor
3201 * allocate a new buffer and copy the buffer contents even for readonly aliases.
3202 * By contrast, the fastCopyFrom() function implements the old,
3203 * more efficient but less safe behavior
3204 * of making this string also a readonly alias to the same buffer.
3206 * If the source object has an "open" buffer from getBuffer(minCapacity),
3207 * then the copy is an empty string.
3209 * @param that The UnicodeString object to copy.
3213 UnicodeString(const UnicodeString
& that
);
3215 #ifndef U_HIDE_DRAFT_API
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
;
3225 #endif /* U_HIDE_DRAFT_API */
3228 * 'Substring' constructor from tail of source string.
3229 * @param src The UnicodeString object to copy.
3230 * @param srcStart The offset into <tt>src</tt> at which to start copying.
3233 UnicodeString(const UnicodeString
& src
, int32_t srcStart
);
3236 * 'Substring' constructor from subrange of source string.
3237 * @param src The UnicodeString object to copy.
3238 * @param srcStart The offset into <tt>src</tt> at which to start copying.
3239 * @param srcLength The number of characters from <tt>src</tt> to copy.
3242 UnicodeString(const UnicodeString
& src
, int32_t srcStart
, int32_t srcLength
);
3245 * Clone this object, an instance of a subclass of Replaceable.
3246 * Clones can be used concurrently in multiple threads.
3247 * If a subclass does not implement clone(), or if an error occurs,
3248 * then NULL is returned.
3249 * The clone functions in all subclasses return a pointer to a Replaceable
3250 * because some compilers do not support covariant (same-as-this)
3251 * return types; cast to the appropriate subclass if necessary.
3252 * The caller must delete the clone.
3254 * @return a clone of this object
3256 * @see Replaceable::clone
3257 * @see getDynamicClassID
3260 virtual Replaceable
*clone() const;
3265 virtual ~UnicodeString();
3268 * Create a UnicodeString from a UTF-8 string.
3269 * Illegal input is replaced with U+FFFD. Otherwise, errors result in a bogus string.
3270 * Calls u_strFromUTF8WithSub().
3272 * @param utf8 UTF-8 input string.
3273 * Note that a StringPiece can be implicitly constructed
3274 * from a std::string or a NUL-terminated const char * string.
3275 * @return A UnicodeString with equivalent UTF-16 contents.
3280 static UnicodeString
fromUTF8(const StringPiece
&utf8
);
3283 * Create a UnicodeString from a UTF-32 string.
3284 * Illegal input is replaced with U+FFFD. Otherwise, errors result in a bogus string.
3285 * Calls u_strFromUTF32WithSub().
3287 * @param utf32 UTF-32 input string. Must not be NULL.
3288 * @param length Length of the input string, or -1 if NUL-terminated.
3289 * @return A UnicodeString with equivalent UTF-16 contents.
3293 static UnicodeString
fromUTF32(const UChar32
*utf32
, int32_t length
);
3295 /* Miscellaneous operations */
3298 * Unescape a string of characters and return a string containing
3299 * the result. The following escape sequences are recognized:
3301 * \\uhhhh 4 hex digits; h in [0-9A-Fa-f]
3302 * \\Uhhhhhhhh 8 hex digits
3303 * \\xhh 1-2 hex digits
3304 * \\ooo 1-3 octal digits; o in [0-7]
3305 * \\cX control-X; X is masked with 0x1F
3307 * as well as the standard ANSI C escapes:
3309 * \\a => U+0007, \\b => U+0008, \\t => U+0009, \\n => U+000A,
3310 * \\v => U+000B, \\f => U+000C, \\r => U+000D, \\e => U+001B,
3311 * \\" => U+0022, \\' => U+0027, \\? => U+003F, \\\\ => U+005C
3313 * Anything else following a backslash is generically escaped. For
3314 * example, "[a\\-z]" returns "[a-z]".
3316 * If an escape sequence is ill-formed, this method returns an empty
3317 * string. An example of an ill-formed sequence is "\\u" followed by
3318 * fewer than 4 hex digits.
3320 * This function is similar to u_unescape() but not identical to it.
3321 * The latter takes a source char*, so it does escape recognition
3322 * and also invariant conversion.
3324 * @return a string with backslash escapes interpreted, or an
3325 * empty string on error.
3326 * @see UnicodeString#unescapeAt()
3328 * @see u_unescapeAt()
3331 UnicodeString
unescape() const;
3334 * Unescape a single escape sequence and return the represented
3335 * character. See unescape() for a listing of the recognized escape
3336 * sequences. The character at offset-1 is assumed (without
3337 * checking) to be a backslash. If the escape sequence is
3338 * ill-formed, or the offset is out of range, U_SENTINEL=-1 is
3341 * @param offset an input output parameter. On input, it is the
3342 * offset into this string where the escape sequence is located,
3343 * after the initial backslash. On output, it is advanced after the
3344 * last character parsed. On error, it is not advanced at all.
3345 * @return the character represented by the escape sequence at
3346 * offset, or U_SENTINEL=-1 on error.
3347 * @see UnicodeString#unescape()
3349 * @see u_unescapeAt()
3352 UChar32
unescapeAt(int32_t &offset
) const;
3355 * ICU "poor man's RTTI", returns a UClassID for this class.
3359 static UClassID U_EXPORT2
getStaticClassID();
3362 * ICU "poor man's RTTI", returns a UClassID for the actual class.
3366 virtual UClassID
getDynamicClassID() const;
3368 //========================================
3369 // Implementation methods
3370 //========================================
3374 * Implement Replaceable::getLength() (see jitterbug 1027).
3377 virtual int32_t getLength() const;
3380 * The change in Replaceable to use virtual getCharAt() allows
3381 * UnicodeString::charAt() to be inline again (see jitterbug 709).
3384 virtual UChar
getCharAt(int32_t offset
) const;
3387 * The change in Replaceable to use virtual getChar32At() allows
3388 * UnicodeString::char32At() to be inline again (see jitterbug 709).
3391 virtual UChar32
getChar32At(int32_t offset
) const;
3394 // For char* constructors. Could be made public.
3395 UnicodeString
&setToUTF8(const StringPiece
&utf8
);
3396 // For extract(char*).
3397 // We could make a toUTF8(target, capacity, errorCode) public but not
3398 // this version: New API will be cleaner if we make callers create substrings
3399 // rather than having start+length on every method,
3400 // and it should take a UErrorCode&.
3402 toUTF8(int32_t start
, int32_t len
,
3403 char *target
, int32_t capacity
) const;
3406 * Internal string contents comparison, called by operator==.
3407 * Requires: this & text not bogus and have same lengths.
3409 UBool
doEquals(const UnicodeString
&text
, int32_t len
) const;
3412 doCompare(int32_t start
,
3414 const UnicodeString
& srcText
,
3416 int32_t srcLength
) const;
3418 int8_t doCompare(int32_t start
,
3420 const UChar
*srcChars
,
3422 int32_t srcLength
) const;
3425 doCompareCodePointOrder(int32_t start
,
3427 const UnicodeString
& srcText
,
3429 int32_t srcLength
) const;
3431 int8_t doCompareCodePointOrder(int32_t start
,
3433 const UChar
*srcChars
,
3435 int32_t srcLength
) const;
3438 doCaseCompare(int32_t start
,
3440 const UnicodeString
&srcText
,
3443 uint32_t options
) const;
3446 doCaseCompare(int32_t start
,
3448 const UChar
*srcChars
,
3451 uint32_t options
) const;
3453 int32_t doIndexOf(UChar c
,
3455 int32_t length
) const;
3457 int32_t doIndexOf(UChar32 c
,
3459 int32_t length
) const;
3461 int32_t doLastIndexOf(UChar c
,
3463 int32_t length
) const;
3465 int32_t doLastIndexOf(UChar32 c
,
3467 int32_t length
) const;
3469 void doExtract(int32_t start
,
3472 int32_t dstStart
) const;
3474 inline void doExtract(int32_t start
,
3476 UnicodeString
& target
) const;
3478 inline UChar
doCharAt(int32_t offset
) const;
3480 UnicodeString
& doReplace(int32_t start
,
3482 const UnicodeString
& srcText
,
3486 UnicodeString
& doReplace(int32_t start
,
3488 const UChar
*srcChars
,
3492 UnicodeString
& doAppend(const UnicodeString
& src
, int32_t srcStart
, int32_t srcLength
);
3493 UnicodeString
& doAppend(const UChar
*srcChars
, int32_t srcStart
, int32_t srcLength
);
3495 UnicodeString
& doReverse(int32_t start
,
3498 // calculate hash code
3499 int32_t doHashCode(void) const;
3501 // get pointer to start of array
3502 // these do not check for kOpenGetBuffer, unlike the public getBuffer() function
3503 inline UChar
* getArrayStart(void);
3504 inline const UChar
* getArrayStart(void) const;
3506 inline UBool
hasShortLength() const;
3507 inline int32_t getShortLength() const;
3509 // A UnicodeString object (not necessarily its current buffer)
3510 // is writable unless it isBogus() or it has an "open" getBuffer(minCapacity).
3511 inline UBool
isWritable() const;
3513 // Is the current buffer writable?
3514 inline UBool
isBufferWritable() const;
3516 // None of the following does releaseArray().
3517 inline void setZeroLength();
3518 inline void setShortLength(int32_t len
);
3519 inline void setLength(int32_t len
);
3520 inline void setToEmpty();
3521 inline void setArray(UChar
*array
, int32_t len
, int32_t capacity
); // sets length but not flags
3523 // allocate the array; result may be the stack buffer
3524 // sets refCount to 1 if appropriate
3525 // sets fArray, fCapacity, and flags
3527 // returns boolean for success or failure
3528 UBool
allocate(int32_t capacity
);
3530 // release the array if owned
3531 void releaseArray(void);
3533 // turn a bogus string into an empty one
3536 // implements assigment operator, copy constructor, and fastCopyFrom()
3537 UnicodeString
©From(const UnicodeString
&src
, UBool fastCopy
=FALSE
);
3539 // Copies just the fields without memory management.
3540 void copyFieldsFrom(UnicodeString
&src
, UBool setSrcToBogus
) U_NOEXCEPT
;
3542 // Pin start and limit to acceptable values.
3543 inline void pinIndex(int32_t& start
) const;
3544 inline void pinIndices(int32_t& start
,
3545 int32_t& length
) const;
3547 #if !UCONFIG_NO_CONVERSION
3549 /* Internal extract() using UConverter. */
3550 int32_t doExtract(int32_t start
, int32_t length
,
3551 char *dest
, int32_t destCapacity
,
3553 UErrorCode
&errorCode
) const;
3556 * Real constructor for converting from codepage data.
3557 * It assumes that it is called with !fRefCounted.
3559 * If <code>codepage==0</code>, then the default converter
3560 * is used for the platform encoding.
3561 * If <code>codepage</code> is an empty string (<code>""</code>),
3562 * then a simple conversion is performed on the codepage-invariant
3563 * subset ("invariant characters") of the platform encoding. See utypes.h.
3565 void doCodepageCreate(const char *codepageData
,
3567 const char *codepage
);
3570 * Worker function for creating a UnicodeString from
3571 * a codepage string using a UConverter.
3574 doCodepageCreate(const char *codepageData
,
3576 UConverter
*converter
,
3577 UErrorCode
&status
);
3582 * This function is called when write access to the array
3585 * We need to make a copy of the array if
3586 * the buffer is read-only, or
3587 * the buffer is refCounted (shared), and refCount>1, or
3588 * the buffer is too small.
3590 * Return FALSE if memory could not be allocated.
3592 UBool
cloneArrayIfNeeded(int32_t newCapacity
= -1,
3593 int32_t growCapacity
= -1,
3594 UBool doCopyArray
= TRUE
,
3595 int32_t **pBufferToDelete
= 0,
3596 UBool forceClone
= FALSE
);
3599 * Common function for UnicodeString case mappings.
3600 * The stringCaseMapper has the same type UStringCaseMapper
3601 * as in ustr_imp.h for ustrcase_map().
3604 caseMap(const UCaseMap
*csm
, UStringCaseMapper
*stringCaseMapper
);
3608 int32_t removeRef(void);
3609 int32_t refCount(void) const;
3614 * Size of stack buffer for short strings.
3615 * Must be at least U16_MAX_LENGTH for the single-code point constructor to work.
3616 * @see UNISTR_OBJECT_SIZE
3618 US_STACKBUF_SIZE
=(int32_t)(UNISTR_OBJECT_SIZE
-sizeof(void *)-2)/U_SIZEOF_UCHAR
,
3619 kInvalidUChar
=0xffff, // U+FFFF returned by charAt(invalid index)
3620 kGrowSize
=128, // grow size for this buffer
3621 kInvalidHashCode
=0, // invalid hash code
3622 kEmptyHashCode
=1, // hash code for empty string
3624 // bit flag values for fLengthAndFlags
3625 kIsBogus
=1, // this string is bogus, i.e., not valid or NULL
3626 kUsingStackBuffer
=2,// using fUnion.fStackFields instead of fUnion.fFields
3627 kRefCounted
=4, // there is a refCount field before the characters in fArray
3628 kBufferIsReadonly
=8,// do not write to this buffer
3629 kOpenGetBuffer
=16, // getBuffer(minCapacity) was called (is "open"),
3630 // and releaseBuffer(newLength) must be called
3631 kAllStorageFlags
=0x1f,
3633 kLengthShift
=5, // remaining 11 bits for non-negative short length, or negative if long
3634 kLength1
=1<<kLengthShift
,
3635 kMaxShortLength
=0x3ff, // max non-negative short length (leaves top bit 0)
3636 kLengthIsLarge
=0xffe0, // short length < 0, real length is in fUnion.fFields.fLength
3638 // combined values for convenience
3639 kShortString
=kUsingStackBuffer
,
3640 kLongString
=kRefCounted
,
3641 kReadonlyAlias
=kBufferIsReadonly
,
3645 friend class UnicodeStringAppendable
;
3647 union StackBufferOrFields
; // forward declaration necessary before friend declaration
3648 friend union StackBufferOrFields
; // make US_STACKBUF_SIZE visible inside fUnion
3651 * The following are all the class fields that are stored
3652 * in each UnicodeString object.
3653 * Note that UnicodeString has virtual functions,
3654 * therefore there is an implicit vtable pointer
3655 * as the first real field.
3656 * The fields should be aligned such that no padding is necessary.
3657 * On 32-bit machines, the size should be 32 bytes,
3658 * on 64-bit machines (8-byte pointers), it should be 40 bytes.
3660 * We use a hack to achieve this.
3662 * With at least some compilers, each of the following is forced to
3663 * a multiple of sizeof(pointer) [the largest field base unit here is a data pointer],
3664 * rounded up with additional padding if the fields do not already fit that requirement:
3665 * - sizeof(class UnicodeString)
3666 * - offsetof(UnicodeString, fUnion)
3668 * - sizeof(fStackFields)
3670 * We optimize for the longest possible internal buffer for short strings.
3671 * fUnion.fStackFields begins with 2 bytes for storage flags
3672 * and the length of relatively short strings,
3673 * followed by the buffer for short string contents.
3674 * There is no padding inside fStackFields.
3676 * Heap-allocated and aliased strings use fUnion.fFields.
3677 * Both fStackFields and fFields must begin with the same fields for flags and short length,
3678 * that is, those must have the same memory offsets inside the object,
3679 * because the flags must be inspected in order to decide which half of fUnion is being used.
3680 * We assume that the compiler does not reorder the fields.
3682 * (Padding at the end of fFields is ok:
3683 * As long as it is no larger than fStackFields, it is not wasted space.)
3685 * For some of the history of the UnicodeString class fields layout, see
3686 * - ICU ticket #11551 "longer UnicodeString contents in stack buffer"
3687 * - ICU ticket #11336 "UnicodeString: recombine stack buffer arrays"
3688 * - ICU ticket #8322 "why is sizeof(UnicodeString)==48?"
3690 // (implicit) *vtable;
3691 union StackBufferOrFields
{
3692 // fStackFields is used iff (fLengthAndFlags&kUsingStackBuffer) else fFields is used.
3693 // Each struct of the union must begin with fLengthAndFlags.
3695 int16_t fLengthAndFlags
; // bit fields: see constants above
3696 UChar fBuffer
[US_STACKBUF_SIZE
]; // buffer for short strings
3699 int16_t fLengthAndFlags
; // bit fields: see constants above
3700 int32_t fLength
; // number of characters in fArray if >127; else undefined
3701 int32_t fCapacity
; // capacity of fArray (in UChars)
3702 // array pointer last to minimize padding for machines with P128 data model
3703 // or pointer sizes that are not a power of 2
3704 UChar
*fArray
; // the Unicode data
3710 * Create a new UnicodeString with the concatenation of two others.
3712 * @param s1 The first string to be copied to the new one.
3713 * @param s2 The second string to be copied to the new one, after s1.
3714 * @return UnicodeString(s1).append(s2)
3717 U_COMMON_API UnicodeString U_EXPORT2
3718 operator+ (const UnicodeString
&s1
, const UnicodeString
&s2
);
3720 //========================================
3722 //========================================
3724 //========================================
3726 //========================================
3729 UnicodeString::pinIndex(int32_t& start
) const
3734 } else if(start
> length()) {
3740 UnicodeString::pinIndices(int32_t& start
,
3741 int32_t& _length
) const
3744 int32_t len
= length();
3747 } else if(start
> len
) {
3752 } else if(_length
> (len
- start
)) {
3753 _length
= (len
- start
);
3758 UnicodeString::getArrayStart() {
3759 return (fUnion
.fFields
.fLengthAndFlags
&kUsingStackBuffer
) ?
3760 fUnion
.fStackFields
.fBuffer
: fUnion
.fFields
.fArray
;
3764 UnicodeString::getArrayStart() const {
3765 return (fUnion
.fFields
.fLengthAndFlags
&kUsingStackBuffer
) ?
3766 fUnion
.fStackFields
.fBuffer
: fUnion
.fFields
.fArray
;
3769 //========================================
3770 // Default constructor
3771 //========================================
3774 UnicodeString::UnicodeString() {
3775 fUnion
.fStackFields
.fLengthAndFlags
=kShortString
;
3778 //========================================
3779 // Read-only implementation methods
3780 //========================================
3782 UnicodeString::hasShortLength() const {
3783 return fUnion
.fFields
.fLengthAndFlags
>=0;
3787 UnicodeString::getShortLength() const {
3788 // fLengthAndFlags must be non-negative -> short length >= 0
3789 // and arithmetic or logical shift does not matter.
3790 return fUnion
.fFields
.fLengthAndFlags
>>kLengthShift
;
3794 UnicodeString::length() const {
3795 return hasShortLength() ? getShortLength() : fUnion
.fFields
.fLength
;
3799 UnicodeString::getCapacity() const {
3800 return (fUnion
.fFields
.fLengthAndFlags
&kUsingStackBuffer
) ?
3801 US_STACKBUF_SIZE
: fUnion
.fFields
.fCapacity
;
3805 UnicodeString::hashCode() const
3806 { return doHashCode(); }
3809 UnicodeString::isBogus() const
3810 { return (UBool
)(fUnion
.fFields
.fLengthAndFlags
& kIsBogus
); }
3813 UnicodeString::isWritable() const
3814 { return (UBool
)!(fUnion
.fFields
.fLengthAndFlags
&(kOpenGetBuffer
|kIsBogus
)); }
3817 UnicodeString::isBufferWritable() const
3820 !(fUnion
.fFields
.fLengthAndFlags
&(kOpenGetBuffer
|kIsBogus
|kBufferIsReadonly
)) &&
3821 (!(fUnion
.fFields
.fLengthAndFlags
&kRefCounted
) || refCount()==1));
3824 inline const UChar
*
3825 UnicodeString::getBuffer() const {
3826 if(fUnion
.fFields
.fLengthAndFlags
&(kIsBogus
|kOpenGetBuffer
)) {
3828 } else if(fUnion
.fFields
.fLengthAndFlags
&kUsingStackBuffer
) {
3829 return fUnion
.fStackFields
.fBuffer
;
3831 return fUnion
.fFields
.fArray
;
3835 //========================================
3836 // Read-only alias methods
3837 //========================================
3839 UnicodeString::doCompare(int32_t start
,
3841 const UnicodeString
& srcText
,
3843 int32_t srcLength
) const
3845 if(srcText
.isBogus()) {
3846 return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
3848 srcText
.pinIndices(srcStart
, srcLength
);
3849 return doCompare(start
, thisLength
, srcText
.getArrayStart(), srcStart
, srcLength
);
3854 UnicodeString::operator== (const UnicodeString
& text
) const
3857 return text
.isBogus();
3859 int32_t len
= length(), textLength
= text
.length();
3860 return !text
.isBogus() && len
== textLength
&& doEquals(text
, len
);
3865 UnicodeString::operator!= (const UnicodeString
& text
) const
3866 { return (! operator==(text
)); }
3869 UnicodeString::operator> (const UnicodeString
& text
) const
3870 { return doCompare(0, length(), text
, 0, text
.length()) == 1; }
3873 UnicodeString::operator< (const UnicodeString
& text
) const
3874 { return doCompare(0, length(), text
, 0, text
.length()) == -1; }
3877 UnicodeString::operator>= (const UnicodeString
& text
) const
3878 { return doCompare(0, length(), text
, 0, text
.length()) != -1; }
3881 UnicodeString::operator<= (const UnicodeString
& text
) const
3882 { return doCompare(0, length(), text
, 0, text
.length()) != 1; }
3885 UnicodeString::compare(const UnicodeString
& text
) const
3886 { return doCompare(0, length(), text
, 0, text
.length()); }
3889 UnicodeString::compare(int32_t start
,
3891 const UnicodeString
& srcText
) const
3892 { return doCompare(start
, _length
, srcText
, 0, srcText
.length()); }
3895 UnicodeString::compare(const UChar
*srcChars
,
3896 int32_t srcLength
) const
3897 { return doCompare(0, length(), srcChars
, 0, srcLength
); }
3900 UnicodeString::compare(int32_t start
,
3902 const UnicodeString
& srcText
,
3904 int32_t srcLength
) const
3905 { return doCompare(start
, _length
, srcText
, srcStart
, srcLength
); }
3908 UnicodeString::compare(int32_t start
,
3910 const UChar
*srcChars
) const
3911 { return doCompare(start
, _length
, srcChars
, 0, _length
); }
3914 UnicodeString::compare(int32_t start
,
3916 const UChar
*srcChars
,
3918 int32_t srcLength
) const
3919 { return doCompare(start
, _length
, srcChars
, srcStart
, srcLength
); }
3922 UnicodeString::compareBetween(int32_t start
,
3924 const UnicodeString
& srcText
,
3926 int32_t srcLimit
) const
3927 { return doCompare(start
, limit
- start
,
3928 srcText
, srcStart
, srcLimit
- srcStart
); }
3931 UnicodeString::doCompareCodePointOrder(int32_t start
,
3933 const UnicodeString
& srcText
,
3935 int32_t srcLength
) const
3937 if(srcText
.isBogus()) {
3938 return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
3940 srcText
.pinIndices(srcStart
, srcLength
);
3941 return doCompareCodePointOrder(start
, thisLength
, srcText
.getArrayStart(), srcStart
, srcLength
);
3946 UnicodeString::compareCodePointOrder(const UnicodeString
& text
) const
3947 { return doCompareCodePointOrder(0, length(), text
, 0, text
.length()); }
3950 UnicodeString::compareCodePointOrder(int32_t start
,
3952 const UnicodeString
& srcText
) const
3953 { return doCompareCodePointOrder(start
, _length
, srcText
, 0, srcText
.length()); }
3956 UnicodeString::compareCodePointOrder(const UChar
*srcChars
,
3957 int32_t srcLength
) const
3958 { return doCompareCodePointOrder(0, length(), srcChars
, 0, srcLength
); }
3961 UnicodeString::compareCodePointOrder(int32_t start
,
3963 const UnicodeString
& srcText
,
3965 int32_t srcLength
) const
3966 { return doCompareCodePointOrder(start
, _length
, srcText
, srcStart
, srcLength
); }
3969 UnicodeString::compareCodePointOrder(int32_t start
,
3971 const UChar
*srcChars
) const
3972 { return doCompareCodePointOrder(start
, _length
, srcChars
, 0, _length
); }
3975 UnicodeString::compareCodePointOrder(int32_t start
,
3977 const UChar
*srcChars
,
3979 int32_t srcLength
) const
3980 { return doCompareCodePointOrder(start
, _length
, srcChars
, srcStart
, srcLength
); }
3983 UnicodeString::compareCodePointOrderBetween(int32_t start
,
3985 const UnicodeString
& srcText
,
3987 int32_t srcLimit
) const
3988 { return doCompareCodePointOrder(start
, limit
- start
,
3989 srcText
, srcStart
, srcLimit
- srcStart
); }
3992 UnicodeString::doCaseCompare(int32_t start
,
3994 const UnicodeString
&srcText
,
3997 uint32_t options
) const
3999 if(srcText
.isBogus()) {
4000 return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
4002 srcText
.pinIndices(srcStart
, srcLength
);
4003 return doCaseCompare(start
, thisLength
, srcText
.getArrayStart(), srcStart
, srcLength
, options
);
4008 UnicodeString::caseCompare(const UnicodeString
&text
, uint32_t options
) const {
4009 return doCaseCompare(0, length(), text
, 0, text
.length(), options
);
4013 UnicodeString::caseCompare(int32_t start
,
4015 const UnicodeString
&srcText
,
4016 uint32_t options
) const {
4017 return doCaseCompare(start
, _length
, srcText
, 0, srcText
.length(), options
);
4021 UnicodeString::caseCompare(const UChar
*srcChars
,
4023 uint32_t options
) const {
4024 return doCaseCompare(0, length(), srcChars
, 0, srcLength
, options
);
4028 UnicodeString::caseCompare(int32_t start
,
4030 const UnicodeString
&srcText
,
4033 uint32_t options
) const {
4034 return doCaseCompare(start
, _length
, srcText
, srcStart
, srcLength
, options
);
4038 UnicodeString::caseCompare(int32_t start
,
4040 const UChar
*srcChars
,
4041 uint32_t options
) const {
4042 return doCaseCompare(start
, _length
, srcChars
, 0, _length
, options
);
4046 UnicodeString::caseCompare(int32_t start
,
4048 const UChar
*srcChars
,
4051 uint32_t options
) const {
4052 return doCaseCompare(start
, _length
, srcChars
, srcStart
, srcLength
, options
);
4056 UnicodeString::caseCompareBetween(int32_t start
,
4058 const UnicodeString
&srcText
,
4061 uint32_t options
) const {
4062 return doCaseCompare(start
, limit
- start
, srcText
, srcStart
, srcLimit
- srcStart
, options
);
4066 UnicodeString::indexOf(const UnicodeString
& srcText
,
4070 int32_t _length
) const
4072 if(!srcText
.isBogus()) {
4073 srcText
.pinIndices(srcStart
, srcLength
);
4075 return indexOf(srcText
.getArrayStart(), srcStart
, srcLength
, start
, _length
);
4082 UnicodeString::indexOf(const UnicodeString
& text
) const
4083 { return indexOf(text
, 0, text
.length(), 0, length()); }
4086 UnicodeString::indexOf(const UnicodeString
& text
,
4087 int32_t start
) const {
4089 return indexOf(text
, 0, text
.length(), start
, length() - start
);
4093 UnicodeString::indexOf(const UnicodeString
& text
,
4095 int32_t _length
) const
4096 { return indexOf(text
, 0, text
.length(), start
, _length
); }
4099 UnicodeString::indexOf(const UChar
*srcChars
,
4101 int32_t start
) const {
4103 return indexOf(srcChars
, 0, srcLength
, start
, length() - start
);
4107 UnicodeString::indexOf(const UChar
*srcChars
,
4110 int32_t _length
) const
4111 { return indexOf(srcChars
, 0, srcLength
, start
, _length
); }
4114 UnicodeString::indexOf(UChar c
,
4116 int32_t _length
) const
4117 { return doIndexOf(c
, start
, _length
); }
4120 UnicodeString::indexOf(UChar32 c
,
4122 int32_t _length
) const
4123 { return doIndexOf(c
, start
, _length
); }
4126 UnicodeString::indexOf(UChar c
) const
4127 { return doIndexOf(c
, 0, length()); }
4130 UnicodeString::indexOf(UChar32 c
) const
4131 { return indexOf(c
, 0, length()); }
4134 UnicodeString::indexOf(UChar c
,
4135 int32_t start
) const {
4137 return doIndexOf(c
, start
, length() - start
);
4141 UnicodeString::indexOf(UChar32 c
,
4142 int32_t start
) const {
4144 return indexOf(c
, start
, length() - start
);
4148 UnicodeString::lastIndexOf(const UChar
*srcChars
,
4151 int32_t _length
) const
4152 { return lastIndexOf(srcChars
, 0, srcLength
, start
, _length
); }
4155 UnicodeString::lastIndexOf(const UChar
*srcChars
,
4157 int32_t start
) const {
4159 return lastIndexOf(srcChars
, 0, srcLength
, start
, length() - start
);
4163 UnicodeString::lastIndexOf(const UnicodeString
& srcText
,
4167 int32_t _length
) const
4169 if(!srcText
.isBogus()) {
4170 srcText
.pinIndices(srcStart
, srcLength
);
4172 return lastIndexOf(srcText
.getArrayStart(), srcStart
, srcLength
, start
, _length
);
4179 UnicodeString::lastIndexOf(const UnicodeString
& text
,
4181 int32_t _length
) const
4182 { return lastIndexOf(text
, 0, text
.length(), start
, _length
); }
4185 UnicodeString::lastIndexOf(const UnicodeString
& text
,
4186 int32_t start
) const {
4188 return lastIndexOf(text
, 0, text
.length(), start
, length() - start
);
4192 UnicodeString::lastIndexOf(const UnicodeString
& text
) const
4193 { return lastIndexOf(text
, 0, text
.length(), 0, length()); }
4196 UnicodeString::lastIndexOf(UChar c
,
4198 int32_t _length
) const
4199 { return doLastIndexOf(c
, start
, _length
); }
4202 UnicodeString::lastIndexOf(UChar32 c
,
4204 int32_t _length
) const {
4205 return doLastIndexOf(c
, start
, _length
);
4209 UnicodeString::lastIndexOf(UChar c
) const
4210 { return doLastIndexOf(c
, 0, length()); }
4213 UnicodeString::lastIndexOf(UChar32 c
) const {
4214 return lastIndexOf(c
, 0, length());
4218 UnicodeString::lastIndexOf(UChar c
,
4219 int32_t start
) const {
4221 return doLastIndexOf(c
, start
, length() - start
);
4225 UnicodeString::lastIndexOf(UChar32 c
,
4226 int32_t start
) const {
4228 return lastIndexOf(c
, start
, length() - start
);
4232 UnicodeString::startsWith(const UnicodeString
& text
) const
4233 { return compare(0, text
.length(), text
, 0, text
.length()) == 0; }
4236 UnicodeString::startsWith(const UnicodeString
& srcText
,
4238 int32_t srcLength
) const
4239 { return doCompare(0, srcLength
, srcText
, srcStart
, srcLength
) == 0; }
4242 UnicodeString::startsWith(const UChar
*srcChars
, int32_t srcLength
) const {
4244 srcLength
= u_strlen(srcChars
);
4246 return doCompare(0, srcLength
, srcChars
, 0, srcLength
) == 0;
4250 UnicodeString::startsWith(const UChar
*srcChars
, int32_t srcStart
, int32_t srcLength
) const {
4252 srcLength
= u_strlen(srcChars
);
4254 return doCompare(0, srcLength
, srcChars
, srcStart
, srcLength
) == 0;
4258 UnicodeString::endsWith(const UnicodeString
& text
) const
4259 { return doCompare(length() - text
.length(), text
.length(),
4260 text
, 0, text
.length()) == 0; }
4263 UnicodeString::endsWith(const UnicodeString
& srcText
,
4265 int32_t srcLength
) const {
4266 srcText
.pinIndices(srcStart
, srcLength
);
4267 return doCompare(length() - srcLength
, srcLength
,
4268 srcText
, srcStart
, srcLength
) == 0;
4272 UnicodeString::endsWith(const UChar
*srcChars
,
4273 int32_t srcLength
) const {
4275 srcLength
= u_strlen(srcChars
);
4277 return doCompare(length() - srcLength
, srcLength
,
4278 srcChars
, 0, srcLength
) == 0;
4282 UnicodeString::endsWith(const UChar
*srcChars
,
4284 int32_t srcLength
) const {
4286 srcLength
= u_strlen(srcChars
+ srcStart
);
4288 return doCompare(length() - srcLength
, srcLength
,
4289 srcChars
, srcStart
, srcLength
) == 0;
4292 //========================================
4294 //========================================
4295 inline UnicodeString
&
4296 UnicodeString::replace(int32_t start
,
4298 const UnicodeString
& srcText
)
4299 { return doReplace(start
, _length
, srcText
, 0, srcText
.length()); }
4301 inline UnicodeString
&
4302 UnicodeString::replace(int32_t start
,
4304 const UnicodeString
& srcText
,
4307 { return doReplace(start
, _length
, srcText
, srcStart
, srcLength
); }
4309 inline UnicodeString
&
4310 UnicodeString::replace(int32_t start
,
4312 const UChar
*srcChars
,
4314 { return doReplace(start
, _length
, srcChars
, 0, srcLength
); }
4316 inline UnicodeString
&
4317 UnicodeString::replace(int32_t start
,
4319 const UChar
*srcChars
,
4322 { return doReplace(start
, _length
, srcChars
, srcStart
, srcLength
); }
4324 inline UnicodeString
&
4325 UnicodeString::replace(int32_t start
,
4328 { return doReplace(start
, _length
, &srcChar
, 0, 1); }
4330 inline UnicodeString
&
4331 UnicodeString::replaceBetween(int32_t start
,
4333 const UnicodeString
& srcText
)
4334 { return doReplace(start
, limit
- start
, srcText
, 0, srcText
.length()); }
4336 inline UnicodeString
&
4337 UnicodeString::replaceBetween(int32_t start
,
4339 const UnicodeString
& srcText
,
4342 { return doReplace(start
, limit
- start
, srcText
, srcStart
, srcLimit
- srcStart
); }
4344 inline UnicodeString
&
4345 UnicodeString::findAndReplace(const UnicodeString
& oldText
,
4346 const UnicodeString
& newText
)
4347 { return findAndReplace(0, length(), oldText
, 0, oldText
.length(),
4348 newText
, 0, newText
.length()); }
4350 inline UnicodeString
&
4351 UnicodeString::findAndReplace(int32_t start
,
4353 const UnicodeString
& oldText
,
4354 const UnicodeString
& newText
)
4355 { return findAndReplace(start
, _length
, oldText
, 0, oldText
.length(),
4356 newText
, 0, newText
.length()); }
4358 // ============================
4360 // ============================
4362 UnicodeString::doExtract(int32_t start
,
4364 UnicodeString
& target
) const
4365 { target
.replace(0, target
.length(), *this, start
, _length
); }
4368 UnicodeString::extract(int32_t start
,
4371 int32_t targetStart
) const
4372 { doExtract(start
, _length
, target
, targetStart
); }
4375 UnicodeString::extract(int32_t start
,
4377 UnicodeString
& target
) const
4378 { doExtract(start
, _length
, target
); }
4380 #if !UCONFIG_NO_CONVERSION
4383 UnicodeString::extract(int32_t start
,
4386 const char *codepage
) const
4389 // This dstSize value will be checked explicitly
4390 return extract(start
, _length
, dst
, dst
!=0 ? 0xffffffff : 0, codepage
);
4396 UnicodeString::extractBetween(int32_t start
,
4399 int32_t dstStart
) const {
4402 doExtract(start
, limit
- start
, dst
, dstStart
);
4405 inline UnicodeString
4406 UnicodeString::tempSubStringBetween(int32_t start
, int32_t limit
) const {
4407 return tempSubString(start
, limit
- start
);
4411 UnicodeString::doCharAt(int32_t offset
) const
4413 if((uint32_t)offset
< (uint32_t)length()) {
4414 return getArrayStart()[offset
];
4416 return kInvalidUChar
;
4421 UnicodeString::charAt(int32_t offset
) const
4422 { return doCharAt(offset
); }
4425 UnicodeString::operator[] (int32_t offset
) const
4426 { return doCharAt(offset
); }
4429 UnicodeString::isEmpty() const {
4430 // Arithmetic or logical right shift does not matter: only testing for 0.
4431 return (fUnion
.fFields
.fLengthAndFlags
>>kLengthShift
) == 0;
4434 //========================================
4435 // Write implementation methods
4436 //========================================
4438 UnicodeString::setZeroLength() {
4439 fUnion
.fFields
.fLengthAndFlags
&= kAllStorageFlags
;
4443 UnicodeString::setShortLength(int32_t len
) {
4444 // requires 0 <= len <= kMaxShortLength
4445 fUnion
.fFields
.fLengthAndFlags
=
4446 (int16_t)((fUnion
.fFields
.fLengthAndFlags
& kAllStorageFlags
) | (len
<< kLengthShift
));
4450 UnicodeString::setLength(int32_t len
) {
4451 if(len
<= kMaxShortLength
) {
4452 setShortLength(len
);
4454 fUnion
.fFields
.fLengthAndFlags
|= kLengthIsLarge
;
4455 fUnion
.fFields
.fLength
= len
;
4460 UnicodeString::setToEmpty() {
4461 fUnion
.fFields
.fLengthAndFlags
= kShortString
;
4465 UnicodeString::setArray(UChar
*array
, int32_t len
, int32_t capacity
) {
4467 fUnion
.fFields
.fArray
= array
;
4468 fUnion
.fFields
.fCapacity
= capacity
;
4471 inline UnicodeString
&
4472 UnicodeString::operator= (UChar ch
)
4473 { return doReplace(0, length(), &ch
, 0, 1); }
4475 inline UnicodeString
&
4476 UnicodeString::operator= (UChar32 ch
)
4477 { return replace(0, length(), ch
); }
4479 inline UnicodeString
&
4480 UnicodeString::setTo(const UnicodeString
& srcText
,
4485 return doReplace(0, length(), srcText
, srcStart
, srcLength
);
4488 inline UnicodeString
&
4489 UnicodeString::setTo(const UnicodeString
& srcText
,
4493 srcText
.pinIndex(srcStart
);
4494 return doReplace(0, length(), srcText
, srcStart
, srcText
.length() - srcStart
);
4497 inline UnicodeString
&
4498 UnicodeString::setTo(const UnicodeString
& srcText
)
4500 return copyFrom(srcText
);
4503 inline UnicodeString
&
4504 UnicodeString::setTo(const UChar
*srcChars
,
4508 return doReplace(0, length(), srcChars
, 0, srcLength
);
4511 inline UnicodeString
&
4512 UnicodeString::setTo(UChar srcChar
)
4515 return doReplace(0, length(), &srcChar
, 0, 1);
4518 inline UnicodeString
&
4519 UnicodeString::setTo(UChar32 srcChar
)
4522 return replace(0, length(), srcChar
);
4525 inline UnicodeString
&
4526 UnicodeString::append(const UnicodeString
& srcText
,
4529 { return doAppend(srcText
, srcStart
, srcLength
); }
4531 inline UnicodeString
&
4532 UnicodeString::append(const UnicodeString
& srcText
)
4533 { return doAppend(srcText
, 0, srcText
.length()); }
4535 inline UnicodeString
&
4536 UnicodeString::append(const UChar
*srcChars
,
4539 { return doAppend(srcChars
, srcStart
, srcLength
); }
4541 inline UnicodeString
&
4542 UnicodeString::append(const UChar
*srcChars
,
4544 { return doAppend(srcChars
, 0, srcLength
); }
4546 inline UnicodeString
&
4547 UnicodeString::append(UChar srcChar
)
4548 { return doAppend(&srcChar
, 0, 1); }
4550 inline UnicodeString
&
4551 UnicodeString::operator+= (UChar ch
)
4552 { return doAppend(&ch
, 0, 1); }
4554 inline UnicodeString
&
4555 UnicodeString::operator+= (UChar32 ch
) {
4559 inline UnicodeString
&
4560 UnicodeString::operator+= (const UnicodeString
& srcText
)
4561 { return doAppend(srcText
, 0, srcText
.length()); }
4563 inline UnicodeString
&
4564 UnicodeString::insert(int32_t start
,
4565 const UnicodeString
& srcText
,
4568 { return doReplace(start
, 0, srcText
, srcStart
, srcLength
); }
4570 inline UnicodeString
&
4571 UnicodeString::insert(int32_t start
,
4572 const UnicodeString
& srcText
)
4573 { return doReplace(start
, 0, srcText
, 0, srcText
.length()); }
4575 inline UnicodeString
&
4576 UnicodeString::insert(int32_t start
,
4577 const UChar
*srcChars
,
4580 { return doReplace(start
, 0, srcChars
, srcStart
, srcLength
); }
4582 inline UnicodeString
&
4583 UnicodeString::insert(int32_t start
,
4584 const UChar
*srcChars
,
4586 { return doReplace(start
, 0, srcChars
, 0, srcLength
); }
4588 inline UnicodeString
&
4589 UnicodeString::insert(int32_t start
,
4591 { return doReplace(start
, 0, &srcChar
, 0, 1); }
4593 inline UnicodeString
&
4594 UnicodeString::insert(int32_t start
,
4596 { return replace(start
, 0, srcChar
); }
4599 inline UnicodeString
&
4600 UnicodeString::remove()
4602 // remove() of a bogus string makes the string empty and non-bogus
4611 inline UnicodeString
&
4612 UnicodeString::remove(int32_t start
,
4615 if(start
<= 0 && _length
== INT32_MAX
) {
4616 // remove(guaranteed everything) of a bogus string makes the string empty and non-bogus
4619 return doReplace(start
, _length
, NULL
, 0, 0);
4622 inline UnicodeString
&
4623 UnicodeString::removeBetween(int32_t start
,
4625 { return doReplace(start
, limit
- start
, NULL
, 0, 0); }
4627 inline UnicodeString
&
4628 UnicodeString::retainBetween(int32_t start
, int32_t limit
) {
4630 return doReplace(0, start
, NULL
, 0, 0);
4634 UnicodeString::truncate(int32_t targetLength
)
4636 if(isBogus() && targetLength
== 0) {
4637 // truncate(0) of a bogus string makes the string empty and non-bogus
4640 } else if((uint32_t)targetLength
< (uint32_t)length()) {
4641 setLength(targetLength
);
4648 inline UnicodeString
&
4649 UnicodeString::reverse()
4650 { return doReverse(0, length()); }
4652 inline UnicodeString
&
4653 UnicodeString::reverse(int32_t start
,
4655 { return doReverse(start
, _length
); }