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

Side by Side Diff: tools/gn/pattern.h

Issue 964203002: tools/gn: Fix errors found by Facebook's flint tool. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix chromium-style plugin errors Created 5 years, 9 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
« no previous file with comments | « tools/gn/parse_tree.h ('k') | tools/gn/scope.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef TOOLS_GN_PATTERN_H_ 5 #ifndef TOOLS_GN_PATTERN_H_
6 #define TOOLS_GN_PATTERN_H_ 6 #define TOOLS_GN_PATTERN_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "tools/gn/value.h" 11 #include "tools/gn/value.h"
12 12
13 class Pattern { 13 class Pattern {
14 public: 14 public:
15 struct Subrange { 15 struct Subrange {
16 enum Type { 16 enum Type {
17 LITERAL, // Matches exactly the contents of the string. 17 LITERAL, // Matches exactly the contents of the string.
18 ANYTHING, // * (zero or more chars). 18 ANYTHING, // * (zero or more chars).
19 PATH_BOUNDARY // '/' or beginning of string. 19 PATH_BOUNDARY // '/' or beginning of string.
20 }; 20 };
21 21
22 Subrange(Type t, const std::string& l = std::string()) 22 explicit Subrange(Type t, const std::string& l = std::string())
23 : type(t), 23 : type(t),
24 literal(l) { 24 literal(l) {
25 } 25 }
26 26
27 // Returns the minimum number of chars that this subrange requires. 27 // Returns the minimum number of chars that this subrange requires.
28 size_t MinSize() const { 28 size_t MinSize() const {
29 switch (type) { 29 switch (type) {
30 case LITERAL: 30 case LITERAL:
31 return literal.size(); 31 return literal.size();
32 case ANYTHING: 32 case ANYTHING:
33 return 0; 33 return 0;
34 case PATH_BOUNDARY: 34 case PATH_BOUNDARY:
35 return 0; // Can match beginning or end of string, which is 0 len. 35 return 0; // Can match beginning or end of string, which is 0 len.
36 default: 36 default:
37 return 0; 37 return 0;
38 } 38 }
39 } 39 }
40 40
41 Type type; 41 Type type;
42 42
43 // When type == LITERAL this is the text to match. 43 // When type == LITERAL this is the text to match.
44 std::string literal; 44 std::string literal;
45 }; 45 };
46 46
47 Pattern(const std::string& s); 47 explicit Pattern(const std::string& s);
48 ~Pattern(); 48 ~Pattern();
49 49
50 // Returns true if the current pattern matches the given string. 50 // Returns true if the current pattern matches the given string.
51 bool MatchesString(const std::string& s) const; 51 bool MatchesString(const std::string& s) const;
52 52
53 private: 53 private:
54 // allow_implicit_path_boundary determines if a path boundary should accept 54 // allow_implicit_path_boundary determines if a path boundary should accept
55 // matches at the beginning or end of the string. 55 // matches at the beginning or end of the string.
56 bool RecursiveMatch(const std::string& s, 56 bool RecursiveMatch(const std::string& s,
57 size_t begin_char, 57 size_t begin_char,
(...skipping 21 matching lines...) Expand all
79 void SetFromValue(const Value& v, Err* err); 79 void SetFromValue(const Value& v, Err* err);
80 80
81 bool MatchesString(const std::string& s) const; 81 bool MatchesString(const std::string& s) const;
82 bool MatchesValue(const Value& v) const; 82 bool MatchesValue(const Value& v) const;
83 83
84 private: 84 private:
85 std::vector<Pattern> patterns_; 85 std::vector<Pattern> patterns_;
86 }; 86 };
87 87
88 #endif // TOOLS_GN_PATTERN_H_ 88 #endif // TOOLS_GN_PATTERN_H_
OLDNEW
« no previous file with comments | « tools/gn/parse_tree.h ('k') | tools/gn/scope.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698