Plasma Engine  2.0
Loading...
Searching...
No Matches
plHybridStringBase< Size > Struct Template Reference

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

#include <String.h>

Inheritance diagram for plHybridStringBase< Size >:

Public Member Functions

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

Protected Member Functions

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

Friends

class plStringBuilder
 

Additional Inherited Members

- Public Types inherited from plStringBase< plHybridStringBase< Size > >
using iterator
 
using const_iterator
 
using reverse_iterator
 
using const_reverse_iterator
 

Detailed Description

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

Member Function Documentation

◆ Clear()

template<plUInt16 Size>
void plHybridStringBase< Size >::Clear ( )

Resets this string to an empty string.

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

◆ GetCharacterCount()

template<plUInt16 Size>
PL_ALWAYS_INLINE plUInt32 plHybridStringBase< Size >::GetCharacterCount ( ) const

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<plUInt16 Size>
plStringView plHybridStringBase< Size >::GetFirst ( plUInt32 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 plHybridString lives. Once the original string is destroyed, all views to them will point into invalid memory.

◆ GetLast()

template<plUInt16 Size>
plStringView plHybridStringBase< Size >::GetLast ( plUInt32 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 plHybridString lives. Once the original string is destroyed, all views to them will point into invalid memory.

◆ GetSubString()

template<plUInt16 Size>
plStringView plHybridStringBase< Size >::GetSubString ( plUInt32 uiFirstCharacter,
plUInt32 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 plHybridString 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: