Changeset 7146789f5fd7e837313f69da8c772ebb67b80ec1

Show
Ignore:
Timestamp:
08/03/06 12:32:34 (3 years ago)
Author:
Rémi Denis-Courmont <rem@videolan.org>
git-committer:
Rémi Denis-Courmont <rem@videolan.org> 1141817554 +0000
git-parent:

[d3de78aa5fb85672dda1bd221b29776603575cc2]

git-author:
Rémi Denis-Courmont <rem@videolan.org> 1141817554 +0000
Message:

i18n_atof(): locale-agnostic atof()

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • include/charset.h

    r5e3d57f r7146789  
    5050VLC_EXPORT( char *, __vlc_fix_readdir_charset, ( vlc_object_t *, const char * ) ); 
    5151#define vlc_fix_readdir_charset(a,b) __vlc_fix_readdir_charset(VLC_OBJECT(a),b) 
     52extern double i18n_atof( const char * ); 
    5253 
    5354# ifdef __cplusplus 
  • src/Makefile.am

    r5915e27 r7146789  
    373373    touch stamp-api 
    374374 
     375############################################################################### 
     376# Unit/regression test 
     377############################################################################### 
     378if USE_LIBTOOL 
     379check_PROGRAMS = test_i18n_atof 
     380TESTS = $(check_PROGRAMS) 
     381 
     382CFLAGS_tests = `$(VLC_CONFIG) --cflags vlc` 
     383 
     384test_i18n_atof_SOURCES = test/i18n_atof.c 
     385test_i18n_atof_LDADD = libvlc.la 
     386test_i18n_atof_CFLAGS = $(CFLAGS_tests) 
     387endif 
     388 
  • src/misc/charset.c

    red9e26d r7146789  
    11/***************************************************************************** 
    2  * charset.c: Determine a canonical name for the current locale's character 
    3  *            encoding. 
     2 * charset.c: Locale's character encoding stuff. 
    43 ***************************************************************************** 
    5  * Copyright (C) 2003-2005 the VideoLAN team 
     4 * See also unicode.c for Unicode to locale conversion helpers. 
     5 * 
     6 * Copyright (C) 2003-2006 the VideoLAN team 
    67 * $Id$ 
    78 * 
    8  * Author: Derk-Jan Hartman <thedj at users.sf.net> 
     9 * Authors: Derk-Jan Hartman <thedj at users.sf.net> 
     10 *          Christophe Massiot 
     11 *          Rémi Denis-Courmont 
    912 * 
    1013 * vlc_current_charset() an adaption of mp_locale_charset(): 
     
    372375    return strdup( psz_string ); 
    373376} 
     377 
     378/** 
     379 * There are two decimal separators in the computer world-wide locales: 
     380 * dot (which is the american default), and comma (which is used in France, 
     381 * the country with the most VLC developers, among others). 
     382 * 
     383 * i18n_atof() has the same prototype as ANSI C atof() but it accepts 
     384 * either decimal separator when deserializing the string to a float number, 
     385 * independant of the local computer setting. 
     386 */ 
     387double i18n_atof( const char *str ) 
     388{ 
     389    char *end; 
     390    double d = strtod( str, &end ); 
     391 
     392    if(( *end == ',' ) || ( *end == '.' )) 
     393    { 
     394        char *dup = strdup( str ); 
     395 
     396        if( dup == NULL ) 
     397            return d; 
     398 
     399        dup[end - str] = ( *end == ',' ) ? '.' : ','; 
     400        d = strtod( dup, &end ); 
     401        free( dup ); 
     402    } 
     403    return d; 
     404}