diff options
| author | Mattias Andrée <m@maandree.se> | 2025-12-20 06:49:30 +0100 |
|---|---|---|
| committer | Mattias Andrée <m@maandree.se> | 2025-12-20 06:49:30 +0100 |
| commit | 28f3247dbb786a42f0460a7aa88d558056a68144 (patch) | |
| tree | 16be29e366f0dd9b5a8499e0edb72d8ec780ad8d /libcmap_find_script.c | |
| download | libcmap-28f3247dbb786a42f0460a7aa88d558056a68144.tar.gz libcmap-28f3247dbb786a42f0460a7aa88d558056a68144.tar.bz2 libcmap-28f3247dbb786a42f0460a7aa88d558056a68144.tar.xz | |
First commit
Signed-off-by: Mattias Andrée <m@maandree.se>
Diffstat (limited to '')
| -rw-r--r-- | libcmap_find_script.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/libcmap_find_script.c b/libcmap_find_script.c new file mode 100644 index 0000000..f8787f8 --- /dev/null +++ b/libcmap_find_script.c @@ -0,0 +1,29 @@ +/* See LICENSE file for copyright and license details. */ +#include "libcmap.h" + + +const struct libcmap_script * +libcmap_find_script(uint32_t codepoint, size_t *offset_out, size_t *subrange_out) +{ + const struct libcmap_script *list = libcmap_script_list; + size_t i, j, n = libcmap_script_list_size; + size_t skipped; + for (i = 0; i < n; i++) { + skipped = 0; + for (j = 0; j < list[i].nranges; j++) { + if (list[i].ranges[j].first <= codepoint && list[i].ranges[j].last <= codepoint) { + if (offset_out) + *offset_out = skipped + (size_t)(codepoint - list[i].ranges[j].first); + if (subrange_out) + *subrange_out = j; + return &list[i]; + } + skipped += (size_t)(list[i].ranges[j].last - list[i].ranges[j].first) + 1U; + } + } + if (offset_out) + *offset_out = (size_t)codepoint; + if (subrange_out) + *subrange_out = 0; + return NULL; +} |
