diff options
-rw-r--r-- | common/str.cpp | 21 | ||||
-rw-r--r-- | common/str.h | 5 |
2 files changed, 26 insertions, 0 deletions
diff --git a/common/str.cpp b/common/str.cpp index 01d24c1e75..88aca87bb4 100644 --- a/common/str.cpp +++ b/common/str.cpp @@ -86,7 +86,16 @@ String::String(const String &str) } assert(_str != 0); } + +String::String(char c) +: _len(0), _str(_storage) { + _storage[0] = c; + _storage[1] = 0; + + _len = (c == 0) ? 0 : 1; +} + String::~String() { decRefCount(_extern._refCount); } @@ -437,6 +446,18 @@ String operator +(const String &x, const char *y) { return temp; } +String operator +(char x, const String &y) { + String temp(x); + temp += y; + return temp; +} + +String operator +(const String &x, char y) { + String temp(x); + temp += y; + return temp; +} + char *ltrim(char *t) { while (isspace(*t)) t++; diff --git a/common/str.h b/common/str.h index 509300dd6f..55ff94c51c 100644 --- a/common/str.h +++ b/common/str.h @@ -99,6 +99,7 @@ public: String() : _len(0), _str(_storage) { _storage[0] = 0; } String(const char *str, uint32 len = 0); String(const String &str); + String(char c); virtual ~String(); String &operator =(const char *str); @@ -187,9 +188,13 @@ protected: // Append two strings to form a new (temp) string String operator +(const String &x, const String &y); + String operator +(const char *x, const String &y); String operator +(const String &x, const char *y); +String operator +(const String &x, char y); +String operator +(char x, const String &y); + // Some useful additional comparision operators for Strings bool operator == (const char *x, const String &y); bool operator != (const char *x, const String &y); |