aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/script/script.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2024-07-28 16:23:13 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2024-07-28 16:23:13 +0200
commitab4c1b8a8b67fd9ffc89c804efa260584530897d (patch)
tree050bd00ec20c7668ac249cab4a9b777bc577f8d5 /libbuild2/script/script.cxx
parentff07b9a24212fd8cb92504f51b650afd52d7d408 (diff)
Factor out and generalize/extend to_stream_quoted(string)
Diffstat (limited to 'libbuild2/script/script.cxx')
-rw-r--r--libbuild2/script/script.cxx45
1 files changed, 2 insertions, 43 deletions
diff --git a/libbuild2/script/script.cxx b/libbuild2/script/script.cxx
index b53fc23..ee2c9aa 100644
--- a/libbuild2/script/script.cxx
+++ b/libbuild2/script/script.cxx
@@ -237,56 +237,15 @@ namespace build2
}
}
- // Quote a string unconditionally, assuming it contains some special
- // characters.
- //
- // If the quote character is present in the string then it is double
- // quoted rather than single quoted. In this case the following characters
- // are escaped:
- //
- // \"
- //
- static void
- to_stream_quoted (ostream& o, const char* s)
- {
- if (strchr (s, '\'') != nullptr)
- {
- o << '"';
-
- for (; *s != '\0'; ++s)
- {
- // Escape characters special inside double quotes.
- //
- if (strchr ("\\\"", *s) != nullptr)
- o << '\\';
-
- o << *s;
- }
-
- o << '"';
- }
- else
- o << '\'' << s << '\'';
- }
-
- static inline void
- to_stream_quoted (ostream& o, const string& s)
- {
- to_stream_quoted (o, s.c_str ());
- }
-
// Quote if empty or contains spaces or any of the command line special
// characters.
//
- static void
+ static inline void
to_stream_q (ostream& o, const string& s)
{
// NOTE: update dump(line) if adding any new special character.
//
- if (s.empty () || s.find_first_of (" |&<>=\\\"'") != string::npos)
- to_stream_quoted (o, s);
- else
- o << s;
+ to_stream_quoted (o, s, " |&<>=\\\"'");
}
void