From 9646e38c3bd41e0fbc60881f95259ded7b79f6e5 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Wed, 27 Aug 2014 09:13:42 -0700 Subject: [PATCH] Don't use error_ in parse_arg_index. --- format.cc | 27 ++++++++++++--------------- format.h | 6 ++---- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/format.cc b/format.cc index ceadbce8..f31c70bb 100644 --- a/format.cc +++ b/format.cc @@ -754,22 +754,21 @@ template inline const Arg &fmt::BasicFormatter::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::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 diff --git a/format.h b/format.h index a2cc1277..f4716675 100644 --- a/format.h +++ b/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(start, end - start); } - - // TODO }; // A printf formatter.