diff options
| author | Robert Schumacher <roschuma@microsoft.com> | 2017-10-03 15:51:04 -0700 |
|---|---|---|
| committer | Robert Schumacher <roschuma@microsoft.com> | 2017-10-03 15:51:24 -0700 |
| commit | 3838d5880470fdc884f035ed3d1c67d3bdd1e16e (patch) | |
| tree | a12cdb0b99a4999649d93a7710d7a0a96fc1ffe9 | |
| parent | 85f0a060db8be34f4fce134be450bd1e4bd2b06f (diff) | |
| download | vcpkg-3838d5880470fdc884f035ed3d1c67d3bdd1e16e.tar.gz vcpkg-3838d5880470fdc884f035ed3d1c67d3bdd1e16e.zip | |
[vcpkg] Add more operator== to CStringView. Uppercase Span to follow naming convention.
| -rw-r--r-- | toolsrc/include/CStringView.h | 44 | ||||
| -rw-r--r-- | toolsrc/include/SourceParagraph.h | 2 | ||||
| -rw-r--r-- | toolsrc/include/Span.h | 28 | ||||
| -rw-r--r-- | toolsrc/src/PostBuildLint.cpp | 4 | ||||
| -rw-r--r-- | toolsrc/src/SourceParagraph.cpp | 4 | ||||
| -rw-r--r-- | toolsrc/src/VcpkgPaths.cpp | 6 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg_Build.cpp | 2 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg_Strings.cpp | 2 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg_System.cpp | 13 |
9 files changed, 80 insertions, 25 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) { diff --git a/toolsrc/include/SourceParagraph.h b/toolsrc/include/SourceParagraph.h index 1357b3769..ccf9faf4f 100644 --- a/toolsrc/include/SourceParagraph.h +++ b/toolsrc/include/SourceParagraph.h @@ -57,7 +57,7 @@ namespace vcpkg std::vector<std::unique_ptr<FeatureParagraph>> feature_paragraphs; }; - void print_error_message(span<const std::unique_ptr<Parse::ParseControlErrorInfo>> error_info_list); + void print_error_message(Span<const std::unique_ptr<Parse::ParseControlErrorInfo>> error_info_list); inline void print_error_message(const std::unique_ptr<Parse::ParseControlErrorInfo>& error_info_list) { return print_error_message({&error_info_list, 1}); diff --git a/toolsrc/include/Span.h b/toolsrc/include/Span.h index b16af2cef..b2c9acdbc 100644 --- a/toolsrc/include/Span.h +++ b/toolsrc/include/Span.h @@ -5,7 +5,7 @@ #include <vector>
template<class T>
-struct span
+struct Span
{
public:
using element_type = T;
@@ -13,18 +13,18 @@ public: using reference = T&;
using iterator = T*;
- constexpr span() noexcept : m_ptr(nullptr), m_count(0) {}
- constexpr span(std::nullptr_t) noexcept : span() {}
- constexpr span(T* ptr, size_t count) noexcept : m_ptr(ptr), m_count(count) {}
- constexpr span(T* ptr_begin, T* ptr_end) noexcept : m_ptr(ptr_begin), m_count(ptr_end - ptr_begin) {}
+ constexpr Span() noexcept : m_ptr(nullptr), m_count(0) {}
+ constexpr Span(std::nullptr_t) noexcept : Span() {}
+ constexpr Span(T* ptr, size_t count) noexcept : m_ptr(ptr), m_count(count) {}
+ constexpr Span(T* ptr_begin, T* ptr_end) noexcept : m_ptr(ptr_begin), m_count(ptr_end - ptr_begin) {}
template<size_t N>
- constexpr span(T (&arr)[N]) noexcept : span(arr, N)
+ constexpr Span(T (&arr)[N]) noexcept : Span(arr, N)
{
}
- span(std::vector<T>& v) noexcept : span(v.data(), v.size()) {}
- span(const std::vector<std::remove_const_t<T>>& v) noexcept : span(v.data(), v.size()) {}
+ Span(std::vector<T>& v) noexcept : Span(v.data(), v.size()) {}
+ Span(const std::vector<std::remove_const_t<T>>& v) noexcept : Span(v.data(), v.size()) {}
constexpr iterator begin() const { return m_ptr; }
constexpr iterator end() const { return m_ptr + m_count; }
@@ -36,3 +36,15 @@ private: pointer m_ptr;
size_t m_count;
};
+
+template<class T>
+Span<T> make_span(std::vector<T>& v)
+{
+ return {v.data(), v.size()};
+}
+
+template<class T>
+Span<const T> make_span(const std::vector<T>& v)
+{
+ return {v.data(), v.size()};
+}
diff --git a/toolsrc/src/PostBuildLint.cpp b/toolsrc/src/PostBuildLint.cpp index 1fd48d3ec..416d4a636 100644 --- a/toolsrc/src/PostBuildLint.cpp +++ b/toolsrc/src/PostBuildLint.cpp @@ -38,7 +38,7 @@ namespace vcpkg::PostBuildLint } }; - const std::vector<OutdatedDynamicCrt>& get_outdated_dynamic_crts() + Span<const OutdatedDynamicCrt> get_outdated_dynamic_crts(CStringView toolset) { static const std::vector<OutdatedDynamicCrt> V_NO_MSVCRT = { {"msvcp100.dll", R"(msvcp100\.dll)"}, @@ -662,7 +662,7 @@ namespace vcpkg::PostBuildLint "Running command:\n %s\n failed", Strings::to_utf8(cmd_line)); - for (const OutdatedDynamicCrt& outdated_crt : get_outdated_dynamic_crts()) + for (const OutdatedDynamicCrt& outdated_crt : get_outdated_dynamic_crts("v141")) { if (std::regex_search(ec_data.output.cbegin(), ec_data.output.cend(), outdated_crt.regex)) { diff --git a/toolsrc/src/SourceParagraph.cpp b/toolsrc/src/SourceParagraph.cpp index 171689ce7..0f1a38d19 100644 --- a/toolsrc/src/SourceParagraph.cpp +++ b/toolsrc/src/SourceParagraph.cpp @@ -25,7 +25,7 @@ namespace vcpkg static const std::string VERSION = "Version"; } - static span<const std::string> get_list_of_valid_fields() + static Span<const std::string> get_list_of_valid_fields() { static const std::string valid_fields[] = { Fields::SOURCE, @@ -38,7 +38,7 @@ namespace vcpkg return valid_fields; } - void print_error_message(span<const std::unique_ptr<Parse::ParseControlErrorInfo>> error_info_list) + void print_error_message(Span<const std::unique_ptr<Parse::ParseControlErrorInfo>> error_info_list) { Checks::check_exit(VCPKG_LINE_INFO, error_info_list.size() > 0); diff --git a/toolsrc/src/VcpkgPaths.cpp b/toolsrc/src/VcpkgPaths.cpp index d491cb7fb..cb00183fd 100644 --- a/toolsrc/src/VcpkgPaths.cpp +++ b/toolsrc/src/VcpkgPaths.cpp @@ -10,9 +10,9 @@ namespace vcpkg { - // Intentionally wstring so we can easily use operator== with CWStringView. - static const std::wstring V_140 = L"v140"; - static const std::wstring V_141 = L"v141"; + static constexpr CWStringView V_120 = L"v120"; + static constexpr CWStringView V_140 = L"v140"; + static constexpr CWStringView V_141 = L"v141"; static bool exists_and_has_equal_or_greater_version(const std::wstring& version_cmd, const std::array<int, 3>& expected_version) diff --git a/toolsrc/src/vcpkg_Build.cpp b/toolsrc/src/vcpkg_Build.cpp index 5ac13c6c6..853f84998 100644 --- a/toolsrc/src/vcpkg_Build.cpp +++ b/toolsrc/src/vcpkg_Build.cpp @@ -165,7 +165,7 @@ namespace vcpkg::Build {L"PORT", config.src.name}, {L"CURRENT_PORT_DIR", config.port_dir / "/."}, {L"TARGET_TRIPLET", triplet.canonical_name()}, - {L"VCPKG_PLATFORM_TOOLSET", toolset.version}, + {L"VCPKG_PLATFORM_TOOLSET", toolset.version.c_str()}, {L"VCPKG_USE_HEAD_VERSION", to_bool(config.build_package_options.use_head_version) ? L"1" : L"0"}, {L"_VCPKG_NO_DOWNLOADS", !to_bool(config.build_package_options.allow_downloads) ? L"1" : L"0"}, {L"GIT", git_exe_path}, diff --git a/toolsrc/src/vcpkg_Strings.cpp b/toolsrc/src/vcpkg_Strings.cpp index 07147862f..21df2c309 100644 --- a/toolsrc/src/vcpkg_Strings.cpp +++ b/toolsrc/src/vcpkg_Strings.cpp @@ -106,7 +106,7 @@ namespace vcpkg::Strings int case_insensitive_ascii_compare(const CStringView left, const CStringView right) { - return _stricmp(left, right); + return _stricmp(left.c_str(), right.c_str()); } std::string ascii_to_lowercase(const std::string& input) diff --git a/toolsrc/src/vcpkg_System.cpp b/toolsrc/src/vcpkg_System.cpp index 40e335117..4d2e88b73 100644 --- a/toolsrc/src/vcpkg_System.cpp +++ b/toolsrc/src/vcpkg_System.cpp @@ -226,7 +226,7 @@ namespace vcpkg::System void println() { println(Strings::EMPTY); } - void print(const CStringView message) { fputs(message, stdout); } + void print(const CStringView message) { fputs(message.c_str(), stdout); } void println(const CStringView message) { @@ -255,13 +255,13 @@ namespace vcpkg::System Optional<std::wstring> get_environment_variable(const CWStringView varname) noexcept { - const auto sz = GetEnvironmentVariableW(varname, nullptr, 0); + const auto sz = GetEnvironmentVariableW(varname.c_str(), nullptr, 0); if (sz == 0) return nullopt; std::wstring ret(sz, L'\0'); Checks::check_exit(VCPKG_LINE_INFO, MAXDWORD >= ret.size()); - const auto sz2 = GetEnvironmentVariableW(varname, ret.data(), static_cast<DWORD>(ret.size())); + const auto sz2 = GetEnvironmentVariableW(varname.c_str(), ret.data(), static_cast<DWORD>(ret.size())); Checks::check_exit(VCPKG_LINE_INFO, sz2 + 1 == sz); ret.pop_back(); return ret; @@ -275,19 +275,20 @@ namespace vcpkg::System Optional<std::wstring> get_registry_string(HKEY base, const CWStringView sub_key, const CWStringView valuename) { HKEY k = nullptr; - const LSTATUS ec = RegOpenKeyExW(base, sub_key, NULL, KEY_READ, &k); + const LSTATUS ec = RegOpenKeyExW(base, sub_key.c_str(), NULL, KEY_READ, &k); if (ec != ERROR_SUCCESS) return nullopt; DWORD dw_buffer_size = 0; DWORD dw_type = 0; - auto rc = RegQueryValueExW(k, valuename, nullptr, &dw_type, nullptr, &dw_buffer_size); + auto rc = RegQueryValueExW(k, valuename.c_str(), nullptr, &dw_type, nullptr, &dw_buffer_size); if (rc != ERROR_SUCCESS || !is_string_keytype(dw_type) || dw_buffer_size == 0 || dw_buffer_size % sizeof(wchar_t) != 0) return nullopt; std::wstring ret; ret.resize(dw_buffer_size / sizeof(wchar_t)); - rc = RegQueryValueExW(k, valuename, nullptr, &dw_type, reinterpret_cast<LPBYTE>(ret.data()), &dw_buffer_size); + rc = RegQueryValueExW( + k, valuename.c_str(), nullptr, &dw_type, reinterpret_cast<LPBYTE>(ret.data()), &dw_buffer_size); if (rc != ERROR_SUCCESS || !is_string_keytype(dw_type) || dw_buffer_size != sizeof(wchar_t) * ret.size()) return nullopt; |
