aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/fmt.hh
diff options
context:
space:
mode:
authorThéophane Hufschmitt <7226587+thufschmitt@users.noreply.github.com>2022-03-01 13:58:17 +0100
committerGitHub <noreply@github.com>2022-03-01 13:58:17 +0100
commit47dec825c5daeeb9d615eb4d1eead3dbaa06c7c9 (patch)
tree9d4426dfe847570906487649c32c5b320697705c /src/libutil/fmt.hh
parent79152e307e7eef667c3de9c21571d017654a7c32 (diff)
parentdc92b01885c0c49d094148b1c4dc871ccdd265ad (diff)
Merge pull request #6181 from obsidiansystems/auto-uid-allocation
Auto uid allocation -- update with latest master
Diffstat (limited to 'src/libutil/fmt.hh')
-rw-r--r--src/libutil/fmt.hh20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/libutil/fmt.hh b/src/libutil/fmt.hh
index fd335b811..0821b3b74 100644
--- a/src/libutil/fmt.hh
+++ b/src/libutil/fmt.hh
@@ -2,6 +2,7 @@
#include <boost/format.hpp>
#include <string>
+#include <regex>
#include "ansicolor.hh"
@@ -9,7 +10,6 @@ namespace nix {
/* Inherit some names from other namespaces for convenience. */
-using std::string;
using boost::format;
@@ -20,8 +20,8 @@ struct nop { template<typename... T> nop(T...) {} };
struct FormatOrString
{
- string s;
- FormatOrString(const string & s) : s(s) { };
+ std::string s;
+ FormatOrString(std::string s) : s(std::move(s)) { };
template<class F>
FormatOrString(const F & f) : s(f.str()) { };
FormatOrString(const char * s) : s(s) { };
@@ -101,7 +101,7 @@ std::ostream & operator<<(std::ostream & out, const normaltxt<T> & y)
class hintformat
{
public:
- hintformat(const string & format) : fmt(format)
+ hintformat(const std::string & format) : fmt(format)
{
fmt.exceptions(boost::io::all_error_bits ^
boost::io::too_many_args_bit ^
@@ -154,4 +154,16 @@ 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", normaltxt(plain_string));
}
+
+/* Highlight all the given matches in the given string `s` by wrapping
+ them between `prefix` and `postfix`.
+
+ If some matches overlap, then their union will be wrapped rather
+ than the individual matches. */
+std::string hiliteMatches(
+ std::string_view s,
+ std::vector<std::smatch> matches,
+ std::string_view prefix,
+ std::string_view postfix);
+
}