diff options
| author | Alexander Karatarakis <alkarata@microsoft.com> | 2017-04-03 14:21:51 -0700 |
|---|---|---|
| committer | Alexander Karatarakis <alkarata@microsoft.com> | 2017-04-04 16:44:41 -0700 |
| commit | 604d0e58dab76f8ab31eb4f7807f7b561c4d571d (patch) | |
| tree | 56c5f18eaa5cc9e3fa7129a7479e243c4db44988 | |
| parent | 80e48c2756cc2c453ba221fe38c32f969d5139ea (diff) | |
| download | vcpkg-604d0e58dab76f8ab31eb4f7807f7b561c4d571d.tar.gz vcpkg-604d0e58dab76f8ab31eb4f7807f7b561c4d571d.zip | |
cstring_view -> CStringView
| -rw-r--r-- | toolsrc/include/CStringView.h | 30 | ||||
| -rw-r--r-- | toolsrc/include/cstring_view.h | 30 | ||||
| -rw-r--r-- | toolsrc/include/vcpkg_Checks.h | 4 | ||||
| -rw-r--r-- | toolsrc/include/vcpkg_Input.h | 2 | ||||
| -rw-r--r-- | toolsrc/include/vcpkg_Strings.h | 6 | ||||
| -rw-r--r-- | toolsrc/include/vcpkg_System.h | 20 | ||||
| -rw-r--r-- | toolsrc/include/vcpkg_paths.h | 2 | ||||
| -rw-r--r-- | toolsrc/include/vcpkglib.h | 8 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg_Checks.cpp | 4 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg_Input.cpp | 2 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg_Strings.cpp | 4 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg_System.cpp | 20 | ||||
| -rw-r--r-- | toolsrc/src/vcpkglib.cpp | 8 | ||||
| -rw-r--r-- | toolsrc/vcpkglib/vcpkglib.vcxproj | 2 | ||||
| -rw-r--r-- | toolsrc/vcpkglib/vcpkglib.vcxproj.filters | 6 |
15 files changed, 74 insertions, 74 deletions
diff --git a/toolsrc/include/CStringView.h b/toolsrc/include/CStringView.h new file mode 100644 index 000000000..3da76e63f --- /dev/null +++ b/toolsrc/include/CStringView.h @@ -0,0 +1,30 @@ +#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*"); +} diff --git a/toolsrc/include/cstring_view.h b/toolsrc/include/cstring_view.h deleted file mode 100644 index 92f1a6fa5..000000000 --- a/toolsrc/include/cstring_view.h +++ /dev/null @@ -1,30 +0,0 @@ -#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*"); -} diff --git a/toolsrc/include/vcpkg_Checks.h b/toolsrc/include/vcpkg_Checks.h index 5bcc59fee..8e7a35f4d 100644 --- a/toolsrc/include/vcpkg_Checks.h +++ b/toolsrc/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) diff --git a/toolsrc/include/vcpkg_Input.h b/toolsrc/include/vcpkg_Input.h index 4f102d029..868b77a44 100644 --- a/toolsrc/include/vcpkg_Input.h +++ b/toolsrc/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); } diff --git a/toolsrc/include/vcpkg_Strings.h b/toolsrc/include/vcpkg_Strings.h index e0ad51a8e..03b16975e 100644 --- a/toolsrc/include/vcpkg_Strings.h +++ b/toolsrc/include/vcpkg_Strings.h @@ -1,7 +1,7 @@ #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); diff --git a/toolsrc/include/vcpkg_System.h b/toolsrc/include/vcpkg_System.h index 33aad646c..2c2b945f4 100644 --- a/toolsrc/include/vcpkg_System.h +++ b/toolsrc/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(); diff --git a/toolsrc/include/vcpkg_paths.h b/toolsrc/include/vcpkg_paths.h index 474f47255..5bfc91967 100644 --- a/toolsrc/include/vcpkg_paths.h +++ b/toolsrc/include/vcpkg_paths.h @@ -11,7 +11,7 @@ namespace vcpkg { fs::path dumpbin; fs::path vcvarsall; - cwstring_view version; + CWStringView version; }; struct vcpkg_paths diff --git a/toolsrc/include/vcpkglib.h b/toolsrc/include/vcpkglib.h index bab1c28a1..6acfb6227 100644 --- a/toolsrc/include/vcpkglib.h +++ b/toolsrc/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; }; diff --git a/toolsrc/src/vcpkg_Checks.cpp b/toolsrc/src/vcpkg_Checks.cpp index acc15df99..18154ccf3 100644 --- a/toolsrc/src/vcpkg_Checks.cpp +++ b/toolsrc/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) { diff --git a/toolsrc/src/vcpkg_Input.cpp b/toolsrc/src/vcpkg_Input.cpp index 82dcca8a8..552ddc3da 100644 --- a/toolsrc/src/vcpkg_Input.cpp +++ b/toolsrc/src/vcpkg_Input.cpp @@ -6,7 +6,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) + 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); diff --git a/toolsrc/src/vcpkg_Strings.cpp b/toolsrc/src/vcpkg_Strings.cpp index 4878a02f4..26dc6388b 100644 --- a/toolsrc/src/vcpkg_Strings.cpp +++ b/toolsrc/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); diff --git a/toolsrc/src/vcpkg_System.cpp b/toolsrc/src/vcpkg_System.cpp index 688773aea..bf0ae9ebd 100644 --- a/toolsrc/src/vcpkg_System.cpp +++ b/toolsrc/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); diff --git a/toolsrc/src/vcpkglib.cpp b/toolsrc/src/vcpkglib.cpp index 152b9ac2b..8dff013bd 100644 --- a/toolsrc/src/vcpkglib.cpp +++ b/toolsrc/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) { diff --git a/toolsrc/vcpkglib/vcpkglib.vcxproj b/toolsrc/vcpkglib/vcpkglib.vcxproj index 9234f9c77..c26bbf885 100644 --- a/toolsrc/vcpkglib/vcpkglib.vcxproj +++ b/toolsrc/vcpkglib/vcpkglib.vcxproj @@ -137,7 +137,7 @@ </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" /> diff --git a/toolsrc/vcpkglib/vcpkglib.vcxproj.filters b/toolsrc/vcpkglib/vcpkglib.vcxproj.filters index 9901bcd95..00a54dafd 100644 --- a/toolsrc/vcpkglib/vcpkglib.vcxproj.filters +++ b/toolsrc/vcpkglib/vcpkglib.vcxproj.filters @@ -302,9 +302,6 @@ <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> @@ -314,5 +311,8 @@ <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 |
