diff options
author | Ben Burdette <bburdette@gmail.com> | 2020-06-19 15:29:19 -0600 |
---|---|---|
committer | Ben Burdette <bburdette@gmail.com> | 2020-06-19 15:29:19 -0600 |
commit | b193aca4ae339fb20184827e28523169d2d5370a (patch) | |
tree | 0d4eaaeed975877b76534963f0589170f925a07f /src | |
parent | db475f9e7e7a35d7d73d39f06633ce04ac1b67fc (diff) |
escape percents
Diffstat (limited to 'src')
-rw-r--r-- | src/libutil/fmt.hh | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/libutil/fmt.hh b/src/libutil/fmt.hh index 12ab9c407..ccab1c512 100644 --- a/src/libutil/fmt.hh +++ b/src/libutil/fmt.hh @@ -1,6 +1,7 @@ #pragma once #include <boost/format.hpp> +#include <boost/algorithm/string/replace.hpp> #include <string> #include "ansicolor.hh" @@ -103,7 +104,9 @@ class hintformat public: hintformat(const string &format) :fmt(format) { - fmt.exceptions(boost::io::all_error_bits ^ boost::io::too_many_args_bit); + fmt.exceptions(boost::io::all_error_bits ^ + boost::io::too_many_args_bit ^ + boost::io::too_few_args_bit); } hintformat(const hintformat &hf) @@ -136,4 +139,12 @@ inline hintformat hintfmt(const std::string & fs, const Args & ... args) return f; } +inline hintformat hintfmt(std::string fs) +{ + // we won't be receiving any args in this case, so escape all percents. + boost::replace_all(fs, "%", "%%"); + hintformat f(fs); + formatHelper(f); + return f; +} } |