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: Split up String class into two, cleaned up RegExpFilter methods Created Feb. 4, 2016, 7:20 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/InvalidFilter.cpp ('k') | compiled/RegExpFilter.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: compiled/RegExpFilter.h
===================================================================
new file mode 100644
--- /dev/null
+++ b/compiled/RegExpFilter.h
@@ -0,0 +1,98 @@
+#ifndef ADBLOCK_PLUS_REG_EXP_FILTER_H
+#define ADBLOCK_PLUS_REG_EXP_FILTER_H
+
+#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:
+ virtual DomainMap* GetDomains() const;
+ virtual SitekeySet* GetSitekeys() const;
+public:
+ RegExpFilter(const String& text, const RegExpFilterData& data);
+ ~RegExpFilter();
+ static Type Parse(DependentString& text, OwnedString& error,
+ RegExpFilterData& data);
+ EMSCRIPTEN_KEEPALIVE static void InitJSTypes();
+ static OwnedString RegExpFromSource(const String& source);
+ Type GetType() const;
+ EMSCRIPTEN_KEEPALIVE bool Matches(const String& location, int typeMask,
+ DependentString& docDomain, bool thirdParty, const String& sitekey) const;
+};
+
+#endif
« no previous file with comments | « compiled/InvalidFilter.cpp ('k') | compiled/RegExpFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld