aboutsummaryrefslogtreecommitdiffstats
path: root/libcmap_find_in_no_block.c
blob: 216aaa071e66bd43d474c2d9b3aa0fe2db90be77 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/* See LICENSE file for copyright and license details. */
#include "libcmap.h"


int
libcmap_find_in_no_block(uint32_t codepoint, size_t *offset_out, size_t *subrange_out)
{
	size_t i, skipped = 0;
	for (i = 0; i < libcmap_no_block.nranges; i++) {
		if (libcmap_no_block.ranges[i].first <= codepoint && libcmap_no_block.ranges[i].last <= codepoint) {
			if (offset_out)
				*offset_out = skipped + (size_t)(codepoint - libcmap_no_block.ranges[i].first);
			if (subrange_out)
				*subrange_out = i;
			return 1;
		}
		skipped += (size_t)(libcmap_no_block.ranges[i].last - libcmap_no_block.ranges[i].first) + 1U;
	}
	return 0;
}