45 lines
755 B
C
45 lines
755 B
C
|
#pragma once
|
||
|
#include <luna/Result.h>
|
||
|
|
||
|
class String
|
||
|
{
|
||
|
public:
|
||
|
String(char* c_str);
|
||
|
String(char* c_str, usize length);
|
||
|
|
||
|
String();
|
||
|
|
||
|
String(String&&);
|
||
|
String(const String&) = delete;
|
||
|
|
||
|
~String();
|
||
|
|
||
|
Result<String> clone() const;
|
||
|
|
||
|
Result<String> substring(usize begin, usize size) const;
|
||
|
|
||
|
static Result<String> from_string_literal(const char* str);
|
||
|
|
||
|
const char* chars() const
|
||
|
{
|
||
|
return m_inline ? m_inline_storage : m_string;
|
||
|
}
|
||
|
|
||
|
usize length() const
|
||
|
{
|
||
|
return m_length;
|
||
|
}
|
||
|
|
||
|
const char& operator[](usize) const;
|
||
|
|
||
|
private:
|
||
|
union {
|
||
|
char* m_string { nullptr };
|
||
|
char m_inline_storage[sizeof(char*)];
|
||
|
};
|
||
|
|
||
|
bool m_inline { true };
|
||
|
|
||
|
usize m_length { 0 };
|
||
|
};
|