diff --git a/src/common/string.cpp b/src/common/string.cpp index 6b57854af..ecde9ee40 100644 --- a/src/common/string.cpp +++ b/src/common/string.cpp @@ -166,6 +166,11 @@ String::String(String&& moveString) Assign(moveString); } +String::String(const std::string_view& sv) +{ + AppendString(sv.data(), static_cast(sv.size())); +} + String::~String() { StringDataRelease(m_pStringData); diff --git a/src/common/string.h b/src/common/string.h index a0c1c7b9d..90d3c5966 100644 --- a/src/common/string.h +++ b/src/common/string.h @@ -54,6 +54,9 @@ public: // Construct a string from a data object, does not increment the reference count on the string data, use carefully. explicit String(StringData* pStringData) : m_pStringData(pStringData) {} + // Creates string from string_view. + String(const std::string_view& sv); + // Destructor. Child classes may not have any destructors, as this is not virtual. ~String(); @@ -307,6 +310,12 @@ public: Assign(copyString.GetCharArray()); } + StackString(const std::string_view& sv) : String(&m_sStringData) + { + InitStackStringData(); + AppendString(sv.data(), static_cast(sv.size())); + } + // Override the fromstring method static StackString FromFormat(const char* FormatString, ...) {