OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/json_schema_compiler/util.h" | 5 #include "tools/json_schema_compiler/util.h" |
6 | 6 |
| 7 #include "base/stl_util.h" |
7 #include "base/values.h" | 8 #include "base/values.h" |
8 | 9 |
9 namespace json_schema_compiler { | 10 namespace json_schema_compiler { |
10 namespace util { | 11 namespace util { |
11 | 12 |
12 bool PopulateItem(const base::Value& from, int* out) { | 13 bool PopulateItem(const base::Value& from, int* out) { |
13 return from.GetAsInteger(out); | 14 return from.GetAsInteger(out); |
14 } | 15 } |
15 | 16 |
16 bool PopulateItem(const base::Value& from, bool* out) { | 17 bool PopulateItem(const base::Value& from, bool* out) { |
17 return from.GetAsBoolean(out); | 18 return from.GetAsBoolean(out); |
18 } | 19 } |
19 | 20 |
20 bool PopulateItem(const base::Value& from, double* out) { | 21 bool PopulateItem(const base::Value& from, double* out) { |
21 return from.GetAsDouble(out); | 22 return from.GetAsDouble(out); |
22 } | 23 } |
23 | 24 |
24 bool PopulateItem(const base::Value& from, std::string* out) { | 25 bool PopulateItem(const base::Value& from, std::string* out) { |
25 return from.GetAsString(out); | 26 return from.GetAsString(out); |
26 } | 27 } |
27 | 28 |
| 29 bool PopulateItem(const base::ListValue& from, |
| 30 int index, |
| 31 std::vector<char>* out) { |
| 32 const base::BinaryValue* binary = nullptr; |
| 33 if (!from.GetAsBinary(&binary)) |
| 34 return false; |
| 35 out->assign(binary->GetBuffer(), binary->GetBuffer() + binary->GetSize()); |
| 36 return true; |
| 37 } |
| 38 |
28 bool PopulateItem(const base::Value& from, linked_ptr<base::Value>* out) { | 39 bool PopulateItem(const base::Value& from, linked_ptr<base::Value>* out) { |
29 *out = make_linked_ptr(from.DeepCopy()); | 40 *out = make_linked_ptr(from.DeepCopy()); |
30 return true; | 41 return true; |
31 } | 42 } |
32 | 43 |
33 bool PopulateItem(const base::Value& from, | 44 bool PopulateItem(const base::Value& from, |
34 linked_ptr<base::DictionaryValue>* out) { | 45 linked_ptr<base::DictionaryValue>* out) { |
35 const base::DictionaryValue* dict = NULL; | 46 const base::DictionaryValue* dict = nullptr; |
36 if (!from.GetAsDictionary(&dict)) | 47 if (!from.GetAsDictionary(&dict)) |
37 return false; | 48 return false; |
38 *out = make_linked_ptr(dict->DeepCopy()); | 49 *out = make_linked_ptr(dict->DeepCopy()); |
39 return true; | 50 return true; |
40 } | 51 } |
41 | 52 |
42 void AddItemToList(const int from, base::ListValue* out) { | 53 void AddItemToList(const int from, base::ListValue* out) { |
43 out->Append(new base::FundamentalValue(from)); | 54 out->Append(new base::FundamentalValue(from)); |
44 } | 55 } |
45 | 56 |
46 void AddItemToList(const bool from, base::ListValue* out) { | 57 void AddItemToList(const bool from, base::ListValue* out) { |
47 out->Append(new base::FundamentalValue(from)); | 58 out->Append(new base::FundamentalValue(from)); |
48 } | 59 } |
49 | 60 |
50 void AddItemToList(const double from, base::ListValue* out) { | 61 void AddItemToList(const double from, base::ListValue* out) { |
51 out->Append(new base::FundamentalValue(from)); | 62 out->Append(new base::FundamentalValue(from)); |
52 } | 63 } |
53 | 64 |
54 void AddItemToList(const std::string& from, base::ListValue* out) { | 65 void AddItemToList(const std::string& from, base::ListValue* out) { |
55 out->Append(new base::StringValue(from)); | 66 out->Append(new base::StringValue(from)); |
56 } | 67 } |
57 | 68 |
| 69 void AddItemToList(const std::vector<char>& from, base::ListValue* out) { |
| 70 out->Append(base::BinaryValue::CreateWithCopiedBuffer(vector_as_array(&from), |
| 71 from.size())); |
| 72 } |
| 73 |
58 void AddItemToList(const linked_ptr<base::Value>& from, base::ListValue* out) { | 74 void AddItemToList(const linked_ptr<base::Value>& from, base::ListValue* out) { |
59 out->Append(from->DeepCopy()); | 75 out->Append(from->DeepCopy()); |
60 } | 76 } |
61 | 77 |
62 void AddItemToList(const linked_ptr<base::DictionaryValue>& from, | 78 void AddItemToList(const linked_ptr<base::DictionaryValue>& from, |
63 base::ListValue* out) { | 79 base::ListValue* out) { |
64 out->Append(static_cast<base::Value*>(from->DeepCopy())); | 80 out->Append(static_cast<base::Value*>(from->DeepCopy())); |
65 } | 81 } |
66 | 82 |
67 std::string ValueTypeToString(base::Value::Type type) { | 83 std::string ValueTypeToString(base::Value::Type type) { |
(...skipping 12 matching lines...) Expand all Loading... |
80 return "binary"; | 96 return "binary"; |
81 case base::Value::TYPE_DICTIONARY: | 97 case base::Value::TYPE_DICTIONARY: |
82 return "dictionary"; | 98 return "dictionary"; |
83 case base::Value::TYPE_LIST: | 99 case base::Value::TYPE_LIST: |
84 return "list"; | 100 return "list"; |
85 } | 101 } |
86 NOTREACHED(); | 102 NOTREACHED(); |
87 return ""; | 103 return ""; |
88 } | 104 } |
89 | 105 |
90 } // namespace api_util | 106 } // namespace util |
91 } // namespace extensions | 107 } // namespace json_schema_compiler |
OLD | NEW |