aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/include
diff options
context:
space:
mode:
authorAlexander Karatarakis <alkarata@microsoft.com>2017-10-16 13:50:28 -0700
committerAlexander Karatarakis <alkarata@microsoft.com>2017-10-16 13:50:28 -0700
commitced047ad78734aed239669a0fd9eca9e81718966 (patch)
tree055860c1ebb25c1f4a9ef2beeddc54bf9dc72a1b /toolsrc/include
parent7214c3583bdf569bc873305908ec109a6c8716cc (diff)
downloadvcpkg-ced047ad78734aed239669a0fd9eca9e81718966.tar.gz
vcpkg-ced047ad78734aed239669a0fd9eca9e81718966.zip
Remove usages of CWStringView, except in Strings::to_utf8()
Diffstat (limited to 'toolsrc/include')
-rw-r--r--toolsrc/include/vcpkg/base/cstringview.h89
-rw-r--r--toolsrc/include/vcpkg/base/strings.h4
-rw-r--r--toolsrc/include/vcpkg/base/system.h7
-rw-r--r--toolsrc/include/vcpkg/metrics.h2
4 files changed, 35 insertions, 67 deletions
diff --git a/toolsrc/include/vcpkg/base/cstringview.h b/toolsrc/include/vcpkg/base/cstringview.h
index eac204f97..342455402 100644
--- a/toolsrc/include/vcpkg/base/cstringview.h
+++ b/toolsrc/include/vcpkg/base/cstringview.h
@@ -5,94 +5,65 @@
namespace vcpkg
{
- template<class CharType>
- struct BasicCStringView
+ struct CStringView
{
- constexpr BasicCStringView() : cstr(nullptr) {}
- constexpr BasicCStringView(const CharType* cstr) : cstr(cstr) {}
- constexpr BasicCStringView(const BasicCStringView&) = default;
- BasicCStringView(const std::basic_string<CharType>& str) : cstr(str.c_str()) {}
+ constexpr CStringView() : cstr(nullptr) {}
+ constexpr CStringView(const char* cstr) : cstr(cstr) {}
+ constexpr CStringView(const CStringView&) = default;
+ CStringView(const std::string& str) : cstr(str.c_str()) {}
- constexpr const CharType* c_str() const { return cstr; }
+ constexpr const char* c_str() const { return cstr; }
private:
- const CharType* cstr;
+ const char* cstr;
+ };
+
+ struct CWStringView
+ {
+ constexpr CWStringView() : cstr(nullptr) {}
+ constexpr CWStringView(const wchar_t* cstr) : cstr(cstr) {}
+ constexpr CWStringView(const CWStringView&) = default;
+ CWStringView(const std::wstring& str) : cstr(str.c_str()) {}
+
+ constexpr const wchar_t* c_str() const { return cstr; }
+
+ private:
+ const wchar_t* 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)
+ inline bool operator==(const CStringView& l, const CStringView& 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());
- }
+ inline bool operator==(const char* l, const CStringView& 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());
- }
+ inline bool operator==(const CStringView& r, const char* l) { return details::vcpkg_strcmp(l, r.c_str()); }
- template<class CharType>
- bool operator==(const std::basic_string<CharType>& l, const BasicCStringView<CharType>& r)
- {
- return l == r.c_str();
- }
+ inline bool operator==(const std::string& l, const CStringView& r) { return l == r.c_str(); }
- template<class CharType>
- bool operator==(const BasicCStringView<CharType>& r, const std::basic_string<CharType>& l)
- {
- return l == r.c_str();
- }
+ inline bool operator==(const CStringView& r, const std::string& l) { return l == r.c_str(); }
// notequals
- template<class CharType>
- bool operator!=(const BasicCStringView<CharType>& l, const BasicCStringView<CharType>& r)
+ inline bool operator!=(const CStringView& l, const CStringView& 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());
- }
+ inline bool operator!=(const char* l, const CStringView& r) { return !details::vcpkg_strcmp(l, r.c_str()); }
- template<class CharType>
- bool operator!=(const BasicCStringView<CharType>& r, const std::basic_string<CharType>& l)
- {
- return l != r.c_str();
- }
+ inline bool operator!=(const CStringView& r, const char* l) { return !details::vcpkg_strcmp(l, r.c_str()); }
- template<class CharType>
- bool operator!=(const std::basic_string<CharType>& l, const BasicCStringView<CharType>& r)
- {
- return l != r.c_str();
- }
+ inline bool operator!=(const CStringView& r, const std::string& l) { return l != r.c_str(); }
- using CStringView = BasicCStringView<char>;
- using CWStringView = BasicCStringView<wchar_t>;
+ inline bool operator!=(const std::string& l, const CStringView& r) { return l != r.c_str(); }
inline const char* to_printf_arg(const CStringView string_view) { return string_view.c_str(); }
- inline const wchar_t* to_wprintf_arg(const CWStringView string_view) { return string_view.c_str(); }
-
static_assert(sizeof(CStringView) == sizeof(void*), "CStringView must be a simple wrapper around char*");
- static_assert(sizeof(CWStringView) == sizeof(void*), "CWStringView must be a simple wrapper around wchar_t*");
}
diff --git a/toolsrc/include/vcpkg/base/strings.h b/toolsrc/include/vcpkg/base/strings.h
index 93b36a29d..4adcadb0d 100644
--- a/toolsrc/include/vcpkg/base/strings.h
+++ b/toolsrc/include/vcpkg/base/strings.h
@@ -47,9 +47,9 @@ namespace vcpkg::Strings
return details::wformat_internal(fmtstr, to_wprintf_arg(to_wprintf_arg(args))...);
}
- std::wstring to_utf16(const CStringView s);
+ std::wstring to_utf16(const CStringView& s);
- std::string to_utf8(const CWStringView w);
+ std::string to_utf8(const CWStringView& w);
std::string::const_iterator case_insensitive_ascii_find(const std::string& s, const std::string& pattern);
diff --git a/toolsrc/include/vcpkg/base/system.h b/toolsrc/include/vcpkg/base/system.h
index f2344c919..b396ef293 100644
--- a/toolsrc/include/vcpkg/base/system.h
+++ b/toolsrc/include/vcpkg/base/system.h
@@ -4,7 +4,6 @@
#include <vcpkg/base/optional.h>
#include <vcpkg/base/strings.h>
-
namespace vcpkg::System
{
tm get_current_date_time();
@@ -64,9 +63,7 @@ namespace vcpkg::System
Optional<std::string> get_environment_variable(const CStringView varname) noexcept;
- Optional<std::wstring> get_registry_string(void* base_hkey,
- const CWStringView subkey,
- const CWStringView valuename);
+ Optional<std::string> get_registry_string(void* base_hkey, const CStringView subkey, const CStringView valuename);
enum class CPUArchitecture
{
@@ -76,7 +73,7 @@ namespace vcpkg::System
ARM64,
};
- Optional<CPUArchitecture> to_cpu_architecture(CStringView arch);
+ Optional<CPUArchitecture> to_cpu_architecture(const CStringView& arch);
CPUArchitecture get_host_processor();
diff --git a/toolsrc/include/vcpkg/metrics.h b/toolsrc/include/vcpkg/metrics.h
index 41be5002d..d570624eb 100644
--- a/toolsrc/include/vcpkg/metrics.h
+++ b/toolsrc/include/vcpkg/metrics.h
@@ -23,6 +23,6 @@ namespace vcpkg::Metrics
extern Util::LockGuarded<Metrics> g_metrics;
- std::wstring get_SQM_user();
+ std::string get_SQM_user();
bool get_compiled_metrics_enabled();
}