From 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 20:24:20 +0200 Subject: Adding upstream version 14.2.21. Signed-off-by: Daniel Baumann --- .../property_tree/test/prefixing_callbacks.hpp | 79 ++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 src/boost/libs/property_tree/test/prefixing_callbacks.hpp (limited to 'src/boost/libs/property_tree/test/prefixing_callbacks.hpp') diff --git a/src/boost/libs/property_tree/test/prefixing_callbacks.hpp b/src/boost/libs/property_tree/test/prefixing_callbacks.hpp new file mode 100644 index 00000000..d993fb59 --- /dev/null +++ b/src/boost/libs/property_tree/test/prefixing_callbacks.hpp @@ -0,0 +1,79 @@ +#ifndef JSON_PARSER_PREFIXING_CALLBACKS_HPP +#define JSON_PARSER_PREFIXING_CALLBACKS_HPP + +#include + +namespace constants +{ + template const Ch* null_prefix(); + template <> inline const char* null_prefix() { return "_:"; } + template <> inline const wchar_t* null_prefix() { return L"_:"; } + + template const Ch* boolean_prefix(); + template <> inline const char* boolean_prefix() { return "b:"; } + template <> inline const wchar_t* boolean_prefix() { return L"b:"; } + + template const Ch* number_prefix(); + template <> inline const char* number_prefix() { return "n:"; } + template <> inline const wchar_t* number_prefix() { return L"n:"; } + + template const Ch* string_prefix(); + template <> inline const char* string_prefix() { return "s:"; } + template <> inline const wchar_t* string_prefix() { return L"s:"; } + + template const Ch* array_prefix(); + template <> inline const char* array_prefix() { return "a:"; } + template <> inline const wchar_t* array_prefix() { return L"a:"; } + + template const Ch* object_prefix(); + template <> inline const char* object_prefix() { return "o:"; } + template <> inline const wchar_t* object_prefix() { return L"o:"; } +} + +template +struct prefixing_callbacks + : boost::property_tree::json_parser::detail::standard_callbacks { + typedef boost::property_tree::json_parser::detail::standard_callbacks + base; + typedef typename base::string string; + typedef typename base::char_type char_type; + + void on_null() { + base::on_null(); + this->current_value().insert(0, constants::null_prefix()); + } + + void on_boolean(bool b) { + base::on_boolean(b); + this->current_value().insert(0, constants::boolean_prefix()); + } + + template + void on_number(Range code_units) { + base::on_number(code_units); + this->current_value().insert(0, constants::number_prefix()); + } + void on_begin_number() { + base::on_begin_number(); + this->current_value() = constants::number_prefix(); + } + + void on_begin_string() { + base::on_begin_string(); + if (!this->is_key()) { + this->current_value() = constants::string_prefix(); + } + } + + void on_begin_array() { + base::on_begin_array(); + this->current_value() = constants::array_prefix(); + } + + void on_begin_object() { + base::on_begin_object(); + this->current_value() = constants::object_prefix(); + } +}; + +#endif -- cgit v1.2.3