ezEngine  Milestone 7
ezStringView Class Reference

ezStringView represent a read-only sub-string of a larger string, as it can store a dedicated string end position. It derives from ezStringBase and thus provides a large set of functions for search and comparisons. More...

#include <StringView.h>

Inheritance diagram for ezStringView:

Public Member Functions

 ezStringView ()
 Default constructor creates an invalid view.
 
 ezStringView (const char *pStart)
 Creates a string view starting at the given position, ending at the next '\0' terminator.
 
 ezStringView (const char *pStart, const char *pEnd)
 Creates a string view for the range from pStart to pEnd.
 
void operator++ ()
 Advances the start to the next character, unless the end of the range was reached.
 
void operator+= (ezUInt32 d)
 Advances the start forwards by d characters. Does not move it beyond the range's end.
 
ezUInt32 GetCharacter () const
 Returns the first pointed to character in Utf32 encoding.
 
bool IsValid () const
 Returns true, if the current string pointed to is non empty.
 
const char * GetData () const
 Returns the string. May not be zero-terminated.
 
ezUInt32 GetElementCount () const
 Returns the number of bytes from the start position up to its end. More...
 
void SetStartPosition (const char *szCurPos)
 Allows to set the start position to a different value. More...
 
const char * GetStartPosition () const
 Returns the start of the view range.
 
const char * GetEndPosition () const
 Returns the end of the view range. This will point to the byte AFTER the last character. More...
 
bool IsEqual (const ezStringView &sOther) const
 Compares this string view with the other string view for equality.
 
bool IsEqual_NoCase (const ezStringView &sOther) const
 Compares this string view with the other string view for equality.
 
void Shrink (ezUInt32 uiShrinkCharsFront, ezUInt32 uiShrinkCharsBack)
 Shrinks the view range by uiShrinkCharsFront characters at the front and by uiShrinkCharsBack characters at the back. More...
 
void Trim (const char *szTrimChars)
 Removes all characters from the start and end that appear in the given strings by adjusting the begin and end of the view.
 
void Trim (const char *szTrimCharsStart, const char *szTrimCharsEnd)
 Removes all characters from the start and/or end that appear in the given strings by adjusting the begin and end of the view.
 
- Public Member Functions inherited from ezStringBase< ezStringView >
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...
 

Private Attributes

const char * m_pStart
 
const char * m_pEnd
 

Additional Inherited Members

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

Detailed Description

ezStringView represent a read-only sub-string of a larger string, as it can store a dedicated string end position. It derives from ezStringBase and thus provides a large set of functions for search and comparisons.

Attention: ezStringView does not store string data itself. It only stores pointers into memory. For example, when you get an ezStringView to an ezStringBuilder, the ezStringView instance will point to the exact same memory, enabling you to iterate over it (read-only). That means that an ezStringView is only valid as long as its source data is not modified. Once you make any kind of modification to the source data, you should not continue using the ezStringView to that data anymore, as it might now point into invalid memory.

Member Function Documentation

ezUInt32 ezStringView::GetElementCount ( ) const
inline

Returns the number of bytes from the start position up to its end.

Note
Note that the element count (bytes) may be larger than the number of characters in that string, due to Utf8 encoding.
const char* ezStringView::GetEndPosition ( ) const
inline

Returns the end of the view range. This will point to the byte AFTER the last character.

That means it might point to the '\0' terminator, UNLESS the view only represents a sub-string of a larger string. Accessing the value at 'GetEnd' has therefore no real use.

void ezStringView::SetStartPosition ( const char *  szCurPos)
inline

Allows to set the start position to a different value.

Must be between the current start and end range.

void ezStringView::Shrink ( ezUInt32  uiShrinkCharsFront,
ezUInt32  uiShrinkCharsBack 
)
inline

Shrinks the view range by uiShrinkCharsFront characters at the front and by uiShrinkCharsBack characters at the back.

Thus reduces the range of the view to a smaller sub-string. The current position is clamped to the new start of the range. The new end position is clamped to the new start of the range. If more characters are removed from the range, than it actually contains, the view range will become 'empty' and its state will be set to invalid, however no error or assert will be triggered.


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