Files
oldlinux-files/study/Ref-docs/C/locale.html
2024-02-19 00:25:23 -05:00

379 lines
14 KiB
HTML

<HTML><HEAD><TITLE>&lt;locale.h&gt;</TITLE></HEAD><BODY BGCOLOR="#FFFFFF">
<H1><A NAME="&lt;locale.h&gt;"><CODE>&lt;locale.h&gt;</CODE></A></H1><HR>
<P><CODE>
#define <A HREF="#LC_ALL"><B>LC_ALL</B></A>
<I>&lt;integer constant expression&gt;</I><BR>
#define <A HREF="#LC_COLLATE"><B>LC_COLLATE</B></A>
<I>&lt;integer constant expression&gt;</I><BR>
#define <A HREF="#LC_CTYPE"><B>LC_CTYPE</B></A>
<I>&lt;integer constant expression&gt;</I><BR>
#define <A HREF="#LC_MONETARY"><B>LC_MONETARY</B></A>
<I>&lt;integer constant expression&gt;</I><BR>
#define <A HREF="#LC_NUMERIC"><B>LC_NUMERIC</B></A>
<I>&lt;integer constant expression&gt;</I><BR>
#define <A HREF="#LC_TIME"><B>LC_TIME</B></A>
<I>&lt;integer constant expression&gt;</I><BR>
#define <A HREF="#NULL"><B>NULL</B></A>
<I>&lt;either 0, 0L, or (void *)0&gt;</I> <B>[0 in C++]</B><BR>
struct <A HREF="#lconv"><B>lconv</B></A>;<BR>
struct lconv *<A HREF="#localeconv"><B>localeconv</B></A>(void);<BR>
char *<A HREF="#setlocale"><B>setlocale</B></A>(int category,
const char *locale);
</CODE></P>
<P>Include the standard header <B><CODE>&lt;locale.h&gt;</CODE></B>
to alter or access properties of the current
<B><A NAME="locale">locale</A></B>
-- a collection of culture-specific information.
An implementation can define additional
macros in this standard header with names that begin with <CODE>LC_</CODE>.
You can use any of these macro names as the
<B><A NAME="locale category">locale category</A></B> argument
(which selects a cohesive subset of a locale) to
<A HREF="#setlocale"><CODE>setlocale</CODE></A>.</P>
<H2><A NAME="LC_ALL"><CODE>LC_ALL</CODE></A></H2>
<P><CODE>
#define <B>LC_ALL</B> <I>&lt;integer constant expression&gt;</I>
</CODE></P>
<P>The macro yields the
<A HREF="#locale category">locale category</A>
argument value that affects all locale categories.</P>
<H2><A NAME="LC_COLLATE"><CODE>LC_COLLATE</CODE></A></H2>
<P><CODE>
#define <B>LC_COLLATE</B> <I>&lt;integer constant expression&gt;</I>
</CODE></P>
<P>The macro yields the
<A HREF="#locale category">locale category</A>
argument value that affects the collation functions
<CODE>strcoll</CODE> and
<CODE>strxfrm</CODE>.</P>
<H2><A NAME="LC_CTYPE"><CODE>LC_CTYPE</CODE></A></H2>
<P><CODE>
#define <B>LC_CTYPE</B> <I>&lt;integer constant expression&gt;</I>
</CODE></P>
<P>The macro yields the
<A HREF="#locale category">locale category</A>
argument value that affects
<A HREF="ctype.html" tppabs="http://ccs.ucsd.edu/c/ctype.html">character classification</A> functions,
<A HREF="wctype.html" tppabs="http://ccs.ucsd.edu/c/wctype.html">wide-character classification</A> functions,
and various multibyte conversion functions.</P>
<H2><A NAME="LC_MONETARY"><CODE>LC_MONETARY</CODE></A></H2>
<P><CODE>
#define <B>LC_MONETARY</B> <I>&lt;integer constant expression&gt;</I>
</CODE></P>
<P>The macro yields the
<A HREF="#locale category">locale category</A>
argument value that affects monetary information returned by
<A HREF="#localeconv"><CODE>localeconv</CODE></A>.</P>
<H2><A NAME="LC_NUMERIC"><CODE>LC_NUMERIC</CODE></A></H2>
<P><CODE>
#define <B>LC_NUMERIC</B> <I>&lt;integer constant expression&gt;</I>
</CODE></P>
<P>The macro yields the
<A HREF="#locale category">locale category</A>
argument value that affects numeric information returned by
<A HREF="#localeconv"><CODE>localeconv</CODE></A>,
including the decimal point used by numeric conversion,
read, and write functions.</P>
<H2><A NAME="LC_TIME"><CODE>LC_TIME</CODE></A></H2>
<P><CODE>
#define <B>LC_TIME</B> <I>&lt;integer constant expression&gt;</I>
</CODE></P>
<P>The macro yields the
<A HREF="#locale category">locale category</A>
argument value that affects the time conversion function
<A HREF="time.html#strftime" tppabs="http://ccs.ucsd.edu/c/time.html#strftime"><CODE>strftime</CODE></A>.</P>
<H2><A NAME="NULL"><CODE>NULL</CODE></A></H2>
<P><CODE>
#define <B>NULL</B> <I>&lt;either 0, 0L, or (void *)0&gt;</I> <B>[0 in C++]</B>
</CODE></P>
<P>The macro yields a null pointer constant that is usable as an
<A HREF="express.html#address constant expression" tppabs="http://ccs.ucsd.edu/c/express.html#address constant expression">
address constant expression</A>.</P>
<H2><A NAME="lconv"><CODE>lconv</CODE></A></H2>
<PRE>struct <B>lconv</B> {
<B>ELEMENT "C" LOCALE LOCALE CATEGORY</B>
char *currency_symbol; <B>"" LC_MONETARY</B>
char *decimal_point; <B>"." LC_NUMERIC</B>
char *grouping; <B>"" LC_NUMERIC</B>
char *int_curr_symbol; <B>"" LC_MONETARY</B>
char *mon_decimal_point; <B>"" LC_MONETARY</B>
char *mon_grouping; <B>"" LC_MONETARY</B>
char *mon_thousands_sep; <B>"" LC_MONETARY</B>
char *negative_sign; <B>"" LC_MONETARY</B>
char *positive_sign; <B>"" LC_MONETARY</B>
char *thousands_sep; <B>"" LC_NUMERIC</B>
char frac_digits; <B>CHAR_MAX LC_MONETARY</B>
char int_frac_digits; <B>CHAR_MAX LC_MONETARY</B>
char n_cs_precedes; <B>CHAR_MAX LC_MONETARY</B>
char n_sep_by_space; <B>CHAR_MAX LC_MONETARY</B>
char n_sign_posn; <B>CHAR_MAX LC_MONETARY</B>
char p_cs_precedes; <B>CHAR_MAX LC_MONETARY</B>
char p_sep_by_space; <B>CHAR_MAX LC_MONETARY</B>
char p_sign_posn; <B>CHAR_MAX LC_MONETARY</B>
};
</PRE>
<P><CODE>struct lconv</CODE> contains members that describe how to format
numeric and monetary values. Functions in the Standard C library use
only the field <CODE>decimal_point</CODE>.
The information is otherwise advisory:</P>
<UL>
<LI>Members of type <I>pointer to char</I> all point to
<A HREF="lib_over.html#C string" tppabs="http://ccs.ucsd.edu/c/lib_over.html#C string">C strings</A>.
<LI>Members of type <I>char</I> have nonnegative values.
<LI>A <I>char</I> value of
<A HREF="limits.html#CHAR_MAX" tppabs="http://ccs.ucsd.edu/c/limits.html#CHAR_MAX"><CODE>CHAR_MAX</CODE></A>
indicates that a meaningful
value is not available in the current locale.
</UL>
<P>The members shown above can occur in arbitrary order and can
be interspersed with additional members. The comment following each
member shows its value for the
<B><A NAME="C locale"><CODE>"C"</CODE> locale</A></B>,
the locale in effect at
<A HREF="lib_over.html#program startup" tppabs="http://ccs.ucsd.edu/c/lib_over.html#program startup">program startup</A>,
followed by the
<A HREF="#locale category">locale category</A>
that can affect its value.</P>
<P>A description of each member follows, with an example in parentheses
that would be suitable for a USA locale.</P>
<P><B><A NAME="currency_symbol"><CODE>currency_symbol</CODE></A></B>
-- the local currency symbol (<CODE>"$"</CODE>)</P>
<P><B><A NAME="decimal_point"><CODE>decimal_point</CODE></A></B>
-- the decimal point for non-monetary values (<CODE>"."</CODE>)</P>
<P><B><A NAME="grouping"><CODE>grouping</CODE></A></B>
-- the sizes of digit groups for non-monetary values.
Successive elements of the string describe groups going away
from the decimal point:</P>
<UL>
<LI>An element value of zero (the terminating null character) calls
for the previous element value to be repeated indefinitely.
<LI>An element value of
<A HREF="limits.html#CHAR_MAX" tppabs="http://ccs.ucsd.edu/c/limits.html#CHAR_MAX"><CODE>CHAR_MAX</CODE></A>
ends any further grouping (and hence ends the string).
</UL>
<P>Thus, the array <CODE>{3, 2, CHAR_MAX}</CODE> calls for a group of
three digits, then two, then whatever remains, as in
<CODE>9876,54,321</CODE>, while <CODE>"\3"</CODE>
calls for repeated groups of three digits, as in
<CODE>987,654,321</CODE>. (<CODE>"\3"</CODE>)</P>
<P><B><A NAME="int_curr_symbol"><CODE>int_curr_symbol</CODE></A></B>
-- the international currency symbol
specified by ISO 4217 (<CODE>"USD "</CODE>)</P>
<P><B><A NAME="mon_decimal_point"><CODE>mon_decimal_point</CODE></A></B>
-- the decimal point for monetary values (<CODE>"."</CODE>)</P>
<P><B><A NAME="mon_grouping"><CODE>mon_grouping</CODE></A></B>
-- the sizes of digit groups for monetary values.
Successive elements of the string describe groups going away
from the decimal point. The encoding is the same as for
<A HREF="#grouping"><CODE>grouping</CODE></A>.</P>
<P><B><A NAME="mon_thousands_sep"><CODE>mon_thousands_sep</CODE></A></B>
-- the separator for digit groups to the left of the decimal point
for monetary values (<CODE>","</CODE>)</P>
<P><B><A NAME="negative_sign"><CODE>negative_sign</CODE></A></B>
-- the negative sign for monetary values (<CODE>"-"</CODE>)</P>
<P><B><A NAME="positive_sign"><CODE>positive_sign</CODE></A></B>
-- the positive sign for monetary values (<CODE>"+"</CODE>)</P>
<P><B><A NAME="thousands_sep"><CODE>thousands_sep</CODE></A></B>
-- the separator for digit groups to the left of the decimal point
for non-monetary values (<CODE>","</CODE>)</P>
<P><B><A NAME="frac_digits"><CODE>frac_digits</CODE></A></B>
-- the number of digits to display to the right of the decimal point
for monetary values (<CODE>2</CODE>)</P>
<P><B><A NAME="int_frac_digits"><CODE>int_frac_digits</CODE></A></B>
-- the number of digits to display to the right of the decimal point
for international monetary values (<CODE>2</CODE>)</P>
<P><B><A NAME="n_cs_precedes"><CODE>n_cs_precedes</CODE></A></B>
-- whether the currency symbol
precedes or follows the value for negative monetary values:</P>
<UL>
<LI>A value of 0 indicates that the symbol follows the value.
<LI>A value of 1 indicates that the symbol precedes the value.
(<CODE>1</CODE>)
</UL>
<P><B><A NAME="n_sep_by_space"><CODE>n_sep_by_space</CODE></A></B>
-- whether the currency symbol
is separated by a space or by no space from the value
for negative monetary values:</P>
<UL>
<LI>A value of 0 indicates that no space separates symbol and value.
<LI>A value of 1 indicates that a space separates symbol and value.
(<CODE>0</CODE>)
</UL>
<P><B><A NAME="n_sign_posn"><CODE>n_sign_posn</CODE></A></B>
-- the format for negative monetary values:</P>
<UL>
<LI>A value of 0 indicates that parentheses surround the value and the
currency symbol.
<LI>A value of 1 indicates that the negative sign precedes the value and the
currency symbol.
<LI>A value of 2 indicates that the negative sign follows the value and the
currency_symbol.
<LI>A value of 3 indicates that the negative sign immediately precedes the
currency symbol.
<LI>A value of 4 indicates that the negative sign immediately follows the
currency_symbol. (<CODE>4</CODE>)
</UL>
<P><B><A NAME="p_cs_precedes"><CODE>p_cs_precedes</CODE></A></B>
-- whether the currency symbol precedes
or follows the value for positive monetary values:</P>
<UL>
<LI>A value of 0 indicates that the symbol follows the value.
<LI>A value of 1 indicates that the symbol precedes the value.
(<CODE>1</CODE>)
</UL>
<P><B><A NAME="p_sep_by_space"><CODE>p_sep_by_space</CODE></A></B>
-- whether the currency symbol is separated
by a space or by no space from the value for positive monetary values:</P>
<UL>
<LI>A value of 0 indicates that no space separates symbol and value.
<LI>A value of 1 indicates that a space separates symbol and value.
(<CODE>0</CODE>)
</UL>
<P><B><A NAME="p_sign_posn"><CODE>p_sign_posn</CODE></A></B>
-- the format for positive monetary values:</P>
<UL>
<LI>A value of 0 indicates that parentheses surround the value and
the currency symbol.
<LI>A value of 1 indicates that the negative sign precedes the value
and the currency symbol.
<LI>A value of 2 indicates that the negative sign follows the value
and the currency symbol.
<LI>A value of 3 indicates that the negative sign immediately precedes
the currency symbol.
<LI>A value of 4 indicates that the negative sign immediately follows
the currency symbol. (<CODE>4</CODE>)
</UL>
<H2><A NAME="localeconv"><CODE>localeconv</CODE></A></H2>
<P><CODE>
struct lconv *<B>localeconv</B>(void);
</CODE></P>
<P>The function returns a pointer to a static-duration structure
containing numeric formatting information for the current locale.
You cannot alter values stored in the static-duration structure. The
stored values can change on later calls
to <CODE>localeconv</CODE> or on calls to
<A HREF="#setlocale"><CODE>setlocale</CODE></A>
that alter any of the categories
<A HREF="#LC_ALL"><CODE>LC_ALL</CODE></A>,
<A HREF="#LC_MONETARY"><CODE>LC_MONETARY</CODE></A>, or
<A HREF="#LC_NUMERIC"><CODE>LC_NUMERIC</CODE></A>.</P>
<H2><A NAME="setlocale"><CODE>setlocale</CODE></A></H2>
<P><CODE>
char *<B>setlocale</B>(int category, const char *locale);
</CODE></P>
<P>The function either returns a pointer to a static-duration string
describing a new locale or returns a null pointer (if the new locale
cannot be selected). The value of <CODE>category</CODE>
selects one or more
<A HREF="#locale category">locale categories</A>,
each of which must match the value
of one of the macros defined in this standard header with names that
begin with <CODE>LC_</CODE>.</P>
<P>If <CODE>locale</CODE> is a null pointer, the locale remains unchanged.
If <CODE>locale</CODE> points to the string <CODE>"C"</CODE>,
the new locale is the
<A HREF="#C locale"><CODE>"C"</CODE></A> locale
for the locale category specified. If <CODE>locale</CODE>
points to the string <CODE>""</CODE>, the new locale is the
<B><A NAME="native locale">native locale</A></B>
(a default locale presumably tailored for the local culture)
for the locale category specified.
<CODE>locale</CODE> can also point to a string
returned on an earlier call to <CODE>setlocale</CODE> or to other strings
that the implementation can define.</P>
<P>At
<A HREF="lib_over.html#program startup" tppabs="http://ccs.ucsd.edu/c/lib_over.html#program startup">program startup</A>,
the target environment calls <CODE>setlocale(
<A HREF="#LC_ALL">LC_ALL</A>,
"C")</CODE> before it calls <CODE>main</CODE>.</P>
<HR>
<P>See also the
<B><A HREF="index.html#Table of Contents" tppabs="http://ccs.ucsd.edu/c/index.html#Table of Contents">Table of Contents</A></B> and the
<B><A HREF="_index.html" tppabs="http://ccs.ucsd.edu/c/_index.html">Index</A></B>.</P>
<P><I>
<A HREF="crit_pb.html" tppabs="http://ccs.ucsd.edu/c/crit_pb.html">Copyright</A> &#169; 1989-1996
by P.J. Plauger and Jim Brodie. All rights reserved.</I></P>
</BODY></HTML>