|
From: Stephan B. <sg...@go...> - 2010-04-19 16:13:47
|
On Mon, Apr 19, 2010 at 4:37 PM, <ma...@al...> wrote:
> I decided to use jsoncpp in my application, but faced an issue !
>
> The application uses std:wstring for JSON message values due to unicode
> maintenance,
>
> but I don’t see how I can form JSON message through Json::Value.
>
> So, why it doesn’t support std::wstring and how it could be solved ?
>
std::wstring uses an unspecified character size and (AFAIK) byte ordering.
e.g. gcc's wstring uses 4-byte characters. i recently implemented a
conversion from wstring to std::basic_string<uint16_t> for use with utf8cpp,
and it looks like this:
ValueType == basic_string<uint16_t>
void Utf16String::init( wchar_t const * v, size_t len )
{
size_t const sl = (v&&len) ? len : 0;
if( ! sl )
{
this->init( ValueType(), 0 );
return;
}
ValueType vec;
vec.reserve( sl );
vec.assign( v, v+sl );
this->init( vec, 0);
}
Utf16String::Utf16String( std::wstring const & v )
{
this->init( v.empty() ? 0 : v.c_str(), v.size() );
}
however, i don't know if that will work as-is for both big- and
little-endian.
i hope this helps a little bit.
--
----- stephan beal
http://wanderinghorse.net/home/stephan/
|