mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-14 10:06:02 +08:00
Added JsonUtils to post-process written json (backported from master)
This commit is contained in:
parent
06dffc3f80
commit
1bc0a65106
@ -509,6 +509,8 @@ set(SLIC3R_SOURCES
|
|||||||
Arachne/WallToolPaths.hpp
|
Arachne/WallToolPaths.hpp
|
||||||
Arachne/WallToolPaths.cpp
|
Arachne/WallToolPaths.cpp
|
||||||
StaticMap.hpp
|
StaticMap.hpp
|
||||||
|
Utils/JsonUtils.hpp
|
||||||
|
Utils/JsonUtils.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(libslic3r STATIC ${SLIC3R_SOURCES})
|
add_library(libslic3r STATIC ${SLIC3R_SOURCES})
|
||||||
|
24
src/libslic3r/Utils/JsonUtils.cpp
Normal file
24
src/libslic3r/Utils/JsonUtils.cpp
Normal 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
|
12
src/libslic3r/Utils/JsonUtils.hpp
Normal file
12
src/libslic3r/Utils/JsonUtils.hpp
Normal 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_
|
Loading…
x
Reference in New Issue
Block a user