From 123e058eb342e532fbe83c8b768331f7a97f74a7 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sun, 14 Jan 2024 08:11:13 -0800 Subject: [PATCH] Improve scan prototype --- test/scan-test.cc | 8 +++++--- test/scan.h | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/test/scan-test.cc b/test/scan-test.cc index 803ba0697850..f78d72ca35c5 100644 --- a/test/scan-test.cc +++ b/test/scan-test.cc @@ -97,7 +97,10 @@ template <> struct scanner { 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 { } // 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); } diff --git a/test/scan.h b/test/scan.h index 1ef94f41f0a7..54714313d97b 100644 --- a/test/scan.h +++ b/test/scan.h @@ -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}));