StString Class Reference

Standard string class in the SmartTools library. More...

#include <ststring.h>

List of all members.

Public Member Functions

 StString ()
 StString (const StString &str)
 StString (const char *text)
 StString (const std::string &text)
 StString (char ch)
 StString (int i)
 StString (unsigned i)
 ~StString ()
void setText (const char *text)
void setText (const StString &text)
void setText (const std::string &text)
void setText (char ch)
void setText (int i)
void setText (unsigned i)
const char & at (unsigned index) const
char & at (unsigned index)
void add (char c)
unsigned length () const
bool empty () const
void clear ()
StString section (const StString &sep, int start, int end=0x7fffffff, bool allowEmptyEntires=false) const
StStringsprintf (const StString &format,...)
const char * c_str () const
int toInt ()
StString left (unsigned numChars) const
StString right (unsigned numChars) const
StString mid (unsigned index, unsigned numChars) const
int find (const StString &str, SmartTools::Position searchFrom=SmartTools::Left) const
unsigned contains (const StString &str)
StStringremove (const StString &str)
StStringoperator= (const char *text)
StStringoperator= (const StString &text)
StStringoperator= (const std::string &text)
StStringoperator= (char ch)
StStringoperator= (int i)
StStringoperator= (unsigned i)
StStringoperator+= (const StString &s)
StStringoperator+= (const std::string &s)
StStringoperator+= (const char *t)
StStringoperator+= (char c)
StStringoperator+= (int i)
StStringoperator+= (unsigned i)
StString operator+ (const StString &s) const
StString operator+ (const std::string &t) const
StString operator+ (const char *t) const
StString operator+ (char c) const
StString operator+ (int i) const
StString operator+ (unsigned i) const
bool operator== (const StString &s) const
bool operator!= (const StString &s) const
bool operator< (const StString &s) const
bool operator> (const StString &s) const
const char & operator[] (unsigned index) const
char & operator[] (unsigned index)
 operator std::string () const

Public Attributes

StSharedMemory memory

Private Member Functions

void init ()
template<typename I>
int countDigits (I num) const


Detailed Description

Standard string class in the SmartTools library.

This class is used everywhere in SmartTools where strings are needed. StString provides easy construction. You can construct an St class using a static string (without telling that you want StString to be created), const char*, char, int or std::string, and SmartTools will construct an StString.

StString allows you to access any char using the at() function or operator[] with length() to check how long your string is. You can remove() a substring, find() or count with contains(). If you want get a substring, use left(), right(), mid() or section() (this works similiarly to explode in php).


Constructor & Destructor Documentation

StString::StString (  )  [inline]

StString::StString ( const StString str  )  [inline]

StString::StString ( const char *  text  )  [inline]

StString::StString ( const std::string &  text  )  [inline]

StString::StString ( char  ch  )  [inline]

StString::StString ( int  i  )  [inline]

StString::StString ( unsigned  i  )  [inline]

StString::~StString (  ) 


Member Function Documentation

void StString::add ( char  c  ) 

Add one char to the string

char& StString::at ( unsigned  index  )  [inline]

const char& StString::at ( unsigned  index  )  const [inline]

const char* StString::c_str (  )  const [inline]

Returns:
const char* representation of the string

void StString::clear (  )  [inline]

unsigned StString::contains ( const StString str  ) 

Returns:
number of occurrence of str in string

template<typename I>
int StString::countDigits ( num  )  const [private]

bool StString::empty (  )  const [inline]

int StString::find ( const StString str,
SmartTools::Position  searchFrom = SmartTools::Left 
) const

Returns:
the first apperance of str or -1 if it isn't in the string
Parameters:
str String to find
searchFrom From which side begin to search?

void StString::init (  )  [private]

StString StString::left ( unsigned  numChars  )  const [inline]

Return stripped chars from left side. If the end of the string is reached it will return the whole string.

Parameters:
numChars number of chars
See also:
mid() right()

unsigned StString::length (  )  const [inline]

Returns the length of the string

StString StString::mid ( unsigned  index,
unsigned  numChars 
) const

Return stripped chars from the middle of the string. If the end of the string is reached it will returnthe string to the end.

Parameters:
index index of first char to return couting from 0
numChars number of chars
See also:
left() right()

StString::operator std::string (  )  const [inline]

bool StString::operator!= ( const StString s  )  const [inline]

StString StString::operator+ ( unsigned  i  )  const [inline]

StString StString::operator+ ( int  i  )  const [inline]

StString StString::operator+ ( char  c  )  const [inline]

StString StString::operator+ ( const char *  t  )  const [inline]

StString StString::operator+ ( const std::string &  t  )  const [inline]

StString StString::operator+ ( const StString s  )  const [inline]

StString& StString::operator+= ( unsigned  i  )  [inline]

StString& StString::operator+= ( int  i  )  [inline]

StString& StString::operator+= ( char  c  )  [inline]

StString& StString::operator+= ( const char *  t  )  [inline]

StString& StString::operator+= ( const std::string &  s  )  [inline]

StString & StString::operator+= ( const StString s  ) 

bool StString::operator< ( const StString s  )  const [inline]

StString& StString::operator= ( unsigned  i  )  [inline]

StString& StString::operator= ( int  i  )  [inline]

StString& StString::operator= ( char  ch  )  [inline]

StString& StString::operator= ( const std::string &  text  )  [inline]

StString& StString::operator= ( const StString text  )  [inline]

StString& StString::operator= ( const char *  text  )  [inline]

bool StString::operator== ( const StString s  )  const

bool StString::operator> ( const StString s  )  const [inline]

char& StString::operator[] ( unsigned  index  )  [inline]

const char& StString::operator[] ( unsigned  index  )  const [inline]

StString & StString::remove ( const StString str  ) 

Removes every occurrence of str in this string.

Returns:
reference to the string.

StString StString::right ( unsigned  numChars  )  const

Return stripped chars from right side. If the beginning of the string is reached it will return the whole string.

Parameters:
numChars number of chars
See also:
left() mid()

StString StString::section ( const StString sep,
int  start,
int  end = 0x7fffffff,
bool  allowEmptyEntires = false 
) const

Strip string using seperator sep and return parts starting from start to end.

Parameters:
sep - string seperator
start - if below zero, then work from finish to start
end - like start.
allowEmptyEntires - if true, two seperators next to themselves will create an empty element
StString names = "john|ann|kim|bob";

names.section( '|', 0,0 ); // returns john
names.section( '|', 1,1 ); // raturns ann
names.section( '|', 1 ); // returns ann|kim|bob

// from backwards
names.section( '|', -1 ); // returns bob

//this:
names.section( '|', -1, 1 ); // returns bob|kim|ann
// is equal to
names.section('|', 2, 0);

names.section('|', 0, -2); // returns john|ann|kim

// this returns whole string
names.section('|', 0);

void StString::setText ( unsigned  i  ) 

void StString::setText ( int  i  ) 

void StString::setText ( char  ch  ) 

void StString::setText ( const std::string &  text  )  [inline]

void StString::setText ( const StString text  ) 

void StString::setText ( const char *  text  ) 

StString & StString::sprintf ( const StString format,
  ... 
)

Works like sprintf from stdio.h but writes into a string. It erases the current content.

Note:
Check the third manual page of sprintf.

int StString::toInt (  )  [inline]

Try to convert current string to integer


Member Data Documentation

StSharedMemory StString::memory


The documentation for this class was generated from the following files:
Generated on Tue Nov 14 21:15:10 2006 for Smart Tools Library by  doxygen 1.4.7