sl@0: /* sl@0: ********************************************************************** sl@0: * Copyright (C) 1998-2005, International Business Machines sl@0: * Corporation and others. All Rights Reserved. sl@0: ********************************************************************** sl@0: * sl@0: * File unistr.h sl@0: * sl@0: * Modification History: sl@0: * sl@0: * Date Name Description sl@0: * 09/25/98 stephen Creation. sl@0: * 11/11/98 stephen Changed per 11/9 code review. sl@0: * 04/20/99 stephen Overhauled per 4/16 code review. sl@0: * 11/18/99 aliu Made to inherit from Replaceable. Added method sl@0: * handleReplaceBetween(); other methods unchanged. sl@0: * 06/25/01 grhoten Remove dependency on iostream. sl@0: ****************************************************************************** sl@0: */ sl@0: sl@0: #ifndef UNISTR_H sl@0: #define UNISTR_H sl@0: sl@0: /** sl@0: * \file sl@0: * \brief C++ API: Unicode String sl@0: */ sl@0: sl@0: #include "unicode/rep.h" sl@0: sl@0: struct UConverter; // unicode/ucnv.h sl@0: class StringThreadTest; sl@0: sl@0: #ifndef U_COMPARE_CODE_POINT_ORDER sl@0: /* see also ustring.h and unorm.h */ sl@0: /** sl@0: * Option bit for u_strCaseCompare, u_strcasecmp, unorm_compare, etc: sl@0: * Compare strings in code point order instead of code unit order. sl@0: * @stable ICU 2.2 sl@0: */ sl@0: #define U_COMPARE_CODE_POINT_ORDER 0x8000 sl@0: #endif sl@0: sl@0: #ifndef USTRING_H sl@0: /* see ustring.h */ sl@0: U_STABLE int32_t U_EXPORT2 sl@0: u_strlen(const UChar *s); sl@0: #endif sl@0: sl@0: U_NAMESPACE_BEGIN sl@0: sl@0: class Locale; // unicode/locid.h sl@0: class StringCharacterIterator; sl@0: class BreakIterator; // unicode/brkiter.h sl@0: sl@0: /* The include has been moved to unicode/ustream.h */ sl@0: sl@0: /** sl@0: * Constant to be used in the UnicodeString(char *, int32_t, EInvariant) constructor sl@0: * which constructs a Unicode string from an invariant-character char * string. sl@0: * About invariant characters see utypes.h. sl@0: * This constructor has no runtime dependency on conversion code and is sl@0: * therefore recommended over ones taking a charset name string sl@0: * (where the empty string "" indicates invariant-character conversion). sl@0: * sl@0: * @draft ICU 3.2 sl@0: */ sl@0: #define US_INV UnicodeString::kInvariant sl@0: sl@0: /** sl@0: * Unicode String literals in C++. sl@0: * Dependent on the platform properties, different UnicodeString sl@0: * constructors should be used to create a UnicodeString object from sl@0: * a string literal. sl@0: * The macros are defined for maximum performance. sl@0: * They work only for strings that contain "invariant characters", i.e., sl@0: * only latin letters, digits, and some punctuation. sl@0: * See utypes.h for details. sl@0: * sl@0: * The string parameter must be a C string literal. sl@0: * The length of the string, not including the terminating sl@0: * NUL, must be specified as a constant. sl@0: * The U_STRING_DECL macro should be invoked exactly once for one sl@0: * such string variable before it is used. sl@0: * @stable ICU 2.0 sl@0: */ sl@0: #if U_SIZEOF_WCHAR_T==U_SIZEOF_UCHAR && (U_CHARSET_FAMILY==U_ASCII_FAMILY || (U_SIZEOF_UCHAR == 2 && defined(U_WCHAR_IS_UTF16))) sl@0: # define UNICODE_STRING(cs, _length) UnicodeString(TRUE, (const UChar *)L ## cs, _length) sl@0: #elif U_SIZEOF_UCHAR==1 && U_CHARSET_FAMILY==U_ASCII_FAMILY sl@0: # define UNICODE_STRING(cs, _length) UnicodeString(TRUE, (const UChar *)cs, _length) sl@0: #else sl@0: # define UNICODE_STRING(cs, _length) UnicodeString(cs, _length, US_INV) sl@0: #endif sl@0: sl@0: /** sl@0: * Unicode String literals in C++. sl@0: * Dependent on the platform properties, different UnicodeString sl@0: * constructors should be used to create a UnicodeString object from sl@0: * a string literal. sl@0: * The macros are defined for improved performance. sl@0: * They work only for strings that contain "invariant characters", i.e., sl@0: * only latin letters, digits, and some punctuation. sl@0: * See utypes.h for details. sl@0: * sl@0: * The string parameter must be a C string literal. sl@0: * @stable ICU 2.0 sl@0: */ sl@0: #if U_SIZEOF_WCHAR_T==U_SIZEOF_UCHAR && (U_CHARSET_FAMILY==U_ASCII_FAMILY || (U_SIZEOF_UCHAR == 2 && defined(U_WCHAR_IS_UTF16))) sl@0: # define UNICODE_STRING_SIMPLE(cs) UnicodeString(TRUE, (const UChar *)L ## cs, -1) sl@0: #elif U_SIZEOF_UCHAR==1 && U_CHARSET_FAMILY==U_ASCII_FAMILY sl@0: # define UNICODE_STRING_SIMPLE(cs) UnicodeString(TRUE, (const UChar *)cs, -1) sl@0: #else sl@0: # define UNICODE_STRING_SIMPLE(cs) UnicodeString(cs, -1, US_INV) sl@0: #endif sl@0: sl@0: /** sl@0: * UnicodeString is a string class that stores Unicode characters directly and provides sl@0: * similar functionality as the Java String and StringBuffer classes. sl@0: * It is a concrete implementation of the abstract class Replaceable (for transliteration). sl@0: * sl@0: * The UnicodeString class is not suitable for subclassing. sl@0: * sl@0: *

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

sl@0: * sl@0: *

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

sl@0: * sl@0: *

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

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

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

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