From 2ae41242a56e5b63544d8147df4a64e29908f1cd Mon Sep 17 00:00:00 2001 From: Daniela Engert Date: Wed, 18 Apr 2018 19:16:31 +0200 Subject: [PATCH] allow time formatting with wchar_t contexts change total specialization of 'struct formatter' into partial specialization 'template struct formatter', backed by matching 'strftime'-like overloads --- include/fmt/time.h | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/include/fmt/time.h b/include/fmt/time.h index b5d81a72..9cfa3152 100644 --- a/include/fmt/time.h +++ b/include/fmt/time.h @@ -93,11 +93,21 @@ inline std::tm gmtime(std::time_t time) { return std::tm(); } -template <> -struct formatter { +namespace internal { +inline std::size_t strftime(char *str, std::size_t count, const char *format, const std::tm *time) { + return std::strftime(str, count, format, time); +} + +inline std::size_t strftime(wchar_t *str, std::size_t count, const wchar_t *format, const std::tm *time) { + return std::wcsftime(str, count, format, time); +} +} + +template +struct formatter { template auto parse(ParseContext &ctx) -> decltype(ctx.begin()) { - auto it = internal::null_terminating_iterator(ctx); + auto it = internal::null_terminating_iterator(ctx); if (*it == ':') ++it; auto end = it; @@ -110,12 +120,13 @@ struct formatter { return pointer_from(end); } - auto format(const std::tm &tm, format_context &ctx) -> decltype(ctx.begin()) { - internal::buffer &buf = internal::get_container(ctx.begin()); + template + auto format(const std::tm &tm, FormatContext &ctx) -> decltype(ctx.begin()) { + internal::basic_buffer &buf = internal::get_container(ctx.begin()); std::size_t start = buf.size(); for (;;) { std::size_t size = buf.capacity() - start; - std::size_t count = std::strftime(&buf[start], size, &tm_format[0], &tm); + std::size_t count = internal::strftime(&buf[start], size, &tm_format[0], &tm); if (count != 0) { buf.resize(start + count); break; @@ -133,7 +144,7 @@ struct formatter { return ctx.begin(); } - memory_buffer tm_format; + basic_memory_buffer tm_format; }; }