栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

语言环境如何在Linux / POSIX中工作,并且应用了哪些转换?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

语言环境如何在Linux / POSIX中工作,并且应用了哪些转换?

我将问题归结为

strcoll()
函数问题,该问题与Unipre规范化无关。回顾:我的最小示例展示了
uniq
依赖当前语言环境的不同行为:

$ echo -e "xc9xa2nxc9xac" > test.txt$ cat test.txtɢɬ$ LC_COLLATE=C uniq -D test.txt$ LC_COLLATE=en_US.UTF-8 uniq -D test.txtɢɬ

显然,如果语言环境是

en_US.UTF-8

uniq
对待
ɢ
ɬ
作为重复项,则情况并非如此。然后,我再次使用运行相同的命令,
valgrind
并使用来调查了两个调用图
kcachegrind

$ LC_COLLATE=C valgrind --tool=callgrind uniq -D test.txt$ LC_COLLATE=en_US.UTF-8 valgrind --tool=callgrind uniq -D test.txt$ kcachegrind callgrind.out.5754 &$ kcachegrind callgrind.out.5763 &

唯一的区别是,与该版本

LC_COLLATE=en_US.UTF-8
名为
strcoll()
LC_COLLATE=C
没有这样做。因此,我提出了以下最小示例
strcoll()

#include <iostream>#include <cstring>#include <clocale>int main(){    const char* s1 = "xc9xa2";    const char* s2 = "xc9xac";    std::cout << s1 << std::endl;    std::cout << s2 << std::endl;    std::setlocale(LC_COLLATE, "en_US.UTF-8");    std::cout << std::strcoll(s1, s2) << std::endl;    std::cout << std::strcmp(s1, s2) << std::endl;    std::setlocale(LC_COLLATE, "C");    std::cout << std::strcoll(s1, s2) << std::endl;    std::cout << std::strcmp(s1, s2) << std::endl;    std::cout << std::endl;    s1 = "xa2";    s2 = "xac";    std::cout << s1 << std::endl;    std::cout << s2 << std::endl;    std::setlocale(LC_COLLATE, "en_US.UTF-8");    std::cout << std::strcoll(s1, s2) << std::endl;    std::cout << std::strcmp(s1, s2) << std::endl;    std::setlocale(LC_COLLATE, "C");    std::cout << std::strcoll(s1, s2) << std::endl;    std::cout << std::strcmp(s1, s2) << std::endl;}

输出:

ɢɬ0-1-10-1��0-1-10-1

那么,这怎么了?为什么对两个不同的字符

strcoll()
返回
0
(等于)?



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/412478.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号