summaryrefslogtreecommitdiffhomepage
path: root/diff.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'diff.cpp')
-rw-r--r--diff.cpp29
1 files changed, 20 insertions, 9 deletions
diff --git a/diff.cpp b/diff.cpp
index 99a2f14..b56fd51 100644
--- a/diff.cpp
+++ b/diff.cpp
@@ -1,6 +1,7 @@
#include "diff.h"
#include <algorithm>
+#include <iostream>
#include <sstream>
#include <boost/property_tree/xml_parser.hpp>
@@ -102,6 +103,22 @@ void Diff::create(const std::string& old_version, const std::string& new_version
m_data = new_version.substr(old_pos0, new_pos1 - new_pos0);
}
+Diff::Diff(const boost::property_tree::ptree& ptree)
+{
+ create(ptree);
+}
+
+void Diff::create(const boost::property_tree::ptree& ptree)
+{
+ m_pos0 = ptree.get<int>("diff.start");
+ m_pos1 = ptree.get<int>("diff.end");
+
+ if (m_pos0 > m_pos1)
+ throw std::runtime_error("Bad range in diff");
+
+ m_data = ptree.get<std::string>("diff.data");
+}
+
Diff::Diff(const std::string& xml)
{
create(xml);
@@ -109,17 +126,11 @@ Diff::Diff(const std::string& xml)
void Diff::create(const std::string& xml)
{
- pt::ptree tree;
+ pt::ptree ptree;
std::istringstream ss{xml};
- pt::read_xml(ss, tree, pt::xml_parser::no_comments | pt::xml_parser::trim_whitespace);
-
- m_pos0 = tree.get<int>("diff.start");
- m_pos1 = tree.get<int>("diff.end");
-
- if (m_pos0 > m_pos1)
- throw std::runtime_error("Bad range in diff");
+ pt::read_xml(ss, ptree, pt::xml_parser::no_comments | pt::xml_parser::trim_whitespace);
- m_data = tree.get<std::string>("diff.data");
+ create(ptree);
}
boost::property_tree::ptree Diff::get_structure() const