Chinaunix首页 | 论坛 | 博客
  • 博客访问: 6906676
  • 博文数量: 3857
  • 博客积分: 6409
  • 博客等级: 准将
  • 技术积分: 15948
  • 用 户 组: 普通用户
  • 注册时间: 2008-09-02 16:48
个人简介

迷彩 潜伏 隐蔽 伪装

文章分类

全部博文(3857)

文章存档

2017年(5)

2016年(63)

2015年(927)

2014年(677)

2013年(807)

2012年(1241)

2011年(67)

2010年(7)

2009年(36)

2008年(28)

分类: C/C++

2014-01-17 09:59:47

原文地址:node.js 中文编码支持 作者:ygfinsight

1.node.js 默认支持编码方式为UTF-8,代码写好后,需转换为UTF-8编码方式才能正确显示中文。
2.如果编码方式不是UTF-8,在写c++ addons过程中会出现加载模块问题。
3.v8返回的字符串默认也是UTF-8编码,为了支持中文,首先要将字符串转化为UTF-8编码。
常用的转化:
char* GBKToUtf8(const char* strGBK)

int len=MultiByteToWideChar(CP_ACP, 0, (LPCCH)strGBK, -1, NULL,0); 
unsigned short * wszUtf8 = new unsigned short[len+1]; 
memset(wszUtf8, 0, len * 2 + 2); 
MultiByteToWideChar(CP_ACP, 0, (LPCCH)strGBK, -1, (LPWSTR)wszUtf8, len); 
len = WideCharToMultiByte(CP_UTF8, 0, (LPCWSTR)wszUtf8, -1, NULL, 0, NULL, NULL); 
char *szUtf8=new char[len + 1]; 
memset(szUtf8, 0, len + 1); 
WideCharToMultiByte (CP_UTF8, 0, (LPCWSTR)wszUtf8, -1, (LPSTR)szUtf8, len, NULL,NULL);
return szUtf8; 
}

HandleScope scope;
std::string ss = "支持中文";
return scope.Close(String::New(GBKToUtf8(ss.c_str())));
此时返回将支持中文了。
阅读(745) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~