资源简介
跨平台(windows Linux)是纯c实现 gbk/utf8互转,Ansi/Utf8互转,
代码片段和文件信息
#include “public_functions.h“
#include “strnormalize.h“
namespace PublicFunctions
{
std::string AnsiToUtf8(const char* sAnsi)
{
std::string strRet;
if (sAnsi == NULL || strlen(sAnsi) == 0) {
return strRet;
}
str_normalize_init();
size_t gbk_len = strlen(sAnsi);
unsigned int utf8buffer_len = gbk_len * 3 + 1;
char *utf8buffer = (char *)malloc(utf8buffer_len);
memset(utf8buffer 0 utf8buffer_len);
gbk_to_utf8(sAnsi gbk_len &utf8buffer &utf8buffer_len);
strRet = utf8buffer;
free(utf8buffer);
return strRet;
}
std::string Utf8ToAnsi(const char* sUtf8)
{
std::string strAnsi;
if (sUtf8 == NULL || strlen(sUtf8) == 0) {
return strAnsi;
}
str_normalize_init();
unsigned int utf8_len = strlen(sUtf8);
unsigned int gbkbuffer_len = utf8_len * 2 + 1;
char *gbkbuffer = (char *)malloc(gbkbuffer_len);
memset(gbkbuffer 0 gbkbuffer_len);
utf8_to_gbk(sUtf8 utf8_len &gbkbuffer &gbkbuffer_len);
strAnsi = gbkbuffer;
free(gbkbuffer);
return strAnsi;
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 373 2017-12-04 20:47 public_functions.h
文件 458513 2017-12-04 16:30 strnormalize.c
文件 882 2017-12-04 20:43 strnormalize.h
文件 1071 2017-12-04 20:47 public_functions.cpp
----------- --------- ---------- ----- ----
460839 4
- 上一篇:高斯混合模型直观实现
- 下一篇:msado.dll用于ado
评论
共有 条评论