#include <ustr.hpp>
Inheritance diagram for ubit::UStr:
Public Member Functions | |
virtual unsigned short | getNodeType () const |
returns the XML node type. | |
virtual const UStr * | getNodeName () const |
return the XML node name. | |
virtual const UStr * | getNodeValue () const |
return the XML node value. | |
virtual const UStr * | getData () const |
virtual UStr & | onChange (UCall &c) |
adds a callback that is fired when the string is modified. | |
UStr (const UStr &) | |
UStr (const char *) | |
UStr (const std::string &) | |
UStr (const UInteger &) | |
UStr (const UFloat &) | |
UStr (const UDouble &) | |
creates a new Ubit String. | |
virtual | ~UStr () |
destructor. | |
virtual bool | empty () const |
virtual bool | isEmpty () const |
true if content is empty | |
int | length () const |
returns the char count of the string. | |
bool | operator== (const char *s2) const |
bool | operator== (const UStr &s2) const |
bool | operator== (const std::string &s2) const |
returns true if string contents are the same. | |
bool | operator!= (const char *s2) const |
bool | operator!= (const UStr &s2) const |
bool | operator!= (const std::string &s2) const |
returns true if string contents differ. | |
virtual bool | equals (const char *, bool ignore_case=false) const |
virtual bool | equals (const UStr &, bool ignore_case=false) const |
virtual bool | equals (const std::string &, bool ignore_case=false) const |
returns true if string contents are the same, ignores case if second argument is true. | |
virtual int | compare (const char *, bool ignore_case=false) const |
virtual int | compare (const UStr &, bool ignore_case=false) const |
virtual int | compare (const std::string &, bool ignore_case=false) const |
compare strings lexicographically, ignores case if second argument is true. | |
virtual int | compareN (const char *, unsigned int n, bool ignore_case=false) const |
virtual int | compareN (const UStr &, unsigned int n, bool ignore_case=false) const |
virtual int | compareN (const std::string &, unsigned int n, bool ignore_case=false) const |
compare the N first chars of strings, ignores case if second argument is true. | |
virtual int | find (char s, int pos=0) const |
virtual int | find (const UStr &s, int pos=0) const |
virtual int | find (const char *s, int pos=0) const |
virtual int | find (const std::string &s, int pos=0) const |
search for the first occurrence of 's' starting at position 'pos'. | |
virtual int | rfind (char s) const |
search for the last occurrence of 's'. | |
UStr & | operator= (const char *s2) |
UStr & | operator= (const UStr &s2) |
UStr & | operator= (const std::string &s2) |
UStr & | operator= (const UInteger &v2) |
UStr & | operator= (const UFloat &v2) |
UStr & | operator= (const UDouble &v2) |
copy the value of the argument to this string. | |
virtual void | clear () |
clears the string's content. | |
virtual void | set (const char *) |
virtual void | set (const UStr &) |
virtual void | set (const std::string &) |
virtual void | set (const UInteger &) |
virtual void | set (const UFloat &) |
virtual void | set (const UDouble &) |
copy the value of the argument to this string. | |
virtual void | setInt (int) |
void | setLong (long) |
virtual void | setFloat (float) |
virtual void | setDouble (double) |
virtual int | toInt () const |
< number to UStr conversions. | |
virtual long | toLong () const |
virtual float | toFloat () const |
virtual double | toDouble () const |
UStr to number conversions. | |
std::string | toString (int pos=0, unsigned int nbchars=npos) const |
bool | toString (std::string &to, int pos=0, unsigned int nbchars=npos) const |
UStr to std::string conversion. | |
UStr | substring (int from_pos=0, unsigned int nbchars=npos) const |
returns a substring. | |
virtual UStr | toUpper () const |
virtual UStr | toLower () const |
returns a upercase/lowercase copy. | |
void | upper () |
void | lower () |
void | capitalize () |
converts to uppercase or to lowercase or capitalizes this UStr. | |
UStr | split (int pos, bool delete_char_at_pos=false) |
splits this UStr removes chars after 'pos' in this UStr and returns the remaining chars in another UStr | |
void | trim (bool trim_beginning=true, bool trim_end=true) |
removes white spaces, tabs and newlines at the beginning and/or the end of this UStr. | |
int | tokenize (std::vector< UStr * > &tokens, const UStr &separators, bool trim_begin=true, bool trim_end=true) const |
parses this UStr and stores the tokens separated by a separator in the vector. | |
const char * | chars () const |
const char * | c_str () const |
returns a C string that should not be changed nor deleted. | |
char | charAt (int pos) const |
char | at (int pos) const |
char | operator[] (int pos) const |
returns the character at offset 'pos'. | |
char | setCharAt (int pos, char c, bool update=true) |
changes the character at offset 'pos'. | |
virtual void | append (char) |
virtual void | append (const char *) |
virtual void | append (const char *, unsigned int nbchars) |
virtual void | append (const UStr &) |
virtual void | append (const UStr &, unsigned int nbchars) |
virtual void | append (const std::string &) |
virtual void | append (const std::string &, unsigned int nbchars) |
virtual void | append (int) |
virtual void | append (double) |
virtual void | append (const UInteger &) |
virtual void | append (const UDouble &) |
appends the argument to the end of *this string. | |
UStr & | operator &= (const char c) |
UStr & | operator &= (const char *s2) |
UStr & | operator &= (const UStr &s2) |
UStr & | operator &= (const std::string &s2) |
UStr & | operator &= (int i) |
UStr & | operator &= (double d) |
UStr & | operator &= (const UInteger &i) |
UStr & | operator &= (const UDouble &d) |
appends the argument to the end of this UStr. | |
virtual bool | insert (int to_pos, char) |
virtual bool | insert (int to_pos, const char *from, int from_pos=0, unsigned int from_nbchars=npos) |
virtual bool | insert (int to_pos, const UStr &from, int from_pos=0, unsigned int from_nbchars=npos) |
virtual bool | insert (int to_pos, const std::string &from, int from_pos=0, unsigned int from_nbchars=npos) |
inserts 'from' string at offset 'to_pos' in *this string. | |
virtual void | remove (int pos, unsigned int nbchars) |
removes 'nbchars' characters from offset 'pos' details:
| |
virtual void | replace (int pos, unsigned int nbchars, const UStr &) |
virtual void | replace (int pos, unsigned int nbchars, const char *) |
virtual void | replace (int pos, unsigned int nbchars, const std::string &) |
replaces 'nbchars' characters from offset 'pos' in this string by the argument string. | |
virtual UStr | basename (bool with_suffix=true) const |
returns the base name of a pathname (omitting the directory). | |
virtual UStr | dirname (bool with_final_slash=true) const |
returns the directory of a pathname (omitting the file name). | |
virtual UStr | suffix () const |
returns the suffix of a pathname. | |
virtual UStr | expand () const |
expands a pathname that contains a ~ into an absolute path. | |
virtual int | read (const UStr &pathname) |
reads this file and loads its content into this UStr. | |
virtual int | write (const UStr &pathname) |
writes the content of this UStr in this file. | |
virtual void | changed (bool update=true) |
[impl] called when object's content is changed. | |
virtual void | update () |
updates grahics. | |
Static Public Member Functions | |
static int | readLines (const UStr &filename, std::vector< UStr * > &lines, bool trim_beginning=true, bool trim_end=true) |
reads this file and store its lines as a UStr vector. | |
Static Public Attributes | |
static const unsigned int | npos = static_cast<unsigned int>(-1) |
static UStr | none |
static UStr | newline |
Friends | |
UStr & | ustr () |
UStr & | ustr (const UStr &_s) |
UStr & | ustr (const char *_s) |
UStr & | ustr (const std::string &_s) |
creator shortcuts (same as *new UStr()). | |
std::ostream & | operator<< (std::ostream &, const UStr &) |
prints string on output stream, for instance: cout << str. | |
std::istream & | operator>> (std::istream &, UStr &) |
reads string from input stream, for instance: cin >> str. | |
UStr | operator & (const UStr &s1, const UStr &s2) |
UStr | operator & (const UStr &s1, const char *s2) |
UStr | operator & (const char *s1, const UStr &s2) |
UStr | operator & (const UStr &s1, const std::string &s2) |
UStr | operator & (const std::string &s1, const UStr &s2) |
UStr | operator & (const UStr &, int) |
UStr | operator & (int, const UStr &) |
UStr | operator & (const UStr &, double) |
UStr | operator & (double, const UStr &) |
UStr | operator & (const UStr &, const UInteger &) |
UStr | operator & (const UInteger &, const UStr &) |
UStr | operator & (const UStr &, const UDouble &) |
UStr | operator & (const UDouble &, const UStr &) |
creates a new string that collates the 2 arguments. |
Strings can have callback functions that are fired when their value is changed (see an example below). String parents can also be notified when string are modified by using the UOn::strChange condition:
Example:
class Demo { public: void strCB(UStr* s); // this method can have an optional UEvent& parameter void textCB(UEvent&); // the UEvent& parameter is optional .... };
Demo* d = new Demo(); UStr* s = new UStr("Hello");
// d->strCB(s) will be called when the content of 's' is changed s->onChange( ucall(d, s, &Demo::strCB) );
// 's' is displayed in (and edited by) the textfield // (as expected, the strCB() callback will be called when 's' is modified) UBox* tf = new UTextfield(*s); ....
Alternatively:
// utextfield(...) is a shortcut for *new UTextfield(...) UBox& tf = utextfield(s + UOn::strChange / ucall(d, &Demo::textCB));
d->textCB(UEvent&) will be called when the content of 's' is changed. The UEvent& parameter is optional. It makes it possible to retrieve the string as follows:
void Demo::textCB(UEvent& e) { UStr* s = 0; if (e.getTarget()) s = e.getTarget()->strCast(); ...etc... // NB: one could also write: // if (e.getTarget()) s = dynamic_cast<UStr*>(e.getTarget()); }
Note strCB() could also have a UEvent& parameter that would make it possible to retrieve the string in the same way.
ubit::UStr::UStr | ( | const UDouble & | ) |
creates a new Ubit String.
Note: argument value is duplicated internally (and can thus be freed)
UStr ubit::UStr::basename | ( | bool | with_suffix = true |
) | const [virtual] |
returns the base name of a pathname (omitting the directory).
this string is supposed to contain the pathname. the suffix (= the pathname extension) is removed if 'with_suffix' is false.
void ubit::UStr::changed | ( | bool | update = true |
) | [virtual] |
[impl] called when object's content is changed.
This function updates graphics (if 'update' is true) then fires parents' UOn::strChange callbacks
Reimplemented from ubit::UData.
UStr ubit::UStr::dirname | ( | bool | with_final_slash = true |
) | const [virtual] |
returns the directory of a pathname (omitting the file name).
this string is supposed to contain the pathname. the returned dirname is ended by a / if 'with_final_slash' is true.
int ubit::UStr::find | ( | const std::string & | s, | |
int | pos = 0 | |||
) | const [virtual] |
search for the first occurrence of 's' starting at position 'pos'.
returns the position of 's' or -1 if not found.
bool ubit::UStr::insert | ( | int | to_pos, | |
const std::string & | from, | |||
int | from_pos = 0 , |
|||
unsigned int | from_nbchars = npos | |||
) | [virtual] |
inserts 'from' string at offset 'to_pos' in *this string.
details:
adds a callback that is fired when the string is modified.
Reimplemented from ubit::UData.
appends the argument to the end of this UStr.
usage: str &= arg; see also: append() and operator &
char ubit::UStr::operator[] | ( | int | pos | ) | const |
returns the character at offset 'pos'.
int ubit::UStr::read | ( | const UStr & | pathname | ) | [virtual] |
reads this file and loads its content into this UStr.
pathname can start with a ~ returns the reading status (see UFilestat)
int ubit::UStr::rfind | ( | char | s | ) | const [virtual] |
search for the last occurrence of 's'.
returns the position of 's' or -1 if not found.
char ubit::UStr::setCharAt | ( | int | pos, | |
char | c, | |||
bool | update = true | |||
) |
changes the character at offset 'pos'.
int ubit::UStr::tokenize | ( | std::vector< UStr * > & | tokens, | |
const UStr & | separators, | |||
bool | trim_begin = true , |
|||
bool | trim_end = true | |||
) | const |
parses this UStr and stores the tokens separated by a separator in the vector.
bool ubit::UStr::toString | ( | std::string & | to, | |
int | pos = 0 , |
|||
unsigned int | nbchars = npos | |||
) | const |
UStr to std::string conversion.
nbchars = npos means "copy to the end of *this string". the second variant appends the substring to the 'to' argument.
int ubit::UStr::write | ( | const UStr & | pathname | ) | [virtual] |
writes the content of this UStr in this file.
pathname can start with a ~ returns the writing status (see UFilestat)
creates a new string that collates the 2 arguments.
usage: str = arg1 & arg2; NB: the + operator has another meaning: it is used to create widget child lists