mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2025-03-06 14:27:44 +00:00
Common/String: Support constructing from string_view
This commit is contained in:
parent
84b0522abc
commit
aa383d0bda
src/common
|
@ -166,6 +166,11 @@ String::String(String&& moveString)
|
||||||
Assign(moveString);
|
Assign(moveString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String::String(const std::string_view& sv)
|
||||||
|
{
|
||||||
|
AppendString(sv.data(), static_cast<u32>(sv.size()));
|
||||||
|
}
|
||||||
|
|
||||||
String::~String()
|
String::~String()
|
||||||
{
|
{
|
||||||
StringDataRelease(m_pStringData);
|
StringDataRelease(m_pStringData);
|
||||||
|
|
|
@ -54,6 +54,9 @@ public:
|
||||||
// Construct a string from a data object, does not increment the reference count on the string data, use carefully.
|
// 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) {}
|
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.
|
// Destructor. Child classes may not have any destructors, as this is not virtual.
|
||||||
~String();
|
~String();
|
||||||
|
|
||||||
|
@ -307,6 +310,12 @@ public:
|
||||||
Assign(copyString.GetCharArray());
|
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
|
// Override the fromstring method
|
||||||
static StackString FromFormat(const char* FormatString, ...)
|
static StackString FromFormat(const char* FormatString, ...)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue