7.12.2010 - bug fixes in PIString, all classes now based on PIString

This commit is contained in:
peri4
2010-12-07 19:13:15 +03:00
parent 08f214dbfa
commit 66d998f289
14 changed files with 194 additions and 145 deletions

View File

@@ -11,7 +11,7 @@ public:
PIString(const char * str) {*this += str;}
PIString(const string & str) {*this += str;}
PIString(const PIString & str) {*this += str;}
PIString(const int len, const char c = ' ') {resize(len, c);}
PIString(const int len, const char c = ' ') {for (uint i = 0; i < len; ++i) push_back(c);}
operator const char*() {return (size() == 0) ? "" : string(&at(0), size()).c_str();}
operator const string() {return (size() == 0) ? string() : string(&at(0), size());}
@@ -28,6 +28,21 @@ public:
inline bool operator ==(const char * str) const {return *this == PIString(str);}
inline bool operator ==(const string & str) const {return *this == PIString(str);}
bool operator !=(const PIString & str) const;
inline bool operator !=(const char & c) const {return *this != PIString(c);}
inline bool operator !=(const char * str) const {return *this != PIString(str);}
inline bool operator !=(const string & str) const {return *this != PIString(str);}
PIString & operator <<(const PIString & str) {*this += str; return *this;}
inline PIString & operator <<(const char & c) {*this += c; return *this;}
inline PIString & operator <<(const char * str) {*this += str; return *this;}
inline PIString & operator <<(const string & str) {*this += str; return *this;}
inline PIString & operator <<(const int & num) {*this += PIString::fromNumber(num); return *this;}
inline PIString & operator <<(const short & num) {*this += PIString::fromNumber(num); return *this;}
inline PIString & operator <<(const long & num) {*this += PIString::fromNumber(num); return *this;}
inline PIString & operator <<(const float & num) {*this += PIString::fromNumber(num); return *this;}
inline PIString & operator <<(const double & num) {*this += PIString::fromNumber(num); return *this;}
PIString mid(const int start, const int len = -1) const;
inline PIString left(const int len) const {return len <= 0 ? PIString() : mid(0, len);}
inline PIString right(const int len) const {return len <= 0 ? PIString() : mid(size() - len, len);}
@@ -35,6 +50,7 @@ public:
inline PIString & cutLeft(const int len) {return len <= 0 ? *this : cutMid(0, len);}
inline PIString & cutRight(const int len) {return len <= 0 ? *this : cutMid(size() - len, len);}
PIString trimmed() const;
PIString & trim();
const char * data() const {return ((size() == 0) ? string() : string(&at(0), size())).c_str();}
string stdString() const {return (size() == 0) ? string() : string(&at(0), size());}
@@ -59,11 +75,17 @@ public:
float toFloat() const {return (float)atof(data());}
double toDouble() const {return atof(data());}
inline static PIString fromInt(const int value) {return PIString(itos(value));}
inline static PIString fromShort(const short value) {return PIString(itos(value));}
inline static PIString fromLong(const long value) {return PIString(ltos(value));}
inline static PIString fromFloat(const float value) {return PIString(ftos(value));}
inline static PIString fromDouble(const double value) {return PIString(dtos(value));}
inline PIString & setNumber(const int value) {clear(); *this += itos(value); return *this;}
inline PIString & setNumber(const short value) {clear(); *this += itos(value); return *this;}
inline PIString & setNumber(const long value) {clear(); *this += ltos(value); return *this;}
inline PIString & setNumber(const float value) {clear(); *this += ftos(value); return *this;}
inline PIString & setNumber(const double value) {clear(); *this += dtos(value); return *this;}
inline static PIString fromNumber(const int value) {return PIString(itos(value));}
inline static PIString fromNumber(const short value) {return PIString(itos(value));}
inline static PIString fromNumber(const long value) {return PIString(ltos(value));}
inline static PIString fromNumber(const float value) {return PIString(ftos(value));}
inline static PIString fromNumber(const double value) {return PIString(dtos(value));}
};