xref: /netbsd-src/external/gpl3/gcc.old/dist/libstdc++-v3/doc/xml/manual/locale.xml (revision b7b7574d3bf8eeb51a1fa3977b59142ec6434a55)
1<section id="std.localization.locales.locale" xreflabel="Locale">
2
3<sectioninfo>
4  <keywordset>
5    <keyword>
6      ISO C++
7    </keyword>
8    <keyword>
9      locale
10    </keyword>
11  </keywordset>
12</sectioninfo>
13
14<title>locale</title>
15
16<para>
17Describes the basic locale object, including nested
18classes id, facet, and the reference-counted implementation object,
19class _Impl.
20</para>
21
22<section id="locales.locale.req">
23<title>Requirements</title>
24
25<para>
26Class locale is non-templatized and has two distinct types nested
27inside of it:
28</para>
29
30<blockquote>
31<para>
32<emphasis>
33class facet
3422.1.1.1.2 Class locale::facet
35</emphasis>
36</para>
37</blockquote>
38
39<para>
40Facets actually implement locale functionality. For instance, a facet
41called numpunct is the data object that can be used to query for the
42thousands separator in the locale.
43</para>
44
45<para>
46Literally, a facet is strictly defined:
47</para>
48
49<itemizedlist>
50  <listitem>
51    <para>
52      Containing the following public data member:
53    </para>
54    <para>
55      <code>static locale::id id;</code>
56    </para>
57  </listitem>
58
59  <listitem>
60    <para>
61      Derived from another facet:
62    </para>
63    <para>
64      <code>class gnu_codecvt: public std::ctype&lt;user-defined-type&gt;</code>
65    </para>
66  </listitem>
67</itemizedlist>
68
69<para>
70Of interest in this class are the memory management options explicitly
71specified as an argument to facet's constructor. Each constructor of a
72facet class takes a std::size_t __refs argument: if __refs == 0, the
73facet is deleted when the locale containing it is destroyed. If __refs
74== 1, the facet is not destroyed, even when it is no longer
75referenced.
76</para>
77
78<blockquote>
79<para>
80<emphasis>
81class id
8222.1.1.1.3 - Class locale::id
83</emphasis>
84</para>
85</blockquote>
86
87<para>
88Provides an index for looking up specific facets.
89</para>
90</section>
91
92<section id="locales.locale.design">
93<title>Design</title>
94
95<para>
96The major design challenge is fitting an object-orientated and
97non-global locale design on top of POSIX and other relevant standards,
98which include the Single Unix (nee X/Open.)
99</para>
100
101<para>
102Because C and earlier versions of POSIX fall down so completely,
103portability is an issue.
104</para>
105
106</section>
107
108<section id="locales.locale.impl">
109<title>Implementation</title>
110
111  <section id="locale.impl.c">
112    <title>Interacting with &quot;C&quot; locales</title>
113
114<itemizedlist>
115   <listitem>
116     <para>
117       <code>`locale -a`</code> displays available locales.
118     </para>
119<blockquote>
120<programlisting>
121af_ZA
122ar_AE
123ar_AE.utf8
124ar_BH
125ar_BH.utf8
126ar_DZ
127ar_DZ.utf8
128ar_EG
129ar_EG.utf8
130ar_IN
131ar_IQ
132ar_IQ.utf8
133ar_JO
134ar_JO.utf8
135ar_KW
136ar_KW.utf8
137ar_LB
138ar_LB.utf8
139ar_LY
140ar_LY.utf8
141ar_MA
142ar_MA.utf8
143ar_OM
144ar_OM.utf8
145ar_QA
146ar_QA.utf8
147ar_SA
148ar_SA.utf8
149ar_SD
150ar_SD.utf8
151ar_SY
152ar_SY.utf8
153ar_TN
154ar_TN.utf8
155ar_YE
156ar_YE.utf8
157be_BY
158be_BY.utf8
159bg_BG
160bg_BG.utf8
161br_FR
162bs_BA
163C
164ca_ES
165ca_ES@euro
166ca_ES.utf8
167ca_ES.utf8@euro
168cs_CZ
169cs_CZ.utf8
170cy_GB
171da_DK
172da_DK.iso885915
173da_DK.utf8
174de_AT
175de_AT@euro
176de_AT.utf8
177de_AT.utf8@euro
178de_BE
179de_BE@euro
180de_BE.utf8
181de_BE.utf8@euro
182de_CH
183de_CH.utf8
184de_DE
185de_DE@euro
186de_DE.utf8
187de_DE.utf8@euro
188de_LU
189de_LU@euro
190de_LU.utf8
191de_LU.utf8@euro
192el_GR
193el_GR.utf8
194en_AU
195en_AU.utf8
196en_BW
197en_BW.utf8
198en_CA
199en_CA.utf8
200en_DK
201en_DK.utf8
202en_GB
203en_GB.iso885915
204en_GB.utf8
205en_HK
206en_HK.utf8
207en_IE
208en_IE@euro
209en_IE.utf8
210en_IE.utf8@euro
211en_IN
212en_NZ
213en_NZ.utf8
214en_PH
215en_PH.utf8
216en_SG
217en_SG.utf8
218en_US
219en_US.iso885915
220en_US.utf8
221en_ZA
222en_ZA.utf8
223en_ZW
224en_ZW.utf8
225es_AR
226es_AR.utf8
227es_BO
228es_BO.utf8
229es_CL
230es_CL.utf8
231es_CO
232es_CO.utf8
233es_CR
234es_CR.utf8
235es_DO
236es_DO.utf8
237es_EC
238es_EC.utf8
239es_ES
240es_ES@euro
241es_ES.utf8
242es_ES.utf8@euro
243es_GT
244es_GT.utf8
245es_HN
246es_HN.utf8
247es_MX
248es_MX.utf8
249es_NI
250es_NI.utf8
251es_PA
252es_PA.utf8
253es_PE
254es_PE.utf8
255es_PR
256es_PR.utf8
257es_PY
258es_PY.utf8
259es_SV
260es_SV.utf8
261es_US
262es_US.utf8
263es_UY
264es_UY.utf8
265es_VE
266es_VE.utf8
267et_EE
268et_EE.utf8
269eu_ES
270eu_ES@euro
271eu_ES.utf8
272eu_ES.utf8@euro
273fa_IR
274fi_FI
275fi_FI@euro
276fi_FI.utf8
277fi_FI.utf8@euro
278fo_FO
279fo_FO.utf8
280fr_BE
281fr_BE@euro
282fr_BE.utf8
283fr_BE.utf8@euro
284fr_CA
285fr_CA.utf8
286fr_CH
287fr_CH.utf8
288fr_FR
289fr_FR@euro
290fr_FR.utf8
291fr_FR.utf8@euro
292fr_LU
293fr_LU@euro
294fr_LU.utf8
295fr_LU.utf8@euro
296ga_IE
297ga_IE@euro
298ga_IE.utf8
299ga_IE.utf8@euro
300gl_ES
301gl_ES@euro
302gl_ES.utf8
303gl_ES.utf8@euro
304gv_GB
305gv_GB.utf8
306he_IL
307he_IL.utf8
308hi_IN
309hr_HR
310hr_HR.utf8
311hu_HU
312hu_HU.utf8
313id_ID
314id_ID.utf8
315is_IS
316is_IS.utf8
317it_CH
318it_CH.utf8
319it_IT
320it_IT@euro
321it_IT.utf8
322it_IT.utf8@euro
323iw_IL
324iw_IL.utf8
325ja_JP.eucjp
326ja_JP.utf8
327ka_GE
328kl_GL
329kl_GL.utf8
330ko_KR.euckr
331ko_KR.utf8
332kw_GB
333kw_GB.utf8
334lt_LT
335lt_LT.utf8
336lv_LV
337lv_LV.utf8
338mi_NZ
339mk_MK
340mk_MK.utf8
341mr_IN
342ms_MY
343ms_MY.utf8
344mt_MT
345mt_MT.utf8
346nl_BE
347nl_BE@euro
348nl_BE.utf8
349nl_BE.utf8@euro
350nl_NL
351nl_NL@euro
352nl_NL.utf8
353nl_NL.utf8@euro
354nn_NO
355nn_NO.utf8
356no_NO
357no_NO.utf8
358oc_FR
359pl_PL
360pl_PL.utf8
361POSIX
362pt_BR
363pt_BR.utf8
364pt_PT
365pt_PT@euro
366pt_PT.utf8
367pt_PT.utf8@euro
368ro_RO
369ro_RO.utf8
370ru_RU
371ru_RU.koi8r
372ru_RU.utf8
373ru_UA
374ru_UA.utf8
375se_NO
376sk_SK
377sk_SK.utf8
378sl_SI
379sl_SI.utf8
380sq_AL
381sq_AL.utf8
382sr_YU
383sr_YU@cyrillic
384sr_YU.utf8
385sr_YU.utf8@cyrillic
386sv_FI
387sv_FI@euro
388sv_FI.utf8
389sv_FI.utf8@euro
390sv_SE
391sv_SE.iso885915
392sv_SE.utf8
393ta_IN
394te_IN
395tg_TJ
396th_TH
397th_TH.utf8
398tl_PH
399tr_TR
400tr_TR.utf8
401uk_UA
402uk_UA.utf8
403ur_PK
404uz_UZ
405vi_VN
406vi_VN.tcvn
407wa_BE
408wa_BE@euro
409yi_US
410zh_CN
411zh_CN.gb18030
412zh_CN.gbk
413zh_CN.utf8
414zh_HK
415zh_HK.utf8
416zh_TW
417zh_TW.euctw
418zh_TW.utf8
419</programlisting>
420</blockquote>
421</listitem>
422
423   <listitem>
424     <para>
425       <code>`locale`</code> displays environmental variables that
426       impact how locale("") will be deduced.
427     </para>
428<blockquote>
429<programlisting>
430LANG=en_US
431LC_CTYPE="en_US"
432LC_NUMERIC="en_US"
433LC_TIME="en_US"
434LC_COLLATE="en_US"
435LC_MONETARY="en_US"
436LC_MESSAGES="en_US"
437LC_PAPER="en_US"
438LC_NAME="en_US"
439LC_ADDRESS="en_US"
440LC_TELEPHONE="en_US"
441LC_MEASUREMENT="en_US"
442LC_IDENTIFICATION="en_US"
443LC_ALL=
444</programlisting>
445</blockquote>
446</listitem>
447</itemizedlist>
448
449<para>
450From Josuttis, p. 697-698, which says, that "there is only *one*
451relation (of the C++ locale mechanism) to the C locale mechanism: the
452global C locale is modified if a named C++ locale object is set as the
453global locale" (emphasis Paolo), that is:
454</para>
455
456<programlisting>std::locale::global(std::locale(""));</programlisting>
457
458<para>affects the C functions as if the following call was made:</para>
459
460<programlisting>std::setlocale(LC_ALL, "");</programlisting>
461
462<para>
463  On the other hand, there is *no* vice versa, that is, calling
464  setlocale has *no* whatsoever on the C++ locale mechanism, in
465  particular on the working of locale(""), which constructs the locale
466  object from the environment of the running program, that is, in
467  practice, the set of LC_ALL, LANG, etc. variable of the shell.
468</para>
469
470  </section>
471</section>
472
473<section id="locales.locale.future">
474<title>Future</title>
475
476<itemizedlist>
477   <listitem>
478     <para>
479       Locale initialization: at what point does _S_classic, _S_global
480       get initialized? Can named locales assume this initialization
481       has already taken place?
482     </para>
483     </listitem>
484
485   <listitem>
486     <para>
487       Document how named locales error check when filling data
488       members. I.e., a fr_FR locale that doesn't have
489       numpunct::truename(): does it use "true"? Or is it a blank
490       string? What's the convention?
491   </para>
492   </listitem>
493
494   <listitem>
495     <para>
496       Explain how locale aliasing happens. When does "de_DE" use "de"
497       information? What is the rule for locales composed of just an
498       ISO language code (say, "de") and locales with both an ISO
499       language code and ISO country code (say, "de_DE").
500     </para>
501   </listitem>
502
503   <listitem>
504     <para>
505       What should non-required facet instantiations do?  If the
506       generic implementation is provided, then how to end-users
507       provide specializations?
508   </para>
509   </listitem>
510</itemizedlist>
511</section>
512
513<bibliography id="locales.locale.biblio">
514<title>Bibliography</title>
515
516  <biblioentry>
517    <title>
518      The GNU C Library
519    </title>
520    <author>
521      <surname>McGrath</surname>
522      <firstname>Roland</firstname>
523    </author>
524    <author>
525      <surname>Drepper</surname>
526      <firstname>Ulrich</firstname>
527    </author>
528    <copyright>
529      <year>2007</year>
530      <holder>FSF</holder>
531    </copyright>
532    <pagenums>
533      Chapters 6 Character Set Handling and 7 Locales and
534      Internationalization
535    </pagenums>
536  </biblioentry>
537
538  <biblioentry>
539    <title>
540      Correspondence
541    </title>
542    <author>
543      <surname>Drepper</surname>
544      <firstname>Ulrich</firstname>
545    </author>
546    <copyright>
547      <year>2002</year>
548      <holder></holder>
549    </copyright>
550  </biblioentry>
551
552  <biblioentry>
553    <title>
554      ISO/IEC 14882:1998 Programming languages - C++
555    </title>
556    <copyright>
557      <year>1998</year>
558      <holder>ISO</holder>
559    </copyright>
560  </biblioentry>
561
562  <biblioentry>
563    <title>
564      ISO/IEC 9899:1999 Programming languages - C
565    </title>
566    <copyright>
567      <year>1999</year>
568      <holder>ISO</holder>
569    </copyright>
570  </biblioentry>
571
572  <biblioentry>
573    <biblioid class="uri">
574      <ulink url="http://www.opengroup.org/austin/">
575	<citetitle>
576	  System Interface Definitions, Issue 7 (IEEE Std. 1003.1-2008)
577	</citetitle>
578      </ulink>
579    </biblioid>
580    <copyright>
581      <year>2008</year>
582      <holder>
583	The Open Group/The Institute of Electrical and Electronics
584	Engineers, Inc.
585      </holder>
586    </copyright>
587  </biblioentry>
588
589  <biblioentry>
590    <title>
591      The C++ Programming Language, Special Edition
592    </title>
593    <author>
594      <surname>Stroustrup</surname>
595      <firstname>Bjarne</firstname>
596    </author>
597    <copyright>
598      <year>2000</year>
599      <holder>Addison Wesley, Inc.</holder>
600    </copyright>
601    <pagenums>Appendix D</pagenums>
602    <publisher>
603      <publishername>
604	Addison Wesley
605      </publishername>
606    </publisher>
607  </biblioentry>
608
609  <biblioentry>
610    <title>
611      Standard C++ IOStreams and Locales
612    </title>
613    <subtitle>
614      Advanced Programmer's Guide and Reference
615    </subtitle>
616    <author>
617      <surname>Langer</surname>
618      <firstname>Angelika</firstname>
619    </author>
620    <author>
621      <surname>Kreft</surname>
622      <firstname>Klaus</firstname>
623    </author>
624    <copyright>
625      <year>2000</year>
626      <holder>Addison Wesley Longman, Inc.</holder>
627    </copyright>
628    <publisher>
629      <publishername>
630	Addison Wesley Longman
631      </publishername>
632    </publisher>
633  </biblioentry>
634
635</bibliography>
636
637</section>
638