ezEngine  Milestone 7
ezHybridStringBase< Size > Class Template Reference

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

#include <String.h>

Inheritance diagram for ezHybridStringBase< Size >:

Public Member Functions

 operator ezStringView () const
 Returns a string view to this string's data.
 
 operator const char * () const
 Returns a pointer to the internal Utf8 string.
 
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.
 
ezStringView GetSubString (ezUInt32 uiFirstCharacter, ezUInt32 uiNumCharacters) const
 Returns an iterator to a sub-string of this string, starting at character uiFirstCharacter, up until uiFirstCharacter + uiNumCharacters. More...
 
ezStringView GetFirst (ezUInt32 uiNumCharacters) const
 Returns an iterator to the sub-string containing the first uiNumCharacters characters of this string. More...
 
ezStringView GetLast (ezUInt32 uiNumCharacters) const
 Returns an iterator to the sub-string containing the last uiNumCharacters characters of this string. More...
 
void ReadAll (ezStreamReaderBase &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 (const char *szStartsWith) const
 Returns true, if this string starts with the given string.
 
bool StartsWith_NoCase (const char *szStartsWith) const
 Returns true, if this string starts with the given string. Case insensitive.
 
bool EndsWith (const char *szEndsWith) const
 Returns true, if this string ends with the given string.
 
bool EndsWith_NoCase (const char *szEndsWith) const
 Returns true, if this string ends with the given string. Case insensitive.
 
const char * FindSubString (const char *szStringToFind, const char *szStartSearchAt=nullptr) const
 
const char * FindSubString_NoCase (const char *szStringToFind, const char *szStartSearchAt=nullptr) const
 
const char * FindLastSubString (const char *szStringToFind, const char *szStartSearchAt=nullptr) const
 
const char * FindLastSubString_NoCase (const char *szStringToFind, const char *szStartSearchAt=nullptr) const
 
const char * FindWholeWord (const char *szSearchFor, ezStringUtils::EZ_CHARACTER_FILTER IsDelimiterCB, const char *szStartSearchAt=nullptr) const
 Searches for the word szSearchFor. If IsDelimiterCB returns true for both characters in front and back of the word, the position is returned. Otherwise nullptr.
 
const char * FindWholeWord_NoCase (const char *szSearchFor, ezStringUtils::EZ_CHARACTER_FILTER IsDelimiterCB, const char *szStartSearchAt=nullptr) const
 Searches for the word szSearchFor. If IsDelimiterCB returns true for both characters in front and back of the word, the position is returned. Otherwise nullptr. Ignores case.
 
ezInt32 Compare (const char *pString2) const
 Compares this string with the other one. Returns 0 for equality, -1 if this string is 'smaller', 1 otherwise.
 
ezInt32 CompareN (const char *pString2, ezUInt32 uiCharsToCompare) const
 Compares up to a given number of characters of this string with the other one. Returns 0 for equality, -1 if this string is 'smaller', 1 otherwise.
 
ezInt32 Compare_NoCase (const char *pString2) 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 (const char *pString2, ezUInt32 uiCharsToCompare) const
 Compares up to a given number of characters of this string with the other one. Returns 0 for equality, -1 if this string is 'smaller', 1 otherwise. Case insensitive.
 
bool IsEqual (const char *pString2) const
 Compares this string with the other string for equality.
 
bool IsEqualN (const char *pString2, 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 (const char *pString2) const
 Compares this string with the other string for equality.
 
bool IsEqualN_NoCase (const char *pString2, 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...
 

Protected Member Functions

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

Private Attributes

ezHybridArray< char, Size > m_Data
 
ezUInt32 m_uiCharacterCount
 

Friends

class ezStringBuilder
 

Additional Inherited Members

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

Detailed Description

template<ezUInt16 Size>
class 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'ed 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'ed ezHybridString to use a cache size that is sufficient for more than 90% of all use cases.

Member Function Documentation

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.

template<ezUInt16 Size>
ezStringView ezHybridStringBase< Size >::GetFirst ( ezUInt32  uiNumCharacters) const

Returns an iterator to the sub-string containing the first uiNumCharacters characters of this string.

Note that this iterator will only be valid as long as this ezHybridString lives. Once the original string is destroyed, all iterators to them will point into invalid memory.

template<ezUInt16 Size>
ezStringView ezHybridStringBase< Size >::GetLast ( ezUInt32  uiNumCharacters) const

Returns an iterator to the sub-string containing the last uiNumCharacters characters of this string.

Note that this iterator will only be valid as long as this ezHybridString lives. Once the original string is destroyed, all iterators to them will point into invalid memory.

template<ezUInt16 Size>
ezStringView ezHybridStringBase< Size >::GetSubString ( ezUInt32  uiFirstCharacter,
ezUInt32  uiNumCharacters 
) const

Returns an iterator to a sub-string of this string, starting at character uiFirstCharacter, up until uiFirstCharacter + uiNumCharacters.

Note that this iterator will only be valid as long as this ezHybridString lives. Once the original string is destroyed, all iterators to them will point into invalid memory.


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