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

Unified 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.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « compiled/filter/RegExpFilter.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: compiled/filter/RegExpFilter.cpp
===================================================================
--- a/compiled/filter/RegExpFilter.cpp
+++ b/compiled/filter/RegExpFilter.cpp
@@ -10,17 +10,19 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <cctype>
#include <climits>
+#include <cstdio>
#include <emscripten.h>
#include "RegExpFilter.h"
#include "../StringScanner.h"
#include "../StringMap.h"
namespace
@@ -337,21 +339,36 @@ void RegExpFilter::ParseSitekeys(const S
{
if (scanner.position() > start)
AddSitekey(DependentString(sitekeys, start, scanner.position() - start));
start = scanner.position() + 1;
}
}
}
-void RegExpFilter::InitJSTypes()
+void RegExpFilter::GenerateCustomBindings()
{
- EM_ASM(exports.RegExpFilter.typeMap = {};);
+ printf("exports.RegExpFilter.typeMap = {\n");
+
+ OwnedString type;
+ char type_cstr[256];
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.
- EM_ASM_ARGS(exports.RegExpFilter.typeMap[readString($0).replace("-", "_").toUpperCase()] = $1, &(it->first), it->second);
+ {
+ type = it->first;
+ for (int i = 0; i < type.length(); i++)
+ {
+ if (type[i] == '-')
+ type_cstr[i] = '_';
+ else
+ type_cstr[i] = toupper(type[i]);
+ }
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
+ type_cstr[type.length()] = 0;
+ printf(" %s: %i,\n", type_cstr, it->second);
+ }
+ printf("};\n");
}
RegExpFilter::DomainMap* RegExpFilter::GetDomains() const
{
if (!mData.DomainsParsingDone())
{
ParseDomains(mData.GetDomainsSource(mText), u'|');
mData.SetDomainsParsingDone();
« 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