2 **********************************************************************
3 * Copyright (C) 1998-2006, 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/rep.h"
31 struct UConverter
; // unicode/ucnv.h
32 class StringThreadTest
;
34 #ifndef U_COMPARE_CODE_POINT_ORDER
35 /* see also ustring.h and unorm.h */
37 * Option bit for u_strCaseCompare, u_strcasecmp, unorm_compare, etc:
38 * Compare strings in code point order instead of code unit order.
41 #define U_COMPARE_CODE_POINT_ORDER 0x8000
46 * \ingroup ustring_ustrlen
48 U_STABLE
int32_t U_EXPORT2
49 u_strlen(const UChar
*s
);
54 class Locale
; // unicode/locid.h
55 class StringCharacterIterator
;
56 class BreakIterator
; // unicode/brkiter.h
58 /* The <iostream> include has been moved to unicode/ustream.h */
61 * Constant to be used in the UnicodeString(char *, int32_t, EInvariant) constructor
62 * which constructs a Unicode string from an invariant-character char * string.
63 * About invariant characters see utypes.h.
64 * This constructor has no runtime dependency on conversion code and is
65 * therefore recommended over ones taking a charset name string
66 * (where the empty string "" indicates invariant-character conversion).
70 #define US_INV UnicodeString::kInvariant
73 * Unicode String literals in C++.
74 * Dependent on the platform properties, different UnicodeString
75 * constructors should be used to create a UnicodeString object from
77 * The macros are defined for maximum performance.
78 * They work only for strings that contain "invariant characters", i.e.,
79 * only latin letters, digits, and some punctuation.
80 * See utypes.h for details.
82 * The string parameter must be a C string literal.
83 * The length of the string, not including the terminating
84 * <code>NUL</code>, must be specified as a constant.
85 * The U_STRING_DECL macro should be invoked exactly once for one
86 * such string variable before it is used.
89 #if U_SIZEOF_WCHAR_T==U_SIZEOF_UCHAR && (U_CHARSET_FAMILY==U_ASCII_FAMILY || (U_SIZEOF_UCHAR == 2 && defined(U_WCHAR_IS_UTF16)))
90 # define UNICODE_STRING(cs, _length) UnicodeString(TRUE, (const UChar *)L ## cs, _length)
91 #elif U_SIZEOF_UCHAR==1 && U_CHARSET_FAMILY==U_ASCII_FAMILY
92 # define UNICODE_STRING(cs, _length) UnicodeString(TRUE, (const UChar *)cs, _length)
94 # define UNICODE_STRING(cs, _length) UnicodeString(cs, _length, US_INV)
98 * Unicode String literals in C++.
99 * Dependent on the platform properties, different UnicodeString
100 * constructors should be used to create a UnicodeString object from
102 * The macros are defined for improved performance.
103 * They work only for strings that contain "invariant characters", i.e.,
104 * only latin letters, digits, and some punctuation.
105 * See utypes.h for details.
107 * The string parameter must be a C string literal.
110 #if U_SIZEOF_WCHAR_T==U_SIZEOF_UCHAR && (U_CHARSET_FAMILY==U_ASCII_FAMILY || (U_SIZEOF_UCHAR == 2 && defined(U_WCHAR_IS_UTF16)))
111 # define UNICODE_STRING_SIMPLE(cs) UnicodeString(TRUE, (const UChar *)L ## cs, -1)
112 #elif U_SIZEOF_UCHAR==1 && U_CHARSET_FAMILY==U_ASCII_FAMILY
113 # define UNICODE_STRING_SIMPLE(cs) UnicodeString(TRUE, (const UChar *)cs, -1)
115 # define UNICODE_STRING_SIMPLE(cs) UnicodeString(cs, -1, US_INV)
119 * UnicodeString is a string class that stores Unicode characters directly and provides
120 * similar functionality as the Java String and StringBuffer classes.
121 * It is a concrete implementation of the abstract class Replaceable (for transliteration).
123 * The UnicodeString class is not suitable for subclassing.
125 * <p>For an overview of Unicode strings in C and C++ see the
126 * <a href="http://icu.sourceforge.net/userguide/strings.html">User Guide Strings chapter</a>.</p>
128 * <p>In ICU, a Unicode string consists of 16-bit Unicode <em>code units</em>.
129 * A Unicode character may be stored with either one code unit
130 * (the most common case) or with a matched pair of special code units
131 * ("surrogates"). The data type for code units is UChar.
132 * For single-character handling, a Unicode character code <em>point</em> is a value
133 * in the range 0..0x10ffff. ICU uses the UChar32 type for code points.</p>
135 * <p>Indexes and offsets into and lengths of strings always count code units, not code points.
136 * This is the same as with multi-byte char* strings in traditional string handling.
137 * Operations on partial strings typically do not test for code point boundaries.
138 * If necessary, the user needs to take care of such boundaries by testing for the code unit
139 * values or by using functions like
140 * UnicodeString::getChar32Start() and UnicodeString::getChar32Limit()
141 * (or, in C, the equivalent macros U16_SET_CP_START() and U16_SET_CP_LIMIT(), see utf.h).</p>
143 * UnicodeString methods are more lenient with regard to input parameter values
144 * than other ICU APIs. In particular:
145 * - If indexes are out of bounds for a UnicodeString object
146 * (<0 or >length()) then they are "pinned" to the nearest boundary.
147 * - If primitive string pointer values (e.g., const UChar * or char *)
148 * for input strings are NULL, then those input string parameters are treated
149 * as if they pointed to an empty string.
150 * However, this is <em>not</em> the case for char * parameters for charset names
152 * - Most UnicodeString methods do not take a UErrorCode parameter because
153 * there are usually very few opportunities for failure other than a shortage
154 * of memory, error codes in low-level C++ string methods would be inconvenient,
155 * and the error code as the last parameter (ICU convention) would prevent
156 * the use of default parameter values.
157 * Instead, such methods set the UnicodeString into a "bogus" state
158 * (see isBogus()) if an error occurs.
160 * In string comparisons, two UnicodeString objects that are both "bogus"
161 * compare equal (to be transitive and prevent endless loops in sorting),
162 * and a "bogus" string compares less than any non-"bogus" one.
164 * Const UnicodeString methods are thread-safe. Multiple threads can use
165 * const methods on the same UnicodeString object simultaneously,
166 * but non-const methods must not be called concurrently (in multiple threads)
167 * with any other (const or non-const) methods.
169 * Similarly, const UnicodeString & parameters are thread-safe.
170 * One object may be passed in as such a parameter concurrently in multiple threads.
171 * This includes the const UnicodeString & parameters for
172 * copy construction, assignment, and cloning.
174 * <p>UnicodeString uses several storage methods.
175 * String contents can be stored inside the UnicodeString object itself,
176 * in an allocated and shared buffer, or in an outside buffer that is "aliased".
177 * Most of this is done transparently, but careful aliasing in particular provides
178 * significant performance improvements.
179 * Also, the internal buffer is accessible via special functions.
180 * For details see the
181 * <a href="http://icu.sourceforge.net/userguide/strings.html">User Guide Strings chapter</a>.</p>
184 * @see CharacterIterator
187 class U_COMMON_API UnicodeString
: public Replaceable
192 * Constant to be used in the UnicodeString(char *, int32_t, EInvariant) constructor
193 * which constructs a Unicode string from an invariant-character char * string.
194 * Use the macro US_INV instead of the full qualification for this value.
207 //========================================
208 // Read-only operations
209 //========================================
211 /* Comparison - bitwise only - for international comparison use collation */
214 * Equality operator. Performs only bitwise comparison.
215 * @param text The UnicodeString to compare to this one.
216 * @return TRUE if <TT>text</TT> contains the same characters as this one,
220 inline UBool
operator== (const UnicodeString
& text
) const;
223 * Inequality operator. Performs only bitwise comparison.
224 * @param text The UnicodeString to compare to this one.
225 * @return FALSE if <TT>text</TT> contains the same characters as this one,
229 inline UBool
operator!= (const UnicodeString
& text
) const;
232 * Greater than operator. Performs only bitwise comparison.
233 * @param text The UnicodeString to compare to this one.
234 * @return TRUE if the characters in this are bitwise
235 * greater than the characters in <code>text</code>, FALSE otherwise
238 inline UBool
operator> (const UnicodeString
& text
) const;
241 * Less than operator. Performs only bitwise comparison.
242 * @param text The UnicodeString to compare to this one.
243 * @return TRUE if the characters in this are bitwise
244 * less than the characters in <code>text</code>, FALSE otherwise
247 inline UBool
operator< (const UnicodeString
& text
) const;
250 * Greater than or equal operator. Performs only bitwise comparison.
251 * @param text The UnicodeString to compare to this one.
252 * @return TRUE if the characters in this are bitwise
253 * greater than or equal to the characters in <code>text</code>, FALSE otherwise
256 inline UBool
operator>= (const UnicodeString
& text
) const;
259 * Less than or equal operator. Performs only bitwise comparison.
260 * @param text The UnicodeString to compare to this one.
261 * @return TRUE if the characters in this are bitwise
262 * less than or equal to the characters in <code>text</code>, FALSE otherwise
265 inline UBool
operator<= (const UnicodeString
& text
) const;
268 * Compare the characters bitwise in this UnicodeString to
269 * the characters in <code>text</code>.
270 * @param text The UnicodeString to compare to this one.
271 * @return The result of bitwise character comparison: 0 if this
272 * contains the same characters as <code>text</code>, -1 if the characters in
273 * this are bitwise less than the characters in <code>text</code>, +1 if the
274 * characters in this are bitwise greater than the characters
275 * in <code>text</code>.
278 inline int8_t compare(const UnicodeString
& text
) const;
281 * Compare the characters bitwise in the range
282 * [<TT>start</TT>, <TT>start + length</TT>) with the characters
284 * @param start the offset at which the compare operation begins
285 * @param length the number of characters of text to compare.
286 * @param text the other text to be compared against this string.
287 * @return The result of bitwise character comparison: 0 if this
288 * contains the same characters as <code>text</code>, -1 if the characters in
289 * this are bitwise less than the characters in <code>text</code>, +1 if the
290 * characters in this are bitwise greater than the characters
291 * in <code>text</code>.
294 inline int8_t compare(int32_t start
,
296 const UnicodeString
& text
) const;
299 * Compare the characters bitwise in the range
300 * [<TT>start</TT>, <TT>start + length</TT>) with the characters
301 * in <TT>srcText</TT> in the range
302 * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
303 * @param start the offset at which the compare operation begins
304 * @param length the number of characters in this to compare.
305 * @param srcText the text to be compared
306 * @param srcStart the offset into <TT>srcText</TT> to start comparison
307 * @param srcLength the number of characters in <TT>src</TT> to compare
308 * @return The result of bitwise character comparison: 0 if this
309 * contains the same characters as <code>srcText</code>, -1 if the characters in
310 * this are bitwise less than the characters in <code>srcText</code>, +1 if the
311 * characters in this are bitwise greater than the characters
312 * in <code>srcText</code>.
315 inline int8_t compare(int32_t start
,
317 const UnicodeString
& srcText
,
319 int32_t srcLength
) const;
322 * Compare the characters bitwise in this UnicodeString with the first
323 * <TT>srcLength</TT> characters in <TT>srcChars</TT>.
324 * @param srcChars The characters to compare to this UnicodeString.
325 * @param srcLength the number of characters in <TT>srcChars</TT> to compare
326 * @return The result of bitwise character comparison: 0 if this
327 * contains the same characters as <code>srcChars</code>, -1 if the characters in
328 * this are bitwise less than the characters in <code>srcChars</code>, +1 if the
329 * characters in this are bitwise greater than the characters
330 * in <code>srcChars</code>.
333 inline int8_t compare(const UChar
*srcChars
,
334 int32_t srcLength
) const;
337 * Compare the characters bitwise in the range
338 * [<TT>start</TT>, <TT>start + length</TT>) with the first
339 * <TT>length</TT> characters in <TT>srcChars</TT>
340 * @param start the offset at which the compare operation begins
341 * @param length the number of characters to compare.
342 * @param srcChars the characters to be compared
343 * @return The result of bitwise character comparison: 0 if this
344 * contains the same characters as <code>srcChars</code>, -1 if the characters in
345 * this are bitwise less than the characters in <code>srcChars</code>, +1 if the
346 * characters in this are bitwise greater than the characters
347 * in <code>srcChars</code>.
350 inline int8_t compare(int32_t start
,
352 const UChar
*srcChars
) const;
355 * Compare the characters bitwise in the range
356 * [<TT>start</TT>, <TT>start + length</TT>) with the characters
357 * in <TT>srcChars</TT> in the range
358 * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
359 * @param start the offset at which the compare operation begins
360 * @param length the number of characters in this to compare
361 * @param srcChars the characters to be compared
362 * @param srcStart the offset into <TT>srcChars</TT> to start comparison
363 * @param srcLength the number of characters in <TT>srcChars</TT> to compare
364 * @return The result of bitwise character comparison: 0 if this
365 * contains the same characters as <code>srcChars</code>, -1 if the characters in
366 * this are bitwise less than the characters in <code>srcChars</code>, +1 if the
367 * characters in this are bitwise greater than the characters
368 * in <code>srcChars</code>.
371 inline int8_t compare(int32_t start
,
373 const UChar
*srcChars
,
375 int32_t srcLength
) const;
378 * Compare the characters bitwise in the range
379 * [<TT>start</TT>, <TT>limit</TT>) with the characters
380 * in <TT>srcText</TT> in the range
381 * [<TT>srcStart</TT>, <TT>srcLimit</TT>).
382 * @param start the offset at which the compare operation begins
383 * @param limit the offset immediately following the compare operation
384 * @param srcText the text to be compared
385 * @param srcStart the offset into <TT>srcText</TT> to start comparison
386 * @param srcLimit the offset into <TT>srcText</TT> to limit comparison
387 * @return The result of bitwise character comparison: 0 if this
388 * contains the same characters as <code>srcText</code>, -1 if the characters in
389 * this are bitwise less than the characters in <code>srcText</code>, +1 if the
390 * characters in this are bitwise greater than the characters
391 * in <code>srcText</code>.
394 inline int8_t compareBetween(int32_t start
,
396 const UnicodeString
& srcText
,
398 int32_t srcLimit
) const;
401 * Compare two Unicode strings in code point order.
402 * This is different in UTF-16 from how compare(), operator==, startsWith() etc. work
403 * if supplementary characters are present:
405 * In UTF-16, supplementary characters (with code points U+10000 and above) are
406 * stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff,
407 * which means that they compare as less than some other BMP characters like U+feff.
408 * This function compares Unicode strings in code point order.
409 * If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.
411 * @param text Another string to compare this one to.
412 * @return a negative/zero/positive integer corresponding to whether
413 * this string is less than/equal to/greater than the second one
414 * in code point order
417 inline int8_t compareCodePointOrder(const UnicodeString
& text
) const;
420 * Compare two Unicode strings in code point order.
421 * This is different in UTF-16 from how compare(), operator==, startsWith() etc. work
422 * if supplementary characters are present:
424 * In UTF-16, supplementary characters (with code points U+10000 and above) are
425 * stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff,
426 * which means that they compare as less than some other BMP characters like U+feff.
427 * This function compares Unicode strings in code point order.
428 * If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.
430 * @param start The start offset in this string at which the compare operation begins.
431 * @param length The number of code units from this string to compare.
432 * @param srcText Another string to compare this one to.
433 * @return a negative/zero/positive integer corresponding to whether
434 * this string is less than/equal to/greater than the second one
435 * in code point order
438 inline int8_t compareCodePointOrder(int32_t start
,
440 const UnicodeString
& srcText
) const;
443 * Compare two Unicode strings in code point order.
444 * This is different in UTF-16 from how compare(), operator==, startsWith() etc. work
445 * if supplementary characters are present:
447 * In UTF-16, supplementary characters (with code points U+10000 and above) are
448 * stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff,
449 * which means that they compare as less than some other BMP characters like U+feff.
450 * This function compares Unicode strings in code point order.
451 * If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.
453 * @param start The start offset in this string at which the compare operation begins.
454 * @param length The number of code units from this string to compare.
455 * @param srcText Another string to compare this one to.
456 * @param srcStart The start offset in that string at which the compare operation begins.
457 * @param srcLength The number of code units from that string to compare.
458 * @return a negative/zero/positive integer corresponding to whether
459 * this string is less than/equal to/greater than the second one
460 * in code point order
463 inline int8_t compareCodePointOrder(int32_t start
,
465 const UnicodeString
& srcText
,
467 int32_t srcLength
) const;
470 * Compare two Unicode strings in code point order.
471 * This is different in UTF-16 from how compare(), operator==, startsWith() etc. work
472 * if supplementary characters are present:
474 * In UTF-16, supplementary characters (with code points U+10000 and above) are
475 * stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff,
476 * which means that they compare as less than some other BMP characters like U+feff.
477 * This function compares Unicode strings in code point order.
478 * If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.
480 * @param srcChars A pointer to another string to compare this one to.
481 * @param srcLength The number of code units from that string to compare.
482 * @return a negative/zero/positive integer corresponding to whether
483 * this string is less than/equal to/greater than the second one
484 * in code point order
487 inline int8_t compareCodePointOrder(const UChar
*srcChars
,
488 int32_t srcLength
) const;
491 * Compare two Unicode strings in code point order.
492 * This is different in UTF-16 from how compare(), operator==, startsWith() etc. work
493 * if supplementary characters are present:
495 * In UTF-16, supplementary characters (with code points U+10000 and above) are
496 * stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff,
497 * which means that they compare as less than some other BMP characters like U+feff.
498 * This function compares Unicode strings in code point order.
499 * If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.
501 * @param start The start offset in this string at which the compare operation begins.
502 * @param length The number of code units from this string to compare.
503 * @param srcChars A pointer to another string to compare this one to.
504 * @return a negative/zero/positive integer corresponding to whether
505 * this string is less than/equal to/greater than the second one
506 * in code point order
509 inline int8_t compareCodePointOrder(int32_t start
,
511 const UChar
*srcChars
) const;
514 * Compare two Unicode strings in code point order.
515 * This is different in UTF-16 from how compare(), operator==, startsWith() etc. work
516 * if supplementary characters are present:
518 * In UTF-16, supplementary characters (with code points U+10000 and above) are
519 * stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff,
520 * which means that they compare as less than some other BMP characters like U+feff.
521 * This function compares Unicode strings in code point order.
522 * If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.
524 * @param start The start offset in this string at which the compare operation begins.
525 * @param length The number of code units from this string to compare.
526 * @param srcChars A pointer to another string to compare this one to.
527 * @param srcStart The start offset in that string at which the compare operation begins.
528 * @param srcLength The number of code units from that string to compare.
529 * @return a negative/zero/positive integer corresponding to whether
530 * this string is less than/equal to/greater than the second one
531 * in code point order
534 inline int8_t compareCodePointOrder(int32_t start
,
536 const UChar
*srcChars
,
538 int32_t srcLength
) const;
541 * Compare two Unicode strings in code point order.
542 * This is different in UTF-16 from how compare(), operator==, startsWith() etc. work
543 * if supplementary characters are present:
545 * In UTF-16, supplementary characters (with code points U+10000 and above) are
546 * stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff,
547 * which means that they compare as less than some other BMP characters like U+feff.
548 * This function compares Unicode strings in code point order.
549 * If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.
551 * @param start The start offset in this string at which the compare operation begins.
552 * @param limit The offset after the last code unit from this string to compare.
553 * @param srcText Another string to compare this one to.
554 * @param srcStart The start offset in that string at which the compare operation begins.
555 * @param srcLimit The offset after the last code unit from that string to compare.
556 * @return a negative/zero/positive integer corresponding to whether
557 * this string is less than/equal to/greater than the second one
558 * in code point order
561 inline int8_t compareCodePointOrderBetween(int32_t start
,
563 const UnicodeString
& srcText
,
565 int32_t srcLimit
) const;
568 * Compare two strings case-insensitively using full case folding.
569 * This is equivalent to this->foldCase(options).compare(text.foldCase(options)).
571 * @param text Another string to compare this one to.
572 * @param options A bit set of options:
573 * - U_FOLD_CASE_DEFAULT or 0 is used for default options:
574 * Comparison in code unit order with default case folding.
576 * - U_COMPARE_CODE_POINT_ORDER
577 * Set to choose code point order instead of code unit order
578 * (see u_strCompare for details).
580 * - U_FOLD_CASE_EXCLUDE_SPECIAL_I
582 * @return A negative, zero, or positive integer indicating the comparison result.
585 inline int8_t caseCompare(const UnicodeString
& text
, uint32_t options
) const;
588 * Compare two strings case-insensitively using full case folding.
589 * This is equivalent to this->foldCase(options).compare(srcText.foldCase(options)).
591 * @param start The start offset in this string at which the compare operation begins.
592 * @param length The number of code units from this string to compare.
593 * @param srcText Another string to compare this one to.
594 * @param options A bit set of options:
595 * - U_FOLD_CASE_DEFAULT or 0 is used for default options:
596 * Comparison in code unit order with default case folding.
598 * - U_COMPARE_CODE_POINT_ORDER
599 * Set to choose code point order instead of code unit order
600 * (see u_strCompare for details).
602 * - U_FOLD_CASE_EXCLUDE_SPECIAL_I
604 * @return A negative, zero, or positive integer indicating the comparison result.
607 inline int8_t caseCompare(int32_t start
,
609 const UnicodeString
& srcText
,
610 uint32_t options
) const;
613 * Compare two strings case-insensitively using full case folding.
614 * This is equivalent to this->foldCase(options).compare(srcText.foldCase(options)).
616 * @param start The start offset in this string at which the compare operation begins.
617 * @param length The number of code units from this string to compare.
618 * @param srcText Another string to compare this one to.
619 * @param srcStart The start offset in that string at which the compare operation begins.
620 * @param srcLength The number of code units from that string to compare.
621 * @param options A bit set of options:
622 * - U_FOLD_CASE_DEFAULT or 0 is used for default options:
623 * Comparison in code unit order with default case folding.
625 * - U_COMPARE_CODE_POINT_ORDER
626 * Set to choose code point order instead of code unit order
627 * (see u_strCompare for details).
629 * - U_FOLD_CASE_EXCLUDE_SPECIAL_I
631 * @return A negative, zero, or positive integer indicating the comparison result.
634 inline int8_t caseCompare(int32_t start
,
636 const UnicodeString
& srcText
,
639 uint32_t options
) const;
642 * Compare two strings case-insensitively using full case folding.
643 * This is equivalent to this->foldCase(options).compare(srcChars.foldCase(options)).
645 * @param srcChars A pointer to another string to compare this one to.
646 * @param srcLength The number of code units from that string to compare.
647 * @param options A bit set of options:
648 * - U_FOLD_CASE_DEFAULT or 0 is used for default options:
649 * Comparison in code unit order with default case folding.
651 * - U_COMPARE_CODE_POINT_ORDER
652 * Set to choose code point order instead of code unit order
653 * (see u_strCompare for details).
655 * - U_FOLD_CASE_EXCLUDE_SPECIAL_I
657 * @return A negative, zero, or positive integer indicating the comparison result.
660 inline int8_t caseCompare(const UChar
*srcChars
,
662 uint32_t options
) const;
665 * Compare two strings case-insensitively using full case folding.
666 * This is equivalent to this->foldCase(options).compare(srcChars.foldCase(options)).
668 * @param start The start offset in this string at which the compare operation begins.
669 * @param length The number of code units from this string to compare.
670 * @param srcChars A pointer to another string to compare this one to.
671 * @param options A bit set of options:
672 * - U_FOLD_CASE_DEFAULT or 0 is used for default options:
673 * Comparison in code unit order with default case folding.
675 * - U_COMPARE_CODE_POINT_ORDER
676 * Set to choose code point order instead of code unit order
677 * (see u_strCompare for details).
679 * - U_FOLD_CASE_EXCLUDE_SPECIAL_I
681 * @return A negative, zero, or positive integer indicating the comparison result.
684 inline int8_t caseCompare(int32_t start
,
686 const UChar
*srcChars
,
687 uint32_t options
) const;
690 * Compare two strings case-insensitively using full case folding.
691 * This is equivalent to this->foldCase(options).compare(srcChars.foldCase(options)).
693 * @param start The start offset in this string at which the compare operation begins.
694 * @param length The number of code units from this string to compare.
695 * @param srcChars A pointer to another string to compare this one to.
696 * @param srcStart The start offset in that string at which the compare operation begins.
697 * @param srcLength The number of code units from that string to compare.
698 * @param options A bit set of options:
699 * - U_FOLD_CASE_DEFAULT or 0 is used for default options:
700 * Comparison in code unit order with default case folding.
702 * - U_COMPARE_CODE_POINT_ORDER
703 * Set to choose code point order instead of code unit order
704 * (see u_strCompare for details).
706 * - U_FOLD_CASE_EXCLUDE_SPECIAL_I
708 * @return A negative, zero, or positive integer indicating the comparison result.
711 inline int8_t caseCompare(int32_t start
,
713 const UChar
*srcChars
,
716 uint32_t options
) const;
719 * Compare two strings case-insensitively using full case folding.
720 * This is equivalent to this->foldCase(options).compareBetween(text.foldCase(options)).
722 * @param start The start offset in this string at which the compare operation begins.
723 * @param limit The offset after the last code unit from this string to compare.
724 * @param srcText Another string to compare this one to.
725 * @param srcStart The start offset in that string at which the compare operation begins.
726 * @param srcLimit The offset after the last code unit from that string to compare.
727 * @param options A bit set of options:
728 * - U_FOLD_CASE_DEFAULT or 0 is used for default options:
729 * Comparison in code unit order with default case folding.
731 * - U_COMPARE_CODE_POINT_ORDER
732 * Set to choose code point order instead of code unit order
733 * (see u_strCompare for details).
735 * - U_FOLD_CASE_EXCLUDE_SPECIAL_I
737 * @return A negative, zero, or positive integer indicating the comparison result.
740 inline int8_t caseCompareBetween(int32_t start
,
742 const UnicodeString
& srcText
,
745 uint32_t options
) const;
748 * Determine if this starts with the characters in <TT>text</TT>
749 * @param text The text to match.
750 * @return TRUE if this starts with the characters in <TT>text</TT>,
754 inline UBool
startsWith(const UnicodeString
& text
) const;
757 * Determine if this starts with the characters in <TT>srcText</TT>
758 * in the range [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
759 * @param srcText The text to match.
760 * @param srcStart the offset into <TT>srcText</TT> to start matching
761 * @param srcLength the number of characters in <TT>srcText</TT> to match
762 * @return TRUE if this starts with the characters in <TT>text</TT>,
766 inline UBool
startsWith(const UnicodeString
& srcText
,
768 int32_t srcLength
) const;
771 * Determine if this starts with the characters in <TT>srcChars</TT>
772 * @param srcChars The characters to match.
773 * @param srcLength the number of characters in <TT>srcChars</TT>
774 * @return TRUE if this starts with the characters in <TT>srcChars</TT>,
778 inline UBool
startsWith(const UChar
*srcChars
,
779 int32_t srcLength
) const;
782 * Determine if this ends with the characters in <TT>srcChars</TT>
783 * in the range [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
784 * @param srcChars The characters to match.
785 * @param srcStart the offset into <TT>srcText</TT> to start matching
786 * @param srcLength the number of characters in <TT>srcChars</TT> to match
787 * @return TRUE if this ends with the characters in <TT>srcChars</TT>, FALSE otherwise
790 inline UBool
startsWith(const UChar
*srcChars
,
792 int32_t srcLength
) const;
795 * Determine if this ends with the characters in <TT>text</TT>
796 * @param text The text to match.
797 * @return TRUE if this ends with the characters in <TT>text</TT>,
801 inline UBool
endsWith(const UnicodeString
& text
) const;
804 * Determine if this ends with the characters in <TT>srcText</TT>
805 * in the range [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
806 * @param srcText The text to match.
807 * @param srcStart the offset into <TT>srcText</TT> to start matching
808 * @param srcLength the number of characters in <TT>srcText</TT> to match
809 * @return TRUE if this ends with the characters in <TT>text</TT>,
813 inline UBool
endsWith(const UnicodeString
& srcText
,
815 int32_t srcLength
) const;
818 * Determine if this ends with the characters in <TT>srcChars</TT>
819 * @param srcChars The characters to match.
820 * @param srcLength the number of characters in <TT>srcChars</TT>
821 * @return TRUE if this ends with the characters in <TT>srcChars</TT>,
825 inline UBool
endsWith(const UChar
*srcChars
,
826 int32_t srcLength
) const;
829 * Determine if this ends with the characters in <TT>srcChars</TT>
830 * in the range [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
831 * @param srcChars The characters to match.
832 * @param srcStart the offset into <TT>srcText</TT> to start matching
833 * @param srcLength the number of characters in <TT>srcChars</TT> to match
834 * @return TRUE if this ends with the characters in <TT>srcChars</TT>,
838 inline UBool
endsWith(const UChar
*srcChars
,
840 int32_t srcLength
) const;
843 /* Searching - bitwise only */
846 * Locate in this the first occurrence of the characters in <TT>text</TT>,
847 * using bitwise comparison.
848 * @param text The text to search for.
849 * @return The offset into this of the start of <TT>text</TT>,
850 * or -1 if not found.
853 inline int32_t indexOf(const UnicodeString
& text
) const;
856 * Locate in this the first occurrence of the characters in <TT>text</TT>
857 * starting at offset <TT>start</TT>, using bitwise comparison.
858 * @param text The text to search for.
859 * @param start The offset at which searching will start.
860 * @return The offset into this of the start of <TT>text</TT>,
861 * or -1 if not found.
864 inline int32_t indexOf(const UnicodeString
& text
,
865 int32_t start
) const;
868 * Locate in this the first occurrence in the range
869 * [<TT>start</TT>, <TT>start + length</TT>) of the characters
870 * in <TT>text</TT>, using bitwise comparison.
871 * @param text The text to search for.
872 * @param start The offset at which searching will start.
873 * @param length The number of characters to search
874 * @return The offset into this of the start of <TT>text</TT>,
875 * or -1 if not found.
878 inline int32_t indexOf(const UnicodeString
& text
,
880 int32_t length
) const;
883 * Locate in this the first occurrence in the range
884 * [<TT>start</TT>, <TT>start + length</TT>) of the characters
885 * in <TT>srcText</TT> in the range
886 * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>),
887 * using bitwise comparison.
888 * @param srcText The text to search for.
889 * @param srcStart the offset into <TT>srcText</TT> at which
891 * @param srcLength the number of characters in <TT>srcText</TT> to match
892 * @param start the offset into this at which to start matching
893 * @param length the number of characters in this to search
894 * @return The offset into this of the start of <TT>text</TT>,
895 * or -1 if not found.
898 inline int32_t indexOf(const UnicodeString
& srcText
,
902 int32_t length
) const;
905 * Locate in this the first occurrence of the characters in
907 * starting at offset <TT>start</TT>, using bitwise comparison.
908 * @param srcChars The text to search for.
909 * @param srcLength the number of characters in <TT>srcChars</TT> to match
910 * @param start the offset into this at which to start matching
911 * @return The offset into this of the start of <TT>text</TT>,
912 * or -1 if not found.
915 inline int32_t indexOf(const UChar
*srcChars
,
917 int32_t start
) const;
920 * Locate in this the first occurrence in the range
921 * [<TT>start</TT>, <TT>start + length</TT>) of the characters
922 * in <TT>srcChars</TT>, using bitwise comparison.
923 * @param srcChars The text to search for.
924 * @param srcLength the number of characters in <TT>srcChars</TT>
925 * @param start The offset at which searching will start.
926 * @param length The number of characters to search
927 * @return The offset into this of the start of <TT>srcChars</TT>,
928 * or -1 if not found.
931 inline int32_t indexOf(const UChar
*srcChars
,
934 int32_t length
) const;
937 * Locate in this the first occurrence in the range
938 * [<TT>start</TT>, <TT>start + length</TT>) of the characters
939 * in <TT>srcChars</TT> in the range
940 * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>),
941 * using bitwise comparison.
942 * @param srcChars The text to search for.
943 * @param srcStart the offset into <TT>srcChars</TT> at which
945 * @param srcLength the number of characters in <TT>srcChars</TT> to match
946 * @param start the offset into this at which to start matching
947 * @param length the number of characters in this to search
948 * @return The offset into this of the start of <TT>text</TT>,
949 * or -1 if not found.
952 int32_t indexOf(const UChar
*srcChars
,
956 int32_t length
) const;
959 * Locate in this the first occurrence of the BMP code point <code>c</code>,
960 * using bitwise comparison.
961 * @param c The code unit to search for.
962 * @return The offset into this of <TT>c</TT>, or -1 if not found.
965 inline int32_t indexOf(UChar c
) const;
968 * Locate in this the first occurrence of the code point <TT>c</TT>,
969 * using bitwise comparison.
971 * @param c The code point to search for.
972 * @return The offset into this of <TT>c</TT>, or -1 if not found.
975 inline int32_t indexOf(UChar32 c
) const;
978 * Locate in this the first occurrence of the BMP code point <code>c</code>,
979 * starting at offset <TT>start</TT>, using bitwise comparison.
980 * @param c The code unit to search for.
981 * @param start The offset at which searching will start.
982 * @return The offset into this of <TT>c</TT>, or -1 if not found.
985 inline int32_t indexOf(UChar c
,
986 int32_t start
) const;
989 * Locate in this the first occurrence of the code point <TT>c</TT>
990 * starting at offset <TT>start</TT>, using bitwise comparison.
992 * @param c The code point to search for.
993 * @param start The offset at which searching will start.
994 * @return The offset into this of <TT>c</TT>, or -1 if not found.
997 inline int32_t indexOf(UChar32 c
,
998 int32_t start
) const;
1001 * Locate in this the first occurrence of the BMP code point <code>c</code>
1002 * in the range [<TT>start</TT>, <TT>start + length</TT>),
1003 * using bitwise comparison.
1004 * @param c The code unit to search for.
1005 * @param start the offset into this at which to start matching
1006 * @param length the number of characters in this to search
1007 * @return The offset into this of <TT>c</TT>, or -1 if not found.
1010 inline int32_t indexOf(UChar c
,
1012 int32_t length
) const;
1015 * Locate in this the first occurrence of the code point <TT>c</TT>
1016 * in the range [<TT>start</TT>, <TT>start + length</TT>),
1017 * using bitwise comparison.
1019 * @param c The code point to search for.
1020 * @param start the offset into this at which to start matching
1021 * @param length the number of characters in this to search
1022 * @return The offset into this of <TT>c</TT>, or -1 if not found.
1025 inline int32_t indexOf(UChar32 c
,
1027 int32_t length
) const;
1030 * Locate in this the last occurrence of the characters in <TT>text</TT>,
1031 * using bitwise comparison.
1032 * @param text The text to search for.
1033 * @return The offset into this of the start of <TT>text</TT>,
1034 * or -1 if not found.
1037 inline int32_t lastIndexOf(const UnicodeString
& text
) const;
1040 * Locate in this the last occurrence of the characters in <TT>text</TT>
1041 * starting at offset <TT>start</TT>, using bitwise comparison.
1042 * @param text The text to search for.
1043 * @param start The offset at which searching will start.
1044 * @return The offset into this of the start of <TT>text</TT>,
1045 * or -1 if not found.
1048 inline int32_t lastIndexOf(const UnicodeString
& text
,
1049 int32_t start
) const;
1052 * Locate in this the last occurrence in the range
1053 * [<TT>start</TT>, <TT>start + length</TT>) of the characters
1054 * in <TT>text</TT>, using bitwise comparison.
1055 * @param text The text to search for.
1056 * @param start The offset at which searching will start.
1057 * @param length The number of characters to search
1058 * @return The offset into this of the start of <TT>text</TT>,
1059 * or -1 if not found.
1062 inline int32_t lastIndexOf(const UnicodeString
& text
,
1064 int32_t length
) const;
1067 * Locate in this the last occurrence in the range
1068 * [<TT>start</TT>, <TT>start + length</TT>) of the characters
1069 * in <TT>srcText</TT> in the range
1070 * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>),
1071 * using bitwise comparison.
1072 * @param srcText The text to search for.
1073 * @param srcStart the offset into <TT>srcText</TT> at which
1075 * @param srcLength the number of characters in <TT>srcText</TT> to match
1076 * @param start the offset into this at which to start matching
1077 * @param length the number of characters in this to search
1078 * @return The offset into this of the start of <TT>text</TT>,
1079 * or -1 if not found.
1082 inline int32_t lastIndexOf(const UnicodeString
& srcText
,
1086 int32_t length
) const;
1089 * Locate in this the last occurrence of the characters in <TT>srcChars</TT>
1090 * starting at offset <TT>start</TT>, using bitwise comparison.
1091 * @param srcChars The text to search for.
1092 * @param srcLength the number of characters in <TT>srcChars</TT> to match
1093 * @param start the offset into this at which to start matching
1094 * @return The offset into this of the start of <TT>text</TT>,
1095 * or -1 if not found.
1098 inline int32_t lastIndexOf(const UChar
*srcChars
,
1100 int32_t start
) const;
1103 * Locate in this the last occurrence in the range
1104 * [<TT>start</TT>, <TT>start + length</TT>) of the characters
1105 * in <TT>srcChars</TT>, using bitwise comparison.
1106 * @param srcChars The text to search for.
1107 * @param srcLength the number of characters in <TT>srcChars</TT>
1108 * @param start The offset at which searching will start.
1109 * @param length The number of characters to search
1110 * @return The offset into this of the start of <TT>srcChars</TT>,
1111 * or -1 if not found.
1114 inline int32_t lastIndexOf(const UChar
*srcChars
,
1117 int32_t length
) const;
1120 * Locate in this the last occurrence in the range
1121 * [<TT>start</TT>, <TT>start + length</TT>) of the characters
1122 * in <TT>srcChars</TT> in the range
1123 * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>),
1124 * using bitwise comparison.
1125 * @param srcChars The text to search for.
1126 * @param srcStart the offset into <TT>srcChars</TT> at which
1128 * @param srcLength the number of characters in <TT>srcChars</TT> to match
1129 * @param start the offset into this at which to start matching
1130 * @param length the number of characters in this to search
1131 * @return The offset into this of the start of <TT>text</TT>,
1132 * or -1 if not found.
1135 int32_t lastIndexOf(const UChar
*srcChars
,
1139 int32_t length
) const;
1142 * Locate in this the last occurrence of the BMP code point <code>c</code>,
1143 * using bitwise comparison.
1144 * @param c The code unit to search for.
1145 * @return The offset into this of <TT>c</TT>, or -1 if not found.
1148 inline int32_t lastIndexOf(UChar c
) const;
1151 * Locate in this the last occurrence of the code point <TT>c</TT>,
1152 * using bitwise comparison.
1154 * @param c The code point to search for.
1155 * @return The offset into this of <TT>c</TT>, or -1 if not found.
1158 inline int32_t lastIndexOf(UChar32 c
) const;
1161 * Locate in this the last occurrence of the BMP code point <code>c</code>
1162 * starting at offset <TT>start</TT>, using bitwise comparison.
1163 * @param c The code unit to search for.
1164 * @param start The offset at which searching will start.
1165 * @return The offset into this of <TT>c</TT>, or -1 if not found.
1168 inline int32_t lastIndexOf(UChar c
,
1169 int32_t start
) const;
1172 * Locate in this the last occurrence of the code point <TT>c</TT>
1173 * starting at offset <TT>start</TT>, using bitwise comparison.
1175 * @param c The code point to search for.
1176 * @param start The offset at which searching will start.
1177 * @return The offset into this of <TT>c</TT>, or -1 if not found.
1180 inline int32_t lastIndexOf(UChar32 c
,
1181 int32_t start
) const;
1184 * Locate in this the last occurrence of the BMP code point <code>c</code>
1185 * in the range [<TT>start</TT>, <TT>start + length</TT>),
1186 * using bitwise comparison.
1187 * @param c The code unit to search for.
1188 * @param start the offset into this at which to start matching
1189 * @param length the number of characters in this to search
1190 * @return The offset into this of <TT>c</TT>, or -1 if not found.
1193 inline int32_t lastIndexOf(UChar c
,
1195 int32_t length
) const;
1198 * Locate in this the last occurrence of the code point <TT>c</TT>
1199 * in the range [<TT>start</TT>, <TT>start + length</TT>),
1200 * using bitwise comparison.
1202 * @param c The code point to search for.
1203 * @param start the offset into this at which to start matching
1204 * @param length the number of characters in this to search
1205 * @return The offset into this of <TT>c</TT>, or -1 if not found.
1208 inline int32_t lastIndexOf(UChar32 c
,
1210 int32_t length
) const;
1213 /* Character access */
1216 * Return the code unit at offset <tt>offset</tt>.
1217 * If the offset is not valid (0..length()-1) then U+ffff is returned.
1218 * @param offset a valid offset into the text
1219 * @return the code unit at offset <tt>offset</tt>
1220 * or 0xffff if the offset is not valid for this string
1223 inline UChar
charAt(int32_t offset
) const;
1226 * Return the code unit at offset <tt>offset</tt>.
1227 * If the offset is not valid (0..length()-1) then U+ffff is returned.
1228 * @param offset a valid offset into the text
1229 * @return the code unit at offset <tt>offset</tt>
1232 inline UChar
operator[] (int32_t offset
) const;
1235 * Return the code point that contains the code unit
1236 * at offset <tt>offset</tt>.
1237 * If the offset is not valid (0..length()-1) then U+ffff is returned.
1238 * @param offset a valid offset into the text
1239 * that indicates the text offset of any of the code units
1240 * that will be assembled into a code point (21-bit value) and returned
1241 * @return the code point of text at <tt>offset</tt>
1242 * or 0xffff if the offset is not valid for this string
1245 inline UChar32
char32At(int32_t offset
) const;
1248 * Adjust a random-access offset so that
1249 * it points to the beginning of a Unicode character.
1250 * The offset that is passed in points to
1251 * any code unit of a code point,
1252 * while the returned offset will point to the first code unit
1253 * of the same code point.
1254 * In UTF-16, if the input offset points to a second surrogate
1255 * of a surrogate pair, then the returned offset will point
1256 * to the first surrogate.
1257 * @param offset a valid offset into one code point of the text
1258 * @return offset of the first code unit of the same code point
1259 * @see U16_SET_CP_START
1262 inline int32_t getChar32Start(int32_t offset
) const;
1265 * Adjust a random-access offset so that
1266 * it points behind a Unicode character.
1267 * The offset that is passed in points behind
1268 * any code unit of a code point,
1269 * while the returned offset will point behind the last code unit
1270 * of the same code point.
1271 * In UTF-16, if the input offset points behind the first surrogate
1272 * (i.e., to the second surrogate)
1273 * of a surrogate pair, then the returned offset will point
1274 * behind the second surrogate (i.e., to the first surrogate).
1275 * @param offset a valid offset after any code unit of a code point of the text
1276 * @return offset of the first code unit after the same code point
1277 * @see U16_SET_CP_LIMIT
1280 inline int32_t getChar32Limit(int32_t offset
) const;
1283 * Move the code unit index along the string by delta code points.
1284 * Interpret the input index as a code unit-based offset into the string,
1285 * move the index forward or backward by delta code points, and
1286 * return the resulting index.
1287 * The input index should point to the first code unit of a code point,
1288 * if there is more than one.
1290 * Both input and output indexes are code unit-based as for all
1291 * string indexes/offsets in ICU (and other libraries, like MBCS char*).
1292 * If delta<0 then the index is moved backward (toward the start of the string).
1293 * If delta>0 then the index is moved forward (toward the end of the string).
1295 * This behaves like CharacterIterator::move32(delta, kCurrent).
1297 * Behavior for out-of-bounds indexes:
1298 * <code>moveIndex32</code> pins the input index to 0..length(), i.e.,
1299 * if the input index<0 then it is pinned to 0;
1300 * if it is index>length() then it is pinned to length().
1301 * Afterwards, the index is moved by <code>delta</code> code points
1302 * forward or backward,
1303 * but no further backward than to 0 and no further forward than to length().
1304 * The resulting index return value will be in between 0 and length(), inclusively.
1308 * // s has code points 'a' U+10000 'b' U+10ffff U+2029
1309 * UnicodeString s=UNICODE_STRING("a\\U00010000b\\U0010ffff\\u2029", 31).unescape();
1311 * // initial index: position of U+10000
1314 * // the following examples will all result in index==4, position of U+10ffff
1316 * // skip 2 code points from some position in the string
1317 * index=s.moveIndex32(index, 2); // skips U+10000 and 'b'
1319 * // go to the 3rd code point from the start of s (0-based)
1320 * index=s.moveIndex32(0, 3); // skips 'a', U+10000, and 'b'
1322 * // go to the next-to-last code point of s
1323 * index=s.moveIndex32(s.length(), -2); // backward-skips U+2029 and U+10ffff
1326 * @param index input code unit index
1327 * @param delta (signed) code point count to move the index forward or backward
1329 * @return the resulting code unit index
1332 int32_t moveIndex32(int32_t index
, int32_t delta
) const;
1334 /* Substring extraction */
1337 * Copy the characters in the range
1338 * [<tt>start</tt>, <tt>start + length</tt>) into the array <tt>dst</tt>,
1339 * beginning at <tt>dstStart</tt>.
1340 * If the string aliases to <code>dst</code> itself as an external buffer,
1341 * then extract() will not copy the contents.
1343 * @param start offset of first character which will be copied into the array
1344 * @param length the number of characters to extract
1345 * @param dst array in which to copy characters. The length of <tt>dst</tt>
1346 * must be at least (<tt>dstStart + length</tt>).
1347 * @param dstStart the offset in <TT>dst</TT> where the first character
1351 inline void extract(int32_t start
,
1354 int32_t dstStart
= 0) const;
1357 * Copy the contents of the string into dest.
1358 * This is a convenience function that
1359 * checks if there is enough space in dest,
1360 * extracts the entire string if possible,
1361 * and NUL-terminates dest if possible.
1363 * If the string fits into dest but cannot be NUL-terminated
1364 * (length()==destCapacity) then the error code is set to U_STRING_NOT_TERMINATED_WARNING.
1365 * If the string itself does not fit into dest
1366 * (length()>destCapacity) then the error code is set to U_BUFFER_OVERFLOW_ERROR.
1368 * If the string aliases to <code>dest</code> itself as an external buffer,
1369 * then extract() will not copy the contents.
1371 * @param dest Destination string buffer.
1372 * @param destCapacity Number of UChars available at dest.
1373 * @param errorCode ICU error code.
1378 extract(UChar
*dest
, int32_t destCapacity
,
1379 UErrorCode
&errorCode
) const;
1382 * Copy the characters in the range
1383 * [<tt>start</tt>, <tt>start + length</tt>) into the UnicodeString
1385 * @param start offset of first character which will be copied
1386 * @param length the number of characters to extract
1387 * @param target UnicodeString into which to copy characters.
1388 * @return A reference to <TT>target</TT>
1391 inline void extract(int32_t start
,
1393 UnicodeString
& target
) const;
1396 * Copy the characters in the range [<tt>start</tt>, <tt>limit</tt>)
1397 * into the array <tt>dst</tt>, beginning at <tt>dstStart</tt>.
1398 * @param start offset of first character which will be copied into the array
1399 * @param limit offset immediately following the last character to be copied
1400 * @param dst array in which to copy characters. The length of <tt>dst</tt>
1401 * must be at least (<tt>dstStart + (limit - start)</tt>).
1402 * @param dstStart the offset in <TT>dst</TT> where the first character
1406 inline void extractBetween(int32_t start
,
1409 int32_t dstStart
= 0) const;
1412 * Copy the characters in the range [<tt>start</tt>, <tt>limit</tt>)
1413 * into the UnicodeString <tt>target</tt>. Replaceable API.
1414 * @param start offset of first character which will be copied
1415 * @param limit offset immediately following the last character to be copied
1416 * @param target UnicodeString into which to copy characters.
1417 * @return A reference to <TT>target</TT>
1420 virtual void extractBetween(int32_t start
,
1422 UnicodeString
& target
) const;
1425 * Copy the characters in the range
1426 * [<tt>start</TT>, <tt>start + length</TT>) into an array of characters.
1427 * All characters must be invariant (see utypes.h).
1428 * Use US_INV as the last, signature-distinguishing parameter.
1430 * This function does not write any more than <code>targetLength</code>
1431 * characters but returns the length of the entire output string
1432 * so that one can allocate a larger buffer and call the function again
1434 * The output string is NUL-terminated if possible.
1436 * @param start offset of first character which will be copied
1437 * @param startLength the number of characters to extract
1438 * @param target the target buffer for extraction, can be NULL
1439 * if targetLength is 0
1440 * @param targetCapacity the length of the target buffer
1441 * @param inv Signature-distinguishing paramater, use US_INV.
1442 * @return the output string length, not including the terminating NUL
1445 int32_t extract(int32_t start
,
1446 int32_t startLength
,
1448 int32_t targetCapacity
,
1449 enum EInvariant inv
) const;
1451 #if !UCONFIG_NO_CONVERSION
1454 * Copy the characters in the range
1455 * [<tt>start</TT>, <tt>start + length</TT>) into an array of characters
1456 * in a specified codepage.
1457 * The output string is NUL-terminated.
1459 * Recommendation: For invariant-character strings use
1460 * extract(int32_t start, int32_t length, char *target, int32_t targetCapacity, enum EInvariant inv) const
1461 * because it avoids object code dependencies of UnicodeString on
1462 * the conversion code.
1464 * @param start offset of first character which will be copied
1465 * @param startLength the number of characters to extract
1466 * @param target the target buffer for extraction
1467 * @param codepage the desired codepage for the characters. 0 has
1468 * the special meaning of the default codepage
1469 * If <code>codepage</code> is an empty string (<code>""</code>),
1470 * then a simple conversion is performed on the codepage-invariant
1471 * subset ("invariant characters") of the platform encoding. See utypes.h.
1472 * If <TT>target</TT> is NULL, then the number of bytes required for
1473 * <TT>target</TT> is returned. It is assumed that the target is big enough
1474 * to fit all of the characters.
1475 * @return the output string length, not including the terminating NUL
1478 inline int32_t extract(int32_t start
,
1479 int32_t startLength
,
1481 const char *codepage
= 0) const;
1484 * Copy the characters in the range
1485 * [<tt>start</TT>, <tt>start + length</TT>) into an array of characters
1486 * in a specified codepage.
1487 * This function does not write any more than <code>targetLength</code>
1488 * characters but returns the length of the entire output string
1489 * so that one can allocate a larger buffer and call the function again
1491 * The output string is NUL-terminated if possible.
1493 * Recommendation: For invariant-character strings use
1494 * extract(int32_t start, int32_t length, char *target, int32_t targetCapacity, enum EInvariant inv) const
1495 * because it avoids object code dependencies of UnicodeString on
1496 * the conversion code.
1498 * @param start offset of first character which will be copied
1499 * @param startLength the number of characters to extract
1500 * @param target the target buffer for extraction
1501 * @param targetLength the length of the target buffer
1502 * @param codepage the desired codepage for the characters. 0 has
1503 * the special meaning of the default codepage
1504 * If <code>codepage</code> is an empty string (<code>""</code>),
1505 * then a simple conversion is performed on the codepage-invariant
1506 * subset ("invariant characters") of the platform encoding. See utypes.h.
1507 * If <TT>target</TT> is NULL, then the number of bytes required for
1508 * <TT>target</TT> is returned.
1509 * @return the output string length, not including the terminating NUL
1512 int32_t extract(int32_t start
,
1513 int32_t startLength
,
1515 uint32_t targetLength
,
1516 const char *codepage
= 0) const;
1519 * Convert the UnicodeString into a codepage string using an existing UConverter.
1520 * The output string is NUL-terminated if possible.
1522 * This function avoids the overhead of opening and closing a converter if
1523 * multiple strings are extracted.
1525 * @param dest destination string buffer, can be NULL if destCapacity==0
1526 * @param destCapacity the number of chars available at dest
1527 * @param cnv the converter object to be used (ucnv_resetFromUnicode() will be called),
1528 * or NULL for the default converter
1529 * @param errorCode normal ICU error code
1530 * @return the length of the output string, not counting the terminating NUL;
1531 * if the length is greater than destCapacity, then the string will not fit
1532 * and a buffer of the indicated length would need to be passed in
1535 int32_t extract(char *dest
, int32_t destCapacity
,
1537 UErrorCode
&errorCode
) const;
1541 /* Length operations */
1544 * Return the length of the UnicodeString object.
1545 * The length is the number of UChar code units are in the UnicodeString.
1546 * If you want the number of code points, please use countChar32().
1547 * @return the length of the UnicodeString object
1551 inline int32_t length(void) const;
1554 * Count Unicode code points in the length UChar code units of the string.
1555 * A code point may occupy either one or two UChar code units.
1556 * Counting code points involves reading all code units.
1558 * This functions is basically the inverse of moveIndex32().
1560 * @param start the index of the first code unit to check
1561 * @param length the number of UChar code units to check
1562 * @return the number of code points in the specified code units
1567 countChar32(int32_t start
=0, int32_t length
=INT32_MAX
) const;
1570 * Check if the length UChar code units of the string
1571 * contain more Unicode code points than a certain number.
1572 * This is more efficient than counting all code points in this part of the string
1573 * and comparing that number with a threshold.
1574 * This function may not need to scan the string at all if the length
1575 * falls within a certain range, and
1576 * never needs to count more than 'number+1' code points.
1577 * Logically equivalent to (countChar32(start, length)>number).
1578 * A Unicode code point may occupy either one or two UChar code units.
1580 * @param start the index of the first code unit to check (0 for the entire string)
1581 * @param length the number of UChar code units to check
1582 * (use INT32_MAX for the entire string; remember that start/length
1583 * values are pinned)
1584 * @param number The number of code points in the (sub)string is compared against
1585 * the 'number' parameter.
1586 * @return Boolean value for whether the string contains more Unicode code points
1587 * than 'number'. Same as (u_countChar32(s, length)>number).
1589 * @see u_strHasMoreChar32Than
1593 hasMoreChar32Than(int32_t start
, int32_t length
, int32_t number
) const;
1596 * Determine if this string is empty.
1597 * @return TRUE if this string contains 0 characters, FALSE otherwise.
1600 inline UBool
isEmpty(void) const;
1603 * Return the capacity of the internal buffer of the UnicodeString object.
1604 * This is useful together with the getBuffer functions.
1605 * See there for details.
1607 * @return the number of UChars available in the internal buffer
1611 inline int32_t getCapacity(void) const;
1613 /* Other operations */
1616 * Generate a hash code for this object.
1617 * @return The hash code of this UnicodeString.
1620 inline int32_t hashCode(void) const;
1623 * Determine if this object contains a valid string.
1624 * A bogus string has no value. It is different from an empty string.
1625 * It can be used to indicate that no string value is available.
1626 * getBuffer() and getTerminatedBuffer() return NULL, and
1627 * length() returns 0.
1629 * @return TRUE if the string is valid, FALSE otherwise
1633 inline UBool
isBogus(void) const;
1636 //========================================
1638 //========================================
1640 /* Assignment operations */
1643 * Assignment operator. Replace the characters in this UnicodeString
1644 * with the characters from <TT>srcText</TT>.
1645 * @param srcText The text containing the characters to replace
1646 * @return a reference to this
1649 UnicodeString
&operator=(const UnicodeString
&srcText
);
1652 * Almost the same as the assignment operator.
1653 * Replace the characters in this UnicodeString
1654 * with the characters from <code>srcText</code>.
1656 * This function works the same for all strings except for ones that
1657 * are readonly aliases.
1658 * Starting with ICU 2.4, the assignment operator and the copy constructor
1659 * allocate a new buffer and copy the buffer contents even for readonly aliases.
1660 * This function implements the old, more efficient but less safe behavior
1661 * of making this string also a readonly alias to the same buffer.
1662 * The fastCopyFrom function must be used only if it is known that the lifetime of
1663 * this UnicodeString is at least as long as the lifetime of the aliased buffer
1664 * including its contents, for example for strings from resource bundles
1665 * or aliases to string contents.
1667 * @param src The text containing the characters to replace.
1668 * @return a reference to this
1671 UnicodeString
&fastCopyFrom(const UnicodeString
&src
);
1674 * Assignment operator. Replace the characters in this UnicodeString
1675 * with the code unit <TT>ch</TT>.
1676 * @param ch the code unit to replace
1677 * @return a reference to this
1680 inline UnicodeString
& operator= (UChar ch
);
1683 * Assignment operator. Replace the characters in this UnicodeString
1684 * with the code point <TT>ch</TT>.
1685 * @param ch the code point to replace
1686 * @return a reference to this
1689 inline UnicodeString
& operator= (UChar32 ch
);
1692 * Set the text in the UnicodeString object to the characters
1693 * in <TT>srcText</TT> in the range
1694 * [<TT>srcStart</TT>, <TT>srcText.length()</TT>).
1695 * <TT>srcText</TT> is not modified.
1696 * @param srcText the source for the new characters
1697 * @param srcStart the offset into <TT>srcText</TT> where new characters
1699 * @return a reference to this
1702 inline UnicodeString
& setTo(const UnicodeString
& srcText
,
1706 * Set the text in the UnicodeString object to the characters
1707 * in <TT>srcText</TT> in the range
1708 * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
1709 * <TT>srcText</TT> is not modified.
1710 * @param srcText the source for the new characters
1711 * @param srcStart the offset into <TT>srcText</TT> where new characters
1713 * @param srcLength the number of characters in <TT>srcText</TT> in the
1715 * @return a reference to this
1718 inline UnicodeString
& setTo(const UnicodeString
& srcText
,
1723 * Set the text in the UnicodeString object to the characters in
1725 * <TT>srcText</TT> is not modified.
1726 * @param srcText the source for the new characters
1727 * @return a reference to this
1730 inline UnicodeString
& setTo(const UnicodeString
& srcText
);
1733 * Set the characters in the UnicodeString object to the characters
1734 * in <TT>srcChars</TT>. <TT>srcChars</TT> is not modified.
1735 * @param srcChars the source for the new characters
1736 * @param srcLength the number of Unicode characters in srcChars.
1737 * @return a reference to this
1740 inline UnicodeString
& setTo(const UChar
*srcChars
,
1744 * Set the characters in the UnicodeString object to the code unit
1746 * @param srcChar the code unit which becomes the UnicodeString's character
1748 * @return a reference to this
1751 UnicodeString
& setTo(UChar srcChar
);
1754 * Set the characters in the UnicodeString object to the code point
1756 * @param srcChar the code point which becomes the UnicodeString's character
1758 * @return a reference to this
1761 UnicodeString
& setTo(UChar32 srcChar
);
1764 * Aliasing setTo() function, analogous to the readonly-aliasing UChar* constructor.
1765 * The text will be used for the UnicodeString object, but
1766 * it will not be released when the UnicodeString is destroyed.
1767 * This has copy-on-write semantics:
1768 * When the string is modified, then the buffer is first copied into
1769 * newly allocated memory.
1770 * The aliased buffer is never modified.
1771 * In an assignment to another UnicodeString, the text will be aliased again,
1772 * so that both strings then alias the same readonly-text.
1774 * @param isTerminated specifies if <code>text</code> is <code>NUL</code>-terminated.
1775 * This must be true if <code>textLength==-1</code>.
1776 * @param text The characters to alias for the UnicodeString.
1777 * @param textLength The number of Unicode characters in <code>text</code> to alias.
1778 * If -1, then this constructor will determine the length
1779 * by calling <code>u_strlen()</code>.
1780 * @return a reference to this
1783 UnicodeString
&setTo(UBool isTerminated
,
1785 int32_t textLength
);
1788 * Aliasing setTo() function, analogous to the writable-aliasing UChar* constructor.
1789 * The text will be used for the UnicodeString object, but
1790 * it will not be released when the UnicodeString is destroyed.
1791 * This has write-through semantics:
1792 * For as long as the capacity of the buffer is sufficient, write operations
1793 * will directly affect the buffer. When more capacity is necessary, then
1794 * a new buffer will be allocated and the contents copied as with regularly
1795 * constructed strings.
1796 * In an assignment to another UnicodeString, the buffer will be copied.
1797 * The extract(UChar *dst) function detects whether the dst pointer is the same
1798 * as the string buffer itself and will in this case not copy the contents.
1800 * @param buffer The characters to alias for the UnicodeString.
1801 * @param buffLength The number of Unicode characters in <code>buffer</code> to alias.
1802 * @param buffCapacity The size of <code>buffer</code> in UChars.
1803 * @return a reference to this
1806 UnicodeString
&setTo(UChar
*buffer
,
1808 int32_t buffCapacity
);
1811 * Make this UnicodeString object invalid.
1812 * The string will test TRUE with isBogus().
1814 * A bogus string has no value. It is different from an empty string.
1815 * It can be used to indicate that no string value is available.
1816 * getBuffer() and getTerminatedBuffer() return NULL, and
1817 * length() returns 0.
1819 * This utility function is used throughout the UnicodeString
1820 * implementation to indicate that a UnicodeString operation failed,
1821 * and may be used in other functions,
1822 * especially but not exclusively when such functions do not
1823 * take a UErrorCode for simplicity.
1825 * The following methods, and no others, will clear a string object's bogus flag:
1827 * - remove(0, INT32_MAX)
1829 * - operator=() (assignment operator)
1832 * The simplest ways to turn a bogus string into an empty one
1833 * is to use the remove() function.
1834 * Examples for other functions that are equivalent to "set to empty string":
1837 * s.remove(); // set to an empty string (remove all), or
1838 * s.remove(0, INT32_MAX); // set to an empty string (remove all), or
1839 * s.truncate(0); // set to an empty string (complete truncation), or
1840 * s=UnicodeString(); // assign an empty string, or
1841 * s.setTo((UChar32)-1); // set to a pseudo code point that is out of range, or
1842 * static const UChar nul=0;
1843 * s.setTo(&nul, 0); // set to an empty C Unicode string
1853 * Set the character at the specified offset to the specified character.
1854 * @param offset A valid offset into the text of the character to set
1855 * @param ch The new character
1856 * @return A reference to this
1859 UnicodeString
& setCharAt(int32_t offset
,
1863 /* Append operations */
1866 * Append operator. Append the code unit <TT>ch</TT> to the UnicodeString
1868 * @param ch the code unit to be appended
1869 * @return a reference to this
1872 inline UnicodeString
& operator+= (UChar ch
);
1875 * Append operator. Append the code point <TT>ch</TT> to the UnicodeString
1877 * @param ch the code point to be appended
1878 * @return a reference to this
1881 inline UnicodeString
& operator+= (UChar32 ch
);
1884 * Append operator. Append the characters in <TT>srcText</TT> to the
1885 * UnicodeString object at offset <TT>start</TT>. <TT>srcText</TT> is
1887 * @param srcText the source for the new characters
1888 * @return a reference to this
1891 inline UnicodeString
& operator+= (const UnicodeString
& srcText
);
1894 * Append the characters
1895 * in <TT>srcText</TT> in the range
1896 * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>) to the
1897 * UnicodeString object at offset <TT>start</TT>. <TT>srcText</TT>
1899 * @param srcText the source for the new characters
1900 * @param srcStart the offset into <TT>srcText</TT> where new characters
1902 * @param srcLength the number of characters in <TT>srcText</TT> in
1904 * @return a reference to this
1907 inline UnicodeString
& append(const UnicodeString
& srcText
,
1912 * Append the characters in <TT>srcText</TT> to the UnicodeString object at
1913 * offset <TT>start</TT>. <TT>srcText</TT> is not modified.
1914 * @param srcText the source for the new characters
1915 * @return a reference to this
1918 inline UnicodeString
& append(const UnicodeString
& srcText
);
1921 * Append the characters in <TT>srcChars</TT> in the range
1922 * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>) to the UnicodeString
1924 * <TT>start</TT>. <TT>srcChars</TT> is not modified.
1925 * @param srcChars the source for the new characters
1926 * @param srcStart the offset into <TT>srcChars</TT> where new characters
1928 * @param srcLength the number of characters in <TT>srcChars</TT> in
1930 * @return a reference to this
1933 inline UnicodeString
& append(const UChar
*srcChars
,
1938 * Append the characters in <TT>srcChars</TT> to the UnicodeString object
1939 * at offset <TT>start</TT>. <TT>srcChars</TT> is not modified.
1940 * @param srcChars the source for the new characters
1941 * @param srcLength the number of Unicode characters in <TT>srcChars</TT>
1942 * @return a reference to this
1945 inline UnicodeString
& append(const UChar
*srcChars
,
1949 * Append the code unit <TT>srcChar</TT> to the UnicodeString object.
1950 * @param srcChar the code unit to append
1951 * @return a reference to this
1954 inline UnicodeString
& append(UChar srcChar
);
1957 * Append the code point <TT>srcChar</TT> to the UnicodeString object.
1958 * @param srcChar the code point to append
1959 * @return a reference to this
1962 inline UnicodeString
& append(UChar32 srcChar
);
1965 /* Insert operations */
1968 * Insert the characters in <TT>srcText</TT> in the range
1969 * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>) into the UnicodeString
1970 * object at offset <TT>start</TT>. <TT>srcText</TT> is not modified.
1971 * @param start the offset where the insertion begins
1972 * @param srcText the source for the new characters
1973 * @param srcStart the offset into <TT>srcText</TT> where new characters
1975 * @param srcLength the number of characters in <TT>srcText</TT> in
1977 * @return a reference to this
1980 inline UnicodeString
& insert(int32_t start
,
1981 const UnicodeString
& srcText
,
1986 * Insert the characters in <TT>srcText</TT> into the UnicodeString object
1987 * at offset <TT>start</TT>. <TT>srcText</TT> is not modified.
1988 * @param start the offset where the insertion begins
1989 * @param srcText the source for the new characters
1990 * @return a reference to this
1993 inline UnicodeString
& insert(int32_t start
,
1994 const UnicodeString
& srcText
);
1997 * Insert the characters in <TT>srcChars</TT> in the range
1998 * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>) into the UnicodeString
1999 * object at offset <TT>start</TT>. <TT>srcChars</TT> is not modified.
2000 * @param start the offset at which the insertion begins
2001 * @param srcChars the source for the new characters
2002 * @param srcStart the offset into <TT>srcChars</TT> where new characters
2004 * @param srcLength the number of characters in <TT>srcChars</TT>
2005 * in the insert string
2006 * @return a reference to this
2009 inline UnicodeString
& insert(int32_t start
,
2010 const UChar
*srcChars
,
2015 * Insert the characters in <TT>srcChars</TT> into the UnicodeString object
2016 * at offset <TT>start</TT>. <TT>srcChars</TT> is not modified.
2017 * @param start the offset where the insertion begins
2018 * @param srcChars the source for the new characters
2019 * @param srcLength the number of Unicode characters in srcChars.
2020 * @return a reference to this
2023 inline UnicodeString
& insert(int32_t start
,
2024 const UChar
*srcChars
,
2028 * Insert the code unit <TT>srcChar</TT> into the UnicodeString object at
2029 * offset <TT>start</TT>.
2030 * @param start the offset at which the insertion occurs
2031 * @param srcChar the code unit to insert
2032 * @return a reference to this
2035 inline UnicodeString
& insert(int32_t start
,
2039 * Insert the code point <TT>srcChar</TT> into the UnicodeString object at
2040 * offset <TT>start</TT>.
2041 * @param start the offset at which the insertion occurs
2042 * @param srcChar the code point to insert
2043 * @return a reference to this
2046 inline UnicodeString
& insert(int32_t start
,
2050 /* Replace operations */
2053 * Replace the characters in the range
2054 * [<TT>start</TT>, <TT>start + length</TT>) with the characters in
2055 * <TT>srcText</TT> in the range
2056 * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
2057 * <TT>srcText</TT> is not modified.
2058 * @param start the offset at which the replace operation begins
2059 * @param length the number of characters to replace. The character at
2060 * <TT>start + length</TT> is not modified.
2061 * @param srcText the source for the new characters
2062 * @param srcStart the offset into <TT>srcText</TT> where new characters
2064 * @param srcLength the number of characters in <TT>srcText</TT> in
2065 * the replace string
2066 * @return a reference to this
2069 UnicodeString
& replace(int32_t start
,
2071 const UnicodeString
& srcText
,
2076 * Replace the characters in the range
2077 * [<TT>start</TT>, <TT>start + length</TT>)
2078 * with the characters in <TT>srcText</TT>. <TT>srcText</TT> is
2080 * @param start the offset at which the replace operation begins
2081 * @param length the number of characters to replace. The character at
2082 * <TT>start + length</TT> is not modified.
2083 * @param srcText the source for the new characters
2084 * @return a reference to this
2087 UnicodeString
& replace(int32_t start
,
2089 const UnicodeString
& srcText
);
2092 * Replace the characters in the range
2093 * [<TT>start</TT>, <TT>start + length</TT>) with the characters in
2094 * <TT>srcChars</TT> in the range
2095 * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>). <TT>srcChars</TT>
2097 * @param start the offset at which the replace operation begins
2098 * @param length the number of characters to replace. The character at
2099 * <TT>start + length</TT> is not modified.
2100 * @param srcChars the source for the new characters
2101 * @param srcStart the offset into <TT>srcChars</TT> where new characters
2103 * @param srcLength the number of characters in <TT>srcChars</TT>
2104 * in the replace string
2105 * @return a reference to this
2108 UnicodeString
& replace(int32_t start
,
2110 const UChar
*srcChars
,
2115 * Replace the characters in the range
2116 * [<TT>start</TT>, <TT>start + length</TT>) with the characters in
2117 * <TT>srcChars</TT>. <TT>srcChars</TT> is not modified.
2118 * @param start the offset at which the replace operation begins
2119 * @param length number of characters to replace. The character at
2120 * <TT>start + length</TT> is not modified.
2121 * @param srcChars the source for the new characters
2122 * @param srcLength the number of Unicode characters in srcChars
2123 * @return a reference to this
2126 inline UnicodeString
& replace(int32_t start
,
2128 const UChar
*srcChars
,
2132 * Replace the characters in the range
2133 * [<TT>start</TT>, <TT>start + length</TT>) with the code unit
2135 * @param start the offset at which the replace operation begins
2136 * @param length the number of characters to replace. The character at
2137 * <TT>start + length</TT> is not modified.
2138 * @param srcChar the new code unit
2139 * @return a reference to this
2142 inline UnicodeString
& replace(int32_t start
,
2147 * Replace the characters in the range
2148 * [<TT>start</TT>, <TT>start + length</TT>) with the code point
2150 * @param start the offset at which the replace operation begins
2151 * @param length the number of characters to replace. The character at
2152 * <TT>start + length</TT> is not modified.
2153 * @param srcChar the new code point
2154 * @return a reference to this
2157 inline UnicodeString
& replace(int32_t start
,
2162 * Replace the characters in the range [<TT>start</TT>, <TT>limit</TT>)
2163 * with the characters in <TT>srcText</TT>. <TT>srcText</TT> is not modified.
2164 * @param start the offset at which the replace operation begins
2165 * @param limit the offset immediately following the replace range
2166 * @param srcText the source for the new characters
2167 * @return a reference to this
2170 inline UnicodeString
& replaceBetween(int32_t start
,
2172 const UnicodeString
& srcText
);
2175 * Replace the characters in the range [<TT>start</TT>, <TT>limit</TT>)
2176 * with the characters in <TT>srcText</TT> in the range
2177 * [<TT>srcStart</TT>, <TT>srcLimit</TT>). <TT>srcText</TT> is not modified.
2178 * @param start the offset at which the replace operation begins
2179 * @param limit the offset immediately following the replace range
2180 * @param srcText the source for the new characters
2181 * @param srcStart the offset into <TT>srcChars</TT> where new characters
2183 * @param srcLimit the offset immediately following the range to copy
2184 * in <TT>srcText</TT>
2185 * @return a reference to this
2188 inline UnicodeString
& replaceBetween(int32_t start
,
2190 const UnicodeString
& srcText
,
2195 * Replace a substring of this object with the given text.
2196 * @param start the beginning index, inclusive; <code>0 <= start
2198 * @param limit the ending index, exclusive; <code>start <= limit
2199 * <= length()</code>.
2200 * @param text the text to replace characters <code>start</code>
2201 * to <code>limit - 1</code>
2204 virtual void handleReplaceBetween(int32_t start
,
2206 const UnicodeString
& text
);
2210 * @return TRUE if it has MetaData
2213 virtual UBool
hasMetaData() const;
2216 * Copy a substring of this object, retaining attribute (out-of-band)
2217 * information. This method is used to duplicate or reorder substrings.
2218 * The destination index must not overlap the source range.
2220 * @param start the beginning index, inclusive; <code>0 <= start <=
2222 * @param limit the ending index, exclusive; <code>start <= limit <=
2224 * @param dest the destination index. The characters from
2225 * <code>start..limit-1</code> will be copied to <code>dest</code>.
2226 * Implementations of this method may assume that <code>dest <= start ||
2227 * dest >= limit</code>.
2230 virtual void copy(int32_t start
, int32_t limit
, int32_t dest
);
2232 /* Search and replace operations */
2235 * Replace all occurrences of characters in oldText with the characters
2237 * @param oldText the text containing the search text
2238 * @param newText the text containing the replacement text
2239 * @return a reference to this
2242 inline UnicodeString
& findAndReplace(const UnicodeString
& oldText
,
2243 const UnicodeString
& newText
);
2246 * Replace all occurrences of characters in oldText with characters
2248 * in the range [<TT>start</TT>, <TT>start + length</TT>).
2249 * @param start the start of the range in which replace will performed
2250 * @param length the length of the range in which replace will be performed
2251 * @param oldText the text containing the search text
2252 * @param newText the text containing the replacement text
2253 * @return a reference to this
2256 inline UnicodeString
& findAndReplace(int32_t start
,
2258 const UnicodeString
& oldText
,
2259 const UnicodeString
& newText
);
2262 * Replace all occurrences of characters in oldText in the range
2263 * [<TT>oldStart</TT>, <TT>oldStart + oldLength</TT>) with the characters
2264 * in newText in the range
2265 * [<TT>newStart</TT>, <TT>newStart + newLength</TT>)
2266 * in the range [<TT>start</TT>, <TT>start + length</TT>).
2267 * @param start the start of the range in which replace will performed
2268 * @param length the length of the range in which replace will be performed
2269 * @param oldText the text containing the search text
2270 * @param oldStart the start of the search range in <TT>oldText</TT>
2271 * @param oldLength the length of the search range in <TT>oldText</TT>
2272 * @param newText the text containing the replacement text
2273 * @param newStart the start of the replacement range in <TT>newText</TT>
2274 * @param newLength the length of the replacement range in <TT>newText</TT>
2275 * @return a reference to this
2278 UnicodeString
& findAndReplace(int32_t start
,
2280 const UnicodeString
& oldText
,
2283 const UnicodeString
& newText
,
2288 /* Remove operations */
2291 * Remove all characters from the UnicodeString object.
2292 * @return a reference to this
2295 inline UnicodeString
& remove(void);
2298 * Remove the characters in the range
2299 * [<TT>start</TT>, <TT>start + length</TT>) from the UnicodeString object.
2300 * @param start the offset of the first character to remove
2301 * @param length the number of characters to remove
2302 * @return a reference to this
2305 inline UnicodeString
& remove(int32_t start
,
2306 int32_t length
= (int32_t)INT32_MAX
);
2309 * Remove the characters in the range
2310 * [<TT>start</TT>, <TT>limit</TT>) from the UnicodeString object.
2311 * @param start the offset of the first character to remove
2312 * @param limit the offset immediately following the range to remove
2313 * @return a reference to this
2316 inline UnicodeString
& removeBetween(int32_t start
,
2317 int32_t limit
= (int32_t)INT32_MAX
);
2320 /* Length operations */
2323 * Pad the start of this UnicodeString with the character <TT>padChar</TT>.
2324 * If the length of this UnicodeString is less than targetLength,
2325 * length() - targetLength copies of padChar will be added to the
2326 * beginning of this UnicodeString.
2327 * @param targetLength the desired length of the string
2328 * @param padChar the character to use for padding. Defaults to
2330 * @return TRUE if the text was padded, FALSE otherwise.
2333 UBool
padLeading(int32_t targetLength
,
2334 UChar padChar
= 0x0020);
2337 * Pad the end of this UnicodeString with the character <TT>padChar</TT>.
2338 * If the length of this UnicodeString is less than targetLength,
2339 * length() - targetLength copies of padChar will be added to the
2340 * end of this UnicodeString.
2341 * @param targetLength the desired length of the string
2342 * @param padChar the character to use for padding. Defaults to
2344 * @return TRUE if the text was padded, FALSE otherwise.
2347 UBool
padTrailing(int32_t targetLength
,
2348 UChar padChar
= 0x0020);
2351 * Truncate this UnicodeString to the <TT>targetLength</TT>.
2352 * @param targetLength the desired length of this UnicodeString.
2353 * @return TRUE if the text was truncated, FALSE otherwise
2356 inline UBool
truncate(int32_t targetLength
);
2359 * Trims leading and trailing whitespace from this UnicodeString.
2360 * @return a reference to this
2363 UnicodeString
& trim(void);
2366 /* Miscellaneous operations */
2369 * Reverse this UnicodeString in place.
2370 * @return a reference to this
2373 inline UnicodeString
& reverse(void);
2376 * Reverse the range [<TT>start</TT>, <TT>start + length</TT>) in
2377 * this UnicodeString.
2378 * @param start the start of the range to reverse
2379 * @param length the number of characters to to reverse
2380 * @return a reference to this
2383 inline UnicodeString
& reverse(int32_t start
,
2387 * Convert the characters in this to UPPER CASE following the conventions of
2388 * the default locale.
2389 * @return A reference to this.
2392 UnicodeString
& toUpper(void);
2395 * Convert the characters in this to UPPER CASE following the conventions of
2396 * a specific locale.
2397 * @param locale The locale containing the conventions to use.
2398 * @return A reference to this.
2401 UnicodeString
& toUpper(const Locale
& locale
);
2404 * Convert the characters in this to lower case following the conventions of
2405 * the default locale.
2406 * @return A reference to this.
2409 UnicodeString
& toLower(void);
2412 * Convert the characters in this to lower case following the conventions of
2413 * a specific locale.
2414 * @param locale The locale containing the conventions to use.
2415 * @return A reference to this.
2418 UnicodeString
& toLower(const Locale
& locale
);
2420 #if !UCONFIG_NO_BREAK_ITERATION
2423 * Titlecase this string, convenience function using the default locale.
2425 * Casing is locale-dependent and context-sensitive.
2426 * Titlecasing uses a break iterator to find the first characters of words
2427 * that are to be titlecased. It titlecases those characters and lowercases
2430 * The titlecase break iterator can be provided to customize for arbitrary
2431 * styles, using rules and dictionaries beyond the standard iterators.
2432 * It may be more efficient to always provide an iterator to avoid
2433 * opening and closing one for each string.
2434 * The standard titlecase iterator for the root locale implements the
2435 * algorithm of Unicode TR 21.
2437 * This function uses only the first() and next() methods of the
2438 * provided break iterator.
2440 * @param titleIter A break iterator to find the first characters of words
2441 * that are to be titlecased.
2442 * If none is provided (0), then a standard titlecase
2443 * break iterator is opened.
2444 * Otherwise the provided iterator is set to the string's text.
2445 * @return A reference to this.
2448 UnicodeString
&toTitle(BreakIterator
*titleIter
);
2451 * Titlecase this string.
2453 * Casing is locale-dependent and context-sensitive.
2454 * Titlecasing uses a break iterator to find the first characters of words
2455 * that are to be titlecased. It titlecases those characters and lowercases
2458 * The titlecase break iterator can be provided to customize for arbitrary
2459 * styles, using rules and dictionaries beyond the standard iterators.
2460 * It may be more efficient to always provide an iterator to avoid
2461 * opening and closing one for each string.
2462 * The standard titlecase iterator for the root locale implements the
2463 * algorithm of Unicode TR 21.
2465 * This function uses only the first() and next() methods of the
2466 * provided break iterator.
2468 * @param titleIter A break iterator to find the first characters of words
2469 * that are to be titlecased.
2470 * If none is provided (0), then a standard titlecase
2471 * break iterator is opened.
2472 * Otherwise the provided iterator is set to the string's text.
2473 * @param locale The locale to consider.
2474 * @return A reference to this.
2477 UnicodeString
&toTitle(BreakIterator
*titleIter
, const Locale
&locale
);
2482 * Case-fold the characters in this string.
2483 * Case-folding is locale-independent and not context-sensitive,
2484 * but there is an option for whether to include or exclude mappings for dotted I
2485 * and dotless i that are marked with 'I' in CaseFolding.txt.
2486 * The result may be longer or shorter than the original.
2488 * @param options Either U_FOLD_CASE_DEFAULT or U_FOLD_CASE_EXCLUDE_SPECIAL_I
2489 * @return A reference to this.
2492 UnicodeString
&foldCase(uint32_t options
=0 /*U_FOLD_CASE_DEFAULT*/);
2494 //========================================
2495 // Access to the internal buffer
2496 //========================================
2499 * Get a read/write pointer to the internal buffer.
2500 * The buffer is guaranteed to be large enough for at least minCapacity UChars,
2501 * writable, and is still owned by the UnicodeString object.
2502 * Calls to getBuffer(minCapacity) must not be nested, and
2503 * must be matched with calls to releaseBuffer(newLength).
2504 * If the string buffer was read-only or shared,
2505 * then it will be reallocated and copied.
2507 * An attempted nested call will return 0, and will not further modify the
2508 * state of the UnicodeString object.
2509 * It also returns 0 if the string is bogus.
2511 * The actual capacity of the string buffer may be larger than minCapacity.
2512 * getCapacity() returns the actual capacity.
2513 * For many operations, the full capacity should be used to avoid reallocations.
2515 * While the buffer is "open" between getBuffer(minCapacity)
2516 * and releaseBuffer(newLength), the following applies:
2517 * - The string length is set to 0.
2518 * - Any read API call on the UnicodeString object will behave like on a 0-length string.
2519 * - Any write API call on the UnicodeString object is disallowed and will have no effect.
2520 * - You can read from and write to the returned buffer.
2521 * - The previous string contents will still be in the buffer;
2522 * if you want to use it, then you need to call length() before getBuffer(minCapacity).
2523 * If the length() was greater than minCapacity, then any contents after minCapacity
2525 * The buffer contents is not NUL-terminated by getBuffer().
2526 * If length()<getCapacity() then you can terminate it by writing a NUL
2527 * at index length().
2528 * - You must call releaseBuffer(newLength) before and in order to
2529 * return to normal UnicodeString operation.
2531 * @param minCapacity the minimum number of UChars that are to be available
2532 * in the buffer, starting at the returned pointer;
2533 * default to the current string capacity if minCapacity==-1
2534 * @return a writable pointer to the internal string buffer,
2535 * or 0 if an error occurs (nested calls, out of memory)
2537 * @see releaseBuffer
2538 * @see getTerminatedBuffer()
2541 UChar
*getBuffer(int32_t minCapacity
);
2544 * Release a read/write buffer on a UnicodeString object with an
2545 * "open" getBuffer(minCapacity).
2546 * This function must be called in a matched pair with getBuffer(minCapacity).
2547 * releaseBuffer(newLength) must be called if and only if a getBuffer(minCapacity) is "open".
2549 * It will set the string length to newLength, at most to the current capacity.
2550 * If newLength==-1 then it will set the length according to the
2551 * first NUL in the buffer, or to the capacity if there is no NUL.
2553 * After calling releaseBuffer(newLength) the UnicodeString is back to normal operation.
2555 * @param newLength the new length of the UnicodeString object;
2556 * defaults to the current capacity if newLength is greater than that;
2557 * if newLength==-1, it defaults to u_strlen(buffer) but not more than
2558 * the current capacity of the string
2560 * @see getBuffer(int32_t minCapacity)
2563 void releaseBuffer(int32_t newLength
=-1);
2566 * Get a read-only pointer to the internal buffer.
2567 * This can be called at any time on a valid UnicodeString.
2569 * It returns 0 if the string is bogus, or
2570 * during an "open" getBuffer(minCapacity).
2572 * It can be called as many times as desired.
2573 * The pointer that it returns will remain valid until the UnicodeString object is modified,
2574 * at which time the pointer is semantically invalidated and must not be used any more.
2576 * The capacity of the buffer can be determined with getCapacity().
2577 * The part after length() may or may not be initialized and valid,
2578 * depending on the history of the UnicodeString object.
2580 * The buffer contents is (probably) not NUL-terminated.
2581 * You can check if it is with
2582 * <code>(s.length()<s.getCapacity() && buffer[s.length()]==0)</code>.
2583 * (See getTerminatedBuffer().)
2585 * The buffer may reside in read-only memory. Its contents must not
2588 * @return a read-only pointer to the internal string buffer,
2589 * or 0 if the string is empty or bogus
2591 * @see getBuffer(int32_t minCapacity)
2592 * @see getTerminatedBuffer()
2595 inline const UChar
*getBuffer() const;
2598 * Get a read-only pointer to the internal buffer,
2599 * making sure that it is NUL-terminated.
2600 * This can be called at any time on a valid UnicodeString.
2602 * It returns 0 if the string is bogus, or
2603 * during an "open" getBuffer(minCapacity), or if the buffer cannot
2604 * be NUL-terminated (because memory allocation failed).
2606 * It can be called as many times as desired.
2607 * The pointer that it returns will remain valid until the UnicodeString object is modified,
2608 * at which time the pointer is semantically invalidated and must not be used any more.
2610 * The capacity of the buffer can be determined with getCapacity().
2611 * The part after length()+1 may or may not be initialized and valid,
2612 * depending on the history of the UnicodeString object.
2614 * The buffer contents is guaranteed to be NUL-terminated.
2615 * getTerminatedBuffer() may reallocate the buffer if a terminating NUL
2617 * For this reason, this function is not const, unlike getBuffer().
2618 * Note that a UnicodeString may also contain NUL characters as part of its contents.
2620 * The buffer may reside in read-only memory. Its contents must not
2623 * @return a read-only pointer to the internal string buffer,
2624 * or 0 if the string is empty or bogus
2626 * @see getBuffer(int32_t minCapacity)
2630 inline const UChar
*getTerminatedBuffer();
2632 //========================================
2634 //========================================
2636 /** Construct an empty UnicodeString.
2642 * Construct a UnicodeString with capacity to hold <TT>capacity</TT> UChars
2643 * @param capacity the number of UChars this UnicodeString should hold
2644 * before a resize is necessary; if count is greater than 0 and count
2645 * code points c take up more space than capacity, then capacity is adjusted
2647 * @param c is used to initially fill the string
2648 * @param count specifies how many code points c are to be written in the
2652 UnicodeString(int32_t capacity
, UChar32 c
, int32_t count
);
2655 * Single UChar (code unit) constructor.
2656 * @param ch the character to place in the UnicodeString
2659 UnicodeString(UChar ch
);
2662 * Single UChar32 (code point) constructor.
2663 * @param ch the character to place in the UnicodeString
2666 UnicodeString(UChar32 ch
);
2669 * UChar* constructor.
2670 * @param text The characters to place in the UnicodeString. <TT>text</TT>
2671 * must be NULL (U+0000) terminated.
2674 UnicodeString(const UChar
*text
);
2677 * UChar* constructor.
2678 * @param text The characters to place in the UnicodeString.
2679 * @param textLength The number of Unicode characters in <TT>text</TT>
2683 UnicodeString(const UChar
*text
,
2684 int32_t textLength
);
2687 * Readonly-aliasing UChar* constructor.
2688 * The text will be used for the UnicodeString object, but
2689 * it will not be released when the UnicodeString is destroyed.
2690 * This has copy-on-write semantics:
2691 * When the string is modified, then the buffer is first copied into
2692 * newly allocated memory.
2693 * The aliased buffer is never modified.
2694 * In an assignment to another UnicodeString, the text will be aliased again,
2695 * so that both strings then alias the same readonly-text.
2697 * @param isTerminated specifies if <code>text</code> is <code>NUL</code>-terminated.
2698 * This must be true if <code>textLength==-1</code>.
2699 * @param text The characters to alias for the UnicodeString.
2700 * @param textLength The number of Unicode characters in <code>text</code> to alias.
2701 * If -1, then this constructor will determine the length
2702 * by calling <code>u_strlen()</code>.
2705 UnicodeString(UBool isTerminated
,
2707 int32_t textLength
);
2710 * Writable-aliasing UChar* constructor.
2711 * The text will be used for the UnicodeString object, but
2712 * it will not be released when the UnicodeString is destroyed.
2713 * This has write-through semantics:
2714 * For as long as the capacity of the buffer is sufficient, write operations
2715 * will directly affect the buffer. When more capacity is necessary, then
2716 * a new buffer will be allocated and the contents copied as with regularly
2717 * constructed strings.
2718 * In an assignment to another UnicodeString, the buffer will be copied.
2719 * The extract(UChar *dst) function detects whether the dst pointer is the same
2720 * as the string buffer itself and will in this case not copy the contents.
2722 * @param buffer The characters to alias for the UnicodeString.
2723 * @param buffLength The number of Unicode characters in <code>buffer</code> to alias.
2724 * @param buffCapacity The size of <code>buffer</code> in UChars.
2727 UnicodeString(UChar
*buffer
, int32_t buffLength
, int32_t buffCapacity
);
2729 #if !UCONFIG_NO_CONVERSION
2732 * char* constructor.
2733 * @param codepageData an array of bytes, null-terminated
2734 * @param codepage the encoding of <TT>codepageData</TT>. The special
2735 * value 0 for <TT>codepage</TT> indicates that the text is in the
2736 * platform's default codepage.
2738 * If <code>codepage</code> is an empty string (<code>""</code>),
2739 * then a simple conversion is performed on the codepage-invariant
2740 * subset ("invariant characters") of the platform encoding. See utypes.h.
2741 * Recommendation: For invariant-character strings use the constructor
2742 * UnicodeString(const char *src, int32_t length, enum EInvariant inv)
2743 * because it avoids object code dependencies of UnicodeString on
2744 * the conversion code.
2748 UnicodeString(const char *codepageData
,
2749 const char *codepage
= 0);
2752 * char* constructor.
2753 * @param codepageData an array of bytes.
2754 * @param dataLength The number of bytes in <TT>codepageData</TT>.
2755 * @param codepage the encoding of <TT>codepageData</TT>. The special
2756 * value 0 for <TT>codepage</TT> indicates that the text is in the
2757 * platform's default codepage.
2758 * If <code>codepage</code> is an empty string (<code>""</code>),
2759 * then a simple conversion is performed on the codepage-invariant
2760 * subset ("invariant characters") of the platform encoding. See utypes.h.
2761 * Recommendation: For invariant-character strings use the constructor
2762 * UnicodeString(const char *src, int32_t length, enum EInvariant inv)
2763 * because it avoids object code dependencies of UnicodeString on
2764 * the conversion code.
2768 UnicodeString(const char *codepageData
,
2770 const char *codepage
= 0);
2773 * char * / UConverter constructor.
2774 * This constructor uses an existing UConverter object to
2775 * convert the codepage string to Unicode and construct a UnicodeString
2778 * The converter is reset at first.
2779 * If the error code indicates a failure before this constructor is called,
2780 * or if an error occurs during conversion or construction,
2781 * then the string will be bogus.
2783 * This function avoids the overhead of opening and closing a converter if
2784 * multiple strings are constructed.
2786 * @param src input codepage string
2787 * @param srcLength length of the input string, can be -1 for NUL-terminated strings
2788 * @param cnv converter object (ucnv_resetToUnicode() will be called),
2789 * can be NULL for the default converter
2790 * @param errorCode normal ICU error code
2794 const char *src
, int32_t srcLength
,
2796 UErrorCode
&errorCode
);
2801 * Constructs a Unicode string from an invariant-character char * string.
2802 * About invariant characters see utypes.h.
2803 * This constructor has no runtime dependency on conversion code and is
2804 * therefore recommended over ones taking a charset name string
2805 * (where the empty string "" indicates invariant-character conversion).
2807 * Use the macro US_INV as the third, signature-distinguishing parameter.
2811 * void fn(const char *s) {
2812 * UnicodeString ustr(s, -1, US_INV);
2817 * @param src String using only invariant characters.
2818 * @param length Length of src, or -1 if NUL-terminated.
2819 * @param inv Signature-distinguishing paramater, use US_INV.
2824 UnicodeString(const char *src
, int32_t length
, enum EInvariant inv
);
2829 * @param that The UnicodeString object to copy.
2832 UnicodeString(const UnicodeString
& that
);
2835 * 'Substring' constructor from tail of source string.
2836 * @param src The UnicodeString object to copy.
2837 * @param srcStart The offset into <tt>src</tt> at which to start copying.
2840 UnicodeString(const UnicodeString
& src
, int32_t srcStart
);
2843 * 'Substring' constructor from subrange of source string.
2844 * @param src The UnicodeString object to copy.
2845 * @param srcStart The offset into <tt>src</tt> at which to start copying.
2846 * @param srcLength The number of characters from <tt>src</tt> to copy.
2849 UnicodeString(const UnicodeString
& src
, int32_t srcStart
, int32_t srcLength
);
2852 * Clone this object, an instance of a subclass of Replaceable.
2853 * Clones can be used concurrently in multiple threads.
2854 * If a subclass does not implement clone(), or if an error occurs,
2855 * then NULL is returned.
2856 * The clone functions in all subclasses return a pointer to a Replaceable
2857 * because some compilers do not support covariant (same-as-this)
2858 * return types; cast to the appropriate subclass if necessary.
2859 * The caller must delete the clone.
2861 * @return a clone of this object
2863 * @see Replaceable::clone
2864 * @see getDynamicClassID
2867 virtual Replaceable
*clone() const;
2872 virtual ~UnicodeString();
2875 /* Miscellaneous operations */
2878 * Unescape a string of characters and return a string containing
2879 * the result. The following escape sequences are recognized:
2881 * \\uhhhh 4 hex digits; h in [0-9A-Fa-f]
2882 * \\Uhhhhhhhh 8 hex digits
2883 * \\xhh 1-2 hex digits
2884 * \\ooo 1-3 octal digits; o in [0-7]
2885 * \\cX control-X; X is masked with 0x1F
2887 * as well as the standard ANSI C escapes:
2889 * \\a => U+0007, \\b => U+0008, \\t => U+0009, \\n => U+000A,
2890 * \\v => U+000B, \\f => U+000C, \\r => U+000D, \\e => U+001B,
2891 * \\" => U+0022, \\' => U+0027, \\? => U+003F, \\\\ => U+005C
2893 * Anything else following a backslash is generically escaped. For
2894 * example, "[a\\-z]" returns "[a-z]".
2896 * If an escape sequence is ill-formed, this method returns an empty
2897 * string. An example of an ill-formed sequence is "\\u" followed by
2898 * fewer than 4 hex digits.
2900 * This function is similar to u_unescape() but not identical to it.
2901 * The latter takes a source char*, so it does escape recognition
2902 * and also invariant conversion.
2904 * @return a string with backslash escapes interpreted, or an
2905 * empty string on error.
2906 * @see UnicodeString#unescapeAt()
2908 * @see u_unescapeAt()
2911 UnicodeString
unescape() const;
2914 * Unescape a single escape sequence and return the represented
2915 * character. See unescape() for a listing of the recognized escape
2916 * sequences. The character at offset-1 is assumed (without
2917 * checking) to be a backslash. If the escape sequence is
2918 * ill-formed, or the offset is out of range, (UChar32)0xFFFFFFFF is
2921 * @param offset an input output parameter. On input, it is the
2922 * offset into this string where the escape sequence is located,
2923 * after the initial backslash. On output, it is advanced after the
2924 * last character parsed. On error, it is not advanced at all.
2925 * @return the character represented by the escape sequence at
2926 * offset, or (UChar32)0xFFFFFFFF on error.
2927 * @see UnicodeString#unescape()
2929 * @see u_unescapeAt()
2932 UChar32
unescapeAt(int32_t &offset
) const;
2935 * ICU "poor man's RTTI", returns a UClassID for this class.
2939 static UClassID U_EXPORT2
getStaticClassID();
2942 * ICU "poor man's RTTI", returns a UClassID for the actual class.
2946 virtual UClassID
getDynamicClassID() const;
2948 //========================================
2949 // Implementation methods
2950 //========================================
2954 * Implement Replaceable::getLength() (see jitterbug 1027).
2957 virtual int32_t getLength() const;
2960 * The change in Replaceable to use virtual getCharAt() allows
2961 * UnicodeString::charAt() to be inline again (see jitterbug 709).
2964 virtual UChar
getCharAt(int32_t offset
) const;
2967 * The change in Replaceable to use virtual getChar32At() allows
2968 * UnicodeString::char32At() to be inline again (see jitterbug 709).
2971 virtual UChar32
getChar32At(int32_t offset
) const;
2976 doCompare(int32_t start
,
2978 const UnicodeString
& srcText
,
2980 int32_t srcLength
) const;
2982 int8_t doCompare(int32_t start
,
2984 const UChar
*srcChars
,
2986 int32_t srcLength
) const;
2989 doCompareCodePointOrder(int32_t start
,
2991 const UnicodeString
& srcText
,
2993 int32_t srcLength
) const;
2995 int8_t doCompareCodePointOrder(int32_t start
,
2997 const UChar
*srcChars
,
2999 int32_t srcLength
) const;
3002 doCaseCompare(int32_t start
,
3004 const UnicodeString
&srcText
,
3007 uint32_t options
) const;
3010 doCaseCompare(int32_t start
,
3012 const UChar
*srcChars
,
3015 uint32_t options
) const;
3017 int32_t doIndexOf(UChar c
,
3019 int32_t length
) const;
3021 int32_t doIndexOf(UChar32 c
,
3023 int32_t length
) const;
3025 int32_t doLastIndexOf(UChar c
,
3027 int32_t length
) const;
3029 int32_t doLastIndexOf(UChar32 c
,
3031 int32_t length
) const;
3033 void doExtract(int32_t start
,
3036 int32_t dstStart
) const;
3038 inline void doExtract(int32_t start
,
3040 UnicodeString
& target
) const;
3042 inline UChar
doCharAt(int32_t offset
) const;
3044 UnicodeString
& doReplace(int32_t start
,
3046 const UnicodeString
& srcText
,
3050 UnicodeString
& doReplace(int32_t start
,
3052 const UChar
*srcChars
,
3056 UnicodeString
& doReverse(int32_t start
,
3059 // calculate hash code
3060 int32_t doHashCode(void) const;
3062 // get pointer to start of array
3063 inline UChar
* getArrayStart(void);
3064 inline const UChar
* getArrayStart(void) const;
3066 // allocate the array; result may be fStackBuffer
3067 // sets refCount to 1 if appropriate
3068 // sets fArray, fCapacity, and fFlags
3069 // returns boolean for success or failure
3070 UBool
allocate(int32_t capacity
);
3072 // release the array if owned
3073 void releaseArray(void);
3075 // turn a bogus string into an empty one
3078 // implements assigment operator, copy constructor, and fastCopyFrom()
3079 UnicodeString
©From(const UnicodeString
&src
, UBool fastCopy
=FALSE
);
3081 // Pin start and limit to acceptable values.
3082 inline void pinIndex(int32_t& start
) const;
3083 inline void pinIndices(int32_t& start
,
3084 int32_t& length
) const;
3086 #if !UCONFIG_NO_CONVERSION
3088 /* Internal extract() using UConverter. */
3089 int32_t doExtract(int32_t start
, int32_t length
,
3090 char *dest
, int32_t destCapacity
,
3092 UErrorCode
&errorCode
) const;
3095 * Real constructor for converting from codepage data.
3096 * It assumes that it is called with !fRefCounted.
3098 * If <code>codepage==0</code>, then the default converter
3099 * is used for the platform encoding.
3100 * If <code>codepage</code> is an empty string (<code>""</code>),
3101 * then a simple conversion is performed on the codepage-invariant
3102 * subset ("invariant characters") of the platform encoding. See utypes.h.
3104 void doCodepageCreate(const char *codepageData
,
3106 const char *codepage
);
3109 * Worker function for creating a UnicodeString from
3110 * a codepage string using a UConverter.
3113 doCodepageCreate(const char *codepageData
,
3115 UConverter
*converter
,
3116 UErrorCode
&status
);
3121 * This function is called when write access to the array
3124 * We need to make a copy of the array if
3125 * the buffer is read-only, or
3126 * the buffer is refCounted (shared), and refCount>1, or
3127 * the buffer is too small.
3129 * Return FALSE if memory could not be allocated.
3131 UBool
cloneArrayIfNeeded(int32_t newCapacity
= -1,
3132 int32_t growCapacity
= -1,
3133 UBool doCopyArray
= TRUE
,
3134 int32_t **pBufferToDelete
= 0,
3135 UBool forceClone
= FALSE
);
3137 // common function for case mappings
3139 caseMap(BreakIterator
*titleIter
,
3142 int32_t toWhichCase
);
3146 int32_t removeRef(void);
3147 int32_t refCount(void) const;
3151 US_STACKBUF_SIZE
=7, // Size of stack buffer for small strings
3152 kInvalidUChar
=0xffff, // invalid UChar index
3153 kGrowSize
=128, // grow size for this buffer
3154 kInvalidHashCode
=0, // invalid hash code
3155 kEmptyHashCode
=1, // hash code for empty string
3157 // bit flag values for fFlags
3158 kIsBogus
=1, // this string is bogus, i.e., not valid or NULL
3159 kUsingStackBuffer
=2,// fArray==fStackBuffer
3160 kRefCounted
=4, // there is a refCount field before the characters in fArray
3161 kBufferIsReadonly
=8,// do not write to this buffer
3162 kOpenGetBuffer
=16, // getBuffer(minCapacity) was called (is "open"),
3163 // and releaseBuffer(newLength) must be called
3165 // combined values for convenience
3166 kShortString
=kUsingStackBuffer
,
3167 kLongString
=kRefCounted
,
3168 kReadonlyAlias
=kBufferIsReadonly
,
3172 friend class StringCharacterIterator
;
3173 friend class StringThreadTest
;
3176 * The following are all the class fields that are stored
3177 * in each UnicodeString object.
3178 * Note that UnicodeString has virtual functions,
3179 * therefore there is an implicit vtable pointer
3180 * as the first real field.
3181 * The fields should be aligned such that no padding is
3182 * necessary, mostly by having larger types first.
3183 * On 32-bit machines, the size should be 32 bytes,
3184 * on 64-bit machines (8-byte pointers), it should be 40 bytes.
3186 // (implicit) *vtable;
3187 int32_t fLength
; // number of characters in fArray
3188 int32_t fCapacity
; // sizeof fArray
3189 UChar
*fArray
; // the Unicode data
3190 uint16_t fFlags
; // bit flags: see constants above
3191 UChar fStackBuffer
[ US_STACKBUF_SIZE
]; // buffer for small strings
3196 * Create a new UnicodeString with the concatenation of two others.
3198 * @param s1 The first string to be copied to the new one.
3199 * @param s2 The second string to be copied to the new one, after s1.
3200 * @return UnicodeString(s1).append(s2)
3203 U_COMMON_API UnicodeString U_EXPORT2
3204 operator+ (const UnicodeString
&s1
, const UnicodeString
&s2
);
3206 //========================================
3208 //========================================
3210 //========================================
3212 //========================================
3215 UnicodeString::pinIndex(int32_t& start
) const
3220 } else if(start
> fLength
) {
3226 UnicodeString::pinIndices(int32_t& start
,
3227 int32_t& _length
) const
3232 } else if(start
> fLength
) {
3237 } else if(_length
> (fLength
- start
)) {
3238 _length
= (fLength
- start
);
3243 UnicodeString::getArrayStart()
3247 UnicodeString::getArrayStart() const
3250 //========================================
3251 // Read-only implementation methods
3252 //========================================
3254 UnicodeString::length() const
3258 UnicodeString::getCapacity() const
3259 { return fCapacity
; }
3262 UnicodeString::hashCode() const
3263 { return doHashCode(); }
3266 UnicodeString::isBogus() const
3267 { return (UBool
)(fFlags
& kIsBogus
); }
3269 inline const UChar
*
3270 UnicodeString::getBuffer() const {
3271 if(!(fFlags
&(kIsBogus
|kOpenGetBuffer
))) {
3278 //========================================
3279 // Read-only alias methods
3280 //========================================
3282 UnicodeString::doCompare(int32_t start
,
3284 const UnicodeString
& srcText
,
3286 int32_t srcLength
) const
3288 if(srcText
.isBogus()) {
3289 return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
3291 srcText
.pinIndices(srcStart
, srcLength
);
3292 return doCompare(start
, length
, srcText
.fArray
, srcStart
, srcLength
);
3297 UnicodeString::operator== (const UnicodeString
& text
) const
3300 return text
.isBogus();
3304 fLength
== text
.fLength
&&
3305 doCompare(0, fLength
, text
, 0, text
.fLength
) == 0;
3310 UnicodeString::operator!= (const UnicodeString
& text
) const
3311 { return (! operator==(text
)); }
3314 UnicodeString::operator> (const UnicodeString
& text
) const
3315 { return doCompare(0, fLength
, text
, 0, text
.fLength
) == 1; }
3318 UnicodeString::operator< (const UnicodeString
& text
) const
3319 { return doCompare(0, fLength
, text
, 0, text
.fLength
) == -1; }
3322 UnicodeString::operator>= (const UnicodeString
& text
) const
3323 { return doCompare(0, fLength
, text
, 0, text
.fLength
) != -1; }
3326 UnicodeString::operator<= (const UnicodeString
& text
) const
3327 { return doCompare(0, fLength
, text
, 0, text
.fLength
) != 1; }
3330 UnicodeString::compare(const UnicodeString
& text
) const
3331 { return doCompare(0, fLength
, text
, 0, text
.fLength
); }
3334 UnicodeString::compare(int32_t start
,
3336 const UnicodeString
& srcText
) const
3337 { return doCompare(start
, _length
, srcText
, 0, srcText
.fLength
); }
3340 UnicodeString::compare(const UChar
*srcChars
,
3341 int32_t srcLength
) const
3342 { return doCompare(0, fLength
, srcChars
, 0, srcLength
); }
3345 UnicodeString::compare(int32_t start
,
3347 const UnicodeString
& srcText
,
3349 int32_t srcLength
) const
3350 { return doCompare(start
, _length
, srcText
, srcStart
, srcLength
); }
3353 UnicodeString::compare(int32_t start
,
3355 const UChar
*srcChars
) const
3356 { return doCompare(start
, _length
, srcChars
, 0, _length
); }
3359 UnicodeString::compare(int32_t start
,
3361 const UChar
*srcChars
,
3363 int32_t srcLength
) const
3364 { return doCompare(start
, _length
, srcChars
, srcStart
, srcLength
); }
3367 UnicodeString::compareBetween(int32_t start
,
3369 const UnicodeString
& srcText
,
3371 int32_t srcLimit
) const
3372 { return doCompare(start
, limit
- start
,
3373 srcText
, srcStart
, srcLimit
- srcStart
); }
3376 UnicodeString::doCompareCodePointOrder(int32_t start
,
3378 const UnicodeString
& srcText
,
3380 int32_t srcLength
) const
3382 if(srcText
.isBogus()) {
3383 return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
3385 srcText
.pinIndices(srcStart
, srcLength
);
3386 return doCompareCodePointOrder(start
, length
, srcText
.fArray
, srcStart
, srcLength
);
3391 UnicodeString::compareCodePointOrder(const UnicodeString
& text
) const
3392 { return doCompareCodePointOrder(0, fLength
, text
, 0, text
.fLength
); }
3395 UnicodeString::compareCodePointOrder(int32_t start
,
3397 const UnicodeString
& srcText
) const
3398 { return doCompareCodePointOrder(start
, _length
, srcText
, 0, srcText
.fLength
); }
3401 UnicodeString::compareCodePointOrder(const UChar
*srcChars
,
3402 int32_t srcLength
) const
3403 { return doCompareCodePointOrder(0, fLength
, srcChars
, 0, srcLength
); }
3406 UnicodeString::compareCodePointOrder(int32_t start
,
3408 const UnicodeString
& srcText
,
3410 int32_t srcLength
) const
3411 { return doCompareCodePointOrder(start
, _length
, srcText
, srcStart
, srcLength
); }
3414 UnicodeString::compareCodePointOrder(int32_t start
,
3416 const UChar
*srcChars
) const
3417 { return doCompareCodePointOrder(start
, _length
, srcChars
, 0, _length
); }
3420 UnicodeString::compareCodePointOrder(int32_t start
,
3422 const UChar
*srcChars
,
3424 int32_t srcLength
) const
3425 { return doCompareCodePointOrder(start
, _length
, srcChars
, srcStart
, srcLength
); }
3428 UnicodeString::compareCodePointOrderBetween(int32_t start
,
3430 const UnicodeString
& srcText
,
3432 int32_t srcLimit
) const
3433 { return doCompareCodePointOrder(start
, limit
- start
,
3434 srcText
, srcStart
, srcLimit
- srcStart
); }
3437 UnicodeString::doCaseCompare(int32_t start
,
3439 const UnicodeString
&srcText
,
3442 uint32_t options
) const
3444 if(srcText
.isBogus()) {
3445 return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
3447 srcText
.pinIndices(srcStart
, srcLength
);
3448 return doCaseCompare(start
, length
, srcText
.fArray
, srcStart
, srcLength
, options
);
3453 UnicodeString::caseCompare(const UnicodeString
&text
, uint32_t options
) const {
3454 return doCaseCompare(0, fLength
, text
, 0, text
.fLength
, options
);
3458 UnicodeString::caseCompare(int32_t start
,
3460 const UnicodeString
&srcText
,
3461 uint32_t options
) const {
3462 return doCaseCompare(start
, _length
, srcText
, 0, srcText
.fLength
, options
);
3466 UnicodeString::caseCompare(const UChar
*srcChars
,
3468 uint32_t options
) const {
3469 return doCaseCompare(0, fLength
, srcChars
, 0, srcLength
, options
);
3473 UnicodeString::caseCompare(int32_t start
,
3475 const UnicodeString
&srcText
,
3478 uint32_t options
) const {
3479 return doCaseCompare(start
, _length
, srcText
, srcStart
, srcLength
, options
);
3483 UnicodeString::caseCompare(int32_t start
,
3485 const UChar
*srcChars
,
3486 uint32_t options
) const {
3487 return doCaseCompare(start
, _length
, srcChars
, 0, _length
, options
);
3491 UnicodeString::caseCompare(int32_t start
,
3493 const UChar
*srcChars
,
3496 uint32_t options
) const {
3497 return doCaseCompare(start
, _length
, srcChars
, srcStart
, srcLength
, options
);
3501 UnicodeString::caseCompareBetween(int32_t start
,
3503 const UnicodeString
&srcText
,
3506 uint32_t options
) const {
3507 return doCaseCompare(start
, limit
- start
, srcText
, srcStart
, srcLimit
- srcStart
, options
);
3511 UnicodeString::indexOf(const UnicodeString
& srcText
,
3515 int32_t _length
) const
3517 if(!srcText
.isBogus()) {
3518 srcText
.pinIndices(srcStart
, srcLength
);
3520 return indexOf(srcText
.getArrayStart(), srcStart
, srcLength
, start
, _length
);
3527 UnicodeString::indexOf(const UnicodeString
& text
) const
3528 { return indexOf(text
, 0, text
.fLength
, 0, fLength
); }
3531 UnicodeString::indexOf(const UnicodeString
& text
,
3532 int32_t start
) const {
3534 return indexOf(text
, 0, text
.fLength
, start
, fLength
- start
);
3538 UnicodeString::indexOf(const UnicodeString
& text
,
3540 int32_t _length
) const
3541 { return indexOf(text
, 0, text
.fLength
, start
, _length
); }
3544 UnicodeString::indexOf(const UChar
*srcChars
,
3546 int32_t start
) const {
3548 return indexOf(srcChars
, 0, srcLength
, start
, fLength
- start
);
3552 UnicodeString::indexOf(const UChar
*srcChars
,
3555 int32_t _length
) const
3556 { return indexOf(srcChars
, 0, srcLength
, start
, _length
); }
3559 UnicodeString::indexOf(UChar c
,
3561 int32_t _length
) const
3562 { return doIndexOf(c
, start
, _length
); }
3565 UnicodeString::indexOf(UChar32 c
,
3567 int32_t _length
) const
3568 { return doIndexOf(c
, start
, _length
); }
3571 UnicodeString::indexOf(UChar c
) const
3572 { return doIndexOf(c
, 0, fLength
); }
3575 UnicodeString::indexOf(UChar32 c
) const
3576 { return indexOf(c
, 0, fLength
); }
3579 UnicodeString::indexOf(UChar c
,
3580 int32_t start
) const {
3582 return doIndexOf(c
, start
, fLength
- start
);
3586 UnicodeString::indexOf(UChar32 c
,
3587 int32_t start
) const {
3589 return indexOf(c
, start
, fLength
- start
);
3593 UnicodeString::lastIndexOf(const UChar
*srcChars
,
3596 int32_t _length
) const
3597 { return lastIndexOf(srcChars
, 0, srcLength
, start
, _length
); }
3600 UnicodeString::lastIndexOf(const UChar
*srcChars
,
3602 int32_t start
) const {
3604 return lastIndexOf(srcChars
, 0, srcLength
, start
, fLength
- start
);
3608 UnicodeString::lastIndexOf(const UnicodeString
& srcText
,
3612 int32_t _length
) const
3614 if(!srcText
.isBogus()) {
3615 srcText
.pinIndices(srcStart
, srcLength
);
3617 return lastIndexOf(srcText
.getArrayStart(), srcStart
, srcLength
, start
, _length
);
3624 UnicodeString::lastIndexOf(const UnicodeString
& text
,
3626 int32_t _length
) const
3627 { return lastIndexOf(text
, 0, text
.fLength
, start
, _length
); }
3630 UnicodeString::lastIndexOf(const UnicodeString
& text
,
3631 int32_t start
) const {
3633 return lastIndexOf(text
, 0, text
.fLength
, start
, fLength
- start
);
3637 UnicodeString::lastIndexOf(const UnicodeString
& text
) const
3638 { return lastIndexOf(text
, 0, text
.fLength
, 0, fLength
); }
3641 UnicodeString::lastIndexOf(UChar c
,
3643 int32_t _length
) const
3644 { return doLastIndexOf(c
, start
, _length
); }
3647 UnicodeString::lastIndexOf(UChar32 c
,
3649 int32_t _length
) const {
3650 return doLastIndexOf(c
, start
, _length
);
3654 UnicodeString::lastIndexOf(UChar c
) const
3655 { return doLastIndexOf(c
, 0, fLength
); }
3658 UnicodeString::lastIndexOf(UChar32 c
) const {
3659 return lastIndexOf(c
, 0, fLength
);
3663 UnicodeString::lastIndexOf(UChar c
,
3664 int32_t start
) const {
3666 return doLastIndexOf(c
, start
, fLength
- start
);
3670 UnicodeString::lastIndexOf(UChar32 c
,
3671 int32_t start
) const {
3673 return lastIndexOf(c
, start
, fLength
- start
);
3677 UnicodeString::startsWith(const UnicodeString
& text
) const
3678 { return compare(0, text
.fLength
, text
, 0, text
.fLength
) == 0; }
3681 UnicodeString::startsWith(const UnicodeString
& srcText
,
3683 int32_t srcLength
) const
3684 { return doCompare(0, srcLength
, srcText
, srcStart
, srcLength
) == 0; }
3687 UnicodeString::startsWith(const UChar
*srcChars
,
3688 int32_t srcLength
) const
3689 { return doCompare(0, srcLength
, srcChars
, 0, srcLength
) == 0; }
3692 UnicodeString::startsWith(const UChar
*srcChars
,
3694 int32_t srcLength
) const
3695 { return doCompare(0, srcLength
, srcChars
, srcStart
, srcLength
) == 0;}
3698 UnicodeString::endsWith(const UnicodeString
& text
) const
3699 { return doCompare(fLength
- text
.fLength
, text
.fLength
,
3700 text
, 0, text
.fLength
) == 0; }
3703 UnicodeString::endsWith(const UnicodeString
& srcText
,
3705 int32_t srcLength
) const {
3706 srcText
.pinIndices(srcStart
, srcLength
);
3707 return doCompare(fLength
- srcLength
, srcLength
,
3708 srcText
, srcStart
, srcLength
) == 0;
3712 UnicodeString::endsWith(const UChar
*srcChars
,
3713 int32_t srcLength
) const {
3715 srcLength
= u_strlen(srcChars
);
3717 return doCompare(fLength
- srcLength
, srcLength
,
3718 srcChars
, 0, srcLength
) == 0;
3722 UnicodeString::endsWith(const UChar
*srcChars
,
3724 int32_t srcLength
) const {
3726 srcLength
= u_strlen(srcChars
+ srcStart
);
3728 return doCompare(fLength
- srcLength
, srcLength
,
3729 srcChars
, srcStart
, srcLength
) == 0;
3732 //========================================
3734 //========================================
3735 inline UnicodeString
&
3736 UnicodeString::replace(int32_t start
,
3738 const UnicodeString
& srcText
)
3739 { return doReplace(start
, _length
, srcText
, 0, srcText
.fLength
); }
3741 inline UnicodeString
&
3742 UnicodeString::replace(int32_t start
,
3744 const UnicodeString
& srcText
,
3747 { return doReplace(start
, _length
, srcText
, srcStart
, srcLength
); }
3749 inline UnicodeString
&
3750 UnicodeString::replace(int32_t start
,
3752 const UChar
*srcChars
,
3754 { return doReplace(start
, _length
, srcChars
, 0, srcLength
); }
3756 inline UnicodeString
&
3757 UnicodeString::replace(int32_t start
,
3759 const UChar
*srcChars
,
3762 { return doReplace(start
, _length
, srcChars
, srcStart
, srcLength
); }
3764 inline UnicodeString
&
3765 UnicodeString::replace(int32_t start
,
3768 { return doReplace(start
, _length
, &srcChar
, 0, 1); }
3770 inline UnicodeString
&
3771 UnicodeString::replace(int32_t start
,
3774 UChar buffer
[U16_MAX_LENGTH
];
3776 UBool isError
= FALSE
;
3777 U16_APPEND(buffer
, count
, U16_MAX_LENGTH
, srcChar
, isError
);
3778 return doReplace(start
, _length
, buffer
, 0, count
);
3781 inline UnicodeString
&
3782 UnicodeString::replaceBetween(int32_t start
,
3784 const UnicodeString
& srcText
)
3785 { return doReplace(start
, limit
- start
, srcText
, 0, srcText
.fLength
); }
3787 inline UnicodeString
&
3788 UnicodeString::replaceBetween(int32_t start
,
3790 const UnicodeString
& srcText
,
3793 { return doReplace(start
, limit
- start
, srcText
, srcStart
, srcLimit
- srcStart
); }
3795 inline UnicodeString
&
3796 UnicodeString::findAndReplace(const UnicodeString
& oldText
,
3797 const UnicodeString
& newText
)
3798 { return findAndReplace(0, fLength
, oldText
, 0, oldText
.fLength
,
3799 newText
, 0, newText
.fLength
); }
3801 inline UnicodeString
&
3802 UnicodeString::findAndReplace(int32_t start
,
3804 const UnicodeString
& oldText
,
3805 const UnicodeString
& newText
)
3806 { return findAndReplace(start
, _length
, oldText
, 0, oldText
.fLength
,
3807 newText
, 0, newText
.fLength
); }
3809 // ============================
3811 // ============================
3813 UnicodeString::doExtract(int32_t start
,
3815 UnicodeString
& target
) const
3816 { target
.replace(0, target
.fLength
, *this, start
, _length
); }
3819 UnicodeString::extract(int32_t start
,
3822 int32_t targetStart
) const
3823 { doExtract(start
, _length
, target
, targetStart
); }
3826 UnicodeString::extract(int32_t start
,
3828 UnicodeString
& target
) const
3829 { doExtract(start
, _length
, target
); }
3831 #if !UCONFIG_NO_CONVERSION
3834 UnicodeString::extract(int32_t start
,
3837 const char *codepage
) const
3840 // This dstSize value will be checked explicitly
3841 return extract(start
, _length
, dst
, dst
!=0 ? 0xffffffff : 0, codepage
);
3847 UnicodeString::extractBetween(int32_t start
,
3850 int32_t dstStart
) const {
3853 doExtract(start
, limit
- start
, dst
, dstStart
);
3857 UnicodeString::doCharAt(int32_t offset
) const
3859 if((uint32_t)offset
< (uint32_t)fLength
) {
3860 return fArray
[offset
];
3862 return kInvalidUChar
;
3867 UnicodeString::charAt(int32_t offset
) const
3868 { return doCharAt(offset
); }
3871 UnicodeString::operator[] (int32_t offset
) const
3872 { return doCharAt(offset
); }
3875 UnicodeString::char32At(int32_t offset
) const
3877 if((uint32_t)offset
< (uint32_t)fLength
) {
3879 U16_GET(fArray
, 0, offset
, fLength
, c
);
3882 return kInvalidUChar
;
3887 UnicodeString::getChar32Start(int32_t offset
) const {
3888 if((uint32_t)offset
< (uint32_t)fLength
) {
3889 U16_SET_CP_START(fArray
, 0, offset
);
3897 UnicodeString::getChar32Limit(int32_t offset
) const {
3898 if((uint32_t)offset
< (uint32_t)fLength
) {
3899 U16_SET_CP_LIMIT(fArray
, 0, offset
, fLength
);
3907 UnicodeString::isEmpty() const {
3908 return fLength
== 0;
3911 //========================================
3912 // Write implementation methods
3913 //========================================
3914 inline const UChar
*
3915 UnicodeString::getTerminatedBuffer() {
3916 if(fFlags
&(kIsBogus
|kOpenGetBuffer
)) {
3918 } else if(fLength
<fCapacity
&& fArray
[fLength
]==0) {
3920 } else if(cloneArrayIfNeeded(fLength
+1)) {
3928 inline UnicodeString
&
3929 UnicodeString::operator= (UChar ch
)
3930 { return doReplace(0, fLength
, &ch
, 0, 1); }
3932 inline UnicodeString
&
3933 UnicodeString::operator= (UChar32 ch
)
3934 { return replace(0, fLength
, ch
); }
3936 inline UnicodeString
&
3937 UnicodeString::setTo(const UnicodeString
& srcText
,
3942 return doReplace(0, fLength
, srcText
, srcStart
, srcLength
);
3945 inline UnicodeString
&
3946 UnicodeString::setTo(const UnicodeString
& srcText
,
3950 srcText
.pinIndex(srcStart
);
3951 return doReplace(0, fLength
, srcText
, srcStart
, srcText
.fLength
- srcStart
);
3954 inline UnicodeString
&
3955 UnicodeString::setTo(const UnicodeString
& srcText
)
3958 return doReplace(0, fLength
, srcText
, 0, srcText
.fLength
);
3961 inline UnicodeString
&
3962 UnicodeString::setTo(const UChar
*srcChars
,
3966 return doReplace(0, fLength
, srcChars
, 0, srcLength
);
3969 inline UnicodeString
&
3970 UnicodeString::setTo(UChar srcChar
)
3973 return doReplace(0, fLength
, &srcChar
, 0, 1);
3976 inline UnicodeString
&
3977 UnicodeString::setTo(UChar32 srcChar
)
3980 return replace(0, fLength
, srcChar
);
3983 inline UnicodeString
&
3984 UnicodeString::append(const UnicodeString
& srcText
,
3987 { return doReplace(fLength
, 0, srcText
, srcStart
, srcLength
); }
3989 inline UnicodeString
&
3990 UnicodeString::append(const UnicodeString
& srcText
)
3991 { return doReplace(fLength
, 0, srcText
, 0, srcText
.fLength
); }
3993 inline UnicodeString
&
3994 UnicodeString::append(const UChar
*srcChars
,
3997 { return doReplace(fLength
, 0, srcChars
, srcStart
, srcLength
); }
3999 inline UnicodeString
&
4000 UnicodeString::append(const UChar
*srcChars
,
4002 { return doReplace(fLength
, 0, srcChars
, 0, srcLength
); }
4004 inline UnicodeString
&
4005 UnicodeString::append(UChar srcChar
)
4006 { return doReplace(fLength
, 0, &srcChar
, 0, 1); }
4008 inline UnicodeString
&
4009 UnicodeString::append(UChar32 srcChar
) {
4010 UChar buffer
[U16_MAX_LENGTH
];
4011 int32_t _length
= 0;
4012 UBool isError
= FALSE
;
4013 U16_APPEND(buffer
, _length
, U16_MAX_LENGTH
, srcChar
, isError
);
4014 return doReplace(fLength
, 0, buffer
, 0, _length
);
4017 inline UnicodeString
&
4018 UnicodeString::operator+= (UChar ch
)
4019 { return doReplace(fLength
, 0, &ch
, 0, 1); }
4021 inline UnicodeString
&
4022 UnicodeString::operator+= (UChar32 ch
) {
4026 inline UnicodeString
&
4027 UnicodeString::operator+= (const UnicodeString
& srcText
)
4028 { return doReplace(fLength
, 0, srcText
, 0, srcText
.fLength
); }
4030 inline UnicodeString
&
4031 UnicodeString::insert(int32_t start
,
4032 const UnicodeString
& srcText
,
4035 { return doReplace(start
, 0, srcText
, srcStart
, srcLength
); }
4037 inline UnicodeString
&
4038 UnicodeString::insert(int32_t start
,
4039 const UnicodeString
& srcText
)
4040 { return doReplace(start
, 0, srcText
, 0, srcText
.fLength
); }
4042 inline UnicodeString
&
4043 UnicodeString::insert(int32_t start
,
4044 const UChar
*srcChars
,
4047 { return doReplace(start
, 0, srcChars
, srcStart
, srcLength
); }
4049 inline UnicodeString
&
4050 UnicodeString::insert(int32_t start
,
4051 const UChar
*srcChars
,
4053 { return doReplace(start
, 0, srcChars
, 0, srcLength
); }
4055 inline UnicodeString
&
4056 UnicodeString::insert(int32_t start
,
4058 { return doReplace(start
, 0, &srcChar
, 0, 1); }
4060 inline UnicodeString
&
4061 UnicodeString::insert(int32_t start
,
4063 { return replace(start
, 0, srcChar
); }
4066 inline UnicodeString
&
4067 UnicodeString::remove()
4069 // remove() of a bogus string makes the string empty and non-bogus
4078 inline UnicodeString
&
4079 UnicodeString::remove(int32_t start
,
4082 if(start
<= 0 && _length
== INT32_MAX
) {
4083 // remove(guaranteed everything) of a bogus string makes the string empty and non-bogus
4086 return doReplace(start
, _length
, NULL
, 0, 0);
4089 inline UnicodeString
&
4090 UnicodeString::removeBetween(int32_t start
,
4092 { return doReplace(start
, limit
- start
, NULL
, 0, 0); }
4095 UnicodeString::truncate(int32_t targetLength
)
4097 if(isBogus() && targetLength
== 0) {
4098 // truncate(0) of a bogus string makes the string empty and non-bogus
4101 } else if((uint32_t)targetLength
< (uint32_t)fLength
) {
4102 fLength
= targetLength
;
4109 inline UnicodeString
&
4110 UnicodeString::reverse()
4111 { return doReverse(0, fLength
); }
4113 inline UnicodeString
&
4114 UnicodeString::reverse(int32_t start
,
4116 { return doReverse(start
, _length
); }