diff options
author | Enrico Turri <enricoturri@seznam.cz> | 2018-05-15 13:19:43 +0300 |
---|---|---|
committer | Enrico Turri <enricoturri@seznam.cz> | 2018-05-15 13:19:43 +0300 |
commit | a612b5b64821e9468ed0bfe9ed1fefa67e3aad5c (patch) | |
tree | ce14e00eb9a9b243235beb6618cc002e4fdc92c5 /xs/src/libslic3r/Format | |
parent | 328eba56102329c415e130a24977b54277412cd2 (diff) |
Replacement of xml escape characters when exporting to amf
Diffstat (limited to 'xs/src/libslic3r/Format')
-rw-r--r-- | xs/src/libslic3r/Format/AMF.cpp | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/xs/src/libslic3r/Format/AMF.cpp b/xs/src/libslic3r/Format/AMF.cpp index b446f456b..83b50ec9e 100644 --- a/xs/src/libslic3r/Format/AMF.cpp +++ b/xs/src/libslic3r/Format/AMF.cpp @@ -674,6 +674,33 @@ bool load_amf(const char *path, PresetBundle* bundle, Model *model) return false; } +std::string xml_escape(std::string text) +{ + std::string::size_type pos = 0; + for (;;) + { + pos = text.find_first_of("\"\'&<>", pos); + if (pos == std::string::npos) + break; + + std::string replacement; + switch (text[pos]) + { + case '\"': replacement = """; break; + case '\'': replacement = "'"; break; + case '&': replacement = "&"; break; + case '<': replacement = "<"; break; + case '>': replacement = ">"; break; + default: break; + } + + text.replace(pos, 1, replacement); + pos += replacement.size(); + } + + return text; +} + bool store_amf(const char *path, Model *model, Print* print, bool export_print_config) { if ((path == nullptr) || (model == nullptr) || (print == nullptr)) @@ -701,7 +728,7 @@ bool store_amf(const char *path, Model *model, Print* print, bool export_print_c { std::string config = "\n"; GCode::append_full_config(*print, config); - stream << "<metadata type=\"" << SLIC3R_CONFIG_TYPE << "\">" << config << "</metadata>\n"; + stream << "<metadata type=\"" << SLIC3R_CONFIG_TYPE << "\">" << xml_escape(config) << "</metadata>\n"; } for (const auto &material : model->materials) { |