C++ 计算字符创长度之Function(包含unicode,utf-8),包含特殊字符

时间:2014-02-22 09:26:13   收藏:0   阅读:457



//字符串长度

int calcCharCount(const char *pszText)

{

    int n = 0;

    char ch = 0;

    while ((ch = *pszText))

    {

        CC_BREAK_IF(! ch);

        

        if ((0x80 & ch) == 0x00) {

            n++;

        } else if (0x80 != (0xC0 & ch)) {

            n+=2;

        }

        ++pszText;

    }

    return n;

}




//包含特殊字符

bool checkSpecialCharacter(string text)

{

    char temp;

    for (int i =0; i <text.length(); i++) {

        temp = text[i];

        

        if ((temp >= 0 && temp <= 47) || (temp >= 58 && temp<= 64) || (temp >=91 && temp <= 96) || (temp >= 123 && temp <= 223 )) {

            CCLog("用户名称包含特殊字符");

            return true;

        }

    }

    return false;

}



原文:http://blog.csdn.net/wisdom605768292/article/details/19614325

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!