#include <ststring.h>
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 |
StString & | sprintf (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) |
StString & | remove (const StString &str) |
StString & | operator= (const char *text) |
StString & | operator= (const StString &text) |
StString & | operator= (const std::string &text) |
StString & | operator= (char ch) |
StString & | operator= (int i) |
StString & | operator= (unsigned i) |
StString & | operator+= (const StString &s) |
StString & | operator+= (const std::string &s) |
StString & | operator+= (const char *t) |
StString & | operator+= (char c) |
StString & | operator+= (int i) |
StString & | operator+= (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 |
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).
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 | ( | ) |
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] |
void StString::clear | ( | ) | [inline] |
unsigned StString::contains | ( | const StString & | str | ) |
int StString::countDigits | ( | I | num | ) | const [private] |
bool StString::empty | ( | ) | const [inline] |
int StString::find | ( | const StString & | str, | |
SmartTools::Position | searchFrom = SmartTools::Left | |||
) | const |
str | String to find | |
searchFrom | From which side begin to search? |
void StString::init | ( | ) | [private] |
StString StString::left | ( | unsigned | numChars | ) | const [inline] |
unsigned StString::length | ( | ) | const [inline] |
Returns the length of the string
StString StString::mid | ( | unsigned | index, | |
unsigned | numChars | |||
) | const |
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+= | ( | 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] |
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 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] |
Removes every occurrence of str in this string.
StString StString::right | ( | unsigned | numChars | ) | const |
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.
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 | ) |
Works like sprintf from stdio.h but writes into a string. It erases the current content.
int StString::toInt | ( | ) | [inline] |
Try to convert current string to integer