| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, | |
| 3 * Copyright (C) 2006-present eyeo GmbH | |
| 4 * | |
| 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 | |
| 7 * published by the Free Software Foundation. | |
| 8 * | |
| 9 * Adblock Plus is distributed in the hope that it will be useful, | |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 12 * GNU General Public License for more details. | |
| 13 * | |
| 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/>. | |
| 16 */ | |
| 17 | |
| 18 #include <cwctype> | |
| 19 #include <regex> | |
| 20 | |
| 21 #include "String.h" | |
| 22 #include "library.h" | |
| 23 | |
| 24 | |
| 25 char16_t CharToLower(char16_t charCode) | |
| 26 { | |
| 27 return std::towlower(charCode); | |
| 28 } | |
| 29 | |
| 30 | |
| 31 void JSNotifyFilterChange(FilterNotifier::Topic topic, Filter& filter, | |
| 32 Subscription* subscription, unsigned int position) | |
| 33 { | |
|
sergei
2018/01/11 08:54:07
stubs are OK for present.
| |
| 34 } | |
| 35 | |
| 36 void JSNotifySubscriptionChange(FilterNotifier::Topic topic, | |
| 37 Subscription& subscription) | |
| 38 { | |
| 39 } | |
| 40 | |
| 41 namespace { | |
| 42 std::vector<std::unique_ptr<std::wregex>> mRegexPool; | |
|
sergei
2018/01/11 08:54:06
BTW, this code is not thread safe, we should be ve
hub
2018/01/11 20:41:27
Done.
| |
| 43 | |
| 44 std::wstring from_string(const String& str) | |
|
sergei
2018/01/11 08:54:07
What about putting this method into some utils.h (
hub
2018/01/11 20:41:27
Done.
| |
| 45 { | |
| 46 std::wstring s; | |
| 47 for (String::size_type idx = 0; idx < str.length(); idx++) | |
| 48 s.push_back(str[idx]); | |
|
sergei
2018/01/11 08:54:07
std::string has the constructor accepting a pointe
hub
2018/01/11 20:41:27
std::wstring::value_type is a wchar_t which is 32-
sergei
2018/01/12 09:58:12
Acknowledged.
| |
| 49 | |
| 50 return s; | |
| 51 } | |
| 52 } | |
| 53 | |
| 54 int GenerateRegExp(const String& regexp, bool matchCase) | |
| 55 { | |
| 56 auto index = mRegexPool.size(); | |
| 57 auto flags = std::regex_constants::ECMAScript; | |
| 58 if (!matchCase) | |
| 59 flags |= std::regex_constants::icase; | |
| 60 mRegexPool.emplace_back(new std::wregex(from_string(regexp), flags)); | |
| 61 return index; | |
| 62 } | |
| 63 | |
| 64 void DeleteRegExp(int id) | |
| 65 { | |
| 66 if (id < mRegexPool.size()) | |
| 67 mRegexPool[id].reset(); | |
|
sergei
2018/01/11 08:54:07
What about using of std::list and its iterator as
hub
2018/01/11 20:41:27
How do you know if the id is valid? erase() invali
sergei
2018/01/12 09:58:12
IMO there is no necessity in it, as soon as the re
| |
| 68 } | |
| 69 | |
| 70 bool TestRegExp(int id, const String& str) | |
| 71 { | |
| 72 if ((id < mRegexPool.size()) && mRegexPool[id]) | |
| 73 return std::regex_match(from_string(str), *mRegexPool[id]); | |
| 74 | |
| 75 return false; | |
|
sergei
2018/01/11 08:54:07
Could please add an assert here because it should
hub
2018/01/11 20:41:27
Done.
| |
| 76 } | |
| 77 | |
| OLD | NEW |