mirror of
https://github.com/fmtlib/fmt.git
synced 2024-12-27 03:21:34 +00:00
Escape range items convertible to std::string_view
This commit is contained in:
parent
33ee4cc516
commit
796662a612
@ -65,7 +65,9 @@ template <typename T> class is_std_string_like {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
static FMT_CONSTEXPR_DECL const bool value =
|
static FMT_CONSTEXPR_DECL const bool value =
|
||||||
is_string<T>::value || !std::is_void<decltype(check<T>(nullptr))>::value;
|
is_string<T>::value ||
|
||||||
|
std::is_convertible<T, std_string_view<char>>::value ||
|
||||||
|
!std::is_void<decltype(check<T>(nullptr))>::value;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename Char>
|
template <typename Char>
|
||||||
@ -520,6 +522,13 @@ auto write_range_entry(OutputIt out, basic_string_view<Char> str) -> OutputIt {
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename Char, typename OutputIt, typename T,
|
||||||
|
FMT_ENABLE_IF(std::is_convertible<T, std_string_view<char>>::value)>
|
||||||
|
inline auto write_range_entry(OutputIt out, const T& str) -> OutputIt {
|
||||||
|
auto sv = std_string_view<Char>(str);
|
||||||
|
return write_range_entry<Char>(out, basic_string_view<Char>(sv));
|
||||||
|
}
|
||||||
|
|
||||||
template <typename Char, typename OutputIt, typename Arg,
|
template <typename Char, typename OutputIt, typename Arg,
|
||||||
FMT_ENABLE_IF(std::is_same<Arg, Char>::value)>
|
FMT_ENABLE_IF(std::is_same<Arg, Char>::value)>
|
||||||
OutputIt write_range_entry(OutputIt out, const Arg v) {
|
OutputIt write_range_entry(OutputIt out, const Arg v) {
|
||||||
|
@ -350,3 +350,14 @@ TEST(ranges_test, escape_string) {
|
|||||||
"[\"\\xf4\\x8f\\xbf\\xc0\"]");
|
"[\"\\xf4\\x8f\\xbf\\xc0\"]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef FMT_USE_STRING_VIEW
|
||||||
|
struct convertible_to_string_view {
|
||||||
|
operator std::string_view() const { return "foo"; }
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST(ranges_test, escape_convertible_to_string_view) {
|
||||||
|
EXPECT_EQ(fmt::format("{}", std::vector<convertible_to_string_view>(1)),
|
||||||
|
"[\"foo\"]");
|
||||||
|
}
|
||||||
|
#endif // FMT_USE_STRING_VIEW
|
||||||
|
Loading…
Reference in New Issue
Block a user