| OLD | NEW |
| 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 text.reset(text, start, end - start); | 71 text.reset(text, start, end - start); |
| 72 } | 72 } |
| 73 } | 73 } |
| 74 | 74 |
| 75 Filter::Filter(Type type, const String& text) | 75 Filter::Filter(Type type, const String& text) |
| 76 : mText(text), mType(type) | 76 : mText(text), mType(type) |
| 77 { | 77 { |
| 78 annotate_address(this, "Filter"); | 78 annotate_address(this, "Filter"); |
| 79 } | 79 } |
| 80 | 80 |
| 81 Filter::Filter(Type type, String&& text) |
| 82 : mText(text), mType(type) |
| 83 { |
| 84 annotate_address(this, "Filter"); |
| 85 } |
| 86 |
| 81 Filter::~Filter() | 87 Filter::~Filter() |
| 82 { | 88 { |
| 83 knownFilters.erase(mText); | 89 knownFilters.erase(mText); |
| 84 } | 90 } |
| 85 | 91 |
| 86 OwnedString Filter::Serialize() const | 92 OwnedString Filter::Serialize() const |
| 87 { | 93 { |
| 88 OwnedString result(u"[Filter]\ntext="_str); | 94 OwnedString result(u"[Filter]\ntext="_str); |
| 89 result.append(mText); | 95 result.append(mText); |
| 90 result.append(u'\n'); | 96 result.append(u'\n'); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 case ElemHideEmulationFilter::classType: | 149 case ElemHideEmulationFilter::classType: |
| 144 filter = FilterPtr(new ElemHideEmulationFilter(text, data.elemhide), false
); | 150 filter = FilterPtr(new ElemHideEmulationFilter(text, data.elemhide), false
); |
| 145 if (static_cast<ElemHideEmulationFilter*>(filter.get())->IsGeneric()) | 151 if (static_cast<ElemHideEmulationFilter*>(filter.get())->IsGeneric()) |
| 146 filter = FilterPtr(new InvalidFilter(text, u"filter_elemhideemulation_no
domain"_str), false); | 152 filter = FilterPtr(new InvalidFilter(text, u"filter_elemhideemulation_no
domain"_str), false); |
| 147 break; | 153 break; |
| 148 default: | 154 default: |
| 149 // This should never happen but just in case | 155 // This should never happen but just in case |
| 150 return nullptr; | 156 return nullptr; |
| 151 } | 157 } |
| 152 | 158 |
| 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, | |
| 155 // text refers to a temporary buffer which will go away. | |
| 156 enter_context("Adding to known filters"); | 159 enter_context("Adding to known filters"); |
| 157 knownFilter.assign(filter->mText, filter.get()); | 160 if (text != filter->mText) |
| 161 knownFilters[filter->mText] = filter.get(); |
| 162 else |
| 163 // This is a hack: we looked up the entry using text but create it using |
| 164 // filter->mText. This works because both are equal at this point. However, |
| 165 // text refers to a temporary buffer which will go away. |
| 166 knownFilter.assign(filter->mText, filter.get()); |
| 158 exit_context(); | 167 exit_context(); |
| 159 | 168 |
| 160 return filter.release(); | 169 return filter.release(); |
| 161 } | 170 } |
| OLD | NEW |