是否有受 setlocale() 影响的完整函数列表?
Is there a comprehensive list of functions affected by setlocale()?
所以我们都知道调用 setlocale()
会导致许多 C 运行时函数根据当前活动的语言环境更改其行为。例如,当使用德语语言环境时,strtod()
会突然期望用逗号将整数与数字的小数部分分开,因为这是德语中浮点数的表示方式。
我正在寻找的是所有 C 运行时函数的完整列表,这些函数可能会受到调用setlocale()
的影响。 man pages of setlocale 提到了一些功能,但列表远未完成,例如strtod()
根本没有提到。
我为什么要找这样的列表?我需要将几个项目从可移植的 "C" 语言环境转换到系统的语言环境,我不想破坏任何东西,所以我需要 grep 查找可能受语言环境更改影响的所有 C 运行时函数,以便适应或修复代码以与任意语言环境兼容,而不仅仅是便携式 "C" 语言环境。
我认为这不存在,但是 POSIX 列出了一些直接依赖于语言环境和语言环境相关变量的函数 The Open Group Base Specifications Issue 7, 2018 edition, 7 Locale。我不认为这是详尽无遗的(我很确定它不是)。据说:
The standard utilities in the Shell and Utilities volume of
POSIX.1-2017 shall base their behavior on the current locale, as
defined in the ENVIRONMENT VARIABLES section for each utility. The
behavior of some of the C-language functions defined in the System
Interfaces volume of POSIX.1-2017 shall also be modified based on a
locale selection.
这意味着(对我而言):阅读功能手册...
您在标准 C 中也有关于此的信息:7.11.1 语言环境控制:
7.11.1 Locale control
7.11.1.1 The setlocale
function
The setlocale function selects the appropriate portion of the
program’s locale as specified by the category and locale arguments.
The setlocale function may be used to change or query the program’s
entire current locale or portions thereof. The value LC_ALL
for
category names the program’s entire locale; the other values for
category name only a portion of the program’s locale. LC_COLLATE
affects the behavior of the strcoll
and strxfrm
functions. LC_CTYPE
affects the behavior of the character handling functions, see 7.4) and the
multibyte and wide character functions. LC_MONETARY
affects the
monetary formatting information returned by the localeconv
function.
LC_NUMERIC
affects the decimal-point character for the formatted
input/output functions and the string conversion functions, as well as
the nonmonetary formatting information returned by the localeconv
function. LC_TIME
affects the behavior of the strftime
and wcsftime
functions.
和
7.4 Character handling
7.4.1 Character classification functions
7.4.1.1 The isalnum
function
7.4.1.2 The isalpha
function
7.4.1.3 The isblank
function
7.4.1.4 The iscntrl
function
7.4.1.5 The isdigit
function
7.4.1.6 The isgraph
function
7.4.1.7 The islower
function
7.4.1.8 The isprint
function
7.4.1.9 The ispunct
function
7.4.1.10 The isspace
function
7.4.1.11 The isupper
function
7.4.1.12 The isxdigit
function
7.4.2 Character case mapping functions
7.4.2.1 The tolower
function
7.4.2.2 The toupper
function
所以我们都知道调用 setlocale()
会导致许多 C 运行时函数根据当前活动的语言环境更改其行为。例如,当使用德语语言环境时,strtod()
会突然期望用逗号将整数与数字的小数部分分开,因为这是德语中浮点数的表示方式。
我正在寻找的是所有 C 运行时函数的完整列表,这些函数可能会受到调用setlocale()
的影响。 man pages of setlocale 提到了一些功能,但列表远未完成,例如strtod()
根本没有提到。
我为什么要找这样的列表?我需要将几个项目从可移植的 "C" 语言环境转换到系统的语言环境,我不想破坏任何东西,所以我需要 grep 查找可能受语言环境更改影响的所有 C 运行时函数,以便适应或修复代码以与任意语言环境兼容,而不仅仅是便携式 "C" 语言环境。
我认为这不存在,但是 POSIX 列出了一些直接依赖于语言环境和语言环境相关变量的函数 The Open Group Base Specifications Issue 7, 2018 edition, 7 Locale。我不认为这是详尽无遗的(我很确定它不是)。据说:
The standard utilities in the Shell and Utilities volume of POSIX.1-2017 shall base their behavior on the current locale, as defined in the ENVIRONMENT VARIABLES section for each utility. The behavior of some of the C-language functions defined in the System Interfaces volume of POSIX.1-2017 shall also be modified based on a locale selection.
这意味着(对我而言):阅读功能手册...
您在标准 C 中也有关于此的信息:7.11.1 语言环境控制:
7.11.1 Locale control
7.11.1.1 The
setlocale
functionThe setlocale function selects the appropriate portion of the program’s locale as specified by the category and locale arguments. The setlocale function may be used to change or query the program’s entire current locale or portions thereof. The value
LC_ALL
for category names the program’s entire locale; the other values for category name only a portion of the program’s locale.LC_COLLATE
affects the behavior of thestrcoll
andstrxfrm
functions.LC_CTYPE
affects the behavior of the character handling functions, see 7.4) and the multibyte and wide character functions.LC_MONETARY
affects the monetary formatting information returned by thelocaleconv
function.LC_NUMERIC
affects the decimal-point character for the formatted input/output functions and the string conversion functions, as well as the nonmonetary formatting information returned by the localeconv function.LC_TIME
affects the behavior of thestrftime
andwcsftime
functions.
和
7.4 Character handling
7.4.1 Character classification functions
7.4.1.1 The
isalnum
function7.4.1.2 The
isalpha
function7.4.1.3 The
isblank
function7.4.1.4 The
iscntrl
function7.4.1.5 The
isdigit
function7.4.1.6 The
isgraph
function7.4.1.7 The
islower
function7.4.1.8 The
isprint
function7.4.1.9 The
ispunct
function7.4.1.10 The
isspace
function7.4.1.11 The
isupper
function7.4.1.12 The
isxdigit
function7.4.2 Character case mapping functions
7.4.2.1 The
tolower
function7.4.2.2 The
toupper
function