Common/String: Add helpers for std::string, std::string_view

This commit is contained in:
Connor McLaughlin
2021-01-30 14:36:03 +10:00
parent d8ea9c2983
commit e614522de5
2 changed files with 75 additions and 0 deletions

View File

@ -4,6 +4,7 @@
#include <cstdarg>
#include <cstring>
#include <limits>
#include <string>
#include <string_view>
//
@ -63,6 +64,8 @@ public:
// manual assignment
void Assign(const String& copyString);
void Assign(const char* copyText);
void Assign(const std::string& copyString);
void Assign(const std::string_view& copyString);
void Assign(String&& moveString);
// assignment but ensures that we have our own copy.
@ -90,6 +93,8 @@ public:
void AppendString(const String& appendStr);
void AppendString(const char* appendText);
void AppendString(const char* appendString, u32 Count);
void AppendString(const std::string& appendString);
void AppendString(const std::string_view& appendString);
// append a substring of the specified string to this string
void AppendSubString(const String& appendStr, s32 Offset = 0, s32 Count = std::numeric_limits<s32>::max());
@ -106,6 +111,8 @@ public:
void PrependString(const String& appendStr);
void PrependString(const char* appendText);
void PrependString(const char* appendString, u32 Count);
void PrependString(const std::string& appendStr);
void PrependString(const std::string_view& appendStr);
// append a substring of the specified string to this string
void PrependSubString(const String& appendStr, s32 Offset = 0, s32 Count = std::numeric_limits<s32>::max());
@ -119,6 +126,8 @@ public:
void InsertString(s32 offset, const String& appendStr);
void InsertString(s32 offset, const char* appendStr);
void InsertString(s32 offset, const char* appendStr, u32 appendStrLength);
void InsertString(s32 offset, const std::string& appendStr);
void InsertString(s32 offset, const std::string_view& appendStr);
// set to formatted string
void Format(const char* FormatString, ...);
@ -243,6 +252,16 @@ public:
Assign(Text);
return *this;
}
String& operator=(const std::string& Text)
{
Assign(Text);
return *this;
}
String& operator=(const std::string_view& Text)
{
Assign(Text);
return *this;
}
// Move operator.
String& operator=(String&& moveString)
@ -348,6 +367,16 @@ public:
Assign(Text);
return *this;
}
StackString& operator=(const std::string& Text)
{
Assign(Text);
return *this;
}
StackString& operator=(const std::string_view& Text)
{
Assign(Text);
return *this;
}
private:
StringData m_sStringData;