1 #ifndef JSON_PARSER_PREFIXING_CALLBACKS_HPP
2 #define JSON_PARSER_PREFIXING_CALLBACKS_HPP
4 #include <boost/property_tree/json_parser/detail/standard_callbacks.hpp>
8 template <typename Ch> const Ch* null_prefix();
9 template <> inline const char* null_prefix() { return "_:"; }
10 template <> inline const wchar_t* null_prefix() { return L"_:"; }
12 template <typename Ch> const Ch* boolean_prefix();
13 template <> inline const char* boolean_prefix() { return "b:"; }
14 template <> inline const wchar_t* boolean_prefix() { return L"b:"; }
16 template <typename Ch> const Ch* number_prefix();
17 template <> inline const char* number_prefix() { return "n:"; }
18 template <> inline const wchar_t* number_prefix() { return L"n:"; }
20 template <typename Ch> const Ch* string_prefix();
21 template <> inline const char* string_prefix() { return "s:"; }
22 template <> inline const wchar_t* string_prefix() { return L"s:"; }
24 template <typename Ch> const Ch* array_prefix();
25 template <> inline const char* array_prefix() { return "a:"; }
26 template <> inline const wchar_t* array_prefix() { return L"a:"; }
28 template <typename Ch> const Ch* object_prefix();
29 template <> inline const char* object_prefix() { return "o:"; }
30 template <> inline const wchar_t* object_prefix() { return L"o:"; }
33 template <typename Ptree>
34 struct prefixing_callbacks
35 : boost::property_tree::json_parser::detail::standard_callbacks<Ptree> {
36 typedef boost::property_tree::json_parser::detail::standard_callbacks<Ptree>
38 typedef typename base::string string;
39 typedef typename base::char_type char_type;
43 this->current_value().insert(0, constants::null_prefix<char_type>());
46 void on_boolean(bool b) {
48 this->current_value().insert(0, constants::boolean_prefix<char_type>());
51 template <typename Range>
52 void on_number(Range code_units) {
53 base::on_number(code_units);
54 this->current_value().insert(0, constants::number_prefix<char_type>());
56 void on_begin_number() {
57 base::on_begin_number();
58 this->current_value() = constants::number_prefix<char_type>();
61 void on_begin_string() {
62 base::on_begin_string();
63 if (!this->is_key()) {
64 this->current_value() = constants::string_prefix<char_type>();
68 void on_begin_array() {
69 base::on_begin_array();
70 this->current_value() = constants::array_prefix<char_type>();
73 void on_begin_object() {
74 base::on_begin_object();
75 this->current_value() = constants::object_prefix<char_type>();