[Scummvm-cvs-logs] CVS: scummvm/common str.h,1.16,1.17 str.cpp,1.25,1.26
Max Horn
fingolfin at users.sourceforge.net
Thu Nov 6 16:03:08 CET 2003
Update of /cvsroot/scummvm/scummvm/common
In directory sc8-pr-cvs1:/tmp/cvs-serv9537
Modified Files:
str.h str.cpp
Log Message:
change (Const)String::c_str to never return 0 (rather return empty string) -> can be used to simplify code. Also don't use stricmp in </<=/>/>= operators, it is inconsisten with == and != operators
Index: str.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/str.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- str.h 8 Oct 2003 21:01:50 -0000 1.16
+++ str.h 7 Nov 2003 00:02:02 -0000 1.17
@@ -66,7 +66,7 @@
return _str[idx];
}
- const char *c_str() const { return _str; }
+ const char *c_str() const { return _str ? _str : ""; }
int size() const { return _len; }
bool isEmpty() const { return (_len == 0); }
Index: str.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/str.cpp,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- str.cpp 8 Oct 2003 21:09:21 -0000 1.25
+++ str.cpp 7 Nov 2003 00:02:03 -0000 1.26
@@ -221,39 +221,29 @@
#pragma mark -
bool ConstString::operator ==(const ConstString &x) const {
- return (_len == x._len) && ((_len == 0) || (0 == strcmp(_str, x._str)));
+ return (0 == strcmp(c_str(), x.c_str()));
}
bool ConstString::operator ==(const char *x) const {
- if (_str == 0)
- return (x == 0) || (*x == 0);
- if (x == 0)
- return (_len == 0);
- return (0 == strcmp(_str, x));
+ assert(x != 0);
+ return (0 == strcmp(c_str(), x));
}
bool ConstString::operator !=(const ConstString &x) const {
- return (_len != x._len) || ((_len != 0) && (0 != strcmp(_str, x._str)));
+ return (0 != strcmp(c_str(), x.c_str()));
}
bool ConstString::operator !=(const char *x) const {
- if (_str == 0)
- return (x != 0) && (*x != 0);
- if (x == 0)
- return (_len != 0);
- return (0 != strcmp(_str, x));
+ assert(x != 0);
+ return (0 != strcmp(c_str(), x));
}
bool ConstString::operator < (const ConstString &x) const {
- if (!_len || !x._len) // Any or both empty?
- return !_len && x._len; // Less only if this string is empty and the other isn't
- return scumm_stricmp(_str, x._str) < 0;
+ return strcmp(c_str(), x.c_str()) < 0;
}
bool ConstString::operator <= (const ConstString &x) const {
- if (!_len || !x._len) // Any or both empty?
- return !_len; // Less or equal unless the other string is empty and this one isn't
- return scumm_stricmp(_str, x._str) <= 0;
+ return strcmp(c_str(), x.c_str()) <= 0;
}
bool ConstString::operator > (const ConstString &x) const {
More information about the Scummvm-git-logs
mailing list