aboutsummaryrefslogtreecommitdiff
path: root/include/StringView.hpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-04-23 09:53:31 +0200
committerdec05eba <dec05eba@protonmail.com>2018-04-23 09:55:12 +0200
commitddff0f1b7ea84f6a1321b8eb8a4d47317873d955 (patch)
tree28565c3a3d336559fcf149e1552ae237cc3d855d /include/StringView.hpp
parent1e0e68f9cda51c881b32a54d9eece71c1428f7ac (diff)
Add word wrap for message board & TODO
TODO: Message board is now redrawn every frame. Text should be modified to render on static & dynamic texture -> text & static images on static texture, gif & video on dynamic texture
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>;
}