STL string replacement.
Standard length doubling strategy allows for continued concatenation. Contains few of the algorithm functions (find_if, etc) but does have conversion from one string format to another. Also contains a Printf() function that creates a string from a standard C style format specifier, without the user having to know the maximum string length beforehand. There is no such thing as a NULL string representation; default constructor and construction from a NULL pointer both result in an empty string. If you must distinguish between empty and unset, use the Geo::Optional class.
Name | Description |
---|---|
T CharType | The character type of this string. |
Name | Description |
---|---|
~GeoString() | Destructor. |
Clear() | Clear the string. |
CopyTo(T *, s32) | Copies the content of this string to the given raw character buffer. |
Crop(s32) | Terminates the string at the given position. |
CropAfterLastChar(T) | This will remove the string beyond and including the last character specified if there is one. |
CropBeforeLastChar(T) | This will remove the string up to and including the last character specified if there is one. |
ForceLength(s32) | Directly sets the length of the string to the given value. |
FromUtf8(const char *) | Creates a new string of this format from a narrow string. |
GeoString() | Default constructor. |
GeoString(const T *) | Explicit constructor from a null-terminated array. |
GeoString(const T *, s32) | Explicit constructor from an array of size n. |
GeoString(s32) | Explicit constructor for an initial buffer length. |
GeoString(const GeoString &) | Copy constructor. |
GeoString(GeoString &&) | Move constructor. |
GetCapacity() | Returns the string capacity. |
GetCString() | Returns a const raw pointer to the string. |
GetLength() | Returns the length of the string. |
GetString() | Returns a non-const raw pointer to the string. |
IsEmpty() | Returns true if the string is empty. |
operator GeoStringView< T >() | Implicit conversion to string view. |
operator[](s32) | Element access operator. Do not use this to assign a terminator, or the string will very likely be corrupted. |
operator<(const GeoString &) | Comparison (required to use strings as keys in a map). |
Printf(const T *, ...) | Creates a string from a standard C style format specifier, without the user having to know the maximum string length beforehand. |
SetCapacity(s32) | Set the string capacity (increase only). |
Substring(Geo::s32, Geo::s32) | Returns a subsection of the string. |
Swap(GeoString &) | Swap places with other. |
ToUtf8() | Returns a new narrow string from this one. |
public: ~GeoString()
Destructor.
public: void Clear()
Clear the string.
public: s32 CopyTo
(
T * buffer,
s32 maxCharsToCopy
) const
Copies the content of this string to the given raw character buffer.
Note this does not
[in] | buffer | The destination buffer. |
[in] | maxCharsToCopy | If this is less than the length of the string then only this many characters will be copied. |
The number of characters copied.
public: bool Crop
(
s32 position
)
Terminates the string at the given position.
If position is less than the current length of the string it returns true, otherwise this is a no-op and returns false.
public: bool CropAfterLastChar
(
T c
)
This will remove the string beyond and including the last character specified if there is one.
If there isn't one it won't do anything.
True if the string was cropped.
public: bool CropBeforeLastChar
(
T c
)
This will remove the string up to and including the last character specified if there is one.
If there isn't one it won't do anything.
True if the string was cropped.
public: void ForceLength
(
s32 position
)
Directly sets the length of the string to the given value.
Useful for when the internal buffer is directly manipulated (after calling GetString()) and the stored length of the string needs to be kept in-sync.
public: GeoString FromUtf8
(
const char * utf8
)
Creates a new string of this format from a narrow string.
public: GeoString()
Default constructor.
public: GeoString
(
const T * str
)
Explicit constructor from a null-terminated array.
public: GeoString
(
const T * str,
s32 n
)
Explicit constructor from an array of size n.
public: GeoString
(
s32 capacity
)
Explicit constructor for an initial buffer length.
public: GeoString
(
const GeoString & rhs
)
Copy constructor.
public: GeoString
(
GeoString && rhs
)
Move constructor.
public: s32 GetCapacity() const
Returns the string capacity.
public: const T * GetCString() const
Returns a const raw pointer to the string.
public: s32 GetLength() const
Returns the length of the string.
public: T * GetString()
Returns a non-const raw pointer to the string.
public: bool IsEmpty() const
Returns true if the string is empty.
public: operator GeoStringView< T >() const
Implicit conversion to string view.
public: T operator[]
(
s32 idx
) const
Element access operator. Do not use this to assign a terminator, or the string will very likely be corrupted.
public: bool operator<
(
const GeoString & rhs
) const
Comparison (required to use strings as keys in a map).
public: GeoString Printf
(
const T * ,
...
)
Creates a string from a standard C style format specifier, without the user having to know the maximum string length beforehand.
public: bool SetCapacity
(
s32 minLength
)
Set the string capacity (increase only).
public: GeoString Substring
(
Geo::s32 idxBegin,
Geo::s32 idxEnd
) const
Returns a subsection of the string.
[in] | idxBegin | Index of first character of substring. |
[in] | idxEnd | Index of 'one past end' of substring. May specify -1 to mean 'end of string'. |
public: void Swap
(
GeoString & other
)
Swap places with other.
public: GeoString< char > ToUtf8() const
Returns a new narrow string from this one.