summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <mk@cm4all.com>2021-03-17 18:39:18 +0100
committerMax Kellermann <max@musicpd.org>2021-04-06 14:06:16 +0200
commit52f46b94e93fff5e6c981ce13cb914b4743383a4 (patch)
tree0109575fd12d9e133041b8fb3a7ade4611b976c9 /src
parente07e0bc9c1aa55ea8364efa14ad29df36ee4737c (diff)
util/AllocatedString: add concatenating constructor
Diffstat (limited to 'src')
-rw-r--r--src/util/AllocatedString.hxx19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/util/AllocatedString.hxx b/src/util/AllocatedString.hxx
index 27c047514..330335c3e 100644
--- a/src/util/AllocatedString.hxx
+++ b/src/util/AllocatedString.hxx
@@ -71,6 +71,18 @@ public:
explicit BasicAllocatedString(const_pointer src)
:value(Duplicate(src)) {}
+ /**
+ * Concatenate several strings.
+ */
+ BasicAllocatedString(std::initializer_list<string_view> src)
+ :value(new value_type[TotalSize(src) + 1])
+ {
+ auto *p = value;
+ for (const auto i : src)
+ p = std::copy(i.begin(), i.end(), p);
+ *p = SENTINEL;
+ }
+
BasicAllocatedString(const BasicAllocatedString &src) noexcept
:BasicAllocatedString(Duplicate(src.value)) {}
@@ -158,6 +170,13 @@ private:
? Duplicate(string_view(src))
: nullptr;
}
+
+ static constexpr std::size_t TotalSize(std::initializer_list<string_view> src) noexcept {
+ std::size_t size = 0;
+ for (std::string_view i : src)
+ size += i.size();
+ return size;
+ }
};
class AllocatedString : public BasicAllocatedString<char> {