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

Side by Side 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.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 27 matching lines...) Expand all
38 return FilterCategory::BLOCKING; 38 return FilterCategory::BLOCKING;
39 if (type == Filter::Type::WHITELIST) 39 if (type == Filter::Type::WHITELIST)
40 return FilterCategory::WHITELIST; 40 return FilterCategory::WHITELIST;
41 if ((type & Filter::Type::ELEMHIDEBASE) == Filter::Type::ELEMHIDEBASE) 41 if ((type & Filter::Type::ELEMHIDEBASE) == Filter::Type::ELEMHIDEBASE)
42 return FilterCategory::ELEMHIDE; 42 return FilterCategory::ELEMHIDE;
43 43
44 return FilterCategory::NONE; 44 return FilterCategory::NONE;
45 } 45 }
46 } 46 }
47 47
48 UserDefinedSubscription::UserDefinedSubscription(const String& id) 48 UserDefinedSubscription::UserDefinedSubscription(const String& id, const KeyValu es& properties)
49 : Subscription(classType, id), mDefaults(0) 49 : Subscription(classType, id, properties), mDefaults(0)
50 { 50 {
51 parseDefaultsProperty(properties, mDefaults);
51 } 52 }
52 53
53 bool UserDefinedSubscription::IsDefaultFor(const Filter& filter) const 54 bool UserDefinedSubscription::IsDefaultFor(const Filter& filter) const
54 { 55 {
55 return mDefaults & filterTypeToCategory(filter.mType); 56 return mDefaults & filterTypeToCategory(filter.mType);
56 } 57 }
57 58
58 void UserDefinedSubscription::MakeDefaultFor(const Filter& filter) 59 void UserDefinedSubscription::MakeDefaultFor(const Filter& filter)
59 { 60 {
60 mDefaults |= filterTypeToCategory(filter.mType); 61 mDefaults |= filterTypeToCategory(filter.mType);
(...skipping 20 matching lines...) Expand all
81 FilterPtr filter(mFilters[pos]); 82 FilterPtr filter(mFilters[pos]);
82 mFilters.erase(mFilters.begin() + pos); 83 mFilters.erase(mFilters.begin() + pos);
83 if (GetListed()) 84 if (GetListed())
84 { 85 {
85 FilterNotifier::FilterChange(FilterNotifier::Topic::FILTER_REMOVED, 86 FilterNotifier::FilterChange(FilterNotifier::Topic::FILTER_REMOVED,
86 *filter.get(), this, pos); 87 *filter.get(), this, pos);
87 } 88 }
88 return true; 89 return true;
89 } 90 }
90 91
91 OwnedString UserDefinedSubscription::Serialize() const 92 OwnedString UserDefinedSubscription::SerializeProperties() const
92 { 93 {
93 OwnedString result(Subscription::Serialize()); 94 OwnedString result(Subscription::DoSerializeProperties());
94 if (!IsGeneric()) 95 if (!IsGeneric())
95 { 96 {
96 result.append(u"defaults="_str); 97 result.append(u"defaults="_str);
97 if (mDefaults & FilterCategory::BLOCKING) 98 if (mDefaults & FilterCategory::BLOCKING)
98 result.append(u" blocking"_str); 99 result.append(u" blocking"_str);
99 if (mDefaults & FilterCategory::WHITELIST) 100 if (mDefaults & FilterCategory::WHITELIST)
100 result.append(u" whitelist"_str); 101 result.append(u" whitelist"_str);
101 if (mDefaults & FilterCategory::ELEMHIDE) 102 if (mDefaults & FilterCategory::ELEMHIDE)
102 result.append(u" elemhide"_str); 103 result.append(u" elemhide"_str);
103 result.append(u'\n'); 104 result.append(u'\n');
104 } 105 }
105 return result; 106 return result;
106 } 107 }
108
109 void UserDefinedSubscription::parseDefaultsProperty(const KeyValues& properties, int& defaults)
110 {
111 auto stringDefaultFor = findPropertyValue(properties, u"defaults"_str);
112 if (stringDefaultFor == nullptr)
113 return;
114 String::size_type prevSpacePos = 0;
115 while (prevSpacePos != String::npos)
116 {
117 String::size_type spacePos = stringDefaultFor->find(u' ', prevSpacePos + 1);
118 auto values = SplitString(DependentString(*stringDefaultFor, prevSpacePos), spacePos);
119 if (values.first == u"blocking"_str)
120 defaults |= FilterCategory::BLOCKING;
121 else if (values.first == u"whitelist"_str)
122 defaults |= FilterCategory::WHITELIST;
123 else if (values.first == u"elemhide"_str)
124 defaults |= FilterCategory::ELEMHIDE;
125 prevSpacePos = spacePos;
126 }
127 }
OLDNEW

Powered by Google App Engine
This is Rietveld