[email protected] | 716c016 | 2013-12-13 20:36:53 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
[email protected] | faceb0f | 2012-04-12 17:07:19 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
[email protected] | 716c016 | 2013-12-13 20:36:53 | [diff] [blame] | 5 | #include "components/url_matcher/url_matcher_helpers.h" |
[email protected] | faceb0f | 2012-04-12 17:07:19 | [diff] [blame] | 6 | |
avi | 5dd91f8 | 2015-12-25 22:30:46 | [diff] [blame] | 7 | #include <stddef.h> |
8 | |||||
[email protected] | faceb0f | 2012-04-12 17:07:19 | [diff] [blame] | 9 | #include "base/values.h" |
10 | |||||
[email protected] | 716c016 | 2013-12-13 20:36:53 | [diff] [blame] | 11 | namespace url_matcher { |
[email protected] | 63f1a9e | 2012-05-09 12:51:00 | [diff] [blame] | 12 | namespace url_matcher_helpers { |
[email protected] | faceb0f | 2012-04-12 17:07:19 | [diff] [blame] | 13 | |
14 | // Converts a ValueList |value| of strings into a vector. Returns true if | ||||
15 | // successful. | ||||
16 | bool GetAsStringVector(const base::Value* value, | ||||
17 | std::vector<std::string>* out) { | ||||
Ivan Kotenkov | 75b1c3a | 2017-10-24 14:47:24 | [diff] [blame] | 18 | const base::ListValue* value_as_list = nullptr; |
[email protected] | faceb0f | 2012-04-12 17:07:19 | [diff] [blame] | 19 | if (!value->GetAsList(&value_as_list)) |
20 | return false; | ||||
21 | |||||
22 | size_t number_types = value_as_list->GetSize(); | ||||
23 | for (size_t i = 0; i < number_types; ++i) { | ||||
24 | std::string item; | ||||
25 | if (!value_as_list->GetString(i, &item)) | ||||
26 | return false; | ||||
27 | out->push_back(item); | ||||
28 | } | ||||
29 | return true; | ||||
30 | } | ||||
31 | |||||
[email protected] | 63f1a9e | 2012-05-09 12:51:00 | [diff] [blame] | 32 | } // namespace url_matcher_helpers |
[email protected] | 716c016 | 2013-12-13 20:36:53 | [diff] [blame] | 33 | } // namespace url_matcher |