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 23 matching lines...) Expand all Loading... |
34 ActiveFilter::DomainMap* ActiveFilter::GetDomains() const | 34 ActiveFilter::DomainMap* ActiveFilter::GetDomains() const |
35 { | 35 { |
36 return mDomains.get(); | 36 return mDomains.get(); |
37 } | 37 } |
38 | 38 |
39 ActiveFilter::SitekeySet* ActiveFilter::GetSitekeys() const | 39 ActiveFilter::SitekeySet* ActiveFilter::GetSitekeys() const |
40 { | 40 { |
41 return mSitekeys.get(); | 41 return mSitekeys.get(); |
42 } | 42 } |
43 | 43 |
44 void ActiveFilter::ParseDomains(const String& domains, | 44 ParsedDomains ActiveFilter::ParseDomainsInternal(const String& domains, |
45 String::value_type separator) const | 45 String::value_type separator, bool ignoreTrailingDot) |
46 { | 46 { |
47 DomainMap::size_type count = 2; | 47 DomainMap::size_type count = 2; |
48 for (String::size_type i = 0; i < domains.length(); i++) | 48 for (String::size_type i = 0; i < domains.length(); i++) |
49 if (domains[i] == separator) | 49 if (domains[i] == separator) |
50 count++; | 50 count++; |
51 | 51 |
52 mDomains.reset(new DomainMap(count)); | |
53 annotate_address(mDomains.get(), "DomainMap"); | |
54 | |
55 StringScanner scanner(domains, 0, separator); | 52 StringScanner scanner(domains, 0, separator); |
56 String::size_type start = 0; | 53 String::size_type start = 0; |
57 bool reverse = false; | 54 bool reverse = false; |
58 bool hasIncludes = false; | 55 ParsedDomains parsed; |
| 56 parsed.hasIncludes = false; |
| 57 parsed.domains.reserve(count); |
59 bool done = scanner.done(); | 58 bool done = scanner.done(); |
60 while (!done) | 59 while (!done) |
61 { | 60 { |
62 done = scanner.done(); | 61 done = scanner.done(); |
63 String::value_type currChar = scanner.next(); | 62 String::value_type currChar = scanner.next(); |
64 if (currChar == u'~' && scanner.position() == start) | 63 if (currChar == u'~' && scanner.position() == start) |
65 { | 64 { |
66 start++; | 65 start++; |
67 reverse = true; | 66 reverse = true; |
68 } | 67 } |
69 else if (currChar == separator) | 68 else if (currChar == separator) |
70 { | 69 { |
71 String::size_type len = scanner.position() - start; | 70 String::size_type len = scanner.position() - start; |
72 if (len > 0 && mIgnoreTrailingDot && domains[start + len - 1] == '.') | 71 if (len > 0 && ignoreTrailingDot && domains[start + len - 1] == '.') |
73 len--; | 72 len--; |
74 if (len > 0) | 73 if (len > 0) |
75 { | 74 { |
76 enter_context("Adding to ActiveFilter.mDomains"); | 75 enter_context("Adding to ParsedDomains"); |
77 (*mDomains)[DependentString(domains, start, len)] = !reverse; | 76 parsed.domains.push_back( |
| 77 ParsedDomains::Domain({start, len, reverse})); |
78 exit_context(); | 78 exit_context(); |
79 | 79 |
80 if (!reverse) | 80 if (!reverse) |
81 hasIncludes = true; | 81 parsed.hasIncludes = true; |
82 } | 82 } |
| 83 else |
| 84 parsed.hasEmpty = true; |
83 start = scanner.position() + 1; | 85 start = scanner.position() + 1; |
84 reverse = false; | 86 reverse = false; |
85 } | 87 } |
86 } | 88 } |
87 enter_context("Adding to ActiveFilter.mDomains"); | 89 return parsed; |
88 (*mDomains)[DEFAULT_DOMAIN] = !hasIncludes; | 90 } |
| 91 |
| 92 void ActiveFilter::FillDomains(const String& domains, const ParsedDomains& parse
d) const |
| 93 { |
| 94 mDomains.reset(new DomainMap(parsed.domains.size())); |
| 95 annotate_address(mDomains.get(), "DomainMap"); |
| 96 |
| 97 for (auto d : parsed.domains) |
| 98 { |
| 99 enter_context("Adding to DomainMap"); |
| 100 (*mDomains)[DependentString(domains, d.pos, d.len)] = !d.reverse; |
| 101 exit_context(); |
| 102 } |
| 103 enter_context("Adding to DomainMap"); |
| 104 (*mDomains)[DEFAULT_DOMAIN] = !parsed.hasIncludes; |
89 exit_context(); | 105 exit_context(); |
90 } | 106 } |
91 | 107 |
| 108 void ActiveFilter::ParseDomains(const String& domains, |
| 109 String::value_type separator, bool ignoreTrailingDot) const |
| 110 { |
| 111 ParsedDomains parsed = ParseDomainsInternal(domains, |
| 112 separator, ignoreTrailingDot); |
| 113 FillDomains(domains, parsed); |
| 114 } |
| 115 |
92 void ActiveFilter::AddSitekey(const String& sitekey) const | 116 void ActiveFilter::AddSitekey(const String& sitekey) const |
93 { | 117 { |
94 if (!mSitekeys) | 118 if (!mSitekeys) |
95 { | 119 { |
96 mSitekeys.reset(new SitekeySet()); | 120 mSitekeys.reset(new SitekeySet()); |
97 annotate_address(mSitekeys.get(), "SitekeySet"); | 121 annotate_address(mSitekeys.get(), "SitekeySet"); |
98 } | 122 } |
99 | 123 |
100 enter_context("Adding to ActiveFilter.mSitekeys"); | 124 enter_context("Adding to ActiveFilter.mSitekeys"); |
101 mSitekeys->insert(sitekey); | 125 mSitekeys->insert(sitekey); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 result.append(u'\n'); | 211 result.append(u'\n'); |
188 } | 212 } |
189 if (mLastHit) | 213 if (mLastHit) |
190 { | 214 { |
191 result.append(u"lastHit="_str); | 215 result.append(u"lastHit="_str); |
192 result.append(mLastHit); | 216 result.append(mLastHit); |
193 result.append(u'\n'); | 217 result.append(u'\n'); |
194 } | 218 } |
195 return result; | 219 return result; |
196 } | 220 } |
OLD | NEW |