2003-08-23 14:59:31 +02:00
|
|
|
/*****************************************************************************
|
2006-11-12 17:19:58 +01:00
|
|
|
* charset.h: Unicode UTF-8 wrappers function
|
2003-08-23 14:59:31 +02:00
|
|
|
*****************************************************************************
|
2005-08-04 21:09:15 +02:00
|
|
|
* Copyright (C) 2003-2005 the VideoLAN team
|
2010-02-07 14:18:02 +01:00
|
|
|
* Copyright © 2005-2010 Rémi Denis-Courmont
|
2005-03-02 17:47:31 +01:00
|
|
|
* $Id$
|
2003-08-23 14:59:31 +02:00
|
|
|
*
|
2006-11-12 17:19:58 +01:00
|
|
|
* Author: Rémi Denis-Courmont <rem # videolan,org>
|
2003-08-23 14:59:31 +02:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
2004-01-25 19:17:08 +01:00
|
|
|
*
|
2003-08-23 14:59:31 +02:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2006-01-13 00:10:04 +01:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
|
2003-08-23 14:59:31 +02:00
|
|
|
*****************************************************************************/
|
|
|
|
|
2008-08-11 18:13:10 +02:00
|
|
|
#ifndef VLC_CHARSET_H
|
|
|
|
#define VLC_CHARSET_H 1
|
2005-10-10 09:56:33 +02:00
|
|
|
|
2008-08-11 17:31:57 +02:00
|
|
|
/**
|
|
|
|
* \file
|
|
|
|
* This files handles locale conversions in vlc
|
|
|
|
*/
|
|
|
|
|
2006-08-31 16:55:20 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2005-08-03 21:01:44 +02:00
|
|
|
VLC_EXPORT( void, LocaleFree, ( const char * ) );
|
2008-09-06 10:30:44 +02:00
|
|
|
VLC_EXPORT( char *, FromLocale, ( const char * ) LIBVLC_USED );
|
|
|
|
VLC_EXPORT( char *, FromLocaleDup, ( const char * ) LIBVLC_USED );
|
|
|
|
VLC_EXPORT( char *, ToLocale, ( const char * ) LIBVLC_USED );
|
|
|
|
VLC_EXPORT( char *, ToLocaleDup, ( const char * ) LIBVLC_USED );
|
2006-02-12 20:57:48 +01:00
|
|
|
|
2006-08-31 16:55:20 +02:00
|
|
|
VLC_EXPORT( int, utf8_vfprintf, ( FILE *stream, const char *fmt, va_list ap ) );
|
2008-05-26 18:58:44 +02:00
|
|
|
VLC_EXPORT( int, utf8_fprintf, ( FILE *, const char *, ... ) LIBVLC_FORMAT( 2, 3 ) );
|
2006-02-21 13:14:27 +01:00
|
|
|
|
2005-08-03 21:01:44 +02:00
|
|
|
VLC_EXPORT( char *, EnsureUTF8, ( char * ) );
|
2008-09-06 10:30:44 +02:00
|
|
|
VLC_EXPORT( const char *, IsUTF8, ( const char * ) LIBVLC_USED );
|
2006-03-22 13:26:11 +01:00
|
|
|
|
2006-11-11 12:37:21 +01:00
|
|
|
#ifdef WIN32
|
2008-09-06 10:30:44 +02:00
|
|
|
LIBVLC_USED
|
2006-11-11 13:48:49 +01:00
|
|
|
static inline char *FromWide (const wchar_t *wide)
|
|
|
|
{
|
|
|
|
size_t len = WideCharToMultiByte (CP_UTF8, 0, wide, -1, NULL, 0, NULL, NULL);
|
|
|
|
if (len == 0)
|
|
|
|
return NULL;
|
|
|
|
|
2006-11-11 18:10:59 +01:00
|
|
|
char *out = (char *)malloc (len);
|
2006-11-11 13:48:49 +01:00
|
|
|
|
2008-08-24 20:15:56 +02:00
|
|
|
if (out)
|
|
|
|
WideCharToMultiByte (CP_UTF8, 0, wide, -1, out, len, NULL, NULL);
|
2006-11-11 13:48:49 +01:00
|
|
|
return out;
|
|
|
|
}
|
2006-11-11 12:37:21 +01:00
|
|
|
#endif
|
2006-03-21 17:42:34 +01:00
|
|
|
|
2008-12-16 18:58:10 +01:00
|
|
|
/**
|
|
|
|
* Converts a nul-terminated string from ISO-8859-1 to UTF-8.
|
|
|
|
*/
|
|
|
|
static inline char *FromLatin1 (const char *latin)
|
|
|
|
{
|
2008-12-16 19:12:00 +01:00
|
|
|
char *str = (char *)malloc (2 * strlen (latin) + 1), *utf8 = str;
|
2008-12-16 18:58:10 +01:00
|
|
|
unsigned char c;
|
|
|
|
|
|
|
|
if (str == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
while ((c = *(latin++)) != '\0')
|
|
|
|
{
|
|
|
|
if (c >= 0x80)
|
|
|
|
{
|
|
|
|
*(utf8++) = 0xC0 | (c >> 6);
|
|
|
|
*(utf8++) = 0x80 | (c & 0x3F);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*(utf8++) = c;
|
|
|
|
}
|
|
|
|
*(utf8++) = '\0';
|
|
|
|
|
2008-12-16 19:12:00 +01:00
|
|
|
utf8 = (char *)realloc (str, utf8 - str);
|
2008-12-16 18:58:10 +01:00
|
|
|
return utf8 ? utf8 : str;
|
|
|
|
}
|
|
|
|
|
2010-01-25 23:05:53 +01:00
|
|
|
VLC_EXPORT( char *, FromCharset, ( const char *charset, const void *data, size_t data_size ) LIBVLC_USED );
|
|
|
|
|
2008-09-06 10:30:44 +02:00
|
|
|
VLC_EXPORT( double, us_strtod, ( const char *, char ** ) LIBVLC_USED );
|
2009-04-14 11:48:33 +02:00
|
|
|
VLC_EXPORT( float, us_strtof, ( const char *, char ** ) LIBVLC_USED );
|
2008-09-06 10:30:44 +02:00
|
|
|
VLC_EXPORT( double, us_atof, ( const char * ) LIBVLC_USED );
|
2008-12-02 01:06:00 +01:00
|
|
|
VLC_EXPORT( int, us_asprintf, ( char **, const char *, ... ) LIBVLC_USED );
|
2004-02-22 00:15:52 +01:00
|
|
|
|
2005-10-10 09:56:33 +02:00
|
|
|
#endif
|