Improve scan prototype

This commit is contained in:
Victor Zverovich 2024-01-14 08:11:13 -08:00
parent f924d20dbd
commit 123e058eb3
2 changed files with 7 additions and 4 deletions

View File

@ -97,7 +97,10 @@ template <> struct scanner<num> {
auto parse(scan_parse_context& ctx) -> scan_parse_context::iterator {
auto it = ctx.begin(), end = ctx.end();
if (it != end && *it == 'x') hex = true;
if (it != end && *it == 'x') {
hex = true;
++it;
}
if (it != end && *it != '}') throw_format_error("invalid format");
return it;
}
@ -111,9 +114,8 @@ template <> struct scanner<num> {
} // namespace fmt
TEST(scan_test, read_custom) {
auto input = "42";
auto n = num();
fmt::scan(input, "{:}", n);
fmt::scan("42", "{}", n);
EXPECT_EQ(n.value, 42);
}

View File

@ -607,8 +607,9 @@ struct scan_handler {
return 0;
}
void on_replacement_field(int arg_id, const char*) {
void on_replacement_field(int arg_id, const char* begin) {
scan_arg arg = scan_ctx_.arg(arg_id);
if (arg.scan_custom(begin, parse_ctx_, scan_ctx_)) return;
auto it = scan_ctx_.begin();
while (it != sentinel() && is_whitespace(*it)) ++it;
scan_ctx_.advance_to(arg.visit(default_arg_scanner{it}));