diff options
author | Roland Reichwein <mail@reichwein.it> | 2023-01-30 21:05:59 +0100 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2023-01-30 21:05:59 +0100 |
commit | 8d1b4f06375bf676c5cf825ba4b116271f3d44c5 (patch) | |
tree | 0f4b4acb148e51c73b6abf3f11b3fc6e98f920ce | |
parent | b2f3b566c0c0edd41b0314fcbf516a3d7876e14b (diff) |
whiteboard v1.5v1.5
-rw-r--r-- | debian/changelog | 4 | ||||
-rw-r--r-- | diff.cpp | 47 |
2 files changed, 43 insertions, 8 deletions
diff --git a/debian/changelog b/debian/changelog index efe5447..688c98f 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -whiteboard (1.5~pre1) UNRELEASED; urgency=medium +whiteboard (1.5) unstable; urgency=medium * Move from FCGI to websocket interface * Position changes w/o file transmit @@ -6,7 +6,7 @@ whiteboard (1.5~pre1) UNRELEASED; urgency=medium * Add reconnect button * Add diff handling - -- Roland Reichwein <mail@reichwein.it> Sat, 21 Jan 2023 18:18:37 +0100 + -- Roland Reichwein <mail@reichwein.it> Mon, 30 Jan 2023 21:05:35 +0100 whiteboard (1.4) unstable; urgency=medium @@ -5,9 +5,44 @@ #include <sstream> #include <boost/property_tree/xml_parser.hpp> +#include <boost/archive/iterators/binary_from_base64.hpp> +#include <boost/archive/iterators/base64_from_binary.hpp> +#include <boost/archive/iterators/transform_width.hpp> +#include <boost/algorithm/string.hpp> namespace pt = boost::property_tree; +namespace { + +// prevent usage of same functions from libreichwein to keep unit self-contained + +std::string decode64(const std::string &val) +{ +#if 0 + using namespace boost::archive::iterators; + using It = transform_width<binary_from_base64<std::string::const_iterator>, 8, 6>; + return boost::algorithm::trim_right_copy_if(std::string(It(std::begin(val)), It(std::end(val))), [](char c) { + return c == '\0'; + }); +#else + return val; +#endif +} + +std::string encode64(const std::string &val) +{ +#if 0 + using namespace boost::archive::iterators; + using It = base64_from_binary<transform_width<std::string::const_iterator, 6, 8>>; + auto tmp = std::string(It(std::begin(val)), It(std::end(val))); + return tmp.append((3 - val.size() % 3) % 3, '='); +#else + return val; +#endif +} + +} // namespace + Diff::Diff() { } @@ -23,7 +58,7 @@ std::string Diff::apply(const std::string& old_version) const if (m_pos0 <= m_pos1 && m_pos1 <= old_version.size()) { result.erase(m_pos0, m_pos1 - m_pos0); - result.insert(m_pos0, m_data); + result.insert(m_pos0, decode64(m_data)); } return result; @@ -47,7 +82,7 @@ void Diff::create(const std::string& old_version, const std::string& new_version if (old_pos0 == old_version.size()) { m_pos0 = old_pos0; m_pos1 = old_pos0; - m_data = new_version.substr(new_pos0); + m_data = encode64(new_version.substr(new_pos0)); return; } @@ -70,7 +105,7 @@ void Diff::create(const std::string& old_version, const std::string& new_version if (old_pos1 == 0) { m_pos0 = 0; m_pos1 = 0; - m_data = new_version.substr(0, new_pos1); + m_data = encode64(new_version.substr(0, new_pos1)); return; } @@ -96,7 +131,7 @@ void Diff::create(const std::string& old_version, const std::string& new_version if (old_pos0 == old_pos1) { m_pos0 = old_pos0; m_pos1 = old_pos0; - m_data = new_version.substr(new_pos0, new_pos1 - new_pos0); + m_data = encode64(new_version.substr(new_pos0, new_pos1 - new_pos0)); return; } @@ -111,7 +146,7 @@ void Diff::create(const std::string& old_version, const std::string& new_version // last resort: remove and add in the middle m_pos0 = old_pos0; m_pos1 = old_pos1; - m_data = new_version.substr(old_pos0, new_pos1 - new_pos0); + m_data = encode64(new_version.substr(old_pos0, new_pos1 - new_pos0)); } Diff::Diff(const boost::property_tree::ptree& ptree) @@ -139,7 +174,7 @@ void Diff::create(const std::string& xml) { pt::ptree ptree; std::istringstream ss{xml}; - pt::read_xml(ss, ptree, pt::xml_parser::no_comments | pt::xml_parser::trim_whitespace); + pt::read_xml(ss, ptree); create(ptree); } |