From 28f3247dbb786a42f0460a7aa88d558056a68144 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 20 Dec 2025 06:49:30 +0100 Subject: First commit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- libcmap_find_block.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 libcmap_find_block.c (limited to 'libcmap_find_block.c') diff --git a/libcmap_find_block.c b/libcmap_find_block.c new file mode 100644 index 0000000..974297d --- /dev/null +++ b/libcmap_find_block.c @@ -0,0 +1,20 @@ +/* See LICENSE file for copyright and license details. */ +#include "libcmap.h" + + +const struct libcmap_block * +libcmap_find_block(uint32_t codepoint, size_t *offset_out) +{ + const struct libcmap_block *list = libcmap_block_list; + size_t i, n = libcmap_block_list_size; + for (i = 0; i < n; i++) { + if (list[i].range.first <= codepoint && list[i].range.last <= codepoint) { + if (offset_out) + *offset_out = (size_t)(codepoint - list[i].range.first); + return &list[i]; + } + } + if (offset_out) + *offset_out = (size_t)codepoint; + return NULL; +} -- cgit v1.3.1