Converting variants to wchar types?

375 views
Skip to first unread message

Kevin Menard

unread,
Jun 14, 2010, 2:02:54 PM6/14/10
to firebre...@googlegroups.com
It looks like FB::Variant can convert to std::string, but can it
handle any of the wchar types, such as std::wstring? I'm guessing
not, since I've tried about every thing I could think of. A lot of
the Win32 API and ATL function calls require LPCTSTR types, so being
able to convert a variant to a wchar string would be great.

Thanks,
Kevin

Richard Bateman

unread,
Jun 14, 2010, 2:50:23 PM6/14/10
to firebre...@googlegroups.com

We have just recently been discussing that; it shouldn't be hard to add support for std::wstring, if someone can supply cross platform code to do the conversion between UTF8 and std::wstring

you can use the ATL USES_CONVERSION stuff to do basic conversion, but that doesn't solve the issue of passing those characters to the page.

Richard

Kevin Menard

unread,
Jun 14, 2010, 2:55:23 PM6/14/10
to firebre...@googlegroups.com
NPAPI uses UTF-8 for its NPString type, I think. I haven't been able
to really understand all the FB cast code yet, but UTF-8 => ASCII
would likely be a more lossy conversion than UTF-8 => wstring. How is
it being handled currently?

--
Kevin

Lloyd Hilaiel

unread,
Jun 14, 2010, 4:19:34 PM6/14/10
to firebre...@googlegroups.com
> We have just recently been discussing that; it shouldn't be hard to
> add support for std::wstring, if someone can supply cross platform
> code to do the conversion between UTF8 and std::wstring

This sounds like what you want:

http://github.com/browserplus/platform/blob/master/src/libs/bputils/src/Utils/bpstrutil.cpp#L61-185

best,
lloyd

Richard Bateman

unread,
Jun 14, 2010, 5:34:32 PM6/14/10
to firebre...@googlegroups.com

Currently it's just being converted to ASCII, assuming it to be a string.  You are correct that this is potentially lossy.

The problem is that we don't have code to convert to UTF8, and I don't have time to figure it out myself.  Thus, as I said, if someone wants to provide code to do the conversion, it should be pretty easy to add in the wstring conversion.

Lloyd's suggestion in his email (http://github.com/browserplus/platform/blob/master/src/libs/bputils/src/Utils/bpstrutil.cpp#L61-185) may be a good way to go; does anyone know for sure if the MPL license allows us to steal code and put it into a bsd license?

Richard

Jarom Loveridge

unread,
Jun 14, 2010, 5:46:33 PM6/14/10
to firebre...@googlegroups.com
MPL is very similar to EPL. I don't believe it allows us to just relicense under BSD though. We could contact the author and request permission to use that segment of code for our project under the BSD/LGPL dual license though.

-Jarom

Kevin Menard

unread,
Jun 14, 2010, 6:09:19 PM6/14/10
to firebre...@googlegroups.com
Selenium has a Chrome plugin that has a utf8ToWChar function:

http://selenium.googlecode.com/svn/trunk/chrome/src/cpp/npchromedriver/npapi_hooks.cc

Selenium is ASLv2, so you can use that without licensing issues. It
does, however, only handle Windows. A more general approach would
probably be based on something in the wcstombs family.

Alternatively, if we're willing to accept lossy conversion, the
following works fine:

std::string blah("something");
std::wstring wide;
wide.assigns(blah.begin(), blah.end());

--
Kevin

Georg Fritzsche

unread,
Jun 15, 2010, 8:06:09 AM6/15/10
to firebreath-dev
The utf8_codecvt_facet from Boost.Serialization might be an option:
http://www.boost.org/doc/libs/1_43_0/libs/serialization/doc/codecvt.html

Georg
Reply all
Reply to author
Forward
0 new messages