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