From bf064874dbbc7c132021e2fe6444b5da9d4e013f Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Wed, 25 Sep 2024 16:27:15 +0200 Subject: [PATCH] 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 --- repos/base/include/util/string.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/repos/base/include/util/string.h b/repos/base/include/util/string.h index 0088a83e8f..af2a438d2b 100644 --- a/repos/base/include/util/string.h +++ b/repos/base/include/util/string.h @@ -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); + } };