localeISO C++locale
Describes the basic locale object, including nested
classes id, facet, and the reference-counted implementation object,
class _Impl.
Requirements
Class locale is non-templatized and has two distinct types nested
inside of it:
class facet
22.1.1.1.2 Class locale::facet
Facets actually implement locale functionality. For instance, a facet
called numpunct is the data object that can be used to query for the
thousands separator in the locale.
Literally, a facet is strictly defined:
Containing the following public data member:
static locale::id id;
Derived from another facet:
class gnu_codecvt: public std::ctype<user-defined-type>
Of interest in this class are the memory management options explicitly
specified as an argument to facet's constructor. Each constructor of a
facet class takes a std::size_t __refs argument: if __refs == 0, the
facet is deleted when the locale containing it is destroyed. If __refs
== 1, the facet is not destroyed, even when it is no longer
referenced.
class id
22.1.1.1.3 - Class locale::id
Provides an index for looking up specific facets.
Design
The major design challenge is fitting an object-orientated and
non-global locale design on top of POSIX and other relevant standards,
which include the Single Unix (nee X/Open.)
Because C and earlier versions of POSIX fall down so completely,
portability is an issue.
ImplementationInteracting with "C" localeslocale -a displays available locales.
From Josuttis, p. 697-698, which says, that "there is only *one*
relation (of the C++ locale mechanism) to the C locale mechanism: the
global C locale is modified if a named C++ locale object is set as the
global locale" (emphasis Paolo), that is:
std::locale::global(std::locale(""));affects the C functions as if the following call was made:std::setlocale(LC_ALL, "");
On the other hand, there is *no* vice versa, that is, calling
setlocale has *no* whatsoever on the C++ locale mechanism, in
particular on the working of locale(""), which constructs the locale
object from the environment of the running program, that is, in
practice, the set of LC_ALL, LANG, etc. variable of the shell.
Future
Locale initialization: at what point does _S_classic, _S_global
get initialized? Can named locales assume this initialization
has already taken place?
Document how named locales error check when filling data
members. I.e., a fr_FR locale that doesn't have
numpunct::truename(): does it use "true"? Or is it a blank
string? What's the convention?
Explain how locale aliasing happens. When does "de_DE" use "de"
information? What is the rule for locales composed of just an
ISO language code (say, "de") and locales with both an ISO
language code and ISO country code (say, "de_DE").
What should non-required facet instantiations do? If the
generic implementation is provided, then how to end-users
provide specializations?
Bibliography
The GNU C Library
McGrathRolandDrepperUlrich2007FSF
Chapters 6 Character Set Handling and 7 Locales and
Internationalization
Correspondence
DrepperUlrich2002
ISO/IEC 14882:1998 Programming languages - C++
1998ISO
ISO/IEC 9899:1999 Programming languages - C
1999ISO
System Interface Definitions, Issue 7 (IEEE Std. 1003.1-2008)
2008
The Open Group/The Institute of Electrical and Electronics
Engineers, Inc.
The C++ Programming Language, Special Edition
StroustrupBjarne2000Addison Wesley, Inc.Appendix D
Addison Wesley
Standard C++ IOStreams and Locales
Advanced Programmer's Guide and Reference
LangerAngelikaKreftKlaus2000Addison Wesley Longman, Inc.
Addison Wesley Longman