Skip to content

Commit

Permalink
Improve scan prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Jan 14, 2024
1 parent f924d20 commit 123e058
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
8 changes: 5 additions & 3 deletions test/scan-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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);
}

Expand Down
3 changes: 2 additions & 1 deletion test/scan.h
Original file line number Diff line number Diff line change
Expand Up @@ -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}));
Expand Down

0 comments on commit 123e058

Please sign in to comment.