-
Notifications
You must be signed in to change notification settings - Fork 18
/
test.c
59 lines (45 loc) · 1.17 KB
/
test.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
/*
* Description:
* History: [email protected], 2013/11/22, create
*/
# undef _GNU_SOURCE
# define _GNU_SOURCE
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include <error.h>
# include <assert.h>
# include "utf8.h"
int main()
{
char *line = NULL;
size_t buf_size = 0;
while (getline(&line, &buf_size, stdin) != -1)
{
size_t len = strlen(line);
if (len && line[len - 1] == '\n')
line[--len] = 0;
printf("in len: %zu\n", len);
size_t max = len + 1;
ucs4_t *us = calloc(max, sizeof(ucs4_t));
int illegal = 0;
size_t n = u8decode(line, us, max, &illegal);
printf("unicode num: %zu, illegal: %d\n", n, illegal);
int i;
for (i = 0; i < n; ++i)
{
printf("%#010x", us[i]);
if (isuchiness(us[i]))
printf(" chiness");
printf("\n");
}
max = n * 6 + 1;
char *cs = calloc(max, 1);
n = u8encode(us, cs, max, &illegal);
printf("UTF-8 len: %zu, illegal: %d\n", n, illegal);
puts(cs);
free(us);
free(cs);
}
return 0;
}