Notes on the locale implementation.

prepared by Benjamin Kosnik (bkoz@redhat.com) on October 14, 2002

1. Abstract

Describes the basic locale object, including nested classes id, facet, and the reference-counted implementation object, class _Impl.

2. What the standard says

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 objects that can be used to query for the thousands separator is in the German locale.

Literally, a facet is strictly defined:

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.

3. Interacting with "C" locales.

Some help on determining the underlying support for locales on a system. Note, this is specific to linux (and glibc-2.3.x)

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* viceversa, 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.

4. Design

The major design challenge is fitting an object-orientated and non-global locale design ontop of POSIX and other relevant stanards, which include the Single Unix (nee X/Open.)

Because POSIX falls down so completely, portibility is an issue.

class _Impl The internal representation of the std::locale object.

5. Examples

More information can be found in the following testcases:

6. Unresolved Issues

7. Acknowledgments

8. Bibliography / Referenced Documents

Drepper, Ulrich, GNU libc (glibc) 2.2 manual. In particular, Chapters "6. Character Set Handling" and "7 Locales and Internationalization"

Drepper, Ulrich, Numerous, late-night email correspondence

ISO/IEC 14882:1998 Programming languages - C++

ISO/IEC 9899:1999 Programming languages - C

Langer, Angelika and Klaus Kreft, Standard C++ IOStreams and Locales, Advanced Programmer's Guide and Reference, Addison Wesley Longman, Inc. 2000

Stroustrup, Bjarne, Appendix D, The C++ Programming Language, Special Edition, Addison Wesley, Inc. 2000

System Interface Definitions, Issue 6 (IEEE Std. 1003.1-200x) The Open Group/The Institute of Electrical and Electronics Engineers, Inc. http://www.opennc.org/austin/docreg.html