串转换与提升区域:在Windows和Linux不同的行为 [英] string conversion with boost locale: different behaviour on windows and linux

查看:146
本文介绍了串转换与提升区域:在Windows和Linux不同的行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的样本code:

This is my sample code:

#pragma execution_character_set("utf-8")

#include <boost/locale.hpp>
#include <boost/algorithm/string/case_conv.hpp>
#include <iostream>

int main()
{
    std::locale loc = boost::locale::generator().generate("");
    std::locale::global(loc);

#ifdef MSVC
    std::cout << boost::locale::conv::from_utf("grüßen vs ", "ISO8859-15");
    std::cout << boost::locale::conv::from_utf(boost::locale::to_upper("grüßen"), "ISO8859-15") << std::endl;
    std::cout << boost::locale::conv::from_utf(boost::locale::fold_case("grüßen"), "ISO8859-15") << std::endl;
    std::cout << boost::locale::conv::from_utf(boost::locale::normalize("grüßen", boost::locale::norm_nfd), "ISO8859-15") << std::endl;
#else
    std::cout << "grüßen vs ";
    std::cout << boost::locale::to_upper("grüßen") << std::endl;
    std::cout << boost::locale::fold_case("grüßen") << std::endl;
    std::cout << boost::locale::normalize("grüßen", boost::locale::norm_nfd) << std::endl;
#endif

    return 0;
}

在Windows 7上输出是:

Output on Windows 7 is:

grüßen vs GRÜßEN
grüßen
grußen

在Linux(openSUSE的12.3)输出是:

Output on Linux (openSuSE 12.3) is:

grüßen vs GRÜSSEN
grüssen
grüßen

在Linux上的德国字母SS转换为SS作为pdicted $ P $,而这个角色将保持不变的Windows。

On Linux the german letter 'ß' is converted to 'SS' as predicted, while this character remains unchanged on Windows.

问:为什么会这样?我怎样才能正确的转换?

Question: why is this so? How can I correct the conversion?

一些注意事项:Windows控制台codePAGE设置为1252。在这两种情况下,区域设置都设置为de_DE。我试图通过以上de_DE.UTF-8替换默认的语言环境中的上市设置 - 无任何影响。
在Windows上,code与Visual Studio 2013编译的Linux上,GCC 4.7,C ++ 11功能。

Some notes: Windows console codepage is set to 1252. In both cases locales are set to de_DE. I tried to replace the default locale setting in the listing above by "de_DE.UTF-8" - without any effect. On Windows this code is compiled with Visual Studio 2013, on Linux with GCC 4.7, c++11 enabled.

任何建议都AP preciated - !在此先感谢您的支持

Any suggestions are appreciated - thanks in advance for your support!

推荐答案

Windows不会做这种转换,因为如果字符串长度变突然这将是太混乱的开发者。并提高presumably只是代表所有的Uni code转换到底层的Windows API

Windows doesn't do this conversion because "it would be too confusing" for developers if the string length changed all of a sudden. And boost presumably just delegates all the Unicode conversions to the underlying Windows APIs

<一个href=\"http://connect.microsoft.com/VisualStudio/feedback/details/619924/system-string-toupper-doesnt-follow-uni$c$c-specialcasing\"相对=nofollow>来源

我猜可靠的方法来处理它是使用第三方的Uni code库,如ICU。

I guess the robust way to handle it would be to use a third-party Unicode library such as ICU.

这篇关于串转换与提升区域:在Windows和Linux不同的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆