| 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 namespace { | 9 namespace { |
| 10 | 10 |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 | 160 |
| 161 void PatternList::SetFromValue(const Value& v, Err* err) { | 161 void PatternList::SetFromValue(const Value& v, Err* err) { |
| 162 patterns_.clear(); | 162 patterns_.clear(); |
| 163 | 163 |
| 164 if (v.type() != Value::LIST) { | 164 if (v.type() != Value::LIST) { |
| 165 *err = Err(v.origin(), "This value must be a list."); | 165 *err = Err(v.origin(), "This value must be a list."); |
| 166 return; | 166 return; |
| 167 } | 167 } |
| 168 | 168 |
| 169 const std::vector<Value>& list = v.list_value(); | 169 const std::vector<Value>& list = v.list_value(); |
| 170 for (size_t i = 0; i < list.size(); i++) { | 170 for (const auto& elem : list) { |
| 171 if (!list[i].VerifyTypeIs(Value::STRING, err)) | 171 if (!elem.VerifyTypeIs(Value::STRING, err)) |
| 172 return; | 172 return; |
| 173 patterns_.push_back(Pattern(list[i].string_value())); | 173 patterns_.push_back(Pattern(elem.string_value())); |
| 174 } | 174 } |
| 175 } | 175 } |
| 176 | 176 |
| 177 bool PatternList::MatchesString(const std::string& s) const { | 177 bool PatternList::MatchesString(const std::string& s) const { |
| 178 for (size_t i = 0; i < patterns_.size(); i++) { | 178 for (const auto& pattern: patterns_) { |
| 179 if (patterns_[i].MatchesString(s)) | 179 if (pattern.MatchesString(s)) |
| 180 return true; | 180 return true; |
| 181 } | 181 } |
| 182 return false; | 182 return false; |
| 183 } | 183 } |
| 184 | 184 |
| 185 bool PatternList::MatchesValue(const Value& v) const { | 185 bool PatternList::MatchesValue(const Value& v) const { |
| 186 if (v.type() == Value::STRING) | 186 if (v.type() == Value::STRING) |
| 187 return MatchesString(v.string_value()); | 187 return MatchesString(v.string_value()); |
| 188 return false; | 188 return false; |
| 189 } | 189 } |
| OLD | NEW |