55 lines
843 B
C++
55 lines
843 B
C++
#pragma once
|
|
#include <luna/Result.h>
|
|
|
|
class String;
|
|
|
|
class StringView
|
|
{
|
|
typedef const char* Iterator;
|
|
|
|
public:
|
|
StringView(const char* c_str);
|
|
StringView(const char* c_str, usize length);
|
|
|
|
StringView();
|
|
|
|
StringView(const StringView&);
|
|
|
|
Result<String> to_string();
|
|
|
|
const char* chars() const
|
|
{
|
|
return m_string;
|
|
}
|
|
|
|
usize length() const
|
|
{
|
|
return m_length;
|
|
}
|
|
|
|
bool is_empty() const
|
|
{
|
|
return m_length == 0;
|
|
}
|
|
|
|
const char& operator[](usize) const;
|
|
|
|
bool operator==(const char* other) const;
|
|
bool operator==(StringView other) const;
|
|
|
|
Iterator begin() const
|
|
{
|
|
return m_string;
|
|
}
|
|
|
|
Iterator end() const
|
|
{
|
|
return m_string + m_length;
|
|
}
|
|
|
|
private:
|
|
const char* m_string { nullptr };
|
|
|
|
usize m_length { 0 };
|
|
};
|