aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Horn2002-08-18 22:24:39 +0000
committerMax Horn2002-08-18 22:24:39 +0000
commit7604484caf2d5846a1cc1606c577fedc5791089c (patch)
treefd032bc2657d77f34c7738dd352eb389d90e5b10
parentad5b605ba1840c256fc934fd9b53c94cc9393d6e (diff)
downloadscummvm-rg350-7604484caf2d5846a1cc1606c577fedc5791089c.tar.gz
scummvm-rg350-7604484caf2d5846a1cc1606c577fedc5791089c.tar.bz2
scummvm-rg350-7604484caf2d5846a1cc1606c577fedc5791089c.zip
added comparision operators to class String
svn-id: r4769
-rw-r--r--util.cpp39
-rw-r--r--util.h8
2 files changed, 47 insertions, 0 deletions
diff --git a/util.cpp b/util.cpp
index 2fae9cc175..4a5d50e369 100644
--- a/util.cpp
+++ b/util.cpp
@@ -229,6 +229,35 @@ String& String::operator +=(char c)
return *this;
}
+bool String::operator ==(const String& x)
+{
+ return (_len == x._len) && ((_len == 0) || (0 == strcmp(_str, x._str)));
+}
+
+bool String::operator ==(const char* x)
+{
+ if (_str == 0)
+ return (x == 0) || (*x == 0);
+ if (x == 0)
+ return (_len == 0);
+ return (0 != strcmp(_str, x));
+}
+
+bool String::operator !=(const String& x)
+{
+ return (_len != x._len) || ((_len != 0) && (0 != strcmp(_str, x._str)));
+}
+
+bool String::operator !=(const char* x)
+{
+ if (_str == 0)
+ return (x != 0) && (*x != 0);
+ if (x == 0)
+ return (_len != 0);
+ return (0 == strcmp(_str, x));
+}
+
+
void String::deleteLastChar() {
if (_len > 0) {
ensureCapacity(_len - 1, true);
@@ -270,4 +299,14 @@ void String::ensureCapacity(int new_len, bool keep_old)
_str = newStr;
}
+bool operator == (const char* y, const String& x)
+{
+ return x == y;
+}
+
+bool operator != (const char* y, const String& x)
+{
+ return x != y;
+}
+
}; // End of namespace ScummVM
diff --git a/util.h b/util.h
index 43410dcba5..0f74ede00f 100644
--- a/util.h
+++ b/util.h
@@ -144,6 +144,11 @@ public:
String& operator +=(const String& str);
String& operator +=(char c);
+ bool operator ==(const String& x);
+ bool operator ==(const char* x);
+ bool operator !=(const String& x);
+ bool operator !=(const char* x);
+
// operator char *() { return _str; }
operator const char *() const { return _str; }
const char *c_str() const { return _str; }
@@ -159,6 +164,9 @@ protected:
void decRefCount();
};
+// Some useful additional comparision operators for Strings
+bool operator == (const char* x, const String& y);
+bool operator != (const char* x, const String& y);
class StringList : public List<String> {
public: