Status: New
Owner: ----
New issue 3276 by [email protected]: Is there any solution for chinese
characters. (High priority)
http://code.google.com/p/v8/issues/detail?id=3276
Hi there,
I was working on a task about v8 engine with high priority. I want to
execute a string contains chinese(e.g:"'你'+'好'"), and am hope it will
return like "你好" after executing code below, but it fails and finally
returns '锟斤拷锟斤拷'. so could anyone help me on this? Thanks a lot.
int _tmain(int argc, _TCHAR* argv[])
{
Isolate* isolate = Isolate::GetCurrent();
HandleScope handle_scope(isolate);
Handle<Context> context = Context::New(isolate);
Context::Scope context_scope(context);
CString temp = "'你'+'好'";
String::Utf8Value
mergeResult(ExecuteJs(isolate,ConvertUnicodeToAnsi(temp.GetBuffer())));
cout<<*mergeResult<<endl;
return 0;
}
char* ConvertUnicodeToAnsi(wchar_t* source)
{
int nLength = 0;
nLength = ::WideCharToMultiByte(CP_ACP,0,source,-1,NULL,0,NULL,NULL);
char* chars = new char[nLength + 1];
::WideCharToMultiByte(CP_ACP,0,source,wcslen(source) +
1,chars,nLength,NULL,NULL);
return chars;
}
Handle<Value> ExecuteJs(Isolate* isolate, const char* code)
{
Handle<String> source = String::NewFromUtf8(isolate, code);
Handle<Script> script = Script::Compile(source);
Handle<Value> result = script->Run();
return result;
}
BTW, I've done with a short test in d8, but the result the same as before.
d8> var a='你好'
undefined
d8> a
"锟斤拷锟斤拷"
d8> a.charCodeAt(0)
65533
d8> a.charCodeAt(1)
65533
And I found there's little to do with my code, even I had checked the test
cases in test/cctest/test-strings.cc, it's hard to modify...
--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.