-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path73_locale.html
684 lines (599 loc) · 27.8 KB
/
73_locale.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
<!-- cribtutor-stl by NewForester is licensed under a Creative Commons Attribution-ShareAlike 4.0 International Licence. -->
<h1> Other STL Containers </h1>
<h2> Locale </h2>
<p>
Localisation is about internationalisation.
It is about producing software (applications) for use around the world.
</p>
<p>
This crib-sheet is an <em>overview</em> of the C++ locale facilities:
it does not cover all the complexities of this subject.
</p>
<!--
The author of this crib sheet has limited experience of internationalisation
and even less of localisation in C/C++.
Describing the C++ localisation when the concepts are only understood
in abstract terms has not been easy.
-->
<h3> Introduction </h3>
<p>
A <em>locale</em> is a set of parameters that define
the user's language, alphabet (character set), country and regional preferences.
Software applications use these <em>parameters</em> to adapt their handling of input and output.
</p>
<p>
locale identifiers are subject to international standardisation
but locale implementation is <em>platform</em> specific
(i.e. Microsoft does not use POSIX locales and Linux does not use Windows locales).
</p>
<p>
On <em>POSIX</em> platforms locale identifiers are defined by ISO 15897.
Their format is:
<pre>
[language[_territory][.codeset][@modifier]].
</pre>
</p>
<p />
<p>
C localisation is available in the header file <<em>clocale</em>>.
It provides 13 categories of locale parameters that may be set independently
but only one <em>global</em> locale.
</p>
<p>
C++ localisation is provided in the <<em>locale</em>> header file.
locale <em>objects</em> provide support for the 6 most important parameter categories through <em>facets</em>.
</p>
<p>
These cover:
<ol><!-- Shuffle List -->
<li> <em>formatting</em> of date/time, numeric and monetary values </li>
<li> <em>character</em> classification and conversion </li>
<li> string <em>collation</em> </li>
<li> <em>message</em> retrieval </li>
</ol>
</p>
<p>
Localisation is not <em>automatic</em>:
applications are designed and implemented with localisation in mind.
The amount of work needed depends on the degree of customisation required.
</p>
<p>
Some aspects of locale specific input and output can be a handled automatically.
In particular character set <em>conversion</em>.
</p>
<p>
In the past this meant conversion
to/from the system <em>code page</em> on output/input.
Today this generally means conversion to/from <em>Unicode</em>.
That is UTF-8 on POSIX systems and UTF-16 on Windows systems.
</p>
<p>
The <em>global</em> nature of the C locale means it affects all input and output.
The <em>object oriented</em> nature of C++ locales means that
a locale can be i/o stream specific: the locale is <em>imbued</em> in the stream.
</p>
<p>
<em>Formatting</em> manipulators, methods and flags alter how numeric values
are input and output in C++.
When imbued with a locale, their effects are altered, sometimes subtly.
</p>
<p>
Not all aspects of the locale can be handled automatically and not all aspects of input/output are stream related
(consider field based GUI/web forms).
Typcially, the details of application specific locale handling
will be <em>encapsulated</em> in custom insertion/extraction <em>operators</em>.
</p>
<p>
Since locale handling is intimately connected with stream handling,
the locale methods have <em>intricate</em> calling sequences.
</p>
<p>
The STL does not provide support for all aspects of a locale
(for example paper size)
but the locale may be customised by <em>extension</em> and <em>overlay</em>.
</p>
<p />
<p>
C/C++ provide the 'char' and 'wchar_t'
(aka narrow and wide character) types.
The first is generally adequate for <em>phonetic</em> alphabets
used by languages such as English and Russian
but the second is needed for <em>logographic</em> alphabets
used by languages such as Chinese and Japanese.
</p>
<p>
STL locale handling uses templates and provides support for both
<em>narrow</em> and <em>wide</em> character types.
With C++ 11 the 'char16_t' and 'char32_t'
provide additional support for Unicode.
</p>
<p>
Every locale object provides locale specific template <em>specialisations</em>.
The STL also provides <em>standalone</em>, locale independent,
template specialisations
that generally correspond to the default "C" locale.
</p>
<p>
The rest of this crib-sheet leaves out such <em>details</em> for the sake of clarity.
</p>
<h3> The locale Class </h3>
<p>
Localisation is provided by the <em>locale</em> class.
This may be thought of as a container for <em>facet</em><> objects.
The locale knows nothing of the capabilities of its facets.
It does not provide internationalisation services itself.
</p>
<p>
The locale contains six (standard) facet<> objects for
six categories of localisation.
<ol><!-- Shuffle List -->
<li> <em>LC_NUMERIC</em> - rules and symbols for number formatting </li>
<li> <em>LC_MONETARY</em> - rules and symbols for monetary information </li>
<li> <em>LC_TIME</em> - values for date and time information </li>
<li> <em>LC_CTYPE</em> - character classification and case conversion </li>
<li> <em>LC_COLLATE</em> - character collation sequences </li>
<li> <em>LC_MESSAGES</em> - formats and values of messages </li>
</ol>
In general, each category is implemented by more than one facet object.
</p>
<p>
The locale container design allows <em>custom</em> facets,
which can either be in addition to or instead of the standard facets.
</p>
<p>
The design also allows the same facet<> <em>objects</em> to be used
in different <em>locales</em>.
They can be retrieved and copied efficiently.
</p>
<p>
Standard locales are constructed by <em>name</em>:
<pre>
locale("De_DE");
</pre>
Names are those of C locales.
</p>
<p>
The name of C locales are <em>platform</em> dependent.
At a very minimum, the system default locale <em>""</em> and
the minimal <em>"C"</em> locale are defined.
</p>
<p>
<em>Custom</em> locales are constructed by <em>composition</em>:
<pre>
locale here (locale::classic(), locale("De_DE"), LC_NUMERIC);
</pre>
where
<pre>
locale::classic();
</pre>
returns the equivalent of the "C" locale
(which corresponds more or less to US English ASCII).
</p>
<p>
Once constructed, locale objects are <em>immutable</em>.
Copy operations are <em>cheap</em> (handle-body-idiom).
</p>
<p>
There are two template functions that operate on locale objects:
<ol><!-- Shuffle List -->
<li> <em>use_facet</em>() - retrieve a facet from a locale </li>
<li> <em>has_facet</em>() - test whether a locale has a facet </li>
</ol>
</p>
<p>
Since locales are constructed by composition,
they all contain the facets defined in the standard:
<em>has_facet</em>() is only needed when using additional <em>custom</em> facets.
</p>
<p>
Which facet is retrieved by <em>use_facet</em>() is specified
by template <em>instantiation</em> and not by parameter:
<pre>
const numpunct< char >& myfacet = use_facet < numpunct< char > > (mylocale);
myvar = myfacet.decimal_point();
</pre>
</p>
<p>
Assume the <em>reference</em> to a facet is valid until the locale object is <em>destroyed</em>.
</p>
<p>
The method:
<ol><!-- Shuffle List -->
<li> locale::<em>global</em>() </li>
</ol>
may be used to set the global C++ locale.
This also affects the C locale and may <em>break</em> third party packages
that are not locale aware.
</p>
<h3> Use of locale Objects </h3>
<p>
A locale may be <em>imbued</em> in an i/o stream as follows:
<pre>
cout.imbue(locale("ru_RU.UTF-8"));
</pre>
</p>
<p>
This may affect:
<ol><!-- Shuffle List -->
<li> character set <em>conversion</em> at a low level </li>
<li> <em>number</em> insertion and extraction </li>
<li> white space recognition during <em>extraction</em> </li>
</ol>
For example:
<pre>
// This will output 1.234.567,89 ...
double n = 1234567.89;
cout.imbue(std::locale("de_DE"));
cout << std::fixed << n << endl;
// ... and this will read it back in
istringstream de_in("1.234.567,89");
de_in.imbue(locale("de_DE"));
double f1;
de_in >> f1;
</pre>
</p>
<h3> facet Class Templates </h3>
<p>
The standard facets are:
<ol><!-- Shuffle List -->
<li> <em>time_get</em><> parses time/date values from an input character sequence into struct std::tm </li>
<li> <em>time_put</em><> formats contents of struct std::tm for output as a character sequence </li>
<li> <em>num_get</em><> parses numeric values from an input character sequence </li>
<li> <em>num_put</em><> formats numeric values for output as a character sequence </li>
<li> <em>numpunct</em><> defines punctuation characters and formatting rules for numeric values </li>
<li> <em>money_get</em><> parses a monetary value from an input character sequence </li>
<li> <em>money_put</em><> formats a monetary value for output as a character sequence </li>
<li> <em>moneypunct</em><> defines punctuation characters and formatting rules for monetary values </li>
<li> <em>ctype</em><> defines character classification tables and provides helper routines </li>
<li> <em>collate</em><> defines lexicographical comparison and hashing of strings </li>
<li> <em>messages</em><> implements retrieval of strings from message catalogues </li>
<li> <em>codecvt</em><> converts between external and internal character encodings </li>
</ol>
All have a common base class std::locale::facet<>.
</p>
<p>
For codecvt<> the first two template parameters are character types.
For all other facets, the first template parameter is a character type.
The STL provides specialisations for <em>char</em> and <em>wchar_t</em>.
</p>
<!--
Support for 'char16_t' and 'char32_t' is provided by the codecvt facet from C++ 11 onwards.
-->
<p>
The twelve facet templates above are to be used with use_facet() to retrieve facet objects from a locale object.
They define abstract interface classes with no implementation.
However, use_facet() returns references to concrete implementations instantiated using the constructor for:
<ol><!-- Shuffle List -->
<li> <em>numpunct_byname</em> instantiation of numpunct for a named locale </li>
<li> <em>moneypunct_byname</em> instantiation of moneypunct for a named locale </li>
<li> <em>time_get_byname</em> instantiation of time_get for a named locale </li>
<li> <em>time_put_byname</em> instantiation of time_put for a named locale </li>
<li> <em>ctype_byname</em> instantiation of ctype for a named locale </li>
<li> <em>collate_byname</em> instantiation of collate for a named locale </li>
<li> <em>messages_byname</em> instantiation of messages for a named locale </li>
<li> <em>codecvt_byname</em> instantiation of codecvt for a named locale </li>
</ol>
Their constructors are only of interest when constructing special purpose locale objects.
</p>
<h3> Character Conversion </h3>
<p>
The codecvt facet of the <em>LC_CTYPE</em> category encapsulates character set conversion.
Specifically between some <em>external</em> character encoding and the corresponding C++ internal 'narrow' or 'wide' character representation.
</p>
<p>
The <em>wide</em> character representations of a character requires one (typically 4 byte) wchar_t position;
The <em>narrow</em> character representations requires one or more char positions.
</p>
<p>
<em>Multi-byte</em> characters are <em>narrow</em> characters that requires more than one char position.
Variable byte encoding and state machine encoding are the two approaches used for multi-byte encoding.
</p>
<p>
The methods provided by the codecvt facet are:
<ol><!-- Shuffle List -->
<li> codecvt.<em>in</em>() convert a string from external to internal representation, such as when reading from file </li>
<li> codecvt.<em>out</em>() convert a string from internal to external representation, such as when writing to file </li>
<li> codecvt.<em>unshift</em>() generate the necessary state machine termination sequence for incomplete conversion to the external representation </li>
<li> codecvt.<em>always_noconv</em>() true if the conversion is the identity (i.e. no conversion required) </li>
<li> codecvt.<em>encoding</em>() the number of external characters needed to produce one internal character (if constant) </li>
<li> codecvt.<em>length</em>() the number of external characters that would be consumed by conversion into a given number of internal characters </li>
<li> codecvt.<em>max_length</em>() the maximum number of external characters that may be generated by the conversion of a single internal character </li>
</ol>
</p>
<p>
codecvt.encoding() returns 0 for a <em>variable byte</em> encoding and -1 for a <em>state machine</em> encoding.
</p>
<!--
C++ 11 appears to add support for Unicode as external representations and also,
through the template conversion classes wstring_convert and wbuffer_convert,
the use of Unicode as internal representations.
-->
<h3> Message Retrieval </h3>
<p>
The <em>LC_MESSAGES</em> category has a single facet that encapsulates the retrieval of strings from message catalogues.
Message catalogues support the lookup of locale specific <em>translations</em> of user interface text (such as error messages).
</p>
<p>
The <em>message</em> facet delegates to platform specific routines:
on GNU/Linux systems, message catalogues are provided by GNU <em>gettext</em> and on POSIX systems by <em>catgets</em>.
</p>
<p>
The methods provided by the message facet are:
<ol><!-- Shuffle List -->
<li> message.<em>open</em>() open a named message catalogue </li>
<li> message.<em>get</em>() retrieve a message from an open message catalogue </li>
<li> message.<em>close</em>() close a message catalogue </li>
</ol>
</p>
<p>
message.open() takes as parameters the <em>catalogue</em> name and a <em>locale</em> object.
It returns a <em>handle</em> of type catalogue that can then be used with message.get() and message.close().
</p>
<p>
The <em>catalogue</em> name is just that (probably the name of the program/application).
The file system location of catalogues is <em>platform</em> specific.
</p>
<p>
If the catalogue could not be opened the handle has a <em>negative</em> value.
Otherwise, the handle remains valid until passed to message.close().
</p>
<p>
message.close() <em>releases</em> any resources allocated to an open catalogue.
</p>
<p>
message.get() is passed <em>text</em> to translate
and returns the <em>translation</em> found in the catalogue or else a copy of the original text.
</p>
<p>
message.get() also takes two <em>platform</em> specific parameters.
On POSIX systems identify the message to be retrieved.
On GNU libstdc++ systems these parameters are <em>ignored</em> and the text is used (as a hash key ?).
</p>
<h3> String Collation </h3>
<p>
The <em>LC_COLLATE</em> category has a single facet that encapsulates locale specific string collation (comparison) and string hashing.
</p>
<p>
Collation order (as opposed to lexicographical order) is <em>dictionary</em> order:
<ol><!-- Shuffle List -->
<li> position within the alphabet takes <em>precedence</em> over case </li>
<li> lowercase <em>collates</em> before uppercase </li>
<li> locale specific order may apply to <em>diacriticals</em> </li>
<li> groups of characters may <em>compare</em> as a single collation unit </li>
</ol>
For example, in Czech 'ch' follows 'h' and precedes 'i',
while Hungarian 'dzs' follows 'dz' and precedes 'g'.
</p>
<p>
The methods provided by the collate facet are:
<ol><!-- Shuffle List -->
<li> collate.<em>compare</em>() compare two strings using dictionary order </li>
<li> collate.<em>transform</em>() transform a string so that collation can be replaced by comparison </li>
<li> collate.<em>hash</em>() generate an integer hash value using collation rules </li>
</ol>
</p>
<p>
collate.compare() compares two character <em>sequences</em> using locale collation rules.
The return value is as for <em>strcmp</em>()
with 0 indicating the two sequences are <em>equivalent</em>.
</p>
<p>
collate.transform() converts a character sequence so that
<em>operator<</em> will yield the same results on transformed strings as
collate.compare() does on the original strings (but is generally faster).
</p>
<p>
collate.hash() converts a character sequence to an <em>integer</em> hash value such that all strings that collate.compare() would consider equivalent have the same hash value
and the <em>probability</em> of two strings otherwise having the same hash value is very small.
</p>
<p>
When a locale object is passed as a comparator to an STL <em>algorithm</em>,
the locale's collate.compare() function is invoked to perform the actual comparison.
True is returned if the two strings are equivalent:
<pre>
sort(v.begin(), v.end(), locale("sv_SE.UTF-8"));
</pre>
</p>
<!-- The collate facet is used by std::basic_regex in C++ 11 and later. -->
<h3> Character Classification </h3>
<p>
The ctype facet of the <em>LC_CTYPE</em> category encapsulates character classification and conversion.
</p>
<p>
The methods provided by the ctype facet are:
<ol><!-- Shuffle List -->
<li> ctype.<em>is</em>() classify a character or a character sequence </li>
<li> ctype.<em>scan_is</em>() locate the first character in a sequence that conforms to the given classification </li>
<li> ctype.<em>scan_not</em>() locate the first character in a sequence that does not conform to the given classification </li>
<li> ctype.<em>toupper</em>() convert a character or characters to uppercase </li>
<li> ctype.<em>tolower</em>() convert a character or characters to lowercase </li>
<li> ctype.<em>widen</em>() convert a character or characters from char to 'charT' </li>
<li> ctype.<em>narrow</em>() convert a character or characters from 'charT' to char </li>
</ol>
</p>
<p>
ctype.is() has two forms.
The first takes a mask and a character as input and returns a <em>bool</em> to indicate a match.
The second takes a character <em>sequence</em> as input and returns a (character) sequence of masks.
</p>
<p>
ctype.scan_is()/ctype.scan_not() take a character <em>sequence</em> and return a <em>pointer</em> to the first matching/non-matching character.
</p>
<p>
The other methods return the <em>converted</em> character when passed a single character.
Alternatively they are passed two character <em>sequences</em>.
</p>
<p>
ctype.toupper()/ctype.tolower() convert characters <em>in-place</em> whereas
ctype.widen()/ctype.narrow() take a pointer to a <em>destination</em> sequence.
</p>
<h3> Formatting of Numeric Values </h3>
<p>
The <em>LC_NUMERIC</em> facets encapsulate conversion between external character representations of numeric values and C++ numeric types.
</p>
<p>
The methods provided by these facets are:
<ol><!-- Shuffle List -->
<li> num_put.<em>put</em>() format a C++ numeric value for output as a character sequence </li>
<li> num_get.<em>get</em>() parse a character sequence producing a numeric value </li>
<li> numpunct.<em>decimal_point</em>() return the 'decimal point' character </li>
<li> numpunct.<em>thousands_sep</em>() return the 'thousands separator' character </li>
<li> numpunct.<em>grouping</em>() return the numbers of digits between pairs of 'thousand separators' </li>
<li> numpunct.<em>falsename</em>() return the locale language representation of 'false' </li>
<li> numpunct.<em>truename</em>() return the locale language representation of 'true' </li>
</ol>
</p>
<p>
The thousand separator is a <em>C-string</em> of char values.
The simplest locale is "\3", which means every <em>third</em> position.
The Nepalese locale uses "\3\2", which means the third position and then every second position moving right to left.
</p>
<p>
The default locale uses '.' as <em>decimal point</em> and ',' as <em>thousands separator</em>.
However, the grouping of thousand separator is an empty string, which means <em>no</em> separators.
</p>
<h3> Formatting of Monetary Values </h3>
<p>
The <em>LC_MONETARY</em> facets encapsulate conversion between external character representations of monetary values and either C++ long double or string types.
</p>
<p>
The internal representations assume the locale's smallest <em>non-fractional</em> currency units. E.g. yen in Japan but cents (not) Euros in Europe.
</p>
<p>
The methods provided by these facets are:
<ol><!-- Shuffle List -->
<li> money_put.<em>put</em>() format a C++ numeric value for output as a character sequence </li>
<li> money_get.<em>get</em>() parse a character sequence producing a numeric value </li>
<li> moneypunct.<em>decimal_point</em>() return the 'decimal point' character </li>
<li> moneypunct.<em>thousands_sep</em>() return the 'thousands' separator character </li>
<li> moneypunct.<em>grouping</em>() return the numbers of digits between pairs of 'thousand' separators </li>
<li> moneypunct.<em>frac_digits</em>() return the number of digits to display after the decimal point (e.g. 2) </li>
<li> moneypunct.<em>curr_symbol</em>() return the string to use as the currency identifier </li>
<li> moneypunct.<em>positive_sign</em>() return the string to indicate a positive value </li>
<li> moneypunct.<em>negative_sign</em>() return the string to indicate a negative value </li>
<li> moneypunct.<em>pos_format</em>() return the formatting pattern for positive currency values </li>
<li> moneypunct.<em>neg_format</em>() return the formatting pattern for negative currency values </li>
</ol>
</p>
<p>
The currency symbol is a string: either a (usually) <em>single</em> character (e.g. "€") or the 3 letter <em>international</em> code followed by a space (e.g "EUR ").
A <em>bool</em> parameter to put()/get()/curr_symbol() determines which.
The std::showbase affects the presence of the currency symbol for currency values very much the way is affects the presence of 0x for hexadecimal values.
</p>
<p>
The positive and negative signs are strings.
If either is more than one character, all but the <em>first</em> appear at the <em>end</em> of the formatted currency value so that "()" gives what is wanted.
The std::showpos has no affect on the presence of the positive sign.
</p>
<p>
The positive and negative formats are each an <em>array</em> of four enumeration values.
The locale independent default is '{symbol, sign, none, value}'.
</p>
<p>
<em>C++ 11</em> introduces the i/o stream manipulators:
<ol><!-- Shuffle List -->
<li> put_money() </li>
<li> get_money() </li>
</ol>
that mean that application software generally need not use these facets directly.
</p>
<h3> Formatting of Date and Time Values</h3>
<p>
The <em>LC_TIME</em> facets encapsulate conversion between external character representations and std::tm (C-style 'struct tm') objects.
Conversion is derived from that of the C-function strftime().
</p>
<p>
The methods provided by these facets are:
<ol><!-- Shuffle List -->
<li> time_put.<em>put</em>() format contents of a std::tm struct for output as a character sequence </li>
<li> time_get.<em>get</em>() parse a character sequence producing a std::tm struct result </li>
<li> time_get.<em>get_time</em>() parse a character sequence representing a time </li>
<li> time_get.<em>get_date</em>() parse a character sequence representing a date </li>
<li> time_get.<em>get_weekday</em>() parse a character sequence representing the name of a weekday </li>
<li> time_get.<em>get_monthname</em>() parse a character sequence representing the name of a month </li>
<li> time_get.<em>get_year</em>() parse a character sequence representing a year number </li>
<li> time_get.<em>date_order</em>() get the enumeration value representing the date format (day, month, year permutation) </li>
</ol>
</p>
<p>
The put() function has two forms:
the format specifier is either a <em>single</em> character representing one of the strftime() format specifiers
or else a <em>C-string</em> suitable for passing to strftime().
</p>
<p>
The get() function is the inverse of put().
It was introduced with <em>C++ 11</em>.
</p>
<p>
The other methods only set <em>pertinent</em> members of the std::tm struct - other members are unchanged.
</p>
<p>
The get_time() and get_date() conversions are the <em>inverse</em> of the strftime() "%X" and "%x" formats.
It must be presumed that the time and date punctuation is locale dependent; the date order certainly is.
</p>
<p>
Abbreviated names of <em>weekdays</em> and <em>months</em> are recognised as well as the full versions.
They are locale language specific.
</p>
<p>
It is not specified whether <em>two digit</em> year numbers are accepted nor in which century they lie.
</p>
<h3> Template Functions </h3>
<p>
A number of template functions are provided that are <em>analogous</em> to familiar C functions.
These take, as a <em>second</em> parameter, a locale object, instead of using the (global) C locale.
</p>
<p>
An example <em>implementation</em> might be:
<pre>
template< class charT >
bool isspace(charT ch, const locale& loc)
{
return use_facet< ctype<charT> >(loc).is(ctype_base::space, ch);
}
</pre>
</p>
<p>
There are a dozen template functions for character classification:
<ol><!-- Shuffle List -->
<li> <em>isspace</em>() true if a character is a locale defined whitespace </li>
<li> <em>isblank</em>() true if a character is a locale defined blank character </li>
<li> <em>iscntrl</em>() true if a character is a locale defined control character </li>
<li> <em>isupper</em>() true if a character is a locale defined uppercase </li>
<li> <em>islower</em>() true if a character is a locale defined lowercase </li>
<li> <em>isalpha</em>() true if a character is a locale defined alphabetic </li>
<li> <em>isdigit</em>() true if a character is a locale defined digit </li>
<li> <em>ispunct</em>() true if a character is a locale defined punctuation </li>
<li> <em>isxdigit</em>() true if a character is a locale defined hexadecimal digit </li>
<li> <em>isalnum</em>() true if a character is a locale defined alphanumeric </li>
<li> <em>isprint</em>() true if a character is a locale defined printable </li>
<li> <em>isgraph</em>() true if a character is a locale defined graphical </li>
</ol>
</p>
<p>
isblank() was new with <em>C++ 11</em>.
</p>
<p>
There are two template functions for character conversion:
<ol><!-- Shuffle List -->
<li> <em>toupper</em>() convert a character to locale uppercase </li>
<li> <em>tolower</em>() convert a character to locale lowercase </li>
</ol>
</p>
<h3> Problems </h3>
<p>
Setting the <em>global</em> C++ locale may have bad side effects.
Many packages are not locale aware and may be broken.
</p>
<p>
Locale names are <em>platform</em> specific as is their availability.
UTF-8 is not supported on Windows.
</p>
<p>
On some platforms the STL supports only the "C" and "POSIX" locales.
GCC supports localisation only under <em>Linux</em>.
</p>
<p>
Some locales use a <em>non-breakable</em> space as a thousands separator.
Not all platforms handle this correctly.
</p>