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

Side by Side Diff: compiled/filter/RegExpFilter.cpp

Issue 29398655: Issue 5062 - [emscripten] Allow generation of custom bindings code (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Patch Set: Improved initialization code Created March 30, 2017, 12:58 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « compiled/filter/RegExpFilter.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 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 <cctype>
18 #include <climits> 19 #include <climits>
20 #include <cstdio>
19 21
20 #include <emscripten.h> 22 #include <emscripten.h>
21 23
22 #include "RegExpFilter.h" 24 #include "RegExpFilter.h"
23 #include "../StringScanner.h" 25 #include "../StringScanner.h"
24 #include "../StringMap.h" 26 #include "../StringMap.h"
25 27
26 namespace 28 namespace
27 { 29 {
28 enum 30 enum
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 done = scanner.done(); 337 done = scanner.done();
336 if (scanner.next() == u'|') 338 if (scanner.next() == u'|')
337 { 339 {
338 if (scanner.position() > start) 340 if (scanner.position() > start)
339 AddSitekey(DependentString(sitekeys, start, scanner.position() - start)) ; 341 AddSitekey(DependentString(sitekeys, start, scanner.position() - start)) ;
340 start = scanner.position() + 1; 342 start = scanner.position() + 1;
341 } 343 }
342 } 344 }
343 } 345 }
344 346
345 void RegExpFilter::InitJSTypes() 347 void RegExpFilter::GenerateCustomBindings()
346 { 348 {
347 EM_ASM(exports.RegExpFilter.typeMap = {};); 349 printf("exports.RegExpFilter.typeMap = {\n");
350
351 OwnedString type;
352 char type_cstr[256];
348 for (auto it = typeMap.begin(); it != typeMap.end(); ++it) 353 for (auto it = typeMap.begin(); it != typeMap.end(); ++it)
hub 2017/03/31 02:57:22 Shouldn't we use a range iterator here (with const
Wladimir Palant 2017/04/04 14:26:01 Done.
349 EM_ASM_ARGS(exports.RegExpFilter.typeMap[readString($0).replace("-", "_").to UpperCase()] = $1, &(it->first), it->second); 354 {
355 type = it->first;
356 for (int i = 0; i < type.length(); i++)
357 {
358 if (type[i] == '-')
359 type_cstr[i] = '_';
360 else
361 type_cstr[i] = toupper(type[i]);
362 }
hub 2017/03/31 02:57:22 Also we don't check that i or type.length() is < 2
Wladimir Palant 2017/04/04 14:26:01 I didn't really want to bother but let's do a prop
363 type_cstr[type.length()] = 0;
364 printf(" %s: %i,\n", type_cstr, it->second);
365 }
366 printf("};\n");
350 } 367 }
351 368
352 RegExpFilter::DomainMap* RegExpFilter::GetDomains() const 369 RegExpFilter::DomainMap* RegExpFilter::GetDomains() const
353 { 370 {
354 if (!mData.DomainsParsingDone()) 371 if (!mData.DomainsParsingDone())
355 { 372 {
356 ParseDomains(mData.GetDomainsSource(mText), u'|'); 373 ParseDomains(mData.GetDomainsSource(mText), u'|');
357 mData.SetDomainsParsingDone(); 374 mData.SetDomainsParsingDone();
358 } 375 }
359 return ActiveFilter::GetDomains(); 376 return ActiveFilter::GetDomains();
(...skipping 20 matching lines...) Expand all
380 return false; 397 return false;
381 } 398 }
382 399
383 if (!mData.RegExpParsingDone()) 400 if (!mData.RegExpParsingDone())
384 { 401 {
385 const OwnedString pattern(mData.GetRegExpSource(mText)); 402 const OwnedString pattern(mData.GetRegExpSource(mText));
386 mData.SetRegExp(GenerateRegExp(RegExpFromSource(pattern), mData.mMatchCase)) ; 403 mData.SetRegExp(GenerateRegExp(RegExpFromSource(pattern), mData.mMatchCase)) ;
387 } 404 }
388 return EM_ASM_INT(return regexps.test($0, $1), mData.mRegexpId, &location); 405 return EM_ASM_INT(return regexps.test($0, $1), mData.mRegexpId, &location);
389 } 406 }
OLDNEW
« no previous file with comments | « compiled/filter/RegExpFilter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld