diff options
author | Max Horn | 2002-08-18 22:24:39 +0000 |
---|---|---|
committer | Max Horn | 2002-08-18 22:24:39 +0000 |
commit | 7604484caf2d5846a1cc1606c577fedc5791089c (patch) | |
tree | fd032bc2657d77f34c7738dd352eb389d90e5b10 | |
parent | ad5b605ba1840c256fc934fd9b53c94cc9393d6e (diff) | |
download | scummvm-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.cpp | 39 | ||||
-rw-r--r-- | util.h | 8 |
2 files changed, 47 insertions, 0 deletions
@@ -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 @@ -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: |