/*****************************************************************************
- * charset.c: Determine a canonical name for the current locale's character
- * encoding.
+ * charset.c: Locale's character encoding stuff.
*****************************************************************************
- * Copyright (C) 2003-2005 the VideoLAN team
+ * See also unicode.c for Unicode to locale conversion helpers.
+ *
+ * Copyright (C) 2003-2006 the VideoLAN team
* $Id$
*
- * Author: Derk-Jan Hartman <thedj at users.sf.net>
+ * Authors: Derk-Jan Hartman <thedj at users.sf.net>
+ * Christophe Massiot
+ * RĂ©mi Denis-Courmont
*
* vlc_current_charset() an adaption of mp_locale_charset():
*
* a lot of basic aliases (check it first by iconv -l).
*
*/
-#if defined WIN32 || defined OS2 || !HAVE_LANGINFO_CODESET
+#if (defined OS2 || !HAVE_LANGINFO_CODESET) && !defined WIN32
static const char* vlc_encoding_from_language( const char *l )
{
/* check for language (and perhaps country) codes */
VLCCharsetAlias aliases[] = {{NULL, NULL}};
#endif
- if( aliases )
- {
- for (a = aliases; a->psz_alias; a++)
- if (strcasecmp (a->psz_alias, psz_name) == 0)
- return a->psz_name;
- }
+ for (a = aliases; a->psz_alias; a++)
+ if (strcasecmp (a->psz_alias, psz_name) == 0)
+ return a->psz_name;
/* we return original name beacuse iconv() probably will know
* something better about name if we don't know it :-) */
}
/* Returns charset from "language_COUNTRY.charset@modifier" string */
-#if defined WIN32 || defined OS2 || !HAVE_LANGINFO_CODESET
+#if (defined OS2 || !HAVE_LANGINFO_CODESET) && !defined WIN32
static void vlc_encoding_from_locale( char *psz_locale, char *psz_charset )
{
char *psz_dot = strchr( psz_locale, '.' );
return strdup( psz_string );
}
+
+/**
+ * There are two decimal separators in the computer world-wide locales:
+ * dot (which is the american default), and comma (which is used in France,
+ * the country with the most VLC developers, among others).
+ *
+ * i18n_strtod() has the same prototype as ANSI C strtod() but it accepts
+ * either decimal separator when deserializing the string to a float number,
+ * independant of the local computer setting.
+ */
+double i18n_strtod( const char *str, char **end )
+{
+ char *end_buf, e;
+ double d;
+
+ if( end == NULL )
+ end = &end_buf;
+ d = strtod( str, end );
+
+ e = **end;
+ if(( e == ',' ) || ( e == '.' ))
+ {
+ char dup[strlen( str ) + 1];
+ strcpy( dup, str );
+
+ if( dup == NULL )
+ return d;
+
+ dup[*end - str] = ( e == ',' ) ? '.' : ',';
+ d = strtod( dup, end );
+ }
+ return d;
+}
+
+/**
+ * i18n_atof() has the same prototype as ANSI C atof() but it accepts
+ * either decimal separator when deserializing the string to a float number,
+ * independant of the local computer setting.
+ */
+double i18n_atof( const char *str )
+{
+ return i18n_strtod( str, NULL );
+}
+
+
+/**
+ * us_strtod() has the same prototype as ANSI C strtod() but it expects
+ * a dot as decimal separator regardless of the system locale.
+ */
+double us_strtod( const char *str, char **end )
+{
+ char dup[strlen( str ) + 1], *ptr;
+ double d;
+ strcpy( dup, str );
+
+ ptr = strchr( dup, ',' );
+ if( ptr != NULL )
+ *ptr = '\0';
+
+ d = strtod( dup, &ptr );
+ if( end != NULL )
+ *end = (char *)&str[ptr - dup];
+
+ return d;
+}
+
+/**
+ * us_atof() has the same prototype as ANSI C atof() but it expects a dot
+ * as decimal separator, regardless of the system locale.
+ */
+double us_atof( const char *str )
+{
+ return us_strtod( str, NULL );
+}
+