473,468 Members | 1,325 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

locale question

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
Jul 19 '05 #1
1 1987
> 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).
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Ksenia Marasanova | last post by:
Hi, I have some problems with locale module. On my workstation, changing locale doesn't have effect: Python 2.3 (#1, Sep 13 2003, 00:49:11) on darwin Type "help", "copyright", "credits" or...
2
by: Jorgen Grahn | last post by:
I'm sitting here with a Debian Linux 'Woody' system with the default Python 2.2 installation, and I want the re module to understand that re.compile(r'\W+'. re.LOCALE) doesn't match my national,...
4
by: Timothy Smith | last post by:
i'm trying to setlocale() on 4.10, and it appears the python package doesn't support this under 4.10. Python 2.3.3 (#2, Apr 28 2004, 22:48:37) ] on freebsd4 Type "help", "copyright", "credits"...
10
by: Timothy Smith | last post by:
hi there i need to set my locale so that when i output a number it's formatted with thousands grouped. the problem i've found is there doesn't seem to be very good cross platform support for...
3
by: Torsten Bronger | last post by:
Hallöchen! I have to generate excerpts in different human languages in a program. In general, the language is not the locale's language, but set at runtime. Nevertheless, GNU's gettext should...
3
by: gelbeiche | last post by:
I have a question regarding the following small C program. #include <locale.h> int main() { char* loc = 0; char before,after; int i;
7
by: Ralf Goertz | last post by:
Hi, since my previous post <455440ad$0$30326$9b4e6d93@newsspool1.arcor-online.netis still unanswered I'd like to rephrase my question. In order to read/write a wstring in UTF-8 encoding it is...
2
by: Daniele C. | last post by:
I will report a snippet from http://php.net/setlocale I spent about 2 seconds before thinking: can it really be? I mean, is there no way to set locale info per thread? And after a brief web...
33
by: Simon Brooke | last post by:
I'm working on a system which uses Google maps. I want the user to see a map of more or less where (s)he is in the world when (s)he first comes to the system. So the obvious thing seemed to be to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.