1 | #include <stdint.h> |
2 | |
3 | #include "cmark_ctype.h" |
4 | |
5 | /** 1 = space, 2 = punct, 3 = digit, 4 = alpha, 0 = other |
6 | */ |
7 | static const uint8_t cmark_ctype_class[256] = { |
8 | /* 0 1 2 3 4 5 6 7 8 9 a b c d e f */ |
9 | /* 0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, |
10 | /* 1 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
11 | /* 2 */ 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
12 | /* 3 */ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, |
13 | /* 4 */ 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, |
14 | /* 5 */ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 2, 2, 2, 2, |
15 | /* 6 */ 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, |
16 | /* 7 */ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 2, 2, 2, 0, |
17 | /* 8 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
18 | /* 9 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
19 | /* a */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
20 | /* b */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
21 | /* c */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
22 | /* d */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
23 | /* e */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
24 | /* f */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; |
25 | |
26 | /** |
27 | * Returns 1 if c is a "whitespace" character as defined by the spec. |
28 | */ |
29 | int cmark_isspace(char c) { return cmark_ctype_class[(uint8_t)c] == 1; } |
30 | |
31 | /** |
32 | * Returns 1 if c is an ascii punctuation character. |
33 | */ |
34 | int cmark_ispunct(char c) { return cmark_ctype_class[(uint8_t)c] == 2; } |
35 | |
36 | int cmark_isalnum(char c) { |
37 | uint8_t result; |
38 | result = cmark_ctype_class[(uint8_t)c]; |
39 | return (result == 3 || result == 4); |
40 | } |
41 | |
42 | int cmark_isdigit(char c) { return cmark_ctype_class[(uint8_t)c] == 3; } |
43 | |
44 | int cmark_isalpha(char c) { return cmark_ctype_class[(uint8_t)c] == 4; } |
45 | |