Refactor ranges, fix chrono, apply clang format to include/fmt/*.h
This commit is contained in:
parent
98a8830d2a
commit
b0c65dffe6
@ -798,19 +798,17 @@ OutputIt format_duration_unit(OutputIt out) {
|
|||||||
if (const char* unit = get_units<Period>())
|
if (const char* unit = get_units<Period>())
|
||||||
return copy_unit(string_view(unit), out, Char());
|
return copy_unit(string_view(unit), out, Char());
|
||||||
|
|
||||||
basic_memory_buffer<Char> buffer;
|
*out++ = '[';
|
||||||
auto bufOut = std::back_inserter(buffer);
|
out = write<Char>(out, Period::num);
|
||||||
*bufOut++ = '[';
|
|
||||||
bufOut = write<Char>(bufOut, Period::num);
|
|
||||||
|
|
||||||
if (const_check(Period::den != 1)) {
|
if (const_check(Period::den != 1)) {
|
||||||
*bufOut++ = '/';
|
*out++ = '/';
|
||||||
bufOut = write<Char>(bufOut, Period::den);
|
out = write<Char>(out, Period::den);
|
||||||
}
|
}
|
||||||
|
|
||||||
*bufOut++ = ']';
|
*out++ = ']';
|
||||||
*bufOut++ = 's';
|
*out++ = 's';
|
||||||
return write<Char>(out, {buffer.data(), buffer.size()});
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename FormatContext, typename OutputIt, typename Rep,
|
template <typename FormatContext, typename OutputIt, typename Rep,
|
||||||
|
|||||||
@ -52,8 +52,8 @@ inline OutputIt vformat_to(
|
|||||||
|
|
||||||
template <typename OutputIt, typename S, typename... Args,
|
template <typename OutputIt, typename S, typename... Args,
|
||||||
bool enable = detail::is_output_iterator<OutputIt, char_t<S>>::value>
|
bool enable = detail::is_output_iterator<OutputIt, char_t<S>>::value>
|
||||||
inline auto format_to(OutputIt out, const std::locale& loc,
|
inline auto format_to(OutputIt out, const std::locale& loc, const S& format_str,
|
||||||
const S& format_str, Args&&... args) ->
|
Args&&... args) ->
|
||||||
typename std::enable_if<enable, OutputIt>::type {
|
typename std::enable_if<enable, OutputIt>::type {
|
||||||
const auto& vargs = fmt::make_args_checked<Args...>(format_str, args...);
|
const auto& vargs = fmt::make_args_checked<Args...>(format_str, args...);
|
||||||
return vformat_to(out, loc, to_string_view(format_str), vargs);
|
return vformat_to(out, loc, to_string_view(format_str), vargs);
|
||||||
|
|||||||
@ -247,31 +247,40 @@ template <typename Range>
|
|||||||
using value_type =
|
using value_type =
|
||||||
remove_cvref_t<decltype(*detail::range_begin(std::declval<Range>()))>;
|
remove_cvref_t<decltype(*detail::range_begin(std::declval<Range>()))>;
|
||||||
|
|
||||||
template <typename Arg, FMT_ENABLE_IF(!is_like_std_string<
|
template <typename OutputIt, typename Formatting>
|
||||||
typename std::decay<Arg>::type>::value)>
|
OutputIt add_range_formatting_spaces(OutputIt out,
|
||||||
FMT_CONSTEXPR const char* format_str_quoted(bool add_space, const Arg&) {
|
const Formatting& formatting) {
|
||||||
return add_space ? " {}" : "{}";
|
if (const_check(formatting.add_prepostfix_space)) {
|
||||||
|
*out++ = ' ';
|
||||||
|
}
|
||||||
|
out = detail::copy(formatting.delimiter, out);
|
||||||
|
if (const_check(formatting.add_delimiter_spaces)) {
|
||||||
|
*out++ = ' ';
|
||||||
|
}
|
||||||
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Arg, FMT_ENABLE_IF(is_like_std_string<
|
template <typename Char, typename OutputIt, typename Arg>
|
||||||
typename std::decay<Arg>::type>::value)>
|
OutputIt write_range_entry(OutputIt out, const Arg& v) {
|
||||||
FMT_CONSTEXPR const char* format_str_quoted(bool add_space, const Arg&) {
|
FMT_CONSTEXPR_DECL const char quote = []() {
|
||||||
return add_space ? " \"{}\"" : "\"{}\"";
|
if (const_check(
|
||||||
|
std::is_same<Arg, const char*>::value ||
|
||||||
|
is_like_std_string<typename std::decay<Arg>::type>::value)) {
|
||||||
|
return '"';
|
||||||
|
} else if (const_check(std::is_same<Arg, Char>::value)) {
|
||||||
|
return '\'';
|
||||||
|
} else {
|
||||||
|
return '\0';
|
||||||
|
}
|
||||||
|
}();
|
||||||
|
|
||||||
|
if (const_check(quote)) *out++ = quote;
|
||||||
|
out = write<Char>(out, v);
|
||||||
|
if (const_check(quote)) *out++ = quote;
|
||||||
|
|
||||||
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
FMT_CONSTEXPR const char* format_str_quoted(bool add_space, const char*) {
|
|
||||||
return add_space ? " \"{}\"" : "\"{}\"";
|
|
||||||
}
|
|
||||||
FMT_CONSTEXPR const wchar_t* format_str_quoted(bool add_space, const wchar_t*) {
|
|
||||||
return add_space ? L" \"{}\"" : L"\"{}\"";
|
|
||||||
}
|
|
||||||
|
|
||||||
FMT_CONSTEXPR const char* format_str_quoted(bool add_space, const char) {
|
|
||||||
return add_space ? " '{}'" : "'{}'";
|
|
||||||
}
|
|
||||||
FMT_CONSTEXPR const wchar_t* format_str_quoted(bool add_space, const wchar_t) {
|
|
||||||
return add_space ? L" '{}'" : L"'{}'";
|
|
||||||
}
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
template <typename T> struct is_tuple_like {
|
template <typename T> struct is_tuple_like {
|
||||||
@ -286,15 +295,10 @@ struct formatter<TupleT, Char, enable_if_t<fmt::is_tuple_like<TupleT>::value>> {
|
|||||||
template <typename FormatContext> struct format_each {
|
template <typename FormatContext> struct format_each {
|
||||||
template <typename T> void operator()(const T& v) {
|
template <typename T> void operator()(const T& v) {
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
if (formatting.add_prepostfix_space) {
|
out = add_range_formatting_spaces(out, formatting);
|
||||||
*out++ = ' ';
|
|
||||||
}
|
|
||||||
out = detail::copy(formatting.delimiter, out);
|
|
||||||
}
|
}
|
||||||
out = vformat_to(out,
|
|
||||||
detail::format_str_quoted(
|
out = detail::write_range_entry<Char>(out, v);
|
||||||
(formatting.add_delimiter_spaces && i > 0), v),
|
|
||||||
make_format_args<FormatContext>(v));
|
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -363,19 +367,19 @@ struct formatter<
|
|||||||
auto end = view.end();
|
auto end = view.end();
|
||||||
for (; it != end; ++it) {
|
for (; it != end; ++it) {
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
if (formatting.add_prepostfix_space) *out++ = ' ';
|
out = detail::add_range_formatting_spaces(out, formatting);
|
||||||
out = detail::copy(formatting.delimiter, out);
|
|
||||||
}
|
}
|
||||||
out = vformat_to(out,
|
|
||||||
detail::format_str_quoted(
|
out = detail::write_range_entry<Char>(out, *it);
|
||||||
(formatting.add_delimiter_spaces && i > 0), *it),
|
|
||||||
make_format_args<FormatContext>(*it));
|
|
||||||
if (++i > formatting.range_length_limit) {
|
if (++i > formatting.range_length_limit) {
|
||||||
out = format_to(out, FMT_STRING("{}"), " ... <other elements>");
|
out = format_to(out, FMT_STRING("{}"), " ... <other elements>");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (formatting.add_prepostfix_space) *out++ = ' ';
|
if (formatting.add_prepostfix_space) {
|
||||||
|
*out++ = ' ';
|
||||||
|
}
|
||||||
return detail::copy(formatting.postfix, out);
|
return detail::copy(formatting.postfix, out);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -52,8 +52,7 @@ void test_chrono() {
|
|||||||
|
|
||||||
void test_text_style() {
|
void test_text_style() {
|
||||||
fmt::print(fg(fmt::rgb(255, 20, 30)), FMT_STRING("{}"), "rgb(255,20,30)");
|
fmt::print(fg(fmt::rgb(255, 20, 30)), FMT_STRING("{}"), "rgb(255,20,30)");
|
||||||
fmt::format(fg(fmt::rgb(255, 20, 30)), FMT_STRING("{}"),
|
fmt::format(fg(fmt::rgb(255, 20, 30)), FMT_STRING("{}"), "rgb(255,20,30)");
|
||||||
"rgb(255,20,30)");
|
|
||||||
|
|
||||||
fmt::text_style ts = fg(fmt::rgb(255, 20, 30));
|
fmt::text_style ts = fg(fmt::rgb(255, 20, 30));
|
||||||
std::string out;
|
std::string out;
|
||||||
@ -62,7 +61,7 @@ void test_text_style() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void test_range() {
|
void test_range() {
|
||||||
std::array<char, 5> hello = {'h','e','l','l','o'};
|
std::array<char, 5> hello = {'h', 'e', 'l', 'l', 'o'};
|
||||||
fmt::format(FMT_STRING("{}"), hello);
|
fmt::format(FMT_STRING("{}"), hello);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user