diff options
| author | Alexander Karatarakis <alkarata@microsoft.com> | 2017-03-31 17:53:02 -0700 |
|---|---|---|
| committer | Alexander Karatarakis <alkarata@microsoft.com> | 2017-03-31 17:53:02 -0700 |
| commit | d3a54b0042041ef6cd3ee12f420c746b4e539420 (patch) | |
| tree | 6a685b671f4abcf14ee06fee51ead74835edea57 | |
| parent | 1e33e2e21362611e350b22f401f25eb50366a2bd (diff) | |
| download | vcpkg-d3a54b0042041ef6cd3ee12f420c746b4e539420.tar.gz vcpkg-d3a54b0042041ef6cd3ee12f420c746b4e539420.zip | |
Place cXstring_view in a separate header
| -rw-r--r-- | toolsrc/include/cstring_view.h | 38 | ||||
| -rw-r--r-- | toolsrc/include/vcpkg_Strings.h | 35 | ||||
| -rw-r--r-- | toolsrc/vcpkglib/vcpkglib.vcxproj | 1 | ||||
| -rw-r--r-- | toolsrc/vcpkglib/vcpkglib.vcxproj.filters | 3 |
4 files changed, 43 insertions, 34 deletions
diff --git a/toolsrc/include/cstring_view.h b/toolsrc/include/cstring_view.h new file mode 100644 index 000000000..f516f9fec --- /dev/null +++ b/toolsrc/include/cstring_view.h @@ -0,0 +1,38 @@ +#pragma once +#include <string> + +namespace vcpkg +{ + struct cstring_view + { + cstring_view(const char* cstr) : cstr(cstr) {} + cstring_view(const std::string& str) : cstr(str.c_str()) {} + + operator const char*() const { return cstr; } + + const char* c_str() const { return cstr; } + + private: + const char* cstr; + }; + + inline const char* to_printf_arg(const cstring_view spec) { return spec.c_str(); } + + struct cwstring_view + { + cwstring_view(const wchar_t* cstr) : cstr(cstr) {} + cwstring_view(const std::wstring& str) : cstr(str.c_str()) {} + + operator const wchar_t*() const { return cstr; } + + const wchar_t* c_str() const { return cstr; } + + private: + const wchar_t* cstr; + }; + + 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_Strings.h b/toolsrc/include/vcpkg_Strings.h index db3851755..b84cc943f 100644 --- a/toolsrc/include/vcpkg_Strings.h +++ b/toolsrc/include/vcpkg_Strings.h @@ -1,40 +1,7 @@ #pragma once #include <vector> - -namespace vcpkg -{ - struct cstring_view - { - cstring_view(const char* cstr) : cstr(cstr) {} - cstring_view(const std::string& str) : cstr(str.c_str()) {} - - operator const char*() const { return cstr; } - - const char* c_str() const { return cstr; } - - private: - const char* cstr; - }; - - inline const char* to_printf_arg(const cstring_view spec) { return spec.c_str(); } - - - struct cwstring_view - { - cwstring_view(const wchar_t* cstr) : cstr(cstr) {} - cwstring_view(const std::wstring& str) : cstr(str.c_str()) {} - - operator const wchar_t*() const { return cstr; } - - const wchar_t* c_str() const { return cstr; } - - private: - const wchar_t* cstr; - }; - - inline const wchar_t* to_wprintf_arg(const cwstring_view spec) { return spec.c_str(); } -} +#include "cstring_view.h" namespace vcpkg::Strings::details { diff --git a/toolsrc/vcpkglib/vcpkglib.vcxproj b/toolsrc/vcpkglib/vcpkglib.vcxproj index c00571cc4..e5023dd68 100644 --- a/toolsrc/vcpkglib/vcpkglib.vcxproj +++ b/toolsrc/vcpkglib/vcpkglib.vcxproj @@ -137,6 +137,7 @@ </ItemDefinitionGroup> <ItemGroup> <ClInclude Include="..\include\BinaryParagraph.h" /> + <ClInclude Include="..\include\cstring_view.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 cd9460f67..6b9a6b65d 100644 --- a/toolsrc/vcpkglib/vcpkglib.vcxproj.filters +++ b/toolsrc/vcpkglib/vcpkglib.vcxproj.filters @@ -302,5 +302,8 @@ <ClInclude Include="..\include\vcpkg_expected.h"> <Filter>Header Files</Filter> </ClInclude> + <ClInclude Include="..\include\cstring_view.h"> + <Filter>Header Files</Filter> + </ClInclude> </ItemGroup> </Project>
\ No newline at end of file |
