csStringBase Class Reference
This is a string class with a range of useful operators and type-safe overloads. More...
#include <csutil/csstring.h>
Inheritance diagram for csStringBase:

Public Member Functions | |
csStringBase & | Append (bool b) |
Append a boolean (as a number -- 1 or 0) to this string. | |
csStringBase & | Append (char c) |
Append a signed character to this string. | |
csStringBase & | Append (const csStringBase &Str, size_t Count=(size_t)-1) |
Append a string to this one. | |
csStringBase & | Append (const char *Str, size_t Count=(size_t)-1) |
Append a null-terminated C-string to this one. | |
csStringBase & | Clear () |
Clear the string (so that it contains only a null terminator). | |
csStringBase | Clone () const |
Get a copy of this string. | |
csStringBase & | Collapse () |
Trim leading and trailing whitespace, and collapse all internal whitespace to a single space. | |
bool | Compare (const char *iStr) const |
Check if a null-terminated C- string is equal to this string. | |
bool | Compare (const csStringBase &iStr) const |
Check if another string is equal to this one. | |
bool | CompareNoCase (const char *iStr) const |
Check if a null-terminated C- string is equal to this string. | |
bool | CompareNoCase (const csStringBase &iStr) const |
Check if another string is equal to this one. | |
csStringBase (unsigned char c) | |
Create a csStringBase object from a single unsigned character. | |
csStringBase (char c) | |
Create a csStringBase object from a single signed character. | |
csStringBase (const char *src, size_t _length) | |
Create a csStringBase object from a C string, given the length. | |
csStringBase (const char *src) | |
Create a csStringBase object from a null-terminated C string. | |
csStringBase (const csStringBase ©) | |
Copy constructor. | |
csStringBase (size_t Length) | |
Create a csStringBase object and reserve space for at least Length characters. | |
csStringBase () | |
Create an empty csStringBase object. | |
csStringBase & | DeleteAt (size_t Pos, size_t Count=1) |
Delete a range of characters from the string. | |
virtual char * | Detach () |
Detach the low-level null-terminated C-string buffer from the csString object. | |
csStringBase & | Downcase () |
Convert this string to lower-case. | |
csStringBase & | Empty () |
Clear the string (so that it contains only a null terminator). | |
size_t | Find (const char *search, size_t pos=0) const |
Find the first occurrence of search in this string starting at pos . | |
size_t | FindFirst (const char *c, size_t pos=0) const |
Find the first occurrence of any of a set of characters in the string. | |
size_t | FindFirst (char c, size_t pos=0) const |
Find the first occurrence of a character in the string. | |
size_t | FindLast (char c, size_t pos=(size_t)-1) const |
Find the last occurrence of a character in the string. | |
void | FindReplace (const char *search, const char *replacement) |
Find all occurrences of search in this string and replace them with replacement . | |
size_t | FindStr (const char *search, size_t pos=0) const |
Find the first occurrence of search in this string starting at pos . | |
csStringBase & | Format (const char *format,...) |
Format this string using cs_snprintf()-style formatting directives. | |
csStringBase & | FormatV (const char *format, va_list args) |
Format this string using cs_snprintf() formatting directives in a va_list. | |
virtual void | Free () |
Free the memory allocated for the string. | |
char | GetAt (size_t n) const |
Get the n'th character. | |
virtual size_t | GetCapacity () const |
Return the current capacity, not including the space for the implicit null terminator. | |
virtual char const * | GetData () const |
Get a pointer to the null-terminated character array. | |
char const * | GetDataSafe () const |
Get a pointer to the null-terminated character array. | |
size_t | GetGrowsBy () const |
Return the number of bytes by which the string grows. | |
bool | GetGrowsExponentially () const |
Returns true if exponential growth is enabled. | |
uint | GetHash () const |
GetHash() as expected by the default csHashComputer<> implementation to allow use of csStrings as hash keys. | |
csStringBase & | Insert (size_t Pos, char C) |
Insert another string into this one. | |
csStringBase & | Insert (size_t Pos, const char *Str) |
Insert another string into this one. | |
csStringBase & | Insert (size_t Pos, const csStringBase &Str) |
Insert another string into this one. | |
bool | IsEmpty () const |
Check if string is empty. | |
size_t | Length () const |
Query string length. | |
csStringBase & | LTrim () |
Trim leading whitespace. | |
operator const char * () const | |
Get a pointer to the null-terminated character array. | |
bool | operator!= (const char *Str) const |
Check if another string is not equal to this one. | |
bool | operator!= (const csStringBase &Str) const |
Check if another string is not equal to this one. | |
csStringBase | operator+ (const csStringBase &iStr) const |
Add another string to this one and return the result as a new string. | |
csStringBase & | operator+= (char const *s) |
template<typename T> | |
csStringBase & | operator+= (T const &s) |
Append a formatted value to this string. | |
bool | operator< (const char *Str) const |
Check if another string is less than this one. | |
bool | operator< (const csStringBase &Str) const |
Check if another string is less than this one. | |
csStringBase & | operator<< (char const *v) |
template<typename T> | |
csStringBase & | operator<< (T const &v) |
Shift operator. | |
template<typename T> | |
const csStringBase & | operator= (T const &s) |
Assign a formatted value to this string. | |
bool | operator== (const char *Str) const |
Check if another string is equal to this one. | |
bool | operator== (const csStringBase &Str) const |
Check if another string is equal to this one. | |
bool | operator> (const char *Str) const |
Check to see if a string is greater than this one. | |
bool | operator> (const csStringBase &Str) const |
Check to see if a string is greater than this one. | |
char | operator[] (size_t n) const |
Get n'th character. | |
char & | operator[] (size_t n) |
Get a modifiable reference to n'th character. | |
csStringBase & | Overwrite (size_t Pos, const csStringBase &Str) |
Overlay another string onto a part of this string. | |
csStringBase & | PadCenter (size_t NewSize, char PadChar= ' ') |
Pad to a specified size with leading and trailing characters so as to center the string. | |
csStringBase & | PadLeft (size_t NewSize, char PadChar= ' ') |
Pad to a specified size with leading characters. | |
csStringBase & | PadRight (size_t NewSize, char PadChar= ' ') |
Pad to a specified size with trailing characters. | |
csStringBase & | Reclaim () |
Set string buffer capacity to hold exactly the current content. | |
template<typename T> | |
csStringBase & | Replace (T const &val) |
Replace contents of this string with the value in formatted form. | |
csStringBase & | Replace (const char *Str, size_t Count=(size_t)-1) |
Replace contents of this string with the contents of another. | |
csStringBase & | Replace (const csStringBase &Str, size_t Count=(size_t)-1) |
Replace contents of this string with the contents of another. | |
void | ReplaceAll (const char *search, const char *replacement) |
Find all occurrences of search in this string and replace them with replacement . | |
csStringBase & | RTrim () |
Trim trailing whitespace. | |
void | SetAt (size_t n, const char c) |
Set the n'th character. | |
void | SetCapacity (size_t NewSize) |
Ask the string to allocate enough space to hold NewSize characters. | |
void | SetGrowsBy (size_t) |
Advise the string that it should grow its allocated buffer by approximately this many bytes when more space is required. | |
void | SetGrowsExponentially (bool b) |
Tell the string to re-size its buffer exponentially as needed. | |
virtual void | ShrinkBestFit () |
Set string buffer capacity to hold exactly the current content. | |
csStringBase | Slice (size_t start, size_t len=(size_t)-1) const |
Copy and return a portion of this string. | |
bool | StartsWith (const char *iStr, bool ignore_case=false) const |
Check if this string starts with a null-terminated C- string. | |
bool | StartsWith (const csStringBase &iStr, bool ignore_case=false) const |
Check if this string starts with another one. | |
void | SubString (csStringBase &sub, size_t start, size_t len=(size_t)-1) const |
Copy a portion of this string. | |
csStringBase & | Trim () |
Trim leading and trailing whitespace. | |
csStringBase & | Truncate (size_t Len) |
Truncate the string. | |
csStringBase & | Upcase () |
Convert this string to upper-case. | |
virtual | ~csStringBase () |
Destroy the csStringBase. | |
csStringBase & | Append (ulonglong v) |
csStringBase & | Append (longlong v) |
csStringBase & | Append (double v) |
csStringBase & | Append (float v) |
csStringBase & | Append (unsigned long v) |
csStringBase & | Append (long v) |
csStringBase & | Append (unsigned int v) |
csStringBase & | Append (int v) |
csStringBase & | Append (unsigned short v) |
csStringBase & | Append (short v) |
Append the value, in formatted form, to this string. | |
csStringBase & | AppendFmt (const char *format,...) |
Append a string formatted using cs_snprintf()-style formatting directives. | |
csStringBase & | AppendFmtV (const char *format, va_list args) |
Append a string formatted using cs_snprintf()-style formatting directives. | |
Protected Types | |
enum | |
Default number of bytes by which allocation should grow. More... | |
Protected Member Functions | |
size_t | ComputeNewSize (size_t NewSize) |
Compute a new buffer size. Takes GrowBy into consideration. | |
void | ExpandIfNeeded (size_t NewSize) |
If necessary, increase the buffer capacity enough to hold NewSize bytes. | |
virtual char * | GetDataMutable () |
Get a pointer to the null-terminated character array. | |
virtual void | SetCapacityInternal (size_t NewSize, bool soft) |
Set the buffer to hold NewSize bytes. | |
Protected Attributes | |
char * | Data |
String buffer. | |
size_t | GrowBy |
Size in bytes by which allocated buffer is increased when needed. | |
size_t | MaxSize |
Size in bytes of allocated string buffer. | |
size_t | Size |
Length of string; not including null terminator. |
Detailed Description
This is a string class with a range of useful operators and type-safe overloads.Strings may contain arbitary binary data, including null bytes. It also guarantees that a null-terminator always follows the last stored character, thus you can safely use the return value from GetData() and `operator char const*()' in calls to functions expecting C strings. The implicit null terminator is not included in the character count returned by Length().
Like a typical C character string pointer, csStringBase can also represent a null pointer. This allows a non-string to be distinguished from an empty (zero-length) string. The csStringBase will represent a null-pointer in the following cases:
- When constructed with no arguments (the default constructor).
- When constructed with an explicit null-pointer.
- When assigned a null-pointer via operator=((char const*)0).
- After an invocation of Replace((char const*)0).
- After invocation of csStringBase::Free() or any method which is documented as invoking Free() as a side-effect, such as ShrinkBestFit().
- After invocation of csStringBase::Detach().
Definition at line 53 of file csstring.h.
Member Enumeration Documentation
|
Default number of bytes by which allocation should grow. *** IMPORTANT *** This must be a power of two (i.e. 8, 16, 32, 64, etc.). Definition at line 60 of file csstring.h. |
Constructor & Destructor Documentation
|
Create an empty csStringBase object.
Definition at line 184 of file csstring.h. |
|
Create a csStringBase object and reserve space for at least
Definition at line 193 of file csstring.h. |
|
Copy constructor.
Definition at line 202 of file csstring.h. |
|
Create a csStringBase object from a null-terminated C string.
Definition at line 211 of file csstring.h. |
|
Create a csStringBase object from a C string, given the length.
Definition at line 220 of file csstring.h. |
|
Create a csStringBase object from a single signed character.
Definition at line 225 of file csstring.h. |
|
Create a csStringBase object from a single unsigned character.
Definition at line 230 of file csstring.h. |
|
Destroy the csStringBase.
|
Member Function Documentation
|
Append the value, in formatted form, to this string.
Definition at line 166 of file csstring.h. |
|
Append a boolean (as a number -- 1 or 0) to this string.
Definition at line 153 of file csstring.h. |
|
Append a signed character to this string.
|
|
Append a string to this one.
|
|
Append a null-terminated C-string to this one.
Referenced by csStringFast< LEN >::csStringFast(), operator+(), and operator+(). |
|
Append a string formatted using cs_snprintf()-style formatting directives.
|
|
Append a string formatted using cs_snprintf()-style formatting directives.
|
|
Clear the string (so that it contains only a null terminator).
Definition at line 334 of file csstring.h. |
|
Get a copy of this string.
Definition at line 681 of file csstring.h. Referenced by operator+(). |
|
Trim leading and trailing whitespace, and collapse all internal whitespace to a single space.
|
|
Check if a null-terminated C- string is equal to this string.
Definition at line 600 of file csstring.h. |
|
Check if another string is equal to this one.
Definition at line 582 of file csstring.h. References GetDataSafe(), and Length(). |
|
Check if a null-terminated C- string is equal to this string.
Definition at line 627 of file csstring.h. References csStrCaseCmp(). |
|
Check if another string is equal to this one.
Definition at line 609 of file csstring.h. References csStrNCaseCmp(), GetDataSafe(), and Length(). |
|
Compute a new buffer size. Takes GrowBy into consideration.
Referenced by csStringFast< LEN >::SetCapacityInternal(). |
|
Delete a range of characters from the string.
|
|
Detach the low-level null-terminated C-string buffer from the csString object.
Reimplemented in csStringFast< LEN >. Definition at line 890 of file csstring.h. Referenced by csStringFast< LEN >::Detach(). |
|
Convert this string to lower-case.
|
|
Clear the string (so that it contains only a null terminator).
Definition at line 304 of file csstring.h. |
|
If necessary, increase the buffer capacity enough to hold Buffer capacity is increased in GrowBy increments or exponentially depending upon configuration. |
|
Find the first occurrence of
|
|
Find the first occurrence of any of a set of characters in the string.
|
|
Find the first occurrence of a character in the string.
|
|
Find the last occurrence of a character in the string.
|
|
Find all occurrences of
Definition at line 526 of file csstring.h. |
|
Find the first occurrence of
Definition at line 511 of file csstring.h. |
|
Format this string using cs_snprintf()-style formatting directives.
Referenced by csIdentStrings::StringForIdent(). |
|
Format this string using cs_snprintf() formatting directives in a va_list.
Referenced by csDebugImageWriter::DebugImageWrite(). |
|
Free the memory allocated for the string.
Reimplemented in csStringFast< LEN >. Referenced by csStringFast< LEN >::Free(), and csStringFast< LEN >::ShrinkBestFit(). |
|
Get the n'th character.
Definition at line 401 of file csstring.h. References CS_ASSERT. |
|
Return the current capacity, not including the space for the implicit null terminator.
Reimplemented in csStringFast< LEN >. Definition at line 118 of file csstring.h. Referenced by csStringFast< LEN >::GetCapacity(). |
|
Get a pointer to the null-terminated character array.
Reimplemented in csStringFast< LEN >. Definition at line 343 of file csstring.h. |
|
Get a pointer to the null-terminated character array.
Reimplemented in csStringFast< LEN >. Definition at line 101 of file csstring.h. |
|
Get a pointer to the null-terminated character array.
Definition at line 355 of file csstring.h. Referenced by Compare(), CompareNoCase(), operator<(), operator>(), and StartsWith(). |
|
Return the number of bytes by which the string grows.
Definition at line 256 of file csstring.h. |
|
Returns true if exponential growth is enabled.
Definition at line 270 of file csstring.h. |
|
GetHash() as expected by the default csHashComputer<> implementation to allow use of csStrings as hash keys.
|
|
Insert another string into this one.
|
|
Insert another string into this one.
|
|
Insert another string into this one.
|
|
Check if string is empty.
Definition at line 371 of file csstring.h. |
|
Query string length.
Definition at line 363 of file csstring.h. Referenced by Compare(), CompareNoCase(), and StartsWith(). |
|
Trim leading whitespace.
|
|
Get a pointer to the null-terminated character array.
Definition at line 777 of file csstring.h. |
|
Check if another string is not equal to this one.
Definition at line 850 of file csstring.h. |
|
Check if another string is not equal to this one.
Definition at line 842 of file csstring.h. |
|
Add another string to this one and return the result as a new string.
Definition at line 767 of file csstring.h. References Append(). |
|
Append a formatted value to this string.
Definition at line 759 of file csstring.h. |
|
Check if another string is less than this one.
Definition at line 812 of file csstring.h. |
|
Check if another string is less than this one.
Definition at line 802 of file csstring.h. References GetDataSafe(). |
|
Shift operator. For example: s << "Hi " << name << ", see " << foo; Definition at line 861 of file csstring.h. |
|
Assign a formatted value to this string.
Reimplemented in csStringFast< LEN >. Definition at line 753 of file csstring.h. |
|
Check if another string is equal to this one.
Definition at line 794 of file csstring.h. |
|
Check if another string is equal to this one.
Definition at line 786 of file csstring.h. |
|
Check to see if a string is greater than this one.
Definition at line 832 of file csstring.h. |
|
Check to see if a string is greater than this one.
Definition at line 822 of file csstring.h. References GetDataSafe(). |
|
Get n'th character.
Definition at line 382 of file csstring.h. References CS_ASSERT. |
|
Get a modifiable reference to n'th character.
Definition at line 375 of file csstring.h. References CS_ASSERT. |
|
Overlay another string onto a part of this string.
|
|
Pad to a specified size with leading and trailing characters so as to center the string.
|
|
Pad to a specified size with leading characters.
|
|
Pad to a specified size with trailing characters.
|
|
Set string buffer capacity to hold exactly the current content.
Definition at line 326 of file csstring.h. |
|
Replace contents of this string with the value in formatted form.
Definition at line 574 of file csstring.h. |
|
Replace contents of this string with the contents of another.
|
|
Replace contents of this string with the contents of another.
Referenced by csVfsDirectoryChanger::ChangeTo(), csStringFast< 0 >::operator=(), and csStringFast< LEN >::operator=(). |
|
Find all occurrences of
|
|
Trim trailing whitespace.
|
|
Set the n'th character.
Definition at line 394 of file csstring.h. References CS_ASSERT. |
|
Ask the string to allocate enough space to hold
Referenced by csStringFast< LEN >::csStringFast(). |
|
Set the buffer to hold NewSize bytes. If soft is true it means the buffer can be rounded up to reduce the number of allocations needed. Reimplemented in csStringFast< LEN >. Referenced by csStringFast< LEN >::SetCapacityInternal(). |
|
Advise the string that it should grow its allocated buffer by approximately this many bytes when more space is required. This is an optimization to avoid excessive memory reallocation and heap management, which can be quite slow.
|
|
Tell the string to re-size its buffer exponentially as needed.
Definition at line 263 of file csstring.h. |
|
Set string buffer capacity to hold exactly the current content.
Reimplemented in csStringFast< LEN >. Referenced by csStringFast< LEN >::ShrinkBestFit(). |
|
Copy and return a portion of this string.
|
|
Check if this string starts with a null-terminated C- string.
Definition at line 659 of file csstring.h. References CS_ASSERT, and csStrNCaseCmp(). |
|
Check if this string starts with another one.
Definition at line 636 of file csstring.h. References CS_ASSERT, csStrNCaseCmp(), GetDataSafe(), and Length(). |
|
Copy a portion of this string.
|
|
Trim leading and trailing whitespace.
|
|
Truncate the string.
|
|
Convert this string to upper-case.
|
Member Data Documentation
|
String buffer.
Definition at line 63 of file csstring.h. Referenced by csStringFast< LEN >::Detach(), csStringFast< LEN >::GetCapacity(), csStringFast< LEN >::GetData(), csStringFast< LEN >::GetDataMutable(), csStringFast< LEN >::SetCapacityInternal(), and csStringFast< LEN >::ShrinkBestFit(). |
|
Size in bytes by which allocated buffer is increased when needed. If this value is zero, then growth occurs exponentially by doubling the size. Definition at line 72 of file csstring.h. |
|
Size in bytes of allocated string buffer.
Definition at line 67 of file csstring.h. Referenced by csStringFast< LEN >::Detach(), and csStringFast< LEN >::SetCapacityInternal(). |
|
Length of string; not including null terminator.
Definition at line 65 of file csstring.h. Referenced by csStringFast< LEN >::Detach(), csStringFast< LEN >::SetCapacityInternal(), and csStringFast< LEN >::ShrinkBestFit(). |
The documentation for this class was generated from the following file:
- csutil/csstring.h
Generated for Crystal Space by doxygen 1.4.4