diff options
author | Max Horn | 2003-11-07 00:02:03 +0000 |
---|---|---|
committer | Max Horn | 2003-11-07 00:02:03 +0000 |
commit | 82aac86edff8e35ed7c0c2560ef5cde8b3111fc6 (patch) | |
tree | d3c937af995d6e6addaee3a7852cec725e51628e /common | |
parent | ba1cf0e957f027011e023f733a304c49cd7eac9b (diff) | |
download | scummvm-rg350-82aac86edff8e35ed7c0c2560ef5cde8b3111fc6.tar.gz scummvm-rg350-82aac86edff8e35ed7c0c2560ef5cde8b3111fc6.tar.bz2 scummvm-rg350-82aac86edff8e35ed7c0c2560ef5cde8b3111fc6.zip |
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
svn-id: r11169
Diffstat (limited to 'common')
-rw-r--r-- | common/str.cpp | 26 | ||||
-rw-r--r-- | common/str.h | 2 |
2 files changed, 9 insertions, 19 deletions
diff --git a/common/str.cpp b/common/str.cpp index 0313e0ccd4..e48a0a9aff 100644 --- a/common/str.cpp +++ b/common/str.cpp @@ -221,39 +221,29 @@ void String::ensureCapacity(int new_len, bool keep_old) { #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 { diff --git a/common/str.h b/common/str.h index a4570bead8..2c18c75554 100644 --- a/common/str.h +++ b/common/str.h @@ -66,7 +66,7 @@ public: 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); } |