VLC  2.1.0-git
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Macros | Typedefs | Functions
vlc_charset.h File Reference

This files handles locale conversions in vlc. More...

Include dependency graph for vlc_charset.h:

Go to the source code of this file.

Macros

#define FromLocale(l)   (l)
#define ToLocale(u)   (u)
#define LocaleFree(s)   ((void)(s))
#define FromLocaleDup   strdup
#define ToLocaleDup   strdup

Typedefs

typedef void * vlc_iconv_t

Functions

vlc_iconv_t vlc_iconv_open (const char *, const char *)
size_t vlc_iconv (vlc_iconv_t, const char **, size_t *, char **, size_t *)
int vlc_iconv_close (vlc_iconv_t)
int utf8_vfprintf (FILE *stream, const char *fmt, va_list ap)
 Formats an UTF-8 string as vfprintf(), then print it, with appropriate conversion to local encoding.
int utf8_fprintf (FILE *, const char *,...)
 Formats an UTF-8 string as fprintf(), then print it, with appropriate conversion to local encoding.
char * vlc_strcasestr (const char *, const char *)
 Look for an UTF-8 string within another one in a case-insensitive fashion.
char * EnsureUTF8 (char *)
 Replaces invalid/overlong UTF-8 sequences with question marks.
const char * IsUTF8 (const char *)
 Checks whether a string is a valid UTF-8 byte sequence.
char * FromCharset (const char *charset, const void *data, size_t data_size)
 Converts a string from the given character encoding to utf-8.
void * ToCharset (const char *charset, const char *in, size_t *outsize)
 Converts a nul-terminated UTF-8 string to a given character encoding.
static char * FromLatin1 (const char *latin)
 Converts a nul-terminated string from ISO-8859-1 to UTF-8.
double us_strtod (const char *, char **)
 us_strtod() has the same prototype as ANSI C strtod() but it uses the POSIX/C decimal format, regardless of the current numeric locale.
float us_strtof (const char *, char **)
 us_strtof() has the same prototype as ANSI C strtof() but it uses the POSIX/C decimal format, regardless of the current numeric locale.
double us_atof (const char *)
 us_atof() has the same prototype as ANSI C atof() but it expects a dot as decimal separator, regardless of the system locale.
int us_vasprintf (char **, const char *, va_list)
 us_vasprintf() has the same prototype as vasprintf(), but doesn't use the system locale.
int us_asprintf (char **, const char *,...)
 us_asprintf() has the same prototype as asprintf(), but doesn't use the system locale.

Detailed Description

This files handles locale conversions in vlc.

Macro Definition Documentation

#define FromLocale (   l)    (l)
#define FromLocaleDup   strdup
#define LocaleFree (   s)    ((void)(s))
#define ToLocale (   u)    (u)
#define ToLocaleDup   strdup

Referenced by vlc_bindtextdomain(), and vlc_getcwd().

Typedef Documentation

typedef void* vlc_iconv_t

Function Documentation

char* EnsureUTF8 ( char *  str)

Replaces invalid/overlong UTF-8 sequences with question marks.

Note that it is not possible to convert from Latin-1 to UTF-8 on the fly, so we don't try that, even though it would be less disruptive.

Returns
str if it was valid UTF-8, NULL if not.

References likely, and vlc_towc().

Referenced by filename_sanitize(), input_item_SetURI(), InputMetaUser(), and test().

char* FromCharset ( const char *  charset,
const void *  data,
size_t  data_size 
)

Converts a string from the given character encoding to utf-8.

Returns
a nul-terminated utf-8 string, or null in case of error. The result must be freed using free().

References vlc_iconv(), vlc_iconv_close(), and vlc_iconv_open().

static char* FromLatin1 ( const char *  latin)
inlinestatic

Converts a nul-terminated string from ISO-8859-1 to UTF-8.

const char* IsUTF8 ( const char *  str)

Checks whether a string is a valid UTF-8 byte sequence.

Parameters
strnul-terminated string to be checked
Returns
str if it was valid UTF-8, NULL if not.

References likely, and vlc_towc().

Referenced by IsSDPString(), and test().

void* ToCharset ( const char *  charset,
const char *  in,
size_t *  outsize 
)

Converts a nul-terminated UTF-8 string to a given character encoding.

Parameters
charseticonv name of the character set
innul-terminated UTF-8 string
outsizepointer to hold the byte size of result
Returns
A pointer to the result, which must be released using free(). The UTF-8 nul terminator is included in the conversion if the target character encoding supports it. However it is not included in the returned byte size. In case of error, NULL is returned and the byte size is undefined.

References unlikely, vlc_iconv(), vlc_iconv_close(), and vlc_iconv_open().

int us_asprintf ( char **  ,
const char *  ,
  ... 
)

us_asprintf() has the same prototype as asprintf(), but doesn't use the system locale.

References us_vasprintf().

double us_atof ( const char *  )

us_atof() has the same prototype as ANSI C atof() but it expects a dot as decimal separator, regardless of the system locale.

References us_strtod().

Referenced by config_ChainParse(), config_LoadCmdLine(), main(), var_Command(), var_InheritURational(), and var_OptionParse().

double us_strtod ( const char *  ,
char **   
)

us_strtod() has the same prototype as ANSI C strtod() but it uses the POSIX/C decimal format, regardless of the current numeric locale.

References freelocale(), LC_NUMERIC_MASK, newlocale(), and uselocale().

Referenced by main(), and us_atof().

float us_strtof ( const char *  ,
char **   
)

us_strtof() has the same prototype as ANSI C strtof() but it uses the POSIX/C decimal format, regardless of the current numeric locale.

References freelocale(), LC_NUMERIC_MASK, newlocale(), strtof(), and uselocale().

int us_vasprintf ( char **  ,
const char *  ,
va_list   
)

us_vasprintf() has the same prototype as vasprintf(), but doesn't use the system locale.

References freelocale(), LC_NUMERIC_MASK, newlocale(), uselocale(), and vasprintf().

Referenced by httpd_MsgAdd(), and us_asprintf().

int utf8_fprintf ( FILE *  ,
const char *  ,
  ... 
)

Formats an UTF-8 string as fprintf(), then print it, with appropriate conversion to local encoding.

References utf8_vfprintf().

Referenced by Help(), libvlc_InternalInit(), ListModules(), print_help_on_full_help(), print_help_section(), PrintColorMsg(), PrintMsg(), Usage(), and Version().

int utf8_vfprintf ( FILE *  stream,
const char *  fmt,
va_list  ap 
)

Formats an UTF-8 string as vfprintf(), then print it, with appropriate conversion to local encoding.

References likely, unlikely, and vasprintf().

Referenced by PrintColorMsg(), PrintMsg(), and utf8_fprintf().

size_t vlc_iconv ( vlc_iconv_t  ,
const char **  ,
size_t *  ,
char **  ,
size_t *   
)
int vlc_iconv_close ( vlc_iconv_t  )
vlc_iconv_t vlc_iconv_open ( const char *  ,
const char *   
)
char* vlc_strcasestr ( const char *  haystack,
const char *  needle 
)

Look for an UTF-8 string within another one in a case-insensitive fashion.

Beware that this is quite slow. Contrary to strcasestr(), this function works regardless of the system character encoding, and handles multibyte code points correctly.

Parameters
haystackstring to look into
needlestring to look for
Returns
a pointer to the first occurence of the needle within the haystack, or NULL if no occurence were found.

References unlikely, and vlc_towc().

Referenced by playlist_LiveSearchUpdateInternal(), and test_strcasestr().