Base Framework
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | List of all members
WideString Class Reference

Wide-character string. More...

#include <base/string/WideString.h>

Classes

class  Default
 
struct  HashEntry
 

Public Types

enum  WideEncoding { UTF16, UCS4 }
 
enum  EncodingFlags {
  ADD_BOM = 1, EAT_BOM = 2, EXPECT_BOM = 4, ASSUME_NATIVE_BYTE_ORDER = 8,
  ASSUME_BE = 16, ASSUME_LE = 32
}
 
typedef WideTraits Traits
 
typedef ucs4 Char
 
typedef ReferenceCountedAllocator< ucs4 >::Iterator Iterator
 
typedef ReferenceCountedAllocator< ucs4 >::ReadIterator ReadIterator
 
typedef ReferenceCountedAllocator< ucs4 >::Enumerator Enumerator
 
typedef ReferenceCountedAllocator< ucs4 >::ReadEnumerator ReadEnumerator
 

Public Member Functions

 WideString () noexcept
 
 WideString (Reference< ReferenceCountedAllocator< Char > > string)
 
 WideString (MemorySize capacity)
 
 WideString (Default d)
 
 WideString (const Literal &string)
 
 WideString (const WideLiteral &string)
 
 WideString (const char *string)
 
 WideString (const char *string, MemorySize length)
 
 WideString (const wchar *string)
 
 WideString (const wchar *string, MemorySize length)
 
 WideString (const char16_t *string)
 
 WideString (const char16_t *string, MemorySize length)
 
 WideString (const char32_t *string)
 
 WideString (const char32_t *string, MemorySize length)
 
 WideString (const String &string)
 
 WideString (const NativeWideString &string)
 
 WideString (const NativeWideString &string, MemorySize maximum)
 
template<MemorySize SIZE>
 WideString (const char(&string)[SIZE])
 
 WideString (const NativeString &string)
 
 WideString (const NativeString &string, MemorySize maximum)
 
 WideString (const WideString &copy) noexcept
 
 WideString (WideString &&move) noexcept
 
 WideString (StringOutputStream &stream)
 
 WideString (FormatOutputStream &stream)
 
WideStringoperator= (const WideString &assign) noexcept
 
WideStringoperator= (WideString &&move) noexcept
 
WideStringoperator= (const Literal &assign)
 
WideStringoperator= (const WideLiteral &assign)
 
WideStringoperator= (const char *assign)
 
WideStringoperator= (const wchar *assign)
 
WideStringoperator= (const char16_t *assign)
 
WideStringoperator= (const char32_t *assign)
 
WideStringoperator= (const String &assign)
 
WideStringoperator= (const StringOutputStream &assign)
 
template<MemorySize SIZE>
WideStringoperator= (const Char(&literal)[SIZE])
 
MemorySize getLength () const noexcept
 
bool isEmpty () const noexcept
 
bool isProper () const noexcept
 
bool isASCII () const noexcept
 
bool isMultiReferenced () const noexcept
 
MemorySize getCapacity () const noexcept
 
void ensureCapacity (MemorySize capacity)
 
void clear ()
 
WideString copy () const
 
void garbageCollect ()
 
void forceToLength (MemorySize length)
 
Iterator getBeginIterator () noexcept
 
Iterator getEndIterator () noexcept
 
ReadIterator getBeginReadIterator () const noexcept
 
ReadIterator getEndReadIterator () const noexcept
 
ReadIterator begin () const noexcept
 
ReadIterator end () const noexcept
 
Enumerator getEnumerator () noexcept
 
ReadEnumerator getReadEnumerator () const noexcept
 
ucs4 getAt (MemorySize index) const
 
void setAt (MemorySize index, ucs4 value)
 
Element operator[] (MemorySize index)
 
 operator bool () const noexcept
 
char operator[] (MemorySize index) const
 
WideStringremove (MemorySize start, MemorySize end)
 
WideStringremoveFrom (MemorySize start)
 
WideStringremoveAt (MemorySize index)
 
WideStringappend (ucs4 ch)
 
WideStringappend (const WideString &string)
 
WideStringappend (const String &string)
 
WideStringappend (const WideLiteral &string)
 
WideStringappend (const NativeWideString &string)
 
WideStringappend (const char *string)
 
WideStringappend (const wchar *string)
 
WideStringappend (const WideLiteral &string, MemorySize maximum)
 
WideStringappend (const NativeWideString &string, MemorySize maximum)
 
WideStringappend (const ConstSpan< Char > &buffer)
 
WideStringappend (const wchar *string, MemorySize maximum)
 
WideStringprepend (ucs4 ch)
 
WideStringprepend (const WideString &string)
 
WideStringinsert (MemorySize index, const ConstSpan< Char > &span)
 
WideStringinsert (MemorySize index, const ConstSpan< wchar > &src)
 
WideStringinsert (MemorySize index, ucs4 ch)
 
WideStringinsert (MemorySize index, const WideString &string)
 
WideStringinsert (MemorySize index, const WideLiteral &string)
 
template<MemorySize SIZE>
WideStringinsert (MemorySize index, const Char(&literal)[SIZE])
 
WideStringinsert (MemorySize index, const NativeWideString &string)
 
WideStringinsert (MemorySize index, const wchar *string)
 
WideStringinsert (MemorySize index, const char *string)
 
WideStringreplace (MemorySize start, MemorySize end, const WideString &string)
 
MemorySize replaceAll (const WideString &fromStr, const WideString &toStr)
 
WideString substring (MemorySize start, MemorySize end) const
 
WideString substring (MemorySize start) const
 
WideStringoperator+= (const WideString &suffix)
 
WideStringoperator+= (const String &suffix)
 
WideStringoperator+= (const WideLiteral &suffix)
 
WideStringoperator+= (const wchar *suffix)
 
WideStringoperator+= (const NativeWideString &suffix)
 
WideStringoperator+= (Char suffix)
 
WideStringoperator-= (const WideString &suffix)
 
WideStringreverse () noexcept
 
WideStringtoLowerCase () noexcept
 
WideStringtoUpperCase () noexcept
 
int compareTo (const WideString &string) const noexcept
 
int compareTo (const WideLiteral &string) const
 
int compareTo (const wchar *string) const
 
int compareTo (const NativeWideString &string) const
 
int compareToIgnoreCase (const WideString &string) const noexcept
 
template<MemorySize SIZE>
int compareToIgnoreCase (const Char(&literal)[SIZE]) const noexcept
 
bool startsWith (const WideString &prefix) const
 
bool startsWith (const WideLiteral &prefix) const
 
template<MemorySize SIZE>
bool startsWith (const Char(&prefix)[SIZE]) const
 
bool endsWith (const WideString &suffix) const
 
bool endsWith (const WideLiteral &suffix) const
 
template<MemorySize SIZE>
bool endsWith (const char(&suffix)[SIZE]) const
 
bool operator== (const WideString &string) const noexcept
 
bool operator!= (const WideString &string) const noexcept
 
bool operator== (const WideLiteral &string) const noexcept
 
bool operator< (const WideString &string) const noexcept
 
bool operator<= (const WideString &string) const noexcept
 
bool operator>= (const WideString &string) const noexcept
 
bool operator> (const WideString &string) const noexcept
 
MemoryDiff indexOf (ucs4 ch, MemorySize start=0) const noexcept
 
MemoryDiff indexOf (const WideString &string, MemorySize start=0) const noexcept
 
MemoryDiff lastIndexOf (ucs4 ch, MemorySize start) const noexcept
 
MemoryDiff lastIndexOf (ucs4 ch) const noexcept
 
MemoryDiff lastIndexOf (const WideString &string, MemorySize start) const noexcept
 
MemoryDiff lastIndexOf (const WideString &string) const noexcept
 
MemorySize count (ucs4 ch, MemorySize start=0) const noexcept
 
MemorySize count (const WideString &string, MemorySize start=0) const noexcept
 
bool isUpperCased () const noexcept
 
bool isLowerCased () const noexcept
 
bool isTitleCased () const noexcept
 
WideStringtrim (ucs4 character=' ')
 
MemoryDiff search (const WideString &substring, MemorySize start=0) const noexcept
 
Array< WideStringsplit (Char separator, bool group=false) const
 
const Reference< ReferenceCountedAllocator< Char > > & getContainer () const
 
Char * getElements ()
 
bool invariant () const noexcept
 
const Char * getElements () const noexcept
 
const Char * getEnd () const noexcept
 
bool hasNull () const noexcept
 
ConstSpan< ucs4 > getSpan () const noexcept
 
const Char * native () const noexcept
 
bool isValidUnicode (bool iso=false) const noexcept
 
WideString getValidUnicode (bool iso=false) const
 

Static Public Member Functions

static WideString makeLength (MemorySize length)
 
static WideString makeCapacity (MemorySize capacity)
 
static ConstSpan< wchar > toSpan (const wchar *string) noexcept
 

Static Public Attributes

static constexpr MemorySize MAXIMUM_LENGTH = (PrimitiveTraits<int>::MAXIMUM/sizeof(ucs4) - 1)
 
static constexpr unsigned int HASH_MODULUS = 1455
 
static const HashEntry hashTable []
 
static const uint32 mappingTable []
 
static constexpr unsigned int MAXIMUM_MULTIBYTES = 6
 
static constexpr ucs4 BOM = 0x0000feff
 

Protected Member Functions

void initialize (const char *string, MemorySize length)
 
void initialize (const wchar *string, MemorySize length)
 
void initialize (const char16_t *string, MemorySize length)
 
void initialize (const ucs4 *string, MemorySize length)
 
Char * getBuffer ()
 
Char * getBuffer (MemorySize length)
 
const Char * getBuffer () const noexcept
 
void setLength (MemorySize length)
 

Static Protected Member Functions

static int compareToIgnoreCase (const ucs4 *left, const ucs4 *right) noexcept
 

Detailed Description

Wide-character string.

Wide-character string implementation. The first modifying operation on a string may force the internal buffer to be duplicated. The implementation is currently NOT MT-safe.

WideString myString = L"Hello, World!";
WideString myOtherString = myString;
Version
1.0
Examples
testsuite/sax.cpp.

Member Typedef Documentation

◆ Enumerator

The type of the modifying string enumerator.

◆ Iterator

The type of the modifying string iterator.

◆ ReadEnumerator

The type of the non-modifying string enumerator.

◆ ReadIterator

The type of the non-modifying string iterator.

◆ Traits

Character specific properties and manipulators.

Member Enumeration Documentation

◆ EncodingFlags

Encoding flags.

Enumerator
ADD_BOM 

Specifies that a BOM should be inserted when encoding to UTF.

EAT_BOM 

Specifies that the BOM should be skipped if present.

EXPECT_BOM 

Specifies that the BOM must be present.

ASSUME_NATIVE_BYTE_ORDER 

Specifies that the encoding is in native byte order.

ASSUME_BE 

Specifies that the encoding is in big endian byte order (ignored if ASSUME_NATIVE_BYTE_ORDER is set).

ASSUME_LE 

Specifies that the encoding is in little endian byte order (ignored if ASSUME_NATIVE_BYTE_ORDER or ASSUME_BE are set).

◆ WideEncoding

Wide character encoding.

Enumerator
UTF16 

UTF-16 encoding.

UCS4 

UCS-4 encoding.

Constructor & Destructor Documentation

◆ WideString() [1/23]

WideString::WideString ( )
noexcept

Initializes an empty string. No allocation done.

◆ WideString() [2/23]

WideString::WideString ( MemorySize  capacity)
explicit

Initializes a string with no characters in it and the given initial capacity.

Parameters
capacityThe initial capacity.

◆ WideString() [3/23]

WideString::WideString ( Default  d)

Forces a non-null empty string. Avoid this.

◆ WideString() [4/23]

WideString::WideString ( const Literal string)

Initializes the string from a string literal. The string literal is not copied into internal buffer. Implicit initialization is allowed.

Parameters
stringThe string.

◆ WideString() [5/23]

WideString::WideString ( const WideLiteral string)

Initializes the string from a string literal. The string literal is not copied into internal buffer. Implicit initialization is allowed.

Parameters
stringThe string.

◆ WideString() [6/23]

WideString::WideString ( const char *  string)

Initializes the string from a string literal. The string literal is not copied into internal buffer. Implicit initialization is allowed.

Parameters
stringThe string.

◆ WideString() [7/23]

WideString::WideString ( const char *  string,
MemorySize  length 
)

Initializes the string from a string literal. The string literal is not copied into internal buffer. Implicit initialization is allowed.

Parameters
stringThe string.
lengthThe length of the string.

◆ WideString() [8/23]

WideString::WideString ( const wchar *  string)

Initializes the string from a string literal. The string literal is not copied into internal buffer. Implicit initialization is allowed.

Parameters
stringThe string.

◆ WideString() [9/23]

WideString::WideString ( const wchar *  string,
MemorySize  length 
)

Initializes the string from a string literal. The string literal is not copied into internal buffer. Implicit initialization is allowed.

Parameters
stringThe string.
lengthThe length of the string.

◆ WideString() [10/23]

WideString::WideString ( const char16_t *  string)

Initializes the string from a string literal. The string literal is not copied into internal buffer. Implicit initialization is allowed.

Parameters
stringThe string.

◆ WideString() [11/23]

WideString::WideString ( const char16_t *  string,
MemorySize  length 
)

Initializes the string from a string literal. The string literal is not copied into internal buffer. Implicit initialization is allowed.

Parameters
stringThe string.
lengthThe length of the string.

◆ WideString() [12/23]

WideString::WideString ( const char32_t *  string)

Initializes the string from a string literal. The string literal is not copied into internal buffer. Implicit initialization is allowed.

Parameters
stringThe string.

◆ WideString() [13/23]

WideString::WideString ( const char32_t *  string,
MemorySize  length 
)

Initializes the string from a string literal. The string literal is not copied into internal buffer. Implicit initialization is allowed.

Parameters
stringThe string.
lengthThe length of the string.

◆ WideString() [14/23]

WideString::WideString ( const String string)

Initializes the string from UTF-8 string.

◆ WideString() [15/23]

WideString::WideString ( const NativeWideString string)

Initializes the string from a NULL-terminated string.

Parameters
stringNULL-terminated string. If NULL, the string is initialized with no characters in it.

◆ WideString() [16/23]

WideString::WideString ( const NativeWideString string,
MemorySize  maximum 
)

Initializes the string from a NULL-terminated string. If the length of the specified string (string) exceeds the maximum length (n) only the first n characters are used. Raises StringException is string exceeds the maximum allowed length.

Parameters
stringNULL-terminated string. If NULL, the string is initialized with no characters in it.
maximumSpecifies the maximum length.

◆ WideString() [17/23]

template<MemorySize SIZE>
WideString::WideString ( const char(&)  string[SIZE])
inline

Initializes string from a NULL-terminated multibyte character string.

Parameters
stringThe NULL-terminated string.

◆ WideString() [18/23]

WideString::WideString ( const NativeString string)

Initializes the string from a NULL-terminated string.

Parameters
stringNULL-terminated string. If nullptr, the string is initialized with no characters in it.

◆ WideString() [19/23]

WideString::WideString ( const NativeString string,
MemorySize  maximum 
)

Initializes string from a NULL-terminated multibyte string.

Parameters
stringThe NULL-terminated string.
maxmimumThe maximum length of the string.

◆ WideString() [20/23]

WideString::WideString ( const WideString copy)
inlinenoexcept

Initializes string from other string.

◆ WideString() [21/23]

WideString::WideString ( WideString &&  move)
inlinenoexcept

Initializes string from other string.

◆ WideString() [22/23]

WideString::WideString ( StringOutputStream stream)

Initializes string from string output stream. Forces flush().

◆ WideString() [23/23]

WideString::WideString ( FormatOutputStream stream)

Initializes string from string output stream via FormatOutputStream. Forces flush(). Throws exception if not a StringOutputStream.

Member Function Documentation

◆ append() [1/11]

WideString& WideString::append ( const char *  string)
inline

Appends the native string to this string.

Parameters
stringThe native string to be appended.

◆ append() [2/11]

WideString& WideString::append ( const ConstSpan< Char > &  buffer)

Appends span.

◆ append() [3/11]

WideString& WideString::append ( const NativeWideString string)
inline

Appends the NULL-terminated string to this string.

Parameters
stringThe string to be appended.

◆ append() [4/11]

WideString& WideString::append ( const NativeWideString string,
MemorySize  maximum 
)

Appends the NULL-terminated string to this string.

Parameters
stringThe string to be appended.
maximumThe maximum length of the string to be appended.

◆ append() [5/11]

WideString& WideString::append ( const String string)
inline

Appends the string to this string.

Parameters
stringThe string to be appended.

◆ append() [6/11]

WideString& WideString::append ( const wchar *  string)
inline

Appends the native string to this string.

Parameters
stringThe native string to be appended.

◆ append() [7/11]

WideString& WideString::append ( const wchar *  string,
MemorySize  maximum 
)

Appends the NULL-terminated string to this string.

Parameters
stringThe string to be appended.
maximumThe maximum length of the to be appended string.

◆ append() [8/11]

WideString& WideString::append ( const WideLiteral string)

Appends the string literal to this string.

Parameters
stringThe string to be appended.

◆ append() [9/11]

WideString& WideString::append ( const WideLiteral string,
MemorySize  maximum 
)

Appends the string literal to this string.

Parameters
stringThe string to be appended.
maximumThe maximum length of the string to be appended.

◆ append() [10/11]

WideString& WideString::append ( const WideString string)
inline

Appends the string to this string.

Parameters
stringThe string to be appended.

◆ append() [11/11]

WideString& WideString::append ( ucs4  ch)
inline

Appends the character to this string.

Parameters
chThe character to be appended.

◆ begin()

ReadIterator WideString::begin ( ) const
inlinenoexcept

Returns the first element of the string as a non-modifying iterator.

◆ clear()

void WideString::clear ( )

Clears the string.

◆ compareTo() [1/4]

int WideString::compareTo ( const NativeWideString string) const
inline

Compares this string with a NULL-terminated string.

Parameters
stringThe string to compare this string with.
Returns
Integer less than, equal to, or greater than zero if this string is found, respectively, to be less than, equal to, or greater than the specified string. False, if string is 0.

◆ compareTo() [2/4]

int WideString::compareTo ( const wchar *  string) const

Compares this string with NULL-terminated string.

Parameters
stringThe string to compare this string with.
Returns
Integer less than, equal to, or greater than zero if this string is found, respectively, to be less than, equal to, or greater than the specified string.

◆ compareTo() [3/4]

int WideString::compareTo ( const WideLiteral string) const

Compares this string to with string literal.

Parameters
stringThe string to compare this string with.
Returns
Integer less than, equal to, or greater than zero if this string is found, respectively, to be less than, equal to, or greater than the specified string.

◆ compareTo() [4/4]

int WideString::compareTo ( const WideString string) const
noexcept

Compare this string with another string.

Parameters
stringThe string to compare this string with.
Returns
Integer less than, equal to, or greater than zero if this string is found, respectively, to be less than, equal to, or greater than the specified string.

◆ compareToIgnoreCase() [1/2]

static int WideString::compareToIgnoreCase ( const ucs4 *  left,
const ucs4 *  right 
)
staticprotectednoexcept

Compare the NULL-terminated strings ignoring the case.

◆ compareToIgnoreCase() [2/2]

int WideString::compareToIgnoreCase ( const WideString string) const
noexcept

Compares this string with NULL-terminated string ignoring the case of the characters.

Parameters
stringThe string to compare this string with.
Returns
Integer less than, equal to, or greater than zero if this string is found, respectively, to be less than, equal to, or greater than the specified string.

◆ copy()

WideString WideString::copy ( ) const

Returns a forced copy of the string.

◆ count() [1/2]

MemorySize WideString::count ( const WideString string,
MemorySize  start = 0 
) const
noexcept

Counts the number of occurances of the specified substring in this string.

Parameters
stringThe substring to be counted.
startThe start position. Default is 0.
Returns
The number of occurances of the substring.

◆ count() [2/2]

MemorySize WideString::count ( ucs4  ch,
MemorySize  start = 0 
) const
noexcept

Returns the number of occurances of the specified character in this string.

Parameters
chThe character to be counted.
startThe start position. Default is 0.
Returns
The number of occurances of the character.

◆ end()

ReadIterator WideString::end ( ) const
inlinenoexcept

Returns the end of the string as a non-modifying iterator.

◆ endsWith() [1/3]

template<MemorySize SIZE>
bool WideString::endsWith ( const char(&)  suffix[SIZE]) const
inline

Returns true if this string ends with prefix.

Parameters
suffixThe string to compare end of this string with.

◆ endsWith() [2/3]

bool WideString::endsWith ( const WideLiteral suffix) const

Returns true if this string ends with the specified suffix.

Parameters
suffixThe string to compare end of this string with.

◆ endsWith() [3/3]

bool WideString::endsWith ( const WideString suffix) const

Returns true if this string ends with the specified suffix.

Parameters
suffixThe string to compare end of this string with.

◆ ensureCapacity()

void WideString::ensureCapacity ( MemorySize  capacity)

Ensures that the capacity of the buffer is at least equal to the specified minimum. This applies to all shared strings.

Parameters
capacitySpecifies the minimum capacity of the string.

◆ forceToLength()

void WideString::forceToLength ( MemorySize  length)

Sets the length of the string without initializing the elements.

◆ garbageCollect()

void WideString::garbageCollect ( )

Releases any unused capacity of the string. This applies to all shared strings.

◆ getAt()

ucs4 WideString::getAt ( MemorySize  index) const

Returns the character at the specified index in this string. Raises OutOfRange if index exceeds the length of the string.

◆ getBeginIterator()

Iterator WideString::getBeginIterator ( )
inlinenoexcept

Returns the first element of the string as a modifying iterator.

◆ getBeginReadIterator()

ReadIterator WideString::getBeginReadIterator ( ) const
inlinenoexcept

Returns the first element of the string as a non-modifying iterator.

◆ getBuffer() [1/3]

Char* WideString::getBuffer ( )
protected

Returns a modifiable buffer. Forces copy of internal buffer if shared by multiple strings.

◆ getBuffer() [2/3]

const Char* WideString::getBuffer ( ) const
inlineprotectednoexcept

Returns a non-modifiable buffer.

◆ getBuffer() [3/3]

Char* WideString::getBuffer ( MemorySize  length)
protected

Returns buffer for modification and resizes at the same time.

◆ getCapacity()

MemorySize WideString::getCapacity ( ) const
inlinenoexcept

Returns the capacity of the string.

◆ getContainer()

const Reference<ReferenceCountedAllocator<Char> >& WideString::getContainer ( ) const
inline

Returns the internal container.

◆ getElements() [1/2]

Char* WideString::getElements ( )

Returns NULL-terminated string for modifying access.

◆ getElements() [2/2]

const Char* WideString::getElements ( ) const
inlinenoexcept

Returns NULL-terminated string.

◆ getEnd()

const Char* WideString::getEnd ( ) const
inlinenoexcept

Returns the end of string.

◆ getEndIterator()

Iterator WideString::getEndIterator ( )
inlinenoexcept

Returns the end of the string as a modifying iterator.

◆ getEndReadIterator()

ReadIterator WideString::getEndReadIterator ( ) const
inlinenoexcept

Returns the end of the string as a non-modifying iterator.

◆ getEnumerator()

Enumerator WideString::getEnumerator ( )
inlinenoexcept

Returns a modifying enumerator of the string.

◆ getLength()

MemorySize WideString::getLength ( ) const
inlinenoexcept

Returns the number of characters in the string.

◆ getReadEnumerator()

ReadEnumerator WideString::getReadEnumerator ( ) const
inlinenoexcept

Returns a non-modifying enumerator of the string.

◆ getSpan()

ConstSpan<ucs4> WideString::getSpan ( ) const
inlinenoexcept

Returns the internal buffer.

◆ getValidUnicode()

WideString WideString::getValidUnicode ( bool  iso = false) const

Returns the string with all invalid Unicode codes removed.

@iso Specifies the ISO codes should be allowed.

◆ hasNull()

bool WideString::hasNull ( ) const
noexcept

Returns true if the NULL is used within the string.

◆ indexOf() [1/2]

MemoryDiff WideString::indexOf ( const WideString string,
MemorySize  start = 0 
) const
noexcept

Returns the index of the first substring that matches the specified string after the start position.

Parameters
stringThe substring to find.
startSpecifies the start position of the search. Default is 0.
Returns
Index of the first match if any otherwise -1. Also returns -1 if substring is empty.

◆ indexOf() [2/2]

MemoryDiff WideString::indexOf ( ucs4  ch,
MemorySize  start = 0 
) const
noexcept

Returns the index of the first character that matches the specified character after the start position.

Parameters
chThe character to find.
startSpecifies the start position of the search. Default is 0.
Returns
Index of the first match if any otherwise -1.

◆ initialize() [1/4]

void WideString::initialize ( const char *  string,
MemorySize  length 
)
protected

Initializes string.

◆ initialize() [2/4]

void WideString::initialize ( const char16_t *  string,
MemorySize  length 
)
protected

Initializes string.

◆ initialize() [3/4]

void WideString::initialize ( const ucs4 *  string,
MemorySize  length 
)
protected

Initializes string.

◆ initialize() [4/4]

void WideString::initialize ( const wchar *  string,
MemorySize  length 
)
protected

Initializes string.

◆ insert() [1/8]

WideString& WideString::insert ( MemorySize  index,
const char *  string 
)
inline

Inserts NULL-terminated string into this string.

Parameters
indexSpecifies the position to insert the string. If the index exceeds the end of this string the string is inserted at the end.
stringThe NULL-terminated string to be inserted.

◆ insert() [2/8]

WideString& WideString::insert ( MemorySize  index,
const ConstSpan< Char > &  span 
)

Inserts the span into this string.

Parameters
indexSpecifies the position to insert the character. If the index exceeds the end of this string the character is inserted at the end.
spanThe characters to be inserted.

◆ insert() [3/8]

WideString& WideString::insert ( MemorySize  index,
const ConstSpan< wchar > &  src 
)

Inserts the span into this string.

Parameters
indexSpecifies the position to insert the character. If the index exceeds the end of this string the character is inserted at the end.
spanThe characters to be inserted.

◆ insert() [4/8]

WideString& WideString::insert ( MemorySize  index,
const NativeWideString string 
)

Inserts NULL-terminated string into this string.

Parameters
indexSpecifies the position to insert the string. If the index exceeds the end of this string the string is inserted at the end.
stringThe NULL-terminated string to be inserted.

◆ insert() [5/8]

WideString& WideString::insert ( MemorySize  index,
const wchar *  string 
)
inline

Inserts NULL-terminated string into this string.

Parameters
indexSpecifies the position to insert the string. If the index exceeds the end of this string the string is inserted at the end.
stringThe NULL-terminated string to be inserted.

◆ insert() [6/8]

WideString& WideString::insert ( MemorySize  index,
const WideLiteral string 
)

Inserts the string literal into this string.

Parameters
indexSpecifies the position to insert the string. If the index exceeds the end of this string the string is inserted at the end.
stringThe string literal to be inserted.

◆ insert() [7/8]

WideString& WideString::insert ( MemorySize  index,
const WideString string 
)

Inserts the string into this string.

Parameters
indexSpecifies the position to insert the string. If the index exceeds the end of this string the string is inserted at the end.
stringThe string to be inserted.

◆ insert() [8/8]

WideString& WideString::insert ( MemorySize  index,
ucs4  ch 
)

Inserts the character into this string.

Parameters
indexSpecifies the position to insert the character. If the index exceeds the end of this string the character is inserted at the end.
chThe character to be inserted.

◆ invariant()

bool WideString::invariant ( ) const
inlinenoexcept

Returns true if state is valid.

◆ isASCII()

bool WideString::isASCII ( ) const
noexcept

Returns true if the string is an ASCII string.

◆ isEmpty()

bool WideString::isEmpty ( ) const
inlinenoexcept

Returns true if the string does not contain characters.

◆ isLowerCased()

bool WideString::isLowerCased ( ) const
noexcept

Returns true if the string is lower case.

◆ isMultiReferenced()

bool WideString::isMultiReferenced ( ) const
noexcept

Returns true if the string has multiple references.

◆ isProper()

bool WideString::isProper ( ) const
inlinenoexcept

Returns true if the string contains characters.

◆ isTitleCased()

bool WideString::isTitleCased ( ) const
noexcept

Returns true if the string is title cased.

◆ isUpperCased()

bool WideString::isUpperCased ( ) const
noexcept

Returns true if the string is upper cased.

◆ isValidUnicode()

bool WideString::isValidUnicode ( bool  iso = false) const
noexcept

Returns true if the string has valid Unicode codes.

@iso Specifies the ISO codes should be allowed.

◆ lastIndexOf() [1/4]

MemoryDiff WideString::lastIndexOf ( const WideString string) const
inlinenoexcept

Returns the index of the last string that matches the specified string starting from the end of the string.

Parameters
stringThe substring to find.
Returns
Index of the last match if any otherwide -1. Also returns -1 if the substring is empty.

◆ lastIndexOf() [2/4]

MemoryDiff WideString::lastIndexOf ( const WideString string,
MemorySize  start 
) const
noexcept

Returns the index of the last substring that matches the specified string before the start position.

Parameters
stringThe substring to find.
startSpecifies the start position of the search.
Returns
Index of the last match if any otherwise -1. Also returns -1 if substring is empty.

◆ lastIndexOf() [3/4]

MemoryDiff WideString::lastIndexOf ( ucs4  ch) const
inlinenoexcept

Returns the index of the last character that matches the specified character.

Parameters
chThe character to find.
Returns
Index of the last match if any otherwise -1.

◆ lastIndexOf() [4/4]

MemoryDiff WideString::lastIndexOf ( ucs4  ch,
MemorySize  start 
) const
noexcept

Returns the index of the last character that matches the specified character before the start position.

Parameters
chThe character to find.
startSpecifies the start position of the search. Default is end of string.
Returns
Index of the last match if any otherwise -1.

◆ makeCapacity()

static WideString WideString::makeCapacity ( MemorySize  capacity)
inlinestatic

Returns an empty string with the given capacity.

◆ makeLength()

static WideString WideString::makeLength ( MemorySize  length)
inlinestatic

Returns a new string of the given length.

◆ native()

const Char* WideString::native ( ) const
inlinenoexcept

Returns the characters of the string for non-modifying access.

◆ operator bool()

WideString::operator bool ( ) const
inlinenoexcept

Returns true if non-empty.

◆ operator!=()

bool WideString::operator!= ( const WideString string) const
inlinenoexcept

Inequality operator.

◆ operator+=() [1/6]

WideString& WideString::operator+= ( Char  suffix)
inline

Appends the character to this string.

Parameters
suffixThe character to be appended.

◆ operator+=() [2/6]

WideString& WideString::operator+= ( const NativeWideString suffix)
inline

Appends the string to this string.

Parameters
suffixThe character to be appended.

◆ operator+=() [3/6]

WideString& WideString::operator+= ( const String suffix)
inline

Appends the string to this string.

Parameters
suffixThe string to be appended.

◆ operator+=() [4/6]

WideString& WideString::operator+= ( const wchar *  suffix)
inline

Appends the string to this string.

Parameters
suffixThe character to be appended.

◆ operator+=() [5/6]

WideString& WideString::operator+= ( const WideLiteral suffix)
inline

Appends the literal to this string.

Parameters
suffixThe character to be appended.

◆ operator+=() [6/6]

WideString& WideString::operator+= ( const WideString suffix)
inline

Appends the string to this string.

Parameters
suffixThe string to be appended.

◆ operator-=()

WideString& WideString::operator-= ( const WideString suffix)

String reduction operator. Removes suffix from this string if and only if it ends with the suffix (e.g. ("presuf"-"suf") results in a new string "pre" whereas ("pre"-"suf") results in "pre").

Parameters
suffixThe suffix to be removed.

◆ operator<()

bool WideString::operator< ( const WideString string) const
inlinenoexcept

Less than operator.

◆ operator<=()

bool WideString::operator<= ( const WideString string) const
inlinenoexcept

Less than or equal operator.

◆ operator=() [1/10]

WideString& WideString::operator= ( const char *  assign)

Assignment of string to string.

◆ operator=() [2/10]

template<MemorySize SIZE>
WideString& WideString::operator= ( const Char(&)  literal[SIZE])
inline

Assignment of string to string.

◆ operator=() [3/10]

WideString& WideString::operator= ( const char16_t *  assign)

Assignment of string to string.

◆ operator=() [4/10]

WideString& WideString::operator= ( const char32_t *  assign)

Assignment of string to string.

◆ operator=() [5/10]

WideString& WideString::operator= ( const Literal assign)

Assignment of string to string.

◆ operator=() [6/10]

WideString& WideString::operator= ( const String assign)

Assignment of string to string.

◆ operator=() [7/10]

WideString& WideString::operator= ( const StringOutputStream assign)

Assignment of string to string.

◆ operator=() [8/10]

WideString& WideString::operator= ( const wchar *  assign)

Assignment of string to string.

◆ operator=() [9/10]

WideString& WideString::operator= ( const WideLiteral assign)

Assignment of string to string.

◆ operator=() [10/10]

WideString& WideString::operator= ( const WideString assign)
inlinenoexcept

Assignment of string to string.

◆ operator==() [1/2]

bool WideString::operator== ( const WideLiteral string) const
inlinenoexcept

Equality operator.

◆ operator==() [2/2]

bool WideString::operator== ( const WideString string) const
inlinenoexcept

Equality operator.

◆ operator>()

bool WideString::operator> ( const WideString string) const
inlinenoexcept

Greater than operator.

◆ operator>=()

bool WideString::operator>= ( const WideString string) const
inlinenoexcept

Greater than or equal operator.

◆ operator[]() [1/2]

Element WideString::operator[] ( MemorySize  index)
inline

Returns a reference to character at the specified index. Raises OutOfRange if index exceeds the length of the string.

◆ operator[]() [2/2]

char WideString::operator[] ( MemorySize  index) const
inline

Returns the character at the specified index. Raises OutOfRange if index exceeds the length of the string.

◆ prepend() [1/2]

WideString& WideString::prepend ( const WideString string)
inline

Prepends the string to this string.

Parameters
stringThe string to be prepended.

◆ prepend() [2/2]

WideString& WideString::prepend ( ucs4  ch)
inline

Prepends the character to this string.

Parameters
chThe character to be prepended.

◆ remove()

WideString& WideString::remove ( MemorySize  start,
MemorySize  end 
)

Removes the characters in a substring of this string.

Parameters
startSpecifies the start of the substring.
endSpecifies the end of the substring.

◆ removeAt()

WideString& WideString::removeAt ( MemorySize  index)
inline

Removes the character at the specified position in this string.

Parameters
indexSpecifies the character to be removed.

◆ removeFrom()

WideString& WideString::removeFrom ( MemorySize  start)

Removes the characters from the specified index to the end of the string.

Parameters
startSpecifies the start of the string.

◆ replace()

WideString& WideString::replace ( MemorySize  start,
MemorySize  end,
const WideString string 
)

Replaces the characters in a substring of this string with the characters in the specified string.

Parameters
startThe start of the substring.
endThe end of the substring.
stringThe string to replace with.

◆ replaceAll()

MemorySize WideString::replaceAll ( const WideString fromStr,
const WideString toStr 
)

Replaces all occurances of the specified substring with another string in this string. Only does one pass of this string.

Parameters
fromStrThe substring to be replaced.
toStrThe new string.
Returns
The number of substrings that was replaced.

◆ reverse()

WideString& WideString::reverse ( )
noexcept

The character sequence contained in this string is replaced by the reverse sequence.

◆ search()

MemoryDiff WideString::search ( const WideString substring,
MemorySize  start = 0 
) const
noexcept

Returns the index of the first substring that matches the specified string after the start position. The implementation is based on the "Boyer-Moore Fast String Searching Algorithm".

See also
indexOf
Parameters
stringThe substring to find.
startSpecifies the start position of the search. Default is 0.
Returns
Index of the first match if any otherwise -1. Also returns -1 if substring is empty.

◆ setAt()

void WideString::setAt ( MemorySize  index,
ucs4  value 
)

Sets the character at the specified index of this string. If the new character is the string terminator ('\0') then the string is cut off from the specified index. Raises OutOfRange if index exceeds the length of the string.

Parameters
indexThe index of the character to set.
valueThe new character value.

◆ setLength()

void WideString::setLength ( MemorySize  length)
inlineprotected

Sets the length of the string.

◆ split()

Array<WideString> WideString::split ( Char  separator,
bool  group = false 
) const

Returns the substrings between the specified separator.

Parameters
separatorSeparator.
groupGroup separators. Default is false.

◆ startsWith() [1/3]

template<MemorySize SIZE>
bool WideString::startsWith ( const Char(&)  prefix[SIZE]) const
inline

Returns true if this string starts with the specified prefix.

Parameters
prefixThe string to compare start of this string with.

◆ startsWith() [2/3]

bool WideString::startsWith ( const WideLiteral prefix) const

Returns true if this string starts with the specified prefix.

Parameters
prefixThe string to compare start of this string with.

◆ startsWith() [3/3]

bool WideString::startsWith ( const WideString prefix) const

Returns true if this string starts with the specified prefix.

Parameters
prefixThe string to compare start of this string with.

◆ substring() [1/2]

WideString WideString::substring ( MemorySize  start) const
inline

Returns a new string that contains a subsequence of characters currently contained in this string. The substring begins at the specified index and extends to the end of the string.

Parameters
startSpecifies the start of the substring.

◆ substring() [2/2]

WideString WideString::substring ( MemorySize  start,
MemorySize  end 
) const

Returns a new string that contains a subsequence of characters currently contained in this string. If 'end' is less than 'start' an empty string is returned.

Parameters
startSpecifies the start of the substring.
endSpecifies the end of the substring.

◆ toLowerCase()

WideString& WideString::toLowerCase ( )
noexcept

Converts the characters of this string into the lower case equivalents.

◆ toSpan()

static ConstSpan<wchar> WideString::toSpan ( const wchar *  string)
inlinestaticnoexcept

Returns the span.

◆ toUpperCase()

WideString& WideString::toUpperCase ( )
noexcept

Converts the characters of this string into the upper case equivalents.

◆ trim()

WideString& WideString::trim ( ucs4  character = ' ')

Trims the string.

Parameters
characterThe character to remove.

Member Data Documentation

◆ BOM

constexpr ucs4 WideString::BOM = 0x0000feff
staticconstexpr

Specifies the byte order mark.

◆ HASH_MODULUS

constexpr unsigned int WideString::HASH_MODULUS = 1455
staticconstexpr

Hash modulus.

◆ hashTable

const HashEntry WideString::hashTable[]
static

Character folding hash table.

◆ mappingTable

const uint32 WideString::mappingTable[]
static

Character mapping table for caseless matching.

◆ MAXIMUM_LENGTH

constexpr MemorySize WideString::MAXIMUM_LENGTH = (PrimitiveTraits<int>::MAXIMUM/sizeof(ucs4) - 1)
staticconstexpr

Specifies the maximum length of any string. Guarantees that an int can hold the length of the string.

◆ MAXIMUM_MULTIBYTES

constexpr unsigned int WideString::MAXIMUM_MULTIBYTES = 6
staticconstexpr

Specifies the maximum number of bytes per character for any supported encoding.

WideString
Wide-character string.
Definition: WideString.h:205