diff --git a/.clang-format b/.clang-format index df55d340..31f8c343 100644 --- a/.clang-format +++ b/.clang-format @@ -6,3 +6,9 @@ IndentPPDirectives: AfterHash IndentCaseLabels: false AlwaysBreakTemplateDeclarations: false DerivePointerAlignment: false +AllowShortCaseLabelsOnASingleLine: true +AlignConsecutiveShortCaseStatements: + Enabled: true + AcrossEmptyLines: true + AcrossComments: true + AlignCaseColons: false \ No newline at end of file diff --git a/include/fmt/base.h b/include/fmt/base.h index 60c27565..0c9e562a 100644 --- a/include/fmt/base.h +++ b/include/fmt/base.h @@ -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 { switch (c) { - case '<': - return align::left; - case '>': - return align::right; - case '^': - return align::center; + case '<': return align::left; + case '>': return align::right; + case '^': return align::center; } return align::none; } @@ -1584,40 +1581,20 @@ FMT_CONSTEXPR auto parse_format_specs(const Char* begin, const Char* end, specs.set_localized(); ++begin; break; - case 'd': - return parse_presentation_type(pres::dec, integral_set); - case 'X': - specs.set_upper(); - FMT_FALLTHROUGH; - case 'x': - return parse_presentation_type(pres::hex, integral_set); - case 'o': - return parse_presentation_type(pres::oct, integral_set); - case 'B': - specs.set_upper(); - FMT_FALLTHROUGH; - case 'b': - return parse_presentation_type(pres::bin, integral_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 'd': return parse_presentation_type(pres::dec, integral_set); + case 'X': specs.set_upper(); FMT_FALLTHROUGH; + case 'x': return parse_presentation_type(pres::hex, integral_set); + case 'o': return parse_presentation_type(pres::oct, integral_set); + case 'B': specs.set_upper(); FMT_FALLTHROUGH; + case 'b': return parse_presentation_type(pres::bin, integral_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': if (arg_type == type::bool_type) report_error("invalid format specifier"); return parse_presentation_type(pres::chr, integral_set); @@ -1629,9 +1606,8 @@ FMT_CONSTEXPR auto parse_format_specs(const Char* begin, const Char* end, case '?': return parse_presentation_type(pres::debug, char_set | string_set | cstring_set); - case '}': - return begin; - default: { + case '}': return begin; + default: { if (*begin == '}') return begin; // Parse fill and alignment. auto fill_end = begin + code_point_length(begin); @@ -1671,13 +1647,9 @@ FMT_CONSTEXPR FMT_INLINE auto parse_replacement_field(const Char* begin, case '}': handler.on_replacement_field(handler.on_arg_id(), begin); return begin + 1; - case '{': - handler.on_text(begin, begin + 1); - return begin + 1; - case ':': - arg_id = handler.on_arg_id(); - break; - default: { + case '{': handler.on_text(begin, begin + 1); return begin + 1; + case ':': arg_id = handler.on_arg_id(); break; + default: { struct id_adapter { Handler& handler; int arg_id; @@ -2559,37 +2531,25 @@ template class basic_format_arg { template FMT_CONSTEXPR FMT_INLINE auto visit(Visitor&& vis) const -> decltype(vis(0)) { switch (type_) { - case detail::type::none_type: - break; - case detail::type::int_type: - return vis(value_.int_value); - case detail::type::uint_type: - 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::none_type: break; + case detail::type::int_type: return vis(value_.int_value); + case detail::type::uint_type: 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: return vis(detail::convert_for_visit(value_.int128_value)); case detail::type::uint128_type: return vis(detail::convert_for_visit(value_.uint128_value)); - case detail::type::bool_type: - return vis(value_.bool_value); - case detail::type::char_type: - return vis(value_.char_value); - case detail::type::float_type: - return vis(value_.float_value); - 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::bool_type: return vis(value_.bool_value); + case detail::type::char_type: return vis(value_.char_value); + case detail::type::float_type: return vis(value_.float_value); + 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: using sv = basic_string_view; return vis(sv(value_.string.data, value_.string.size)); - case detail::type::pointer_type: - return vis(value_.pointer); + case detail::type::pointer_type: return vis(value_.pointer); case detail::type::custom_type: return vis(typename basic_format_arg::handle(value_.custom)); } diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index 3af4ff21..940f357e 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -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")); c = *ptr++; switch (c) { - case '%': - handler.on_text(ptr - 1, ptr); - break; + case '%': handler.on_text(ptr - 1, ptr); break; case 'n': { const Char newline[] = {'\n'}; handler.on_text(newline, newline + 1); @@ -745,45 +743,21 @@ FMT_CONSTEXPR auto parse_chrono_format(const Char* begin, const Char* end, break; } // Year: - case 'Y': - handler.on_year(numeric_system::standard); - break; - case 'y': - handler.on_short_year(numeric_system::standard); - 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; + case 'Y': handler.on_year(numeric_system::standard); break; + case 'y': handler.on_short_year(numeric_system::standard); 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: - case 'a': - handler.on_abbr_weekday(); - break; - case 'A': - 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; + case 'a': handler.on_abbr_weekday(); break; + case 'A': 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: case 'b': - case 'h': - handler.on_abbr_month(); - break; - case 'B': - handler.on_full_month(); - break; - case 'm': - handler.on_dec_month(numeric_system::standard); - break; + case 'h': handler.on_abbr_month(); break; + case 'B': handler.on_full_month(); break; + case 'm': handler.on_dec_month(numeric_system::standard); break; // Day of the year/month: case 'U': 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': handler.on_dec1_week_of_year(numeric_system::standard, pad); break; - case 'V': - handler.on_iso_week_of_year(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 'V': handler.on_iso_week_of_year(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': handler.on_day_of_month(numeric_system::standard, pad_type::space); break; // Hour, minute, second: - case 'H': - handler.on_24_hour(numeric_system::standard, pad); - break; - case 'I': - 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; + case 'H': handler.on_24_hour(numeric_system::standard, pad); break; + case 'I': 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: - case 'c': - handler.on_datetime(numeric_system::standard); - break; - case 'x': - handler.on_loc_date(numeric_system::standard); - break; - case 'X': - handler.on_loc_time(numeric_system::standard); - break; - case 'D': - handler.on_us_date(); - break; - case 'F': - 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; + case 'c': handler.on_datetime(numeric_system::standard); break; + case 'x': handler.on_loc_date(numeric_system::standard); break; + case 'X': handler.on_loc_time(numeric_system::standard); break; + case 'D': handler.on_us_date(); break; + case 'F': 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: case 'E': { if (ptr == end) FMT_THROW(format_error("invalid format")); c = *ptr++; switch (c) { - case 'Y': - handler.on_year(numeric_system::alternative); - break; - case 'y': - handler.on_offset_year(); - break; - case 'C': - handler.on_century(numeric_system::alternative); - 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")); + case 'Y': handler.on_year(numeric_system::alternative); break; + case 'y': handler.on_offset_year(); break; + case 'C': handler.on_century(numeric_system::alternative); 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; } @@ -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")); c = *ptr++; switch (c) { - case 'y': - handler.on_short_year(numeric_system::alternative); - break; - case 'm': - handler.on_dec_month(numeric_system::alternative); - break; + case 'y': handler.on_short_year(numeric_system::alternative); break; + case 'm': handler.on_dec_month(numeric_system::alternative); break; case 'U': handler.on_dec0_week_of_year(numeric_system::alternative, pad); break; @@ -912,33 +827,17 @@ FMT_CONSTEXPR auto parse_chrono_format(const Char* begin, const Char* end, case 'e': handler.on_day_of_month(numeric_system::alternative, pad_type::space); break; - case 'w': - handler.on_dec0_weekday(numeric_system::alternative); - break; - case 'u': - handler.on_dec1_weekday(numeric_system::alternative); - break; - case 'H': - handler.on_24_hour(numeric_system::alternative, pad); - 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")); + case 'w': handler.on_dec0_weekday(numeric_system::alternative); break; + case 'u': handler.on_dec1_weekday(numeric_system::alternative); break; + case 'H': handler.on_24_hour(numeric_system::alternative, pad); 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; - default: - FMT_THROW(format_error("invalid format")); + default: FMT_THROW(format_error("invalid format")); } begin = ptr; } diff --git a/include/fmt/format.h b/include/fmt/format.h index 63af76c7..a6cafc01 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -1959,13 +1959,9 @@ auto write_escaped_cp(OutputIt out, const find_escape_result& escape) *out++ = static_cast('\\'); c = static_cast('t'); break; - case '"': - FMT_FALLTHROUGH; - case '\'': - FMT_FALLTHROUGH; - case '\\': - *out++ = static_cast('\\'); - break; + case '"': FMT_FALLTHROUGH; + case '\'': FMT_FALLTHROUGH; + case '\\': *out++ = static_cast('\\'); break; default: if (escape.cp < 0x100) return write_codepoint<2, Char>(out, 'x', escape.cp); if (escape.cp < 0x10000) @@ -2114,9 +2110,7 @@ auto write_int(OutputIt out, UInt value, unsigned prefix, int num_digits = 0; auto buffer = memory_buffer(); switch (specs.type()) { - default: - FMT_ASSERT(false, ""); - FMT_FALLTHROUGH; + default: FMT_ASSERT(false, ""); FMT_FALLTHROUGH; case presentation_type::none: case presentation_type::dec: num_digits = count_digits(value); @@ -2244,9 +2238,7 @@ FMT_CONSTEXPR FMT_INLINE auto write_int(OutputIt out, write_int_arg arg, auto abs_value = arg.abs_value; auto prefix = arg.prefix; switch (specs.type()) { - default: - FMT_ASSERT(false, ""); - FMT_FALLTHROUGH; + default: FMT_ASSERT(false, ""); FMT_FALLTHROUGH; case presentation_type::none: case presentation_type::dec: 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; for (;;) { switch (to_ascii(*p)) { - case '<': - alignment = align::left; - break; - case '>': - alignment = align::right; - break; - case '^': - alignment = align::center; - break; + case '<': alignment = align::left; break; + case '>': alignment = align::right; break; + case '^': alignment = align::center; break; } if (alignment != align::none) { if (p != begin) { diff --git a/include/fmt/printf.h b/include/fmt/printf.h index 7344416f..aa982055 100644 --- a/include/fmt/printf.h +++ b/include/fmt/printf.h @@ -328,23 +328,14 @@ template void parse_flags(format_specs& specs, const Char*& it, const Char* end) { for (; it != end; ++it) { switch (*it) { - case '-': - specs.set_align(align::left); - break; - case '+': - specs.set_sign(sign::plus); - break; - case '0': - specs.set_fill('0'); - break; + case '-': specs.set_align(align::left); break; + case '+': specs.set_sign(sign::plus); break; + case '0': specs.set_fill('0'); break; case ' ': if (specs.sign() != sign::plus) specs.set_sign(sign::space); break; - case '#': - specs.set_alt(); - break; - default: - return; + case '#': specs.set_alt(); break; + default: return; } } } @@ -392,43 +383,22 @@ inline auto parse_printf_presentation_type(char c, type t, bool& upper) using pt = presentation_type; constexpr auto integral_set = sint_set | uint_set | bool_set | char_set; switch (c) { - case 'd': - return in(t, integral_set) ? pt::dec : pt::none; - case 'o': - return in(t, integral_set) ? pt::oct : pt::none; - case 'X': - upper = true; - FMT_FALLTHROUGH; - case 'x': - return in(t, integral_set) ? pt::hex : pt::none; - case 'E': - upper = true; - FMT_FALLTHROUGH; - case 'e': - return in(t, float_set) ? pt::exp : pt::none; - case 'F': - upper = true; - 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; + case 'd': return in(t, integral_set) ? pt::dec : pt::none; + case 'o': return in(t, integral_set) ? pt::oct : pt::none; + case 'X': upper = true; FMT_FALLTHROUGH; + case 'x': return in(t, integral_set) ? pt::hex : pt::none; + case 'E': upper = true; FMT_FALLTHROUGH; + case 'e': return in(t, float_set) ? pt::exp : pt::none; + case 'F': upper = true; 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& buf, basic_string_view format, convert_arg(arg, t); } break; - case 'j': - convert_arg(arg, t); - break; - case 'z': - convert_arg(arg, t); - break; - case 't': - convert_arg(arg, t); - break; + case 'j': convert_arg(arg, t); break; + case 'z': convert_arg(arg, t); break; + case 't': convert_arg(arg, t); break; case 'L': // printf produces garbage when 'L' is omitted for long double, no // need to do the same. break; - default: - --it; - convert_arg(arg, c); + default: --it; convert_arg(arg, c); } // Parse type. @@ -560,9 +522,7 @@ void vprintf(buffer& buf, basic_string_view format, // Normalize type. switch (type) { case 'i': - case 'u': - type = 'd'; - break; + case 'u': type = 'd'; break; case 'c': arg.visit(char_converter>(arg)); break;