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.

Typedefs

typedef void * vlc_iconv_t

Functions

VLC_API vlc_iconv_t vlc_iconv_open (const char *, const char *) VLC_USED
VLC_API size_t vlc_iconv (vlc_iconv_t, const char **, size_t *, char **, size_t *) VLC_USED
VLC_API int vlc_iconv_close (vlc_iconv_t)
VLC_API void LocaleFree (const char *)
 Releases (if needed) a localized or uniformized string.
VLC_API char * FromLocale (const char *) VLC_USED
 Converts a string from the system locale character encoding to UTF-8.
VLC_API char * FromLocaleDup (const char *) VLC_USED
 converts a string from the system locale character encoding to utf-8, the result is always allocated on the heap.
VLC_API char * ToLocale (const char *) VLC_USED
 ToLocale: converts an UTF-8 string to local system encoding.
VLC_API char * ToLocaleDup (const char *) VLC_USED
 converts a string from UTF-8 to the system locale character encoding, the result is always allocated on the heap.
VLC_API 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.
VLC_API int utf8_fprintf (FILE *, const char *,...) VLC_FORMAT(2
VLC_API int VLC_API char * vlc_strcasestr (const char *, const char *) VLC_USED
 Look for an UTF-8 string within another one in a case-insensitive fashion.
VLC_API char * EnsureUTF8 (char *)
 Replaces invalid/overlong UTF-8 sequences with question marks.
VLC_API const char * IsUTF8 (const char *) VLC_USED
 Checks whether a string is a valid UTF-8 byte sequence.
static char * FromLatin1 (const char *latin)
 Converts a nul-terminated string from ISO-8859-1 to UTF-8.
VLC_API char * FromCharset (const char *charset, const void *data, size_t data_size) VLC_USED
 Converts a string from the given character encoding to utf-8.
VLC_API void * ToCharset (const char *charset, const char *in, size_t *outsize) VLC_USED
 Converts a nul-terminated UTF-8 string to a given character encoding.
VLC_API double us_strtod (const char *, char **) VLC_USED
 us_strtod() has the same prototype as ANSI C strtod() but it uses the POSIX/C decimal format, regardless of the current numeric locale.
VLC_API float us_strtof (const char *, char **) VLC_USED
 us_strtof() has the same prototype as ANSI C strtof() but it uses the POSIX/C decimal format, regardless of the current numeric locale.
VLC_API double us_atof (const char *) VLC_USED
 us_atof() has the same prototype as ANSI C atof() but it expects a dot as decimal separator, regardless of the system locale.
VLC_API int us_vasprintf (char **, const char *, va_list)
 us_vasprintf() has the same prototype as vasprintf(), but doesn't use the system locale.
VLC_API int us_asprintf (char **, const char *,...) VLC_USED
 us_asprintf() has the same prototype as asprintf(), but doesn't use the system locale.

Detailed Description

This files handles locale conversions in vlc.


Typedef Documentation

typedef void* vlc_iconv_t

Function Documentation

VLC_API 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().

VLC_API 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().

Referenced by FromLocale(), FromLocaleDup(), and vlc_readdir().

static char* FromLatin1 ( const char *  latin  )  [inline, static]

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

VLC_API char* FromLocale ( const char *  locale  ) 

Converts a string from the system locale character encoding to UTF-8.

Parameters:
locale nul-terminated string to convert
Returns:
a nul-terminated UTF-8 string, or NULL in case of error. To avoid memory leak, you have to pass the result to LocaleFree() when it is no longer needed.

References FromCharset().

Referenced by config_GetAppDir().

VLC_API char* FromLocaleDup ( const char *  locale  ) 

converts a string from the system locale character encoding to utf-8, the result is always allocated on the heap.

Parameters:
locale nul-terminated string to convert
Returns:
a nul-terminated utf-8 string, or null in case of error. The result must be freed using free() - as with the strdup() function.

References FromCharset(), and strdup().

Referenced by config_GetHomeDir(), config_GetLibDir(), config_GetTypeDir(), and vlc_readdir().

VLC_API const char* IsUTF8 ( const char *  str  ) 

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

Parameters:
str nul-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().

VLC_API void LocaleFree ( const char *  str  ) 

Releases (if needed) a localized or uniformized string.

Parameters:
str non-NULL return value from FromLocale() or ToLocale().

Referenced by config_GetAppDir(), module_Load(), vlc_getaddrinfo(), vlc_mkdir(), vlc_open(), vlc_openat(), vlc_opendir(), vlc_rename(), vlc_statEx(), and vlc_unlink().

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

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

Parameters:
charset iconv name of the character set
in nul-terminated UTF-8 string
outsize pointer 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().

Referenced by ToLocale(), and ToLocaleDup().

VLC_API char* ToLocale ( const char *  utf8  ) 

ToLocale: converts an UTF-8 string to local system encoding.

Parameters:
utf8 nul-terminated string to be converted
Returns:
a nul-terminated string, or NULL in case of error. To avoid memory leak, you have to pass the result to LocaleFree() when it is no longer needed.

References ToCharset().

Referenced by module_Load(), vlc_getaddrinfo(), vlc_mkdir(), vlc_open(), vlc_openat(), vlc_opendir(), vlc_rename(), vlc_statEx(), and vlc_unlink().

VLC_API char* ToLocaleDup ( const char *  utf8  ) 

converts a string from UTF-8 to the system locale character encoding, the result is always allocated on the heap.

Parameters:
utf8 nul-terminated string to convert
Returns:
a nul-terminated string, or null in case of error. The result must be freed using free() - as with the strdup() function.

References strdup(), and ToCharset().

Referenced by utf8_vfprintf(), vlc_bindtextdomain(), and vlc_getcwd().

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

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

References ap, us_vasprintf(), va_end(), and va_start().

VLC_API 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().

VLC_API 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().

VLC_API 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().

VLC_API 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().

VLC_API int utf8_fprintf ( FILE *  ,
const char *  ,
  ... 
)
VLC_API 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, ToLocaleDup(), unlikely, and vasprintf().

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

VLC_API size_t vlc_iconv ( vlc_iconv_t  ,
const char **  ,
size_t *  ,
char **  ,
size_t *   
)
VLC_API int vlc_iconv_close ( vlc_iconv_t   ) 
VLC_API vlc_iconv_t vlc_iconv_open ( const char *  ,
const char *   
)
VLC_API int VLC_API 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:
haystack string to look into
needle string 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().

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines