Expand string class
This commit is contained in:
@@ -48,7 +48,7 @@ namespace OpenVulkano
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
String& operator=(String&& other)
|
String& operator=(String&& other) noexcept
|
||||||
{
|
{
|
||||||
m_string = std::move(other.m_string);
|
m_string = std::move(other.m_string);
|
||||||
return *this;
|
return *this;
|
||||||
@@ -75,17 +75,22 @@ namespace OpenVulkano
|
|||||||
auto operator<=>(const String& other) const = default;
|
auto operator<=>(const String& other) const = default;
|
||||||
explicit operator bool() const { return !m_string.empty(); }
|
explicit operator bool() const { return !m_string.empty(); }
|
||||||
|
|
||||||
operator std::string() const { return m_string; }
|
operator const std::string&() const { return m_string; }
|
||||||
explicit operator std::string_view() const { return m_string; }
|
explicit operator std::string_view() const { return m_string; }
|
||||||
|
|
||||||
char& operator[](size_t index) noexcept { return m_string[index]; }
|
char& operator[](const size_t index) noexcept { return m_string[index]; }
|
||||||
const char& operator[](size_t index) const noexcept { return m_string[index]; }
|
const char& operator[](const size_t index) const noexcept { return m_string[index]; }
|
||||||
char& At(size_t index) { return m_string.at(index); }
|
char& At(const size_t index) { return m_string.at(index); }
|
||||||
const char& At(size_t index) const { return m_string.at(index); }
|
const char& At(const size_t index) const { return m_string.at(index); }
|
||||||
const char* CharString() const { return m_string.c_str(); }
|
const char* CharString() const { return m_string.c_str(); }
|
||||||
const char* Data() { return m_string.data(); }
|
const char* c_str() const { return m_string.c_str(); }
|
||||||
|
const char* Data() const { return m_string.data(); }
|
||||||
|
const char* data() const { return m_string.data(); }
|
||||||
|
char* Data() { return m_string.data(); }
|
||||||
|
char* data() { return m_string.data(); }
|
||||||
size_t Length() const { return m_string.length(); }
|
size_t Length() const { return m_string.length(); }
|
||||||
size_t Size() const { return m_string.size(); }
|
size_t Size() const { return m_string.size(); }
|
||||||
|
size_t size() const { return m_string.size(); }
|
||||||
bool Empty() const { return m_string.empty(); }
|
bool Empty() const { return m_string.empty(); }
|
||||||
size_t Capacity() const { return m_string.capacity(); }
|
size_t Capacity() const { return m_string.capacity(); }
|
||||||
size_t CharCount() const { return utf8::distance(m_string.begin(), m_string.end()); }
|
size_t CharCount() const { return utf8::distance(m_string.begin(), m_string.end()); }
|
||||||
@@ -95,6 +100,7 @@ namespace OpenVulkano
|
|||||||
void PopBack() { m_string.pop_back(); }
|
void PopBack() { m_string.pop_back(); }
|
||||||
void Clear() { m_string.clear(); }
|
void Clear() { m_string.clear(); }
|
||||||
void ShrinkToFit() { m_string.shrink_to_fit(); }
|
void ShrinkToFit() { m_string.shrink_to_fit(); }
|
||||||
|
String substr(size_t start, size_t elementCount) const { return m_string.substr(start, elementCount); }
|
||||||
String SubString(size_t start, size_t elementCount) const { return m_string.substr(start, elementCount); }
|
String SubString(size_t start, size_t elementCount) const { return m_string.substr(start, elementCount); }
|
||||||
bool StartsWith(const std::string_view& str) const { return m_string.find(str) == 0; }
|
bool StartsWith(const std::string_view& str) const { return m_string.find(str) == 0; }
|
||||||
bool EndsWith(const std::string_view& str) const { return m_string.rfind(str) == m_string.size() - str.size(); }
|
bool EndsWith(const std::string_view& str) const { return m_string.rfind(str) == m_string.size() - str.size(); }
|
||||||
@@ -219,24 +225,15 @@ namespace OpenVulkano
|
|||||||
m_string.size() - end - delimiter.size()) };
|
m_string.size() - end - delimiter.size()) };
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int64_t OctToInt(const std::string_view& string)
|
static constexpr int64_t OctToInt(const std::string_view& string)
|
||||||
{
|
{
|
||||||
int64_t result = 0;
|
int64_t result = 0;
|
||||||
for (int i = 0; i < static_cast<int>(string.length()); i++)
|
for (size_t i = 0; i < string.length(); i++)
|
||||||
{
|
{
|
||||||
char c = string[i];
|
char c = string[i];
|
||||||
if (c == 0)
|
if (c == 0) break;
|
||||||
{
|
if (c == ' ') continue;
|
||||||
break;
|
if (c < '0' || c > '7') return -1;
|
||||||
}
|
|
||||||
if (c == ' ')
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (c < '0' || c > '7')
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
result = result * 8 + c - '0';
|
result = result * 8 + c - '0';
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
@@ -244,19 +241,13 @@ namespace OpenVulkano
|
|||||||
|
|
||||||
int64_t OctToInt() const { return OctToInt(m_string); }
|
int64_t OctToInt() const { return OctToInt(m_string); }
|
||||||
|
|
||||||
static inline int64_t HexToInt(const std::string_view& string)
|
static constexpr int64_t HexToInt(const std::string_view& string)
|
||||||
{
|
{
|
||||||
int64_t result = 0;
|
int64_t result = 0;
|
||||||
for (char c: string)
|
for (char c: string)
|
||||||
{
|
{
|
||||||
if (c == 0)
|
if (c == 0) break;
|
||||||
{
|
if (c == ' ') continue;
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (c == ' ')
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (c >= '0' && c <= '9')
|
if (c >= '0' && c <= '9')
|
||||||
{
|
{
|
||||||
result = result * 16 + c - '0';
|
result = result * 16 + c - '0';
|
||||||
@@ -277,7 +268,7 @@ namespace OpenVulkano
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t HexToInt() { return HexToInt(m_string); }
|
int64_t HexToInt() const { return HexToInt(m_string); }
|
||||||
|
|
||||||
static constexpr bool IsUrl(const std::string_view& str)
|
static constexpr bool IsUrl(const std::string_view& str)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user