summaryrefslogtreecommitdiff
path: root/rufl_character_set_test.c
blob: 45fbcaff7a4817bbbdeb276b4e7cebac4fca2c52 (plain)
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
/*
 * This file is part of RUfl
 * Licensed under the MIT License,
 *                http://www.opensource.org/licenses/mit-license
 * Copyright 2005 James Bursa <james@semichrome.net>
 */

#include "rufl_internal.h"


/**
 * Test if a character set contains a character.
 *
 * \param  charset  character set
 * \param  c        character code
 * \return  true if present, false if absent
 */

bool rufl_character_set_test(struct rufl_character_set *charset,
		unsigned int c)
{
	unsigned int block = c >> 8;
	unsigned int byte = (c >> 3) & 31;
	unsigned int bit = c & 7;

	if (256 <= block)
		return false;

	if (charset->index[block] == BLOCK_EMPTY)
		return false;
	else if (charset->index[block] == BLOCK_FULL)
		return true;
	else {
		unsigned char z = charset->block[charset->index[block]][byte];
		return z & (1 << bit);
	}
}