Re: [PHP4BETA] bug or feature ???

[email protected] (Steve Langasek)
Newsgroups php.version4
Message-ID <[email protected]>
On Tue, 23 May 2000, Zeev Suraski wrote:

> At 23:58 22/05/2000 , Sascha Schumann wrote:
> >On Sun, 21 May 2000, Andi Gutmans wrote:

> > > We are using the C library strtod() in order to convert the number to a
> > > decimal. I see that strtod() uses locale.
> > > How should this be handled? Should we move to a US locale for the
> > > conversion? (probably a bit slow).

> >I think using the locale is a feature, not a bug. If people choose to use
> >locales we should not try to force an arbitrary locale onto them.

> Due to the fact that we have to write a scanner that analyzes the tokens, 
> and recognizes floating point numbers, we can't support locales.

If you have the option of introducing an extra variable into the scanner code,
then the POSIX-standard function localeconv() returns a structure that can be
queried to find the decimal point character for the current locale:

/* Structure giving information about numeric and monetary notation.  */
struct lconv
{

  /* Numeric (non-monetary) information.  */
  char *decimal_point;          /* Decimal point character.  */
  char *thousands_sep;          /* Thousands separator.  */

....
};

Only a suggestion--I really don't know lex and yacc that well, so I'm not
sure what it would take to make use of this information.  Trying to drop
something variable like this into the middle of a parser is probably bad juju
in any case.

The other option, of course, is to make sure to switch to the C locale before
making the dangerous function calls, and to then restore the previous locale
when finished.

Steve Langasek
postmodern programmer
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.