Movatterモバイル変換


[0]ホーム

URL:


ICU 77.1  77.1
Data Structures |Public Types |Public Member Functions |Static Public Member Functions |Protected Member Functions |Friends
icu::UnicodeString Class Reference

UnicodeString is a string class that stores Unicode characters directly and provides similar functionality as the Java String and StringBuffer/StringBuilder classes.More...

#include <unistr.h>

Inheritance diagram for icu::UnicodeString:

Public Types

enum  EInvariant {kInvariant }
 Constant to be used in the UnicodeString(char *, int32_t, EInvariant) constructor which constructs a Unicode string from an invariant-character char * string.More...
 

Public Member Functions

bool operator== (constUnicodeString &text) const
 Equality operator.More...
 
template<typename S , typename = std::enable_if_t<ConvertibleToU16StringView<S>>>
bool operator== (const S &text) const
 Equality operator.More...
 
bool operator!= (constUnicodeString &text) const
 Inequality operator.More...
 
template<typename S , typename = std::enable_if_t<ConvertibleToU16StringView<S>>>
bool operator!= (const S &text) const
 Inequality operator.More...
 
UBool operator> (constUnicodeString &text) const
 Greater than operator.More...
 
UBool operator< (constUnicodeString &text) const
 Less than operator.More...
 
UBool operator>= (constUnicodeString &text) const
 Greater than or equal operator.More...
 
UBool operator<= (constUnicodeString &text) const
 Less than or equal operator.More...
 
int8_t compare (constUnicodeString &text) const
 Compare the characters bitwise in thisUnicodeString to the characters intext.More...
 
int8_t compare (int32_t start, int32_tlength, constUnicodeString &text) const
 Compare the characters bitwise in the range [start,start + length) with the characters in theentire stringtext.More...
 
int8_t compare (int32_t start, int32_tlength, constUnicodeString &srcText, int32_t srcStart, int32_t srcLength) const
 Compare the characters bitwise in the range [start,start + length) with the characters insrcText in the range [srcStart,srcStart + srcLength).More...
 
int8_t compare (ConstChar16Ptr srcChars, int32_t srcLength) const
 Compare the characters bitwise in thisUnicodeString with the firstsrcLength characters insrcChars.More...
 
int8_t compare (int32_t start, int32_tlength, const char16_t *srcChars) const
 Compare the characters bitwise in the range [start,start + length) with the firstlength characters insrcCharsMore...
 
int8_t compare (int32_t start, int32_tlength, const char16_t *srcChars, int32_t srcStart, int32_t srcLength) const
 Compare the characters bitwise in the range [start,start + length) with the characters insrcChars in the range [srcStart,srcStart + srcLength).More...
 
int8_t compareBetween (int32_t start, int32_t limit, constUnicodeString &srcText, int32_t srcStart, int32_t srcLimit) const
 Compare the characters bitwise in the range [start,limit) with the characters insrcText in the range [srcStart,srcLimit).More...
 
int8_t compareCodePointOrder (constUnicodeString &text) const
 Compare two Unicode strings in code point order.More...
 
int8_t compareCodePointOrder (int32_t start, int32_tlength, constUnicodeString &srcText) const
 Compare two Unicode strings in code point order.More...
 
int8_t compareCodePointOrder (int32_t start, int32_tlength, constUnicodeString &srcText, int32_t srcStart, int32_t srcLength) const
 Compare two Unicode strings in code point order.More...
 
int8_t compareCodePointOrder (ConstChar16Ptr srcChars, int32_t srcLength) const
 Compare two Unicode strings in code point order.More...
 
int8_t compareCodePointOrder (int32_t start, int32_tlength, const char16_t *srcChars) const
 Compare two Unicode strings in code point order.More...
 
int8_t compareCodePointOrder (int32_t start, int32_tlength, const char16_t *srcChars, int32_t srcStart, int32_t srcLength) const
 Compare two Unicode strings in code point order.More...
 
int8_t compareCodePointOrderBetween (int32_t start, int32_t limit, constUnicodeString &srcText, int32_t srcStart, int32_t srcLimit) const
 Compare two Unicode strings in code point order.More...
 
int8_t caseCompare (constUnicodeString &text, uint32_t options) const
 Compare two strings case-insensitively using full case folding.More...
 
int8_t caseCompare (int32_t start, int32_tlength, constUnicodeString &srcText, uint32_t options) const
 Compare two strings case-insensitively using full case folding.More...
 
int8_t caseCompare (int32_t start, int32_tlength, constUnicodeString &srcText, int32_t srcStart, int32_t srcLength, uint32_t options) const
 Compare two strings case-insensitively using full case folding.More...
 
int8_t caseCompare (ConstChar16Ptr srcChars, int32_t srcLength, uint32_t options) const
 Compare two strings case-insensitively using full case folding.More...
 
int8_t caseCompare (int32_t start, int32_tlength, const char16_t *srcChars, uint32_t options) const
 Compare two strings case-insensitively using full case folding.More...
 
int8_t caseCompare (int32_t start, int32_tlength, const char16_t *srcChars, int32_t srcStart, int32_t srcLength, uint32_t options) const
 Compare two strings case-insensitively using full case folding.More...
 
int8_t caseCompareBetween (int32_t start, int32_t limit, constUnicodeString &srcText, int32_t srcStart, int32_t srcLimit, uint32_t options) const
 Compare two strings case-insensitively using full case folding.More...
 
UBool startsWith (constUnicodeString &text) const
 Determine if this starts with the characters intextMore...
 
UBool startsWith (constUnicodeString &srcText, int32_t srcStart, int32_t srcLength) const
 Determine if this starts with the characters insrcText in the range [srcStart,srcStart + srcLength).More...
 
UBool startsWith (ConstChar16Ptr srcChars, int32_t srcLength) const
 Determine if this starts with the characters insrcCharsMore...
 
UBool startsWith (const char16_t *srcChars, int32_t srcStart, int32_t srcLength) const
 Determine if this ends with the characters insrcChars in the range [srcStart,srcStart + srcLength).More...
 
UBool endsWith (constUnicodeString &text) const
 Determine if this ends with the characters intextMore...
 
UBool endsWith (constUnicodeString &srcText, int32_t srcStart, int32_t srcLength) const
 Determine if this ends with the characters insrcText in the range [srcStart,srcStart + srcLength).More...
 
UBool endsWith (ConstChar16Ptr srcChars, int32_t srcLength) const
 Determine if this ends with the characters insrcCharsMore...
 
UBool endsWith (const char16_t *srcChars, int32_t srcStart, int32_t srcLength) const
 Determine if this ends with the characters insrcChars in the range [srcStart,srcStart + srcLength).More...
 
int32_t indexOf (constUnicodeString &text) const
 Locate in this the first occurrence of the characters intext, using bitwise comparison.More...
 
int32_t indexOf (constUnicodeString &text, int32_t start) const
 Locate in this the first occurrence of the characters intext starting at offsetstart, using bitwise comparison.More...
 
int32_t indexOf (constUnicodeString &text, int32_t start, int32_tlength) const
 Locate in this the first occurrence in the range [start,start + length) of the characters intext, using bitwise comparison.More...
 
int32_t indexOf (constUnicodeString &srcText, int32_t srcStart, int32_t srcLength, int32_t start, int32_tlength) const
 Locate in this the first occurrence in the range [start,start + length) of the characters insrcText in the range [srcStart,srcStart + srcLength), using bitwise comparison.More...
 
int32_t indexOf (const char16_t *srcChars, int32_t srcLength, int32_t start) const
 Locate in this the first occurrence of the characters insrcChars starting at offsetstart, using bitwise comparison.More...
 
int32_t indexOf (ConstChar16Ptr srcChars, int32_t srcLength, int32_t start, int32_tlength) const
 Locate in this the first occurrence in the range [start,start + length) of the characters insrcChars, using bitwise comparison.More...
 
int32_t indexOf (const char16_t *srcChars, int32_t srcStart, int32_t srcLength, int32_t start, int32_tlength) const
 Locate in this the first occurrence in the range [start,start + length) of the characters insrcChars in the range [srcStart,srcStart + srcLength), using bitwise comparison.More...
 
int32_t indexOf (char16_t c) const
 Locate in this the first occurrence of the BMP code pointc, using bitwise comparison.More...
 
int32_t indexOf (UChar32 c) const
 Locate in this the first occurrence of the code pointc, using bitwise comparison.More...
 
int32_t indexOf (char16_t c, int32_t start) const
 Locate in this the first occurrence of the BMP code pointc, starting at offsetstart, using bitwise comparison.More...
 
int32_t indexOf (UChar32 c, int32_t start) const
 Locate in this the first occurrence of the code pointc starting at offsetstart, using bitwise comparison.More...
 
int32_t indexOf (char16_t c, int32_t start, int32_tlength) const
 Locate in this the first occurrence of the BMP code pointc in the range [start,start + length), using bitwise comparison.More...
 
int32_t indexOf (UChar32 c, int32_t start, int32_tlength) const
 Locate in this the first occurrence of the code pointc in the range [start,start + length), using bitwise comparison.More...
 
int32_t lastIndexOf (constUnicodeString &text) const
 Locate in this the last occurrence of the characters intext, using bitwise comparison.More...
 
int32_t lastIndexOf (constUnicodeString &text, int32_t start) const
 Locate in this the last occurrence of the characters intext starting at offsetstart, using bitwise comparison.More...
 
int32_t lastIndexOf (constUnicodeString &text, int32_t start, int32_tlength) const
 Locate in this the last occurrence in the range [start,start + length) of the characters intext, using bitwise comparison.More...
 
int32_t lastIndexOf (constUnicodeString &srcText, int32_t srcStart, int32_t srcLength, int32_t start, int32_tlength) const
 Locate in this the last occurrence in the range [start,start + length) of the characters insrcText in the range [srcStart,srcStart + srcLength), using bitwise comparison.More...
 
int32_t lastIndexOf (const char16_t *srcChars, int32_t srcLength, int32_t start) const
 Locate in this the last occurrence of the characters insrcChars starting at offsetstart, using bitwise comparison.More...
 
int32_t lastIndexOf (ConstChar16Ptr srcChars, int32_t srcLength, int32_t start, int32_tlength) const
 Locate in this the last occurrence in the range [start,start + length) of the characters insrcChars, using bitwise comparison.More...
 
int32_t lastIndexOf (const char16_t *srcChars, int32_t srcStart, int32_t srcLength, int32_t start, int32_tlength) const
 Locate in this the last occurrence in the range [start,start + length) of the characters insrcChars in the range [srcStart,srcStart + srcLength), using bitwise comparison.More...
 
int32_t lastIndexOf (char16_t c) const
 Locate in this the last occurrence of the BMP code pointc, using bitwise comparison.More...
 
int32_t lastIndexOf (UChar32 c) const
 Locate in this the last occurrence of the code pointc, using bitwise comparison.More...
 
int32_t lastIndexOf (char16_t c, int32_t start) const
 Locate in this the last occurrence of the BMP code pointc starting at offsetstart, using bitwise comparison.More...
 
int32_t lastIndexOf (UChar32 c, int32_t start) const
 Locate in this the last occurrence of the code pointc starting at offsetstart, using bitwise comparison.More...
 
int32_t lastIndexOf (char16_t c, int32_t start, int32_tlength) const
 Locate in this the last occurrence of the BMP code pointc in the range [start,start + length), using bitwise comparison.More...
 
int32_t lastIndexOf (UChar32 c, int32_t start, int32_tlength) const
 Locate in this the last occurrence of the code pointc in the range [start,start + length), using bitwise comparison.More...
 
char16_t charAt (int32_t offset) const
 Return the code unit at offsetoffset.More...
 
char16_t operator[] (int32_t offset) const
 Return the code unit at offsetoffset.More...
 
UChar32 char32At (int32_t offset) const
 Return the code point that contains the code unit at offsetoffset.More...
 
int32_t getChar32Start (int32_t offset) const
 Adjust a random-access offset so that it points to the beginning of a Unicode character.More...
 
int32_t getChar32Limit (int32_t offset) const
 Adjust a random-access offset so that it points behind a Unicode character.More...
 
int32_t moveIndex32 (int32_t index, int32_t delta) const
 Move the code unit index along the string by delta code points.More...
 
void extract (int32_t start, int32_tlength,Char16Ptr dst, int32_t dstStart=0) const
 Copy the characters in the range [start,start + length) into the arraydst, beginning atdstStart.More...
 
int32_t extract (Char16Ptr dest, int32_t destCapacity,UErrorCode &errorCode) const
 Copy the contents of the string into dest.More...
 
void extract (int32_t start, int32_tlength,UnicodeString &target) const
 Copy the characters in the range [start,start + length) into theUnicodeStringtarget.More...
 
void extractBetween (int32_t start, int32_t limit, char16_t *dst, int32_t dstStart=0) const
 Copy the characters in the range [start,limit) into the arraydst, beginning atdstStart.More...
 
virtual void extractBetween (int32_t start, int32_t limit,UnicodeString &target) const override
 Copy the characters in the range [start,limit) into theUnicodeStringtarget.More...
 
int32_t extract (int32_t start, int32_t startLength, char *target, int32_t targetCapacity, enumEInvariant inv) const
 Copy the characters in the range [start,start + startLength) into an array of characters.More...
 
int32_t extract (int32_t start, int32_t startLength, char *target, uint32_t targetLength) const
 Copy the characters in the range [start,start + length) into an array of characters in the platform's default codepage.More...
 
int32_t extract (int32_t start, int32_t startLength, char *target, const char *codepage=nullptr) const
 Copy the characters in the range [start,start + length) into an array of characters in a specified codepage.More...
 
int32_t extract (int32_t start, int32_t startLength, char *target, uint32_t targetLength, const char *codepage) const
 Copy the characters in the range [start,start + length) into an array of characters in a specified codepage.More...
 
int32_t extract (char *dest, int32_t destCapacity,UConverter *cnv,UErrorCode &errorCode) const
 Convert theUnicodeString into a codepage string using an existing UConverter.More...
 
UnicodeString tempSubString (int32_t start=0, int32_tlength=INT32_MAX) const
 Create a temporary substring for the specified range.More...
 
UnicodeString tempSubStringBetween (int32_t start, int32_t limit=INT32_MAX) const
 Create a temporary substring for the specified range.More...
 
void toUTF8 (ByteSink &sink) const
 Convert theUnicodeString to UTF-8 and write the result to aByteSink.More...
 
template<typename StringClass >
StringClass & toUTF8String (StringClass &result) const
 Convert theUnicodeString to UTF-8 and append the result to a standard string.More...
 
int32_t toUTF32 (UChar32 *utf32, int32_t capacity,UErrorCode &errorCode) const
 Convert theUnicodeString to UTF-32.More...
 
int32_t length () const
 Return the length of theUnicodeString object.More...
 
int32_t countChar32 (int32_t start=0, int32_tlength=INT32_MAX) const
 Count Unicode code points in the length char16_t code units of the string.More...
 
UBool hasMoreChar32Than (int32_t start, int32_tlength, int32_t number) const
 Check if the length char16_t code units of the string contain more Unicode code points than a certain number.More...
 
UBool isEmpty () const
 Determine if this string is empty.More...
 
int32_t getCapacity () const
 Return the capacity of the internal buffer of theUnicodeString object.More...
 
int32_t hashCode () const
 Generate a hash code for this object.More...
 
UBool isBogus () const
 Determine if this object contains a valid string.More...
 
UnicodeStringoperator= (constUnicodeString &srcText)
 Assignment operator.More...
 
UnicodeStringfastCopyFrom (constUnicodeString &src)
 Almost the same as the assignment operator.More...
 
template<typename S , typename = std::enable_if_t<ConvertibleToU16StringView<S>>>
UnicodeStringoperator= (const S &src)
 Assignment operator.More...
 
UnicodeStringoperator= (UnicodeString &&src) noexcept
 Move assignment operator; might leave src in bogus state.More...
 
void swap (UnicodeString &other) noexcept
 Swap strings.More...
 
UnicodeStringoperator= (char16_t ch)
 Assignment operator.More...
 
UnicodeStringoperator= (UChar32 ch)
 Assignment operator.More...
 
UnicodeStringsetTo (constUnicodeString &srcText, int32_t srcStart)
 Set the text in theUnicodeString object to the characters insrcText in the range [srcStart,srcText.length()).More...
 
UnicodeStringsetTo (constUnicodeString &srcText, int32_t srcStart, int32_t srcLength)
 Set the text in theUnicodeString object to the characters insrcText in the range [srcStart,srcStart + srcLength).More...
 
UnicodeStringsetTo (constUnicodeString &srcText)
 Set the text in theUnicodeString object to the characters insrcText.More...
 
UnicodeStringsetTo (const char16_t *srcChars, int32_t srcLength)
 Set the characters in theUnicodeString object to the characters insrcChars.More...
 
UnicodeStringsetTo (char16_t srcChar)
 Set the characters in theUnicodeString object to the code unitsrcChar.More...
 
UnicodeStringsetTo (UChar32 srcChar)
 Set the characters in theUnicodeString object to the code pointsrcChar.More...
 
UnicodeStringsetTo (UBool isTerminated,ConstChar16Ptr text, int32_t textLength)
 AliasingsetTo() function, analogous to the readonly-aliasing char16_t* constructor.More...
 
UnicodeStringsetTo (char16_t *buffer, int32_t buffLength, int32_t buffCapacity)
 AliasingsetTo() function, analogous to the writable-aliasing char16_t* constructor.More...
 
void setToBogus ()
 Make thisUnicodeString object invalid.More...
 
UnicodeStringsetCharAt (int32_t offset, char16_t ch)
 Set the character at the specified offset to the specified character.More...
 
UnicodeStringoperator+= (char16_t ch)
 Append operator.More...
 
UnicodeStringoperator+= (UChar32 ch)
 Append operator.More...
 
UnicodeStringoperator+= (constUnicodeString &srcText)
 Append operator.More...
 
template<typename S , typename = std::enable_if_t<ConvertibleToU16StringView<S>>>
UnicodeStringoperator+= (const S &src)
 Append operator.More...
 
UnicodeStringappend (constUnicodeString &srcText, int32_t srcStart, int32_t srcLength)
 Append the characters insrcText in the range [srcStart,srcStart + srcLength) to theUnicodeString object at offsetstart.More...
 
UnicodeStringappend (constUnicodeString &srcText)
 Append the characters insrcText to theUnicodeString object.More...
 
UnicodeStringappend (const char16_t *srcChars, int32_t srcStart, int32_t srcLength)
 Append the characters insrcChars in the range [srcStart,srcStart + srcLength) to theUnicodeString object at offsetstart.More...
 
UnicodeStringappend (ConstChar16Ptr srcChars, int32_t srcLength)
 Append the characters insrcChars to theUnicodeString object.More...
 
template<typename S , typename = std::enable_if_t<ConvertibleToU16StringView<S>>>
UnicodeStringappend (const S &src)
 Appends the characters insrc which is, or which is implicitly convertible to, a std::u16string_view or (if U_SIZEOF_WCHAR_T==2) std::wstring_view, to theUnicodeString object.More...
 
UnicodeStringappend (char16_t srcChar)
 Append the code unitsrcChar to theUnicodeString object.More...
 
UnicodeStringappend (UChar32 srcChar)
 Append the code pointsrcChar to theUnicodeString object.More...
 
UnicodeStringinsert (int32_t start, constUnicodeString &srcText, int32_t srcStart, int32_t srcLength)
 Insert the characters insrcText in the range [srcStart,srcStart + srcLength) into theUnicodeString object at offsetstart.More...
 
UnicodeStringinsert (int32_t start, constUnicodeString &srcText)
 Insert the characters insrcText into theUnicodeString object at offsetstart.More...
 
UnicodeStringinsert (int32_t start, const char16_t *srcChars, int32_t srcStart, int32_t srcLength)
 Insert the characters insrcChars in the range [srcStart,srcStart + srcLength) into theUnicodeString object at offsetstart.More...
 
UnicodeStringinsert (int32_t start,ConstChar16Ptr srcChars, int32_t srcLength)
 Insert the characters insrcChars into theUnicodeString object at offsetstart.More...
 
UnicodeStringinsert (int32_t start, char16_t srcChar)
 Insert the code unitsrcChar into theUnicodeString object at offsetstart.More...
 
UnicodeStringinsert (int32_t start,UChar32 srcChar)
 Insert the code pointsrcChar into theUnicodeString object at offsetstart.More...
 
UnicodeStringreplace (int32_t start, int32_tlength, constUnicodeString &srcText, int32_t srcStart, int32_t srcLength)
 Replace the characters in the range [start,start + length) with the characters insrcText in the range [srcStart,srcStart + srcLength).More...
 
UnicodeStringreplace (int32_t start, int32_tlength, constUnicodeString &srcText)
 Replace the characters in the range [start,start + length) with the characters insrcText.More...
 
UnicodeStringreplace (int32_t start, int32_tlength, const char16_t *srcChars, int32_t srcStart, int32_t srcLength)
 Replace the characters in the range [start,start + length) with the characters insrcChars in the range [srcStart,srcStart + srcLength).More...
 
UnicodeStringreplace (int32_t start, int32_tlength,ConstChar16Ptr srcChars, int32_t srcLength)
 Replace the characters in the range [start,start + length) with the characters insrcChars.More...
 
UnicodeStringreplace (int32_t start, int32_tlength, char16_t srcChar)
 Replace the characters in the range [start,start + length) with the code unitsrcChar.More...
 
UnicodeStringreplace (int32_t start, int32_tlength,UChar32 srcChar)
 Replace the characters in the range [start,start + length) with the code pointsrcChar.More...
 
UnicodeStringreplaceBetween (int32_t start, int32_t limit, constUnicodeString &srcText)
 Replace the characters in the range [start,limit) with the characters insrcText.More...
 
UnicodeStringreplaceBetween (int32_t start, int32_t limit, constUnicodeString &srcText, int32_t srcStart, int32_t srcLimit)
 Replace the characters in the range [start,limit) with the characters insrcText in the range [srcStart,srcLimit).More...
 
virtual void handleReplaceBetween (int32_t start, int32_t limit, constUnicodeString &text) override
 Replace a substring of this object with the given text.More...
 
virtualUBool hasMetaData () const override
 Replaceable API.More...
 
virtual void copy (int32_t start, int32_t limit, int32_t dest) override
 Copy a substring of this object, retaining attribute (out-of-band) information.More...
 
UnicodeStringfindAndReplace (constUnicodeString &oldText, constUnicodeString &newText)
 Replace all occurrences of characters in oldText with the characters in newText.More...
 
UnicodeStringfindAndReplace (int32_t start, int32_tlength, constUnicodeString &oldText, constUnicodeString &newText)
 Replace all occurrences of characters in oldText with characters in newText in the range [start,start + length).More...
 
UnicodeStringfindAndReplace (int32_t start, int32_tlength, constUnicodeString &oldText, int32_t oldStart, int32_t oldLength, constUnicodeString &newText, int32_t newStart, int32_t newLength)
 Replace all occurrences of characters in oldText in the range [oldStart,oldStart + oldLength) with the characters in newText in the range [newStart,newStart + newLength) in the range [start,start + length).More...
 
UnicodeStringremove ()
 Removes all characters from theUnicodeString object and clears the bogus flag.More...
 
UnicodeStringremove (int32_t start, int32_tlength=static_cast< int32_t >(INT32_MAX))
 Remove the characters in the range [start,start + length) from theUnicodeString object.More...
 
UnicodeStringremoveBetween (int32_t start, int32_t limit=static_cast< int32_t >(INT32_MAX))
 Remove the characters in the range [start,limit) from theUnicodeString object.More...
 
UnicodeStringretainBetween (int32_t start, int32_t limit=INT32_MAX)
 Retain only the characters in the range [start,limit) from theUnicodeString object.More...
 
UBool padLeading (int32_t targetLength, char16_t padChar=0x0020)
 Pad the start of thisUnicodeString with the characterpadChar.More...
 
UBool padTrailing (int32_t targetLength, char16_t padChar=0x0020)
 Pad the end of thisUnicodeString with the characterpadChar.More...
 
UBool truncate (int32_t targetLength)
 Truncate thisUnicodeString to thetargetLength.More...
 
UnicodeStringtrim ()
 Trims leading and trailing whitespace from thisUnicodeString.More...
 
UnicodeStringreverse ()
 Reverse thisUnicodeString in place.More...
 
UnicodeStringreverse (int32_t start, int32_tlength)
 Reverse the range [start,start + length) in thisUnicodeString.More...
 
UnicodeStringtoUpper ()
 Convert the characters in this to UPPER CASE following the conventions of the default locale.More...
 
UnicodeStringtoUpper (constLocale &locale)
 Convert the characters in this to UPPER CASE following the conventions of a specific locale.More...
 
UnicodeStringtoLower ()
 Convert the characters in this to lower case following the conventions of the default locale.More...
 
UnicodeStringtoLower (constLocale &locale)
 Convert the characters in this to lower case following the conventions of a specific locale.More...
 
UnicodeStringtoTitle (BreakIterator *titleIter)
 Titlecase this string, convenience function using the default locale.More...
 
UnicodeStringtoTitle (BreakIterator *titleIter, constLocale &locale)
 Titlecase this string.More...
 
UnicodeStringtoTitle (BreakIterator *titleIter, constLocale &locale, uint32_t options)
 Titlecase this string, with options.More...
 
UnicodeStringfoldCase (uint32_t options=0)
 Case-folds the characters in this string.More...
 
char16_t * getBuffer (int32_t minCapacity)
 Get a read/write pointer to the internal buffer.More...
 
void releaseBuffer (int32_t newLength=-1)
 Release a read/write buffer on aUnicodeString object with an "open" getBuffer(minCapacity).More...
 
const char16_t * getBuffer () const
 Get a read-only pointer to the internal buffer.More...
 
const char16_t * getTerminatedBuffer ()
 Get a read-only pointer to the internal buffer, making sure that it is NUL-terminated.More...
 
 operator std::u16string_view () const
 Converts to a std::u16string_view.More...
 
 operator std::wstring_view () const
 Converts to a std::wstring_view.More...
 
 UnicodeString ()
 Construct an emptyUnicodeString.More...
 
 UnicodeString (int32_t capacity,UChar32 c, int32_t count)
 Construct aUnicodeString with capacity to holdcapacity char16_ts.More...
 
UNISTR_FROM_CHAR_EXPLICIT UnicodeString (char16_t ch)
 Single char16_t (code unit) constructor.More...
 
UNISTR_FROM_CHAR_EXPLICIT UnicodeString (UChar32 ch)
 Single UChar32 (code point) constructor.More...
 
UNISTR_FROM_STRING_EXPLICIT UnicodeString (const std::nullptr_t text)
 nullptr_t constructor.More...
 
 UnicodeString (const char16_t *text, int32_t textLength)
 char16_t* constructor.More...
 
 UnicodeString (const uint16_t *text, int32_t textLength)
 uint16_t * constructor.More...
 
 UnicodeString (const wchar_t *text, int32_t textLength)
 wchar_t * constructor.More...
 
 UnicodeString (const std::nullptr_t text, int32_t textLength)
 nullptr_t constructor.More...
 
template<typename S , typename = std::enable_if_t<ConvertibleToU16StringView<S>>>
UNISTR_FROM_STRING_EXPLICIT UnicodeString (const S &text)
 Constructor fromtext which is, or which is implicitly convertible to, a std::u16string_view or (if U_SIZEOF_WCHAR_T==2) std::wstring_view.More...
 
 UnicodeString (UBool isTerminated,ConstChar16Ptr text, int32_t textLength)
 Readonly-aliasing char16_t* constructor.More...
 
 UnicodeString (char16_t *buffer, int32_t buffLength, int32_t buffCapacity)
 Writable-aliasing char16_t* constructor.More...
 
 UnicodeString (uint16_t *buffer, int32_t buffLength, int32_t buffCapacity)
 Writable-aliasing uint16_t * constructor.More...
 
 UnicodeString (wchar_t *buffer, int32_t buffLength, int32_t buffCapacity)
 Writable-aliasing wchar_t * constructor.More...
 
 UnicodeString (std::nullptr_t buffer, int32_t buffLength, int32_t buffCapacity)
 Writable-aliasing nullptr_t constructor.More...
 
UNISTR_FROM_STRING_EXPLICIT UnicodeString (const char *codepageData)
 char* constructor.More...
 
 UnicodeString (const char *codepageData, int32_t dataLength)
 char* constructor.More...
 
 UnicodeString (const char *codepageData, const char *codepage)
 char* constructor.More...
 
 UnicodeString (const char *codepageData, int32_t dataLength, const char *codepage)
 char* constructor.More...
 
 UnicodeString (const char *src, int32_t srcLength,UConverter *cnv,UErrorCode &errorCode)
 char * / UConverter constructor.More...
 
 UnicodeString (const char *src, int32_t textLength, enumEInvariant inv)
 Constructs a Unicode string from an invariant-character char * string.More...
 
 UnicodeString (constUnicodeString &that)
 Copy constructor.More...
 
 UnicodeString (UnicodeString &&src) noexcept
 Move constructor; might leave src in bogus state.More...
 
 UnicodeString (constUnicodeString &src, int32_t srcStart)
 'Substring' constructor from tail of source string.More...
 
 UnicodeString (constUnicodeString &src, int32_t srcStart, int32_t srcLength)
 'Substring' constructor from subrange of source string.More...
 
virtualUnicodeStringclone () const override
 Clone this object, an instance of a subclass ofReplaceable.More...
 
virtual ~UnicodeString ()
 Destructor.More...
 
UnicodeString unescape () const
 Unescape a string of characters and return a string containing the result.More...
 
UChar32 unescapeAt (int32_t &offset) const
 Unescape a single escape sequence and return the represented character.More...
 
virtualUClassID getDynamicClassID () const override
 ICU "poor man's RTTI", returns a UClassID for the actual class.More...
 
- Public Member Functions inherited fromicu::Replaceable
virtual ~Replaceable ()
 Destructor.More...
 
int32_t length () const
 Returns the number of 16-bit code units in the text.More...
 
char16_t charAt (int32_t offset) const
 Returns the 16-bit code unit at the given offset into the text.More...
 
UChar32 char32At (int32_t offset) const
 Returns the 32-bit code point at the given 16-bit offset into the text.More...
 
- Public Member Functions inherited fromicu::UObject
virtual ~UObject ()
 Destructor.More...
 

Static Public Member Functions

template<typename S , typename = std::enable_if_t<ConvertibleToU16StringView<S>>>
staticUnicodeString readOnlyAlias (const S &text)
 Readonly-aliasing factory method.More...
 
staticUnicodeString readOnlyAlias (constUnicodeString &text)
 Readonly-aliasing factory method.More...
 
staticUnicodeString fromUTF8 (StringPiece utf8)
 Create aUnicodeString from a UTF-8 string.More...
 
staticUnicodeString fromUTF32 (constUChar32 *utf32, int32_tlength)
 Create aUnicodeString from a UTF-32 string.More...
 
staticUClassID getStaticClassID ()
 ICU "poor man's RTTI", returns a UClassID for this class.More...
 

Protected Member Functions

virtual int32_t getLength () const override
 ImplementReplaceable::getLength() (see jitterbug 1027).More...
 
virtual char16_t getCharAt (int32_t offset) const override
 The change inReplaceable to use virtualgetCharAt() allowsUnicodeString::charAt() to be inline again (see jitterbug 709).More...
 
virtualUChar32 getChar32At (int32_t offset) const override
 The change inReplaceable to use virtualgetChar32At() allowsUnicodeString::char32At() to be inline again (see jitterbug 709).More...
 
- Protected Member Functions inherited fromicu::Replaceable
 Replaceable ()
 Default constructor.More...
 

Friends

class UnicodeStringAppendable
 
union StackBufferOrFields
 
void swap (UnicodeString &s1,UnicodeString &s2) noexcept
 Non-memberUnicodeString swap function.More...
 

Detailed Description

UnicodeString is a string class that stores Unicode characters directly and provides similar functionality as the Java String and StringBuffer/StringBuilder classes.

It is a concrete implementation of the abstract classReplaceable (for transliteration).

TheUnicodeString equivalent of std::string’s clear() isremove().

AUnicodeString may "alias" an external array of characters (that is, point to it, rather than own the array) whose lifetime must then at least match the lifetime of the aliasing object. This aliasing may be preserved when returning aUnicodeString by value, depending on the compiler and the function implementation, via Return Value Optimization (RVO) or the move assignment operator. (However, the copy assignment operator does not preserve aliasing.) For details see the description of storage models at the end of the class API docs and in the User Guide chapter linked from there.

TheUnicodeString class is not suitable for subclassing.

For an overview of Unicode strings in C and C++ see theUser Guide Strings chapter.

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

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

UnicodeString methods are more lenient with regard to input parameter values than other ICU APIs. In particular:

In string comparisons, twoUnicodeString objects that are both "bogus" compare equal (to be transitive and prevent endless loops in sorting), and a "bogus" string compares less than any non-"bogus" one.

ConstUnicodeString methods are thread-safe. Multiple threads can use const methods on the sameUnicodeString object simultaneously, but non-const methods must not be called concurrently (in multiple threads) with any other (const or non-const) methods.

Similarly, constUnicodeString & parameters are thread-safe. One object may be passed in as such a parameter concurrently in multiple threads. This includes the constUnicodeString & parameters for copy construction, assignment, and cloning.

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

See also
utf.h
CharacterIterator
Stable:
ICU 2.0

Definition at line295 of fileunistr.h.

Member Enumeration Documentation

◆ EInvariant

enumicu::UnicodeString::EInvariant

Constant to be used in the UnicodeString(char *, int32_t, EInvariant) constructor which constructs a Unicode string from an invariant-character char * string.

Use the macro US_INV instead of the full qualification for this value.

See also
US_INV
Stable:
ICU 3.2
Enumerator
kInvariant 
See also
EInvariant
Stable:
ICU 3.2

Definition at line307 of fileunistr.h.

Constructor & Destructor Documentation

◆ UnicodeString()[1/25]

icu::UnicodeString::UnicodeString()
inline

Construct an emptyUnicodeString.

Stable:
ICU 2.0

Definition at line4182 of fileunistr.h.

◆ UnicodeString()[2/25]

icu::UnicodeString::UnicodeString(int32_t capacity,
UChar32 c,
int32_t count 
)

Construct aUnicodeString with capacity to holdcapacity char16_ts.

Parameters
capacitythe number of char16_ts thisUnicodeString should hold before a resize is necessary; if count is greater than 0 and count code points c take up more space than capacity, then capacity is adjusted accordingly.
cis used to initially fill the string
countspecifies how many code points c are to be written in the string
Stable:
ICU 2.0

◆ UnicodeString()[3/25]

UNISTR_FROM_CHAR_EXPLICIT icu::UnicodeString::UnicodeString(char16_t ch)

Single char16_t (code unit) constructor.

It is recommended to mark this constructor "explicit" by-DUNISTR_FROM_CHAR_EXPLICIT=explicit on the compiler command line or similar.

Parameters
chthe character to place in theUnicodeString
Stable:
ICU 2.0

◆ UnicodeString()[4/25]

UNISTR_FROM_CHAR_EXPLICIT icu::UnicodeString::UnicodeString(UChar32 ch)

Single UChar32 (code point) constructor.

It is recommended to mark this constructor "explicit" by-DUNISTR_FROM_CHAR_EXPLICIT=explicit on the compiler command line or similar.

Parameters
chthe character to place in theUnicodeString
Stable:
ICU 2.0

◆ UnicodeString()[5/25]

icu::UnicodeString::UnicodeString(const std::nullptr_t text)
inline

nullptr_t constructor.

Effectively the same as the default constructor, makes an empty string object.

It is recommended to mark this constructor "explicit" by-DUNISTR_FROM_STRING_EXPLICIT=explicit on the compiler command line or similar.

Parameters
textnullptr
Stable:
ICU 59

Definition at line4186 of fileunistr.h.

◆ UnicodeString()[6/25]

icu::UnicodeString::UnicodeString(const char16_t * text,
int32_t textLength 
)

char16_t* constructor.

Note, for string literals: Since C++17 and ICU 76, you can use UTF-16 string literals with compile-time length determination:

UnicodeString str(u"literal");
if (str == u"other literal") { ... }
UnicodeString()
Construct an empty UnicodeString.
Definition:unistr.h:4182
Parameters
textThe characters to place in theUnicodeString.
textLengthThe number of Unicode characters intext to copy.
Stable:
ICU 2.0

◆ UnicodeString()[7/25]

icu::UnicodeString::UnicodeString(const uint16_t * text,
int32_t textLength 
)
inline

uint16_t * constructor.

Delegates toUnicodeString(const char16_t *, int32_t).

Note, for string literals: Since C++17 and ICU 76, you can use UTF-16 string literals with compile-time length determination:

UnicodeString str(u"literal");
if (str == u"other literal") { ... }
Parameters
textUTF-16 string
textLengthstring length
Stable:
ICU 59

Definition at line3225 of fileunistr.h.

◆ UnicodeString()[8/25]

icu::UnicodeString::UnicodeString(const wchar_t * text,
int32_t textLength 
)
inline

wchar_t * constructor.

(Only defined if U_SIZEOF_WCHAR_T==2.) Delegates toUnicodeString(const char16_t *, int32_t).

Note, for string literals: Since C++17 and ICU 76, you can use UTF-16 string literals with compile-time length determination:

UnicodeString str(u"literal");
if (str == u"other literal") { ... }
Parameters
textUTF-16 string
textLengthstring length
Stable:
ICU 59

Definition at line3247 of fileunistr.h.

◆ UnicodeString()[9/25]

icu::UnicodeString::UnicodeString(const std::nullptr_t text,
int32_t textLength 
)
inline

nullptr_t constructor.

Effectively the same as the default constructor, makes an empty string object.

Parameters
textnullptr
textLengthignored
Stable:
ICU 59

Definition at line4190 of fileunistr.h.

◆ UnicodeString()[10/25]

template<typename S , typename = std::enable_if_t<ConvertibleToU16StringView<S>>>
UNISTR_FROM_STRING_EXPLICIT icu::UnicodeString::UnicodeString(const S & text)
inline

Constructor fromtext which is, or which is implicitly convertible to, a std::u16string_view or (if U_SIZEOF_WCHAR_T==2) std::wstring_view.

The string is bogus if the string view is too long.

If you need aUnicodeString but need not copy the string view contents, then you can call theUnicodeString::readOnlyAlias() function instead of this constructor.

Parameters
textUTF-16 string
Draft:
This API may be changed in the future versions and was introduced in ICU 76

Definition at line3274 of fileunistr.h.

◆ UnicodeString()[11/25]

icu::UnicodeString::UnicodeString(UBool isTerminated,
ConstChar16Ptr text,
int32_t textLength 
)

Readonly-aliasing char16_t* constructor.

The text will be used for theUnicodeString object, but it will not be released when theUnicodeString is destroyed. This has copy-on-write semantics: When the string is modified, then the buffer is first copied into newly allocated memory. The aliased buffer is never modified.

In an assignment to anotherUnicodeString, when using the copy constructor or the assignment operator, the text will be copied. When usingfastCopyFrom(), the text will be aliased again, so that both strings then alias the same readonly-text.

Note, for string literals: Since C++17 and ICU 76, you can use UTF-16 string literals with compile-time length determination:

UnicodeString alias =UnicodeString::readOnlyAlias(u"literal");
if (str == u"other literal") { ... }
static UnicodeString readOnlyAlias(const S &text)
Readonly-aliasing factory method.
Definition:unistr.h:3600
Parameters
isTerminatedspecifies iftext isNUL-terminated. This must be true iftextLength==-1.
textThe characters to alias for theUnicodeString.
textLengthThe number of Unicode characters intext to alias. If -1, then this constructor will determine the length by callingu_strlen().
Stable:
ICU 2.0

◆ UnicodeString()[12/25]

icu::UnicodeString::UnicodeString(char16_t * buffer,
int32_t buffLength,
int32_t buffCapacity 
)

Writable-aliasing char16_t* constructor.

The text will be used for theUnicodeString object, but it will not be released when theUnicodeString is destroyed. This has write-through semantics: For as long as the capacity of the buffer is sufficient, write operations will directly affect the buffer. When more capacity is necessary, then a new buffer will be allocated and the contents copied as with regularly constructed strings. In an assignment to anotherUnicodeString, the buffer will be copied. The extract(Char16Ptr dst) function detects whether the dst pointer is the same as the string buffer itself and will in this case not copy the contents.

Parameters
bufferThe characters to alias for theUnicodeString.
buffLengthThe number of Unicode characters inbuffer to alias.
buffCapacityThe size ofbuffer in char16_ts.
Stable:
ICU 2.0

◆ UnicodeString()[13/25]

icu::UnicodeString::UnicodeString(uint16_t * buffer,
int32_t buffLength,
int32_t buffCapacity 
)
inline

Writable-aliasing uint16_t * constructor.

Delegates to UnicodeString(const char16_t *, int32_t, int32_t).

Parameters
bufferwritable buffer of/for UTF-16 text
buffLengthlength of the current buffer contents
buffCapacitybuffer capacity
Stable:
ICU 59

Definition at line3343 of fileunistr.h.

◆ UnicodeString()[14/25]

icu::UnicodeString::UnicodeString(wchar_t * buffer,
int32_t buffLength,
int32_t buffCapacity 
)
inline

Writable-aliasing wchar_t * constructor.

(Only defined if U_SIZEOF_WCHAR_T==2.) Delegates to UnicodeString(const char16_t *, int32_t, int32_t).

Parameters
bufferwritable buffer of/for UTF-16 text
buffLengthlength of the current buffer contents
buffCapacitybuffer capacity
Stable:
ICU 59

Definition at line3357 of fileunistr.h.

◆ UnicodeString()[15/25]

icu::UnicodeString::UnicodeString(std::nullptr_t buffer,
int32_t buffLength,
int32_t buffCapacity 
)
inline

Writable-aliasing nullptr_t constructor.

Effectively the same as the default constructor, makes an empty string object.

Parameters
buffernullptr
buffLengthignored
buffCapacityignored
Stable:
ICU 59

Definition at line4194 of fileunistr.h.

◆ UnicodeString()[16/25]

UNISTR_FROM_STRING_EXPLICIT icu::UnicodeString::UnicodeString(const char * codepageData)

char* constructor.

Uses the default converter (and thus depends on the ICU conversion code) unless U_CHARSET_IS_UTF8 is set to 1.

For ASCII (really "invariant character") strings it is more efficient to use the constructor that takes a US_INV (for its enum EInvariant).

Note, for string literals: Since C++17 and ICU 76, you can use UTF-16 string literals with compile-time length determination:

UnicodeString str(u"literal");
if (str == u"other literal") { ... }

It is recommended to mark this constructor "explicit" by-DUNISTR_FROM_STRING_EXPLICIT=explicit on the compiler command line or similar.

Parameters
codepageDataan array of bytes, null-terminated, in the platform's default codepage.
Stable:
ICU 2.0

◆ UnicodeString()[17/25]

icu::UnicodeString::UnicodeString(const char * codepageData,
int32_t dataLength 
)

char* constructor.

Uses the default converter (and thus depends on the ICU conversion code) unless U_CHARSET_IS_UTF8 is set to 1.

Parameters
codepageDataan array of bytes in the platform's default codepage.
dataLengthThe number of bytes incodepageData.
Stable:
ICU 2.0

◆ UnicodeString()[18/25]

icu::UnicodeString::UnicodeString(const char * codepageData,
const char * codepage 
)

char* constructor.

Parameters
codepageDataan array of bytes, null-terminated
codepagethe encoding ofcodepageData. The special value 0 forcodepage indicates that the text is in the platform's default codepage.

Ifcodepage is an empty string (""), then a simple conversion is performed on the codepage-invariant subset ("invariant characters") of the platform encoding. Seeutypes.h. Recommendation: For invariant-character strings use the constructorUnicodeString(const char *src, int32_t length, enum EInvariant inv) because it avoids object code dependencies ofUnicodeString on the conversion code.

Stable:
ICU 2.0

◆ UnicodeString()[19/25]

icu::UnicodeString::UnicodeString(const char * codepageData,
int32_t dataLength,
const char * codepage 
)

char* constructor.

Parameters
codepageDataan array of bytes.
dataLengthThe number of bytes incodepageData.
codepagethe encoding ofcodepageData. The special value 0 forcodepage indicates that the text is in the platform's default codepage. Ifcodepage is an empty string (""), then a simple conversion is performed on the codepage-invariant subset ("invariant characters") of the platform encoding. Seeutypes.h. Recommendation: For invariant-character strings use the constructorUnicodeString(const char *src, int32_t length, enum EInvariant inv) because it avoids object code dependencies ofUnicodeString on the conversion code.
Stable:
ICU 2.0

◆ UnicodeString()[20/25]

icu::UnicodeString::UnicodeString(const char * src,
int32_t srcLength,
UConvertercnv,
UErrorCodeerrorCode 
)

char * / UConverter constructor.

This constructor uses an existing UConverter object to convert the codepage string to Unicode and construct aUnicodeString from that.

The converter is reset at first. If the error code indicates a failure before this constructor is called, or if an error occurs during conversion or construction, then the string will be bogus.

This function avoids the overhead of opening and closing a converter if multiple strings are constructed.

Parameters
srcinput codepage string
srcLengthlength of the input string, can be -1 for NUL-terminated strings
cnvconverter object (ucnv_resetToUnicode() will be called), can be nullptr for the default converter
errorCodenormal ICU error code
Stable:
ICU 2.0

◆ UnicodeString()[21/25]

icu::UnicodeString::UnicodeString(const char * src,
int32_t textLength,
enumEInvariant inv 
)

Constructs a Unicode string from an invariant-character char * string.

About invariant characters seeutypes.h. This constructor has no runtime dependency on conversion code and is therefore recommended over ones taking a charset name string (where the empty string "" indicates invariant-character conversion).

Use the macro US_INV as the third, signature-distinguishing parameter.

For example:

void fn(constchar *s) {
UnicodeString ustr(s, -1,US_INV);
// use ustr ...
}
#define US_INV
Constant to be used in the UnicodeString(char *, int32_t, EInvariant) constructor which constructs a ...
Definition:unistr.h:98

Note, for string literals: Since C++17 and ICU 76, you can use UTF-16 string literals with compile-time length determination:

UnicodeString str(u"literal");
if (str == u"other literal") { ... }
Parameters
srcString using only invariant characters.
textLengthLength of src, or -1 if NUL-terminated.
invSignature-distinguishing parameter, use US_INV.
See also
US_INV
Stable:
ICU 3.2

◆ UnicodeString()[22/25]

icu::UnicodeString::UnicodeString(constUnicodeStringthat)

Copy constructor.

Starting with ICU 2.4, the assignment operator and the copy constructor allocate a new buffer and copy the buffer contents even for readonly aliases. By contrast, thefastCopyFrom() function implements the old, more efficient but less safe behavior of making this string also a readonly alias to the same buffer.

If the source object has an "open" buffer from getBuffer(minCapacity), then the copy is an empty string.

Parameters
thatTheUnicodeString object to copy.
Stable:
ICU 2.0
See also
fastCopyFrom

◆ UnicodeString()[23/25]

icu::UnicodeString::UnicodeString(UnicodeString && src)
noexcept

Move constructor; might leave src in bogus state.

This string will have the same contents and state that the source string had.

Parameters
srcsource string
Stable:
ICU 56

◆ UnicodeString()[24/25]

icu::UnicodeString::UnicodeString(constUnicodeStringsrc,
int32_t srcStart 
)

'Substring' constructor from tail of source string.

Parameters
srcTheUnicodeString object to copy.
srcStartThe offset intosrc at which to start copying.
Stable:
ICU 2.2

◆ UnicodeString()[25/25]

icu::UnicodeString::UnicodeString(constUnicodeStringsrc,
int32_t srcStart,
int32_t srcLength 
)

'Substring' constructor from subrange of source string.

Parameters
srcTheUnicodeString object to copy.
srcStartThe offset intosrc at which to start copying.
srcLengthThe number of characters fromsrc to copy.
Stable:
ICU 2.2

◆ ~UnicodeString()

virtual icu::UnicodeString::~UnicodeString()
virtual

Destructor.

Stable:
ICU 2.0

Member Function Documentation

◆ append()[1/7]

UnicodeString & icu::UnicodeString::append(char16_t srcChar)
inline

Append the code unitsrcChar to theUnicodeString object.

Parameters
srcCharthe code unit to append
Returns
a reference to this
Stable:
ICU 2.0

Definition at line4981 of fileunistr.h.

◆ append()[2/7]

UnicodeString & icu::UnicodeString::append(const char16_t * srcChars,
int32_t srcStart,
int32_t srcLength 
)
inline

Append the characters insrcChars in the range [srcStart,srcStart + srcLength) to theUnicodeString object at offsetstart.

srcChars is not modified.

Parameters
srcCharsthe source for the new characters
srcStartthe offset intosrcChars where new characters will be obtained
srcLengththe number of characters insrcChars in the append string; can be -1 ifsrcChars is NUL-terminated
Returns
a reference to this
Stable:
ICU 2.0

Definition at line4970 of fileunistr.h.

◆ append()[3/7]

template<typename S , typename = std::enable_if_t<ConvertibleToU16StringView<S>>>
UnicodeString& icu::UnicodeString::append(const S & src)
inline

Appends the characters insrc which is, or which is implicitly convertible to, a std::u16string_view or (if U_SIZEOF_WCHAR_T==2) std::wstring_view, to theUnicodeString object.

Parameters
srcthe source for the new characters
Returns
a reference to this
Draft:
This API may be changed in the future versions and was introduced in ICU 76

Definition at line2300 of fileunistr.h.

◆ append()[4/7]

UnicodeString & icu::UnicodeString::append(constUnicodeStringsrcText)
inline

Append the characters insrcText to theUnicodeString object.

srcText is not modified.

Parameters
srcTextthe source for the new characters
Returns
a reference to this
Stable:
ICU 2.0

Definition at line4966 of fileunistr.h.

Referenceslength().

◆ append()[5/7]

UnicodeString & icu::UnicodeString::append(constUnicodeStringsrcText,
int32_t srcStart,
int32_t srcLength 
)
inline

Append the characters insrcText in the range [srcStart,srcStart + srcLength) to theUnicodeString object at offsetstart.

srcText is not modified.

Parameters
srcTextthe source for the new characters
srcStartthe offset intosrcText where new characters will be obtained
srcLengththe number of characters insrcText in the append string
Returns
a reference to this
Stable:
ICU 2.0

Definition at line4960 of fileunistr.h.

Referenced byicu::Transliterator::setID().

◆ append()[6/7]

UnicodeString & icu::UnicodeString::append(ConstChar16Ptr srcChars,
int32_t srcLength 
)
inline

Append the characters insrcChars to theUnicodeString object.

srcChars is not modified.

Parameters
srcCharsthe source for the new characters
srcLengththe number of Unicode characters insrcChars; can be -1 ifsrcChars is NUL-terminated
Returns
a reference to this
Stable:
ICU 2.0

Definition at line4976 of fileunistr.h.

◆ append()[7/7]

UnicodeString& icu::UnicodeString::append(UChar32 srcChar)

Append the code pointsrcChar to theUnicodeString object.

Parameters
srcCharthe code point to append
Returns
a reference to this
Stable:
ICU 2.0

◆ caseCompare()[1/6]

int8_t icu::UnicodeString::caseCompare(constUnicodeStringtext,
uint32_t options 
) const
inline

Compare two strings case-insensitively using full case folding.

This is equivalent to this->foldCase(options).compare(text.foldCase(options)).

Parameters
textAnother string to compare this one to.
optionsA bit set of options:
  • U_FOLD_CASE_DEFAULT or 0 is used for default options: Comparison in code unit order with default case folding.
  • U_COMPARE_CODE_POINT_ORDER Set to choose code point order instead of code unit order (see u_strCompare for details).
  • U_FOLD_CASE_EXCLUDE_SPECIAL_I
Returns
A negative, zero, or positive integer indicating the comparison result.
Stable:
ICU 2.0

Definition at line4443 of fileunistr.h.

Referenceslength().

◆ caseCompare()[2/6]

int8_t icu::UnicodeString::caseCompare(ConstChar16Ptr srcChars,
int32_t srcLength,
uint32_t options 
) const
inline

Compare two strings case-insensitively using full case folding.

This is equivalent to this->foldCase(options).compare(srcChars.foldCase(options)).

Parameters
srcCharsA pointer to another string to compare this one to.
srcLengthThe number of code units from that string to compare.
optionsA bit set of options:
  • U_FOLD_CASE_DEFAULT or 0 is used for default options: Comparison in code unit order with default case folding.
  • U_COMPARE_CODE_POINT_ORDER Set to choose code point order instead of code unit order (see u_strCompare for details).
  • U_FOLD_CASE_EXCLUDE_SPECIAL_I
Returns
A negative, zero, or positive integer indicating the comparison result.
Stable:
ICU 2.0

Definition at line4456 of fileunistr.h.

◆ caseCompare()[3/6]

int8_t icu::UnicodeString::caseCompare(int32_t start,
int32_t length,
const char16_t * srcChars,
int32_t srcStart,
int32_t srcLength,
uint32_t options 
) const
inline

Compare two strings case-insensitively using full case folding.

This is equivalent to this->foldCase(options).compare(srcChars.foldCase(options)).

Parameters
startThe start offset in this string at which the compare operation begins.
lengthThe number of code units from this string to compare.
srcCharsA pointer to another string to compare this one to.
srcStartThe start offset in that string at which the compare operation begins.
srcLengthThe number of code units from that string to compare.
optionsA bit set of options:
  • U_FOLD_CASE_DEFAULT or 0 is used for default options: Comparison in code unit order with default case folding.
  • U_COMPARE_CODE_POINT_ORDER Set to choose code point order instead of code unit order (see u_strCompare for details).
  • U_FOLD_CASE_EXCLUDE_SPECIAL_I
Returns
A negative, zero, or positive integer indicating the comparison result.
Stable:
ICU 2.0

Definition at line4481 of fileunistr.h.

◆ caseCompare()[4/6]

int8_t icu::UnicodeString::caseCompare(int32_t start,
int32_t length,
const char16_t * srcChars,
uint32_t options 
) const
inline

Compare two strings case-insensitively using full case folding.

This is equivalent to this->foldCase(options).compare(srcChars.foldCase(options)).

Parameters
startThe start offset in this string at which the compare operation begins.
lengthThe number of code units from this string to compare.
srcCharsA pointer to another string to compare this one to.
optionsA bit set of options:
  • U_FOLD_CASE_DEFAULT or 0 is used for default options: Comparison in code unit order with default case folding.
  • U_COMPARE_CODE_POINT_ORDER Set to choose code point order instead of code unit order (see u_strCompare for details).
  • U_FOLD_CASE_EXCLUDE_SPECIAL_I
Returns
A negative, zero, or positive integer indicating the comparison result.
Stable:
ICU 2.0

Definition at line4473 of fileunistr.h.

◆ caseCompare()[5/6]

int8_t icu::UnicodeString::caseCompare(int32_t start,
int32_t length,
constUnicodeStringsrcText,
int32_t srcStart,
int32_t srcLength,
uint32_t options 
) const
inline

Compare two strings case-insensitively using full case folding.

This is equivalent to this->foldCase(options).compare(srcText.foldCase(options)).

Parameters
startThe start offset in this string at which the compare operation begins.
lengthThe number of code units from this string to compare.
srcTextAnother string to compare this one to.
srcStartThe start offset in that string at which the compare operation begins.
srcLengthThe number of code units from that string to compare.
optionsA bit set of options:
  • U_FOLD_CASE_DEFAULT or 0 is used for default options: Comparison in code unit order with default case folding.
  • U_COMPARE_CODE_POINT_ORDER Set to choose code point order instead of code unit order (see u_strCompare for details).
  • U_FOLD_CASE_EXCLUDE_SPECIAL_I
Returns
A negative, zero, or positive integer indicating the comparison result.
Stable:
ICU 2.0

Definition at line4463 of fileunistr.h.

◆ caseCompare()[6/6]

int8_t icu::UnicodeString::caseCompare(int32_t start,
int32_t length,
constUnicodeStringsrcText,
uint32_t options 
) const
inline

Compare two strings case-insensitively using full case folding.

This is equivalent to this->foldCase(options).compare(srcText.foldCase(options)).

Parameters
startThe start offset in this string at which the compare operation begins.
lengthThe number of code units from this string to compare.
srcTextAnother string to compare this one to.
optionsA bit set of options:
  • U_FOLD_CASE_DEFAULT or 0 is used for default options: Comparison in code unit order with default case folding.
  • U_COMPARE_CODE_POINT_ORDER Set to choose code point order instead of code unit order (see u_strCompare for details).
  • U_FOLD_CASE_EXCLUDE_SPECIAL_I
Returns
A negative, zero, or positive integer indicating the comparison result.
Stable:
ICU 2.0

Definition at line4448 of fileunistr.h.

Referenceslength().

◆ caseCompareBetween()

int8_t icu::UnicodeString::caseCompareBetween(int32_t start,
int32_t limit,
constUnicodeStringsrcText,
int32_t srcStart,
int32_t srcLimit,
uint32_t options 
) const
inline

Compare two strings case-insensitively using full case folding.

This is equivalent to this->foldCase(options).compareBetween(text.foldCase(options)).

Parameters
startThe start offset in this string at which the compare operation begins.
limitThe offset after the last code unit from this string to compare.
srcTextAnother string to compare this one to.
srcStartThe start offset in that string at which the compare operation begins.
srcLimitThe offset after the last code unit from that string to compare.
optionsA bit set of options:
  • U_FOLD_CASE_DEFAULT or 0 is used for default options: Comparison in code unit order with default case folding.
  • U_COMPARE_CODE_POINT_ORDER Set to choose code point order instead of code unit order (see u_strCompare for details).
  • U_FOLD_CASE_EXCLUDE_SPECIAL_I
Returns
A negative, zero, or positive integer indicating the comparison result.
Stable:
ICU 2.0

Definition at line4491 of fileunistr.h.

◆ char32At()

UChar32 icu::UnicodeString::char32At(int32_t offset) const

Return the code point that contains the code unit at offsetoffset.

If the offset is not valid (0..length()-1) then U+ffff is returned.

Parameters
offseta valid offset into the text that indicates the text offset of any of the code units that will be assembled into a code point (21-bit value) and returned
Returns
the code point of text atoffset or 0xffff if the offset is not valid for this string
Stable:
ICU 2.0

Referenced byicu::DecimalFormatSymbols::setSymbol().

◆ charAt()

char16_t icu::UnicodeString::charAt(int32_t offset) const
inline

Return the code unit at offsetoffset.

If the offset is not valid (0..length()-1) then U+ffff is returned.

Parameters
offseta valid offset into the text
Returns
the code unit at offsetoffset or 0xffff if the offset is not valid for this string
Stable:
ICU 2.0

Definition at line4855 of fileunistr.h.

◆ clone()

virtualUnicodeString* icu::UnicodeString::clone() const
overridevirtual

Clone this object, an instance of a subclass ofReplaceable.

Clones can be used concurrently in multiple threads. If a subclass does not implementclone(), or if an error occurs, then nullptr is returned. The caller must delete the clone.

Returns
a clone of this object
See also
Replaceable::clone
getDynamicClassID
Stable:
ICU 2.6

Reimplemented fromicu::Replaceable.

◆ compare()[1/6]

int8_t icu::UnicodeString::compare(constUnicodeStringtext) const
inline

Compare the characters bitwise in thisUnicodeString to the characters intext.

Parameters
textTheUnicodeString to compare to this one.
Returns
The result of bitwise character comparison: 0 if this contains the same characters astext, -1 if the characters in this are bitwise less than the characters intext, +1 if the characters in this are bitwise greater than the characters intext.
Stable:
ICU 2.0

Definition at line4320 of fileunistr.h.

Referenceslength().

◆ compare()[2/6]

int8_t icu::UnicodeString::compare(ConstChar16Ptr srcChars,
int32_t srcLength 
) const
inline

Compare the characters bitwise in thisUnicodeString with the firstsrcLength characters insrcChars.

Parameters
srcCharsThe characters to compare to thisUnicodeString.
srcLengththe number of characters insrcChars to compare
Returns
The result of bitwise character comparison: 0 if this contains the same characters assrcChars, -1 if the characters in this are bitwise less than the characters insrcChars, +1 if the characters in this are bitwise greater than the characters insrcChars.
Stable:
ICU 2.0

Definition at line4330 of fileunistr.h.

◆ compare()[3/6]

int8_t icu::UnicodeString::compare(int32_t start,
int32_t length,
const char16_t * srcChars 
) const
inline

Compare the characters bitwise in the range [start,start + length) with the firstlength characters insrcChars

Parameters
startthe offset at which the compare operation begins
lengththe number of characters to compare.
srcCharsthe characters to be compared
Returns
The result of bitwise character comparison: 0 if this contains the same characters assrcChars, -1 if the characters in this are bitwise less than the characters insrcChars, +1 if the characters in this are bitwise greater than the characters insrcChars.
Stable:
ICU 2.0

Definition at line4343 of fileunistr.h.

◆ compare()[4/6]

int8_t icu::UnicodeString::compare(int32_t start,
int32_t length,
const char16_t * srcChars,
int32_t srcStart,
int32_t srcLength 
) const
inline

Compare the characters bitwise in the range [start,start + length) with the characters insrcChars in the range [srcStart,srcStart + srcLength).

Parameters
startthe offset at which the compare operation begins
lengththe number of characters in this to compare
srcCharsthe characters to be compared
srcStartthe offset intosrcChars to start comparison
srcLengththe number of characters insrcChars to compare
Returns
The result of bitwise character comparison: 0 if this contains the same characters assrcChars, -1 if the characters in this are bitwise less than the characters insrcChars, +1 if the characters in this are bitwise greater than the characters insrcChars.
Stable:
ICU 2.0

Definition at line4349 of fileunistr.h.

◆ compare()[5/6]

int8_t icu::UnicodeString::compare(int32_t start,
int32_t length,
constUnicodeStringsrcText,
int32_t srcStart,
int32_t srcLength 
) const
inline

Compare the characters bitwise in the range [start,start + length) with the characters insrcText in the range [srcStart,srcStart + srcLength).

Parameters
startthe offset at which the compare operation begins
lengththe number of characters in this to compare.
srcTextthe text to be compared
srcStartthe offset intosrcText to start comparison
srcLengththe number of characters insrc to compare
Returns
The result of bitwise character comparison: 0 if this contains the same characters assrcText, -1 if the characters in this are bitwise less than the characters insrcText, +1 if the characters in this are bitwise greater than the characters insrcText.
Stable:
ICU 2.0

Definition at line4335 of fileunistr.h.

◆ compare()[6/6]

int8_t icu::UnicodeString::compare(int32_t start,
int32_t length,
constUnicodeStringtext 
) const
inline

Compare the characters bitwise in the range [start,start + length) with the characters in theentire stringtext.

(The parameters "start" and "length" are not applied to the other text "text".)

Parameters
startthe offset at which the compare operation begins
lengththe number of characters of text to compare.
textthe other text to be compared against this string.
Returns
The result of bitwise character comparison: 0 if this contains the same characters astext, -1 if the characters in this are bitwise less than the characters intext, +1 if the characters in this are bitwise greater than the characters intext.
Stable:
ICU 2.0

Definition at line4324 of fileunistr.h.

Referenceslength().

◆ compareBetween()

int8_t icu::UnicodeString::compareBetween(int32_t start,
int32_t limit,
constUnicodeStringsrcText,
int32_t srcStart,
int32_t srcLimit 
) const
inline

Compare the characters bitwise in the range [start,limit) with the characters insrcText in the range [srcStart,srcLimit).

Parameters
startthe offset at which the compare operation begins
limitthe offset immediately following the compare operation
srcTextthe text to be compared
srcStartthe offset intosrcText to start comparison
srcLimitthe offset intosrcText to limit comparison
Returns
The result of bitwise character comparison: 0 if this contains the same characters assrcText, -1 if the characters in this are bitwise less than the characters insrcText, +1 if the characters in this are bitwise greater than the characters insrcText.
Stable:
ICU 2.0

Definition at line4357 of fileunistr.h.

◆ compareCodePointOrder()[1/6]

int8_t icu::UnicodeString::compareCodePointOrder(constUnicodeStringtext) const
inline

Compare two Unicode strings in code point order.

The result may be different from the results ofcompare(), operator<, etc. if supplementary characters are present:

In UTF-16, supplementary characters (with code points U+10000 and above) are stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff, which means that they compare as less than some other BMP characters like U+feff. This function compares Unicode strings in code point order. If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.

Parameters
textAnother string to compare this one to.
Returns
a negative/zero/positive integer corresponding to whether this string is less than/equal to/greater than the second one in code point order
Stable:
ICU 2.0

Definition at line4381 of fileunistr.h.

Referenceslength().

◆ compareCodePointOrder()[2/6]

int8_t icu::UnicodeString::compareCodePointOrder(ConstChar16Ptr srcChars,
int32_t srcLength 
) const
inline

Compare two Unicode strings in code point order.

The result may be different from the results ofcompare(), operator<, etc. if supplementary characters are present:

In UTF-16, supplementary characters (with code points U+10000 and above) are stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff, which means that they compare as less than some other BMP characters like U+feff. This function compares Unicode strings in code point order. If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.

Parameters
srcCharsA pointer to another string to compare this one to.
srcLengthThe number of code units from that string to compare.
Returns
a negative/zero/positive integer corresponding to whether this string is less than/equal to/greater than the second one in code point order
Stable:
ICU 2.0

Definition at line4391 of fileunistr.h.

◆ compareCodePointOrder()[3/6]

int8_t icu::UnicodeString::compareCodePointOrder(int32_t start,
int32_t length,
const char16_t * srcChars 
) const
inline

Compare two Unicode strings in code point order.

The result may be different from the results ofcompare(), operator<, etc. if supplementary characters are present:

In UTF-16, supplementary characters (with code points U+10000 and above) are stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff, which means that they compare as less than some other BMP characters like U+feff. This function compares Unicode strings in code point order. If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.

Parameters
startThe start offset in this string at which the compare operation begins.
lengthThe number of code units from this string to compare.
srcCharsA pointer to another string to compare this one to.
Returns
a negative/zero/positive integer corresponding to whether this string is less than/equal to/greater than the second one in code point order
Stable:
ICU 2.0

Definition at line4404 of fileunistr.h.

◆ compareCodePointOrder()[4/6]

int8_t icu::UnicodeString::compareCodePointOrder(int32_t start,
int32_t length,
const char16_t * srcChars,
int32_t srcStart,
int32_t srcLength 
) const
inline

Compare two Unicode strings in code point order.

The result may be different from the results ofcompare(), operator<, etc. if supplementary characters are present:

In UTF-16, supplementary characters (with code points U+10000 and above) are stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff, which means that they compare as less than some other BMP characters like U+feff. This function compares Unicode strings in code point order. If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.

Parameters
startThe start offset in this string at which the compare operation begins.
lengthThe number of code units from this string to compare.
srcCharsA pointer to another string to compare this one to.
srcStartThe start offset in that string at which the compare operation begins.
srcLengthThe number of code units from that string to compare.
Returns
a negative/zero/positive integer corresponding to whether this string is less than/equal to/greater than the second one in code point order
Stable:
ICU 2.0

Definition at line4410 of fileunistr.h.

◆ compareCodePointOrder()[5/6]

int8_t icu::UnicodeString::compareCodePointOrder(int32_t start,
int32_t length,
constUnicodeStringsrcText 
) const
inline

Compare two Unicode strings in code point order.

The result may be different from the results ofcompare(), operator<, etc. if supplementary characters are present:

In UTF-16, supplementary characters (with code points U+10000 and above) are stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff, which means that they compare as less than some other BMP characters like U+feff. This function compares Unicode strings in code point order. If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.

Parameters
startThe start offset in this string at which the compare operation begins.
lengthThe number of code units from this string to compare.
srcTextAnother string to compare this one to.
Returns
a negative/zero/positive integer corresponding to whether this string is less than/equal to/greater than the second one in code point order
Stable:
ICU 2.0

Definition at line4385 of fileunistr.h.

Referenceslength().

◆ compareCodePointOrder()[6/6]

int8_t icu::UnicodeString::compareCodePointOrder(int32_t start,
int32_t length,
constUnicodeStringsrcText,
int32_t srcStart,
int32_t srcLength 
) const
inline

Compare two Unicode strings in code point order.

The result may be different from the results ofcompare(), operator<, etc. if supplementary characters are present:

In UTF-16, supplementary characters (with code points U+10000 and above) are stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff, which means that they compare as less than some other BMP characters like U+feff. This function compares Unicode strings in code point order. If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.

Parameters
startThe start offset in this string at which the compare operation begins.
lengthThe number of code units from this string to compare.
srcTextAnother string to compare this one to.
srcStartThe start offset in that string at which the compare operation begins.
srcLengthThe number of code units from that string to compare.
Returns
a negative/zero/positive integer corresponding to whether this string is less than/equal to/greater than the second one in code point order
Stable:
ICU 2.0

Definition at line4396 of fileunistr.h.

◆ compareCodePointOrderBetween()

int8_t icu::UnicodeString::compareCodePointOrderBetween(int32_t start,
int32_t limit,
constUnicodeStringsrcText,
int32_t srcStart,
int32_t srcLimit 
) const
inline

Compare two Unicode strings in code point order.

The result may be different from the results ofcompare(), operator<, etc. if supplementary characters are present:

In UTF-16, supplementary characters (with code points U+10000 and above) are stored with pairs of surrogate code units. These have values from 0xd800 to 0xdfff, which means that they compare as less than some other BMP characters like U+feff. This function compares Unicode strings in code point order. If either of the UTF-16 strings is malformed (i.e., it contains unpaired surrogates), then the result is not defined.

Parameters
startThe start offset in this string at which the compare operation begins.
limitThe offset after the last code unit from this string to compare.
srcTextAnother string to compare this one to.
srcStartThe start offset in that string at which the compare operation begins.
srcLimitThe offset after the last code unit from that string to compare.
Returns
a negative/zero/positive integer corresponding to whether this string is less than/equal to/greater than the second one in code point order
Stable:
ICU 2.0

Definition at line4418 of fileunistr.h.

◆ copy()

virtual void icu::UnicodeString::copy(int32_t start,
int32_t limit,
int32_t dest 
)
overridevirtual

Copy a substring of this object, retaining attribute (out-of-band) information.

This method is used to duplicate or reorder substrings. The destination index must not overlap the source range.

Parameters
startthe beginning index, inclusive;0 <= start <= limit.
limitthe ending index, exclusive;start <= limit <=length().
destthe destination index. The characters fromstart..limit-1 will be copied todest. Implementations of this method may assume thatdest <= start || dest >= limit.
Stable:
ICU 2.0

Implementsicu::Replaceable.

◆ countChar32()

int32_t icu::UnicodeString::countChar32(int32_t start =0,
int32_t length =INT32_MAX 
) const

Count Unicode code points in the length char16_t code units of the string.

A code point may occupy either one or two char16_t code units. Counting code points involves reading all code units.

This functions is basically the inverse ofmoveIndex32().

Parameters
startthe index of the first code unit to check
lengththe number of char16_t code units to check
Returns
the number of code points in the specified code units
See also
length
Stable:
ICU 2.0

Referenced byicu::DecimalFormatSymbols::setSymbol().

◆ endsWith()[1/4]

UBool icu::UnicodeString::endsWith(const char16_t * srcChars,
int32_t srcStart,
int32_t srcLength 
) const
inline

Determine if this ends with the characters insrcChars in the range [srcStart,srcStart + srcLength).

Parameters
srcCharsThe characters to match.
srcStartthe offset intosrcText to start matching
srcLengththe number of characters insrcChars to match
Returns
true if this ends with the characters insrcChars, false otherwise
Stable:
ICU 2.0

Definition at line4716 of fileunistr.h.

Referencesu_strlen().

◆ endsWith()[2/4]

UBool icu::UnicodeString::endsWith(constUnicodeStringsrcText,
int32_t srcStart,
int32_t srcLength 
) const
inline

Determine if this ends with the characters insrcText in the range [srcStart,srcStart + srcLength).

Parameters
srcTextThe text to match.
srcStartthe offset intosrcText to start matching
srcLengththe number of characters insrcText to match
Returns
true if this ends with the characters intext, false otherwise
Stable:
ICU 2.0

Definition at line4698 of fileunistr.h.

◆ endsWith()[3/4]

UBool icu::UnicodeString::endsWith(constUnicodeStringtext) const
inline

Determine if this ends with the characters intext

Parameters
textThe text to match.
Returns
true if this ends with the characters intext, false otherwise
Stable:
ICU 2.0

Definition at line4693 of fileunistr.h.

Referenceslength().

◆ endsWith()[4/4]

UBool icu::UnicodeString::endsWith(ConstChar16Ptr srcChars,
int32_t srcLength 
) const
inline

Determine if this ends with the characters insrcChars

Parameters
srcCharsThe characters to match.
srcLengththe number of characters insrcChars
Returns
true if this ends with the characters insrcChars, false otherwise
Stable:
ICU 2.0

Definition at line4707 of fileunistr.h.

Referencesu_strlen().

◆ extract()[1/8]

int32_t icu::UnicodeString::extract(char * dest,
int32_t destCapacity,
UConvertercnv,
UErrorCodeerrorCode 
) const

Convert theUnicodeString into a codepage string using an existing UConverter.

The output string is NUL-terminated if possible.

This function avoids the overhead of opening and closing a converter if multiple strings are extracted.

Parameters
destdestination string buffer, can be nullptr if destCapacity==0
destCapacitythe number of chars available at dest
cnvthe converter object to be used (ucnv_resetFromUnicode() will be called), or nullptr for the default converter
errorCodenormal ICU error code
Returns
the length of the output string, not counting the terminating NUL; if the length is greater than destCapacity, then the string will not fit and a buffer of the indicated length would need to be passed in
Stable:
ICU 2.0

◆ extract()[2/8]

int32_t icu::UnicodeString::extract(Char16Ptr dest,
int32_t destCapacity,
UErrorCodeerrorCode 
) const

Copy the contents of the string into dest.

This is a convenience function that checks if there is enough space in dest, extracts the entire string if possible, and NUL-terminates dest if possible.

If the string fits into dest but cannot be NUL-terminated (length()==destCapacity) then the error code is set to U_STRING_NOT_TERMINATED_WARNING. If the string itself does not fit into dest (length()>destCapacity) then the error code is set to U_BUFFER_OVERFLOW_ERROR.

If the string aliases todest itself as an external buffer, thenextract() will not copy the contents.

Parameters
destDestination string buffer.
destCapacityNumber of char16_ts available at dest.
errorCodeICU error code.
Returns
length()
Stable:
ICU 2.0

◆ extract()[3/8]

void icu::UnicodeString::extract(int32_t start,
int32_t length,
Char16Ptr dst,
int32_t dstStart =0 
) const
inline

Copy the characters in the range [start,start + length) into the arraydst, beginning atdstStart.

If the string aliases todst itself as an external buffer, thenextract() will not copy the contents.

Parameters
startoffset of first character which will be copied into the array
lengththe number of characters to extract
dstarray in which to copy characters. The length ofdst must be at least (dstStart + length).
dstStartthe offset indst where the first character will be extracted
Stable:
ICU 2.0

Definition at line4802 of fileunistr.h.

◆ extract()[4/8]

void icu::UnicodeString::extract(int32_t start,
int32_t length,
UnicodeStringtarget 
) const
inline

Copy the characters in the range [start,start + length) into theUnicodeStringtarget.

Parameters
startoffset of first character which will be copied
lengththe number of characters to extract
targetUnicodeString into which to copy characters.
Stable:
ICU 2.0

Definition at line4809 of fileunistr.h.

◆ extract()[5/8]

int32_t icu::UnicodeString::extract(int32_t start,
int32_t startLength,
char * target,
const char * codepage =nullptr 
) const
inline

Copy the characters in the range [start,start + length) into an array of characters in a specified codepage.

The output string is NUL-terminated.

Recommendation: For invariant-character strings useextract(int32_t start, int32_t length, char *target, int32_t targetCapacity, enum EInvariant inv) const because it avoids object code dependencies ofUnicodeString on the conversion code.

Parameters
startoffset of first character which will be copied
startLengththe number of characters to extract
targetthe target buffer for extraction
codepagethe desired codepage for the characters. 0 has the special meaning of the default codepage Ifcodepage is an empty string (""), then a simple conversion is performed on the codepage-invariant subset ("invariant characters") of the platform encoding. Seeutypes.h. Iftarget is nullptr, then the number of bytes required fortarget is returned. It is assumed that the target is big enough to fit all of the characters.
Returns
the output string length, not including the terminating NUL
Stable:
ICU 2.0

Definition at line4817 of fileunistr.h.

◆ extract()[6/8]

int32_t icu::UnicodeString::extract(int32_t start,
int32_t startLength,
char * target,
int32_t targetCapacity,
enumEInvariant inv 
) const

Copy the characters in the range [start,start + startLength) into an array of characters.

All characters must be invariant (seeutypes.h). Use US_INV as the last, signature-distinguishing parameter.

This function does not write any more thantargetCapacity characters but returns the length of the entire output string so that one can allocate a larger buffer and call the function again if necessary. The output string is NUL-terminated if possible.

Parameters
startoffset of first character which will be copied
startLengththe number of characters to extract
targetthe target buffer for extraction, can be nullptr if targetLength is 0
targetCapacitythe length of the target buffer
invSignature-distinguishing parameter, use US_INV.
Returns
the output string length, not including the terminating NUL
Stable:
ICU 3.2

◆ extract()[7/8]

int32_t icu::UnicodeString::extract(int32_t start,
int32_t startLength,
char * target,
uint32_t targetLength 
) const

Copy the characters in the range [start,start + length) into an array of characters in the platform's default codepage.

This function does not write any more thantargetLength characters but returns the length of the entire output string so that one can allocate a larger buffer and call the function again if necessary. The output string is NUL-terminated if possible.

Parameters
startoffset of first character which will be copied
startLengththe number of characters to extract
targetthe target buffer for extraction
targetLengththe length of the target buffer Iftarget is nullptr, then the number of bytes required fortarget is returned.
Returns
the output string length, not including the terminating NUL
Stable:
ICU 2.0

◆ extract()[8/8]

int32_t icu::UnicodeString::extract(int32_t start,
int32_t startLength,
char * target,
uint32_t targetLength,
const char * codepage 
) const

Copy the characters in the range [start,start + length) into an array of characters in a specified codepage.

This function does not write any more thantargetLength characters but returns the length of the entire output string so that one can allocate a larger buffer and call the function again if necessary. The output string is NUL-terminated if possible.

Recommendation: For invariant-character strings useextract(int32_t start, int32_t length, char *target, int32_t targetCapacity, enum EInvariant inv) const because it avoids object code dependencies ofUnicodeString on the conversion code.

Parameters
startoffset of first character which will be copied
startLengththe number of characters to extract
targetthe target buffer for extraction
targetLengththe length of the target buffer
codepagethe desired codepage for the characters. 0 has the special meaning of the default codepage Ifcodepage is an empty string (""), then a simple conversion is performed on the codepage-invariant subset ("invariant characters") of the platform encoding. Seeutypes.h. Iftarget is nullptr, then the number of bytes required fortarget is returned.
Returns
the output string length, not including the terminating NUL
Stable:
ICU 2.0

◆ extractBetween()[1/2]

void icu::UnicodeString::extractBetween(int32_t start,
int32_t limit,
char16_t * dst,
int32_t dstStart =0 
) const
inline

Copy the characters in the range [start,limit) into the arraydst, beginning atdstStart.

Parameters
startoffset of first character which will be copied into the array
limitoffset immediately following the last character to be copied
dstarray in which to copy characters. The length ofdst must be at least (dstStart + (limit - start)).
dstStartthe offset indst where the first character will be extracted
Stable:
ICU 2.0

Definition at line4830 of fileunistr.h.

◆ extractBetween()[2/2]

virtual void icu::UnicodeString::extractBetween(int32_t start,
int32_t limit,
UnicodeStringtarget 
) const
overridevirtual

Copy the characters in the range [start,limit) into theUnicodeStringtarget.

Replaceable API.

Parameters
startoffset of first character which will be copied
limitoffset immediately following the last character to be copied
targetUnicodeString into which to copy characters.
Stable:
ICU 2.0

Implementsicu::Replaceable.

◆ fastCopyFrom()

UnicodeString& icu::UnicodeString::fastCopyFrom(constUnicodeStringsrc)

Almost the same as the assignment operator.

Replace the characters in thisUnicodeString with the characters fromsrcText.

This function works the same as the assignment operator for all strings except for ones that are readonly aliases.

Starting with ICU 2.4, the assignment operator and the copy constructor allocate a new buffer and copy the buffer contents even for readonly aliases. This function implements the old, more efficient but less safe behavior of making this string also a readonly alias to the same buffer.

The fastCopyFrom function must be used only if it is known that the lifetime of thisUnicodeString does not exceed the lifetime of the aliased buffer including its contents, for example for strings from resource bundles or aliases to string constants.

If the source object has an "open" buffer from getBuffer(minCapacity), then the copy is an empty string.

Parameters
srcThe text containing the characters to replace.
Returns
a reference to this
Stable:
ICU 2.4

◆ findAndReplace()[1/3]

UnicodeString & icu::UnicodeString::findAndReplace(constUnicodeStringoldText,
constUnicodeStringnewText 
)
inline

Replace all occurrences of characters in oldText with the characters in newText.

Parameters
oldTextthe text containing the search text
newTextthe text containing the replacement text
Returns
a reference to this
Stable:
ICU 2.0

Definition at line4779 of fileunistr.h.

Referenceslength().

◆ findAndReplace()[2/3]

UnicodeString & icu::UnicodeString::findAndReplace(int32_t start,
int32_t length,
constUnicodeStringoldText,
constUnicodeStringnewText 
)
inline

Replace all occurrences of characters in oldText with characters in newText in the range [start,start + length).

Parameters
startthe start of the range in which replace will performed
lengththe length of the range in which replace will be performed
oldTextthe text containing the search text
newTextthe text containing the replacement text
Returns
a reference to this
Stable:
ICU 2.0

Definition at line4785 of fileunistr.h.

Referenceslength().

◆ findAndReplace()[3/3]

UnicodeString& icu::UnicodeString::findAndReplace(int32_t start,
int32_t length,
constUnicodeStringoldText,
int32_t oldStart,
int32_t oldLength,
constUnicodeStringnewText,
int32_t newStart,
int32_t newLength 
)

Replace all occurrences of characters in oldText in the range [oldStart,oldStart + oldLength) with the characters in newText in the range [newStart,newStart + newLength) in the range [start,start + length).

Parameters
startthe start of the range in which replace will performed
lengththe length of the range in which replace will be performed
oldTextthe text containing the search text
oldStartthe start of the search range inoldText
oldLengththe length of the search range inoldText
newTextthe text containing the replacement text
newStartthe start of the replacement range innewText
newLengththe length of the replacement range innewText
Returns
a reference to this
Stable:
ICU 2.0

◆ foldCase()

UnicodeString& icu::UnicodeString::foldCase(uint32_t options =0)

Case-folds the characters in this string.

Case-folding is locale-independent and not context-sensitive, but there is an option for whether to include or exclude mappings for dotted I and dotless i that are marked with 'T' in CaseFolding.txt.

The result may be longer or shorter than the original.

Parameters
optionsEither U_FOLD_CASE_DEFAULT or U_FOLD_CASE_EXCLUDE_SPECIAL_I
Returns
A reference to this.
Stable:
ICU 2.0

◆ fromUTF32()

staticUnicodeString icu::UnicodeString::fromUTF32(constUChar32utf32,
int32_t length 
)
static

Create aUnicodeString from a UTF-32 string.

Illegal input is replaced with U+FFFD. Otherwise, errors result in a bogus string. Callsu_strFromUTF32WithSub().

Parameters
utf32UTF-32 input string. Must not be nullptr.
lengthLength of the input string, or -1 if NUL-terminated.
Returns
AUnicodeString with equivalent UTF-16 contents.
See also
toUTF32
Stable:
ICU 4.2

◆ fromUTF8()

staticUnicodeString icu::UnicodeString::fromUTF8(StringPiece utf8)
static

Create aUnicodeString from a UTF-8 string.

Illegal input is replaced with U+FFFD. Otherwise, errors result in a bogus string. Callsu_strFromUTF8WithSub().

Parameters
utf8UTF-8 input string. Note that aStringPiece can be implicitly constructed from a std::string or a NUL-terminated const char * string.
Returns
AUnicodeString with equivalent UTF-16 contents.
See also
toUTF8
toUTF8String
Stable:
ICU 4.2

◆ getBuffer()[1/2]

const char16_t * icu::UnicodeString::getBuffer() const
inline

Get a read-only pointer to the internal buffer.

This can be called at any time on a validUnicodeString.

It returns 0 if the string is bogus, or during an "open" getBuffer(minCapacity).

It can be called as many times as desired. The pointer that it returns will remain valid until theUnicodeString object is modified, at which time the pointer is semantically invalidated and must not be used any more.

The capacity of the buffer can be determined withgetCapacity(). The part afterlength() may or may not be initialized and valid, depending on the history of theUnicodeString object.

The buffer contents is (probably) not NUL-terminated. You can check if it is with(s.length() < s.getCapacity() && buffer[s.length()]==0). (SeegetTerminatedBuffer().)

The buffer may reside in read-only memory. Its contents must not be modified.

Returns
a read-only pointer to the internal string buffer, or nullptr if the string is empty or bogus
See also
getBuffer(int32_t minCapacity)
getTerminatedBuffer()
Stable:
ICU 2.0

Definition at line4245 of fileunistr.h.

◆ getBuffer()[2/2]

char16_t* icu::UnicodeString::getBuffer(int32_t minCapacity)

Get a read/write pointer to the internal buffer.

The buffer is guaranteed to be large enough for at least minCapacity char16_ts, writable, and is still owned by theUnicodeString object. Calls to getBuffer(minCapacity) must not be nested, and must be matched with calls to releaseBuffer(newLength). If the string buffer was read-only or shared, then it will be reallocated and copied.

An attempted nested call will return 0, and will not further modify the state of theUnicodeString object. It also returns 0 if the string is bogus.

The actual capacity of the string buffer may be larger than minCapacity.getCapacity() returns the actual capacity. For many operations, the full capacity should be used to avoid reallocations.

While the buffer is "open" between getBuffer(minCapacity) and releaseBuffer(newLength), the following applies:

  • The string length is set to 0.
  • Any read API call on theUnicodeString object will behave like on a 0-length string.
  • Any write API call on theUnicodeString object is disallowed and will have no effect.
  • You can read from and write to the returned buffer.
  • The previous string contents will still be in the buffer; if you want to use it, then you need to calllength() before getBuffer(minCapacity). If thelength() was greater than minCapacity, then any contents after minCapacity may be lost. The buffer contents is not NUL-terminated bygetBuffer(). Iflength() <getCapacity() then you can terminate it by writing a NUL at indexlength().
  • You must call releaseBuffer(newLength) before and in order to return to normalUnicodeString operation.
Parameters
minCapacitythe minimum number of char16_ts that are to be available in the buffer, starting at the returned pointer; default to the current string capacity if minCapacity==-1
Returns
a writable pointer to the internal string buffer, or nullptr if an error occurs (nested calls, out of memory)
See also
releaseBuffer
getTerminatedBuffer()
Stable:
ICU 2.0

Referenced byicu::Normalizer::compare(),icu::UnicodeSet::span(), andicu::UnicodeSet::spanBack().

◆ getCapacity()

int32_t icu::UnicodeString::getCapacity() const
inline

Return the capacity of the internal buffer of theUnicodeString object.

This is useful together with the getBuffer functions. See there for details.

Returns
the number of char16_ts available in the internal buffer
See also
getBuffer
Stable:
ICU 2.0

Definition at line4219 of fileunistr.h.

◆ getChar32At()

virtualUChar32 icu::UnicodeString::getChar32At(int32_t offset) const
overrideprotectedvirtual

The change inReplaceable to use virtualgetChar32At() allowsUnicodeString::char32At() to be inline again (see jitterbug 709).

Stable:
ICU 2.4

Implementsicu::Replaceable.

◆ getChar32Limit()

int32_t icu::UnicodeString::getChar32Limit(int32_t offset) const

Adjust a random-access offset so that it points behind a Unicode character.

The offset that is passed in points behind any code unit of a code point, while the returned offset will point behind the last code unit of the same code point. In UTF-16, if the input offset points behind the first surrogate (i.e., to the second surrogate) of a surrogate pair, then the returned offset will point behind the second surrogate (i.e., to the first surrogate).

Parameters
offseta valid offset after any code unit of a code point of the text
Returns
offset of the first code unit after the same code point
See also
U16_SET_CP_LIMIT
Stable:
ICU 2.0

◆ getChar32Start()

int32_t icu::UnicodeString::getChar32Start(int32_t offset) const

Adjust a random-access offset so that it points to the beginning of a Unicode character.

The offset that is passed in points to any code unit of a code point, while the returned offset will point to the first code unit of the same code point. In UTF-16, if the input offset points to a second surrogate of a surrogate pair, then the returned offset will point to the first surrogate.

Parameters
offseta valid offset into one code point of the text
Returns
offset of the first code unit of the same code point
See also
U16_SET_CP_START
Stable:
ICU 2.0

◆ getCharAt()

virtual char16_t icu::UnicodeString::getCharAt(int32_t offset) const
overrideprotectedvirtual

The change inReplaceable to use virtualgetCharAt() allowsUnicodeString::charAt() to be inline again (see jitterbug 709).

Stable:
ICU 2.4

Implementsicu::Replaceable.

◆ getDynamicClassID()

virtualUClassID icu::UnicodeString::getDynamicClassID() const
overridevirtual

ICU "poor man's RTTI", returns a UClassID for the actual class.

Stable:
ICU 2.2

Reimplemented fromicu::UObject.

◆ getLength()

virtual int32_t icu::UnicodeString::getLength() const
overrideprotectedvirtual

ImplementReplaceable::getLength() (see jitterbug 1027).

Stable:
ICU 2.4

Implementsicu::Replaceable.

◆ getStaticClassID()

staticUClassID icu::UnicodeString::getStaticClassID()
static

ICU "poor man's RTTI", returns a UClassID for this class.

Stable:
ICU 2.2

◆ getTerminatedBuffer()

const char16_t* icu::UnicodeString::getTerminatedBuffer()

Get a read-only pointer to the internal buffer, making sure that it is NUL-terminated.

This can be called at any time on a validUnicodeString.

It returns 0 if the string is bogus, or during an "open" getBuffer(minCapacity), or if the buffer cannot be NUL-terminated (because memory allocation failed).

It can be called as many times as desired. The pointer that it returns will remain valid until theUnicodeString object is modified, at which time the pointer is semantically invalidated and must not be used any more.

The capacity of the buffer can be determined withgetCapacity(). The part afterlength()+1 may or may not be initialized and valid, depending on the history of theUnicodeString object.

The buffer contents is guaranteed to be NUL-terminated.getTerminatedBuffer() may reallocate the buffer if a terminating NUL is written. For this reason, this function is not const, unlikegetBuffer(). Note that aUnicodeString may also contain NUL characters as part of its contents.

The buffer may reside in read-only memory. Its contents must not be modified.

Returns
a read-only pointer to the internal string buffer, or 0 if the string is empty or bogus
See also
getBuffer(int32_t minCapacity)
getBuffer()
Stable:
ICU 2.2

◆ handleReplaceBetween()

virtual void icu::UnicodeString::handleReplaceBetween(int32_t start,
int32_t limit,
constUnicodeStringtext 
)
overridevirtual

Replace a substring of this object with the given text.

Parameters
startthe beginning index, inclusive;0 <= start <= limit.
limitthe ending index, exclusive;start <= limit <=length().
textthe text to replace charactersstart tolimit - 1
Stable:
ICU 2.0

Implementsicu::Replaceable.

◆ hashCode()

int32_t icu::UnicodeString::hashCode() const
inline

Generate a hash code for this object.

Returns
The hash code of thisUnicodeString.
Stable:
ICU 2.0

Definition at line4225 of fileunistr.h.

◆ hasMetaData()

virtualUBool icu::UnicodeString::hasMetaData() const
overridevirtual

Replaceable API.

Returns
true if it has MetaData
Stable:
ICU 2.4

Reimplemented fromicu::Replaceable.

◆ hasMoreChar32Than()

UBool icu::UnicodeString::hasMoreChar32Than(int32_t start,
int32_t length,
int32_t number 
) const

Check if the length char16_t code units of the string contain more Unicode code points than a certain number.

This is more efficient than counting all code points in this part of the string and comparing that number with a threshold. This function may not need to scan the string at all if the length falls within a certain range, and never needs to count more than 'number+1' code points. Logically equivalent to (countChar32(start, length)>number). A Unicode code point may occupy either one or two char16_t code units.

Parameters
startthe index of the first code unit to check (0 for the entire string)
lengththe number of char16_t code units to check (use INT32_MAX for the entire string; remember that start/length values are pinned)
numberThe number of code points in the (sub)string is compared against the 'number' parameter.
Returns
Boolean value for whether the string contains more Unicode code points than 'number'. Same as (u_countChar32(s, length)>number).
See also
countChar32
u_strHasMoreChar32Than
Stable:
ICU 2.4

◆ indexOf()[1/13]

int32_t icu::UnicodeString::indexOf(char16_t c) const
inline

Locate in this the first occurrence of the BMP code pointc, using bitwise comparison.

Parameters
cThe code unit to search for.
Returns
The offset into this ofc, or -1 if not found.
Stable:
ICU 2.0

Definition at line4561 of fileunistr.h.

◆ indexOf()[2/13]

int32_t icu::UnicodeString::indexOf(char16_t c,
int32_t start 
) const
inline

Locate in this the first occurrence of the BMP code pointc, starting at offsetstart, using bitwise comparison.

Parameters
cThe code unit to search for.
startThe offset at which searching will start.
Returns
The offset into this ofc, or -1 if not found.
Stable:
ICU 2.0

Definition at line4569 of fileunistr.h.

◆ indexOf()[3/13]

int32_t icu::UnicodeString::indexOf(char16_t c,
int32_t start,
int32_t length 
) const
inline

Locate in this the first occurrence of the BMP code pointc in the range [start,start + length), using bitwise comparison.

Parameters
cThe code unit to search for.
startthe offset into this at which to start matching
lengththe number of characters in this to search
Returns
The offset into this ofc, or -1 if not found.
Stable:
ICU 2.0

Definition at line4549 of fileunistr.h.

◆ indexOf()[4/13]

int32_t icu::UnicodeString::indexOf(const char16_t * srcChars,
int32_t srcLength,
int32_t start 
) const
inline

Locate in this the first occurrence of the characters insrcChars starting at offsetstart, using bitwise comparison.

Parameters
srcCharsThe text to search for.
srcLengththe number of characters insrcChars to match
startthe offset into this at which to start matching
Returns
The offset into this of the start oftext, or -1 if not found.
Stable:
ICU 2.0

Definition at line4534 of fileunistr.h.

◆ indexOf()[5/13]

int32_t icu::UnicodeString::indexOf(const char16_t * srcChars,
int32_t srcStart,
int32_t srcLength,
int32_t start,
int32_t length 
) const

Locate in this the first occurrence in the range [start,start + length) of the characters insrcChars in the range [srcStart,srcStart + srcLength), using bitwise comparison.

Parameters
srcCharsThe text to search for.
srcStartthe offset intosrcChars at which to start matching
srcLengththe number of characters insrcChars to match
startthe offset into this at which to start matching
lengththe number of characters in this to search
Returns
The offset into this of the start oftext, or -1 if not found.
Stable:
ICU 2.0

◆ indexOf()[6/13]

int32_t icu::UnicodeString::indexOf(constUnicodeStringsrcText,
int32_t srcStart,
int32_t srcLength,
int32_t start,
int32_t length 
) const
inline

Locate in this the first occurrence in the range [start,start + length) of the characters insrcText in the range [srcStart,srcStart + srcLength), using bitwise comparison.

Parameters
srcTextThe text to search for.
srcStartthe offset intosrcText at which to start matching
srcLengththe number of characters insrcText to match
startthe offset into this at which to start matching
lengththe number of characters in this to search
Returns
The offset into this of the start oftext, or -1 if not found.
Stable:
ICU 2.0

Definition at line4501 of fileunistr.h.

ReferencesisBogus().

◆ indexOf()[7/13]

int32_t icu::UnicodeString::indexOf(constUnicodeStringtext) const
inline

Locate in this the first occurrence of the characters intext, using bitwise comparison.

Parameters
textThe text to search for.
Returns
The offset into this of the start oftext, or -1 if not found.
Stable:
ICU 2.0

Definition at line4517 of fileunistr.h.

Referenceslength().

◆ indexOf()[8/13]

int32_t icu::UnicodeString::indexOf(constUnicodeStringtext,
int32_t start 
) const
inline

Locate in this the first occurrence of the characters intext starting at offsetstart, using bitwise comparison.

Parameters
textThe text to search for.
startThe offset at which searching will start.
Returns
The offset into this of the start oftext, or -1 if not found.
Stable:
ICU 2.0

Definition at line4521 of fileunistr.h.

Referenceslength().

◆ indexOf()[9/13]

int32_t icu::UnicodeString::indexOf(constUnicodeStringtext,
int32_t start,
int32_t length 
) const
inline

Locate in this the first occurrence in the range [start,start + length) of the characters intext, using bitwise comparison.

Parameters
textThe text to search for.
startThe offset at which searching will start.
lengthThe number of characters to search
Returns
The offset into this of the start oftext, or -1 if not found.
Stable:
ICU 2.0

Definition at line4528 of fileunistr.h.

Referenceslength().

◆ indexOf()[10/13]

int32_t icu::UnicodeString::indexOf(ConstChar16Ptr srcChars,
int32_t srcLength,
int32_t start,
int32_t length 
) const
inline

Locate in this the first occurrence in the range [start,start + length) of the characters insrcChars, using bitwise comparison.

Parameters
srcCharsThe text to search for.
srcLengththe number of characters insrcChars
startThe offset at which searching will start.
lengthThe number of characters to search
Returns
The offset into this of the start ofsrcChars, or -1 if not found.
Stable:
ICU 2.0

Definition at line4542 of fileunistr.h.

◆ indexOf()[11/13]

int32_t icu::UnicodeString::indexOf(UChar32 c) const
inline

Locate in this the first occurrence of the code pointc, using bitwise comparison.

Parameters
cThe code point to search for.
Returns
The offset into this ofc, or -1 if not found.
Stable:
ICU 2.0

Definition at line4565 of fileunistr.h.

◆ indexOf()[12/13]

int32_t icu::UnicodeString::indexOf(UChar32 c,
int32_t start 
) const
inline

Locate in this the first occurrence of the code pointc starting at offsetstart, using bitwise comparison.

Parameters
cThe code point to search for.
startThe offset at which searching will start.
Returns
The offset into this ofc, or -1 if not found.
Stable:
ICU 2.0

Definition at line4576 of fileunistr.h.

◆ indexOf()[13/13]

int32_t icu::UnicodeString::indexOf(UChar32 c,
int32_t start,
int32_t length 
) const
inline

Locate in this the first occurrence of the code pointc in the range [start,start + length), using bitwise comparison.

Parameters
cThe code point to search for.
startthe offset into this at which to start matching
lengththe number of characters in this to search
Returns
The offset into this ofc, or -1 if not found.
Stable:
ICU 2.0

Definition at line4555 of fileunistr.h.

◆ insert()[1/6]

UnicodeString & icu::UnicodeString::insert(int32_t start,
char16_t srcChar 
)
inline

Insert the code unitsrcChar into theUnicodeString object at offsetstart.

Parameters
startthe offset at which the insertion occurs
srcCharthe code unit to insert
Returns
a reference to this
Stable:
ICU 2.0

Definition at line5023 of fileunistr.h.

◆ insert()[2/6]

UnicodeString & icu::UnicodeString::insert(int32_t start,
const char16_t * srcChars,
int32_t srcStart,
int32_t srcLength 
)
inline

Insert the characters insrcChars in the range [srcStart,srcStart + srcLength) into theUnicodeString object at offsetstart.

srcChars is not modified.

Parameters
startthe offset at which the insertion begins
srcCharsthe source for the new characters
srcStartthe offset intosrcChars where new characters will be obtained
srcLengththe number of characters insrcChars in the insert string
Returns
a reference to this
Stable:
ICU 2.0

Definition at line5010 of fileunistr.h.

◆ insert()[3/6]

UnicodeString & icu::UnicodeString::insert(int32_t start,
constUnicodeStringsrcText 
)
inline

Insert the characters insrcText into theUnicodeString object at offsetstart.

srcText is not modified.

Parameters
startthe offset where the insertion begins
srcTextthe source for the new characters
Returns
a reference to this
Stable:
ICU 2.0

Definition at line5005 of fileunistr.h.

Referenceslength().

◆ insert()[4/6]

UnicodeString & icu::UnicodeString::insert(int32_t start,
constUnicodeStringsrcText,
int32_t srcStart,
int32_t srcLength 
)
inline

Insert the characters insrcText in the range [srcStart,srcStart + srcLength) into theUnicodeString object at offsetstart.

srcText is not modified.

Parameters
startthe offset where the insertion begins
srcTextthe source for the new characters
srcStartthe offset intosrcText where new characters will be obtained
srcLengththe number of characters insrcText in the insert string
Returns
a reference to this
Stable:
ICU 2.0

Definition at line4998 of fileunistr.h.

◆ insert()[5/6]

UnicodeString & icu::UnicodeString::insert(int32_t start,
ConstChar16Ptr srcChars,
int32_t srcLength 
)
inline

Insert the characters insrcChars into theUnicodeString object at offsetstart.

srcChars is not modified.

Parameters
startthe offset where the insertion begins
srcCharsthe source for the new characters
srcLengththe number of Unicode characters in srcChars.
Returns
a reference to this
Stable:
ICU 2.0

Definition at line5017 of fileunistr.h.

◆ insert()[6/6]

UnicodeString & icu::UnicodeString::insert(int32_t start,
UChar32 srcChar 
)
inline

Insert the code pointsrcChar into theUnicodeString object at offsetstart.

Parameters
startthe offset at which the insertion occurs
srcCharthe code point to insert
Returns
a reference to this
Stable:
ICU 2.0

Definition at line5028 of fileunistr.h.

◆ isBogus()

UBool icu::UnicodeString::isBogus() const
inline

Determine if this object contains a valid string.

A bogus string has no value. It is different from an empty string, although in both casesisEmpty() returns true andlength() returns 0.setToBogus() andisBogus() can be used to indicate that no string value is available. For a bogus string,getBuffer() andgetTerminatedBuffer() return nullptr, andlength() returns 0.

Returns
true if the string is bogus/invalid, false otherwise
See also
setToBogus()
Stable:
ICU 2.0

Definition at line4229 of fileunistr.h.

Referenced byindexOf(),lastIndexOf(), andoperator==().

◆ isEmpty()

UBool icu::UnicodeString::isEmpty() const
inline

Determine if this string is empty.

Returns
true if this string contains 0 characters, false otherwise.
Stable:
ICU 2.0

Definition at line4863 of fileunistr.h.

◆ lastIndexOf()[1/13]

int32_t icu::UnicodeString::lastIndexOf(char16_t c) const
inline

Locate in this the last occurrence of the BMP code pointc, using bitwise comparison.

Parameters
cThe code unit to search for.
Returns
The offset into this ofc, or -1 if not found.
Stable:
ICU 2.0

Definition at line4644 of fileunistr.h.

◆ lastIndexOf()[2/13]

int32_t icu::UnicodeString::lastIndexOf(char16_t c,
int32_t start 
) const
inline

Locate in this the last occurrence of the BMP code pointc starting at offsetstart, using bitwise comparison.

Parameters
cThe code unit to search for.
startThe offset at which searching will start.
Returns
The offset into this ofc, or -1 if not found.
Stable:
ICU 2.0

Definition at line4653 of fileunistr.h.

◆ lastIndexOf()[3/13]

int32_t icu::UnicodeString::lastIndexOf(char16_t c,
int32_t start,
int32_t length 
) const
inline

Locate in this the last occurrence of the BMP code pointc in the range [start,start + length), using bitwise comparison.

Parameters
cThe code unit to search for.
startthe offset into this at which to start matching
lengththe number of characters in this to search
Returns
The offset into this ofc, or -1 if not found.
Stable:
ICU 2.0

Definition at line4631 of fileunistr.h.

◆ lastIndexOf()[4/13]

int32_t icu::UnicodeString::lastIndexOf(const char16_t * srcChars,
int32_t srcLength,
int32_t start 
) const
inline

Locate in this the last occurrence of the characters insrcChars starting at offsetstart, using bitwise comparison.

Parameters
srcCharsThe text to search for.
srcLengththe number of characters insrcChars to match
startthe offset into this at which to start matching
Returns
The offset into this of the start oftext, or -1 if not found.
Stable:
ICU 2.0

Definition at line4590 of fileunistr.h.

◆ lastIndexOf()[5/13]

int32_t icu::UnicodeString::lastIndexOf(const char16_t * srcChars,
int32_t srcStart,
int32_t srcLength,
int32_t start,
int32_t length 
) const

Locate in this the last occurrence in the range [start,start + length) of the characters insrcChars in the range [srcStart,srcStart + srcLength), using bitwise comparison.

Parameters
srcCharsThe text to search for.
srcStartthe offset intosrcChars at which to start matching
srcLengththe number of characters insrcChars to match
startthe offset into this at which to start matching
lengththe number of characters in this to search
Returns
The offset into this of the start oftext, or -1 if not found.
Stable:
ICU 2.0

◆ lastIndexOf()[6/13]

int32_t icu::UnicodeString::lastIndexOf(constUnicodeStringsrcText,
int32_t srcStart,
int32_t srcLength,
int32_t start,
int32_t length 
) const
inline

Locate in this the last occurrence in the range [start,start + length) of the characters insrcText in the range [srcStart,srcStart + srcLength), using bitwise comparison.

Parameters
srcTextThe text to search for.
srcStartthe offset intosrcText at which to start matching
srcLengththe number of characters insrcText to match
startthe offset into this at which to start matching
lengththe number of characters in this to search
Returns
The offset into this of the start oftext, or -1 if not found.
Stable:
ICU 2.0

Definition at line4598 of fileunistr.h.

ReferencesisBogus().

◆ lastIndexOf()[7/13]

int32_t icu::UnicodeString::lastIndexOf(constUnicodeStringtext) const
inline

Locate in this the last occurrence of the characters intext, using bitwise comparison.

Parameters
textThe text to search for.
Returns
The offset into this of the start oftext, or -1 if not found.
Stable:
ICU 2.0

Definition at line4627 of fileunistr.h.

Referenceslength().

◆ lastIndexOf()[8/13]

int32_t icu::UnicodeString::lastIndexOf(constUnicodeStringtext,
int32_t start 
) const
inline

Locate in this the last occurrence of the characters intext starting at offsetstart, using bitwise comparison.

Parameters
textThe text to search for.
startThe offset at which searching will start.
Returns
The offset into this of the start oftext, or -1 if not found.
Stable:
ICU 2.0

Definition at line4620 of fileunistr.h.

Referenceslength().

◆ lastIndexOf()[9/13]

int32_t icu::UnicodeString::lastIndexOf(constUnicodeStringtext,
int32_t start,
int32_t length 
) const
inline

Locate in this the last occurrence in the range [start,start + length) of the characters intext, using bitwise comparison.

Parameters
textThe text to search for.
startThe offset at which searching will start.
lengthThe number of characters to search
Returns
The offset into this of the start oftext, or -1 if not found.
Stable:
ICU 2.0

Definition at line4614 of fileunistr.h.

Referenceslength().

◆ lastIndexOf()[10/13]

int32_t icu::UnicodeString::lastIndexOf(ConstChar16Ptr srcChars,
int32_t srcLength,
int32_t start,
int32_t length 
) const
inline

Locate in this the last occurrence in the range [start,start + length) of the characters insrcChars, using bitwise comparison.

Parameters
srcCharsThe text to search for.
srcLengththe number of characters insrcChars
startThe offset at which searching will start.
lengthThe number of characters to search
Returns
The offset into this of the start ofsrcChars, or -1 if not found.
Stable:
ICU 2.0

Definition at line4583 of fileunistr.h.

◆ lastIndexOf()[11/13]

int32_t icu::UnicodeString::lastIndexOf(UChar32 c) const
inline

Locate in this the last occurrence of the code pointc, using bitwise comparison.

Parameters
cThe code point to search for.
Returns
The offset into this ofc, or -1 if not found.
Stable:
ICU 2.0

Definition at line4648 of fileunistr.h.

◆ lastIndexOf()[12/13]

int32_t icu::UnicodeString::lastIndexOf(UChar32 c,
int32_t start 
) const
inline

Locate in this the last occurrence of the code pointc starting at offsetstart, using bitwise comparison.

Parameters
cThe code point to search for.
startThe offset at which searching will start.
Returns
The offset into this ofc, or -1 if not found.
Stable:
ICU 2.0

Definition at line4660 of fileunistr.h.

◆ lastIndexOf()[13/13]

int32_t icu::UnicodeString::lastIndexOf(UChar32 c,
int32_t start,
int32_t length 
) const
inline

Locate in this the last occurrence of the code pointc in the range [start,start + length), using bitwise comparison.

Parameters
cThe code point to search for.
startthe offset into this at which to start matching
lengththe number of characters in this to search
Returns
The offset into this ofc, or -1 if not found.
Stable:
ICU 2.0

Definition at line4637 of fileunistr.h.

◆ length()

int32_t icu::UnicodeString::length() const
inline

Return the length of theUnicodeString object.

The length is the number of char16_t code units are in theUnicodeString. If you want the number of code points, please usecountChar32().

Returns
the length of theUnicodeString object
See also
countChar32
Stable:
ICU 2.0

Definition at line4214 of fileunistr.h.

Referenced byappend(),caseCompare(),icu::Normalizer::compare(),compare(),compareCodePointOrder(),endsWith(),findAndReplace(),indexOf(),insert(),lastIndexOf(),operator+=(),operator<(),operator<=(),operator==(),operator>(),operator>=(),replace(),replaceBetween(),setTo(),icu::UnicodeSet::span(),icu::UnicodeSet::spanBack(), andstartsWith().

◆ moveIndex32()

int32_t icu::UnicodeString::moveIndex32(int32_t index,
int32_t delta 
) const

Move the code unit index along the string by delta code points.

Interpret the input index as a code unit-based offset into the string, move the index forward or backward by delta code points, and return the resulting index. The input index should point to the first code unit of a code point, if there is more than one.

Both input and output indexes are code unit-based as for all string indexes/offsets in ICU (and other libraries, like MBCS char*). If delta<0 then the index is moved backward (toward the start of the string). If delta>0 then the index is moved forward (toward the end of the string).

This behaves like CharacterIterator::move32(delta, kCurrent).

Behavior for out-of-bounds indexes:moveIndex32 pins the input index to 0..length(), i.e., if the input index<0 then it is pinned to 0; if it is index>length() then it is pinned tolength(). Afterwards, the index is moved bydelta code points forward or backward, but no further backward than to 0 and no further forward than tolength(). The resulting index return value will be in between 0 andlength(), inclusively.

Examples:

// s has code points 'a' U+10000 'b' U+10ffff U+2029
UnicodeString s(u"a\U00010000b\U0010ffff\u2029");
// initial index: position of U+10000
int32_t index=1;
// the following examples will all result in index==4, position of U+10ffff
// skip 2 code points from some position in the string
index=s.moveIndex32(index, 2);// skips U+10000 and 'b'
// go to the 3rd code point from the start of s (0-based)
index=s.moveIndex32(0, 3);// skips 'a', U+10000, and 'b'
// go to the next-to-last code point of s
index=s.moveIndex32(s.length(), -2);// backward-skips U+2029 and U+10ffff
Parameters
indexinput code unit index
delta(signed) code point count to move the index forward or backward in the string
Returns
the resulting code unit index
Stable:
ICU 2.0

◆ operator std::u16string_view()

icu::UnicodeString::operator std::u16string_view() const
inline

Converts to a std::u16string_view.

Returns
a string view of the contents of this string
Draft:
This API may be changed in the future versions and was introduced in ICU 76

Definition at line3035 of fileunistr.h.

Referencesicu::Replaceable::length().

◆ operator std::wstring_view()

icu::UnicodeString::operator std::wstring_view() const
inline

Converts to a std::wstring_view.

Note: This should remain draft until C++ standard plans about char16_t vs. wchar_t become clearer.

Returns
a string view of the contents of this string
Draft:
This API may be changed in the future versions and was introduced in ICU 76

Definition at line3049 of fileunistr.h.

Referencesicu::Replaceable::length(), andU_ALIASING_BARRIER.

◆ operator!=()[1/2]

template<typename S , typename = std::enable_if_t<ConvertibleToU16StringView<S>>>
bool icu::UnicodeString::operator!=(const S & text) const
inline

Inequality operator.

Performs only bitwise comparison withtext which is, or which is implicitly convertible to, a std::u16string_view or (if U_SIZEOF_WCHAR_T==2) std::wstring_view.

For performance, you can use std::u16string_view literals with compile-time length determination:

#include &lt;string_view&gt;
using namespacestd::string_view_literals;
UnicodeString str = ...;
if (str != u"literal"sv) { ... }
Parameters
textThe string view to compare to this string.
Returns
false iftext contains the same characters as this one, true otherwise.
Draft:
This API may be changed in the future versions and was introduced in ICU 76

Definition at line382 of fileunistr.h.

Referencesicu::operator==().

◆ operator!=()[2/2]

bool icu::UnicodeString::operator!=(constUnicodeStringtext) const
inline

Inequality operator.

Performs only bitwise comparison.

Parameters
textTheUnicodeString to compare to this one.
Returns
false iftext contains the same characters as this one, true otherwise.
Stable:
ICU 2.0

Definition at line4300 of fileunistr.h.

◆ operator+=()[1/4]

UnicodeString & icu::UnicodeString::operator+=(char16_t ch)
inline

Append operator.

Append the code unitch to theUnicodeString object.

Parameters
chthe code unit to be appended
Returns
a reference to this
Stable:
ICU 2.0

Definition at line4985 of fileunistr.h.

◆ operator+=()[2/4]

template<typename S , typename = std::enable_if_t<ConvertibleToU16StringView<S>>>
UnicodeString& icu::UnicodeString::operator+=(const S & src)
inline

Append operator.

Appends the characters insrc which is, or which is implicitly convertible to, a std::u16string_view or (if U_SIZEOF_WCHAR_T==2) std::wstring_view, to theUnicodeString object.

Parameters
srcthe source for the new characters
Returns
a reference to this
Draft:
This API may be changed in the future versions and was introduced in ICU 76

Definition at line2227 of fileunistr.h.

◆ operator+=()[3/4]

UnicodeString & icu::UnicodeString::operator+=(constUnicodeStringsrcText)
inline

Append operator.

Append the characters insrcText to theUnicodeString object.srcText is not modified.

Parameters
srcTextthe source for the new characters
Returns
a reference to this
Stable:
ICU 2.0

Definition at line4994 of fileunistr.h.

Referenceslength().

◆ operator+=()[4/4]

UnicodeString & icu::UnicodeString::operator+=(UChar32 ch)
inline

Append operator.

Append the code pointch to theUnicodeString object.

Parameters
chthe code point to be appended
Returns
a reference to this
Stable:
ICU 2.0

Definition at line4989 of fileunistr.h.

◆ operator<()

UBool icu::UnicodeString::operator<(constUnicodeStringtext) const
inline

Less than operator.

Performs only bitwise comparison.

Parameters
textTheUnicodeString to compare to this one.
Returns
true if the characters in this are bitwise less than the characters intext, false otherwise
Stable:
ICU 2.0

Definition at line4307 of fileunistr.h.

Referenceslength().

◆ operator<=()

UBool icu::UnicodeString::operator<=(constUnicodeStringtext) const
inline

Less than or equal operator.

Performs only bitwise comparison.

Parameters
textTheUnicodeString to compare to this one.
Returns
true if the characters in this are bitwise less than or equal to the characters intext, false otherwise
Stable:
ICU 2.0

Definition at line4315 of fileunistr.h.

Referenceslength().

◆ operator=()[1/5]

UnicodeString & icu::UnicodeString::operator=(char16_t ch)
inline

Assignment operator.

Replace the characters in thisUnicodeString with the code unitch.

Parameters
chthe code unit to replace
Returns
a reference to this
Stable:
ICU 2.0

Definition at line4906 of fileunistr.h.

◆ operator=()[2/5]

template<typename S , typename = std::enable_if_t<ConvertibleToU16StringView<S>>>
UnicodeString& icu::UnicodeString::operator=(const S & src)
inline

Assignment operator.

Replaces the characters in thisUnicodeString with a copy of the characters from thesrc which is, or which is implicitly convertible to, a std::u16string_view or (if U_SIZEOF_WCHAR_T==2) std::wstring_view.

Parameters
srcThe string view containing the characters to copy.
Returns
a reference to this
Draft:
This API may be changed in the future versions and was introduced in ICU 76

Definition at line1960 of fileunistr.h.

Referencesicu::Replaceable::length().

◆ operator=()[3/5]

UnicodeString& icu::UnicodeString::operator=(constUnicodeStringsrcText)

Assignment operator.

Replace the characters in thisUnicodeString with the characters fromsrcText.

Starting with ICU 2.4, the assignment operator and the copy constructor allocate a new buffer and copy the buffer contents even for readonly aliases. By contrast, thefastCopyFrom() function implements the old, more efficient but less safe behavior of making this string also a readonly alias to the same buffer.

If the source object has an "open" buffer from getBuffer(minCapacity), then the copy is an empty string.

Parameters
srcTextThe text containing the characters to replace
Returns
a reference to this
Stable:
ICU 2.0
See also
fastCopyFrom

◆ operator=()[4/5]

UnicodeString & icu::UnicodeString::operator=(UChar32 ch)
inline

Assignment operator.

Replace the characters in thisUnicodeString with the code pointch.

Parameters
chthe code point to replace
Returns
a reference to this
Stable:
ICU 2.0

Definition at line4910 of fileunistr.h.

◆ operator=()[5/5]

UnicodeString& icu::UnicodeString::operator=(UnicodeString && src)
noexcept

Move assignment operator; might leave src in bogus state.

This string will have the same contents and state that the source string had. The behavior is undefined if *this and src are the same object.

Parameters
srcsource string
Returns
*this
Stable:
ICU 56

◆ operator==()[1/2]

template<typename S , typename = std::enable_if_t<ConvertibleToU16StringView<S>>>
bool icu::UnicodeString::operator==(const S & text) const
inline

Equality operator.

Performs only bitwise comparison withtext which is, or which is implicitly convertible to, a std::u16string_view or (if U_SIZEOF_WCHAR_T==2) std::wstring_view.

For performance, you can use UTF-16 string literals with compile-time length determination:

UnicodeString str = ...;
if (str == u"literal") { ... }
Parameters
textThe string view to compare to this string.
Returns
true iftext contains the same characters as this one, false otherwise.
Draft:
This API may be changed in the future versions and was introduced in ICU 76

Definition at line347 of fileunistr.h.

Referencesicu::Replaceable::length().

◆ operator==()[2/2]

bool icu::UnicodeString::operator==(constUnicodeStringtext) const
inline

Equality operator.

Performs only bitwise comparison.

Parameters
textTheUnicodeString to compare to this one.
Returns
true iftext contains the same characters as this one, false otherwise.
Stable:
ICU 2.0

Definition at line4289 of fileunistr.h.

ReferencesisBogus(), andlength().

◆ operator>()

UBool icu::UnicodeString::operator>(constUnicodeStringtext) const
inline

Greater than operator.

Performs only bitwise comparison.

Parameters
textTheUnicodeString to compare to this one.
Returns
true if the characters in this are bitwise greater than the characters intext, false otherwise
Stable:
ICU 2.0

Definition at line4304 of fileunistr.h.

Referenceslength().

◆ operator>=()

UBool icu::UnicodeString::operator>=(constUnicodeStringtext) const
inline

Greater than or equal operator.

Performs only bitwise comparison.

Parameters
textTheUnicodeString to compare to this one.
Returns
true if the characters in this are bitwise greater than or equal to the characters intext, false otherwise
Stable:
ICU 2.0

Definition at line4312 of fileunistr.h.

Referenceslength().

◆ operator[]()

char16_t icu::UnicodeString::operator[](int32_t offset) const
inline

Return the code unit at offsetoffset.

If the offset is not valid (0..length()-1) then U+ffff is returned.

Parameters
offseta valid offset into the text
Returns
the code unit at offsetoffset
Stable:
ICU 2.0

Definition at line4859 of fileunistr.h.

◆ padLeading()

UBool icu::UnicodeString::padLeading(int32_t targetLength,
char16_t padChar =0x0020 
)

Pad the start of thisUnicodeString with the characterpadChar.

If the length of thisUnicodeString is less than targetLength,length() - targetLength copies of padChar will be added to the beginning of thisUnicodeString.

Parameters
targetLengththe desired length of the string
padCharthe character to use for padding. Defaults to space (U+0020)
Returns
true if the text was padded, false otherwise.
Stable:
ICU 2.0

◆ padTrailing()

UBool icu::UnicodeString::padTrailing(int32_t targetLength,
char16_t padChar =0x0020 
)

Pad the end of thisUnicodeString with the characterpadChar.

If the length of thisUnicodeString is less than targetLength,length() - targetLength copies of padChar will be added to the end of thisUnicodeString.

Parameters
targetLengththe desired length of the string
padCharthe character to use for padding. Defaults to space (U+0020)
Returns
true if the text was padded, false otherwise.
Stable:
ICU 2.0

◆ readOnlyAlias()[1/2]

template<typename S , typename = std::enable_if_t<ConvertibleToU16StringView<S>>>
staticUnicodeString icu::UnicodeString::readOnlyAlias(const S & text)
inlinestatic

Readonly-aliasing factory method.

Aliases the same buffer as the inputtext which is, or which is implicitly convertible to, a std::u16string_view or (if U_SIZEOF_WCHAR_T==2) std::wstring_view. The string is bogus if the string view is too long.

The text will be used for theUnicodeString object, but it will not be released when theUnicodeString is destroyed. This has copy-on-write semantics: When the string is modified, then the buffer is first copied into newly allocated memory. The aliased buffer is never modified.

In an assignment to anotherUnicodeString, when using the copy constructor or the assignment operator, the text will be copied. When usingfastCopyFrom(), the text will be aliased again, so that both strings then alias the same readonly-text.

Parameters
textThe string view to alias for theUnicodeString.
Draft:
This API may be changed in the future versions and was introduced in ICU 76

Definition at line3600 of fileunistr.h.

◆ readOnlyAlias()[2/2]

staticUnicodeString icu::UnicodeString::readOnlyAlias(constUnicodeStringtext)
inlinestatic

Readonly-aliasing factory method.

Aliases the same buffer as the inputtext.

The text will be used for theUnicodeString object, but it will not be released when theUnicodeString is destroyed. This has copy-on-write semantics: When the string is modified, then the buffer is first copied into newly allocated memory. The aliased buffer is never modified.

In an assignment to anotherUnicodeString, when using the copy constructor or the assignment operator, the text will be copied. When usingfastCopyFrom(), the text will be aliased again, so that both strings then alias the same readonly-text.

Parameters
textTheUnicodeString to alias.
Draft:
This API may be changed in the future versions and was introduced in ICU 76

Definition at line3623 of fileunistr.h.

◆ releaseBuffer()

void icu::UnicodeString::releaseBuffer(int32_t newLength =-1)

Release a read/write buffer on aUnicodeString object with an "open" getBuffer(minCapacity).

This function must be called in a matched pair with getBuffer(minCapacity). releaseBuffer(newLength) must be called if and only if a getBuffer(minCapacity) is "open".

It will set the string length to newLength, at most to the current capacity. If newLength==-1 then it will set the length according to the first NUL in the buffer, or to the capacity if there is no NUL.

After calling releaseBuffer(newLength) theUnicodeString is back to normal operation.

Parameters
newLengththe new length of theUnicodeString object; defaults to the current capacity if newLength is greater than that; if newLength==-1, it defaults to u_strlen(buffer) but not more than the current capacity of the string
See also
getBuffer(int32_t minCapacity)
Stable:
ICU 2.0

◆ remove()[1/2]

UnicodeString & icu::UnicodeString::remove()
inline

Removes all characters from theUnicodeString object and clears the bogus flag.

This is theUnicodeString equivalent of std::string’s clear().

Returns
a reference to this
See also
setToBogus
Stable:
ICU 2.0

Definition at line5034 of fileunistr.h.

◆ remove()[2/2]

UnicodeString & icu::UnicodeString::remove(int32_t start,
int32_t length =static_cast<int32_t>(INT32_MAX) 
)
inline

Remove the characters in the range [start,start + length) from theUnicodeString object.

Parameters
startthe offset of the first character to remove
lengththe number of characters to remove
Returns
a reference to this
Stable:
ICU 2.0

Definition at line5046 of fileunistr.h.

ReferencesINT32_MAX.

◆ removeBetween()

UnicodeString & icu::UnicodeString::removeBetween(int32_t start,
int32_t limit =static_cast<int32_t>(INT32_MAX) 
)
inline

Remove the characters in the range [start,limit) from theUnicodeString object.

Parameters
startthe offset of the first character to remove
limitthe offset immediately following the range to remove
Returns
a reference to this
Stable:
ICU 2.0

Definition at line5057 of fileunistr.h.

◆ replace()[1/6]

UnicodeString & icu::UnicodeString::replace(int32_t start,
int32_t length,
char16_t srcChar 
)
inline

Replace the characters in the range [start,start + length) with the code unitsrcChar.

Parameters
startthe offset at which the replace operation begins
lengththe number of characters to replace. The character atstart + length is not modified.
srcCharthe new code unit
Returns
a reference to this
Stable:
ICU 2.0

Definition at line4759 of fileunistr.h.

◆ replace()[2/6]

UnicodeString & icu::UnicodeString::replace(int32_t start,
int32_t length,
const char16_t * srcChars,
int32_t srcStart,
int32_t srcLength 
)
inline

Replace the characters in the range [start,start + length) with the characters insrcChars in the range [srcStart,srcStart + srcLength).

srcChars is not modified.

Parameters
startthe offset at which the replace operation begins
lengththe number of characters to replace. The character atstart + length is not modified.
srcCharsthe source for the new characters
srcStartthe offset intosrcChars where new characters will be obtained
srcLengththe number of characters insrcChars in the replace string
Returns
a reference to this
Stable:
ICU 2.0

Definition at line4751 of fileunistr.h.

◆ replace()[3/6]

UnicodeString & icu::UnicodeString::replace(int32_t start,
int32_t length,
constUnicodeStringsrcText 
)
inline

Replace the characters in the range [start,start + length) with the characters insrcText.

srcText is not modified.

Parameters
startthe offset at which the replace operation begins
lengththe number of characters to replace. The character atstart + length is not modified.
srcTextthe source for the new characters
Returns
a reference to this
Stable:
ICU 2.0

Definition at line4730 of fileunistr.h.

Referenceslength().

◆ replace()[4/6]

UnicodeString & icu::UnicodeString::replace(int32_t start,
int32_t length,
constUnicodeStringsrcText,
int32_t srcStart,
int32_t srcLength 
)
inline

Replace the characters in the range [start,start + length) with the characters insrcText in the range [srcStart,srcStart + srcLength).

srcText is not modified.

Parameters
startthe offset at which the replace operation begins
lengththe number of characters to replace. The character atstart + length is not modified.
srcTextthe source for the new characters
srcStartthe offset intosrcText where new characters will be obtained
srcLengththe number of characters insrcText in the replace string
Returns
a reference to this
Stable:
ICU 2.0

Definition at line4736 of fileunistr.h.

◆ replace()[5/6]

UnicodeString & icu::UnicodeString::replace(int32_t start,
int32_t length,
ConstChar16Ptr srcChars,
int32_t srcLength 
)
inline

Replace the characters in the range [start,start + length) with the characters insrcChars.

srcChars is not modified.

Parameters
startthe offset at which the replace operation begins
lengthnumber of characters to replace. The character atstart + length is not modified.
srcCharsthe source for the new characters
srcLengththe number of Unicode characters in srcChars
Returns
a reference to this
Stable:
ICU 2.0

Definition at line4744 of fileunistr.h.

◆ replace()[6/6]

UnicodeString& icu::UnicodeString::replace(int32_t start,
int32_t length,
UChar32 srcChar 
)

Replace the characters in the range [start,start + length) with the code pointsrcChar.

Parameters
startthe offset at which the replace operation begins
lengththe number of characters to replace. The character atstart + length is not modified.
srcCharthe new code point
Returns
a reference to this
Stable:
ICU 2.0

◆ replaceBetween()[1/2]

UnicodeString & icu::UnicodeString::replaceBetween(int32_t start,
int32_t limit,
constUnicodeStringsrcText 
)
inline

Replace the characters in the range [start,limit) with the characters insrcText.

srcText is not modified.

Parameters
startthe offset at which the replace operation begins
limitthe offset immediately following the replace range
srcTextthe source for the new characters
Returns
a reference to this
Stable:
ICU 2.0

Definition at line4765 of fileunistr.h.

Referenceslength().

◆ replaceBetween()[2/2]

UnicodeString & icu::UnicodeString::replaceBetween(int32_t start,
int32_t limit,
constUnicodeStringsrcText,
int32_t srcStart,
int32_t srcLimit 
)
inline

Replace the characters in the range [start,limit) with the characters insrcText in the range [srcStart,srcLimit).

srcText is not modified.

Parameters
startthe offset at which the replace operation begins
limitthe offset immediately following the replace range
srcTextthe source for the new characters
srcStartthe offset intosrcChars where new characters will be obtained
srcLimitthe offset immediately following the range to copy insrcText
Returns
a reference to this
Stable:
ICU 2.0

Definition at line4771 of fileunistr.h.

◆ retainBetween()

UnicodeString & icu::UnicodeString::retainBetween(int32_t start,
int32_t limit =INT32_MAX 
)
inline

Retain only the characters in the range [start,limit) from theUnicodeString object.

Removes characters beforestart and at and afterlimit.

Parameters
startthe offset of the first character to retain
limitthe offset immediately following the range to retain
Returns
a reference to this
Stable:
ICU 4.4

Definition at line5062 of fileunistr.h.

◆ reverse()[1/2]

UnicodeString & icu::UnicodeString::reverse()
inline

Reverse thisUnicodeString in place.

Returns
a reference to this
Stable:
ICU 2.0

Definition at line5083 of fileunistr.h.

◆ reverse()[2/2]

UnicodeString & icu::UnicodeString::reverse(int32_t start,
int32_t length 
)
inline

Reverse the range [start,start + length) in thisUnicodeString.

Parameters
startthe start of the range to reverse
lengththe number of characters to to reverse
Returns
a reference to this
Stable:
ICU 2.0

Definition at line5087 of fileunistr.h.

◆ setCharAt()

UnicodeString& icu::UnicodeString::setCharAt(int32_t offset,
char16_t ch 
)

Set the character at the specified offset to the specified character.

Parameters
offsetA valid offset into the text of the character to set
chThe new character
Returns
A reference to this
Stable:
ICU 2.0

◆ setTo()[1/8]

UnicodeString& icu::UnicodeString::setTo(char16_t * buffer,
int32_t buffLength,
int32_t buffCapacity 
)

AliasingsetTo() function, analogous to the writable-aliasing char16_t* constructor.

The text will be used for theUnicodeString object, but it will not be released when theUnicodeString is destroyed. This has write-through semantics: For as long as the capacity of the buffer is sufficient, write operations will directly affect the buffer. When more capacity is necessary, then a new buffer will be allocated and the contents copied as with regularly constructed strings. In an assignment to anotherUnicodeString, the buffer will be copied. The extract(Char16Ptr dst) function detects whether the dst pointer is the same as the string buffer itself and will in this case not copy the contents.

Parameters
bufferThe characters to alias for theUnicodeString.
buffLengthThe number of Unicode characters inbuffer to alias.
buffCapacityThe size ofbuffer in char16_ts.
Returns
a reference to this
Stable:
ICU 2.0

◆ setTo()[2/8]

UnicodeString & icu::UnicodeString::setTo(char16_t srcChar)
inline

Set the characters in theUnicodeString object to the code unitsrcChar.

Parameters
srcCharthe code unit which becomes theUnicodeString's character content
Returns
a reference to this
Stable:
ICU 2.0

Definition at line4946 of fileunistr.h.

◆ setTo()[3/8]

UnicodeString & icu::UnicodeString::setTo(const char16_t * srcChars,
int32_t srcLength 
)
inline

Set the characters in theUnicodeString object to the characters insrcChars.

srcChars is not modified.

Parameters
srcCharsthe source for the new characters
srcLengththe number of Unicode characters in srcChars.
Returns
a reference to this
Stable:
ICU 2.0

Definition at line4938 of fileunistr.h.

◆ setTo()[4/8]

UnicodeString & icu::UnicodeString::setTo(constUnicodeStringsrcText)
inline

Set the text in theUnicodeString object to the characters insrcText.

srcText is not modified.

Parameters
srcTextthe source for the new characters
Returns
a reference to this
Stable:
ICU 2.0

Definition at line4932 of fileunistr.h.

◆ setTo()[5/8]

UnicodeString & icu::UnicodeString::setTo(constUnicodeStringsrcText,
int32_t srcStart 
)
inline

Set the text in theUnicodeString object to the characters insrcText in the range [srcStart,srcText.length()).

srcText is not modified.

Parameters
srcTextthe source for the new characters
srcStartthe offset intosrcText where new characters will be obtained
Returns
a reference to this
Stable:
ICU 2.2

Definition at line4923 of fileunistr.h.

Referenceslength().

Referenced byicu::ures_getNextUnicodeString(),icu::ures_getUnicodeString(),icu::ures_getUnicodeStringByIndex(), andicu::ures_getUnicodeStringByKey().

◆ setTo()[6/8]

UnicodeString & icu::UnicodeString::setTo(constUnicodeStringsrcText,
int32_t srcStart,
int32_t srcLength 
)
inline

Set the text in theUnicodeString object to the characters insrcText in the range [srcStart,srcStart + srcLength).

srcText is not modified.

Parameters
srcTextthe source for the new characters
srcStartthe offset intosrcText where new characters will be obtained
srcLengththe number of characters insrcText in the replace string.
Returns
a reference to this
Stable:
ICU 2.0

Definition at line4914 of fileunistr.h.

◆ setTo()[7/8]

UnicodeString& icu::UnicodeString::setTo(UBool isTerminated,
ConstChar16Ptr text,
int32_t textLength 
)

AliasingsetTo() function, analogous to the readonly-aliasing char16_t* constructor.

The text will be used for theUnicodeString object, but it will not be released when theUnicodeString is destroyed. This has copy-on-write semantics: When the string is modified, then the buffer is first copied into newly allocated memory. The aliased buffer is never modified.

In an assignment to anotherUnicodeString, when using the copy constructor or the assignment operator, the text will be copied. When usingfastCopyFrom(), the text will be aliased again, so that both strings then alias the same readonly-text.

Parameters
isTerminatedspecifies iftext isNUL-terminated. This must be true iftextLength==-1.
textThe characters to alias for theUnicodeString.
textLengthThe number of Unicode characters intext to alias. If -1, then this constructor will determine the length by callingu_strlen().
Returns
a reference to this
Stable:
ICU 2.0

◆ setTo()[8/8]

UnicodeString & icu::UnicodeString::setTo(UChar32 srcChar)
inline

Set the characters in theUnicodeString object to the code pointsrcChar.

Parameters
srcCharthe code point which becomes theUnicodeString's character content
Returns
a reference to this
Stable:
ICU 2.0

Definition at line4953 of fileunistr.h.

◆ setToBogus()

void icu::UnicodeString::setToBogus()

Make thisUnicodeString object invalid.

The string will test true withisBogus().

A bogus string has no value. It is different from an empty string. It can be used to indicate that no string value is available.getBuffer() andgetTerminatedBuffer() return nullptr, andlength() returns 0.

This utility function is used throughout theUnicodeString implementation to indicate that aUnicodeString operation failed, and may be used in other functions, especially but not exclusively when such functions do not take a UErrorCode for simplicity.

The following methods, and no others, will clear a string object's bogus flag:

The simplest ways to turn a bogus string into an empty one is to use theremove() function. Examples for other functions that are equivalent to "set to empty string":

if(s.isBogus()) {
s.remove();// set to an empty string (remove all), or
s.remove(0,INT32_MAX);// set to an empty string (remove all), or
s.truncate(0);// set to an empty string (complete truncation), or
s=UnicodeString();// assign an empty string, or
s.setTo((UChar32)-1);// set to a pseudo code point that is out of range, or
s.setTo(u"", 0);// set to an empty C Unicode string
}
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
Definition:umachine.h:427
#define INT32_MAX
The largest value a 32 bit signed integer can hold.
Definition:umachine.h:186
See also
isBogus()
Stable:
ICU 2.0

Referenced byicu::ures_getNextUnicodeString(),icu::ures_getUnicodeString(),icu::ures_getUnicodeStringByIndex(), andicu::ures_getUnicodeStringByKey().

◆ startsWith()[1/4]

UBool icu::UnicodeString::startsWith(const char16_t * srcChars,
int32_t srcStart,
int32_t srcLength 
) const
inline

Determine if this ends with the characters insrcChars in the range [srcStart,srcStart + srcLength).

Parameters
srcCharsThe characters to match.
srcStartthe offset intosrcText to start matching
srcLengththe number of characters insrcChars to match
Returns
true if this ends with the characters insrcChars, false otherwise
Stable:
ICU 2.0

Definition at line4685 of fileunistr.h.

Referencesu_strlen().

◆ startsWith()[2/4]

UBool icu::UnicodeString::startsWith(constUnicodeStringsrcText,
int32_t srcStart,
int32_t srcLength 
) const
inline

Determine if this starts with the characters insrcText in the range [srcStart,srcStart + srcLength).

Parameters
srcTextThe text to match.
srcStartthe offset intosrcText to start matching
srcLengththe number of characters insrcText to match
Returns
true if this starts with the characters intext, false otherwise
Stable:
ICU 2.0

Definition at line4671 of fileunistr.h.

◆ startsWith()[3/4]

UBool icu::UnicodeString::startsWith(constUnicodeStringtext) const
inline

Determine if this starts with the characters intext

Parameters
textThe text to match.
Returns
true if this starts with the characters intext, false otherwise
Stable:
ICU 2.0

Definition at line4667 of fileunistr.h.

Referenceslength().

◆ startsWith()[4/4]

UBool icu::UnicodeString::startsWith(ConstChar16Ptr srcChars,
int32_t srcLength 
) const
inline

Determine if this starts with the characters insrcChars

Parameters
srcCharsThe characters to match.
srcLengththe number of characters insrcChars
Returns
true if this starts with the characters insrcChars, false otherwise
Stable:
ICU 2.0

Definition at line4677 of fileunistr.h.

Referencesu_strlen().

◆ swap()

void icu::UnicodeString::swap(UnicodeStringother)
noexcept

Swap strings.

Parameters
otherother string
Stable:
ICU 56

◆ tempSubString()

UnicodeString icu::UnicodeString::tempSubString(int32_t start =0,
int32_t length =INT32_MAX 
) const

Create a temporary substring for the specified range.

Unlike the substring constructor andsetTo() functions, the object returned here will be a read-only alias (usinggetBuffer()) rather than copying the text. As a result, this substring operation is much faster but requires that the original string not be modified or deleted during the lifetime of the returned substring object.

Parameters
startoffset of the first character visible in the substring
lengthlength of the substring
Returns
a read-only aliasUnicodeString object for the substring
Stable:
ICU 4.4

Referenced byicu::MessagePattern::getSubstring().

◆ tempSubStringBetween()

UnicodeString icu::UnicodeString::tempSubStringBetween(int32_t start,
int32_t limit =INT32_MAX 
) const
inline

Create a temporary substring for the specified range.

Same as tempSubString(start, length) except that the substring range is specified as a (start, limit) pair (with an exclusive limit index) rather than a (start, length) pair.

Parameters
startoffset of the first character visible in the substring
limitoffset immediately following the last character visible in the substring
Returns
a read-only aliasUnicodeString object for the substring
Stable:
ICU 4.4

Definition at line4840 of fileunistr.h.

◆ toLower()[1/2]

UnicodeString& icu::UnicodeString::toLower()

Convert the characters in this to lower case following the conventions of the default locale.

Returns
A reference to this.
Stable:
ICU 2.0

◆ toLower()[2/2]

UnicodeString& icu::UnicodeString::toLower(constLocalelocale)

Convert the characters in this to lower case following the conventions of a specific locale.

Parameters
localeThe locale containing the conventions to use.
Returns
A reference to this.
Stable:
ICU 2.0

◆ toTitle()[1/3]

UnicodeString& icu::UnicodeString::toTitle(BreakIteratortitleIter)

Titlecase this string, convenience function using the default locale.

Casing is locale-dependent and context-sensitive. Titlecasing uses a break iterator to find the first characters of words that are to be titlecased. It titlecases those characters and lowercases all others.

The titlecase break iterator can be provided to customize for arbitrary styles, using rules and dictionaries beyond the standard iterators. It may be more efficient to always provide an iterator to avoid opening and closing one for each string. If the break iterator passed in is null, the default Unicode algorithm will be used to determine the titlecase positions.

This function uses only the setText(), first() and next() methods of the provided break iterator.

Parameters
titleIterA break iterator to find the first characters of words that are to be titlecased. If none is provided (0), then a standard titlecase break iterator is opened. Otherwise the provided iterator is set to the string's text.
Returns
A reference to this.
Stable:
ICU 2.1

◆ toTitle()[2/3]

UnicodeString& icu::UnicodeString::toTitle(BreakIteratortitleIter,
constLocalelocale 
)

Titlecase this string.

Casing is locale-dependent and context-sensitive. Titlecasing uses a break iterator to find the first characters of words that are to be titlecased. It titlecases those characters and lowercases all others.

The titlecase break iterator can be provided to customize for arbitrary styles, using rules and dictionaries beyond the standard iterators. It may be more efficient to always provide an iterator to avoid opening and closing one for each string. If the break iterator passed in is null, the default Unicode algorithm will be used to determine the titlecase positions.

This function uses only the setText(), first() and next() methods of the provided break iterator.

Parameters
titleIterA break iterator to find the first characters of words that are to be titlecased. If none is provided (0), then a standard titlecase break iterator is opened. Otherwise the provided iterator is set to the string's text.
localeThe locale to consider.
Returns
A reference to this.
Stable:
ICU 2.1

◆ toTitle()[3/3]

UnicodeString& icu::UnicodeString::toTitle(BreakIteratortitleIter,
constLocalelocale,
uint32_t options 
)

Titlecase this string, with options.

Casing is locale-dependent and context-sensitive. Titlecasing uses a break iterator to find the first characters of words that are to be titlecased. It titlecases those characters and lowercases all others. (This can be modified with options.)

The titlecase break iterator can be provided to customize for arbitrary styles, using rules and dictionaries beyond the standard iterators. It may be more efficient to always provide an iterator to avoid opening and closing one for each string. If the break iterator passed in is null, the default Unicode algorithm will be used to determine the titlecase positions.

This function uses only the setText(), first() and next() methods of the provided break iterator.

Parameters
titleIterA break iterator to find the first characters of words that are to be titlecased. If none is provided (0), then a standard titlecase break iterator is opened. Otherwise the provided iterator is set to the string's text.
localeThe locale to consider.
optionsOptions bit set, usually 0. See U_TITLECASE_NO_LOWERCASE, U_TITLECASE_NO_BREAK_ADJUSTMENT, U_TITLECASE_ADJUST_TO_CASED, U_TITLECASE_WHOLE_STRING, U_TITLECASE_SENTENCES.
Returns
A reference to this.
Stable:
ICU 3.8

◆ toUpper()[1/2]

UnicodeString& icu::UnicodeString::toUpper()

Convert the characters in this to UPPER CASE following the conventions of the default locale.

Returns
A reference to this.
Stable:
ICU 2.0

◆ toUpper()[2/2]

UnicodeString& icu::UnicodeString::toUpper(constLocalelocale)

Convert the characters in this to UPPER CASE following the conventions of a specific locale.

Parameters
localeThe locale containing the conventions to use.
Returns
A reference to this.
Stable:
ICU 2.0

◆ toUTF32()

int32_t icu::UnicodeString::toUTF32(UChar32utf32,
int32_t capacity,
UErrorCodeerrorCode 
) const

Convert theUnicodeString to UTF-32.

Unpaired surrogates are replaced with U+FFFD. Callsu_strToUTF32WithSub().

Parameters
utf32destination string buffer, can be nullptr if capacity==0
capacitythe number of UChar32s available at utf32
errorCodeStandard ICU error code. Its input value must pass theU_SUCCESS() test, or else the function returns immediately. Check forU_FAILURE() on output or use with function chaining. (See User Guide for details.)
Returns
The length of the UTF-32 string.
See also
fromUTF32
Stable:
ICU 4.2

◆ toUTF8()

void icu::UnicodeString::toUTF8(ByteSinksink) const

Convert theUnicodeString to UTF-8 and write the result to aByteSink.

This is called bytoUTF8String(). Unpaired surrogates are replaced with U+FFFD. Callsu_strToUTF8WithSub().

Parameters
sinkAByteSink to which the UTF-8 version of the string is written. sink.Flush() is called at the end.
Stable:
ICU 4.2
See also
toUTF8String

◆ toUTF8String()

template<typename StringClass >
StringClass& icu::UnicodeString::toUTF8String(StringClass & result) const
inline

Convert theUnicodeString to UTF-8 and append the result to a standard string.

Unpaired surrogates are replaced with U+FFFD. CallstoUTF8().

Parameters
resultA standard string (or a compatible object) to which the UTF-8 version of the string is appended.
Returns
The string object.
Stable:
ICU 4.2
See also
toUTF8

Definition at line1777 of fileunistr.h.

Referencesicu::Replaceable::length().

◆ trim()

UnicodeString& icu::UnicodeString::trim()

Trims leading and trailing whitespace from thisUnicodeString.

Returns
a reference to this
Stable:
ICU 2.0

◆ truncate()

UBool icu::UnicodeString::truncate(int32_t targetLength)
inline

Truncate thisUnicodeString to thetargetLength.

Parameters
targetLengththe desired length of thisUnicodeString.
Returns
true if the text was truncated, false otherwise
Stable:
ICU 2.0

Definition at line5068 of fileunistr.h.

Referenced byicu::Transliterator::setID().

◆ unescape()

UnicodeString icu::UnicodeString::unescape() const

Unescape a string of characters and return a string containing the result.

The following escape sequences are recognized:

\uhhhh 4 hex digits; h in [0-9A-Fa-f] \Uhhhhhhhh 8 hex digits \xhh 1-2 hex digits \ooo 1-3 octal digits; o in [0-7] \cX control-X; X is masked with 0x1F

as well as the standard ANSI C escapes:

\a => U+0007, \b => U+0008, \t => U+0009, \n => U+000A, \v => U+000B, \f => U+000C, \r => U+000D, \e => U+001B, \" => U+0022, \' => U+0027, \? => U+003F, \\ => U+005C

Anything else following a backslash is generically escaped. For example, "[a\\-z]" returns "[a-z]".

If an escape sequence is ill-formed, this method returns an empty string. An example of an ill-formed sequence is "\\u" followed by fewer than 4 hex digits.

This function is similar tou_unescape() but not identical to it. The latter takes a source char*, so it does escape recognition and also invariant conversion.

Returns
a string with backslash escapes interpreted, or an empty string on error.
See also
UnicodeString::unescapeAt()
u_unescape()
u_unescapeAt()
Stable:
ICU 2.0

◆ unescapeAt()

UChar32 icu::UnicodeString::unescapeAt(int32_t & offset) const

Unescape a single escape sequence and return the represented character.

Seeunescape() for a listing of the recognized escape sequences. The character at offset-1 is assumed (without checking) to be a backslash. If the escape sequence is ill-formed, or the offset is out of range, U_SENTINEL=-1 is returned.

Parameters
offsetan input output parameter. On input, it is the offset into this string where the escape sequence is located, after the initial backslash. On output, it is advanced after the last character parsed. On error, it is not advanced at all.
Returns
the character represented by the escape sequence at offset, or U_SENTINEL=-1 on error.
See also
UnicodeString::unescape()
u_unescape()
u_unescapeAt()
Stable:
ICU 2.0

Friends And Related Function Documentation

◆ swap

void swap(UnicodeStrings1,
UnicodeStrings2 
)
friend

Non-memberUnicodeString swap function.

Parameters
s1will get s2's contents and state
s2will get s1's contents and state
Stable:
ICU 56

Definition at line1990 of fileunistr.h.


The documentation for this class was generated from the following file:

Generated by doxygen 1.9.1
[8]ページ先頭

©2009-2025 Movatter.jp