diff options
author | Roland Reichwein <mail@reichwein.it> | 2023-01-29 17:54:14 +0100 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2023-01-29 17:54:14 +0100 |
commit | b2f3b566c0c0edd41b0314fcbf516a3d7876e14b (patch) | |
tree | 1cebf349b746ae606354733e9464581d530fb5e7 /diff.cpp | |
parent | 32b5b50dacb1bfc02a0baef0eda47df8d5f2be37 (diff) |
Fix concurrent edit, tests
Diffstat (limited to 'diff.cpp')
-rw-r--r-- | diff.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
@@ -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; |