| 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/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 | 10 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 | 62 |
| 63 bool PopulateItem(const base::Value& from, | 63 bool PopulateItem(const base::Value& from, |
| 64 std::string* out, | 64 std::string* out, |
| 65 base::string16* error) { | 65 base::string16* error) { |
| 66 if (!from.GetAsString(out)) | 66 if (!from.GetAsString(out)) |
| 67 return ReportError(from, base::Value::Type::STRING, error); | 67 return ReportError(from, base::Value::Type::STRING, error); |
| 68 return true; | 68 return true; |
| 69 } | 69 } |
| 70 | 70 |
| 71 bool PopulateItem(const base::Value& from, std::vector<char>* out) { | 71 bool PopulateItem(const base::Value& from, std::vector<char>* out) { |
| 72 const base::BinaryValue* binary = nullptr; | 72 const base::Value* binary = nullptr; |
| 73 if (!from.GetAsBinary(&binary)) | 73 if (!from.GetAsBinary(&binary)) |
| 74 return false; | 74 return false; |
| 75 out->assign(binary->GetBuffer(), binary->GetBuffer() + binary->GetSize()); | 75 out->assign(binary->GetBuffer(), binary->GetBuffer() + binary->GetSize()); |
| 76 return true; | 76 return true; |
| 77 } | 77 } |
| 78 | 78 |
| 79 bool PopulateItem(const base::Value& from, | 79 bool PopulateItem(const base::Value& from, |
| 80 std::vector<char>* out, | 80 std::vector<char>* out, |
| 81 base::string16* error) { | 81 base::string16* error) { |
| 82 const base::BinaryValue* binary = nullptr; | 82 const base::Value* binary = nullptr; |
| 83 if (!from.GetAsBinary(&binary)) | 83 if (!from.GetAsBinary(&binary)) |
| 84 return ReportError(from, base::Value::Type::BINARY, error); | 84 return ReportError(from, base::Value::Type::BINARY, error); |
| 85 out->assign(binary->GetBuffer(), binary->GetBuffer() + binary->GetSize()); | 85 out->assign(binary->GetBuffer(), binary->GetBuffer() + binary->GetSize()); |
| 86 return true; | 86 return true; |
| 87 } | 87 } |
| 88 | 88 |
| 89 bool PopulateItem(const base::Value& from, std::unique_ptr<base::Value>* out) { | 89 bool PopulateItem(const base::Value& from, std::unique_ptr<base::Value>* out) { |
| 90 *out = from.CreateDeepCopy(); | 90 *out = from.CreateDeepCopy(); |
| 91 return true; | 91 return true; |
| 92 } | 92 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 | 127 |
| 128 void AddItemToList(const double from, base::ListValue* out) { | 128 void AddItemToList(const double from, base::ListValue* out) { |
| 129 out->AppendDouble(from); | 129 out->AppendDouble(from); |
| 130 } | 130 } |
| 131 | 131 |
| 132 void AddItemToList(const std::string& from, base::ListValue* out) { | 132 void AddItemToList(const std::string& from, base::ListValue* out) { |
| 133 out->AppendString(from); | 133 out->AppendString(from); |
| 134 } | 134 } |
| 135 | 135 |
| 136 void AddItemToList(const std::vector<char>& from, base::ListValue* out) { | 136 void AddItemToList(const std::vector<char>& from, base::ListValue* out) { |
| 137 out->Append( | 137 out->Append(base::Value::CreateWithCopiedBuffer(from.data(), from.size())); |
| 138 base::BinaryValue::CreateWithCopiedBuffer(from.data(), from.size())); | |
| 139 } | 138 } |
| 140 | 139 |
| 141 void AddItemToList(const std::unique_ptr<base::Value>& from, | 140 void AddItemToList(const std::unique_ptr<base::Value>& from, |
| 142 base::ListValue* out) { | 141 base::ListValue* out) { |
| 143 out->Append(from->CreateDeepCopy()); | 142 out->Append(from->CreateDeepCopy()); |
| 144 } | 143 } |
| 145 | 144 |
| 146 void AddItemToList(const std::unique_ptr<base::DictionaryValue>& from, | 145 void AddItemToList(const std::unique_ptr<base::DictionaryValue>& from, |
| 147 base::ListValue* out) { | 146 base::ListValue* out) { |
| 148 out->Append(from->CreateDeepCopy()); | 147 out->Append(from->CreateDeepCopy()); |
| 149 } | 148 } |
| 150 | 149 |
| 151 } // namespace util | 150 } // namespace util |
| 152 } // namespace json_schema_compiler | 151 } // namespace json_schema_compiler |
| OLD | NEW |