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

Delta Between Two Patch Sets: compiled/subscription/UserDefinedSubscription.cpp

Issue 29548581: Issue 4128, 5138 - Add Parser and Serializer implemented in C++ Base URL: https://github.com/adblockplus/adblockpluscore.git
Left Patch Set: Created Sept. 18, 2017, 5:23 p.m.
Right 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « compiled/subscription/UserDefinedSubscription.h ('k') | lib/filterStorage.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 #include <cstdlib> 18 #include <cstdlib>
19 19
20 #include "UserDefinedSubscription.h" 20 #include "UserDefinedSubscription.h"
21 #include "../FilterNotifier.h" 21 #include "../FilterNotifier.h"
22 22
23 ABP_NS_USING
24
23 namespace 25 namespace
24 { 26 {
25 enum FilterCategory 27 enum FilterCategory
26 { 28 {
27 NONE = 0, 29 NONE = 0,
28 WHITELIST = 1, 30 WHITELIST = 1,
29 BLOCKING = 2, 31 BLOCKING = 2,
30 ELEMHIDE = 4, 32 ELEMHIDE = 4,
31 }; 33 };
32 34
33 const FilterCategory filterTypeToCategory[] = { 35 FilterCategory filterTypeToCategory(Filter::Type type)
34 FilterCategory::BLOCKING, // UNKNOWN 36 {
35 FilterCategory::NONE, // INVALID 37 if (type == Filter::Type::BLOCKING)
36 FilterCategory::NONE, // COMMENT 38 return FilterCategory::BLOCKING;
37 FilterCategory::BLOCKING, // BLOCKING 39 if (type == Filter::Type::WHITELIST)
38 FilterCategory::WHITELIST, // WHITELIST 40 return FilterCategory::WHITELIST;
39 FilterCategory::ELEMHIDE, // ELEMHIDE 41 if ((type & Filter::Type::ELEMHIDEBASE) == Filter::Type::ELEMHIDEBASE)
40 FilterCategory::ELEMHIDE, // ELEMHIDEEXCEPTION 42 return FilterCategory::ELEMHIDE;
41 FilterCategory::ELEMHIDE, // ELEMHIDEEMULATION
42 };
43 43
44 static_assert( 44 return FilterCategory::NONE;
45 sizeof(filterTypeToCategory) / sizeof(filterTypeToCategory[0]) == Filter::Ty pe::VALUE_COUNT, 45 }
46 "Unexpected number of filter types, was a new type added?"
47 );
48 } 46 }
49 47
50 UserDefinedSubscription::UserDefinedSubscription(const String& id, const KeyValu es& properties) 48 UserDefinedSubscription::UserDefinedSubscription(const String& id, const KeyValu es& properties)
51 : Subscription(Type::USERDEFINED, id, properties), mDefaults(FilterCategory: :NONE) 49 : Subscription(classType, id, properties), mDefaults(0)
52 { 50 {
53 parseDefaultsProperty(properties, mDefaults); 51 parseDefaultsProperty(properties, mDefaults);
54 } 52 }
55 53
56 bool UserDefinedSubscription::IsDefaultFor(const Filter& filter) const 54 bool UserDefinedSubscription::IsDefaultFor(const Filter& filter) const
57 { 55 {
58 if (filter.mType >= Filter::Type::VALUE_COUNT) 56 return mDefaults & filterTypeToCategory(filter.mType);
59 {
60 assert(false, "Filter type exceeds valid range");
61 abort();
62 }
63 return mDefaults & filterTypeToCategory[filter.mType];
64 } 57 }
65 58
66 void UserDefinedSubscription::MakeDefaultFor(const Filter& filter) 59 void UserDefinedSubscription::MakeDefaultFor(const Filter& filter)
67 { 60 {
68 if (filter.mType >= Filter::Type::VALUE_COUNT) 61 mDefaults |= filterTypeToCategory(filter.mType);
69 {
70 assert(false, "Filter type exceeds valid range");
71 abort();
72 }
73 mDefaults |= filterTypeToCategory[filter.mType];
74 } 62 }
75 63
76 void UserDefinedSubscription::InsertFilterAt(Filter& filter, unsigned pos) 64 void UserDefinedSubscription::InsertFilterAt(Filter& filter, unsigned pos)
77 { 65 {
78 if (pos >= mFilters.size()) 66 if (pos >= mFilters.size())
79 pos = mFilters.size(); 67 pos = mFilters.size();
80 mFilters.emplace(mFilters.begin() + pos, &filter); 68 mFilters.emplace(mFilters.begin() + pos, &filter);
81 69
82 if (GetListed()) 70 if (GetListed())
83 { 71 {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 String::size_type spacePos = stringDefaultFor->find(u' ', prevSpacePos + 1); 117 String::size_type spacePos = stringDefaultFor->find(u' ', prevSpacePos + 1);
130 auto values = SplitString(DependentString(*stringDefaultFor, prevSpacePos), spacePos); 118 auto values = SplitString(DependentString(*stringDefaultFor, prevSpacePos), spacePos);
131 if (values.first == u"blocking"_str) 119 if (values.first == u"blocking"_str)
132 defaults |= FilterCategory::BLOCKING; 120 defaults |= FilterCategory::BLOCKING;
133 else if (values.first == u"whitelist"_str) 121 else if (values.first == u"whitelist"_str)
134 defaults |= FilterCategory::WHITELIST; 122 defaults |= FilterCategory::WHITELIST;
135 else if (values.first == u"elemhide"_str) 123 else if (values.first == u"elemhide"_str)
136 defaults |= FilterCategory::ELEMHIDE; 124 defaults |= FilterCategory::ELEMHIDE;
137 prevSpacePos = spacePos; 125 prevSpacePos = spacePos;
138 } 126 }
139 } 127 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld