[ardour-dev] Re: i18n serialization

Walco walco-ardour at n--tree.net
Thu Dec 2 01:30:53 PST 2004


Hi Paul,

My findings:

- The setting of LC_NUMERIC doesn't have any influence on the output or 
scanning.

LC_NUMERIC=nl_NL at euro ./is
LC_NUMERIC=nl_NL at euro
scanned value is 13.000000
1234567.89
printf gives 13.200000
c++ iostreams says 13.2

But when I changed the code to set the locale numeric setting explicitly:
      setlocale(LC_NUMERIC, getenv("LC_NUMERIC"));

with my default system LC_NUMERIC setting (nl_NL at euro), the result is:

LC_NUMERIC=nl_NL at euro ./is
LC_NUMERIC=nl_NL at euro
scanned value is 13,200000
1234567,89
printf gives 13,200000
c++ iostreams says 13.2

If I run the modified program specifying any locale that isn't installed 
on my system, the output is the same as in the first run. If I generate 
the da_DK locale

localedef -i da_DK -f ISO-8859-1 da_DK

the output is:

LC_NUMERIC=da_DK ./is
LC_NUMERIC=da_DK
scanned value is 13,200000
1234567,89
printf gives 13,200000
c++ iostreams says 13.2

The decimal formatting is correct, but there is no digit grouping though 
although the Danish locale definition in /usr/share/i18n/locales/da_DK 
does indeed specify this.

Hope this helps a bit ;-)

Cheers,
Walco

 > you are invited to try to get this program to misbehave by setting
 > some locale-related environment variables. i seem unable to do so,
 > despite what man 3 printf says about LC_NUMERIC ...
 >
 > in theory using LC_NUMERIC=da_DK should change the print format of the
 > larger floating value, and nl_NL should change the scanning of the
 > "str" variable.
 >
 > --p
 >
 >
 > ---------------------------------------
 >
 > /* save as is.cc then compile with g++ -o is is.cc */
 >
 > #include <stdio.h>
 > #include <unistd.h>
 > #include <stdlib.h>
 >
 > #include <iostream>
 >
 > using namespace std;
 >
 > int
 > main (int argc, char *argv[])
 > {
 >     char* str = "13,2";
 >     float val;
 >
 >     printf ("LC_NUMERIC=%s\n", getenv ("LC_NUMERIC"));
 >
 >     if (sscanf (str, "%f", &val) != 1) {
 >         fprintf (stderr, "not scanned\n");
 >     } else {
 >         printf ("scanned value is %f\n", val);
 >     }
 >
 >     val = 13.2;
 >
 >     printf ("%.2f\n", 1234567.89);
 >
 >     printf ("printf gives %f\n", val);
 >     cerr << "c++ iostreams says " << val << endl;
 > }
 > _______________________________________________
 > ardour-dev mailing list
 > ardour-dev at lists.ardour.org
 > http://lists.ardour.org/listinfo.cgi/ardour-dev-ardour.org





More information about the Ardour-Dev mailing list