![]() |
XII Release 0.1.0
|
A string class for storing and passing around strings. More...
#include <String.h>
Public Member Functions | |
void | Clear () |
Resets this string to an empty string. | |
const char * | GetData () const |
Returns a pointer to the internal Utf8 string. | |
xiiUInt32 | GetElementCount () const |
Returns the amount of bytes that this string takes (excluding the '\0' terminator). | |
xiiUInt32 | GetCharacterCount () const |
Returns the number of characters in this string. Might be less than GetElementCount, if it contains Utf8 multi-byte characters. | |
xiiStringView | GetSubString (xiiUInt32 uiFirstCharacter, xiiUInt32 uiNumCharacters) const |
Returns a view to a sub-string of this string, starting at character uiFirstCharacter, up until uiFirstCharacter + uiNumCharacters. | |
xiiStringView | GetFirst (xiiUInt32 uiNumCharacters) const |
Returns a view to the sub-string containing the first uiNumCharacters characters of this string. | |
xiiStringView | GetLast (xiiUInt32 uiNumCharacters) const |
Returns a view to the sub-string containing the last uiNumCharacters characters of this string. | |
void | ReadAll (xiiStreamReader &ref_stream) |
Replaces the current string with the content from the stream. Reads the stream to its end. | |
xiiUInt64 | GetHeapMemoryUsage () const |
Returns the amount of bytes that are currently allocated on the heap. | |
![]() | |
bool | IsEmpty () const |
Returns whether the string is an empty string. | |
bool | StartsWith (xiiStringView sStartsWith) const |
Returns true, if this string starts with the given string. | |
bool | StartsWith_NoCase (xiiStringView sStartsWith) const |
Returns true, if this string starts with the given string. Case insensitive. | |
bool | EndsWith (xiiStringView sEndsWith) const |
Returns true, if this string ends with the given string. | |
bool | EndsWith_NoCase (xiiStringView sEndsWith) const |
Returns true, if this string ends with the given string. Case insensitive. | |
const char * | FindSubString (xiiStringView sStringToFind, const char *szStartSearchAt=nullptr) const |
const char * | FindSubString_NoCase (xiiStringView sStringToFind, const char *szStartSearchAt=nullptr) const |
const char * | FindLastSubString (xiiStringView sStringToFind, const char *szStartSearchAt=nullptr) const |
const char * | FindLastSubString_NoCase (xiiStringView sStringToFind, const char *szStartSearchAt=nullptr) const |
const char * | FindWholeWord (const char *szSearchFor, xiiStringUtils::XII_CHARACTER_FILTER isDelimiterCB, const char *szStartSearchAt=nullptr) const |
const char * | FindWholeWord_NoCase (const char *szSearchFor, xiiStringUtils::XII_CHARACTER_FILTER isDelimiterCB, const char *szStartSearchAt=nullptr) const |
xiiInt32 | Compare (xiiStringView sOther) const |
Compares this string with the other one. Returns 0 for equality, -1 if this string is 'smaller', 1 otherwise. | |
xiiInt32 | CompareN (xiiStringView sOther, xiiUInt32 uiCharsToCompare) const |
xiiInt32 | Compare_NoCase (xiiStringView sOther) const |
Compares this string with the other one. Returns 0 for equality, -1 if this string is 'smaller', 1 otherwise. Case insensitive. | |
xiiInt32 | CompareN_NoCase (xiiStringView sOther, xiiUInt32 uiCharsToCompare) const |
bool | IsEqual (xiiStringView sOther) const |
Compares this string with the other string for equality. | |
bool | IsEqualN (xiiStringView sOther, xiiUInt32 uiCharsToCompare) const |
Compares up to a given number of characters of this string with the other string for equality. Case insensitive. | |
bool | IsEqual_NoCase (xiiStringView sOther) const |
Compares this string with the other string for equality. | |
bool | IsEqualN_NoCase (xiiStringView sOther, xiiUInt32 uiCharsToCompare) const |
Compares up to a given number of characters of this string with the other string for equality. Case insensitive. | |
const char * | ComputeCharacterPosition (xiiUInt32 uiCharacterIndex) const |
Computes the pointer to the n-th character in the string. This is a linear search from the start. | |
iterator | GetIteratorFront () const |
Returns an iterator to this string, which points to the very first character. | |
reverse_iterator | GetIteratorBack () const |
Returns an iterator to this string, which points to the very last character (NOT the end). | |
operator xiiStringView () const | |
Returns a string view to this string's data. | |
xiiStringView | GetView () const |
Returns a string view to this string's data. | |
XII_ALWAYS_INLINE | operator const char * () const |
Returns a pointer to the internal Utf8 string. | |
void | Split (bool bReturnEmptyStrings, Container &ref_output, const char *szSeparator1, const char *szSeparator2=nullptr, const char *szSeparator3=nullptr, const char *szSeparator4=nullptr, const char *szSeparator5=nullptr, const char *szSeparator6=nullptr) const |
Fills the given container with xiiStringView's which represent each found substring. If bReturnEmptyStrings is true, even empty strings between separators are returned. Output must be a container that stores xiiStringView's and provides the functions 'Clear' and 'Append'. szSeparator1 to szSeparator6 are strings which act as separators and indicate where to split the string. This string itself will not be modified. | |
bool | HasAnyExtension () const |
Checks whether the given path has any file extension. | |
bool | HasExtension (xiiStringView sExtension) const |
Checks whether the given path ends with the given extension. szExtension should start with a '.' for performance reasons, but it will work without a '.' too. | |
xiiStringView | GetFileExtension (bool bFullExtension=false) const |
Returns the file extension of the given path. Will be empty, if the path does not end with a proper extension. | |
xiiStringView | GetFileName () const |
Returns the file name of a path, excluding the path and extension. | |
xiiStringView | GetFileNameAndExtension () const |
Returns the substring that represents the file name including the file extension. | |
xiiStringView | GetFileDirectory () const |
Returns the directory of the given file, which is the substring up to the last path separator. | |
bool | IsAbsolutePath () const |
Returns true, if the given path represents an absolute path on the current OS. | |
bool | IsRelativePath () const |
Returns true, if the given path represents a relative path on the current OS. | |
bool | IsRootedPath () const |
Returns true, if the given path represents a 'rooted' path. See xiiFileSystem for details. | |
xiiStringView | GetRootedPathRootName () const |
Extracts the root name from a rooted path. | |
Protected Member Functions | |
xiiHybridStringBase (xiiAllocatorBase *pAllocator) | |
Creates an empty string. | |
xiiHybridStringBase (const xiiHybridStringBase &rhs, xiiAllocatorBase *pAllocator) | |
Copies the data from rhs. | |
xiiHybridStringBase (xiiHybridStringBase &&rhs, xiiAllocatorBase *pAllocator) | |
Moves the data from rhs. | |
xiiHybridStringBase (const char *rhs, xiiAllocatorBase *pAllocator) | |
Copies the data from rhs. | |
xiiHybridStringBase (const wchar_t *rhs, xiiAllocatorBase *pAllocator) | |
Copies the data from rhs. | |
xiiHybridStringBase (const xiiStringView &rhs, xiiAllocatorBase *pAllocator) | |
Copies the data from rhs. | |
xiiHybridStringBase (const xiiStringBuilder &rhs, xiiAllocatorBase *pAllocator) | |
Copies the data from rhs. | |
xiiHybridStringBase (xiiStringBuilder &&rhs, xiiAllocatorBase *pAllocator) | |
Moves the data from rhs. | |
~xiiHybridStringBase () | |
Destructor. | |
void | operator= (const xiiHybridStringBase &rhs) |
Copies the data from rhs. | |
void | operator= (xiiHybridStringBase &&rhs) |
Moves the data from rhs. | |
void | operator= (const char *rhs) |
Copies the data from rhs. | |
void | operator= (const wchar_t *rhs) |
Copies the data from rhs. | |
void | operator= (const xiiStringView &rhs) |
Copies the data from rhs. | |
void | operator= (const xiiStringBuilder &rhs) |
Copies the data from rhs. | |
void | operator= (xiiStringBuilder &&rhs) |
Moves the data from rhs. | |
Friends | |
class | xiiStringBuilder |
Additional Inherited Members | |
![]() | |
using | iterator |
using | const_iterator |
using | reverse_iterator |
using | const_reverse_iterator |
A string class for storing and passing around strings.
This class only allows read-access to its data. It does not allow modifications. To build / modify strings, use the xiiStringBuilder class. xiiHybridString has an internal array to store short strings without any memory allocations, it will dynamically allocate additional memory, if that cache is insufficient. Thus a hybrid string will always take up a certain amount of memory, which might be of concern when it is used as a member variable, in such cases you might want to use an xiiHybridString with a very small internal array (1 would basically make it into a completely dynamic string). On the other hand, creating xiiHybridString instances on the stack and working locally with them, is quite fast. Prefer to use the aliased string types xiiString, xiiDynamicString, xiiString32 etc. Most strings in an application are rather short, typically shorter than 20 characters. Use xiiString, which is an aliased xiiHybridString to use a cache size that is sufficient for more than 90% of all use cases.
void xiiHybridStringBase< Size >::Clear | ( | ) |
Resets this string to an empty string.
This will not deallocate any previously allocated data, but reuse that memory.
XII_ALWAYS_INLINE xiiUInt32 xiiHybridStringBase< Size >::GetCharacterCount | ( | ) | const |
Returns the number of characters in this string. Might be less than GetElementCount, if it contains Utf8 multi-byte characters.
xiiStringView xiiHybridStringBase< Size >::GetFirst | ( | xiiUInt32 | uiNumCharacters | ) | const |
Returns a view to the sub-string containing the first uiNumCharacters characters of this string.
Note that this view will only be valid as long as this xiiHybridString lives. Once the original string is destroyed, all views to them will point into invalid memory.
xiiStringView xiiHybridStringBase< Size >::GetLast | ( | xiiUInt32 | uiNumCharacters | ) | const |
Returns a view to the sub-string containing the last uiNumCharacters characters of this string.
Note that this view will only be valid as long as this xiiHybridString lives. Once the original string is destroyed, all views to them will point into invalid memory.
xiiStringView xiiHybridStringBase< Size >::GetSubString | ( | xiiUInt32 | uiFirstCharacter, |
xiiUInt32 | uiNumCharacters ) const |
Returns a view to a sub-string of this string, starting at character uiFirstCharacter, up until uiFirstCharacter + uiNumCharacters.
Note that this view will only be valid as long as this xiiHybridString lives. Once the original string is destroyed, all views to them will point into invalid memory.