]> git.ipfire.org Git - thirdparty/squid.git/blob - lib/charset.c
Docs: Copyright updates for 2018 (#114)
[thirdparty/squid.git] / lib / charset.c
1 /*
2 * Copyright (C) 1996-2018 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9 #include "squid.h"
10 #include "charset.h"
11
12 /** Convert ISO-LATIN-1 to UTF-8 */
13 char *
14 latin1_to_utf8(char *out, size_t size, const char *in)
15 {
16 unsigned char *p = (unsigned char *)out;
17 for (; *in && size > 2; in++) {
18 unsigned char ch = (unsigned char)*in;
19 if (ch < 0x80) {
20 *p++ = ch;
21 size--;
22 } else {
23 *p++ = (ch >> 6) | 0xc0;
24 size--;
25 *p++ = (ch & 0x3f) | 0x80;
26 size--;
27 }
28 }
29 *p = '\0';
30 if (*in)
31 return NULL;
32 return out;
33 }
34