forked from fmtlib/fmt
Fix format_to + FMT_STRING for wide character type (#3931)
Added overload that takes a wformat_string. Fixes issue #3925.
This commit is contained in:
committed by
GitHub
parent
99735764ea
commit
ee0c3351a4
@ -141,6 +141,13 @@ auto format(wformat_string<T...> fmt, T&&... args) -> std::wstring {
|
|||||||
return vformat(fmt::wstring_view(fmt), fmt::make_wformat_args(args...));
|
return vformat(fmt::wstring_view(fmt), fmt::make_wformat_args(args...));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename OutputIt, typename... T>
|
||||||
|
auto format_to(OutputIt out, wformat_string<T...> fmt, T&&... args)
|
||||||
|
-> OutputIt {
|
||||||
|
return vformat_to(out, fmt::wstring_view(fmt),
|
||||||
|
fmt::make_wformat_args(args...));
|
||||||
|
}
|
||||||
|
|
||||||
// Pass char_t as a default template parameter instead of using
|
// Pass char_t as a default template parameter instead of using
|
||||||
// std::basic_string<char_t<S>> to reduce the symbol size.
|
// std::basic_string<char_t<S>> to reduce the symbol size.
|
||||||
template <typename S, typename... T,
|
template <typename S, typename... T,
|
||||||
@ -186,8 +193,9 @@ auto vformat_to(OutputIt out, const S& format_str,
|
|||||||
|
|
||||||
template <typename OutputIt, typename S, typename... T,
|
template <typename OutputIt, typename S, typename... T,
|
||||||
typename Char = detail::format_string_char_t<S>,
|
typename Char = detail::format_string_char_t<S>,
|
||||||
FMT_ENABLE_IF(detail::is_output_iterator<OutputIt, Char>::value&&
|
FMT_ENABLE_IF(detail::is_output_iterator<OutputIt, Char>::value &&
|
||||||
detail::is_exotic_char<Char>::value)>
|
!std::is_same<Char, char>::value &&
|
||||||
|
!std::is_same<Char, wchar_t>::value)>
|
||||||
inline auto format_to(OutputIt out, const S& fmt, T&&... args) -> OutputIt {
|
inline auto format_to(OutputIt out, const S& fmt, T&&... args) -> OutputIt {
|
||||||
return vformat_to(out, detail::to_string_view(fmt),
|
return vformat_to(out, detail::to_string_view(fmt),
|
||||||
fmt::make_format_args<buffered_context<Char>>(args...));
|
fmt::make_format_args<buffered_context<Char>>(args...));
|
||||||
|
@ -195,6 +195,12 @@ TEST(xchar_test, format_to) {
|
|||||||
EXPECT_STREQ(buf.data(), L"42");
|
EXPECT_STREQ(buf.data(), L"42");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(xchar_test, compile_time_string_format_to) {
|
||||||
|
std::wstring ws;
|
||||||
|
fmt::format_to(std::back_inserter(ws), FMT_STRING(L"{}"), 42);
|
||||||
|
EXPECT_EQ(L"42", ws);
|
||||||
|
}
|
||||||
|
|
||||||
TEST(xchar_test, vformat_to) {
|
TEST(xchar_test, vformat_to) {
|
||||||
int n = 42;
|
int n = 42;
|
||||||
auto args = fmt::make_wformat_args(n);
|
auto args = fmt::make_wformat_args(n);
|
||||||
|
Reference in New Issue
Block a user