提升string_algo的to_upper函数不考虑语言环境 [英] boost to_upper function of string_algo doesn't take into account the locale
问题描述
我对string_algo软件包中的功能有疑问.
I have a problem with the functions in the string_algo package.
考虑这段代码:
#include <boost/algorithm/string.hpp>
int main() {
try{
string s = "meißen";
locale l("de_DE.UTF-8");
to_upper(s, l);
cout << s << endl;
catch(std::runtime_error& e){
cerr << e.what() << endl;
}
try{
string s = "composición";
locale l("es_CO.UTF-8");
to_upper(s, l);
cout << s << endl;
catch(std::runtime_error& e){
cerr << e.what() << endl;
}
}
此代码的预期输出为:
MEISSEN
COMPOSICIÓN
但是我唯一得到的是
MEIßEN
COMPOSICIóN
因此,很明显,没有考虑区域设置.我什至尝试设置全局语言环境都没有成功.我该怎么办?
so, clearly the locale is not being taken into account. I even try to set the global locale with no success. What can I do?
推荐答案
std :: toupper假定为1:1转换,因此从ß到SS的情况(没有Boost.StringAlgo)都没有希望.
std::toupper assumes a 1:1 conversion, so there is no hope for the ß to SS case, Boost.StringAlgo or not.
查看 StringAlgo的代码,我们看到它确实使用语言环境(似乎Borland除外).因此,对于另一种情况,我很好奇:您的平台上toupper('ó', std::locale("es_CO.UTF-8"))
的结果是什么?
Looking at StringAlgo's code, we see that it does use the locale (Except on Borland, it seems). So, for the other case, I'm curious: What is the result of toupper('ó', std::locale("es_CO.UTF-8"))
on your platform?
以上内容使我想到了其他事情:源代码中字符串的编码是什么? UTF8?在这种情况下,std :: toupper将看到两个代码单元ó",因此没有希望.拉丁文1?在这种情况下,使用名为".UTF-8"的语言环境是不一致的.
Writing the above makes me think about something else: What is the encoding of the strings in your sources? UTF8? In that case, std::toupper will see two code units for 'ó', so there is no hope. Latin1? In that case, using a locale named ".UTF-8" is inconsistent.
这篇关于提升string_algo的to_upper函数不考虑语言环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!