aboutsummaryrefslogtreecommitdiff
path: root/include/StringView.hpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-04-22 05:58:44 +0200
committerdec05eba <dec05eba@protonmail.com>2018-04-22 05:59:18 +0200
commit1e0e68f9cda51c881b32a54d9eece71c1428f7ac (patch)
treeb8faa1d971c245e3fcf046aa1d2daa1fa601e0f9 /include/StringView.hpp
parent424b02609fa34175a4e2aadb95e68b3c9c8dc93c (diff)
Add video and gif support
Gif streams from url. Todo: Add play controls to video
Diffstat (limited to 'include/StringView.hpp')
-rw-r--r--include/StringView.hpp62
1 files changed, 62 insertions, 0 deletions
diff --git a/include/StringView.hpp b/include/StringView.hpp
new file mode 100644
index 0000000..3293358
--- /dev/null
+++ b/include/StringView.hpp
@@ -0,0 +1,62 @@
+#pragma once
+
+#include "types.hpp"
+#include <cstring>
+#include <cassert>
+
+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;
+ };
+}