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

Function parse_header

include/fmt/printf.h:330–379  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

328
329template <typename Char, typename GetArg>
330auto parse_header(const Char*& it, const Char* end, format_specs& specs,
331 GetArg get_arg) -> int {
332 int arg_index = -1;
333 if (it == end) return arg_index;
334 Char c = *it;
335 if (c >= '0' && c <= '9') {
336 // Parse an argument index (if followed by '$') or a width possibly
337 // preceded with '0' flag(s).
338 int value = parse_nonnegative_int(it, end, -1);
339 if (it != end && *it == '$') { // value is an argument index
340 ++it;
341 arg_index = value != -1 ? value : max_value<int>();
342 } else {
343 if (c == '0') specs.set_fill('0');
344 if (value != 0) {
345 // Nonzero value means that we parsed width and don't need to
346 // parse it or flags again, so return now.
347 if (value == -1) report_error("number is too big");
348 specs.width = value;
349 return arg_index;
350 }
351 }
352 }
353 parse_flags(specs, it, end);
354 // Parse width.
355 if (it != end) {
356 if (*it >= '0' && *it <= '9') {
357 specs.width = parse_nonnegative_int(it, end, -1);
358 if (specs.width == -1) report_error("number is too big");
359 } else if (*it == '*') {
360 ++it;
361 // Check for positional width argument like *1$
362 if (it != end && *it >= '0' && *it <= '9') {
363 int width_index = parse_nonnegative_int(it, end, -1);
364 if (it != end && *it == '$') {
365 ++it;
366 specs.width = static_cast<int>(
367 get_arg(width_index).visit(detail::printf_width_handler(specs)));
368 } else {
369 // Invalid format, rewind and treat as non-positional
370 report_error("invalid format specifier");
371 }
372 } else {
373 specs.width = static_cast<int>(
374 get_arg(-1).visit(detail::printf_width_handler(specs)));
375 }
376 }
377 }
378 return arg_index;
379}
380
381inline auto parse_printf_presentation_type(char c, type t, bool& upper)
382 -> presentation_type {

Callers 1

vprintfFunction · 0.85

Calls 6

parse_nonnegative_intFunction · 0.85
report_errorFunction · 0.85
parse_flagsFunction · 0.85
set_fillMethod · 0.80
visitMethod · 0.45

Tested by

no test coverage detected