From 3838d5880470fdc884f035ed3d1c67d3bdd1e16e Mon Sep 17 00:00:00 2001 From: Robert Schumacher Date: Tue, 3 Oct 2017 15:51:04 -0700 Subject: [vcpkg] Add more operator== to CStringView. Uppercase Span to follow naming convention. --- toolsrc/include/CStringView.h | 44 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'toolsrc/include/CStringView.h') diff --git a/toolsrc/include/CStringView.h b/toolsrc/include/CStringView.h index 282caad3a..c1810b4f1 100644 --- a/toolsrc/include/CStringView.h +++ b/toolsrc/include/CStringView.h @@ -11,13 +11,36 @@ namespace vcpkg constexpr BasicCStringView(const BasicCStringView&) = default; BasicCStringView(const std::basic_string& str) : cstr(str.c_str()) {} - constexpr operator const CharType*() const { return cstr; } constexpr const CharType* c_str() const { return cstr; } private: const CharType* cstr; }; + namespace details + { + inline bool vcpkg_strcmp(const char* l, const char* r) { return strcmp(l, r) == 0; } + inline bool vcpkg_strcmp(const wchar_t* l, const wchar_t* r) { return wcscmp(l, r) == 0; } + } + + template + bool operator==(const BasicCStringView& l, const BasicCStringView& r) + { + return details::vcpkg_strcmp(l.c_str(), r.c_str()); + } + + template + bool operator==(const CharType* l, const BasicCStringView& r) + { + return details::vcpkg_strcmp(l, r.c_str()); + } + + template + bool operator==(const BasicCStringView& r, const CharType* l) + { + return details::vcpkg_strcmp(l, r.c_str()); + } + template bool operator==(const std::basic_string& l, const BasicCStringView& r) { @@ -30,6 +53,25 @@ namespace vcpkg return l == r.c_str(); } + // notequals + template + bool operator!=(const BasicCStringView& l, const BasicCStringView& r) + { + return !details::vcpkg_strcmp(l.c_str(), r.c_str()); + } + + template + bool operator!=(const CharType* l, const BasicCStringView& r) + { + return !details::vcpkg_strcmp(l, r.c_str()); + } + + template + bool operator!=(const BasicCStringView& r, const CharType* l) + { + return !details::vcpkg_strcmp(l, r.c_str()); + } + template bool operator!=(const BasicCStringView& r, const std::basic_string& l) { -- cgit v1.2.3