Join variables by their delimiter in quoted expansion

This switches quoted expansion like "$foo" to use foo's delimiter instead of
space. The delimiter is space for normal variables and colonf or path variables.
Expansions like "$PATH" will now expand using ':'.
This commit is contained in:
ridiculousfish
2018-09-30 19:34:01 -04:00
parent 3f3b3a7006
commit 5947aa0171
9 changed files with 41 additions and 13 deletions

View File

@@ -1898,7 +1898,18 @@ wcstring_list_t split_string(const wcstring &val, wchar_t sep) {
}
wcstring join_strings(const wcstring_list_t &vals, wchar_t sep) {
if (vals.empty()) return wcstring{};
// Reserve the size we will need.
// count-1 separators, plus the length of all strings.
size_t size = vals.size() - 1;
for (const wcstring &s : vals) {
size += s.size();
}
// Construct the string.
wcstring result;
result.reserve(size);
bool first = true;
for (const wcstring &s : vals) {
if (!first) {