From b193aca4ae339fb20184827e28523169d2d5370a Mon Sep 17 00:00:00 2001 From: Ben Burdette Date: Fri, 19 Jun 2020 15:29:19 -0600 Subject: escape percents --- src/libutil/fmt.hh | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/libutil/fmt.hh') 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 +#include #include #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; +} } -- cgit v1.2.3 From 397dbe114e78682a370832e31269147b9d6ac6fa Mon Sep 17 00:00:00 2001 From: Ben Burdette Date: Fri, 19 Jun 2020 15:57:19 -0600 Subject: remove formathelper --- src/libutil/fmt.hh | 1 - 1 file changed, 1 deletion(-) (limited to 'src/libutil/fmt.hh') diff --git a/src/libutil/fmt.hh b/src/libutil/fmt.hh index ccab1c512..789e500ef 100644 --- a/src/libutil/fmt.hh +++ b/src/libutil/fmt.hh @@ -144,7 +144,6 @@ 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; } } -- cgit v1.2.3 From 28b079067f4248c81b8946c459435c7a91dc2971 Mon Sep 17 00:00:00 2001 From: Ben Burdette Date: Mon, 22 Jun 2020 10:00:37 -0600 Subject: Update src/libutil/fmt.hh Co-authored-by: John Ericson --- src/libutil/fmt.hh | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'src/libutil/fmt.hh') diff --git a/src/libutil/fmt.hh b/src/libutil/fmt.hh index 789e500ef..dc7fe8056 100644 --- a/src/libutil/fmt.hh +++ b/src/libutil/fmt.hh @@ -139,11 +139,9 @@ inline hintformat hintfmt(const std::string & fs, const Args & ... args) return f; } -inline hintformat hintfmt(std::string fs) +inline hintformat hintfmt(std::string plain_string) { - // we won't be receiving any args in this case, so escape all percents. - boost::replace_all(fs, "%", "%%"); - hintformat f(fs); - return f; + // we won't be receiving any args in this case, so just print the original string + return hintfmt("%s", plain_string); } } -- cgit v1.2.3 From 9d1cb0c5e64db3e34896ac43de978f132860f894 Mon Sep 17 00:00:00 2001 From: Ben Burdette Date: Mon, 22 Jun 2020 11:32:20 -0600 Subject: with normaltxt, elide yellow color code instead of canceling it; use normaltxt on plain_string hintfmt --- src/libutil/fmt.hh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/libutil/fmt.hh') diff --git a/src/libutil/fmt.hh b/src/libutil/fmt.hh index dc7fe8056..a39de041f 100644 --- a/src/libutil/fmt.hh +++ b/src/libutil/fmt.hh @@ -120,6 +120,13 @@ public: return *this; } + template + hintformat& operator%(const normaltxt &value) + { + fmt % value.value; + return *this; + } + std::string str() const { return fmt.str(); @@ -142,6 +149,6 @@ inline hintformat hintfmt(const std::string & fs, const Args & ... args) inline hintformat hintfmt(std::string plain_string) { // we won't be receiving any args in this case, so just print the original string - return hintfmt("%s", plain_string); + return hintfmt("%s", normaltxt(plain_string)); } } -- cgit v1.2.3