Rename fancy->styled

This commit is contained in:
Evan Driscoll 2018-06-05 22:51:11 -05:00
parent 6ce7cc0470
commit e2974c38e4
4 changed files with 54 additions and 54 deletions

View File

@ -214,7 +214,7 @@ namespace detail
/////////////////// ///////////////////
template<typename BasicJsonType> template<typename BasicJsonType>
class fancy_serializer class styled_serializer
{ {
using stylizer_t = basic_print_stylizer<BasicJsonType>; using stylizer_t = basic_print_stylizer<BasicJsonType>;
using primitive_serializer_t = primitive_serializer<BasicJsonType>; using primitive_serializer_t = primitive_serializer<BasicJsonType>;
@ -231,15 +231,15 @@ class fancy_serializer
@param[in] s output stream to serialize to @param[in] s output stream to serialize to
@param[in] ichar indentation character to use @param[in] ichar indentation character to use
*/ */
fancy_serializer(output_adapter_t<char> s, styled_serializer(output_adapter_t<char> s,
const stylizer_t& st) const stylizer_t& st)
: o(std::move(s)), stylizer(st), : o(std::move(s)), stylizer(st),
indent_string(512, st.get_default_style().indent_char) indent_string(512, st.get_default_style().indent_char)
{} {}
// delete because of pointer members // delete because of pointer members
fancy_serializer(const fancy_serializer&) = delete; styled_serializer(const styled_serializer&) = delete;
fancy_serializer& operator=(const fancy_serializer&) = delete; styled_serializer& operator=(const styled_serializer&) = delete;
void dump(const BasicJsonType& val, const bool ensure_ascii) void dump(const BasicJsonType& val, const bool ensure_ascii)
{ {
@ -517,7 +517,7 @@ class fancy_serializer
} }
private: private:
/// the output of the fancy_serializer /// the output of the styled_serializer
output_adapter_t<char> o = nullptr; output_adapter_t<char> o = nullptr;
/// Used for serializing "base" objects. Strings are sort of /// Used for serializing "base" objects. Strings are sort of
@ -533,20 +533,20 @@ class fancy_serializer
} }
template<typename BasicJsonType> template<typename BasicJsonType>
std::ostream& fancy_dump(std::ostream& o, const BasicJsonType& j, std::ostream& styled_dump(std::ostream& o, const BasicJsonType& j,
basic_print_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::styled_serializer<BasicJsonType> s(detail::output_adapter<char>(o), stylizer);
s.dump(j, false); s.dump(j, false);
return o; return o;
} }
template<typename BasicJsonType> template<typename BasicJsonType>
std::ostream& fancy_dump(std::ostream& o, const BasicJsonType& j, print_style style) std::ostream& styled_dump(std::ostream& o, const BasicJsonType& j, print_style style)
{ {
basic_print_stylizer<BasicJsonType> stylizer(style); basic_print_stylizer<BasicJsonType> stylizer(style);
return fancy_dump(o, j, stylizer); return styled_dump(o, j, stylizer);
} }
} }

View File

@ -167,7 +167,7 @@ class basic_json
friend ::nlohmann::json_pointer<basic_json>; friend ::nlohmann::json_pointer<basic_json>;
friend ::nlohmann::detail::parser<basic_json>; friend ::nlohmann::detail::parser<basic_json>;
friend ::nlohmann::detail::serializer<basic_json>; friend ::nlohmann::detail::serializer<basic_json>;
friend ::nlohmann::detail::fancy_serializer<basic_json>; friend ::nlohmann::detail::styled_serializer<basic_json>;
template<typename BasicJsonType> template<typename BasicJsonType>
friend class ::nlohmann::detail::iter_impl; friend class ::nlohmann::detail::iter_impl;
template<typename BasicJsonType, typename CharType> template<typename BasicJsonType, typename CharType>

View File

@ -11019,7 +11019,7 @@ namespace detail
/////////////////// ///////////////////
template<typename BasicJsonType> template<typename BasicJsonType>
class fancy_serializer class styled_serializer
{ {
using stylizer_t = basic_print_stylizer<BasicJsonType>; using stylizer_t = basic_print_stylizer<BasicJsonType>;
using primitive_serializer_t = primitive_serializer<BasicJsonType>; using primitive_serializer_t = primitive_serializer<BasicJsonType>;
@ -11036,15 +11036,15 @@ class fancy_serializer
@param[in] s output stream to serialize to @param[in] s output stream to serialize to
@param[in] ichar indentation character to use @param[in] ichar indentation character to use
*/ */
fancy_serializer(output_adapter_t<char> s, styled_serializer(output_adapter_t<char> s,
const stylizer_t& st) const stylizer_t& st)
: o(std::move(s)), stylizer(st), : o(std::move(s)), stylizer(st),
indent_string(512, st.get_default_style().indent_char) indent_string(512, st.get_default_style().indent_char)
{} {}
// delete because of pointer members // delete because of pointer members
fancy_serializer(const fancy_serializer&) = delete; styled_serializer(const styled_serializer&) = delete;
fancy_serializer& operator=(const fancy_serializer&) = delete; styled_serializer& operator=(const styled_serializer&) = delete;
void dump(const BasicJsonType& val, const bool ensure_ascii) void dump(const BasicJsonType& val, const bool ensure_ascii)
{ {
@ -11322,7 +11322,7 @@ class fancy_serializer
} }
private: private:
/// the output of the fancy_serializer /// the output of the styled_serializer
output_adapter_t<char> o = nullptr; output_adapter_t<char> o = nullptr;
/// Used for serializing "base" objects. Strings are sort of /// Used for serializing "base" objects. Strings are sort of
@ -11338,20 +11338,20 @@ class fancy_serializer
} }
template<typename BasicJsonType> template<typename BasicJsonType>
std::ostream& fancy_dump(std::ostream& o, const BasicJsonType& j, std::ostream& styled_dump(std::ostream& o, const BasicJsonType& j,
basic_print_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::styled_serializer<BasicJsonType> s(detail::output_adapter<char>(o), stylizer);
s.dump(j, false); s.dump(j, false);
return o; return o;
} }
template<typename BasicJsonType> template<typename BasicJsonType>
std::ostream& fancy_dump(std::ostream& o, const BasicJsonType& j, print_style style) std::ostream& styled_dump(std::ostream& o, const BasicJsonType& j, print_style style)
{ {
basic_print_stylizer<BasicJsonType> stylizer(style); basic_print_stylizer<BasicJsonType> stylizer(style);
return fancy_dump(o, j, stylizer); return styled_dump(o, j, stylizer);
} }
} }
@ -11570,7 +11570,7 @@ class basic_json
friend ::nlohmann::json_pointer<basic_json>; friend ::nlohmann::json_pointer<basic_json>;
friend ::nlohmann::detail::parser<basic_json>; friend ::nlohmann::detail::parser<basic_json>;
friend ::nlohmann::detail::serializer<basic_json>; friend ::nlohmann::detail::serializer<basic_json>;
friend ::nlohmann::detail::fancy_serializer<basic_json>; friend ::nlohmann::detail::styled_serializer<basic_json>;
template<typename BasicJsonType> template<typename BasicJsonType>
friend class ::nlohmann::detail::iter_impl; friend class ::nlohmann::detail::iter_impl;
template<typename BasicJsonType, typename CharType> template<typename BasicJsonType, typename CharType>

View File

@ -34,7 +34,7 @@ SOFTWARE.
using nlohmann::json; using nlohmann::json;
using nlohmann::json_pointer; using nlohmann::json_pointer;
using nlohmann::fancy_dump; using nlohmann::styled_dump;
using nlohmann::print_style; using nlohmann::print_style;
using nlohmann::print_stylizer; using nlohmann::print_stylizer;
@ -73,17 +73,17 @@ std::string dedent(const char* str)
return ans; return ans;
} }
std::string fancy_to_string(json j, print_style style = print_style()) std::string styled_to_string(json j, print_style style = print_style())
{ {
std::stringstream ss; std::stringstream ss;
fancy_dump(ss, j, style); styled_dump(ss, j, style);
return ss.str(); return ss.str();
} }
std::string fancy_to_string(json j, print_stylizer stylizer) std::string styled_to_string(json j, print_stylizer stylizer)
{ {
std::stringstream ss; std::stringstream ss;
fancy_dump(ss, j, stylizer); styled_dump(ss, j, stylizer);
return ss.str(); return ss.str();
} }
@ -93,31 +93,31 @@ TEST_CASE("serialization")
{ {
SECTION("null") SECTION("null")
{ {
auto str = fancy_to_string({}); auto str = styled_to_string({});
CHECK(str == "null"); CHECK(str == "null");
} }
SECTION("true") SECTION("true")
{ {
auto str = fancy_to_string(true); auto str = styled_to_string(true);
CHECK(str == "true"); CHECK(str == "true");
} }
SECTION("false") SECTION("false")
{ {
auto str = fancy_to_string(false); auto str = styled_to_string(false);
CHECK(str == "false"); CHECK(str == "false");
} }
SECTION("integer") SECTION("integer")
{ {
auto str = fancy_to_string(10); auto str = styled_to_string(10);
CHECK(str == "10"); CHECK(str == "10");
} }
SECTION("floating point") SECTION("floating point")
{ {
auto str = fancy_to_string(7.5); auto str = styled_to_string(7.5);
CHECK(str == "7.5"); CHECK(str == "7.5");
} }
} }
@ -126,7 +126,7 @@ TEST_CASE("serialization")
{ {
SECTION("long strings usually print") SECTION("long strings usually print")
{ {
auto str = fancy_to_string( auto str = styled_to_string(
"The quick brown fox jumps over the lazy brown dog"); "The quick brown fox jumps over the lazy brown dog");
CHECK(str == CHECK(str ==
"\"The quick brown fox jumps over the lazy brown dog\""); "\"The quick brown fox jumps over the lazy brown dog\"");
@ -137,7 +137,7 @@ TEST_CASE("serialization")
print_style style; print_style style;
style.strings_maximum_length = 10; style.strings_maximum_length = 10;
auto str = fancy_to_string( auto str = styled_to_string(
"The quick brown fox jumps over the lazy brown dog", "The quick brown fox jumps over the lazy brown dog",
style); style);
CHECK(str == "\"The qu...g\""); CHECK(str == "\"The qu...g\"");
@ -160,7 +160,7 @@ TEST_CASE("serialization")
{ {
print_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 = styled_to_string(quick, style);
CHECK(str == test.second); CHECK(str == test.second);
} }
} }
@ -170,7 +170,7 @@ TEST_CASE("serialization")
print_style style; print_style style;
style.strings_maximum_length = 0; style.strings_maximum_length = 0;
auto str = fancy_to_string( auto str = styled_to_string(
"The quick brown fox jumps over the lazy brown dog", "The quick brown fox jumps over the lazy brown dog",
style); style);
CHECK(str == CHECK(str ==
@ -182,7 +182,7 @@ TEST_CASE("serialization")
print_style style; print_style style;
style.strings_maximum_length = 100; style.strings_maximum_length = 100;
auto str = fancy_to_string( auto str = styled_to_string(
"The quick brown fox jumps over the lazy brown dog", "The quick brown fox jumps over the lazy brown dog",
style); style);
CHECK(str == CHECK(str ==
@ -200,12 +200,12 @@ TEST_CASE("serialization")
print_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 = styled_to_string({1, {1}}, style);
CHECK(str_flat == "[1,[...]]"); CHECK(str_flat == "[1,[...]]");
style = print_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 = styled_to_string({1, {1}}, style);
CHECK(str_lines == dedent(R"( CHECK(str_lines == dedent(R"(
[ [
1, 1,
@ -218,12 +218,12 @@ TEST_CASE("serialization")
print_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 = styled_to_string({1, {{"one", 1}}}, style);
CHECK(str_flat == "[1,{...}]"); CHECK(str_flat == "[1,{...}]");
style = print_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 = styled_to_string({1, {{"one", 1}}}, style);
CHECK(str_lines == dedent(R"( CHECK(str_lines == dedent(R"(
[ [
1, 1,
@ -240,7 +240,7 @@ TEST_CASE("serialization")
stylizer.get_default_style() = print_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 = styled_to_string(
{ {
{ {
"one line", {1, 2} "one line", {1, 2}
@ -267,7 +267,7 @@ TEST_CASE("serialization")
stylizer.get_default_style() = print_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 = styled_to_string(
{ {
{ {
"one line", {{"still one line", {1, 2}}} "one line", {{"still one line", {1, 2}}}
@ -295,7 +295,7 @@ TEST_CASE("serialization")
} }
).space_after_comma = true; ).space_after_comma = true;
auto str = fancy_to_string( auto str = styled_to_string(
{ {
{ {
"each elem on one line", { "each elem on one line", {
@ -339,7 +339,7 @@ TEST_CASE("serialization")
} }
) = print_style::preset_one_line; ) = print_style::preset_one_line;
auto str = fancy_to_string( auto str = styled_to_string(
{ {
{ {
"an array", {1, 2, 3} "an array", {1, 2, 3}
@ -366,7 +366,7 @@ TEST_CASE("serialization")
{ {
print_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 = styled_to_string({1, 2, 3}, style);
CHECK(str == "[1, 2, 3]"); CHECK(str == "[1, 2, 3]");
} }
@ -374,7 +374,7 @@ TEST_CASE("serialization")
{ {
print_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 = styled_to_string({{"one", 1}}, style);
CHECK(str == "{\"one\": 1}"); CHECK(str == "{\"one\": 1}");
} }
@ -382,7 +382,7 @@ TEST_CASE("serialization")
{ {
print_style style = print_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 = styled_to_string({{"one", 1}}, style);
CHECK(str == dedent(R"( CHECK(str == dedent(R"(
{ {
"one":1 "one":1
@ -394,7 +394,7 @@ TEST_CASE("serialization")
SECTION("given width") SECTION("given width")
{ {
print_style style = print_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 = styled_to_string({"foo", 1, 2, 3, false, {{"one", 1}}}, style);
CHECK(str == dedent(R"( CHECK(str == dedent(R"(
[ [
"foo", "foo",
@ -414,7 +414,7 @@ TEST_CASE("serialization")
style.indent_step = 1; style.indent_step = 1;
style.indent_char = '\t'; style.indent_char = '\t';
auto str = fancy_to_string({"foo", 1, 2, 3, false, {{"one", 1}}}, style); auto str = styled_to_string({"foo", 1, 2, 3, false, {{"one", 1}}}, style);
CHECK(str == CHECK(str ==
"[\n" "[\n"
"\t\"foo\",\n" "\t\"foo\",\n"
@ -435,7 +435,7 @@ TEST_CASE("serialization")
style.indent_step = 300; style.indent_step = 300;
style.indent_char = 'X'; style.indent_char = 'X';
auto str = fancy_to_string({1, {1}}, style); auto str = styled_to_string({1, {1}}, style);
std::string indent(300, 'X'); std::string indent(300, 'X');
CHECK(str == CHECK(str ==
@ -453,7 +453,7 @@ TEST_CASE("serialization")
style.indent_step = 300; style.indent_step = 300;
style.indent_char = 'X'; style.indent_char = 'X';
auto str = fancy_to_string({{"key", {{"key", 1}}}}, style); auto str = styled_to_string({{"key", {{"key", 1}}}}, style);
std::string indent(300, 'X'); std::string indent(300, 'X');
CHECK(str == CHECK(str ==