Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: compiled/subscription/UserDefinedSubscription.cpp

Issue 29548581: Issue 4128, 5138 - Add Parser and Serializer implemented in C++ Base URL: https://github.com/adblockplus/adblockpluscore.git
Patch Set: rebase Created March 7, 2018, 12:01 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: compiled/subscription/UserDefinedSubscription.cpp
diff --git a/compiled/subscription/UserDefinedSubscription.cpp b/compiled/subscription/UserDefinedSubscription.cpp
index 5e3972e09d80281d08e5f9c192b7ae129a2c6ce2..749e86f5033ee306b5703c260c2d3f20b42493ce 100644
--- a/compiled/subscription/UserDefinedSubscription.cpp
+++ b/compiled/subscription/UserDefinedSubscription.cpp
@@ -45,9 +45,10 @@ namespace
}
}
-UserDefinedSubscription::UserDefinedSubscription(const String& id)
- : Subscription(classType, id), mDefaults(0)
+UserDefinedSubscription::UserDefinedSubscription(const String& id, const KeyValues& properties)
+ : Subscription(classType, id, properties), mDefaults(0)
{
+ parseDefaultsProperty(properties, mDefaults);
}
bool UserDefinedSubscription::IsDefaultFor(const Filter& filter) const
@@ -88,9 +89,9 @@ bool UserDefinedSubscription::RemoveFilterAt(unsigned pos)
return true;
}
-OwnedString UserDefinedSubscription::Serialize() const
+OwnedString UserDefinedSubscription::SerializeProperties() const
{
- OwnedString result(Subscription::Serialize());
+ OwnedString result(Subscription::DoSerializeProperties());
if (!IsGeneric())
{
result.append(u"defaults="_str);
@@ -104,3 +105,23 @@ OwnedString UserDefinedSubscription::Serialize() const
}
return result;
}
+
+void UserDefinedSubscription::parseDefaultsProperty(const KeyValues& properties, int& defaults)
+{
+ auto stringDefaultFor = findPropertyValue(properties, u"defaults"_str);
+ if (stringDefaultFor == nullptr)
+ return;
+ String::size_type prevSpacePos = 0;
+ while (prevSpacePos != String::npos)
+ {
+ String::size_type spacePos = stringDefaultFor->find(u' ', prevSpacePos + 1);
+ auto values = SplitString(DependentString(*stringDefaultFor, prevSpacePos), spacePos);
+ if (values.first == u"blocking"_str)
+ defaults |= FilterCategory::BLOCKING;
+ else if (values.first == u"whitelist"_str)
+ defaults |= FilterCategory::WHITELIST;
+ else if (values.first == u"elemhide"_str)
+ defaults |= FilterCategory::ELEMHIDE;
+ prevSpacePos = spacePos;
+ }
+}

Powered by Google App Engine
This is Rietveld