aboutsummaryrefslogtreecommitdiffstats
path: root/lib-common.h
blob: 2ab89a0aef3300fabda53504e84904780c6649a9 (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/* See LICENSE file for copyright and license details. */
#include "libcharconv.h"
#include <ctype.h>
#include <string.h>
#include <strings.h>


size_t libcharconv_decode_utf8_(const char *s, size_t slen, uint_least32_t *cp);

extern const unsigned char libcharconv_yijing_hexagrams_[];


#define CYCLE_2(A, B)\
	{UINT32_C(A), UINT32_C(B)},\
	{UINT32_C(B), UINT32_C(A)}

#define CYCLE_4(A, B, C, D)\
	{UINT32_C(A), UINT32_C(B)},\
	{UINT32_C(B), UINT32_C(C)},\
	{UINT32_C(C), UINT32_C(D)},\
	{UINT32_C(D), UINT32_C(A)}

#define CYCLE_8(A, B, C, D, E, F, G, H)\
	{UINT32_C(A), UINT32_C(B)},\
	{UINT32_C(B), UINT32_C(C)},\
	{UINT32_C(C), UINT32_C(D)},\
	{UINT32_C(D), UINT32_C(E)},\
	{UINT32_C(E), UINT32_C(F)},\
	{UINT32_C(F), UINT32_C(G)},\
	{UINT32_C(G), UINT32_C(H)},\
	{UINT32_C(H), UINT32_C(A)}


#define PLAIN_RANGE(FIRST, LAST, FIRST_CP)\
	do {\
		if ((FIRST) <= *s && *s <= (LAST)) { \
			c = (uint_least32_t)(UINT32_C(FIRST_CP) + (unsigned)(*s - (FIRST)));\
			goto conv;\
		}\
	} while (0)

#define PLAIN_CASE_RANGE(FIRST, LAST, FIRST_CP)\
	do {\
		if (tolower(FIRST) <= tolower(*s) && tolower(*s) <= tolower(LAST)) { \
			c = (uint_least32_t)(UINT32_C(FIRST_CP) + (unsigned)(tolower(*s) - tolower(FIRST)));\
			goto conv;\
		}\
	} while (0)

#define PLAIN_SINGLE(C, CP)\
	do {\
		if (*s == (C)) {\
			c = (uint_least32_t)UINT32_C(CP);\
			goto conv;\
		}\
	} while (0)

#define PLAIN_CASE_SINGLE(C, CP)\
	do {\
		if (*s == tolower(C) || *s == toupper(C)) {\
			c = (uint_least32_t)UINT32_C(CP);\
			goto conv;\
		}\
	} while (0)

#define PLAIN_SELECT(CS, FIRST_CP)\
	do {\
		size_t i__;\
		for (i__ = 0u; (CS)[i__]; i__++) {\
			if (*s == (CS)[i__]) {\
				c = (uint_least32_t)(UINT32_C(FIRST_CP) + i__);\
				goto conv;\
			}\
		}\
	} while (0)

#define PLAIN_CASE_SELECT(CS, FIRST_CP)\
	do {\
		size_t i__;\
		for (i__ = 0u; (CS)[i__]; i__++) {\
			if (*s == tolower((CS)[i__]) || *s == toupper((CS)[i__])) {\
				c = (uint_least32_t)(UINT32_C(FIRST_CP) + i__); \
				goto conv;\
			}\
		}\
	} while (0)

#define PLAIN_RANGE_SWAP(LOW_FIRST, LOW_LAST, HIGH_FIRST, HIGH_LAST)\
	do {\
		if (UINT32_C(LOW_FIRST) <= c && c <= UINT32_C(LOW_LAST)) {\
			c += UINT32_C(HIGH_FIRST) - UINT32_C(LOW_FIRST);\
			goto conv;\
		} else if (UINT32_C(HIGH_FIRST) <= c && c <= UINT32_C(HIGH_LAST)) {\
			c -= UINT32_C(HIGH_FIRST) - UINT32_C(LOW_FIRST);\
			goto conv;\
		}\
	} while (0)