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

Delta Between Two Patch Sets: compiled/filter/RegExpFilter.cpp

Issue 29398655: Issue 5062 - [emscripten] Allow generation of custom bindings code (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Left Patch Set: Made the code slightly safer Created April 4, 2017, 2:25 p.m.
Right Patch Set: Rebased Created April 13, 2017, 1:06 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « compiled/filter/RegExpFilter.h ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 <cctype>
19 #include <climits> 19 #include <climits>
20 #include <cstdio> 20 #include <cstdio>
21 #include <stdexcept> 21 #include <string>
22 #include <iterator>
23 22
24 #include <emscripten.h> 23 #include <emscripten.h>
25 24
26 #include "RegExpFilter.h" 25 #include "RegExpFilter.h"
27 #include "../StringScanner.h" 26 #include "../StringScanner.h"
28 #include "../StringMap.h" 27 #include "../StringMap.h"
29 28
30 namespace 29 namespace
31 { 30 {
32 enum 31 enum
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 AddSitekey(DependentString(sitekeys, start, scanner.position() - start)) ; 346 AddSitekey(DependentString(sitekeys, start, scanner.position() - start)) ;
348 start = scanner.position() + 1; 347 start = scanner.position() + 1;
349 } 348 }
350 } 349 }
351 } 350 }
352 351
353 void RegExpFilter::GenerateCustomBindings() 352 void RegExpFilter::GenerateCustomBindings()
354 { 353 {
355 printf("exports.RegExpFilter.typeMap = {\n"); 354 printf("exports.RegExpFilter.typeMap = {\n");
356 355
357 OwnedString type; 356 for (const auto& item : typeMap)
358 char type_cstr[256]; 357 {
359 for (const auto& it : typeMap) 358 std::string type(item.first.length(), '\0');
360 { 359 for (int i = 0; i < item.first.length(); i++)
361 type = it.first; 360 type[i] = (item.first[i] == '-' ? '_' : toupper(item.first[i]));
362 auto len = type.length(); 361 printf(" %s: %i,\n", type.c_str(), item.second);
363 if (len >= std::end(type_cstr) - std::begin(type_cstr))
364 throw std::runtime_error("Value size too large for the buffer");
sergei 2017/04/04 14:49:31 Well, if you touch this code then I would recommen
Wladimir Palant 2017/04/04 15:41:48 Done.
365 for (int i = 0; i < len; i++)
366 {
367 if (type[i] == '-')
368 type_cstr[i] = '_';
369 else
370 type_cstr[i] = toupper(type[i]);
371 }
372 type_cstr[len] = 0;
373 printf(" %s: %i,\n", type_cstr, it.second);
374 } 362 }
375 printf("};\n"); 363 printf("};\n");
376 } 364 }
377 365
378 RegExpFilter::DomainMap* RegExpFilter::GetDomains() const 366 RegExpFilter::DomainMap* RegExpFilter::GetDomains() const
379 { 367 {
380 if (!mData.DomainsParsingDone()) 368 if (!mData.DomainsParsingDone())
381 { 369 {
382 ParseDomains(mData.GetDomainsSource(mText), u'|'); 370 ParseDomains(mData.GetDomainsSource(mText), u'|');
383 mData.SetDomainsParsingDone(); 371 mData.SetDomainsParsingDone();
(...skipping 22 matching lines...) Expand all
406 return false; 394 return false;
407 } 395 }
408 396
409 if (!mData.RegExpParsingDone()) 397 if (!mData.RegExpParsingDone())
410 { 398 {
411 const OwnedString pattern(mData.GetRegExpSource(mText)); 399 const OwnedString pattern(mData.GetRegExpSource(mText));
412 mData.SetRegExp(GenerateRegExp(RegExpFromSource(pattern), mData.mMatchCase)) ; 400 mData.SetRegExp(GenerateRegExp(RegExpFromSource(pattern), mData.mMatchCase)) ;
413 } 401 }
414 return EM_ASM_INT(return regexps.test($0, $1), mData.mRegexpId, &location); 402 return EM_ASM_INT(return regexps.test($0, $1), mData.mRegexpId, &location);
415 } 403 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld