util/AllocatedString: add concatenating constructor
This commit is contained in:
parent
e07e0bc9c1
commit
52f46b94e9
@ -71,6 +71,18 @@ public:
|
|||||||
explicit BasicAllocatedString(const_pointer src)
|
explicit BasicAllocatedString(const_pointer src)
|
||||||
:value(Duplicate(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(const BasicAllocatedString &src) noexcept
|
||||||
:BasicAllocatedString(Duplicate(src.value)) {}
|
:BasicAllocatedString(Duplicate(src.value)) {}
|
||||||
|
|
||||||
@ -158,6 +170,13 @@ private:
|
|||||||
? Duplicate(string_view(src))
|
? Duplicate(string_view(src))
|
||||||
: nullptr;
|
: 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> {
|
class AllocatedString : public BasicAllocatedString<char> {
|
||||||
|
Loading…
Reference in New Issue
Block a user