mirror of
https://github.com/openmoh/openmohaa.git
synced 2025-04-28 21:57:57 +03:00
Add str move constructor/assignment
This commit is contained in:
parent
9c811c2318
commit
cfb343d262
2 changed files with 25 additions and 6 deletions
|
@ -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 == ?
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue