472,967 Members | 1,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,967 software developers and data experts.

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 1963
> 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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.