Luna/luna/src/OwnedStringView.cpp

36 lines
657 B
C++
Raw Normal View History

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