C++ Unicode检测中文

来源:互联网 发布:淘宝自定义区怎么设置 编辑:程序博客网 时间:2024/05/21 10:34
// 这个函数检测输入的Unicode字符串在首字母不是数字的前提下,是否是由字母、数字和汉字组成,不能包含ASCII码表的特殊字符(下划线和丨线除外)
bool VerifyAccountName(wstring wstrName){bool            bFlag = false;do {if (wstrName[0] >= L'0' && wstrName[0] <= L'9')break;int nLen = wstrName.length();for (int i = 0; i < nLen; i++){// 数字以前的字符if (wstrName[i] >= 0 && wstrName[i] < 48){goto __ExitProc; }// 数字和大写字母之间的字符if (wstrName[i] > 57 && wstrName[i] < 65){goto __ExitProc; }// 大写和小写字母之间的字符if (wstrName[i] > 90  && wstrName[i] < 97){// 只可以使用下划线if (wstrName[i] != L'_'){goto __ExitProc; }elsecontinue;}if (wstrName[i] > 122 && wstrName[i] < 256){if (wstrName[i] != L'|'){goto __ExitProc; }elsecontinue;}// 判断下是不是中文,这里根据Unicode汉字编码表返回进行判断,这里要根据系统的内存布局来调整unsigned char* pCh = (unsigned char*)&wstrName[i];if (((*pCh >= 0) && (*pCh <= 0xff)) && (*(pCh + 1) >= 0x4e && *(pCh + 1) <= 0x95))continue;elsegoto __ExitProc;  // 不是中文}bFlag = true;} while (false);__ExitProc:return bFlag;}

0 0
原创粉丝点击