summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Kellermann <mk@cm4all.com>2021-01-14 13:34:43 +0100
committerMax Kellermann <max@musicpd.org>2021-03-04 18:04:17 +0100
commitbca5d79f88a63a79d964181cead4271ac76dc40f (patch)
treeadcd4ef0408c44eecfde019683f3ae8d5b28fec7
parent6e1c8edf095bb89aa50db4bb54e4507320f14e76 (diff)
util/AllocatedString: add const_pointer constructor
-rw-r--r--src/util/AllocatedString.hxx11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/util/AllocatedString.hxx b/src/util/AllocatedString.hxx
index 6d02aa25e..e977712fc 100644
--- a/src/util/AllocatedString.hxx
+++ b/src/util/AllocatedString.hxx
@@ -65,7 +65,10 @@ public:
BasicAllocatedString(std::nullptr_t n) noexcept
:value(n) {}
- explicit BasicAllocatedString(string_view src) noexcept
+ explicit BasicAllocatedString(string_view src)
+ :value(Duplicate(src)) {}
+
+ explicit BasicAllocatedString(const_pointer src)
:value(Duplicate(src)) {}
BasicAllocatedString(BasicAllocatedString &&src) noexcept
@@ -144,6 +147,12 @@ private:
*std::copy_n(src.data(), src.size(), p) = SENTINEL;
return p;
}
+
+ static pointer Duplicate(const_pointer src) {
+ return src != nullptr
+ ? Duplicate(std::string_view(src))
+ : nullptr;
+ }
};
class AllocatedString : public BasicAllocatedString<char> {