summaryrefslogtreecommitdiffhomepage
path: root/diff.cpp
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2023-01-29 17:54:14 +0100
committerRoland Reichwein <mail@reichwein.it>2023-01-29 17:54:14 +0100
commitb2f3b566c0c0edd41b0314fcbf516a3d7876e14b (patch)
tree1cebf349b746ae606354733e9464581d530fb5e7 /diff.cpp
parent32b5b50dacb1bfc02a0baef0eda47df8d5f2be37 (diff)
Fix concurrent edit, tests
Diffstat (limited to 'diff.cpp')
-rw-r--r--diff.cpp12
1 files changed, 9 insertions, 3 deletions
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;