From a7520f47a66551e95a35bfe124c082c54eefb789 Mon Sep 17 00:00:00 2001 From: Vojtech Bubnik Date: Tue, 25 Jan 2022 16:28:07 +0100 Subject: [PATCH] GCodeFindReplace: Implemented perl's "match single line" option to the back-end. --- src/libslic3r/GCode/FindReplace.cpp | 4 +++- src/libslic3r/GCode/FindReplace.hpp | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/libslic3r/GCode/FindReplace.cpp b/src/libslic3r/GCode/FindReplace.cpp index 4ad2eff36..e9c9a97d0 100644 --- a/src/libslic3r/GCode/FindReplace.cpp +++ b/src/libslic3r/GCode/FindReplace.cpp @@ -37,6 +37,7 @@ GCodeFindReplace::GCodeFindReplace(const std::vector &gcode_substit out.regexp = strchr(params.c_str(), 'r') != nullptr || strchr(params.c_str(), 'R') != nullptr; out.case_insensitive = strchr(params.c_str(), 'i') != nullptr || strchr(params.c_str(), 'I') != nullptr; out.whole_word = strchr(params.c_str(), 'w') != nullptr || strchr(params.c_str(), 'W') != nullptr; + out.single_line = strchr(params.c_str(), 's') != nullptr || strchr(params.c_str(), 'S') != nullptr; if (out.regexp) { out.regexp_pattern.assign( out.whole_word ? @@ -116,7 +117,8 @@ std::string GCodeFindReplace::process_layer(const std::string &ain) temp.clear(); temp.reserve(in->size()); boost::regex_replace(ToStringIterator(temp), in->begin(), in->end(), - substitution.regexp_pattern, substitution.format, boost::match_default | boost::match_single_line /* | boost::match_not_dot_newline | boost::match_not_dot_null */ | boost::format_all); + substitution.regexp_pattern, substitution.format, + (substitution.single_line ? boost::match_single_line | boost::match_default : boost::match_default) | boost::format_all); std::swap(out, temp); } else { if (in == &ain) diff --git a/src/libslic3r/GCode/FindReplace.hpp b/src/libslic3r/GCode/FindReplace.hpp index 2d12cf28b..9bc0a481c 100644 --- a/src/libslic3r/GCode/FindReplace.hpp +++ b/src/libslic3r/GCode/FindReplace.hpp @@ -24,6 +24,8 @@ private: bool regexp { false }; bool case_insensitive { false }; bool whole_word { false }; + // Valid for regexp only. Equivalent to Perl's /s modifier. + bool single_line { false }; }; std::vector m_substitutions; };