Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc-gpu
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
vlc-gpu
Commits
7146789f
Commit
7146789f
authored
Mar 08, 2006
by
Rémi Denis-Courmont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
i18n_atof(): locale-agnostic atof()
parent
d3de78aa
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
91 additions
and
4 deletions
+91
-4
include/charset.h
include/charset.h
+1
-0
src/Makefile.am
src/Makefile.am
+14
-0
src/misc/charset.c
src/misc/charset.c
+35
-4
src/test/i18n_atof.c
src/test/i18n_atof.c
+41
-0
No files found.
include/charset.h
View file @
7146789f
...
...
@@ -49,6 +49,7 @@ VLC_EXPORT( char *, EnsureUTF8, ( char * ) );
VLC_EXPORT
(
char
*
,
FromUTF32
,
(
const
wchar_t
*
)
);
VLC_EXPORT
(
char
*
,
__vlc_fix_readdir_charset
,
(
vlc_object_t
*
,
const
char
*
)
);
#define vlc_fix_readdir_charset(a,b) __vlc_fix_readdir_charset(VLC_OBJECT(a),b)
extern
double
i18n_atof
(
const
char
*
);
# ifdef __cplusplus
}
...
...
src/Makefile.am
View file @
7146789f
...
...
@@ -372,3 +372,17 @@ stamp-api: Makefile.in $(HEADERS_include) ../vlc-api.pl
top_srcdir
=
"
$(top_srcdir)
"
perl
$(top_srcdir)
/vlc-api.pl
touch
stamp-api
###############################################################################
# Unit/regression test
###############################################################################
if
USE_LIBTOOL
check_PROGRAMS
=
test_i18n_atof
TESTS
=
$(check_PROGRAMS)
CFLAGS_tests
=
`
$(VLC_CONFIG)
--cflags
vlc
`
test_i18n_atof_SOURCES
=
test
/i18n_atof.c
test_i18n_atof_LDADD
=
libvlc.la
test_i18n_atof_CFLAGS
=
$(CFLAGS_tests)
endif
src/misc/charset.c
View file @
7146789f
/*****************************************************************************
* 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():
*
...
...
@@ -371,3 +374,31 @@ char *__vlc_fix_readdir_charset( vlc_object_t *p_this, const char *psz_string )
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_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
)
{
char
*
end
;
double
d
=
strtod
(
str
,
&
end
);
if
((
*
end
==
','
)
||
(
*
end
==
'.'
))
{
char
*
dup
=
strdup
(
str
);
if
(
dup
==
NULL
)
return
d
;
dup
[
end
-
str
]
=
(
*
end
==
','
)
?
'.'
:
','
;
d
=
strtod
(
dup
,
&
end
);
free
(
dup
);
}
return
d
;
}
src/test/i18n_atof.c
0 → 100644
View file @
7146789f
/*****************************************************************************
* i18n_atof.c: Test for i18n_atof
*****************************************************************************
* Copyright (C) 2006 Rémi Denis-Courmont
* $Id$
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include <vlc/vlc.h>
#include "charset.h"
#undef NDEBUG
#include <assert.h>
int
main
(
void
)
{
assert
(
i18n_atof
(
"0"
)
==
0
.);
assert
(
i18n_atof
(
"1"
)
==
1
.);
assert
(
i18n_atof
(
"1."
)
==
1
.);
assert
(
i18n_atof
(
"1,"
)
==
1
.);
assert
(
i18n_atof
(
"1#"
)
==
1
.);
assert
(
i18n_atof
(
"999999.999999"
)
==
999999
.
999999
);
assert
(
i18n_atof
(
"999999,999999"
)
==
999999
.
999999
);
assert
(
i18n_atof
(
"999999#999999"
)
==
999999
.);
assert
(
i18n_atof
(
"invalid"
)
==
0
.);
return
0
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment