Base Framework
|
#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 ©) noexcept | |
String (String &&move) noexcept | |
String (StringOutputStream &stream) | |
String (FormatOutputStream &stream) | |
String & | operator= (const String &assign) noexcept |
String & | operator= (String &&move) noexcept |
String & | operator= (const Literal &assign) |
String & | operator= (const WideLiteral &assign) |
String & | operator= (const NativeString &assign) |
String & | operator= (const char *assign) |
String & | operator= (const wchar *assign) |
String & | operator= (const char16_t *assign) |
String & | operator= (const char32_t *assign) |
String & | operator= (const WideString &assign) |
String & | operator= (const StringOutputStream &assign) |
template<MemorySize SIZE> | |
String & | operator= (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 |
String & | remove (MemorySize start, MemorySize end) |
String & | removeFrom (MemorySize start) |
String & | removeAt (MemorySize index) |
String & | append (char ch) |
String & | append (uint8 ch) |
String & | append (ucs4 ch) |
String & | append (const String &string) |
String & | append (const NativeString &string) |
String & | append (const char *string) |
String & | append (const Literal &string) |
template<MemorySize SIZE> | |
String & | append (const char(&literal)[SIZE]) |
String & | append (const Literal &string, MemorySize maximum) |
String & | append (const NativeString &string, MemorySize maximum) |
String & | append (const ConstSpan< char > &buffer) |
String & | prepend (char ch) |
String & | prepend (const String &string) |
String & | insert (MemorySize index, const ConstSpan< char > &span) |
String & | insert (MemorySize index, char ch) |
String & | insert (MemorySize index, const String &string) |
String & | insert (MemorySize index, const Literal &string) |
template<MemorySize SIZE> | |
String & | insert (MemorySize index, const char(&literal)[SIZE]) |
String & | insert (MemorySize index, const NativeString &string) |
String & | replace (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 |
String & | operator+= (const String &suffix) |
String & | operator+= (const Literal &suffix) |
String & | operator+= (const char *suffix) |
String & | operator+= (char suffix) |
String & | operator-= (const String &suffix) |
String & | reverse () noexcept |
String & | toLowerCase () noexcept |
String & | toUpperCase () 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 |
String & | trim (char character=' ') |
MemoryDiff | search (const String &substring, MemorySize start=0) const noexcept |
Array< String > | split (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 |
String class. The first modifing operation on a string may force the internal buffer to be duplicated. The implementation is currently NOT MT-safe.
typedef CharTraits String::Traits |
Character specific properties and manipulators.
|
noexcept |
Initializes an empty string. No allocation done.
|
explicit |
Initializes a string with no characters in it and the given initial capacity.
capacity | The initial capacity. |
String::String | ( | Default | d | ) |
Forces a non-null empty string. Avoid this.
String::String | ( | const UTF8Stringify & | stringify | ) |
Initializes string.
String::String | ( | const OwnedNativeString & | string | ) |
Initializes string.
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.
string | The string. |
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.
string | The string. |
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.
string | The string. |
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.
string | The string. |
length | The length of the string. |
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.
string | The string. |
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.
string | The string. |
length | The length of the string. |
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.
string | The string. |
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.
string | The string. |
length | The length of the string. |
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.
string | The string. |
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.
string | The string. |
length | The length of the string. |
String::String | ( | const WideString & | string | ) |
Initializes the string from string.
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.
string | NULL-terminated string. If NULL, the string is initialized with no characters in it. |
maximum | Specifies the maximum length. |
|
inlinenoexcept |
Initializes string from other string.
|
inlinenoexcept |
Initializes string from other string.
String::String | ( | StringOutputStream & | stream | ) |
Initializes string from string output stream. Forces flush().
String::String | ( | FormatOutputStream & | stream | ) |
Initializes string from string output stream via FormatOutputStream. Forces flush(). Throws exception if not a StringOutputStream.
|
inline |
Appends the character to this string.
ch | The character to be appended. |
|
inline |
Appends the native string to this string.
string | The native string to be appended. |
Appends the string to this string.
string | The string to be appended. |
Appends the string literal to this string.
string | The string to be appended. |
maximum | The maximum length of the string to be appended. |
|
inline |
Appends the NULL-terminated string to this string.
string | The string to be appended. |
String& String::append | ( | const NativeString & | string, |
MemorySize | maximum | ||
) |
Appends the NULL-terminated string to this string.
string | The string to be appended. |
maximum | The maximum length of the string to be appended. |
Appends the string to this string.
string | The string to be appended. |
String& String::append | ( | ucs4 | ch | ) |
Appends the character to this string.
ch | The character to be appended. |
|
inline |
Appends the character to this string.
ch | The character to be appended. |
|
inlinenoexcept |
Returns the first element of the string as a non-modifying iterator.
void String::clear | ( | ) |
Clears the string.
|
noexcept |
Compares this string to with string literal.
string | The string to compare this string with. |
|
noexcept |
Compares this string with a NULL-terminated string.
string | The string to compare this string with. |
|
noexcept |
Compare this string with another string.
string | The string to compare this string with. |
|
staticprotectednoexcept |
Compare the NULL-terminated strings ignoring the case.
int String::compareToIgnoreCase | ( | const NativeString & | string | ) | const |
Compares this string with NULL-terminated string ignoring the case of the characters.
string | The string to compare this string with. |
|
noexcept |
Compares this string with other string ignoring the case of the characters.
string | The string to compare this string with. |
String String::copy | ( | ) | const |
Returns a forced copy of the string.
|
noexcept |
Returns the number of occurances of the specified character in this string.
ch | The character to be counted. |
start | The start position. Default is 0. |
|
noexcept |
Counts the number of occurances of the specified substring in this string.
string | The substring to be counted. |
start | The start position. Default is 0. |
|
inlinenoexcept |
Returns the end of the string as a non-modifying iterator.
|
inlinenoexcept |
Returns true if this string ends with prefix.
suffix | The string to compare end of this string with. |
|
noexcept |
Returns true if this string ends with the specified suffix.
suffix | The string to compare end of this string with. |
|
noexcept |
Returns true if this string ends with the specified suffix.
suffix | The string to compare end of this string with. |
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.
capacity | Specifies the minimum capacity of the string. |
void String::forceToLength | ( | MemorySize | length | ) |
Sets the length of the string without initializing the elements.
void String::garbageCollect | ( | ) |
Releases any unused capacity of the string. This applies to all shared strings.
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.
|
inlinenoexcept |
Returns the first element of the string as a modifying iterator.
|
inlinenoexcept |
Returns the first element of the string as a non-modifying iterator.
|
protected |
Returns a modifiable buffer. Forces copy of internal buffer if shared by multiple strings.
|
inlineprotectednoexcept |
Returns a non-modifiable buffer.
|
protected |
Returns buffer for modification and resizes at the same time.
|
inlinenoexcept |
Returns NULL-terminated string as bytes.
|
inlinenoexcept |
Returns the capacity of the string.
|
inline |
Returns the internal container.
char* String::getElements | ( | ) |
Returns NULL-terminated string for modifying access.
|
inlinenoexcept |
Returns NULL-terminated string.
|
inlinenoexcept |
Returns the end of string.
|
inlinenoexcept |
Returns the end of the string as a modifying iterator.
|
inlinenoexcept |
Returns the end of the string as a non-modifying iterator.
|
inlinenoexcept |
Returns a modifying enumerator of the string.
|
inlinenoexcept |
Returns the number of characters in the string.
|
inlinenoexcept |
Returns a non-modifying enumerator of the string.
|
inlinenoexcept |
Returns the internal buffer.
|
inlinenoexcept |
Returns the first element of the string as a non-modifying iterator.
|
inlinenoexcept |
Returns the end of the string as a non-modifying iterator.
|
inlinenoexcept |
Returns UTF-8 non-modifying enumerator.
|
inlinenoexcept |
Returns UTF-8 string.
String String::getValidUTF8 | ( | ) | const |
Returns a valid UTF-8 string by discarding bad codes.
|
noexcept |
Returns true if the NULL is used within the string.
|
noexcept |
Returns the index of the first character that matches the specified character after the start position.
ch | The character to find. |
start | Specifies the start position of the search. Default is 0. |
|
noexcept |
Returns the index of the first substring that matches the specified string after the start position.
string | The substring to find. |
start | Specifies the start position of the search. Default is 0. |
|
protected |
Initializes string.
|
protected |
Initializes string.
|
protected |
Initializes string.
|
protected |
Initializes string.
String& String::insert | ( | MemorySize | index, |
char | ch | ||
) |
Inserts the character into this string.
index | Specifies the position to insert the character. If the index exceeds the end of this string the character is inserted at the end. |
ch | The character to be inserted. |
Inserts the span into this string.
index | Specifies the position to insert the character. If the index exceeds the end of this string the character is inserted at the end. |
span | The characters to be inserted. |
Inserts the string literal into this string.
index | Specifies the position to insert the string. If the index exceeds the end of this string the string is inserted at the end. |
string | The string literal to be inserted. |
String& String::insert | ( | MemorySize | index, |
const NativeString & | string | ||
) |
Inserts NULL-terminated string into this string.
index | Specifies the position to insert the string. If the index exceeds the end of this string the string is inserted at the end. |
string | The NULL-terminated string to be inserted. |
Inserts the string into this string.
index | Specifies the position to insert the string. If the index exceeds the end of this string the string is inserted at the end. |
string | The string to be inserted. |
|
inlinenoexcept |
Returns true if state is valid.
|
noexcept |
Returns true if the string is an ASCII string.
|
inlinenoexcept |
Returns true if the string does not contain characters.
|
noexcept |
Returns true if the string has multiple references.
|
inlinenoexcept |
Returns true if the string contains characters.
|
inlinenoexcept |
Returns the index of the last character that matches the specified character.
ch | The character to find. |
|
noexcept |
Returns the index of the last character that matches the specified character before the start position.
ch | The character to find. |
start | Specifies the start position of the search. Default is end of string. |
|
inlinenoexcept |
Returns the index of the last string that matches the specified string starting from the end of the string.
string | The substring to find. |
|
noexcept |
Returns the index of the last substring that matches the specified string before the start position.
string | The substring to find. |
start | Specifies the start position of the search. |
|
inlinestatic |
Returns an empty string with the given capacity.
|
inlinestatic |
Returns a new string of the given length.
|
inlinenoexcept |
Returns the characters of the string for non-modifying access.
|
inlinenoexcept |
Returns true if non-empty.
|
inlinenoexcept |
Equality operator.
|
inlinenoexcept |
Inequality operator.
|
inlinenoexcept |
Inequality operator.
String String::operator() | ( | ARGS &&... | args | ) |
Substitutes string using % syntax.
|
inline |
Appends the character to this string.
suffix | The character to be appended. |
|
inline |
Appends the string to this string.
suffix | The character to be appended. |
Appends the literal to this string.
suffix | The character to be appended. |
Appends the string to this string.
suffix | The string to be appended. |
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").
suffix | The suffix to be removed. |
|
inlinenoexcept |
Less than operator.
|
inlinenoexcept |
Less than or equal operator.
String& String::operator= | ( | const char * | assign | ) |
Assignment of string to string.
|
inline |
Assignment of string to string.
String& String::operator= | ( | const char16_t * | assign | ) |
Assignment of string to string.
String& String::operator= | ( | const char32_t * | assign | ) |
Assignment of string to string.
String& String::operator= | ( | const NativeString & | assign | ) |
Assignment of string to string.
String& String::operator= | ( | const StringOutputStream & | assign | ) |
Assignment of string to string.
String& String::operator= | ( | const wchar * | assign | ) |
Assignment of string to string.
String& String::operator= | ( | const WideLiteral & | assign | ) |
Assignment of string to string.
String& String::operator= | ( | const WideString & | assign | ) |
Assignment of string to string.
|
inlinenoexcept |
Equality operator.
|
inlinenoexcept |
Equality operator.
|
inlinenoexcept |
Equality operator.
|
inlinenoexcept |
Greater than operator.
|
inlinenoexcept |
Greater than or equal operator.
|
inlinenoexcept |
Greater than or equal operator.
|
inline |
Returns a reference to character at the specified index. Raises OutOfRange if index exceeds the length of the string.
|
inline |
Returns the character at the specified index. Raises OutOfRange if index exceeds the length of the string.
|
inline |
Prepends the character to this string.
ch | The character to be prepended. |
Prepends the string to this string.
string | The string to be prepended. |
String& String::remove | ( | MemorySize | start, |
MemorySize | end | ||
) |
Removes the characters in a substring of this string.
start | Specifies the start of the substring. |
end | Specifies the end of the substring. |
|
inline |
Removes the character at the specified position in this string.
index | Specifies the character to be removed. |
String& String::removeFrom | ( | MemorySize | start | ) |
Removes the characters from the specified index to the end of the string.
start | Specifies the start of the string. |
Replaces the characters in a substring of this string with the characters in the specified string.
start | The start of the substring. |
end | The end of the substring. |
string | The string to replace with. |
Replaces all occurances of the specified substring with another string in this string. Only does one pass of this string.
fromStr | The substring to be replaced. |
toStr | The new string. |
|
noexcept |
The character sequence contained in this string is replaced by the reverse sequence.
|
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".
string | The substring to find. |
start | Specifies the start position of the search. Default is 0. |
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.
index | The index of the character to set. |
value | The new character value. |
|
inlineprotected |
Sets the length of the string.
|
inlinenoexcept |
Returns true if this string starts with the specified prefix.
prefix | The string to compare start of this string with. |
|
noexcept |
Returns true if this string starts with the specified prefix.
prefix | The string to compare start of this string with. |
|
noexcept |
Returns true if this string starts with the specified prefix.
prefix | The string to compare start of this string with. |
|
static |
Simple string substitution.
|
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.
start | Specifies the start of the substring. |
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.
start | Specifies the start of the substring. |
end | Specifies the end of the substring. |
|
noexcept |
Converts the characters of this string into the lower case equivalents.
|
inlinestaticnoexcept |
Returns the span.
|
noexcept |
Converts the characters of this string into the upper case equivalents.
String& String::trim | ( | char | character = ' ' | ) |
Trims the string.
character | The character to remove. |
|
static |
Specifies the maximum length of any string. Guarantees that an int can hold the length of the string.
|
static |
Specifies the string terminator.