Adjust clang-format

This commit is contained in:
Victor Zverovich 2024-09-10 18:24:35 -07:00
parent 3e9fdb3a1f
commit 5345cfe6b3
5 changed files with 126 additions and 315 deletions

View File

@ -6,3 +6,9 @@ IndentPPDirectives: AfterHash
IndentCaseLabels: false IndentCaseLabels: false
AlwaysBreakTemplateDeclarations: false AlwaysBreakTemplateDeclarations: false
DerivePointerAlignment: false DerivePointerAlignment: false
AllowShortCaseLabelsOnASingleLine: true
AlignConsecutiveShortCaseStatements:
Enabled: true
AcrossEmptyLines: true
AcrossComments: true
AlignCaseColons: false

View File

@ -1364,12 +1364,9 @@ FMT_CONSTEXPR auto parse_nonnegative_int(const Char*& begin, const Char* end,
FMT_CONSTEXPR inline auto parse_align(char c) -> align { FMT_CONSTEXPR inline auto parse_align(char c) -> align {
switch (c) { switch (c) {
case '<': case '<': return align::left;
return align::left; case '>': return align::right;
case '>': case '^': return align::center;
return align::right;
case '^':
return align::center;
} }
return align::none; return align::none;
} }
@ -1584,40 +1581,20 @@ FMT_CONSTEXPR auto parse_format_specs(const Char* begin, const Char* end,
specs.set_localized(); specs.set_localized();
++begin; ++begin;
break; break;
case 'd': case 'd': return parse_presentation_type(pres::dec, integral_set);
return parse_presentation_type(pres::dec, integral_set); case 'X': specs.set_upper(); FMT_FALLTHROUGH;
case 'X': case 'x': return parse_presentation_type(pres::hex, integral_set);
specs.set_upper(); case 'o': return parse_presentation_type(pres::oct, integral_set);
FMT_FALLTHROUGH; case 'B': specs.set_upper(); FMT_FALLTHROUGH;
case 'x': case 'b': return parse_presentation_type(pres::bin, integral_set);
return parse_presentation_type(pres::hex, integral_set); case 'E': specs.set_upper(); FMT_FALLTHROUGH;
case 'o': case 'e': return parse_presentation_type(pres::exp, float_set);
return parse_presentation_type(pres::oct, integral_set); case 'F': specs.set_upper(); FMT_FALLTHROUGH;
case 'B': case 'f': return parse_presentation_type(pres::fixed, float_set);
specs.set_upper(); case 'G': specs.set_upper(); FMT_FALLTHROUGH;
FMT_FALLTHROUGH; case 'g': return parse_presentation_type(pres::general, float_set);
case 'b': case 'A': specs.set_upper(); FMT_FALLTHROUGH;
return parse_presentation_type(pres::bin, integral_set); case 'a': return parse_presentation_type(pres::hexfloat, float_set);
case 'E':
specs.set_upper();
FMT_FALLTHROUGH;
case 'e':
return parse_presentation_type(pres::exp, float_set);
case 'F':
specs.set_upper();
FMT_FALLTHROUGH;
case 'f':
return parse_presentation_type(pres::fixed, float_set);
case 'G':
specs.set_upper();
FMT_FALLTHROUGH;
case 'g':
return parse_presentation_type(pres::general, float_set);
case 'A':
specs.set_upper();
FMT_FALLTHROUGH;
case 'a':
return parse_presentation_type(pres::hexfloat, float_set);
case 'c': case 'c':
if (arg_type == type::bool_type) report_error("invalid format specifier"); if (arg_type == type::bool_type) report_error("invalid format specifier");
return parse_presentation_type(pres::chr, integral_set); return parse_presentation_type(pres::chr, integral_set);
@ -1629,8 +1606,7 @@ FMT_CONSTEXPR auto parse_format_specs(const Char* begin, const Char* end,
case '?': case '?':
return parse_presentation_type(pres::debug, return parse_presentation_type(pres::debug,
char_set | string_set | cstring_set); char_set | string_set | cstring_set);
case '}': case '}': return begin;
return begin;
default: { default: {
if (*begin == '}') return begin; if (*begin == '}') return begin;
// Parse fill and alignment. // Parse fill and alignment.
@ -1671,12 +1647,8 @@ FMT_CONSTEXPR FMT_INLINE auto parse_replacement_field(const Char* begin,
case '}': case '}':
handler.on_replacement_field(handler.on_arg_id(), begin); handler.on_replacement_field(handler.on_arg_id(), begin);
return begin + 1; return begin + 1;
case '{': case '{': handler.on_text(begin, begin + 1); return begin + 1;
handler.on_text(begin, begin + 1); case ':': arg_id = handler.on_arg_id(); break;
return begin + 1;
case ':':
arg_id = handler.on_arg_id();
break;
default: { default: {
struct id_adapter { struct id_adapter {
Handler& handler; Handler& handler;
@ -2559,37 +2531,25 @@ template <typename Context> class basic_format_arg {
template <typename Visitor> template <typename Visitor>
FMT_CONSTEXPR FMT_INLINE auto visit(Visitor&& vis) const -> decltype(vis(0)) { FMT_CONSTEXPR FMT_INLINE auto visit(Visitor&& vis) const -> decltype(vis(0)) {
switch (type_) { switch (type_) {
case detail::type::none_type: case detail::type::none_type: break;
break; case detail::type::int_type: return vis(value_.int_value);
case detail::type::int_type: case detail::type::uint_type: return vis(value_.uint_value);
return vis(value_.int_value); case detail::type::long_long_type: return vis(value_.long_long_value);
case detail::type::uint_type: case detail::type::ulong_long_type: return vis(value_.ulong_long_value);
return vis(value_.uint_value);
case detail::type::long_long_type:
return vis(value_.long_long_value);
case detail::type::ulong_long_type:
return vis(value_.ulong_long_value);
case detail::type::int128_type: case detail::type::int128_type:
return vis(detail::convert_for_visit(value_.int128_value)); return vis(detail::convert_for_visit(value_.int128_value));
case detail::type::uint128_type: case detail::type::uint128_type:
return vis(detail::convert_for_visit(value_.uint128_value)); return vis(detail::convert_for_visit(value_.uint128_value));
case detail::type::bool_type: case detail::type::bool_type: return vis(value_.bool_value);
return vis(value_.bool_value); case detail::type::char_type: return vis(value_.char_value);
case detail::type::char_type: case detail::type::float_type: return vis(value_.float_value);
return vis(value_.char_value); case detail::type::double_type: return vis(value_.double_value);
case detail::type::float_type: case detail::type::long_double_type: return vis(value_.long_double_value);
return vis(value_.float_value); case detail::type::cstring_type: return vis(value_.string.data);
case detail::type::double_type:
return vis(value_.double_value);
case detail::type::long_double_type:
return vis(value_.long_double_value);
case detail::type::cstring_type:
return vis(value_.string.data);
case detail::type::string_type: case detail::type::string_type:
using sv = basic_string_view<char_type>; using sv = basic_string_view<char_type>;
return vis(sv(value_.string.data, value_.string.size)); return vis(sv(value_.string.data, value_.string.size));
case detail::type::pointer_type: case detail::type::pointer_type: return vis(value_.pointer);
return vis(value_.pointer);
case detail::type::custom_type: case detail::type::custom_type:
return vis(typename basic_format_arg<Context>::handle(value_.custom)); return vis(typename basic_format_arg<Context>::handle(value_.custom));
} }

View File

@ -731,9 +731,7 @@ FMT_CONSTEXPR auto parse_chrono_format(const Char* begin, const Char* end,
if (ptr == end) FMT_THROW(format_error("invalid format")); if (ptr == end) FMT_THROW(format_error("invalid format"));
c = *ptr++; c = *ptr++;
switch (c) { switch (c) {
case '%': case '%': handler.on_text(ptr - 1, ptr); break;
handler.on_text(ptr - 1, ptr);
break;
case 'n': { case 'n': {
const Char newline[] = {'\n'}; const Char newline[] = {'\n'};
handler.on_text(newline, newline + 1); handler.on_text(newline, newline + 1);
@ -745,45 +743,21 @@ FMT_CONSTEXPR auto parse_chrono_format(const Char* begin, const Char* end,
break; break;
} }
// Year: // Year:
case 'Y': case 'Y': handler.on_year(numeric_system::standard); break;
handler.on_year(numeric_system::standard); case 'y': handler.on_short_year(numeric_system::standard); break;
break; case 'C': handler.on_century(numeric_system::standard); break;
case 'y': case 'G': handler.on_iso_week_based_year(); break;
handler.on_short_year(numeric_system::standard); case 'g': handler.on_iso_week_based_short_year(); break;
break;
case 'C':
handler.on_century(numeric_system::standard);
break;
case 'G':
handler.on_iso_week_based_year();
break;
case 'g':
handler.on_iso_week_based_short_year();
break;
// Day of the week: // Day of the week:
case 'a': case 'a': handler.on_abbr_weekday(); break;
handler.on_abbr_weekday(); case 'A': handler.on_full_weekday(); break;
break; case 'w': handler.on_dec0_weekday(numeric_system::standard); break;
case 'A': case 'u': handler.on_dec1_weekday(numeric_system::standard); break;
handler.on_full_weekday();
break;
case 'w':
handler.on_dec0_weekday(numeric_system::standard);
break;
case 'u':
handler.on_dec1_weekday(numeric_system::standard);
break;
// Month: // Month:
case 'b': case 'b':
case 'h': case 'h': handler.on_abbr_month(); break;
handler.on_abbr_month(); case 'B': handler.on_full_month(); break;
break; case 'm': handler.on_dec_month(numeric_system::standard); break;
case 'B':
handler.on_full_month();
break;
case 'm':
handler.on_dec_month(numeric_system::standard);
break;
// Day of the year/month: // Day of the year/month:
case 'U': case 'U':
handler.on_dec0_week_of_year(numeric_system::standard, pad); handler.on_dec0_week_of_year(numeric_system::standard, pad);
@ -791,99 +765,44 @@ FMT_CONSTEXPR auto parse_chrono_format(const Char* begin, const Char* end,
case 'W': case 'W':
handler.on_dec1_week_of_year(numeric_system::standard, pad); handler.on_dec1_week_of_year(numeric_system::standard, pad);
break; break;
case 'V': case 'V': handler.on_iso_week_of_year(numeric_system::standard, pad); break;
handler.on_iso_week_of_year(numeric_system::standard, pad); case 'j': handler.on_day_of_year(); break;
break; case 'd': handler.on_day_of_month(numeric_system::standard, pad); break;
case 'j':
handler.on_day_of_year();
break;
case 'd':
handler.on_day_of_month(numeric_system::standard, pad);
break;
case 'e': case 'e':
handler.on_day_of_month(numeric_system::standard, pad_type::space); handler.on_day_of_month(numeric_system::standard, pad_type::space);
break; break;
// Hour, minute, second: // Hour, minute, second:
case 'H': case 'H': handler.on_24_hour(numeric_system::standard, pad); break;
handler.on_24_hour(numeric_system::standard, pad); case 'I': handler.on_12_hour(numeric_system::standard, pad); break;
break; case 'M': handler.on_minute(numeric_system::standard, pad); break;
case 'I': case 'S': handler.on_second(numeric_system::standard, pad); break;
handler.on_12_hour(numeric_system::standard, pad);
break;
case 'M':
handler.on_minute(numeric_system::standard, pad);
break;
case 'S':
handler.on_second(numeric_system::standard, pad);
break;
// Other: // Other:
case 'c': case 'c': handler.on_datetime(numeric_system::standard); break;
handler.on_datetime(numeric_system::standard); case 'x': handler.on_loc_date(numeric_system::standard); break;
break; case 'X': handler.on_loc_time(numeric_system::standard); break;
case 'x': case 'D': handler.on_us_date(); break;
handler.on_loc_date(numeric_system::standard); case 'F': handler.on_iso_date(); break;
break; case 'r': handler.on_12_hour_time(); break;
case 'X': case 'R': handler.on_24_hour_time(); break;
handler.on_loc_time(numeric_system::standard); case 'T': handler.on_iso_time(); break;
break; case 'p': handler.on_am_pm(); break;
case 'D': case 'Q': handler.on_duration_value(); break;
handler.on_us_date(); case 'q': handler.on_duration_unit(); break;
break; case 'z': handler.on_utc_offset(numeric_system::standard); break;
case 'F': case 'Z': handler.on_tz_name(); break;
handler.on_iso_date();
break;
case 'r':
handler.on_12_hour_time();
break;
case 'R':
handler.on_24_hour_time();
break;
case 'T':
handler.on_iso_time();
break;
case 'p':
handler.on_am_pm();
break;
case 'Q':
handler.on_duration_value();
break;
case 'q':
handler.on_duration_unit();
break;
case 'z':
handler.on_utc_offset(numeric_system::standard);
break;
case 'Z':
handler.on_tz_name();
break;
// Alternative representation: // Alternative representation:
case 'E': { case 'E': {
if (ptr == end) FMT_THROW(format_error("invalid format")); if (ptr == end) FMT_THROW(format_error("invalid format"));
c = *ptr++; c = *ptr++;
switch (c) { switch (c) {
case 'Y': case 'Y': handler.on_year(numeric_system::alternative); break;
handler.on_year(numeric_system::alternative); case 'y': handler.on_offset_year(); break;
break; case 'C': handler.on_century(numeric_system::alternative); break;
case 'y': case 'c': handler.on_datetime(numeric_system::alternative); break;
handler.on_offset_year(); case 'x': handler.on_loc_date(numeric_system::alternative); break;
break; case 'X': handler.on_loc_time(numeric_system::alternative); break;
case 'C': case 'z': handler.on_utc_offset(numeric_system::alternative); break;
handler.on_century(numeric_system::alternative); default: FMT_THROW(format_error("invalid format"));
break;
case 'c':
handler.on_datetime(numeric_system::alternative);
break;
case 'x':
handler.on_loc_date(numeric_system::alternative);
break;
case 'X':
handler.on_loc_time(numeric_system::alternative);
break;
case 'z':
handler.on_utc_offset(numeric_system::alternative);
break;
default:
FMT_THROW(format_error("invalid format"));
} }
break; break;
} }
@ -891,12 +810,8 @@ FMT_CONSTEXPR auto parse_chrono_format(const Char* begin, const Char* end,
if (ptr == end) FMT_THROW(format_error("invalid format")); if (ptr == end) FMT_THROW(format_error("invalid format"));
c = *ptr++; c = *ptr++;
switch (c) { switch (c) {
case 'y': case 'y': handler.on_short_year(numeric_system::alternative); break;
handler.on_short_year(numeric_system::alternative); case 'm': handler.on_dec_month(numeric_system::alternative); break;
break;
case 'm':
handler.on_dec_month(numeric_system::alternative);
break;
case 'U': case 'U':
handler.on_dec0_week_of_year(numeric_system::alternative, pad); handler.on_dec0_week_of_year(numeric_system::alternative, pad);
break; break;
@ -912,33 +827,17 @@ FMT_CONSTEXPR auto parse_chrono_format(const Char* begin, const Char* end,
case 'e': case 'e':
handler.on_day_of_month(numeric_system::alternative, pad_type::space); handler.on_day_of_month(numeric_system::alternative, pad_type::space);
break; break;
case 'w': case 'w': handler.on_dec0_weekday(numeric_system::alternative); break;
handler.on_dec0_weekday(numeric_system::alternative); case 'u': handler.on_dec1_weekday(numeric_system::alternative); break;
break; case 'H': handler.on_24_hour(numeric_system::alternative, pad); break;
case 'u': case 'I': handler.on_12_hour(numeric_system::alternative, pad); break;
handler.on_dec1_weekday(numeric_system::alternative); case 'M': handler.on_minute(numeric_system::alternative, pad); break;
break; case 'S': handler.on_second(numeric_system::alternative, pad); break;
case 'H': case 'z': handler.on_utc_offset(numeric_system::alternative); break;
handler.on_24_hour(numeric_system::alternative, pad); default: FMT_THROW(format_error("invalid format"));
break;
case 'I':
handler.on_12_hour(numeric_system::alternative, pad);
break;
case 'M':
handler.on_minute(numeric_system::alternative, pad);
break;
case 'S':
handler.on_second(numeric_system::alternative, pad);
break;
case 'z':
handler.on_utc_offset(numeric_system::alternative);
break;
default:
FMT_THROW(format_error("invalid format"));
} }
break; break;
default: default: FMT_THROW(format_error("invalid format"));
FMT_THROW(format_error("invalid format"));
} }
begin = ptr; begin = ptr;
} }

View File

@ -1959,13 +1959,9 @@ auto write_escaped_cp(OutputIt out, const find_escape_result<Char>& escape)
*out++ = static_cast<Char>('\\'); *out++ = static_cast<Char>('\\');
c = static_cast<Char>('t'); c = static_cast<Char>('t');
break; break;
case '"': case '"': FMT_FALLTHROUGH;
FMT_FALLTHROUGH; case '\'': FMT_FALLTHROUGH;
case '\'': case '\\': *out++ = static_cast<Char>('\\'); break;
FMT_FALLTHROUGH;
case '\\':
*out++ = static_cast<Char>('\\');
break;
default: default:
if (escape.cp < 0x100) return write_codepoint<2, Char>(out, 'x', escape.cp); if (escape.cp < 0x100) return write_codepoint<2, Char>(out, 'x', escape.cp);
if (escape.cp < 0x10000) if (escape.cp < 0x10000)
@ -2114,9 +2110,7 @@ auto write_int(OutputIt out, UInt value, unsigned prefix,
int num_digits = 0; int num_digits = 0;
auto buffer = memory_buffer(); auto buffer = memory_buffer();
switch (specs.type()) { switch (specs.type()) {
default: default: FMT_ASSERT(false, ""); FMT_FALLTHROUGH;
FMT_ASSERT(false, "");
FMT_FALLTHROUGH;
case presentation_type::none: case presentation_type::none:
case presentation_type::dec: case presentation_type::dec:
num_digits = count_digits(value); num_digits = count_digits(value);
@ -2244,9 +2238,7 @@ FMT_CONSTEXPR FMT_INLINE auto write_int(OutputIt out, write_int_arg<T> arg,
auto abs_value = arg.abs_value; auto abs_value = arg.abs_value;
auto prefix = arg.prefix; auto prefix = arg.prefix;
switch (specs.type()) { switch (specs.type()) {
default: default: FMT_ASSERT(false, ""); FMT_FALLTHROUGH;
FMT_ASSERT(false, "");
FMT_FALLTHROUGH;
case presentation_type::none: case presentation_type::none:
case presentation_type::dec: case presentation_type::dec:
begin = do_format_decimal(buffer, abs_value, buffer_size); begin = do_format_decimal(buffer, abs_value, buffer_size);
@ -2399,15 +2391,9 @@ FMT_CONSTEXPR auto parse_align(const Char* begin, const Char* end,
if (end - p <= 0) p = begin; if (end - p <= 0) p = begin;
for (;;) { for (;;) {
switch (to_ascii(*p)) { switch (to_ascii(*p)) {
case '<': case '<': alignment = align::left; break;
alignment = align::left; case '>': alignment = align::right; break;
break; case '^': alignment = align::center; break;
case '>':
alignment = align::right;
break;
case '^':
alignment = align::center;
break;
} }
if (alignment != align::none) { if (alignment != align::none) {
if (p != begin) { if (p != begin) {

View File

@ -328,23 +328,14 @@ template <typename Char>
void parse_flags(format_specs& specs, const Char*& it, const Char* end) { void parse_flags(format_specs& specs, const Char*& it, const Char* end) {
for (; it != end; ++it) { for (; it != end; ++it) {
switch (*it) { switch (*it) {
case '-': case '-': specs.set_align(align::left); break;
specs.set_align(align::left); case '+': specs.set_sign(sign::plus); break;
break; case '0': specs.set_fill('0'); break;
case '+':
specs.set_sign(sign::plus);
break;
case '0':
specs.set_fill('0');
break;
case ' ': case ' ':
if (specs.sign() != sign::plus) specs.set_sign(sign::space); if (specs.sign() != sign::plus) specs.set_sign(sign::space);
break; break;
case '#': case '#': specs.set_alt(); break;
specs.set_alt(); default: return;
break;
default:
return;
} }
} }
} }
@ -392,43 +383,22 @@ inline auto parse_printf_presentation_type(char c, type t, bool& upper)
using pt = presentation_type; using pt = presentation_type;
constexpr auto integral_set = sint_set | uint_set | bool_set | char_set; constexpr auto integral_set = sint_set | uint_set | bool_set | char_set;
switch (c) { switch (c) {
case 'd': case 'd': return in(t, integral_set) ? pt::dec : pt::none;
return in(t, integral_set) ? pt::dec : pt::none; case 'o': return in(t, integral_set) ? pt::oct : pt::none;
case 'o': case 'X': upper = true; FMT_FALLTHROUGH;
return in(t, integral_set) ? pt::oct : pt::none; case 'x': return in(t, integral_set) ? pt::hex : pt::none;
case 'X': case 'E': upper = true; FMT_FALLTHROUGH;
upper = true; case 'e': return in(t, float_set) ? pt::exp : pt::none;
FMT_FALLTHROUGH; case 'F': upper = true; FMT_FALLTHROUGH;
case 'x': case 'f': return in(t, float_set) ? pt::fixed : pt::none;
return in(t, integral_set) ? pt::hex : pt::none; case 'G': upper = true; FMT_FALLTHROUGH;
case 'E': case 'g': return in(t, float_set) ? pt::general : pt::none;
upper = true; case 'A': upper = true; FMT_FALLTHROUGH;
FMT_FALLTHROUGH; case 'a': return in(t, float_set) ? pt::hexfloat : pt::none;
case 'e': case 'c': return in(t, integral_set) ? pt::chr : pt::none;
return in(t, float_set) ? pt::exp : pt::none; case 's': return in(t, string_set | cstring_set) ? pt::string : pt::none;
case 'F': case 'p': return in(t, pointer_set | cstring_set) ? pt::pointer : pt::none;
upper = true; default: return pt::none;
FMT_FALLTHROUGH;
case 'f':
return in(t, float_set) ? pt::fixed : pt::none;
case 'G':
upper = true;
FMT_FALLTHROUGH;
case 'g':
return in(t, float_set) ? pt::general : pt::none;
case 'A':
upper = true;
FMT_FALLTHROUGH;
case 'a':
return in(t, float_set) ? pt::hexfloat : pt::none;
case 'c':
return in(t, integral_set) ? pt::chr : pt::none;
case 's':
return in(t, string_set | cstring_set) ? pt::string : pt::none;
case 'p':
return in(t, pointer_set | cstring_set) ? pt::pointer : pt::none;
default:
return pt::none;
} }
} }
@ -535,22 +505,14 @@ void vprintf(buffer<Char>& buf, basic_string_view<Char> format,
convert_arg<long>(arg, t); convert_arg<long>(arg, t);
} }
break; break;
case 'j': case 'j': convert_arg<intmax_t>(arg, t); break;
convert_arg<intmax_t>(arg, t); case 'z': convert_arg<size_t>(arg, t); break;
break; case 't': convert_arg<std::ptrdiff_t>(arg, t); break;
case 'z':
convert_arg<size_t>(arg, t);
break;
case 't':
convert_arg<std::ptrdiff_t>(arg, t);
break;
case 'L': case 'L':
// printf produces garbage when 'L' is omitted for long double, no // printf produces garbage when 'L' is omitted for long double, no
// need to do the same. // need to do the same.
break; break;
default: default: --it; convert_arg<void>(arg, c);
--it;
convert_arg<void>(arg, c);
} }
// Parse type. // Parse type.
@ -560,9 +522,7 @@ void vprintf(buffer<Char>& buf, basic_string_view<Char> format,
// Normalize type. // Normalize type.
switch (type) { switch (type) {
case 'i': case 'i':
case 'u': case 'u': type = 'd'; break;
type = 'd';
break;
case 'c': case 'c':
arg.visit(char_converter<basic_printf_context<Char>>(arg)); arg.visit(char_converter<basic_printf_context<Char>>(arg));
break; break;