作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
大家好!
在土耳其语中,字母表中的一个字母具有不同的行为,即 I - 和 i-。在英语中,I 和 i 是大写和小写。在土耳其语中,I 的小写不是 i,而是 ı。
因此在土耳其语环境(即 Windows)中,“DOMAIN.COM”和“domain.com”并不相等。由于电子邮件传输和DNS完全是英文的,如果邮件地址中包含大写的I,可能会出现问题。
在 C# 中,我们可以使用 InvariantCultureIgnoreCase 标志来纠正这个问题:
// Mock
string localDomain = "domain.com";
string mailAddress = "USER@DOMAIN.COM";
string domainOfAddress = mailAddress.Split('@')[1];
string localInbox = "";
//
// Local inbox check
//Case insensitive method
bool ignoreCase = true; // Equal to StringComparison.CurrentCultureIgnoreCase
if (System.String.Compare(localDomain, domainOfAddress, ignoreCase) == 0)
{
// This one fails in Turkish environment
localInbox = mailAddress.Split('@')[0];
}
//Culture-safe version
if (System.String.Compare(localDomain, domainOfAddress, StringComparison.InvariantCultureIgnoreCase) == 0)
{
// This one is the correct/universal method
localInbox = mailAddress.Split('@')[0];
}
由于我没有使用 C++ 的经验,这两个示例的 C++ 等价物 是什么?
最佳答案
如果您在 Windows
中编程,您可以将线程的 locale
更改为 en_US
然后使用 _stricmp
,或者为 en_US
创建一个语言环境对象,然后使用 _stricmp_l
:
setlocale( LC_CTYPE, "English" );
assert( _stricmp("DOMAIN", "domain") == 0 );
_locale_t l = _create_locale( LC_CTYPE, "English" );
assert( _stricmp_l("DOMAIN", "domain", l) == 0 );
如果 boost
是您的选择,一个更便携和 C++ 友好的解决方案是使用 boost::locale图书馆
关于c++ - C++ 中 Turkish-I 的解决方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13146241/
我是一名优秀的程序员,十分优秀!