FreeCalypso > hg > sms-coding-utils
comparison libcoding/utf8_decode.c @ 0:2d0082216916
libcoding: beginning with a subset of uptools version
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 05 Aug 2023 00:46:23 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:2d0082216916 |
---|---|
1 /* | |
2 * This library module implements a function that converts text input | |
3 * from UTF-8 to ISO 8859-1, rejecting any input Unicode characters | |
4 * that aren't in the 8859-1 range. The conversion in done in place. | |
5 */ | |
6 | |
7 #include <sys/types.h> | |
8 | |
9 utf8_to_latin1(buf) | |
10 u_char *buf; | |
11 { | |
12 u_char *ip = buf, *op = buf; | |
13 int c, c2; | |
14 | |
15 while (c = *ip++) { | |
16 if (c < 0x80) { | |
17 *op++ = c; | |
18 continue; | |
19 } | |
20 if (c != 0xC2 && c != 0xC3) | |
21 return(-1); | |
22 c2 = *ip++; | |
23 if (c2 < 0x80 || c2 > 0xBF) | |
24 return(-1); | |
25 *op++ = ((c & 3) << 6) | (c2 & 0x3F); | |
26 } | |
27 *op = '\0'; | |
28 return(0); | |
29 } |