📄 sta_9169.htm
字号:
<HTML><HEAD><TITLE>1.3 The Standard C Locale and the Standard C++ Locales</TITLE></HEAD><BODY><A HREF="ug2.htm"><IMG SRC="images/banner.gif"></A><BR><A HREF="int_7592.htm"><IMG SRC="images/prev.gif"></A><A HREF="booktoc2.htm"><IMG SRC="images/toc.gif"></A><A HREF="loc_1541.htm"><IMG SRC="images/next.gif"></A><BR><STRONG>Click on the banner to return to the user guide home page.</STRONG><H2>1.3 The Standard C Locale and the Standard C++ Locales</H2><P>As a software developer, you may already have some background in the C programming language, and the internationalization services provided by the C library. You may even be facing the problem of integrating internationalized software written in C with software in C++. If so, we recommend that you study this section. Here we give a short recap of the internationalization services provided by the C library, and its relationship to C++ locales. We then describe the C++ locales in terms of the C locale.</P><A NAME="1.3.1"><H3>1.3.1 The C Locale</H3></A><P>All the culture and language dependencies discussed in the previous section need to be represented in an operating system. This information is usually represented in a kind of language table, called a <I>locale</I>.</P><P>The X/Open consortium has standardized a variety of services for <I>Native Language Support (NLS)</I> in the programming language C. This standard is commonly known as XPG4. The X/Open's <I>Native Language Support</I> includes internationalization services as well as localization support. <A HREF="endnote2.htm#fn6">[6]</A> The description below is based on this standard.</P><P>According to XPG4, the C locale is composed of several categories:</P><CENTER><TABLE BORDER CELLSPACING=3 CELLPADDING=3><TR VALIGN=top><TD><B>Category</B><BR></TD><TD><B>Content </B><BR></TD></TR><TR VALIGN=top><TD><SAMP>LC_NUMERIC</SAMP><BR></TD><TD><UL><P>Rules and symbols for numbers<BR></TD></TR><TR VALIGN=top><TD><SAMP>LC_TIME</SAMP><BR></TD><TD><UL><P>Values for date and time information<BR></TD></TR><TR VALIGN=top><TD><SAMP>LC_MONETARY</SAMP><BR></TD><TD><UL><P>Rules and symbols for monetary information<BR></TD></TR><TR VALIGN=top><TD><SAMP>LC_CTYPE</SAMP><BR></TD><TD><UL><P>Character classification and case conversion<BR></TD></TR><TR VALIGN=top><TD><SAMP>LC_COLLATE</SAMP><BR></TD><TD><UL><P>Collation sequence<BR></TD></TR><TR VALIGN=top><TD><SAMP>LC_MESSAGE</SAMP><BR></TD><TD><UL><P>Formats and values of messages<BR></TD></TR></TABLE></CENTER><P>The external representation of a C locale is usually as a file in UNIX. Other operating systems may choose other representations. The external representation is transformed into an internal memory representation by calling the function <SAMP>setlocale()</SAMP>, as shown in Figure 4 below:</P><H4>Figure 4. Transformation of a C locale from external to internal representation</H4><BR><IMG SRC="images/image4.gif"><P>Inside a program, the C locale is represented by one or more global data structures. The C library provides a set of functions that use information from those global data structures to adapt their behavior to local conventions. Examples of these functions and the information they cover are listed in Table 2:</P><CENTER><TABLE BORDER CELLSPACING=3 CELLPADDING=3><TR VALIGN=top><TD><B>C locale function</B><BR></TD><TD><B>Information covered</B><BR></TD></TR><TR VALIGN=top><TD><SAMP>setlocale(),</SAMP> ...<BR></TD><TD>Locale initialization and language information<BR></TD></TR><TR VALIGN=top><TD><SAMP>isalpha()</SAMP>, <SAMP>isupper()</SAMP>, <SAMP>isdigit()</SAMP>, ...<BR></TD><TD>Character classification<BR></TD></TR><TR VALIGN=top><TD><SAMP>strftime()</SAMP>, ...<BR></TD><TD>Date and time functions<BR></TD></TR><TR VALIGN=top><TD><SAMP>strfmon()</SAMP><BR></TD><TD>Monetary functions<BR></TD></TR><TR VALIGN=top><TD><SAMP>printf()</SAMP>, <SAMP>scanf()</SAMP>, ...<BR></TD><TD>Number parsing and formatting<BR></TD></TR><TR VALIGN=top><TD><SAMP>strcoll()</SAMP>, <SAMP>wcscoll()</SAMP>, ...<BR>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -