mirror of
https://github.com/fmtlib/fmt.git
synced 2024-11-04 17:26:42 +00:00
Don't use error_ in parse_arg_index.
This commit is contained in:
parent
da0f7c0a51
commit
9646e38c3b
27
format.cc
27
format.cc
@ -754,22 +754,21 @@ template <typename Char>
|
||||
inline const Arg
|
||||
&fmt::BasicFormatter<Char>::parse_arg_index(const Char *&s) {
|
||||
const Arg *arg = 0;
|
||||
const char *error = 0;
|
||||
if (*s < '0' || *s > '9') {
|
||||
arg = &next_arg();
|
||||
arg = &next_arg(error);
|
||||
} else {
|
||||
if (next_arg_index_ > 0)
|
||||
error_ = "cannot switch from automatic to manual argument indexing";
|
||||
error = "cannot switch from automatic to manual argument indexing";
|
||||
next_arg_index_ = -1;
|
||||
unsigned arg_index = parse_nonnegative_int(s, error_);
|
||||
unsigned arg_index = parse_nonnegative_int(s, error);
|
||||
if (arg_index < args_.size())
|
||||
arg = &args_[arg_index];
|
||||
else if (!error_)
|
||||
error_ = "argument index is out of range in format";
|
||||
}
|
||||
if (error_) {
|
||||
throw FormatError(
|
||||
*s != '}' && *s != ':' ? "invalid format string" : error_);
|
||||
else if (!error)
|
||||
error = "argument index is out of range in format";
|
||||
}
|
||||
if (error)
|
||||
throw FormatError(*s != '}' && *s != ':' ? "invalid format string" : error);
|
||||
return *arg;
|
||||
}
|
||||
|
||||
@ -788,17 +787,15 @@ void fmt::BasicFormatter<Char>::check_sign(
|
||||
++s;
|
||||
}
|
||||
|
||||
const Arg &fmt::internal::FormatterBase::next_arg() {
|
||||
const Arg &fmt::internal::FormatterBase::next_arg(const char *&error) {
|
||||
if (next_arg_index_ < 0) {
|
||||
if (!error_)
|
||||
error_ = "cannot switch from manual to automatic argument indexing";
|
||||
error = "cannot switch from manual to automatic argument indexing";
|
||||
return DUMMY_ARG;
|
||||
}
|
||||
unsigned arg_index = next_arg_index_++;
|
||||
if (arg_index < args_.size())
|
||||
return args_[arg_index];
|
||||
if (!error_)
|
||||
error_ = "argument index is out of range in format";
|
||||
error = "argument index is out of range in format";
|
||||
return DUMMY_ARG;
|
||||
}
|
||||
|
||||
@ -816,7 +813,7 @@ const Arg &fmt::internal::FormatterBase::handle_arg_index(unsigned arg_index) {
|
||||
error_ = "argument index is out of range in format";
|
||||
return DUMMY_ARG;
|
||||
}
|
||||
return next_arg();
|
||||
return next_arg(error_);
|
||||
}
|
||||
|
||||
template <typename Char>
|
||||
|
6
format.h
6
format.h
@ -845,11 +845,11 @@ class FormatterBase {
|
||||
protected:
|
||||
ArgList args_;
|
||||
int next_arg_index_;
|
||||
const char *error_;
|
||||
const char *error_; // TODO: remove
|
||||
|
||||
FormatterBase() : error_(0) {}
|
||||
|
||||
const Arg &next_arg();
|
||||
const Arg &next_arg(const char *&error);
|
||||
|
||||
const Arg &handle_arg_index(unsigned arg_index);
|
||||
|
||||
@ -858,8 +858,6 @@ protected:
|
||||
if (start != end)
|
||||
w << BasicStringRef<Char>(start, end - start);
|
||||
}
|
||||
|
||||
// TODO
|
||||
};
|
||||
|
||||
// A printf formatter.
|
||||
|
Loading…
Reference in New Issue
Block a user