<?xml version="1.0" encoding="ISO-8859-1"?><!DOCTYPE htmlPUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><meta name="AUTHOR" content="bkoz@redhat.com (Benjamin Kosnik)" /><meta name="KEYWORDS" content="HOWTO, libstdc++, locale name LC_ALL" /><meta name="DESCRIPTION" content="Notes on the locale implementation." /><title>Notes on the locale implementation.</title><link rel="StyleSheet" href="../lib3styles.css" type="text/css" /><link rel="Start" href="../documentation.html" type="text/html"title="GNU C++ Standard Library" /><link rel="Bookmark" href="howto.html" type="text/html" title="Localization" /><link rel="Copyright" href="../17_intro/license.html" type="text/html" /><link rel="Help" href="../faq/index.html" type="text/html" title="F.A.Q." /></head><body><h1>Notes on the locale implementation.</h1><em>prepared by Benjamin Kosnik (bkoz@redhat.com) on October 14, 2002</em><h2>1. Abstract</h2><p>Describes the basic locale object, including nestedclasses id, facet, and the reference-counted implementation object,class _Impl.</p><h2>2. What the standard says</h2>Class locale is non-templatized and has two distinct types nestedinside of it:<blockquote><em>class facet22.1.1.1.2 Class locale::facet</em></blockquote><p>Facets actually implement locale functionality. For instance, a facetcalled numpunct is the data objects that can be used to query for thethousands separator is in the German locale.</p>Literally, a facet is strictly defined:<ul><li>containing the following public data member:<p><code>static locale::id id;</code></p></li><li>derived from another facet:<p><code> class gnu_codecvt: public std::ctype<user-defined-type></code></p></li></ul><p>Of interest in this class are the memory management options explicitlyspecified as an argument to facet's constructor. Each constructor of afacet class takes a std::size_t __refs argument: if __refs == 0, thefacet is deleted when the locale containing it is destroyed. If __refs== 1, the facet is not destroyed, even when it is no longerreferenced.</p><blockquote><em>class id22.1.1.1.3 - Class locale::id</em></blockquote><p>Provides an index for looking up specific facets.</p><h2>3. Interacting with "C" locales.</h2><p>Some help on determining the underlying support for locales on a system.Note, this is specific to linux (and glibc-2.3.x)</p><ul><li> <code>`locale -a`</code> displays available locales.<blockquote><pre>af_ZAar_AEar_AE.utf8ar_BHar_BH.utf8ar_DZar_DZ.utf8ar_EGar_EG.utf8ar_INar_IQar_IQ.utf8ar_JOar_JO.utf8ar_KWar_KW.utf8ar_LBar_LB.utf8ar_LYar_LY.utf8ar_MAar_MA.utf8ar_OMar_OM.utf8ar_QAar_QA.utf8ar_SAar_SA.utf8ar_SDar_SD.utf8ar_SYar_SY.utf8ar_TNar_TN.utf8ar_YEar_YE.utf8be_BYbe_BY.utf8bg_BGbg_BG.utf8br_FRbs_BACca_ESca_ES@euroca_ES.utf8ca_ES.utf8@eurocs_CZcs_CZ.utf8cy_GBda_DKda_DK.iso885915da_DK.utf8de_ATde_AT@eurode_AT.utf8de_AT.utf8@eurode_BEde_BE@eurode_BE.utf8de_BE.utf8@eurode_CHde_CH.utf8de_DEde_DE@eurode_DE.utf8de_DE.utf8@eurode_LUde_LU@eurode_LU.utf8de_LU.utf8@euroel_GRel_GR.utf8en_AUen_AU.utf8en_BWen_BW.utf8en_CAen_CA.utf8en_DKen_DK.utf8en_GBen_GB.iso885915en_GB.utf8en_HKen_HK.utf8en_IEen_IE@euroen_IE.utf8en_IE.utf8@euroen_INen_NZen_NZ.utf8en_PHen_PH.utf8en_SGen_SG.utf8en_USen_US.iso885915en_US.utf8en_ZAen_ZA.utf8en_ZWen_ZW.utf8es_ARes_AR.utf8es_BOes_BO.utf8es_CLes_CL.utf8es_COes_CO.utf8es_CRes_CR.utf8es_DOes_DO.utf8es_ECes_EC.utf8es_ESes_ES@euroes_ES.utf8es_ES.utf8@euroes_GTes_GT.utf8es_HNes_HN.utf8es_MXes_MX.utf8es_NIes_NI.utf8es_PAes_PA.utf8es_PEes_PE.utf8es_PRes_PR.utf8es_PYes_PY.utf8es_SVes_SV.utf8es_USes_US.utf8es_UYes_UY.utf8es_VEes_VE.utf8et_EEet_EE.utf8eu_ESeu_ES@euroeu_ES.utf8eu_ES.utf8@eurofa_IRfi_FIfi_FI@eurofi_FI.utf8fi_FI.utf8@eurofo_FOfo_FO.utf8fr_BEfr_BE@eurofr_BE.utf8fr_BE.utf8@eurofr_CAfr_CA.utf8fr_CHfr_CH.utf8fr_FRfr_FR@eurofr_FR.utf8fr_FR.utf8@eurofr_LUfr_LU@eurofr_LU.utf8fr_LU.utf8@euroga_IEga_IE@euroga_IE.utf8ga_IE.utf8@eurogl_ESgl_ES@eurogl_ES.utf8gl_ES.utf8@eurogv_GBgv_GB.utf8he_ILhe_IL.utf8hi_INhr_HRhr_HR.utf8hu_HUhu_HU.utf8id_IDid_ID.utf8is_ISis_IS.utf8it_CHit_CH.utf8it_ITit_IT@euroit_IT.utf8it_IT.utf8@euroiw_ILiw_IL.utf8ja_JP.eucjpja_JP.utf8ka_GEkl_GLkl_GL.utf8ko_KR.euckrko_KR.utf8kw_GBkw_GB.utf8lt_LTlt_LT.utf8lv_LVlv_LV.utf8mi_NZmk_MKmk_MK.utf8mr_INms_MYms_MY.utf8mt_MTmt_MT.utf8nl_BEnl_BE@euronl_BE.utf8nl_BE.utf8@euronl_NLnl_NL@euronl_NL.utf8nl_NL.utf8@euronn_NOnn_NO.utf8no_NOno_NO.utf8oc_FRpl_PLpl_PL.utf8POSIXpt_BRpt_BR.utf8pt_PTpt_PT@europt_PT.utf8pt_PT.utf8@euroro_ROro_RO.utf8ru_RUru_RU.koi8rru_RU.utf8ru_UAru_UA.utf8se_NOsk_SKsk_SK.utf8sl_SIsl_SI.utf8sq_ALsq_AL.utf8sr_YUsr_YU@cyrillicsr_YU.utf8sr_YU.utf8@cyrillicsv_FIsv_FI@eurosv_FI.utf8sv_FI.utf8@eurosv_SEsv_SE.iso885915sv_SE.utf8ta_INte_INtg_TJth_THth_TH.utf8tl_PHtr_TRtr_TR.utf8uk_UAuk_UA.utf8ur_PKuz_UZvi_VNvi_VN.tcvnwa_BEwa_BE@euroyi_USzh_CNzh_CN.gb18030zh_CN.gbkzh_CN.utf8zh_HKzh_HK.utf8zh_TWzh_TW.euctwzh_TW.utf8</pre></blockquote></li><li> <code>`locale`</code> displays environmental variablesthat impact how locale("") will be deduced.<blockquote><pre>LANG=en_USLC_CTYPE="en_US"LC_NUMERIC="en_US"LC_TIME="en_US"LC_COLLATE="en_US"LC_MONETARY="en_US"LC_MESSAGES="en_US"LC_PAPER="en_US"LC_NAME="en_US"LC_ADDRESS="en_US"LC_TELEPHONE="en_US"LC_MEASUREMENT="en_US"LC_IDENTIFICATION="en_US"LC_ALL=</pre></blockquote></li></ul><p>From Josuttis, p. 697-698, which says, that "there is only *one*relation (of the C++ locale mechanism) to the C locale mechanism: theglobal C locale is modified if a named C++ locale object is set as theglobal locale" (emphasis Paolo), that is:</p><code>std::locale::global(std::locale(""));</code><p>affects the C functions as if the following call was made:</p><code>std::setlocale(LC_ALL, "");</code><p>On the other hand, there is *no* viceversa, that is, calling setlocalehas *no* whatsoever on the C++ locale mechanism, in particular on theworking of locale(""), which constructs the locale object from theenvironment of the running program, that is, in practice, the set ofLC_ALL, LANG, etc. variable of the shell.</p><h2>4. Design</h2><p>The major design challenge is fitting an object-orientated andnon-global locale design ontop of POSIX and other relevant stanards,which include the Single Unix (nee X/Open.)</p><p>Because POSIX falls down so completely, portibility is an issue.</p>class _ImplThe internal representation of the std::locale object.<h2>5. Examples</h2>More information can be found in the following testcases:<ul><li> testsuite/22_locale/all </li></ul><h2>6. Unresolved Issues</h2><ul><li> locale initialization: at what point does _S_classic,_S_global get initialized? Can named locales assume thisinitialization has already taken place? </li><li> document how named locales error check when filling datamembers. Ie, a fr_FR locale that doesn't havenumpunct::truename(): does it use "true"? Or is it a blankstring? What's the convention? </li><li> explain how locale aliasing happens. When does "de_DE"use "de" information? What is the rule for locales composed ofjust an ISO language code (say, "de") and locales with both anISO language code and ISO country code (say, "de_DE"). </li><li> what should non-required facet instantiations do? If thegeneric implemenation is provided, then how to end-usersprovide specializations? </li></ul><h2>7. Acknowledgments</h2><h2>8. Bibliography / Referenced Documents</h2>Drepper, Ulrich, GNU libc (glibc) 2.2 manual. In particular, Chapters "6. Character Set Handling" and "7 Locales and Internationalization"<p>Drepper, Ulrich, Numerous, late-night email correspondence</p><p>ISO/IEC 14882:1998 Programming languages - C++</p><p>ISO/IEC 9899:1999 Programming languages - C</p><p>Langer, Angelika and Klaus Kreft, Standard C++ IOStreams and Locales, Advanced Programmer's Guide and Reference, Addison Wesley Longman, Inc. 2000</p><p>Stroustrup, Bjarne, Appendix D, The C++ Programming Language, Special Edition, Addison Wesley, Inc. 2000</p><p>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</p></body></html>