OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "third_party/libaddressinput/src/cpp/src/util/json.h" | 5 #include "third_party/libaddressinput/src/cpp/src/util/json.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
| 8 #include <memory> |
8 | 9 |
9 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
10 #include "base/logging.h" | 11 #include "base/logging.h" |
11 #include "base/macros.h" | 12 #include "base/macros.h" |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 | 15 |
16 namespace i18n { | 16 namespace i18n { |
17 namespace addressinput { | 17 namespace addressinput { |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 // Returns |json| parsed into a JSON dictionary. Sets |parser_error| to true if | 21 // Returns |json| parsed into a JSON dictionary. Sets |parser_error| to true if |
22 // parsing failed. | 22 // parsing failed. |
23 ::scoped_ptr<const base::DictionaryValue> Parse(const std::string& json, | 23 ::std::unique_ptr<const base::DictionaryValue> Parse(const std::string& json, |
24 bool* parser_error) { | 24 bool* parser_error) { |
25 DCHECK(parser_error); | 25 DCHECK(parser_error); |
26 ::scoped_ptr<const base::DictionaryValue> result; | 26 ::std::unique_ptr<const base::DictionaryValue> result; |
27 | 27 |
28 // |json| is converted to a |c_str()| here because rapidjson and other parts | 28 // |json| is converted to a |c_str()| here because rapidjson and other parts |
29 // of the standalone library use char* rather than std::string. | 29 // of the standalone library use char* rather than std::string. |
30 ::scoped_ptr<const base::Value> parsed(base::JSONReader::Read(json.c_str())); | 30 ::std::unique_ptr<const base::Value> parsed( |
| 31 base::JSONReader::Read(json.c_str())); |
31 *parser_error = !parsed || !parsed->IsType(base::Value::TYPE_DICTIONARY); | 32 *parser_error = !parsed || !parsed->IsType(base::Value::TYPE_DICTIONARY); |
32 | 33 |
33 if (*parser_error) | 34 if (*parser_error) |
34 result.reset(new base::DictionaryValue); | 35 result.reset(new base::DictionaryValue); |
35 else | 36 else |
36 result.reset(static_cast<const base::DictionaryValue*>(parsed.release())); | 37 result.reset(static_cast<const base::DictionaryValue*>(parsed.release())); |
37 | 38 |
38 return result; | 39 return result; |
39 } | 40 } |
40 | 41 |
(...skipping 26 matching lines...) Expand all Loading... |
67 } | 68 } |
68 | 69 |
69 bool GetStringValueForKey(const std::string& key, std::string* value) const { | 70 bool GetStringValueForKey(const std::string& key, std::string* value) const { |
70 return dict_.GetStringWithoutPathExpansion(key, value); | 71 return dict_.GetStringWithoutPathExpansion(key, value); |
71 } | 72 } |
72 | 73 |
73 private: | 74 private: |
74 explicit JsonImpl(const base::DictionaryValue& dict) | 75 explicit JsonImpl(const base::DictionaryValue& dict) |
75 : parser_error_(false), dict_(dict) {} | 76 : parser_error_(false), dict_(dict) {} |
76 | 77 |
77 const ::scoped_ptr<const base::DictionaryValue> owned_; | 78 const ::std::unique_ptr<const base::DictionaryValue> owned_; |
78 bool parser_error_; | 79 bool parser_error_; |
79 const base::DictionaryValue& dict_; | 80 const base::DictionaryValue& dict_; |
80 std::vector<const Json*> sub_dicts_; | 81 std::vector<const Json*> sub_dicts_; |
81 | 82 |
82 DISALLOW_COPY_AND_ASSIGN(JsonImpl); | 83 DISALLOW_COPY_AND_ASSIGN(JsonImpl); |
83 }; | 84 }; |
84 | 85 |
85 Json::Json() {} | 86 Json::Json() {} |
86 | 87 |
87 Json::~Json() {} | 88 Json::~Json() {} |
(...skipping 12 matching lines...) Expand all Loading... |
100 | 101 |
101 bool Json::GetStringValueForKey(const std::string& key, | 102 bool Json::GetStringValueForKey(const std::string& key, |
102 std::string* value) const { | 103 std::string* value) const { |
103 return impl_->GetStringValueForKey(key, value); | 104 return impl_->GetStringValueForKey(key, value); |
104 } | 105 } |
105 | 106 |
106 Json::Json(JsonImpl* impl) : impl_(impl) {} | 107 Json::Json(JsonImpl* impl) : impl_(impl) {} |
107 | 108 |
108 } // namespace addressinput | 109 } // namespace addressinput |
109 } // namespace i18n | 110 } // namespace i18n |
OLD | NEW |