aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/utility.hxx
diff options
context:
space:
mode:
Diffstat (limited to 'libbuild2/utility.hxx')
-rw-r--r--libbuild2/utility.hxx61
1 files changed, 53 insertions, 8 deletions
diff --git a/libbuild2/utility.hxx b/libbuild2/utility.hxx
index b534f41..f4fd7bc 100644
--- a/libbuild2/utility.hxx
+++ b/libbuild2/utility.hxx
@@ -877,17 +877,29 @@ namespace build2
//
template <typename I, typename F>
void
- append_option_values (cstrings&,
- const char* opt,
- I begin, I end,
- F&& get = [] (const string& s) {return s.c_str ();});
+ append_option_values (
+ cstrings&,
+ const char* opt,
+ I begin, I end,
+ F&& get = [] (const string& s) {return s.c_str ();});
template <typename I, typename F>
void
- append_option_values (sha256&,
- const char* opt,
- I begin, I end,
- F&& get = [] (const string& s) {return s;});
+ append_option_values (
+ sha256&,
+ const char* opt,
+ I begin, I end,
+ F&& get = [] (const string& s) -> const string& {return s;});
+
+ // As above but in a combined form (e.g., -L/usr/local/lib).
+ //
+ template <typename I, typename F>
+ void
+ append_combined_option_values (
+ strings&,
+ const char* opt,
+ I begin, I end,
+ F&& get = [] (const string& s) -> const string& {return s;});
// As above but append a single option (used for append/hash uniformity).
//
@@ -1102,6 +1114,39 @@ namespace build2
//
optional<uint64_t>
parse_number (const string&, uint64_t max = UINT64_MAX);
+
+
+ // Write a string to a stream, single or double-quoting it unconditionally.
+ //
+ // If no quote characters are present in the string, then it is single-
+ // quoted. Otherwise, it is double quoted and the `\"` characters (backslach
+ // and double quote) inside the string are escaped.
+ //
+ LIBBUILD2_SYMEXPORT void
+ to_stream_quoted (ostream&, const char*);
+
+ inline void
+ to_stream_quoted (ostream& o, const string& s)
+ {
+ to_stream_quoted (o, s.c_str ());
+ }
+
+ // As above but only quote the string if it contains any of the specified
+ // special characters (which should include backslash as well as single and
+ // double quotes) or is empty (unless empty is false).
+ //
+ LIBBUILD2_SYMEXPORT void
+ to_stream_quoted (ostream&, const string&,
+ const char* special, bool empty = true);
+
+ // Write a vector of strings to a stream separating elements with a space
+ // and quoting each element if it is empty or contains any of the specified
+ // special characters (which should include space and backslash as well as
+ // single and double quotes; this is also the default which is suitable for
+ // displaying command line options, etc).
+ //
+ LIBBUILD2_SYMEXPORT void
+ to_stream_quoted (ostream&, const strings&, const char* special = " \\\"'");
}
#include <libbuild2/utility.ixx>