cstring_view -> CStringView
ADD
include/CStringView.h
+#pragma once
+#include <string>
+
+namespace vcpkg
+{
+ template<class CharType>
+ struct BasicCStringView
+ {
+ constexpr BasicCStringView() : cstr(nullptr) {}
+ constexpr BasicCStringView(const CharType* cstr) : cstr(cstr) {}
+ 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;
+ };
+
+ using CStringView = BasicCStringView<char>;
+ using CWStringView = BasicCStringView<wchar_t>;
+
+ inline const char* to_printf_arg(const CStringView spec) { return spec.c_str(); }
+
+ inline const wchar_t* to_wprintf_arg(const CWStringView spec) { return spec.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*");
+}

DELETE
include/cstring_view.h
-#pragma once
-#include <string>
-
-namespace vcpkg
-{
- template<class CharType>
- struct basic_cstring_view
- {
- constexpr basic_cstring_view() : cstr(nullptr) {}
- constexpr basic_cstring_view(const CharType* cstr) : cstr(cstr) {}
- basic_cstring_view(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;
- };
-
- using cstring_view = basic_cstring_view<char>;
- using cwstring_view = basic_cstring_view<wchar_t>;
-
- inline const char* to_printf_arg(const cstring_view spec) { return spec.c_str(); }
-
- inline const wchar_t* to_wprintf_arg(const cwstring_view spec) { return spec.c_str(); }
-
- static_assert(sizeof(cstring_view) == sizeof(void*), "cstring_view must be a simple wrapper around char*");
- static_assert(sizeof(cwstring_view) == sizeof(void*), "cwstring_view must be a simple wrapper around wchar_t*");
-}

MODIFY
include/vcpkg_Checks.h
include/vcpkg_Checks.h
@@ -25,7 +25,7 @@ namespace vcpkg::Checks
// Part of the reason these exist is to not include extra headers in this one to avoid circular #includes.
[[noreturn]]
- void exit_with_message(const LineInfo& line_info, const cstring_view errorMessage);
+ void exit_with_message(const LineInfo& line_info, const CStringView errorMessage);
template <class Arg1, class...Args>
[[noreturn]]
@@ -36,7 +36,7 @@ namespace vcpkg::Checks
void check_exit(const LineInfo& line_info, bool expression);
- void check_exit(const LineInfo& line_info, bool expression, const cstring_view errorMessage);
+ void check_exit(const LineInfo& line_info, bool expression, const CStringView errorMessage);
template <class Arg1, class...Args>
void check_exit(const LineInfo& line_info, bool expression, const char* errorMessageTemplate, const Arg1 errorMessageArg1, const Args&... errorMessageArgs)

MODIFY
include/vcpkg_Input.h
include/vcpkg_Input.h
@@ -8,7 +8,7 @@ namespace vcpkg::Input
package_spec check_and_get_package_spec(
const std::string& package_spec_as_string,
const triplet& default_target_triplet,
- cstring_view example_text);
+ CStringView example_text);
void check_triplet(const triplet& t, const vcpkg_paths& paths);
}

MODIFY
include/vcpkg_Strings.h
include/vcpkg_Strings.h
#pragma once
#include <vector>
-#include "cstring_view.h"
+#include "CStringView.h"
namespace vcpkg::Strings::details
{
@@ -66,9 +66,9 @@ namespace vcpkg::Strings
return details::wformat_internal(fmtstr, to_wprintf_arg(to_wprintf_arg(args))...);
}
- std::wstring utf8_to_utf16(const cstring_view s);
+ std::wstring utf8_to_utf16(const CStringView s);
- std::string utf16_to_utf8(const cwstring_view w);
+ std::string utf16_to_utf8(const CWStringView w);
std::string::const_iterator case_insensitive_ascii_find(const std::string& s, const std::string& pattern);

MODIFY
include/vcpkg_System.h
include/vcpkg_System.h
@@ -15,13 +15,13 @@ namespace vcpkg::System
std::string output;
};
- int cmd_execute_clean(const cwstring_view cmd_line);
+ int cmd_execute_clean(const CWStringView cmd_line);
- int cmd_execute(const cwstring_view cmd_line);
+ int cmd_execute(const CWStringView cmd_line);
- exit_code_and_output cmd_execute_and_capture_output(const cwstring_view cmd_line);
+ exit_code_and_output cmd_execute_and_capture_output(const CWStringView cmd_line);
- std::wstring create_powershell_script_cmd(const fs::path& script_path, const cwstring_view args = L"");
+ std::wstring create_powershell_script_cmd(const fs::path& script_path, const CWStringView args = L"");
enum class color
{
@@ -30,10 +30,10 @@ namespace vcpkg::System
warning = 14,
};
- void print(const cstring_view message);
- void println(const cstring_view message);
- void print(const color c, const cstring_view message);
- void println(const color c, const cstring_view message);
+ void print(const CStringView message);
+ void println(const CStringView message);
+ void print(const color c, const CStringView message);
+ void println(const color c, const CStringView message);
template <class Arg1, class...Args>
void print(const char* messageTemplate, const Arg1& messageArg1, const Args&... messageArgs)
@@ -59,9 +59,9 @@ namespace vcpkg::System
return println(c, Strings::format(messageTemplate, messageArg1, messageArgs...));
}
- optional<std::wstring> get_environmental_variable(const cwstring_view varname) noexcept;
+ optional<std::wstring> get_environmental_variable(const CWStringView varname) noexcept;
- optional<std::wstring> get_registry_string(HKEY base, const cwstring_view subkey, const cwstring_view valuename);
+ optional<std::wstring> get_registry_string(HKEY base, const CWStringView subkey, const CWStringView valuename);
const fs::path& get_ProgramFiles_32_bit();

MODIFY
include/vcpkg_paths.h
include/vcpkg_paths.h
@@ -11,7 +11,7 @@ namespace vcpkg
{
fs::path dumpbin;
fs::path vcvarsall;
- cwstring_view version;
+ CWStringView version;
};
struct vcpkg_paths

MODIFY
include/vcpkglib.h
include/vcpkglib.h
@@ -24,10 +24,10 @@ namespace vcpkg
struct CMakeVariable
{
- CMakeVariable(const cwstring_view varname, const wchar_t* varvalue);
- CMakeVariable(const cwstring_view varname, const std::string& varvalue);
- CMakeVariable(const cwstring_view varname, const std::wstring& varvalue);
- CMakeVariable(const cwstring_view varname, const fs::path& path);
+ CMakeVariable(const CWStringView varname, const wchar_t* varvalue);
+ CMakeVariable(const CWStringView varname, const std::string& varvalue);
+ CMakeVariable(const CWStringView varname, const std::wstring& varvalue);
+ CMakeVariable(const CWStringView varname, const fs::path& path);
std::wstring s;
};

MODIFY
src/vcpkg_Checks.cpp
src/vcpkg_Checks.cpp
@@ -29,7 +29,7 @@ namespace vcpkg::Checks
}
[[noreturn]]
- void exit_with_message(const LineInfo& line_info, const cstring_view errorMessage)
+ void exit_with_message(const LineInfo& line_info, const CStringView errorMessage)
{
System::println(System::color::error, errorMessage);
exit_fail(line_info);
@@ -43,7 +43,7 @@ namespace vcpkg::Checks
}
}
- void check_exit(const LineInfo& line_info, bool expression, const cstring_view errorMessage)
+ void check_exit(const LineInfo& line_info, bool expression, const CStringView errorMessage)
{
if (!expression)
{

MODIFY
src/vcpkg_Input.cpp
src/vcpkg_Input.cpp
namespace vcpkg::Input
{
- package_spec check_and_get_package_spec(const std::string& package_spec_as_string, const triplet& default_target_triplet, cstring_view example_text)
+ package_spec check_and_get_package_spec(const std::string& package_spec_as_string, const triplet& default_target_triplet, CStringView example_text)
{
const std::string as_lowercase = Strings::ascii_to_lowercase(package_spec_as_string);
expected<package_spec> expected_spec = package_spec::from_string(as_lowercase, default_target_triplet);

MODIFY
src/vcpkg_Strings.cpp
src/vcpkg_Strings.cpp
@@ -50,13 +50,13 @@ namespace vcpkg::Strings::details
namespace vcpkg::Strings
{
- std::wstring utf8_to_utf16(const cstring_view s)
+ std::wstring utf8_to_utf16(const CStringView s)
{
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> conversion;
return conversion.from_bytes(s);
}
- std::string utf16_to_utf8(const cwstring_view w)
+ std::string utf16_to_utf8(const CWStringView w)
{
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> conversion;
return conversion.to_bytes(w);

MODIFY
src/vcpkg_System.cpp
src/vcpkg_System.cpp
@@ -13,7 +13,7 @@ namespace vcpkg::System
return fs::path(buf, buf + bytes);
}
- int cmd_execute_clean(const cwstring_view cmd_line)
+ int cmd_execute_clean(const CWStringView cmd_line)
{
static const std::wstring system_root = get_environmental_variable(L"SystemRoot").value_or_exit(VCPKG_LINE_INFO);
static const std::wstring system_32 = system_root + LR"(\system32)";
@@ -88,7 +88,7 @@ namespace vcpkg::System
return static_cast<int>(exit_code);
}
- int cmd_execute(const cwstring_view cmd_line)
+ int cmd_execute(const CWStringView cmd_line)
{
// Flush stdout before launching external process
_flushall();
@@ -99,7 +99,7 @@ namespace vcpkg::System
return exit_code;
}
- exit_code_and_output cmd_execute_and_capture_output(const cwstring_view cmd_line)
+ exit_code_and_output cmd_execute_and_capture_output(const CWStringView cmd_line)
{
// Flush stdout before launching external process
fflush(stdout);
@@ -125,24 +125,24 @@ namespace vcpkg::System
return { ec, output };
}
- std::wstring create_powershell_script_cmd(const fs::path& script_path, const cwstring_view args)
+ std::wstring create_powershell_script_cmd(const fs::path& script_path, const CWStringView args)
{
// TODO: switch out ExecutionPolicy Bypass with "Remove Mark Of The Web" code and restore RemoteSigned
return Strings::wformat(LR"(powershell -NoProfile -ExecutionPolicy Bypass -Command "& {& '%s' %s}")", script_path.native(), args);
}
- void print(const cstring_view message)
+ void print(const CStringView message)
{
fputs(message, stdout);
}
- void println(const cstring_view message)
+ void println(const CStringView message)
{
print(message);
putchar('\n');
}
- void print(const color c, const cstring_view message)
+ void print(const color c, const CStringView message)
{
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
@@ -155,13 +155,13 @@ namespace vcpkg::System
SetConsoleTextAttribute(hConsole, original_color);
}
- void println(const color c, const cstring_view message)
+ void println(const color c, const CStringView message)
{
print(c, message);
putchar('\n');
}
- optional<std::wstring> get_environmental_variable(const cwstring_view varname) noexcept
+ optional<std::wstring> get_environmental_variable(const CWStringView varname) noexcept
{
auto sz = GetEnvironmentVariableW(varname, nullptr, 0);
if (sz == 0)
@@ -181,7 +181,7 @@ namespace vcpkg::System
return hkey_type == REG_SZ || hkey_type == REG_MULTI_SZ || hkey_type == REG_EXPAND_SZ;
}
- optional<std::wstring> get_registry_string(HKEY base, const cwstring_view subKey, const cwstring_view valuename)
+ optional<std::wstring> get_registry_string(HKEY base, const CWStringView subKey, const CWStringView valuename)
{
HKEY k = nullptr;
LSTATUS ec = RegOpenKeyExW(base, subKey, NULL, KEY_READ, &k);

MODIFY
src/vcpkglib.cpp
src/vcpkglib.cpp
@@ -215,10 +215,10 @@ namespace vcpkg
return installed_files;
}
- CMakeVariable::CMakeVariable(const cwstring_view varname, const wchar_t* varvalue) : s(Strings::wformat(LR"("-D%s=%s")", varname, varvalue)) { }
- CMakeVariable::CMakeVariable(const cwstring_view varname, const std::string& varvalue) : CMakeVariable(varname, Strings::utf8_to_utf16(varvalue).c_str()) { }
- CMakeVariable::CMakeVariable(const cwstring_view varname, const std::wstring& varvalue) : CMakeVariable(varname, varvalue.c_str()) {}
- CMakeVariable::CMakeVariable(const cwstring_view varname, const fs::path& path) : CMakeVariable(varname, path.generic_wstring()) {}
+ CMakeVariable::CMakeVariable(const CWStringView varname, const wchar_t* varvalue) : s(Strings::wformat(LR"("-D%s=%s")", varname, varvalue)) { }
+ CMakeVariable::CMakeVariable(const CWStringView varname, const std::string& varvalue) : CMakeVariable(varname, Strings::utf8_to_utf16(varvalue).c_str()) { }
+ CMakeVariable::CMakeVariable(const CWStringView varname, const std::wstring& varvalue) : CMakeVariable(varname, varvalue.c_str()) {}
+ CMakeVariable::CMakeVariable(const CWStringView varname, const fs::path& path) : CMakeVariable(varname, path.generic_wstring()) {}
std::wstring make_cmake_cmd(const fs::path& cmake_exe, const fs::path& cmake_script, const std::vector<CMakeVariable>& pass_variables)
{

MODIFY
vcpkglib/vcpkglib.vcxproj
vcpkglib/vcpkglib.vcxproj
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="..\include\BinaryParagraph.h" />
- <ClInclude Include="..\include\cstring_view.h" />
+ <ClInclude Include="..\include\CStringView.h" />
<ClInclude Include="..\include\lazy.h" />
<ClInclude Include="..\include\LineInfo.h" />
<ClInclude Include="..\include\paragraph_parse_result.h" />

MODIFY
vcpkglib/vcpkglib.vcxproj.filters
vcpkglib/vcpkglib.vcxproj.filters
<ClInclude Include="..\include\vcpkg_expected.h">
<Filter>Header Files</Filter>
</ClInclude>
- <ClInclude Include="..\include\cstring_view.h">
- <Filter>Header Files</Filter>
- </ClInclude>
<ClInclude Include="..\include\version_t.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\SortedVector.h">
<Filter>Header Files</Filter>
</ClInclude>
+ <ClInclude Include="..\include\CStringView.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
</ItemGroup>
</Project>
\ No newline at end of file

cstring_view -> CStringView