2 **********************************************************************
3 * Copyright (C) 1998-2008, 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 U_NAMESPACE_QUALIFIER 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 defined(U_DECLARE_UTF16)
90 # define UNICODE_STRING(cs, _length) U_NAMESPACE_QUALIFIER UnicodeString(TRUE, (const UChar *)U_DECLARE_UTF16(cs), _length)
91 #elif U_SIZEOF_WCHAR_T==U_SIZEOF_UCHAR && (U_CHARSET_FAMILY==U_ASCII_FAMILY || (U_SIZEOF_UCHAR == 2 && defined(U_WCHAR_IS_UTF16)))
92 # define UNICODE_STRING(cs, _length) U_NAMESPACE_QUALIFIER UnicodeString(TRUE, (const UChar *)L ## cs, _length)
93 #elif U_SIZEOF_UCHAR==1 && U_CHARSET_FAMILY==U_ASCII_FAMILY
94 # define UNICODE_STRING(cs, _length) U_NAMESPACE_QUALIFIER UnicodeString(TRUE, (const UChar *)cs, _length)
96 # define UNICODE_STRING(cs, _length) U_NAMESPACE_QUALIFIER UnicodeString(cs, _length, US_INV)
100 * Unicode String literals in C++.
101 * Dependent on the platform properties, different UnicodeString
102 * constructors should be used to create a UnicodeString object from
104 * The macros are defined for improved performance.
105 * They work only for strings that contain "invariant characters", i.e.,
106 * only latin letters, digits, and some punctuation.
107 * See utypes.h for details.
109 * The string parameter must be a C string literal.
112 #define UNICODE_STRING_SIMPLE(cs) UNICODE_STRING(cs, -1)
115 * UnicodeString is a string class that stores Unicode characters directly and provides
116 * similar functionality as the Java String and StringBuffer classes.
117 * It is a concrete implementation of the abstract class Replaceable (for transliteration).
119 * The UnicodeString class is not suitable for subclassing.
121 * <p>For an overview of Unicode strings in C and C++ see the
122 * <a href="http://icu-project.org/userguide/strings.html">User Guide Strings chapter</a>.</p>
124 * <p>In ICU, a Unicode string consists of 16-bit Unicode <em>code units</em>.
125 * A Unicode character may be stored with either one code unit
126 * (the most common case) or with a matched pair of special code units
127 * ("surrogates"). The data type for code units is UChar.
128 * For single-character handling, a Unicode character code <em>point</em> is a value
129 * in the range 0..0x10ffff. ICU uses the UChar32 type for code points.</p>
131 * <p>Indexes and offsets into and lengths of strings always count code units, not code points.
132 * This is the same as with multi-byte char* strings in traditional string handling.
133 * Operations on partial strings typically do not test for code point boundaries.
134 * If necessary, the user needs to take care of such boundaries by testing for the code unit
135 * values or by using functions like
136 * UnicodeString::getChar32Start() and UnicodeString::getChar32Limit()
137 * (or, in C, the equivalent macros U16_SET_CP_START() and U16_SET_CP_LIMIT(), see utf.h).</p>
139 * UnicodeString methods are more lenient with regard to input parameter values
140 * than other ICU APIs. In particular:
141 * - If indexes are out of bounds for a UnicodeString object
142 * (<0 or >length()) then they are "pinned" to the nearest boundary.
143 * - If primitive string pointer values (e.g., const UChar * or char *)
144 * for input strings are NULL, then those input string parameters are treated
145 * as if they pointed to an empty string.
146 * However, this is <em>not</em> the case for char * parameters for charset names
148 * - Most UnicodeString methods do not take a UErrorCode parameter because
149 * there are usually very few opportunities for failure other than a shortage
150 * of memory, error codes in low-level C++ string methods would be inconvenient,
151 * and the error code as the last parameter (ICU convention) would prevent
152 * the use of default parameter values.
153 * Instead, such methods set the UnicodeString into a "bogus" state
154 * (see isBogus()) if an error occurs.
156 * In string comparisons, two UnicodeString objects that are both "bogus"
157 * compare equal (to be transitive and prevent endless loops in sorting),
158 * and a "bogus" string compares less than any non-"bogus" one.
160 * Const UnicodeString methods are thread-safe. Multiple threads can use
161 * const methods on the same UnicodeString object simultaneously,
162 * but non-const methods must not be called concurrently (in multiple threads)
163 * with any other (const or non-const) methods.
165 * Similarly, const UnicodeString & parameters are thread-safe.
166 * One object may be passed in as such a parameter concurrently in multiple threads.
167 * This includes the const UnicodeString & parameters for
168 * copy construction, assignment, and cloning.
170 * <p>UnicodeString uses several storage methods.
171 * String contents can be stored inside the UnicodeString object itself,
172 * in an allocated and shared buffer, or in an outside buffer that is "aliased".
173 * Most of this is done transparently, but careful aliasing in particular provides
174 * significant performance improvements.
175 * Also, the internal buffer is accessible via special functions.
176 * For details see the
177 * <a href="http://icu-project.org/userguide/strings.html">User Guide Strings chapter</a>.</p>
180 * @see CharacterIterator
183 class U_COMMON_API UnicodeString
: public Replaceable
188 * Constant to be used in the UnicodeString(char *, int32_t, EInvariant) constructor
189 * which constructs a Unicode string from an invariant-character char * string.
190 * Use the macro US_INV instead of the full qualification for this value.
203 //========================================
204 // Read-only operations
205 //========================================
207 /* Comparison - bitwise only - for international comparison use collation */
210 * Equality operator. Performs only bitwise comparison.
211 * @param text The UnicodeString to compare to this one.
212 * @return TRUE if <TT>text</TT> contains the same characters as this one,
216 inline UBool
operator== (const UnicodeString
& text
) const;
219 * Inequality operator. Performs only bitwise comparison.
220 * @param text The UnicodeString to compare to this one.
221 * @return FALSE if <TT>text</TT> contains the same characters as this one,
225 inline UBool
operator!= (const UnicodeString
& text
) const;
228 * Greater than operator. Performs only bitwise comparison.
229 * @param text The UnicodeString to compare to this one.
230 * @return TRUE if the characters in this are bitwise
231 * greater than the characters in <code>text</code>, FALSE otherwise
234 inline UBool
operator> (const UnicodeString
& text
) const;
237 * Less than operator. Performs only bitwise comparison.
238 * @param text The UnicodeString to compare to this one.
239 * @return TRUE if the characters in this are bitwise
240 * less than the characters in <code>text</code>, FALSE otherwise
243 inline UBool
operator< (const UnicodeString
& text
) const;
246 * Greater than or equal operator. Performs only bitwise comparison.
247 * @param text The UnicodeString to compare to this one.
248 * @return TRUE if the characters in this are bitwise
249 * greater than or equal to the characters in <code>text</code>, FALSE otherwise
252 inline UBool
operator>= (const UnicodeString
& text
) const;
255 * Less than or equal operator. Performs only bitwise comparison.
256 * @param text The UnicodeString to compare to this one.
257 * @return TRUE if the characters in this are bitwise
258 * less than or equal to the characters in <code>text</code>, FALSE otherwise
261 inline UBool
operator<= (const UnicodeString
& text
) const;
264 * Compare the characters bitwise in this UnicodeString to
265 * the characters in <code>text</code>.
266 * @param text The UnicodeString to compare to this one.
267 * @return The result of bitwise character comparison: 0 if this
268 * contains the same characters as <code>text</code>, -1 if the characters in
269 * this are bitwise less than the characters in <code>text</code>, +1 if the
270 * characters in this are bitwise greater than the characters
271 * in <code>text</code>.
274 inline int8_t compare(const UnicodeString
& text
) const;
277 * Compare the characters bitwise in the range
278 * [<TT>start</TT>, <TT>start + length</TT>) with the characters
280 * @param start the offset at which the compare operation begins
281 * @param length the number of characters of text to compare.
282 * @param text the other text to be compared against this string.
283 * @return The result of bitwise character comparison: 0 if this
284 * contains the same characters as <code>text</code>, -1 if the characters in
285 * this are bitwise less than the characters in <code>text</code>, +1 if the
286 * characters in this are bitwise greater than the characters
287 * in <code>text</code>.
290 inline int8_t compare(int32_t start
,
292 const UnicodeString
& text
) const;
295 * Compare the characters bitwise in the range
296 * [<TT>start</TT>, <TT>start + length</TT>) with the characters
297 * in <TT>srcText</TT> in the range
298 * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
299 * @param start the offset at which the compare operation begins
300 * @param length the number of characters in this to compare.
301 * @param srcText the text to be compared
302 * @param srcStart the offset into <TT>srcText</TT> to start comparison
303 * @param srcLength the number of characters in <TT>src</TT> to compare
304 * @return The result of bitwise character comparison: 0 if this
305 * contains the same characters as <code>srcText</code>, -1 if the characters in
306 * this are bitwise less than the characters in <code>srcText</code>, +1 if the
307 * characters in this are bitwise greater than the characters
308 * in <code>srcText</code>.
311 inline int8_t compare(int32_t start
,
313 const UnicodeString
& srcText
,
315 int32_t srcLength
) const;
318 * Compare the characters bitwise in this UnicodeString with the first
319 * <TT>srcLength</TT> characters in <TT>srcChars</TT>.
320 * @param srcChars The characters to compare to this UnicodeString.
321 * @param srcLength the number of characters in <TT>srcChars</TT> to compare
322 * @return The result of bitwise character comparison: 0 if this
323 * contains the same characters as <code>srcChars</code>, -1 if the characters in
324 * this are bitwise less than the characters in <code>srcChars</code>, +1 if the
325 * characters in this are bitwise greater than the characters
326 * in <code>srcChars</code>.
329 inline int8_t compare(const UChar
*srcChars
,
330 int32_t srcLength
) const;
333 * Compare the characters bitwise in the range
334 * [<TT>start</TT>, <TT>start + length</TT>) with the first
335 * <TT>length</TT> characters in <TT>srcChars</TT>
336 * @param start the offset at which the compare operation begins
337 * @param length the number of characters to compare.
338 * @param srcChars the characters to be compared
339 * @return The result of bitwise character comparison: 0 if this
340 * contains the same characters as <code>srcChars</code>, -1 if the characters in
341 * this are bitwise less than the characters in <code>srcChars</code>, +1 if the
342 * characters in this are bitwise greater than the characters
343 * in <code>srcChars</code>.
346 inline int8_t compare(int32_t start
,
348 const UChar
*srcChars
) const;
351 * Compare the characters bitwise in the range
352 * [<TT>start</TT>, <TT>start + length</TT>) with the characters
353 * in <TT>srcChars</TT> in the range
354 * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
355 * @param start the offset at which the compare operation begins
356 * @param length the number of characters in this to compare
357 * @param srcChars the characters to be compared
358 * @param srcStart the offset into <TT>srcChars</TT> to start comparison
359 * @param srcLength the number of characters in <TT>srcChars</TT> to compare
360 * @return The result of bitwise character comparison: 0 if this
361 * contains the same characters as <code>srcChars</code>, -1 if the characters in
362 * this are bitwise less than the characters in <code>srcChars</code>, +1 if the
363 * characters in this are bitwise greater than the characters
364 * in <code>srcChars</code>.
367 inline int8_t compare(int32_t start
,
369 const UChar
*srcChars
,
371 int32_t srcLength
) const;
374 * Compare the characters bitwise in the range
375 * [<TT>start</TT>, <TT>limit</TT>) with the characters
376 * in <TT>srcText</TT> in the range
377 * [<TT>srcStart</TT>, <TT>srcLimit</TT>).
378 * @param start the offset at which the compare operation begins
379 * @param limit the offset immediately following the compare operation
380 * @param srcText the text to be compared
381 * @param srcStart the offset into <TT>srcText</TT> to start comparison
382 * @param srcLimit the offset into <TT>srcText</TT> to limit comparison
383 * @return The result of bitwise character comparison: 0 if this
384 * contains the same characters as <code>srcText</code>, -1 if the characters in
385 * this are bitwise less than the characters in <code>srcText</code>, +1 if the
386 * characters in this are bitwise greater than the characters
387 * in <code>srcText</code>.
390 inline int8_t compareBetween(int32_t start
,
392 const UnicodeString
& srcText
,
394 int32_t srcLimit
) const;
397 * Compare two Unicode strings in code point order.
398 * The result may be different from the results of compare(), operator<, etc.
399 * if supplementary characters are present:
401 * In UTF-16, supplementary characters (with code points U+10000 and above) are
402 * stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff,
403 * which means that they compare as less than some other BMP characters like U+feff.
404 * This function compares Unicode strings in code point order.
405 * If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.
407 * @param text Another string to compare this one to.
408 * @return a negative/zero/positive integer corresponding to whether
409 * this string is less than/equal to/greater than the second one
410 * in code point order
413 inline int8_t compareCodePointOrder(const UnicodeString
& text
) const;
416 * Compare two Unicode strings in code point order.
417 * The result may be different from the results of compare(), operator<, etc.
418 * if supplementary characters are present:
420 * In UTF-16, supplementary characters (with code points U+10000 and above) are
421 * stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff,
422 * which means that they compare as less than some other BMP characters like U+feff.
423 * This function compares Unicode strings in code point order.
424 * If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.
426 * @param start The start offset in this string at which the compare operation begins.
427 * @param length The number of code units from this string to compare.
428 * @param srcText Another string to compare this one to.
429 * @return a negative/zero/positive integer corresponding to whether
430 * this string is less than/equal to/greater than the second one
431 * in code point order
434 inline int8_t compareCodePointOrder(int32_t start
,
436 const UnicodeString
& srcText
) const;
439 * Compare two Unicode strings in code point order.
440 * The result may be different from the results of compare(), operator<, etc.
441 * if supplementary characters are present:
443 * In UTF-16, supplementary characters (with code points U+10000 and above) are
444 * stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff,
445 * which means that they compare as less than some other BMP characters like U+feff.
446 * This function compares Unicode strings in code point order.
447 * If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.
449 * @param start The start offset in this string at which the compare operation begins.
450 * @param length The number of code units from this string to compare.
451 * @param srcText Another string to compare this one to.
452 * @param srcStart The start offset in that string at which the compare operation begins.
453 * @param srcLength The number of code units from that string to compare.
454 * @return a negative/zero/positive integer corresponding to whether
455 * this string is less than/equal to/greater than the second one
456 * in code point order
459 inline int8_t compareCodePointOrder(int32_t start
,
461 const UnicodeString
& srcText
,
463 int32_t srcLength
) const;
466 * Compare two Unicode strings in code point order.
467 * The result may be different from the results of compare(), operator<, etc.
468 * if supplementary characters are present:
470 * In UTF-16, supplementary characters (with code points U+10000 and above) are
471 * stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff,
472 * which means that they compare as less than some other BMP characters like U+feff.
473 * This function compares Unicode strings in code point order.
474 * If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.
476 * @param srcChars A pointer to another string to compare this one to.
477 * @param srcLength The number of code units from that string to compare.
478 * @return a negative/zero/positive integer corresponding to whether
479 * this string is less than/equal to/greater than the second one
480 * in code point order
483 inline int8_t compareCodePointOrder(const UChar
*srcChars
,
484 int32_t srcLength
) const;
487 * Compare two Unicode strings in code point order.
488 * The result may be different from the results of compare(), operator<, etc.
489 * if supplementary characters are present:
491 * In UTF-16, supplementary characters (with code points U+10000 and above) are
492 * stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff,
493 * which means that they compare as less than some other BMP characters like U+feff.
494 * This function compares Unicode strings in code point order.
495 * If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.
497 * @param start The start offset in this string at which the compare operation begins.
498 * @param length The number of code units from this string to compare.
499 * @param srcChars A pointer to another string to compare this one to.
500 * @return a negative/zero/positive integer corresponding to whether
501 * this string is less than/equal to/greater than the second one
502 * in code point order
505 inline int8_t compareCodePointOrder(int32_t start
,
507 const UChar
*srcChars
) const;
510 * Compare two Unicode strings in code point order.
511 * The result may be different from the results of compare(), operator<, etc.
512 * if supplementary characters are present:
514 * In UTF-16, supplementary characters (with code points U+10000 and above) are
515 * stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff,
516 * which means that they compare as less than some other BMP characters like U+feff.
517 * This function compares Unicode strings in code point order.
518 * If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.
520 * @param start The start offset in this string at which the compare operation begins.
521 * @param length The number of code units from this string to compare.
522 * @param srcChars A pointer to another string to compare this one to.
523 * @param srcStart The start offset in that string at which the compare operation begins.
524 * @param srcLength The number of code units from that string to compare.
525 * @return a negative/zero/positive integer corresponding to whether
526 * this string is less than/equal to/greater than the second one
527 * in code point order
530 inline int8_t compareCodePointOrder(int32_t start
,
532 const UChar
*srcChars
,
534 int32_t srcLength
) const;
537 * Compare two Unicode strings in code point order.
538 * The result may be different from the results of compare(), operator<, etc.
539 * if supplementary characters are present:
541 * In UTF-16, supplementary characters (with code points U+10000 and above) are
542 * stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff,
543 * which means that they compare as less than some other BMP characters like U+feff.
544 * This function compares Unicode strings in code point order.
545 * If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.
547 * @param start The start offset in this string at which the compare operation begins.
548 * @param limit The offset after the last code unit from this string to compare.
549 * @param srcText Another string to compare this one to.
550 * @param srcStart The start offset in that string at which the compare operation begins.
551 * @param srcLimit The offset after the last code unit from that string to compare.
552 * @return a negative/zero/positive integer corresponding to whether
553 * this string is less than/equal to/greater than the second one
554 * in code point order
557 inline int8_t compareCodePointOrderBetween(int32_t start
,
559 const UnicodeString
& srcText
,
561 int32_t srcLimit
) const;
564 * Compare two strings case-insensitively using full case folding.
565 * This is equivalent to this->foldCase(options).compare(text.foldCase(options)).
567 * @param text Another string to compare this one to.
568 * @param options A bit set of options:
569 * - U_FOLD_CASE_DEFAULT or 0 is used for default options:
570 * Comparison in code unit order with default case folding.
572 * - U_COMPARE_CODE_POINT_ORDER
573 * Set to choose code point order instead of code unit order
574 * (see u_strCompare for details).
576 * - U_FOLD_CASE_EXCLUDE_SPECIAL_I
578 * @return A negative, zero, or positive integer indicating the comparison result.
581 inline int8_t caseCompare(const UnicodeString
& text
, uint32_t options
) const;
584 * Compare two strings case-insensitively using full case folding.
585 * This is equivalent to this->foldCase(options).compare(srcText.foldCase(options)).
587 * @param start The start offset in this string at which the compare operation begins.
588 * @param length The number of code units from this string to compare.
589 * @param srcText Another string to compare this one to.
590 * @param options A bit set of options:
591 * - U_FOLD_CASE_DEFAULT or 0 is used for default options:
592 * Comparison in code unit order with default case folding.
594 * - U_COMPARE_CODE_POINT_ORDER
595 * Set to choose code point order instead of code unit order
596 * (see u_strCompare for details).
598 * - U_FOLD_CASE_EXCLUDE_SPECIAL_I
600 * @return A negative, zero, or positive integer indicating the comparison result.
603 inline int8_t caseCompare(int32_t start
,
605 const UnicodeString
& srcText
,
606 uint32_t options
) const;
609 * Compare two strings case-insensitively using full case folding.
610 * This is equivalent to this->foldCase(options).compare(srcText.foldCase(options)).
612 * @param start The start offset in this string at which the compare operation begins.
613 * @param length The number of code units from this string to compare.
614 * @param srcText Another string to compare this one to.
615 * @param srcStart The start offset in that string at which the compare operation begins.
616 * @param srcLength The number of code units from that string to compare.
617 * @param options A bit set of options:
618 * - U_FOLD_CASE_DEFAULT or 0 is used for default options:
619 * Comparison in code unit order with default case folding.
621 * - U_COMPARE_CODE_POINT_ORDER
622 * Set to choose code point order instead of code unit order
623 * (see u_strCompare for details).
625 * - U_FOLD_CASE_EXCLUDE_SPECIAL_I
627 * @return A negative, zero, or positive integer indicating the comparison result.
630 inline int8_t caseCompare(int32_t start
,
632 const UnicodeString
& srcText
,
635 uint32_t options
) const;
638 * Compare two strings case-insensitively using full case folding.
639 * This is equivalent to this->foldCase(options).compare(srcChars.foldCase(options)).
641 * @param srcChars A pointer to another string to compare this one to.
642 * @param srcLength The number of code units from that string to compare.
643 * @param options A bit set of options:
644 * - U_FOLD_CASE_DEFAULT or 0 is used for default options:
645 * Comparison in code unit order with default case folding.
647 * - U_COMPARE_CODE_POINT_ORDER
648 * Set to choose code point order instead of code unit order
649 * (see u_strCompare for details).
651 * - U_FOLD_CASE_EXCLUDE_SPECIAL_I
653 * @return A negative, zero, or positive integer indicating the comparison result.
656 inline int8_t caseCompare(const UChar
*srcChars
,
658 uint32_t options
) const;
661 * Compare two strings case-insensitively using full case folding.
662 * This is equivalent to this->foldCase(options).compare(srcChars.foldCase(options)).
664 * @param start The start offset in this string at which the compare operation begins.
665 * @param length The number of code units from this string to compare.
666 * @param srcChars A pointer to another string to compare this one to.
667 * @param options A bit set of options:
668 * - U_FOLD_CASE_DEFAULT or 0 is used for default options:
669 * Comparison in code unit order with default case folding.
671 * - U_COMPARE_CODE_POINT_ORDER
672 * Set to choose code point order instead of code unit order
673 * (see u_strCompare for details).
675 * - U_FOLD_CASE_EXCLUDE_SPECIAL_I
677 * @return A negative, zero, or positive integer indicating the comparison result.
680 inline int8_t caseCompare(int32_t start
,
682 const UChar
*srcChars
,
683 uint32_t options
) const;
686 * Compare two strings case-insensitively using full case folding.
687 * This is equivalent to this->foldCase(options).compare(srcChars.foldCase(options)).
689 * @param start The start offset in this string at which the compare operation begins.
690 * @param length The number of code units from this string to compare.
691 * @param srcChars A pointer to another string to compare this one to.
692 * @param srcStart The start offset in that string at which the compare operation begins.
693 * @param srcLength The number of code units from that string to compare.
694 * @param options A bit set of options:
695 * - U_FOLD_CASE_DEFAULT or 0 is used for default options:
696 * Comparison in code unit order with default case folding.
698 * - U_COMPARE_CODE_POINT_ORDER
699 * Set to choose code point order instead of code unit order
700 * (see u_strCompare for details).
702 * - U_FOLD_CASE_EXCLUDE_SPECIAL_I
704 * @return A negative, zero, or positive integer indicating the comparison result.
707 inline int8_t caseCompare(int32_t start
,
709 const UChar
*srcChars
,
712 uint32_t options
) const;
715 * Compare two strings case-insensitively using full case folding.
716 * This is equivalent to this->foldCase(options).compareBetween(text.foldCase(options)).
718 * @param start The start offset in this string at which the compare operation begins.
719 * @param limit The offset after the last code unit from this string to compare.
720 * @param srcText Another string to compare this one to.
721 * @param srcStart The start offset in that string at which the compare operation begins.
722 * @param srcLimit The offset after the last code unit from that string to compare.
723 * @param options A bit set of options:
724 * - U_FOLD_CASE_DEFAULT or 0 is used for default options:
725 * Comparison in code unit order with default case folding.
727 * - U_COMPARE_CODE_POINT_ORDER
728 * Set to choose code point order instead of code unit order
729 * (see u_strCompare for details).
731 * - U_FOLD_CASE_EXCLUDE_SPECIAL_I
733 * @return A negative, zero, or positive integer indicating the comparison result.
736 inline int8_t caseCompareBetween(int32_t start
,
738 const UnicodeString
& srcText
,
741 uint32_t options
) const;
744 * Determine if this starts with the characters in <TT>text</TT>
745 * @param text The text to match.
746 * @return TRUE if this starts with the characters in <TT>text</TT>,
750 inline UBool
startsWith(const UnicodeString
& text
) const;
753 * Determine if this starts with the characters in <TT>srcText</TT>
754 * in the range [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
755 * @param srcText The text to match.
756 * @param srcStart the offset into <TT>srcText</TT> to start matching
757 * @param srcLength the number of characters in <TT>srcText</TT> to match
758 * @return TRUE if this starts with the characters in <TT>text</TT>,
762 inline UBool
startsWith(const UnicodeString
& srcText
,
764 int32_t srcLength
) const;
767 * Determine if this starts with the characters in <TT>srcChars</TT>
768 * @param srcChars The characters to match.
769 * @param srcLength the number of characters in <TT>srcChars</TT>
770 * @return TRUE if this starts with the characters in <TT>srcChars</TT>,
774 inline UBool
startsWith(const UChar
*srcChars
,
775 int32_t srcLength
) const;
778 * Determine if this ends with the characters in <TT>srcChars</TT>
779 * in the range [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
780 * @param srcChars The characters to match.
781 * @param srcStart the offset into <TT>srcText</TT> to start matching
782 * @param srcLength the number of characters in <TT>srcChars</TT> to match
783 * @return TRUE if this ends with the characters in <TT>srcChars</TT>, FALSE otherwise
786 inline UBool
startsWith(const UChar
*srcChars
,
788 int32_t srcLength
) const;
791 * Determine if this ends with the characters in <TT>text</TT>
792 * @param text The text to match.
793 * @return TRUE if this ends with the characters in <TT>text</TT>,
797 inline UBool
endsWith(const UnicodeString
& text
) const;
800 * Determine if this ends with the characters in <TT>srcText</TT>
801 * in the range [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
802 * @param srcText The text to match.
803 * @param srcStart the offset into <TT>srcText</TT> to start matching
804 * @param srcLength the number of characters in <TT>srcText</TT> to match
805 * @return TRUE if this ends with the characters in <TT>text</TT>,
809 inline UBool
endsWith(const UnicodeString
& srcText
,
811 int32_t srcLength
) const;
814 * Determine if this ends with the characters in <TT>srcChars</TT>
815 * @param srcChars The characters to match.
816 * @param srcLength the number of characters in <TT>srcChars</TT>
817 * @return TRUE if this ends with the characters in <TT>srcChars</TT>,
821 inline UBool
endsWith(const UChar
*srcChars
,
822 int32_t srcLength
) const;
825 * Determine if this ends with the characters in <TT>srcChars</TT>
826 * in the range [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
827 * @param srcChars The characters to match.
828 * @param srcStart the offset into <TT>srcText</TT> to start matching
829 * @param srcLength the number of characters in <TT>srcChars</TT> to match
830 * @return TRUE if this ends with the characters in <TT>srcChars</TT>,
834 inline UBool
endsWith(const UChar
*srcChars
,
836 int32_t srcLength
) const;
839 /* Searching - bitwise only */
842 * Locate in this the first occurrence of the characters in <TT>text</TT>,
843 * using bitwise comparison.
844 * @param text The text to search for.
845 * @return The offset into this of the start of <TT>text</TT>,
846 * or -1 if not found.
849 inline int32_t indexOf(const UnicodeString
& text
) const;
852 * Locate in this the first occurrence of the characters in <TT>text</TT>
853 * starting at offset <TT>start</TT>, using bitwise comparison.
854 * @param text The text to search for.
855 * @param start The offset at which searching will start.
856 * @return The offset into this of the start of <TT>text</TT>,
857 * or -1 if not found.
860 inline int32_t indexOf(const UnicodeString
& text
,
861 int32_t start
) const;
864 * Locate in this the first occurrence in the range
865 * [<TT>start</TT>, <TT>start + length</TT>) of the characters
866 * in <TT>text</TT>, using bitwise comparison.
867 * @param text The text to search for.
868 * @param start The offset at which searching will start.
869 * @param length The number of characters to search
870 * @return The offset into this of the start of <TT>text</TT>,
871 * or -1 if not found.
874 inline int32_t indexOf(const UnicodeString
& text
,
876 int32_t length
) const;
879 * Locate in this the first occurrence in the range
880 * [<TT>start</TT>, <TT>start + length</TT>) of the characters
881 * in <TT>srcText</TT> in the range
882 * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>),
883 * using bitwise comparison.
884 * @param srcText The text to search for.
885 * @param srcStart the offset into <TT>srcText</TT> at which
887 * @param srcLength the number of characters in <TT>srcText</TT> to match
888 * @param start the offset into this at which to start matching
889 * @param length the number of characters in this to search
890 * @return The offset into this of the start of <TT>text</TT>,
891 * or -1 if not found.
894 inline int32_t indexOf(const UnicodeString
& srcText
,
898 int32_t length
) const;
901 * Locate in this the first occurrence of the characters in
903 * starting at offset <TT>start</TT>, using bitwise comparison.
904 * @param srcChars The text to search for.
905 * @param srcLength the number of characters in <TT>srcChars</TT> to match
906 * @param start the offset into this at which to start matching
907 * @return The offset into this of the start of <TT>text</TT>,
908 * or -1 if not found.
911 inline int32_t indexOf(const UChar
*srcChars
,
913 int32_t start
) const;
916 * Locate in this the first occurrence in the range
917 * [<TT>start</TT>, <TT>start + length</TT>) of the characters
918 * in <TT>srcChars</TT>, using bitwise comparison.
919 * @param srcChars The text to search for.
920 * @param srcLength the number of characters in <TT>srcChars</TT>
921 * @param start The offset at which searching will start.
922 * @param length The number of characters to search
923 * @return The offset into this of the start of <TT>srcChars</TT>,
924 * or -1 if not found.
927 inline int32_t indexOf(const UChar
*srcChars
,
930 int32_t length
) const;
933 * Locate in this the first occurrence in the range
934 * [<TT>start</TT>, <TT>start + length</TT>) of the characters
935 * in <TT>srcChars</TT> in the range
936 * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>),
937 * using bitwise comparison.
938 * @param srcChars The text to search for.
939 * @param srcStart the offset into <TT>srcChars</TT> at which
941 * @param srcLength the number of characters in <TT>srcChars</TT> to match
942 * @param start the offset into this at which to start matching
943 * @param length the number of characters in this to search
944 * @return The offset into this of the start of <TT>text</TT>,
945 * or -1 if not found.
948 int32_t indexOf(const UChar
*srcChars
,
952 int32_t length
) const;
955 * Locate in this the first occurrence of the BMP code point <code>c</code>,
956 * using bitwise comparison.
957 * @param c The code unit to search for.
958 * @return The offset into this of <TT>c</TT>, or -1 if not found.
961 inline int32_t indexOf(UChar c
) const;
964 * Locate in this the first occurrence of the code point <TT>c</TT>,
965 * using bitwise comparison.
967 * @param c The code point to search for.
968 * @return The offset into this of <TT>c</TT>, or -1 if not found.
971 inline int32_t indexOf(UChar32 c
) const;
974 * Locate in this the first occurrence of the BMP code point <code>c</code>,
975 * starting at offset <TT>start</TT>, using bitwise comparison.
976 * @param c The code unit to search for.
977 * @param start The offset at which searching will start.
978 * @return The offset into this of <TT>c</TT>, or -1 if not found.
981 inline int32_t indexOf(UChar c
,
982 int32_t start
) const;
985 * Locate in this the first occurrence of the code point <TT>c</TT>
986 * starting at offset <TT>start</TT>, using bitwise comparison.
988 * @param c The code point to search for.
989 * @param start The offset at which searching will start.
990 * @return The offset into this of <TT>c</TT>, or -1 if not found.
993 inline int32_t indexOf(UChar32 c
,
994 int32_t start
) const;
997 * Locate in this the first occurrence of the BMP code point <code>c</code>
998 * in the range [<TT>start</TT>, <TT>start + length</TT>),
999 * using bitwise comparison.
1000 * @param c The code unit to search for.
1001 * @param start the offset into this at which to start matching
1002 * @param length the number of characters in this to search
1003 * @return The offset into this of <TT>c</TT>, or -1 if not found.
1006 inline int32_t indexOf(UChar c
,
1008 int32_t length
) const;
1011 * Locate in this the first occurrence of the code point <TT>c</TT>
1012 * in the range [<TT>start</TT>, <TT>start + length</TT>),
1013 * using bitwise comparison.
1015 * @param c The code point to search for.
1016 * @param start the offset into this at which to start matching
1017 * @param length the number of characters in this to search
1018 * @return The offset into this of <TT>c</TT>, or -1 if not found.
1021 inline int32_t indexOf(UChar32 c
,
1023 int32_t length
) const;
1026 * Locate in this the last occurrence of the characters in <TT>text</TT>,
1027 * using bitwise comparison.
1028 * @param text The text to search for.
1029 * @return The offset into this of the start of <TT>text</TT>,
1030 * or -1 if not found.
1033 inline int32_t lastIndexOf(const UnicodeString
& text
) const;
1036 * Locate in this the last occurrence of the characters in <TT>text</TT>
1037 * starting at offset <TT>start</TT>, using bitwise comparison.
1038 * @param text The text to search for.
1039 * @param start The offset at which searching will start.
1040 * @return The offset into this of the start of <TT>text</TT>,
1041 * or -1 if not found.
1044 inline int32_t lastIndexOf(const UnicodeString
& text
,
1045 int32_t start
) const;
1048 * Locate in this the last occurrence in the range
1049 * [<TT>start</TT>, <TT>start + length</TT>) of the characters
1050 * in <TT>text</TT>, using bitwise comparison.
1051 * @param text The text to search for.
1052 * @param start The offset at which searching will start.
1053 * @param length The number of characters to search
1054 * @return The offset into this of the start of <TT>text</TT>,
1055 * or -1 if not found.
1058 inline int32_t lastIndexOf(const UnicodeString
& text
,
1060 int32_t length
) const;
1063 * Locate in this the last occurrence in the range
1064 * [<TT>start</TT>, <TT>start + length</TT>) of the characters
1065 * in <TT>srcText</TT> in the range
1066 * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>),
1067 * using bitwise comparison.
1068 * @param srcText The text to search for.
1069 * @param srcStart the offset into <TT>srcText</TT> at which
1071 * @param srcLength the number of characters in <TT>srcText</TT> to match
1072 * @param start the offset into this at which to start matching
1073 * @param length the number of characters in this to search
1074 * @return The offset into this of the start of <TT>text</TT>,
1075 * or -1 if not found.
1078 inline int32_t lastIndexOf(const UnicodeString
& srcText
,
1082 int32_t length
) const;
1085 * Locate in this the last occurrence of the characters in <TT>srcChars</TT>
1086 * starting at offset <TT>start</TT>, using bitwise comparison.
1087 * @param srcChars The text to search for.
1088 * @param srcLength the number of characters in <TT>srcChars</TT> to match
1089 * @param start the offset into this at which to start matching
1090 * @return The offset into this of the start of <TT>text</TT>,
1091 * or -1 if not found.
1094 inline int32_t lastIndexOf(const UChar
*srcChars
,
1096 int32_t start
) const;
1099 * Locate in this the last occurrence in the range
1100 * [<TT>start</TT>, <TT>start + length</TT>) of the characters
1101 * in <TT>srcChars</TT>, using bitwise comparison.
1102 * @param srcChars The text to search for.
1103 * @param srcLength the number of characters in <TT>srcChars</TT>
1104 * @param start The offset at which searching will start.
1105 * @param length The number of characters to search
1106 * @return The offset into this of the start of <TT>srcChars</TT>,
1107 * or -1 if not found.
1110 inline int32_t lastIndexOf(const UChar
*srcChars
,
1113 int32_t length
) const;
1116 * Locate in this the last occurrence in the range
1117 * [<TT>start</TT>, <TT>start + length</TT>) of the characters
1118 * in <TT>srcChars</TT> in the range
1119 * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>),
1120 * using bitwise comparison.
1121 * @param srcChars The text to search for.
1122 * @param srcStart the offset into <TT>srcChars</TT> at which
1124 * @param srcLength the number of characters in <TT>srcChars</TT> to match
1125 * @param start the offset into this at which to start matching
1126 * @param length the number of characters in this to search
1127 * @return The offset into this of the start of <TT>text</TT>,
1128 * or -1 if not found.
1131 int32_t lastIndexOf(const UChar
*srcChars
,
1135 int32_t length
) const;
1138 * Locate in this the last occurrence of the BMP code point <code>c</code>,
1139 * using bitwise comparison.
1140 * @param c The code unit to search for.
1141 * @return The offset into this of <TT>c</TT>, or -1 if not found.
1144 inline int32_t lastIndexOf(UChar c
) const;
1147 * Locate in this the last occurrence of the code point <TT>c</TT>,
1148 * using bitwise comparison.
1150 * @param c The code point to search for.
1151 * @return The offset into this of <TT>c</TT>, or -1 if not found.
1154 inline int32_t lastIndexOf(UChar32 c
) const;
1157 * Locate in this the last occurrence of the BMP code point <code>c</code>
1158 * starting at offset <TT>start</TT>, using bitwise comparison.
1159 * @param c The code unit to search for.
1160 * @param start The offset at which searching will start.
1161 * @return The offset into this of <TT>c</TT>, or -1 if not found.
1164 inline int32_t lastIndexOf(UChar c
,
1165 int32_t start
) const;
1168 * Locate in this the last occurrence of the code point <TT>c</TT>
1169 * starting at offset <TT>start</TT>, using bitwise comparison.
1171 * @param c The code point to search for.
1172 * @param start The offset at which searching will start.
1173 * @return The offset into this of <TT>c</TT>, or -1 if not found.
1176 inline int32_t lastIndexOf(UChar32 c
,
1177 int32_t start
) const;
1180 * Locate in this the last occurrence of the BMP code point <code>c</code>
1181 * in the range [<TT>start</TT>, <TT>start + length</TT>),
1182 * using bitwise comparison.
1183 * @param c The code unit to search for.
1184 * @param start the offset into this at which to start matching
1185 * @param length the number of characters in this to search
1186 * @return The offset into this of <TT>c</TT>, or -1 if not found.
1189 inline int32_t lastIndexOf(UChar c
,
1191 int32_t length
) const;
1194 * Locate in this the last occurrence of the code point <TT>c</TT>
1195 * in the range [<TT>start</TT>, <TT>start + length</TT>),
1196 * using bitwise comparison.
1198 * @param c The code point to search for.
1199 * @param start the offset into this at which to start matching
1200 * @param length the number of characters in this to search
1201 * @return The offset into this of <TT>c</TT>, or -1 if not found.
1204 inline int32_t lastIndexOf(UChar32 c
,
1206 int32_t length
) const;
1209 /* Character access */
1212 * Return the code unit at offset <tt>offset</tt>.
1213 * If the offset is not valid (0..length()-1) then U+ffff is returned.
1214 * @param offset a valid offset into the text
1215 * @return the code unit at offset <tt>offset</tt>
1216 * or 0xffff if the offset is not valid for this string
1219 inline UChar
charAt(int32_t offset
) const;
1222 * Return the code unit at offset <tt>offset</tt>.
1223 * If the offset is not valid (0..length()-1) then U+ffff is returned.
1224 * @param offset a valid offset into the text
1225 * @return the code unit at offset <tt>offset</tt>
1228 inline UChar
operator[] (int32_t offset
) const;
1231 * Return the code point that contains the code unit
1232 * at offset <tt>offset</tt>.
1233 * If the offset is not valid (0..length()-1) then U+ffff is returned.
1234 * @param offset a valid offset into the text
1235 * that indicates the text offset of any of the code units
1236 * that will be assembled into a code point (21-bit value) and returned
1237 * @return the code point of text at <tt>offset</tt>
1238 * or 0xffff if the offset is not valid for this string
1241 inline UChar32
char32At(int32_t offset
) const;
1244 * Adjust a random-access offset so that
1245 * it points to the beginning of a Unicode character.
1246 * The offset that is passed in points to
1247 * any code unit of a code point,
1248 * while the returned offset will point to the first code unit
1249 * of the same code point.
1250 * In UTF-16, if the input offset points to a second surrogate
1251 * of a surrogate pair, then the returned offset will point
1252 * to the first surrogate.
1253 * @param offset a valid offset into one code point of the text
1254 * @return offset of the first code unit of the same code point
1255 * @see U16_SET_CP_START
1258 inline int32_t getChar32Start(int32_t offset
) const;
1261 * Adjust a random-access offset so that
1262 * it points behind a Unicode character.
1263 * The offset that is passed in points behind
1264 * any code unit of a code point,
1265 * while the returned offset will point behind the last code unit
1266 * of the same code point.
1267 * In UTF-16, if the input offset points behind the first surrogate
1268 * (i.e., to the second surrogate)
1269 * of a surrogate pair, then the returned offset will point
1270 * behind the second surrogate (i.e., to the first surrogate).
1271 * @param offset a valid offset after any code unit of a code point of the text
1272 * @return offset of the first code unit after the same code point
1273 * @see U16_SET_CP_LIMIT
1276 inline int32_t getChar32Limit(int32_t offset
) const;
1279 * Move the code unit index along the string by delta code points.
1280 * Interpret the input index as a code unit-based offset into the string,
1281 * move the index forward or backward by delta code points, and
1282 * return the resulting index.
1283 * The input index should point to the first code unit of a code point,
1284 * if there is more than one.
1286 * Both input and output indexes are code unit-based as for all
1287 * string indexes/offsets in ICU (and other libraries, like MBCS char*).
1288 * If delta<0 then the index is moved backward (toward the start of the string).
1289 * If delta>0 then the index is moved forward (toward the end of the string).
1291 * This behaves like CharacterIterator::move32(delta, kCurrent).
1293 * Behavior for out-of-bounds indexes:
1294 * <code>moveIndex32</code> pins the input index to 0..length(), i.e.,
1295 * if the input index<0 then it is pinned to 0;
1296 * if it is index>length() then it is pinned to length().
1297 * Afterwards, the index is moved by <code>delta</code> code points
1298 * forward or backward,
1299 * but no further backward than to 0 and no further forward than to length().
1300 * The resulting index return value will be in between 0 and length(), inclusively.
1304 * // s has code points 'a' U+10000 'b' U+10ffff U+2029
1305 * UnicodeString s=UNICODE_STRING("a\\U00010000b\\U0010ffff\\u2029", 31).unescape();
1307 * // initial index: position of U+10000
1310 * // the following examples will all result in index==4, position of U+10ffff
1312 * // skip 2 code points from some position in the string
1313 * index=s.moveIndex32(index, 2); // skips U+10000 and 'b'
1315 * // go to the 3rd code point from the start of s (0-based)
1316 * index=s.moveIndex32(0, 3); // skips 'a', U+10000, and 'b'
1318 * // go to the next-to-last code point of s
1319 * index=s.moveIndex32(s.length(), -2); // backward-skips U+2029 and U+10ffff
1322 * @param index input code unit index
1323 * @param delta (signed) code point count to move the index forward or backward
1325 * @return the resulting code unit index
1328 int32_t moveIndex32(int32_t index
, int32_t delta
) const;
1330 /* Substring extraction */
1333 * Copy the characters in the range
1334 * [<tt>start</tt>, <tt>start + length</tt>) into the array <tt>dst</tt>,
1335 * beginning at <tt>dstStart</tt>.
1336 * If the string aliases to <code>dst</code> itself as an external buffer,
1337 * then extract() will not copy the contents.
1339 * @param start offset of first character which will be copied into the array
1340 * @param length the number of characters to extract
1341 * @param dst array in which to copy characters. The length of <tt>dst</tt>
1342 * must be at least (<tt>dstStart + length</tt>).
1343 * @param dstStart the offset in <TT>dst</TT> where the first character
1347 inline void extract(int32_t start
,
1350 int32_t dstStart
= 0) const;
1353 * Copy the contents of the string into dest.
1354 * This is a convenience function that
1355 * checks if there is enough space in dest,
1356 * extracts the entire string if possible,
1357 * and NUL-terminates dest if possible.
1359 * If the string fits into dest but cannot be NUL-terminated
1360 * (length()==destCapacity) then the error code is set to U_STRING_NOT_TERMINATED_WARNING.
1361 * If the string itself does not fit into dest
1362 * (length()>destCapacity) then the error code is set to U_BUFFER_OVERFLOW_ERROR.
1364 * If the string aliases to <code>dest</code> itself as an external buffer,
1365 * then extract() will not copy the contents.
1367 * @param dest Destination string buffer.
1368 * @param destCapacity Number of UChars available at dest.
1369 * @param errorCode ICU error code.
1374 extract(UChar
*dest
, int32_t destCapacity
,
1375 UErrorCode
&errorCode
) const;
1378 * Copy the characters in the range
1379 * [<tt>start</tt>, <tt>start + length</tt>) into the UnicodeString
1381 * @param start offset of first character which will be copied
1382 * @param length the number of characters to extract
1383 * @param target UnicodeString into which to copy characters.
1384 * @return A reference to <TT>target</TT>
1387 inline void extract(int32_t start
,
1389 UnicodeString
& target
) const;
1392 * Copy the characters in the range [<tt>start</tt>, <tt>limit</tt>)
1393 * into the array <tt>dst</tt>, beginning at <tt>dstStart</tt>.
1394 * @param start offset of first character which will be copied into the array
1395 * @param limit offset immediately following the last character to be copied
1396 * @param dst array in which to copy characters. The length of <tt>dst</tt>
1397 * must be at least (<tt>dstStart + (limit - start)</tt>).
1398 * @param dstStart the offset in <TT>dst</TT> where the first character
1402 inline void extractBetween(int32_t start
,
1405 int32_t dstStart
= 0) const;
1408 * Copy the characters in the range [<tt>start</tt>, <tt>limit</tt>)
1409 * into the UnicodeString <tt>target</tt>. Replaceable API.
1410 * @param start offset of first character which will be copied
1411 * @param limit offset immediately following the last character to be copied
1412 * @param target UnicodeString into which to copy characters.
1413 * @return A reference to <TT>target</TT>
1416 virtual void extractBetween(int32_t start
,
1418 UnicodeString
& target
) const;
1421 * Copy the characters in the range
1422 * [<tt>start</TT>, <tt>start + length</TT>) into an array of characters.
1423 * All characters must be invariant (see utypes.h).
1424 * Use US_INV as the last, signature-distinguishing parameter.
1426 * This function does not write any more than <code>targetLength</code>
1427 * characters but returns the length of the entire output string
1428 * so that one can allocate a larger buffer and call the function again
1430 * The output string is NUL-terminated if possible.
1432 * @param start offset of first character which will be copied
1433 * @param startLength the number of characters to extract
1434 * @param target the target buffer for extraction, can be NULL
1435 * if targetLength is 0
1436 * @param targetCapacity the length of the target buffer
1437 * @param inv Signature-distinguishing paramater, use US_INV.
1438 * @return the output string length, not including the terminating NUL
1441 int32_t extract(int32_t start
,
1442 int32_t startLength
,
1444 int32_t targetCapacity
,
1445 enum EInvariant inv
) const;
1447 #if !UCONFIG_NO_CONVERSION
1450 * Copy the characters in the range
1451 * [<tt>start</TT>, <tt>start + length</TT>) into an array of characters
1452 * in a specified codepage.
1453 * The output string is NUL-terminated.
1455 * Recommendation: For invariant-character strings use
1456 * extract(int32_t start, int32_t length, char *target, int32_t targetCapacity, enum EInvariant inv) const
1457 * because it avoids object code dependencies of UnicodeString on
1458 * the conversion code.
1460 * @param start offset of first character which will be copied
1461 * @param startLength the number of characters to extract
1462 * @param target the target buffer for extraction
1463 * @param codepage the desired codepage for the characters. 0 has
1464 * the special meaning of the default codepage
1465 * If <code>codepage</code> is an empty string (<code>""</code>),
1466 * then a simple conversion is performed on the codepage-invariant
1467 * subset ("invariant characters") of the platform encoding. See utypes.h.
1468 * If <TT>target</TT> is NULL, then the number of bytes required for
1469 * <TT>target</TT> is returned. It is assumed that the target is big enough
1470 * to fit all of the characters.
1471 * @return the output string length, not including the terminating NUL
1474 inline int32_t extract(int32_t start
,
1475 int32_t startLength
,
1477 const char *codepage
= 0) const;
1480 * Copy the characters in the range
1481 * [<tt>start</TT>, <tt>start + length</TT>) into an array of characters
1482 * in a specified codepage.
1483 * This function does not write any more than <code>targetLength</code>
1484 * characters but returns the length of the entire output string
1485 * so that one can allocate a larger buffer and call the function again
1487 * The output string is NUL-terminated if possible.
1489 * Recommendation: For invariant-character strings use
1490 * extract(int32_t start, int32_t length, char *target, int32_t targetCapacity, enum EInvariant inv) const
1491 * because it avoids object code dependencies of UnicodeString on
1492 * the conversion code.
1494 * @param start offset of first character which will be copied
1495 * @param startLength the number of characters to extract
1496 * @param target the target buffer for extraction
1497 * @param targetLength the length of the target buffer
1498 * @param codepage the desired codepage for the characters. 0 has
1499 * the special meaning of the default codepage
1500 * If <code>codepage</code> is an empty string (<code>""</code>),
1501 * then a simple conversion is performed on the codepage-invariant
1502 * subset ("invariant characters") of the platform encoding. See utypes.h.
1503 * If <TT>target</TT> is NULL, then the number of bytes required for
1504 * <TT>target</TT> is returned.
1505 * @return the output string length, not including the terminating NUL
1508 int32_t extract(int32_t start
,
1509 int32_t startLength
,
1511 uint32_t targetLength
,
1512 const char *codepage
= 0) const;
1515 * Convert the UnicodeString into a codepage string using an existing UConverter.
1516 * The output string is NUL-terminated if possible.
1518 * This function avoids the overhead of opening and closing a converter if
1519 * multiple strings are extracted.
1521 * @param dest destination string buffer, can be NULL if destCapacity==0
1522 * @param destCapacity the number of chars available at dest
1523 * @param cnv the converter object to be used (ucnv_resetFromUnicode() will be called),
1524 * or NULL for the default converter
1525 * @param errorCode normal ICU error code
1526 * @return the length of the output string, not counting the terminating NUL;
1527 * if the length is greater than destCapacity, then the string will not fit
1528 * and a buffer of the indicated length would need to be passed in
1531 int32_t extract(char *dest
, int32_t destCapacity
,
1533 UErrorCode
&errorCode
) const;
1537 /* Length operations */
1540 * Return the length of the UnicodeString object.
1541 * The length is the number of UChar code units are in the UnicodeString.
1542 * If you want the number of code points, please use countChar32().
1543 * @return the length of the UnicodeString object
1547 inline int32_t length(void) const;
1550 * Count Unicode code points in the length UChar code units of the string.
1551 * A code point may occupy either one or two UChar code units.
1552 * Counting code points involves reading all code units.
1554 * This functions is basically the inverse of moveIndex32().
1556 * @param start the index of the first code unit to check
1557 * @param length the number of UChar code units to check
1558 * @return the number of code points in the specified code units
1563 countChar32(int32_t start
=0, int32_t length
=INT32_MAX
) const;
1566 * Check if the length UChar code units of the string
1567 * contain more Unicode code points than a certain number.
1568 * This is more efficient than counting all code points in this part of the string
1569 * and comparing that number with a threshold.
1570 * This function may not need to scan the string at all if the length
1571 * falls within a certain range, and
1572 * never needs to count more than 'number+1' code points.
1573 * Logically equivalent to (countChar32(start, length)>number).
1574 * A Unicode code point may occupy either one or two UChar code units.
1576 * @param start the index of the first code unit to check (0 for the entire string)
1577 * @param length the number of UChar code units to check
1578 * (use INT32_MAX for the entire string; remember that start/length
1579 * values are pinned)
1580 * @param number The number of code points in the (sub)string is compared against
1581 * the 'number' parameter.
1582 * @return Boolean value for whether the string contains more Unicode code points
1583 * than 'number'. Same as (u_countChar32(s, length)>number).
1585 * @see u_strHasMoreChar32Than
1589 hasMoreChar32Than(int32_t start
, int32_t length
, int32_t number
) const;
1592 * Determine if this string is empty.
1593 * @return TRUE if this string contains 0 characters, FALSE otherwise.
1596 inline UBool
isEmpty(void) const;
1599 * Return the capacity of the internal buffer of the UnicodeString object.
1600 * This is useful together with the getBuffer functions.
1601 * See there for details.
1603 * @return the number of UChars available in the internal buffer
1607 inline int32_t getCapacity(void) const;
1609 /* Other operations */
1612 * Generate a hash code for this object.
1613 * @return The hash code of this UnicodeString.
1616 inline int32_t hashCode(void) const;
1619 * Determine if this object contains a valid string.
1620 * A bogus string has no value. It is different from an empty string.
1621 * It can be used to indicate that no string value is available.
1622 * getBuffer() and getTerminatedBuffer() return NULL, and
1623 * length() returns 0.
1625 * @return TRUE if the string is valid, FALSE otherwise
1629 inline UBool
isBogus(void) const;
1632 //========================================
1634 //========================================
1636 /* Assignment operations */
1639 * Assignment operator. Replace the characters in this UnicodeString
1640 * with the characters from <TT>srcText</TT>.
1641 * @param srcText The text containing the characters to replace
1642 * @return a reference to this
1645 UnicodeString
&operator=(const UnicodeString
&srcText
);
1648 * Almost the same as the assignment operator.
1649 * Replace the characters in this UnicodeString
1650 * with the characters from <code>srcText</code>.
1652 * This function works the same for all strings except for ones that
1653 * are readonly aliases.
1654 * Starting with ICU 2.4, the assignment operator and the copy constructor
1655 * allocate a new buffer and copy the buffer contents even for readonly aliases.
1656 * This function implements the old, more efficient but less safe behavior
1657 * of making this string also a readonly alias to the same buffer.
1658 * The fastCopyFrom function must be used only if it is known that the lifetime of
1659 * this UnicodeString is at least as long as the lifetime of the aliased buffer
1660 * including its contents, for example for strings from resource bundles
1661 * or aliases to string contents.
1663 * @param src The text containing the characters to replace.
1664 * @return a reference to this
1667 UnicodeString
&fastCopyFrom(const UnicodeString
&src
);
1670 * Assignment operator. Replace the characters in this UnicodeString
1671 * with the code unit <TT>ch</TT>.
1672 * @param ch the code unit to replace
1673 * @return a reference to this
1676 inline UnicodeString
& operator= (UChar ch
);
1679 * Assignment operator. Replace the characters in this UnicodeString
1680 * with the code point <TT>ch</TT>.
1681 * @param ch the code point to replace
1682 * @return a reference to this
1685 inline UnicodeString
& operator= (UChar32 ch
);
1688 * Set the text in the UnicodeString object to the characters
1689 * in <TT>srcText</TT> in the range
1690 * [<TT>srcStart</TT>, <TT>srcText.length()</TT>).
1691 * <TT>srcText</TT> is not modified.
1692 * @param srcText the source for the new characters
1693 * @param srcStart the offset into <TT>srcText</TT> where new characters
1695 * @return a reference to this
1698 inline UnicodeString
& setTo(const UnicodeString
& srcText
,
1702 * Set the text in the UnicodeString object to the characters
1703 * in <TT>srcText</TT> in the range
1704 * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
1705 * <TT>srcText</TT> is not modified.
1706 * @param srcText the source for the new characters
1707 * @param srcStart the offset into <TT>srcText</TT> where new characters
1709 * @param srcLength the number of characters in <TT>srcText</TT> in the
1711 * @return a reference to this
1714 inline UnicodeString
& setTo(const UnicodeString
& srcText
,
1719 * Set the text in the UnicodeString object to the characters in
1721 * <TT>srcText</TT> is not modified.
1722 * @param srcText the source for the new characters
1723 * @return a reference to this
1726 inline UnicodeString
& setTo(const UnicodeString
& srcText
);
1729 * Set the characters in the UnicodeString object to the characters
1730 * in <TT>srcChars</TT>. <TT>srcChars</TT> is not modified.
1731 * @param srcChars the source for the new characters
1732 * @param srcLength the number of Unicode characters in srcChars.
1733 * @return a reference to this
1736 inline UnicodeString
& setTo(const UChar
*srcChars
,
1740 * Set the characters in the UnicodeString object to the code unit
1742 * @param srcChar the code unit which becomes the UnicodeString's character
1744 * @return a reference to this
1747 UnicodeString
& setTo(UChar srcChar
);
1750 * Set the characters in the UnicodeString object to the code point
1752 * @param srcChar the code point which becomes the UnicodeString's character
1754 * @return a reference to this
1757 UnicodeString
& setTo(UChar32 srcChar
);
1760 * Aliasing setTo() function, analogous to the readonly-aliasing UChar* constructor.
1761 * The text will be used for the UnicodeString object, but
1762 * it will not be released when the UnicodeString is destroyed.
1763 * This has copy-on-write semantics:
1764 * When the string is modified, then the buffer is first copied into
1765 * newly allocated memory.
1766 * The aliased buffer is never modified.
1767 * In an assignment to another UnicodeString, the text will be aliased again,
1768 * so that both strings then alias the same readonly-text.
1770 * @param isTerminated specifies if <code>text</code> is <code>NUL</code>-terminated.
1771 * This must be true if <code>textLength==-1</code>.
1772 * @param text The characters to alias for the UnicodeString.
1773 * @param textLength The number of Unicode characters in <code>text</code> to alias.
1774 * If -1, then this constructor will determine the length
1775 * by calling <code>u_strlen()</code>.
1776 * @return a reference to this
1779 UnicodeString
&setTo(UBool isTerminated
,
1781 int32_t textLength
);
1784 * Aliasing setTo() function, analogous to the writable-aliasing UChar* constructor.
1785 * The text will be used for the UnicodeString object, but
1786 * it will not be released when the UnicodeString is destroyed.
1787 * This has write-through semantics:
1788 * For as long as the capacity of the buffer is sufficient, write operations
1789 * will directly affect the buffer. When more capacity is necessary, then
1790 * a new buffer will be allocated and the contents copied as with regularly
1791 * constructed strings.
1792 * In an assignment to another UnicodeString, the buffer will be copied.
1793 * The extract(UChar *dst) function detects whether the dst pointer is the same
1794 * as the string buffer itself and will in this case not copy the contents.
1796 * @param buffer The characters to alias for the UnicodeString.
1797 * @param buffLength The number of Unicode characters in <code>buffer</code> to alias.
1798 * @param buffCapacity The size of <code>buffer</code> in UChars.
1799 * @return a reference to this
1802 UnicodeString
&setTo(UChar
*buffer
,
1804 int32_t buffCapacity
);
1807 * Make this UnicodeString object invalid.
1808 * The string will test TRUE with isBogus().
1810 * A bogus string has no value. It is different from an empty string.
1811 * It can be used to indicate that no string value is available.
1812 * getBuffer() and getTerminatedBuffer() return NULL, and
1813 * length() returns 0.
1815 * This utility function is used throughout the UnicodeString
1816 * implementation to indicate that a UnicodeString operation failed,
1817 * and may be used in other functions,
1818 * especially but not exclusively when such functions do not
1819 * take a UErrorCode for simplicity.
1821 * The following methods, and no others, will clear a string object's bogus flag:
1823 * - remove(0, INT32_MAX)
1825 * - operator=() (assignment operator)
1828 * The simplest ways to turn a bogus string into an empty one
1829 * is to use the remove() function.
1830 * Examples for other functions that are equivalent to "set to empty string":
1833 * s.remove(); // set to an empty string (remove all), or
1834 * s.remove(0, INT32_MAX); // set to an empty string (remove all), or
1835 * s.truncate(0); // set to an empty string (complete truncation), or
1836 * s=UnicodeString(); // assign an empty string, or
1837 * s.setTo((UChar32)-1); // set to a pseudo code point that is out of range, or
1838 * static const UChar nul=0;
1839 * s.setTo(&nul, 0); // set to an empty C Unicode string
1849 * Set the character at the specified offset to the specified character.
1850 * @param offset A valid offset into the text of the character to set
1851 * @param ch The new character
1852 * @return A reference to this
1855 UnicodeString
& setCharAt(int32_t offset
,
1859 /* Append operations */
1862 * Append operator. Append the code unit <TT>ch</TT> to the UnicodeString
1864 * @param ch the code unit to be appended
1865 * @return a reference to this
1868 inline UnicodeString
& operator+= (UChar ch
);
1871 * Append operator. Append the code point <TT>ch</TT> to the UnicodeString
1873 * @param ch the code point to be appended
1874 * @return a reference to this
1877 inline UnicodeString
& operator+= (UChar32 ch
);
1880 * Append operator. Append the characters in <TT>srcText</TT> to the
1881 * UnicodeString object at offset <TT>start</TT>. <TT>srcText</TT> is
1883 * @param srcText the source for the new characters
1884 * @return a reference to this
1887 inline UnicodeString
& operator+= (const UnicodeString
& srcText
);
1890 * Append the characters
1891 * in <TT>srcText</TT> in the range
1892 * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>) to the
1893 * UnicodeString object at offset <TT>start</TT>. <TT>srcText</TT>
1895 * @param srcText the source for the new characters
1896 * @param srcStart the offset into <TT>srcText</TT> where new characters
1898 * @param srcLength the number of characters in <TT>srcText</TT> in
1900 * @return a reference to this
1903 inline UnicodeString
& append(const UnicodeString
& srcText
,
1908 * Append the characters in <TT>srcText</TT> to the UnicodeString object at
1909 * offset <TT>start</TT>. <TT>srcText</TT> is not modified.
1910 * @param srcText the source for the new characters
1911 * @return a reference to this
1914 inline UnicodeString
& append(const UnicodeString
& srcText
);
1917 * Append the characters in <TT>srcChars</TT> in the range
1918 * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>) to the UnicodeString
1920 * <TT>start</TT>. <TT>srcChars</TT> is not modified.
1921 * @param srcChars the source for the new characters
1922 * @param srcStart the offset into <TT>srcChars</TT> where new characters
1924 * @param srcLength the number of characters in <TT>srcChars</TT> in
1926 * @return a reference to this
1929 inline UnicodeString
& append(const UChar
*srcChars
,
1934 * Append the characters in <TT>srcChars</TT> to the UnicodeString object
1935 * at offset <TT>start</TT>. <TT>srcChars</TT> is not modified.
1936 * @param srcChars the source for the new characters
1937 * @param srcLength the number of Unicode characters in <TT>srcChars</TT>
1938 * @return a reference to this
1941 inline UnicodeString
& append(const UChar
*srcChars
,
1945 * Append the code unit <TT>srcChar</TT> to the UnicodeString object.
1946 * @param srcChar the code unit to append
1947 * @return a reference to this
1950 inline UnicodeString
& append(UChar srcChar
);
1953 * Append the code point <TT>srcChar</TT> to the UnicodeString object.
1954 * @param srcChar the code point to append
1955 * @return a reference to this
1958 inline UnicodeString
& append(UChar32 srcChar
);
1961 /* Insert operations */
1964 * Insert the characters in <TT>srcText</TT> in the range
1965 * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>) into the UnicodeString
1966 * object at offset <TT>start</TT>. <TT>srcText</TT> is not modified.
1967 * @param start the offset where the insertion begins
1968 * @param srcText the source for the new characters
1969 * @param srcStart the offset into <TT>srcText</TT> where new characters
1971 * @param srcLength the number of characters in <TT>srcText</TT> in
1973 * @return a reference to this
1976 inline UnicodeString
& insert(int32_t start
,
1977 const UnicodeString
& srcText
,
1982 * Insert the characters in <TT>srcText</TT> into the UnicodeString object
1983 * at offset <TT>start</TT>. <TT>srcText</TT> is not modified.
1984 * @param start the offset where the insertion begins
1985 * @param srcText the source for the new characters
1986 * @return a reference to this
1989 inline UnicodeString
& insert(int32_t start
,
1990 const UnicodeString
& srcText
);
1993 * Insert the characters in <TT>srcChars</TT> in the range
1994 * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>) into the UnicodeString
1995 * object at offset <TT>start</TT>. <TT>srcChars</TT> is not modified.
1996 * @param start the offset at which the insertion begins
1997 * @param srcChars the source for the new characters
1998 * @param srcStart the offset into <TT>srcChars</TT> where new characters
2000 * @param srcLength the number of characters in <TT>srcChars</TT>
2001 * in the insert string
2002 * @return a reference to this
2005 inline UnicodeString
& insert(int32_t start
,
2006 const UChar
*srcChars
,
2011 * Insert the characters in <TT>srcChars</TT> into the UnicodeString object
2012 * at offset <TT>start</TT>. <TT>srcChars</TT> is not modified.
2013 * @param start the offset where the insertion begins
2014 * @param srcChars the source for the new characters
2015 * @param srcLength the number of Unicode characters in srcChars.
2016 * @return a reference to this
2019 inline UnicodeString
& insert(int32_t start
,
2020 const UChar
*srcChars
,
2024 * Insert the code unit <TT>srcChar</TT> into the UnicodeString object at
2025 * offset <TT>start</TT>.
2026 * @param start the offset at which the insertion occurs
2027 * @param srcChar the code unit to insert
2028 * @return a reference to this
2031 inline UnicodeString
& insert(int32_t start
,
2035 * Insert the code point <TT>srcChar</TT> into the UnicodeString object at
2036 * offset <TT>start</TT>.
2037 * @param start the offset at which the insertion occurs
2038 * @param srcChar the code point to insert
2039 * @return a reference to this
2042 inline UnicodeString
& insert(int32_t start
,
2046 /* Replace operations */
2049 * Replace the characters in the range
2050 * [<TT>start</TT>, <TT>start + length</TT>) with the characters in
2051 * <TT>srcText</TT> in the range
2052 * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>).
2053 * <TT>srcText</TT> is not modified.
2054 * @param start the offset at which the replace operation begins
2055 * @param length the number of characters to replace. The character at
2056 * <TT>start + length</TT> is not modified.
2057 * @param srcText the source for the new characters
2058 * @param srcStart the offset into <TT>srcText</TT> where new characters
2060 * @param srcLength the number of characters in <TT>srcText</TT> in
2061 * the replace string
2062 * @return a reference to this
2065 UnicodeString
& replace(int32_t start
,
2067 const UnicodeString
& srcText
,
2072 * Replace the characters in the range
2073 * [<TT>start</TT>, <TT>start + length</TT>)
2074 * with the characters in <TT>srcText</TT>. <TT>srcText</TT> is
2076 * @param start the offset at which the replace operation begins
2077 * @param length the number of characters to replace. The character at
2078 * <TT>start + length</TT> is not modified.
2079 * @param srcText the source for the new characters
2080 * @return a reference to this
2083 UnicodeString
& replace(int32_t start
,
2085 const UnicodeString
& srcText
);
2088 * Replace the characters in the range
2089 * [<TT>start</TT>, <TT>start + length</TT>) with the characters in
2090 * <TT>srcChars</TT> in the range
2091 * [<TT>srcStart</TT>, <TT>srcStart + srcLength</TT>). <TT>srcChars</TT>
2093 * @param start the offset at which the replace operation begins
2094 * @param length the number of characters to replace. The character at
2095 * <TT>start + length</TT> is not modified.
2096 * @param srcChars the source for the new characters
2097 * @param srcStart the offset into <TT>srcChars</TT> where new characters
2099 * @param srcLength the number of characters in <TT>srcChars</TT>
2100 * in the replace string
2101 * @return a reference to this
2104 UnicodeString
& replace(int32_t start
,
2106 const UChar
*srcChars
,
2111 * Replace the characters in the range
2112 * [<TT>start</TT>, <TT>start + length</TT>) with the characters in
2113 * <TT>srcChars</TT>. <TT>srcChars</TT> is not modified.
2114 * @param start the offset at which the replace operation begins
2115 * @param length number of characters to replace. The character at
2116 * <TT>start + length</TT> is not modified.
2117 * @param srcChars the source for the new characters
2118 * @param srcLength the number of Unicode characters in srcChars
2119 * @return a reference to this
2122 inline UnicodeString
& replace(int32_t start
,
2124 const UChar
*srcChars
,
2128 * Replace the characters in the range
2129 * [<TT>start</TT>, <TT>start + length</TT>) with the code unit
2131 * @param start the offset at which the replace operation begins
2132 * @param length the number of characters to replace. The character at
2133 * <TT>start + length</TT> is not modified.
2134 * @param srcChar the new code unit
2135 * @return a reference to this
2138 inline UnicodeString
& replace(int32_t start
,
2143 * Replace the characters in the range
2144 * [<TT>start</TT>, <TT>start + length</TT>) with the code point
2146 * @param start the offset at which the replace operation begins
2147 * @param length the number of characters to replace. The character at
2148 * <TT>start + length</TT> is not modified.
2149 * @param srcChar the new code point
2150 * @return a reference to this
2153 inline UnicodeString
& replace(int32_t start
,
2158 * Replace the characters in the range [<TT>start</TT>, <TT>limit</TT>)
2159 * with the characters in <TT>srcText</TT>. <TT>srcText</TT> is not modified.
2160 * @param start the offset at which the replace operation begins
2161 * @param limit the offset immediately following the replace range
2162 * @param srcText the source for the new characters
2163 * @return a reference to this
2166 inline UnicodeString
& replaceBetween(int32_t start
,
2168 const UnicodeString
& srcText
);
2171 * Replace the characters in the range [<TT>start</TT>, <TT>limit</TT>)
2172 * with the characters in <TT>srcText</TT> in the range
2173 * [<TT>srcStart</TT>, <TT>srcLimit</TT>). <TT>srcText</TT> is not modified.
2174 * @param start the offset at which the replace operation begins
2175 * @param limit the offset immediately following the replace range
2176 * @param srcText the source for the new characters
2177 * @param srcStart the offset into <TT>srcChars</TT> where new characters
2179 * @param srcLimit the offset immediately following the range to copy
2180 * in <TT>srcText</TT>
2181 * @return a reference to this
2184 inline UnicodeString
& replaceBetween(int32_t start
,
2186 const UnicodeString
& srcText
,
2191 * Replace a substring of this object with the given text.
2192 * @param start the beginning index, inclusive; <code>0 <= start
2194 * @param limit the ending index, exclusive; <code>start <= limit
2195 * <= length()</code>.
2196 * @param text the text to replace characters <code>start</code>
2197 * to <code>limit - 1</code>
2200 virtual void handleReplaceBetween(int32_t start
,
2202 const UnicodeString
& text
);
2206 * @return TRUE if it has MetaData
2209 virtual UBool
hasMetaData() const;
2212 * Copy a substring of this object, retaining attribute (out-of-band)
2213 * information. This method is used to duplicate or reorder substrings.
2214 * The destination index must not overlap the source range.
2216 * @param start the beginning index, inclusive; <code>0 <= start <=
2218 * @param limit the ending index, exclusive; <code>start <= limit <=
2220 * @param dest the destination index. The characters from
2221 * <code>start..limit-1</code> will be copied to <code>dest</code>.
2222 * Implementations of this method may assume that <code>dest <= start ||
2223 * dest >= limit</code>.
2226 virtual void copy(int32_t start
, int32_t limit
, int32_t dest
);
2228 /* Search and replace operations */
2231 * Replace all occurrences of characters in oldText with the characters
2233 * @param oldText the text containing the search text
2234 * @param newText the text containing the replacement text
2235 * @return a reference to this
2238 inline UnicodeString
& findAndReplace(const UnicodeString
& oldText
,
2239 const UnicodeString
& newText
);
2242 * Replace all occurrences of characters in oldText with characters
2244 * in the range [<TT>start</TT>, <TT>start + length</TT>).
2245 * @param start the start of the range in which replace will performed
2246 * @param length the length of the range in which replace will be performed
2247 * @param oldText the text containing the search text
2248 * @param newText the text containing the replacement text
2249 * @return a reference to this
2252 inline UnicodeString
& findAndReplace(int32_t start
,
2254 const UnicodeString
& oldText
,
2255 const UnicodeString
& newText
);
2258 * Replace all occurrences of characters in oldText in the range
2259 * [<TT>oldStart</TT>, <TT>oldStart + oldLength</TT>) with the characters
2260 * in newText in the range
2261 * [<TT>newStart</TT>, <TT>newStart + newLength</TT>)
2262 * in the range [<TT>start</TT>, <TT>start + length</TT>).
2263 * @param start the start of the range in which replace will performed
2264 * @param length the length of the range in which replace will be performed
2265 * @param oldText the text containing the search text
2266 * @param oldStart the start of the search range in <TT>oldText</TT>
2267 * @param oldLength the length of the search range in <TT>oldText</TT>
2268 * @param newText the text containing the replacement text
2269 * @param newStart the start of the replacement range in <TT>newText</TT>
2270 * @param newLength the length of the replacement range in <TT>newText</TT>
2271 * @return a reference to this
2274 UnicodeString
& findAndReplace(int32_t start
,
2276 const UnicodeString
& oldText
,
2279 const UnicodeString
& newText
,
2284 /* Remove operations */
2287 * Remove all characters from the UnicodeString object.
2288 * @return a reference to this
2291 inline UnicodeString
& remove(void);
2294 * Remove the characters in the range
2295 * [<TT>start</TT>, <TT>start + length</TT>) from the UnicodeString object.
2296 * @param start the offset of the first character to remove
2297 * @param length the number of characters to remove
2298 * @return a reference to this
2301 inline UnicodeString
& remove(int32_t start
,
2302 int32_t length
= (int32_t)INT32_MAX
);
2305 * Remove the characters in the range
2306 * [<TT>start</TT>, <TT>limit</TT>) from the UnicodeString object.
2307 * @param start the offset of the first character to remove
2308 * @param limit the offset immediately following the range to remove
2309 * @return a reference to this
2312 inline UnicodeString
& removeBetween(int32_t start
,
2313 int32_t limit
= (int32_t)INT32_MAX
);
2316 /* Length operations */
2319 * Pad the start of this UnicodeString with the character <TT>padChar</TT>.
2320 * If the length of this UnicodeString is less than targetLength,
2321 * length() - targetLength copies of padChar will be added to the
2322 * beginning of this UnicodeString.
2323 * @param targetLength the desired length of the string
2324 * @param padChar the character to use for padding. Defaults to
2326 * @return TRUE if the text was padded, FALSE otherwise.
2329 UBool
padLeading(int32_t targetLength
,
2330 UChar padChar
= 0x0020);
2333 * Pad the end of this UnicodeString with the character <TT>padChar</TT>.
2334 * If the length of this UnicodeString is less than targetLength,
2335 * length() - targetLength copies of padChar will be added to the
2336 * end of this UnicodeString.
2337 * @param targetLength the desired length of the string
2338 * @param padChar the character to use for padding. Defaults to
2340 * @return TRUE if the text was padded, FALSE otherwise.
2343 UBool
padTrailing(int32_t targetLength
,
2344 UChar padChar
= 0x0020);
2347 * Truncate this UnicodeString to the <TT>targetLength</TT>.
2348 * @param targetLength the desired length of this UnicodeString.
2349 * @return TRUE if the text was truncated, FALSE otherwise
2352 inline UBool
truncate(int32_t targetLength
);
2355 * Trims leading and trailing whitespace from this UnicodeString.
2356 * @return a reference to this
2359 UnicodeString
& trim(void);
2362 /* Miscellaneous operations */
2365 * Reverse this UnicodeString in place.
2366 * @return a reference to this
2369 inline UnicodeString
& reverse(void);
2372 * Reverse the range [<TT>start</TT>, <TT>start + length</TT>) in
2373 * this UnicodeString.
2374 * @param start the start of the range to reverse
2375 * @param length the number of characters to to reverse
2376 * @return a reference to this
2379 inline UnicodeString
& reverse(int32_t start
,
2383 * Convert the characters in this to UPPER CASE following the conventions of
2384 * the default locale.
2385 * @return A reference to this.
2388 UnicodeString
& toUpper(void);
2391 * Convert the characters in this to UPPER CASE following the conventions of
2392 * a specific locale.
2393 * @param locale The locale containing the conventions to use.
2394 * @return A reference to this.
2397 UnicodeString
& toUpper(const Locale
& locale
);
2400 * Convert the characters in this to lower case following the conventions of
2401 * the default locale.
2402 * @return A reference to this.
2405 UnicodeString
& toLower(void);
2408 * Convert the characters in this to lower case following the conventions of
2409 * a specific locale.
2410 * @param locale The locale containing the conventions to use.
2411 * @return A reference to this.
2414 UnicodeString
& toLower(const Locale
& locale
);
2416 #if !UCONFIG_NO_BREAK_ITERATION
2419 * Titlecase this string, convenience function using the default locale.
2421 * Casing is locale-dependent and context-sensitive.
2422 * Titlecasing uses a break iterator to find the first characters of words
2423 * that are to be titlecased. It titlecases those characters and lowercases
2426 * The titlecase break iterator can be provided to customize for arbitrary
2427 * styles, using rules and dictionaries beyond the standard iterators.
2428 * It may be more efficient to always provide an iterator to avoid
2429 * opening and closing one for each string.
2430 * The standard titlecase iterator for the root locale implements the
2431 * algorithm of Unicode TR 21.
2433 * This function uses only the setText(), first() and next() methods of the
2434 * provided break iterator.
2436 * @param titleIter A break iterator to find the first characters of words
2437 * that are to be titlecased.
2438 * If none is provided (0), then a standard titlecase
2439 * break iterator is opened.
2440 * Otherwise the provided iterator is set to the string's text.
2441 * @return A reference to this.
2444 UnicodeString
&toTitle(BreakIterator
*titleIter
);
2447 * Titlecase this string.
2449 * Casing is locale-dependent and context-sensitive.
2450 * Titlecasing uses a break iterator to find the first characters of words
2451 * that are to be titlecased. It titlecases those characters and lowercases
2454 * The titlecase break iterator can be provided to customize for arbitrary
2455 * styles, using rules and dictionaries beyond the standard iterators.
2456 * It may be more efficient to always provide an iterator to avoid
2457 * opening and closing one for each string.
2458 * The standard titlecase iterator for the root locale implements the
2459 * algorithm of Unicode TR 21.
2461 * This function uses only the setText(), first() and next() methods of the
2462 * provided break iterator.
2464 * @param titleIter A break iterator to find the first characters of words
2465 * that are to be titlecased.
2466 * If none is provided (0), then a standard titlecase
2467 * break iterator is opened.
2468 * Otherwise the provided iterator is set to the string's text.
2469 * @param locale The locale to consider.
2470 * @return A reference to this.
2473 UnicodeString
&toTitle(BreakIterator
*titleIter
, const Locale
&locale
);
2476 * Titlecase this string, with options.
2478 * Casing is locale-dependent and context-sensitive.
2479 * Titlecasing uses a break iterator to find the first characters of words
2480 * that are to be titlecased. It titlecases those characters and lowercases
2481 * all others. (This can be modified with options.)
2483 * The titlecase break iterator can be provided to customize for arbitrary
2484 * styles, using rules and dictionaries beyond the standard iterators.
2485 * It may be more efficient to always provide an iterator to avoid
2486 * opening and closing one for each string.
2487 * The standard titlecase iterator for the root locale implements the
2488 * algorithm of Unicode TR 21.
2490 * This function uses only the setText(), first() and next() methods of the
2491 * provided break iterator.
2493 * @param titleIter A break iterator to find the first characters of words
2494 * that are to be titlecased.
2495 * If none is provided (0), then a standard titlecase
2496 * break iterator is opened.
2497 * Otherwise the provided iterator is set to the string's text.
2498 * @param locale The locale to consider.
2499 * @param options Options bit set, see ucasemap_open().
2500 * @return A reference to this.
2501 * @see U_TITLECASE_NO_LOWERCASE
2502 * @see U_TITLECASE_NO_BREAK_ADJUSTMENT
2503 * @see ucasemap_open
2506 UnicodeString
&toTitle(BreakIterator
*titleIter
, const Locale
&locale
, uint32_t options
);
2511 * Case-fold the characters in this string.
2512 * Case-folding is locale-independent and not context-sensitive,
2513 * but there is an option for whether to include or exclude mappings for dotted I
2514 * and dotless i that are marked with 'I' in CaseFolding.txt.
2515 * The result may be longer or shorter than the original.
2517 * @param options Either U_FOLD_CASE_DEFAULT or U_FOLD_CASE_EXCLUDE_SPECIAL_I
2518 * @return A reference to this.
2521 UnicodeString
&foldCase(uint32_t options
=0 /*U_FOLD_CASE_DEFAULT*/);
2523 //========================================
2524 // Access to the internal buffer
2525 //========================================
2528 * Get a read/write pointer to the internal buffer.
2529 * The buffer is guaranteed to be large enough for at least minCapacity UChars,
2530 * writable, and is still owned by the UnicodeString object.
2531 * Calls to getBuffer(minCapacity) must not be nested, and
2532 * must be matched with calls to releaseBuffer(newLength).
2533 * If the string buffer was read-only or shared,
2534 * then it will be reallocated and copied.
2536 * An attempted nested call will return 0, and will not further modify the
2537 * state of the UnicodeString object.
2538 * It also returns 0 if the string is bogus.
2540 * The actual capacity of the string buffer may be larger than minCapacity.
2541 * getCapacity() returns the actual capacity.
2542 * For many operations, the full capacity should be used to avoid reallocations.
2544 * While the buffer is "open" between getBuffer(minCapacity)
2545 * and releaseBuffer(newLength), the following applies:
2546 * - The string length is set to 0.
2547 * - Any read API call on the UnicodeString object will behave like on a 0-length string.
2548 * - Any write API call on the UnicodeString object is disallowed and will have no effect.
2549 * - You can read from and write to the returned buffer.
2550 * - The previous string contents will still be in the buffer;
2551 * if you want to use it, then you need to call length() before getBuffer(minCapacity).
2552 * If the length() was greater than minCapacity, then any contents after minCapacity
2554 * The buffer contents is not NUL-terminated by getBuffer().
2555 * If length()<getCapacity() then you can terminate it by writing a NUL
2556 * at index length().
2557 * - You must call releaseBuffer(newLength) before and in order to
2558 * return to normal UnicodeString operation.
2560 * @param minCapacity the minimum number of UChars that are to be available
2561 * in the buffer, starting at the returned pointer;
2562 * default to the current string capacity if minCapacity==-1
2563 * @return a writable pointer to the internal string buffer,
2564 * or 0 if an error occurs (nested calls, out of memory)
2566 * @see releaseBuffer
2567 * @see getTerminatedBuffer()
2570 UChar
*getBuffer(int32_t minCapacity
);
2573 * Release a read/write buffer on a UnicodeString object with an
2574 * "open" getBuffer(minCapacity).
2575 * This function must be called in a matched pair with getBuffer(minCapacity).
2576 * releaseBuffer(newLength) must be called if and only if a getBuffer(minCapacity) is "open".
2578 * It will set the string length to newLength, at most to the current capacity.
2579 * If newLength==-1 then it will set the length according to the
2580 * first NUL in the buffer, or to the capacity if there is no NUL.
2582 * After calling releaseBuffer(newLength) the UnicodeString is back to normal operation.
2584 * @param newLength the new length of the UnicodeString object;
2585 * defaults to the current capacity if newLength is greater than that;
2586 * if newLength==-1, it defaults to u_strlen(buffer) but not more than
2587 * the current capacity of the string
2589 * @see getBuffer(int32_t minCapacity)
2592 void releaseBuffer(int32_t newLength
=-1);
2595 * Get a read-only pointer to the internal buffer.
2596 * This can be called at any time on a valid UnicodeString.
2598 * It returns 0 if the string is bogus, or
2599 * during an "open" getBuffer(minCapacity).
2601 * It can be called as many times as desired.
2602 * The pointer that it returns will remain valid until the UnicodeString object is modified,
2603 * at which time the pointer is semantically invalidated and must not be used any more.
2605 * The capacity of the buffer can be determined with getCapacity().
2606 * The part after length() may or may not be initialized and valid,
2607 * depending on the history of the UnicodeString object.
2609 * The buffer contents is (probably) not NUL-terminated.
2610 * You can check if it is with
2611 * <code>(s.length()<s.getCapacity() && buffer[s.length()]==0)</code>.
2612 * (See getTerminatedBuffer().)
2614 * The buffer may reside in read-only memory. Its contents must not
2617 * @return a read-only pointer to the internal string buffer,
2618 * or 0 if the string is empty or bogus
2620 * @see getBuffer(int32_t minCapacity)
2621 * @see getTerminatedBuffer()
2624 inline const UChar
*getBuffer() const;
2627 * Get a read-only pointer to the internal buffer,
2628 * making sure that it is NUL-terminated.
2629 * This can be called at any time on a valid UnicodeString.
2631 * It returns 0 if the string is bogus, or
2632 * during an "open" getBuffer(minCapacity), or if the buffer cannot
2633 * be NUL-terminated (because memory allocation failed).
2635 * It can be called as many times as desired.
2636 * The pointer that it returns will remain valid until the UnicodeString object is modified,
2637 * at which time the pointer is semantically invalidated and must not be used any more.
2639 * The capacity of the buffer can be determined with getCapacity().
2640 * The part after length()+1 may or may not be initialized and valid,
2641 * depending on the history of the UnicodeString object.
2643 * The buffer contents is guaranteed to be NUL-terminated.
2644 * getTerminatedBuffer() may reallocate the buffer if a terminating NUL
2646 * For this reason, this function is not const, unlike getBuffer().
2647 * Note that a UnicodeString may also contain NUL characters as part of its contents.
2649 * The buffer may reside in read-only memory. Its contents must not
2652 * @return a read-only pointer to the internal string buffer,
2653 * or 0 if the string is empty or bogus
2655 * @see getBuffer(int32_t minCapacity)
2659 inline const UChar
*getTerminatedBuffer();
2661 //========================================
2663 //========================================
2665 /** Construct an empty UnicodeString.
2671 * Construct a UnicodeString with capacity to hold <TT>capacity</TT> UChars
2672 * @param capacity the number of UChars this UnicodeString should hold
2673 * before a resize is necessary; if count is greater than 0 and count
2674 * code points c take up more space than capacity, then capacity is adjusted
2676 * @param c is used to initially fill the string
2677 * @param count specifies how many code points c are to be written in the
2681 UnicodeString(int32_t capacity
, UChar32 c
, int32_t count
);
2684 * Single UChar (code unit) constructor.
2685 * @param ch the character to place in the UnicodeString
2688 UnicodeString(UChar ch
);
2691 * Single UChar32 (code point) constructor.
2692 * @param ch the character to place in the UnicodeString
2695 UnicodeString(UChar32 ch
);
2698 * UChar* constructor.
2699 * @param text The characters to place in the UnicodeString. <TT>text</TT>
2700 * must be NULL (U+0000) terminated.
2703 UnicodeString(const UChar
*text
);
2706 * UChar* constructor.
2707 * @param text The characters to place in the UnicodeString.
2708 * @param textLength The number of Unicode characters in <TT>text</TT>
2712 UnicodeString(const UChar
*text
,
2713 int32_t textLength
);
2716 * Readonly-aliasing UChar* constructor.
2717 * The text will be used for the UnicodeString object, but
2718 * it will not be released when the UnicodeString is destroyed.
2719 * This has copy-on-write semantics:
2720 * When the string is modified, then the buffer is first copied into
2721 * newly allocated memory.
2722 * The aliased buffer is never modified.
2723 * In an assignment to another UnicodeString, the text will be aliased again,
2724 * so that both strings then alias the same readonly-text.
2726 * @param isTerminated specifies if <code>text</code> is <code>NUL</code>-terminated.
2727 * This must be true if <code>textLength==-1</code>.
2728 * @param text The characters to alias for the UnicodeString.
2729 * @param textLength The number of Unicode characters in <code>text</code> to alias.
2730 * If -1, then this constructor will determine the length
2731 * by calling <code>u_strlen()</code>.
2734 UnicodeString(UBool isTerminated
,
2736 int32_t textLength
);
2739 * Writable-aliasing UChar* constructor.
2740 * The text will be used for the UnicodeString object, but
2741 * it will not be released when the UnicodeString is destroyed.
2742 * This has write-through semantics:
2743 * For as long as the capacity of the buffer is sufficient, write operations
2744 * will directly affect the buffer. When more capacity is necessary, then
2745 * a new buffer will be allocated and the contents copied as with regularly
2746 * constructed strings.
2747 * In an assignment to another UnicodeString, the buffer will be copied.
2748 * The extract(UChar *dst) function detects whether the dst pointer is the same
2749 * as the string buffer itself and will in this case not copy the contents.
2751 * @param buffer The characters to alias for the UnicodeString.
2752 * @param buffLength The number of Unicode characters in <code>buffer</code> to alias.
2753 * @param buffCapacity The size of <code>buffer</code> in UChars.
2756 UnicodeString(UChar
*buffer
, int32_t buffLength
, int32_t buffCapacity
);
2758 #if !UCONFIG_NO_CONVERSION
2761 * char* constructor.
2762 * @param codepageData an array of bytes, null-terminated
2763 * @param codepage the encoding of <TT>codepageData</TT>. The special
2764 * value 0 for <TT>codepage</TT> indicates that the text is in the
2765 * platform's default codepage.
2767 * If <code>codepage</code> is an empty string (<code>""</code>),
2768 * then a simple conversion is performed on the codepage-invariant
2769 * subset ("invariant characters") of the platform encoding. See utypes.h.
2770 * Recommendation: For invariant-character strings use the constructor
2771 * UnicodeString(const char *src, int32_t length, enum EInvariant inv)
2772 * because it avoids object code dependencies of UnicodeString on
2773 * the conversion code.
2777 UnicodeString(const char *codepageData
,
2778 const char *codepage
= 0);
2781 * char* constructor.
2782 * @param codepageData an array of bytes.
2783 * @param dataLength The number of bytes in <TT>codepageData</TT>.
2784 * @param codepage the encoding of <TT>codepageData</TT>. The special
2785 * value 0 for <TT>codepage</TT> indicates that the text is in the
2786 * platform's default codepage.
2787 * If <code>codepage</code> is an empty string (<code>""</code>),
2788 * then a simple conversion is performed on the codepage-invariant
2789 * subset ("invariant characters") of the platform encoding. See utypes.h.
2790 * Recommendation: For invariant-character strings use the constructor
2791 * UnicodeString(const char *src, int32_t length, enum EInvariant inv)
2792 * because it avoids object code dependencies of UnicodeString on
2793 * the conversion code.
2797 UnicodeString(const char *codepageData
,
2799 const char *codepage
= 0);
2802 * char * / UConverter constructor.
2803 * This constructor uses an existing UConverter object to
2804 * convert the codepage string to Unicode and construct a UnicodeString
2807 * The converter is reset at first.
2808 * If the error code indicates a failure before this constructor is called,
2809 * or if an error occurs during conversion or construction,
2810 * then the string will be bogus.
2812 * This function avoids the overhead of opening and closing a converter if
2813 * multiple strings are constructed.
2815 * @param src input codepage string
2816 * @param srcLength length of the input string, can be -1 for NUL-terminated strings
2817 * @param cnv converter object (ucnv_resetToUnicode() will be called),
2818 * can be NULL for the default converter
2819 * @param errorCode normal ICU error code
2823 const char *src
, int32_t srcLength
,
2825 UErrorCode
&errorCode
);
2830 * Constructs a Unicode string from an invariant-character char * string.
2831 * About invariant characters see utypes.h.
2832 * This constructor has no runtime dependency on conversion code and is
2833 * therefore recommended over ones taking a charset name string
2834 * (where the empty string "" indicates invariant-character conversion).
2836 * Use the macro US_INV as the third, signature-distinguishing parameter.
2840 * void fn(const char *s) {
2841 * UnicodeString ustr(s, -1, US_INV);
2846 * @param src String using only invariant characters.
2847 * @param length Length of src, or -1 if NUL-terminated.
2848 * @param inv Signature-distinguishing paramater, use US_INV.
2853 UnicodeString(const char *src
, int32_t length
, enum EInvariant inv
);
2858 * @param that The UnicodeString object to copy.
2861 UnicodeString(const UnicodeString
& that
);
2864 * 'Substring' constructor from tail of source string.
2865 * @param src The UnicodeString object to copy.
2866 * @param srcStart The offset into <tt>src</tt> at which to start copying.
2869 UnicodeString(const UnicodeString
& src
, int32_t srcStart
);
2872 * 'Substring' constructor from subrange of source string.
2873 * @param src The UnicodeString object to copy.
2874 * @param srcStart The offset into <tt>src</tt> at which to start copying.
2875 * @param srcLength The number of characters from <tt>src</tt> to copy.
2878 UnicodeString(const UnicodeString
& src
, int32_t srcStart
, int32_t srcLength
);
2881 * Clone this object, an instance of a subclass of Replaceable.
2882 * Clones can be used concurrently in multiple threads.
2883 * If a subclass does not implement clone(), or if an error occurs,
2884 * then NULL is returned.
2885 * The clone functions in all subclasses return a pointer to a Replaceable
2886 * because some compilers do not support covariant (same-as-this)
2887 * return types; cast to the appropriate subclass if necessary.
2888 * The caller must delete the clone.
2890 * @return a clone of this object
2892 * @see Replaceable::clone
2893 * @see getDynamicClassID
2896 virtual Replaceable
*clone() const;
2901 virtual ~UnicodeString();
2904 /* Miscellaneous operations */
2907 * Unescape a string of characters and return a string containing
2908 * the result. The following escape sequences are recognized:
2910 * \\uhhhh 4 hex digits; h in [0-9A-Fa-f]
2911 * \\Uhhhhhhhh 8 hex digits
2912 * \\xhh 1-2 hex digits
2913 * \\ooo 1-3 octal digits; o in [0-7]
2914 * \\cX control-X; X is masked with 0x1F
2916 * as well as the standard ANSI C escapes:
2918 * \\a => U+0007, \\b => U+0008, \\t => U+0009, \\n => U+000A,
2919 * \\v => U+000B, \\f => U+000C, \\r => U+000D, \\e => U+001B,
2920 * \\" => U+0022, \\' => U+0027, \\? => U+003F, \\\\ => U+005C
2922 * Anything else following a backslash is generically escaped. For
2923 * example, "[a\\-z]" returns "[a-z]".
2925 * If an escape sequence is ill-formed, this method returns an empty
2926 * string. An example of an ill-formed sequence is "\\u" followed by
2927 * fewer than 4 hex digits.
2929 * This function is similar to u_unescape() but not identical to it.
2930 * The latter takes a source char*, so it does escape recognition
2931 * and also invariant conversion.
2933 * @return a string with backslash escapes interpreted, or an
2934 * empty string on error.
2935 * @see UnicodeString#unescapeAt()
2937 * @see u_unescapeAt()
2940 UnicodeString
unescape() const;
2943 * Unescape a single escape sequence and return the represented
2944 * character. See unescape() for a listing of the recognized escape
2945 * sequences. The character at offset-1 is assumed (without
2946 * checking) to be a backslash. If the escape sequence is
2947 * ill-formed, or the offset is out of range, (UChar32)0xFFFFFFFF is
2950 * @param offset an input output parameter. On input, it is the
2951 * offset into this string where the escape sequence is located,
2952 * after the initial backslash. On output, it is advanced after the
2953 * last character parsed. On error, it is not advanced at all.
2954 * @return the character represented by the escape sequence at
2955 * offset, or (UChar32)0xFFFFFFFF on error.
2956 * @see UnicodeString#unescape()
2958 * @see u_unescapeAt()
2961 UChar32
unescapeAt(int32_t &offset
) const;
2964 * ICU "poor man's RTTI", returns a UClassID for this class.
2968 static UClassID U_EXPORT2
getStaticClassID();
2971 * ICU "poor man's RTTI", returns a UClassID for the actual class.
2975 virtual UClassID
getDynamicClassID() const;
2977 //========================================
2978 // Implementation methods
2979 //========================================
2983 * Implement Replaceable::getLength() (see jitterbug 1027).
2986 virtual int32_t getLength() const;
2989 * The change in Replaceable to use virtual getCharAt() allows
2990 * UnicodeString::charAt() to be inline again (see jitterbug 709).
2993 virtual UChar
getCharAt(int32_t offset
) const;
2996 * The change in Replaceable to use virtual getChar32At() allows
2997 * UnicodeString::char32At() to be inline again (see jitterbug 709).
3000 virtual UChar32
getChar32At(int32_t offset
) const;
3005 doCompare(int32_t start
,
3007 const UnicodeString
& srcText
,
3009 int32_t srcLength
) const;
3011 int8_t doCompare(int32_t start
,
3013 const UChar
*srcChars
,
3015 int32_t srcLength
) const;
3018 doCompareCodePointOrder(int32_t start
,
3020 const UnicodeString
& srcText
,
3022 int32_t srcLength
) const;
3024 int8_t doCompareCodePointOrder(int32_t start
,
3026 const UChar
*srcChars
,
3028 int32_t srcLength
) const;
3031 doCaseCompare(int32_t start
,
3033 const UnicodeString
&srcText
,
3036 uint32_t options
) const;
3039 doCaseCompare(int32_t start
,
3041 const UChar
*srcChars
,
3044 uint32_t options
) const;
3046 int32_t doIndexOf(UChar c
,
3048 int32_t length
) const;
3050 int32_t doIndexOf(UChar32 c
,
3052 int32_t length
) const;
3054 int32_t doLastIndexOf(UChar c
,
3056 int32_t length
) const;
3058 int32_t doLastIndexOf(UChar32 c
,
3060 int32_t length
) const;
3062 void doExtract(int32_t start
,
3065 int32_t dstStart
) const;
3067 inline void doExtract(int32_t start
,
3069 UnicodeString
& target
) const;
3071 inline UChar
doCharAt(int32_t offset
) const;
3073 UnicodeString
& doReplace(int32_t start
,
3075 const UnicodeString
& srcText
,
3079 UnicodeString
& doReplace(int32_t start
,
3081 const UChar
*srcChars
,
3085 UnicodeString
& doReverse(int32_t start
,
3088 // calculate hash code
3089 int32_t doHashCode(void) const;
3091 // get pointer to start of array
3092 // these do not check for kOpenGetBuffer, unlike the public getBuffer() function
3093 inline UChar
* getArrayStart(void);
3094 inline const UChar
* getArrayStart(void) const;
3096 // A UnicodeString object (not necessarily its current buffer)
3097 // is writable unless it isBogus() or it has an "open" getBuffer(minCapacity).
3098 inline UBool
isWritable() const;
3100 // Is the current buffer writable?
3101 inline UBool
isBufferWritable() const;
3103 // None of the following does releaseArray().
3104 inline void setLength(int32_t len
); // sets only fShortLength and fLength
3105 inline void setToEmpty(); // sets fFlags=kShortString
3106 inline void setToStackBuffer(int32_t len
); // sets fFlags=kShortString
3107 inline void setArray(UChar
*array
, int32_t len
, int32_t capacity
); // does not set fFlags
3109 // allocate the array; result may be fStackBuffer
3110 // sets refCount to 1 if appropriate
3111 // sets fArray, fCapacity, and fFlags
3112 // returns boolean for success or failure
3113 UBool
allocate(int32_t capacity
);
3115 // release the array if owned
3116 void releaseArray(void);
3118 // turn a bogus string into an empty one
3121 // implements assigment operator, copy constructor, and fastCopyFrom()
3122 UnicodeString
©From(const UnicodeString
&src
, UBool fastCopy
=FALSE
);
3124 // Pin start and limit to acceptable values.
3125 inline void pinIndex(int32_t& start
) const;
3126 inline void pinIndices(int32_t& start
,
3127 int32_t& length
) const;
3129 #if !UCONFIG_NO_CONVERSION
3131 /* Internal extract() using UConverter. */
3132 int32_t doExtract(int32_t start
, int32_t length
,
3133 char *dest
, int32_t destCapacity
,
3135 UErrorCode
&errorCode
) const;
3138 * Real constructor for converting from codepage data.
3139 * It assumes that it is called with !fRefCounted.
3141 * If <code>codepage==0</code>, then the default converter
3142 * is used for the platform encoding.
3143 * If <code>codepage</code> is an empty string (<code>""</code>),
3144 * then a simple conversion is performed on the codepage-invariant
3145 * subset ("invariant characters") of the platform encoding. See utypes.h.
3147 void doCodepageCreate(const char *codepageData
,
3149 const char *codepage
);
3152 * Worker function for creating a UnicodeString from
3153 * a codepage string using a UConverter.
3156 doCodepageCreate(const char *codepageData
,
3158 UConverter
*converter
,
3159 UErrorCode
&status
);
3164 * This function is called when write access to the array
3167 * We need to make a copy of the array if
3168 * the buffer is read-only, or
3169 * the buffer is refCounted (shared), and refCount>1, or
3170 * the buffer is too small.
3172 * Return FALSE if memory could not be allocated.
3174 UBool
cloneArrayIfNeeded(int32_t newCapacity
= -1,
3175 int32_t growCapacity
= -1,
3176 UBool doCopyArray
= TRUE
,
3177 int32_t **pBufferToDelete
= 0,
3178 UBool forceClone
= FALSE
);
3180 // common function for case mappings
3182 caseMap(BreakIterator
*titleIter
,
3185 int32_t toWhichCase
);
3189 int32_t removeRef(void);
3190 int32_t refCount(void) const;
3194 // Set the stack buffer size so that sizeof(UnicodeString) is a multiple of sizeof(pointer):
3195 // 32-bit pointers: 4+1+1+13*2 = 32 bytes
3196 // 64-bit pointers: 8+1+1+15*2 = 40 bytes
3197 US_STACKBUF_SIZE
= sizeof(void *)==4 ? 13 : 15, // Size of stack buffer for small strings
3198 kInvalidUChar
=0xffff, // invalid UChar index
3199 kGrowSize
=128, // grow size for this buffer
3200 kInvalidHashCode
=0, // invalid hash code
3201 kEmptyHashCode
=1, // hash code for empty string
3203 // bit flag values for fFlags
3204 kIsBogus
=1, // this string is bogus, i.e., not valid or NULL
3205 kUsingStackBuffer
=2,// fArray==fStackBuffer
3206 kRefCounted
=4, // there is a refCount field before the characters in fArray
3207 kBufferIsReadonly
=8,// do not write to this buffer
3208 kOpenGetBuffer
=16, // getBuffer(minCapacity) was called (is "open"),
3209 // and releaseBuffer(newLength) must be called
3211 // combined values for convenience
3212 kShortString
=kUsingStackBuffer
,
3213 kLongString
=kRefCounted
,
3214 kReadonlyAlias
=kBufferIsReadonly
,
3218 friend class StringThreadTest
;
3220 union StackBufferOrFields
; // forward declaration necessary before friend declaration
3221 friend union StackBufferOrFields
; // make US_STACKBUF_SIZE visible inside fUnion
3224 * The following are all the class fields that are stored
3225 * in each UnicodeString object.
3226 * Note that UnicodeString has virtual functions,
3227 * therefore there is an implicit vtable pointer
3228 * as the first real field.
3229 * The fields should be aligned such that no padding is
3230 * necessary, mostly by having larger types first.
3231 * On 32-bit machines, the size should be 32 bytes,
3232 * on 64-bit machines (8-byte pointers), it should be 40 bytes.
3234 // (implicit) *vtable;
3235 int8_t fShortLength
; // 0..127: length <0: real length is in fUnion.fFields.fLength
3236 uint8_t fFlags
; // bit flags: see constants above
3237 union StackBufferOrFields
{
3238 // fStackBuffer is used iff (fFlags&kUsingStackBuffer)
3239 // else fFields is used
3240 UChar fStackBuffer
[US_STACKBUF_SIZE
]; // buffer for small strings
3242 uint16_t fPadding
; // align the following field at 8B (32b pointers) or 12B (64b)
3243 int32_t fLength
; // number of characters in fArray if >127; else undefined
3244 UChar
*fArray
; // the Unicode data (aligned at 12B (32b pointers) or 16B (64b))
3245 int32_t fCapacity
; // sizeof fArray
3251 * Create a new UnicodeString with the concatenation of two others.
3253 * @param s1 The first string to be copied to the new one.
3254 * @param s2 The second string to be copied to the new one, after s1.
3255 * @return UnicodeString(s1).append(s2)
3258 U_COMMON_API UnicodeString U_EXPORT2
3259 operator+ (const UnicodeString
&s1
, const UnicodeString
&s2
);
3261 //========================================
3263 //========================================
3265 //========================================
3267 //========================================
3270 UnicodeString::pinIndex(int32_t& start
) const
3275 } else if(start
> length()) {
3281 UnicodeString::pinIndices(int32_t& start
,
3282 int32_t& _length
) const
3285 int32_t len
= length();
3288 } else if(start
> len
) {
3293 } else if(_length
> (len
- start
)) {
3294 _length
= (len
- start
);
3299 UnicodeString::getArrayStart()
3300 { return (fFlags
&kUsingStackBuffer
) ? fUnion
.fStackBuffer
: fUnion
.fFields
.fArray
; }
3303 UnicodeString::getArrayStart() const
3304 { return (fFlags
&kUsingStackBuffer
) ? fUnion
.fStackBuffer
: fUnion
.fFields
.fArray
; }
3306 //========================================
3307 // Read-only implementation methods
3308 //========================================
3310 UnicodeString::length() const
3311 { return fShortLength
>=0 ? fShortLength
: fUnion
.fFields
.fLength
; }
3314 UnicodeString::getCapacity() const
3315 { return (fFlags
&kUsingStackBuffer
) ? US_STACKBUF_SIZE
: fUnion
.fFields
.fCapacity
; }
3318 UnicodeString::hashCode() const
3319 { return doHashCode(); }
3322 UnicodeString::isBogus() const
3323 { return (UBool
)(fFlags
& kIsBogus
); }
3326 UnicodeString::isWritable() const
3327 { return (UBool
)!(fFlags
&(kOpenGetBuffer
|kIsBogus
)); }
3330 UnicodeString::isBufferWritable() const
3333 !(fFlags
&(kOpenGetBuffer
|kIsBogus
|kBufferIsReadonly
)) &&
3334 (!(fFlags
&kRefCounted
) || refCount()==1));
3337 inline const UChar
*
3338 UnicodeString::getBuffer() const {
3339 if(fFlags
&(kIsBogus
|kOpenGetBuffer
)) {
3341 } else if(fFlags
&kUsingStackBuffer
) {
3342 return fUnion
.fStackBuffer
;
3344 return fUnion
.fFields
.fArray
;
3348 //========================================
3349 // Read-only alias methods
3350 //========================================
3352 UnicodeString::doCompare(int32_t start
,
3354 const UnicodeString
& srcText
,
3356 int32_t srcLength
) const
3358 if(srcText
.isBogus()) {
3359 return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
3361 srcText
.pinIndices(srcStart
, srcLength
);
3362 return doCompare(start
, thisLength
, srcText
.getArrayStart(), srcStart
, srcLength
);
3367 UnicodeString::operator== (const UnicodeString
& text
) const
3370 return text
.isBogus();
3372 int32_t len
= length(), textLength
= text
.length();
3375 len
== textLength
&&
3376 doCompare(0, len
, text
, 0, textLength
) == 0;
3381 UnicodeString::operator!= (const UnicodeString
& text
) const
3382 { return (! operator==(text
)); }
3385 UnicodeString::operator> (const UnicodeString
& text
) const
3386 { return doCompare(0, length(), text
, 0, text
.length()) == 1; }
3389 UnicodeString::operator< (const UnicodeString
& text
) const
3390 { return doCompare(0, length(), text
, 0, text
.length()) == -1; }
3393 UnicodeString::operator>= (const UnicodeString
& text
) const
3394 { return doCompare(0, length(), text
, 0, text
.length()) != -1; }
3397 UnicodeString::operator<= (const UnicodeString
& text
) const
3398 { return doCompare(0, length(), text
, 0, text
.length()) != 1; }
3401 UnicodeString::compare(const UnicodeString
& text
) const
3402 { return doCompare(0, length(), text
, 0, text
.length()); }
3405 UnicodeString::compare(int32_t start
,
3407 const UnicodeString
& srcText
) const
3408 { return doCompare(start
, _length
, srcText
, 0, srcText
.length()); }
3411 UnicodeString::compare(const UChar
*srcChars
,
3412 int32_t srcLength
) const
3413 { return doCompare(0, length(), srcChars
, 0, srcLength
); }
3416 UnicodeString::compare(int32_t start
,
3418 const UnicodeString
& srcText
,
3420 int32_t srcLength
) const
3421 { return doCompare(start
, _length
, srcText
, srcStart
, srcLength
); }
3424 UnicodeString::compare(int32_t start
,
3426 const UChar
*srcChars
) const
3427 { return doCompare(start
, _length
, srcChars
, 0, _length
); }
3430 UnicodeString::compare(int32_t start
,
3432 const UChar
*srcChars
,
3434 int32_t srcLength
) const
3435 { return doCompare(start
, _length
, srcChars
, srcStart
, srcLength
); }
3438 UnicodeString::compareBetween(int32_t start
,
3440 const UnicodeString
& srcText
,
3442 int32_t srcLimit
) const
3443 { return doCompare(start
, limit
- start
,
3444 srcText
, srcStart
, srcLimit
- srcStart
); }
3447 UnicodeString::doCompareCodePointOrder(int32_t start
,
3449 const UnicodeString
& srcText
,
3451 int32_t srcLength
) const
3453 if(srcText
.isBogus()) {
3454 return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
3456 srcText
.pinIndices(srcStart
, srcLength
);
3457 return doCompareCodePointOrder(start
, thisLength
, srcText
.getArrayStart(), srcStart
, srcLength
);
3462 UnicodeString::compareCodePointOrder(const UnicodeString
& text
) const
3463 { return doCompareCodePointOrder(0, length(), text
, 0, text
.length()); }
3466 UnicodeString::compareCodePointOrder(int32_t start
,
3468 const UnicodeString
& srcText
) const
3469 { return doCompareCodePointOrder(start
, _length
, srcText
, 0, srcText
.length()); }
3472 UnicodeString::compareCodePointOrder(const UChar
*srcChars
,
3473 int32_t srcLength
) const
3474 { return doCompareCodePointOrder(0, length(), srcChars
, 0, srcLength
); }
3477 UnicodeString::compareCodePointOrder(int32_t start
,
3479 const UnicodeString
& srcText
,
3481 int32_t srcLength
) const
3482 { return doCompareCodePointOrder(start
, _length
, srcText
, srcStart
, srcLength
); }
3485 UnicodeString::compareCodePointOrder(int32_t start
,
3487 const UChar
*srcChars
) const
3488 { return doCompareCodePointOrder(start
, _length
, srcChars
, 0, _length
); }
3491 UnicodeString::compareCodePointOrder(int32_t start
,
3493 const UChar
*srcChars
,
3495 int32_t srcLength
) const
3496 { return doCompareCodePointOrder(start
, _length
, srcChars
, srcStart
, srcLength
); }
3499 UnicodeString::compareCodePointOrderBetween(int32_t start
,
3501 const UnicodeString
& srcText
,
3503 int32_t srcLimit
) const
3504 { return doCompareCodePointOrder(start
, limit
- start
,
3505 srcText
, srcStart
, srcLimit
- srcStart
); }
3508 UnicodeString::doCaseCompare(int32_t start
,
3510 const UnicodeString
&srcText
,
3513 uint32_t options
) const
3515 if(srcText
.isBogus()) {
3516 return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
3518 srcText
.pinIndices(srcStart
, srcLength
);
3519 return doCaseCompare(start
, thisLength
, srcText
.getArrayStart(), srcStart
, srcLength
, options
);
3524 UnicodeString::caseCompare(const UnicodeString
&text
, uint32_t options
) const {
3525 return doCaseCompare(0, length(), text
, 0, text
.length(), options
);
3529 UnicodeString::caseCompare(int32_t start
,
3531 const UnicodeString
&srcText
,
3532 uint32_t options
) const {
3533 return doCaseCompare(start
, _length
, srcText
, 0, srcText
.length(), options
);
3537 UnicodeString::caseCompare(const UChar
*srcChars
,
3539 uint32_t options
) const {
3540 return doCaseCompare(0, length(), srcChars
, 0, srcLength
, options
);
3544 UnicodeString::caseCompare(int32_t start
,
3546 const UnicodeString
&srcText
,
3549 uint32_t options
) const {
3550 return doCaseCompare(start
, _length
, srcText
, srcStart
, srcLength
, options
);
3554 UnicodeString::caseCompare(int32_t start
,
3556 const UChar
*srcChars
,
3557 uint32_t options
) const {
3558 return doCaseCompare(start
, _length
, srcChars
, 0, _length
, options
);
3562 UnicodeString::caseCompare(int32_t start
,
3564 const UChar
*srcChars
,
3567 uint32_t options
) const {
3568 return doCaseCompare(start
, _length
, srcChars
, srcStart
, srcLength
, options
);
3572 UnicodeString::caseCompareBetween(int32_t start
,
3574 const UnicodeString
&srcText
,
3577 uint32_t options
) const {
3578 return doCaseCompare(start
, limit
- start
, srcText
, srcStart
, srcLimit
- srcStart
, options
);
3582 UnicodeString::indexOf(const UnicodeString
& srcText
,
3586 int32_t _length
) const
3588 if(!srcText
.isBogus()) {
3589 srcText
.pinIndices(srcStart
, srcLength
);
3591 return indexOf(srcText
.getArrayStart(), srcStart
, srcLength
, start
, _length
);
3598 UnicodeString::indexOf(const UnicodeString
& text
) const
3599 { return indexOf(text
, 0, text
.length(), 0, length()); }
3602 UnicodeString::indexOf(const UnicodeString
& text
,
3603 int32_t start
) const {
3605 return indexOf(text
, 0, text
.length(), start
, length() - start
);
3609 UnicodeString::indexOf(const UnicodeString
& text
,
3611 int32_t _length
) const
3612 { return indexOf(text
, 0, text
.length(), start
, _length
); }
3615 UnicodeString::indexOf(const UChar
*srcChars
,
3617 int32_t start
) const {
3619 return indexOf(srcChars
, 0, srcLength
, start
, length() - start
);
3623 UnicodeString::indexOf(const UChar
*srcChars
,
3626 int32_t _length
) const
3627 { return indexOf(srcChars
, 0, srcLength
, start
, _length
); }
3630 UnicodeString::indexOf(UChar c
,
3632 int32_t _length
) const
3633 { return doIndexOf(c
, start
, _length
); }
3636 UnicodeString::indexOf(UChar32 c
,
3638 int32_t _length
) const
3639 { return doIndexOf(c
, start
, _length
); }
3642 UnicodeString::indexOf(UChar c
) const
3643 { return doIndexOf(c
, 0, length()); }
3646 UnicodeString::indexOf(UChar32 c
) const
3647 { return indexOf(c
, 0, length()); }
3650 UnicodeString::indexOf(UChar c
,
3651 int32_t start
) const {
3653 return doIndexOf(c
, start
, length() - start
);
3657 UnicodeString::indexOf(UChar32 c
,
3658 int32_t start
) const {
3660 return indexOf(c
, start
, length() - start
);
3664 UnicodeString::lastIndexOf(const UChar
*srcChars
,
3667 int32_t _length
) const
3668 { return lastIndexOf(srcChars
, 0, srcLength
, start
, _length
); }
3671 UnicodeString::lastIndexOf(const UChar
*srcChars
,
3673 int32_t start
) const {
3675 return lastIndexOf(srcChars
, 0, srcLength
, start
, length() - start
);
3679 UnicodeString::lastIndexOf(const UnicodeString
& srcText
,
3683 int32_t _length
) const
3685 if(!srcText
.isBogus()) {
3686 srcText
.pinIndices(srcStart
, srcLength
);
3688 return lastIndexOf(srcText
.getArrayStart(), srcStart
, srcLength
, start
, _length
);
3695 UnicodeString::lastIndexOf(const UnicodeString
& text
,
3697 int32_t _length
) const
3698 { return lastIndexOf(text
, 0, text
.length(), start
, _length
); }
3701 UnicodeString::lastIndexOf(const UnicodeString
& text
,
3702 int32_t start
) const {
3704 return lastIndexOf(text
, 0, text
.length(), start
, length() - start
);
3708 UnicodeString::lastIndexOf(const UnicodeString
& text
) const
3709 { return lastIndexOf(text
, 0, text
.length(), 0, length()); }
3712 UnicodeString::lastIndexOf(UChar c
,
3714 int32_t _length
) const
3715 { return doLastIndexOf(c
, start
, _length
); }
3718 UnicodeString::lastIndexOf(UChar32 c
,
3720 int32_t _length
) const {
3721 return doLastIndexOf(c
, start
, _length
);
3725 UnicodeString::lastIndexOf(UChar c
) const
3726 { return doLastIndexOf(c
, 0, length()); }
3729 UnicodeString::lastIndexOf(UChar32 c
) const {
3730 return lastIndexOf(c
, 0, length());
3734 UnicodeString::lastIndexOf(UChar c
,
3735 int32_t start
) const {
3737 return doLastIndexOf(c
, start
, length() - start
);
3741 UnicodeString::lastIndexOf(UChar32 c
,
3742 int32_t start
) const {
3744 return lastIndexOf(c
, start
, length() - start
);
3748 UnicodeString::startsWith(const UnicodeString
& text
) const
3749 { return compare(0, text
.length(), text
, 0, text
.length()) == 0; }
3752 UnicodeString::startsWith(const UnicodeString
& srcText
,
3754 int32_t srcLength
) const
3755 { return doCompare(0, srcLength
, srcText
, srcStart
, srcLength
) == 0; }
3758 UnicodeString::startsWith(const UChar
*srcChars
,
3759 int32_t srcLength
) const
3760 { return doCompare(0, srcLength
, srcChars
, 0, srcLength
) == 0; }
3763 UnicodeString::startsWith(const UChar
*srcChars
,
3765 int32_t srcLength
) const
3766 { return doCompare(0, srcLength
, srcChars
, srcStart
, srcLength
) == 0;}
3769 UnicodeString::endsWith(const UnicodeString
& text
) const
3770 { return doCompare(length() - text
.length(), text
.length(),
3771 text
, 0, text
.length()) == 0; }
3774 UnicodeString::endsWith(const UnicodeString
& srcText
,
3776 int32_t srcLength
) const {
3777 srcText
.pinIndices(srcStart
, srcLength
);
3778 return doCompare(length() - srcLength
, srcLength
,
3779 srcText
, srcStart
, srcLength
) == 0;
3783 UnicodeString::endsWith(const UChar
*srcChars
,
3784 int32_t srcLength
) const {
3786 srcLength
= u_strlen(srcChars
);
3788 return doCompare(length() - srcLength
, srcLength
,
3789 srcChars
, 0, srcLength
) == 0;
3793 UnicodeString::endsWith(const UChar
*srcChars
,
3795 int32_t srcLength
) const {
3797 srcLength
= u_strlen(srcChars
+ srcStart
);
3799 return doCompare(length() - srcLength
, srcLength
,
3800 srcChars
, srcStart
, srcLength
) == 0;
3803 //========================================
3805 //========================================
3806 inline UnicodeString
&
3807 UnicodeString::replace(int32_t start
,
3809 const UnicodeString
& srcText
)
3810 { return doReplace(start
, _length
, srcText
, 0, srcText
.length()); }
3812 inline UnicodeString
&
3813 UnicodeString::replace(int32_t start
,
3815 const UnicodeString
& srcText
,
3818 { return doReplace(start
, _length
, srcText
, srcStart
, srcLength
); }
3820 inline UnicodeString
&
3821 UnicodeString::replace(int32_t start
,
3823 const UChar
*srcChars
,
3825 { return doReplace(start
, _length
, srcChars
, 0, srcLength
); }
3827 inline UnicodeString
&
3828 UnicodeString::replace(int32_t start
,
3830 const UChar
*srcChars
,
3833 { return doReplace(start
, _length
, srcChars
, srcStart
, srcLength
); }
3835 inline UnicodeString
&
3836 UnicodeString::replace(int32_t start
,
3839 { return doReplace(start
, _length
, &srcChar
, 0, 1); }
3841 inline UnicodeString
&
3842 UnicodeString::replace(int32_t start
,
3845 UChar buffer
[U16_MAX_LENGTH
];
3847 UBool isError
= FALSE
;
3848 U16_APPEND(buffer
, count
, U16_MAX_LENGTH
, srcChar
, isError
);
3849 return doReplace(start
, _length
, buffer
, 0, count
);
3852 inline UnicodeString
&
3853 UnicodeString::replaceBetween(int32_t start
,
3855 const UnicodeString
& srcText
)
3856 { return doReplace(start
, limit
- start
, srcText
, 0, srcText
.length()); }
3858 inline UnicodeString
&
3859 UnicodeString::replaceBetween(int32_t start
,
3861 const UnicodeString
& srcText
,
3864 { return doReplace(start
, limit
- start
, srcText
, srcStart
, srcLimit
- srcStart
); }
3866 inline UnicodeString
&
3867 UnicodeString::findAndReplace(const UnicodeString
& oldText
,
3868 const UnicodeString
& newText
)
3869 { return findAndReplace(0, length(), oldText
, 0, oldText
.length(),
3870 newText
, 0, newText
.length()); }
3872 inline UnicodeString
&
3873 UnicodeString::findAndReplace(int32_t start
,
3875 const UnicodeString
& oldText
,
3876 const UnicodeString
& newText
)
3877 { return findAndReplace(start
, _length
, oldText
, 0, oldText
.length(),
3878 newText
, 0, newText
.length()); }
3880 // ============================
3882 // ============================
3884 UnicodeString::doExtract(int32_t start
,
3886 UnicodeString
& target
) const
3887 { target
.replace(0, target
.length(), *this, start
, _length
); }
3890 UnicodeString::extract(int32_t start
,
3893 int32_t targetStart
) const
3894 { doExtract(start
, _length
, target
, targetStart
); }
3897 UnicodeString::extract(int32_t start
,
3899 UnicodeString
& target
) const
3900 { doExtract(start
, _length
, target
); }
3902 #if !UCONFIG_NO_CONVERSION
3905 UnicodeString::extract(int32_t start
,
3908 const char *codepage
) const
3911 // This dstSize value will be checked explicitly
3912 return extract(start
, _length
, dst
, dst
!=0 ? 0xffffffff : 0, codepage
);
3918 UnicodeString::extractBetween(int32_t start
,
3921 int32_t dstStart
) const {
3924 doExtract(start
, limit
- start
, dst
, dstStart
);
3928 UnicodeString::doCharAt(int32_t offset
) const
3930 if((uint32_t)offset
< (uint32_t)length()) {
3931 return getArrayStart()[offset
];
3933 return kInvalidUChar
;
3938 UnicodeString::charAt(int32_t offset
) const
3939 { return doCharAt(offset
); }
3942 UnicodeString::operator[] (int32_t offset
) const
3943 { return doCharAt(offset
); }
3946 UnicodeString::char32At(int32_t offset
) const
3948 int32_t len
= length();
3949 if((uint32_t)offset
< (uint32_t)len
) {
3950 const UChar
*array
= getArrayStart();
3952 U16_GET(array
, 0, offset
, len
, c
);
3955 return kInvalidUChar
;
3960 UnicodeString::getChar32Start(int32_t offset
) const {
3961 if((uint32_t)offset
< (uint32_t)length()) {
3962 const UChar
*array
= getArrayStart();
3963 U16_SET_CP_START(array
, 0, offset
);
3971 UnicodeString::getChar32Limit(int32_t offset
) const {
3972 int32_t len
= length();
3973 if((uint32_t)offset
< (uint32_t)len
) {
3974 const UChar
*array
= getArrayStart();
3975 U16_SET_CP_LIMIT(array
, 0, offset
, len
);
3983 UnicodeString::isEmpty() const {
3984 return fShortLength
== 0;
3987 //========================================
3988 // Write implementation methods
3989 //========================================
3991 UnicodeString::setLength(int32_t len
) {
3993 fShortLength
= (int8_t)len
;
3995 fShortLength
= (int8_t)-1;
3996 fUnion
.fFields
.fLength
= len
;
4001 UnicodeString::setToEmpty() {
4003 fFlags
= kShortString
;
4007 UnicodeString::setToStackBuffer(int32_t len
) {
4008 fShortLength
= (int8_t)len
;
4009 fFlags
= kShortString
;
4013 UnicodeString::setArray(UChar
*array
, int32_t len
, int32_t capacity
) {
4015 fUnion
.fFields
.fArray
= array
;
4016 fUnion
.fFields
.fCapacity
= capacity
;
4019 inline const UChar
*
4020 UnicodeString::getTerminatedBuffer() {
4024 UChar
*array
= getArrayStart();
4025 int32_t len
= length();
4026 if(len
< getCapacity() && array
[len
] == 0) {
4028 } else if(cloneArrayIfNeeded(len
+1)) {
4029 array
= getArrayStart();
4038 inline UnicodeString
&
4039 UnicodeString::operator= (UChar ch
)
4040 { return doReplace(0, length(), &ch
, 0, 1); }
4042 inline UnicodeString
&
4043 UnicodeString::operator= (UChar32 ch
)
4044 { return replace(0, length(), ch
); }
4046 inline UnicodeString
&
4047 UnicodeString::setTo(const UnicodeString
& srcText
,
4052 return doReplace(0, length(), srcText
, srcStart
, srcLength
);
4055 inline UnicodeString
&
4056 UnicodeString::setTo(const UnicodeString
& srcText
,
4060 srcText
.pinIndex(srcStart
);
4061 return doReplace(0, length(), srcText
, srcStart
, srcText
.length() - srcStart
);
4064 inline UnicodeString
&
4065 UnicodeString::setTo(const UnicodeString
& srcText
)
4068 return doReplace(0, length(), srcText
, 0, srcText
.length());
4071 inline UnicodeString
&
4072 UnicodeString::setTo(const UChar
*srcChars
,
4076 return doReplace(0, length(), srcChars
, 0, srcLength
);
4079 inline UnicodeString
&
4080 UnicodeString::setTo(UChar srcChar
)
4083 return doReplace(0, length(), &srcChar
, 0, 1);
4086 inline UnicodeString
&
4087 UnicodeString::setTo(UChar32 srcChar
)
4090 return replace(0, length(), srcChar
);
4093 inline UnicodeString
&
4094 UnicodeString::append(const UnicodeString
& srcText
,
4097 { return doReplace(length(), 0, srcText
, srcStart
, srcLength
); }
4099 inline UnicodeString
&
4100 UnicodeString::append(const UnicodeString
& srcText
)
4101 { return doReplace(length(), 0, srcText
, 0, srcText
.length()); }
4103 inline UnicodeString
&
4104 UnicodeString::append(const UChar
*srcChars
,
4107 { return doReplace(length(), 0, srcChars
, srcStart
, srcLength
); }
4109 inline UnicodeString
&
4110 UnicodeString::append(const UChar
*srcChars
,
4112 { return doReplace(length(), 0, srcChars
, 0, srcLength
); }
4114 inline UnicodeString
&
4115 UnicodeString::append(UChar srcChar
)
4116 { return doReplace(length(), 0, &srcChar
, 0, 1); }
4118 inline UnicodeString
&
4119 UnicodeString::append(UChar32 srcChar
) {
4120 UChar buffer
[U16_MAX_LENGTH
];
4121 int32_t _length
= 0;
4122 UBool isError
= FALSE
;
4123 U16_APPEND(buffer
, _length
, U16_MAX_LENGTH
, srcChar
, isError
);
4124 return doReplace(length(), 0, buffer
, 0, _length
);
4127 inline UnicodeString
&
4128 UnicodeString::operator+= (UChar ch
)
4129 { return doReplace(length(), 0, &ch
, 0, 1); }
4131 inline UnicodeString
&
4132 UnicodeString::operator+= (UChar32 ch
) {
4136 inline UnicodeString
&
4137 UnicodeString::operator+= (const UnicodeString
& srcText
)
4138 { return doReplace(length(), 0, srcText
, 0, srcText
.length()); }
4140 inline UnicodeString
&
4141 UnicodeString::insert(int32_t start
,
4142 const UnicodeString
& srcText
,
4145 { return doReplace(start
, 0, srcText
, srcStart
, srcLength
); }
4147 inline UnicodeString
&
4148 UnicodeString::insert(int32_t start
,
4149 const UnicodeString
& srcText
)
4150 { return doReplace(start
, 0, srcText
, 0, srcText
.length()); }
4152 inline UnicodeString
&
4153 UnicodeString::insert(int32_t start
,
4154 const UChar
*srcChars
,
4157 { return doReplace(start
, 0, srcChars
, srcStart
, srcLength
); }
4159 inline UnicodeString
&
4160 UnicodeString::insert(int32_t start
,
4161 const UChar
*srcChars
,
4163 { return doReplace(start
, 0, srcChars
, 0, srcLength
); }
4165 inline UnicodeString
&
4166 UnicodeString::insert(int32_t start
,
4168 { return doReplace(start
, 0, &srcChar
, 0, 1); }
4170 inline UnicodeString
&
4171 UnicodeString::insert(int32_t start
,
4173 { return replace(start
, 0, srcChar
); }
4176 inline UnicodeString
&
4177 UnicodeString::remove()
4179 // remove() of a bogus string makes the string empty and non-bogus
4188 inline UnicodeString
&
4189 UnicodeString::remove(int32_t start
,
4192 if(start
<= 0 && _length
== INT32_MAX
) {
4193 // remove(guaranteed everything) of a bogus string makes the string empty and non-bogus
4196 return doReplace(start
, _length
, NULL
, 0, 0);
4199 inline UnicodeString
&
4200 UnicodeString::removeBetween(int32_t start
,
4202 { return doReplace(start
, limit
- start
, NULL
, 0, 0); }
4205 UnicodeString::truncate(int32_t targetLength
)
4207 if(isBogus() && targetLength
== 0) {
4208 // truncate(0) of a bogus string makes the string empty and non-bogus
4211 } else if((uint32_t)targetLength
< (uint32_t)length()) {
4212 setLength(targetLength
);
4219 inline UnicodeString
&
4220 UnicodeString::reverse()
4221 { return doReverse(0, length()); }
4223 inline UnicodeString
&
4224 UnicodeString::reverse(int32_t start
,
4226 { return doReverse(start
, _length
); }