/* 统一按照GBK格式计算字符串长度 */
int astrlen_gbk(const char *str)
{
const char *p_ch = NULL;
int len = 0;
int byte = 0;
if (!str)
return 0;
p_ch = str;
while (*p_ch)
{
if (*p_ch & 0x80)
{
char num = *p_ch;
byte = 0;
//GBK
if ((num & 0xC0) == 0x80)
byte = 2;
else
{
//GBK或UTF8
while (num & 0x80)
{
byte += 1;
num <<= 1;
}
}
p_ch += byte;
len += 2;
}
else
{
len++;
p_ch++;
}
}
return len;
}
UTF8/GBK编码字符串统一按照GBK格式计算长度
最新推荐文章于 2023-02-03 15:43:23 发布