Rename 'fancy_serializer_{style,stylizer}' to 'print_{...}'

This commit is contained in:
Evan Driscoll 2018-06-04 22:41:11 -05:00
parent 494be1c445
commit 680a85b7a2
4 changed files with 102 additions and 104 deletions

View File

@ -29,7 +29,7 @@
namespace nlohmann namespace nlohmann
{ {
struct fancy_serializer_style struct print_style
{ {
unsigned int indent_step = 4; unsigned int indent_step = 4;
char indent_char = ' '; char indent_char = ' ';
@ -43,23 +43,23 @@ struct fancy_serializer_style
bool multiline = false; bool multiline = false;
fancy_serializer_style() = default; print_style() = default;
fancy_serializer_style(bool s_colon, bool s_comma, bool ml) print_style(bool s_colon, bool s_comma, bool ml)
: space_after_colon(s_colon), space_after_comma(s_comma), multiline(ml) : space_after_colon(s_colon), space_after_comma(s_comma), multiline(ml)
{} {}
static const fancy_serializer_style preset_compact; static const print_style preset_compact;
static const fancy_serializer_style preset_one_line; static const print_style preset_one_line;
static const fancy_serializer_style preset_multiline; static const print_style preset_multiline;
}; };
const fancy_serializer_style fancy_serializer_style::preset_compact(false, false, false); const print_style print_style::preset_compact(false, false, false);
const fancy_serializer_style fancy_serializer_style::preset_one_line(true, true, false); const print_style print_style::preset_one_line(true, true, false);
const fancy_serializer_style fancy_serializer_style::preset_multiline(true, true, true); const print_style print_style::preset_multiline(true, true, true);
template<typename BasicJsonType> template<typename BasicJsonType>
class basic_fancy_serializer_stylizer class basic_print_stylizer
{ {
public: public:
using string_t = typename BasicJsonType::string_t; using string_t = typename BasicJsonType::string_t;
@ -69,27 +69,27 @@ class basic_fancy_serializer_stylizer
using context_matcher_predicate = std::function<bool (const json_pointer_t&)>; using context_matcher_predicate = std::function<bool (const json_pointer_t&)>;
using matcher_predicate = std::function<bool (const json_pointer_t&, const BasicJsonType&)>; using matcher_predicate = std::function<bool (const json_pointer_t&, const BasicJsonType&)>;
basic_fancy_serializer_stylizer(fancy_serializer_style const& ds) basic_print_stylizer(print_style const& ds)
: default_style(ds) : default_style(ds)
{} {}
basic_fancy_serializer_stylizer() = default; basic_print_stylizer() = default;
public: public:
const fancy_serializer_style& get_default_style() const const print_style& get_default_style() const
{ {
return default_style; return default_style;
} }
fancy_serializer_style& get_default_style() print_style& get_default_style()
{ {
return default_style; return default_style;
} }
const fancy_serializer_style* get_new_style_or_active( const print_style* get_new_style_or_active(
const json_pointer_t& pointer, const json_pointer_t& pointer,
const json& j, const json& j,
const fancy_serializer_style* active_style) const const print_style* active_style) const
{ {
for (auto const& pair : styles) for (auto const& pair : styles)
{ {
@ -101,18 +101,18 @@ class basic_fancy_serializer_stylizer
return active_style; return active_style;
} }
fancy_serializer_style& register_style( print_style& register_style(
matcher_predicate p, matcher_predicate p,
fancy_serializer_style style = fancy_serializer_style()) print_style style = print_style())
{ {
styles.emplace_back(p, style); styles.emplace_back(p, style);
return styles.back().second; return styles.back().second;
} }
template <typename Predicate> template <typename Predicate>
fancy_serializer_style& register_style_object_pred( print_style& register_style_object_pred(
Predicate p, Predicate p,
fancy_serializer_style style = fancy_serializer_style()) print_style style = print_style())
{ {
auto wrapper = [p](const json_pointer_t&, const BasicJsonType & j) auto wrapper = [p](const json_pointer_t&, const BasicJsonType & j)
{ {
@ -123,9 +123,9 @@ class basic_fancy_serializer_stylizer
} }
template <typename Predicate> template <typename Predicate>
fancy_serializer_style& register_style_context_pred( print_style& register_style_context_pred(
Predicate p, Predicate p,
fancy_serializer_style style = fancy_serializer_style()) print_style style = print_style())
{ {
auto wrapper = [p](const json_pointer_t& c, const BasicJsonType&) auto wrapper = [p](const json_pointer_t& c, const BasicJsonType&)
{ {
@ -135,9 +135,9 @@ class basic_fancy_serializer_stylizer
return styles.back().second; return styles.back().second;
} }
fancy_serializer_style& register_key_matcher_style( print_style& register_key_matcher_style(
string_t str, string_t str,
fancy_serializer_style style = fancy_serializer_style()) print_style style = print_style())
{ {
return register_style_context_pred([str](const json_pointer_t& pointer) return register_style_context_pred([str](const json_pointer_t& pointer)
{ {
@ -147,14 +147,14 @@ class basic_fancy_serializer_stylizer
style); style);
} }
fancy_serializer_style& last_registered_style() print_style& last_registered_style()
{ {
return styles.back().second; return styles.back().second;
} }
private: private:
fancy_serializer_style default_style; print_style default_style;
std::vector<std::pair<matcher_predicate, fancy_serializer_style>> styles; std::vector<std::pair<matcher_predicate, print_style>> styles;
}; };
namespace detail namespace detail
@ -166,7 +166,7 @@ namespace detail
template<typename BasicJsonType> template<typename BasicJsonType>
class fancy_serializer class fancy_serializer
{ {
using stylizer_t = basic_fancy_serializer_stylizer<BasicJsonType>; using stylizer_t = basic_print_stylizer<BasicJsonType>;
using primitive_serializer_t = primitive_serializer<BasicJsonType>; using primitive_serializer_t = primitive_serializer<BasicJsonType>;
using string_t = typename BasicJsonType::string_t; using string_t = typename BasicJsonType::string_t;
using number_float_t = typename BasicJsonType::number_float_t; using number_float_t = typename BasicJsonType::number_float_t;
@ -216,7 +216,7 @@ class fancy_serializer
void dump(const BasicJsonType& val, void dump(const BasicJsonType& val,
const bool ensure_ascii, const bool ensure_ascii,
const unsigned int depth, const unsigned int depth,
const fancy_serializer_style* active_style, const print_style* active_style,
const json_pointer_t& context) const json_pointer_t& context)
{ {
active_style = stylizer.get_new_style_or_active(context, val, active_style); active_style = stylizer.get_new_style_or_active(context, val, active_style);
@ -290,7 +290,7 @@ class fancy_serializer
template <typename Iterator> template <typename Iterator>
void dump_object_key_value( void dump_object_key_value(
Iterator i, bool ensure_ascii, unsigned int depth, Iterator i, bool ensure_ascii, unsigned int depth,
const fancy_serializer_style* active_style, const print_style* active_style,
const json_pointer_t& context) const json_pointer_t& context)
{ {
const auto new_indent = (depth + 1) * active_style->indent_step * active_style->multiline; const auto new_indent = (depth + 1) * active_style->indent_step * active_style->multiline;
@ -306,7 +306,7 @@ class fancy_serializer
void dump_object(const BasicJsonType& val, void dump_object(const BasicJsonType& val,
bool ensure_ascii, bool ensure_ascii,
unsigned int depth, unsigned int depth,
const fancy_serializer_style* active_style, const print_style* active_style,
const json_pointer_t& context) const json_pointer_t& context)
{ {
if (val.m_value.object->empty()) if (val.m_value.object->empty())
@ -352,7 +352,7 @@ class fancy_serializer
void dump_array(const BasicJsonType& val, void dump_array(const BasicJsonType& val,
bool ensure_ascii, bool ensure_ascii,
unsigned int depth, unsigned int depth,
const fancy_serializer_style* active_style, const print_style* active_style,
const json_pointer_t& context) const json_pointer_t& context)
{ {
if (val.m_value.array->empty()) if (val.m_value.array->empty())
@ -405,7 +405,7 @@ class fancy_serializer
} }
void dump_string(const string_t& str, bool ensure_ascii, void dump_string(const string_t& str, bool ensure_ascii,
const fancy_serializer_style* active_style) const print_style* active_style)
{ {
o->write_character('\"'); o->write_character('\"');
if (active_style->strings_maximum_length == 0) if (active_style->strings_maximum_length == 0)
@ -484,7 +484,7 @@ class fancy_serializer
template<typename BasicJsonType> template<typename BasicJsonType>
std::ostream& fancy_dump(std::ostream& o, const BasicJsonType& j, std::ostream& fancy_dump(std::ostream& o, const BasicJsonType& j,
basic_fancy_serializer_stylizer<BasicJsonType> const& stylizer) basic_print_stylizer<BasicJsonType> const& stylizer)
{ {
// do the actual serialization // do the actual serialization
detail::fancy_serializer<BasicJsonType> s(detail::output_adapter<char>(o), stylizer); detail::fancy_serializer<BasicJsonType> s(detail::output_adapter<char>(o), stylizer);
@ -493,10 +493,9 @@ std::ostream& fancy_dump(std::ostream& o, const BasicJsonType& j,
} }
template<typename BasicJsonType> template<typename BasicJsonType>
std::ostream& fancy_dump(std::ostream& o, const BasicJsonType& j, std::ostream& fancy_dump(std::ostream& o, const BasicJsonType& j, print_style style)
fancy_serializer_style style)
{ {
basic_fancy_serializer_stylizer<BasicJsonType> stylizer(style); basic_print_stylizer<BasicJsonType> stylizer(style);
return fancy_dump(o, j, stylizer); return fancy_dump(o, j, stylizer);
} }

View File

@ -7625,7 +7625,7 @@ class basic_json
/// @} /// @}
}; };
using fancy_serializer_stylizer = basic_fancy_serializer_stylizer<json>; using print_stylizer = basic_print_stylizer<json>;
} // namespace nlohmann } // namespace nlohmann
/////////////////////// ///////////////////////

View File

@ -10834,7 +10834,7 @@ class json_pointer
namespace nlohmann namespace nlohmann
{ {
struct fancy_serializer_style struct print_style
{ {
unsigned int indent_step = 4; unsigned int indent_step = 4;
char indent_char = ' '; char indent_char = ' ';
@ -10848,23 +10848,23 @@ struct fancy_serializer_style
bool multiline = false; bool multiline = false;
fancy_serializer_style() = default; print_style() = default;
fancy_serializer_style(bool s_colon, bool s_comma, bool ml) print_style(bool s_colon, bool s_comma, bool ml)
: space_after_colon(s_colon), space_after_comma(s_comma), multiline(ml) : space_after_colon(s_colon), space_after_comma(s_comma), multiline(ml)
{} {}
static const fancy_serializer_style preset_compact; static const print_style preset_compact;
static const fancy_serializer_style preset_one_line; static const print_style preset_one_line;
static const fancy_serializer_style preset_multiline; static const print_style preset_multiline;
}; };
const fancy_serializer_style fancy_serializer_style::preset_compact(false, false, false); const print_style print_style::preset_compact(false, false, false);
const fancy_serializer_style fancy_serializer_style::preset_one_line(true, true, false); const print_style print_style::preset_one_line(true, true, false);
const fancy_serializer_style fancy_serializer_style::preset_multiline(true, true, true); const print_style print_style::preset_multiline(true, true, true);
template<typename BasicJsonType> template<typename BasicJsonType>
class basic_fancy_serializer_stylizer class basic_print_stylizer
{ {
public: public:
using string_t = typename BasicJsonType::string_t; using string_t = typename BasicJsonType::string_t;
@ -10874,27 +10874,27 @@ class basic_fancy_serializer_stylizer
using context_matcher_predicate = std::function<bool (const json_pointer_t&)>; using context_matcher_predicate = std::function<bool (const json_pointer_t&)>;
using matcher_predicate = std::function<bool (const json_pointer_t&, const BasicJsonType&)>; using matcher_predicate = std::function<bool (const json_pointer_t&, const BasicJsonType&)>;
basic_fancy_serializer_stylizer(fancy_serializer_style const& ds) basic_print_stylizer(print_style const& ds)
: default_style(ds) : default_style(ds)
{} {}
basic_fancy_serializer_stylizer() = default; basic_print_stylizer() = default;
public: public:
const fancy_serializer_style& get_default_style() const const print_style& get_default_style() const
{ {
return default_style; return default_style;
} }
fancy_serializer_style& get_default_style() print_style& get_default_style()
{ {
return default_style; return default_style;
} }
const fancy_serializer_style* get_new_style_or_active( const print_style* get_new_style_or_active(
const json_pointer_t& pointer, const json_pointer_t& pointer,
const json& j, const json& j,
const fancy_serializer_style* active_style) const const print_style* active_style) const
{ {
for (auto const& pair : styles) for (auto const& pair : styles)
{ {
@ -10906,18 +10906,18 @@ class basic_fancy_serializer_stylizer
return active_style; return active_style;
} }
fancy_serializer_style& register_style( print_style& register_style(
matcher_predicate p, matcher_predicate p,
fancy_serializer_style style = fancy_serializer_style()) print_style style = print_style())
{ {
styles.emplace_back(p, style); styles.emplace_back(p, style);
return styles.back().second; return styles.back().second;
} }
template <typename Predicate> template <typename Predicate>
fancy_serializer_style& register_style_object_pred( print_style& register_style_object_pred(
Predicate p, Predicate p,
fancy_serializer_style style = fancy_serializer_style()) print_style style = print_style())
{ {
auto wrapper = [p](const json_pointer_t&, const BasicJsonType & j) auto wrapper = [p](const json_pointer_t&, const BasicJsonType & j)
{ {
@ -10928,9 +10928,9 @@ class basic_fancy_serializer_stylizer
} }
template <typename Predicate> template <typename Predicate>
fancy_serializer_style& register_style_context_pred( print_style& register_style_context_pred(
Predicate p, Predicate p,
fancy_serializer_style style = fancy_serializer_style()) print_style style = print_style())
{ {
auto wrapper = [p](const json_pointer_t& c, const BasicJsonType&) auto wrapper = [p](const json_pointer_t& c, const BasicJsonType&)
{ {
@ -10940,9 +10940,9 @@ class basic_fancy_serializer_stylizer
return styles.back().second; return styles.back().second;
} }
fancy_serializer_style& register_key_matcher_style( print_style& register_key_matcher_style(
string_t str, string_t str,
fancy_serializer_style style = fancy_serializer_style()) print_style style = print_style())
{ {
return register_style_context_pred([str](const json_pointer_t& pointer) return register_style_context_pred([str](const json_pointer_t& pointer)
{ {
@ -10952,14 +10952,14 @@ class basic_fancy_serializer_stylizer
style); style);
} }
fancy_serializer_style& last_registered_style() print_style& last_registered_style()
{ {
return styles.back().second; return styles.back().second;
} }
private: private:
fancy_serializer_style default_style; print_style default_style;
std::vector<std::pair<matcher_predicate, fancy_serializer_style>> styles; std::vector<std::pair<matcher_predicate, print_style>> styles;
}; };
namespace detail namespace detail
@ -10971,7 +10971,7 @@ namespace detail
template<typename BasicJsonType> template<typename BasicJsonType>
class fancy_serializer class fancy_serializer
{ {
using stylizer_t = basic_fancy_serializer_stylizer<BasicJsonType>; using stylizer_t = basic_print_stylizer<BasicJsonType>;
using primitive_serializer_t = primitive_serializer<BasicJsonType>; using primitive_serializer_t = primitive_serializer<BasicJsonType>;
using string_t = typename BasicJsonType::string_t; using string_t = typename BasicJsonType::string_t;
using number_float_t = typename BasicJsonType::number_float_t; using number_float_t = typename BasicJsonType::number_float_t;
@ -11021,7 +11021,7 @@ class fancy_serializer
void dump(const BasicJsonType& val, void dump(const BasicJsonType& val,
const bool ensure_ascii, const bool ensure_ascii,
const unsigned int depth, const unsigned int depth,
const fancy_serializer_style* active_style, const print_style* active_style,
const json_pointer_t& context) const json_pointer_t& context)
{ {
active_style = stylizer.get_new_style_or_active(context, val, active_style); active_style = stylizer.get_new_style_or_active(context, val, active_style);
@ -11095,7 +11095,7 @@ class fancy_serializer
template <typename Iterator> template <typename Iterator>
void dump_object_key_value( void dump_object_key_value(
Iterator i, bool ensure_ascii, unsigned int depth, Iterator i, bool ensure_ascii, unsigned int depth,
const fancy_serializer_style* active_style, const print_style* active_style,
const json_pointer_t& context) const json_pointer_t& context)
{ {
const auto new_indent = (depth + 1) * active_style->indent_step * active_style->multiline; const auto new_indent = (depth + 1) * active_style->indent_step * active_style->multiline;
@ -11111,7 +11111,7 @@ class fancy_serializer
void dump_object(const BasicJsonType& val, void dump_object(const BasicJsonType& val,
bool ensure_ascii, bool ensure_ascii,
unsigned int depth, unsigned int depth,
const fancy_serializer_style* active_style, const print_style* active_style,
const json_pointer_t& context) const json_pointer_t& context)
{ {
if (val.m_value.object->empty()) if (val.m_value.object->empty())
@ -11157,7 +11157,7 @@ class fancy_serializer
void dump_array(const BasicJsonType& val, void dump_array(const BasicJsonType& val,
bool ensure_ascii, bool ensure_ascii,
unsigned int depth, unsigned int depth,
const fancy_serializer_style* active_style, const print_style* active_style,
const json_pointer_t& context) const json_pointer_t& context)
{ {
if (val.m_value.array->empty()) if (val.m_value.array->empty())
@ -11210,7 +11210,7 @@ class fancy_serializer
} }
void dump_string(const string_t& str, bool ensure_ascii, void dump_string(const string_t& str, bool ensure_ascii,
const fancy_serializer_style* active_style) const print_style* active_style)
{ {
o->write_character('\"'); o->write_character('\"');
if (active_style->strings_maximum_length == 0) if (active_style->strings_maximum_length == 0)
@ -11289,7 +11289,7 @@ class fancy_serializer
template<typename BasicJsonType> template<typename BasicJsonType>
std::ostream& fancy_dump(std::ostream& o, const BasicJsonType& j, std::ostream& fancy_dump(std::ostream& o, const BasicJsonType& j,
basic_fancy_serializer_stylizer<BasicJsonType> const& stylizer) basic_print_stylizer<BasicJsonType> const& stylizer)
{ {
// do the actual serialization // do the actual serialization
detail::fancy_serializer<BasicJsonType> s(detail::output_adapter<char>(o), stylizer); detail::fancy_serializer<BasicJsonType> s(detail::output_adapter<char>(o), stylizer);
@ -11298,10 +11298,9 @@ std::ostream& fancy_dump(std::ostream& o, const BasicJsonType& j,
} }
template<typename BasicJsonType> template<typename BasicJsonType>
std::ostream& fancy_dump(std::ostream& o, const BasicJsonType& j, std::ostream& fancy_dump(std::ostream& o, const BasicJsonType& j, print_style style)
fancy_serializer_style style)
{ {
basic_fancy_serializer_stylizer<BasicJsonType> stylizer(style); basic_print_stylizer<BasicJsonType> stylizer(style);
return fancy_dump(o, j, stylizer); return fancy_dump(o, j, stylizer);
} }
@ -18979,7 +18978,7 @@ class basic_json
/// @} /// @}
}; };
using fancy_serializer_stylizer = basic_fancy_serializer_stylizer<json>; using print_stylizer = basic_print_stylizer<json>;
} // namespace nlohmann } // namespace nlohmann
/////////////////////// ///////////////////////

View File

@ -35,8 +35,8 @@ SOFTWARE.
using nlohmann::json; using nlohmann::json;
using nlohmann::json_pointer; using nlohmann::json_pointer;
using nlohmann::fancy_dump; using nlohmann::fancy_dump;
using nlohmann::fancy_serializer_style; using nlohmann::print_style;
using nlohmann::fancy_serializer_stylizer; using nlohmann::print_stylizer;
// Chops off the first line (if empty, but if it *isn't* empty you're // Chops off the first line (if empty, but if it *isn't* empty you're
// probably using this wrong), measures the leading indent on the // probably using this wrong), measures the leading indent on the
@ -73,14 +73,14 @@ std::string dedent(const char* str)
return ans; return ans;
} }
std::string fancy_to_string(json j, fancy_serializer_style style = fancy_serializer_style()) std::string fancy_to_string(json j, print_style style = print_style())
{ {
std::stringstream ss; std::stringstream ss;
fancy_dump(ss, j, style); fancy_dump(ss, j, style);
return ss.str(); return ss.str();
} }
std::string fancy_to_string(json j, fancy_serializer_stylizer stylizer) std::string fancy_to_string(json j, print_stylizer stylizer)
{ {
std::stringstream ss; std::stringstream ss;
fancy_dump(ss, j, stylizer); fancy_dump(ss, j, stylizer);
@ -134,7 +134,7 @@ TEST_CASE("serialization")
SECTION("long strings can be shortened") SECTION("long strings can be shortened")
{ {
fancy_serializer_style style; print_style style;
style.strings_maximum_length = 10; style.strings_maximum_length = 10;
auto str = fancy_to_string( auto str = fancy_to_string(
@ -158,7 +158,7 @@ TEST_CASE("serialization")
for (auto test : tests) for (auto test : tests)
{ {
fancy_serializer_style style; print_style style;
style.strings_maximum_length = test.first; style.strings_maximum_length = test.first;
auto str = fancy_to_string(quick, style); auto str = fancy_to_string(quick, style);
CHECK(str == test.second); CHECK(str == test.second);
@ -167,7 +167,7 @@ TEST_CASE("serialization")
SECTION("But you cannot ask for a length of zero; that means unlimited") SECTION("But you cannot ask for a length of zero; that means unlimited")
{ {
fancy_serializer_style style; print_style style;
style.strings_maximum_length = 0; style.strings_maximum_length = 0;
auto str = fancy_to_string( auto str = fancy_to_string(
@ -179,7 +179,7 @@ TEST_CASE("serialization")
SECTION("\"Limiting\" to something long doesn't do anything") SECTION("\"Limiting\" to something long doesn't do anything")
{ {
fancy_serializer_style style; print_style style;
style.strings_maximum_length = 100; style.strings_maximum_length = 100;
auto str = fancy_to_string( auto str = fancy_to_string(
@ -197,13 +197,13 @@ TEST_CASE("serialization")
{ {
SECTION("recursing past the maximum depth with a list elides the subobjects") SECTION("recursing past the maximum depth with a list elides the subobjects")
{ {
fancy_serializer_style style; print_style style;
style.depth_limit = 1; style.depth_limit = 1;
auto str_flat = fancy_to_string({1, {1}}, style); auto str_flat = fancy_to_string({1, {1}}, style);
CHECK(str_flat == "[1,[...]]"); CHECK(str_flat == "[1,[...]]");
style = fancy_serializer_style::preset_multiline; style = print_style::preset_multiline;
style.depth_limit = 1; style.depth_limit = 1;
auto str_lines = fancy_to_string({1, {1}}, style); auto str_lines = fancy_to_string({1, {1}}, style);
CHECK(str_lines == dedent(R"( CHECK(str_lines == dedent(R"(
@ -215,13 +215,13 @@ TEST_CASE("serialization")
SECTION("recursing past the maximum depth with an object elides the subobjects") SECTION("recursing past the maximum depth with an object elides the subobjects")
{ {
fancy_serializer_style style; print_style style;
style.depth_limit = 1; style.depth_limit = 1;
auto str_flat = fancy_to_string({1, {{"one", 1}}}, style); auto str_flat = fancy_to_string({1, {{"one", 1}}}, style);
CHECK(str_flat == "[1,{...}]"); CHECK(str_flat == "[1,{...}]");
style = fancy_serializer_style::preset_multiline; style = print_style::preset_multiline;
style.depth_limit = 1; style.depth_limit = 1;
auto str_lines = fancy_to_string({1, {{"one", 1}}}, style); auto str_lines = fancy_to_string({1, {{"one", 1}}}, style);
CHECK(str_lines == dedent(R"( CHECK(str_lines == dedent(R"(
@ -236,8 +236,8 @@ TEST_CASE("serialization")
{ {
SECTION("can style objects of a key differently") SECTION("can style objects of a key differently")
{ {
fancy_serializer_stylizer stylizer; print_stylizer stylizer;
stylizer.get_default_style() = fancy_serializer_style::preset_multiline; stylizer.get_default_style() = print_style::preset_multiline;
stylizer.register_key_matcher_style("one line"); stylizer.register_key_matcher_style("one line");
auto str = fancy_to_string( auto str = fancy_to_string(
@ -263,8 +263,8 @@ TEST_CASE("serialization")
SECTION("changes propagate (unless overridden)") SECTION("changes propagate (unless overridden)")
{ {
fancy_serializer_stylizer stylizer; print_stylizer stylizer;
stylizer.get_default_style() = fancy_serializer_style::preset_multiline; stylizer.get_default_style() = print_style::preset_multiline;
stylizer.register_key_matcher_style("one line"); stylizer.register_key_matcher_style("one line");
auto str = fancy_to_string( auto str = fancy_to_string(
@ -283,8 +283,8 @@ TEST_CASE("serialization")
SECTION("example of more sophisticated context matcher") SECTION("example of more sophisticated context matcher")
{ {
fancy_serializer_stylizer stylizer; print_stylizer stylizer;
stylizer.get_default_style() = fancy_serializer_style::preset_multiline; stylizer.get_default_style() = print_style::preset_multiline;
stylizer.register_style_context_pred( stylizer.register_style_context_pred(
[] (const json_pointer<json>& context) [] (const json_pointer<json>& context)
@ -329,15 +329,15 @@ TEST_CASE("serialization")
SECTION("example of more sophisticated json matcher") SECTION("example of more sophisticated json matcher")
{ {
fancy_serializer_stylizer stylizer; print_stylizer stylizer;
stylizer.get_default_style() = fancy_serializer_style::preset_multiline; stylizer.get_default_style() = print_style::preset_multiline;
stylizer.register_style_object_pred( stylizer.register_style_object_pred(
[] (const json & j) [] (const json & j)
{ {
return j.type() == json::value_t::array; return j.type() == json::value_t::array;
} }
) = fancy_serializer_style::preset_one_line; ) = print_style::preset_one_line;
auto str = fancy_to_string( auto str = fancy_to_string(
{ {
@ -364,7 +364,7 @@ TEST_CASE("serialization")
{ {
SECTION("commas") SECTION("commas")
{ {
fancy_serializer_style style; print_style style;
style.space_after_comma = true; style.space_after_comma = true;
auto str = fancy_to_string({1, 2, 3}, style); auto str = fancy_to_string({1, 2, 3}, style);
CHECK(str == "[1, 2, 3]"); CHECK(str == "[1, 2, 3]");
@ -372,7 +372,7 @@ TEST_CASE("serialization")
SECTION("colons") SECTION("colons")
{ {
fancy_serializer_style style; print_style style;
style.space_after_colon = true; style.space_after_colon = true;
auto str = fancy_to_string({{"one", 1}}, style); auto str = fancy_to_string({{"one", 1}}, style);
CHECK(str == "{\"one\": 1}"); CHECK(str == "{\"one\": 1}");
@ -380,7 +380,7 @@ TEST_CASE("serialization")
SECTION("multiline can have no space") SECTION("multiline can have no space")
{ {
fancy_serializer_style style = fancy_serializer_style::preset_multiline; print_style style = print_style::preset_multiline;
style.space_after_colon = false; style.space_after_colon = false;
auto str = fancy_to_string({{"one", 1}}, style); auto str = fancy_to_string({{"one", 1}}, style);
CHECK(str == dedent(R"( CHECK(str == dedent(R"(
@ -393,7 +393,7 @@ TEST_CASE("serialization")
SECTION("given width") SECTION("given width")
{ {
fancy_serializer_style style = fancy_serializer_style::preset_multiline; print_style style = print_style::preset_multiline;
auto str = fancy_to_string({"foo", 1, 2, 3, false, {{"one", 1}}}, style); auto str = fancy_to_string({"foo", 1, 2, 3, false, {{"one", 1}}}, style);
CHECK(str == dedent(R"( CHECK(str == dedent(R"(
[ [
@ -410,7 +410,7 @@ TEST_CASE("serialization")
SECTION("given fill") SECTION("given fill")
{ {
fancy_serializer_style style = fancy_serializer_style::preset_multiline; print_style style = print_style::preset_multiline;
style.indent_step = 1; style.indent_step = 1;
style.indent_char = '\t'; style.indent_char = '\t';
@ -431,7 +431,7 @@ TEST_CASE("serialization")
SECTION("indent_char is honored for deep indents in lists") SECTION("indent_char is honored for deep indents in lists")
{ {
fancy_serializer_style style = fancy_serializer_style::preset_multiline; print_style style = print_style::preset_multiline;
style.indent_step = 300; style.indent_step = 300;
style.indent_char = 'X'; style.indent_char = 'X';
@ -449,7 +449,7 @@ TEST_CASE("serialization")
SECTION("indent_char is honored for deep indents in objects") SECTION("indent_char is honored for deep indents in objects")
{ {
fancy_serializer_style style = fancy_serializer_style::preset_multiline; print_style style = print_style::preset_multiline;
style.indent_step = 300; style.indent_step = 300;
style.indent_char = 'X'; style.indent_char = 'X';