Skip to content

Commit

Permalink
Refactor format_specs for #1109 and #940
Browse files Browse the repository at this point in the history
Refactor `format_specs` and related APIs to support variable-width fill
(#1109), improve naming consistency, remove legacy setters (#940), and
optimize layout.
  • Loading branch information
vitaut committed Jul 7, 2019
1 parent 8e0dcd2 commit e4f84ee
Show file tree
Hide file tree
Showing 8 changed files with 195 additions and 176 deletions.
10 changes: 5 additions & 5 deletions include/fmt/chrono.h
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ struct chrono_formatter {
template <typename Rep, typename Period, typename Char>
struct formatter<std::chrono::duration<Rep, Period>, Char> {
private:
align_spec spec;
basic_format_specs<Char> spec;
int precision;
typedef internal::arg_ref<Char> arg_ref_type;
arg_ref_type width_ref;
Expand Down Expand Up @@ -744,9 +744,9 @@ struct formatter<std::chrono::duration<Rep, Period>, Char> {
}

void on_error(const char* msg) { FMT_THROW(format_error(msg)); }
void on_fill(Char fill) { f.spec.fill_ = fill; }
void on_align(alignment align) { f.spec.align_ = align; }
void on_width(unsigned width) { f.spec.width_ = width; }
void on_fill(Char fill) { f.spec.fill[0] = fill; }
void on_align(align_t align) { f.spec.align = align; }
void on_width(unsigned width) { f.spec.width = width; }
void on_precision(unsigned precision) { f.precision = precision; }
void end_precision() {}

Expand Down Expand Up @@ -804,7 +804,7 @@ struct formatter<std::chrono::duration<Rep, Period>, Char> {
using range = internal::output_range<decltype(ctx.out()), Char>;
internal::basic_writer<range> w(range(ctx.out()));
internal::handle_dynamic_spec<internal::width_checker>(
spec.width_, width_ref, ctx, format_str.begin());
spec.width, width_ref, ctx, format_str.begin());
internal::handle_dynamic_spec<internal::precision_checker>(
precision, precision_ref, ctx, format_str.begin());
if (begin == end || *begin == '}') {
Expand Down
2 changes: 1 addition & 1 deletion include/fmt/format-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ char* sprintf_format(Double value, internal::buffer<char>& buf,
char format[max_format_size];
char* format_ptr = format;
*format_ptr++ = '%';
if (spec.has(HASH_FLAG) || !spec.type) *format_ptr++ = '#';
if (spec.alt || !spec.type) *format_ptr++ = '#';
if (spec.precision >= 0) {
*format_ptr++ = '.';
*format_ptr++ = '*';
Expand Down
Loading

0 comments on commit e4f84ee

Please sign in to comment.