Ascii utf8 Unicode 字符串转换
来源:互联网 发布:mysql 5.6.25.tar.gz 编辑:程序博客网 时间:2024/06/10 05:05
简介
最近在做Sqlite相关代码,发现Sqlite只支持utf_8字符集,因此需要unicode/ascii到utf_8的转换,因此记录下一下代码,方便一会重用;
linux下支持并未编写,因此用 static_assert(false)阻止编译通过
代码
std::string BLES_EXPORT AsciiToUtf8( const std::string& aStr ){//先把 ascii 转为 unicode std::wstring wstr = AsciiToUnicode( aStr );//最后把 unicode 转为 utf8return UnicodeToUtf8(wstr);}std::string BLES_EXPORT UnicodeToAscii( const std::wstring wStr ){std::string resultstring;#ifdef SC_WINint widesize = WideCharToMultiByte (CP_ACP, 0, wStr.c_str(), -1, NULL, 0, NULL, NULL );assert( 0 != widesize );resultstring.resize(widesize);int convresult = ::WideCharToMultiByte(CP_ACP, 0, wStr.c_str(), -1, (char*)resultstring.c_str(), widesize, NULL, NULL);assert( convresult == widesize );#elsestatic_assert( 0 );#endifreturn resultstring;}std::string BLES_EXPORT Utf8ToAscii( const std::string& utf8Str ){std::wstring wstr = Utf8ToUnicode( utf8Str );return UnicodeToAscii( wstr );}std::wstring BLES_EXPORT Utf8ToUnicode( const std::string& utf8Str ){std::wstring resultstring;#ifdef SC_WINint widesize = MultiByteToWideChar (CP_ACP, 0, (char*)utf8Str.c_str(), -1, NULL, 0);assert( widesize != ERROR_NO_UNICODE_TRANSLATION &&0 != widesize );resultstring.resize(widesize);int convresult = MultiByteToWideChar (CP_ACP, 0, (char*)utf8Str.c_str(), -1, (wchar_t*)resultstring.c_str(), widesize);assert( convresult == widesize );#elsestatic_assert( 0 );#endifreturn resultstring;}
- Ascii utf8 Unicode 字符串转换
- ASCII/UNICODE/UTF8字符串互相转换的C++代码
- UTF8, ASCII, UNICODE相互转换
- ASCII,UniCode&UTF8编码
- unicode utf8 ascii
- ASCII Unicode UTF8
- ASCII字符串与UNICODE字符串转换
- 字符串处理 - ANSI - Unicode - UTF8 转换
- 字符串处理 - ANSI - Unicode - UTF8 转换
- win32 字符串 utf8 unicode ansi相互转换
- 字符串处理 - ANSI - Unicode - UTF8 转换
- 字符串处理 - ANSI - Unicode - UTF8 转换
- 字符串处理 - ANSI - Unicode - UTF8 转换
- 字符串处理 - ANSI - Unicode - UTF8 转换
- 常用字符转换 string wstring utf8 unicode ascii
- 【Python】utf8,unicode,ascii编码的相互转换
- 基础知识Notes: 字符串编码(ASCII, Unicode and UTF8)
- ASCII,UTF-8,Unicode字符串相互转换
- 中国“天河二号”成为全球最快超级计算机
- 音乐播放器之源码解析五
- poj 2533 LCS
- 使用xjc生成java类
- 2013java面试题2(答案会更新)
- Ascii utf8 Unicode 字符串转换
- C++基本数据类型
- Android之Button
- 黑马程序员_关于System.Object
- Hadoop安全云盘开发(第2篇)
- NO2:设置RedHat Linux下的samba开机启动
- 音乐播放器之源码解析六
- IE上载Office2007文件时在上载对话框中变成ZIP文件有关问题的解决
- 面试题3