diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2015-01-17 22:55:48 +0000 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2015-01-17 22:55:48 +0000 |
| commit | 7cdeb3d7f70790b70ff5a1ecafeaa8d4e6e69c76 (patch) | |
| tree | f1c612882b738a1156c644e4408d44e1a909d598 | |
| parent | 32319aca45265453baad756bf406e34a4568d169 (diff) | |
simplify echo code, avoid trailing spaces
| -rw-r--r-- | src/commands.cc | 4 | ||||
| -rw-r--r-- | src/string.hh | 4 |
2 files changed, 3 insertions, 5 deletions
diff --git a/src/commands.cc b/src/commands.cc index 8373bddd..23cf03e8 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -780,9 +780,7 @@ const CommandDesc echo_cmd = { CommandCompleter{}, [](const ParametersParser& parser, Context& context) { - String message; - for (auto& param : parser) - message += param + " "; + String message = join(parser, ' ', false); if (parser.has_option("debug")) write_debug(message); else diff --git a/src/string.hh b/src/string.hh index 54a8b900..62cbe5cc 100644 --- a/src/string.hh +++ b/src/string.hh @@ -242,14 +242,14 @@ String escape(StringView str, StringView characters, char escape); String unescape(StringView str, StringView characters, char escape); template<typename Container> -String join(const Container& container, char joiner) +String join(const Container& container, char joiner, bool esc_joiner = true) { String res; for (const auto& str : container) { if (not res.empty()) res += joiner; - res += escape(str, joiner, '\\'); + res += esc_joiner ? escape(str, joiner, '\\') : str; } return res; } |
