24 if (parsed.has_precision && parsed.precision > Config::max_float_precision)
26 return ResolvedField{.error = Error::FloatPrecisionLimitExceeded};
31 if (presentation == 0)
33 return ResolvedField{.error = Error::ArgumentTypeMismatch};
35 bool upper_case = presentation ==
'F' || presentation ==
'E' || presentation ==
'G';
37 FormatType type = FormatType::End;
38 FormatPackKind pack = FormatPackKind::F32;
40 auto pick_type = [&](FormatType f32_type, FormatType f64_type,
41 FormatType ld_type)
consteval ->
bool
45 case ArgumentKind::Float32:
47 pack = FormatPackKind::F32;
49 case ArgumentKind::Float64:
50 type = Config::enable_float_double ? f64_type : f32_type;
51 pack = Config::enable_float_double ? FormatPackKind::F64 : FormatPackKind::F32;
53 case ArgumentKind::LongDouble:
54 if (!Config::enable_float_long_double)
59 pack = FormatPackKind::LongDouble;
70 if (!Config::enable_float_fixed ||
71 !pick_type(FormatType::FloatFixed, FormatType::DoubleFixed,
72 FormatType::LongDoubleFixed))
74 return ResolvedField{.error = Error::ArgumentTypeMismatch};
79 if (!Config::enable_float_scientific ||
80 !pick_type(FormatType::FloatScientific, FormatType::DoubleScientific,
81 FormatType::LongDoubleScientific))
83 return ResolvedField{.error = Error::ArgumentTypeMismatch};
88 if (!Config::enable_float_general ||
89 !pick_type(FormatType::FloatGeneral, FormatType::DoubleGeneral,
90 FormatType::LongDoubleGeneral))
92 return ResolvedField{.error = Error::ArgumentTypeMismatch};
96 return ResolvedField{.error = Error::ArgumentTypeMismatch};
99 return ResolvedField{.field =
MakeField(parsed, type, pack, upper_case)};
111[[nodiscard]]
consteval ResolvedField
ResolveField(
const ParsedField& parsed)
114 if (parsed.arg_index >= argument_summaries.size())
116 return ResolvedField{.error = Error::MissingArgument};
119 auto argument = argument_summaries[parsed.arg_index];
120 switch (argument.kind)
122 case ArgumentKind::Bool:
124 case ArgumentKind::Character:
126 case ArgumentKind::Signed:
128 case ArgumentKind::Unsigned:
130 case ArgumentKind::String:
132 case ArgumentKind::Pointer:
134 case ArgumentKind::Float32:
135 case ArgumentKind::Float64:
136 case ArgumentKind::LongDouble:
138 case ArgumentKind::Unsupported:
140 return ResolvedField{.error = Error::UnsupportedArgumentType};
constexpr FormatField MakeField(const ParsedField &parsed, FormatType type, FormatPackKind pack, bool upper_case=false)
根据 brace 字段属性构造一条共享 FormatField 记录 / Build one shared FormatField record from parsed brace-field prop...