FreeCalypso > hg > freecalypso-tools
comparison uptools/libcoding/utf8_decode.c @ 354:ec0d6d58e043
uptools/libcoding: UTF-8 input conversion to 8859-1 implemented
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Mon, 05 Feb 2018 19:01:27 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 353:3bcc56883b17 | 354:ec0d6d58e043 |
|---|---|
| 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 } |
