Add wchar_t overload of format_to_n (#764)
This commit is contained in:
parent
c2fbadb9cf
commit
0508bbc7ae
@ -3526,6 +3526,13 @@ inline OutputIt vformat_to(OutputIt out, string_view format_str,
|
||||
typedef output_range<OutputIt, char> range;
|
||||
return vformat_to<arg_formatter<range>>(range(out), format_str, args);
|
||||
}
|
||||
template <typename OutputIt, typename... Args>
|
||||
inline OutputIt vformat_to(
|
||||
OutputIt out, wstring_view format_str,
|
||||
typename format_args_t<OutputIt, wchar_t>::type args) {
|
||||
typedef output_range<OutputIt, wchar_t> range;
|
||||
return vformat_to<arg_formatter<range>>(range(out), format_str, args);
|
||||
}
|
||||
|
||||
/**
|
||||
\rst
|
||||
@ -3578,12 +3585,20 @@ struct format_to_n_result {
|
||||
*/
|
||||
template <typename OutputIt, typename... Args>
|
||||
inline format_to_n_result<OutputIt> format_to_n(
|
||||
OutputIt out, std::size_t n, string_view format_str, const Args & ... args) {
|
||||
OutputIt out, std::size_t n, string_view format_str, const Args &... args) {
|
||||
typedef internal::truncating_iterator<OutputIt> It;
|
||||
auto it = vformat_to(It(out, n), format_str,
|
||||
make_format_args<typename format_context_t<It>::type>(args...));
|
||||
return {it.base(), it.count()};
|
||||
}
|
||||
template <typename OutputIt, typename... Args>
|
||||
inline format_to_n_result<OutputIt> format_to_n(
|
||||
OutputIt out, std::size_t n, wstring_view format_str, const Args &... args) {
|
||||
typedef internal::truncating_iterator<OutputIt> It;
|
||||
auto it = vformat_to(It(out, n), format_str,
|
||||
make_format_args<typename format_context_t<It, wchar_t>::type>(args...));
|
||||
return {it.base(), it.count()};
|
||||
}
|
||||
|
||||
inline std::string vformat(string_view format_str, format_args args) {
|
||||
memory_buffer buffer;
|
||||
|
@ -1525,6 +1525,15 @@ TEST(FormatTest, FormatToN) {
|
||||
EXPECT_EQ("foox", fmt::string_view(buffer, 4));
|
||||
}
|
||||
|
||||
TEST(FormatTest, WideFormatToN) {
|
||||
wchar_t buffer[4];
|
||||
buffer[3] = L'x';
|
||||
auto result = fmt::format_to_n(buffer, 3, L"{}", 12345);
|
||||
EXPECT_EQ(5u, result.size);
|
||||
EXPECT_EQ(buffer + 3, result.out);
|
||||
EXPECT_EQ(L"123x", fmt::wstring_view(buffer, 4));
|
||||
}
|
||||
|
||||
#if FMT_USE_CONSTEXPR
|
||||
struct test_arg_id_handler {
|
||||
enum result { NONE, EMPTY, INDEX, NAME, ERROR };
|
||||
|
Loading…
Reference in New Issue
Block a user