Always use FMT_STRING internally where possible
This commit is contained in:
parent
1936dddc3c
commit
9501da5796
@ -764,13 +764,15 @@ inline std::chrono::duration<Rep, std::milli> get_milliseconds(
|
|||||||
|
|
||||||
template <typename Char, typename Rep, typename OutputIt>
|
template <typename Char, typename Rep, typename OutputIt>
|
||||||
OutputIt format_duration_value(OutputIt out, Rep val, int precision) {
|
OutputIt format_duration_value(OutputIt out, Rep val, int precision) {
|
||||||
const Char pr_f[] = {'{', ':', '.', '{', '}', 'f', '}', 0};
|
if (precision >= 0)
|
||||||
if (precision >= 0) return format_to(out, pr_f, val, precision);
|
return format_to(out, FMT_STRING("{:.{}f}"), val, precision);
|
||||||
const Char fp_f[] = {'{', ':', 'g', '}', 0};
|
if (std::is_floating_point<Rep>::value) {
|
||||||
const Char format[] = {'{', '}', 0};
|
return format_to(out, FMT_STRING("{:g}"), val);
|
||||||
return format_to(out, std::is_floating_point<Rep>::value ? fp_f : format,
|
} else {
|
||||||
val);
|
return format_to(out, FMT_STRING("{}"), val);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Char, typename OutputIt>
|
template <typename Char, typename OutputIt>
|
||||||
OutputIt copy_unit(string_view unit, OutputIt out, Char) {
|
OutputIt copy_unit(string_view unit, OutputIt out, Char) {
|
||||||
return std::copy(unit.begin(), unit.end(), out);
|
return std::copy(unit.begin(), unit.end(), out);
|
||||||
@ -788,10 +790,9 @@ template <typename Char, typename Period, typename OutputIt>
|
|||||||
OutputIt format_duration_unit(OutputIt out) {
|
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());
|
||||||
const Char num_f[] = {'[', '{', '}', ']', 's', 0};
|
if (const_check(Period::den == 1))
|
||||||
if (const_check(Period::den == 1)) return format_to(out, num_f, Period::num);
|
return format_to(out, FMT_STRING("[{}]s"), Period::num);
|
||||||
const Char num_def_f[] = {'[', '{', '}', '/', '{', '}', ']', 's', 0};
|
return format_to(out, FMT_STRING("[{}/{}]s"), Period::num, Period::den);
|
||||||
return format_to(out, num_def_f, Period::num, Period::den);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename FormatContext, typename OutputIt, typename Rep,
|
template <typename FormatContext, typename OutputIt, typename Rep,
|
||||||
|
|||||||
@ -578,7 +578,7 @@ inline std::basic_string<Char> vformat(
|
|||||||
*/
|
*/
|
||||||
template <typename S, typename... Args, typename Char = char_t<S>>
|
template <typename S, typename... Args, typename Char = char_t<S>>
|
||||||
inline std::basic_string<Char> format(const text_style& ts, const S& format_str,
|
inline std::basic_string<Char> format(const text_style& ts, const S& format_str,
|
||||||
const Args&... args) {
|
Args&&... args) {
|
||||||
return vformat(ts, to_string_view(format_str),
|
return vformat(ts, to_string_view(format_str),
|
||||||
fmt::make_args_checked<Args...>(format_str, args...));
|
fmt::make_args_checked<Args...>(format_str, args...));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -145,8 +145,8 @@ FMT_FUNC void format_error_code(detail::buffer<char>& out, int error_code,
|
|||||||
error_code_size += detail::to_unsigned(detail::count_digits(abs_value));
|
error_code_size += detail::to_unsigned(detail::count_digits(abs_value));
|
||||||
auto it = buffer_appender<char>(out);
|
auto it = buffer_appender<char>(out);
|
||||||
if (message.size() <= inline_buffer_size - error_code_size)
|
if (message.size() <= inline_buffer_size - error_code_size)
|
||||||
format_to(it, "{}{}", message, SEP);
|
format_to(it, FMT_STRING("{}{}"), message, SEP);
|
||||||
format_to(it, "{}{}", ERROR_STR, error_code);
|
format_to(it, FMT_STRING("{}{}"), ERROR_STR, error_code);
|
||||||
assert(out.size() <= inline_buffer_size);
|
assert(out.size() <= inline_buffer_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2662,14 +2662,15 @@ template <> struct formatter<detail::bigint> {
|
|||||||
for (auto i = n.bigits_.size(); i > 0; --i) {
|
for (auto i = n.bigits_.size(); i > 0; --i) {
|
||||||
auto value = n.bigits_[i - 1u];
|
auto value = n.bigits_[i - 1u];
|
||||||
if (first) {
|
if (first) {
|
||||||
out = format_to(out, "{:x}", value);
|
out = format_to(out, FMT_STRING("{:x}"), value);
|
||||||
first = false;
|
first = false;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
out = format_to(out, "{:08x}", value);
|
out = format_to(out, FMT_STRING("{:08x}"), value);
|
||||||
}
|
}
|
||||||
if (n.exp_ > 0)
|
if (n.exp_ > 0)
|
||||||
out = format_to(out, "p{}", n.exp_ * detail::bigint::bigit_bits);
|
out = format_to(out, FMT_STRING("p{}"),
|
||||||
|
n.exp_ * detail::bigint::bigit_bits);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -2715,8 +2716,8 @@ FMT_FUNC void format_system_error(detail::buffer<char>& out, int error_code,
|
|||||||
int result =
|
int result =
|
||||||
detail::safe_strerror(error_code, system_message, buf.size());
|
detail::safe_strerror(error_code, system_message, buf.size());
|
||||||
if (result == 0) {
|
if (result == 0) {
|
||||||
format_to(detail::buffer_appender<char>(out), "{}: {}", message,
|
format_to(detail::buffer_appender<char>(out), FMT_STRING("{}: {}"),
|
||||||
system_message);
|
message, system_message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (result != ERANGE)
|
if (result != ERANGE)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user