Commit cf5ebf20 authored by Victor Zverovich's avatar Victor Zverovich

Cleanup

parent 9c20e72d
...@@ -1834,7 +1834,7 @@ FMT_CONSTEXPR unsigned parse_nonnegative_int(const Char*& begin, ...@@ -1834,7 +1834,7 @@ FMT_CONSTEXPR unsigned parse_nonnegative_int(const Char*& begin,
template <typename Context> class custom_formatter { template <typename Context> class custom_formatter {
private: private:
typedef typename Context::char_type char_type; using char_type = typename Context::char_type;
basic_parse_context<char_type>& parse_ctx_; basic_parse_context<char_type>& parse_ctx_;
Context& ctx_; Context& ctx_;
...@@ -1852,12 +1852,11 @@ template <typename Context> class custom_formatter { ...@@ -1852,12 +1852,11 @@ template <typename Context> class custom_formatter {
template <typename T> bool operator()(T) const { return false; } template <typename T> bool operator()(T) const { return false; }
}; };
template <typename T> struct is_integer { template <typename T>
enum { using is_integer =
value = std::is_integral<T>::value && !std::is_same<T, bool>::value && bool_constant<std::is_integral<T>::value && !std::is_same<T, bool>::value &&
!std::is_same<T, char>::value && !std::is_same<T, wchar_t>::value !std::is_same<T, char>::value &&
}; !std::is_same<T, wchar_t>::value>;
};
template <typename ErrorHandler> class width_checker { template <typename ErrorHandler> class width_checker {
public: public:
...@@ -2031,7 +2030,7 @@ FMT_CONSTEXPR typename Context::format_arg get_arg(Context& ctx, unsigned id) { ...@@ -2031,7 +2030,7 @@ FMT_CONSTEXPR typename Context::format_arg get_arg(Context& ctx, unsigned id) {
template <typename ParseContext, typename Context> template <typename ParseContext, typename Context>
class specs_handler : public specs_setter<typename Context::char_type> { class specs_handler : public specs_setter<typename Context::char_type> {
public: public:
typedef typename Context::char_type char_type; using char_type = typename Context::char_type;
FMT_CONSTEXPR specs_handler(basic_format_specs<char_type>& specs, FMT_CONSTEXPR specs_handler(basic_format_specs<char_type>& specs,
ParseContext& parse_ctx, Context& ctx) ParseContext& parse_ctx, Context& ctx)
...@@ -2053,7 +2052,7 @@ class specs_handler : public specs_setter<typename Context::char_type> { ...@@ -2053,7 +2052,7 @@ class specs_handler : public specs_setter<typename Context::char_type> {
private: private:
// This is only needed for compatibility with gcc 4.4. // This is only needed for compatibility with gcc 4.4.
typedef typename Context::format_arg format_arg; using format_arg = typename Context::format_arg;
FMT_CONSTEXPR format_arg get_arg(auto_id) { FMT_CONSTEXPR format_arg get_arg(auto_id) {
return internal::get_arg(context_, parse_context_.next_arg_id()); return internal::get_arg(context_, parse_context_.next_arg_id());
...@@ -2090,23 +2089,25 @@ struct string_view_metadata { ...@@ -2090,23 +2089,25 @@ struct string_view_metadata {
std::size_t size_; std::size_t size_;
}; };
enum class arg_id_kind { none, index, name };
// An argument reference. // An argument reference.
template <typename Char> struct arg_ref { template <typename Char> struct arg_ref {
enum Kind { NONE, INDEX, NAME };
typedef Char char_type; typedef Char char_type;
FMT_CONSTEXPR arg_ref() : kind(NONE), val() {} FMT_CONSTEXPR arg_ref() : kind(arg_id_kind::none), val() {}
FMT_CONSTEXPR explicit arg_ref(unsigned index) : kind(INDEX), val(index) {} FMT_CONSTEXPR explicit arg_ref(unsigned index)
: kind(arg_id_kind::index), val(index) {}
FMT_CONSTEXPR explicit arg_ref(string_view_metadata name) FMT_CONSTEXPR explicit arg_ref(string_view_metadata name)
: kind(NAME), val(name) {} : kind(arg_id_kind::name), val(name) {}
FMT_CONSTEXPR arg_ref& operator=(unsigned idx) { FMT_CONSTEXPR arg_ref& operator=(unsigned idx) {
kind = INDEX; kind = arg_id_kind::index;
val.index = idx; val.index = idx;
return *this; return *this;
} }
Kind kind; arg_id_kind kind;
union value { union value {
FMT_CONSTEXPR value() : index(0u) {} FMT_CONSTEXPR value() : index(0u) {}
FMT_CONSTEXPR value(unsigned id) : index(id) {} FMT_CONSTEXPR value(unsigned id) : index(id) {}
...@@ -2537,19 +2538,19 @@ template <template <typename> class Handler, typename Spec, typename Context> ...@@ -2537,19 +2538,19 @@ template <template <typename> class Handler, typename Spec, typename Context>
void handle_dynamic_spec(Spec& value, arg_ref<typename Context::char_type> ref, void handle_dynamic_spec(Spec& value, arg_ref<typename Context::char_type> ref,
Context& ctx, Context& ctx,
const typename Context::char_type* format_str) { const typename Context::char_type* format_str) {
typedef typename Context::char_type char_type;
switch (ref.kind) { switch (ref.kind) {
case arg_ref<char_type>::NONE: case arg_id_kind::none:
break; break;
case arg_ref<char_type>::INDEX: case arg_id_kind::index:
internal::set_dynamic_spec<Handler>(value, ctx.arg(ref.val.index), internal::set_dynamic_spec<Handler>(value, ctx.arg(ref.val.index),
ctx.error_handler()); ctx.error_handler());
break; break;
case arg_ref<char_type>::NAME: { case arg_id_kind::name: {
const auto arg_id = ref.val.name.to_view(format_str); const auto arg_id = ref.val.name.to_view(format_str);
internal::set_dynamic_spec<Handler>(value, ctx.arg(arg_id), internal::set_dynamic_spec<Handler>(value, ctx.arg(arg_id),
ctx.error_handler()); ctx.error_handler());
} break; break;
}
} }
} }
} // namespace internal } // namespace internal
...@@ -2838,13 +2839,13 @@ class format_int { ...@@ -2838,13 +2839,13 @@ class format_int {
private: private:
// Buffer should be large enough to hold all digits (digits10 + 1), // Buffer should be large enough to hold all digits (digits10 + 1),
// a sign and a null character. // a sign and a null character.
enum { BUFFER_SIZE = std::numeric_limits<unsigned long long>::digits10 + 3 }; enum { buffer_size = std::numeric_limits<unsigned long long>::digits10 + 3 };
mutable char buffer_[BUFFER_SIZE]; mutable char buffer_[buffer_size];
char* str_; char* str_;
// Formats value in reverse and returns a pointer to the beginning. // Formats value in reverse and returns a pointer to the beginning.
char* format_decimal(unsigned long long value) { char* format_decimal(unsigned long long value) {
char* ptr = buffer_ + (BUFFER_SIZE - 1); // Parens to workaround MSVC bug. char* ptr = buffer_ + (buffer_size - 1); // Parens to workaround MSVC bug.
while (value >= 100) { while (value >= 100) {
// Integer division is slow so do it for a group of two digits instead // Integer division is slow so do it for a group of two digits instead
// of for every digit. The idea comes from the talk by Alexandrescu // of for every digit. The idea comes from the talk by Alexandrescu
...@@ -2882,7 +2883,7 @@ class format_int { ...@@ -2882,7 +2883,7 @@ class format_int {
/** Returns the number of characters written to the output buffer. */ /** Returns the number of characters written to the output buffer. */
std::size_t size() const { std::size_t size() const {
return internal::to_unsigned(buffer_ - str_ + BUFFER_SIZE - 1); return internal::to_unsigned(buffer_ - str_ + buffer_size - 1);
} }
/** /**
...@@ -2896,7 +2897,7 @@ class format_int { ...@@ -2896,7 +2897,7 @@ class format_int {
character appended. character appended.
*/ */
const char* c_str() const { const char* c_str() const {
buffer_[BUFFER_SIZE - 1] = '\0'; buffer_[buffer_size - 1] = '\0';
return str_; return str_;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment