Improved printing of std::basic_string_view objects
This commit is contained in:
parent
41e65dced7
commit
9fd6fea20c
@ -725,6 +725,49 @@ inline void PrintTo(const ::std::wstring& s, ::std::ostream* os) {
|
|||||||
}
|
}
|
||||||
#endif // GTEST_HAS_STD_WSTRING
|
#endif // GTEST_HAS_STD_WSTRING
|
||||||
|
|
||||||
|
#if defined(__cpp_lib_string_view) || GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
|
// Overloads for ::std::string_view.
|
||||||
|
#ifdef GTEST_HAS_ABSL
|
||||||
|
// Otherwise internal::StringView is implemented using ::std::string_view
|
||||||
|
// and has already overloaded PrintTo for it below.
|
||||||
|
GTEST_API_ void PrintStringTo(const ::std::string_view& sv, ::std::ostream* os);
|
||||||
|
inline void PrintTo(const ::std::string_view& sv, ::std::ostream* os) {
|
||||||
|
PrintStringTo(sv, os);
|
||||||
|
}
|
||||||
|
#endif // GTEST_HAS_ABSL
|
||||||
|
|
||||||
|
// Overloads for ::std::u8string_view
|
||||||
|
#ifdef __cpp_lib_char8_t
|
||||||
|
GTEST_API_ void PrintU8StringTo(const ::std::u8string_view& sv, ::std::ostream* os);
|
||||||
|
inline void PrintTo(const ::std::u8string_view& sv, ::std::ostream* os) {
|
||||||
|
PrintU8StringTo(sv, os);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Overloads for ::std::u16string_view
|
||||||
|
GTEST_API_ void PrintU16StringTo(const ::std::u16string_view& sv, ::std::ostream* os);
|
||||||
|
inline void PrintTo(const ::std::u16string_view& sv, ::std::ostream* os) {
|
||||||
|
PrintU16StringTo(sv, os);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Overloads for ::std::u32string_view
|
||||||
|
GTEST_API_ void PrintU32StringTo(const ::std::u32string_view& sv, ::std::ostream* os);
|
||||||
|
inline void PrintTo(const ::std::u32string_view& sv, ::std::ostream* os) {
|
||||||
|
PrintU32StringTo(sv, os);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Overloads for ::std::wstring_view.
|
||||||
|
#if GTEST_HAS_STD_WSTRING
|
||||||
|
GTEST_API_ void PrintWideStringTo(const ::std::wstring_view& sv, ::std::ostream* os);
|
||||||
|
inline void PrintTo(const ::std::wstring_view& sv, ::std::ostream* os) {
|
||||||
|
PrintWideStringTo(sv, os);
|
||||||
|
}
|
||||||
|
#endif // GTEST_HAS_STD_WSTRING
|
||||||
|
#endif // __cpp_lib_string_view
|
||||||
|
|
||||||
|
|
||||||
#if GTEST_INTERNAL_HAS_STRING_VIEW
|
#if GTEST_INTERNAL_HAS_STRING_VIEW
|
||||||
// Overload for internal::StringView.
|
// Overload for internal::StringView.
|
||||||
inline void PrintTo(internal::StringView sp, ::std::ostream* os) {
|
inline void PrintTo(internal::StringView sp, ::std::ostream* os) {
|
||||||
|
@ -550,6 +550,39 @@ void PrintWideStringTo(const ::std::wstring& s, ostream* os) {
|
|||||||
}
|
}
|
||||||
#endif // GTEST_HAS_STD_WSTRING
|
#endif // GTEST_HAS_STD_WSTRING
|
||||||
|
|
||||||
|
#if defined(__cpp_lib_string_view) || GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L
|
||||||
|
|
||||||
|
#ifdef GTEST_HAS_ABSL
|
||||||
|
void PrintStringTo(const ::std::string_view& sv, ostream* os) {
|
||||||
|
if (PrintCharsAsStringTo(sv.data(), sv.size(), os) == kHexEscape) {
|
||||||
|
if (GTEST_FLAG_GET(print_utf8)) {
|
||||||
|
ConditionalPrintAsText(sv.data(), sv.size(), os);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cpp_lib_char8_t
|
||||||
|
void PrintU8StringTo(const ::std::u8string_view& sv, ostream* os) {
|
||||||
|
PrintCharsAsStringTo(sv.data(), sv.size(), os);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void PrintU16StringTo(const ::std::u16string_view& sv, ostream* os) {
|
||||||
|
PrintCharsAsStringTo(sv.data(), sv.size(), os);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PrintU32StringTo(const ::std::u32string_view& sv, ostream* os) {
|
||||||
|
PrintCharsAsStringTo(sv.data(), sv.size(), os);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if GTEST_HAS_STD_WSTRING
|
||||||
|
void PrintWideStringTo(const ::std::wstring_view& sv, ::std::ostream* os) {
|
||||||
|
PrintCharsAsStringTo(sv.data(), sv.size(), os);
|
||||||
|
}
|
||||||
|
#endif // GTEST_HAS_STD_WSTRING
|
||||||
|
#endif // __cpp_lib_string_view
|
||||||
|
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
|
|
||||||
} // namespace testing
|
} // namespace testing
|
||||||
|
Loading…
Reference in New Issue
Block a user