summaryrefslogtreecommitdiff
path: root/AK/StringView.h
diff options
context:
space:
mode:
authorasynts <asynts@gmail.com>2020-07-27 14:15:37 +0200
committerAndreas Kling <kling@serenityos.org>2020-07-27 19:58:09 +0200
commita922abd9d7ec36412750649cf2413ee8c46ca316 (patch)
tree3671dfb817991cc2980deb07fe08022dda7d05fc /AK/StringView.h
parentc42450786c0a6b731849b9e4b316e9ec10a29ead (diff)
downloadserenity-a922abd9d7ec36412750649cf2413ee8c46ca316.zip
AK: Add span() / bytes() methods to container types.
Diffstat (limited to 'AK/StringView.h')
-rw-r--r--AK/StringView.h5
1 files changed, 5 insertions, 0 deletions
diff --git a/AK/StringView.h b/AK/StringView.h
index 35c99e69f5..c0d65a511b 100644
--- a/AK/StringView.h
+++ b/AK/StringView.h
@@ -29,6 +29,7 @@
#include <AK/Assertions.h>
#include <AK/Checked.h>
#include <AK/Forward.h>
+#include <AK/Span.h>
#include <AK/StdLibExtras.h>
#include <AK/StringUtils.h>
@@ -63,8 +64,12 @@ public:
bool is_null() const { return !m_characters; }
bool is_empty() const { return m_length == 0; }
+
const char* characters_without_null_termination() const { return m_characters; }
size_t length() const { return m_length; }
+
+ ReadonlyBytes bytes() const { return { m_characters, m_length }; }
+
const char& operator[](size_t index) const { return m_characters[index]; }
ConstIterator begin() const { return characters_without_null_termination(); }