[ardour-dev] i18n serialization

Doug McLain nostar at comcast.net
Wed Dec 1 20:29:36 PST 2004


Looks the the %'.2f is the key here, but even so I can't get it to work 
by setting LC_NUMERIC as an environment variable, only via setlocale().  
It works like I think you expect with the changes below, and specifying 
the locale on the command line:

bash-2.05b$ ./is da_DK
returned from setlocale: da_DK
scanned value is 13,200000
1.234.567,89
printf gives 13,200000
c++ iostreams says 13.2
bash-2.05b$

bash-2.05b$ diff -u is.cc is2.cc
--- is.cc       2004-12-02 04:17:45.000000000 +0000
+++ is2.cc      2004-12-02 04:16:49.000000000 +0000
@@ -1,6 +1,7 @@
 #include <stdio.h>
 #include <unistd.h>
 #include <stdlib.h>
+#include <locale.h>

 #include <iostream>

@@ -12,7 +13,7 @@
        char* str = "13,2";
        float val;

-       printf ("LC_NUMERIC=%s\n", getenv ("LC_NUMERIC"));
+       printf("returned from setlocale: %s\n", setlocale (LC_NUMERIC, 
argv[1]));

        if (sscanf (str, "%f", &val) != 1) {
                fprintf (stderr, "not scanned\n");
@@ -22,7 +23,7 @@

        val = 13.2;

-       printf ("%.2f\n", 1234567.89);
+       printf ("%'.2f\n", 1234567.89);

        printf ("printf gives %f\n", val);
        cerr << "c++ iostreams says " << val << endl;

Paul Davis wrote:

>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