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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_SUBSTRING_SET_MATCHER_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_SUBSTRING_SET_MATCHER_H_
7 #pragma once
8
9 #include <map>
10 #include <set>
11 #include <string>
12 #include <vector>
13
14 #include "base/basictypes.h"
15 #include "base/memory/linked_ptr.h"
16
17 namespace extensions {
18
19 // An individual pattern of the SubstringSetMatcher. A pattern consists of
20 // a string (interpreted as individual char8 characters) and an identifier.
21 // The identifier has the purpose to identify all patterns that were contained
22 // 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.
23 class SubstringPattern {
24 public:
25 typedef int ID;
26
27 SubstringPattern(const std::string& pattern, ID id);
28 SubstringPattern(const SubstringPattern& other);
29 SubstringPattern();
30 ~SubstringPattern();
31 SubstringPattern& operator=(const SubstringPattern& other);
32 bool operator==(const SubstringPattern& other) const;
33 bool operator!=(const SubstringPattern& other) const;
34 bool operator<(const SubstringPattern& other) const;
35
36 const std::string& pattern() const { return pattern_; }
37 ID id() const { return id_; }
38
39 private:
40 std::string pattern_;
41 ID id_;
42 };
43
44
45 // Class that store a set of string patterns and can find for a string S,
46 // which string patterns occur in S.
47 class SubstringSetMatcher {
48 public:
49 SubstringSetMatcher();
50 ~SubstringSetMatcher();
51
52 // Registers list of patterns. The same pattern cannot be registered twice.
53 void RegisterPatterns(const std::vector<SubstringPattern>& patterns);
54 void UnregisterPatterns(const std::vector<SubstringPattern>& patterns);
55 void RegisterAndUnregisterPatterns(
56 const std::vector<SubstringPattern>& to_register,
57 const std::vector<SubstringPattern>& to_unregister);
58 bool Match(const std::string& text,
59 std::set<SubstringPattern::ID>* matches) const;
60 void Clear();
61
62 private:
63 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.
64
65 DISALLOW_COPY_AND_ASSIGN(SubstringSetMatcher);
66 };
67
68 } // namespace extensions
69
70 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_SUBSTRING_SET_MATCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698