| 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/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 | 9 |
| 10 namespace json_schema_compiler { | 10 namespace json_schema_compiler { |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 error->append(base::UTF8ToUTF16("; ")); | 93 error->append(base::UTF8ToUTF16("; ")); |
| 94 } | 94 } |
| 95 error->append(base::UTF8ToUTF16("expected binary, got " + | 95 error->append(base::UTF8ToUTF16("expected binary, got " + |
| 96 ValueTypeToString(from.GetType()))); | 96 ValueTypeToString(from.GetType()))); |
| 97 return false; | 97 return false; |
| 98 } | 98 } |
| 99 out->assign(binary->GetBuffer(), binary->GetBuffer() + binary->GetSize()); | 99 out->assign(binary->GetBuffer(), binary->GetBuffer() + binary->GetSize()); |
| 100 return true; | 100 return true; |
| 101 } | 101 } |
| 102 | 102 |
| 103 bool PopulateItem(const base::Value& from, scoped_ptr<base::Value>* out) { | 103 bool PopulateItem(const base::Value& from, std::unique_ptr<base::Value>* out) { |
| 104 *out = make_scoped_ptr(from.DeepCopy()); | 104 *out = from.CreateDeepCopy(); |
| 105 return true; | 105 return true; |
| 106 } | 106 } |
| 107 | 107 |
| 108 bool PopulateItem(const base::Value& from, | 108 bool PopulateItem(const base::Value& from, |
| 109 scoped_ptr<base::Value>* out, | 109 std::unique_ptr<base::Value>* out, |
| 110 base::string16* error) { | 110 base::string16* error) { |
| 111 *out = make_scoped_ptr(from.DeepCopy()); | 111 *out = from.CreateDeepCopy(); |
| 112 return true; | 112 return true; |
| 113 } | 113 } |
| 114 | 114 |
| 115 bool PopulateItem(const base::Value& from, | 115 bool PopulateItem(const base::Value& from, |
| 116 scoped_ptr<base::DictionaryValue>* out) { | 116 std::unique_ptr<base::DictionaryValue>* out) { |
| 117 const base::DictionaryValue* dict = nullptr; | 117 const base::DictionaryValue* dict = nullptr; |
| 118 if (!from.GetAsDictionary(&dict)) | 118 if (!from.GetAsDictionary(&dict)) |
| 119 return false; | 119 return false; |
| 120 *out = make_scoped_ptr(dict->DeepCopy()); | 120 *out = dict->CreateDeepCopy(); |
| 121 return true; | 121 return true; |
| 122 } | 122 } |
| 123 | 123 |
| 124 bool PopulateItem(const base::Value& from, | 124 bool PopulateItem(const base::Value& from, |
| 125 scoped_ptr<base::DictionaryValue>* out, | 125 std::unique_ptr<base::DictionaryValue>* out, |
| 126 base::string16* error) { | 126 base::string16* error) { |
| 127 const base::DictionaryValue* dict = nullptr; | 127 const base::DictionaryValue* dict = nullptr; |
| 128 if (!from.GetAsDictionary(&dict)) { | 128 if (!from.GetAsDictionary(&dict)) { |
| 129 if (error->length()) { | 129 if (error->length()) { |
| 130 error->append(base::UTF8ToUTF16("; ")); | 130 error->append(base::UTF8ToUTF16("; ")); |
| 131 } | 131 } |
| 132 error->append(base::UTF8ToUTF16("expected dictionary, got " + | 132 error->append(base::UTF8ToUTF16("expected dictionary, got " + |
| 133 ValueTypeToString(from.GetType()))); | 133 ValueTypeToString(from.GetType()))); |
| 134 return false; | 134 return false; |
| 135 } | 135 } |
| 136 *out = make_scoped_ptr(dict->DeepCopy()); | 136 *out = dict->CreateDeepCopy(); |
| 137 return true; | 137 return true; |
| 138 } | 138 } |
| 139 | 139 |
| 140 void AddItemToList(const int from, base::ListValue* out) { | 140 void AddItemToList(const int from, base::ListValue* out) { |
| 141 out->Append(new base::FundamentalValue(from)); | 141 out->Append(new base::FundamentalValue(from)); |
| 142 } | 142 } |
| 143 | 143 |
| 144 void AddItemToList(const bool from, base::ListValue* out) { | 144 void AddItemToList(const bool from, base::ListValue* out) { |
| 145 out->Append(new base::FundamentalValue(from)); | 145 out->Append(new base::FundamentalValue(from)); |
| 146 } | 146 } |
| 147 | 147 |
| 148 void AddItemToList(const double from, base::ListValue* out) { | 148 void AddItemToList(const double from, base::ListValue* out) { |
| 149 out->Append(new base::FundamentalValue(from)); | 149 out->Append(new base::FundamentalValue(from)); |
| 150 } | 150 } |
| 151 | 151 |
| 152 void AddItemToList(const std::string& from, base::ListValue* out) { | 152 void AddItemToList(const std::string& from, base::ListValue* out) { |
| 153 out->Append(new base::StringValue(from)); | 153 out->Append(new base::StringValue(from)); |
| 154 } | 154 } |
| 155 | 155 |
| 156 void AddItemToList(const std::vector<char>& from, base::ListValue* out) { | 156 void AddItemToList(const std::vector<char>& from, base::ListValue* out) { |
| 157 out->Append( | 157 out->Append( |
| 158 base::BinaryValue::CreateWithCopiedBuffer(from.data(), from.size())); | 158 base::BinaryValue::CreateWithCopiedBuffer(from.data(), from.size())); |
| 159 } | 159 } |
| 160 | 160 |
| 161 void AddItemToList(const scoped_ptr<base::Value>& from, base::ListValue* out) { | 161 void AddItemToList(const std::unique_ptr<base::Value>& from, |
| 162 base::ListValue* out) { |
| 162 out->Append(from->DeepCopy()); | 163 out->Append(from->DeepCopy()); |
| 163 } | 164 } |
| 164 | 165 |
| 165 void AddItemToList(const scoped_ptr<base::DictionaryValue>& from, | 166 void AddItemToList(const std::unique_ptr<base::DictionaryValue>& from, |
| 166 base::ListValue* out) { | 167 base::ListValue* out) { |
| 167 out->Append(static_cast<base::Value*>(from->DeepCopy())); | 168 out->Append(static_cast<base::Value*>(from->DeepCopy())); |
| 168 } | 169 } |
| 169 | 170 |
| 170 std::string ValueTypeToString(base::Value::Type type) { | 171 std::string ValueTypeToString(base::Value::Type type) { |
| 171 switch (type) { | 172 switch (type) { |
| 172 case base::Value::TYPE_NULL: | 173 case base::Value::TYPE_NULL: |
| 173 return "null"; | 174 return "null"; |
| 174 case base::Value::TYPE_BOOLEAN: | 175 case base::Value::TYPE_BOOLEAN: |
| 175 return "boolean"; | 176 return "boolean"; |
| 176 case base::Value::TYPE_INTEGER: | 177 case base::Value::TYPE_INTEGER: |
| 177 return "integer"; | 178 return "integer"; |
| 178 case base::Value::TYPE_DOUBLE: | 179 case base::Value::TYPE_DOUBLE: |
| 179 return "number"; | 180 return "number"; |
| 180 case base::Value::TYPE_STRING: | 181 case base::Value::TYPE_STRING: |
| 181 return "string"; | 182 return "string"; |
| 182 case base::Value::TYPE_BINARY: | 183 case base::Value::TYPE_BINARY: |
| 183 return "binary"; | 184 return "binary"; |
| 184 case base::Value::TYPE_DICTIONARY: | 185 case base::Value::TYPE_DICTIONARY: |
| 185 return "dictionary"; | 186 return "dictionary"; |
| 186 case base::Value::TYPE_LIST: | 187 case base::Value::TYPE_LIST: |
| 187 return "list"; | 188 return "list"; |
| 188 } | 189 } |
| 189 NOTREACHED(); | 190 NOTREACHED(); |
| 190 return ""; | 191 return ""; |
| 191 } | 192 } |
| 192 | 193 |
| 193 } // namespace util | 194 } // namespace util |
| 194 } // namespace json_schema_compiler | 195 } // namespace json_schema_compiler |
| OLD | NEW |