]> git.sesse.net Git - vlc/blobdiff - src/text/charset.c
failing test for libvlc_media_list_player added
[vlc] / src / text / charset.c
index f7de34c15901a384485053bd1c432ede3a985201..c06124ada3ce940df69840fc87c863ce33bb60a9 100644 (file)
@@ -39,7 +39,7 @@
 # include "config.h"
 #endif
 
-#include <vlc/vlc.h>
+#include <vlc_common.h>
 
 #if !defined WIN32
 # ifdef HAVE_LANGINFO_CODESET
 #ifdef __APPLE__
 #   include <errno.h>
 #   include <string.h>
+#   include <xlocale.h>
 #endif
 
+#include "libvlc.h"
 #include <vlc_charset.h>
 
 typedef struct VLCCharsetAlias
@@ -377,60 +379,22 @@ char *vlc_fix_readdir( const char *psz_string )
 }
 
 
-static 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.
+ * 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 us_strtod( const char *str, char **end )
 {
-    char dup[strlen( str ) + 1], *ptr;
-    double d;
-    strcpy( dup, str );
+    locale_t loc = newlocale (LC_NUMERIC_MASK, "C", NULL);
+    locale_t oldloc = uselocale (loc);
+    double res = strtod (str, end);
 
-    ptr = strchr( dup, ',' );
-    if( ptr != NULL )
-        *ptr = '\0';
-
-    d = strtod( dup, &ptr );
-    if( end != NULL )
-        *end = (char *)&str[ptr - dup];
-
-    return d;
+    if (loc != (locale_t)0)
+    {
+        uselocale (oldloc);
+        freelocale (loc);
+    }
+    return res;
 }
 
 /**