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 |
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 "CommentFilter.h" | 18 #include "CommentFilter.h" |
19 | 19 |
20 CommentFilter::CommentFilter(const String& text) | 20 CommentFilter::CommentFilter(const String& text) |
21 : Filter(classType, text) | 21 : Filter(classType, text) |
22 { | 22 { |
| 23 if (text[0] == u'!') // this is unlikely to be false at that point |
| 24 { |
| 25 bool foundColon = false; |
| 26 String::size_type beginParam = 0; |
| 27 String::size_type endParam = 0; |
| 28 String::size_type beginValue = 0; |
| 29 for (String::size_type i = 1; i < mText.length(); i++) |
| 30 { |
| 31 switch (mText[i]) |
| 32 { |
| 33 case ' ': |
| 34 case '\t': |
| 35 if (beginParam > 0 && !foundColon) |
| 36 { |
| 37 endParam = i - 1; |
| 38 } |
| 39 break; |
| 40 case ':': |
| 41 foundColon = true; |
| 42 break; |
| 43 default: |
| 44 if (foundColon) |
| 45 { |
| 46 beginValue = i; |
| 47 } |
| 48 else |
| 49 { |
| 50 if (beginParam == 0) |
| 51 beginParam = i; |
| 52 } |
| 53 break; |
| 54 } |
| 55 if (beginValue > 0) |
| 56 break; |
| 57 } |
| 58 if (beginValue > 0) |
| 59 { |
| 60 mParam = DependentString(mText, beginParam, endParam - beginParam); |
| 61 mParam.toLower(); |
| 62 mValue = DependentString(mText, beginValue, |
| 63 mText.length() - 1 - beginValue); |
| 64 } |
| 65 } |
23 } | 66 } |
24 | 67 |
25 Filter::Type CommentFilter::Parse(const String& text) | 68 Filter::Type CommentFilter::Parse(const String& text) |
26 { | 69 { |
27 if (text.length() && text[0] == u'!') | 70 if (text.length() && text[0] == u'!') |
28 return Type::COMMENT; | 71 return Type::COMMENT; |
29 else | 72 else |
30 return Type::UNKNOWN; | 73 return Type::UNKNOWN; |
31 } | 74 } |
32 | 75 |
33 CommentFilter* CommentFilter::Create(const String& text) | 76 CommentFilter* CommentFilter::Create(const String& text) |
34 { | 77 { |
35 Type type = Parse(text); | 78 Type type = Parse(text); |
36 if (type == Type::COMMENT) | 79 if (type == Type::COMMENT) |
37 return new CommentFilter(text); | 80 return new CommentFilter(text); |
38 else | 81 else |
39 return nullptr; | 82 return nullptr; |
40 } | 83 } |
OLD | NEW |