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

Unified Diff: compiled/subscription/Subscription.cpp

Issue 29385742: Issue 4127 - [emscripten] Convert subscription classes to C++ - Part 2 (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Patch Set: Rebased Created April 13, 2017, 1: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
« no previous file with comments | « compiled/subscription/Subscription.h ('k') | compiled/subscription/UserDefinedSubscription.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: compiled/subscription/Subscription.cpp
===================================================================
--- a/compiled/subscription/Subscription.cpp
+++ b/compiled/subscription/Subscription.cpp
@@ -34,16 +34,33 @@ Subscription::Subscription(Type type, co
annotate_address(this, "Subscription");
}
Subscription::~Subscription()
{
knownSubscriptions.erase(mID);
}
+Filter* Subscription::FilterAt(unsigned index)
+{
+ if (index >= mFilters.size())
+ return nullptr;
+
+ FilterPtr result(mFilters[index]);
+ return result.release();
+}
+
+int Subscription::IndexOfFilter(Filter* filter)
+{
+ for (unsigned i = 0; i < mFilters.size(); i++)
+ if (mFilters[i] == filter)
+ return i;
+ return -1;
+}
+
OwnedString Subscription::Serialize() const
{
OwnedString result(u"[Subscription]\nurl="_str);
result.append(mID);
result.append(u'\n');
if (!mTitle.empty())
{
result.append(u"title="_str);
@@ -53,18 +70,27 @@ OwnedString Subscription::Serialize() co
if (mDisabled)
result.append(u"disabled=true\n"_str);
return result;
}
OwnedString Subscription::SerializeFilters() const
{
- // TODO
- return OwnedString();
+ if (!mFilters.size())
+ return OwnedString();
+
+ OwnedString result(u"[Subscription filters]\n"_str);
+ for (const auto& filter : mFilters)
+ {
+ // TODO: Escape [ characters
+ result.append(filter->GetText());
+ result.append(u'\n');
+ }
+ return result;
}
Subscription* Subscription::FromID(const String& id)
{
if (id.empty())
{
// Generate a new random ID
unsigned int seed = knownSubscriptions.size();
@@ -85,19 +111,19 @@ Subscription* Subscription::FromID(const
if (knownSubscription)
{
knownSubscription->second->AddRef();
return knownSubscription->second;
}
SubscriptionPtr subscription;
if (!id.empty() && id[0] == '~')
- subscription = new UserDefinedSubscription(id);
+ subscription = SubscriptionPtr(new UserDefinedSubscription(id), false);
else
- subscription = new DownloadableSubscription(id);
+ subscription = SubscriptionPtr(new DownloadableSubscription(id), false);
// This is a hack: we looked up the entry using id but create it using
// subscription->mID. This works because both are equal at this point.
// However, id refers to a temporary buffer which will go away.
enter_context("Adding to known subscriptions");
knownSubscription.assign(subscription->mID, subscription.get());
exit_context();
« no previous file with comments | « compiled/subscription/Subscription.h ('k') | compiled/subscription/UserDefinedSubscription.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld