summaryrefslogtreecommitdiffhomepage
path: root/diff.cpp
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2023-01-28 15:07:14 +0100
committerRoland Reichwein <mail@reichwein.it>2023-01-28 15:07:14 +0100
commita61c702d91d7444ce0bb094ddccc70f72416500b (patch)
tree8d5a47c73666ee2b710a7a34c0c392b728bda45b /diff.cpp
parentf44d36b05e43cabde31aeaba5d25fded140345a1 (diff)
Added WebAssembly for C++ implementation of Diff
Diffstat (limited to 'diff.cpp')
-rw-r--r--diff.cpp38
1 files changed, 35 insertions, 3 deletions
diff --git a/diff.cpp b/diff.cpp
index b3ed5ce..ee17fad 100644
--- a/diff.cpp
+++ b/diff.cpp
@@ -102,12 +102,28 @@ 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 std::string& xml)
+{
+ create(xml);
+}
+
+void Diff::create(const std::string& xml)
+{
+ pt::ptree tree;
+ 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");
+ m_data = tree.get<std::string>("diff.data");
+}
+
boost::property_tree::ptree Diff::get_structure() const
{
pt::ptree ptree;
- ptree.put("diff.chunk.start", std::to_string(m_pos0));
- ptree.put("diff.chunk.end", std::to_string(m_pos1));
- ptree.put("diff.chunk.data", m_data);
+ ptree.put("diff.start", std::to_string(m_pos0));
+ ptree.put("diff.end", std::to_string(m_pos1));
+ ptree.put("diff.data", m_data);
return ptree;
}
@@ -123,3 +139,19 @@ std::string Diff::get_xml() const
return oss.str();
}
+extern "C" {
+
+ const char* diff_create(const char* old_version, const char* new_version)
+ {
+ Diff diff{old_version, new_version};
+ return strdup(diff.get_xml().c_str());
+ }
+
+ const char* diff_apply(const char* old_version, const char* diff)
+ {
+ Diff d{diff};
+
+ return strdup(d.apply(old_version).c_str());
+ }
+
+}