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
String Class Reference

String. More...

#include <base/string/String.h>

Inherited by StringInputStream [protected].

Classes

class  Default
 
class  UTF8String
 

Public Types

typedef CharTraits Traits
 
typedef ReferenceCountedAllocator< char >::Iterator Iterator
 
typedef ReferenceCountedAllocator< char >::ReadIterator ReadIterator
 
typedef ReferenceCountedAllocator< char >::Enumerator Enumerator
 
typedef ReferenceCountedAllocator< char >::ReadEnumerator ReadEnumerator
 

Public Member Functions

 String () noexcept
 
 String (Reference< ReferenceCountedAllocator< char > > string)
 
 String (MemorySize capacity)
 
 String (Default d)
 
 String (const UTF8Stringify &stringify)
 
 String (const OwnedNativeString &string)
 
 String (const NativeString &string)
 
 String (const Literal &string)
 
 String (const char *string)
 
 String (const char *string, MemorySize length)
 
 String (const wchar *string)
 
 String (const wchar *string, MemorySize length)
 
 String (const char16_t *string)
 
 String (const char16_t *string, MemorySize length)
 
 String (const char32_t *string)
 
 String (const char32_t *string, MemorySize length)
 
 String (const WideString &string)
 
 String (const NativeString &string, MemorySize maximum)
 
 String (const String &copy) noexcept
 
 String (String &&move) noexcept
 
 String (StringOutputStream &stream)
 
 String (FormatOutputStream &stream)
 
Stringoperator= (const String &assign) noexcept
 
Stringoperator= (String &&move) noexcept
 
Stringoperator= (const Literal &assign)
 
Stringoperator= (const WideLiteral &assign)
 
Stringoperator= (const NativeString &assign)
 
Stringoperator= (const char *assign)
 
Stringoperator= (const wchar *assign)
 
Stringoperator= (const char16_t *assign)
 
Stringoperator= (const char32_t *assign)
 
Stringoperator= (const WideString &assign)
 
Stringoperator= (const StringOutputStream &assign)
 
template<MemorySize SIZE>
Stringoperator= (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 ()
 
String 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
 
String getValidUTF8 () const
 
UTF8Iterator getUTF8BeginReadIterator () const noexcept
 
UTF8Iterator getUTF8EndReadIterator () const noexcept
 
UTF8Enumerator getUTF8ReadEnumerator () const noexcept
 
UTF8String getUTF8String () const noexcept
 
char getAt (MemorySize index) const
 
void setAt (MemorySize index, char value)
 
Element operator[] (MemorySize index)
 
 operator bool () const noexcept
 
char operator[] (MemorySize index) const
 
Stringremove (MemorySize start, MemorySize end)
 
StringremoveFrom (MemorySize start)
 
StringremoveAt (MemorySize index)
 
Stringappend (char ch)
 
Stringappend (uint8 ch)
 
Stringappend (ucs4 ch)
 
Stringappend (const String &string)
 
Stringappend (const NativeString &string)
 
Stringappend (const char *string)
 
Stringappend (const Literal &string)
 
template<MemorySize SIZE>
Stringappend (const char(&literal)[SIZE])
 
Stringappend (const Literal &string, MemorySize maximum)
 
Stringappend (const NativeString &string, MemorySize maximum)
 
Stringappend (const ConstSpan< char > &buffer)
 
Stringprepend (char ch)
 
Stringprepend (const String &string)
 
Stringinsert (MemorySize index, const ConstSpan< char > &span)
 
Stringinsert (MemorySize index, char ch)
 
Stringinsert (MemorySize index, const String &string)
 
Stringinsert (MemorySize index, const Literal &string)
 
template<MemorySize SIZE>
Stringinsert (MemorySize index, const char(&literal)[SIZE])
 
Stringinsert (MemorySize index, const NativeString &string)
 
Stringreplace (MemorySize start, MemorySize end, const String &string)
 
MemorySize replaceAll (const String &fromStr, const String &toStr)
 
String substring (MemorySize start, MemorySize end) const
 
String substring (MemorySize start) const
 
Stringoperator+= (const String &suffix)
 
Stringoperator+= (const Literal &suffix)
 
Stringoperator+= (const char *suffix)
 
Stringoperator+= (char suffix)
 
Stringoperator-= (const String &suffix)
 
Stringreverse () noexcept
 
StringtoLowerCase () noexcept
 
StringtoUpperCase () noexcept
 
int compareTo (const String &string) const noexcept
 
int compareTo (const Literal &string) const noexcept
 
int compareTo (const NativeString &string) const noexcept
 
int compareToIgnoreCase (const String &string) const noexcept
 
int compareToIgnoreCase (const NativeString &string) const
 
template<MemorySize SIZE>
int compareToIgnoreCase (const char(&literal)[SIZE]) const noexcept
 
bool startsWith (const String &prefix) const noexcept
 
bool startsWith (const Literal &prefix) const noexcept
 
template<MemorySize SIZE>
bool startsWith (const char(&prefix)[SIZE]) const noexcept
 
bool endsWith (const String &suffix) const noexcept
 
bool endsWith (const Literal &suffix) const noexcept
 
template<MemorySize SIZE>
bool endsWith (const char(&suffix)[SIZE]) const noexcept
 
bool operator== (const String &string) const noexcept
 
bool operator== (const Literal &string) const noexcept
 
template<MemorySize SIZE>
bool operator== (const char(&literal)[SIZE]) const noexcept
 
bool operator!= (const String &string) const noexcept
 
bool operator!= (const Literal &string) const noexcept
 
template<MemorySize SIZE>
bool operator!= (const char(&literal)[SIZE]) const noexcept
 
bool operator< (const String &string) const noexcept
 
template<MemorySize SIZE>
bool operator< (const char(&literal)[SIZE]) const noexcept
 
bool operator<= (const String &string) const noexcept
 
template<MemorySize SIZE>
bool operator<= (const char(&literal)[SIZE]) const noexcept
 
bool operator>= (const String &string) const noexcept
 
template<MemorySize SIZE>
bool operator>= (const char(&literal)[SIZE]) const noexcept
 
bool operator> (const String &string) const noexcept
 
template<MemorySize SIZE>
bool operator> (const char(&literal)[SIZE]) const noexcept
 
bool operator== (const NativeString &string) const noexcept
 
bool operator!= (const NativeString &string) const noexcept
 
bool operator< (const NativeString &string) const noexcept
 
bool operator<= (const NativeString &string) const noexcept
 
bool operator>= (const NativeString &string) const noexcept
 
bool operator> (const NativeString &string) const noexcept
 
MemoryDiff indexOf (char ch, MemorySize start=0) const noexcept
 
MemoryDiff indexOf (const String &string, MemorySize start=0) const noexcept
 
MemoryDiff lastIndexOf (char ch, MemorySize start) const noexcept
 
MemoryDiff lastIndexOf (char ch) const noexcept
 
MemoryDiff lastIndexOf (const String &string, MemorySize start) const noexcept
 
MemoryDiff lastIndexOf (const String &string) const noexcept
 
MemorySize count (char ch, MemorySize start=0) const noexcept
 
MemorySize count (const String &string, MemorySize start=0) const noexcept
 
Stringtrim (char character=' ')
 
MemoryDiff search (const String &substring, MemorySize start=0) const noexcept
 
Array< Stringsplit (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
 
const uint8 * getBytes () const noexcept
 
bool hasNull () const noexcept
 
ConstSpan< char > getSpan () const noexcept
 
const char * native () const noexcept
 
template<typename... ARGS>
String operator() (ARGS &&... args)
 

Static Public Member Functions

static String makeLength (MemorySize length)
 
static String makeCapacity (MemorySize capacity)
 
static ConstSpan< char > toSpan (const char *string) noexcept
 
static String substImpl (const UTF8Stringify &text, const UTF8Stringify *args, MemorySize numberOfArgs)
 

Static Public Attributes

static const char TERMINATOR = '\0'
 
static const MemorySize MAXIMUM_LENGTH = PrimitiveTraits<int>::MAXIMUM - sizeof(TERMINATOR)
 

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 char *left, const char *right) noexcept
 

Detailed Description

String.

String class. The first modifing operation on a string may force the internal buffer to be duplicated. The implementation is currently NOT MT-safe.

String myString = "Hello, World!";
String myOtherString = myString;
Version
1.0
Examples
testsuite/client.cpp, testsuite/digest.cpp, testsuite/du.cpp, testsuite/echod.cpp, testsuite/eval.cpp, testsuite/ftp.cpp, testsuite/http.cpp, testsuite/IEEE1394.cpp, testsuite/ln.cpp, testsuite/ls.cpp, testsuite/ping.cpp, testsuite/Quota.cpp, testsuite/rm.cpp, testsuite/sax.cpp, testsuite/server.cpp, testsuite/validate.cpp, and testsuite/xsltprocessor.cpp.

Member Typedef Documentation

◆ Traits

Character specific properties and manipulators.

Constructor & Destructor Documentation

◆ String() [1/21]

String::String ( )
noexcept

Initializes an empty string. No allocation done.

◆ String() [2/21]

String::String ( MemorySize  capacity)
explicit

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

Parameters
capacityThe initial capacity.

◆ String() [3/21]

String::String ( Default  d)

Forces a non-null empty string. Avoid this.

◆ String() [4/21]

String::String ( const UTF8Stringify stringify)

Initializes string.

◆ String() [5/21]

String::String ( const OwnedNativeString string)

Initializes string.

◆ String() [6/21]

String::String ( const NativeString string)

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

Parameters
stringThe string.

◆ String() [7/21]

String::String ( 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.

◆ String() [8/21]

String::String ( 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.

◆ String() [9/21]

String::String ( 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.

◆ String() [10/21]

String::String ( 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.

◆ String() [11/21]

String::String ( 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.

◆ String() [12/21]

String::String ( 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.

◆ String() [13/21]

String::String ( 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.

◆ String() [14/21]

String::String ( 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.

◆ String() [15/21]

String::String ( 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.

◆ String() [16/21]

String::String ( const WideString string)

Initializes the string from string.

◆ String() [17/21]

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

Initializes the string from a char. If you use \0 you will get a string of length 1 with the \0. 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.

◆ String() [18/21]

String::String ( const String copy)
inlinenoexcept

Initializes string from other string.

◆ String() [19/21]

String::String ( String &&  move)
inlinenoexcept

Initializes string from other string.

◆ String() [20/21]

String::String ( StringOutputStream stream)

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

◆ String() [21/21]

String::String ( FormatOutputStream stream)

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

Member Function Documentation

◆ append() [1/10]

String& String::append ( char  ch)
inline

Appends the character to this string.

Parameters
chThe character to be appended.

◆ append() [2/10]

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

Appends the native string to this string.

Parameters
stringThe native string to be appended.

◆ append() [3/10]

String& String::append ( const ConstSpan< char > &  buffer)

Appends span.

◆ append() [4/10]

String& String::append ( const Literal string)

Appends the string to this string.

Parameters
stringThe string to be appended.

◆ append() [5/10]

String& String::append ( const Literal 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() [6/10]

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

Appends the NULL-terminated string to this string.

Parameters
stringThe string to be appended.

◆ append() [7/10]

String& String::append ( const NativeString 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() [8/10]

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

Appends the string to this string.

Parameters
stringThe string to be appended.

◆ append() [9/10]

String& String::append ( ucs4  ch)

Appends the character to this string.

Parameters
chThe character to be appended.

◆ append() [10/10]

String& String::append ( uint8  ch)
inline

Appends the character to this string.

Parameters
chThe character to be appended.

◆ begin()

ReadIterator String::begin ( ) const
inlinenoexcept

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

◆ clear()

void String::clear ( )

Clears the string.

◆ compareTo() [1/3]

int String::compareTo ( const Literal string) const
noexcept

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() [2/3]

int String::compareTo ( const NativeString string) const
noexcept

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() [3/3]

int String::compareTo ( const String 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/3]

static int String::compareToIgnoreCase ( const char *  left,
const char *  right 
)
staticprotectednoexcept

Compare the NULL-terminated strings ignoring the case.

◆ compareToIgnoreCase() [2/3]

int String::compareToIgnoreCase ( const NativeString string) const

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.

◆ compareToIgnoreCase() [3/3]

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

Compares this string with other 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()

String String::copy ( ) const

Returns a forced copy of the string.

◆ count() [1/2]

MemorySize String::count ( char  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.

◆ count() [2/2]

MemorySize String::count ( const String 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.

◆ end()

ReadIterator String::end ( ) const
inlinenoexcept

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

◆ endsWith() [1/3]

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

Returns true if this string ends with prefix.

Parameters
suffixThe string to compare end of this string with.

◆ endsWith() [2/3]

bool String::endsWith ( const Literal suffix) const
noexcept

Returns true if this string ends with the specified suffix.

Parameters
suffixThe string to compare end of this string with.

◆ endsWith() [3/3]

bool String::endsWith ( const String suffix) const
noexcept

Returns true if this string ends with the specified suffix.

Parameters
suffixThe string to compare end of this string with.

◆ ensureCapacity()

void String::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 String::forceToLength ( MemorySize  length)

Sets the length of the string without initializing the elements.

◆ garbageCollect()

void String::garbageCollect ( )

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

◆ getAt()

char String::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 String::getBeginIterator ( )
inlinenoexcept

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

◆ getBeginReadIterator()

ReadIterator String::getBeginReadIterator ( ) const
inlinenoexcept

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

Examples
testsuite/ftp.cpp, and testsuite/http.cpp.

◆ getBuffer() [1/3]

char* String::getBuffer ( )
protected

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

◆ getBuffer() [2/3]

const char* String::getBuffer ( ) const
inlineprotectednoexcept

Returns a non-modifiable buffer.

◆ getBuffer() [3/3]

char* String::getBuffer ( MemorySize  length)
protected

Returns buffer for modification and resizes at the same time.

◆ getBytes()

const uint8* String::getBytes ( ) const
inlinenoexcept

Returns NULL-terminated string as bytes.

◆ getCapacity()

MemorySize String::getCapacity ( ) const
inlinenoexcept

Returns the capacity of the string.

◆ getContainer()

const Reference<ReferenceCountedAllocator<char> >& String::getContainer ( ) const
inline

Returns the internal container.

◆ getElements() [1/2]

char* String::getElements ( )

Returns NULL-terminated string for modifying access.

◆ getElements() [2/2]

const char* String::getElements ( ) const
inlinenoexcept

Returns NULL-terminated string.

◆ getEnd()

const char* String::getEnd ( ) const
inlinenoexcept

Returns the end of string.

◆ getEndIterator()

Iterator String::getEndIterator ( )
inlinenoexcept

Returns the end of the string as a modifying iterator.

◆ getEndReadIterator()

ReadIterator String::getEndReadIterator ( ) const
inlinenoexcept

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

Examples
testsuite/ftp.cpp, and testsuite/http.cpp.

◆ getEnumerator()

Enumerator String::getEnumerator ( )
inlinenoexcept

Returns a modifying enumerator of the string.

◆ getLength()

MemorySize String::getLength ( ) const
inlinenoexcept

Returns the number of characters in the string.

Examples
testsuite/ftp.cpp, and testsuite/ls.cpp.

◆ getReadEnumerator()

ReadEnumerator String::getReadEnumerator ( ) const
inlinenoexcept

Returns a non-modifying enumerator of the string.

◆ getSpan()

ConstSpan<char> String::getSpan ( ) const
inlinenoexcept

Returns the internal buffer.

◆ getUTF8BeginReadIterator()

UTF8Iterator String::getUTF8BeginReadIterator ( ) const
inlinenoexcept

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

◆ getUTF8EndReadIterator()

UTF8Iterator String::getUTF8EndReadIterator ( ) const
inlinenoexcept

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

◆ getUTF8ReadEnumerator()

UTF8Enumerator String::getUTF8ReadEnumerator ( ) const
inlinenoexcept

Returns UTF-8 non-modifying enumerator.

◆ getUTF8String()

UTF8String String::getUTF8String ( ) const
inlinenoexcept

Returns UTF-8 string.

◆ getValidUTF8()

String String::getValidUTF8 ( ) const

Returns a valid UTF-8 string by discarding bad codes.

◆ hasNull()

bool String::hasNull ( ) const
noexcept

Returns true if the NULL is used within the string.

◆ indexOf() [1/2]

MemoryDiff String::indexOf ( char  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.
Examples
testsuite/ftp.cpp, and testsuite/IEEE1394.cpp.

◆ indexOf() [2/2]

MemoryDiff String::indexOf ( const String 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.

◆ initialize() [1/4]

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

Initializes string.

◆ initialize() [2/4]

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

Initializes string.

◆ initialize() [3/4]

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

Initializes string.

◆ initialize() [4/4]

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

Initializes string.

◆ insert() [1/5]

String& String::insert ( MemorySize  index,
char  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.

◆ insert() [2/5]

String& String::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/5]

String& String::insert ( MemorySize  index,
const Literal 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() [4/5]

String& String::insert ( MemorySize  index,
const NativeString 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/5]

String& String::insert ( MemorySize  index,
const String 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.

◆ invariant()

bool String::invariant ( ) const
inlinenoexcept

Returns true if state is valid.

◆ isASCII()

bool String::isASCII ( ) const
noexcept

Returns true if the string is an ASCII string.

◆ isEmpty()

bool String::isEmpty ( ) const
inlinenoexcept

Returns true if the string does not contain characters.

Examples
testsuite/ftp.cpp, testsuite/http.cpp, and testsuite/ping.cpp.

◆ isMultiReferenced()

bool String::isMultiReferenced ( ) const
noexcept

Returns true if the string has multiple references.

◆ isProper()

bool String::isProper ( ) const
inlinenoexcept

Returns true if the string contains characters.

Examples
testsuite/http.cpp, testsuite/IEEE1394.cpp, and testsuite/sax.cpp.

◆ lastIndexOf() [1/4]

MemoryDiff String::lastIndexOf ( char  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() [2/4]

MemoryDiff String::lastIndexOf ( char  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.

◆ lastIndexOf() [3/4]

MemoryDiff String::lastIndexOf ( const String 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() [4/4]

MemoryDiff String::lastIndexOf ( const String 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.

◆ makeCapacity()

static String String::makeCapacity ( MemorySize  capacity)
inlinestatic

Returns an empty string with the given capacity.

Examples
testsuite/ftp.cpp.

◆ makeLength()

static String String::makeLength ( MemorySize  length)
inlinestatic

Returns a new string of the given length.

◆ native()

const char* String::native ( ) const
inlinenoexcept

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

◆ operator bool()

String::operator bool ( ) const
inlinenoexcept

Returns true if non-empty.

◆ operator!=() [1/3]

bool String::operator!= ( const Literal string) const
inlinenoexcept

Equality operator.

◆ operator!=() [2/3]

bool String::operator!= ( const NativeString string) const
inlinenoexcept

Inequality operator.

◆ operator!=() [3/3]

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

Inequality operator.

◆ operator()()

template<typename... ARGS>
String String::operator() ( ARGS &&...  args)

Substitutes string using % syntax.

◆ operator+=() [1/4]

String& String::operator+= ( char  suffix)
inline

Appends the character to this string.

Parameters
suffixThe character to be appended.

◆ operator+=() [2/4]

String& String::operator+= ( const char *  suffix)
inline

Appends the string to this string.

Parameters
suffixThe character to be appended.

◆ operator+=() [3/4]

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

Appends the literal to this string.

Parameters
suffixThe character to be appended.

◆ operator+=() [4/4]

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

Appends the string to this string.

Parameters
suffixThe string to be appended.

◆ operator-=()

String& String::operator-= ( const String 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<() [1/2]

bool String::operator< ( const NativeString string) const
inlinenoexcept

Less than operator.

◆ operator<() [2/2]

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

Less than operator.

◆ operator<=() [1/2]

bool String::operator<= ( const NativeString string) const
inlinenoexcept

Less than or equal operator.

◆ operator<=() [2/2]

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

Less than or equal operator.

◆ operator=() [1/11]

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

Assignment of string to string.

◆ operator=() [2/11]

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

Assignment of string to string.

◆ operator=() [3/11]

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

Assignment of string to string.

◆ operator=() [4/11]

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

Assignment of string to string.

◆ operator=() [5/11]

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

Assignment of string to string.

◆ operator=() [6/11]

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

Assignment of string to string.

◆ operator=() [7/11]

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

Assignment of string to string.

◆ operator=() [8/11]

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

Assignment of string to string.

◆ operator=() [9/11]

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

Assignment of string to string.

◆ operator=() [10/11]

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

Assignment of string to string.

◆ operator=() [11/11]

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

Assignment of string to string.

◆ operator==() [1/3]

bool String::operator== ( const Literal string) const
inlinenoexcept

Equality operator.

◆ operator==() [2/3]

bool String::operator== ( const NativeString string) const
inlinenoexcept

Equality operator.

◆ operator==() [3/3]

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

Equality operator.

◆ operator>() [1/2]

bool String::operator> ( const NativeString string) const
inlinenoexcept

Greater than operator.

◆ operator>() [2/2]

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

Greater than operator.

◆ operator>=() [1/2]

bool String::operator>= ( const NativeString string) const
inlinenoexcept

Greater than or equal operator.

◆ operator>=() [2/2]

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

Greater than or equal operator.

◆ operator[]() [1/2]

Element String::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 String::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]

String& String::prepend ( char  ch)
inline

Prepends the character to this string.

Parameters
chThe character to be prepended.

◆ prepend() [2/2]

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

Prepends the string to this string.

Parameters
stringThe string to be prepended.

◆ remove()

String& String::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()

String& String::removeAt ( MemorySize  index)
inline

Removes the character at the specified position in this string.

Parameters
indexSpecifies the character to be removed.

◆ removeFrom()

String& String::removeFrom ( MemorySize  start)

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

Parameters
startSpecifies the start of the string.

◆ replace()

String& String::replace ( MemorySize  start,
MemorySize  end,
const String 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 String::replaceAll ( const String fromStr,
const String 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()

String& String::reverse ( )
noexcept

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

◆ search()

MemoryDiff String::search ( const String 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 String::setAt ( MemorySize  index,
char  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 String::setLength ( MemorySize  length)
inlineprotected

Sets the length of the string.

◆ split()

Array<String> String::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 String::startsWith ( const char(&)  prefix[SIZE]) const
inlinenoexcept

Returns true if this string starts with the specified prefix.

Parameters
prefixThe string to compare start of this string with.

◆ startsWith() [2/3]

bool String::startsWith ( const Literal prefix) const
noexcept

Returns true if this string starts with the specified prefix.

Parameters
prefixThe string to compare start of this string with.

◆ startsWith() [3/3]

bool String::startsWith ( const String prefix) const
noexcept

Returns true if this string starts with the specified prefix.

Parameters
prefixThe string to compare start of this string with.

◆ substImpl()

static String String::substImpl ( const UTF8Stringify text,
const UTF8Stringify args,
MemorySize  numberOfArgs 
)
static

Simple string substitution.

◆ substring() [1/2]

String String::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]

String String::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.
Examples
testsuite/http.cpp, testsuite/IEEE1394.cpp, and testsuite/ls.cpp.

◆ toLowerCase()

String& String::toLowerCase ( )
noexcept

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

◆ toSpan()

static ConstSpan<char> String::toSpan ( const char *  string)
inlinestaticnoexcept

Returns the span.

◆ toUpperCase()

String& String::toUpperCase ( )
noexcept

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

◆ trim()

String& String::trim ( char  character = ' ')

Trims the string.

Parameters
characterThe character to remove.

Member Data Documentation

◆ MAXIMUM_LENGTH

const MemorySize String::MAXIMUM_LENGTH = PrimitiveTraits<int>::MAXIMUM - sizeof(TERMINATOR)
static

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

◆ TERMINATOR

const char String::TERMINATOR = '\0'
static

Specifies the string terminator.

String
String.
Definition: String.h:102