-
Notifications
You must be signed in to change notification settings - Fork 0
/
unicode.c
64 lines (55 loc) · 1.9 KB
/
unicode.c
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
#include "unicode.h"
size_t ciapos_grapheme_len(ciapos_codepoint *grapheme) {
size_t len = 0;
while (*(grapheme++)) len++;
return len;
}
int ciapos_is_whitespace(ciapos_codepoint *grapheme) {
// TODO this is only implemented over ASCII graphemes
switch (*grapheme) {
case ' ': case '\t': case '\n': case '\r':
return 1;
}
return 0;
}
int ciapos_is_newline(ciapos_codepoint *grapheme) {
// TODO this is only implemented over ASCII graphemes
size_t len = ciapos_grapheme_len(grapheme);
if (len == 2 && grapheme[0] == '\r' && grapheme[1] == '\n') return 1;
if (len == 1 && (*grapheme == '\r' || *grapheme == '\n')) return 1;
return 0;
}
int ciapos_is_opening_bracket(ciapos_codepoint *grapheme) {
// TODO this is only implemented over ASCII graphemes
switch (*grapheme) {
case '(': case '[': case '{':
return 1;
}
return 0;
}
int ciapos_is_closing_bracket(ciapos_codepoint *grapheme) {
// TODO this is only implemented over ASCII graphemes
switch (*grapheme) {
case ')': case ']': case '}':
return 1;
}
return 0;
}
int ciapos_are_matching_brackets(ciapos_codepoint *open, ciapos_codepoint *close) {
// TODO this is only implemented of ASCII graphemes
if (*open == '(' && *close == ')') return 1;
if (*open == '[' && *close == ']') return 1;
if (*open == '{' && *close == '}') return 1;
return 0;
}
int ciapos_is_opening_quote(ciapos_codepoint *grapheme) { return *grapheme == '"'; }
int ciapos_is_closing_quote(ciapos_codepoint *grapheme) { return *grapheme == '"'; }
int ciapos_are_matching_quotes(ciapos_codepoint *open, ciapos_codepoint *close) {
return (*open == *close) && *open == '"';
}
int ciapos_is_numeric(ciapos_codepoint *grapheme) {
return *grapheme >= '0' && *grapheme <= '9';
}
int ciapos_is_sign(ciapos_codepoint *grapheme) {
return *grapheme == '-' || *grapheme == '+';
}