X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Ftext%2Fcharset.c;h=7d090240cb9f36fbd5997880039dfc7bba1c371f;hb=c9517f626f4402d3fdadab92e1c6d7d9fb2b18b6;hp=4e265324a1b662ac77ed4d410f5ce47471c8a43f;hpb=df61d33b06e2b3cbbe746b2f5a9bea5b370c24ff;p=vlc diff --git a/src/text/charset.c b/src/text/charset.c index 4e265324a1..7d090240cb 100644 --- a/src/text/charset.c +++ b/src/text/charset.c @@ -53,6 +53,7 @@ #ifdef __APPLE__ # include # include +# include #endif #include @@ -378,68 +379,21 @@ char *vlc_fix_readdir( const char *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. + * us_strtod() has the same prototype as ANSI C strtod() but it uses the + * POSIX/C decimal format, regardless of the current numeric locale. */ -double i18n_strtod( const char *str, char **end ) +double us_strtod( const char *str, char **end ) { - char *end_buf, e; - double d; - - if( end == NULL ) - end = &end_buf; - d = strtod( str, end ); + locale_t loc = newlocale (LC_NUMERIC_MASK, "C", NULL); + locale_t oldloc = uselocale (loc); + double res = strtod (str, end); - e = **end; - if(( e == ',' ) || ( e == '.' )) + if (loc != (locale_t)0) { - char dup[strlen( str ) + 1]; - strcpy( dup, str ); - - if( dup == NULL ) - return d; - - dup[*end - str] = ( e == ',' ) ? '.' : ','; - d = strtod( dup, end ); + uselocale (oldloc); + freelocale (loc); } - 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; + return res; } /**