Don't use error_ in parse_arg_index.

This commit is contained in:
Victor Zverovich 2014-08-27 09:13:42 -07:00
parent da0f7c0a51
commit 9646e38c3b
2 changed files with 14 additions and 19 deletions

View File

@ -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>

View File

@ -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.