MCPcopy Create free account
hub / github.com/fmtlib/fmt / parse_format_specs

Function parse_format_specs

include/fmt/base.h:1444–1579  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1442// Parses standard format specifiers.
1443template <typename Char>
1444FMT_CONSTEXPR auto parse_format_specs(const Char* begin, const Char* end,
1445 dynamic_format_specs<Char>& specs,
1446 parse_context<Char>& ctx, type arg_type)
1447 -> const Char* {
1448 auto c = '\0';
1449 if (end - begin > 1) {
1450 auto next = to_ascii(begin[1]);
1451 c = parse_align(next) == align::none ? to_ascii(*begin) : '\0';
1452 } else {
1453 if (begin == end) return begin;
1454 c = to_ascii(*begin);
1455 }
1456
1457 struct {
1458 state current_state = state::start;
1459 FMT_CONSTEXPR void operator()(state s, bool valid = true) {
1460 if (current_state >= s || !valid)
1461 report_error("invalid format specifier");
1462 current_state = s;
1463 }
1464 } enter_state;
1465
1466 using pres = presentation_type;
1467 constexpr auto integral_set = sint_set | uint_set | bool_set | char_set;
1468 struct {
1469 const Char*& begin;
1470 format_specs& specs;
1471 type arg_type;
1472
1473 FMT_CONSTEXPR auto operator()(pres pres_type, int set) -> const Char* {
1474 if (!in(arg_type, set)) report_error("invalid format specifier");
1475 specs.set_type(pres_type);
1476 return begin + 1;
1477 }
1478 } parse_presentation_type{begin, specs, arg_type};
1479
1480 for (;;) {
1481 switch (c) {
1482 case '<':
1483 case '>':
1484 case '^':
1485 enter_state(state::align);
1486 specs.set_align(parse_align(c));
1487 ++begin;
1488 break;
1489 case '+':
1490 case ' ':
1491 specs.set_sign(c == ' ' ? sign::space : sign::plus);
1492 FMT_FALLTHROUGH;
1493 case '-':
1494 enter_state(state::sign, in(arg_type, sint_set | float_set));
1495 ++begin;
1496 break;
1497 case '#':
1498 enter_state(state::hash, is_arithmetic_type(arg_type));
1499 specs.set_alt();
1500 ++begin;
1501 break;

Callers 6

parse_test_specsFunction · 0.85
parseMethod · 0.85
on_format_specsMethod · 0.85
parseMethod · 0.85
parseMethod · 0.85
parseMethod · 0.85

Calls 15

to_asciiFunction · 0.85
parse_alignFunction · 0.85
inFunction · 0.85
is_arithmetic_typeFunction · 0.85
report_errorFunction · 0.85
parse_widthFunction · 0.85
parse_precisionFunction · 0.85
code_point_lengthFunction · 0.85
to_unsignedFunction · 0.85
set_alignMethod · 0.80
set_signMethod · 0.80
set_altMethod · 0.80

Tested by 1

parse_test_specsFunction · 0.68