libluna: Leave String in a valid state when moved

This commit is contained in:
apio 2023-04-28 21:16:11 +02:00
parent ae7c841fff
commit 8adfb6fdb9
Signed by: apio
GPG Key ID: B8A7D06E42258954
2 changed files with 9 additions and 2 deletions

View File

@ -91,5 +91,7 @@ class String
usize m_length { 0 };
void empty();
static Result<String> vformat(StringView fmt, va_list ap);
};

View File

@ -5,6 +5,11 @@
#include <luna/Vector.h>
String::String()
{
empty();
}
void String::empty()
{
m_inline = true;
m_length = 0;
@ -20,7 +25,7 @@ String::String(String&& other)
if (m_inline) memcpy(m_inline_storage, other.m_inline_storage, sizeof(m_inline_storage));
other.m_string = nullptr;
other.empty();
}
String& String::operator=(String&& other)
@ -36,7 +41,7 @@ String& String::operator=(String&& other)
if (m_inline) memcpy(m_inline_storage, other.m_inline_storage, sizeof(m_inline_storage));
other.m_string = nullptr;
other.empty();
return *this;
}