[vcpkg] Add more operator== to CStringView. Uppercase Span to follow naming convention.
MODIFY
include/CStringView.h
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)
{

MODIFY
include/SourceParagraph.h
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});

MODIFY
include/Span.h
include/Span.h
#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()};
+}

MODIFY
src/PostBuildLint.cpp
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))
{

MODIFY
src/SourceParagraph.cpp
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);

MODIFY
src/VcpkgPaths.cpp
src/VcpkgPaths.cpp
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)

MODIFY
src/vcpkg_Build.cpp
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},

MODIFY
src/vcpkg_Strings.cpp
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)

MODIFY
src/vcpkg_System.cpp
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;

[vcpkg] Add more operator== to CStringView. Uppercase Span to follow naming convention.