From 08e688bc1eb1d2fcd69349c314c91b82b976e537 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Thu, 14 Apr 2016 18:54:52 +1000 Subject: [PATCH] format: add basic hex specifier support --- format.ipp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/format.ipp b/format.ipp index c3944bf1..cae1712e 100644 --- a/format.ipp +++ b/format.ipp @@ -68,14 +68,14 @@ namespace util { template <> inline bool is_type_specifier (const char *s) - { return *s == 'u'; } + { return *s == 'u' || *s == 'x'; } //--------------------------------------------------------------------- template <> inline bool is_type_specifier (const char *s) - { return *s == 'u'; } + { return *s == 'u' || *s == 'x'; } //--------------------------------------------------------------------- @@ -83,7 +83,7 @@ namespace util { inline bool is_type_specifier (const char *s) { - return *s == 'i' || *s == 'd'; + return *s == 'i' || *s == 'd' || *s == 'x'; } @@ -160,7 +160,10 @@ namespace util { if (!is_valid_specifier::type> (&*spec)) throw util::format::format_error ("invalid/unhandled format specifier"); - dest << val; + if (*spec == 'x') { + dest << std::hex << val << std::dec; + } else + dest << val; render (spec + 1, last, dest, std::forward (args)...); }