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

Delta Between Two Patch Sets: compiled/filter/Filter.cpp

Issue 29574591: Issue 5258 - Implement Filter::As<>() method to make working with filters easier from C++ code (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Left Patch Set: Created Oct. 12, 2017, 12:13 p.m.
Right Patch Set: Removed unnecessary base class check Created Oct. 13, 2017, 4:57 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « compiled/filter/Filter.h ('k') | compiled/filter/InvalidFilter.h » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 auto knownFilter = knownFilters.find(text); 115 auto knownFilter = knownFilters.find(text);
116 if (knownFilter) 116 if (knownFilter)
117 { 117 {
118 knownFilter->second->AddRef(); 118 knownFilter->second->AddRef();
119 return knownFilter->second; 119 return knownFilter->second;
120 } 120 }
121 121
122 FilterPtr filter; 122 FilterPtr filter;
123 switch (type) 123 switch (type)
124 { 124 {
125 case Filter::Type::COMMENT: 125 case CommentFilter::classType:
126 filter = FilterPtr(new CommentFilter(text), false); 126 filter = FilterPtr(new CommentFilter(text), false);
127 break; 127 break;
128 case Filter::Type::INVALID: 128 case InvalidFilter::classType:
129 filter = FilterPtr(new InvalidFilter(text, error), false); 129 filter = FilterPtr(new InvalidFilter(text, error), false);
130 break; 130 break;
131 case Filter::Type::BLOCKING: 131 case BlockingFilter::classType:
132 filter = FilterPtr(new BlockingFilter(text, data.regexp), false); 132 filter = FilterPtr(new BlockingFilter(text, data.regexp), false);
133 break; 133 break;
134 case Filter::Type::WHITELIST: 134 case WhitelistFilter::classType:
135 filter = FilterPtr(new WhitelistFilter(text, data.regexp), false); 135 filter = FilterPtr(new WhitelistFilter(text, data.regexp), false);
136 break; 136 break;
137 case Filter::Type::ELEMHIDE: 137 case ElemHideFilter::classType:
138 filter = FilterPtr(new ElemHideFilter(text, data.elemhide), false); 138 filter = FilterPtr(new ElemHideFilter(text, data.elemhide), false);
139 break; 139 break;
140 case Filter::Type::ELEMHIDEEXCEPTION: 140 case ElemHideException::classType:
141 filter = FilterPtr(new ElemHideException(text, data.elemhide), false); 141 filter = FilterPtr(new ElemHideException(text, data.elemhide), false);
142 break; 142 break;
143 case Filter::Type::ELEMHIDEEMULATION: 143 case ElemHideEmulationFilter::classType:
144 filter = FilterPtr(new ElemHideEmulationFilter(text, data.elemhide), false ); 144 filter = FilterPtr(new ElemHideEmulationFilter(text, data.elemhide), false );
145 if (static_cast<ElemHideEmulationFilter*>(filter.get())->IsGeneric()) 145 if (static_cast<ElemHideEmulationFilter*>(filter.get())->IsGeneric())
146 filter = FilterPtr(new InvalidFilter(text, u"filter_elemhideemulation_no domain"_str), false); 146 filter = FilterPtr(new InvalidFilter(text, u"filter_elemhideemulation_no domain"_str), false);
147 break; 147 break;
148 default: 148 default:
149 // This should never happen but just in case 149 // This should never happen but just in case
150 return nullptr; 150 return nullptr;
151 } 151 }
152 152
153 // This is a hack: we looked up the entry using text but create it using 153 // This is a hack: we looked up the entry using text but create it using
154 // filter->mText. This works because both are equal at this point. However, 154 // filter->mText. This works because both are equal at this point. However,
155 // text refers to a temporary buffer which will go away. 155 // text refers to a temporary buffer which will go away.
156 enter_context("Adding to known filters"); 156 enter_context("Adding to known filters");
157 knownFilter.assign(filter->mText, filter.get()); 157 knownFilter.assign(filter->mText, filter.get());
158 exit_context(); 158 exit_context();
159 159
160 return filter.release(); 160 return filter.release();
161 } 161 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld