unistr.h
Go to the documentation of this file.
// © 2016 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
/*
**********************************************************************
* Copyright (C) 1998-2016, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
*
* File unistr.h
*
* Modification History:
*
* Date Name Description
* 09/25/98 stephen Creation.
* 11/11/98 stephen Changed per 11/9 code review.
* 04/20/99 stephen Overhauled per 4/16 code review.
* 11/18/99 aliu Made to inherit from Replaceable. Added method
* handleReplaceBetween(); other methods unchanged.
* 06/25/01 grhoten Remove dependency on iostream.
******************************************************************************
*/
#ifndef UNISTR_H
#define UNISTR_H
#include "unicode/utypes.h"
#if U_SHOW_CPLUSPLUS_API
#include <cstddef>
#include "unicode/char16ptr.h"
#include "unicode/rep.h"
#include "unicode/std_string.h"
#include "unicode/stringpiece.h"
#include "unicode/bytestream.h"
struct UConverter; // unicode/ucnv.h
#ifndef USTRING_H
U_CAPI int32_t U_EXPORT2 u_strlen(const UChar *s);
#endif
U_NAMESPACE_BEGIN
#if !UCONFIG_NO_BREAK_ITERATION
class BreakIterator; // unicode/brkiter.h
#endif
class Edits;
U_NAMESPACE_END
// Not #ifndef U_HIDE_INTERNAL_API because UnicodeString needs the UStringCaseMapper.
typedef int32_t U_CALLCONV
UStringCaseMapper(int32_t caseLocale, uint32_t options,
#if !UCONFIG_NO_BREAK_ITERATION
icu::BreakIterator *iter,
#endif
char16_t *dest, int32_t destCapacity,
const char16_t *src, int32_t srcLength,
icu::Edits *edits,
UErrorCode &errorCode);
U_NAMESPACE_BEGIN
class Locale; // unicode/locid.h
class StringCharacterIterator;
class UnicodeStringAppendable; // unicode/appendable.h
/* The <iostream> include has been moved to unicode/ustream.h */
#define US_INV icu::UnicodeString::kInvariant
#if !U_CHAR16_IS_TYPEDEF
# define UNICODE_STRING(cs, _length) icu::UnicodeString(true, u ## cs, _length)
#else
# define UNICODE_STRING(cs, _length) icu::UnicodeString(true, (const char16_t*)u ## cs, _length)
#endif
#define UNICODE_STRING_SIMPLE(cs) UNICODE_STRING(cs, -1)
#ifndef UNISTR_FROM_CHAR_EXPLICIT
# if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION)
// Auto-"explicit" in ICU library code.
# define UNISTR_FROM_CHAR_EXPLICIT explicit
# else
// Empty by default for source code compatibility.
# define UNISTR_FROM_CHAR_EXPLICIT
# endif
#endif
#ifndef UNISTR_FROM_STRING_EXPLICIT
# if defined(U_COMBINED_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) || defined(U_I18N_IMPLEMENTATION) || defined(U_IO_IMPLEMENTATION)
// Auto-"explicit" in ICU library code.
# define UNISTR_FROM_STRING_EXPLICIT explicit
# else
// Empty by default for source code compatibility.
# define UNISTR_FROM_STRING_EXPLICIT
# endif
#endif
#ifndef UNISTR_OBJECT_SIZE
# define UNISTR_OBJECT_SIZE 64
#endif
class U_COMMON_API UnicodeString : public Replaceable
{
public:
enum EInvariant {
kInvariant
};
//========================================
// Read-only operations
//========================================
/* Comparison - bitwise only - for international comparison use collation */
inline bool operator== (const UnicodeString& text) const;
inline bool operator!= (const UnicodeString& text) const;
inline UBool operator> (const UnicodeString& text) const;
inline UBool operator< (const UnicodeString& text) const;
inline UBool operator>= (const UnicodeString& text) const;
inline UBool operator<= (const UnicodeString& text) const;
inline int8_t compare(const UnicodeString& text) const;
inline int8_t compare(int32_t start,
int32_t length,
const UnicodeString& text) const;
inline int8_t compare(int32_t start,
int32_t length,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength) const;
inline int8_t compare(ConstChar16Ptr srcChars,
int32_t srcLength) const;
inline int8_t compare(int32_t start,
int32_t length,
const char16_t *srcChars) const;
inline int8_t compare(int32_t start,
int32_t length,
const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength) const;
inline int8_t compareBetween(int32_t start,
int32_t limit,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLimit) const;
inline int8_t compareCodePointOrder(const UnicodeString& text) const;
inline int8_t compareCodePointOrder(int32_t start,
int32_t length,
const UnicodeString& srcText) const;
inline int8_t compareCodePointOrder(int32_t start,
int32_t length,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength) const;
inline int8_t compareCodePointOrder(ConstChar16Ptr srcChars,
int32_t srcLength) const;
inline int8_t compareCodePointOrder(int32_t start,
int32_t length,
const char16_t *srcChars) const;
inline int8_t compareCodePointOrder(int32_t start,
int32_t length,
const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength) const;
inline int8_t compareCodePointOrderBetween(int32_t start,
int32_t limit,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLimit) const;
inline int8_t caseCompare(const UnicodeString& text, uint32_t options) const;
inline int8_t caseCompare(int32_t start,
int32_t length,
const UnicodeString& srcText,
uint32_t options) const;
inline int8_t caseCompare(int32_t start,
int32_t length,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength,
uint32_t options) const;
inline int8_t caseCompare(ConstChar16Ptr srcChars,
int32_t srcLength,
uint32_t options) const;
inline int8_t caseCompare(int32_t start,
int32_t length,
const char16_t *srcChars,
uint32_t options) const;
inline int8_t caseCompare(int32_t start,
int32_t length,
const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength,
uint32_t options) const;
inline int8_t caseCompareBetween(int32_t start,
int32_t limit,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLimit,
uint32_t options) const;
inline UBool startsWith(const UnicodeString& text) const;
inline UBool startsWith(const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength) const;
inline UBool startsWith(ConstChar16Ptr srcChars,
int32_t srcLength) const;
inline UBool startsWith(const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength) const;
inline UBool endsWith(const UnicodeString& text) const;
inline UBool endsWith(const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength) const;
inline UBool endsWith(ConstChar16Ptr srcChars,
int32_t srcLength) const;
inline UBool endsWith(const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength) const;
/* Searching - bitwise only */
inline int32_t indexOf(const UnicodeString& text) const;
inline int32_t indexOf(const UnicodeString& text,
int32_t start) const;
inline int32_t indexOf(const UnicodeString& text,
int32_t start,
int32_t length) const;
inline int32_t indexOf(const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength,
int32_t start,
int32_t length) const;
inline int32_t indexOf(const char16_t *srcChars,
int32_t srcLength,
int32_t start) const;
inline int32_t indexOf(ConstChar16Ptr srcChars,
int32_t srcLength,
int32_t start,
int32_t length) const;
int32_t indexOf(const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength,
int32_t start,
int32_t length) const;
inline int32_t indexOf(char16_t c) const;
inline int32_t indexOf(UChar32 c) const;
inline int32_t indexOf(char16_t c,
int32_t start) const;
inline int32_t indexOf(UChar32 c,
int32_t start) const;
inline int32_t indexOf(char16_t c,
int32_t start,
int32_t length) const;
inline int32_t indexOf(UChar32 c,
int32_t start,
int32_t length) const;
inline int32_t lastIndexOf(const UnicodeString& text) const;
inline int32_t lastIndexOf(const UnicodeString& text,
int32_t start) const;
inline int32_t lastIndexOf(const UnicodeString& text,
int32_t start,
int32_t length) const;
inline int32_t lastIndexOf(const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength,
int32_t start,
int32_t length) const;
inline int32_t lastIndexOf(const char16_t *srcChars,
int32_t srcLength,
int32_t start) const;
inline int32_t lastIndexOf(ConstChar16Ptr srcChars,
int32_t srcLength,
int32_t start,
int32_t length) const;
int32_t lastIndexOf(const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength,
int32_t start,
int32_t length) const;
inline int32_t lastIndexOf(char16_t c) const;
inline int32_t lastIndexOf(UChar32 c) const;
inline int32_t lastIndexOf(char16_t c,
int32_t start) const;
inline int32_t lastIndexOf(UChar32 c,
int32_t start) const;
inline int32_t lastIndexOf(char16_t c,
int32_t start,
int32_t length) const;
inline int32_t lastIndexOf(UChar32 c,
int32_t start,
int32_t length) const;
/* Character access */
inline char16_t charAt(int32_t offset) const;
inline char16_t operator[] (int32_t offset) const;
UChar32 char32At(int32_t offset) const;
int32_t getChar32Start(int32_t offset) const;
int32_t getChar32Limit(int32_t offset) const;
int32_t moveIndex32(int32_t index, int32_t delta) const;
/* Substring extraction */
inline void extract(int32_t start,
int32_t length,
Char16Ptr dst,
int32_t dstStart = 0) const;
int32_t
extract(Char16Ptr dest, int32_t destCapacity,
UErrorCode &errorCode) const;
inline void extract(int32_t start,
int32_t length,
UnicodeString& target) const;
inline void extractBetween(int32_t start,
int32_t limit,
char16_t *dst,
int32_t dstStart = 0) const;
virtual void extractBetween(int32_t start,
int32_t limit,
UnicodeString& target) const override;
int32_t extract(int32_t start,
int32_t startLength,
char *target,
int32_t targetCapacity,
enum EInvariant inv) const;
#if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
int32_t extract(int32_t start,
int32_t startLength,
char *target,
uint32_t targetLength) const;
#endif
#if !UCONFIG_NO_CONVERSION
inline 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;
#endif
UnicodeString tempSubString(int32_t start=0, int32_t length=INT32_MAX) const;
inline UnicodeString tempSubStringBetween(int32_t start, int32_t limit=INT32_MAX) const;
void toUTF8(ByteSink &sink) const;
template<typename StringClass>
StringClass &toUTF8String(StringClass &result) const {
StringByteSink<StringClass> sbs(&result, length());
toUTF8(sbs);
return result;
}
int32_t toUTF32(UChar32 *utf32, int32_t capacity, UErrorCode &errorCode) const;
/* Length operations */
inline int32_t length(void) const;
int32_t
countChar32(int32_t start=0, int32_t length=INT32_MAX) const;
UBool
hasMoreChar32Than(int32_t start, int32_t length, int32_t number) const;
inline UBool isEmpty(void) const;
inline int32_t getCapacity(void) const;
/* Other operations */
inline int32_t hashCode(void) const;
inline UBool isBogus(void) const;
//========================================
// Write operations
//========================================
/* Assignment operations */
UnicodeString &operator=(const UnicodeString &srcText);
UnicodeString &fastCopyFrom(const UnicodeString &src);
UnicodeString &operator=(UnicodeString &&src) noexcept;
void swap(UnicodeString &other) noexcept;
friend inline void U_EXPORT2
swap(UnicodeString &s1, UnicodeString &s2) noexcept {
s1.swap(s2);
}
inline UnicodeString& operator= (char16_t ch);
inline UnicodeString& operator= (UChar32 ch);
inline UnicodeString& setTo(const UnicodeString& srcText,
int32_t srcStart);
inline UnicodeString& setTo(const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength);
inline UnicodeString& setTo(const UnicodeString& srcText);
inline UnicodeString& setTo(const char16_t *srcChars,
int32_t srcLength);
inline UnicodeString& setTo(char16_t srcChar);
inline UnicodeString& setTo(UChar32 srcChar);
UnicodeString &setTo(UBool isTerminated,
ConstChar16Ptr text,
int32_t textLength);
UnicodeString &setTo(char16_t *buffer,
int32_t buffLength,
int32_t buffCapacity);
void setToBogus();
UnicodeString& setCharAt(int32_t offset,
char16_t ch);
/* Append operations */
inline UnicodeString& operator+= (char16_t ch);
inline UnicodeString& operator+= (UChar32 ch);
inline UnicodeString& operator+= (const UnicodeString& srcText);
inline UnicodeString& append(const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength);
inline UnicodeString& append(const UnicodeString& srcText);
inline UnicodeString& append(const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength);
inline UnicodeString& append(ConstChar16Ptr srcChars,
int32_t srcLength);
inline UnicodeString& append(char16_t srcChar);
UnicodeString& append(UChar32 srcChar);
/* Insert operations */
inline UnicodeString& insert(int32_t start,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength);
inline UnicodeString& insert(int32_t start,
const UnicodeString& srcText);
inline UnicodeString& insert(int32_t start,
const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength);
inline UnicodeString& insert(int32_t start,
ConstChar16Ptr srcChars,
int32_t srcLength);
inline UnicodeString& insert(int32_t start,
char16_t srcChar);
inline UnicodeString& insert(int32_t start,
UChar32 srcChar);
/* Replace operations */
inline UnicodeString& replace(int32_t start,
int32_t length,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength);
inline UnicodeString& replace(int32_t start,
int32_t length,
const UnicodeString& srcText);
inline UnicodeString& replace(int32_t start,
int32_t length,
const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength);
inline UnicodeString& replace(int32_t start,
int32_t length,
ConstChar16Ptr srcChars,
int32_t srcLength);
inline UnicodeString& replace(int32_t start,
int32_t length,
char16_t srcChar);
UnicodeString& replace(int32_t start, int32_t length, UChar32 srcChar);
inline UnicodeString& replaceBetween(int32_t start,
int32_t limit,
const UnicodeString& srcText);
inline UnicodeString& replaceBetween(int32_t start,
int32_t limit,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLimit);
virtual void handleReplaceBetween(int32_t start,
int32_t limit,
const UnicodeString& text) override;
virtual UBool hasMetaData() const override;
virtual void copy(int32_t start, int32_t limit, int32_t dest) override;
/* Search and replace operations */
inline UnicodeString& findAndReplace(const UnicodeString& oldText,
const UnicodeString& newText);
inline UnicodeString& findAndReplace(int32_t start,
int32_t length,
const UnicodeString& oldText,
const UnicodeString& newText);
UnicodeString& findAndReplace(int32_t start,
int32_t length,
const UnicodeString& oldText,
int32_t oldStart,
int32_t oldLength,
const UnicodeString& newText,
int32_t newStart,
int32_t newLength);
/* Remove operations */
inline UnicodeString& remove();
inline UnicodeString& remove(int32_t start,
int32_t length = (int32_t)INT32_MAX);
inline UnicodeString& removeBetween(int32_t start,
int32_t limit = (int32_t)INT32_MAX);
inline UnicodeString &retainBetween(int32_t start, int32_t limit = INT32_MAX);
/* Length operations */
UBool padLeading(int32_t targetLength,
char16_t padChar = 0x0020);
UBool padTrailing(int32_t targetLength,
char16_t padChar = 0x0020);
inline UBool truncate(int32_t targetLength);
UnicodeString& trim(void);
/* Miscellaneous operations */
inline UnicodeString& reverse(void);
inline UnicodeString& reverse(int32_t start,
int32_t length);
UnicodeString& toUpper(void);
UnicodeString& toUpper(const Locale& locale);
UnicodeString& toLower(void);
UnicodeString& toLower(const Locale& locale);
#if !UCONFIG_NO_BREAK_ITERATION
UnicodeString &toTitle(BreakIterator *titleIter);
UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale);
UnicodeString &toTitle(BreakIterator *titleIter, const Locale &locale, uint32_t options);
#endif
UnicodeString &foldCase(uint32_t options=0 /*U_FOLD_CASE_DEFAULT*/);
//========================================
// Access to the internal buffer
//========================================
char16_t *getBuffer(int32_t minCapacity);
void releaseBuffer(int32_t newLength=-1);
inline const char16_t *getBuffer() const;
const char16_t *getTerminatedBuffer();
//========================================
// Constructors
//========================================
inline UnicodeString();
UnicodeString(int32_t capacity, UChar32 c, int32_t count);
UNISTR_FROM_CHAR_EXPLICIT UnicodeString(char16_t ch);
UNISTR_FROM_CHAR_EXPLICIT UnicodeString(UChar32 ch);
UNISTR_FROM_STRING_EXPLICIT UnicodeString(const char16_t *text);
#if !U_CHAR16_IS_TYPEDEF
UNISTR_FROM_STRING_EXPLICIT UnicodeString(const uint16_t *text) :
UnicodeString(ConstChar16Ptr(text)) {}
#endif
#if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
UNISTR_FROM_STRING_EXPLICIT UnicodeString(const wchar_t *text) :
UnicodeString(ConstChar16Ptr(text)) {}
#endif
UNISTR_FROM_STRING_EXPLICIT inline UnicodeString(const std::nullptr_t text);
UnicodeString(const char16_t *text,
int32_t textLength);
#if !U_CHAR16_IS_TYPEDEF
UnicodeString(const uint16_t *text, int32_t textLength) :
UnicodeString(ConstChar16Ptr(text), textLength) {}
#endif
#if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
UnicodeString(const wchar_t *text, int32_t textLength) :
UnicodeString(ConstChar16Ptr(text), textLength) {}
#endif
inline UnicodeString(const std::nullptr_t text, int32_t textLength);
UnicodeString(UBool isTerminated,
ConstChar16Ptr text,
int32_t textLength);
UnicodeString(char16_t *buffer, int32_t buffLength, int32_t buffCapacity);
#if !U_CHAR16_IS_TYPEDEF
UnicodeString(uint16_t *buffer, int32_t buffLength, int32_t buffCapacity) :
UnicodeString(Char16Ptr(buffer), buffLength, buffCapacity) {}
#endif
#if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
UnicodeString(wchar_t *buffer, int32_t buffLength, int32_t buffCapacity) :
UnicodeString(Char16Ptr(buffer), buffLength, buffCapacity) {}
#endif
inline UnicodeString(std::nullptr_t buffer, int32_t buffLength, int32_t buffCapacity);
#if U_CHARSET_IS_UTF8 || !UCONFIG_NO_CONVERSION
UNISTR_FROM_STRING_EXPLICIT UnicodeString(const char *codepageData);
UnicodeString(const char *codepageData, int32_t dataLength);
#endif
#if !UCONFIG_NO_CONVERSION
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);
#endif
UnicodeString(const char *src, int32_t textLength, enum EInvariant inv);
UnicodeString(const UnicodeString& that);
UnicodeString(UnicodeString &&src) noexcept;
UnicodeString(const UnicodeString& src, int32_t srcStart);
UnicodeString(const UnicodeString& src, int32_t srcStart, int32_t srcLength);
virtual UnicodeString *clone() const override;
virtual ~UnicodeString();
static UnicodeString fromUTF8(StringPiece utf8);
static UnicodeString fromUTF32(const UChar32 *utf32, int32_t length);
/* Miscellaneous operations */
UnicodeString unescape() const;
UChar32 unescapeAt(int32_t &offset) const;
static UClassID U_EXPORT2 getStaticClassID();
virtual UClassID getDynamicClassID() const override;
//========================================
// Implementation methods
//========================================
protected:
virtual int32_t getLength() const override;
virtual char16_t getCharAt(int32_t offset) const override;
virtual UChar32 getChar32At(int32_t offset) const override;
private:
// For char* constructors. Could be made public.
UnicodeString &setToUTF8(StringPiece utf8);
// For extract(char*).
// We could make a toUTF8(target, capacity, errorCode) public but not
// this version: New API will be cleaner if we make callers create substrings
// rather than having start+length on every method,
// and it should take a UErrorCode&.
int32_t
toUTF8(int32_t start, int32_t len,
char *target, int32_t capacity) const;
UBool doEquals(const UnicodeString &text, int32_t len) const;
inline UBool
doEqualsSubstring(int32_t start,
int32_t length,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength) const;
UBool doEqualsSubstring(int32_t start,
int32_t length,
const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength) const;
inline 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 char16_t *srcChars,
int32_t srcStart,
int32_t srcLength) const;
inline 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 char16_t *srcChars,
int32_t srcStart,
int32_t srcLength) const;
inline 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 char16_t *srcChars,
int32_t srcStart,
int32_t srcLength,
uint32_t options) const;
int32_t doIndexOf(char16_t c,
int32_t start,
int32_t length) const;
int32_t doIndexOf(UChar32 c,
int32_t start,
int32_t length) const;
int32_t doLastIndexOf(char16_t c,
int32_t start,
int32_t length) const;
int32_t doLastIndexOf(UChar32 c,
int32_t start,
int32_t length) const;
void doExtract(int32_t start,
int32_t length,
char16_t *dst,
int32_t dstStart) const;
inline void doExtract(int32_t start,
int32_t length,
UnicodeString& target) const;
inline char16_t doCharAt(int32_t offset) const;
UnicodeString& doReplace(int32_t start,
int32_t length,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength);
UnicodeString& doReplace(int32_t start,
int32_t length,
const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength);
UnicodeString& doAppend(const UnicodeString& src, int32_t srcStart, int32_t srcLength);
UnicodeString& doAppend(const char16_t *srcChars, int32_t srcStart, int32_t srcLength);
UnicodeString& doReverse(int32_t start,
int32_t length);
// calculate hash code
int32_t doHashCode(void) const;
// get pointer to start of array
// these do not check for kOpenGetBuffer, unlike the public getBuffer() function
inline char16_t* getArrayStart(void);
inline const char16_t* getArrayStart(void) const;
inline UBool hasShortLength() const;
inline int32_t getShortLength() const;
// A UnicodeString object (not necessarily its current buffer)
// is writable unless it isBogus() or it has an "open" getBuffer(minCapacity).
inline UBool isWritable() const;
// Is the current buffer writable?
inline UBool isBufferWritable() const;
// None of the following does releaseArray().
inline void setZeroLength();
inline void setShortLength(int32_t len);
inline void setLength(int32_t len);
inline void setToEmpty();
inline void setArray(char16_t *array, int32_t len, int32_t capacity); // sets length but not flags
// allocate the array; result may be the stack buffer
// sets refCount to 1 if appropriate
// sets fArray, fCapacity, and flags
// sets length to 0
// returns boolean for success or failure
UBool allocate(int32_t capacity);
// release the array if owned
void releaseArray(void);
// turn a bogus string into an empty one
void unBogus();
// implements assignment operator, copy constructor, and fastCopyFrom()
UnicodeString &copyFrom(const UnicodeString &src, UBool fastCopy=false);
// Copies just the fields without memory management.
void copyFieldsFrom(UnicodeString &src, UBool setSrcToBogus) noexcept;
// Pin start and limit to acceptable values.
inline void pinIndex(int32_t& start) const;
inline void pinIndices(int32_t& start,
int32_t& length) const;
#if !UCONFIG_NO_CONVERSION
/* Internal extract() using UConverter. */
int32_t doExtract(int32_t start, int32_t length,
char *dest, int32_t destCapacity,
UConverter *cnv,
UErrorCode &errorCode) const;
/*
* Real constructor for converting from codepage data.
* It assumes that it is called with !fRefCounted.
*
* If `codepage==0`, then the default converter
* is used for the platform encoding.
* If `codepage` is an empty string (`""`),
* then a simple conversion is performed on the codepage-invariant
* subset ("invariant characters") of the platform encoding. See utypes.h.
*/
void doCodepageCreate(const char *codepageData,
int32_t dataLength,
const char *codepage);
/*
* Worker function for creating a UnicodeString from
* a codepage string using a UConverter.
*/
void
doCodepageCreate(const char *codepageData,
int32_t dataLength,
UConverter *converter,
UErrorCode &status);
#endif
/*
* This function is called when write access to the array
* is necessary.
*
* We need to make a copy of the array if
* the buffer is read-only, or
* the buffer is refCounted (shared), and refCount>1, or
* the buffer is too small.
*
* Return false if memory could not be allocated.
*/
UBool cloneArrayIfNeeded(int32_t newCapacity = -1,
int32_t growCapacity = -1,
UBool doCopyArray = true,
int32_t **pBufferToDelete = 0,
UBool forceClone = false);
UnicodeString &
caseMap(int32_t caseLocale, uint32_t options,
#if !UCONFIG_NO_BREAK_ITERATION
BreakIterator *iter,
#endif
UStringCaseMapper *stringCaseMapper);
// ref counting
void addRef(void);
int32_t removeRef(void);
int32_t refCount(void) const;
// constants
enum {
US_STACKBUF_SIZE=(int32_t)(UNISTR_OBJECT_SIZE-sizeof(void *)-2)/U_SIZEOF_UCHAR,
kInvalidUChar=0xffff, // U+FFFF returned by charAt(invalid index)
kInvalidHashCode=0, // invalid hash code
kEmptyHashCode=1, // hash code for empty string
// bit flag values for fLengthAndFlags
kIsBogus=1, // this string is bogus, i.e., not valid or nullptr
kUsingStackBuffer=2,// using fUnion.fStackFields instead of fUnion.fFields
kRefCounted=4, // there is a refCount field before the characters in fArray
kBufferIsReadonly=8,// do not write to this buffer
kOpenGetBuffer=16, // getBuffer(minCapacity) was called (is "open"),
// and releaseBuffer(newLength) must be called
kAllStorageFlags=0x1f,
kLengthShift=5, // remaining 11 bits for non-negative short length, or negative if long
kLength1=1<<kLengthShift,
kMaxShortLength=0x3ff, // max non-negative short length (leaves top bit 0)
kLengthIsLarge=0xffe0, // short length < 0, real length is in fUnion.fFields.fLength
// combined values for convenience
kShortString=kUsingStackBuffer,
kLongString=kRefCounted,
kReadonlyAlias=kBufferIsReadonly,
kWritableAlias=0
};
friend class UnicodeStringAppendable;
union StackBufferOrFields; // forward declaration necessary before friend declaration
friend union StackBufferOrFields; // make US_STACKBUF_SIZE visible inside fUnion
/*
* The following are all the class fields that are stored
* in each UnicodeString object.
* Note that UnicodeString has virtual functions,
* therefore there is an implicit vtable pointer
* as the first real field.
* The fields should be aligned such that no padding is necessary.
* On 32-bit machines, the size should be 32 bytes,
* on 64-bit machines (8-byte pointers), it should be 40 bytes.
*
* We use a hack to achieve this.
*
* With at least some compilers, each of the following is forced to
* a multiple of sizeof(pointer) [the largest field base unit here is a data pointer],
* rounded up with additional padding if the fields do not already fit that requirement:
* - sizeof(class UnicodeString)
* - offsetof(UnicodeString, fUnion)
* - sizeof(fUnion)
* - sizeof(fStackFields)
*
* We optimize for the longest possible internal buffer for short strings.
* fUnion.fStackFields begins with 2 bytes for storage flags
* and the length of relatively short strings,
* followed by the buffer for short string contents.
* There is no padding inside fStackFields.
*
* Heap-allocated and aliased strings use fUnion.fFields.
* Both fStackFields and fFields must begin with the same fields for flags and short length,
* that is, those must have the same memory offsets inside the object,
* because the flags must be inspected in order to decide which half of fUnion is being used.
* We assume that the compiler does not reorder the fields.
*
* (Padding at the end of fFields is ok:
* As long as it is no larger than fStackFields, it is not wasted space.)
*
* For some of the history of the UnicodeString class fields layout, see
* - ICU ticket #11551 "longer UnicodeString contents in stack buffer"
* - ICU ticket #11336 "UnicodeString: recombine stack buffer arrays"
* - ICU ticket #8322 "why is sizeof(UnicodeString)==48?"
*/
// (implicit) *vtable;
union StackBufferOrFields {
// fStackFields is used iff (fLengthAndFlags&kUsingStackBuffer) else fFields is used.
// Each struct of the union must begin with fLengthAndFlags.
struct {
int16_t fLengthAndFlags; // bit fields: see constants above
char16_t fBuffer[US_STACKBUF_SIZE]; // buffer for short strings
} fStackFields;
struct {
int16_t fLengthAndFlags; // bit fields: see constants above
int32_t fLength; // number of characters in fArray if >127; else undefined
int32_t fCapacity; // capacity of fArray (in char16_ts)
// array pointer last to minimize padding for machines with P128 data model
// or pointer sizes that are not a power of 2
char16_t *fArray; // the Unicode data
} fFields;
} fUnion;
};
U_COMMON_API UnicodeString U_EXPORT2
operator+ (const UnicodeString &s1, const UnicodeString &s2);
//========================================
// Inline members
//========================================
//========================================
// Privates
//========================================
inline void
UnicodeString::pinIndex(int32_t& start) const
{
// pin index
if(start < 0) {
start = 0;
} else if(start > length()) {
start = length();
}
}
inline void
UnicodeString::pinIndices(int32_t& start,
int32_t& _length) const
{
// pin indices
int32_t len = length();
if(start < 0) {
start = 0;
} else if(start > len) {
start = len;
}
if(_length < 0) {
_length = 0;
} else if(_length > (len - start)) {
_length = (len - start);
}
}
inline char16_t*
UnicodeString::getArrayStart() {
return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
}
inline const char16_t*
UnicodeString::getArrayStart() const {
return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
fUnion.fStackFields.fBuffer : fUnion.fFields.fArray;
}
//========================================
// Default constructor
//========================================
inline
UnicodeString::UnicodeString() {
fUnion.fStackFields.fLengthAndFlags=kShortString;
}
inline UnicodeString::UnicodeString(const std::nullptr_t /*text*/) {
fUnion.fStackFields.fLengthAndFlags=kShortString;
}
inline UnicodeString::UnicodeString(const std::nullptr_t /*text*/, int32_t /*length*/) {
fUnion.fStackFields.fLengthAndFlags=kShortString;
}
inline UnicodeString::UnicodeString(std::nullptr_t /*buffer*/, int32_t /*buffLength*/, int32_t /*buffCapacity*/) {
fUnion.fStackFields.fLengthAndFlags=kShortString;
}
//========================================
// Read-only implementation methods
//========================================
inline UBool
UnicodeString::hasShortLength() const {
return fUnion.fFields.fLengthAndFlags>=0;
}
inline int32_t
UnicodeString::getShortLength() const {
// fLengthAndFlags must be non-negative -> short length >= 0
// and arithmetic or logical shift does not matter.
return fUnion.fFields.fLengthAndFlags>>kLengthShift;
}
inline int32_t
UnicodeString::length() const {
return hasShortLength() ? getShortLength() : fUnion.fFields.fLength;
}
inline int32_t
UnicodeString::getCapacity() const {
return (fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) ?
US_STACKBUF_SIZE : fUnion.fFields.fCapacity;
}
inline int32_t
UnicodeString::hashCode() const
{ return doHashCode(); }
inline UBool
UnicodeString::isBogus() const
{ return (UBool)(fUnion.fFields.fLengthAndFlags & kIsBogus); }
inline UBool
UnicodeString::isWritable() const
{ return (UBool)!(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus)); }
inline UBool
UnicodeString::isBufferWritable() const
{
return (UBool)(
!(fUnion.fFields.fLengthAndFlags&(kOpenGetBuffer|kIsBogus|kBufferIsReadonly)) &&
(!(fUnion.fFields.fLengthAndFlags&kRefCounted) || refCount()==1));
}
inline const char16_t *
UnicodeString::getBuffer() const {
if(fUnion.fFields.fLengthAndFlags&(kIsBogus|kOpenGetBuffer)) {
return nullptr;
} else if(fUnion.fFields.fLengthAndFlags&kUsingStackBuffer) {
return fUnion.fStackFields.fBuffer;
} else {
return fUnion.fFields.fArray;
}
}
//========================================
// Read-only alias methods
//========================================
inline int8_t
UnicodeString::doCompare(int32_t start,
int32_t thisLength,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength) const
{
if(srcText.isBogus()) {
return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
} else {
srcText.pinIndices(srcStart, srcLength);
return doCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
}
}
inline UBool
UnicodeString::doEqualsSubstring(int32_t start,
int32_t thisLength,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength) const
{
if(srcText.isBogus()) {
return isBogus();
} else {
srcText.pinIndices(srcStart, srcLength);
return !isBogus() && doEqualsSubstring(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
}
}
inline bool
UnicodeString::operator== (const UnicodeString& text) const
{
if(isBogus()) {
return text.isBogus();
} else {
int32_t len = length(), textLength = text.length();
return !text.isBogus() && len == textLength && doEquals(text, len);
}
}
inline bool
UnicodeString::operator!= (const UnicodeString& text) const
{ return (! operator==(text)); }
inline UBool
UnicodeString::operator> (const UnicodeString& text) const
{ return doCompare(0, length(), text, 0, text.length()) == 1; }
inline UBool
UnicodeString::operator< (const UnicodeString& text) const
{ return doCompare(0, length(), text, 0, text.length()) == -1; }
inline UBool
UnicodeString::operator>= (const UnicodeString& text) const
{ return doCompare(0, length(), text, 0, text.length()) != -1; }
inline UBool
UnicodeString::operator<= (const UnicodeString& text) const
{ return doCompare(0, length(), text, 0, text.length()) != 1; }
inline int8_t
UnicodeString::compare(const UnicodeString& text) const
{ return doCompare(0, length(), text, 0, text.length()); }
inline int8_t
UnicodeString::compare(int32_t start,
int32_t _length,
const UnicodeString& srcText) const
{ return doCompare(start, _length, srcText, 0, srcText.length()); }
inline int8_t
UnicodeString::compare(ConstChar16Ptr srcChars,
int32_t srcLength) const
{ return doCompare(0, length(), srcChars, 0, srcLength); }
inline int8_t
UnicodeString::compare(int32_t start,
int32_t _length,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength) const
{ return doCompare(start, _length, srcText, srcStart, srcLength); }
inline int8_t
UnicodeString::compare(int32_t start,
int32_t _length,
const char16_t *srcChars) const
{ return doCompare(start, _length, srcChars, 0, _length); }
inline int8_t
UnicodeString::compare(int32_t start,
int32_t _length,
const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength) const
{ return doCompare(start, _length, srcChars, srcStart, srcLength); }
inline int8_t
UnicodeString::compareBetween(int32_t start,
int32_t limit,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLimit) const
{ return doCompare(start, limit - start,
srcText, srcStart, srcLimit - srcStart); }
inline int8_t
UnicodeString::doCompareCodePointOrder(int32_t start,
int32_t thisLength,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength) const
{
if(srcText.isBogus()) {
return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
} else {
srcText.pinIndices(srcStart, srcLength);
return doCompareCodePointOrder(start, thisLength, srcText.getArrayStart(), srcStart, srcLength);
}
}
inline int8_t
UnicodeString::compareCodePointOrder(const UnicodeString& text) const
{ return doCompareCodePointOrder(0, length(), text, 0, text.length()); }
inline int8_t
UnicodeString::compareCodePointOrder(int32_t start,
int32_t _length,
const UnicodeString& srcText) const
{ return doCompareCodePointOrder(start, _length, srcText, 0, srcText.length()); }
inline int8_t
UnicodeString::compareCodePointOrder(ConstChar16Ptr srcChars,
int32_t srcLength) const
{ return doCompareCodePointOrder(0, length(), srcChars, 0, srcLength); }
inline int8_t
UnicodeString::compareCodePointOrder(int32_t start,
int32_t _length,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength) const
{ return doCompareCodePointOrder(start, _length, srcText, srcStart, srcLength); }
inline int8_t
UnicodeString::compareCodePointOrder(int32_t start,
int32_t _length,
const char16_t *srcChars) const
{ return doCompareCodePointOrder(start, _length, srcChars, 0, _length); }
inline int8_t
UnicodeString::compareCodePointOrder(int32_t start,
int32_t _length,
const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength) const
{ return doCompareCodePointOrder(start, _length, srcChars, srcStart, srcLength); }
inline int8_t
UnicodeString::compareCodePointOrderBetween(int32_t start,
int32_t limit,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLimit) const
{ return doCompareCodePointOrder(start, limit - start,
srcText, srcStart, srcLimit - srcStart); }
inline int8_t
UnicodeString::doCaseCompare(int32_t start,
int32_t thisLength,
const UnicodeString &srcText,
int32_t srcStart,
int32_t srcLength,
uint32_t options) const
{
if(srcText.isBogus()) {
return (int8_t)!isBogus(); // 0 if both are bogus, 1 otherwise
} else {
srcText.pinIndices(srcStart, srcLength);
return doCaseCompare(start, thisLength, srcText.getArrayStart(), srcStart, srcLength, options);
}
}
inline int8_t
UnicodeString::caseCompare(const UnicodeString &text, uint32_t options) const {
return doCaseCompare(0, length(), text, 0, text.length(), options);
}
inline int8_t
UnicodeString::caseCompare(int32_t start,
int32_t _length,
const UnicodeString &srcText,
uint32_t options) const {
return doCaseCompare(start, _length, srcText, 0, srcText.length(), options);
}
inline int8_t
UnicodeString::caseCompare(ConstChar16Ptr srcChars,
int32_t srcLength,
uint32_t options) const {
return doCaseCompare(0, length(), srcChars, 0, srcLength, options);
}
inline int8_t
UnicodeString::caseCompare(int32_t start,
int32_t _length,
const UnicodeString &srcText,
int32_t srcStart,
int32_t srcLength,
uint32_t options) const {
return doCaseCompare(start, _length, srcText, srcStart, srcLength, options);
}
inline int8_t
UnicodeString::caseCompare(int32_t start,
int32_t _length,
const char16_t *srcChars,
uint32_t options) const {
return doCaseCompare(start, _length, srcChars, 0, _length, options);
}
inline int8_t
UnicodeString::caseCompare(int32_t start,
int32_t _length,
const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength,
uint32_t options) const {
return doCaseCompare(start, _length, srcChars, srcStart, srcLength, options);
}
inline int8_t
UnicodeString::caseCompareBetween(int32_t start,
int32_t limit,
const UnicodeString &srcText,
int32_t srcStart,
int32_t srcLimit,
uint32_t options) const {
return doCaseCompare(start, limit - start, srcText, srcStart, srcLimit - srcStart, options);
}
inline int32_t
UnicodeString::indexOf(const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength,
int32_t start,
int32_t _length) const
{
if(!srcText.isBogus()) {
srcText.pinIndices(srcStart, srcLength);
if(srcLength > 0) {
return indexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
}
}
return -1;
}
inline int32_t
UnicodeString::indexOf(const UnicodeString& text) const
{ return indexOf(text, 0, text.length(), 0, length()); }
inline int32_t
UnicodeString::indexOf(const UnicodeString& text,
int32_t start) const {
pinIndex(start);
return indexOf(text, 0, text.length(), start, length() - start);
}
inline int32_t
UnicodeString::indexOf(const UnicodeString& text,
int32_t start,
int32_t _length) const
{ return indexOf(text, 0, text.length(), start, _length); }
inline int32_t
UnicodeString::indexOf(const char16_t *srcChars,
int32_t srcLength,
int32_t start) const {
pinIndex(start);
return indexOf(srcChars, 0, srcLength, start, length() - start);
}
inline int32_t
UnicodeString::indexOf(ConstChar16Ptr srcChars,
int32_t srcLength,
int32_t start,
int32_t _length) const
{ return indexOf(srcChars, 0, srcLength, start, _length); }
inline int32_t
UnicodeString::indexOf(char16_t c,
int32_t start,
int32_t _length) const
{ return doIndexOf(c, start, _length); }
inline int32_t
UnicodeString::indexOf(UChar32 c,
int32_t start,
int32_t _length) const
{ return doIndexOf(c, start, _length); }
inline int32_t
UnicodeString::indexOf(char16_t c) const
{ return doIndexOf(c, 0, length()); }
inline int32_t
UnicodeString::indexOf(UChar32 c) const
{ return indexOf(c, 0, length()); }
inline int32_t
UnicodeString::indexOf(char16_t c,
int32_t start) const {
pinIndex(start);
return doIndexOf(c, start, length() - start);
}
inline int32_t
UnicodeString::indexOf(UChar32 c,
int32_t start) const {
pinIndex(start);
return indexOf(c, start, length() - start);
}
inline int32_t
UnicodeString::lastIndexOf(ConstChar16Ptr srcChars,
int32_t srcLength,
int32_t start,
int32_t _length) const
{ return lastIndexOf(srcChars, 0, srcLength, start, _length); }
inline int32_t
UnicodeString::lastIndexOf(const char16_t *srcChars,
int32_t srcLength,
int32_t start) const {
pinIndex(start);
return lastIndexOf(srcChars, 0, srcLength, start, length() - start);
}
inline int32_t
UnicodeString::lastIndexOf(const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength,
int32_t start,
int32_t _length) const
{
if(!srcText.isBogus()) {
srcText.pinIndices(srcStart, srcLength);
if(srcLength > 0) {
return lastIndexOf(srcText.getArrayStart(), srcStart, srcLength, start, _length);
}
}
return -1;
}
inline int32_t
UnicodeString::lastIndexOf(const UnicodeString& text,
int32_t start,
int32_t _length) const
{ return lastIndexOf(text, 0, text.length(), start, _length); }
inline int32_t
UnicodeString::lastIndexOf(const UnicodeString& text,
int32_t start) const {
pinIndex(start);
return lastIndexOf(text, 0, text.length(), start, length() - start);
}
inline int32_t
UnicodeString::lastIndexOf(const UnicodeString& text) const
{ return lastIndexOf(text, 0, text.length(), 0, length()); }
inline int32_t
UnicodeString::lastIndexOf(char16_t c,
int32_t start,
int32_t _length) const
{ return doLastIndexOf(c, start, _length); }
inline int32_t
UnicodeString::lastIndexOf(UChar32 c,
int32_t start,
int32_t _length) const {
return doLastIndexOf(c, start, _length);
}
inline int32_t
UnicodeString::lastIndexOf(char16_t c) const
{ return doLastIndexOf(c, 0, length()); }
inline int32_t
UnicodeString::lastIndexOf(UChar32 c) const {
return lastIndexOf(c, 0, length());
}
inline int32_t
UnicodeString::lastIndexOf(char16_t c,
int32_t start) const {
pinIndex(start);
return doLastIndexOf(c, start, length() - start);
}
inline int32_t
UnicodeString::lastIndexOf(UChar32 c,
int32_t start) const {
pinIndex(start);
return lastIndexOf(c, start, length() - start);
}
inline UBool
UnicodeString::startsWith(const UnicodeString& text) const
{ return doEqualsSubstring(0, text.length(), text, 0, text.length()); }
inline UBool
UnicodeString::startsWith(const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength) const
{ return doEqualsSubstring(0, srcLength, srcText, srcStart, srcLength); }
inline UBool
UnicodeString::startsWith(ConstChar16Ptr srcChars, int32_t srcLength) const {
if(srcLength < 0) {
srcLength = u_strlen(toUCharPtr(srcChars));
}
return doEqualsSubstring(0, srcLength, srcChars, 0, srcLength);
}
inline UBool
UnicodeString::startsWith(const char16_t *srcChars, int32_t srcStart, int32_t srcLength) const {
if(srcLength < 0) {
srcLength = u_strlen(toUCharPtr(srcChars));
}
return doEqualsSubstring(0, srcLength, srcChars, srcStart, srcLength);
}
inline UBool
UnicodeString::endsWith(const UnicodeString& text) const
{ return doEqualsSubstring(length() - text.length(), text.length(),
text, 0, text.length()); }
inline UBool
UnicodeString::endsWith(const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength) const {
srcText.pinIndices(srcStart, srcLength);
return doEqualsSubstring(length() - srcLength, srcLength,
srcText, srcStart, srcLength);
}
inline UBool
UnicodeString::endsWith(ConstChar16Ptr srcChars,
int32_t srcLength) const {
if(srcLength < 0) {
srcLength = u_strlen(toUCharPtr(srcChars));
}
return doEqualsSubstring(length() - srcLength, srcLength, srcChars, 0, srcLength);
}
inline UBool
UnicodeString::endsWith(const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength) const {
if(srcLength < 0) {
srcLength = u_strlen(toUCharPtr(srcChars + srcStart));
}
return doEqualsSubstring(length() - srcLength, srcLength,
srcChars, srcStart, srcLength);
}
//========================================
// replace
//========================================
inline UnicodeString&
UnicodeString::replace(int32_t start,
int32_t _length,
const UnicodeString& srcText)
{ return doReplace(start, _length, srcText, 0, srcText.length()); }
inline UnicodeString&
UnicodeString::replace(int32_t start,
int32_t _length,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength)
{ return doReplace(start, _length, srcText, srcStart, srcLength); }
inline UnicodeString&
UnicodeString::replace(int32_t start,
int32_t _length,
ConstChar16Ptr srcChars,
int32_t srcLength)
{ return doReplace(start, _length, srcChars, 0, srcLength); }
inline UnicodeString&
UnicodeString::replace(int32_t start,
int32_t _length,
const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength)
{ return doReplace(start, _length, srcChars, srcStart, srcLength); }
inline UnicodeString&
UnicodeString::replace(int32_t start,
int32_t _length,
char16_t srcChar)
{ return doReplace(start, _length, &srcChar, 0, 1); }
inline UnicodeString&
UnicodeString::replaceBetween(int32_t start,
int32_t limit,
const UnicodeString& srcText)
{ return doReplace(start, limit - start, srcText, 0, srcText.length()); }
inline UnicodeString&
UnicodeString::replaceBetween(int32_t start,
int32_t limit,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLimit)
{ return doReplace(start, limit - start, srcText, srcStart, srcLimit - srcStart); }
inline UnicodeString&
UnicodeString::findAndReplace(const UnicodeString& oldText,
const UnicodeString& newText)
{ return findAndReplace(0, length(), oldText, 0, oldText.length(),
newText, 0, newText.length()); }
inline UnicodeString&
UnicodeString::findAndReplace(int32_t start,
int32_t _length,
const UnicodeString& oldText,
const UnicodeString& newText)
{ return findAndReplace(start, _length, oldText, 0, oldText.length(),
newText, 0, newText.length()); }
// ============================
// extract
// ============================
inline void
UnicodeString::doExtract(int32_t start,
int32_t _length,
UnicodeString& target) const
{ target.replace(0, target.length(), *this, start, _length); }
inline void
UnicodeString::extract(int32_t start,
int32_t _length,
Char16Ptr target,
int32_t targetStart) const
{ doExtract(start, _length, target, targetStart); }
inline void
UnicodeString::extract(int32_t start,
int32_t _length,
UnicodeString& target) const
{ doExtract(start, _length, target); }
#if !UCONFIG_NO_CONVERSION
inline int32_t
UnicodeString::extract(int32_t start,
int32_t _length,
char *dst,
const char *codepage) const
{
// This dstSize value will be checked explicitly
return extract(start, _length, dst, dst!=0 ? 0xffffffff : 0, codepage);
}
#endif
inline void
UnicodeString::extractBetween(int32_t start,
int32_t limit,
char16_t *dst,
int32_t dstStart) const {
pinIndex(start);
pinIndex(limit);
doExtract(start, limit - start, dst, dstStart);
}
inline UnicodeString
UnicodeString::tempSubStringBetween(int32_t start, int32_t limit) const {
return tempSubString(start, limit - start);
}
inline char16_t
UnicodeString::doCharAt(int32_t offset) const
{
if((uint32_t)offset < (uint32_t)length()) {
return getArrayStart()[offset];
} else {
return kInvalidUChar;
}
}
inline char16_t
UnicodeString::charAt(int32_t offset) const
{ return doCharAt(offset); }
inline char16_t
UnicodeString::operator[] (int32_t offset) const
{ return doCharAt(offset); }
inline UBool
UnicodeString::isEmpty() const {
// Arithmetic or logical right shift does not matter: only testing for 0.
return (fUnion.fFields.fLengthAndFlags>>kLengthShift) == 0;
}
//========================================
// Write implementation methods
//========================================
inline void
UnicodeString::setZeroLength() {
fUnion.fFields.fLengthAndFlags &= kAllStorageFlags;
}
inline void
UnicodeString::setShortLength(int32_t len) {
// requires 0 <= len <= kMaxShortLength
fUnion.fFields.fLengthAndFlags =
(int16_t)((fUnion.fFields.fLengthAndFlags & kAllStorageFlags) | (len << kLengthShift));
}
inline void
UnicodeString::setLength(int32_t len) {
if(len <= kMaxShortLength) {
setShortLength(len);
} else {
fUnion.fFields.fLengthAndFlags |= kLengthIsLarge;
fUnion.fFields.fLength = len;
}
}
inline void
UnicodeString::setToEmpty() {
fUnion.fFields.fLengthAndFlags = kShortString;
}
inline void
UnicodeString::setArray(char16_t *array, int32_t len, int32_t capacity) {
setLength(len);
fUnion.fFields.fArray = array;
fUnion.fFields.fCapacity = capacity;
}
inline UnicodeString&
UnicodeString::operator= (char16_t ch)
{ return doReplace(0, length(), &ch, 0, 1); }
inline UnicodeString&
UnicodeString::operator= (UChar32 ch)
{ return replace(0, length(), ch); }
inline UnicodeString&
UnicodeString::setTo(const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength)
{
unBogus();
return doReplace(0, length(), srcText, srcStart, srcLength);
}
inline UnicodeString&
UnicodeString::setTo(const UnicodeString& srcText,
int32_t srcStart)
{
unBogus();
srcText.pinIndex(srcStart);
return doReplace(0, length(), srcText, srcStart, srcText.length() - srcStart);
}
inline UnicodeString&
UnicodeString::setTo(const UnicodeString& srcText)
{
return copyFrom(srcText);
}
inline UnicodeString&
UnicodeString::setTo(const char16_t *srcChars,
int32_t srcLength)
{
unBogus();
return doReplace(0, length(), srcChars, 0, srcLength);
}
inline UnicodeString&
UnicodeString::setTo(char16_t srcChar)
{
unBogus();
return doReplace(0, length(), &srcChar, 0, 1);
}
inline UnicodeString&
UnicodeString::setTo(UChar32 srcChar)
{
unBogus();
return replace(0, length(), srcChar);
}
inline UnicodeString&
UnicodeString::append(const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength)
{ return doAppend(srcText, srcStart, srcLength); }
inline UnicodeString&
UnicodeString::append(const UnicodeString& srcText)
{ return doAppend(srcText, 0, srcText.length()); }
inline UnicodeString&
UnicodeString::append(const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength)
{ return doAppend(srcChars, srcStart, srcLength); }
inline UnicodeString&
UnicodeString::append(ConstChar16Ptr srcChars,
int32_t srcLength)
{ return doAppend(srcChars, 0, srcLength); }
inline UnicodeString&
UnicodeString::append(char16_t srcChar)
{ return doAppend(&srcChar, 0, 1); }
inline UnicodeString&
UnicodeString::operator+= (char16_t ch)
{ return doAppend(&ch, 0, 1); }
inline UnicodeString&
UnicodeString::operator+= (UChar32 ch) {
return append(ch);
}
inline UnicodeString&
UnicodeString::operator+= (const UnicodeString& srcText)
{ return doAppend(srcText, 0, srcText.length()); }
inline UnicodeString&
UnicodeString::insert(int32_t start,
const UnicodeString& srcText,
int32_t srcStart,
int32_t srcLength)
{ return doReplace(start, 0, srcText, srcStart, srcLength); }
inline UnicodeString&
UnicodeString::insert(int32_t start,
const UnicodeString& srcText)
{ return doReplace(start, 0, srcText, 0, srcText.length()); }
inline UnicodeString&
UnicodeString::insert(int32_t start,
const char16_t *srcChars,
int32_t srcStart,
int32_t srcLength)
{ return doReplace(start, 0, srcChars, srcStart, srcLength); }
inline UnicodeString&
UnicodeString::insert(int32_t start,
ConstChar16Ptr srcChars,
int32_t srcLength)
{ return doReplace(start, 0, srcChars, 0, srcLength); }
inline UnicodeString&
UnicodeString::insert(int32_t start,
char16_t srcChar)
{ return doReplace(start, 0, &srcChar, 0, 1); }
inline UnicodeString&
UnicodeString::insert(int32_t start,
UChar32 srcChar)
{ return replace(start, 0, srcChar); }
inline UnicodeString&
UnicodeString::remove()
{
// remove() of a bogus string makes the string empty and non-bogus
if(isBogus()) {
setToEmpty();
} else {
setZeroLength();
}
return *this;
}
inline UnicodeString&
UnicodeString::remove(int32_t start,
int32_t _length)
{
if(start <= 0 && _length == INT32_MAX) {
// remove(guaranteed everything) of a bogus string makes the string empty and non-bogus
return remove();
}
return doReplace(start, _length, nullptr, 0, 0);
}
inline UnicodeString&
UnicodeString::removeBetween(int32_t start,
int32_t limit)
{ return doReplace(start, limit - start, nullptr, 0, 0); }
inline UnicodeString &
UnicodeString::retainBetween(int32_t start, int32_t limit) {
truncate(limit);
return doReplace(0, start, nullptr, 0, 0);
}
inline UBool
UnicodeString::truncate(int32_t targetLength)
{
if(isBogus() && targetLength == 0) {
// truncate(0) of a bogus string makes the string empty and non-bogus
unBogus();
return false;
} else if((uint32_t)targetLength < (uint32_t)length()) {
setLength(targetLength);
return true;
} else {
return false;
}
}
inline UnicodeString&
UnicodeString::reverse()
{ return doReverse(0, length()); }
inline UnicodeString&
UnicodeString::reverse(int32_t start,
int32_t _length)
{ return doReverse(start, _length); }
U_NAMESPACE_END
#endif /* U_SHOW_CPLUSPLUS_API */
#endif
bytestream.h
C++ API: Interface for writing bytes, and implementation classes.
char16ptr.h
C++ API: char16_t pointer wrappers with implicit conversion from bit-compatible raw pointer types.
icu::BreakIterator
The BreakIterator class implements methods for finding the location of boundaries in text.
Definition: brkiter.h:106
icu::ByteSink
A ByteSink can be filled with bytes.
Definition: bytestream.h:53
icu::Char16Ptr
char16_t * wrapper with implicit conversion from distinct but bit-compatible pointer types.
Definition: char16ptr.h:42
icu::ConstChar16Ptr
const char16_t * wrapper with implicit conversion from distinct but bit-compatible pointer types.
Definition: char16ptr.h:149
icu::Edits
Records lengths of string edits but not replacement text.
Definition: edits.h:80
icu::Locale
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:195
icu::Replaceable
Replaceable is an abstract base class representing a string of characters that supports the replaceme...
Definition: rep.h:77
icu::Replaceable::extractBetween
virtual void extractBetween(int32_t start, int32_t limit, UnicodeString &target) const =0
Copies characters in the range [start, limit) into the UnicodeString target.
icu::Replaceable::charAt
char16_t charAt(int32_t offset) const
Returns the 16-bit code unit at the given offset into the text.
Definition: rep.h:251
icu::Replaceable::length
int32_t length() const
Returns the number of 16-bit code units in the text.
Definition: rep.h:246
icu::StringByteSink
Implementation of ByteSink that writes to a "string".
Definition: bytestream.h:267
icu::StringPiece
A string-like object that points to a sized piece of memory.
Definition: stringpiece.h:60
icu::UnicodeStringAppendable
An Appendable implementation which writes to a UnicodeString.
Definition: appendable.h:156
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:296
icu::UnicodeString::indexOf
int32_t 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 in srcChar...
icu::UnicodeString::UnicodeString
UnicodeString(const UnicodeString &that)
Copy constructor.
icu::UnicodeString::swap
void swap(UnicodeString &other) noexcept
Swap strings.
icu::UnicodeString::getCharAt
virtual char16_t getCharAt(int32_t offset) const override
The change in Replaceable to use virtual getCharAt() allows UnicodeString::charAt() to be inline agai...
icu::UnicodeString::getLength
virtual int32_t getLength() const override
Implement Replaceable::getLength() (see jitterbug 1027).
icu::UnicodeString::foldCase
UnicodeString & foldCase(uint32_t options=0)
Case-folds the characters in this string.
icu::UnicodeString::unescapeAt
UChar32 unescapeAt(int32_t &offset) const
Unescape a single escape sequence and return the represented character.
icu::UnicodeString::UnicodeString
UnicodeString(const wchar_t *text, int32_t textLength)
wchar_t * constructor.
Definition: unistr.h:3060
icu::UnicodeString::handleReplaceBetween
virtual void handleReplaceBetween(int32_t start, int32_t limit, const UnicodeString &text) override
Replace a substring of this object with the given text.
icu::UnicodeString::hasMoreChar32Than
UBool 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...
icu::UnicodeString::UnicodeString
UnicodeString(const UnicodeString &src, int32_t srcStart, int32_t srcLength)
'Substring' constructor from subrange of source string.
icu::UnicodeString::operator=
UnicodeString & operator=(UnicodeString &&src) noexcept
Move assignment operator; might leave src in bogus state.
icu::UnicodeString::~UnicodeString
virtual ~UnicodeString()
Destructor.
icu::UnicodeString::UnicodeString
UnicodeString(const char *codepageData, int32_t dataLength, const char *codepage)
char* constructor.
icu::UnicodeString::UnicodeString
UnicodeString(const char *codepageData, const char *codepage)
char* constructor.
icu::UnicodeString::UnicodeString
UnicodeString(UBool isTerminated, ConstChar16Ptr text, int32_t textLength)
Readonly-aliasing char16_t* constructor.
icu::UnicodeString::fastCopyFrom
UnicodeString & fastCopyFrom(const UnicodeString &src)
Almost the same as the assignment operator.
icu::UnicodeString::toTitle
UnicodeString & toTitle(BreakIterator *titleIter)
Titlecase this string, convenience function using the default locale.
icu::UnicodeString::EInvariant
EInvariant
Constant to be used in the UnicodeString(char *, int32_t, EInvariant) constructor which constructs a ...
Definition: unistr.h:307
icu::UnicodeString::unescape
UnicodeString unescape() const
Unescape a string of characters and return a string containing the result.
icu::UnicodeString::UnicodeString
UnicodeString(const UnicodeString &src, int32_t srcStart)
'Substring' constructor from tail of source string.
icu::UnicodeString::getChar32Limit
int32_t getChar32Limit(int32_t offset) const
Adjust a random-access offset so that it points behind a Unicode character.
icu::UnicodeString::UnicodeString
UnicodeString(char16_t *buffer, int32_t buffLength, int32_t buffCapacity)
Writable-aliasing char16_t* constructor.
icu::UnicodeString::UnicodeString
UnicodeString(int32_t capacity, UChar32 c, int32_t count)
Construct a UnicodeString with capacity to hold capacity char16_ts.
icu::UnicodeString::UnicodeString
UNISTR_FROM_STRING_EXPLICIT UnicodeString(const uint16_t *text)
uint16_t * constructor.
Definition: unistr.h:2997
icu::UnicodeString::trim
UnicodeString & trim(void)
Trims leading and trailing whitespace from this UnicodeString.
icu::UnicodeString::extract
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 c...
icu::UnicodeString::findAndReplace
UnicodeString & findAndReplace(int32_t start, int32_t length, const UnicodeString &oldText, int32_t oldStart, int32_t oldLength, const UnicodeString &newText, int32_t newStart, int32_t newLength)
Replace all occurrences of characters in oldText in the range [oldStart, oldStart + oldLength) with t...
icu::UnicodeString::copy
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.
icu::UnicodeString::extractBetween
virtual void extractBetween(int32_t start, int32_t limit, UnicodeString &target) const override
Copy the characters in the range [start, limit) into the UnicodeString target.
icu::UnicodeString::replace
UnicodeString & replace(int32_t start, int32_t length, const UnicodeString &srcText, int32_t srcStart, int32_t srcLength)
Replace the characters in the range [start, start + length) with the characters in srcText in the ran...
Definition: unistr.h:4425
icu::UnicodeString::padLeading
UBool padLeading(int32_t targetLength, char16_t padChar=0x0020)
Pad the start of this UnicodeString with the character padChar.
icu::UnicodeString::getChar32Start
int32_t getChar32Start(int32_t offset) const
Adjust a random-access offset so that it points to the beginning of a Unicode character.
icu::UnicodeString::char32At
UChar32 char32At(int32_t offset) const
Return the code point that contains the code unit at offset offset.
icu::UnicodeString::UnicodeString
UnicodeString(const char *src, int32_t textLength, enum EInvariant inv)
Constructs a Unicode string from an invariant-character char * string.
icu::UnicodeString::operator=
UnicodeString & operator=(const UnicodeString &srcText)
Assignment operator.
icu::UnicodeString::append
UnicodeString & append(UChar32 srcChar)
Append the code point srcChar to the UnicodeString object.
icu::UnicodeString::toUTF8String
StringClass & toUTF8String(StringClass &result) const
Convert the UnicodeString to UTF-8 and append the result to a standard string.
Definition: unistr.h:1729
icu::UnicodeString::toLower
UnicodeString & toLower(const Locale &locale)
Convert the characters in this to lower case following the conventions of a specific locale.
icu::UnicodeString::toTitle
UnicodeString & toTitle(BreakIterator *titleIter, const Locale &locale)
Titlecase this string.
icu::UnicodeString::length
int32_t length(void) const
Return the length of the UnicodeString object.
Definition: unistr.h:3903
icu::UnicodeString::tempSubString
UnicodeString tempSubString(int32_t start=0, int32_t length=INT32_MAX) const
Create a temporary substring for the specified range.
icu::UnicodeString::extract
int32_t extract(Char16Ptr dest, int32_t destCapacity, UErrorCode &errorCode) const
Copy the contents of the string into dest.
icu::UnicodeString::getChar32At
virtual UChar32 getChar32At(int32_t offset) const override
The change in Replaceable to use virtual getChar32At() allows UnicodeString::char32At() to be inline ...
icu::UnicodeString::extract
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'...
icu::UnicodeString::fromUTF8
static UnicodeString fromUTF8(StringPiece utf8)
Create a UnicodeString from a UTF-8 string.
icu::UnicodeString::toUpper
UnicodeString & toUpper(void)
Convert the characters in this to UPPER CASE following the conventions of the default locale.
icu::UnicodeString::UnicodeString
UNISTR_FROM_CHAR_EXPLICIT UnicodeString(char16_t ch)
Single char16_t (code unit) constructor.
icu::UnicodeString::lastIndexOf
int32_t 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 in srcChars...
icu::UnicodeString::UnicodeString
UnicodeString(wchar_t *buffer, int32_t buffLength, int32_t buffCapacity)
Writable-aliasing wchar_t * constructor.
Definition: unistr.h:3142
icu::UnicodeString::setToBogus
void setToBogus()
Make this UnicodeString object invalid.
icu::UnicodeString::swap
friend void swap(UnicodeString &s1, UnicodeString &s2) noexcept
Non-member UnicodeString swap function.
Definition: unistr.h:1925
icu::UnicodeString::moveIndex32
int32_t moveIndex32(int32_t index, int32_t delta) const
Move the code unit index along the string by delta code points.
icu::UnicodeString::fromUTF32
static UnicodeString fromUTF32(const UChar32 *utf32, int32_t length)
Create a UnicodeString from a UTF-32 string.
icu::UnicodeString::countChar32
int32_t 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.
icu::UnicodeString::UnicodeString
UNISTR_FROM_CHAR_EXPLICIT UnicodeString(UChar32 ch)
Single UChar32 (code point) constructor.
icu::UnicodeString::setTo
UnicodeString & setTo(UBool isTerminated, ConstChar16Ptr text, int32_t textLength)
Aliasing setTo() function, analogous to the readonly-aliasing char16_t* constructor.
icu::UnicodeString::toTitle
UnicodeString & toTitle(BreakIterator *titleIter, const Locale &locale, uint32_t options)
Titlecase this string, with options.
icu::UnicodeString::clone
virtual UnicodeString * clone() const override
Clone this object, an instance of a subclass of Replaceable.
icu::UnicodeString::extract
int32_t extract(char *dest, int32_t destCapacity, UConverter *cnv, UErrorCode &errorCode) const
Convert the UnicodeString into a codepage string using an existing UConverter.
icu::UnicodeString::UnicodeString
UnicodeString(UnicodeString &&src) noexcept
Move constructor; might leave src in bogus state.
icu::UnicodeString::UnicodeString
UnicodeString(const char16_t *text, int32_t textLength)
char16_t* constructor.
icu::UnicodeString::replace
UnicodeString & replace(int32_t start, int32_t length, UChar32 srcChar)
Replace the characters in the range [start, start + length) with the code point srcChar.
icu::UnicodeString::UnicodeString
UnicodeString(const char *src, int32_t srcLength, UConverter *cnv, UErrorCode &errorCode)
char * / UConverter constructor.
icu::UnicodeString::UnicodeString
UnicodeString(const char *codepageData, int32_t dataLength)
char* constructor.
icu::UnicodeString::getStaticClassID
static UClassID getStaticClassID()
ICU "poor man's RTTI", returns a UClassID for this class.
icu::UnicodeString::UnicodeString
UnicodeString(uint16_t *buffer, int32_t buffLength, int32_t buffCapacity)
Writable-aliasing uint16_t * constructor.
Definition: unistr.h:3128
icu::UnicodeString::toUTF32
int32_t toUTF32(UChar32 *utf32, int32_t capacity, UErrorCode &errorCode) const
Convert the UnicodeString to UTF-32.
icu::UnicodeString::getTerminatedBuffer
const char16_t * getTerminatedBuffer()
Get a read-only pointer to the internal buffer, making sure that it is NUL-terminated.
icu::UnicodeString::toLower
UnicodeString & toLower(void)
Convert the characters in this to lower case following the conventions of the default locale.
icu::UnicodeString::UnicodeString
UnicodeString(const uint16_t *text, int32_t textLength)
uint16_t * constructor.
Definition: unistr.h:3047
icu::UnicodeString::UnicodeString
UNISTR_FROM_STRING_EXPLICIT UnicodeString(const char16_t *text)
char16_t* constructor.
icu::UnicodeString::getDynamicClassID
virtual UClassID getDynamicClassID() const override
ICU "poor man's RTTI", returns a UClassID for the actual class.
icu::UnicodeString::extract
int32_t extract(int32_t start, int32_t startLength, char *target, int32_t targetCapacity, enum EInvariant inv) const
Copy the characters in the range [start, start + startLength) into an array of characters.
icu::UnicodeString::UnicodeString
UNISTR_FROM_STRING_EXPLICIT UnicodeString(const wchar_t *text)
wchar_t * constructor.
Definition: unistr.h:3013
icu::UnicodeString::isBogus
UBool isBogus(void) const
Determine if this object contains a valid string.
Definition: unistr.h:3918
icu::UnicodeString::setCharAt
UnicodeString & setCharAt(int32_t offset, char16_t ch)
Set the character at the specified offset to the specified character.
icu::UnicodeString::setTo
UnicodeString & setTo(char16_t *buffer, int32_t buffLength, int32_t buffCapacity)
Aliasing setTo() function, analogous to the writable-aliasing char16_t* constructor.
icu::UnicodeString::padTrailing
UBool padTrailing(int32_t targetLength, char16_t padChar=0x0020)
Pad the end of this UnicodeString with the character padChar.
icu::UnicodeString::UnicodeString
UNISTR_FROM_STRING_EXPLICIT UnicodeString(const char *codepageData)
char* constructor.
icu::UnicodeString::releaseBuffer
void releaseBuffer(int32_t newLength=-1)
Release a read/write buffer on a UnicodeString object with an "open" getBuffer(minCapacity).
icu::UnicodeString::getBuffer
char16_t * getBuffer(int32_t minCapacity)
Get a read/write pointer to the internal buffer.
icu::UnicodeString::toUTF8
void toUTF8(ByteSink &sink) const
Convert the UnicodeString to UTF-8 and write the result to a ByteSink.
icu::UnicodeString::hasMetaData
virtual UBool hasMetaData() const override
Replaceable API.
icu::UnicodeString::toUpper
UnicodeString & toUpper(const Locale &locale)
Convert the characters in this to UPPER CASE following the conventions of a specific locale.
u_strlen
U_CAPI int32_t u_strlen(const UChar *s)
icu::operator==
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
icu::operator!=
bool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
Definition: stringpiece.h:335
icu::toUCharPtr
const UChar * toUCharPtr(const char16_t *p)
Converts from const char16_t * to const UChar *.
Definition: char16ptr.h:260
icu::operator+
U_COMMON_API UnicodeString operator+(const UnicodeString &s1, const UnicodeString &s2)
Create a new UnicodeString with the concatenation of two others.
U_CALLCONV
#define U_CALLCONV
Similar to U_CDECL_BEGIN/U_CDECL_END, this qualifier is necessary in callback function typedefs to ma...
Definition: platform.h:866
rep.h
C++ API: Replaceable String.
std_string.h
C++ API: Central ICU header for including the C++ standard <string> header and for related definition...
stringpiece.h
C++ API: StringPiece: Read-only byte string wrapper class.
UConverter
struct UConverter UConverter
Definition: ucnv_err.h:96
UCONFIG_NO_BREAK_ITERATION
#define UCONFIG_NO_BREAK_ITERATION
This switch turns off break iteration.
Definition: uconfig.h:358
UChar32
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
Definition: umachine.h:435
INT32_MAX
#define INT32_MAX
The largest value a 32 bit signed integer can hold.
Definition: umachine.h:186
UBool
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition: umachine.h:247
U_CAPI
#define U_CAPI
This is used to declare a function as a public ICU C API.
Definition: umachine.h:110
UChar
char16_t UChar
The base type for UTF-16 code units and pointers.
Definition: umachine.h:386
U_SIZEOF_UCHAR
#define U_SIZEOF_UCHAR
Number of bytes in a UChar (always 2).
Definition: umachine.h:330
UNISTR_FROM_CHAR_EXPLICIT
#define UNISTR_FROM_CHAR_EXPLICIT
This can be defined to be empty or "explicit".
Definition: unistr.h:150
UStringCaseMapper
int32_t UStringCaseMapper(int32_t caseLocale, uint32_t options, icu::BreakIterator *iter, char16_t *dest, int32_t destCapacity, const char16_t *src, int32_t srcLength, icu::Edits *edits, UErrorCode &errorCode)
Internal string case mapping function type.
Definition: unistr.h:70
UNISTR_FROM_STRING_EXPLICIT
#define UNISTR_FROM_STRING_EXPLICIT
This can be defined to be empty or "explicit".
Definition: unistr.h:170
UNISTR_OBJECT_SIZE
#define UNISTR_OBJECT_SIZE
Desired sizeof(UnicodeString) in bytes.
Definition: unistr.h:208
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:96
utypes.h
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:415
U_COMMON_API
#define U_COMMON_API
Set to export library symbols from inside the common library, and to import them from outside.
Definition: utypes.h:300