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: Created Sept. 18, 2017, 5:23 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 f2d6cd137f8246c878c9d82bbc3d6ae06bbfeafc..2b665ed96a603d63b0fb3caf1494eeb25bc0d805 100644
--- a/compiled/subscription/UserDefinedSubscription.cpp
+++ b/compiled/subscription/UserDefinedSubscription.cpp
@@ -47,9 +47,10 @@ namespace
);
}
-UserDefinedSubscription::UserDefinedSubscription(const String& id)
- : Subscription(Type::USERDEFINED, id), mDefaults(0)
+UserDefinedSubscription::UserDefinedSubscription(const String& id, const KeyValues& properties)
+ : Subscription(Type::USERDEFINED, id, properties), mDefaults(FilterCategory::NONE)
{
+ parseDefaultsProperty(properties, mDefaults);
}
bool UserDefinedSubscription::IsDefaultFor(const Filter& filter) const
@@ -100,9 +101,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);
@@ -116,3 +117,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