Merge branch 'main' into devtools
This commit is contained in:
+13
-3
@@ -52,7 +52,7 @@ void stringifyObj(
|
|||||||
bool nice
|
bool nice
|
||||||
);
|
);
|
||||||
|
|
||||||
void stringify(
|
void stringifyValue(
|
||||||
const Value& value,
|
const Value& value,
|
||||||
std::stringstream& ss,
|
std::stringstream& ss,
|
||||||
int indent,
|
int indent,
|
||||||
@@ -74,7 +74,7 @@ void stringify(
|
|||||||
if (i > 0 || nice) {
|
if (i > 0 || nice) {
|
||||||
newline(ss, nice, indent, indentstr);
|
newline(ss, nice, indent, indentstr);
|
||||||
}
|
}
|
||||||
stringify(value, ss, indent+1, indentstr, nice);
|
stringifyValue(value, ss, indent+1, indentstr, nice);
|
||||||
if (i + 1 < list->size()) {
|
if (i + 1 < list->size()) {
|
||||||
ss << ',';
|
ss << ',';
|
||||||
}
|
}
|
||||||
@@ -114,7 +114,7 @@ void stringifyObj(
|
|||||||
}
|
}
|
||||||
const Value& value = entry.second;
|
const Value& value = entry.second;
|
||||||
ss << util::escape(key) << ": ";
|
ss << util::escape(key) << ": ";
|
||||||
stringify(value, ss, indent+1, indentstr, nice);
|
stringifyValue(value, ss, indent+1, indentstr, nice);
|
||||||
index++;
|
index++;
|
||||||
if (index < obj->values.size()) {
|
if (index < obj->values.size()) {
|
||||||
ss << ',';
|
ss << ',';
|
||||||
@@ -136,6 +136,16 @@ std::string json::stringify(
|
|||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string json::stringify(
|
||||||
|
const dynamic::Value& value,
|
||||||
|
bool nice,
|
||||||
|
const std::string& indent
|
||||||
|
) {
|
||||||
|
std::stringstream ss;
|
||||||
|
stringifyValue(value, ss, 1, indent, nice);
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
|
||||||
Parser::Parser(std::string_view filename, std::string_view source)
|
Parser::Parser(std::string_view filename, std::string_view source)
|
||||||
: BasicParser(filename, source) {
|
: BasicParser(filename, source) {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,12 @@ namespace json {
|
|||||||
bool nice,
|
bool nice,
|
||||||
const std::string& indent
|
const std::string& indent
|
||||||
);
|
);
|
||||||
|
|
||||||
|
std::string stringify(
|
||||||
|
const dynamic::Value& value,
|
||||||
|
bool nice,
|
||||||
|
const std::string& indent
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // CODERS_JSON_HPP_
|
#endif // CODERS_JSON_HPP_
|
||||||
|
|||||||
@@ -1,7 +1,24 @@
|
|||||||
#include "dynamic.hpp"
|
#include "dynamic.hpp"
|
||||||
|
|
||||||
|
#include "../coders/json.hpp"
|
||||||
|
|
||||||
using namespace dynamic;
|
using namespace dynamic;
|
||||||
|
|
||||||
|
std::ostream& operator<<(std::ostream& stream, const dynamic::Value& value) {
|
||||||
|
stream << json::stringify(value, false, " ");
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ostream& operator<<(std::ostream& stream, const dynamic::Map_sptr& value) {
|
||||||
|
stream << json::stringify(value, false, " ");
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ostream& operator<<(std::ostream& stream, const dynamic::List_sptr& value) {
|
||||||
|
stream << json::stringify(value, false, " ");
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
|
|
||||||
std::string List::str(size_t index) const {
|
std::string List::str(size_t index) const {
|
||||||
const auto& value = values[index];
|
const auto& value = values[index];
|
||||||
switch (static_cast<Type>(value.index())) {
|
switch (static_cast<Type>(value.index())) {
|
||||||
|
|||||||
@@ -137,4 +137,8 @@ namespace dynamic {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::ostream& operator<<(std::ostream& stream, const dynamic::Value& value);
|
||||||
|
std::ostream& operator<<(std::ostream& stream, const dynamic::Map_sptr& value);
|
||||||
|
std::ostream& operator<<(std::ostream& stream, const dynamic::List_sptr& value);
|
||||||
|
|
||||||
#endif // DATA_DYNAMIC_HPP_
|
#endif // DATA_DYNAMIC_HPP_
|
||||||
|
|||||||
Reference in New Issue
Block a user