Skip to content

Commit

Permalink
Fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
ShawnZhong committed Jan 13, 2023
1 parent 43c2eae commit 0f10801
Showing 1 changed file with 19 additions and 32 deletions.
51 changes: 19 additions & 32 deletions include/fmt/chrono.h
Original file line number Diff line number Diff line change
Expand Up @@ -677,16 +677,15 @@ enum class pad_type {
};

template <typename OutputIt>
auto write_padding(OutputIt out, int width, pad_type pad) {
switch (pad) {
case pad_type::zero:
case pad_type::unspecified:
return std::fill_n(out, width, '0');
case pad_type::space:
return std::fill_n(out, width, ' ');
case pad_type::none:
return out;
}
auto write_padding(OutputIt out, pad_type pad, int width) -> OutputIt {
if (pad == pad_type::none) return out;
return std::fill_n(out, width, pad == pad_type::space ? ' ' : '0');
}

template <typename OutputIt>
auto write_padding(OutputIt out, pad_type pad) -> OutputIt {
if (pad != pad_type::none) *out++ = pad == pad_type::space ? ' ' : '0';
return out;
}

// Parses a put_time-like format string and invokes handler actions.
Expand Down Expand Up @@ -1279,26 +1278,14 @@ class tm_writer {
*out_++ = *d;
}
void write2(int value, pad_type pad) {
switch (pad) {
case pad_type::unspecified:
case pad_type::zero:
write2(value);
break;
case pad_type::space:
if (value < 10) {
*out_++ = ' ';
write1(value);
} else {
write2(value);
}
break;
case pad_type::none:
if (value < 10) {
write1(value);
} else {
write2(value);
}
break;
unsigned int v = to_unsigned(value) % 100;
if (v >= 10) {
const char* d = digits2(v);
*out_++ = *d++;
*out_++ = *d;
} else {
detail::write_padding(out_, pad);
*out_++ = static_cast<char>('0' + v);
}
}

Expand Down Expand Up @@ -1891,7 +1878,7 @@ struct chrono_formatter {
to_unsigned(to_nonnegative_int(value, max_value<int>()));
int num_digits = detail::count_digits(n);
if (width > num_digits) {
out = detail::write_padding(out, width - num_digits, pad);
out = detail::write_padding(out, pad, width - num_digits);
}
out = format_decimal<char_type>(out, n, num_digits).end;
}
Expand Down Expand Up @@ -1978,7 +1965,7 @@ struct chrono_formatter {
precision);
if (negative) *out++ = '-';
if (buf.size() < 2 || buf[1] == '.') {
out = detail::write_padding(out, 1, pad);
out = detail::write_padding(out, pad);
}
out = std::copy(buf.begin(), buf.end(), out);
} else {
Expand Down

0 comments on commit 0f10801

Please sign in to comment.