mirror of
https://github.com/fmtlib/fmt.git
synced 2025-08-01 03:34:45 +02:00
Simplify arg_formatter_base
This commit is contained in:
@@ -1680,7 +1680,7 @@ class arg_formatter_base {
|
|||||||
using format_specs = basic_format_specs<char_type>;
|
using format_specs = basic_format_specs<char_type>;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
iterator out_; // Output iterator.
|
iterator out_;
|
||||||
locale_ref locale_;
|
locale_ref locale_;
|
||||||
format_specs* specs_;
|
format_specs* specs_;
|
||||||
|
|
||||||
@@ -1705,19 +1705,6 @@ class arg_formatter_base {
|
|||||||
it = format_decimal<char_type>(it, abs_value, num_digits);
|
it = format_decimal<char_type>(it, abs_value, num_digits);
|
||||||
}
|
}
|
||||||
|
|
||||||
void write(int value) { write_decimal(value); }
|
|
||||||
void write(long value) { write_decimal(value); }
|
|
||||||
void write(long long value) { write_decimal(value); }
|
|
||||||
|
|
||||||
void write(unsigned value) { write_decimal(value); }
|
|
||||||
void write(unsigned long value) { write_decimal(value); }
|
|
||||||
void write(unsigned long long value) { write_decimal(value); }
|
|
||||||
|
|
||||||
#if FMT_USE_INT128
|
|
||||||
void write(int128_t value) { write_decimal(value); }
|
|
||||||
void write(uint128_t value) { write_decimal(value); }
|
|
||||||
#endif
|
|
||||||
|
|
||||||
template <typename T> void write_int(T value, const format_specs& spec) {
|
template <typename T> void write_int(T value, const format_specs& spec) {
|
||||||
using uint_type = uint32_or_64_or_128_t<T>;
|
using uint_type = uint32_or_64_or_128_t<T>;
|
||||||
int_writer<iterator, char_type, uint_type> w(out_, locale_, value, spec);
|
int_writer<iterator, char_type, uint_type> w(out_, locale_, value, spec);
|
||||||
@@ -1762,7 +1749,7 @@ class arg_formatter_base {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void write_pointer(const void* p) {
|
void write_pointer(const void* p) {
|
||||||
out_ = write_ptr<char_type>(out_, detail::to_uintptr(p), specs_);
|
out_ = write_ptr<char_type>(out_, to_uintptr(p), specs_);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -1790,7 +1777,7 @@ class arg_formatter_base {
|
|||||||
|
|
||||||
iterator operator()(monostate) {
|
iterator operator()(monostate) {
|
||||||
FMT_ASSERT(false, "invalid argument type");
|
FMT_ASSERT(false, "invalid argument type");
|
||||||
return out();
|
return out_;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, FMT_ENABLE_IF(is_integral<T>::value)>
|
template <typename T, FMT_ENABLE_IF(is_integral<T>::value)>
|
||||||
@@ -1798,20 +1785,20 @@ class arg_formatter_base {
|
|||||||
if (specs_)
|
if (specs_)
|
||||||
write_int(value, *specs_);
|
write_int(value, *specs_);
|
||||||
else
|
else
|
||||||
write(value);
|
write_decimal(value);
|
||||||
return out();
|
return out_;
|
||||||
}
|
}
|
||||||
|
|
||||||
iterator operator()(char_type value) {
|
iterator operator()(char_type value) {
|
||||||
detail::handle_char_specs(
|
handle_char_specs(specs_,
|
||||||
specs_, char_spec_handler(*this, static_cast<char_type>(value)));
|
char_spec_handler(*this, static_cast<char_type>(value)));
|
||||||
return out();
|
return out_;
|
||||||
}
|
}
|
||||||
|
|
||||||
iterator operator()(bool value) {
|
iterator operator()(bool value) {
|
||||||
if (specs_ && specs_->type) return (*this)(value ? 1 : 0);
|
if (specs_ && specs_->type) return (*this)(value ? 1 : 0);
|
||||||
write(value != 0);
|
write(value != 0);
|
||||||
return out();
|
return out_;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, FMT_ENABLE_IF(std::is_floating_point<T>::value)>
|
template <typename T, FMT_ENABLE_IF(std::is_floating_point<T>::value)>
|
||||||
@@ -1821,7 +1808,7 @@ class arg_formatter_base {
|
|||||||
out_ = detail::write(out_, value, specs, locale_);
|
out_ = detail::write(out_, value, specs, locale_);
|
||||||
else
|
else
|
||||||
FMT_ASSERT(false, "unsupported float argument type");
|
FMT_ASSERT(false, "unsupported float argument type");
|
||||||
return out();
|
return out_;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct char_spec_handler : ErrorHandler {
|
struct char_spec_handler : ErrorHandler {
|
||||||
@@ -1857,26 +1844,25 @@ class arg_formatter_base {
|
|||||||
};
|
};
|
||||||
|
|
||||||
iterator operator()(const char_type* value) {
|
iterator operator()(const char_type* value) {
|
||||||
if (!specs_) return write(value), out();
|
if (!specs_) return write(value), out_;
|
||||||
detail::handle_cstring_type_spec(specs_->type,
|
handle_cstring_type_spec(specs_->type, cstring_spec_handler(*this, value));
|
||||||
cstring_spec_handler(*this, value));
|
return out_;
|
||||||
return out();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
iterator operator()(basic_string_view<char_type> value) {
|
iterator operator()(basic_string_view<char_type> value) {
|
||||||
if (specs_) {
|
if (specs_) {
|
||||||
detail::check_string_type_spec(specs_->type, detail::error_handler());
|
check_string_type_spec(specs_->type, error_handler());
|
||||||
write(value, *specs_);
|
write(value, *specs_);
|
||||||
} else {
|
} else {
|
||||||
write(value);
|
write(value);
|
||||||
}
|
}
|
||||||
return out();
|
return out_;
|
||||||
}
|
}
|
||||||
|
|
||||||
iterator operator()(const void* value) {
|
iterator operator()(const void* value) {
|
||||||
if (specs_) check_pointer_type_spec(specs_->type, detail::error_handler());
|
if (specs_) check_pointer_type_spec(specs_->type, error_handler());
|
||||||
write_pointer(value);
|
write_pointer(value);
|
||||||
return out();
|
return out_;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user