OLD | NEW |
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 #include "tools/gn/pattern.h" | 5 #include "tools/gn/pattern.h" |
6 | 6 |
7 #include "tools/gn/value.h" | 7 #include "tools/gn/value.h" |
8 | 8 |
9 const char kPattern_Help[] = | |
10 "Patterns\n" | |
11 " Patterns are VERY limited regular expressions that are used in\n" | |
12 " several places.\n" | |
13 "\n" | |
14 " Patterns must match the entire input string to be counted as a match.\n" | |
15 " In regular expression parlance, there is an implicit \"^...$\"\n" | |
16 " surrounding your input. If you want to match a substring, you need to\n" | |
17 " use wildcards at the beginning and end.\n" | |
18 "\n" | |
19 " There are only two special tokens understood by the pattern matcher.\n" | |
20 " Everything else is a literal.\n" | |
21 "\n" | |
22 " * Matches zero or more of any character. It does not depend on the\n" | |
23 " preceding character (in regular expression parlance it is\n" | |
24 " equivalent to \".*\").\n" | |
25 "\n" | |
26 " \\b Matches a path boundary. This will match the beginning or end of\n" | |
27 " a string, or a slash.\n" | |
28 "\n" | |
29 "Examples\n" | |
30 "\n" | |
31 " \"*asdf*\"\n" | |
32 " Matches a string containing \"asdf\" anywhere.\n" | |
33 "\n" | |
34 " \"asdf\"\n" | |
35 " Matches only the exact string \"asdf\".\n" | |
36 "\n" | |
37 " \"*.cc\"\n" | |
38 " Matches strings ending in the literal \".cc\".\n" | |
39 "\n" | |
40 " \"\\bwin/*\"\n" | |
41 " Matches \"win/foo\" and \"foo/win/bar.cc\" but not \"iwin/foo\".\n"; | |
42 | |
43 namespace { | 9 namespace { |
44 | 10 |
45 void ParsePattern(const std::string& s, std::vector<Pattern::Subrange>* out) { | 11 void ParsePattern(const std::string& s, std::vector<Pattern::Subrange>* out) { |
46 // Set when the last subrange is a literal so we can just append when we | 12 // Set when the last subrange is a literal so we can just append when we |
47 // find another literal. | 13 // find another literal. |
48 Pattern::Subrange* last_literal = NULL; | 14 Pattern::Subrange* last_literal = NULL; |
49 | 15 |
50 for (size_t i = 0; i < s.size(); i++) { | 16 for (size_t i = 0; i < s.size(); i++) { |
51 if (s[i] == '*') { | 17 if (s[i] == '*') { |
52 // Don't allow two **. | 18 // Don't allow two **. |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 return true; | 180 return true; |
215 } | 181 } |
216 return false; | 182 return false; |
217 } | 183 } |
218 | 184 |
219 bool PatternList::MatchesValue(const Value& v) const { | 185 bool PatternList::MatchesValue(const Value& v) const { |
220 if (v.type() == Value::STRING) | 186 if (v.type() == Value::STRING) |
221 return MatchesString(v.string_value()); | 187 return MatchesString(v.string_value()); |
222 return false; | 188 return false; |
223 } | 189 } |
OLD | NEW |