Added JsonUtils to post-process written json (backported from master)

This commit is contained in:
YuSanka 2024-02-13 13:40:19 +01:00 committed by Lukas Matena
parent 06dffc3f80
commit 1bc0a65106
3 changed files with 38 additions and 0 deletions

View File

@ -509,6 +509,8 @@ set(SLIC3R_SOURCES
Arachne/WallToolPaths.hpp
Arachne/WallToolPaths.cpp
StaticMap.hpp
Utils/JsonUtils.hpp
Utils/JsonUtils.cpp
)
add_library(libslic3r STATIC ${SLIC3R_SOURCES})

View File

@ -0,0 +1,24 @@
#include "JsonUtils.hpp"
#include <boost/algorithm/string/replace.hpp>
#include <regex>
namespace Slic3r {
namespace pt = boost::property_tree;
std::string write_json_with_post_process(const pt::ptree& ptree)
{
std::stringstream oss;
pt::write_json(oss, ptree);
// fix json-out to show node values as a string just for string nodes
std::regex reg("\\\"([0-9]+\\.{0,1}[0-9]*)\\\""); // code is borrowed from https://stackoverflow.com/questions/2855741/why-does-boost-property-tree-write-json-save-everything-as-string-is-it-possibl
std::string result = std::regex_replace(oss.str(), reg, "$1");
boost::replace_all(result, "\"true\"", "true");
boost::replace_all(result, "\"false\"", "false");
return result;
}
} // namespace Slic3r

View File

@ -0,0 +1,12 @@
#ifndef slic3r_JsonUtils_hpp_
#define slic3r_JsonUtils_hpp_
#include <boost/property_tree/json_parser.hpp>
namespace Slic3r {
std::string write_json_with_post_process(const boost::property_tree::ptree& ptree);
} // namespace Slic3r
#endif // slic3r_jsonUtils_hpp_