diff options
author | Roland Reichwein <mail@reichwein.it> | 2023-01-28 20:31:24 +0100 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2023-01-28 20:31:24 +0100 |
commit | a69b1d0c580bc779740ef79a7d16b69229896785 (patch) | |
tree | 962ecac93c521c1d09f1dc1ca727b7121d1b5472 /diff.cpp | |
parent | dd358ac5cdfc2b449dcbe94a33a06a7540d8f966 (diff) |
Client to Server: send diffs instead of whole file
Diffstat (limited to 'diff.cpp')
-rw-r--r-- | diff.cpp | 29 |
1 files changed, 20 insertions, 9 deletions
@@ -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 |