Add str move constructor/assignment
Some checks failed
CodeQL / Analyze (push) Waiting to run
Build branch / build-all (push) Failing after 13s

This commit is contained in:
smallmodel 2025-02-01 15:46:18 +01:00
parent 9c811c2318
commit cfb343d262
No known key found for this signature in database
GPG key ID: 9F2D623CEDF08512
2 changed files with 25 additions and 6 deletions

View file

@ -631,7 +631,7 @@ void TestStringClass(void)
str b; // b.len == 0, b.data == "\0"
str c("test"); // c.len == 4, c.data == "test\0"
str d(c); // d.len == 4, d.data == "test\0"
str e(nullptr);
str e(nullptr);
// e.len == 0, e.data == "\0" ASSERT!
size_t i; // i == ?

View file

@ -1,6 +1,6 @@
/*
===========================================================================
Copyright (C) 2015 the OpenMoHAA team
Copyright (C) 2025 the OpenMoHAA team
This file is part of OpenMoHAA source code.
@ -96,6 +96,9 @@ public:
str(const long long num);
str(const unsigned long long num);
str(str&& string);
str& operator=(str&& string);
size_t length(void) const;
const char *c_str(void) const;
@ -387,6 +390,24 @@ inline const char *str::c_str(void) const
}
}
inline str::str(str&& string)
: m_data(string.m_data)
{
string.m_data = NULL;
}
inline str& str::operator=(str&& string)
{
if (m_data) {
m_data->DelRef();
}
m_data = string.m_data;
string.m_data = NULL;
return *this;
}
inline void str::append(const char *text)
{
size_t len;
@ -626,8 +647,7 @@ inline int str::cmpn(const str& text, size_t n) const
inline void str::tolower(void)
{
if (m_data)
{
if (m_data) {
EnsureDataWritable();
str::tolower(m_data->data);
@ -636,8 +656,7 @@ inline void str::tolower(void)
inline void str::toupper(void)
{
if (m_data)
{
if (m_data) {
EnsureDataWritable();
str::toupper(m_data->data);