Simplify format string checks

This commit is contained in:
Victor Zverovich
2019-02-10 18:00:19 -08:00
parent 4a9d676362
commit 9660ea1bff
5 changed files with 25 additions and 33 deletions
+9 -8
View File
@@ -187,7 +187,6 @@ class prepared_format {
public:
typedef FMT_CHAR(Format) char_type;
typedef format_part<char_type> format_part_t;
typedef internal::checked_args<Format, Args...> checked_args;
prepared_format(Format f)
: format_(std::move(f)), parts_provider_(to_string_view(format_)) {}
@@ -218,7 +217,7 @@ class prepared_format {
std::basic_string<char_type> format(const Args&... args) const {
basic_memory_buffer<char_type> buffer;
typedef back_insert_range<internal::basic_buffer<char_type>> range;
this->vformat_to(range(buffer), *checked_args(format_, args...));
this->vformat_to(range(buffer), make_args_checked(format_, args...));
return to_string(buffer);
}
@@ -229,7 +228,7 @@ class prepared_format {
const Args&... args) const {
internal::container_buffer<Container> buffer(internal::get_container(out));
typedef back_insert_range<internal::basic_buffer<char_type>> range;
this->vformat_to(range(buffer), *checked_args(format_, args...));
this->vformat_to(range(buffer), make_args_checked(format_, args...));
return out;
}
@@ -245,16 +244,18 @@ class prepared_format {
inline typename buffer_context<char_type>::type::iterator format_to(
basic_memory_buffer<char_type, SIZE>& buf, const Args&... args) const {
typedef back_insert_range<internal::basic_buffer<char_type>> range;
return this->vformat_to(range(buf), *checked_args(format_, args...));
return this->vformat_to(range(buf), make_args_checked(format_, args...));
}
private:
template <typename Range, typename Context>
typename Context::iterator vformat_to(Range out,
basic_format_args<Context> args) const {
typedef typename buffer_context<char_type>::type context;
template <typename Range>
typename context::iterator vformat_to(Range out,
basic_format_args<context> args) const {
const auto format_view = internal::to_string_view(format_);
basic_parse_context<char_type> parse_ctx(format_view);
Context ctx(out.begin(), args);
context ctx(out.begin(), args);
const auto& parts = parts_provider_.parts();
for (auto part_it = parts.begin(); part_it != parts.end(); ++part_it) {