C 中土耳其语I的解决方案

Solution for Turkish-I in C++

本文关键字:解决方案 土耳其语      更新时间:2023-10-16

嗨,hi all!

在土耳其语中,字母之一的字母具有不同的行为,就是i和i-。在英语中,我和我很高&较低的情况。在土耳其小写中,我不是我,而是ı

因此,在土耳其环境(即窗口)中," domain.com"answers" domain.com"并不相等。由于电子邮件运输&DNS完全用英语,如果邮件地址包含大写I,则可能有问题。

在c#中,我们可以使用 novariantcultureignorecase flag纠正问题:

        // 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 Library

相关文章: