| 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::Value& from, std::vector<char>* out) { |
| 30 const base::BinaryValue* binary = nullptr; |
| 31 if (!from.GetAsBinary(&binary)) |
| 32 return false; |
| 33 out->assign(binary->GetBuffer(), binary->GetBuffer() + binary->GetSize()); |
| 34 return true; |
| 35 } |
| 36 |
| 28 bool PopulateItem(const base::Value& from, linked_ptr<base::Value>* out) { | 37 bool PopulateItem(const base::Value& from, linked_ptr<base::Value>* out) { |
| 29 *out = make_linked_ptr(from.DeepCopy()); | 38 *out = make_linked_ptr(from.DeepCopy()); |
| 30 return true; | 39 return true; |
| 31 } | 40 } |
| 32 | 41 |
| 33 bool PopulateItem(const base::Value& from, | 42 bool PopulateItem(const base::Value& from, |
| 34 linked_ptr<base::DictionaryValue>* out) { | 43 linked_ptr<base::DictionaryValue>* out) { |
| 35 const base::DictionaryValue* dict = NULL; | 44 const base::DictionaryValue* dict = nullptr; |
| 36 if (!from.GetAsDictionary(&dict)) | 45 if (!from.GetAsDictionary(&dict)) |
| 37 return false; | 46 return false; |
| 38 *out = make_linked_ptr(dict->DeepCopy()); | 47 *out = make_linked_ptr(dict->DeepCopy()); |
| 39 return true; | 48 return true; |
| 40 } | 49 } |
| 41 | 50 |
| 42 void AddItemToList(const int from, base::ListValue* out) { | 51 void AddItemToList(const int from, base::ListValue* out) { |
| 43 out->Append(new base::FundamentalValue(from)); | 52 out->Append(new base::FundamentalValue(from)); |
| 44 } | 53 } |
| 45 | 54 |
| 46 void AddItemToList(const bool from, base::ListValue* out) { | 55 void AddItemToList(const bool from, base::ListValue* out) { |
| 47 out->Append(new base::FundamentalValue(from)); | 56 out->Append(new base::FundamentalValue(from)); |
| 48 } | 57 } |
| 49 | 58 |
| 50 void AddItemToList(const double from, base::ListValue* out) { | 59 void AddItemToList(const double from, base::ListValue* out) { |
| 51 out->Append(new base::FundamentalValue(from)); | 60 out->Append(new base::FundamentalValue(from)); |
| 52 } | 61 } |
| 53 | 62 |
| 54 void AddItemToList(const std::string& from, base::ListValue* out) { | 63 void AddItemToList(const std::string& from, base::ListValue* out) { |
| 55 out->Append(new base::StringValue(from)); | 64 out->Append(new base::StringValue(from)); |
| 56 } | 65 } |
| 57 | 66 |
| 67 void AddItemToList(const std::vector<char>& from, base::ListValue* out) { |
| 68 out->Append(base::BinaryValue::CreateWithCopiedBuffer(vector_as_array(&from), |
| 69 from.size())); |
| 70 } |
| 71 |
| 58 void AddItemToList(const linked_ptr<base::Value>& from, base::ListValue* out) { | 72 void AddItemToList(const linked_ptr<base::Value>& from, base::ListValue* out) { |
| 59 out->Append(from->DeepCopy()); | 73 out->Append(from->DeepCopy()); |
| 60 } | 74 } |
| 61 | 75 |
| 62 void AddItemToList(const linked_ptr<base::DictionaryValue>& from, | 76 void AddItemToList(const linked_ptr<base::DictionaryValue>& from, |
| 63 base::ListValue* out) { | 77 base::ListValue* out) { |
| 64 out->Append(static_cast<base::Value*>(from->DeepCopy())); | 78 out->Append(static_cast<base::Value*>(from->DeepCopy())); |
| 65 } | 79 } |
| 66 | 80 |
| 67 std::string ValueTypeToString(base::Value::Type type) { | 81 std::string ValueTypeToString(base::Value::Type type) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 80 return "binary"; | 94 return "binary"; |
| 81 case base::Value::TYPE_DICTIONARY: | 95 case base::Value::TYPE_DICTIONARY: |
| 82 return "dictionary"; | 96 return "dictionary"; |
| 83 case base::Value::TYPE_LIST: | 97 case base::Value::TYPE_LIST: |
| 84 return "list"; | 98 return "list"; |
| 85 } | 99 } |
| 86 NOTREACHED(); | 100 NOTREACHED(); |
| 87 return ""; | 101 return ""; |
| 88 } | 102 } |
| 89 | 103 |
| 90 } // namespace api_util | 104 } // namespace util |
| 91 } // namespace extensions | 105 } // namespace json_schema_compiler |
| OLD | NEW |