boost使用property_tree/json_parser处理包含中文字符的UTF8时异常的解决办法

这主要是由json_parser_read.hpp里面的一个bug造成的,修改如下代码:     

   struct a_unicode

        {
            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<Ch>::max)()));


                typedef typename std::make_unsigned<Ch>::type UCh;
                u = (std::min)(u, static_cast<unsigned long>((std::numeric_limits<UCh>::max)()));


                c.string += Ch(u);
            }

        };

如上修改在xcode和visual studio环境下编译正常,但在gcc环境下,可能需要修改typedef typename std::make_unsigned<Ch>::type UCh;为typedef typename make_unsigned<Ch>::type UCh;

你可能感兴趣的:(boost使用property_tree/json_parser处理包含中文字符的UTF8时异常的解决办法)