From 04a1f6e991f82bf85fcfc092c86cf7064cce9761 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sat, 11 Jul 2020 08:21:14 -0700 Subject: [PATCH] Improve handling of single code units in compile --- include/fmt/compile.h | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/include/fmt/compile.h b/include/fmt/compile.h index cb212f20..a97c0bdc 100644 --- a/include/fmt/compile.h +++ b/include/fmt/compile.h @@ -406,6 +406,19 @@ constexpr text make_text(basic_string_view s, size_t pos, return {{&s[pos], size}}; } +template struct code_unit { + Char value; + using char_type = Char; + + template + OutputIt format(OutputIt out, const Args&...) const { + return write(out, value); + } +}; + +template +struct is_compiled_format> : std::true_type {}; + // A replacement field that refers to argument N. template struct field { using char_type = Char; @@ -530,8 +543,13 @@ constexpr auto compile_format_string(S format_str) { return parse_tail(make_text(str, POS, 1), format_str); } else { constexpr auto end = parse_text(str, POS + 1); - return parse_tail(make_text(str, POS, end - POS), - format_str); + if constexpr (end - POS > 1) { + return parse_tail(make_text(str, POS, end - POS), + format_str); + } else { + return parse_tail(code_unit{str[0]}, + format_str); + } } }