[Scummvm-cvs-logs] CVS: scummvm util.h,1.5,1.6 util.cpp,1.5,1.6

Max Horn fingolfin at users.sourceforge.net
Sun Aug 18 15:25:03 CEST 2002


Update of /cvsroot/scummvm/scummvm
In directory usw-pr-cvs1:/tmp/cvs-serv24407

Modified Files:
	util.h util.cpp 
Log Message:
added comparision operators to class String

Index: util.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/util.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- util.h	27 Jul 2002 13:27:34 -0000	1.5
+++ util.h	18 Aug 2002 22:24:39 -0000	1.6
@@ -144,6 +144,11 @@
 	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 @@
 	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:

Index: util.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/util.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- util.cpp	26 Jul 2002 17:40:04 -0000	1.5
+++ util.cpp	18 Aug 2002 22:24:39 -0000	1.6
@@ -229,6 +229,35 @@
 	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);
@@ -268,6 +297,16 @@
 	_refCount = new int(1);
 	_capacity = newCapacity;
 	_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





More information about the Scummvm-git-logs mailing list