3#include "printf_frontend_parse_util.hpp"
18[[nodiscard]]
consteval Error ParseFlags(std::string_view source,
size_t& pos,
21 while (pos < source.size())
35 if (!Config::enable_alternate)
37 return Error::InvalidSpecifier;
62[[nodiscard]]
consteval Error ParseWidth(std::string_view source,
size_t& pos,
65 if (pos < source.size() && source[pos] ==
'*')
67 return Error::DynamicField;
70 if (!Config::enable_width && pos < source.size() && IsDigit(source[pos]))
72 return Error::InvalidSpecifier;
75 return ParseByte(source, pos, std::numeric_limits<uint8_t>::max(), conversion.
width);
90 if (pos >= source.size() || source[pos] !=
'.')
95 if (!Config::enable_precision)
97 return Error::InvalidSpecifier;
101 if (pos < source.size() && source[pos] ==
'*')
103 return Error::DynamicField;
106 if (pos < source.size() && IsDigit(source[pos]))
110 static_cast<uint8_t
>(std::numeric_limits<uint8_t>::max() - 1),
128 if (pos >= source.size())
133 char token = source[pos];
134 if (token ==
'h' || token ==
'l')
137 conversion.
length = (token ==
'h') ? Length::Short : Length::Long;
138 if (pos < source.size() && source[pos] == token)
140 conversion.
length = (token ==
'h') ? Length::Char : Length::LongLong;
149 conversion.
length = Length::IntMax;
153 conversion.
length = Length::Size;
157 conversion.
length = Length::PtrDiff;
161 conversion.
length = Length::LongDouble;
182 if (pos >= source.size())
184 return Error::UnexpectedEnd;
187 auto descriptor = FieldSelection::LookupSpecifier(source[pos]);
188 if (descriptor.type == ValueKind::None)
190 return Error::InvalidSpecifier;
192 if (!FieldSelection::LengthAllowed(descriptor.length_policy, conversion.
length))
194 return Error::InvalidLength;
196 if (!FieldSelection::TypeEnabled(descriptor.gate, conversion.
length))
198 return Error::InvalidSpecifier;
201 conversion.
type = descriptor.type;
218[[nodiscard]]
consteval Error Parse(std::string_view source,
size_t& pos,
222 if (pos >= source.size())
224 return Error::UnexpectedEnd;
228 if (error != Error::None)
234 if (error != Error::None)
240 if (error != Error::None)
246 if (error != Error::None)
253 if (error != Error::None)
258 error = FieldSelection::ValidateConversion(conversion);
259 if (error != Error::None)
268 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_positional
at least one conversion used n$ syntax / 至少有一个转换使用了 n$ 语法
size_t next_index
next sequential argument index / 下一个顺序参数索引