
hi, from the documentation [1] : "[...] the library uses the codecvt<wchar_t, char> locale facet from the global locale." The quote is taken from the unicode-documentation part. May i ask why the locale is taken from the global locale, instead of the locale assigned to the stream? What I'd like to do is (currently yields a logic_error) // assume stream contains "a = 1,2" // ... std::locale loc("German_Germany"); stream.imbue(loc); po::parse_config_file(stream, opts, false); instead i have to std::locale loc("German_Germany"); std::locale::global(loc); po::parse_config_file(stream, opts, false); to parse the config file correctly. Best regards, Christoph [1] "http://www.boost.org/doc/libs/1_43_0/doc/html/program_options/howto.html#id1...

Christoph Heindl wrote:
hi,
from the documentation [1] : "[...] the library uses the codecvt<wchar_t, char> locale facet from the global locale." The quote is taken from the unicode-documentation part. May i ask why the locale is taken from the global locale, instead of the locale assigned to the stream?
What do you mean by "the stream"?
What I'd like to do is (currently yields a logic_error)
// assume stream contains "a = 1,2" // ... std::locale loc("German_Germany"); stream.imbue(loc); po::parse_config_file(stream, opts, false);
Ah, that's what you mean. The problem is that command-line parsing does not have any associated locale other than the global one, and it would be somewhat awkward to remember a locale associated with source config file.
instead i have to
std::locale loc("German_Germany"); std::locale::global(loc); po::parse_config_file(stream, opts, false);
to parse the config file correctly.
Is it common to use different locales for different files? - Volodya

Is it common to use different locales for different files?
It is very uncommon to use global locale as... about half of programs will be broken as they not locale-aware. (example boost::lexical_cast<std::string>(1024)=="1.024", many developers would not expect this) On the other hand when locale is used it would be imbued by default to the newly created io-stream. Additional point is the fact that there are may be many C++ locale instances unlike the case of C locales. So the **right** thing to do: 1. Use iostream's locale if you use stream 2. Use your own locale and provide imbue()/getloc() option as io-stream does. Artyom

Artyom wrote:
Is it common to use different locales for different files?
It is very uncommon to use global locale as... about half of programs will be broken as they not locale-aware.
(example boost::lexical_cast<std::string>(1024)=="1.024", many developers would not expect this)
You can change only codecvt facet. - Volodya

On Mon, Jun 21, 2010 at 1:34 PM, Vladimir Prus <vladimir@codesourcery.com> wrote:
Ah, that's what you mean. The problem is that command-line parsing does not have any associated locale other than the global one,
I don't quite understand. reading from std::cin does have an locale, doesn't it? I.e the following is valid: std::cin.imbue(loc);
it would be somewhat awkward to remember a locale associated with source config file.
remember? that's what stream.imbue(loc) does, or not?
Is it common to use different locales for different files?
No, it shoudn't, but happens :) Best regards, Christoph
participants (3)
-
Artyom
-
Christoph Heindl
-
Vladimir Prus