aboutsummaryrefslogtreecommitdiff
path: root/include/StringView.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'include/StringView.hpp')
-rw-r--r--include/StringView.hpp26
1 files changed, 15 insertions, 11 deletions
diff --git a/include/StringView.hpp b/include/StringView.hpp
index 3293358..4e9066b 100644
--- a/include/StringView.hpp
+++ b/include/StringView.hpp
@@ -6,36 +6,37 @@
namespace dchat
{
- class StringView
+ template <typename CharType>
+ class BasicStringView
{
public:
- StringView() : data(nullptr), size(0)
+ BasicStringView() : data(nullptr), size(0)
{
}
- StringView(const StringView &other) : data(other.data), size(other.size)
+ BasicStringView(const BasicStringView<CharType> &other) : data(other.data), size(other.size)
{
}
- StringView(const char *_data) : data(_data), size(strlen(_data))
+ BasicStringView(const CharType *_data) : data(_data), size(strlen(_data))
{
}
- StringView(const char *_data, usize _size) : data(_data), size(_size)
+ BasicStringView(const CharType *_data, usize _size) : data(_data), size(_size)
{
}
- StringView operator = (const StringView &other)
+ BasicStringView<CharType> operator = (const BasicStringView<CharType> &other)
{
- StringView result(other.data, other.size);
+ BasicStringView<CharType> result(other.data, other.size);
return result;
}
- StringView(StringView &&other)
+ BasicStringView( BasicStringView<CharType> &&other)
{
data = other.data;
size = other.size;
@@ -44,19 +45,22 @@ namespace dchat
other.size = 0;
}
- bool equals(const StringView &other) const
+ bool equals(const BasicStringView<CharType> &other) const
{
if(size != other.size) return false;
return memcmp(data, other.data, size) == 0;
}
- char operator [] (usize index) const
+ CharType operator [] (usize index) const
{
assert(index < size);
return data[index];
}
- const char *data;
+ const CharType *data;
usize size;
};
+
+ using StringView = BasicStringView<char>;
+ using StringViewUtf32 = BasicStringView<u32>;
}