vlc_charset.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * charset.h: Unicode UTF-8 wrappers function
00003  *****************************************************************************
00004  * Copyright (C) 2003-2005 the VideoLAN team
00005  * Copyright © 2005-2006 Rémi Denis-Courmont
00006  * $Id: ab6d5299a67ed9f06256accd10bc94ff6b1d4c77 $
00007  *
00008  * Author: Rémi Denis-Courmont <rem # videolan,org>
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
00023  *****************************************************************************/
00024 
00025 #ifndef VLC_CHARSET_H
00026 #define VLC_CHARSET_H 1
00027 
00028 /**
00029  * \file
00030  * This files handles locale conversions in vlc
00031  */
00032 
00033 #include <stdarg.h>
00034 #include <sys/types.h>
00035 #include <dirent.h>
00036 
00037 VLC_EXPORT( void, LocaleFree, ( const char * ) );
00038 VLC_EXPORT( char *, FromLocale, ( const char * ) LIBVLC_USED );
00039 VLC_EXPORT( char *, FromLocaleDup, ( const char * ) LIBVLC_USED );
00040 VLC_EXPORT( char *, ToLocale, ( const char * ) LIBVLC_USED );
00041 VLC_EXPORT( char *, ToLocaleDup, ( const char * ) LIBVLC_USED );
00042 
00043 /* TODO: move all of this to "vlc_fs.h" or something like that */
00044 VLC_EXPORT( int, utf8_open, ( const char *filename, int flags, ... ) LIBVLC_USED );
00045 VLC_EXPORT( FILE *, utf8_fopen, ( const char *filename, const char *mode ) LIBVLC_USED );
00046 VLC_EXPORT( DIR *, utf8_opendir, ( const char *dirname ) LIBVLC_USED );
00047 VLC_EXPORT( char *, utf8_readdir, ( DIR *dir ) LIBVLC_USED );
00048 VLC_EXPORT( int, utf8_loaddir, ( DIR *dir, char ***namelist, int (*select)( const char * ), int (*compar)( const char **, const char ** ) ) );
00049 VLC_EXPORT( int, utf8_scandir, ( const char *dirname, char ***namelist, int (*select)( const char * ), int (*compar)( const char **, const char ** ) ) );
00050 VLC_EXPORT( int, utf8_mkdir, ( const char *filename, mode_t mode ) );
00051 VLC_EXPORT( int, utf8_unlink, ( const char *filename ) );
00052 int utf8_rename( const char *, const char * );
00053 
00054 #if defined( WIN32 ) && !defined( UNDER_CE )
00055 # define stat _stati64
00056 #endif
00057 
00058 VLC_EXPORT( int, utf8_stat, ( const char *filename, struct stat *buf ) );
00059 VLC_EXPORT( int, utf8_lstat, ( const char *filename, struct stat *buf ) );
00060 
00061 VLC_EXPORT( int, utf8_vfprintf, ( FILE *stream, const char *fmt, va_list ap ) );
00062 VLC_EXPORT( int, utf8_fprintf, ( FILE *, const char *, ... ) LIBVLC_FORMAT( 2, 3 ) );
00063 
00064 VLC_EXPORT( int, utf8_mkstemp, ( char * ) );
00065 
00066 VLC_EXPORT( char *, EnsureUTF8, ( char * ) );
00067 VLC_EXPORT( const char *, IsUTF8, ( const char * ) LIBVLC_USED );
00068 
00069 #ifdef WIN32
00070 LIBVLC_USED
00071 static inline char *FromWide (const wchar_t *wide)
00072 {
00073     size_t len = WideCharToMultiByte (CP_UTF8, 0, wide, -1, NULL, 0, NULL, NULL);
00074     if (len == 0)
00075         return NULL;
00076 
00077     char *out = (char *)malloc (len);
00078 
00079     if (out)
00080         WideCharToMultiByte (CP_UTF8, 0, wide, -1, out, len, NULL, NULL);
00081     return out;
00082 }
00083 #endif
00084 
00085 /**
00086  * Converts a nul-terminated string from ISO-8859-1 to UTF-8.
00087  */
00088 static inline char *FromLatin1 (const char *latin)
00089 {
00090     char *str = (char *)malloc (2 * strlen (latin) + 1), *utf8 = str;
00091     unsigned char c;
00092 
00093     if (str == NULL)
00094         return NULL;
00095 
00096     while ((c = *(latin++)) != '\0')
00097     {
00098          if (c >= 0x80)
00099          {
00100              *(utf8++) = 0xC0 | (c >> 6);
00101              *(utf8++) = 0x80 | (c & 0x3F);
00102          }
00103          else
00104              *(utf8++) = c;
00105     }
00106     *(utf8++) = '\0';
00107 
00108     utf8 = (char *)realloc (str, utf8 - str);
00109     return utf8 ? utf8 : str;
00110 }
00111 
00112 VLC_EXPORT( const char *, GetFallbackEncoding, ( void ) LIBVLC_USED );
00113 
00114 VLC_EXPORT( double, us_strtod, ( const char *, char ** ) LIBVLC_USED );
00115 VLC_EXPORT( float, us_strtof, ( const char *, char ** ) LIBVLC_USED );
00116 VLC_EXPORT( double, us_atof, ( const char * ) LIBVLC_USED );
00117 VLC_EXPORT( int, us_asprintf, ( char **, const char *, ... ) LIBVLC_USED );
00118 
00119 #endif

Generated on Sun Nov 22 08:05:12 2009 for VLC by  doxygen 1.5.6