ezEngine  Release 25.03
ezHybridStringBase< Size > Struct Template Reference

A string class for storing and passing around strings. More...

#include <String.h>

Inheritance diagram for ezHybridStringBase< Size >:

Public Member Functions

void Clear ()
 Resets this string to an empty string. More...
 
const char * GetData () const
 Returns a pointer to the internal Utf8 string.
 
ezUInt32 GetElementCount () const
 Returns the amount of bytes that this string takes (excluding the '\0' terminator).
 
ezUInt32 GetCharacterCount () const
 Returns the number of characters in this string. Might be less than GetElementCount, if it contains Utf8 multi-byte characters. More...
 
ezStringView GetSubString (ezUInt32 uiFirstCharacter, ezUInt32 uiNumCharacters) const
 Returns a view to a sub-string of this string, starting at character uiFirstCharacter, up until uiFirstCharacter + uiNumCharacters. More...
 
ezStringView GetFirst (ezUInt32 uiNumCharacters) const
 Returns a view to the sub-string containing the first uiNumCharacters characters of this string. More...
 
ezStringView GetLast (ezUInt32 uiNumCharacters) const
 Returns a view to the sub-string containing the last uiNumCharacters characters of this string. More...
 
void ReadAll (ezStreamReader &inout_stream)
 Replaces the current string with the content from the stream. Reads the stream to its end.
 
ezUInt64 GetHeapMemoryUsage () const
 Returns the amount of bytes that are currently allocated on the heap.
 
- Public Member Functions inherited from ezStringBase< ezHybridStringBase< Size > >
bool IsEmpty () const
 Returns whether the string is an empty string.
 
bool StartsWith (ezStringView sStartsWith) const
 Returns true, if this string starts with the given string.
 
bool StartsWith_NoCase (ezStringView sStartsWith) const
 Returns true, if this string starts with the given string. Case insensitive.
 
bool EndsWith (ezStringView sEndsWith) const
 Returns true, if this string ends with the given string.
 
bool EndsWith_NoCase (ezStringView sEndsWith) const
 Returns true, if this string ends with the given string. Case insensitive.
 
const char * FindSubString (ezStringView sStringToFind, const char *szStartSearchAt=nullptr) const
 
const char * FindSubString_NoCase (ezStringView sStringToFind, const char *szStartSearchAt=nullptr) const
 
const char * FindLastSubString (ezStringView sStringToFind, const char *szStartSearchAt=nullptr) const
 
const char * FindLastSubString_NoCase (ezStringView sStringToFind, const char *szStartSearchAt=nullptr) const
 
const char * FindWholeWord (const char *szSearchFor, ezStringUtils::EZ_CHARACTER_FILTER isDelimiterCB, const char *szStartSearchAt=nullptr) const
 
const char * FindWholeWord_NoCase (const char *szSearchFor, ezStringUtils::EZ_CHARACTER_FILTER isDelimiterCB, const char *szStartSearchAt=nullptr) const
 
ezInt32 Compare (ezStringView sOther) const
 Compares this string with the other one. Returns 0 for equality, -1 if this string is 'smaller', 1 otherwise.
 
ezInt32 CompareN (ezStringView sOther, ezUInt32 uiCharsToCompare) const
 
ezInt32 Compare_NoCase (ezStringView sOther) const
 Compares this string with the other one. Returns 0 for equality, -1 if this string is 'smaller', 1 otherwise. Case insensitive.
 
ezInt32 CompareN_NoCase (ezStringView sOther, ezUInt32 uiCharsToCompare) const
 
bool IsEqual (ezStringView sOther) const
 Compares this string with the other string for equality.
 
bool IsEqualN (ezStringView sOther, ezUInt32 uiCharsToCompare) const
 Compares up to a given number of characters of this string with the other string for equality. Case insensitive.
 
bool IsEqual_NoCase (ezStringView sOther) const
 Compares this string with the other string for equality.
 
bool IsEqualN_NoCase (ezStringView sOther, ezUInt32 uiCharsToCompare) const
 Compares up to a given number of characters of this string with the other string for equality. Case insensitive.
 
const char * ComputeCharacterPosition (ezUInt32 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. More...
 
reverse_iterator GetIteratorBack () const
 Returns an iterator to this string, which points to the very last character (NOT the end). More...
 
 operator ezStringView () const
 Returns a string view to this string's data.
 
ezStringView GetView () const
 Returns a string view to this string's data.
 
EZ_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 ezStringView's which represent each found substring. If bReturnEmptyStrings is true, even empty strings between separators are returned. Output must be a container that stores ezStringView'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 (ezStringView 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.
 
ezStringView 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.
 
ezStringView GetFileName () const
 Returns the file name of a path, excluding the path and extension. More...
 
ezStringView GetFileNameAndExtension () const
 Returns the substring that represents the file name including the file extension. More...
 
ezStringView GetFileDirectory () const
 Returns the directory of the given file, which is the substring up to the last path separator. More...
 
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 ezFileSystem for details.
 
ezStringView GetRootedPathRootName () const
 Extracts the root name from a rooted path. More...
 

Protected Member Functions

 ezHybridStringBase (ezAllocator *pAllocator)
 Creates an empty string.
 
 ezHybridStringBase (const ezHybridStringBase &rhs, ezAllocator *pAllocator)
 Copies the data from rhs.
 
 ezHybridStringBase (ezHybridStringBase &&rhs, ezAllocator *pAllocator)
 Moves the data from rhs.
 
 ezHybridStringBase (const char *rhs, ezAllocator *pAllocator)
 Copies the data from rhs.
 
 ezHybridStringBase (const wchar_t *rhs, ezAllocator *pAllocator)
 Copies the data from rhs.
 
 ezHybridStringBase (const ezStringView &rhs, ezAllocator *pAllocator)
 Copies the data from rhs.
 
 ezHybridStringBase (const ezStringBuilder &rhs, ezAllocator *pAllocator)
 Copies the data from rhs.
 
 ezHybridStringBase (ezStringBuilder &&rhs, ezAllocator *pAllocator)
 Moves the data from rhs.
 
 ~ezHybridStringBase ()
 Destructor.
 
void operator= (const ezHybridStringBase &rhs)
 Copies the data from rhs.
 
void operator= (ezHybridStringBase &&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 ezStringView &rhs)
 Copies the data from rhs.
 
void operator= (const ezStringBuilder &rhs)
 Copies the data from rhs.
 
void operator= (ezStringBuilder &&rhs)
 Moves the data from rhs.
 

Friends

class ezStringBuilder
 

Additional Inherited Members

- Public Types inherited from ezStringBase< ezHybridStringBase< Size > >
using iterator = ezStringIterator
 
using const_iterator = ezStringIterator
 
using reverse_iterator = ezStringReverseIterator
 
using const_reverse_iterator = ezStringReverseIterator
 

Detailed Description

template<ezUInt16 Size>
struct ezHybridStringBase< Size >

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 ezStringBuilder class. ezHybridString 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 ezHybridString with a very small internal array (1 would basically make it into a completely dynamic string). On the other hand, creating ezHybridString instances on the stack and working locally with them, is quite fast. Prefer to use the typedef'd string types ezString, ezDynamicString, ezString32 etc. Most strings in an application are rather short, typically shorter than 20 characters. Use ezString, which is a typedef'd ezHybridString to use a cache size that is sufficient for more than 90% of all use cases.

Member Function Documentation

◆ Clear()

template<ezUInt16 Size>
void ezHybridStringBase< Size >::Clear

Resets this string to an empty string.

This will not deallocate any previously allocated data, but reuse that memory.

◆ GetCharacterCount()

template<ezUInt16 Size>
EZ_ALWAYS_INLINE ezUInt32 ezHybridStringBase< Size >::GetCharacterCount

Returns the number of characters in this string. Might be less than GetElementCount, if it contains Utf8 multi-byte characters.

Note
This is a slow operation, as it has to run through the entire string to count the Unicode characters. Only call this once and use the result as long as the string doesn't change. Don't call this in a loop.

◆ GetFirst()

template<ezUInt16 Size>
ezStringView ezHybridStringBase< Size >::GetFirst ( ezUInt32  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 ezHybridString lives. Once the original string is destroyed, all views to them will point into invalid memory.

◆ GetLast()

template<ezUInt16 Size>
ezStringView ezHybridStringBase< Size >::GetLast ( ezUInt32  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 ezHybridString lives. Once the original string is destroyed, all views to them will point into invalid memory.

◆ GetSubString()

template<ezUInt16 Size>
ezStringView ezHybridStringBase< Size >::GetSubString ( ezUInt32  uiFirstCharacter,
ezUInt32  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 ezHybridString lives. Once the original string is destroyed, all views to them will point into invalid memory.


The documentation for this struct was generated from the following files: