19 #include <ubit/udata.hpp> 75 static const unsigned int npos =
static_cast<unsigned int>(-1);
80 virtual const UStr& getData()
const {
return *
this;}
101 UStr(
const std::string&);
109 bool empty()
const {
return (len == 0);}
118 virtual UStr& operator=(
const char*);
119 virtual UStr& operator=(
const UStr&);
120 virtual UStr& operator=(
const std::string&);
124 UStr& setFloat(
float);
125 UStr& setDouble(
double);
129 float toFloat()
const;
130 double toDouble()
const;
132 int scan(
const char* format, ...)
const;
134 bool scanValue(
float& val,
UStr& unit)
const;
135 bool scanValue(
float& val,
const char*& unit)
const;
137 const char*
c_str()
const {
return s;}
140 char at(
int pos)
const;
165 bool operator==(
const char* s2)
const {
return equals(s2);}
166 bool operator==(
const UStr& s2)
const {
return equals(s2);}
167 bool operator==(
const std::string& s2)
const {
return equals(s2);}
169 bool operator!=(
const char* s2)
const {
return !
equals(s2);}
170 bool operator!=(
const UStr& s2)
const {
return !
equals(s2);}
171 bool operator!=(
const std::string& s2)
const {
return !
equals(s2);}
173 virtual bool equals(
const char*,
bool ignore_case =
false)
const;
176 virtual bool equals(
const UStr&,
bool ignore_case =
false)
const;
179 virtual bool equals(
const std::string&,
bool ignore_case =
false)
const;
182 virtual int compare(
const char*,
bool ignore_case =
false)
const;
185 virtual int compare(
const UStr&,
bool ignore_case =
false)
const;
188 virtual int compare(
const std::string&,
bool ignore_case =
false)
const;
191 virtual int compareN(
const char*,
unsigned int n,
bool ignore_case =
false)
const;
194 virtual int compareN(
const UStr&,
unsigned int n,
bool ignore_case =
false)
const;
197 virtual int compareN(
const std::string&,
unsigned int n,
bool ignore_case=
false)
const;
202 virtual int find(
char s,
int pos = 0)
const;
205 virtual int find(
const char* s,
int pos = 0)
const;
208 virtual int find(
const UStr& s,
int pos = 0)
const;
211 virtual int find(
const std::string& s,
int pos = 0)
const;
214 virtual int rfind(
char s)
const;
217 UStr substring(
int from_pos=0,
unsigned int nbchars = npos)
const;
220 std::string
toString(
int pos=0,
unsigned int nbchars = npos)
const;
226 bool toString(std::string& to,
int pos=0,
unsigned int nbchars = npos)
const;
247 UStr split(
int pos,
bool delete_char_at_pos =
false);
253 void trim(
bool trim_beginning =
true,
bool trim_end =
true);
256 int tokenize(std::vector<UStr*>& tokens,
const UStr& separators,
257 bool trim_begin =
true,
bool trim_end =
true)
const;
273 virtual void append(
char);
274 virtual void append(
const char*);
275 virtual void append(
const char*,
unsigned int nbchars);
276 virtual void append(
const UStr&);
277 virtual void append(
const UStr&,
unsigned int nbchars);
278 virtual void append(
const std::string&);
279 virtual void append(
const std::string&,
unsigned int nbchars);
280 virtual void append(
int);
281 virtual void append(
double);
283 UStr& operator&=(
const char c) {append(c);
return *
this;}
284 UStr& operator&=(
const char* s2) {append(s2);
return *
this;}
285 UStr& operator&=(
const UStr& s2) {append(s2);
return *
this;}
286 UStr& operator&=(
const std::string& s2) {append(s2);
return *
this;}
287 UStr& operator&=(
int i) {append(i);
return *
this;}
288 UStr& operator&=(
double d) {append(d);
return *
this;}
295 friend UStr operator&(
const UStr& s1,
const char* s2);
296 friend UStr operator&(
const char* s1,
const UStr& s2);
297 friend UStr operator&(
const UStr& s1,
const std::string& s2);
298 friend UStr operator&(
const std::string& s1,
const UStr& s2);
299 friend UStr operator&(
const UStr&,
int);
300 friend UStr operator&(
int,
const UStr&);
301 friend UStr operator&(
const UStr&,
double);
302 friend UStr operator&(
double,
const UStr&);
310 virtual bool insert(
int to_pos,
char);
311 virtual bool insert(
int to_pos,
const char* from,
312 int from_pos = 0,
unsigned int from_nbchars = npos);
313 virtual bool insert(
int to_pos,
const UStr& from,
314 int from_pos = 0,
unsigned int from_nbchars = npos);
315 virtual bool insert(
int to_pos,
const std::string& from,
316 int from_pos = 0,
unsigned int from_nbchars = npos);
326 virtual void remove(
int pos,
unsigned int nbchars);
335 virtual void replace(
int pos,
unsigned int nbchars,
const UStr&);
336 virtual void replace(
int pos,
unsigned int nbchars,
const char*);
337 virtual void replace(
int pos,
unsigned int nbchars,
const std::string&);
349 virtual UStr dirname(
bool with_final_slash =
true)
const;
364 virtual int read(
const UStr& pathname);
376 static int readLines(
const UStr& filename, std::vector<UStr*>& lines,
377 bool trim_beginning =
true,
bool trim_end =
true);
403 virtual void syncVals(
char*,
int);
409 virtual bool checkFormat(
int pos,
int newchar);
410 virtual bool checkFormat(
int pos,
const char*);
413 virtual void initImpl(
const char*,
int len);
414 virtual void setImpl(
const char*,
int len);
415 virtual void setImplNoCopy(
char *_s,
int _len);
416 virtual bool insertImpl(
int to_pos,
char newchar,
bool upd);
417 virtual bool insertImpl(
int to_pos,
const char* s2,
int from_pos,
418 unsigned int from_len,
bool upd);
419 virtual bool replaceImpl(
int pos,
unsigned int nbchars,
420 const char* s2,
bool upd);
427 int offset,
int& str_sublen,
int& change_line)
const;
447 inline UStr& ustr() {
return *
new UStr();}
450 inline UStr& ustr(
const char* s) {
return *
new UStr(s);}
456 inline UStr& ustr(
const std::string& s) {
return *
new UStr(s);}
465 static char* dup(
const char* s);
468 static char* dup(
const char* s1,
const char* s2);
471 static char* dup(
const char* s1,
char sep,
const char* s2);
474 static bool equals(
const char* s1,
const char* s2,
bool ignore_case =
false);
477 static int compare(
const char* s1,
const char* s2,
bool ignore_case =
false);
480 static int compareN(
const char* s1,
const char* s2,
unsigned int n,
bool ignore_case =
false);
483 static const char*
suffix(
const char *pathname);
489 static void parsePath(
char* path_name,
int path_len,
490 char*& dir_name,
int& dir_len,
491 char*& base_name,
int& base_len,
492 char*& suffix,
int& suffix_len);
virtual void changed(bool update=true)
[impl] called when object's content is changed.
Definition: ustr.cpp:444
useful functions for C strings.
Definition: ustr.hpp:464
2D Dimension.
Definition: ugeom.hpp:55
char at(int pos) const
returns the character at this position.
Definition: ustr.cpp:467
Definition: uobject.hpp:282
bool isEmpty() const
returns true if the string is empty.
Definition: ustr.hpp:112
class for drawing on widgets.
Definition: ugraph.hpp:44
2D Rectangle.
Definition: ugeom.hpp:165
virtual UStr & clear()
clears the string's content.
Definition: ustr.cpp:186
UStr toLower() const
returns a lowercase copy.
Definition: ustr.cpp:389
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 int find(char s, int pos=0) const
search for the first occurrence of 's' starting at 'pos', return -1 if not found. ...
virtual UStr * toStr()
dynamic cast: returns this object if it derives from UStr and null otherwise.
Definition: ustr.hpp:82
virtual UStr suffix() const
returns the suffix of a pathname.
Definition: ustr.cpp:1047
virtual const UStr * toStr() const
dynamic cast: returns this object if it derives from UStr and null otherwise.
Definition: ustr.hpp:83
virtual int write(const UStr &pathname)
writes the content of this UStr in this file.
Definition: ustr.cpp:1141
friend std::istream & operator>>(std::istream &, UStr &)
reads the string from an input stream (eg. cin >> str).
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.
Base class for Viewable Objects.
Definition: udata.hpp:31
virtual int rfind(char s) const
search for the last occurrence of 's', return -1 if not found.
Definition: ustr.cpp:895
virtual void removingFrom(UChild &, UElem &parent)
NOTE that this function require a specific destructor.
Definition: ustr.cpp:128
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.
Definition: ustr.cpp:814
lightweight general purpose container.
Definition: uelem.hpp:44
virtual void addingTo(UChild &, UElem &parent)
called when this object is added to a parent.
Definition: ustr.cpp:111
friend std::ostream & operator<<(std::ostream &, const UStr &)
prints the string on an output stream (e.g. cout << str).
std::string toString(int pos=0, unsigned int nbchars=npos) const
UStr to std::string conversion.
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.
Definition: ustr.cpp:1121
virtual UStr basename(bool with_suffix=true) const
returns the base name of a pathname (omitting the directory).
Definition: ustr.cpp:1017
base class of callback objects for firing functions or methods.
Definition: ucall.hpp:144
UStr toUpper() const
returns a upercase copy.
Definition: ustr.cpp:382
char operator[](int pos) const
same as at(int).
Definition: ustr.cpp:461
UStr()
creates a new empty string;
Definition: ustr.cpp:59
int length() const
returns the char count of the string.
Definition: ustr.hpp:106
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.
Definition: ustr.cpp:784
virtual void update()
updates grahics.
Definition: ustr.cpp:437
Definition: uupdatecontext.hpp:32
Definition: uhardfont.hpp:31
void capitalize()
capitalizes this string.
Definition: ustr.cpp:406
char setCharAt(int pos, char c, bool update=true)
changes the character at offset 'pos'.
Definition: ustr.cpp:473
UStr substring(int from_pos=0, unsigned int nbchars=npos) const
returns a substring.
Definition: ustr.cpp:776
const char * c_str() const
returns an unmutable C string.
Definition: ustr.hpp:137
virtual UStr & onChange(UCall &c)
adds a callback that is fired when the string is modified.
Definition: ustr.cpp:49
virtual int getNodeType() const
returns the XML node type.
Definition: ustr.hpp:77
void lower()
converts to lowercase characters.
Definition: ustr.cpp:401
virtual bool replaceImpl(int pos, unsigned int nbchars, const char *s2, bool upd)
Definition: ustr.cpp:697
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 US...
Definition: ustr.cpp:849
bool empty() const
returns true if the string is empty.
Definition: ustr.hpp:109
virtual int compare(const char *, bool ignore_case=false) const
compare strings lexicographically, ignores case if last argument is true.
virtual int read(const UStr &pathname)
reads this file and loads its content into this UStr.
Definition: ustr.cpp:1073
Ubit String.
Definition: ustr.hpp:72
virtual const UStr & getNodeName() const
return the XML node name.
Definition: ustr.cpp:47
virtual UStr expand() const
expands a pathname that contains a ~ into an absolute path.
Definition: ustr.cpp:1058
void upper()
converts to uppercase characters.
Definition: ustr.cpp:396
virtual UStr dirname(bool with_final_slash=true) const
returns the directory of a pathname (omitting the file name).
Definition: ustr.cpp:1031
[impl] Internal implementation of a child node.
Definition: uchild.hpp:23
virtual UStr getNodeValue() const
return the XML node value.
Definition: ustr.hpp:79