Common/String: Support constructing from string_view

This commit is contained in:
Connor McLaughlin 2020-09-13 00:05:17 +10:00
parent 84b0522abc
commit aa383d0bda
2 changed files with 14 additions and 0 deletions

View file

@ -166,6 +166,11 @@ String::String(String&& moveString)
Assign(moveString);
}
String::String(const std::string_view& sv)
{
AppendString(sv.data(), static_cast<u32>(sv.size()));
}
String::~String()
{
StringDataRelease(m_pStringData);

View file

@ -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<u32>(sv.size()));
}
// Override the fromstring method
static StackString FromFormat(const char* FormatString, ...)
{