aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/include/CStringView.h
diff options
context:
space:
mode:
authorRobert Schumacher <roschuma@microsoft.com>2017-10-03 15:51:04 -0700
committerRobert Schumacher <roschuma@microsoft.com>2017-10-03 15:51:24 -0700
commit3838d5880470fdc884f035ed3d1c67d3bdd1e16e (patch)
treea12cdb0b99a4999649d93a7710d7a0a96fc1ffe9 /toolsrc/include/CStringView.h
parent85f0a060db8be34f4fce134be450bd1e4bd2b06f (diff)
downloadvcpkg-3838d5880470fdc884f035ed3d1c67d3bdd1e16e.tar.gz
vcpkg-3838d5880470fdc884f035ed3d1c67d3bdd1e16e.zip
[vcpkg] Add more operator== to CStringView. Uppercase Span to follow naming convention.
Diffstat (limited to 'toolsrc/include/CStringView.h')
-rw-r--r--toolsrc/include/CStringView.h44
1 files changed, 43 insertions, 1 deletions
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<CharType>& 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<class CharType>
+ bool operator==(const BasicCStringView<CharType>& l, const BasicCStringView<CharType>& r)
+ {
+ return details::vcpkg_strcmp(l.c_str(), r.c_str());
+ }
+
+ template<class CharType>
+ bool operator==(const CharType* l, const BasicCStringView<CharType>& r)
+ {
+ return details::vcpkg_strcmp(l, r.c_str());
+ }
+
+ template<class CharType>
+ bool operator==(const BasicCStringView<CharType>& r, const CharType* l)
+ {
+ return details::vcpkg_strcmp(l, r.c_str());
+ }
+
template<class CharType>
bool operator==(const std::basic_string<CharType>& l, const BasicCStringView<CharType>& r)
{
@@ -30,6 +53,25 @@ namespace vcpkg
return l == r.c_str();
}
+ // notequals
+ template<class CharType>
+ bool operator!=(const BasicCStringView<CharType>& l, const BasicCStringView<CharType>& r)
+ {
+ return !details::vcpkg_strcmp(l.c_str(), r.c_str());
+ }
+
+ template<class CharType>
+ bool operator!=(const CharType* l, const BasicCStringView<CharType>& r)
+ {
+ return !details::vcpkg_strcmp(l, r.c_str());
+ }
+
+ template<class CharType>
+ bool operator!=(const BasicCStringView<CharType>& r, const CharType* l)
+ {
+ return !details::vcpkg_strcmp(l, r.c_str());
+ }
+
template<class CharType>
bool operator!=(const BasicCStringView<CharType>& r, const std::basic_string<CharType>& l)
{