mirror of
https://github.com/fmtlib/fmt.git
synced 2025-07-30 10:47:35 +02:00
Don't use error_ in parse_arg_index.
This commit is contained in:
27
format.cc
27
format.cc
@ -754,22 +754,21 @@ template <typename Char>
|
|||||||
inline const Arg
|
inline const Arg
|
||||||
&fmt::BasicFormatter<Char>::parse_arg_index(const Char *&s) {
|
&fmt::BasicFormatter<Char>::parse_arg_index(const Char *&s) {
|
||||||
const Arg *arg = 0;
|
const Arg *arg = 0;
|
||||||
|
const char *error = 0;
|
||||||
if (*s < '0' || *s > '9') {
|
if (*s < '0' || *s > '9') {
|
||||||
arg = &next_arg();
|
arg = &next_arg(error);
|
||||||
} else {
|
} else {
|
||||||
if (next_arg_index_ > 0)
|
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;
|
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())
|
if (arg_index < args_.size())
|
||||||
arg = &args_[arg_index];
|
arg = &args_[arg_index];
|
||||||
else if (!error_)
|
else if (!error)
|
||||||
error_ = "argument index is out of range in format";
|
error = "argument index is out of range in format";
|
||||||
}
|
|
||||||
if (error_) {
|
|
||||||
throw FormatError(
|
|
||||||
*s != '}' && *s != ':' ? "invalid format string" : error_);
|
|
||||||
}
|
}
|
||||||
|
if (error)
|
||||||
|
throw FormatError(*s != '}' && *s != ':' ? "invalid format string" : error);
|
||||||
return *arg;
|
return *arg;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -788,17 +787,15 @@ void fmt::BasicFormatter<Char>::check_sign(
|
|||||||
++s;
|
++s;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Arg &fmt::internal::FormatterBase::next_arg() {
|
const Arg &fmt::internal::FormatterBase::next_arg(const char *&error) {
|
||||||
if (next_arg_index_ < 0) {
|
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;
|
return DUMMY_ARG;
|
||||||
}
|
}
|
||||||
unsigned arg_index = next_arg_index_++;
|
unsigned arg_index = next_arg_index_++;
|
||||||
if (arg_index < args_.size())
|
if (arg_index < args_.size())
|
||||||
return args_[arg_index];
|
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;
|
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";
|
error_ = "argument index is out of range in format";
|
||||||
return DUMMY_ARG;
|
return DUMMY_ARG;
|
||||||
}
|
}
|
||||||
return next_arg();
|
return next_arg(error_);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Char>
|
template <typename Char>
|
||||||
|
6
format.h
6
format.h
@ -845,11 +845,11 @@ class FormatterBase {
|
|||||||
protected:
|
protected:
|
||||||
ArgList args_;
|
ArgList args_;
|
||||||
int next_arg_index_;
|
int next_arg_index_;
|
||||||
const char *error_;
|
const char *error_; // TODO: remove
|
||||||
|
|
||||||
FormatterBase() : error_(0) {}
|
FormatterBase() : error_(0) {}
|
||||||
|
|
||||||
const Arg &next_arg();
|
const Arg &next_arg(const char *&error);
|
||||||
|
|
||||||
const Arg &handle_arg_index(unsigned arg_index);
|
const Arg &handle_arg_index(unsigned arg_index);
|
||||||
|
|
||||||
@ -858,8 +858,6 @@ protected:
|
|||||||
if (start != end)
|
if (start != end)
|
||||||
w << BasicStringRef<Char>(start, end - start);
|
w << BasicStringRef<Char>(start, end - start);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// A printf formatter.
|
// A printf formatter.
|
||||||
|
Reference in New Issue
Block a user