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

ByteBuffer: Add slice_view(). Works like slice() but makes a wrapper only.

So we already have ByteBuffer::wrap() which is like a StringView for random
data. This might not be the best abstraction actually, but this will be
immediately useful so let's add it.
This commit is contained in:
Andreas Kling 2019-07-27 15:26:51 +02:00
parent c7a4c8f93b
commit 6f397e23f1

View file

@ -155,6 +155,17 @@ public:
m_impl->trim(size);
}
ByteBuffer slice_view(int offset, int size) const
{
if (is_null())
return {};
if (offset >= this->size())
return {};
if (offset + size >= this->size())
size = this->size() - offset;
return wrap(offset_pointer(offset), size);
}
ByteBuffer slice(int offset, int size) const
{
if (is_null())