Fix typo in http interface
[vlc.git] / include / vlc_charset.h
blob4fb08609ead12178fdb30d316dc6eb63eba9ed1b
1 /*****************************************************************************
2 * charset.h: Unicode UTF-8 wrappers function
3 *****************************************************************************
4 * Copyright (C) 2003-2005 the VideoLAN team
5 * Copyright © 2005-2010 Rémi Denis-Courmont
6 * $Id$
8 * Author: Rémi Denis-Courmont <rem # videolan,org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 #ifndef VLC_CHARSET_H
26 #define VLC_CHARSET_H 1
28 /**
29 * \file
30 * This files handles locale conversions in vlc
33 /* iconv wrappers (defined in src/extras/libc.c) */
34 typedef void *vlc_iconv_t;
35 VLC_API vlc_iconv_t vlc_iconv_open( const char *, const char * ) VLC_USED;
36 VLC_API size_t vlc_iconv( vlc_iconv_t, const char **, size_t *, char **, size_t * ) VLC_USED;
37 VLC_API int vlc_iconv_close( vlc_iconv_t );
39 #include <stdarg.h>
41 VLC_API void LocaleFree( const char * );
42 VLC_API char * FromLocale( const char * ) VLC_USED;
43 VLC_API char * FromLocaleDup( const char * ) VLC_USED;
44 VLC_API char * ToLocale( const char * ) VLC_USED;
45 VLC_API char * ToLocaleDup( const char * ) VLC_USED;
47 VLC_API int utf8_vfprintf( FILE *stream, const char *fmt, va_list ap );
48 VLC_API int utf8_fprintf( FILE *, const char *, ... ) VLC_FORMAT( 2, 3 );
49 VLC_API char * vlc_strcasestr(const char *, const char *) VLC_USED;
51 VLC_API char * EnsureUTF8( char * );
52 VLC_API const char * IsUTF8( const char * ) VLC_USED;
54 #ifdef WIN32
55 VLC_USED
56 static inline char *FromWide (const wchar_t *wide)
58 size_t len = WideCharToMultiByte (CP_UTF8, 0, wide, -1, NULL, 0, NULL, NULL);
59 if (len == 0)
60 return NULL;
62 char *out = (char *)malloc (len);
64 if (likely(out))
65 WideCharToMultiByte (CP_UTF8, 0, wide, -1, out, len, NULL, NULL);
66 return out;
69 VLC_USED
70 static inline wchar_t *ToWide (const char *utf8)
72 int len = MultiByteToWideChar (CP_UTF8, 0, utf8, -1, NULL, 0);
73 if (len == 0)
74 return NULL;
76 wchar_t *out = (wchar_t *)malloc (len * sizeof (wchar_t));
78 if (likely(out))
79 MultiByteToWideChar (CP_UTF8, 0, utf8, -1, out, len);
80 return out;
82 #endif
84 /**
85 * Converts a nul-terminated string from ISO-8859-1 to UTF-8.
87 static inline char *FromLatin1 (const char *latin)
89 char *str = (char *)malloc (2 * strlen (latin) + 1), *utf8 = str;
90 unsigned char c;
92 if (str == NULL)
93 return NULL;
95 while ((c = *(latin++)) != '\0')
97 if (c >= 0x80)
99 *(utf8++) = 0xC0 | (c >> 6);
100 *(utf8++) = 0x80 | (c & 0x3F);
102 else
103 *(utf8++) = c;
105 *(utf8++) = '\0';
107 utf8 = (char *)realloc (str, utf8 - str);
108 return utf8 ? utf8 : str;
111 VLC_API char * FromCharset( const char *charset, const void *data, size_t data_size ) VLC_USED;
112 VLC_API void * ToCharset( const char *charset, const char *in, size_t *outsize ) VLC_USED;
114 VLC_API double us_strtod( const char *, char ** ) VLC_USED;
115 VLC_API float us_strtof( const char *, char ** ) VLC_USED;
116 VLC_API double us_atof( const char * ) VLC_USED;
117 VLC_API int us_vasprintf( char **, const char *, va_list );
118 VLC_API int us_asprintf( char **, const char *, ... ) VLC_USED;
120 #endif