Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4875)

Unified Diff: chrome/browser/extensions/api/declarative/substring_set_matcher.h

Issue 9390018: Implementation of a Matching strategy for URLs in the Declarative WebRequest API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/declarative/substring_set_matcher.h
diff --git a/chrome/browser/extensions/api/declarative/substring_set_matcher.h b/chrome/browser/extensions/api/declarative/substring_set_matcher.h
new file mode 100644
index 0000000000000000000000000000000000000000..89ed14f1b2f5ebd081846532a2e29fc13b003f3e
--- /dev/null
+++ b/chrome/browser/extensions/api/declarative/substring_set_matcher.h
@@ -0,0 +1,70 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_SUBSTRING_SET_MATCHER_H_
+#define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_SUBSTRING_SET_MATCHER_H_
+#pragma once
+
+#include <map>
+#include <set>
+#include <string>
+#include <vector>
+
+#include "base/basictypes.h"
+#include "base/memory/linked_ptr.h"
+
+namespace extensions {
+
+// An individual pattern of the SubstringSetMatcher. A pattern consists of
+// a string (interpreted as individual char8 characters) and an identifier.
+// The identifier has the purpose to identify all patterns that were contained
+// in a string in the SubstringSetMatcher.
Matt Perry 2012/02/14 01:38:34 I don't really follow this comment. Could you add
battre 2012/02/14 19:32:21 Done.
+class SubstringPattern {
+ public:
+ typedef int ID;
+
+ SubstringPattern(const std::string& pattern, ID id);
+ SubstringPattern(const SubstringPattern& other);
+ SubstringPattern();
+ ~SubstringPattern();
+ SubstringPattern& operator=(const SubstringPattern& other);
+ bool operator==(const SubstringPattern& other) const;
+ bool operator!=(const SubstringPattern& other) const;
+ bool operator<(const SubstringPattern& other) const;
+
+ const std::string& pattern() const { return pattern_; }
+ ID id() const { return id_; }
+
+ private:
+ std::string pattern_;
+ ID id_;
+};
+
+
+// Class that store a set of string patterns and can find for a string S,
+// which string patterns occur in S.
+class SubstringSetMatcher {
+ public:
+ SubstringSetMatcher();
+ ~SubstringSetMatcher();
+
+ // Registers list of patterns. The same pattern cannot be registered twice.
+ void RegisterPatterns(const std::vector<SubstringPattern>& patterns);
+ void UnregisterPatterns(const std::vector<SubstringPattern>& patterns);
+ void RegisterAndUnregisterPatterns(
+ const std::vector<SubstringPattern>& to_register,
+ const std::vector<SubstringPattern>& to_unregister);
+ bool Match(const std::string& text,
+ std::set<SubstringPattern::ID>* matches) const;
+ void Clear();
+
+ private:
+ std::vector<SubstringPattern> patterns_;
Matt Perry 2012/02/14 01:38:34 If it really stores sets, you should use std::set
battre 2012/02/14 19:32:21 Done.
+
+ DISALLOW_COPY_AND_ASSIGN(SubstringSetMatcher);
+};
+
+} // namespace extensions
+
+#endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_SUBSTRING_SET_MATCHER_H_

Powered by Google App Engine
This is Rietveld 408576698