A managed String which uses RAII to free its contents. It's not a proper string though, since it's read-only. So it's a StringView... but an owned one. Can't be copied automatically, must be either moved or copied manually by calling clone() on it.
27 lines
446 B
C++
27 lines
446 B
C++
#pragma once
|
|
|
|
class OwnedStringView
|
|
{
|
|
public:
|
|
OwnedStringView(char* c_str);
|
|
OwnedStringView();
|
|
OwnedStringView(OwnedStringView&&);
|
|
OwnedStringView(const OwnedStringView&) = delete;
|
|
~OwnedStringView();
|
|
|
|
Result<OwnedStringView> clone();
|
|
|
|
const char* chars()
|
|
{
|
|
return m_string;
|
|
}
|
|
|
|
usize length()
|
|
{
|
|
return m_length;
|
|
}
|
|
|
|
private:
|
|
char* m_string{nullptr};
|
|
usize m_length{0};
|
|
}; |