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

Unified Diff: compiled/RegExpFilter.h

Issue 29333474: Issue 4125 - [emscripten] Convert filter classes to C++ (Closed)
Patch Set: Rebased, addressed comments, changed StringMap::find() return value Created Feb. 18, 2016, 4:02 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
Index: compiled/RegExpFilter.h
===================================================================
new file mode 100644
--- /dev/null
+++ b/compiled/RegExpFilter.h
@@ -0,0 +1,94 @@
+#pragma once
+
+#include "Filter.h"
+#include "ActiveFilter.h"
+
+enum class TrippleState {YES, NO, ANY};
+
+struct RegExpFilterData
+{
+ mutable String::size_type mPatternStart;
+ union
+ {
+ mutable int mRegexpId;
+ mutable String::size_type mPatternEnd;
+ };
+ mutable String::size_type mDomainsStart;
+ mutable String::size_type mDomainsEnd;
+ mutable String::size_type mSitekeysStart;
+ mutable String::size_type mSitekeysEnd;
+ int mContentType;
+ bool mMatchCase;
+ TrippleState mThirdParty;
+ TrippleState mCollapse;
+
+ bool RegExpParsingDone() const
+ {
+ return mPatternStart == String::npos;
+ }
+
+ void SetRegExp(int regexpId) const
+ {
+ mRegexpId = regexpId;
+ mPatternStart = String::npos;
+ }
+
+ bool HasRegExp() const
+ {
+ return RegExpParsingDone() && mRegexpId;
+ }
+
+ const DependentString GetRegExpSource(const String& text) const
+ {
+ return DependentString(text, mPatternStart, mPatternEnd - mPatternStart);
+ }
+
+ bool DomainsParsingDone() const
+ {
+ return mDomainsStart == String::npos;
+ }
+
+ void SetDomainsParsingDone() const
+ {
+ mDomainsStart = String::npos;
+ }
+
+ const DependentString GetDomainsSource(const String& text) const
+ {
+ return DependentString(text, mDomainsStart, mDomainsEnd - mDomainsStart);
+ }
+
+ bool SitekeyParsingDone() const
+ {
+ return mSitekeysStart == String::npos;
+ }
+
+ void SetSitekeysParsingDone() const
+ {
+ mSitekeysStart = String::npos;
+ }
+
+ const DependentString GetSitekeysSource(const String& text) const
+ {
+ return DependentString(text, mSitekeysStart, mSitekeysEnd - mSitekeysStart);
+ }
+};
+
+class RegExpFilter : public ActiveFilter, protected RegExpFilterData
+{
+private:
+ void ParseSitekeys(const String& sitekeys) const;
+
+protected:
+ DomainMap* GetDomains() const override;
+ SitekeySet* GetSitekeys() const override;
+public:
+ RegExpFilter(const String& text, const RegExpFilterData& data);
+ ~RegExpFilter();
+ static Type Parse(DependentString& text, DependentString& error,
+ RegExpFilterData& data);
+ EMSCRIPTEN_KEEPALIVE static void InitJSTypes();
+ static OwnedString RegExpFromSource(const String& source);
+ EMSCRIPTEN_KEEPALIVE bool Matches(const String& location, int typeMask,
+ DependentString& docDomain, bool thirdParty, const String& sitekey) const;
+};

Powered by Google App Engine
This is Rietveld