2022-12-16 17:17:15 +00:00
|
|
|
#include <luna/Alloc.h>
|
|
|
|
#include <luna/OwnedStringView.h>
|
|
|
|
#include <luna/String.h>
|
|
|
|
|
|
|
|
OwnedStringView::OwnedStringView()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
OwnedStringView::OwnedStringView(OwnedStringView&& other)
|
|
|
|
{
|
|
|
|
m_string = other.m_string;
|
|
|
|
m_length = other.m_length;
|
|
|
|
|
|
|
|
other.m_string = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
OwnedStringView::OwnedStringView(char* c_str)
|
|
|
|
{
|
|
|
|
m_string = c_str;
|
|
|
|
|
|
|
|
if (m_string) { m_length = strlen(m_string); }
|
|
|
|
}
|
|
|
|
|
|
|
|
OwnedStringView::~OwnedStringView()
|
|
|
|
{
|
|
|
|
if (m_string) destroy_array(m_string);
|
|
|
|
}
|
|
|
|
|
2022-12-16 18:48:22 +00:00
|
|
|
Result<OwnedStringView> OwnedStringView::clone() const
|
2022-12-16 17:17:15 +00:00
|
|
|
{
|
|
|
|
char* buf = TRY(make_array<char>(m_length + 1));
|
|
|
|
|
|
|
|
memcpy(buf, m_string, m_length + 1);
|
|
|
|
|
|
|
|
return OwnedStringView{buf};
|
|
|
|
}
|