1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 11:47:35 +00:00

AK: Add span() / bytes() methods to container types.

This commit is contained in:
asynts 2020-07-27 14:15:37 +02:00 committed by Andreas Kling
parent c42450786c
commit a922abd9d7
4 changed files with 24 additions and 5 deletions

View file

@ -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(); }