summaryrefslogtreecommitdiffhomepage
path: root/diff.cpp
diff options
context:
space:
mode:
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;