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()
|
|
|
|
{
|
2022-12-16 19:37:57 +00:00
|
|
|
if (m_string) raw_free(m_string);
|
2022-12-16 17:17:15 +00:00
|
|
|
}
|
|
|
|
|
2022-12-16 18:48:22 +00:00
|
|
|
Result<OwnedStringView> OwnedStringView::clone() const
|
2022-12-16 17:17:15 +00:00
|
|
|
{
|
2022-12-16 19:37:57 +00:00
|
|
|
char* const c_str = strdup(m_string);
|
2022-12-16 17:17:15 +00:00
|
|
|
|
2022-12-16 19:37:57 +00:00
|
|
|
if (!c_str) return err(ENOMEM);
|
2022-12-16 17:17:15 +00:00
|
|
|
|
2022-12-16 19:37:57 +00:00
|
|
|
return OwnedStringView{c_str};
|
2022-12-16 17:17:15 +00:00
|
|
|
}
|