判断字符串的编码类型(GBK / UTF8)
来源:互联网 发布:魔法王座升阶数据大全 编辑:程序博客网 时间:2024/06/05 16:44
GBK:
_____________________________________________________________
int isgbk(char *s, size_t ns)
{
if(ns > 2 && (uint8_t)*s >= 0x81 && (uint8_t)*s <= 0xfe
&& (
((uint8_t)*(s+1) >= 0x80 && (uint8_t)*(s+1) <= 0x7e)
|| ((uint8_t)*(s+1) >= 0xa1 && (uint8_t)*(s+1) <= 0xfe)
)
)
{
return 1;
}
return 0;
}
{
if(ns > 2 && (uint8_t)*s >= 0x81 && (uint8_t)*s <= 0xfe
&& (
((uint8_t)*(s+1) >= 0x80 && (uint8_t)*(s+1) <= 0x7e)
|| ((uint8_t)*(s+1) >= 0xa1 && (uint8_t)*(s+1) <= 0xfe)
)
)
{
return 1;
}
return 0;
}
_______________________________________________________________
bool isGBKCode(const string& strIn)
{
unsigned char ch1;
unsigned char ch2;
if (strIn.size() >= 2)
{
ch1 = (unsigned char)strIn.at(0);
ch2 = (unsigned char)strIn.at(1);
if (ch1>=129 && ch1<=254 && ch2>=64 && ch2<=254)
return true;
else return false;
}
else return false;
}
______________________________________________________________
{
unsigned char ch1;
unsigned char ch2;
if (strIn.size() >= 2)
{
ch1 = (unsigned char)strIn.at(0);
ch2 = (unsigned char)strIn.at(1);
if (ch1>=129 && ch1<=254 && ch2>=64 && ch2<=254)
return true;
else return false;
}
else return false;
}
______________________________________________________________
UTF8:
______________________________________________________________
int isutf8(char *s, size_t ns)
{
uint8_t x = 0, i = 0, j = 0, nbytes = 0, n = 0;
for(i = 1; i < 7; i++)
{
x = (uint8_t)(255 << i);
if(((uint8_t)*s & x) == x)
{
n = nbytes = (8 - i);
for(j = 0; (j < nbytes && j < ns); j++)
{
if((uint8_t)s[j] <= 0x80 && (uint8_t)s[j] >= 0xc0)break;
else n--;
}
if(n == 0) return nbytes;
}
}
return 0;
}
{
uint8_t x = 0, i = 0, j = 0, nbytes = 0, n = 0;
for(i = 1; i < 7; i++)
{
x = (uint8_t)(255 << i);
if(((uint8_t)*s & x) == x)
{
n = nbytes = (8 - i);
for(j = 0; (j < nbytes && j < ns); j++)
{
if((uint8_t)s[j] <= 0x80 && (uint8_t)s[j] >= 0xc0)break;
else n--;
}
if(n == 0) return nbytes;
}
}
return 0;
}
______________________________________________________________
0 0
- 判断字符串的编码类型(GBK / UTF8)
- 判断字符串的编码类型(GBK / UTF8)
- 判断字符串是UTF8编码还是GBK编码
- php判断字符串的编码以及将字符串从GBK转换为UTF8字符集
- c++字符串编码GBK到UTF8的转换
- 判断字符串是否UTF8编码
- php检测字符串编码(utf-8,gbk,gb2312)是否为utf8编码的方法总结
- UTF8字符串的判断
- utf8与gbk字符编码的转换
- 网页编码utf8 gb2312 gbk的区别
- 【编码格式】GBK和UTF8 的区别
- php判断字符串编码是否为utf8的函数
- PHP判断字符串编码是否utf8并转换的方法
- PHP判断字符串编码是否utf8并转换的方法
- PHP判断字符串编码是否utf8并转换的方法
- 检测字节流的编码类型(GBK,UNICODE,GB18030,UTF8..)
- JAVA编码--Gbk-->Utf8
- GBK UTF8 编码转换
- 七大主流排序算法时间效率比较(基于C语言)
- unity3d刚体和碰撞检测学习一:新建一个plane和一个sphere,却碰撞检测失败的问题
- StreamWriter(流形式写入文本文件)
- Oba's Google Style
- linux C C++ 字符集转换,UTF-8,GB2312
- 判断字符串的编码类型(GBK / UTF8)
- Windows Server 2012&R2超级虚拟化之十一 软件定义网络之网络虚拟化
- 32 F 1 0X_XX宏定义的选择32 flash大小的选择
- Gas Station -- LeetCode
- codeforces#239_div2_C Triangle
- 面试官角度看招聘注意事项
- 在ListView存在下如何在布局底部放一个子布局
- Oracle 语句优化
- C++笔记:面向对象编程(Visual)