diff options
author | Josh Blum | 2013-06-01 17:18:53 -0700 |
---|---|---|
committer | Josh Blum | 2013-06-01 17:18:53 -0700 |
commit | bd7d2bff5fa5d23d2b7b5dfeec20c03cb97a4fb6 (patch) | |
tree | 8e63365ac10cc86e3297ad3aaa247f6a676bc6db /lib/json_parser.cpp | |
parent | 618c0467762e3610f7e2afa48016183ff3a67060 (diff) | |
download | sandhi-bd7d2bff5fa5d23d2b7b5dfeec20c03cb97a4fb6.tar.gz sandhi-bd7d2bff5fa5d23d2b7b5dfeec20c03cb97a4fb6.tar.bz2 sandhi-bd7d2bff5fa5d23d2b7b5dfeec20c03cb97a4fb6.zip |
props: switched input args over to JSON
Diffstat (limited to 'lib/json_parser.cpp')
-rw-r--r-- | lib/json_parser.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/json_parser.cpp b/lib/json_parser.cpp new file mode 100644 index 0000000..4a75f3d --- /dev/null +++ b/lib/json_parser.cpp @@ -0,0 +1,36 @@ +// Copyright (C) by Josh Blum. See LICENSE.txt for licensing information. + +//--------- begin bullshit --------------// +#include <boost/version.hpp> +//why the fuck does no OS ever patch boost when there is a bug +//https://svn.boost.org/trac/boost/ticket/6785 +#if BOOST_VERSION == 104900 +#include "json_parser_read_104900.hpp" +#endif +//--------- end bullshit --------------// + +#include "gras_impl/debug.hpp" +#include <boost/property_tree/json_parser.hpp> +#include <boost/property_tree/ptree.hpp> +#include <boost/regex.hpp> +#include <sstream> +#include <string> + +boost::property_tree::ptree json_to_ptree(const std::string &s) +{ + std::stringstream ss(s); + boost::property_tree::ptree pt; + boost::property_tree::json_parser::read_json(ss, pt); + return pt; +} + +//http://stackoverflow.com/questions/13464383/boost-property-write-json-incorrect-behaviour +std::string ptree_to_json(const boost::property_tree::ptree &p) +{ + boost::regex exp("\"(null|true|false|[0-9]+(\\.[0-9]+)?)\""); + std::stringstream ss; + boost::property_tree::json_parser::write_json(ss, p); + std::string rv = boost::regex_replace(ss.str(), exp, "$1"); + + return rv; +} |