fix CString::compare()
This commit is contained in:
committed by
Mathias Agopian
parent
7fd24c38d7
commit
653b2e859c
@@ -22,6 +22,8 @@
|
||||
#include <utils/compiler.h>
|
||||
#include <utils/ostream.h>
|
||||
|
||||
#include <string_view>
|
||||
|
||||
#include <assert.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
@@ -197,16 +199,13 @@ private:
|
||||
};
|
||||
|
||||
int compare(const CString& rhs) const noexcept {
|
||||
size_type const lhs_size = size();
|
||||
size_type const rhs_size = rhs.size();
|
||||
if (lhs_size < rhs_size) return -1;
|
||||
if (lhs_size > rhs_size) return 1;
|
||||
return strncmp(data(), rhs.data(), size());
|
||||
auto const l = std::string_view{data(), size()};
|
||||
auto const r = std::string_view{rhs.data(), rhs.size()};
|
||||
return l.compare(r);
|
||||
}
|
||||
|
||||
friend bool operator==(CString const& lhs, CString const& rhs) noexcept {
|
||||
return (lhs.data() == rhs.data()) ||
|
||||
((lhs.size() == rhs.size()) && !strncmp(lhs.data(), rhs.data(), lhs.size()));
|
||||
return lhs.compare(rhs) == 0;
|
||||
}
|
||||
friend bool operator!=(CString const& lhs, CString const& rhs) noexcept {
|
||||
return !(lhs == rhs);
|
||||
|
||||
Reference in New Issue
Block a user