Changeset 7146789f5fd7e837313f69da8c772ebb67b80ec1
- 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
| r5e3d57f |
r7146789 |
|
| 50 | 50 | VLC_EXPORT( char *, __vlc_fix_readdir_charset, ( vlc_object_t *, const char * ) ); |
|---|
| 51 | 51 | #define vlc_fix_readdir_charset(a,b) __vlc_fix_readdir_charset(VLC_OBJECT(a),b) |
|---|
| | 52 | extern double i18n_atof( const char * ); |
|---|
| 52 | 53 | |
|---|
| 53 | 54 | # ifdef __cplusplus |
|---|
| r5915e27 |
r7146789 |
|
| 373 | 373 | touch stamp-api |
|---|
| 374 | 374 | |
|---|
| | 375 | ############################################################################### |
|---|
| | 376 | # Unit/regression test |
|---|
| | 377 | ############################################################################### |
|---|
| | 378 | if USE_LIBTOOL |
|---|
| | 379 | check_PROGRAMS = test_i18n_atof |
|---|
| | 380 | TESTS = $(check_PROGRAMS) |
|---|
| | 381 | |
|---|
| | 382 | CFLAGS_tests = `$(VLC_CONFIG) --cflags vlc` |
|---|
| | 383 | |
|---|
| | 384 | test_i18n_atof_SOURCES = test/i18n_atof.c |
|---|
| | 385 | test_i18n_atof_LDADD = libvlc.la |
|---|
| | 386 | test_i18n_atof_CFLAGS = $(CFLAGS_tests) |
|---|
| | 387 | endif |
|---|
| | 388 | |
|---|
| red9e26d |
r7146789 |
|
| 1 | 1 | /***************************************************************************** |
|---|
| 2 | | * charset.c: Determine a canonical name for the current locale's character |
|---|
| 3 | | * encoding. |
|---|
| | 2 | * charset.c: Locale's character encoding stuff. |
|---|
| 4 | 3 | ***************************************************************************** |
|---|
| 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 |
|---|
| 6 | 7 | * $Id$ |
|---|
| 7 | 8 | * |
|---|
| 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 |
|---|
| 9 | 12 | * |
|---|
| 10 | 13 | * vlc_current_charset() an adaption of mp_locale_charset(): |
|---|
| … | … | |
| 372 | 375 | return strdup( psz_string ); |
|---|
| 373 | 376 | } |
|---|
| | 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 | */ |
|---|
| | 387 | double 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 | } |
|---|