3#include "printf_frontend_parse_util.hpp"
16[[nodiscard]]
consteval Error ParseFlags(std::string_view source,
size_t& pos,
19 while (pos < source.size())
33 if (!Config::enable_alternate)
35 return Error::InvalidSpecifier;
58[[nodiscard]]
consteval Error ParseWidth(std::string_view source,
size_t& pos,
61 if (pos < source.size() && source[pos] ==
'*')
63 return Error::DynamicField;
66 if (!Config::enable_width && pos < source.size() && IsDigit(source[pos]))
68 return Error::InvalidSpecifier;
71 return ParseByte(source, pos, std::numeric_limits<uint8_t>::max(),
85 if (pos >= source.size() || source[pos] !=
'.')
90 if (!Config::enable_precision)
92 return Error::InvalidSpecifier;
96 if (pos < source.size() && source[pos] ==
'*')
98 return Error::DynamicField;
101 if (pos < source.size() && IsDigit(source[pos]))
105 source, pos,
static_cast<uint8_t
>(std::numeric_limits<uint8_t>::max() - 1),
120consteval void ParseLength(std::string_view source,
size_t& pos,
123 if (pos >= source.size())
128 char token = source[pos];
129 if (token ==
'h' || token ==
'l')
132 conversion.
length = (token ==
'h') ? Length::Short : Length::Long;
133 if (pos < source.size() && source[pos] == token)
135 conversion.
length = (token ==
'h') ? Length::Char : Length::LongLong;
144 conversion.
length = Length::IntMax;
148 conversion.
length = Length::Size;
152 conversion.
length = Length::PtrDiff;
156 conversion.
length = Length::LongDouble;
174 if (pos >= source.size())
176 return Error::UnexpectedEnd;
179 auto descriptor = FieldSelection::LookupSpecifier(source[pos]);
180 if (descriptor.type == ValueKind::None)
182 return Error::InvalidSpecifier;
184 if (!FieldSelection::LengthAllowed(descriptor.length_policy, conversion.
length))
186 return Error::InvalidLength;
188 if (!FieldSelection::TypeEnabled(descriptor.gate, conversion.
length))
190 return Error::InvalidSpecifier;
193 conversion.
type = descriptor.type;
207[[nodiscard]]
consteval Error Parse(std::string_view source,
size_t& pos,
212 if (pos >= source.size())
214 return Error::UnexpectedEnd;
218 if (error != Error::None)
224 if (error != Error::None)
230 if (error != Error::None)
236 if (error != Error::None)
243 if (error != Error::None)
248 error = FieldSelection::ValidateConversion(conversion);
249 if (error != Error::None)
258 return Error::MixedIndexing;
consteval Error ParseByte(std::string_view source, size_t &pos, uint8_t limit, uint8_t &value)
解析一个目标为字节宽度的十进制整数字段片段,并检查是否溢出 / Parse one decimal byte-sized integer fragment with overflow checking
consteval Error ParseArgumentIndex(std::string_view source, size_t &pos, IndexingState &indexing, Conversion &conversion)
解析可选的前导 n$ 位置参数选择器 / Parse the optional leading n$ positional argument selector
consteval Error ParseWidth(std::string_view source, size_t &pos, Conversion &conversion)
解析一个可选的常量宽度字段 / Parse one optional constant width field
consteval void ParseLength(std::string_view source, size_t &pos, Conversion &conversion)
解析一个可选的长度修饰符序列 / Parse one optional length modifier sequence
consteval Error ParsePrecision(std::string_view source, size_t &pos, Conversion &conversion)
解析一个可选的常量精度字段 / Parse one optional constant precision field
consteval Error ParseSpecifier(std::string_view source, size_t &pos, Conversion &conversion)
解析并校验最终的转换说明符字符 / Parse and validate the final conversion specifier token
consteval Error Parse(std::string_view source, size_t &pos, IndexingState &indexing, Conversion &conversion)
在前导 % 之后解析一个完整 printf 转换项 / Parse one complete printf conversion after the leading %
consteval Error ParseFlags(std::string_view source, size_t &pos, Conversion &conversion)
单个 printf 转换体的源级解析器 / Source parser for one printf conversion body
单个 printf 转换在降为共享格式前的解析结果 / One parsed printf conversion before lowering into the shared format
ValueKind type
semantic conversion category / 转换项归一化后的语义类别
bool upper_case
implied uppercase output / 隐含的大写输出标志
bool left_align
parsed - flag / 已解析的 - 标志
Length length
parsed length modifier / 已解析的长度修饰符
uint8_t width
parsed field width / 已解析的字段宽度
bool force_sign
parsed + flag / 已解析的 + 标志
bool positional
whether arg_index came from n$ syntax / arg_index 是否来自 n$ 语法
bool zero_pad
parsed 0 flag / 已解析的 0 标志
bool space_sign
parsed space-sign flag / 已解析的空格正号标志
size_t arg_index
source argument index consumed by this field / 当前字段消耗的源参数索引
bool alternate
parsed # flag / 已解析的 # 标志
uint8_t precision
parsed precision value / 已解析的精度值
bool has_precision
whether precision was explicitly provided / 是否显式提供了精度
brace 字段自动索引与手动索引的源级状态 / Source-level indexing mode for automatic versus manual brace fields
bool uses_sequential
at least one conversion used implicit sequential order / 至少有一个转换使用了隐式顺序参数
bool uses_positional
at least one conversion used n$ syntax / 至少有一个转换使用了 n$ 语法
size_t next_index
next sequential argument index / 下一个顺序参数索引