Skip to content

Commit

Permalink
remove vformat from chrono.h
Browse files Browse the repository at this point in the history
  • Loading branch information
Walter Gray committed Dec 21, 2020
1 parent c85d5e3 commit b9063f9
Showing 1 changed file with 18 additions and 22 deletions.
40 changes: 18 additions & 22 deletions include/fmt/chrono.h
Original file line number Diff line number Diff line change
Expand Up @@ -768,24 +768,16 @@ inline std::chrono::duration<Rep, std::milli> get_milliseconds(
template <typename Char, typename Rep, typename OutputIt,
FMT_ENABLE_IF(std::is_integral<Rep>::value)>
OutputIt format_duration_value(OutputIt out, Rep val, int) {
static FMT_CONSTEXPR_DECL const Char format[] = {'{', '}', 0};
return vformat_to(out, to_string_view(format),
make_format_args<buffer_context<Char>>(val));
return write<Char>(out, val);
}

template <typename Char, typename Rep, typename OutputIt,
FMT_ENABLE_IF(std::is_floating_point<Rep>::value)>
OutputIt format_duration_value(OutputIt out, Rep val, int precision) {
static FMT_CONSTEXPR_DECL const Char pr_f[] = {'{', ':', '.', '{',
'}', 'f', '}', 0};
if (precision >= 0) {
return vformat_to(out, to_string_view(pr_f),
make_format_args<buffer_context<Char>>(val, precision));
}
static FMT_CONSTEXPR_DECL const Char fp_f[] = {'{', ':', 'g', '}', 0};

return vformat_to(out, to_string_view(fp_f),
make_format_args<buffer_context<Char>>(val));
basic_format_specs<Char> specs;
specs.precision = precision;
specs.type = precision > 0 ? 'f' : 'g';
return write<Char>(out, val, specs);
}

template <typename Char, typename OutputIt>
Expand All @@ -805,16 +797,20 @@ template <typename Char, typename Period, typename OutputIt>
OutputIt format_duration_unit(OutputIt out) {
if (const char* unit = get_units<Period>())
return copy_unit(string_view(unit), out, Char());
static FMT_CONSTEXPR_DECL const Char num_f[] = {'[', '{', '}', ']', 's', 0};
if (const_check(Period::den == 1)) {
return vformat_to(out, to_string_view(num_f),
make_format_args<buffer_context<Char>>(Period::num));

basic_memory_buffer<Char> buffer;
auto bufOut = std::back_inserter(buffer);
*bufOut++ = '[';
bufOut = write<Char>(bufOut, Period::num);

if (const_check(Period::den != 1)) {
*bufOut++ = '/';
bufOut = write<Char>(bufOut, Period::den);
}
static FMT_CONSTEXPR_DECL const Char num_def_f[] = {'[', '{', '}', '/', '{',
'}', ']', 's', 0};
return vformat_to(
out, to_string_view(num_def_f),
make_format_args<buffer_context<Char>>(Period::num, Period::den));

*bufOut++ = ']';
*bufOut++ = 's';
return write<Char>(out, {buffer.data(), buffer.size()});
}

template <typename FormatContext, typename OutputIt, typename Rep,
Expand Down

0 comments on commit b9063f9

Please sign in to comment.