From fd510b7507b5341416f8733efdea57296ff56ed3 Mon Sep 17 00:00:00 2001 From: Florin Iucha Date: Sat, 15 Dec 2018 12:45:04 -0500 Subject: [PATCH] Remove more signed/unsigned complications --- include/fmt/format.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index 8b77f132..2c2b07f8 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -956,8 +956,9 @@ inline wchar_t thousands_sep(locale_ref loc) { // thousands_sep is a functor that is called after writing each char to // add a thousands separator if necessary. template -inline Char *format_decimal(Char *buffer, UInt value, unsigned num_digits, +inline Char *format_decimal(Char *buffer, UInt value, int num_digits, ThousandsSep thousands_sep) { + FMT_ASSERT(num_digits >= 0, "invalid digit count"); buffer += num_digits; Char *end = buffer; while (value >= 100) { @@ -985,7 +986,8 @@ inline Char *format_decimal(Char *buffer, UInt value, unsigned num_digits, template inline Iterator format_decimal( - Iterator out, UInt value, unsigned num_digits, ThousandsSep sep) { + Iterator out, UInt value, int num_digits, ThousandsSep sep) { + FMT_ASSERT(num_digits >= 0, "invalid digit count"); typedef typename ThousandsSep::char_type char_type; // Buffer should be large enough to hold all digits (<= digits10 + 1). enum { max_size = std::numeric_limits::digits10 + 1 }; @@ -996,12 +998,12 @@ inline Iterator format_decimal( } template -inline It format_decimal(It out, UInt value, unsigned num_digits) { +inline It format_decimal(It out, UInt value, int num_digits) { return format_decimal(out, value, num_digits, no_thousands_sep()); } template -inline Char *format_uint(Char *buffer, UInt value, unsigned num_digits, +inline Char *format_uint(Char *buffer, UInt value, int num_digits, bool upper = false) { buffer += num_digits; Char *end = buffer; @@ -1014,7 +1016,7 @@ inline Char *format_uint(Char *buffer, UInt value, unsigned num_digits, } template -inline It format_uint(It out, UInt value, unsigned num_digits, +inline It format_uint(It out, UInt value, int num_digits, bool upper = false) { // Buffer should be large enough to hold all digits (digits / BASE_BITS + 1) // and null.