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

Justin Haygood jhaygood at spsu.edu
Sat Nov 25 21:32:48 PST 2006

Can you do memcpy with a UChar* ?


From: Maciej Stachowiak [mailto:mjs at apple.com] 
Sent: Sunday, November 26, 2006 12:28 AM
To: Justin Haygood
Cc: webkit-dev at lists.webkit.org
Subject: Re: [webkit-dev] (JavaScriptCore impl) UString -> unsigned short



On Nov 25, 2006, at 9:20 PM, Justin Haygood wrote:

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:

You don't need the ZeroMemory, and instead of the copy loop you could try





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


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

Richer Media. Richer Results.



webkit-dev mailing list

webkit-dev at lists.webkit.org



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

More information about the webkit-dev mailing list