intl/icu/source/common/unicode/unistr.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial