Commit 52f46b94 authored by Max Kellermann's avatar Max Kellermann Committed by Max Kellermann

util/AllocatedString: add concatenating constructor

parent e07e0bc9
......@@ -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> {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment