#include <string.h>
Public Member Functions | |
cstring () | |
Default onstructor. | |
cstring (char const *str) | |
Constructor initializing the encapsulated string. | |
cstring (char const *str, size_t len) | |
Constructor setting the encapsulated string to a portion of a string. | |
cstring (cstring const &cs) | |
Copy constructor. | |
cstring & | operator= (cstring const &right) |
Assignment operator (for cstring r-values). | |
cstring & | operator= (char const *right) |
Assigns a new string. | |
bool | operator== (char const *right) const |
Checks two strings for equality, byte-per-byte. | |
bool | operator!= (char const *right) const |
Checks two strings for difference, byte-per-byte. | |
operator char * () | |
Conversion operator (to char *). | |
operator char const * () const | |
Conversion operator (to const char *). | |
cstring & | assign (char const *str) |
Assigns a new string. | |
cstring & | assign (char const *str, size_t len) |
Assigns a limited portion of a string. | |
int | compare (char const *str) const |
Compares to a string, byte-per-byte. | |
int | compare (char const *str, size_t len) const |
Compares to a limited portion of a string, byte-per-byte. | |
char * | reserve (size_t size) |
Reserves a minimum size of writable memory. | |
void | swap (misc::cstring &str) |
Swaps encapsulated strings of two cstring objects. | |
char * | str () |
Returns The encapsulated string. | |
char const * | str () const |
Returns the encapsulated string (const version). |
This class is suitable for small memory requirements.
misc::cstring::cstring | ( | char const * | str | ) | [inline, explicit] |
This constructor initializes the encapsulated string to a duplicate of the given string.
[in] | str | The string to copy. |
misc::cstring::cstring | ( | char const * | str, | |
size_t | len | |||
) | [inline] |
This constructor initializes the encapsulated string to a duplicate of a limited portion of the given string.
[in] | str | The string to copy. If it is NULL, then the encapsulated string is set to NULL and len is ignored. |
[in] | len | The maximum number of characters to copy. |
cstring& misc::cstring::operator= | ( | char const * | right | ) | [inline] |
Assigns a new string to the encapsulated string. The old string is automatically freed.
[in] | right | The string to copy. |
bool misc::cstring::operator== | ( | char const * | right | ) | const |
Does a byte-per-byte comparison of the encapsulated string and the given one.
[in] | right | The string to compare to the encapsulated string. |
bool misc::cstring::operator!= | ( | char const * | right | ) | const [inline] |
Does a byte-per-byte comparison of the encapsulated string and the given one.
[in] | right | The string to compare to the encapsulated string. |
cstring& misc::cstring::assign | ( | char const * | str | ) | [inline] |
Assigns a new string to the encapsulated string. The old string is automatically freed.
[in] | str | The string to copy. May be NULL. |
cstring& misc::cstring::assign | ( | char const * | str, | |
size_t | len | |||
) | [inline] |
Assigns a limited portion of a string to the encapsulated string. The old string is automatically freed.
[in] | str | The string to copy. If it is NULL, then the encapsulated string is set to NULL and len is ignored. |
[in] | len | The maximum number of characters to copy. |
int misc::cstring::compare | ( | char const * | str | ) | const |
Compares a string with the encapsulated string, byte-per-byte.
[in] | str | The string to compare. |
int misc::cstring::compare | ( | char const * | str, | |
size_t | len | |||
) | const |
Compares a limited portion of a string with the encapsulated string, byte-per-byte.
[in] | str | The string to compare. |
[in] | len | The maximum number of characters to compare in the strings. |
char* misc::cstring::reserve | ( | size_t | size | ) |
Reserves a minimum size of writable memory for the enclosed string (this includes the NULL termination character). The contents of the string currently assigned is lost.
[in] | size | The size of the memory to reserve. Note that if this parameter has the value 0, then this function is an no-op. |
void misc::cstring::swap | ( | misc::cstring & | str | ) |
Swaps encapsulated strings of two cstring objects. This is more optimized than normal swapping since no reallocation is done, the encapsulated pointers are simply exchanged.
[in] | str | The string to swap. |