octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: locale support patch for [fs]sscanf function


From: CdeMills
Subject: Re: locale support patch for [fs]sscanf function
Date: Thu, 19 Jan 2012 13:56:49 -0800 (PST)

John W. Eaton wrote
> 
> Please, let's just remove this change and then discuss what is the
> right thing to do.
> 
> For example, does the locale affect the way scanf works for anything
> other than "," in numbers?  If not, then maybe we could handle this in
> some other way.
> 
> Should setting the locale only be possible using the optional argument
> to scanf, or should it be possible to set this (semi) globally?  For
> example, imagine a script with many calls to scanf.  The way it is
> now, I would have to change each of those calls to use a different
> locale.  It seems to me that it would be convenient to be able to set
> the prevailing locale in one place so that scripts with many calls to
> scanf could change behavior without having to be modified.
> 
> So I think it is worth putting some more thought into this before
> committing a change.
> 
> jwe
> 

According to the C++ ref (http://www.cplusplus.com/reference/std/locale/),
numbers can be formatted using decimal separator, thousand separator,
grouping, as well as "true" and "false" translations for logical vars. "3
000 000,123" should be interpreted as 3e6 +1.23e-1 according to french
locale.

There are two ways to use locale to modify the way inputs are interpreted.
The first is the higher level scanf family, working on istreams, the other
is the low-level std::num_get::get.

For the convenience, we can indeed have a [io]stream_locale builtin, which
is used to imbue each [io]stream. This way, you could have
istream_locale("fr_FR") %# prepare for reading a file with french numbers
convention
fid = fopen('some file') %# this stream will be imbued with "fr_FR" 
% do a lot of fscanf
fclose(fid)
istream_locale(""); %# restore default

We should also add the ability to imbue "cin" by specify that setting
istream_locale in the .octaverc has the effect of imbuing cin.

Regards

Pascal

--
View this message in context: 
http://octave.1599824.n4.nabble.com/locale-support-patch-for-fs-sscanf-function-tp4303471p4311636.html
Sent from the Octave - Maintainers mailing list archive at Nabble.com.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]