From 147e5ebbbc01c51def90d7d51141a60de7b2934b Mon Sep 17 00:00:00 2001 From: vitaut Date: Wed, 17 Jun 2015 07:21:16 -0700 Subject: [PATCH] Move casts to CharTraits for custom character types --- format.cc | 4 ++-- format.h | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/format.cc b/format.cc index 7d92385e..77227589 100644 --- a/format.cc +++ b/format.cc @@ -440,7 +440,7 @@ class BasicArgFormatter : public ArgVisitor { if (spec_.align_ == ALIGN_NUMERIC || spec_.flags_ != 0) FMT_THROW(FormatError("invalid format specifier for char")); typedef typename BasicWriter::CharPtr CharPtr; - Char fill = static_cast(spec_.fill()); + Char fill = internal::CharTraits::cast(spec_.fill()); CharPtr out = CharPtr(); if (spec_.width_ > 1) { out = writer_.grow_buffer(spec_.width_); @@ -455,7 +455,7 @@ class BasicArgFormatter : public ArgVisitor { } else { out = writer_.grow_buffer(1); } - *out = static_cast(value); + *out = internal::CharTraits::cast(value); } void visit_string(Arg::StringValue value) { diff --git a/format.h b/format.h index 30d1b4e0..51d77767 100644 --- a/format.h +++ b/format.h @@ -522,6 +522,7 @@ class BasicCharTraits { #else typedef Char *CharPtr; #endif + static Char cast(wchar_t value) { return static_cast(value); } }; template @@ -2036,7 +2037,7 @@ typename BasicWriter::CharPtr BasicWriter::write_str( CharPtr out = CharPtr(); if (spec.width() > size) { out = grow_buffer(spec.width()); - Char fill = static_cast(spec.fill()); + Char fill = internal::CharTraits::cast(spec.fill()); if (spec.align() == ALIGN_RIGHT) { std::fill_n(out, spec.width() - size, fill); out += spec.width() - size; @@ -2059,7 +2060,7 @@ typename BasicWriter::CharPtr std::size_t content_size, wchar_t fill) { std::size_t padding = total_size - content_size; std::size_t left_padding = padding / 2; - Char fill_char = static_cast(fill); + Char fill_char = internal::CharTraits::cast(fill); std::fill_n(buffer, left_padding, fill_char); buffer += left_padding; CharPtr content = buffer; @@ -2075,7 +2076,7 @@ typename BasicWriter::CharPtr const char *prefix, unsigned prefix_size) { unsigned width = spec.width(); Alignment align = spec.align(); - Char fill = static_cast(spec.fill()); + Char fill = internal::CharTraits::cast(spec.fill()); if (spec.precision() > static_cast(num_digits)) { // Octal prefix '0' is counted as a digit, so ignore it if precision // is specified. @@ -2314,7 +2315,7 @@ void BasicWriter::write_double( *format_ptr = '\0'; // Format using snprintf. - Char fill = static_cast(spec.fill()); + Char fill = internal::CharTraits::cast(spec.fill()); for (;;) { std::size_t buffer_size = buffer_.capacity() - offset; #if _MSC_VER