Public Types | Public Member Functions | Static Public Attributes | Protected Attributes

base::StringT< charT, traits > Class Template Reference

A thread-safe string class. More...

#include <libppbase/base/String.h>

List of all members.

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.
StringTappend (charT ch)
 Appends ch to this string.
StringTappend (double n)
 Appends n to this string.
StringTappend (int n)
 Appends n to this string.
StringTappend (unsigned int n)
 Appends n to this string.
StringTappend (long n)
 Appends n to this string.
StringTappend (unsigned long n)
 Appends n to this string.
StringTappend (longlong_t n)
 Appends n to this string.
StringTappend (u_longlong_t n)
 Appends n to this string.
StringTappend (const StringT &s)
 Appends s to this string.
StringTappend (const StringT &s, size_type pos, size_type len=npos)
 Appends len bytes of s starting at pos to this string.
StringTappend (const charT *s)
 Appends s to this string.
StringTappend (const charT *s, size_type len)
 Appends len bytes of s to this string.
StringTappend (size_type n, charT ch)
 Appends n bytes of ch to this string.
StringTappendf (const charT *fmt,...)
 Appends data to this string.
StringTappendvf (const charT *fmt, va_list ap)
 Appends data to this string.
StringTassign (charT ch)
 Sets this string to ch.
StringTassign (double n)
 Sets this string to n.
StringTassign (int n)
 Sets this string to n.
StringTassign (unsigned int n)
 Sets this string to n.
StringTassign (long n)
 Sets this string to n.
StringTassign (unsigned long n)
 Sets this string to n.
StringTassign (longlong_t n)
 Sets this string to n.
StringTassign (u_longlong_t n)
 Sets this string to n.
StringTassign (const StringT &s)
 Sets this string to s.
StringTassign (const StringT &s, size_type pos, size_type len=npos)
 Sets this string to len bytes from pos of s.
StringTassign (const charT *s)
 Sets this string to s.
StringTassign (const charT *s, size_type len)
 Sets this string to the first len bytes of s.
StringTassignf (const charT *fmt,...)
 Sets this string.
StringTassignvf (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.
StringTclear ()
 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.
StringTerase (size_type pos=0, size_type len=npos)
 Erases len bytes from pos.
StringTeraseAll (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.
StringTinsert (size_type pos, charT ch)
 Inserts ch at position pos.
StringTinsert (size_type pos, const StringT &s)
 Inserts s at position pos.
StringTinsert (size_type pos, const charT *s)
 Inserts s at position pos.
StringTinsert (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.
StringTreplace (size_type pos, size_type cnt, const StringT &s, size_type start=0, size_type len=npos)
 Replaces characters.
StringTreplace (size_type pos, size_type cnt, const charT *s)
 Replaces characters.
StringTreplace (size_type pos, size_type cnt, const charT *s, size_type len)
 Replaces characters.
StringTreplaceAll (const StringT &oldstr, const StringT &newstr)
 Replaces old string with new string.
StringTreplaceAll (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< StringTsplit (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.
StringTltrim ()
 Removes whitespace at the beginning of the string.
StringT right (size_type len) const
 Returns a substring of the len rightmost characters.
StringTrtrim ()
 Removes whitespace at the end of the string.
StringTtoLowerCase ()
 Converts this string to lower case.
StringTtoUpperCase ()
 Converts this string to upper case.
StringTtrim ()
 removes leading and trailing whitespace
StringTtrim (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.
StringToperator= (const StringT &s)
 Assignment operator.
template<typename T >
StringToperator= (T t)
 Assignment operator.
template<typename T >
StringToperator+= (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

Detailed Description

template<class charT, class traits = CharTraits<charT>>
class base::StringT< charT, traits >

A thread-safe string class.

Author:
Christoph Schwarz
Version:
Id:
String.h 21 2010-09-05 04:18:17Z cschwarz1

Member Function Documentation

template<class charT, class traits = CharTraits<charT>>
StringT& base::StringT< charT, traits >::appendf ( const charT *  fmt,
  ... 
) [inline]

Appends data to this string.

Parameters:
fmt a printf-like format string
... arguments for the format string
template<class charT, class traits = CharTraits<charT>>
StringT& base::StringT< charT, traits >::appendvf ( const charT *  fmt,
va_list  ap 
) [inline]

Appends data to this string.

Parameters:
fmt a printf-like format string
ap arguments for the format string

Referenced by base::StringT< char >::appendf().

template<class charT, class traits = CharTraits<charT>>
StringT& base::StringT< charT, traits >::assignf ( const charT *  fmt,
  ... 
) [inline]

Sets this string.

Parameters:
fmt a printf-like format string
... arguments for the format string

Referenced by base::StringT< char >::operator[]().

template<class charT, class traits = CharTraits<charT>>
StringT& base::StringT< charT, traits >::assignvf ( const charT *  fmt,
va_list  ap 
) [inline]

Sets this string.

Parameters:
fmt a printf-like format string
ap arguments for the format string

Referenced by base::StringT< char >::assignf().

template<class charT, class traits = CharTraits<charT>>
int base::StringT< charT, traits >::compare ( const StringT< charT, traits > &  s,
bool  icase = false 
) const [inline]

Compares this string to another.

Parameters:
s the string to compare to
icase flag: ignore case
Returns:
-1=this string is less, 1=this string is greater, 0=this string is equal to s

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>=().

template<class charT, class traits = CharTraits<charT>>
StringT& base::StringT< charT, traits >::replaceAll ( const StringT< charT, traits > &  oldstr,
const StringT< charT, traits > &  newstr 
) [inline]

Replaces old string with new string.

Parameters:
oldstr the old string
newstr the string which shall be in place for the old one
Returns:
a reference to the string
template<class charT, class traits = CharTraits<charT>>
StringT& base::StringT< charT, traits >::replaceAll ( charT  oldch,
charT  newch 
) [inline]

Replaces old character with new character.

Parameters:
oldch the old character
newch the character which shall be in place for the old one
Returns:
a reference to the string
template<class charT, class traits = CharTraits<charT>>
std::vector<StringT> base::StringT< charT, traits >::split ( const charT *  delim  )  const [inline]

Splits a string into tokens.

Parameters:
delim the delimiters
Returns:
the tokens
template<class charT, class traits = CharTraits<charT>>
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.

Parameters:
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
Returns:
the buffer, the caller must free the buffer when he does not need it any longer.
template<class charT, class traits = CharTraits<charT>>
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().


The documentation for this class was generated from the following file: