|
Boost : |
Subject: [boost] [property_tree]bug in serialization of json, when it process UTF8 encoding string with std::string.
From: Qiu Yuzhou (qbowater_at_[hidden])
Date: 2009-11-22 02:14:54
Hi,
Because char is singed in msvc, the ptree serialization code will truncate
the value when it greater than 127.
Patch for boost_1_41_0\boost\property_tree\detail\json_parser_write.hpp:
21a22,33
> template<typename Ch>
> unsigned long to_unsigned( Ch ch )
> {
> return static_cast<unsigned long>( ch );
> }
> template<>
> inline unsigned long to_unsigned<char>( char ch )
> {
> unsigned char* p = reinterpret_cast<unsigned char*>( &ch );
> return *p;
> }
>
46c58
< unsigned long u = (std::min)(static_cast<unsigned
long>(*b), 0xFFFFul);
--- > unsigned long u = (std::min)(to_unsigned<Ch>(*b), 0xFFFFul); Patch for boost_1_41_0\boost\property_tree\detail\json_parser_read.hpp 141a142 > template<typename CH_T> 148,149c149,150 < u = (std::min)(u, static_cast<unsigned long>((std::numeric_limits<Ch>::max)())); < c.string += Ch(u); --- > u = (std::min)(u, static_cast<unsigned long>((std::numeric_limits<CH_T>::max)())); > c.string += CH_T(u); 152a154,165 > template<> > struct a_unicode<char> > { > context &c; > a_unicode(context &c): c(c) { } > void operator()(unsigned long u) const > { > u = (std::min)(u, static_cast<unsigned long>((std::numeric_limits<unsigned char>::max)())); > c.string += char(u); > } > }; > 250c263 < | 'u' >> uint_parser<unsigned long, 16, 4, 4>()[typename Context::a_unicode(self.c)] --- > | 'u' >> uint_parser<unsigned long, 16, 4, 4>()[typename Context::a_unicode<Context::Ch>(self.c)] Best, Qiu Yuzhou
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk