mirror of
https://github.com/fmtlib/fmt.git
synced 2025-03-14 04:18:45 +00:00
Improve scan prototype
This commit is contained in:
parent
f924d20dbd
commit
123e058eb3
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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}));
|
||||
|
Loading…
x
Reference in New Issue
Block a user