scc

A fork of https://git.simple-cc.org/scc/ for Qute

git clone https://git.8pit.net/scc.git

 1#include <wchar.h>
 2
 3#include "../libc.h"
 4
 5struct range {
 6	unsigned long begin, end;
 7	int valid;
 8	int nbytes;
 9};
10
11int
12_validutf8(wchar_t wc, int *nbytes)
13{
14	static struct range ranges[] = {
15		{0,         0x80,       1, 1},
16		{0x80,      0x800,      1, 2},
17		{0x800,     0xD800,     1, 3},
18		{0xD800,    0xDD00,     0, 3},
19		{0xDD00,    0x10000,    1, 3},
20		{0x10000,   0x110000,   1, 4},
21		{0x110000,  -1ul,       0, 0},
22	};
23	struct range *bp;
24
25	for (bp = ranges; bp->begin > wc || bp->end <= wc; ++bp)
26		;
27	*nbytes = bp->nbytes;
28
29	return bp->valid;
30}