Logo Search packages:      
Sourcecode: icu version File versions  Download package

UnicodeString Class Reference

#include <unistr.h>

Inheritance diagram for UnicodeString:
Collaboration diagram for UnicodeString:

List of all members.

Classes

union  StackBufferOrFields

Public Types

enum  EInvariant { kInvariant }

Public Member Functions

UnicodeStringappend (const UnicodeString &srcText, int32_t srcStart, int32_t srcLength)
UnicodeStringappend (const UnicodeString &srcText)
UnicodeStringappend (const UChar *srcChars, int32_t srcStart, int32_t srcLength)
UnicodeStringappend (const UChar *srcChars, int32_t srcLength)
UnicodeStringappend (UChar srcChar)
UnicodeStringappend (UChar32 srcChar)
int8_t caseCompare (const UnicodeString &text, uint32_t options) const
int8_t caseCompare (int32_t start, int32_t length, const UnicodeString &srcText, uint32_t options) const
int8_t caseCompare (int32_t start, int32_t length, const UnicodeString &srcText, int32_t srcStart, int32_t srcLength, uint32_t options) const
int8_t caseCompare (const UChar *srcChars, int32_t srcLength, uint32_t options) const
int8_t caseCompare (int32_t start, int32_t length, const UChar *srcChars, uint32_t options) const
int8_t caseCompare (int32_t start, int32_t length, const UChar *srcChars, int32_t srcStart, int32_t srcLength, uint32_t options) const
int8_t caseCompareBetween (int32_t start, int32_t limit, const UnicodeString &srcText, int32_t srcStart, int32_t srcLimit, uint32_t options) const
UChar32 char32At (int32_t offset) const
UChar charAt (int32_t offset) const
virtual Replaceableclone () const
int8_t compare (const UnicodeString &text) const
int8_t compare (int32_t start, int32_t length, const UnicodeString &text) const
int8_t compare (int32_t start, int32_t length, const UnicodeString &srcText, int32_t srcStart, int32_t srcLength) const
int8_t compare (const UChar *srcChars, int32_t srcLength) const
int8_t compare (int32_t start, int32_t length, const UChar *srcChars) const
int8_t compare (int32_t start, int32_t length, const UChar *srcChars, int32_t srcStart, int32_t srcLength) const
int8_t compareBetween (int32_t start, int32_t limit, const UnicodeString &srcText, int32_t srcStart, int32_t srcLimit) const
int8_t compareCodePointOrder (const UnicodeString &text) const
int8_t compareCodePointOrder (int32_t start, int32_t length, const UnicodeString &srcText) const
int8_t compareCodePointOrder (int32_t start, int32_t length, const UnicodeString &srcText, int32_t srcStart, int32_t srcLength) const
int8_t compareCodePointOrder (const UChar *srcChars, int32_t srcLength) const
int8_t compareCodePointOrder (int32_t start, int32_t length, const UChar *srcChars) const
int8_t compareCodePointOrder (int32_t start, int32_t length, const UChar *srcChars, int32_t srcStart, int32_t srcLength) const
int8_t compareCodePointOrderBetween (int32_t start, int32_t limit, const UnicodeString &srcText, int32_t srcStart, int32_t srcLimit) const
virtual void copy (int32_t start, int32_t limit, int32_t dest)
int32_t countChar32 (int32_t start=0, int32_t length=INT32_MAX) const
UBool endsWith (const UnicodeString &text) const
UBool endsWith (const UnicodeString &srcText, int32_t srcStart, int32_t srcLength) const
UBool endsWith (const UChar *srcChars, int32_t srcLength) const
UBool endsWith (const UChar *srcChars, int32_t srcStart, int32_t srcLength) const
void extract (int32_t start, int32_t length, UChar *dst, int32_t dstStart=0) const
int32_t extract (UChar *dest, int32_t destCapacity, UErrorCode &errorCode) const
void extract (int32_t start, int32_t length, UnicodeString &target) const
int32_t extract (int32_t start, int32_t startLength, char *target, int32_t targetCapacity, enum EInvariant inv) const
int32_t extract (int32_t start, int32_t startLength, char *target, uint32_t targetLength) const
int32_t extract (int32_t start, int32_t startLength, char *target, const char *codepage=0) const
int32_t extract (int32_t start, int32_t startLength, char *target, uint32_t targetLength, const char *codepage) const
int32_t extract (char *dest, int32_t destCapacity, UConverter *cnv, UErrorCode &errorCode) const
void extractBetween (int32_t start, int32_t limit, UChar *dst, int32_t dstStart=0) const
virtual void extractBetween (int32_t start, int32_t limit, UnicodeString &target) const
UnicodeStringfastCopyFrom (const UnicodeString &src)
UnicodeStringfindAndReplace (const UnicodeString &oldText, const UnicodeString &newText)
UnicodeStringfindAndReplace (int32_t start, int32_t length, const UnicodeString &oldText, const UnicodeString &newText)
UnicodeStringfindAndReplace (int32_t start, int32_t length, const UnicodeString &oldText, int32_t oldStart, int32_t oldLength, const UnicodeString &newText, int32_t newStart, int32_t newLength)
UnicodeStringfoldCase (uint32_t options=0)
UChargetBuffer (int32_t minCapacity)
const UChargetBuffer () const
int32_t getCapacity (void) const
int32_t getChar32Limit (int32_t offset) const
int32_t getChar32Start (int32_t offset) const
virtual UClassID getDynamicClassID () const
const UChargetTerminatedBuffer ()
virtual void handleReplaceBetween (int32_t start, int32_t limit, const UnicodeString &text)
int32_t hashCode (void) const
virtual UBool hasMetaData () const
UBool hasMoreChar32Than (int32_t start, int32_t length, int32_t number) const
int32_t indexOf (const UnicodeString &text) const
int32_t indexOf (const UnicodeString &text, int32_t start) const
int32_t indexOf (const UnicodeString &text, int32_t start, int32_t length) const
int32_t indexOf (const UnicodeString &srcText, int32_t srcStart, int32_t srcLength, int32_t start, int32_t length) const
int32_t indexOf (const UChar *srcChars, int32_t srcLength, int32_t start) const
int32_t indexOf (const UChar *srcChars, int32_t srcLength, int32_t start, int32_t length) const
int32_t indexOf (const UChar *srcChars, int32_t srcStart, int32_t srcLength, int32_t start, int32_t length) const
int32_t indexOf (UChar c) const
int32_t indexOf (UChar32 c) const
int32_t indexOf (UChar c, int32_t start) const
int32_t indexOf (UChar32 c, int32_t start) const
int32_t indexOf (UChar c, int32_t start, int32_t length) const
int32_t indexOf (UChar32 c, int32_t start, int32_t length) const
UnicodeStringinsert (int32_t start, const UnicodeString &srcText, int32_t srcStart, int32_t srcLength)
UnicodeStringinsert (int32_t start, const UnicodeString &srcText)
UnicodeStringinsert (int32_t start, const UChar *srcChars, int32_t srcStart, int32_t srcLength)
UnicodeStringinsert (int32_t start, const UChar *srcChars, int32_t srcLength)
UnicodeStringinsert (int32_t start, UChar srcChar)
UnicodeStringinsert (int32_t start, UChar32 srcChar)
UBool isBogus (void) const
UBool isEmpty (void) const
int32_t lastIndexOf (const UnicodeString &text) const
int32_t lastIndexOf (const UnicodeString &text, int32_t start) const
int32_t lastIndexOf (const UnicodeString &text, int32_t start, int32_t length) const
int32_t lastIndexOf (const UnicodeString &srcText, int32_t srcStart, int32_t srcLength, int32_t start, int32_t length) const
int32_t lastIndexOf (const UChar *srcChars, int32_t srcLength, int32_t start) const
int32_t lastIndexOf (const UChar *srcChars, int32_t srcLength, int32_t start, int32_t length) const
int32_t lastIndexOf (const UChar *srcChars, int32_t srcStart, int32_t srcLength, int32_t start, int32_t length) const
int32_t lastIndexOf (UChar c) const
int32_t lastIndexOf (UChar32 c) const
int32_t lastIndexOf (UChar c, int32_t start) const
int32_t lastIndexOf (UChar32 c, int32_t start) const
int32_t lastIndexOf (UChar c, int32_t start, int32_t length) const
int32_t lastIndexOf (UChar32 c, int32_t start, int32_t length) const
int32_t length (void) const
int32_t moveIndex32 (int32_t index, int32_t delta) const
UBool operator!= (const UnicodeString &text) const
UnicodeStringoperator+= (UChar ch)
UnicodeStringoperator+= (UChar32 ch)
UnicodeStringoperator+= (const UnicodeString &srcText)
UBool operator< (const UnicodeString &text) const
UBool operator<= (const UnicodeString &text) const
UnicodeStringoperator= (const UnicodeString &srcText)
UnicodeStringoperator= (UChar ch)
UnicodeStringoperator= (UChar32 ch)
UBool operator== (const UnicodeString &text) const
UBool operator> (const UnicodeString &text) const
UBool operator>= (const UnicodeString &text) const
UChar operator[] (int32_t offset) const
UBool padLeading (int32_t targetLength, UChar padChar=0x0020)
UBool padTrailing (int32_t targetLength, UChar padChar=0x0020)
void releaseBuffer (int32_t newLength=-1)
UnicodeStringremove (void)
UnicodeStringremove (int32_t start, int32_t length=(int32_t) INT32_MAX)
UnicodeStringremoveBetween (int32_t start, int32_t limit=(int32_t) INT32_MAX)
UnicodeStringreplace (int32_t start, int32_t length, const UnicodeString &srcText, int32_t srcStart, int32_t srcLength)
UnicodeStringreplace (int32_t start, int32_t length, const UnicodeString &srcText)
UnicodeStringreplace (int32_t start, int32_t length, const UChar *srcChars, int32_t srcStart, int32_t srcLength)
UnicodeStringreplace (int32_t start, int32_t length, const UChar *srcChars, int32_t srcLength)
UnicodeStringreplace (int32_t start, int32_t length, UChar srcChar)
UnicodeStringreplace (int32_t start, int32_t length, UChar32 srcChar)
UnicodeStringreplaceBetween (int32_t start, int32_t limit, const UnicodeString &srcText)
UnicodeStringreplaceBetween (int32_t start, int32_t limit, const UnicodeString &srcText, int32_t srcStart, int32_t srcLimit)
UnicodeStringretainBetween (int32_t start, int32_t limit=INT32_MAX)
UnicodeStringreverse (void)
UnicodeStringreverse (int32_t start, int32_t length)
UnicodeStringsetCharAt (int32_t offset, UChar ch)
UnicodeStringsetTo (const UnicodeString &srcText, int32_t srcStart)
UnicodeStringsetTo (const UnicodeString &srcText, int32_t srcStart, int32_t srcLength)
UnicodeStringsetTo (const UnicodeString &srcText)
UnicodeStringsetTo (const UChar *srcChars, int32_t srcLength)
UnicodeStringsetTo (UChar srcChar)
UnicodeStringsetTo (UChar32 srcChar)
UnicodeStringsetTo (UBool isTerminated, const UChar *text, int32_t textLength)
UnicodeStringsetTo (UChar *buffer, int32_t buffLength, int32_t buffCapacity)
void setToBogus ()
UBool startsWith (const UnicodeString &text) const
UBool startsWith (const UnicodeString &srcText, int32_t srcStart, int32_t srcLength) const
UBool startsWith (const UChar *srcChars, int32_t srcLength) const
UBool startsWith (const UChar *srcChars, int32_t srcStart, int32_t srcLength) const
UnicodeString tempSubString (int32_t start=0, int32_t length=INT32_MAX) const
UnicodeString tempSubStringBetween (int32_t start, int32_t limit=INT32_MAX) const
UnicodeStringtoLower (void)
UnicodeStringtoLower (const Locale &locale)
UnicodeStringtoTitle (BreakIterator *titleIter)
UnicodeStringtoTitle (BreakIterator *titleIter, const Locale &locale)
UnicodeStringtoTitle (BreakIterator *titleIter, const Locale &locale, uint32_t options)
UnicodeStringtoUpper (void)
UnicodeStringtoUpper (const Locale &locale)
int32_t toUTF32 (UChar32 *utf32, int32_t capacity, UErrorCode &errorCode) const
void toUTF8 (ByteSink &sink) const
UnicodeStringtrim (void)
UBool truncate (int32_t targetLength)
UnicodeString unescape () const
UChar32 unescapeAt (int32_t &offset) const
 UnicodeString ()
 UnicodeString (int32_t capacity, UChar32 c, int32_t count)
 UnicodeString (UChar ch)
 UnicodeString (UChar32 ch)
 UnicodeString (const UChar *text)
 UnicodeString (const UChar *text, int32_t textLength)
 UnicodeString (UBool isTerminated, const UChar *text, int32_t textLength)
 UnicodeString (UChar *buffer, int32_t buffLength, int32_t buffCapacity)
 UnicodeString (const char *codepageData)
 UnicodeString (const char *codepageData, int32_t dataLength)
 UnicodeString (const char *codepageData, const char *codepage)
 UnicodeString (const char *codepageData, int32_t dataLength, const char *codepage)
 UnicodeString (const char *src, int32_t srcLength, UConverter *cnv, UErrorCode &errorCode)
 UnicodeString (const char *src, int32_t length, enum EInvariant inv)
 UnicodeString (const UnicodeString &that)
 UnicodeString (const UnicodeString &src, int32_t srcStart)
 UnicodeString (const UnicodeString &src, int32_t srcStart, int32_t srcLength)
virtual ~UnicodeString ()

Static Public Member Functions

static UnicodeString fromUTF32 (const UChar32 *utf32, int32_t length)
static UnicodeString fromUTF8 (const StringPiece &utf8)
static UClassID U_EXPORT2 getStaticClassID ()
static void U_EXPORT2 operator delete (void *p) U_NO_THROW
static void U_EXPORT2 operator delete (void *, void *) U_NO_THROW
static void U_EXPORT2 operator delete[] (void *p) U_NO_THROW
static void *U_EXPORT2 operator new (size_t size) U_NO_THROW
static void *U_EXPORT2 operator new (size_t, void *ptr) U_NO_THROW
static void *U_EXPORT2 operator new[] (size_t size) U_NO_THROW

Protected Member Functions

virtual UChar32 getChar32At (int32_t offset) const
virtual UChar getCharAt (int32_t offset) const
virtual int32_t getLength () const

Private Types

enum  {
  US_STACKBUF_SIZE = sizeof(void *)==4 ? 13 : 15, kInvalidUChar = 0xffff, kGrowSize = 128, kInvalidHashCode = 0,
  kEmptyHashCode = 1, kIsBogus = 1, kUsingStackBuffer = 2, kRefCounted = 4,
  kBufferIsReadonly = 8, kOpenGetBuffer = 16, kShortString = kUsingStackBuffer, kLongString = kRefCounted,
  kReadonlyAlias = kBufferIsReadonly, kWritableAlias = 0
}

Private Member Functions

void addRef (void)
UBool allocate (int32_t capacity)
UnicodeStringcaseMap (BreakIterator *titleIter, const char *locale, uint32_t options, int32_t toWhichCase)
UBool cloneArrayIfNeeded (int32_t newCapacity=-1, int32_t growCapacity=-1, UBool doCopyArray=TRUE, int32_t **pBufferToDelete=0, UBool forceClone=FALSE)
UnicodeStringcopyFrom (const UnicodeString &src, UBool fastCopy=FALSE)
int8_t doCaseCompare (int32_t start, int32_t length, const UnicodeString &srcText, int32_t srcStart, int32_t srcLength, uint32_t options) const
int8_t doCaseCompare (int32_t start, int32_t length, const UChar *srcChars, int32_t srcStart, int32_t srcLength, uint32_t options) const
UChar doCharAt (int32_t offset) const
void doCodepageCreate (const char *codepageData, int32_t dataLength, const char *codepage)
void doCodepageCreate (const char *codepageData, int32_t dataLength, UConverter *converter, UErrorCode &status)
int8_t doCompare (int32_t start, int32_t length, const UnicodeString &srcText, int32_t srcStart, int32_t srcLength) const
int8_t doCompare (int32_t start, int32_t length, const UChar *srcChars, int32_t srcStart, int32_t srcLength) const
int8_t doCompareCodePointOrder (int32_t start, int32_t length, const UnicodeString &srcText, int32_t srcStart, int32_t srcLength) const
int8_t doCompareCodePointOrder (int32_t start, int32_t length, const UChar *srcChars, int32_t srcStart, int32_t srcLength) const
void doExtract (int32_t start, int32_t length, UChar *dst, int32_t dstStart) const
void doExtract (int32_t start, int32_t length, UnicodeString &target) const
int32_t doExtract (int32_t start, int32_t length, char *dest, int32_t destCapacity, UConverter *cnv, UErrorCode &errorCode) const
int32_t doHashCode (void) const
int32_t doIndexOf (UChar c, int32_t start, int32_t length) const
int32_t doIndexOf (UChar32 c, int32_t start, int32_t length) const
int32_t doLastIndexOf (UChar c, int32_t start, int32_t length) const
int32_t doLastIndexOf (UChar32 c, int32_t start, int32_t length) const
UnicodeStringdoReplace (int32_t start, int32_t length, const UnicodeString &srcText, int32_t srcStart, int32_t srcLength)
UnicodeStringdoReplace (int32_t start, int32_t length, const UChar *srcChars, int32_t srcStart, int32_t srcLength)
UnicodeStringdoReverse (int32_t start, int32_t length)
UChargetArrayStart (void)
const UChargetArrayStart (void) const
UBool isBufferWritable () const
UBool isWritable () const
void pinIndex (int32_t &start) const
void pinIndices (int32_t &start, int32_t &length) const
int32_t refCount (void) const
void releaseArray (void)
int32_t removeRef (void)
void setArray (UChar *array, int32_t len, int32_t capacity)
void setLength (int32_t len)
void setToEmpty ()
UnicodeStringsetToUTF8 (const StringPiece &utf8)
int32_t toUTF8 (int32_t start, int32_t len, char *target, int32_t capacity) const
void unBogus ()

Private Attributes

uint8_t fFlags
UChar fRestOfStackBuffer [US_STACKBUF_SIZE-8]
int8_t fShortLength
union
UnicodeString::StackBufferOrFields 
fUnion

Friends

union StackBufferOrFields
class StringThreadTest
class UnicodeStringAppendable

Detailed Description

UnicodeString is a string class that stores Unicode characters directly and provides similar functionality as the Java String and StringBuffer classes. It is a concrete implementation of the abstract class Replaceable (for transliteration).

The UnicodeString class is not suitable for subclassing.

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

In ICU, a Unicode string consists of 16-bit Unicode code 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 UChar. For single-character handling, a Unicode character code point 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 like UnicodeString::getChar32Start() and UnicodeString::getChar32Limit() (or, in C, the equivalent macros U16_SET_CP_START() and U16_SET_CP_LIMIT(), see utf.h).

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

  • If indexes are out of bounds for a UnicodeString object (<0 or >length()) then they are "pinned" to the nearest boundary.
  • If primitive string pointer values (e.g., const UChar * or char *) for input strings are NULL, then those input string parameters are treated as if they pointed to an empty string. However, this is not the case for char * parameters for charset names or other IDs.
  • Most UnicodeString methods do not take a UErrorCode parameter because there are usually very few opportunities for failure other than a shortage of memory, error codes in low-level C++ string methods would be inconvenient, and the error code as the last parameter (ICU convention) would prevent the use of default parameter values. Instead, such methods set the UnicodeString into a "bogus" state (see isBogus()) if an error occurs.

In string comparisons, two UnicodeString 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.

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

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

UnicodeString uses several storage methods. String contents can be stored inside the UnicodeString 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 the User Guide Strings chapter.

See also:
utf.h
CharacterIterator ICU 2.0

Definition at line 188 of file unistr.h.


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

Generated by  Doxygen 1.6.0   Back to index