-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathemoticons.c
75 lines (69 loc) · 1.87 KB
/
emoticons.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
65
66
67
68
69
70
71
72
73
74
75
#include <stdio.h>
#include <stdlib.h>
typedef struct {
char* name;
int start;
int end;
} range_t;
range_t ranges[] = {
{"Emoticons", 0x1F600, 0x1F64F},
{"Miscellaneous Symbols and Pictographs", 0x1F300, 0x1F5FF},
{"Supplemental Symbols and Pictographs", 0x1F900, 0x1F9FF},
{"Transport and Map Symbols", 0x1F680, 0x1F6FF},
{"Diversity Modifiers", 0x1F3FB, 0x1F3FF},
{"Dingbats", 0x2700, 0x27BF},
{"Miscellaneous", 0x2600, 0x26FF},
};
// U+0000 .. U+007F 1 byte 0xxx xxxx
// U+0080 .. U+07FF 2 bytes 110x xxxx 10xx xxxx
// U+0800 .. U+FFFF 3 bytes 1110 xxxx 10xx xxxx 10xx xxxx
// U+10000 .. U+10FFFF 4 bytes 1111 0xxx 10xx xxxx 10xx xxxx 10xx xxxx
int utf8out(char* buf, int ch) {
if(ch <= 0x7F) {
buf[0] = ch;
buf[1] = 0;
return 1;
} else if(ch <= 0x7FF) {
buf[0] = (ch >> 6) | 0xC0;
buf[1] = (ch & 0x3F) | 0x80;
buf[2] = 0;
return 2;
} else if(ch <= 0xFFFF) {
buf[0] = (ch >> 12) | 0xE0;
buf[1] = ((ch >> 6) & 0x3F) | 0x80;
buf[2] = (ch & 0x3F) | 0x80;
buf[3] = 0;
return 3;
} else if(ch <= 0x10FFFF) {
buf[0] = (ch >> 18) | 0xF0;
buf[1] = ((ch >> 12) & 0x3F) | 0x80;
buf[2] = ((ch >> 6) & 0x3F) | 0x80;
buf[3] = (ch & 0x3F) | 0x80;
buf[4] = 0;
return 4;
}
return 0;
}
int main(int argc, char *argv[]) {
char buf[] = {0,0,0,0,0};
for(int i = 0; i < sizeof(ranges) / sizeof(range_t); i++) {
range_t range = ranges[i];
printf("## %s\n\n", range.name);
for(int emoticon = range.start; emoticon <= range.end; emoticon++) {
int s = utf8out(buf, emoticon);
printf("`");
for(int i = 0; i < s; i++) {
printf("%02x", buf[i] & 0xff);
if(i != s - 1) {
printf(" ");
}
}
printf("` ");
if(s == 0 || fwrite(buf, 1, s, stdout) != s) {
exit(1);
}
printf("\n\n");
}
}
return 0;
}