资源简介
utf16 utf8 ascii unicode
所有代码都已经经过验证。而且里面也有相应的例子。
所有的编码格式进行转换,windows平台。

代码片段和文件信息
#include “utfTools.h“
#include
#include
using namespace std;
CUtfTools* CUtfTools::getInstance()
{
static CUtfTools gCUtfTools;
return &gCUtfTools;
}
CUtfTools::CUtfTools()
{
}
CUtfTools::~CUtfTools()
{
}
int CUtfTools::Utf16_To_Utf8(MYUTF16* sourceStart MYUTF8* targetStart size_t outLen ConversionFlags flags SourceDataByteOrder byteOrder)
{
int result = 0;
MYUTF16* source = sourceStart;
MYUTF8* target = targetStart;
MYUTF8* targetEnd = targetStart + outLen;
if ((NULL == source) || (NULL == targetStart)){
printf(“ERR Utf16_To_Utf8: source=%p targetStart=%p\n“ source targetStart);
return conversionFailed;
}
while (*source) {
//网络上的数据都是大端,权重越大的数据优先传输
if (byteOrder == BigEndian)
{
*source = ntohs(*source);
}
MYUTF32 ch;
unsigned short bytesToWrite = 0;
const MYUTF32 byteMask = 0xBF;
const MYUTF32 byteMark = 0x80;
MYUTF16* oldSource = source; /* In case we have to back up because of target overflow. */
ch = *source++;
/* If we have a surrogate pair convert to UTF32 first. */
if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_HIGH_END) {
/* If the 16 bits following the high surrogate are in the source buffer... */
if (*source){
MYUTF32 ch2 = *source;
/* If it‘s a low surrogate convert to UTF32. */
if (ch2 >= UNI_SUR_LOW_START && ch2 <= UNI_SUR_LOW_END) {
ch = ((ch - UNI_SUR_HIGH_START) << halfShift) + (ch2 - UNI_SUR_LOW_START) + halfbase;
++source;
}
else if (flags == strictConversion) { /* it‘s an unpaired high surrogate */
--source; /* return to the illegal value itself */
result = sourceIllegal;
break;
}
}
else { /* We don‘t have the 16 bits following the high surrogate. */
--source; /* return to the high surrogate */
result = sourceExhausted;
break;
}
}
else if (flags == strictConversion) {
/* UTF-16 surrogate values are illegal in UTF-32 */
if (ch >= UNI_SUR_LOW_START && ch <= UNI_SUR_LOW_END){
--source; /* return to the illegal value itself */
result = sourceIllegal;
break;
}
}
/* Figure out how many bytes the result will require */
if (ch < (MYUTF32)0x80){
bytesToWrite = 1;
}
else if (ch < (MYUTF32)0x800) {
bytesToWrite = 2;
}
else if (ch < (MYUTF32)0x10000) {
bytesToWrite = 3;
}
else if (ch < (MYUTF32)0x110000){
bytesToWrite = 4;
}
else {
bytesToWrite = 3;
ch = UNI_REPLACEMENT_CHAR;
}
target += bytesToWrite;
if (target > targetEnd) {
source = oldSource; /* Back up source pointer! */
target -= bytesToWrite; result = targetExhausted; break;
}
switch (bytesToWrite) { /* note: everything falls through. */
case 4: *--target = (MYUTF8)((ch | byteMark) & byteMask); ch >>= 6;
case 3: *--target = (MYUTF8)((ch | byteMark) & byteMask); ch >>= 6;
case 2: *--target = (MYUTF8)((ch | byteMark) & byteMask); ch >>= 6;
case 1
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 320 2019-01-25 09:32 readMe.txt
文件 16729 2019-01-25 09:17 utfTools.cpp
文件 3762 2019-01-25 09:10 utfTools.h
文件 33628 2019-01-25 09:33 字符编码.docx
- 上一篇:大学生宿舍管理系统数据库设计
- 下一篇:RDA5851完整规格书
相关资源
- UNICODE GBK双向码表二进制文件
- 常用编码(UnicodeUTF-8GBK)转换工具
- 中文转化unicoder码的方法
- 易语言QQTEA算法源码
- UTF8编码表汉字对照
- 易语言查询话费欠费信息源码
- Discuz! X2 简体中文 UTF8.zip
- 程序员输入法unicode版
- 维吾尔文字符集unicode编码表
- 维吾尔文unicode编码表
- 字库工具 guitool(Trial) Setup 1.13.rar
- DFM文件Unicode汉字转换器 V1.3
- 08cms房产8.1-UTF8补丁包单城市多城市共
- 通用规范汉字表8105字及化学元素周期
- 谭松波-酒店评论语料-utf8gb 两种格式
- ECShop_V2.7.0_UTF8_Release0720
- cacti_linux_安装包分卷5(cacti-0.8.7b-cn
- EzCad2.7.0_UNICODE(20120326)新狗
- ECSHOP_V2.7.2_utf8_release0604.zip
- cscms_v3.5_utf8
- IdHTTPServer+utf8转换+json解析
- ECShop_V2.7.3_UTF8 完整版
- DedeCMS5.7UTF8华丽蓝色后台管理界面模板
- 12*1216*16完整点阵字库包含所有unicod
- ueditor-1.4.3.3 utf8-net
- 简约_通用_自由配色 电脑版(UTF8编码
- ueditor1_4_3_3-utf8-net.zip
- sourceinsight3.5-可用版+UTF8插件+多标签插
- espcms_utf8_v5.8.14.02.12
- 用MR和Hive对sougou.500w.utf8进行数据分析
评论
共有 条评论