util/string.h: Byte_range_ptr::with_skipped_bytes

The new method provides a safe way to narrow the byte range to a
given offset.

Issue #5351
This commit is contained in:
Norman Feske 2024-09-25 16:27:15 +02:00 committed by Christian Helmuth
parent 5c20de212a
commit bf064874db

View File

@ -84,6 +84,15 @@ struct Genode::Byte_range_ptr : Noncopyable
Byte_range_ptr(char *start, size_t num_bytes)
: start(start), num_bytes(num_bytes) { }
void with_skipped_bytes(size_t const n, auto const &fn)
{
if (num_bytes <= n)
return;
Byte_range_ptr const remainder { start + n, num_bytes - n };
fn(remainder);
}
};