aboutsummaryrefslogtreecommitdiff
path: root/include/StringView.hpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-05-04 20:50:49 +0200
committerdec05eba <dec05eba@protonmail.com>2018-05-04 20:50:52 +0200
commit640d8df5277af4ac4b545cc6d4cf2830509e61b9 (patch)
tree3fdf9d2f0c78ecc6b869b0657989dfacbb0e6d33 /include/StringView.hpp
parent70d01f1f5699e265f79985b61136a62f9fa18a49 (diff)
Add proper parsing of Text, add url
Diffstat (limited to 'include/StringView.hpp')
-rw-r--r--include/StringView.hpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/include/StringView.hpp b/include/StringView.hpp
index 45d0f5b..c4e7ce3 100644
--- a/include/StringView.hpp
+++ b/include/StringView.hpp
@@ -68,6 +68,24 @@ namespace dchat
return data[index];
}
+ // Returns -1 if substr not found.
+ // TODO: Make this more efficient
+ usize find(const BasicStringView<CharType> &substr, usize offset = 0) const
+ {
+ if(substr.size == 0)
+ return -1;
+
+ if(offset + substr.size > size)
+ return -1;
+
+ for(usize i = offset; i < size - (substr.size - 1); ++i)
+ {
+ if(memcmp(data + i, substr.data, substr.size) == 0)
+ return i;
+ }
+ return -1;
+ }
+
const CharType *data;
usize size;
};