C localization functions: Difference between revisions

Content deleted Content added
Criticism: Expanded it a bit
cleanup
Line 1:
{{cleanup|date=September 2011}}
{{C Standard Library}}
In [[computing]], '''C localization functions''' are a group of functions in the [[C (programming language)|C programming language]] implementing basic localization routines.<ref name="c99">{{cite book | url=http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf | title=ISO/IEC 9899:1999 specification | at=p. 204, § 7.11 ''Localization'' }}</ref><ref name="c_primer">{{cite book|title=C primer plus | first=Stephen | last=Prata | year=2004 | publisher=Sams Publishing | isbn=0-672-32696-5 | at=Appendix B, Section V: The Standard ANSI C Library with C99 Additions}}</ref> The functions are used in multilingual programs to adapt to the specific locale. In particular, the way of displaying of numbers and currency can be modified. These settings affect the behaviour of [[C file input/output | input/output functions]] in the C Standard Library.
Line 5 ⟶ 4:
==Overview of functions==
 
C localization functions and types are defined in <tt>locale.h</tt> (<tt>clocale</tt> header in C++).<ref name=www.utas.edu.au>{{cite web|title=locale.h|url=http://www.utas.edu.au/infosys/info/documentation/C/CStdLib.html#locale.h|work=utas.edu.au|publisher=infosys|accessdate=14 September 2011}}</ref>
 
{| class="wikitable" style="font-size:0.85em;"
'''struct lconv'''
|-
*explain formatting monetary and other numeric values.
| {{anchor|setlocale}}<code>[http://en.cppreference.com/w/cpp/locale/setlocale setlocale]</code>
<code>'''char'''* decimal point;</code>
| sets and gets the current C locale
*decimal point for non-monetary values
|-
<code> '''char'''* grouping;</code>
| {{anchor|localeconv}}<code>[http://en.cppreference.com/w/cpp/locale/localeconv localeconv]</code>
*size pf digit groups for non-monetary values
| returns numeric and monetary formatting details of the current locale
<code>'''struct''' lconv* localeconv('''void''');</code><br />
|-
<code>'''char'''* setlocale('''int''', '''const char'''*);</code>
|}
<code>'''char'''thousand sep;</code>
*separator for non-monetary values
<code>'''char'''* currency symbol;</code>
*currency symbol
<code>'''char'''* int curr symbol;</code>
*international currency symbol
<code>'''char'''*mon-decimal point</code>
*decimal point for monetary values
<code>'''char'''* mon grouping; </code>
*sizes of digit groups for monetary values
<code>'''char'''* mon thousand sep;</code>
*separator for digit groups for monetary values
<ref name=www.utas.edu.au>{{cite web|title=local.h|url=http://www.utas.edu.au/infosys/info/documentation/C/CStdLib.html#locale.h|work=utas.edu.au|publisher=infosys|accessdate=14 September 2011}}</ref>
 
==Criticism==
 
{{expand section|date=November 2011}}
C standard localization functions are criticized because the localization state is stored globally. This means that in a given program all operations involving a locale can use only one locale at a time. As a result, it is very difficult to implement programs that use more than one locale.<ref>{{cite web | title=The Standard C Locale and the Standard C++ Locales | url=http://www.math.hkbu.edu.hk/parallel/pgi/doc/pgC++_lib/stdlibug/sta_9169.htm | publisher=Rogue Wave Software, Inc. | year=1996}}</ref>
 
Line 60 ⟶ 46:
{{Reflist}}
 
{{use dmy dates|January 2012}}
[[Category:C Standard Library]]