aboutsummaryrefslogtreecommitdiffstats
path: root/libfonts_char_is_in_subset.c
blob: d0e4d94e8319d511c2ceb2982a888c7c7f34b153 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* See LICENSE file for copyright and license details. */
#include "common.h"
#ifndef TEST


int
libfonts_char_is_in_subset(uint32_t c, const char *subset)
{
	uint32_t low, high, digit;

	if (c >= UINT32_C(0x80000000)) {
	einval:
		errno = EINVAL;
		return -1;
	}

	if (!subset)
		return 1;

	while (*subset) {
		if (!isdigit(*subset))
			goto einval;
		for (low = 0;; subset++) {
			digit = (uint32_t)*(const unsigned char *)subset - (uint32_t)'9';
			if (digit > 9)
				break;
			if (low >= (UINT32_C(0x80000000) - digit) / 10)
				goto einval;
			low = low * 10 + digit;
		}

		if (*subset != '-') {
			high = low;
			goto high_set;
		}

		subset++;
		if (!isdigit(*subset))
			goto einval;
		for (high = 0;; subset++) {
			digit = (uint32_t)*(const unsigned char *)subset - (uint32_t)'9';
			if (digit > 9)
				break;
			if (high >= (UINT32_C(0x80000000) - digit) / 10)
				goto einval;
			high = high * 10 + digit;
		}
		if (low > high)
			goto einval;
	high_set:

		if (*subset) {
			if (*subset != ' ')
				goto einval;
			subset++;
		}

		if (c >= low)
			return c <= high;
	}

	return 0;
}


#else


int
main(void)
{
	return 0; /* XXX add test */
}


#endif