summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/Controllers/HighlightManager.cpp')
-rw-r--r--Swift/Controllers/HighlightManager.cpp29
1 files changed, 15 insertions, 14 deletions
diff --git a/Swift/Controllers/HighlightManager.cpp b/Swift/Controllers/HighlightManager.cpp
index 7ab578e..fa98a6e 100644
--- a/Swift/Controllers/HighlightManager.cpp
+++ b/Swift/Controllers/HighlightManager.cpp
@@ -10,6 +10,9 @@
#include <boost/regex.hpp>
#include <boost/bind.hpp>
#include <boost/numeric/conversion/cast.hpp>
+#include <boost/serialization/vector.hpp>
+#include <boost/archive/text_oarchive.hpp>
+#include <boost/archive/text_iarchive.hpp>
#include <Swiften/Base/foreach.h>
#include <Swift/Controllers/HighlightManager.h>
@@ -63,25 +66,23 @@ void HighlightManager::loadSettings()
std::string HighlightManager::rulesToString() const
{
- std::string s;
- foreach (HighlightRule r, rules_) {
- s += r.toString() + '\f';
- }
- if (s.size()) {
- s.erase(s.end() - 1);
- }
- return s;
+ std::stringstream stream;
+ boost::archive::text_oarchive archive(stream);
+ archive << rules_;
+ return stream.str();
}
std::vector<HighlightRule> HighlightManager::rulesFromString(const std::string& rulesString)
{
std::vector<HighlightRule> rules;
- std::string s(rulesString);
- typedef boost::split_iterator<std::string::iterator> split_iterator;
- for (split_iterator it = boost::make_split_iterator(s, boost::first_finder("\f")); it != split_iterator(); ++it) {
- HighlightRule r = HighlightRule::fromString(boost::copy_range<std::string>(*it));
- if (!r.isEmpty()) {
- rules.push_back(r);
+ if (rulesString.length()) {
+ std::stringstream stream;
+ stream << rulesString;
+ try {
+ boost::archive::text_iarchive archive(stream);
+ archive >> rules;
+ } catch (boost::archive::archive_exception&) {
+ /* archive corrupted */
}
}
return rules;