setlocale 中文man页面

系统
setlocale() 函数 用来 设置 或者 查询 程序 当前 的 区域选项.

NAME

setlocale - 设置当前的区域选项

总览 (SYNOPSIS)

#include <locale.h>

char *setlocale(int category, const char * locale);

描述 (DESCRIPTION)

setlocale() 函数 用来 设置 或者 查询 程序 当前 的 区域选项.

如果 locale 不是 NULL, 程序 就会 根据 参数 更改 相应的 区域选项. category 参数 指定 区域选项 的 哪一部分 需要 更改.

LC_ALL
代表 所有 部分.
LC_COLLATE
代表 正则 表达式 匹配 (和 范围 表达式[range expressions] 以及 字符类[classes] 有关系) 和 字符串 排序.
LC_CTYPE
代表 正则 表达式 匹配, 字符类(character classification), 转换, 区分大小写 的比较, 以及 宽字符 函数.
LC_MESSAGES
代表 可以 本地化的 消息 (自然语言).
LC_MONETARY
代表 货币 格式.
LC_NUMERIC
代表 数字 格式 (比如 小数点 和 千位分组符).
LC_TIME
代表 时间 和 日期 格式.

locale 参数 是 一个 指向 字符串的 指针. 此 字符串 为 category 需要的 设置. 此 字符串 可以是 一个 众所周知 的 区域选项 常量, 如 "C" 或 "da_DK" (见下), 也可以是 另外 一个 setlocale 调用 返回 的 字符串.

如果 locale 是 , 需要 更改 的 部分 会根据 环境变量 做 相应的 设置. 具体的 和 实现 有关. 对于 glibc 来说, 首先 查看 环境变量 LC_ALL (不管 category),然后查看category (LC_COLLATE, LC_CTYPE, LC_MESSAGES, LC_MONETARY, LC_NUMERIC, LC_TIME) 同名的 环境变量, 最后 查看 环境变量 LANG. 以 先查到 的 环境变量 为准. 如果 其值不是 一个 有效 的 区域选项, 区域选项 将 不会改变, setlocale 会 返回 NULL.

标准 区域选项 CPOSIX 是 可移植的; 它的 LC_CTYPE 部分 对应的 是 7 位的 ASCII 字符集.

一个 典型的 区域选项 有 如下的 格式: language[_territory][.codeset][@modifier], 其中 language 是 一个 ISO 639 语言 代码, territory 是 一个 ISO 3166 国家 代码, codeset 是 一个 象 ISO-8859-1 或者 UTF-8 的 字符集 或者 编码 标识符. 用 "locale -a", cf. locale(1) 可以 获得 一个 系统 支持的 区域选项 的 列表.

如果 localeNULL, 意味着 只是 查询 当前 的 区域选项 而不 更改它.

当 main 程序 开始的 时候 可移植的 C 区域选项 作为 默认值 被设置. 一个 程序 可以 在 初始化 之后 调用 setlocale(LC_ALL, ) 函数, 并且 从 localeconv() 调用 的 返回 中 获得 和 区域选项 相关的 信息, 如果 MB_CUR_MAX > 1 就用 多字节 和 宽字节 函数 来 处理 文本, 用 strcoll(), wcscoll() 或者 strxfrm(), wcsxfrm() 来 比较 字符串, 这样 就可以 使 程序 有 较好的 移植性.

返回值 (RETURN VALUE)

一个 成功的 setlocale() 调用 会 返回 一个 表示 当前 区域选项 的 字符串 (指针). 这个 字符串 可能 是在静态 存储区 中 分配 的. 之后 用 相应的 category 和 这个 字符串 作为 参数 再去调用 这个 函数 会 重新 把 程序 区域选项 的 相应 部分 恢复. 如果 请求 不能 完成将会 返回 NULL .

遵循 (CONFORMING TO)

ANSI C, POSIX.1

注意 (NOTES)

Linux (也就是, GNU libc) 支持 可移植的 CPOSIX 区域选项. 在 以前 它 曾经 支持 欧洲 Latin-1 区域选项 ISO-8859-1 (比如说 在 libc-4.5.21 和 libc-4.6.27 中), 和 俄罗斯的 KOI-8 (更 准确点 是, "koi-8r") 区域选项 (比如 在 libc-4.6.27 中), 所以 设置 一个环境变量 LC_CTYPE=ISO-8859-1 就 能够 让 isprint() 返回 正确的 结果. 现在 不讲英语 的 欧洲人 会 比以前 更麻烦 一些, 他们 需要 安装 相应 的 区域选项 文件.

参见 (SEE ALSO)

locale(1), localedef(1), strcoll(3), isalpha(3), localeconv(3), strftime(3), charsets(4), locale(7)

#p#

NAME

setlocale - set the current locale  

SYNOPSIS

#include <locale.h>

char *setlocale(int category, const char *locale);

DESCRIPTION

The setlocale() function is used to set or query the program's current locale.

If locale is not NULL, the program's current locale is modified according to the arguments. The argument category determines which parts of the program's current locale should be modified.

LC_ALL
for all of the locale.
LC_COLLATE
for regular expression matching (it determines the meaning of range expressions and equivalence classes) and string collation.
LC_CTYPE
for regular expression matching, character classification, conversion, case-sensitive comparison, and wide character functions.
LC_MESSAGES
for localizable natural-language messages.
LC_MONETARY
for monetary formatting.
LC_NUMERIC
for number formatting (such as the decimal point and the thousands separator).
LC_TIME
for time and date formatting.

The argument locale is a pointer to a character string containing the required setting of category. Such a string is either a well-known constant like "C" or "da_DK" (see below), or an opaque string that was returned by another call of setlocale.

If locale is , each part of the locale that should be modified is set according to the environment variables. The details are implementation dependent. For glibc, first (regardless of category), the environment variable LC_ALL is inspected, next the environment variable with the same name as the category (LC_COLLATE, LC_CTYPE, LC_MESSAGES, LC_MONETARY, LC_NUMERIC, LC_TIME) and finally the environment variable LANG. The first existing environment variable is used. If its value is not a valid locale specification, the locale is unchanged, and setlocale returns NULL.

The locale C or POSIX is a portable locale; its LC_CTYPE part corresponds to the 7-bit ASCII character set.

A locale name is typically of the form language[_territory][.codeset][@modifier], where language is an ISO 639 language code, territory is an ISO 3166 country code, and codeset is a character set or encoding identifier like ISO-8859-1 or UTF-8. For a list of all supported locales, try "locale -a", cf. locale(1).

If locale is NULL, the current locale is only queried, not modified.

On startup of the main program, the portable C locale is selected as default. A program may be made portable to all locales by calling setlocale(LC_ALL, ) after program initialization, by using the values returned from a localeconv() call for locale - dependent information, by using the multi-byte and wide character functions for text processing if MB_CUR_MAX > 1, and by using strcoll(), wcscoll() or strxfrm(), wcsxfrm() to compare strings.  

RETURN VALUE

A successful call to setlocale() returns an opaque string that corresponds to the locale set. This string may be allocated in static storage. The string returned is such that a subsequent call with that string and its associated category will restore that part of the process's locale. The return value is NULL if the request cannot be honored.  

CONFORMING TO

ANSI C, POSIX.1  

NOTES

Linux (that is, GNU libc) supports the portable locales C and POSIX. In the good old days there used to be support for the European Latin-1 ISO-8859-1 locale (e.g. in libc-4.5.21 and libc-4.6.27), and the Russian KOI-8 (more precisely, "koi-8r") locale (e.g. in libc-4.6.27), so that having an environment variable LC_CTYPE=ISO-8859-1 sufficed to make isprint() return the right answer. These days non-English speaking Europeans have to work a bit harder, and must install actual locale files.  

SEE ALSO

locale(1), localedef(1), strcoll(3), isalpha(3), localeconv(3), strftime(3), charsets(4), locale(7), nl_langinfo(3)

责任编辑:韩亚珊 来源: CMPP.net
相关推荐

2011-08-24 16:48:36

man中文man

2011-08-15 10:21:09

man中文man

2011-08-11 16:11:49

at中文man

2011-08-25 10:21:56

man.conf中文man

2011-08-25 15:39:42

fcloseall中文man

2011-08-25 15:00:15

cfgetispeed中文man

2011-08-19 18:35:50

issue中文man

2011-08-25 17:03:51

pclose中文man

2011-08-25 17:40:25

setvbuf中文man

2011-08-23 14:21:16

poweroff中文man

2011-08-24 15:52:59

intro中文man

2011-08-23 13:40:31

2011-08-25 17:24:54

puts中文man

2011-08-25 18:34:55

ungetc中文man

2011-08-23 10:03:40

useradd中文man

2011-08-23 10:29:02

chpasswd中文man

2011-08-23 10:34:22

convertquot中文man

2011-08-23 15:39:34

rpmbuild中文man

2011-08-24 15:48:38

INSERT中文man

2011-08-25 09:40:49

UPDATE中文man
点赞
收藏

51CTO技术栈公众号