FreeCalypso > hg > freecalypso-tools
comparison uptools/libcoding/decode_helpers.c @ 328:978571e23318
uptools started with libcoding
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 03 Feb 2018 20:07:05 +0000 |
parents | |
children | 1c599681fd60 |
comparison
equal
deleted
inserted
replaced
327:973d885a68a0 | 328:978571e23318 |
---|---|
1 /* | |
2 * This library module implements the is_decoded_char_ok() and emit_utf8_char() | |
3 * functions used by gsm7_to_ascii_or_ext() and ucs2_to_ascii_or_ext(). | |
4 */ | |
5 | |
6 #include <sys/types.h> | |
7 | |
8 is_decoded_char_ok(uni, ascii_ext) | |
9 unsigned uni; | |
10 { | |
11 unsigned upper_limit; | |
12 | |
13 /* weed out control chars first */ | |
14 if (uni < 0x20) | |
15 return(0); | |
16 if (uni >= 0x7F && uni <= 0x9F) | |
17 return(0); | |
18 /* see what range our output encoding allows */ | |
19 switch (ascii_ext) { | |
20 case 0: | |
21 upper_limit = 0x7F; | |
22 break; | |
23 case 1: | |
24 upper_limit = 0xFF; | |
25 break; | |
26 case 2: | |
27 upper_limit = 0xFFFF; | |
28 break; | |
29 default: | |
30 upper_limit = 0; | |
31 } | |
32 if (uni <= upper_limit) | |
33 return(1); | |
34 else | |
35 return(0); | |
36 } | |
37 | |
38 emit_utf8_char(uni, outp) | |
39 unsigned uni; | |
40 u_char *outp; | |
41 { | |
42 if (uni < 0x80) { | |
43 *outp = uni; | |
44 return(1); | |
45 } | |
46 if (uni < 0x800) { | |
47 outp[0] = 0xC0 | (uni >> 6); | |
48 outp[1] = 0x80 | (uni & 0x3F); | |
49 return(2); | |
50 } | |
51 outp[0] = 0xE0 | (uni >> 12); | |
52 outp[1] = 0x80 | ((uni >> 6) & 0x3F); | |
53 outp[2] = 0x80 | (uni & 0x3F); | |
54 return(3); | |
55 } |