[webkit-dev] (JavaScriptCore impl) UString -> unsigned short array

Justin Haygood jhaygood at spsu.edu
Sat Nov 25 21:20:36 PST 2006


I'm currently working on a project to embed JSCore (chosen since I was
fairly familiar with it, it was C++, and its blazing fast on Windows) into
an app to replace Perl as the company I work for's language of choice for
quick and dirty scripting. Since we have a massive library of Win32 code to
use with it, I was wondering:

 

Is there a quick way to convert a KJS::UString to an array of Unicode shorts
(aka LPCWSTR in Win32 speak).

 

I came up with the much hackish solution below that works, but seems to me
to be really inefficient:

 

      // Convert from UString to LPCWSTR.

      // FIXME: Find a better solution if possible

      // TODO: Convert into global C style function if above FIXME becomes
invalidated

      

const UChar* data = ustring.data();

      int length = ustring.size();

      WCHAR* winstringp = new WCHAR[length+1];

      ZeroMemory(winstring, (sizeof(WCHAR)*length+1));

      for( int i = 0; i < length; i++) winstrinpg[i] = data[i].unicode();

      winstringp[length] = '\0';

      LPCWSTR winstring = winstringp;

 

If someone can think of a better way, that would be totally awesome.

Justin Haygood | Software Engineer | EyeWonder, Inc.

Phone: 678-891-2031 Cell: 404-271-2273 (jhaygood86 at tmomail.net)
jhaygood at eyewonder.com

EyeWonder 
Richer Media. Richer Results.
www.eyewonder.com
<http://mail.eyewonder.com/exchweb/bin/redir.asp?URL=http://www.eyewonder.co
m/> 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/webkit-dev/attachments/20061126/a4769be5/attachment.html


More information about the webkit-dev mailing list