OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/json/json_reader.h" | |
6 #include "base/logging.h" | |
7 #include "util/json.h" | |
please use gerrit instead
2013/11/20 00:03:10
1) Place the header that you're implementing at th
Dan Beam
2013/11/20 00:53:48
Done, however we don't (in Chrome code) re-include
| |
8 | |
9 namespace i18n { | |
10 namespace addressinput { | |
11 | |
12 Json::Json() {} | |
13 Json::~Json() {} | |
14 | |
15 bool Json::ParseObject(const std::string& json) { | |
16 dict_.reset(); | |
17 | |
18 // |json| is converted to a |c_str()| here because rapidjson and other parts | |
19 // of the standalone library use char* rather than std::string. | |
20 scoped_ptr<base::Value> parsed(base::JSONReader::Read(json.c_str())); | |
21 if (parsed && parsed->IsType(base::Value::TYPE_DICTIONARY)) | |
22 dict_.reset(static_cast<base::DictionaryValue*>(parsed.release())); | |
23 | |
24 return !!dict_; | |
25 } | |
26 | |
27 bool Json::HasStringValueForKey(const std::string& key) const { | |
28 const base::Value* val = NULL; | |
29 | |
30 if (dict_) | |
31 dict_->GetWithoutPathExpansion(key, &val); | |
32 else | |
33 NOTREACHED(); | |
34 | |
35 return val && val->IsType(base::Value::TYPE_STRING); | |
36 } | |
37 | |
38 std::string Json::GetStringValueForKey(const std::string& key) const { | |
39 std::string result; | |
40 | |
41 if (dict_) | |
42 dict_->GetStringWithoutPathExpansion(key, &result); | |
43 else | |
44 NOTREACHED(); | |
45 | |
46 return result; | |
47 } | |
48 | |
49 } // namespace addressinput | |
50 } // namespace i18n | |
OLD | NEW |