资源简介
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完整规格书
相关资源
- Discuz新秀网络验证系统-UTF8-ver3.0 - 珍
- DOS或CMD命令下文本UTF8转ANSI软件
- 汉字编码转换工具(汉字与utf-8转换
- uchome2.0模板简约版风格utf8
- shellcode与unicode互相转换器
- 完整UNICODE编码表
- 汉字gbk编码与unicode编码对应数组
- Unicode串口通信Demo
- unicode字符编码表
- Unicode编码与汉字互转.rar
- gb2312和utf8相互转换
- GB2312简体中文编码表+Unicode汉字编码表
- pb9.0 UTF-8 编码转换为Unicode 编码格式
- 文本文件编码转换:ANSI、Unicode、UT
- QQwry.dat utf8
- 支付宝快登ECSHOP支付宝用插件 utf8.r
- ecshop2.7.3 utf8 PC端微信扫码支付插件
- 汉字笔画笔顺Unicode和GB码数据库(2
- 完整汉字笔画笔顺Unicode和GB码数据库
- Txt批量转UTF-8的工具
- 帝国CMS7.5后台模板美化版UTF8V2.0-精准
- pc-font-unicode (14种语言的unicode编码文
- utf8‘‘6位数字典.7z
- Delphi简单DirectUI界面源码Unicode版
- CSerialPort类 VS2015 unicode可用
- 多国语言开发必备工具(点阵字库+多
- Labview 字符串和UTF8的相互转换
- 如何将一个ansi的文本文件转为unicod
- sogou-dic-utf8搜狗词库
- labview text to utf8
评论
共有 条评论