⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 locale.texi

📁 一个C源代码分析器
💻 TEXI
📖 第 1 页 / 共 2 页
字号:
are these three standard ones:@table @code@item "C"This is the standard C locale.  The attributes and behavior it providesare specified in the ANSI C standard.  When your program starts up, itinitially uses this locale by default.@item "POSIX"This is the standard POSIX locale.  Currently, it is an alias for thestandard C locale.@item ""The empty name says to select a locale based on environment variables.@xref{Locale Categories}.@end tableDefining and installing named locales is normally a responsibility ofthe system administrator at your site (or the person who installed theGNU C library).  Some systems may allow users to create locales, butwe don't discuss that here.@c ??? If we give the GNU system that capability, this place will have@c ??? to be changed.If your program needs to use something other than the @samp{C} locale,it will be more portable if you use whatever locale the user specifieswith the environment, rather than trying to specify some non-standardlocale explicitly by name.  Remember, different machines might havedifferent sets of locales installed.@node Numeric Formatting,  , Standard Locales, Locales@section Numeric FormattingWhen you want to format a number or a currency amount using theconventions of the current locale, you can use the function@code{localeconv} to get the data on how to do it.  The function@code{localeconv} is declared in the header file @file{locale.h}.@pindex locale.h@cindex monetary value formatting@cindex numeric value formatting@comment locale.h@comment ANSI@deftypefun {struct lconv *} localeconv (void)The @code{localeconv} function returns a pointer to a structure whosecomponents contain information about how numeric and monetary valuesshould be formatted in the current locale.You shouldn't modify the structure or its contents.  The structure mightbe overwritten by subsequent calls to @code{localeconv}, or by calls to@code{setlocale}, but no other function in the library overwrites thisvalue.@end deftypefun@comment locale.h@comment ANSI@deftp {Data Type} {struct lconv}This is the data type of the value returned by @code{localeconv}.@end deftpIf a member of the structure @code{struct lconv} has type @code{char},and the value is @code{CHAR_MAX}, it means that the current locale hasno value for that parameter.@menu* General Numeric::             Parameters for formatting numbers and                                 currency amounts.* Currency Symbol::             How to print the symbol that identifies an                                 amount of money (e.g. @samp{$}).* Sign of Money Amount::        How to print the (positive or negative) sign                                 for a monetary amount, if one exists.@end menu@node General Numeric, Currency Symbol,  , Numeric Formatting@subsection Generic Numeric Formatting ParametersThese are the standard members of @code{struct lconv}; there may beothers.@table @code@item char *decimal_point@itemx char *mon_decimal_pointThese are the decimal-point separators used in formatting non-monetaryand monetary quantities, respectively.  In the @samp{C} locale, thevalue of @code{decimal_point} is @code{"."}, and the value of@code{mon_decimal_point} is @code{""}.@cindex decimal-point separator@item char *thousands_sep@itemx char *mon_thousands_sepThese are the separators used to delimit groups of digits to the left ofthe decimal point in formatting non-monetary and monetary quantities,respectively.  In the @samp{C} locale, both members have a value of@code{""} (the empty string).@item char *grouping@itemx char *mon_groupingThese are strings that specify how to group the digits to the left ofthe decimal point.  @code{grouping} applies to non-monetary quantitiesand @code{mon_grouping} applies to monetary quantities.  Use either@code{thousands_sep} or @code{mon_thousands_sep} to separate the digitgroups.@cindex grouping of digitsEach string is made up of decimal numbers separated by semicolons.Successive numbers (from left to right) give the sizes of successivegroups (from right to left, starting at the decimal point).  The lastnumber in the string is used over and over for all the remaining groups.If the last integer is @code{-1}, it means that there is no moregrouping---or, put another way, any remaining digits form one largegroup without separators.For example, if @code{grouping} is @code{"4;3;2"}, the correct groupingfor the number @code{123456787654321} is @samp{12}, @samp{34},@samp{56}, @samp{78}, @samp{765}, @samp{4321}.  This uses a group of 4digits at the end, preceded by a group of 3 digits, preceded by groupsof 2 digits (as many as needed).  With a separator of @samp{,}, thenumber would be printed as @samp{12,34,56,78,765,4321}.A value of @code{"3"} indicates repeated groups of three digits, asnormally used in the U.S.In the standard @samp{C} locale, both @code{grouping} and@code{mon_grouping} have a value of @code{""}.  This value specifies nogrouping at all.@item char int_frac_digits@itemx char frac_digitsThese are small integers indicating how many fractional digits (to theright of the decimal point) should be displayed in a monetary value ininternational and local formats, respectively.  (Most often, bothmembers have the same value.)In the standard @samp{C} locale, both of these members have the value@code{CHAR_MAX}, meaning ``unspecified''.  The ANSI standard doesn't saywhat to do when you find this the value; we recommend printing nofractional digits.  (This locale also specifies the empty string for@code{mon_decimal_point}, so printing any fractional digits would beconfusing!)@end table@node Currency Symbol, Sign of Money Amount, General Numeric, Numeric Formatting@subsection Printing the Currency Symbol@cindex currency symbolsThese members of the @code{struct lconv} structure specify how to printthe symbol to identify a monetary value---the international analog of@samp{$} for US dollars.Each country has two standard currency symbols.  The @dfn{local currencysymbol} is used commonly within the country, while the@dfn{international currency symbol} is used internationally to refer tothat country's currency when it is necessary to indicate the countryunambiguously.For example, many countries use the dollar as their monetary unit, andwhen dealing with international currencies it's important to specifythat one is dealing with (say) Canadian dollars instead of U.S. dollarsor Australian dollars.  But when the context is known to be Canada,there is no need to make this explicit---dollar amounts are implicitlyassumed to be in Canadian dollars.@table @code@item char *currency_symbolThe local currency symbol for the selected locale.In the standard @samp{C} locale, this member has a value of @code{""}(the empty string), meaning ``unspecified''.  The ANSI standard doesn'tsay what to do when you find this value; we recommend you simply printthe empty string as you would print any other string found in theappropriate member.@item char *int_curr_symbolThe international currency symbol for the selected locale.The value of @code{int_curr_symbol} should normally consist of athree-letter abbreviation determined by the international standard@cite{ISO 4217 Codes for the Representation of Currency and Funds},followed by a one-character separator (often a space).In the standard @samp{C} locale, this member has a value of @code{""}(the empty string), meaning ``unspecified''.  We recommend you simplyprint the empty string as you would print any other string found in theappropriate member.@item char p_cs_precedes@itemx char n_cs_precedesThese members are @code{1} if the @code{currency_symbol} string shouldprecede the value of a monetary amount, or @code{0} if the string shouldfollow the value.  The @code{p_cs_precedes} member applies to positiveamounts (or zero), and the @code{n_cs_precedes} member applies tonegative amounts.In the standard @samp{C} locale, both of these members have a value of@code{CHAR_MAX}, meaning ``unspecified''.  The ANSI standard doesn't saywhat to do when you find this value, but we recommend printing thecurrency symbol before the amount.  That's right for most countries.In other words, treat all nonzero values alike in these members.The POSIX standard says that these two members apply to the@code{int_curr_symbol} as well as the @code{currency_symbol}.  The ANSIC standard seems to imply that they should apply only to the@code{currency_symbol}---so the @code{int_curr_symbol} should alwaysprecede the amount.We can only guess which of these (if either) matches the usualconventions for printing international currency symbols.  Our guess isthat they should always preceed the amount.  If we find out a reliableanswer, we will put it here.@item char p_sep_by_space@itemx char n_sep_by_spaceThese members are @code{1} if a space should appear between the@code{currency_symbol} string and the amount, or @code{0} if no spaceshould appear.  The @code{p_sep_by_space} member applies to positiveamounts (or zero), and the @code{n_sep_by_space} member applies tonegative amounts.In the standard @samp{C} locale, both of these members have a value of@code{CHAR_MAX}, meaning ``unspecified''.  The ANSI standard doesn't saywhat you should do when you find this value; we suggest you treat it asone (print a space).  In other words, treat all nonzero values alike inthese members.These members apply only to @code{currency_symbol}.  When you use@code{int_curr_symbol}, you never print an additional space, because@code{int_curr_symbol} itself contains the appropriate separator.The POSIX standard says that these two members apply to the@code{int_curr_symbol} as well as the @code{currency_symbol}.  But anexample in the ANSI C standard clearly implies that they should applyonly to the @code{currency_symbol}---that the @code{int_curr_symbol}contains any appropriate separator, so you should never print anadditional space.Based on what we know now, we recommend you ignore these members whenprinting international currency symbols, and print no extra space.@end table@node Sign of Money Amount,  , Currency Symbol, Numeric Formatting@subsection Printing the Sign of an Amount of MoneyThese members of the @code{struct lconv} structure specify how to printthe sign (if any) in a monetary value.@table @code@item char *positive_sign@itemx char *negative_signThese are strings used to indicate positive (or zero) and negative(respectively) monetary quantities.In the standard @samp{C} locale, both of these members have a value of@code{""} (the empty string), meaning ``unspecified''.The ANSI standard doesn't say what to do when you find this value; werecommend printing @code{positive_sign} as you find it, even if it isempty.  For a negative value, print @code{negative_sign} as you find itunless both it and @code{positive_sign} are empty, in which case print@samp{-} instead.  (Failing to indicate the sign at all seems ratherunreasonable.)@item char p_sign_posn@itemx char n_sign_posnThese members have values that are small integers indicating how toposition the sign for nonnegative and negative monetary quantities,respectively.  (The string used by the sign is what was specified with@code{positive_sign} or @code{negative_sign}.)  The possible values areas follows:@table @code@item 0The currency symbol and quantity should be surrounded by parentheses.@item 1Print the sign string before the quantity and currency symbol.@item 2Print the sign string after the quantity and currency symbol.@item 3Print the sign string right before the currency symbol.@item 4Print the sign string right after the currency symbol.@item CHAR_MAX``Unspecified''.  Both members have this value in the standard@samp{C} locale.@end tableThe ANSI standard doesn't say what you should do when the value is@code{CHAR_MAX}.  We recommend you print the sign after the currencysymbol.@end tableIt is not clear whether you should let these members apply to theinternational currency format or not.  POSIX says you should, butintuition plus the examples in the ANSI C standard suggest you shouldnot.  We hope that someone who knows well the conventions for formattingmonetary quantities will tell us what we should recommend.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -