本文介绍了在C ++中比较字符串fussballmanager和fußballmanager的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在SQL中,你可以根据整理成功比较两个字符串
使用Latin1_General_CI_AS,fussballmanager和fußballmanager被认为是平等的。
它们与SQL_Latin1_General_CP1_CI_AS不同。
我试图在C ++中复制相同的行为。我理解它依赖于语言环境,我希望有一些代码,用户可以决定使用哪个语言环境。
我尝试了什么:
STL
std :: locale loc1(german );
wstring a(fussballmanager);
wstring b(fußballmanager);
const std :: collate< wchar_t>& coll = use_facet< std :: collate< wchar_t> >(LOC1);
int nRes = coll.compare(a.data(),a.data()+ a.size(),
b.data(),b.data()+ b.size() );
// => nRes是1而不是0
BOOST
boost :: locale :: generator gen;
std :: locale loc = gen(en-GB);
std :: locale :: global(loc);
wstring a(fussballmanager);
wstring b(fußballmanager);
int nRes = use_facet< boost :: locale :: collator< wchar_t> >(loc).compare(boost :: locale :: collator_base :: primary,a,b);
//崩溃在这里(如果我将区域设置字符串留空,它会起作用:用
解决方案
In SQL, you can compare successfully two strings depending on the collation
With Latin1_General_CI_AS, fussballmanager and fußballmanager are considered equal.
They are different with SQL_Latin1_General_CP1_CI_AS.
I am trying to replicate the same behaviour in C++. I understand it's dependent on the locale and I would like to have some code where the user can decide which locale to use.
What I have tried:
STL
std::locale loc1("german"); wstring a("fussballmanager"); wstring b("fußballmanager"); const std::collate<wchar_t>& coll = use_facet<std::collate<wchar_t> >(loc1); int nRes = coll.compare(a.data(), a.data() + a.size(), b.data(), b.data() + b.size()); // => nRes is 1 not 0
BOOST
boost::locale::generator gen; std::locale loc = gen("en-GB"); std::locale::global(loc); wstring a("fussballmanager"); wstring b("fußballmanager"); int nRes = use_facet<boost::locale::collator<wchar_t> >(loc).compare(boost::locale::collator_base::primary, a, b); // Crash here (it works if I leave the locale string empty: replace en-GB by ""
解决方案
这篇关于在C ++中比较字符串fussballmanager和fußballmanager的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!