#pragma once #include "types.hpp" #include #include namespace dchat { class StringView { public: StringView() : data(nullptr), size(0) { } StringView(const StringView &other) : data(other.data), size(other.size) { } StringView(const char *_data) : data(_data), size(strlen(_data)) { } StringView(const char *_data, usize _size) : data(_data), size(_size) { } StringView operator = (const StringView &other) { StringView result(other.data, other.size); return result; } StringView(StringView &&other) { data = other.data; size = other.size; other.data = nullptr; other.size = 0; } bool equals(const StringView &other) const { if(size != other.size) return false; return memcmp(data, other.data, size) == 0; } char operator [] (usize index) const { assert(index < size); return data[index]; } const char *data; usize size; }; }