]> git.ipfire.org Git - thirdparty/squid.git/blame - lib/charset.c
SourceFormat Enforcement
[thirdparty/squid.git] / lib / charset.c
CommitLineData
f741d2f6 1/*
4ac4a490 2 * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
f741d2f6 3 *
0545caaa
AJ
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.
f741d2f6
HN
7 */
8
f7f3304a 9#include "squid.h"
25f98340 10#include "charset.h"
f741d2f6 11
8df44716 12/** Convert ISO-LATIN-1 to UTF-8 */
f741d2f6
HN
13char *
14latin1_to_utf8(char *out, size_t size, const char *in)
15{
8df44716
AJ
16 unsigned char *p = (unsigned char *)out;
17 for (; *in && size > 2; in++) {
26ac0430
AJ
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 }
f741d2f6 28 }
8df44716 29 *p = '\0';
f741d2f6 30 if (*in)
26ac0430 31 return NULL;
f741d2f6
HN
32 return out;
33}
f53969cc 34