看到有前辈写了一个UTF-8与UNICODE相互转换的代码,顺便提一下,希望可以给大家提供一点帮助.
下面是一些编码格式的bit长
Examples of fixed-width encoding forms:
Type
Each character
encoded as
Notes
7-bit |
a single 7-bit quantity |
example: ISO 646 |
8-bit G0/G1 |
a single 8-bit quantity |
with constraints on use of C0 and C1 spaces |
8-bit |
a single 8-bit quantity |
with no constraints on use of C1 space |
8-bit EBCDIC |
a single 8-bit quantity |
with the EBCDIC conventions rather than ASCII conventions |
16-bit (UCS-2) |
a single 16-bit quantity |
within a code space of 0..FFFF |
32-bit (UCS-4) |
a single 32-bit quantity |
within a code space 0..7FFFFFFF |
32-bit (UTF-32) |
a single 32-bit quantity |
within a code space of 0..10FFFF |
16-bit DBCS process code |
a single 16-bit quantity |
example: UNIX widechar implementations of Asian CCS's |
32-bit DBCS process code |
a single 32-bit quantity |
example: UNIX widechar implementations of Asian CCS's |
DBCS Host |
two 8-bit quantities |
following IBM host conventions |
Examples of variable-width encoding forms:
Name
Characters are encoded as
Notes
UTF-8 |
a mix of one to four 8-bit code units in Unicode
and one to six code units in 10646 |
used only with Unicode/10646 |
UTF-16 |
a mix of one to two 16 bit code units |
used only with Unicode/10646 |
Boost中提供了一个UTF-8 Codecvt Facet,可以在utf8和UCS-4(Unicode-32)之间转换.
使用方式如下
//...
// My encoding type
typedef wchar_t ucs4_t;
std::locale old_locale;
std::locale utf8_locale(old_locale,new utf8_codecvt_facet<ucs4_t>);
// Set a New global locale
std::locale::global(utf8_locale);
// UCS-4 转换为 UTF-8
{
std::wofstream ofs("data.ucd");
ofs.imbue(utf8_locale);
std::copy(ucs4_data.begin(),ucs4_data.end(),
std::ostream_iterator</ucs4_t>
分享到:
相关推荐
采用codecvt标准库写的 utf-8、gbk互转支持vs2010、2012
C ++ 11在核心语言和库级别上提供了对Unicode的一些支持:u8,u和U字符和字符串文字,char16_t和char32_t字符类型,u16string和u32string库类,以及codecvt支持在Unicode编码形式之间进行转换。 同时,开发人员使用...
msvcp140-codecvt-ids.dll
系统依赖DLL动态库
系统依赖DLL动态库
1. 变量初始化 这是使用 C++11 codecvt 时遇到的一个坑,转换编码时,mbstate_t 这个中间状态变量,必须初始化为0,否则运行出错,即: // 不可以!... 这个坑要和 boost 进行比较,在 boost
dll控件常规安装方法(仅供参考): 一、如果在运行某软件或编译程序时提示缺少、找不到dll等类似提示,您可将下载来的dll拷贝到指定目录即可(一般是system系统目录或放到软件同级目录里面),或者重新添加文件引用...
STLport-4.5.3 里面包含源码,文档,使用说明,test etc
<br/>需要注意的是codecvt的转换是针对日文的,这主要跟我的工作有关,大家不需要的话可以不用关心。而native2ascii.exe是JDK带的工具,大家可以改变一下它的参数来适应中文的转换。 ----------...
Ext 界面编辑器 flsh 界面 ,让ext的布局更加轻松。
把需要分词去停用词的文件放入allData文件夹下的originalData文件夹,依次运行1.cutWord.py和2removeStopWord.py之后,allData文件夹下的afterRemoveStopWordData文件夹就是最终分词且去停用词之后的文件