aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Horn2007-06-02 12:42:40 +0000
committerMax Horn2007-06-02 12:42:40 +0000
commit95ba2986d353cbc6a8cd4262cb9980b6071499b1 (patch)
treeb20eecfe588e81a46b49743d7d57070560e9df16
parentf85871b1fc9540c77b43d8ed200059e7d31948be (diff)
downloadscummvm-rg350-95ba2986d353cbc6a8cd4262cb9980b6071499b1.tar.gz
scummvm-rg350-95ba2986d353cbc6a8cd4262cb9980b6071499b1.tar.bz2
scummvm-rg350-95ba2986d353cbc6a8cd4262cb9980b6071499b1.zip
Enhanced Common::String by adding char constructor and operator+ for chars
svn-id: r27051
-rw-r--r--common/str.cpp21
-rw-r--r--common/str.h5
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);