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

Function compile_format_string

include/fmt/compile.h:381–448  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

379// or unknown_format() on unrecognized input.
380template <typename Args, size_t POS, int ID, bool DYNAMIC_NAMES, typename S>
381constexpr auto compile_format_string(S fmt) {
382 using char_type = typename S::char_type;
383 constexpr auto str = basic_string_view<char_type>(fmt);
384 if constexpr (str[POS] == '{') {
385 if constexpr (POS + 1 == str.size())
386 FMT_THROW(format_error("unmatched '{' in format string"));
387 if constexpr (str[POS + 1] == '{') {
388 return parse_tail<Args, POS + 2, ID, DYNAMIC_NAMES>(
389 make_text(str, POS, 1), fmt);
390 } else if constexpr (str[POS + 1] == '}' || str[POS + 1] == ':') {
391 static_assert(ID != manual_indexing_id,
392 "cannot switch from manual to automatic argument indexing");
393 constexpr auto next_id =
394 ID != manual_indexing_id ? ID + 1 : manual_indexing_id;
395 return parse_replacement_field_then_tail<
396 get_type<ID, Args>, Args, POS + 1, ID, next_id, DYNAMIC_NAMES>(fmt);
397 } else {
398 constexpr auto arg_id_result =
399 parse_arg_id<ID>(str.data() + POS + 1, str.data() + str.size());
400 constexpr auto arg_id_end_pos = arg_id_result.arg_id_end - str.data();
401 constexpr char_type c =
402 arg_id_end_pos != str.size() ? str[arg_id_end_pos] : char_type();
403 static_assert(c == '}' || c == ':', "missing '}' in format string");
404 if constexpr (arg_id_result.kind == arg_id_kind::index) {
405 static_assert(
406 ID == manual_indexing_id || ID == 0,
407 "cannot switch from automatic to manual argument indexing");
408 constexpr auto arg_index = arg_id_result.arg_id.index;
409 return parse_replacement_field_then_tail<
410 get_type<arg_index, Args>, Args, arg_id_end_pos, arg_index,
411 manual_indexing_id, DYNAMIC_NAMES>(fmt);
412 } else if constexpr (arg_id_result.kind == arg_id_kind::name) {
413 constexpr auto arg_index =
414 get_arg_index_by_name(arg_id_result.arg_id.name, Args{});
415
416 static_assert(arg_index >= 0 || DYNAMIC_NAMES,
417 "named argument not found");
418
419 if constexpr (arg_index >= 0) {
420 constexpr auto next_id =
421 ID != manual_indexing_id ? ID + 1 : manual_indexing_id;
422 return parse_replacement_field_then_tail<
423 decltype(get_type<arg_index, Args>::value), Args, arg_id_end_pos,
424 arg_index, next_id, DYNAMIC_NAMES>(fmt);
425 } else if constexpr (c == '}') {
426 return parse_tail<Args, arg_id_end_pos + 1, ID, DYNAMIC_NAMES>(
427 runtime_named_field<char_type>{arg_id_result.arg_id.name}, fmt);
428 } else if constexpr (c == ':') {
429 return unknown_format(); // no type info for specs parsing
430 }
431 }
432 }
433 } else if constexpr (str[POS] == '}') {
434 if constexpr (POS + 1 == str.size())
435 FMT_THROW(format_error("unmatched '}' in format string"));
436 return parse_tail<Args, POS + 2, ID, DYNAMIC_NAMES>(make_text(str, POS, 1),
437 fmt);
438 } else {

Callers

nothing calls this directly

Calls 6

make_textFunction · 0.85
get_arg_index_by_nameFunction · 0.85
unknown_formatClass · 0.85
parse_textFunction · 0.85
sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected