|
Boost : |
From: Howard Hinnant (hinnant_at_[hidden])
Date: 2002-05-22 21:42:51
On Wednesday, May 22, 2002, at 09:37 PM, Daryle Walker wrote:
> on 5/22/02 10:34 AM, David Abrahams at david.abrahams_at_[hidden] wrote:
>
>> I was wondering about the reasons for using locale("") as opposed to
>> locale("C") in ios_state_test.cpp; it seems like it opens the test up
>> to
>> lots of different behaviors. For example Metrowerks Pro7 and later
>> look in
>> the environment for a LANG setting in this case, and do something with
>> that
>> (Howard can comment on the reasons if anyone's interested)... which
>> makes
>> it rather hard to pass the test reliably.
>
> There's no particular reason; I just needed a locale name that is
> guaranteed
> to be on every system. What's the difference between the "" and "C"
> locales?
"C" has a definition that is relatively well defined in chapter 22.
Most of its facet's behavior's are specified. But for "" chapter 22
says two things:
> The set of valid string argument values is "C", "", and any
> implementation-defined values.
> cin.imbue(locale("")); // the user's preferred locale
That's it.
In the Metrowerks libs prior to Pro 7 we just set "" identical to "C".
For Pro 7 we attempted (for better or worse) to implement the "spirit"
of chapter 22. Given "", the locale code will try to infer the user's
preferred locale by looking at getenv("LANG"). If this returns a
non-null pointer, we interpret that to point to a locale data file with
which the locale should be built.
Dave's boost tests are failing because he does have a LANG environment
variable, and it doesn't refer to a Metrowerks locale data file. So,
perhaps we (Metrowerks) should choose another environment variable to
key off of (or another technique for interpreting ""). But Dave is
suggesting also that unless boost tests really are looking for "the
user's preferred locale", that it just use "C" since that behavior is
better defined by the standard.
Fwiw, and I haven't looked at the test code in question, if you need
just any old locale, locale(), locale::global() and locale::classic()
are immensely cheaper than locale("C") at least on the Metrowerks
implementation. The former three constructors have semantics that are
relatively well defined at compile time. For locale("C") the C++ lib
has to inspect the const char* at runtime and be prepared to do
who-knows-what with it. The Metrowerks implementation instantiates all
kinds of code prepared to deal with a non-"C" name. If that's what you
need, great. But if its not, no sense paying for it.
-Howard
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk