2022-12-16 17:17:15 +00:00
|
|
|
#pragma once
|
2022-12-16 19:27:44 +00:00
|
|
|
#include <luna/Result.h>
|
2022-12-16 17:17:15 +00:00
|
|
|
|
|
|
|
class OwnedStringView
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
OwnedStringView(char* c_str);
|
2023-01-22 10:27:54 +00:00
|
|
|
OwnedStringView(char* c_str, usize length);
|
2022-12-16 17:17:15 +00:00
|
|
|
OwnedStringView();
|
|
|
|
OwnedStringView(OwnedStringView&&);
|
|
|
|
OwnedStringView(const OwnedStringView&) = delete;
|
|
|
|
~OwnedStringView();
|
|
|
|
|
2022-12-16 18:48:22 +00:00
|
|
|
Result<OwnedStringView> clone() const;
|
2022-12-16 17:17:15 +00:00
|
|
|
|
2023-01-22 10:27:54 +00:00
|
|
|
Result<OwnedStringView> substring(usize begin, usize size) const;
|
|
|
|
|
2022-12-17 10:36:16 +00:00
|
|
|
static Result<OwnedStringView> from_string_literal(const char* str);
|
|
|
|
|
2022-12-16 18:48:22 +00:00
|
|
|
const char* chars() const
|
2022-12-16 17:17:15 +00:00
|
|
|
{
|
|
|
|
return m_string;
|
|
|
|
}
|
|
|
|
|
2022-12-16 18:48:22 +00:00
|
|
|
usize length() const
|
2022-12-16 17:17:15 +00:00
|
|
|
{
|
|
|
|
return m_length;
|
|
|
|
}
|
|
|
|
|
2022-12-16 19:48:58 +00:00
|
|
|
const char& operator[](usize) const;
|
2022-12-16 19:37:57 +00:00
|
|
|
|
2022-12-16 17:17:15 +00:00
|
|
|
private:
|
2022-12-21 19:22:44 +00:00
|
|
|
char* m_string { nullptr };
|
|
|
|
usize m_length { 0 };
|
2023-01-02 12:07:29 +00:00
|
|
|
};
|