|
ubit
|
Ubit String. More...
#include <ustr.hpp>
Public Member Functions | |
| virtual int | getNodeType () const |
| returns the XML node type. | |
| virtual const UStr & | getNodeName () const |
| return the XML node name. | |
| virtual UStr | getNodeValue () const |
| return the XML node value. | |
| virtual const UStr & | getData () const |
| virtual UStr * | toStr () |
| dynamic cast: returns this object if it derives from UStr and null otherwise. | |
| virtual const UStr * | toStr () const |
| dynamic cast: returns this object if it derives from UStr and null otherwise. | |
| virtual UStr & | onChange (UCall &c) |
| adds a callback that is fired when the string is modified. More... | |
| UStr () | |
| creates a new empty string; More... | |
| UStr (const char *) | |
| creates a new string; More... | |
| UStr (const UStr &) | |
| creates a new string; More... | |
| UStr (const std::string &) | |
| creates a new string; More... | |
| int | length () const |
| returns the char count of the string. | |
| bool | empty () const |
| returns true if the string is empty. | |
| bool | isEmpty () const |
| returns true if the string is empty. | |
| virtual UStr & | clear () |
| clears the string's content. | |
| virtual UStr & | operator= (const char *) |
| virtual UStr & | operator= (const UStr &) |
| virtual UStr & | operator= (const std::string &) |
| UStr & | setInt (int) |
| UStr & | setLong (long) |
| UStr & | setFloat (float) |
| UStr & | setDouble (double) |
| int | toInt () const |
| long | toLong () const |
| float | toFloat () const |
| double | toDouble () const |
| int | scan (const char *format,...) const |
| bool | scanValue (float &val, UStr &unit) const |
| bool | scanValue (float &val, const char *&unit) const |
| const char * | c_str () const |
| returns an unmutable C string. | |
| char | at (int pos) const |
| returns the character at this position. More... | |
| char | operator[] (int pos) const |
| same as at(int). | |
| char | setCharAt (int pos, char c, bool update=true) |
| changes the character at offset 'pos'. More... | |
| bool | operator== (const char *s2) const |
| bool | operator== (const UStr &s2) const |
| bool | operator== (const std::string &s2) const |
| bool | operator!= (const char *s2) const |
| bool | operator!= (const UStr &s2) const |
| bool | operator!= (const std::string &s2) const |
| virtual bool | equals (const char *, bool ignore_case=false) const |
| checks if string contents are the same, ignores case if last argument is true. | |
| virtual bool | equals (const UStr &, bool ignore_case=false) const |
| checks if string contents are the same, ignores case if last argument is true. | |
| virtual bool | equals (const std::string &, bool ignore_case=false) const |
| checks if string contents are the same, ignores case if last argument is true. | |
| virtual int | compare (const char *, bool ignore_case=false) const |
| compare strings lexicographically, ignores case if last argument is true. | |
| virtual int | compare (const UStr &, bool ignore_case=false) const |
| compare strings lexicographically, ignores case if last argument is true. | |
| virtual int | compare (const std::string &, bool ignore_case=false) const |
| compare strings lexicographically, ignores case if last argument is true. | |
| virtual int | compareN (const char *, unsigned int n, bool ignore_case=false) const |
| compare the N first chars of strings, ignores case if last argument is true. | |
| virtual int | compareN (const UStr &, unsigned int n, bool ignore_case=false) const |
| compare the N first chars of strings, ignores case if last argument is true. | |
| virtual int | compareN (const std::string &, unsigned int n, bool ignore_case=false) const |
| compare the N first chars of strings, ignores case if last argument is true. | |
| virtual int | find (char s, int pos=0) const |
| search for the first occurrence of 's' starting at 'pos', return -1 if not found. | |
| virtual int | find (const char *s, int pos=0) const |
| search for the first occurrence of 's' starting at 'pos', return -1 if not found. | |
| virtual int | find (const UStr &s, int pos=0) const |
| search for the first occurrence of 's' starting at 'pos', return -1 if not found. | |
| virtual int | find (const std::string &s, int pos=0) const |
| search for the first occurrence of 's' starting at 'pos', return -1 if not found. | |
| virtual int | rfind (char s) const |
| search for the last occurrence of 's', return -1 if not found. | |
| UStr | substring (int from_pos=0, unsigned int nbchars=npos) const |
| returns a substring. | |
| std::string | toString (int pos=0, unsigned int nbchars=npos) const |
| UStr to std::string conversion. More... | |
| bool | toString (std::string &to, int pos=0, unsigned int nbchars=npos) const |
| UStr to std::string conversion. More... | |
| UStr | toUpper () const |
| returns a upercase copy. | |
| UStr | toLower () const |
| returns a lowercase copy. | |
| void | upper () |
| converts to uppercase characters. | |
| void | lower () |
| converts to lowercase characters. | |
| void | capitalize () |
| capitalizes this string. | |
| 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. More... | |
| 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) |
| 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) |
| appends the argument to the end of this UStr. More... | |
| 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. More... | |
| virtual void | remove (int pos, unsigned int nbchars) |
| removes 'nbchars' characters from offset 'pos' details: More... | |
| 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). More... | |
| virtual UStr | dirname (bool with_final_slash=true) const |
| returns the directory of a pathname (omitting the file name). More... | |
| 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. More... | |
| virtual int | write (const UStr &pathname) |
| writes the content of this UStr in this file. More... | |
| virtual void | changed (bool update=true) |
| [impl] called when object's content is changed. More... | |
| virtual void | update () |
| updates grahics. | |
| UStr (const char *, UConst) | |
| creates a new CONSTANT string; More... | |
| virtual void | syncVals (char *, int) |
| virtual void | addingTo (UChild &, UElem &parent) |
| called when this object is added to a parent. | |
| virtual void | removingFrom (UChild &, UElem &parent) |
| NOTE that this function require a specific destructor. | |
| virtual bool | checkFormat (int pos, int newchar) |
| virtual bool | checkFormat (int pos, const char *) |
| checks input conformance to format model (if any). | |
| virtual void | initImpl (const char *, int len) |
| virtual void | setImpl (const char *, int len) |
| virtual void | setImplNoCopy (char *_s, int _len) |
| virtual bool | insertImpl (int to_pos, char newchar, bool upd) |
| virtual bool | insertImpl (int to_pos, const char *s2, int from_pos, unsigned int from_len, bool upd) |
| virtual bool | replaceImpl (int pos, unsigned int nbchars, const char *s2, bool upd) |
| virtual void | getSize (UUpdateContext &, UDimension &) const |
| virtual void | getSize (UUpdateContext &, UDimension &, float available_width, int offset, int &str_sublen, int &change_line) const |
| virtual void | paint (UGraph &, UUpdateContext &, const URect &) const |
| virtual void | paint (UGraph &, UUpdateContext &, const URect &, int offset, int cellen) const |
Public Member Functions inherited from ubit::UData | |
| UABSTRACT_CLASS (UData) | |
| UData (UConst) | |
| virtual int | getDisplayType () const |
| virtual UData * | toData () |
| dynamic cast: returns this object if it derives from UData and null otherwise. | |
| virtual const UData * | toData () const |
| dynamic cast: returns this object if it derives from UData and null otherwise. | |
Public Member Functions inherited from ubit::UNode | |
| virtual int | isDisplayable () const |
| virtual UNode * | toNode () |
| dynamic cast: returns this object if it derives from UNode and null otherwise. | |
| virtual const UNode * | toNode () const |
| dynamic cast: returns this object if it derives from UNode and null otherwise. | |
| virtual bool | isChildOf (const UElem &parent, bool indirect=true) const |
| returns true if this object a child of 'parent'. More... | |
| UParentIter | pbegin () const |
| returns an iterator to the beginning of the list of direct parents. More... | |
| UParentIter | pend () const |
| returns an iterator to the end of the parent list ( More... | |
| virtual UParents & | parents () const |
| returns the list of direct parents ( More... | |
| virtual UElem * | getParent (int pos=0) const |
| returns the Nth direct parent. More... | |
| virtual bool | hasSceneGraphParent () const |
| template<class CC > | |
| CC * | findParent () const |
| < this object has at least one parent in the scene graph. More... | |
| virtual int | getBoxParents (std::vector< UBox *> &parvect) const |
| retrieves direct and indirect parents that are boxes. | |
| virtual UBox * | getParent (const UView *) const |
| returns the direct or indirect parent that contains this view. More... | |
| virtual UView * | getParentView (const UView *) const |
| returns the direct or indirect parent's view that contains this view. More... | |
| virtual UBox * | getParent (const UInputEvent &) const |
| virtual UView * | getParentView (const UInputEvent &) const |
| virtual void | removeFromParents (bool update_parents=true) |
| [impl] removes this object from all direct parents. More... | |
| virtual bool | fire (UEvent &) const |
| fires callback functions that match this event. | |
| virtual UNode & | removeAllAttrs (bool autodel=true) |
| removes all attributes (if any, redefined by subclasses). | |
| bool | isAutoUpdate () const |
| return current update policy: see setAutoUpdate(). | |
| UNode & | setAutoUpdate (bool state=true) |
| changes the update policy of this object when its is modified. More... | |
| void | fireParents (const UCond &c, UNode *n) const |
| void | updateAutoParents (const UUpdate &m) |
| virtual void | addChangeCall (UCall &) |
| virtual UElem * | getSubGroup () const |
| void | _addAttr (const UChild &attribute) |
| [impl] to be removed @. | |
| UChildIter | _abegin () const |
| [impl] to be removed @. | |
| UChildIter | _aend () const |
| [impl] to be removed @. | |
Public Member Functions inherited from ubit::UObject | |
| UObject (const UObject &) | |
| UObject & | operator= (const UObject &) |
| virtual const UClass & | getClass () const |
| instance method that returns the metaclass of this object. More... | |
| const UStr & | getClassName () const |
| returns getClass().getName(). | |
| virtual void | error (const char *function_name, const char *format,...) const |
| prints out an error message. More... | |
| virtual void | warning (const char *function_name, const char *format,...) const |
| prints out a warning message: More... | |
| bool | isDeletable () const |
| checks if this object can be destroyed by 'delete'. More... | |
| bool | isConst () const |
| checks whether the content of this object can be modified ( More... | |
| UObject & | setConst () |
| specifies that the content of this object cannot be modified. More... | |
| bool | isAutoUpdate () const |
| return current update policy: More... | |
| UObject & | setAutoUpdate (bool state=true) |
| changes the update policy of this object when its is modified. More... | |
| bool | isIgnoringChangeCallbacks () const |
| return true if change callbacks are fired. | |
| UObject & | ignoreChangeCallbacks (bool state) |
| change callbacks are not fired if argument is true. | |
| virtual UAttr * | toAttr () |
| dynamic cast: returns this object if it derives from UAttr and null otherwise. | |
| virtual const UAttr * | toAttr () const |
| dynamic cast: returns this object if it derives from UAttr and null otherwise. | |
| virtual UElem * | toElem () |
| dynamic cast: returns this object if it derives from UElem and null otherwise. | |
| virtual const UElem * | toElem () const |
| dynamic cast: returns this object if it derives from UElem and null otherwise. | |
| virtual UCall * | toCall () |
| dynamic cast: returns this object if it derives from UCall and null otherwise. | |
| virtual const UCall * | toCall () const |
| dynamic cast: returns this object if it derives from UCall and null otherwise. | |
| virtual UBox * | toBox () |
| dynamic cast: returns this object if it derives from UBox and null otherwise. | |
| virtual const UBox * | toBox () const |
| dynamic cast: returns this object if it derives from UBox and null otherwise. | |
| virtual UWin * | toWin () |
| dynamic cast: returns this object if it derives from UWin and null otherwise. | |
| virtual const UWin * | toWin () const |
| dynamic cast: returns this object if it derives from UWin and null otherwise. | |
| virtual UMenu * | toMenu () |
| dynamic cast: returns this object if it derives from UMenu and null otherwise. | |
| virtual const UMenu * | toMenu () const |
| dynamic cast: returns this object if it derives from UMenu and null otherwise. | |
| State | getState () const |
| returns the current object state. | |
| void | setState (State s) |
| changes the object state. | |
| PtrCount | getPtrCount () const |
| [impl] returns the number of uptr<> smart pointers that are pointing to this object. | |
| bool | checkConst () const |
| [impl] produces an error if this object is logically constant ( More... | |
| bool | isDestructed () const |
| [impl] this object has been destructed (but memory has not been freed yet). | |
| bool | isDestructing () const |
| [impl] this object is being destructed (one of its destructors has been called). | |
| void * | operator new (size_t) |
| < [impl] returns true if there is at least one scene graph parent (redefined by UNode). More... | |
| void | operator delete (void *) |
| delete operator is forbidden on instances that derive from UObject. | |
| void | addPtr () const |
| [Impl] a uptr is added to this object. | |
| void | removePtr () const |
| [Impl] a uptr is removed from this object. | |
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. More... | |
Static Public Member Functions inherited from ubit::UObject | |
| static const char * | getVersion () |
| returns the version of the Ubit package. | |
| static const UClass & | Class () |
| class method that returns the metaclass of this class. More... | |
| static UStyle * | createStyle () |
Static Public Attributes | |
| static const unsigned int | npos = static_cast<unsigned int>(-1) |
Static Public Attributes inherited from ubit::UObject | |
| static UConst | UCONST |
| UCONST can be given as an argument to some constructors to make the object constant. More... | |
Friends | |
| std::ostream & | operator<< (std::ostream &, const UStr &) |
| prints the string on an output stream (e.g. cout << str). | |
| std::istream & | operator>> (std::istream &, UStr &) |
| reads the string from an input stream (eg. 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 &) |
| creates a new string that collates the 2 arguments. More... | |
Additional Inherited Members | |
Public Types inherited from ubit::UNode | |
| enum | NodeType { ELEMENT_NODE = 1, ATTRIBUTE_NODE = 2, TEXT_NODE = 3, CDATA_SECTION_NODE = 4, ENTITY_REFERENCE_NODE = 5, ENTITY_NODE = 6, PROCESSING_INSTRUCTION_NODE = 7, COMMENT_NODE = 8, DOCUMENT_NODE = 9, DOCUMENT_TYPE_NODE = 10, DOCUMENT_FRAGMENT_NODE = 11, NOTATION_NODE = 12 } |
| redefines Class() and getClass() methods ( More... | |
| enum | DisplayType { WINLIST =-1, UNDISPLAYBLE =0, ATTRIBUTE, DATA, INLINE, BLOCK, BORDER, HARDWIN, SOFTWIN } |
| Ubit display types. | |
Public Types inherited from ubit::UObject | |
| typedef unsigned char | State |
| typedef short | PtrCount |
Protected Member Functions inherited from ubit::UNode | |
| UNode () | |
| constructor, can anly be called by subclasses because UNode is abstract. | |
| virtual | ~UNode () |
| destructor, note that children are recursively destroyed except if pointed elsewhere ( More... | |
| virtual void | destructs () |
| unlinks the object from its parents and destroys its children. | |
Protected Attributes inherited from ubit::UNode | |
| UParents | _parents |
| UChildren | _attributes |
Protected Attributes inherited from ubit::UObject | |
| PtrCount | ptr_count |
| Modes | omodes |
| State | ostate |
Ubit String.
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:
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()->toStr();
...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.
| UStr::UStr | ( | ) |
creates a new empty string;
| ubit::UStr::UStr | ( | const char * | ) |
creates a new string;
| ubit::UStr::UStr | ( | const UStr & | ) |
creates a new string;
| ubit::UStr::UStr | ( | const std::string & | ) |
creates a new string;
| ubit::UStr::UStr | ( | const char * | , |
| UConst | |||
| ) |
creates a new CONSTANT string;
| char UStr::at | ( | int | pos | ) | const |
returns the character at this position.
|
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.
|
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.
|
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.
|
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.
|
inline |
appends the argument to the end of this UStr.
usage: str &= arg; see also: append() and operator &
|
virtual |
reads this file and loads its content into this UStr.
pathname can start with a ~ returns the reading status (see UFilestat)
|
virtual |
removes 'nbchars' characters from offset 'pos' details:
|
virtual |
!
| char UStr::setCharAt | ( | int | pos, |
| char | c, | ||
| bool | update = true |
||
| ) |
changes the character at offset 'pos'.
| int 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.
| std::string ubit::UStr::toString | ( | 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.
| 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.
|
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
1.8.12