Add StringMaker for std::(w)string_view

Fixes #1375
This commit is contained in:
melak47 2018-09-04 17:01:26 +02:00 committed by Martin Hořeňovský
parent 1eb42eed97
commit a575536abe
5 changed files with 68 additions and 13 deletions

View file

@ -116,14 +116,9 @@ std::string StringMaker<std::string>::convert(const std::string& str) {
return s;
}
#ifdef CATCH_CONFIG_WCHAR
std::string StringMaker<std::wstring>::convert(const std::wstring& wstr) {
std::string s;
s.reserve(wstr.size());
for (auto c : wstr) {
s += (c <= 0xff) ? static_cast<char>(c) : '?';
}
return ::Catch::Detail::stringify(s);
#ifdef CATCH_CONFIG_CPP17_STRING_VIEW
std::string StringMaker<std::string_view>::convert(std::string_view str) {
return ::Catch::Detail::stringify(std::string{ str });
}
#endif
@ -141,7 +136,23 @@ std::string StringMaker<char*>::convert(char* str) {
return{ "{null string}" };
}
}
#ifdef CATCH_CONFIG_WCHAR
std::string StringMaker<std::wstring>::convert(const std::wstring& wstr) {
std::string s;
s.reserve(wstr.size());
for (auto c : wstr) {
s += (c <= 0xff) ? static_cast<char>(c) : '?';
}
return ::Catch::Detail::stringify(s);
}
# ifdef CATCH_CONFIG_CPP17_STRING_VIEW
std::string StringMaker<std::wstring_view>::convert(std::wstring_view str) {
return StringMaker<std::wstring>::convert(std::wstring(str));
}
# endif
std::string StringMaker<wchar_t const*>::convert(wchar_t const * str) {
if (str) {
return ::Catch::Detail::stringify(std::wstring{ str });