michael@0: /* michael@0: ********************************************************************** michael@0: * Copyright (C) 1998-2013, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: ********************************************************************** michael@0: * michael@0: * File unistr.h michael@0: * michael@0: * Modification History: michael@0: * michael@0: * Date Name Description michael@0: * 09/25/98 stephen Creation. michael@0: * 11/11/98 stephen Changed per 11/9 code review. michael@0: * 04/20/99 stephen Overhauled per 4/16 code review. michael@0: * 11/18/99 aliu Made to inherit from Replaceable. Added method michael@0: * handleReplaceBetween(); other methods unchanged. michael@0: * 06/25/01 grhoten Remove dependency on iostream. michael@0: ****************************************************************************** michael@0: */ michael@0: michael@0: #ifndef UNISTR_H michael@0: #define UNISTR_H michael@0: michael@0: /** michael@0: * \file michael@0: * \brief C++ API: Unicode String michael@0: */ michael@0: michael@0: #include "unicode/utypes.h" michael@0: #include "unicode/rep.h" michael@0: #include "unicode/std_string.h" michael@0: #include "unicode/stringpiece.h" michael@0: #include "unicode/bytestream.h" michael@0: #include "unicode/ucasemap.h" michael@0: michael@0: struct UConverter; // unicode/ucnv.h michael@0: class StringThreadTest; michael@0: michael@0: #ifndef U_COMPARE_CODE_POINT_ORDER michael@0: /* see also ustring.h and unorm.h */ michael@0: /** michael@0: * Option bit for u_strCaseCompare, u_strcasecmp, unorm_compare, etc: michael@0: * Compare strings in code point order instead of code unit order. michael@0: * @stable ICU 2.2 michael@0: */ michael@0: #define U_COMPARE_CODE_POINT_ORDER 0x8000 michael@0: #endif michael@0: michael@0: #ifndef USTRING_H michael@0: /** michael@0: * \ingroup ustring_ustrlen michael@0: */ michael@0: U_STABLE int32_t U_EXPORT2 michael@0: u_strlen(const UChar *s); michael@0: #endif michael@0: michael@0: /** michael@0: * \def U_STRING_CASE_MAPPER_DEFINED michael@0: * @internal michael@0: */ michael@0: #ifndef U_STRING_CASE_MAPPER_DEFINED michael@0: #define U_STRING_CASE_MAPPER_DEFINED michael@0: michael@0: /** michael@0: * Internal string case mapping function type. michael@0: * @internal michael@0: */ michael@0: typedef int32_t U_CALLCONV michael@0: UStringCaseMapper(const UCaseMap *csm, michael@0: UChar *dest, int32_t destCapacity, michael@0: const UChar *src, int32_t srcLength, michael@0: UErrorCode *pErrorCode); michael@0: michael@0: #endif michael@0: michael@0: U_NAMESPACE_BEGIN michael@0: michael@0: class BreakIterator; // unicode/brkiter.h michael@0: class Locale; // unicode/locid.h michael@0: class StringCharacterIterator; michael@0: class UnicodeStringAppendable; // unicode/appendable.h michael@0: michael@0: /* The include has been moved to unicode/ustream.h */ michael@0: michael@0: /** michael@0: * Constant to be used in the UnicodeString(char *, int32_t, EInvariant) constructor michael@0: * which constructs a Unicode string from an invariant-character char * string. michael@0: * About invariant characters see utypes.h. michael@0: * This constructor has no runtime dependency on conversion code and is michael@0: * therefore recommended over ones taking a charset name string michael@0: * (where the empty string "" indicates invariant-character conversion). michael@0: * michael@0: * @stable ICU 3.2 michael@0: */ michael@0: #define US_INV icu::UnicodeString::kInvariant michael@0: michael@0: /** michael@0: * Unicode String literals in C++. michael@0: * Dependent on the platform properties, different UnicodeString michael@0: * constructors should be used to create a UnicodeString object from michael@0: * a string literal. michael@0: * The macros are defined for maximum performance. michael@0: * They work only for strings that contain "invariant characters", i.e., michael@0: * only latin letters, digits, and some punctuation. michael@0: * See utypes.h for details. michael@0: * michael@0: * The string parameter must be a C string literal. michael@0: * The length of the string, not including the terminating michael@0: * NUL, must be specified as a constant. michael@0: * The U_STRING_DECL macro should be invoked exactly once for one michael@0: * such string variable before it is used. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: #if defined(U_DECLARE_UTF16) michael@0: # define UNICODE_STRING(cs, _length) icu::UnicodeString(TRUE, (const UChar *)U_DECLARE_UTF16(cs), _length) michael@0: #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: # define UNICODE_STRING(cs, _length) icu::UnicodeString(TRUE, (const UChar *)L ## cs, _length) michael@0: #elif U_SIZEOF_UCHAR==1 && U_CHARSET_FAMILY==U_ASCII_FAMILY michael@0: # define UNICODE_STRING(cs, _length) icu::UnicodeString(TRUE, (const UChar *)cs, _length) michael@0: #else michael@0: # define UNICODE_STRING(cs, _length) icu::UnicodeString(cs, _length, US_INV) michael@0: #endif michael@0: michael@0: /** michael@0: * Unicode String literals in C++. michael@0: * Dependent on the platform properties, different UnicodeString michael@0: * constructors should be used to create a UnicodeString object from michael@0: * a string literal. michael@0: * The macros are defined for improved performance. michael@0: * They work only for strings that contain "invariant characters", i.e., michael@0: * only latin letters, digits, and some punctuation. michael@0: * See utypes.h for details. michael@0: * michael@0: * The string parameter must be a C string literal. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: #define UNICODE_STRING_SIMPLE(cs) UNICODE_STRING(cs, -1) michael@0: michael@0: /** michael@0: * \def UNISTR_FROM_CHAR_EXPLICIT michael@0: * This can be defined to be empty or "explicit". michael@0: * If explicit, then the UnicodeString(UChar) and UnicodeString(UChar32) michael@0: * constructors are marked as explicit, preventing their inadvertent use. michael@0: * @stable ICU 49 michael@0: */ michael@0: #ifndef UNISTR_FROM_CHAR_EXPLICIT michael@0: # if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION) michael@0: // Auto-"explicit" in ICU library code. michael@0: # define UNISTR_FROM_CHAR_EXPLICIT explicit michael@0: # else michael@0: // Empty by default for source code compatibility. michael@0: # define UNISTR_FROM_CHAR_EXPLICIT michael@0: # endif michael@0: #endif michael@0: michael@0: /** michael@0: * \def UNISTR_FROM_STRING_EXPLICIT michael@0: * This can be defined to be empty or "explicit". michael@0: * If explicit, then the UnicodeString(const char *) and UnicodeString(const UChar *) michael@0: * constructors are marked as explicit, preventing their inadvertent use. michael@0: * michael@0: * In particular, this helps prevent accidentally depending on ICU conversion code michael@0: * by passing a string literal into an API with a const UnicodeString & parameter. michael@0: * @stable ICU 49 michael@0: */ michael@0: #ifndef UNISTR_FROM_STRING_EXPLICIT michael@0: # if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION) michael@0: // Auto-"explicit" in ICU library code. michael@0: # define UNISTR_FROM_STRING_EXPLICIT explicit michael@0: # else michael@0: // Empty by default for source code compatibility. michael@0: # define UNISTR_FROM_STRING_EXPLICIT michael@0: # endif michael@0: #endif michael@0: michael@0: /** michael@0: * UnicodeString is a string class that stores Unicode characters directly and provides michael@0: * similar functionality as the Java String and StringBuffer classes. michael@0: * It is a concrete implementation of the abstract class Replaceable (for transliteration). michael@0: * michael@0: * The UnicodeString class is not suitable for subclassing. michael@0: * michael@0: *

For an overview of Unicode strings in C and C++ see the michael@0: * User Guide Strings chapter.

michael@0: * michael@0: *

In ICU, a Unicode string consists of 16-bit Unicode code units. michael@0: * A Unicode character may be stored with either one code unit michael@0: * (the most common case) or with a matched pair of special code units michael@0: * ("surrogates"). The data type for code units is UChar. michael@0: * For single-character handling, a Unicode character code point is a value michael@0: * in the range 0..0x10ffff. ICU uses the UChar32 type for code points.

michael@0: * michael@0: *

Indexes and offsets into and lengths of strings always count code units, not code points. michael@0: * This is the same as with multi-byte char* strings in traditional string handling. michael@0: * Operations on partial strings typically do not test for code point boundaries. michael@0: * If necessary, the user needs to take care of such boundaries by testing for the code unit michael@0: * values or by using functions like michael@0: * UnicodeString::getChar32Start() and UnicodeString::getChar32Limit() michael@0: * (or, in C, the equivalent macros U16_SET_CP_START() and U16_SET_CP_LIMIT(), see utf.h).

michael@0: * michael@0: * UnicodeString methods are more lenient with regard to input parameter values michael@0: * than other ICU APIs. In particular: michael@0: * - If indexes are out of bounds for a UnicodeString object michael@0: * (<0 or >length()) then they are "pinned" to the nearest boundary. michael@0: * - If primitive string pointer values (e.g., const UChar * or char *) michael@0: * for input strings are NULL, then those input string parameters are treated michael@0: * as if they pointed to an empty string. michael@0: * However, this is not the case for char * parameters for charset names michael@0: * or other IDs. michael@0: * - Most UnicodeString methods do not take a UErrorCode parameter because michael@0: * there are usually very few opportunities for failure other than a shortage michael@0: * of memory, error codes in low-level C++ string methods would be inconvenient, michael@0: * and the error code as the last parameter (ICU convention) would prevent michael@0: * the use of default parameter values. michael@0: * Instead, such methods set the UnicodeString into a "bogus" state michael@0: * (see isBogus()) if an error occurs. michael@0: * michael@0: * In string comparisons, two UnicodeString objects that are both "bogus" michael@0: * compare equal (to be transitive and prevent endless loops in sorting), michael@0: * and a "bogus" string compares less than any non-"bogus" one. michael@0: * michael@0: * Const UnicodeString methods are thread-safe. Multiple threads can use michael@0: * const methods on the same UnicodeString object simultaneously, michael@0: * but non-const methods must not be called concurrently (in multiple threads) michael@0: * with any other (const or non-const) methods. michael@0: * michael@0: * Similarly, const UnicodeString & parameters are thread-safe. michael@0: * One object may be passed in as such a parameter concurrently in multiple threads. michael@0: * This includes the const UnicodeString & parameters for michael@0: * copy construction, assignment, and cloning. michael@0: * michael@0: *

UnicodeString uses several storage methods. michael@0: * String contents can be stored inside the UnicodeString object itself, michael@0: * in an allocated and shared buffer, or in an outside buffer that is "aliased". michael@0: * Most of this is done transparently, but careful aliasing in particular provides michael@0: * significant performance improvements. michael@0: * Also, the internal buffer is accessible via special functions. michael@0: * For details see the michael@0: * User Guide Strings chapter.

michael@0: * michael@0: * @see utf.h michael@0: * @see CharacterIterator michael@0: * @stable ICU 2.0 michael@0: */ michael@0: class U_COMMON_API UnicodeString : public Replaceable michael@0: { michael@0: public: michael@0: michael@0: /** michael@0: * Constant to be used in the UnicodeString(char *, int32_t, EInvariant) constructor michael@0: * which constructs a Unicode string from an invariant-character char * string. michael@0: * Use the macro US_INV instead of the full qualification for this value. michael@0: * michael@0: * @see US_INV michael@0: * @stable ICU 3.2 michael@0: */ michael@0: enum EInvariant { michael@0: /** michael@0: * @see EInvariant michael@0: * @stable ICU 3.2 michael@0: */ michael@0: kInvariant michael@0: }; michael@0: michael@0: //======================================== michael@0: // Read-only operations michael@0: //======================================== michael@0: michael@0: /* Comparison - bitwise only - for international comparison use collation */ michael@0: michael@0: /** michael@0: * Equality operator. Performs only bitwise comparison. michael@0: * @param text The UnicodeString to compare to this one. michael@0: * @return TRUE if text contains the same characters as this one, michael@0: * FALSE otherwise. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline UBool operator== (const UnicodeString& text) const; michael@0: michael@0: /** michael@0: * Inequality operator. Performs only bitwise comparison. michael@0: * @param text The UnicodeString to compare to this one. michael@0: * @return FALSE if text contains the same characters as this one, michael@0: * TRUE otherwise. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline UBool operator!= (const UnicodeString& text) const; michael@0: michael@0: /** michael@0: * Greater than operator. Performs only bitwise comparison. michael@0: * @param text The UnicodeString to compare to this one. michael@0: * @return TRUE if the characters in this are bitwise michael@0: * greater than the characters in text, FALSE otherwise michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline UBool operator> (const UnicodeString& text) const; michael@0: michael@0: /** michael@0: * Less than operator. Performs only bitwise comparison. michael@0: * @param text The UnicodeString to compare to this one. michael@0: * @return TRUE if the characters in this are bitwise michael@0: * less than the characters in text, FALSE otherwise michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline UBool operator< (const UnicodeString& text) const; michael@0: michael@0: /** michael@0: * Greater than or equal operator. Performs only bitwise comparison. michael@0: * @param text The UnicodeString to compare to this one. michael@0: * @return TRUE if the characters in this are bitwise michael@0: * greater than or equal to the characters in text, FALSE otherwise michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline UBool operator>= (const UnicodeString& text) const; michael@0: michael@0: /** michael@0: * Less than or equal operator. Performs only bitwise comparison. michael@0: * @param text The UnicodeString to compare to this one. michael@0: * @return TRUE if the characters in this are bitwise michael@0: * less than or equal to the characters in text, FALSE otherwise michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline UBool operator<= (const UnicodeString& text) const; michael@0: michael@0: /** michael@0: * Compare the characters bitwise in this UnicodeString to michael@0: * the characters in text. michael@0: * @param text The UnicodeString to compare to this one. michael@0: * @return The result of bitwise character comparison: 0 if this michael@0: * contains the same characters as text, -1 if the characters in michael@0: * this are bitwise less than the characters in text, +1 if the michael@0: * characters in this are bitwise greater than the characters michael@0: * in text. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline int8_t compare(const UnicodeString& text) const; michael@0: michael@0: /** michael@0: * Compare the characters bitwise in the range michael@0: * [start, start + length) with the characters michael@0: * in the entire string text. michael@0: * (The parameters "start" and "length" are not applied to the other text "text".) michael@0: * @param start the offset at which the compare operation begins michael@0: * @param length the number of characters of text to compare. michael@0: * @param text the other text to be compared against this string. michael@0: * @return The result of bitwise character comparison: 0 if this michael@0: * contains the same characters as text, -1 if the characters in michael@0: * this are bitwise less than the characters in text, +1 if the michael@0: * characters in this are bitwise greater than the characters michael@0: * in text. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline int8_t compare(int32_t start, michael@0: int32_t length, michael@0: const UnicodeString& text) const; michael@0: michael@0: /** michael@0: * Compare the characters bitwise in the range michael@0: * [start, start + length) with the characters michael@0: * in srcText in the range michael@0: * [srcStart, srcStart + srcLength). michael@0: * @param start the offset at which the compare operation begins michael@0: * @param length the number of characters in this to compare. michael@0: * @param srcText the text to be compared michael@0: * @param srcStart the offset into srcText to start comparison michael@0: * @param srcLength the number of characters in src to compare michael@0: * @return The result of bitwise character comparison: 0 if this michael@0: * contains the same characters as srcText, -1 if the characters in michael@0: * this are bitwise less than the characters in srcText, +1 if the michael@0: * characters in this are bitwise greater than the characters michael@0: * in srcText. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline int8_t compare(int32_t start, michael@0: int32_t length, michael@0: const UnicodeString& srcText, michael@0: int32_t srcStart, michael@0: int32_t srcLength) const; michael@0: michael@0: /** michael@0: * Compare the characters bitwise in this UnicodeString with the first michael@0: * srcLength characters in srcChars. michael@0: * @param srcChars The characters to compare to this UnicodeString. michael@0: * @param srcLength the number of characters in srcChars to compare michael@0: * @return The result of bitwise character comparison: 0 if this michael@0: * contains the same characters as srcChars, -1 if the characters in michael@0: * this are bitwise less than the characters in srcChars, +1 if the michael@0: * characters in this are bitwise greater than the characters michael@0: * in srcChars. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline int8_t compare(const UChar *srcChars, michael@0: int32_t srcLength) const; michael@0: michael@0: /** michael@0: * Compare the characters bitwise in the range michael@0: * [start, start + length) with the first michael@0: * length characters in srcChars michael@0: * @param start the offset at which the compare operation begins michael@0: * @param length the number of characters to compare. michael@0: * @param srcChars the characters to be compared michael@0: * @return The result of bitwise character comparison: 0 if this michael@0: * contains the same characters as srcChars, -1 if the characters in michael@0: * this are bitwise less than the characters in srcChars, +1 if the michael@0: * characters in this are bitwise greater than the characters michael@0: * in srcChars. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline int8_t compare(int32_t start, michael@0: int32_t length, michael@0: const UChar *srcChars) const; michael@0: michael@0: /** michael@0: * Compare the characters bitwise in the range michael@0: * [start, start + length) with the characters michael@0: * in srcChars in the range michael@0: * [srcStart, srcStart + srcLength). michael@0: * @param start the offset at which the compare operation begins michael@0: * @param length the number of characters in this to compare michael@0: * @param srcChars the characters to be compared michael@0: * @param srcStart the offset into srcChars to start comparison michael@0: * @param srcLength the number of characters in srcChars to compare michael@0: * @return The result of bitwise character comparison: 0 if this michael@0: * contains the same characters as srcChars, -1 if the characters in michael@0: * this are bitwise less than the characters in srcChars, +1 if the michael@0: * characters in this are bitwise greater than the characters michael@0: * in srcChars. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline int8_t compare(int32_t start, michael@0: int32_t length, michael@0: const UChar *srcChars, michael@0: int32_t srcStart, michael@0: int32_t srcLength) const; michael@0: michael@0: /** michael@0: * Compare the characters bitwise in the range michael@0: * [start, limit) with the characters michael@0: * in srcText in the range michael@0: * [srcStart, srcLimit). michael@0: * @param start the offset at which the compare operation begins michael@0: * @param limit the offset immediately following the compare operation michael@0: * @param srcText the text to be compared michael@0: * @param srcStart the offset into srcText to start comparison michael@0: * @param srcLimit the offset into srcText to limit comparison michael@0: * @return The result of bitwise character comparison: 0 if this michael@0: * contains the same characters as srcText, -1 if the characters in michael@0: * this are bitwise less than the characters in srcText, +1 if the michael@0: * characters in this are bitwise greater than the characters michael@0: * in srcText. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline int8_t compareBetween(int32_t start, michael@0: int32_t limit, michael@0: const UnicodeString& srcText, michael@0: int32_t srcStart, michael@0: int32_t srcLimit) const; michael@0: michael@0: /** michael@0: * Compare two Unicode strings in code point order. michael@0: * The result may be different from the results of compare(), operator<, etc. michael@0: * if supplementary characters are present: michael@0: * michael@0: * In UTF-16, supplementary characters (with code points U+10000 and above) are michael@0: * stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff, michael@0: * which means that they compare as less than some other BMP characters like U+feff. michael@0: * This function compares Unicode strings in code point order. michael@0: * If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined. michael@0: * michael@0: * @param text Another string to compare this one to. michael@0: * @return a negative/zero/positive integer corresponding to whether michael@0: * this string is less than/equal to/greater than the second one michael@0: * in code point order michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline int8_t compareCodePointOrder(const UnicodeString& text) const; michael@0: michael@0: /** michael@0: * Compare two Unicode strings in code point order. michael@0: * The result may be different from the results of compare(), operator<, etc. michael@0: * if supplementary characters are present: michael@0: * michael@0: * In UTF-16, supplementary characters (with code points U+10000 and above) are michael@0: * stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff, michael@0: * which means that they compare as less than some other BMP characters like U+feff. michael@0: * This function compares Unicode strings in code point order. michael@0: * If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined. michael@0: * michael@0: * @param start The start offset in this string at which the compare operation begins. michael@0: * @param length The number of code units from this string to compare. michael@0: * @param srcText Another string to compare this one to. michael@0: * @return a negative/zero/positive integer corresponding to whether michael@0: * this string is less than/equal to/greater than the second one michael@0: * in code point order michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline int8_t compareCodePointOrder(int32_t start, michael@0: int32_t length, michael@0: const UnicodeString& srcText) const; michael@0: michael@0: /** michael@0: * Compare two Unicode strings in code point order. michael@0: * The result may be different from the results of compare(), operator<, etc. michael@0: * if supplementary characters are present: michael@0: * michael@0: * In UTF-16, supplementary characters (with code points U+10000 and above) are michael@0: * stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff, michael@0: * which means that they compare as less than some other BMP characters like U+feff. michael@0: * This function compares Unicode strings in code point order. michael@0: * If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined. michael@0: * michael@0: * @param start The start offset in this string at which the compare operation begins. michael@0: * @param length The number of code units from this string to compare. michael@0: * @param srcText Another string to compare this one to. michael@0: * @param srcStart The start offset in that string at which the compare operation begins. michael@0: * @param srcLength The number of code units from that string to compare. michael@0: * @return a negative/zero/positive integer corresponding to whether michael@0: * this string is less than/equal to/greater than the second one michael@0: * in code point order michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline int8_t compareCodePointOrder(int32_t start, michael@0: int32_t length, michael@0: const UnicodeString& srcText, michael@0: int32_t srcStart, michael@0: int32_t srcLength) const; michael@0: michael@0: /** michael@0: * Compare two Unicode strings in code point order. michael@0: * The result may be different from the results of compare(), operator<, etc. michael@0: * if supplementary characters are present: michael@0: * michael@0: * In UTF-16, supplementary characters (with code points U+10000 and above) are michael@0: * stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff, michael@0: * which means that they compare as less than some other BMP characters like U+feff. michael@0: * This function compares Unicode strings in code point order. michael@0: * If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined. michael@0: * michael@0: * @param srcChars A pointer to another string to compare this one to. michael@0: * @param srcLength The number of code units from that string to compare. michael@0: * @return a negative/zero/positive integer corresponding to whether michael@0: * this string is less than/equal to/greater than the second one michael@0: * in code point order michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline int8_t compareCodePointOrder(const UChar *srcChars, michael@0: int32_t srcLength) const; michael@0: michael@0: /** michael@0: * Compare two Unicode strings in code point order. michael@0: * The result may be different from the results of compare(), operator<, etc. michael@0: * if supplementary characters are present: michael@0: * michael@0: * In UTF-16, supplementary characters (with code points U+10000 and above) are michael@0: * stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff, michael@0: * which means that they compare as less than some other BMP characters like U+feff. michael@0: * This function compares Unicode strings in code point order. michael@0: * If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined. michael@0: * michael@0: * @param start The start offset in this string at which the compare operation begins. michael@0: * @param length The number of code units from this string to compare. michael@0: * @param srcChars A pointer to another string to compare this one to. michael@0: * @return a negative/zero/positive integer corresponding to whether michael@0: * this string is less than/equal to/greater than the second one michael@0: * in code point order michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline int8_t compareCodePointOrder(int32_t start, michael@0: int32_t length, michael@0: const UChar *srcChars) const; michael@0: michael@0: /** michael@0: * Compare two Unicode strings in code point order. michael@0: * The result may be different from the results of compare(), operator<, etc. michael@0: * if supplementary characters are present: michael@0: * michael@0: * In UTF-16, supplementary characters (with code points U+10000 and above) are michael@0: * stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff, michael@0: * which means that they compare as less than some other BMP characters like U+feff. michael@0: * This function compares Unicode strings in code point order. michael@0: * If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined. michael@0: * michael@0: * @param start The start offset in this string at which the compare operation begins. michael@0: * @param length The number of code units from this string to compare. michael@0: * @param srcChars A pointer to another string to compare this one to. michael@0: * @param srcStart The start offset in that string at which the compare operation begins. michael@0: * @param srcLength The number of code units from that string to compare. michael@0: * @return a negative/zero/positive integer corresponding to whether michael@0: * this string is less than/equal to/greater than the second one michael@0: * in code point order michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline int8_t compareCodePointOrder(int32_t start, michael@0: int32_t length, michael@0: const UChar *srcChars, michael@0: int32_t srcStart, michael@0: int32_t srcLength) const; michael@0: michael@0: /** michael@0: * Compare two Unicode strings in code point order. michael@0: * The result may be different from the results of compare(), operator<, etc. michael@0: * if supplementary characters are present: michael@0: * michael@0: * In UTF-16, supplementary characters (with code points U+10000 and above) are michael@0: * stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff, michael@0: * which means that they compare as less than some other BMP characters like U+feff. michael@0: * This function compares Unicode strings in code point order. michael@0: * If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined. michael@0: * michael@0: * @param start The start offset in this string at which the compare operation begins. michael@0: * @param limit The offset after the last code unit from this string to compare. michael@0: * @param srcText Another string to compare this one to. michael@0: * @param srcStart The start offset in that string at which the compare operation begins. michael@0: * @param srcLimit The offset after the last code unit from that string to compare. michael@0: * @return a negative/zero/positive integer corresponding to whether michael@0: * this string is less than/equal to/greater than the second one michael@0: * in code point order michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline int8_t compareCodePointOrderBetween(int32_t start, michael@0: int32_t limit, michael@0: const UnicodeString& srcText, michael@0: int32_t srcStart, michael@0: int32_t srcLimit) const; michael@0: michael@0: /** michael@0: * Compare two strings case-insensitively using full case folding. michael@0: * This is equivalent to this->foldCase(options).compare(text.foldCase(options)). michael@0: * michael@0: * @param text Another string to compare this one to. michael@0: * @param options A bit set of options: michael@0: * - U_FOLD_CASE_DEFAULT or 0 is used for default options: michael@0: * Comparison in code unit order with default case folding. michael@0: * michael@0: * - U_COMPARE_CODE_POINT_ORDER michael@0: * Set to choose code point order instead of code unit order michael@0: * (see u_strCompare for details). michael@0: * michael@0: * - U_FOLD_CASE_EXCLUDE_SPECIAL_I michael@0: * michael@0: * @return A negative, zero, or positive integer indicating the comparison result. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline int8_t caseCompare(const UnicodeString& text, uint32_t options) const; michael@0: michael@0: /** michael@0: * Compare two strings case-insensitively using full case folding. michael@0: * This is equivalent to this->foldCase(options).compare(srcText.foldCase(options)). michael@0: * michael@0: * @param start The start offset in this string at which the compare operation begins. michael@0: * @param length The number of code units from this string to compare. michael@0: * @param srcText Another string to compare this one to. michael@0: * @param options A bit set of options: michael@0: * - U_FOLD_CASE_DEFAULT or 0 is used for default options: michael@0: * Comparison in code unit order with default case folding. michael@0: * michael@0: * - U_COMPARE_CODE_POINT_ORDER michael@0: * Set to choose code point order instead of code unit order michael@0: * (see u_strCompare for details). michael@0: * michael@0: * - U_FOLD_CASE_EXCLUDE_SPECIAL_I michael@0: * michael@0: * @return A negative, zero, or positive integer indicating the comparison result. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline int8_t caseCompare(int32_t start, michael@0: int32_t length, michael@0: const UnicodeString& srcText, michael@0: uint32_t options) const; michael@0: michael@0: /** michael@0: * Compare two strings case-insensitively using full case folding. michael@0: * This is equivalent to this->foldCase(options).compare(srcText.foldCase(options)). michael@0: * michael@0: * @param start The start offset in this string at which the compare operation begins. michael@0: * @param length The number of code units from this string to compare. michael@0: * @param srcText Another string to compare this one to. michael@0: * @param srcStart The start offset in that string at which the compare operation begins. michael@0: * @param srcLength The number of code units from that string to compare. michael@0: * @param options A bit set of options: michael@0: * - U_FOLD_CASE_DEFAULT or 0 is used for default options: michael@0: * Comparison in code unit order with default case folding. michael@0: * michael@0: * - U_COMPARE_CODE_POINT_ORDER michael@0: * Set to choose code point order instead of code unit order michael@0: * (see u_strCompare for details). michael@0: * michael@0: * - U_FOLD_CASE_EXCLUDE_SPECIAL_I michael@0: * michael@0: * @return A negative, zero, or positive integer indicating the comparison result. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline int8_t caseCompare(int32_t start, michael@0: int32_t length, michael@0: const UnicodeString& srcText, michael@0: int32_t srcStart, michael@0: int32_t srcLength, michael@0: uint32_t options) const; michael@0: michael@0: /** michael@0: * Compare two strings case-insensitively using full case folding. michael@0: * This is equivalent to this->foldCase(options).compare(srcChars.foldCase(options)). michael@0: * michael@0: * @param srcChars A pointer to another string to compare this one to. michael@0: * @param srcLength The number of code units from that string to compare. michael@0: * @param options A bit set of options: michael@0: * - U_FOLD_CASE_DEFAULT or 0 is used for default options: michael@0: * Comparison in code unit order with default case folding. michael@0: * michael@0: * - U_COMPARE_CODE_POINT_ORDER michael@0: * Set to choose code point order instead of code unit order michael@0: * (see u_strCompare for details). michael@0: * michael@0: * - U_FOLD_CASE_EXCLUDE_SPECIAL_I michael@0: * michael@0: * @return A negative, zero, or positive integer indicating the comparison result. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline int8_t caseCompare(const UChar *srcChars, michael@0: int32_t srcLength, michael@0: uint32_t options) const; michael@0: michael@0: /** michael@0: * Compare two strings case-insensitively using full case folding. michael@0: * This is equivalent to this->foldCase(options).compare(srcChars.foldCase(options)). michael@0: * michael@0: * @param start The start offset in this string at which the compare operation begins. michael@0: * @param length The number of code units from this string to compare. michael@0: * @param srcChars A pointer to another string to compare this one to. michael@0: * @param options A bit set of options: michael@0: * - U_FOLD_CASE_DEFAULT or 0 is used for default options: michael@0: * Comparison in code unit order with default case folding. michael@0: * michael@0: * - U_COMPARE_CODE_POINT_ORDER michael@0: * Set to choose code point order instead of code unit order michael@0: * (see u_strCompare for details). michael@0: * michael@0: * - U_FOLD_CASE_EXCLUDE_SPECIAL_I michael@0: * michael@0: * @return A negative, zero, or positive integer indicating the comparison result. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline int8_t caseCompare(int32_t start, michael@0: int32_t length, michael@0: const UChar *srcChars, michael@0: uint32_t options) const; michael@0: michael@0: /** michael@0: * Compare two strings case-insensitively using full case folding. michael@0: * This is equivalent to this->foldCase(options).compare(srcChars.foldCase(options)). michael@0: * michael@0: * @param start The start offset in this string at which the compare operation begins. michael@0: * @param length The number of code units from this string to compare. michael@0: * @param srcChars A pointer to another string to compare this one to. michael@0: * @param srcStart The start offset in that string at which the compare operation begins. michael@0: * @param srcLength The number of code units from that string to compare. michael@0: * @param options A bit set of options: michael@0: * - U_FOLD_CASE_DEFAULT or 0 is used for default options: michael@0: * Comparison in code unit order with default case folding. michael@0: * michael@0: * - U_COMPARE_CODE_POINT_ORDER michael@0: * Set to choose code point order instead of code unit order michael@0: * (see u_strCompare for details). michael@0: * michael@0: * - U_FOLD_CASE_EXCLUDE_SPECIAL_I michael@0: * michael@0: * @return A negative, zero, or positive integer indicating the comparison result. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline int8_t caseCompare(int32_t start, michael@0: int32_t length, michael@0: const UChar *srcChars, michael@0: int32_t srcStart, michael@0: int32_t srcLength, michael@0: uint32_t options) const; michael@0: michael@0: /** michael@0: * Compare two strings case-insensitively using full case folding. michael@0: * This is equivalent to this->foldCase(options).compareBetween(text.foldCase(options)). michael@0: * michael@0: * @param start The start offset in this string at which the compare operation begins. michael@0: * @param limit The offset after the last code unit from this string to compare. michael@0: * @param srcText Another string to compare this one to. michael@0: * @param srcStart The start offset in that string at which the compare operation begins. michael@0: * @param srcLimit The offset after the last code unit from that string to compare. michael@0: * @param options A bit set of options: michael@0: * - U_FOLD_CASE_DEFAULT or 0 is used for default options: michael@0: * Comparison in code unit order with default case folding. michael@0: * michael@0: * - U_COMPARE_CODE_POINT_ORDER michael@0: * Set to choose code point order instead of code unit order michael@0: * (see u_strCompare for details). michael@0: * michael@0: * - U_FOLD_CASE_EXCLUDE_SPECIAL_I michael@0: * michael@0: * @return A negative, zero, or positive integer indicating the comparison result. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline int8_t caseCompareBetween(int32_t start, michael@0: int32_t limit, michael@0: const UnicodeString& srcText, michael@0: int32_t srcStart, michael@0: int32_t srcLimit, michael@0: uint32_t options) const; michael@0: michael@0: /** michael@0: * Determine if this starts with the characters in text michael@0: * @param text The text to match. michael@0: * @return TRUE if this starts with the characters in text, michael@0: * FALSE otherwise michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline UBool startsWith(const UnicodeString& text) const; michael@0: michael@0: /** michael@0: * Determine if this starts with the characters in srcText michael@0: * in the range [srcStart, srcStart + srcLength). michael@0: * @param srcText The text to match. michael@0: * @param srcStart the offset into srcText to start matching michael@0: * @param srcLength the number of characters in srcText to match michael@0: * @return TRUE if this starts with the characters in text, michael@0: * FALSE otherwise michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline UBool startsWith(const UnicodeString& srcText, michael@0: int32_t srcStart, michael@0: int32_t srcLength) const; michael@0: michael@0: /** michael@0: * Determine if this starts with the characters in srcChars michael@0: * @param srcChars The characters to match. michael@0: * @param srcLength the number of characters in srcChars michael@0: * @return TRUE if this starts with the characters in srcChars, michael@0: * FALSE otherwise michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline UBool startsWith(const UChar *srcChars, michael@0: int32_t srcLength) const; michael@0: michael@0: /** michael@0: * Determine if this ends with the characters in srcChars michael@0: * in the range [srcStart, srcStart + srcLength). michael@0: * @param srcChars The characters to match. michael@0: * @param srcStart the offset into srcText to start matching michael@0: * @param srcLength the number of characters in srcChars to match michael@0: * @return TRUE if this ends with the characters in srcChars, FALSE otherwise michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline UBool startsWith(const UChar *srcChars, michael@0: int32_t srcStart, michael@0: int32_t srcLength) const; michael@0: michael@0: /** michael@0: * Determine if this ends with the characters in text michael@0: * @param text The text to match. michael@0: * @return TRUE if this ends with the characters in text, michael@0: * FALSE otherwise michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline UBool endsWith(const UnicodeString& text) const; michael@0: michael@0: /** michael@0: * Determine if this ends with the characters in srcText michael@0: * in the range [srcStart, srcStart + srcLength). michael@0: * @param srcText The text to match. michael@0: * @param srcStart the offset into srcText to start matching michael@0: * @param srcLength the number of characters in srcText to match michael@0: * @return TRUE if this ends with the characters in text, michael@0: * FALSE otherwise michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline UBool endsWith(const UnicodeString& srcText, michael@0: int32_t srcStart, michael@0: int32_t srcLength) const; michael@0: michael@0: /** michael@0: * Determine if this ends with the characters in srcChars michael@0: * @param srcChars The characters to match. michael@0: * @param srcLength the number of characters in srcChars michael@0: * @return TRUE if this ends with the characters in srcChars, michael@0: * FALSE otherwise michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline UBool endsWith(const UChar *srcChars, michael@0: int32_t srcLength) const; michael@0: michael@0: /** michael@0: * Determine if this ends with the characters in srcChars michael@0: * in the range [srcStart, srcStart + srcLength). michael@0: * @param srcChars The characters to match. michael@0: * @param srcStart the offset into srcText to start matching michael@0: * @param srcLength the number of characters in srcChars to match michael@0: * @return TRUE if this ends with the characters in srcChars, michael@0: * FALSE otherwise michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline UBool endsWith(const UChar *srcChars, michael@0: int32_t srcStart, michael@0: int32_t srcLength) const; michael@0: michael@0: michael@0: /* Searching - bitwise only */ michael@0: michael@0: /** michael@0: * Locate in this the first occurrence of the characters in text, michael@0: * using bitwise comparison. michael@0: * @param text The text to search for. michael@0: * @return The offset into this of the start of text, michael@0: * or -1 if not found. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline int32_t indexOf(const UnicodeString& text) const; michael@0: michael@0: /** michael@0: * Locate in this the first occurrence of the characters in text michael@0: * starting at offset start, using bitwise comparison. michael@0: * @param text The text to search for. michael@0: * @param start The offset at which searching will start. michael@0: * @return The offset into this of the start of text, michael@0: * or -1 if not found. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline int32_t indexOf(const UnicodeString& text, michael@0: int32_t start) const; michael@0: michael@0: /** michael@0: * Locate in this the first occurrence in the range michael@0: * [start, start + length) of the characters michael@0: * in text, using bitwise comparison. michael@0: * @param text The text to search for. michael@0: * @param start The offset at which searching will start. michael@0: * @param length The number of characters to search michael@0: * @return The offset into this of the start of text, michael@0: * or -1 if not found. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline int32_t indexOf(const UnicodeString& text, michael@0: int32_t start, michael@0: int32_t length) const; michael@0: michael@0: /** michael@0: * Locate in this the first occurrence in the range michael@0: * [start, start + length) of the characters michael@0: * in srcText in the range michael@0: * [srcStart, srcStart + srcLength), michael@0: * using bitwise comparison. michael@0: * @param srcText The text to search for. michael@0: * @param srcStart the offset into srcText at which michael@0: * to start matching michael@0: * @param srcLength the number of characters in srcText to match michael@0: * @param start the offset into this at which to start matching michael@0: * @param length the number of characters in this to search michael@0: * @return The offset into this of the start of text, michael@0: * or -1 if not found. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline int32_t indexOf(const UnicodeString& srcText, michael@0: int32_t srcStart, michael@0: int32_t srcLength, michael@0: int32_t start, michael@0: int32_t length) const; michael@0: michael@0: /** michael@0: * Locate in this the first occurrence of the characters in michael@0: * srcChars michael@0: * starting at offset start, using bitwise comparison. michael@0: * @param srcChars The text to search for. michael@0: * @param srcLength the number of characters in srcChars to match michael@0: * @param start the offset into this at which to start matching michael@0: * @return The offset into this of the start of text, michael@0: * or -1 if not found. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline int32_t indexOf(const UChar *srcChars, michael@0: int32_t srcLength, michael@0: int32_t start) const; michael@0: michael@0: /** michael@0: * Locate in this the first occurrence in the range michael@0: * [start, start + length) of the characters michael@0: * in srcChars, using bitwise comparison. michael@0: * @param srcChars The text to search for. michael@0: * @param srcLength the number of characters in srcChars michael@0: * @param start The offset at which searching will start. michael@0: * @param length The number of characters to search michael@0: * @return The offset into this of the start of srcChars, michael@0: * or -1 if not found. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline int32_t indexOf(const UChar *srcChars, michael@0: int32_t srcLength, michael@0: int32_t start, michael@0: int32_t length) const; michael@0: michael@0: /** michael@0: * Locate in this the first occurrence in the range michael@0: * [start, start + length) of the characters michael@0: * in srcChars in the range michael@0: * [srcStart, srcStart + srcLength), michael@0: * using bitwise comparison. michael@0: * @param srcChars The text to search for. michael@0: * @param srcStart the offset into srcChars at which michael@0: * to start matching michael@0: * @param srcLength the number of characters in srcChars to match michael@0: * @param start the offset into this at which to start matching michael@0: * @param length the number of characters in this to search michael@0: * @return The offset into this of the start of text, michael@0: * or -1 if not found. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: int32_t indexOf(const UChar *srcChars, michael@0: int32_t srcStart, michael@0: int32_t srcLength, michael@0: int32_t start, michael@0: int32_t length) const; michael@0: michael@0: /** michael@0: * Locate in this the first occurrence of the BMP code point c, michael@0: * using bitwise comparison. michael@0: * @param c The code unit to search for. michael@0: * @return The offset into this of c, or -1 if not found. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline int32_t indexOf(UChar c) const; michael@0: michael@0: /** michael@0: * Locate in this the first occurrence of the code point c, michael@0: * using bitwise comparison. michael@0: * michael@0: * @param c The code point to search for. michael@0: * @return The offset into this of c, or -1 if not found. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline int32_t indexOf(UChar32 c) const; michael@0: michael@0: /** michael@0: * Locate in this the first occurrence of the BMP code point c, michael@0: * starting at offset start, using bitwise comparison. michael@0: * @param c The code unit to search for. michael@0: * @param start The offset at which searching will start. michael@0: * @return The offset into this of c, or -1 if not found. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline int32_t indexOf(UChar c, michael@0: int32_t start) const; michael@0: michael@0: /** michael@0: * Locate in this the first occurrence of the code point c michael@0: * starting at offset start, using bitwise comparison. michael@0: * michael@0: * @param c The code point to search for. michael@0: * @param start The offset at which searching will start. michael@0: * @return The offset into this of c, or -1 if not found. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline int32_t indexOf(UChar32 c, michael@0: int32_t start) const; michael@0: michael@0: /** michael@0: * Locate in this the first occurrence of the BMP code point c michael@0: * in the range [start, start + length), michael@0: * using bitwise comparison. michael@0: * @param c The code unit to search for. michael@0: * @param start the offset into this at which to start matching michael@0: * @param length the number of characters in this to search michael@0: * @return The offset into this of c, or -1 if not found. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline int32_t indexOf(UChar c, michael@0: int32_t start, michael@0: int32_t length) const; michael@0: michael@0: /** michael@0: * Locate in this the first occurrence of the code point c michael@0: * in the range [start, start + length), michael@0: * using bitwise comparison. michael@0: * michael@0: * @param c The code point to search for. michael@0: * @param start the offset into this at which to start matching michael@0: * @param length the number of characters in this to search michael@0: * @return The offset into this of c, or -1 if not found. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline int32_t indexOf(UChar32 c, michael@0: int32_t start, michael@0: int32_t length) const; michael@0: michael@0: /** michael@0: * Locate in this the last occurrence of the characters in text, michael@0: * using bitwise comparison. michael@0: * @param text The text to search for. michael@0: * @return The offset into this of the start of text, michael@0: * or -1 if not found. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline int32_t lastIndexOf(const UnicodeString& text) const; michael@0: michael@0: /** michael@0: * Locate in this the last occurrence of the characters in text michael@0: * starting at offset start, using bitwise comparison. michael@0: * @param text The text to search for. michael@0: * @param start The offset at which searching will start. michael@0: * @return The offset into this of the start of text, michael@0: * or -1 if not found. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline int32_t lastIndexOf(const UnicodeString& text, michael@0: int32_t start) const; michael@0: michael@0: /** michael@0: * Locate in this the last occurrence in the range michael@0: * [start, start + length) of the characters michael@0: * in text, using bitwise comparison. michael@0: * @param text The text to search for. michael@0: * @param start The offset at which searching will start. michael@0: * @param length The number of characters to search michael@0: * @return The offset into this of the start of text, michael@0: * or -1 if not found. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline int32_t lastIndexOf(const UnicodeString& text, michael@0: int32_t start, michael@0: int32_t length) const; michael@0: michael@0: /** michael@0: * Locate in this the last occurrence in the range michael@0: * [start, start + length) of the characters michael@0: * in srcText in the range michael@0: * [srcStart, srcStart + srcLength), michael@0: * using bitwise comparison. michael@0: * @param srcText The text to search for. michael@0: * @param srcStart the offset into srcText at which michael@0: * to start matching michael@0: * @param srcLength the number of characters in srcText to match michael@0: * @param start the offset into this at which to start matching michael@0: * @param length the number of characters in this to search michael@0: * @return The offset into this of the start of text, michael@0: * or -1 if not found. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline int32_t lastIndexOf(const UnicodeString& srcText, michael@0: int32_t srcStart, michael@0: int32_t srcLength, michael@0: int32_t start, michael@0: int32_t length) const; michael@0: michael@0: /** michael@0: * Locate in this the last occurrence of the characters in srcChars michael@0: * starting at offset start, using bitwise comparison. michael@0: * @param srcChars The text to search for. michael@0: * @param srcLength the number of characters in srcChars to match michael@0: * @param start the offset into this at which to start matching michael@0: * @return The offset into this of the start of text, michael@0: * or -1 if not found. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline int32_t lastIndexOf(const UChar *srcChars, michael@0: int32_t srcLength, michael@0: int32_t start) const; michael@0: michael@0: /** michael@0: * Locate in this the last occurrence in the range michael@0: * [start, start + length) of the characters michael@0: * in srcChars, using bitwise comparison. michael@0: * @param srcChars The text to search for. michael@0: * @param srcLength the number of characters in srcChars michael@0: * @param start The offset at which searching will start. michael@0: * @param length The number of characters to search michael@0: * @return The offset into this of the start of srcChars, michael@0: * or -1 if not found. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline int32_t lastIndexOf(const UChar *srcChars, michael@0: int32_t srcLength, michael@0: int32_t start, michael@0: int32_t length) const; michael@0: michael@0: /** michael@0: * Locate in this the last occurrence in the range michael@0: * [start, start + length) of the characters michael@0: * in srcChars in the range michael@0: * [srcStart, srcStart + srcLength), michael@0: * using bitwise comparison. michael@0: * @param srcChars The text to search for. michael@0: * @param srcStart the offset into srcChars at which michael@0: * to start matching michael@0: * @param srcLength the number of characters in srcChars to match michael@0: * @param start the offset into this at which to start matching michael@0: * @param length the number of characters in this to search michael@0: * @return The offset into this of the start of text, michael@0: * or -1 if not found. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: int32_t lastIndexOf(const UChar *srcChars, michael@0: int32_t srcStart, michael@0: int32_t srcLength, michael@0: int32_t start, michael@0: int32_t length) const; michael@0: michael@0: /** michael@0: * Locate in this the last occurrence of the BMP code point c, michael@0: * using bitwise comparison. michael@0: * @param c The code unit to search for. michael@0: * @return The offset into this of c, or -1 if not found. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline int32_t lastIndexOf(UChar c) const; michael@0: michael@0: /** michael@0: * Locate in this the last occurrence of the code point c, michael@0: * using bitwise comparison. michael@0: * michael@0: * @param c The code point to search for. michael@0: * @return The offset into this of c, or -1 if not found. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline int32_t lastIndexOf(UChar32 c) const; michael@0: michael@0: /** michael@0: * Locate in this the last occurrence of the BMP code point c michael@0: * starting at offset start, using bitwise comparison. michael@0: * @param c The code unit to search for. michael@0: * @param start The offset at which searching will start. michael@0: * @return The offset into this of c, or -1 if not found. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline int32_t lastIndexOf(UChar c, michael@0: int32_t start) const; michael@0: michael@0: /** michael@0: * Locate in this the last occurrence of the code point c michael@0: * starting at offset start, using bitwise comparison. michael@0: * michael@0: * @param c The code point to search for. michael@0: * @param start The offset at which searching will start. michael@0: * @return The offset into this of c, or -1 if not found. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline int32_t lastIndexOf(UChar32 c, michael@0: int32_t start) const; michael@0: michael@0: /** michael@0: * Locate in this the last occurrence of the BMP code point c michael@0: * in the range [start, start + length), michael@0: * using bitwise comparison. michael@0: * @param c The code unit to search for. michael@0: * @param start the offset into this at which to start matching michael@0: * @param length the number of characters in this to search michael@0: * @return The offset into this of c, or -1 if not found. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline int32_t lastIndexOf(UChar c, michael@0: int32_t start, michael@0: int32_t length) const; michael@0: michael@0: /** michael@0: * Locate in this the last occurrence of the code point c michael@0: * in the range [start, start + length), michael@0: * using bitwise comparison. michael@0: * michael@0: * @param c The code point to search for. michael@0: * @param start the offset into this at which to start matching michael@0: * @param length the number of characters in this to search michael@0: * @return The offset into this of c, or -1 if not found. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline int32_t lastIndexOf(UChar32 c, michael@0: int32_t start, michael@0: int32_t length) const; michael@0: michael@0: michael@0: /* Character access */ michael@0: michael@0: /** michael@0: * Return the code unit at offset offset. michael@0: * If the offset is not valid (0..length()-1) then U+ffff is returned. michael@0: * @param offset a valid offset into the text michael@0: * @return the code unit at offset offset michael@0: * or 0xffff if the offset is not valid for this string michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline UChar charAt(int32_t offset) const; michael@0: michael@0: /** michael@0: * Return the code unit at offset offset. michael@0: * If the offset is not valid (0..length()-1) then U+ffff is returned. michael@0: * @param offset a valid offset into the text michael@0: * @return the code unit at offset offset michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline UChar operator[] (int32_t offset) const; michael@0: michael@0: /** michael@0: * Return the code point that contains the code unit michael@0: * at offset offset. michael@0: * If the offset is not valid (0..length()-1) then U+ffff is returned. michael@0: * @param offset a valid offset into the text michael@0: * that indicates the text offset of any of the code units michael@0: * that will be assembled into a code point (21-bit value) and returned michael@0: * @return the code point of text at offset michael@0: * or 0xffff if the offset is not valid for this string michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UChar32 char32At(int32_t offset) const; michael@0: michael@0: /** michael@0: * Adjust a random-access offset so that michael@0: * it points to the beginning of a Unicode character. michael@0: * The offset that is passed in points to michael@0: * any code unit of a code point, michael@0: * while the returned offset will point to the first code unit michael@0: * of the same code point. michael@0: * In UTF-16, if the input offset points to a second surrogate michael@0: * of a surrogate pair, then the returned offset will point michael@0: * to the first surrogate. michael@0: * @param offset a valid offset into one code point of the text michael@0: * @return offset of the first code unit of the same code point michael@0: * @see U16_SET_CP_START michael@0: * @stable ICU 2.0 michael@0: */ michael@0: int32_t getChar32Start(int32_t offset) const; michael@0: michael@0: /** michael@0: * Adjust a random-access offset so that michael@0: * it points behind a Unicode character. michael@0: * The offset that is passed in points behind michael@0: * any code unit of a code point, michael@0: * while the returned offset will point behind the last code unit michael@0: * of the same code point. michael@0: * In UTF-16, if the input offset points behind the first surrogate michael@0: * (i.e., to the second surrogate) michael@0: * of a surrogate pair, then the returned offset will point michael@0: * behind the second surrogate (i.e., to the first surrogate). michael@0: * @param offset a valid offset after any code unit of a code point of the text michael@0: * @return offset of the first code unit after the same code point michael@0: * @see U16_SET_CP_LIMIT michael@0: * @stable ICU 2.0 michael@0: */ michael@0: int32_t getChar32Limit(int32_t offset) const; michael@0: michael@0: /** michael@0: * Move the code unit index along the string by delta code points. michael@0: * Interpret the input index as a code unit-based offset into the string, michael@0: * move the index forward or backward by delta code points, and michael@0: * return the resulting index. michael@0: * The input index should point to the first code unit of a code point, michael@0: * if there is more than one. michael@0: * michael@0: * Both input and output indexes are code unit-based as for all michael@0: * string indexes/offsets in ICU (and other libraries, like MBCS char*). michael@0: * If delta<0 then the index is moved backward (toward the start of the string). michael@0: * If delta>0 then the index is moved forward (toward the end of the string). michael@0: * michael@0: * This behaves like CharacterIterator::move32(delta, kCurrent). michael@0: * michael@0: * Behavior for out-of-bounds indexes: michael@0: * moveIndex32 pins the input index to 0..length(), i.e., michael@0: * if the input index<0 then it is pinned to 0; michael@0: * if it is index>length() then it is pinned to length(). michael@0: * Afterwards, the index is moved by delta code points michael@0: * forward or backward, michael@0: * but no further backward than to 0 and no further forward than to length(). michael@0: * The resulting index return value will be in between 0 and length(), inclusively. michael@0: * michael@0: * Examples: michael@0: *
michael@0:    * // s has code points 'a' U+10000 'b' U+10ffff U+2029
michael@0:    * UnicodeString s=UNICODE_STRING("a\\U00010000b\\U0010ffff\\u2029", 31).unescape();
michael@0:    *
michael@0:    * // initial index: position of U+10000
michael@0:    * int32_t index=1;
michael@0:    *
michael@0:    * // the following examples will all result in index==4, position of U+10ffff
michael@0:    *
michael@0:    * // skip 2 code points from some position in the string
michael@0:    * index=s.moveIndex32(index, 2); // skips U+10000 and 'b'
michael@0:    *
michael@0:    * // go to the 3rd code point from the start of s (0-based)
michael@0:    * index=s.moveIndex32(0, 3); // skips 'a', U+10000, and 'b'
michael@0:    *
michael@0:    * // go to the next-to-last code point of s
michael@0:    * index=s.moveIndex32(s.length(), -2); // backward-skips U+2029 and U+10ffff
michael@0:    * 
michael@0: * michael@0: * @param index input code unit index michael@0: * @param delta (signed) code point count to move the index forward or backward michael@0: * in the string michael@0: * @return the resulting code unit index michael@0: * @stable ICU 2.0 michael@0: */ michael@0: int32_t moveIndex32(int32_t index, int32_t delta) const; michael@0: michael@0: /* Substring extraction */ michael@0: michael@0: /** michael@0: * Copy the characters in the range michael@0: * [start, start + length) into the array dst, michael@0: * beginning at dstStart. michael@0: * If the string aliases to dst itself as an external buffer, michael@0: * then extract() will not copy the contents. michael@0: * michael@0: * @param start offset of first character which will be copied into the array michael@0: * @param length the number of characters to extract michael@0: * @param dst array in which to copy characters. The length of dst michael@0: * must be at least (dstStart + length). michael@0: * @param dstStart the offset in dst where the first character michael@0: * will be extracted michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline void extract(int32_t start, michael@0: int32_t length, michael@0: UChar *dst, michael@0: int32_t dstStart = 0) const; michael@0: michael@0: /** michael@0: * Copy the contents of the string into dest. michael@0: * This is a convenience function that michael@0: * checks if there is enough space in dest, michael@0: * extracts the entire string if possible, michael@0: * and NUL-terminates dest if possible. michael@0: * michael@0: * If the string fits into dest but cannot be NUL-terminated michael@0: * (length()==destCapacity) then the error code is set to U_STRING_NOT_TERMINATED_WARNING. michael@0: * If the string itself does not fit into dest michael@0: * (length()>destCapacity) then the error code is set to U_BUFFER_OVERFLOW_ERROR. michael@0: * michael@0: * If the string aliases to dest itself as an external buffer, michael@0: * then extract() will not copy the contents. michael@0: * michael@0: * @param dest Destination string buffer. michael@0: * @param destCapacity Number of UChars available at dest. michael@0: * @param errorCode ICU error code. michael@0: * @return length() michael@0: * @stable ICU 2.0 michael@0: */ michael@0: int32_t michael@0: extract(UChar *dest, int32_t destCapacity, michael@0: UErrorCode &errorCode) const; michael@0: michael@0: /** michael@0: * Copy the characters in the range michael@0: * [start, start + length) into the UnicodeString michael@0: * target. michael@0: * @param start offset of first character which will be copied michael@0: * @param length the number of characters to extract michael@0: * @param target UnicodeString into which to copy characters. michael@0: * @return A reference to target michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline void extract(int32_t start, michael@0: int32_t length, michael@0: UnicodeString& target) const; michael@0: michael@0: /** michael@0: * Copy the characters in the range [start, limit) michael@0: * into the array dst, beginning at dstStart. michael@0: * @param start offset of first character which will be copied into the array michael@0: * @param limit offset immediately following the last character to be copied michael@0: * @param dst array in which to copy characters. The length of dst michael@0: * must be at least (dstStart + (limit - start)). michael@0: * @param dstStart the offset in dst where the first character michael@0: * will be extracted michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline void extractBetween(int32_t start, michael@0: int32_t limit, michael@0: UChar *dst, michael@0: int32_t dstStart = 0) const; michael@0: michael@0: /** michael@0: * Copy the characters in the range [start, limit) michael@0: * into the UnicodeString target. Replaceable API. michael@0: * @param start offset of first character which will be copied michael@0: * @param limit offset immediately following the last character to be copied michael@0: * @param target UnicodeString into which to copy characters. michael@0: * @return A reference to target michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual void extractBetween(int32_t start, michael@0: int32_t limit, michael@0: UnicodeString& target) const; michael@0: michael@0: /** michael@0: * Copy the characters in the range michael@0: * [start, start + length) into an array of characters. michael@0: * All characters must be invariant (see utypes.h). michael@0: * Use US_INV as the last, signature-distinguishing parameter. michael@0: * michael@0: * This function does not write any more than targetLength michael@0: * characters but returns the length of the entire output string michael@0: * so that one can allocate a larger buffer and call the function again michael@0: * if necessary. michael@0: * The output string is NUL-terminated if possible. michael@0: * michael@0: * @param start offset of first character which will be copied michael@0: * @param startLength the number of characters to extract michael@0: * @param target the target buffer for extraction, can be NULL michael@0: * if targetLength is 0 michael@0: * @param targetCapacity the length of the target buffer michael@0: * @param inv Signature-distinguishing paramater, use US_INV. michael@0: * @return the output string length, not including the terminating NUL michael@0: * @stable ICU 3.2 michael@0: */ michael@0: int32_t extract(int32_t start, michael@0: int32_t startLength, michael@0: char *target, michael@0: int32_t targetCapacity, michael@0: enum EInvariant inv) const; michael@0: michael@0: #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION michael@0: michael@0: /** michael@0: * Copy the characters in the range michael@0: * [start, start + length) into an array of characters michael@0: * in the platform's default codepage. michael@0: * This function does not write any more than targetLength michael@0: * characters but returns the length of the entire output string michael@0: * so that one can allocate a larger buffer and call the function again michael@0: * if necessary. michael@0: * The output string is NUL-terminated if possible. michael@0: * michael@0: * @param start offset of first character which will be copied michael@0: * @param startLength the number of characters to extract michael@0: * @param target the target buffer for extraction michael@0: * @param targetLength the length of the target buffer michael@0: * If target is NULL, then the number of bytes required for michael@0: * target is returned. michael@0: * @return the output string length, not including the terminating NUL michael@0: * @stable ICU 2.0 michael@0: */ michael@0: int32_t extract(int32_t start, michael@0: int32_t startLength, michael@0: char *target, michael@0: uint32_t targetLength) const; michael@0: michael@0: #endif michael@0: michael@0: #if !UCONFIG_NO_CONVERSION michael@0: michael@0: /** michael@0: * Copy the characters in the range michael@0: * [start, start + length) into an array of characters michael@0: * in a specified codepage. michael@0: * The output string is NUL-terminated. michael@0: * michael@0: * Recommendation: For invariant-character strings use michael@0: * extract(int32_t start, int32_t length, char *target, int32_t targetCapacity, enum EInvariant inv) const michael@0: * because it avoids object code dependencies of UnicodeString on michael@0: * the conversion code. michael@0: * michael@0: * @param start offset of first character which will be copied michael@0: * @param startLength the number of characters to extract michael@0: * @param target the target buffer for extraction michael@0: * @param codepage the desired codepage for the characters. 0 has michael@0: * the special meaning of the default codepage michael@0: * If codepage is an empty string (""), michael@0: * then a simple conversion is performed on the codepage-invariant michael@0: * subset ("invariant characters") of the platform encoding. See utypes.h. michael@0: * If target is NULL, then the number of bytes required for michael@0: * target is returned. It is assumed that the target is big enough michael@0: * to fit all of the characters. michael@0: * @return the output string length, not including the terminating NUL michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline int32_t extract(int32_t start, michael@0: int32_t startLength, michael@0: char *target, michael@0: const char *codepage = 0) const; michael@0: michael@0: /** michael@0: * Copy the characters in the range michael@0: * [start, start + length) into an array of characters michael@0: * in a specified codepage. michael@0: * This function does not write any more than targetLength michael@0: * characters but returns the length of the entire output string michael@0: * so that one can allocate a larger buffer and call the function again michael@0: * if necessary. michael@0: * The output string is NUL-terminated if possible. michael@0: * michael@0: * Recommendation: For invariant-character strings use michael@0: * extract(int32_t start, int32_t length, char *target, int32_t targetCapacity, enum EInvariant inv) const michael@0: * because it avoids object code dependencies of UnicodeString on michael@0: * the conversion code. michael@0: * michael@0: * @param start offset of first character which will be copied michael@0: * @param startLength the number of characters to extract michael@0: * @param target the target buffer for extraction michael@0: * @param targetLength the length of the target buffer michael@0: * @param codepage the desired codepage for the characters. 0 has michael@0: * the special meaning of the default codepage michael@0: * If codepage is an empty string (""), michael@0: * then a simple conversion is performed on the codepage-invariant michael@0: * subset ("invariant characters") of the platform encoding. See utypes.h. michael@0: * If target is NULL, then the number of bytes required for michael@0: * target is returned. michael@0: * @return the output string length, not including the terminating NUL michael@0: * @stable ICU 2.0 michael@0: */ michael@0: int32_t extract(int32_t start, michael@0: int32_t startLength, michael@0: char *target, michael@0: uint32_t targetLength, michael@0: const char *codepage) const; michael@0: michael@0: /** michael@0: * Convert the UnicodeString into a codepage string using an existing UConverter. michael@0: * The output string is NUL-terminated if possible. michael@0: * michael@0: * This function avoids the overhead of opening and closing a converter if michael@0: * multiple strings are extracted. michael@0: * michael@0: * @param dest destination string buffer, can be NULL if destCapacity==0 michael@0: * @param destCapacity the number of chars available at dest michael@0: * @param cnv the converter object to be used (ucnv_resetFromUnicode() will be called), michael@0: * or NULL for the default converter michael@0: * @param errorCode normal ICU error code michael@0: * @return the length of the output string, not counting the terminating NUL; michael@0: * if the length is greater than destCapacity, then the string will not fit michael@0: * and a buffer of the indicated length would need to be passed in michael@0: * @stable ICU 2.0 michael@0: */ michael@0: int32_t extract(char *dest, int32_t destCapacity, michael@0: UConverter *cnv, michael@0: UErrorCode &errorCode) const; michael@0: michael@0: #endif michael@0: michael@0: /** michael@0: * Create a temporary substring for the specified range. michael@0: * Unlike the substring constructor and setTo() functions, michael@0: * the object returned here will be a read-only alias (using getBuffer()) michael@0: * rather than copying the text. michael@0: * As a result, this substring operation is much faster but requires michael@0: * that the original string not be modified or deleted during the lifetime michael@0: * of the returned substring object. michael@0: * @param start offset of the first character visible in the substring michael@0: * @param length length of the substring michael@0: * @return a read-only alias UnicodeString object for the substring michael@0: * @stable ICU 4.4 michael@0: */ michael@0: UnicodeString tempSubString(int32_t start=0, int32_t length=INT32_MAX) const; michael@0: michael@0: /** michael@0: * Create a temporary substring for the specified range. michael@0: * Same as tempSubString(start, length) except that the substring range michael@0: * is specified as a (start, limit) pair (with an exclusive limit index) michael@0: * rather than a (start, length) pair. michael@0: * @param start offset of the first character visible in the substring michael@0: * @param limit offset immediately following the last character visible in the substring michael@0: * @return a read-only alias UnicodeString object for the substring michael@0: * @stable ICU 4.4 michael@0: */ michael@0: inline UnicodeString tempSubStringBetween(int32_t start, int32_t limit=INT32_MAX) const; michael@0: michael@0: /** michael@0: * Convert the UnicodeString to UTF-8 and write the result michael@0: * to a ByteSink. This is called by toUTF8String(). michael@0: * Unpaired surrogates are replaced with U+FFFD. michael@0: * Calls u_strToUTF8WithSub(). michael@0: * michael@0: * @param sink A ByteSink to which the UTF-8 version of the string is written. michael@0: * sink.Flush() is called at the end. michael@0: * @stable ICU 4.2 michael@0: * @see toUTF8String michael@0: */ michael@0: void toUTF8(ByteSink &sink) const; michael@0: michael@0: #if U_HAVE_STD_STRING michael@0: michael@0: /** michael@0: * Convert the UnicodeString to UTF-8 and append the result michael@0: * to a standard string. michael@0: * Unpaired surrogates are replaced with U+FFFD. michael@0: * Calls toUTF8(). michael@0: * michael@0: * @param result A standard string (or a compatible object) michael@0: * to which the UTF-8 version of the string is appended. michael@0: * @return The string object. michael@0: * @stable ICU 4.2 michael@0: * @see toUTF8 michael@0: */ michael@0: template michael@0: StringClass &toUTF8String(StringClass &result) const { michael@0: StringByteSink sbs(&result); michael@0: toUTF8(sbs); michael@0: return result; michael@0: } michael@0: michael@0: #endif michael@0: michael@0: /** michael@0: * Convert the UnicodeString to UTF-32. michael@0: * Unpaired surrogates are replaced with U+FFFD. michael@0: * Calls u_strToUTF32WithSub(). michael@0: * michael@0: * @param utf32 destination string buffer, can be NULL if capacity==0 michael@0: * @param capacity the number of UChar32s available at utf32 michael@0: * @param errorCode Standard ICU error code. Its input value must michael@0: * pass the U_SUCCESS() test, or else the function returns michael@0: * immediately. Check for U_FAILURE() on output or use with michael@0: * function chaining. (See User Guide for details.) michael@0: * @return The length of the UTF-32 string. michael@0: * @see fromUTF32 michael@0: * @stable ICU 4.2 michael@0: */ michael@0: int32_t toUTF32(UChar32 *utf32, int32_t capacity, UErrorCode &errorCode) const; michael@0: michael@0: /* Length operations */ michael@0: michael@0: /** michael@0: * Return the length of the UnicodeString object. michael@0: * The length is the number of UChar code units are in the UnicodeString. michael@0: * If you want the number of code points, please use countChar32(). michael@0: * @return the length of the UnicodeString object michael@0: * @see countChar32 michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline int32_t length(void) const; michael@0: michael@0: /** michael@0: * Count Unicode code points in the length UChar code units of the string. michael@0: * A code point may occupy either one or two UChar code units. michael@0: * Counting code points involves reading all code units. michael@0: * michael@0: * This functions is basically the inverse of moveIndex32(). michael@0: * michael@0: * @param start the index of the first code unit to check michael@0: * @param length the number of UChar code units to check michael@0: * @return the number of code points in the specified code units michael@0: * @see length michael@0: * @stable ICU 2.0 michael@0: */ michael@0: int32_t michael@0: countChar32(int32_t start=0, int32_t length=INT32_MAX) const; michael@0: michael@0: /** michael@0: * Check if the length UChar code units of the string michael@0: * contain more Unicode code points than a certain number. michael@0: * This is more efficient than counting all code points in this part of the string michael@0: * and comparing that number with a threshold. michael@0: * This function may not need to scan the string at all if the length michael@0: * falls within a certain range, and michael@0: * never needs to count more than 'number+1' code points. michael@0: * Logically equivalent to (countChar32(start, length)>number). michael@0: * A Unicode code point may occupy either one or two UChar code units. michael@0: * michael@0: * @param start the index of the first code unit to check (0 for the entire string) michael@0: * @param length the number of UChar code units to check michael@0: * (use INT32_MAX for the entire string; remember that start/length michael@0: * values are pinned) michael@0: * @param number The number of code points in the (sub)string is compared against michael@0: * the 'number' parameter. michael@0: * @return Boolean value for whether the string contains more Unicode code points michael@0: * than 'number'. Same as (u_countChar32(s, length)>number). michael@0: * @see countChar32 michael@0: * @see u_strHasMoreChar32Than michael@0: * @stable ICU 2.4 michael@0: */ michael@0: UBool michael@0: hasMoreChar32Than(int32_t start, int32_t length, int32_t number) const; michael@0: michael@0: /** michael@0: * Determine if this string is empty. michael@0: * @return TRUE if this string contains 0 characters, FALSE otherwise. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline UBool isEmpty(void) const; michael@0: michael@0: /** michael@0: * Return the capacity of the internal buffer of the UnicodeString object. michael@0: * This is useful together with the getBuffer functions. michael@0: * See there for details. michael@0: * michael@0: * @return the number of UChars available in the internal buffer michael@0: * @see getBuffer michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline int32_t getCapacity(void) const; michael@0: michael@0: /* Other operations */ michael@0: michael@0: /** michael@0: * Generate a hash code for this object. michael@0: * @return The hash code of this UnicodeString. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline int32_t hashCode(void) const; michael@0: michael@0: /** michael@0: * Determine if this object contains a valid string. michael@0: * A bogus string has no value. It is different from an empty string, michael@0: * although in both cases isEmpty() returns TRUE and length() returns 0. michael@0: * setToBogus() and isBogus() can be used to indicate that no string value is available. michael@0: * For a bogus string, getBuffer() and getTerminatedBuffer() return NULL, and michael@0: * length() returns 0. michael@0: * michael@0: * @return TRUE if the string is bogus/invalid, FALSE otherwise michael@0: * @see setToBogus() michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline UBool isBogus(void) const; michael@0: michael@0: michael@0: //======================================== michael@0: // Write operations michael@0: //======================================== michael@0: michael@0: /* Assignment operations */ michael@0: michael@0: /** michael@0: * Assignment operator. Replace the characters in this UnicodeString michael@0: * with the characters from srcText. michael@0: * @param srcText The text containing the characters to replace michael@0: * @return a reference to this michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UnicodeString &operator=(const UnicodeString &srcText); michael@0: michael@0: /** michael@0: * Almost the same as the assignment operator. michael@0: * Replace the characters in this UnicodeString michael@0: * with the characters from srcText. michael@0: * michael@0: * This function works the same as the assignment operator michael@0: * for all strings except for ones that are readonly aliases. michael@0: * michael@0: * Starting with ICU 2.4, the assignment operator and the copy constructor michael@0: * allocate a new buffer and copy the buffer contents even for readonly aliases. michael@0: * This function implements the old, more efficient but less safe behavior michael@0: * of making this string also a readonly alias to the same buffer. michael@0: * michael@0: * The fastCopyFrom function must be used only if it is known that the lifetime of michael@0: * this UnicodeString does not exceed the lifetime of the aliased buffer michael@0: * including its contents, for example for strings from resource bundles michael@0: * or aliases to string constants. michael@0: * michael@0: * @param src The text containing the characters to replace. michael@0: * @return a reference to this michael@0: * @stable ICU 2.4 michael@0: */ michael@0: UnicodeString &fastCopyFrom(const UnicodeString &src); michael@0: michael@0: /** michael@0: * Assignment operator. Replace the characters in this UnicodeString michael@0: * with the code unit ch. michael@0: * @param ch the code unit to replace michael@0: * @return a reference to this michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline UnicodeString& operator= (UChar ch); michael@0: michael@0: /** michael@0: * Assignment operator. Replace the characters in this UnicodeString michael@0: * with the code point ch. michael@0: * @param ch the code point to replace michael@0: * @return a reference to this michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline UnicodeString& operator= (UChar32 ch); michael@0: michael@0: /** michael@0: * Set the text in the UnicodeString object to the characters michael@0: * in srcText in the range michael@0: * [srcStart, srcText.length()). michael@0: * srcText is not modified. michael@0: * @param srcText the source for the new characters michael@0: * @param srcStart the offset into srcText where new characters michael@0: * will be obtained michael@0: * @return a reference to this michael@0: * @stable ICU 2.2 michael@0: */ michael@0: inline UnicodeString& setTo(const UnicodeString& srcText, michael@0: int32_t srcStart); michael@0: michael@0: /** michael@0: * Set the text in the UnicodeString object to the characters michael@0: * in srcText in the range michael@0: * [srcStart, srcStart + srcLength). michael@0: * srcText is not modified. michael@0: * @param srcText the source for the new characters michael@0: * @param srcStart the offset into srcText where new characters michael@0: * will be obtained michael@0: * @param srcLength the number of characters in srcText in the michael@0: * replace string. michael@0: * @return a reference to this michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline UnicodeString& setTo(const UnicodeString& srcText, michael@0: int32_t srcStart, michael@0: int32_t srcLength); michael@0: michael@0: /** michael@0: * Set the text in the UnicodeString object to the characters in michael@0: * srcText. michael@0: * srcText is not modified. michael@0: * @param srcText the source for the new characters michael@0: * @return a reference to this michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline UnicodeString& setTo(const UnicodeString& srcText); michael@0: michael@0: /** michael@0: * Set the characters in the UnicodeString object to the characters michael@0: * in srcChars. srcChars is not modified. michael@0: * @param srcChars the source for the new characters michael@0: * @param srcLength the number of Unicode characters in srcChars. michael@0: * @return a reference to this michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline UnicodeString& setTo(const UChar *srcChars, michael@0: int32_t srcLength); michael@0: michael@0: /** michael@0: * Set the characters in the UnicodeString object to the code unit michael@0: * srcChar. michael@0: * @param srcChar the code unit which becomes the UnicodeString's character michael@0: * content michael@0: * @return a reference to this michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UnicodeString& setTo(UChar srcChar); michael@0: michael@0: /** michael@0: * Set the characters in the UnicodeString object to the code point michael@0: * srcChar. michael@0: * @param srcChar the code point which becomes the UnicodeString's character michael@0: * content michael@0: * @return a reference to this michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UnicodeString& setTo(UChar32 srcChar); michael@0: michael@0: /** michael@0: * Aliasing setTo() function, analogous to the readonly-aliasing UChar* constructor. michael@0: * The text will be used for the UnicodeString object, but michael@0: * it will not be released when the UnicodeString is destroyed. michael@0: * This has copy-on-write semantics: michael@0: * When the string is modified, then the buffer is first copied into michael@0: * newly allocated memory. michael@0: * The aliased buffer is never modified. michael@0: * michael@0: * In an assignment to another UnicodeString, when using the copy constructor michael@0: * or the assignment operator, the text will be copied. michael@0: * When using fastCopyFrom(), the text will be aliased again, michael@0: * so that both strings then alias the same readonly-text. michael@0: * michael@0: * @param isTerminated specifies if text is NUL-terminated. michael@0: * This must be true if textLength==-1. michael@0: * @param text The characters to alias for the UnicodeString. michael@0: * @param textLength The number of Unicode characters in text to alias. michael@0: * If -1, then this constructor will determine the length michael@0: * by calling u_strlen(). michael@0: * @return a reference to this michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UnicodeString &setTo(UBool isTerminated, michael@0: const UChar *text, michael@0: int32_t textLength); michael@0: michael@0: /** michael@0: * Aliasing setTo() function, analogous to the writable-aliasing UChar* constructor. michael@0: * The text will be used for the UnicodeString object, but michael@0: * it will not be released when the UnicodeString is destroyed. michael@0: * This has write-through semantics: michael@0: * For as long as the capacity of the buffer is sufficient, write operations michael@0: * will directly affect the buffer. When more capacity is necessary, then michael@0: * a new buffer will be allocated and the contents copied as with regularly michael@0: * constructed strings. michael@0: * In an assignment to another UnicodeString, the buffer will be copied. michael@0: * The extract(UChar *dst) function detects whether the dst pointer is the same michael@0: * as the string buffer itself and will in this case not copy the contents. michael@0: * michael@0: * @param buffer The characters to alias for the UnicodeString. michael@0: * @param buffLength The number of Unicode characters in buffer to alias. michael@0: * @param buffCapacity The size of buffer in UChars. michael@0: * @return a reference to this michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UnicodeString &setTo(UChar *buffer, michael@0: int32_t buffLength, michael@0: int32_t buffCapacity); michael@0: michael@0: /** michael@0: * Make this UnicodeString object invalid. michael@0: * The string will test TRUE with isBogus(). michael@0: * michael@0: * A bogus string has no value. It is different from an empty string. michael@0: * It can be used to indicate that no string value is available. michael@0: * getBuffer() and getTerminatedBuffer() return NULL, and michael@0: * length() returns 0. michael@0: * michael@0: * This utility function is used throughout the UnicodeString michael@0: * implementation to indicate that a UnicodeString operation failed, michael@0: * and may be used in other functions, michael@0: * especially but not exclusively when such functions do not michael@0: * take a UErrorCode for simplicity. michael@0: * michael@0: * The following methods, and no others, will clear a string object's bogus flag: michael@0: * - remove() michael@0: * - remove(0, INT32_MAX) michael@0: * - truncate(0) michael@0: * - operator=() (assignment operator) michael@0: * - setTo(...) michael@0: * michael@0: * The simplest ways to turn a bogus string into an empty one michael@0: * is to use the remove() function. michael@0: * Examples for other functions that are equivalent to "set to empty string": michael@0: * \code michael@0: * if(s.isBogus()) { michael@0: * s.remove(); // set to an empty string (remove all), or michael@0: * s.remove(0, INT32_MAX); // set to an empty string (remove all), or michael@0: * s.truncate(0); // set to an empty string (complete truncation), or michael@0: * s=UnicodeString(); // assign an empty string, or michael@0: * s.setTo((UChar32)-1); // set to a pseudo code point that is out of range, or michael@0: * static const UChar nul=0; michael@0: * s.setTo(&nul, 0); // set to an empty C Unicode string michael@0: * } michael@0: * \endcode michael@0: * michael@0: * @see isBogus() michael@0: * @stable ICU 2.0 michael@0: */ michael@0: void setToBogus(); michael@0: michael@0: /** michael@0: * Set the character at the specified offset to the specified character. michael@0: * @param offset A valid offset into the text of the character to set michael@0: * @param ch The new character michael@0: * @return A reference to this michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UnicodeString& setCharAt(int32_t offset, michael@0: UChar ch); michael@0: michael@0: michael@0: /* Append operations */ michael@0: michael@0: /** michael@0: * Append operator. Append the code unit ch to the UnicodeString michael@0: * object. michael@0: * @param ch the code unit to be appended michael@0: * @return a reference to this michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline UnicodeString& operator+= (UChar ch); michael@0: michael@0: /** michael@0: * Append operator. Append the code point ch to the UnicodeString michael@0: * object. michael@0: * @param ch the code point to be appended michael@0: * @return a reference to this michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline UnicodeString& operator+= (UChar32 ch); michael@0: michael@0: /** michael@0: * Append operator. Append the characters in srcText to the michael@0: * UnicodeString object. srcText is not modified. michael@0: * @param srcText the source for the new characters michael@0: * @return a reference to this michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline UnicodeString& operator+= (const UnicodeString& srcText); michael@0: michael@0: /** michael@0: * Append the characters michael@0: * in srcText in the range michael@0: * [srcStart, srcStart + srcLength) to the michael@0: * UnicodeString object at offset start. srcText michael@0: * is not modified. michael@0: * @param srcText the source for the new characters michael@0: * @param srcStart the offset into srcText where new characters michael@0: * will be obtained michael@0: * @param srcLength the number of characters in srcText in michael@0: * the append string michael@0: * @return a reference to this michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline UnicodeString& append(const UnicodeString& srcText, michael@0: int32_t srcStart, michael@0: int32_t srcLength); michael@0: michael@0: /** michael@0: * Append the characters in srcText to the UnicodeString object. michael@0: * srcText is not modified. michael@0: * @param srcText the source for the new characters michael@0: * @return a reference to this michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline UnicodeString& append(const UnicodeString& srcText); michael@0: michael@0: /** michael@0: * Append the characters in srcChars in the range michael@0: * [srcStart, srcStart + srcLength) to the UnicodeString michael@0: * object at offset michael@0: * start. srcChars is not modified. michael@0: * @param srcChars the source for the new characters michael@0: * @param srcStart the offset into srcChars where new characters michael@0: * will be obtained michael@0: * @param srcLength the number of characters in srcChars in michael@0: * the append string; can be -1 if srcChars is NUL-terminated michael@0: * @return a reference to this michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline UnicodeString& append(const UChar *srcChars, michael@0: int32_t srcStart, michael@0: int32_t srcLength); michael@0: michael@0: /** michael@0: * Append the characters in srcChars to the UnicodeString object michael@0: * at offset start. srcChars is not modified. michael@0: * @param srcChars the source for the new characters michael@0: * @param srcLength the number of Unicode characters in srcChars; michael@0: * can be -1 if srcChars is NUL-terminated michael@0: * @return a reference to this michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline UnicodeString& append(const UChar *srcChars, michael@0: int32_t srcLength); michael@0: michael@0: /** michael@0: * Append the code unit srcChar to the UnicodeString object. michael@0: * @param srcChar the code unit to append michael@0: * @return a reference to this michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline UnicodeString& append(UChar srcChar); michael@0: michael@0: /** michael@0: * Append the code point srcChar to the UnicodeString object. michael@0: * @param srcChar the code point to append michael@0: * @return a reference to this michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UnicodeString& append(UChar32 srcChar); michael@0: michael@0: michael@0: /* Insert operations */ michael@0: michael@0: /** michael@0: * Insert the characters in srcText in the range michael@0: * [srcStart, srcStart + srcLength) into the UnicodeString michael@0: * object at offset start. srcText is not modified. michael@0: * @param start the offset where the insertion begins michael@0: * @param srcText the source for the new characters michael@0: * @param srcStart the offset into srcText where new characters michael@0: * will be obtained michael@0: * @param srcLength the number of characters in srcText in michael@0: * the insert string michael@0: * @return a reference to this michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline UnicodeString& insert(int32_t start, michael@0: const UnicodeString& srcText, michael@0: int32_t srcStart, michael@0: int32_t srcLength); michael@0: michael@0: /** michael@0: * Insert the characters in srcText into the UnicodeString object michael@0: * at offset start. srcText is not modified. michael@0: * @param start the offset where the insertion begins michael@0: * @param srcText the source for the new characters michael@0: * @return a reference to this michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline UnicodeString& insert(int32_t start, michael@0: const UnicodeString& srcText); michael@0: michael@0: /** michael@0: * Insert the characters in srcChars in the range michael@0: * [srcStart, srcStart + srcLength) into the UnicodeString michael@0: * object at offset start. srcChars is not modified. michael@0: * @param start the offset at which the insertion begins michael@0: * @param srcChars the source for the new characters michael@0: * @param srcStart the offset into srcChars where new characters michael@0: * will be obtained michael@0: * @param srcLength the number of characters in srcChars michael@0: * in the insert string michael@0: * @return a reference to this michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline UnicodeString& insert(int32_t start, michael@0: const UChar *srcChars, michael@0: int32_t srcStart, michael@0: int32_t srcLength); michael@0: michael@0: /** michael@0: * Insert the characters in srcChars into the UnicodeString object michael@0: * at offset start. srcChars is not modified. michael@0: * @param start the offset where the insertion begins michael@0: * @param srcChars the source for the new characters michael@0: * @param srcLength the number of Unicode characters in srcChars. michael@0: * @return a reference to this michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline UnicodeString& insert(int32_t start, michael@0: const UChar *srcChars, michael@0: int32_t srcLength); michael@0: michael@0: /** michael@0: * Insert the code unit srcChar into the UnicodeString object at michael@0: * offset start. michael@0: * @param start the offset at which the insertion occurs michael@0: * @param srcChar the code unit to insert michael@0: * @return a reference to this michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline UnicodeString& insert(int32_t start, michael@0: UChar srcChar); michael@0: michael@0: /** michael@0: * Insert the code point srcChar into the UnicodeString object at michael@0: * offset start. michael@0: * @param start the offset at which the insertion occurs michael@0: * @param srcChar the code point to insert michael@0: * @return a reference to this michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline UnicodeString& insert(int32_t start, michael@0: UChar32 srcChar); michael@0: michael@0: michael@0: /* Replace operations */ michael@0: michael@0: /** michael@0: * Replace the characters in the range michael@0: * [start, start + length) with the characters in michael@0: * srcText in the range michael@0: * [srcStart, srcStart + srcLength). michael@0: * srcText is not modified. michael@0: * @param start the offset at which the replace operation begins michael@0: * @param length the number of characters to replace. The character at michael@0: * start + length is not modified. michael@0: * @param srcText the source for the new characters michael@0: * @param srcStart the offset into srcText where new characters michael@0: * will be obtained michael@0: * @param srcLength the number of characters in srcText in michael@0: * the replace string michael@0: * @return a reference to this michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UnicodeString& replace(int32_t start, michael@0: int32_t length, michael@0: const UnicodeString& srcText, michael@0: int32_t srcStart, michael@0: int32_t srcLength); michael@0: michael@0: /** michael@0: * Replace the characters in the range michael@0: * [start, start + length) michael@0: * with the characters in srcText. srcText is michael@0: * not modified. michael@0: * @param start the offset at which the replace operation begins michael@0: * @param length the number of characters to replace. The character at michael@0: * start + length is not modified. michael@0: * @param srcText the source for the new characters michael@0: * @return a reference to this michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UnicodeString& replace(int32_t start, michael@0: int32_t length, michael@0: const UnicodeString& srcText); michael@0: michael@0: /** michael@0: * Replace the characters in the range michael@0: * [start, start + length) with the characters in michael@0: * srcChars in the range michael@0: * [srcStart, srcStart + srcLength). srcChars michael@0: * is not modified. michael@0: * @param start the offset at which the replace operation begins michael@0: * @param length the number of characters to replace. The character at michael@0: * start + length is not modified. michael@0: * @param srcChars the source for the new characters michael@0: * @param srcStart the offset into srcChars where new characters michael@0: * will be obtained michael@0: * @param srcLength the number of characters in srcChars michael@0: * in the replace string michael@0: * @return a reference to this michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UnicodeString& replace(int32_t start, michael@0: int32_t length, michael@0: const UChar *srcChars, michael@0: int32_t srcStart, michael@0: int32_t srcLength); michael@0: michael@0: /** michael@0: * Replace the characters in the range michael@0: * [start, start + length) with the characters in michael@0: * srcChars. srcChars is not modified. michael@0: * @param start the offset at which the replace operation begins michael@0: * @param length number of characters to replace. The character at michael@0: * start + length is not modified. michael@0: * @param srcChars the source for the new characters michael@0: * @param srcLength the number of Unicode characters in srcChars michael@0: * @return a reference to this michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline UnicodeString& replace(int32_t start, michael@0: int32_t length, michael@0: const UChar *srcChars, michael@0: int32_t srcLength); michael@0: michael@0: /** michael@0: * Replace the characters in the range michael@0: * [start, start + length) with the code unit michael@0: * srcChar. michael@0: * @param start the offset at which the replace operation begins michael@0: * @param length the number of characters to replace. The character at michael@0: * start + length is not modified. michael@0: * @param srcChar the new code unit michael@0: * @return a reference to this michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline UnicodeString& replace(int32_t start, michael@0: int32_t length, michael@0: UChar srcChar); michael@0: michael@0: /** michael@0: * Replace the characters in the range michael@0: * [start, start + length) with the code point michael@0: * srcChar. michael@0: * @param start the offset at which the replace operation begins michael@0: * @param length the number of characters to replace. The character at michael@0: * start + length is not modified. michael@0: * @param srcChar the new code point michael@0: * @return a reference to this michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UnicodeString& replace(int32_t start, int32_t length, UChar32 srcChar); michael@0: michael@0: /** michael@0: * Replace the characters in the range [start, limit) michael@0: * with the characters in srcText. srcText is not modified. michael@0: * @param start the offset at which the replace operation begins michael@0: * @param limit the offset immediately following the replace range michael@0: * @param srcText the source for the new characters michael@0: * @return a reference to this michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline UnicodeString& replaceBetween(int32_t start, michael@0: int32_t limit, michael@0: const UnicodeString& srcText); michael@0: michael@0: /** michael@0: * Replace the characters in the range [start, limit) michael@0: * with the characters in srcText in the range michael@0: * [srcStart, srcLimit). srcText is not modified. michael@0: * @param start the offset at which the replace operation begins michael@0: * @param limit the offset immediately following the replace range michael@0: * @param srcText the source for the new characters michael@0: * @param srcStart the offset into srcChars where new characters michael@0: * will be obtained michael@0: * @param srcLimit the offset immediately following the range to copy michael@0: * in srcText michael@0: * @return a reference to this michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline UnicodeString& replaceBetween(int32_t start, michael@0: int32_t limit, michael@0: const UnicodeString& srcText, michael@0: int32_t srcStart, michael@0: int32_t srcLimit); michael@0: michael@0: /** michael@0: * Replace a substring of this object with the given text. michael@0: * @param start the beginning index, inclusive; 0 <= start michael@0: * <= limit. michael@0: * @param limit the ending index, exclusive; start <= limit michael@0: * <= length(). michael@0: * @param text the text to replace characters start michael@0: * to limit - 1 michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual void handleReplaceBetween(int32_t start, michael@0: int32_t limit, michael@0: const UnicodeString& text); michael@0: michael@0: /** michael@0: * Replaceable API michael@0: * @return TRUE if it has MetaData michael@0: * @stable ICU 2.4 michael@0: */ michael@0: virtual UBool hasMetaData() const; michael@0: michael@0: /** michael@0: * Copy a substring of this object, retaining attribute (out-of-band) michael@0: * information. This method is used to duplicate or reorder substrings. michael@0: * The destination index must not overlap the source range. michael@0: * michael@0: * @param start the beginning index, inclusive; 0 <= start <= michael@0: * limit. michael@0: * @param limit the ending index, exclusive; start <= limit <= michael@0: * length(). michael@0: * @param dest the destination index. The characters from michael@0: * start..limit-1 will be copied to dest. michael@0: * Implementations of this method may assume that dest <= start || michael@0: * dest >= limit. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual void copy(int32_t start, int32_t limit, int32_t dest); michael@0: michael@0: /* Search and replace operations */ michael@0: michael@0: /** michael@0: * Replace all occurrences of characters in oldText with the characters michael@0: * in newText michael@0: * @param oldText the text containing the search text michael@0: * @param newText the text containing the replacement text michael@0: * @return a reference to this michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline UnicodeString& findAndReplace(const UnicodeString& oldText, michael@0: const UnicodeString& newText); michael@0: michael@0: /** michael@0: * Replace all occurrences of characters in oldText with characters michael@0: * in newText michael@0: * in the range [start, start + length). michael@0: * @param start the start of the range in which replace will performed michael@0: * @param length the length of the range in which replace will be performed michael@0: * @param oldText the text containing the search text michael@0: * @param newText the text containing the replacement text michael@0: * @return a reference to this michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline UnicodeString& findAndReplace(int32_t start, michael@0: int32_t length, michael@0: const UnicodeString& oldText, michael@0: const UnicodeString& newText); michael@0: michael@0: /** michael@0: * Replace all occurrences of characters in oldText in the range michael@0: * [oldStart, oldStart + oldLength) with the characters michael@0: * in newText in the range michael@0: * [newStart, newStart + newLength) michael@0: * in the range [start, start + length). michael@0: * @param start the start of the range in which replace will performed michael@0: * @param length the length of the range in which replace will be performed michael@0: * @param oldText the text containing the search text michael@0: * @param oldStart the start of the search range in oldText michael@0: * @param oldLength the length of the search range in oldText michael@0: * @param newText the text containing the replacement text michael@0: * @param newStart the start of the replacement range in newText michael@0: * @param newLength the length of the replacement range in newText michael@0: * @return a reference to this michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UnicodeString& findAndReplace(int32_t start, michael@0: int32_t length, michael@0: const UnicodeString& oldText, michael@0: int32_t oldStart, michael@0: int32_t oldLength, michael@0: const UnicodeString& newText, michael@0: int32_t newStart, michael@0: int32_t newLength); michael@0: michael@0: michael@0: /* Remove operations */ michael@0: michael@0: /** michael@0: * Remove all characters from the UnicodeString object. michael@0: * @return a reference to this michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline UnicodeString& remove(void); michael@0: michael@0: /** michael@0: * Remove the characters in the range michael@0: * [start, start + length) from the UnicodeString object. michael@0: * @param start the offset of the first character to remove michael@0: * @param length the number of characters to remove michael@0: * @return a reference to this michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline UnicodeString& remove(int32_t start, michael@0: int32_t length = (int32_t)INT32_MAX); michael@0: michael@0: /** michael@0: * Remove the characters in the range michael@0: * [start, limit) from the UnicodeString object. michael@0: * @param start the offset of the first character to remove michael@0: * @param limit the offset immediately following the range to remove michael@0: * @return a reference to this michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline UnicodeString& removeBetween(int32_t start, michael@0: int32_t limit = (int32_t)INT32_MAX); michael@0: michael@0: /** michael@0: * Retain only the characters in the range michael@0: * [start, limit) from the UnicodeString object. michael@0: * Removes characters before start and at and after limit. michael@0: * @param start the offset of the first character to retain michael@0: * @param limit the offset immediately following the range to retain michael@0: * @return a reference to this michael@0: * @stable ICU 4.4 michael@0: */ michael@0: inline UnicodeString &retainBetween(int32_t start, int32_t limit = INT32_MAX); michael@0: michael@0: /* Length operations */ michael@0: michael@0: /** michael@0: * Pad the start of this UnicodeString with the character padChar. michael@0: * If the length of this UnicodeString is less than targetLength, michael@0: * length() - targetLength copies of padChar will be added to the michael@0: * beginning of this UnicodeString. michael@0: * @param targetLength the desired length of the string michael@0: * @param padChar the character to use for padding. Defaults to michael@0: * space (U+0020) michael@0: * @return TRUE if the text was padded, FALSE otherwise. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UBool padLeading(int32_t targetLength, michael@0: UChar padChar = 0x0020); michael@0: michael@0: /** michael@0: * Pad the end of this UnicodeString with the character padChar. michael@0: * If the length of this UnicodeString is less than targetLength, michael@0: * length() - targetLength copies of padChar will be added to the michael@0: * end of this UnicodeString. michael@0: * @param targetLength the desired length of the string michael@0: * @param padChar the character to use for padding. Defaults to michael@0: * space (U+0020) michael@0: * @return TRUE if the text was padded, FALSE otherwise. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UBool padTrailing(int32_t targetLength, michael@0: UChar padChar = 0x0020); michael@0: michael@0: /** michael@0: * Truncate this UnicodeString to the targetLength. michael@0: * @param targetLength the desired length of this UnicodeString. michael@0: * @return TRUE if the text was truncated, FALSE otherwise michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline UBool truncate(int32_t targetLength); michael@0: michael@0: /** michael@0: * Trims leading and trailing whitespace from this UnicodeString. michael@0: * @return a reference to this michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UnicodeString& trim(void); michael@0: michael@0: michael@0: /* Miscellaneous operations */ michael@0: michael@0: /** michael@0: * Reverse this UnicodeString in place. michael@0: * @return a reference to this michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline UnicodeString& reverse(void); michael@0: michael@0: /** michael@0: * Reverse the range [start, start + length) in michael@0: * this UnicodeString. michael@0: * @param start the start of the range to reverse michael@0: * @param length the number of characters to to reverse michael@0: * @return a reference to this michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline UnicodeString& reverse(int32_t start, michael@0: int32_t length); michael@0: michael@0: /** michael@0: * Convert the characters in this to UPPER CASE following the conventions of michael@0: * the default locale. michael@0: * @return A reference to this. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UnicodeString& toUpper(void); michael@0: michael@0: /** michael@0: * Convert the characters in this to UPPER CASE following the conventions of michael@0: * a specific locale. michael@0: * @param locale The locale containing the conventions to use. michael@0: * @return A reference to this. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UnicodeString& toUpper(const Locale& locale); michael@0: michael@0: /** michael@0: * Convert the characters in this to lower case following the conventions of michael@0: * the default locale. michael@0: * @return A reference to this. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UnicodeString& toLower(void); michael@0: michael@0: /** michael@0: * Convert the characters in this to lower case following the conventions of michael@0: * a specific locale. michael@0: * @param locale The locale containing the conventions to use. michael@0: * @return A reference to this. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UnicodeString& toLower(const Locale& locale); michael@0: michael@0: #if !UCONFIG_NO_BREAK_ITERATION michael@0: michael@0: /** michael@0: * Titlecase this string, convenience function using the default locale. michael@0: * michael@0: * Casing is locale-dependent and context-sensitive. michael@0: * Titlecasing uses a break iterator to find the first characters of words michael@0: * that are to be titlecased. It titlecases those characters and lowercases michael@0: * all others. michael@0: * michael@0: * The titlecase break iterator can be provided to customize for arbitrary michael@0: * styles, using rules and dictionaries beyond the standard iterators. michael@0: * It may be more efficient to always provide an iterator to avoid michael@0: * opening and closing one for each string. michael@0: * The standard titlecase iterator for the root locale implements the michael@0: * algorithm of Unicode TR 21. michael@0: * michael@0: * This function uses only the setText(), first() and next() methods of the michael@0: * provided break iterator. michael@0: * michael@0: * @param titleIter A break iterator to find the first characters of words michael@0: * that are to be titlecased. michael@0: * If none is provided (0), then a standard titlecase michael@0: * break iterator is opened. michael@0: * Otherwise the provided iterator is set to the string's text. michael@0: * @return A reference to this. michael@0: * @stable ICU 2.1 michael@0: */ michael@0: UnicodeString &toTitle(BreakIterator *titleIter); michael@0: michael@0: /** michael@0: * Titlecase this string. michael@0: * michael@0: * Casing is locale-dependent and context-sensitive. michael@0: * Titlecasing uses a break iterator to find the first characters of words michael@0: * that are to be titlecased. It titlecases those characters and lowercases michael@0: * all others. michael@0: * michael@0: * The titlecase break iterator can be provided to customize for arbitrary michael@0: * styles, using rules and dictionaries beyond the standard iterators. michael@0: * It may be more efficient to always provide an iterator to avoid michael@0: * opening and closing one for each string. michael@0: * The standard titlecase iterator for the root locale implements the michael@0: * algorithm of Unicode TR 21. michael@0: * michael@0: * This function uses only the setText(), first() and next() methods of the michael@0: * provided break iterator. michael@0: * michael@0: * @param titleIter A break iterator to find the first characters of words michael@0: * that are to be titlecased. michael@0: * If none is provided (0), then a standard titlecase michael@0: * break iterator is opened. michael@0: * Otherwise the provided iterator is set to the string's text. michael@0: * @param locale The locale to consider. michael@0: * @return A reference to this. michael@0: * @stable ICU 2.1 michael@0: */ michael@0: UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale); michael@0: michael@0: /** michael@0: * Titlecase this string, with options. michael@0: * michael@0: * Casing is locale-dependent and context-sensitive. michael@0: * Titlecasing uses a break iterator to find the first characters of words michael@0: * that are to be titlecased. It titlecases those characters and lowercases michael@0: * all others. (This can be modified with options.) michael@0: * michael@0: * The titlecase break iterator can be provided to customize for arbitrary michael@0: * styles, using rules and dictionaries beyond the standard iterators. michael@0: * It may be more efficient to always provide an iterator to avoid michael@0: * opening and closing one for each string. michael@0: * The standard titlecase iterator for the root locale implements the michael@0: * algorithm of Unicode TR 21. michael@0: * michael@0: * This function uses only the setText(), first() and next() methods of the michael@0: * provided break iterator. michael@0: * michael@0: * @param titleIter A break iterator to find the first characters of words michael@0: * that are to be titlecased. michael@0: * If none is provided (0), then a standard titlecase michael@0: * break iterator is opened. michael@0: * Otherwise the provided iterator is set to the string's text. michael@0: * @param locale The locale to consider. michael@0: * @param options Options bit set, see ucasemap_open(). michael@0: * @return A reference to this. michael@0: * @see U_TITLECASE_NO_LOWERCASE michael@0: * @see U_TITLECASE_NO_BREAK_ADJUSTMENT michael@0: * @see ucasemap_open michael@0: * @stable ICU 3.8 michael@0: */ michael@0: UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale, uint32_t options); michael@0: michael@0: #endif michael@0: michael@0: /** michael@0: * Case-folds the characters in this string. michael@0: * michael@0: * Case-folding is locale-independent and not context-sensitive, michael@0: * but there is an option for whether to include or exclude mappings for dotted I michael@0: * and dotless i that are marked with 'T' in CaseFolding.txt. michael@0: * michael@0: * The result may be longer or shorter than the original. michael@0: * michael@0: * @param options Either U_FOLD_CASE_DEFAULT or U_FOLD_CASE_EXCLUDE_SPECIAL_I michael@0: * @return A reference to this. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UnicodeString &foldCase(uint32_t options=0 /*U_FOLD_CASE_DEFAULT*/); michael@0: michael@0: //======================================== michael@0: // Access to the internal buffer michael@0: //======================================== michael@0: michael@0: /** michael@0: * Get a read/write pointer to the internal buffer. michael@0: * The buffer is guaranteed to be large enough for at least minCapacity UChars, michael@0: * writable, and is still owned by the UnicodeString object. michael@0: * Calls to getBuffer(minCapacity) must not be nested, and michael@0: * must be matched with calls to releaseBuffer(newLength). michael@0: * If the string buffer was read-only or shared, michael@0: * then it will be reallocated and copied. michael@0: * michael@0: * An attempted nested call will return 0, and will not further modify the michael@0: * state of the UnicodeString object. michael@0: * It also returns 0 if the string is bogus. michael@0: * michael@0: * The actual capacity of the string buffer may be larger than minCapacity. michael@0: * getCapacity() returns the actual capacity. michael@0: * For many operations, the full capacity should be used to avoid reallocations. michael@0: * michael@0: * While the buffer is "open" between getBuffer(minCapacity) michael@0: * and releaseBuffer(newLength), the following applies: michael@0: * - The string length is set to 0. michael@0: * - Any read API call on the UnicodeString object will behave like on a 0-length string. michael@0: * - Any write API call on the UnicodeString object is disallowed and will have no effect. michael@0: * - You can read from and write to the returned buffer. michael@0: * - The previous string contents will still be in the buffer; michael@0: * if you want to use it, then you need to call length() before getBuffer(minCapacity). michael@0: * If the length() was greater than minCapacity, then any contents after minCapacity michael@0: * may be lost. michael@0: * The buffer contents is not NUL-terminated by getBuffer(). michael@0: * If length()(s.length(). michael@0: * (See getTerminatedBuffer().) michael@0: * michael@0: * The buffer may reside in read-only memory. Its contents must not michael@0: * be modified. michael@0: * michael@0: * @return a read-only pointer to the internal string buffer, michael@0: * or 0 if the string is empty or bogus michael@0: * michael@0: * @see getBuffer(int32_t minCapacity) michael@0: * @see getTerminatedBuffer() michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline const UChar *getBuffer() const; michael@0: michael@0: /** michael@0: * Get a read-only pointer to the internal buffer, michael@0: * making sure that it is NUL-terminated. michael@0: * This can be called at any time on a valid UnicodeString. michael@0: * michael@0: * It returns 0 if the string is bogus, or michael@0: * during an "open" getBuffer(minCapacity), or if the buffer cannot michael@0: * be NUL-terminated (because memory allocation failed). michael@0: * michael@0: * It can be called as many times as desired. michael@0: * The pointer that it returns will remain valid until the UnicodeString object is modified, michael@0: * at which time the pointer is semantically invalidated and must not be used any more. michael@0: * michael@0: * The capacity of the buffer can be determined with getCapacity(). michael@0: * The part after length()+1 may or may not be initialized and valid, michael@0: * depending on the history of the UnicodeString object. michael@0: * michael@0: * The buffer contents is guaranteed to be NUL-terminated. michael@0: * getTerminatedBuffer() may reallocate the buffer if a terminating NUL michael@0: * is written. michael@0: * For this reason, this function is not const, unlike getBuffer(). michael@0: * Note that a UnicodeString may also contain NUL characters as part of its contents. michael@0: * michael@0: * The buffer may reside in read-only memory. Its contents must not michael@0: * be modified. michael@0: * michael@0: * @return a read-only pointer to the internal string buffer, michael@0: * or 0 if the string is empty or bogus michael@0: * michael@0: * @see getBuffer(int32_t minCapacity) michael@0: * @see getBuffer() michael@0: * @stable ICU 2.2 michael@0: */ michael@0: const UChar *getTerminatedBuffer(); michael@0: michael@0: //======================================== michael@0: // Constructors michael@0: //======================================== michael@0: michael@0: /** Construct an empty UnicodeString. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: inline UnicodeString(); michael@0: michael@0: /** michael@0: * Construct a UnicodeString with capacity to hold capacity UChars michael@0: * @param capacity the number of UChars this UnicodeString should hold michael@0: * before a resize is necessary; if count is greater than 0 and count michael@0: * code points c take up more space than capacity, then capacity is adjusted michael@0: * accordingly. michael@0: * @param c is used to initially fill the string michael@0: * @param count specifies how many code points c are to be written in the michael@0: * string michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UnicodeString(int32_t capacity, UChar32 c, int32_t count); michael@0: michael@0: /** michael@0: * Single UChar (code unit) constructor. michael@0: * michael@0: * It is recommended to mark this constructor "explicit" by michael@0: * -DUNISTR_FROM_CHAR_EXPLICIT=explicit michael@0: * on the compiler command line or similar. michael@0: * @param ch the character to place in the UnicodeString michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UNISTR_FROM_CHAR_EXPLICIT UnicodeString(UChar ch); michael@0: michael@0: /** michael@0: * Single UChar32 (code point) constructor. michael@0: * michael@0: * It is recommended to mark this constructor "explicit" by michael@0: * -DUNISTR_FROM_CHAR_EXPLICIT=explicit michael@0: * on the compiler command line or similar. michael@0: * @param ch the character to place in the UnicodeString michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UNISTR_FROM_CHAR_EXPLICIT UnicodeString(UChar32 ch); michael@0: michael@0: /** michael@0: * UChar* constructor. michael@0: * michael@0: * It is recommended to mark this constructor "explicit" by michael@0: * -DUNISTR_FROM_STRING_EXPLICIT=explicit michael@0: * on the compiler command line or similar. michael@0: * @param text The characters to place in the UnicodeString. text michael@0: * must be NULL (U+0000) terminated. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UNISTR_FROM_STRING_EXPLICIT UnicodeString(const UChar *text); michael@0: michael@0: /** michael@0: * UChar* constructor. michael@0: * @param text The characters to place in the UnicodeString. michael@0: * @param textLength The number of Unicode characters in text michael@0: * to copy. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UnicodeString(const UChar *text, michael@0: int32_t textLength); michael@0: michael@0: /** michael@0: * Readonly-aliasing UChar* constructor. michael@0: * The text will be used for the UnicodeString object, but michael@0: * it will not be released when the UnicodeString is destroyed. michael@0: * This has copy-on-write semantics: michael@0: * When the string is modified, then the buffer is first copied into michael@0: * newly allocated memory. michael@0: * The aliased buffer is never modified. michael@0: * michael@0: * In an assignment to another UnicodeString, when using the copy constructor michael@0: * or the assignment operator, the text will be copied. michael@0: * When using fastCopyFrom(), the text will be aliased again, michael@0: * so that both strings then alias the same readonly-text. michael@0: * michael@0: * @param isTerminated specifies if text is NUL-terminated. michael@0: * This must be true if textLength==-1. michael@0: * @param text The characters to alias for the UnicodeString. michael@0: * @param textLength The number of Unicode characters in text to alias. michael@0: * If -1, then this constructor will determine the length michael@0: * by calling u_strlen(). michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UnicodeString(UBool isTerminated, michael@0: const UChar *text, michael@0: int32_t textLength); michael@0: michael@0: /** michael@0: * Writable-aliasing UChar* constructor. michael@0: * The text will be used for the UnicodeString object, but michael@0: * it will not be released when the UnicodeString is destroyed. michael@0: * This has write-through semantics: michael@0: * For as long as the capacity of the buffer is sufficient, write operations michael@0: * will directly affect the buffer. When more capacity is necessary, then michael@0: * a new buffer will be allocated and the contents copied as with regularly michael@0: * constructed strings. michael@0: * In an assignment to another UnicodeString, the buffer will be copied. michael@0: * The extract(UChar *dst) function detects whether the dst pointer is the same michael@0: * as the string buffer itself and will in this case not copy the contents. michael@0: * michael@0: * @param buffer The characters to alias for the UnicodeString. michael@0: * @param buffLength The number of Unicode characters in buffer to alias. michael@0: * @param buffCapacity The size of buffer in UChars. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UnicodeString(UChar *buffer, int32_t buffLength, int32_t buffCapacity); michael@0: michael@0: #if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION michael@0: michael@0: /** michael@0: * char* constructor. michael@0: * Uses the default converter (and thus depends on the ICU conversion code) michael@0: * unless U_CHARSET_IS_UTF8 is set to 1. michael@0: * michael@0: * For ASCII (really "invariant character") strings it is more efficient to use michael@0: * the constructor that takes a US_INV (for its enum EInvariant). michael@0: * For ASCII (invariant-character) string literals, see UNICODE_STRING and michael@0: * UNICODE_STRING_SIMPLE. michael@0: * michael@0: * It is recommended to mark this constructor "explicit" by michael@0: * -DUNISTR_FROM_STRING_EXPLICIT=explicit michael@0: * on the compiler command line or similar. michael@0: * @param codepageData an array of bytes, null-terminated, michael@0: * in the platform's default codepage. michael@0: * @stable ICU 2.0 michael@0: * @see UNICODE_STRING michael@0: * @see UNICODE_STRING_SIMPLE michael@0: */ michael@0: UNISTR_FROM_STRING_EXPLICIT UnicodeString(const char *codepageData); michael@0: michael@0: /** michael@0: * char* constructor. michael@0: * Uses the default converter (and thus depends on the ICU conversion code) michael@0: * unless U_CHARSET_IS_UTF8 is set to 1. michael@0: * @param codepageData an array of bytes in the platform's default codepage. michael@0: * @param dataLength The number of bytes in codepageData. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UnicodeString(const char *codepageData, int32_t dataLength); michael@0: michael@0: #endif michael@0: michael@0: #if !UCONFIG_NO_CONVERSION michael@0: michael@0: /** michael@0: * char* constructor. michael@0: * @param codepageData an array of bytes, null-terminated michael@0: * @param codepage the encoding of codepageData. The special michael@0: * value 0 for codepage indicates that the text is in the michael@0: * platform's default codepage. michael@0: * michael@0: * If codepage is an empty string (""), michael@0: * then a simple conversion is performed on the codepage-invariant michael@0: * subset ("invariant characters") of the platform encoding. See utypes.h. michael@0: * Recommendation: For invariant-character strings use the constructor michael@0: * UnicodeString(const char *src, int32_t length, enum EInvariant inv) michael@0: * because it avoids object code dependencies of UnicodeString on michael@0: * the conversion code. michael@0: * michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UnicodeString(const char *codepageData, const char *codepage); michael@0: michael@0: /** michael@0: * char* constructor. michael@0: * @param codepageData an array of bytes. michael@0: * @param dataLength The number of bytes in codepageData. michael@0: * @param codepage the encoding of codepageData. The special michael@0: * value 0 for codepage indicates that the text is in the michael@0: * platform's default codepage. michael@0: * If codepage is an empty string (""), michael@0: * then a simple conversion is performed on the codepage-invariant michael@0: * subset ("invariant characters") of the platform encoding. See utypes.h. michael@0: * Recommendation: For invariant-character strings use the constructor michael@0: * UnicodeString(const char *src, int32_t length, enum EInvariant inv) michael@0: * because it avoids object code dependencies of UnicodeString on michael@0: * the conversion code. michael@0: * michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UnicodeString(const char *codepageData, int32_t dataLength, const char *codepage); michael@0: michael@0: /** michael@0: * char * / UConverter constructor. michael@0: * This constructor uses an existing UConverter object to michael@0: * convert the codepage string to Unicode and construct a UnicodeString michael@0: * from that. michael@0: * michael@0: * The converter is reset at first. michael@0: * If the error code indicates a failure before this constructor is called, michael@0: * or if an error occurs during conversion or construction, michael@0: * then the string will be bogus. michael@0: * michael@0: * This function avoids the overhead of opening and closing a converter if michael@0: * multiple strings are constructed. michael@0: * michael@0: * @param src input codepage string michael@0: * @param srcLength length of the input string, can be -1 for NUL-terminated strings michael@0: * @param cnv converter object (ucnv_resetToUnicode() will be called), michael@0: * can be NULL for the default converter michael@0: * @param errorCode normal ICU error code michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UnicodeString( michael@0: const char *src, int32_t srcLength, michael@0: UConverter *cnv, michael@0: UErrorCode &errorCode); michael@0: michael@0: #endif michael@0: michael@0: /** michael@0: * Constructs a Unicode string from an invariant-character char * string. michael@0: * About invariant characters see utypes.h. michael@0: * This constructor has no runtime dependency on conversion code and is michael@0: * therefore recommended over ones taking a charset name string michael@0: * (where the empty string "" indicates invariant-character conversion). michael@0: * michael@0: * Use the macro US_INV as the third, signature-distinguishing parameter. michael@0: * michael@0: * For example: michael@0: * \code michael@0: * void fn(const char *s) { michael@0: * UnicodeString ustr(s, -1, US_INV); michael@0: * // use ustr ... michael@0: * } michael@0: * \endcode michael@0: * michael@0: * @param src String using only invariant characters. michael@0: * @param length Length of src, or -1 if NUL-terminated. michael@0: * @param inv Signature-distinguishing paramater, use US_INV. michael@0: * michael@0: * @see US_INV michael@0: * @stable ICU 3.2 michael@0: */ michael@0: UnicodeString(const char *src, int32_t length, enum EInvariant inv); michael@0: michael@0: michael@0: /** michael@0: * Copy constructor. michael@0: * @param that The UnicodeString object to copy. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UnicodeString(const UnicodeString& that); michael@0: michael@0: /** michael@0: * 'Substring' constructor from tail of source string. michael@0: * @param src The UnicodeString object to copy. michael@0: * @param srcStart The offset into src at which to start copying. michael@0: * @stable ICU 2.2 michael@0: */ michael@0: UnicodeString(const UnicodeString& src, int32_t srcStart); michael@0: michael@0: /** michael@0: * 'Substring' constructor from subrange of source string. michael@0: * @param src The UnicodeString object to copy. michael@0: * @param srcStart The offset into src at which to start copying. michael@0: * @param srcLength The number of characters from src to copy. michael@0: * @stable ICU 2.2 michael@0: */ michael@0: UnicodeString(const UnicodeString& src, int32_t srcStart, int32_t srcLength); michael@0: michael@0: /** michael@0: * Clone this object, an instance of a subclass of Replaceable. michael@0: * Clones can be used concurrently in multiple threads. michael@0: * If a subclass does not implement clone(), or if an error occurs, michael@0: * then NULL is returned. michael@0: * The clone functions in all subclasses return a pointer to a Replaceable michael@0: * because some compilers do not support covariant (same-as-this) michael@0: * return types; cast to the appropriate subclass if necessary. michael@0: * The caller must delete the clone. michael@0: * michael@0: * @return a clone of this object michael@0: * michael@0: * @see Replaceable::clone michael@0: * @see getDynamicClassID michael@0: * @stable ICU 2.6 michael@0: */ michael@0: virtual Replaceable *clone() const; michael@0: michael@0: /** Destructor. michael@0: * @stable ICU 2.0 michael@0: */ michael@0: virtual ~UnicodeString(); michael@0: michael@0: /** michael@0: * Create a UnicodeString from a UTF-8 string. michael@0: * Illegal input is replaced with U+FFFD. Otherwise, errors result in a bogus string. michael@0: * Calls u_strFromUTF8WithSub(). michael@0: * michael@0: * @param utf8 UTF-8 input string. michael@0: * Note that a StringPiece can be implicitly constructed michael@0: * from a std::string or a NUL-terminated const char * string. michael@0: * @return A UnicodeString with equivalent UTF-16 contents. michael@0: * @see toUTF8 michael@0: * @see toUTF8String michael@0: * @stable ICU 4.2 michael@0: */ michael@0: static UnicodeString fromUTF8(const StringPiece &utf8); michael@0: michael@0: /** michael@0: * Create a UnicodeString from a UTF-32 string. michael@0: * Illegal input is replaced with U+FFFD. Otherwise, errors result in a bogus string. michael@0: * Calls u_strFromUTF32WithSub(). michael@0: * michael@0: * @param utf32 UTF-32 input string. Must not be NULL. michael@0: * @param length Length of the input string, or -1 if NUL-terminated. michael@0: * @return A UnicodeString with equivalent UTF-16 contents. michael@0: * @see toUTF32 michael@0: * @stable ICU 4.2 michael@0: */ michael@0: static UnicodeString fromUTF32(const UChar32 *utf32, int32_t length); michael@0: michael@0: /* Miscellaneous operations */ michael@0: michael@0: /** michael@0: * Unescape a string of characters and return a string containing michael@0: * the result. The following escape sequences are recognized: michael@0: * michael@0: * \\uhhhh 4 hex digits; h in [0-9A-Fa-f] michael@0: * \\Uhhhhhhhh 8 hex digits michael@0: * \\xhh 1-2 hex digits michael@0: * \\ooo 1-3 octal digits; o in [0-7] michael@0: * \\cX control-X; X is masked with 0x1F michael@0: * michael@0: * as well as the standard ANSI C escapes: michael@0: * michael@0: * \\a => U+0007, \\b => U+0008, \\t => U+0009, \\n => U+000A, michael@0: * \\v => U+000B, \\f => U+000C, \\r => U+000D, \\e => U+001B, michael@0: * \\" => U+0022, \\' => U+0027, \\? => U+003F, \\\\ => U+005C michael@0: * michael@0: * Anything else following a backslash is generically escaped. For michael@0: * example, "[a\\-z]" returns "[a-z]". michael@0: * michael@0: * If an escape sequence is ill-formed, this method returns an empty michael@0: * string. An example of an ill-formed sequence is "\\u" followed by michael@0: * fewer than 4 hex digits. michael@0: * michael@0: * This function is similar to u_unescape() but not identical to it. michael@0: * The latter takes a source char*, so it does escape recognition michael@0: * and also invariant conversion. michael@0: * michael@0: * @return a string with backslash escapes interpreted, or an michael@0: * empty string on error. michael@0: * @see UnicodeString#unescapeAt() michael@0: * @see u_unescape() michael@0: * @see u_unescapeAt() michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UnicodeString unescape() const; michael@0: michael@0: /** michael@0: * Unescape a single escape sequence and return the represented michael@0: * character. See unescape() for a listing of the recognized escape michael@0: * sequences. The character at offset-1 is assumed (without michael@0: * checking) to be a backslash. If the escape sequence is michael@0: * ill-formed, or the offset is out of range, U_SENTINEL=-1 is michael@0: * returned. michael@0: * michael@0: * @param offset an input output parameter. On input, it is the michael@0: * offset into this string where the escape sequence is located, michael@0: * after the initial backslash. On output, it is advanced after the michael@0: * last character parsed. On error, it is not advanced at all. michael@0: * @return the character represented by the escape sequence at michael@0: * offset, or U_SENTINEL=-1 on error. michael@0: * @see UnicodeString#unescape() michael@0: * @see u_unescape() michael@0: * @see u_unescapeAt() michael@0: * @stable ICU 2.0 michael@0: */ michael@0: UChar32 unescapeAt(int32_t &offset) const; michael@0: michael@0: /** michael@0: * ICU "poor man's RTTI", returns a UClassID for this class. michael@0: * michael@0: * @stable ICU 2.2 michael@0: */ michael@0: static UClassID U_EXPORT2 getStaticClassID(); michael@0: michael@0: /** michael@0: * ICU "poor man's RTTI", returns a UClassID for the actual class. michael@0: * michael@0: * @stable ICU 2.2 michael@0: */ michael@0: virtual UClassID getDynamicClassID() const; michael@0: michael@0: //======================================== michael@0: // Implementation methods michael@0: //======================================== michael@0: michael@0: protected: michael@0: /** michael@0: * Implement Replaceable::getLength() (see jitterbug 1027). michael@0: * @stable ICU 2.4 michael@0: */ michael@0: virtual int32_t getLength() const; michael@0: michael@0: /** michael@0: * The change in Replaceable to use virtual getCharAt() allows michael@0: * UnicodeString::charAt() to be inline again (see jitterbug 709). michael@0: * @stable ICU 2.4 michael@0: */ michael@0: virtual UChar getCharAt(int32_t offset) const; michael@0: michael@0: /** michael@0: * The change in Replaceable to use virtual getChar32At() allows michael@0: * UnicodeString::char32At() to be inline again (see jitterbug 709). michael@0: * @stable ICU 2.4 michael@0: */ michael@0: virtual UChar32 getChar32At(int32_t offset) const; michael@0: michael@0: private: michael@0: // For char* constructors. Could be made public. michael@0: UnicodeString &setToUTF8(const StringPiece &utf8); michael@0: // For extract(char*). michael@0: // We could make a toUTF8(target, capacity, errorCode) public but not michael@0: // this version: New API will be cleaner if we make callers create substrings michael@0: // rather than having start+length on every method, michael@0: // and it should take a UErrorCode&. michael@0: int32_t michael@0: toUTF8(int32_t start, int32_t len, michael@0: char *target, int32_t capacity) const; michael@0: michael@0: /** michael@0: * Internal string contents comparison, called by operator==. michael@0: * Requires: this & text not bogus and have same lengths. michael@0: */ michael@0: UBool doEquals(const UnicodeString &text, int32_t len) const; michael@0: michael@0: inline int8_t michael@0: doCompare(int32_t start, michael@0: int32_t length, michael@0: const UnicodeString& srcText, michael@0: int32_t srcStart, michael@0: int32_t srcLength) const; michael@0: michael@0: int8_t doCompare(int32_t start, michael@0: int32_t length, michael@0: const UChar *srcChars, michael@0: int32_t srcStart, michael@0: int32_t srcLength) const; michael@0: michael@0: inline int8_t michael@0: doCompareCodePointOrder(int32_t start, michael@0: int32_t length, michael@0: const UnicodeString& srcText, michael@0: int32_t srcStart, michael@0: int32_t srcLength) const; michael@0: michael@0: int8_t doCompareCodePointOrder(int32_t start, michael@0: int32_t length, michael@0: const UChar *srcChars, michael@0: int32_t srcStart, michael@0: int32_t srcLength) const; michael@0: michael@0: inline int8_t michael@0: doCaseCompare(int32_t start, michael@0: int32_t length, michael@0: const UnicodeString &srcText, michael@0: int32_t srcStart, michael@0: int32_t srcLength, michael@0: uint32_t options) const; michael@0: michael@0: int8_t michael@0: doCaseCompare(int32_t start, michael@0: int32_t length, michael@0: const UChar *srcChars, michael@0: int32_t srcStart, michael@0: int32_t srcLength, michael@0: uint32_t options) const; michael@0: michael@0: int32_t doIndexOf(UChar c, michael@0: int32_t start, michael@0: int32_t length) const; michael@0: michael@0: int32_t doIndexOf(UChar32 c, michael@0: int32_t start, michael@0: int32_t length) const; michael@0: michael@0: int32_t doLastIndexOf(UChar c, michael@0: int32_t start, michael@0: int32_t length) const; michael@0: michael@0: int32_t doLastIndexOf(UChar32 c, michael@0: int32_t start, michael@0: int32_t length) const; michael@0: michael@0: void doExtract(int32_t start, michael@0: int32_t length, michael@0: UChar *dst, michael@0: int32_t dstStart) const; michael@0: michael@0: inline void doExtract(int32_t start, michael@0: int32_t length, michael@0: UnicodeString& target) const; michael@0: michael@0: inline UChar doCharAt(int32_t offset) const; michael@0: michael@0: UnicodeString& doReplace(int32_t start, michael@0: int32_t length, michael@0: const UnicodeString& srcText, michael@0: int32_t srcStart, michael@0: int32_t srcLength); michael@0: michael@0: UnicodeString& doReplace(int32_t start, michael@0: int32_t length, michael@0: const UChar *srcChars, michael@0: int32_t srcStart, michael@0: int32_t srcLength); michael@0: michael@0: UnicodeString& doReverse(int32_t start, michael@0: int32_t length); michael@0: michael@0: // calculate hash code michael@0: int32_t doHashCode(void) const; michael@0: michael@0: // get pointer to start of array michael@0: // these do not check for kOpenGetBuffer, unlike the public getBuffer() function michael@0: inline UChar* getArrayStart(void); michael@0: inline const UChar* getArrayStart(void) const; michael@0: michael@0: // A UnicodeString object (not necessarily its current buffer) michael@0: // is writable unless it isBogus() or it has an "open" getBuffer(minCapacity). michael@0: inline UBool isWritable() const; michael@0: michael@0: // Is the current buffer writable? michael@0: inline UBool isBufferWritable() const; michael@0: michael@0: // None of the following does releaseArray(). michael@0: inline void setLength(int32_t len); // sets only fShortLength and fLength michael@0: inline void setToEmpty(); // sets fFlags=kShortString michael@0: inline void setArray(UChar *array, int32_t len, int32_t capacity); // does not set fFlags michael@0: michael@0: // allocate the array; result may be fStackBuffer michael@0: // sets refCount to 1 if appropriate michael@0: // sets fArray, fCapacity, and fFlags michael@0: // returns boolean for success or failure michael@0: UBool allocate(int32_t capacity); michael@0: michael@0: // release the array if owned michael@0: void releaseArray(void); michael@0: michael@0: // turn a bogus string into an empty one michael@0: void unBogus(); michael@0: michael@0: // implements assigment operator, copy constructor, and fastCopyFrom() michael@0: UnicodeString ©From(const UnicodeString &src, UBool fastCopy=FALSE); michael@0: michael@0: // Pin start and limit to acceptable values. michael@0: inline void pinIndex(int32_t& start) const; michael@0: inline void pinIndices(int32_t& start, michael@0: int32_t& length) const; michael@0: michael@0: #if !UCONFIG_NO_CONVERSION michael@0: michael@0: /* Internal extract() using UConverter. */ michael@0: int32_t doExtract(int32_t start, int32_t length, michael@0: char *dest, int32_t destCapacity, michael@0: UConverter *cnv, michael@0: UErrorCode &errorCode) const; michael@0: michael@0: /* michael@0: * Real constructor for converting from codepage data. michael@0: * It assumes that it is called with !fRefCounted. michael@0: * michael@0: * If codepage==0, then the default converter michael@0: * is used for the platform encoding. michael@0: * If codepage is an empty string (""), michael@0: * then a simple conversion is performed on the codepage-invariant michael@0: * subset ("invariant characters") of the platform encoding. See utypes.h. michael@0: */ michael@0: void doCodepageCreate(const char *codepageData, michael@0: int32_t dataLength, michael@0: const char *codepage); michael@0: michael@0: /* michael@0: * Worker function for creating a UnicodeString from michael@0: * a codepage string using a UConverter. michael@0: */ michael@0: void michael@0: doCodepageCreate(const char *codepageData, michael@0: int32_t dataLength, michael@0: UConverter *converter, michael@0: UErrorCode &status); michael@0: michael@0: #endif michael@0: michael@0: /* michael@0: * This function is called when write access to the array michael@0: * is necessary. michael@0: * michael@0: * We need to make a copy of the array if michael@0: * the buffer is read-only, or michael@0: * the buffer is refCounted (shared), and refCount>1, or michael@0: * the buffer is too small. michael@0: * michael@0: * Return FALSE if memory could not be allocated. michael@0: */ michael@0: UBool cloneArrayIfNeeded(int32_t newCapacity = -1, michael@0: int32_t growCapacity = -1, michael@0: UBool doCopyArray = TRUE, michael@0: int32_t **pBufferToDelete = 0, michael@0: UBool forceClone = FALSE); michael@0: michael@0: /** michael@0: * Common function for UnicodeString case mappings. michael@0: * The stringCaseMapper has the same type UStringCaseMapper michael@0: * as in ustr_imp.h for ustrcase_map(). michael@0: */ michael@0: UnicodeString & michael@0: caseMap(const UCaseMap *csm, UStringCaseMapper *stringCaseMapper); michael@0: michael@0: // ref counting michael@0: void addRef(void); michael@0: int32_t removeRef(void); michael@0: int32_t refCount(void) const; michael@0: michael@0: // constants michael@0: enum { michael@0: // Set the stack buffer size so that sizeof(UnicodeString) is, michael@0: // naturally (without padding), a multiple of sizeof(pointer). michael@0: US_STACKBUF_SIZE= sizeof(void *)==4 ? 13 : 15, // Size of stack buffer for short strings michael@0: kInvalidUChar=0xffff, // invalid UChar index michael@0: kGrowSize=128, // grow size for this buffer michael@0: kInvalidHashCode=0, // invalid hash code michael@0: kEmptyHashCode=1, // hash code for empty string michael@0: michael@0: // bit flag values for fFlags michael@0: kIsBogus=1, // this string is bogus, i.e., not valid or NULL michael@0: kUsingStackBuffer=2,// using fUnion.fStackBuffer instead of fUnion.fFields michael@0: kRefCounted=4, // there is a refCount field before the characters in fArray michael@0: kBufferIsReadonly=8,// do not write to this buffer michael@0: kOpenGetBuffer=16, // getBuffer(minCapacity) was called (is "open"), michael@0: // and releaseBuffer(newLength) must be called michael@0: michael@0: // combined values for convenience michael@0: kShortString=kUsingStackBuffer, michael@0: kLongString=kRefCounted, michael@0: kReadonlyAlias=kBufferIsReadonly, michael@0: kWritableAlias=0 michael@0: }; michael@0: michael@0: friend class StringThreadTest; michael@0: friend class UnicodeStringAppendable; michael@0: michael@0: union StackBufferOrFields; // forward declaration necessary before friend declaration michael@0: friend union StackBufferOrFields; // make US_STACKBUF_SIZE visible inside fUnion michael@0: michael@0: /* michael@0: * The following are all the class fields that are stored michael@0: * in each UnicodeString object. michael@0: * Note that UnicodeString has virtual functions, michael@0: * therefore there is an implicit vtable pointer michael@0: * as the first real field. michael@0: * The fields should be aligned such that no padding is necessary. michael@0: * On 32-bit machines, the size should be 32 bytes, michael@0: * on 64-bit machines (8-byte pointers), it should be 40 bytes. michael@0: * michael@0: * We use a hack to achieve this. michael@0: * michael@0: * With at least some compilers, each of the following is forced to michael@0: * a multiple of sizeof(pointer) [the largest field base unit here is a data pointer], michael@0: * rounded up with additional padding if the fields do not already fit that requirement: michael@0: * - sizeof(class UnicodeString) michael@0: * - offsetof(UnicodeString, fUnion) michael@0: * - sizeof(fUnion) michael@0: * - sizeof(fFields) michael@0: * michael@0: * In order to avoid padding, we make sizeof(fStackBuffer)=16 (=8 UChars) michael@0: * which is at least as large as sizeof(fFields) on 32-bit and 64-bit machines. michael@0: * (Padding at the end of fFields is ok: michael@0: * As long as there is no padding after fStackBuffer, it is not wasted space.) michael@0: * michael@0: * We further assume that the compiler does not reorder the fields, michael@0: * so that fRestOfStackBuffer (which holds a few more UChars) immediately follows after fUnion, michael@0: * with at most some padding (but no other field) in between. michael@0: * (Padding there would be wasted space, but functionally harmless.) michael@0: * michael@0: * We use a few more sizeof(pointer)'s chunks of space with michael@0: * fRestOfStackBuffer, fShortLength and fFlags, michael@0: * to get up exactly to the intended sizeof(UnicodeString). michael@0: */ michael@0: // (implicit) *vtable; michael@0: union StackBufferOrFields { michael@0: // fStackBuffer is used iff (fFlags&kUsingStackBuffer) michael@0: // else fFields is used michael@0: UChar fStackBuffer[8]; // buffer for short strings, together with fRestOfStackBuffer michael@0: struct { michael@0: UChar *fArray; // the Unicode data michael@0: int32_t fCapacity; // capacity of fArray (in UChars) michael@0: int32_t fLength; // number of characters in fArray if >127; else undefined michael@0: } fFields; michael@0: } fUnion; michael@0: UChar fRestOfStackBuffer[US_STACKBUF_SIZE-8]; michael@0: int8_t fShortLength; // 0..127: length <0: real length is in fUnion.fFields.fLength michael@0: uint8_t fFlags; // bit flags: see constants above michael@0: }; michael@0: michael@0: /** michael@0: * Create a new UnicodeString with the concatenation of two others. michael@0: * michael@0: * @param s1 The first string to be copied to the new one. michael@0: * @param s2 The second string to be copied to the new one, after s1. michael@0: * @return UnicodeString(s1).append(s2) michael@0: * @stable ICU 2.8 michael@0: */ michael@0: U_COMMON_API UnicodeString U_EXPORT2 michael@0: operator+ (const UnicodeString &s1, const UnicodeString &s2); michael@0: michael@0: //======================================== michael@0: // Inline members michael@0: //======================================== michael@0: michael@0: //======================================== michael@0: // Privates michael@0: //======================================== michael@0: michael@0: inline void michael@0: UnicodeString::pinIndex(int32_t& start) const michael@0: { michael@0: // pin index michael@0: if(start < 0) { michael@0: start = 0; michael@0: } else if(start > length()) { michael@0: start = length(); michael@0: } michael@0: } michael@0: michael@0: inline void michael@0: UnicodeString::pinIndices(int32_t& start, michael@0: int32_t& _length) const michael@0: { michael@0: // pin indices michael@0: int32_t len = length(); michael@0: if(start < 0) { michael@0: start = 0; michael@0: } else if(start > len) { michael@0: start = len; michael@0: } michael@0: if(_length < 0) { michael@0: _length = 0; michael@0: } else if(_length > (len - start)) { michael@0: _length = (len - start); michael@0: } michael@0: } michael@0: michael@0: inline UChar* michael@0: UnicodeString::getArrayStart() michael@0: { return (fFlags&kUsingStackBuffer) ? fUnion.fStackBuffer : fUnion.fFields.fArray; } michael@0: michael@0: inline const UChar* michael@0: UnicodeString::getArrayStart() const michael@0: { return (fFlags&kUsingStackBuffer) ? fUnion.fStackBuffer : fUnion.fFields.fArray; } michael@0: michael@0: //======================================== michael@0: // Default constructor michael@0: //======================================== michael@0: michael@0: inline michael@0: UnicodeString::UnicodeString() michael@0: : fShortLength(0), michael@0: fFlags(kShortString) michael@0: {} michael@0: michael@0: //======================================== michael@0: // Read-only implementation methods michael@0: //======================================== michael@0: inline int32_t michael@0: UnicodeString::length() const michael@0: { return fShortLength>=0 ? fShortLength : fUnion.fFields.fLength; } michael@0: michael@0: inline int32_t michael@0: UnicodeString::getCapacity() const michael@0: { return (fFlags&kUsingStackBuffer) ? US_STACKBUF_SIZE : fUnion.fFields.fCapacity; } michael@0: michael@0: inline int32_t michael@0: UnicodeString::hashCode() const michael@0: { return doHashCode(); } michael@0: michael@0: inline UBool michael@0: UnicodeString::isBogus() const michael@0: { return (UBool)(fFlags & kIsBogus); } michael@0: michael@0: inline UBool michael@0: UnicodeString::isWritable() const michael@0: { return (UBool)!(fFlags&(kOpenGetBuffer|kIsBogus)); } michael@0: michael@0: inline UBool michael@0: UnicodeString::isBufferWritable() const michael@0: { michael@0: return (UBool)( michael@0: !(fFlags&(kOpenGetBuffer|kIsBogus|kBufferIsReadonly)) && michael@0: (!(fFlags&kRefCounted) || refCount()==1)); michael@0: } michael@0: michael@0: inline const UChar * michael@0: UnicodeString::getBuffer() const { michael@0: if(fFlags&(kIsBogus|kOpenGetBuffer)) { michael@0: return 0; michael@0: } else if(fFlags&kUsingStackBuffer) { michael@0: return fUnion.fStackBuffer; michael@0: } else { michael@0: return fUnion.fFields.fArray; michael@0: } michael@0: } michael@0: michael@0: //======================================== michael@0: // Read-only alias methods michael@0: //======================================== michael@0: inline int8_t michael@0: UnicodeString::doCompare(int32_t start, michael@0: int32_t thisLength, michael@0: const UnicodeString& srcText, michael@0: int32_t srcStart, michael@0: int32_t srcLength) const michael@0: { michael@0: if(srcText.isBogus()) { michael@0: return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise michael@0: } else { michael@0: srcText.pinIndices(srcStart, srcLength); michael@0: return doCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength); michael@0: } michael@0: } michael@0: michael@0: inline UBool michael@0: UnicodeString::operator== (const UnicodeString& text) const michael@0: { michael@0: if(isBogus()) { michael@0: return text.isBogus(); michael@0: } else { michael@0: int32_t len = length(), textLength = text.length(); michael@0: return !text.isBogus() && len == textLength && doEquals(text, len); michael@0: } michael@0: } michael@0: michael@0: inline UBool michael@0: UnicodeString::operator!= (const UnicodeString& text) const michael@0: { return (! operator==(text)); } michael@0: michael@0: inline UBool michael@0: UnicodeString::operator> (const UnicodeString& text) const michael@0: { return doCompare(0, length(), text, 0, text.length()) == 1; } michael@0: michael@0: inline UBool michael@0: UnicodeString::operator< (const UnicodeString& text) const michael@0: { return doCompare(0, length(), text, 0, text.length()) == -1; } michael@0: michael@0: inline UBool michael@0: UnicodeString::operator>= (const UnicodeString& text) const michael@0: { return doCompare(0, length(), text, 0, text.length()) != -1; } michael@0: michael@0: inline UBool michael@0: UnicodeString::operator<= (const UnicodeString& text) const michael@0: { return doCompare(0, length(), text, 0, text.length()) != 1; } michael@0: michael@0: inline int8_t michael@0: UnicodeString::compare(const UnicodeString& text) const michael@0: { return doCompare(0, length(), text, 0, text.length()); } michael@0: michael@0: inline int8_t michael@0: UnicodeString::compare(int32_t start, michael@0: int32_t _length, michael@0: const UnicodeString& srcText) const michael@0: { return doCompare(start, _length, srcText, 0, srcText.length()); } michael@0: michael@0: inline int8_t michael@0: UnicodeString::compare(const UChar *srcChars, michael@0: int32_t srcLength) const michael@0: { return doCompare(0, length(), srcChars, 0, srcLength); } michael@0: michael@0: inline int8_t michael@0: UnicodeString::compare(int32_t start, michael@0: int32_t _length, michael@0: const UnicodeString& srcText, michael@0: int32_t srcStart, michael@0: int32_t srcLength) const michael@0: { return doCompare(start, _length, srcText, srcStart, srcLength); } michael@0: michael@0: inline int8_t michael@0: UnicodeString::compare(int32_t start, michael@0: int32_t _length, michael@0: const UChar *srcChars) const michael@0: { return doCompare(start, _length, srcChars, 0, _length); } michael@0: michael@0: inline int8_t michael@0: UnicodeString::compare(int32_t start, michael@0: int32_t _length, michael@0: const UChar *srcChars, michael@0: int32_t srcStart, michael@0: int32_t srcLength) const michael@0: { return doCompare(start, _length, srcChars, srcStart, srcLength); } michael@0: michael@0: inline int8_t michael@0: UnicodeString::compareBetween(int32_t start, michael@0: int32_t limit, michael@0: const UnicodeString& srcText, michael@0: int32_t srcStart, michael@0: int32_t srcLimit) const michael@0: { return doCompare(start, limit - start, michael@0: srcText, srcStart, srcLimit - srcStart); } michael@0: michael@0: inline int8_t michael@0: UnicodeString::doCompareCodePointOrder(int32_t start, michael@0: int32_t thisLength, michael@0: const UnicodeString& srcText, michael@0: int32_t srcStart, michael@0: int32_t srcLength) const michael@0: { michael@0: if(srcText.isBogus()) { michael@0: return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise michael@0: } else { michael@0: srcText.pinIndices(srcStart, srcLength); michael@0: return doCompareCodePointOrder(start, thisLength, srcText.getArrayStart(), srcStart, srcLength); michael@0: } michael@0: } michael@0: michael@0: inline int8_t michael@0: UnicodeString::compareCodePointOrder(const UnicodeString& text) const michael@0: { return doCompareCodePointOrder(0, length(), text, 0, text.length()); } michael@0: michael@0: inline int8_t michael@0: UnicodeString::compareCodePointOrder(int32_t start, michael@0: int32_t _length, michael@0: const UnicodeString& srcText) const michael@0: { return doCompareCodePointOrder(start, _length, srcText, 0, srcText.length()); } michael@0: michael@0: inline int8_t michael@0: UnicodeString::compareCodePointOrder(const UChar *srcChars, michael@0: int32_t srcLength) const michael@0: { return doCompareCodePointOrder(0, length(), srcChars, 0, srcLength); } michael@0: michael@0: inline int8_t michael@0: UnicodeString::compareCodePointOrder(int32_t start, michael@0: int32_t _length, michael@0: const UnicodeString& srcText, michael@0: int32_t srcStart, michael@0: int32_t srcLength) const michael@0: { return doCompareCodePointOrder(start, _length, srcText, srcStart, srcLength); } michael@0: michael@0: inline int8_t michael@0: UnicodeString::compareCodePointOrder(int32_t start, michael@0: int32_t _length, michael@0: const UChar *srcChars) const michael@0: { return doCompareCodePointOrder(start, _length, srcChars, 0, _length); } michael@0: michael@0: inline int8_t michael@0: UnicodeString::compareCodePointOrder(int32_t start, michael@0: int32_t _length, michael@0: const UChar *srcChars, michael@0: int32_t srcStart, michael@0: int32_t srcLength) const michael@0: { return doCompareCodePointOrder(start, _length, srcChars, srcStart, srcLength); } michael@0: michael@0: inline int8_t michael@0: UnicodeString::compareCodePointOrderBetween(int32_t start, michael@0: int32_t limit, michael@0: const UnicodeString& srcText, michael@0: int32_t srcStart, michael@0: int32_t srcLimit) const michael@0: { return doCompareCodePointOrder(start, limit - start, michael@0: srcText, srcStart, srcLimit - srcStart); } michael@0: michael@0: inline int8_t michael@0: UnicodeString::doCaseCompare(int32_t start, michael@0: int32_t thisLength, michael@0: const UnicodeString &srcText, michael@0: int32_t srcStart, michael@0: int32_t srcLength, michael@0: uint32_t options) const michael@0: { michael@0: if(srcText.isBogus()) { michael@0: return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise michael@0: } else { michael@0: srcText.pinIndices(srcStart, srcLength); michael@0: return doCaseCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength, options); michael@0: } michael@0: } michael@0: michael@0: inline int8_t michael@0: UnicodeString::caseCompare(const UnicodeString &text, uint32_t options) const { michael@0: return doCaseCompare(0, length(), text, 0, text.length(), options); michael@0: } michael@0: michael@0: inline int8_t michael@0: UnicodeString::caseCompare(int32_t start, michael@0: int32_t _length, michael@0: const UnicodeString &srcText, michael@0: uint32_t options) const { michael@0: return doCaseCompare(start, _length, srcText, 0, srcText.length(), options); michael@0: } michael@0: michael@0: inline int8_t michael@0: UnicodeString::caseCompare(const UChar *srcChars, michael@0: int32_t srcLength, michael@0: uint32_t options) const { michael@0: return doCaseCompare(0, length(), srcChars, 0, srcLength, options); michael@0: } michael@0: michael@0: inline int8_t michael@0: UnicodeString::caseCompare(int32_t start, michael@0: int32_t _length, michael@0: const UnicodeString &srcText, michael@0: int32_t srcStart, michael@0: int32_t srcLength, michael@0: uint32_t options) const { michael@0: return doCaseCompare(start, _length, srcText, srcStart, srcLength, options); michael@0: } michael@0: michael@0: inline int8_t michael@0: UnicodeString::caseCompare(int32_t start, michael@0: int32_t _length, michael@0: const UChar *srcChars, michael@0: uint32_t options) const { michael@0: return doCaseCompare(start, _length, srcChars, 0, _length, options); michael@0: } michael@0: michael@0: inline int8_t michael@0: UnicodeString::caseCompare(int32_t start, michael@0: int32_t _length, michael@0: const UChar *srcChars, michael@0: int32_t srcStart, michael@0: int32_t srcLength, michael@0: uint32_t options) const { michael@0: return doCaseCompare(start, _length, srcChars, srcStart, srcLength, options); michael@0: } michael@0: michael@0: inline int8_t michael@0: UnicodeString::caseCompareBetween(int32_t start, michael@0: int32_t limit, michael@0: const UnicodeString &srcText, michael@0: int32_t srcStart, michael@0: int32_t srcLimit, michael@0: uint32_t options) const { michael@0: return doCaseCompare(start, limit - start, srcText, srcStart, srcLimit - srcStart, options); michael@0: } michael@0: michael@0: inline int32_t michael@0: UnicodeString::indexOf(const UnicodeString& srcText, michael@0: int32_t srcStart, michael@0: int32_t srcLength, michael@0: int32_t start, michael@0: int32_t _length) const michael@0: { michael@0: if(!srcText.isBogus()) { michael@0: srcText.pinIndices(srcStart, srcLength); michael@0: if(srcLength > 0) { michael@0: return indexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length); michael@0: } michael@0: } michael@0: return -1; michael@0: } michael@0: michael@0: inline int32_t michael@0: UnicodeString::indexOf(const UnicodeString& text) const michael@0: { return indexOf(text, 0, text.length(), 0, length()); } michael@0: michael@0: inline int32_t michael@0: UnicodeString::indexOf(const UnicodeString& text, michael@0: int32_t start) const { michael@0: pinIndex(start); michael@0: return indexOf(text, 0, text.length(), start, length() - start); michael@0: } michael@0: michael@0: inline int32_t michael@0: UnicodeString::indexOf(const UnicodeString& text, michael@0: int32_t start, michael@0: int32_t _length) const michael@0: { return indexOf(text, 0, text.length(), start, _length); } michael@0: michael@0: inline int32_t michael@0: UnicodeString::indexOf(const UChar *srcChars, michael@0: int32_t srcLength, michael@0: int32_t start) const { michael@0: pinIndex(start); michael@0: return indexOf(srcChars, 0, srcLength, start, length() - start); michael@0: } michael@0: michael@0: inline int32_t michael@0: UnicodeString::indexOf(const UChar *srcChars, michael@0: int32_t srcLength, michael@0: int32_t start, michael@0: int32_t _length) const michael@0: { return indexOf(srcChars, 0, srcLength, start, _length); } michael@0: michael@0: inline int32_t michael@0: UnicodeString::indexOf(UChar c, michael@0: int32_t start, michael@0: int32_t _length) const michael@0: { return doIndexOf(c, start, _length); } michael@0: michael@0: inline int32_t michael@0: UnicodeString::indexOf(UChar32 c, michael@0: int32_t start, michael@0: int32_t _length) const michael@0: { return doIndexOf(c, start, _length); } michael@0: michael@0: inline int32_t michael@0: UnicodeString::indexOf(UChar c) const michael@0: { return doIndexOf(c, 0, length()); } michael@0: michael@0: inline int32_t michael@0: UnicodeString::indexOf(UChar32 c) const michael@0: { return indexOf(c, 0, length()); } michael@0: michael@0: inline int32_t michael@0: UnicodeString::indexOf(UChar c, michael@0: int32_t start) const { michael@0: pinIndex(start); michael@0: return doIndexOf(c, start, length() - start); michael@0: } michael@0: michael@0: inline int32_t michael@0: UnicodeString::indexOf(UChar32 c, michael@0: int32_t start) const { michael@0: pinIndex(start); michael@0: return indexOf(c, start, length() - start); michael@0: } michael@0: michael@0: inline int32_t michael@0: UnicodeString::lastIndexOf(const UChar *srcChars, michael@0: int32_t srcLength, michael@0: int32_t start, michael@0: int32_t _length) const michael@0: { return lastIndexOf(srcChars, 0, srcLength, start, _length); } michael@0: michael@0: inline int32_t michael@0: UnicodeString::lastIndexOf(const UChar *srcChars, michael@0: int32_t srcLength, michael@0: int32_t start) const { michael@0: pinIndex(start); michael@0: return lastIndexOf(srcChars, 0, srcLength, start, length() - start); michael@0: } michael@0: michael@0: inline int32_t michael@0: UnicodeString::lastIndexOf(const UnicodeString& srcText, michael@0: int32_t srcStart, michael@0: int32_t srcLength, michael@0: int32_t start, michael@0: int32_t _length) const michael@0: { michael@0: if(!srcText.isBogus()) { michael@0: srcText.pinIndices(srcStart, srcLength); michael@0: if(srcLength > 0) { michael@0: return lastIndexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length); michael@0: } michael@0: } michael@0: return -1; michael@0: } michael@0: michael@0: inline int32_t michael@0: UnicodeString::lastIndexOf(const UnicodeString& text, michael@0: int32_t start, michael@0: int32_t _length) const michael@0: { return lastIndexOf(text, 0, text.length(), start, _length); } michael@0: michael@0: inline int32_t michael@0: UnicodeString::lastIndexOf(const UnicodeString& text, michael@0: int32_t start) const { michael@0: pinIndex(start); michael@0: return lastIndexOf(text, 0, text.length(), start, length() - start); michael@0: } michael@0: michael@0: inline int32_t michael@0: UnicodeString::lastIndexOf(const UnicodeString& text) const michael@0: { return lastIndexOf(text, 0, text.length(), 0, length()); } michael@0: michael@0: inline int32_t michael@0: UnicodeString::lastIndexOf(UChar c, michael@0: int32_t start, michael@0: int32_t _length) const michael@0: { return doLastIndexOf(c, start, _length); } michael@0: michael@0: inline int32_t michael@0: UnicodeString::lastIndexOf(UChar32 c, michael@0: int32_t start, michael@0: int32_t _length) const { michael@0: return doLastIndexOf(c, start, _length); michael@0: } michael@0: michael@0: inline int32_t michael@0: UnicodeString::lastIndexOf(UChar c) const michael@0: { return doLastIndexOf(c, 0, length()); } michael@0: michael@0: inline int32_t michael@0: UnicodeString::lastIndexOf(UChar32 c) const { michael@0: return lastIndexOf(c, 0, length()); michael@0: } michael@0: michael@0: inline int32_t michael@0: UnicodeString::lastIndexOf(UChar c, michael@0: int32_t start) const { michael@0: pinIndex(start); michael@0: return doLastIndexOf(c, start, length() - start); michael@0: } michael@0: michael@0: inline int32_t michael@0: UnicodeString::lastIndexOf(UChar32 c, michael@0: int32_t start) const { michael@0: pinIndex(start); michael@0: return lastIndexOf(c, start, length() - start); michael@0: } michael@0: michael@0: inline UBool michael@0: UnicodeString::startsWith(const UnicodeString& text) const michael@0: { return compare(0, text.length(), text, 0, text.length()) == 0; } michael@0: michael@0: inline UBool michael@0: UnicodeString::startsWith(const UnicodeString& srcText, michael@0: int32_t srcStart, michael@0: int32_t srcLength) const michael@0: { return doCompare(0, srcLength, srcText, srcStart, srcLength) == 0; } michael@0: michael@0: inline UBool michael@0: UnicodeString::startsWith(const UChar *srcChars, int32_t srcLength) const { michael@0: if(srcLength < 0) { michael@0: srcLength = u_strlen(srcChars); michael@0: } michael@0: return doCompare(0, srcLength, srcChars, 0, srcLength) == 0; michael@0: } michael@0: michael@0: inline UBool michael@0: UnicodeString::startsWith(const UChar *srcChars, int32_t srcStart, int32_t srcLength) const { michael@0: if(srcLength < 0) { michael@0: srcLength = u_strlen(srcChars); michael@0: } michael@0: return doCompare(0, srcLength, srcChars, srcStart, srcLength) == 0; michael@0: } michael@0: michael@0: inline UBool michael@0: UnicodeString::endsWith(const UnicodeString& text) const michael@0: { return doCompare(length() - text.length(), text.length(), michael@0: text, 0, text.length()) == 0; } michael@0: michael@0: inline UBool michael@0: UnicodeString::endsWith(const UnicodeString& srcText, michael@0: int32_t srcStart, michael@0: int32_t srcLength) const { michael@0: srcText.pinIndices(srcStart, srcLength); michael@0: return doCompare(length() - srcLength, srcLength, michael@0: srcText, srcStart, srcLength) == 0; michael@0: } michael@0: michael@0: inline UBool michael@0: UnicodeString::endsWith(const UChar *srcChars, michael@0: int32_t srcLength) const { michael@0: if(srcLength < 0) { michael@0: srcLength = u_strlen(srcChars); michael@0: } michael@0: return doCompare(length() - srcLength, srcLength, michael@0: srcChars, 0, srcLength) == 0; michael@0: } michael@0: michael@0: inline UBool michael@0: UnicodeString::endsWith(const UChar *srcChars, michael@0: int32_t srcStart, michael@0: int32_t srcLength) const { michael@0: if(srcLength < 0) { michael@0: srcLength = u_strlen(srcChars + srcStart); michael@0: } michael@0: return doCompare(length() - srcLength, srcLength, michael@0: srcChars, srcStart, srcLength) == 0; michael@0: } michael@0: michael@0: //======================================== michael@0: // replace michael@0: //======================================== michael@0: inline UnicodeString& michael@0: UnicodeString::replace(int32_t start, michael@0: int32_t _length, michael@0: const UnicodeString& srcText) michael@0: { return doReplace(start, _length, srcText, 0, srcText.length()); } michael@0: michael@0: inline UnicodeString& michael@0: UnicodeString::replace(int32_t start, michael@0: int32_t _length, michael@0: const UnicodeString& srcText, michael@0: int32_t srcStart, michael@0: int32_t srcLength) michael@0: { return doReplace(start, _length, srcText, srcStart, srcLength); } michael@0: michael@0: inline UnicodeString& michael@0: UnicodeString::replace(int32_t start, michael@0: int32_t _length, michael@0: const UChar *srcChars, michael@0: int32_t srcLength) michael@0: { return doReplace(start, _length, srcChars, 0, srcLength); } michael@0: michael@0: inline UnicodeString& michael@0: UnicodeString::replace(int32_t start, michael@0: int32_t _length, michael@0: const UChar *srcChars, michael@0: int32_t srcStart, michael@0: int32_t srcLength) michael@0: { return doReplace(start, _length, srcChars, srcStart, srcLength); } michael@0: michael@0: inline UnicodeString& michael@0: UnicodeString::replace(int32_t start, michael@0: int32_t _length, michael@0: UChar srcChar) michael@0: { return doReplace(start, _length, &srcChar, 0, 1); } michael@0: michael@0: inline UnicodeString& michael@0: UnicodeString::replaceBetween(int32_t start, michael@0: int32_t limit, michael@0: const UnicodeString& srcText) michael@0: { return doReplace(start, limit - start, srcText, 0, srcText.length()); } michael@0: michael@0: inline UnicodeString& michael@0: UnicodeString::replaceBetween(int32_t start, michael@0: int32_t limit, michael@0: const UnicodeString& srcText, michael@0: int32_t srcStart, michael@0: int32_t srcLimit) michael@0: { return doReplace(start, limit - start, srcText, srcStart, srcLimit - srcStart); } michael@0: michael@0: inline UnicodeString& michael@0: UnicodeString::findAndReplace(const UnicodeString& oldText, michael@0: const UnicodeString& newText) michael@0: { return findAndReplace(0, length(), oldText, 0, oldText.length(), michael@0: newText, 0, newText.length()); } michael@0: michael@0: inline UnicodeString& michael@0: UnicodeString::findAndReplace(int32_t start, michael@0: int32_t _length, michael@0: const UnicodeString& oldText, michael@0: const UnicodeString& newText) michael@0: { return findAndReplace(start, _length, oldText, 0, oldText.length(), michael@0: newText, 0, newText.length()); } michael@0: michael@0: // ============================ michael@0: // extract michael@0: // ============================ michael@0: inline void michael@0: UnicodeString::doExtract(int32_t start, michael@0: int32_t _length, michael@0: UnicodeString& target) const michael@0: { target.replace(0, target.length(), *this, start, _length); } michael@0: michael@0: inline void michael@0: UnicodeString::extract(int32_t start, michael@0: int32_t _length, michael@0: UChar *target, michael@0: int32_t targetStart) const michael@0: { doExtract(start, _length, target, targetStart); } michael@0: michael@0: inline void michael@0: UnicodeString::extract(int32_t start, michael@0: int32_t _length, michael@0: UnicodeString& target) const michael@0: { doExtract(start, _length, target); } michael@0: michael@0: #if !UCONFIG_NO_CONVERSION michael@0: michael@0: inline int32_t michael@0: UnicodeString::extract(int32_t start, michael@0: int32_t _length, michael@0: char *dst, michael@0: const char *codepage) const michael@0: michael@0: { michael@0: // This dstSize value will be checked explicitly michael@0: return extract(start, _length, dst, dst!=0 ? 0xffffffff : 0, codepage); michael@0: } michael@0: michael@0: #endif michael@0: michael@0: inline void michael@0: UnicodeString::extractBetween(int32_t start, michael@0: int32_t limit, michael@0: UChar *dst, michael@0: int32_t dstStart) const { michael@0: pinIndex(start); michael@0: pinIndex(limit); michael@0: doExtract(start, limit - start, dst, dstStart); michael@0: } michael@0: michael@0: inline UnicodeString michael@0: UnicodeString::tempSubStringBetween(int32_t start, int32_t limit) const { michael@0: return tempSubString(start, limit - start); michael@0: } michael@0: michael@0: inline UChar michael@0: UnicodeString::doCharAt(int32_t offset) const michael@0: { michael@0: if((uint32_t)offset < (uint32_t)length()) { michael@0: return getArrayStart()[offset]; michael@0: } else { michael@0: return kInvalidUChar; michael@0: } michael@0: } michael@0: michael@0: inline UChar michael@0: UnicodeString::charAt(int32_t offset) const michael@0: { return doCharAt(offset); } michael@0: michael@0: inline UChar michael@0: UnicodeString::operator[] (int32_t offset) const michael@0: { return doCharAt(offset); } michael@0: michael@0: inline UBool michael@0: UnicodeString::isEmpty() const { michael@0: return fShortLength == 0; michael@0: } michael@0: michael@0: //======================================== michael@0: // Write implementation methods michael@0: //======================================== michael@0: inline void michael@0: UnicodeString::setLength(int32_t len) { michael@0: if(len <= 127) { michael@0: fShortLength = (int8_t)len; michael@0: } else { michael@0: fShortLength = (int8_t)-1; michael@0: fUnion.fFields.fLength = len; michael@0: } michael@0: } michael@0: michael@0: inline void michael@0: UnicodeString::setToEmpty() { michael@0: fShortLength = 0; michael@0: fFlags = kShortString; michael@0: } michael@0: michael@0: inline void michael@0: UnicodeString::setArray(UChar *array, int32_t len, int32_t capacity) { michael@0: setLength(len); michael@0: fUnion.fFields.fArray = array; michael@0: fUnion.fFields.fCapacity = capacity; michael@0: } michael@0: michael@0: inline UnicodeString& michael@0: UnicodeString::operator= (UChar ch) michael@0: { return doReplace(0, length(), &ch, 0, 1); } michael@0: michael@0: inline UnicodeString& michael@0: UnicodeString::operator= (UChar32 ch) michael@0: { return replace(0, length(), ch); } michael@0: michael@0: inline UnicodeString& michael@0: UnicodeString::setTo(const UnicodeString& srcText, michael@0: int32_t srcStart, michael@0: int32_t srcLength) michael@0: { michael@0: unBogus(); michael@0: return doReplace(0, length(), srcText, srcStart, srcLength); michael@0: } michael@0: michael@0: inline UnicodeString& michael@0: UnicodeString::setTo(const UnicodeString& srcText, michael@0: int32_t srcStart) michael@0: { michael@0: unBogus(); michael@0: srcText.pinIndex(srcStart); michael@0: return doReplace(0, length(), srcText, srcStart, srcText.length() - srcStart); michael@0: } michael@0: michael@0: inline UnicodeString& michael@0: UnicodeString::setTo(const UnicodeString& srcText) michael@0: { michael@0: return copyFrom(srcText); michael@0: } michael@0: michael@0: inline UnicodeString& michael@0: UnicodeString::setTo(const UChar *srcChars, michael@0: int32_t srcLength) michael@0: { michael@0: unBogus(); michael@0: return doReplace(0, length(), srcChars, 0, srcLength); michael@0: } michael@0: michael@0: inline UnicodeString& michael@0: UnicodeString::setTo(UChar srcChar) michael@0: { michael@0: unBogus(); michael@0: return doReplace(0, length(), &srcChar, 0, 1); michael@0: } michael@0: michael@0: inline UnicodeString& michael@0: UnicodeString::setTo(UChar32 srcChar) michael@0: { michael@0: unBogus(); michael@0: return replace(0, length(), srcChar); michael@0: } michael@0: michael@0: inline UnicodeString& michael@0: UnicodeString::append(const UnicodeString& srcText, michael@0: int32_t srcStart, michael@0: int32_t srcLength) michael@0: { return doReplace(length(), 0, srcText, srcStart, srcLength); } michael@0: michael@0: inline UnicodeString& michael@0: UnicodeString::append(const UnicodeString& srcText) michael@0: { return doReplace(length(), 0, srcText, 0, srcText.length()); } michael@0: michael@0: inline UnicodeString& michael@0: UnicodeString::append(const UChar *srcChars, michael@0: int32_t srcStart, michael@0: int32_t srcLength) michael@0: { return doReplace(length(), 0, srcChars, srcStart, srcLength); } michael@0: michael@0: inline UnicodeString& michael@0: UnicodeString::append(const UChar *srcChars, michael@0: int32_t srcLength) michael@0: { return doReplace(length(), 0, srcChars, 0, srcLength); } michael@0: michael@0: inline UnicodeString& michael@0: UnicodeString::append(UChar srcChar) michael@0: { return doReplace(length(), 0, &srcChar, 0, 1); } michael@0: michael@0: inline UnicodeString& michael@0: UnicodeString::operator+= (UChar ch) michael@0: { return doReplace(length(), 0, &ch, 0, 1); } michael@0: michael@0: inline UnicodeString& michael@0: UnicodeString::operator+= (UChar32 ch) { michael@0: return append(ch); michael@0: } michael@0: michael@0: inline UnicodeString& michael@0: UnicodeString::operator+= (const UnicodeString& srcText) michael@0: { return doReplace(length(), 0, srcText, 0, srcText.length()); } michael@0: michael@0: inline UnicodeString& michael@0: UnicodeString::insert(int32_t start, michael@0: const UnicodeString& srcText, michael@0: int32_t srcStart, michael@0: int32_t srcLength) michael@0: { return doReplace(start, 0, srcText, srcStart, srcLength); } michael@0: michael@0: inline UnicodeString& michael@0: UnicodeString::insert(int32_t start, michael@0: const UnicodeString& srcText) michael@0: { return doReplace(start, 0, srcText, 0, srcText.length()); } michael@0: michael@0: inline UnicodeString& michael@0: UnicodeString::insert(int32_t start, michael@0: const UChar *srcChars, michael@0: int32_t srcStart, michael@0: int32_t srcLength) michael@0: { return doReplace(start, 0, srcChars, srcStart, srcLength); } michael@0: michael@0: inline UnicodeString& michael@0: UnicodeString::insert(int32_t start, michael@0: const UChar *srcChars, michael@0: int32_t srcLength) michael@0: { return doReplace(start, 0, srcChars, 0, srcLength); } michael@0: michael@0: inline UnicodeString& michael@0: UnicodeString::insert(int32_t start, michael@0: UChar srcChar) michael@0: { return doReplace(start, 0, &srcChar, 0, 1); } michael@0: michael@0: inline UnicodeString& michael@0: UnicodeString::insert(int32_t start, michael@0: UChar32 srcChar) michael@0: { return replace(start, 0, srcChar); } michael@0: michael@0: michael@0: inline UnicodeString& michael@0: UnicodeString::remove() michael@0: { michael@0: // remove() of a bogus string makes the string empty and non-bogus michael@0: if(isBogus()) { michael@0: setToEmpty(); michael@0: } else { michael@0: fShortLength = 0; michael@0: } michael@0: return *this; michael@0: } michael@0: michael@0: inline UnicodeString& michael@0: UnicodeString::remove(int32_t start, michael@0: int32_t _length) michael@0: { michael@0: if(start <= 0 && _length == INT32_MAX) { michael@0: // remove(guaranteed everything) of a bogus string makes the string empty and non-bogus michael@0: return remove(); michael@0: } michael@0: return doReplace(start, _length, NULL, 0, 0); michael@0: } michael@0: michael@0: inline UnicodeString& michael@0: UnicodeString::removeBetween(int32_t start, michael@0: int32_t limit) michael@0: { return doReplace(start, limit - start, NULL, 0, 0); } michael@0: michael@0: inline UnicodeString & michael@0: UnicodeString::retainBetween(int32_t start, int32_t limit) { michael@0: truncate(limit); michael@0: return doReplace(0, start, NULL, 0, 0); michael@0: } michael@0: michael@0: inline UBool michael@0: UnicodeString::truncate(int32_t targetLength) michael@0: { michael@0: if(isBogus() && targetLength == 0) { michael@0: // truncate(0) of a bogus string makes the string empty and non-bogus michael@0: unBogus(); michael@0: return FALSE; michael@0: } else if((uint32_t)targetLength < (uint32_t)length()) { michael@0: setLength(targetLength); michael@0: return TRUE; michael@0: } else { michael@0: return FALSE; michael@0: } michael@0: } michael@0: michael@0: inline UnicodeString& michael@0: UnicodeString::reverse() michael@0: { return doReverse(0, length()); } michael@0: michael@0: inline UnicodeString& michael@0: UnicodeString::reverse(int32_t start, michael@0: int32_t _length) michael@0: { return doReverse(start, _length); } michael@0: michael@0: U_NAMESPACE_END michael@0: michael@0: #endif