Comment #10 on issue 3275 by [email protected]: Can V8 Engine handle chinese?
http://code.google.com/p/v8/issues/detail?id=3275

I've found the solution, and needn't change my encoding or system language stuff. Finally, V8 engine will return "你好";
Code as below.

Local<String> CreateString(Isolate* isolate, wchar_t* pValue)
{
return String::NewFromTwoByte(isolate, reinterpret_cast<const uint16_t*>(pValue));
}

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,CreateString(temp.GetBuffer())));
 wchar_t* finalResult = ConvertAnsiToUnicode(*mergeResult);
 cout<<finalResult <<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, Local<String> source)
{
  Handle<Script> script = Script::Compile(source);
  Handle<Value> result = script->Run();
  return result;
}


--
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.

Reply via email to