Search code examples
javascriptc++stringv8embedded-v8

how to create an utf8 string in Google V8 engine


Hello Im using v8 engine embedded in C++ program and I met a string problem.

Well of course v8 engine fully support utf8 string, but i just dont know how.

char path[ 1024 ]; 

GetCurrentDirectory( 1024, (LPWSTR)path );

script->Path = String::New(path);

However, the result is the only character "D", for String::New only accepts char* and utf_16*

I checked the v8 document and found no way to make a utf8 string, can anybody help me?


Solution

  • Since you had to cast "path" to LPWSTR, it looks like you are calling the wide-string (unicode) Win32 API for GetCurrentDirectory, which is UTF-16. Try declaring "path" as wchar_t instead. If utf_16 is a typedef for wchar_t, it may work directly with String::New.