Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r63428 - trunk/boost/property_tree/detail
From: sebastian.redl_at_[hidden]
Date: 2010-06-29 09:59:34


Author: cornedbee
Date: 2010-06-29 09:59:30 EDT (Tue, 29 Jun 2010)
New Revision: 63428
URL: http://svn.boost.org/trac/boost/changeset/63428

Log:
Generate and parse escaped forward slashes in JSON.
Text files modified:
   trunk/boost/property_tree/detail/json_parser_read.hpp | 30 +++++++++++++++++-------------
   trunk/boost/property_tree/detail/json_parser_write.hpp | 10 +++++++---
   2 files changed, 24 insertions(+), 16 deletions(-)

Modified: trunk/boost/property_tree/detail/json_parser_read.hpp
==============================================================================
--- trunk/boost/property_tree/detail/json_parser_read.hpp (original)
+++ trunk/boost/property_tree/detail/json_parser_read.hpp 2010-06-29 09:59:30 EDT (Tue, 29 Jun 2010)
@@ -128,6 +128,7 @@
                 {
                     case Ch('\"'): c.string += Ch('\"'); break;
                     case Ch('\\'): c.string += Ch('\\'); break;
+ case Ch('/'): c.string += Ch('/'); break;
                     case Ch('b'): c.string += Ch('\b'); break;
                     case Ch('f'): c.string += Ch('\f'); break;
                     case Ch('n'): c.string += Ch('\n'); break;
@@ -238,21 +239,24 @@
                           !chset_p(detail::widen<Ch>("-+").c_str()) >>
                           +digit_p)
                         ;
-
- string
+
+ string
                     = +(lexeme_d[confix_p('\"', *character, '\"')])
                         ;
-
- character
- = (anychar_p - "\\" - "\"")[typename Context::a_char(self.c)]
- | ch_p("\\") >> expect_escape(escape)
- ;
-
- escape
- = chset_p(detail::widen<Ch>("\"\\bfnrt").c_str())[typename Context::a_escape(self.c)]
- | 'u' >> uint_parser<unsigned long, 16, 4, 4>()[typename Context::a_unicode(self.c)]
- ;
-
+
+ character
+ = (anychar_p - "\\" - "\"")
+ [typename Context::a_char(self.c)]
+ | ch_p("\\") >> expect_escape(escape)
+ ;
+
+ escape
+ = chset_p(detail::widen<Ch>("\"\\/bfnrt").c_str())
+ [typename Context::a_escape(self.c)]
+ | 'u' >> uint_parser<unsigned long, 16, 4, 4>()
+ [typename Context::a_unicode(self.c)]
+ ;
+
                 // Debug
                 BOOST_SPIRIT_DEBUG_RULE(root);
                 BOOST_SPIRIT_DEBUG_RULE(object);

Modified: trunk/boost/property_tree/detail/json_parser_write.hpp
==============================================================================
--- trunk/boost/property_tree/detail/json_parser_write.hpp (original)
+++ trunk/boost/property_tree/detail/json_parser_write.hpp 2010-06-29 09:59:30 EDT (Tue, 29 Jun 2010)
@@ -12,6 +12,7 @@
 
 #include <boost/property_tree/ptree.hpp>
 #include <boost/next_prior.hpp>
+#include <boost/type_traits/make_unsigned.hpp>
 #include <string>
 #include <ostream>
 #include <iomanip>
@@ -31,19 +32,22 @@
             // This assumes an ASCII superset. But so does everything in PTree.
             // We escape everything outside ASCII, because this code can't
             // handle high unicode characters.
- if (*b == 0x20 || *b == 0x21 ||
- (*b >= 0x23 && *b <= 0x5B) || (*b >= 0x5D && *b <= 0xFF))
+ if (*b == 0x20 || *b == 0x21 || (*b >= 0x23 && *b <= 0x2E) ||
+ (*b >= 0x30 && *b <= 0x5B) || (*b >= 0x5D && *b <= 0xFF))
                 result += *b;
             else if (*b == Ch('\b')) result += Ch('\\'), result += Ch('b');
             else if (*b == Ch('\f')) result += Ch('\\'), result += Ch('f');
             else if (*b == Ch('\n')) result += Ch('\\'), result += Ch('n');
             else if (*b == Ch('\r')) result += Ch('\\'), result += Ch('r');
+ else if (*b == Ch('/')) result += Ch('\\'), result += Ch('/');
             else if (*b == Ch('"')) result += Ch('\\'), result += Ch('"');
             else if (*b == Ch('\\')) result += Ch('\\'), result += Ch('\\');
             else
             {
                 const char *hexdigits = "0123456789ABCDEF";
- unsigned long u = (std::min)(static_cast<unsigned long>(*b),
+ typedef typename make_unsigned<Ch>::type UCh;
+ unsigned long u = (std::min)(static_cast<unsigned long>(
+ static_cast<UCh>(*b)),
                                              0xFFFFul);
                 int d1 = u / 4096; u -= d1 * 4096;
                 int d2 = u / 256; u -= d2 * 256;


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk