1<?xml version="1.0" encoding="ISO-8859-1"?>
2<!DOCTYPE html
3          PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
6<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7<head>
8   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
9   <meta name="AUTHOR" content="bkoz@redhat.com (Benjamin Kosnik)" />
10   <meta name="KEYWORDS" content="HOWTO, libstdc++, locale name LC_ALL" />
11   <meta name="DESCRIPTION" content="Notes on the locale implementation." />
12   <title>Notes on the locale implementation.</title>
13<link rel="StyleSheet" href="../lib3styles.css" type="text/css" />
14<link rel="Start" href="../documentation.html" type="text/html"
15  title="GNU C++ Standard Library" />
16<link rel="Bookmark" href="howto.html" type="text/html" title="Localization" />
17<link rel="Copyright" href="../17_intro/license.html" type="text/html" />
18<link rel="Help" href="../faq/index.html" type="text/html" title="F.A.Q." />
19</head>
20<body>
21  <h1>
22  Notes on the locale implementation.
23  </h1>
24<em>
25prepared by Benjamin Kosnik (bkoz@redhat.com) on October 14, 2002
26</em>
27
28<h2>
291. Abstract
30</h2>
31<p>
32Describes the basic locale object, including nested
33classes id, facet, and the reference-counted implementation object,
34class _Impl.
35</p>
36
37<h2>
382. What the standard says
39</h2>
40Class locale is non-templatized and has two distinct types nested
41inside of it:
42
43<blockquote>
44<em>
45class facet
4622.1.1.1.2 Class locale::facet
47</em>
48</blockquote>
49
50<p>
51Facets actually implement locale functionality. For instance, a facet
52called numpunct is the data objects that can be used to query for the
53thousands separator is in the German locale.
54</p>
55
56Literally, a facet is strictly defined:
57<ul>
58  <li>containing the following public data member:
59  <p>
60  <code>static locale::id id;</code>
61  </p>
62  </li>
63
64  <li>derived from another facet:
65  <p>
66  <code> class gnu_codecvt: public std::ctype&lt;user-defined-type&gt;</code>
67  </p>
68  </li>
69</ul>
70
71<p>
72Of interest in this class are the memory management options explicitly
73specified as an argument to facet's constructor. Each constructor of a
74facet class takes a std::size_t __refs argument: if __refs == 0, the
75facet is deleted when the locale containing it is destroyed. If __refs
76== 1, the facet is not destroyed, even when it is no longer
77referenced.
78</p>
79
80<blockquote>
81<em>
82class id
8322.1.1.1.3 - Class locale::id
84</em>
85</blockquote>
86
87<p>
88Provides an index for looking up specific facets.
89</p>
90
91
92<h2>
933. Interacting with &quot;C&quot; locales.
94</h2>
95
96<p>
97Some help on determining the underlying support for locales on a system.
98Note, this is specific to linux (and glibc-2.3.x)
99</p>
100
101<ul>
102   <li> <code>`locale -a`</code> displays available locales.
103<blockquote>
104<pre>
105af_ZA
106ar_AE
107ar_AE.utf8
108ar_BH
109ar_BH.utf8
110ar_DZ
111ar_DZ.utf8
112ar_EG
113ar_EG.utf8
114ar_IN
115ar_IQ
116ar_IQ.utf8
117ar_JO
118ar_JO.utf8
119ar_KW
120ar_KW.utf8
121ar_LB
122ar_LB.utf8
123ar_LY
124ar_LY.utf8
125ar_MA
126ar_MA.utf8
127ar_OM
128ar_OM.utf8
129ar_QA
130ar_QA.utf8
131ar_SA
132ar_SA.utf8
133ar_SD
134ar_SD.utf8
135ar_SY
136ar_SY.utf8
137ar_TN
138ar_TN.utf8
139ar_YE
140ar_YE.utf8
141be_BY
142be_BY.utf8
143bg_BG
144bg_BG.utf8
145br_FR
146bs_BA
147C
148ca_ES
149ca_ES@euro
150ca_ES.utf8
151ca_ES.utf8@euro
152cs_CZ
153cs_CZ.utf8
154cy_GB
155da_DK
156da_DK.iso885915
157da_DK.utf8
158de_AT
159de_AT@euro
160de_AT.utf8
161de_AT.utf8@euro
162de_BE
163de_BE@euro
164de_BE.utf8
165de_BE.utf8@euro
166de_CH
167de_CH.utf8
168de_DE
169de_DE@euro
170de_DE.utf8
171de_DE.utf8@euro
172de_LU
173de_LU@euro
174de_LU.utf8
175de_LU.utf8@euro
176el_GR
177el_GR.utf8
178en_AU
179en_AU.utf8
180en_BW
181en_BW.utf8
182en_CA
183en_CA.utf8
184en_DK
185en_DK.utf8
186en_GB
187en_GB.iso885915
188en_GB.utf8
189en_HK
190en_HK.utf8
191en_IE
192en_IE@euro
193en_IE.utf8
194en_IE.utf8@euro
195en_IN
196en_NZ
197en_NZ.utf8
198en_PH
199en_PH.utf8
200en_SG
201en_SG.utf8
202en_US
203en_US.iso885915
204en_US.utf8
205en_ZA
206en_ZA.utf8
207en_ZW
208en_ZW.utf8
209es_AR
210es_AR.utf8
211es_BO
212es_BO.utf8
213es_CL
214es_CL.utf8
215es_CO
216es_CO.utf8
217es_CR
218es_CR.utf8
219es_DO
220es_DO.utf8
221es_EC
222es_EC.utf8
223es_ES
224es_ES@euro
225es_ES.utf8
226es_ES.utf8@euro
227es_GT
228es_GT.utf8
229es_HN
230es_HN.utf8
231es_MX
232es_MX.utf8
233es_NI
234es_NI.utf8
235es_PA
236es_PA.utf8
237es_PE
238es_PE.utf8
239es_PR
240es_PR.utf8
241es_PY
242es_PY.utf8
243es_SV
244es_SV.utf8
245es_US
246es_US.utf8
247es_UY
248es_UY.utf8
249es_VE
250es_VE.utf8
251et_EE
252et_EE.utf8
253eu_ES
254eu_ES@euro
255eu_ES.utf8
256eu_ES.utf8@euro
257fa_IR
258fi_FI
259fi_FI@euro
260fi_FI.utf8
261fi_FI.utf8@euro
262fo_FO
263fo_FO.utf8
264fr_BE
265fr_BE@euro
266fr_BE.utf8
267fr_BE.utf8@euro
268fr_CA
269fr_CA.utf8
270fr_CH
271fr_CH.utf8
272fr_FR
273fr_FR@euro
274fr_FR.utf8
275fr_FR.utf8@euro
276fr_LU
277fr_LU@euro
278fr_LU.utf8
279fr_LU.utf8@euro
280ga_IE
281ga_IE@euro
282ga_IE.utf8
283ga_IE.utf8@euro
284gl_ES
285gl_ES@euro
286gl_ES.utf8
287gl_ES.utf8@euro
288gv_GB
289gv_GB.utf8
290he_IL
291he_IL.utf8
292hi_IN
293hr_HR
294hr_HR.utf8
295hu_HU
296hu_HU.utf8
297id_ID
298id_ID.utf8
299is_IS
300is_IS.utf8
301it_CH
302it_CH.utf8
303it_IT
304it_IT@euro
305it_IT.utf8
306it_IT.utf8@euro
307iw_IL
308iw_IL.utf8
309ja_JP.eucjp
310ja_JP.utf8
311ka_GE
312kl_GL
313kl_GL.utf8
314ko_KR.euckr
315ko_KR.utf8
316kw_GB
317kw_GB.utf8
318lt_LT
319lt_LT.utf8
320lv_LV
321lv_LV.utf8
322mi_NZ
323mk_MK
324mk_MK.utf8
325mr_IN
326ms_MY
327ms_MY.utf8
328mt_MT
329mt_MT.utf8
330nl_BE
331nl_BE@euro
332nl_BE.utf8
333nl_BE.utf8@euro
334nl_NL
335nl_NL@euro
336nl_NL.utf8
337nl_NL.utf8@euro
338nn_NO
339nn_NO.utf8
340no_NO
341no_NO.utf8
342oc_FR
343pl_PL
344pl_PL.utf8
345POSIX
346pt_BR
347pt_BR.utf8
348pt_PT
349pt_PT@euro
350pt_PT.utf8
351pt_PT.utf8@euro
352ro_RO
353ro_RO.utf8
354ru_RU
355ru_RU.koi8r
356ru_RU.utf8
357ru_UA
358ru_UA.utf8
359se_NO
360sk_SK
361sk_SK.utf8
362sl_SI
363sl_SI.utf8
364sq_AL
365sq_AL.utf8
366sr_YU
367sr_YU@cyrillic
368sr_YU.utf8
369sr_YU.utf8@cyrillic
370sv_FI
371sv_FI@euro
372sv_FI.utf8
373sv_FI.utf8@euro
374sv_SE
375sv_SE.iso885915
376sv_SE.utf8
377ta_IN
378te_IN
379tg_TJ
380th_TH
381th_TH.utf8
382tl_PH
383tr_TR
384tr_TR.utf8
385uk_UA
386uk_UA.utf8
387ur_PK
388uz_UZ
389vi_VN
390vi_VN.tcvn
391wa_BE
392wa_BE@euro
393yi_US
394zh_CN
395zh_CN.gb18030
396zh_CN.gbk
397zh_CN.utf8
398zh_HK
399zh_HK.utf8
400zh_TW
401zh_TW.euctw
402zh_TW.utf8
403</pre>
404</blockquote>
405</li>
406
407   <li> <code>`locale`</code> displays environmental variables
408   that impact how locale("") will be deduced.
409
410<blockquote>
411<pre>
412LANG=en_US
413LC_CTYPE="en_US"
414LC_NUMERIC="en_US"
415LC_TIME="en_US"
416LC_COLLATE="en_US"
417LC_MONETARY="en_US"
418LC_MESSAGES="en_US"
419LC_PAPER="en_US"
420LC_NAME="en_US"
421LC_ADDRESS="en_US"
422LC_TELEPHONE="en_US"
423LC_MEASUREMENT="en_US"
424LC_IDENTIFICATION="en_US"
425LC_ALL=
426</pre>
427</blockquote>
428</li>
429</ul>
430
431<p>
432From Josuttis, p. 697-698, which says, that "there is only *one*
433relation (of the C++ locale mechanism) to the C locale mechanism: the
434global C locale is modified if a named C++ locale object is set as the
435global locale" (emphasis Paolo), that is:
436</p>
437    <code>std::locale::global(std::locale(""));</code>
438
439<p>affects the C functions as if the following call was made:</p>
440
441    <code>std::setlocale(LC_ALL, "");</code>
442
443<p>
444On the other hand, there is *no* viceversa, that is, calling setlocale
445has *no* whatsoever on the C++ locale mechanism, in particular on the
446working of locale(""), which constructs the locale object from the
447environment of the running program, that is, in practice, the set of
448LC_ALL, LANG, etc. variable of the shell.
449</p>
450
451
452<h2>
4534. Design
454</h2>
455
456
457<p>
458The major design challenge is fitting an object-orientated and
459non-global locale design ontop of POSIX and other relevant stanards,
460which include the Single Unix (nee X/Open.)
461</p>
462
463<p>
464Because POSIX falls down so completely, portibility is an issue.
465</p>
466
467class _Impl
468The internal representation of the std::locale object.
469
470
471<h2>
4725.  Examples
473</h2>
474
475More information can be found in the following testcases:
476<ul>
477<li> testsuite/22_locale/all   </li>
478</ul>
479
480<h2>
4816.  Unresolved Issues
482</h2>
483
484<ul>
485   <li> locale initialization: at what point does _S_classic,
486   _S_global get initialized? Can named locales assume this
487   initialization has already taken place? </li>
488
489   <li> document how named locales error check when filling data
490   members. Ie, a fr_FR locale that doesn't have
491   numpunct::truename(): does it use "true"? Or is it a blank
492   string? What's the convention? </li>
493
494   <li> explain how locale aliasing happens. When does "de_DE"
495   use "de" information? What is the rule for locales composed of
496   just an ISO language code (say, "de") and locales with both an
497   ISO language code and ISO country code (say, "de_DE"). </li>
498
499   <li> what should non-required facet instantiations do?  If the
500   generic implemenation is provided, then how to end-users
501   provide specializations? </li>
502</ul>
503
504<h2>
5057. Acknowledgments
506</h2>
507
508<h2>
5098. Bibliography / Referenced Documents
510</h2>
511
512Drepper, Ulrich, GNU libc (glibc) 2.2 manual. In particular, Chapters &quot;6. Character Set Handling&quot; and &quot;7 Locales and Internationalization&quot;
513
514<p>
515Drepper, Ulrich, Numerous, late-night email correspondence
516</p>
517
518<p>
519ISO/IEC 14882:1998 Programming languages - C++
520</p>
521
522<p>
523ISO/IEC 9899:1999 Programming languages - C
524</p>
525
526<p>
527Langer, Angelika and Klaus Kreft, Standard C++ IOStreams and Locales, Advanced Programmer's Guide and Reference, Addison Wesley Longman, Inc. 2000
528</p>
529
530<p>
531Stroustrup, Bjarne, Appendix D, The C++ Programming Language, Special Edition, Addison Wesley, Inc. 2000
532</p>
533
534<p>
535System Interface Definitions, Issue 6 (IEEE Std. 1003.1-200x)
536The Open Group/The Institute of Electrical and Electronics Engineers, Inc.
537http://www.opennc.org/austin/docreg.html
538</p>
539
540</body>
541</html>
542
543
544