Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > locale question

Reply
Thread Tools

locale question

 
 
Cagdas Ozgenc
Guest
Posts: n/a
 
      11-04-2003
Greetings.

I am confused about C++ standard library locale stuff. It seems as if the
implementations of locales are not part of the library, but only some
guideline classes are there.

What is the standard conformant way of formatting and parsing locale
specific date, time, strings with various character encoding, etc.

Thanks


 
Reply With Quote
 
 
 
 
Mark Kerns
Guest
Posts: n/a
 
      11-04-2003
> I am confused about C++ standard library locale stuff. It seems as if the
> implementations of locales are not part of the library, but only some
> guideline classes are there.
>
> What is the standard conformant way of formatting and parsing locale
> specific date, time, strings with various character encoding, etc.
>
> Thanks


Typically you'll use a locale through a stream but you can also use them
directly. When working with a stream, you simply invoke the stream's "imbue"
member, passing your "locale" object which is encapsulated in the stream.
You can read up on the various locale constructors but the "C" locale (AKA
locale::classic) is used by default (actually, the "locale::global" object
is used but it originates from "locale::classic" unless you change it). You
can pass other implementation-defined strings to a locale's constructor
however, typically based on RFC 1766 which in turn is based on ISO 639 and
3166 - try passing "en-US" (English US ) or "fr-CA" (French Canadian) for
instance or consult your local implementation for details). Subsequently,
whenever you invoke the << or >> operators on your stream, the stream will
handle the date, time, etc. according to the facets stored in the
encapsulated locale (a locale is really just a collection of facet objects
such as "num_put", "time_put", "numpunct" etc.). You can also store your own
customized facets in an existing locale however or provide overrides for the
various (facet) member functions as required. In any case, everything boils
down to invoking the "use_facet()" function template, passing a given
facet's class name as the template arg, the locale you want as the
function's arg, and then invoking a particular member of that facet's class
(that is, a reference to the requested facet object is returned by this
function and you just invoke the member you're interested in). "use_facet()"
is rather ugly to call as you'll soon see (the entire locale/facet design is
ugly IMO) but you should consult this function for details. Also see
"has_facet()" to ensure a facet is even supported by a given locale.
Everything should become clear once you understand "use_facet()" which
forces you to address the issues you're asking about (also note that the <<
and >> stream operators defer to this function in case that's not clear by
now).


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
the relation between C++ locale and C locale zade C++ 1 03-05-2010 06:04 PM
Re: List of locale values for locale.setlocale() under Windows Gabriel Genellina Python 0 02-18-2009 12:00 AM
Create C++ std::locale without changing C locale dertopper@web.de C++ 4 08-26-2008 01:15 PM
i18n problem, involving Locale.getDisplayLanguage and Locale.getDisplayCountry Maurice Hulsman Java 1 07-25-2004 06:11 PM
locale.nl_langinfo(RADIXCHAR) vs locale.localeconv()['decimal_point'] Jeff Epler Python 2 08-31-2003 02:18 PM



Advertisments