mirror of
https://github.com/fmtlib/fmt.git
synced 2024-11-30 21:50:06 +00:00
clang-format
This commit is contained in:
parent
260c115908
commit
bd3fd3bfda
@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
// enable safe chrono durations, unless explicitly disabled
|
// enable safe chrono durations, unless explicitly disabled
|
||||||
#ifndef FMT_SAFE_DURATION_CAST
|
#ifndef FMT_SAFE_DURATION_CAST
|
||||||
# define FMT_SAFE_DURATION_CAST 1
|
# define FMT_SAFE_DURATION_CAST 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if FMT_SAFE_DURATION_CAST
|
#if FMT_SAFE_DURATION_CAST
|
||||||
@ -443,12 +443,10 @@ template <typename T> struct make_unsigned_or_unchanged<T, true> {
|
|||||||
// throwing version of safe_duration_cast
|
// throwing version of safe_duration_cast
|
||||||
template <typename To, typename FromRep, typename FromPeriod>
|
template <typename To, typename FromRep, typename FromPeriod>
|
||||||
To fmt_safe_duration_cast(std::chrono::duration<FromRep, FromPeriod> from) {
|
To fmt_safe_duration_cast(std::chrono::duration<FromRep, FromPeriod> from) {
|
||||||
int ec;
|
int ec;
|
||||||
To to= safe_duration_cast::safe_duration_cast<To>(from,ec);
|
To to = safe_duration_cast::safe_duration_cast<To>(from, ec);
|
||||||
if (ec) {
|
if (ec) FMT_THROW(format_error("cannot format duration"));
|
||||||
FMT_THROW(format_error("cannot format duration"));
|
return to;
|
||||||
}
|
|
||||||
return to;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -463,11 +461,11 @@ inline std::chrono::duration<Rep, std::milli> get_milliseconds(
|
|||||||
typename std::common_type<decltype(d), std::chrono::seconds>::type;
|
typename std::common_type<decltype(d), std::chrono::seconds>::type;
|
||||||
const auto d_as_common = fmt_safe_duration_cast<CommonSecondsType>(d);
|
const auto d_as_common = fmt_safe_duration_cast<CommonSecondsType>(d);
|
||||||
const auto d_as_whole_seconds =
|
const auto d_as_whole_seconds =
|
||||||
fmt_safe_duration_cast<std::chrono::seconds>(d_as_common);
|
fmt_safe_duration_cast<std::chrono::seconds>(d_as_common);
|
||||||
// this conversion should be nonproblematic
|
// this conversion should be nonproblematic
|
||||||
const auto diff = d_as_common - d_as_whole_seconds;
|
const auto diff = d_as_common - d_as_whole_seconds;
|
||||||
const auto ms =
|
const auto ms =
|
||||||
fmt_safe_duration_cast<std::chrono::duration<Rep, std::milli>>(diff);
|
fmt_safe_duration_cast<std::chrono::duration<Rep, std::milli>>(diff);
|
||||||
return ms;
|
return ms;
|
||||||
#else
|
#else
|
||||||
auto s = std::chrono::duration_cast<std::chrono::seconds>(d);
|
auto s = std::chrono::duration_cast<std::chrono::seconds>(d);
|
||||||
@ -624,9 +622,7 @@ struct chrono_formatter {
|
|||||||
void on_tz_name() {}
|
void on_tz_name() {}
|
||||||
|
|
||||||
void on_24_hour(numeric_system ns) {
|
void on_24_hour(numeric_system ns) {
|
||||||
if (handle_nan_inf()) {
|
if (handle_nan_inf()) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ns == numeric_system::standard) return write(hour(), 2);
|
if (ns == numeric_system::standard) return write(hour(), 2);
|
||||||
auto time = tm();
|
auto time = tm();
|
||||||
@ -635,9 +631,7 @@ struct chrono_formatter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void on_12_hour(numeric_system ns) {
|
void on_12_hour(numeric_system ns) {
|
||||||
if (handle_nan_inf()) {
|
if (handle_nan_inf()) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ns == numeric_system::standard) return write(hour12(), 2);
|
if (ns == numeric_system::standard) return write(hour12(), 2);
|
||||||
auto time = tm();
|
auto time = tm();
|
||||||
@ -646,9 +640,7 @@ struct chrono_formatter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void on_minute(numeric_system ns) {
|
void on_minute(numeric_system ns) {
|
||||||
if (handle_nan_inf()) {
|
if (handle_nan_inf()) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ns == numeric_system::standard) return write(minute(), 2);
|
if (ns == numeric_system::standard) return write(minute(), 2);
|
||||||
auto time = tm();
|
auto time = tm();
|
||||||
@ -657,9 +649,7 @@ struct chrono_formatter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void on_second(numeric_system ns) {
|
void on_second(numeric_system ns) {
|
||||||
if (handle_nan_inf()) {
|
if (handle_nan_inf()) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ns == numeric_system::standard) {
|
if (ns == numeric_system::standard) {
|
||||||
write(second(), 2);
|
write(second(), 2);
|
||||||
@ -684,9 +674,7 @@ struct chrono_formatter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void on_12_hour_time() {
|
void on_12_hour_time() {
|
||||||
if (handle_nan_inf()) {
|
if (handle_nan_inf()) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
format_localized(time(), "%r");
|
format_localized(time(), "%r");
|
||||||
}
|
}
|
||||||
@ -706,24 +694,17 @@ struct chrono_formatter {
|
|||||||
void on_iso_time() {
|
void on_iso_time() {
|
||||||
on_24_hour_time();
|
on_24_hour_time();
|
||||||
*out++ = ':';
|
*out++ = ':';
|
||||||
if (handle_nan_inf()) {
|
if (handle_nan_inf()) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
write(second(), 2);
|
write(second(), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void on_am_pm() {
|
void on_am_pm() {
|
||||||
if (handle_nan_inf()) {
|
if (handle_nan_inf()) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
format_localized(time(), "%p");
|
format_localized(time(), "%p");
|
||||||
}
|
}
|
||||||
|
|
||||||
void on_duration_value() {
|
void on_duration_value() {
|
||||||
if (handle_nan_inf()) {
|
if (handle_nan_inf()) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
write_sign();
|
write_sign();
|
||||||
out = format_chrono_duration_value(out, val, precision);
|
out = format_chrono_duration_value(out, val, precision);
|
||||||
}
|
}
|
||||||
|
@ -246,7 +246,8 @@ int format_float(char* buf, std::size_t size, const char* format, int precision,
|
|||||||
T value) {
|
T value) {
|
||||||
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
|
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
|
||||||
if (precision > 100000) {
|
if (precision > 100000) {
|
||||||
throw std::runtime_error("fuzz mode - avoid large allocation inside snprintf");
|
throw std::runtime_error(
|
||||||
|
"fuzz mode - avoid large allocation inside snprintf");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
// Suppress the warning about nonliteral format string.
|
// Suppress the warning about nonliteral format string.
|
||||||
|
Loading…
Reference in New Issue
Block a user