A thread-safe string class. More...
#include <libppbase/base/String.h>
Public Types | |
typedef traits::size_type | size_type |
data type for sizes | |
Public Member Functions | |
StringT () | |
Creates a new string. | |
StringT (const StringT &s) | |
Creates a new string containing s (copy constructor). | |
template<typename T > | |
StringT (T t) | |
Creates a new string from t. | |
StringT (const StringT &s, size_type pos, size_type len=npos) | |
Creates a new string containing len bytes of s starting from pos. | |
StringT (const charT *s, size_type len) | |
Creates a new string containing len bytes of s. | |
~StringT () | |
Destroys this string. | |
StringT & | append (charT ch) |
Appends ch to this string. | |
StringT & | append (double n) |
Appends n to this string. | |
StringT & | append (int n) |
Appends n to this string. | |
StringT & | append (unsigned int n) |
Appends n to this string. | |
StringT & | append (long n) |
Appends n to this string. | |
StringT & | append (unsigned long n) |
Appends n to this string. | |
StringT & | append (longlong_t n) |
Appends n to this string. | |
StringT & | append (u_longlong_t n) |
Appends n to this string. | |
StringT & | append (const StringT &s) |
Appends s to this string. | |
StringT & | append (const StringT &s, size_type pos, size_type len=npos) |
Appends len bytes of s starting at pos to this string. | |
StringT & | append (const charT *s) |
Appends s to this string. | |
StringT & | append (const charT *s, size_type len) |
Appends len bytes of s to this string. | |
StringT & | append (size_type n, charT ch) |
Appends n bytes of ch to this string. | |
StringT & | appendf (const charT *fmt,...) |
Appends data to this string. | |
StringT & | appendvf (const charT *fmt, va_list ap) |
Appends data to this string. | |
StringT & | assign (charT ch) |
Sets this string to ch. | |
StringT & | assign (double n) |
Sets this string to n. | |
StringT & | assign (int n) |
Sets this string to n. | |
StringT & | assign (unsigned int n) |
Sets this string to n. | |
StringT & | assign (long n) |
Sets this string to n. | |
StringT & | assign (unsigned long n) |
Sets this string to n. | |
StringT & | assign (longlong_t n) |
Sets this string to n. | |
StringT & | assign (u_longlong_t n) |
Sets this string to n. | |
StringT & | assign (const StringT &s) |
Sets this string to s. | |
StringT & | assign (const StringT &s, size_type pos, size_type len=npos) |
Sets this string to len bytes from pos of s. | |
StringT & | assign (const charT *s) |
Sets this string to s. | |
StringT & | assign (const charT *s, size_type len) |
Sets this string to the first len bytes of s. | |
StringT & | assignf (const charT *fmt,...) |
Sets this string. | |
StringT & | assignvf (const charT *fmt, va_list ap) |
Sets this string. | |
const charT * | c_str () const |
Returns the string as null-terminated C string. | |
size_type | capacity () const |
Returns the capacity of this string. | |
StringT & | clear () |
Clears the string. | |
int | compare (const StringT &s, bool icase=false) const |
Compares this string to another. | |
int | compare (const StringT &s, size_type pos, size_type len, bool icase=false) const |
Compares this string to the len bytes starting at pos of s. | |
int | compare (size_type pos, size_type len, const StringT &s, bool icase=false) const |
Compares the first len bytes starting at pos of this string to s. | |
int | compare (size_type pos, size_type len, const StringT &s, size_type spos, size_type slen, bool icase=false) const |
Compares the first len bytes starting at pos of this string to the first slen bytes starting at spos of s. | |
int | compare (const charT *s, bool icase=false) const |
Compares this string to s. | |
int | compare (const charT *s, size_type len, bool icase=false) const |
Compares this string to the first len bytes of s. | |
int | compare (size_type pos, size_type len, const charT *s, bool icase=false) const |
Compares the first len bytes starting at pos of this string to s. | |
int | compare (size_type pos, size_type len, const charT *s, size_type slen, bool icase=false) const |
Compares the first len bytes starting at pos of this string to the first slen bytes of s. | |
const charT * | data () const |
Returns the string as null-terminated C string. | |
bool | empty () const |
Checks if the string is empty. | |
StringT & | erase (size_type pos=0, size_type len=npos) |
Erases len bytes from pos. | |
StringT & | eraseAll (charT ch) |
Erases all ch from the string. | |
size_type | find (const StringT &s, size_type pos=0, bool icase=false) const |
Finds s in this string starting at pos possibly ignoring case. | |
size_type | find (const charT *s, size_type pos=0, bool icase=false) const |
Finds s in this string starting at pos possibly ignoring case. | |
size_type | find (const charT *s, size_type pos, size_type len, bool icase=false) const |
Finds s of length len in this string starting at pos possibly ignoring case. | |
size_type | find (charT ch, size_type pos=0) const |
Finds ch in this string starting at pos. | |
size_type | find_first_not_of (const StringT &s, size_type pos=0) const |
Finds the first character that is not contained in the search string. | |
size_type | find_first_not_of (const charT *s, size_type pos=0) const |
Finds the first character that is not contained in the search string. | |
size_type | find_first_not_of (const charT *s, size_type pos, size_type len) const |
Finds the first character that is not contained in the search string. | |
size_type | find_first_of (const StringT &s, size_type pos=0) const |
Finds the first character that is contained in the search string. | |
size_type | find_first_of (const charT *s, size_type pos=0) const |
Finds the first character that is contained in the search string. | |
size_type | find_first_of (const charT *s, size_type pos, size_type len) const |
Finds the first character that is contained in the search string. | |
size_type | find_first_of (charT ch, size_type pos=0) const |
Finds the first character that is contained in the search string. | |
size_type | find_last_not_of (const StringT &s, size_type pos=npos) const |
Finds the last character that is not contained in the search string. | |
size_type | find_last_not_of (const charT *s, size_type pos=npos) const |
Finds the last character that is not contained in the search string. | |
size_type | find_last_not_of (const charT *s, size_type pos, size_type len) const |
Finds the last character that is not contained in the search string. | |
size_type | find_last_of (const StringT &s, size_type pos=npos) const |
Finds one of the characters of s. | |
size_type | find_last_of (const charT *s, size_type pos=npos) const |
Finds one of the characters of s. | |
size_type | find_last_of (const charT *s, size_type pos, size_type len) const |
Finds one of the characters of s. | |
charT * | getBuffer () |
Returns the internal buffer. | |
charT | getCharAt (size_type pos) const |
Returns the character at positon pos. | |
StringT & | insert (size_type pos, charT ch) |
Inserts ch at position pos. | |
StringT & | insert (size_type pos, const StringT &s) |
Inserts s at position pos. | |
StringT & | insert (size_type pos, const charT *s) |
Inserts s at position pos. | |
StringT & | insert (size_type pos, const charT *s, size_type len) |
Inserts the first len bytes of s at position pos. | |
size_type | length () const |
Returns the string length. | |
StringT & | replace (size_type pos, size_type cnt, const StringT &s, size_type start=0, size_type len=npos) |
Replaces characters. | |
StringT & | replace (size_type pos, size_type cnt, const charT *s) |
Replaces characters. | |
StringT & | replace (size_type pos, size_type cnt, const charT *s, size_type len) |
Replaces characters. | |
StringT & | replaceAll (const StringT &oldstr, const StringT &newstr) |
Replaces old string with new string. | |
StringT & | replaceAll (charT oldch, charT newch) |
Replaces old character with new character. | |
void | resize (size_type n) |
Resizes the string buffer to n. | |
size_type | rfind (const StringT &s, size_type pos=npos, bool icase=false) const |
Searches backwards from the end of the string. | |
size_type | rfind (const charT *s, size_type pos=npos, bool icase=false) const |
Searches backwards from the end of the string. | |
size_type | rfind (const charT *s, size_type pos, size_type len, bool icase=false) const |
Searches backwards from the end of the string. | |
size_type | rfind (charT ch, size_type pos=npos) const |
Searches backwards from the end of the string. | |
void | setCharAt (size_type pos, charT ch) |
Sets the character at position pos to ch. | |
void | setLength (size_type len) |
Sets the length of the string. | |
size_type | size () const |
Returns the length of the string. | |
std::vector< StringT > | split (const charT *delim) const |
Splits a string into tokens. | |
charT * | stealBuffer (size_type *rlen=NULL, size_type *rsize=NULL) |
Hands over the internal buffer to the caller. The String is empty after this call. | |
StringT | substr (size_type pos=0, size_type len=npos) const |
Returns a substring of length len starting at pos. | |
StringT | left (size_type len) const |
Returns a substring of the len leftmost characters. | |
StringT & | ltrim () |
Removes whitespace at the beginning of the string. | |
StringT | right (size_type len) const |
Returns a substring of the len rightmost characters. | |
StringT & | rtrim () |
Removes whitespace at the end of the string. | |
StringT & | toLowerCase () |
Converts this string to lower case. | |
StringT & | toUpperCase () |
Converts this string to upper case. | |
StringT & | trim () |
removes leading and trailing whitespace | |
StringT & | trim (charT c) |
removes leading and trailing characters | |
void | useBuffer (charT *buf) |
Replace internal buffer with the one malloc'ed by caller (saves additional malloc). | |
void | useBuffer (charT *buf, size_type len, size_type bufsize) |
Replace internal buffer. | |
void | releaseBuffer () |
release internal buffer without freeing it (has to be freed elsewhere) | |
charT & | operator[] (size_type pos) |
Array operator (writable). | |
charT | operator[] (size_type pos) const |
Array operator (read-only). | |
operator void * () const | |
Void-Operator. | |
bool | operator! () const |
Returns true if the string is not empty. | |
StringT & | operator= (const StringT &s) |
Assignment operator. | |
template<typename T > | |
StringT & | operator= (T t) |
Assignment operator. | |
template<typename T > | |
StringT & | operator+= (T t) |
Concatenation operator. | |
bool | operator== (const StringT &s) const |
Equality operator. | |
bool | operator== (const charT *s) const |
Equality operator. | |
bool | operator!= (const StringT &s) const |
Not equal operator. | |
bool | operator!= (const charT *s) const |
Not equal operator. | |
bool | operator< (const StringT &s) const |
Less than. | |
bool | operator< (const charT *s) const |
Less than. | |
bool | operator<= (const StringT &s) const |
Less or equal than. | |
bool | operator<= (const charT *s) const |
Less or equal than. | |
bool | operator> (const StringT &s) const |
Greater than. | |
bool | operator> (const charT *s) const |
Greater than. | |
bool | operator>= (const StringT &s) const |
Greater or equal than. | |
bool | operator>= (const charT *s) const |
Greater or equal than. | |
Static Public Attributes | |
static const size_type | npos = static_cast<size_type>(-1) |
invalid position | |
Protected Attributes | |
charT * | _buf |
the string itself | |
size_type | _len |
length of the string in bytes | |
size_type | _size |
size of malloced memory in bytes |
A thread-safe string class.
StringT& base::StringT< charT, traits >::appendf | ( | const charT * | fmt, | |
... | ||||
) | [inline] |
Appends data to this string.
fmt | a printf-like format string | |
... | arguments for the format string |
StringT& base::StringT< charT, traits >::appendvf | ( | const charT * | fmt, | |
va_list | ap | |||
) | [inline] |
Appends data to this string.
fmt | a printf-like format string | |
ap | arguments for the format string |
Referenced by base::StringT< char >::appendf().
StringT& base::StringT< charT, traits >::assignf | ( | const charT * | fmt, | |
... | ||||
) | [inline] |
Sets this string.
fmt | a printf-like format string | |
... | arguments for the format string |
Referenced by base::StringT< char >::operator[]().
StringT& base::StringT< charT, traits >::assignvf | ( | const charT * | fmt, | |
va_list | ap | |||
) | [inline] |
Sets this string.
fmt | a printf-like format string | |
ap | arguments for the format string |
Referenced by base::StringT< char >::assignf().
int base::StringT< charT, traits >::compare | ( | const StringT< charT, traits > & | s, | |
bool | icase = false | |||
) | const [inline] |
Compares this string to another.
s | the string to compare to | |
icase | flag: ignore case |
Referenced by base::StringT< char >::compare(), base::StringT< char >::operator!=(), base::StringT< char >::operator<(), base::StringT< char >::operator<=(), base::StringT< char >::operator==(), base::StringT< char >::operator>(), and base::StringT< char >::operator>=().
StringT& base::StringT< charT, traits >::replaceAll | ( | const StringT< charT, traits > & | oldstr, | |
const StringT< charT, traits > & | newstr | |||
) | [inline] |
Replaces old string with new string.
oldstr | the old string | |
newstr | the string which shall be in place for the old one |
StringT& base::StringT< charT, traits >::replaceAll | ( | charT | oldch, | |
charT | newch | |||
) | [inline] |
Replaces old character with new character.
oldch | the old character | |
newch | the character which shall be in place for the old one |
std::vector<StringT> base::StringT< charT, traits >::split | ( | const charT * | delim | ) | const [inline] |
Splits a string into tokens.
delim | the delimiters |
charT* base::StringT< charT, traits >::stealBuffer | ( | size_type * | rlen = NULL , |
|
size_type * | rsize = NULL | |||
) | [inline] |
Hands over the internal buffer to the caller. The String is empty after this call.
rlen | if not NULL, returns the number of bytes used in the buffer | |
rsize | if not NULL, returns the size of the buffer if not null |
void base::StringT< charT, traits >::useBuffer | ( | charT * | buf | ) | [inline] |
Replace internal buffer with the one malloc'ed by caller (saves additional malloc).
This function can replace the following code with a more efficient one: Old code: char *buf = malloc(n); String s = buf; free(buf);
New code: String s; s.useBuffer(malloc(n),n,n);
Referenced by base::StringT< char >::useBuffer().