00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef VLC_CHARSET_H
00026 #define VLC_CHARSET_H 1
00027
00028
00029
00030
00031
00032
00033 #include <stdarg.h>
00034
00035 VLC_EXPORT( void, LocaleFree, ( const char * ) );
00036 VLC_EXPORT( char *, FromLocale, ( const char * ) LIBVLC_USED );
00037 VLC_EXPORT( char *, FromLocaleDup, ( const char * ) LIBVLC_USED );
00038 VLC_EXPORT( char *, ToLocale, ( const char * ) LIBVLC_USED );
00039 VLC_EXPORT( char *, ToLocaleDup, ( const char * ) LIBVLC_USED );
00040
00041 VLC_EXPORT( int, utf8_vfprintf, ( FILE *stream, const char *fmt, va_list ap ) );
00042 VLC_EXPORT( int, utf8_fprintf, ( FILE *, const char *, ... ) LIBVLC_FORMAT( 2, 3 ) );
00043
00044 VLC_EXPORT( char *, EnsureUTF8, ( char * ) );
00045 VLC_EXPORT( const char *, IsUTF8, ( const char * ) LIBVLC_USED );
00046
00047 #ifdef WIN32
00048 LIBVLC_USED
00049 static inline char *FromWide (const wchar_t *wide)
00050 {
00051 size_t len = WideCharToMultiByte (CP_UTF8, 0, wide, -1, NULL, 0, NULL, NULL);
00052 if (len == 0)
00053 return NULL;
00054
00055 char *out = (char *)malloc (len);
00056
00057 if (likely(out))
00058 WideCharToMultiByte (CP_UTF8, 0, wide, -1, out, len, NULL, NULL);
00059 return out;
00060 }
00061
00062 LIBVLC_USED
00063 static inline wchar_t *ToWide (const char *utf8)
00064 {
00065 int len = MultiByteToWideChar (CP_UTF8, 0, utf8, -1, NULL, 0);
00066 if (len == 0)
00067 return NULL;
00068
00069 wchar_t *out = (wchar_t *)malloc (len * sizeof (wchar_t));
00070
00071 if (likely(out))
00072 MultiByteToWideChar (CP_UTF8, 0, utf8, -1, out, len);
00073 return out;
00074 }
00075 #endif
00076
00077
00078
00079
00080 static inline char *FromLatin1 (const char *latin)
00081 {
00082 char *str = (char *)malloc (2 * strlen (latin) + 1), *utf8 = str;
00083 unsigned char c;
00084
00085 if (str == NULL)
00086 return NULL;
00087
00088 while ((c = *(latin++)) != '\0')
00089 {
00090 if (c >= 0x80)
00091 {
00092 *(utf8++) = 0xC0 | (c >> 6);
00093 *(utf8++) = 0x80 | (c & 0x3F);
00094 }
00095 else
00096 *(utf8++) = c;
00097 }
00098 *(utf8++) = '\0';
00099
00100 utf8 = (char *)realloc (str, utf8 - str);
00101 return utf8 ? utf8 : str;
00102 }
00103
00104 VLC_EXPORT( char *, FromCharset, ( const char *charset, const void *data, size_t data_size ) LIBVLC_USED );
00105
00106 VLC_EXPORT( double, us_strtod, ( const char *, char ** ) LIBVLC_USED );
00107 VLC_EXPORT( float, us_strtof, ( const char *, char ** ) LIBVLC_USED );
00108 VLC_EXPORT( double, us_atof, ( const char * ) LIBVLC_USED );
00109 VLC_EXPORT( int, us_asprintf, ( char **, const char *, ... ) LIBVLC_USED );
00110
00111 #endif