18[[nodiscard]]
constexpr bool IsDigit(
char ch)
20 return ch >=
'0' && ch <=
'9';
28[[nodiscard]]
constexpr bool HasEmbeddedNul(std::string_view source)
30 for (
char ch : source)
57 if (pos >= source.size() || !IsDigit(source[pos]))
64 while (probe < source.size() && IsDigit(source[probe]))
66 auto digit =
static_cast<size_t>(source[probe] -
'0');
67 if (index > (std::numeric_limits<size_t>::max() - digit) / 10)
69 return Error::NumberOverflow;
72 index = index * 10 + digit;
76 if (probe >= source.size() || source[probe] !=
'$')
81 if (!Config::enable_explicit_argument_indexing)
83 return Error::PositionalArgumentDisabled;
88 return Error::InvalidArgumentIndex;
92 return Error::MixedIndexing;
110[[nodiscard]]
consteval Error ParseByte(std::string_view source,
size_t& pos,
111 uint8_t limit, uint8_t& value)
114 if (pos >= source.size() || !IsDigit(source[pos]))
119 while (pos < source.size() && IsDigit(source[pos]))
121 auto digit =
static_cast<uint8_t
>(source[pos] -
'0');
122 if (value >
static_cast<uint8_t
>((limit - digit) / 10))
124 return Error::NumberOverflow;
127 value =
static_cast<uint8_t
>(value * 10 + digit);
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
单个 printf 转换在降为共享格式前的解析结果 / One parsed printf conversion before lowering into the shared format
bool positional
whether arg_index came from n$ syntax / arg_index 是否来自 n$ 语法
size_t arg_index
source argument index consumed by this field / 当前字段消耗的源参数索引
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 / 下一个顺序参数索引