mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-17 16:28:06 +03: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:
parent
c7a4c8f93b
commit
6f397e23f1
Notes:
sideshowbarker
2024-07-19 13:01:46 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/6f397e23f1e
@ -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())
|
||||
|
Loading…
Reference in New Issue
Block a user