From b2f3b566c0c0edd41b0314fcbf516a3d7876e14b Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sun, 29 Jan 2023 17:54:14 +0100 Subject: Fix concurrent edit, tests --- diff.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'diff.cpp') diff --git a/diff.cpp b/diff.cpp index ea9b04e..85d3167 100644 --- a/diff.cpp +++ b/diff.cpp @@ -21,9 +21,10 @@ std::string Diff::apply(const std::string& old_version) const { std::string result{old_version}; - result.erase(m_pos0, m_pos1 - m_pos0); - - result.insert(m_pos0, m_data); + if (m_pos0 <= m_pos1 && m_pos1 <= old_version.size()) { + result.erase(m_pos0, m_pos1 - m_pos0); + result.insert(m_pos0, m_data); + } return result; } @@ -143,6 +144,11 @@ void Diff::create(const std::string& xml) create(ptree); } +bool Diff::empty() const +{ + return m_pos0 == m_pos1 && m_data.empty(); +} + boost::property_tree::ptree Diff::get_structure() const { pt::ptree ptree; -- cgit v1.2.3