Chromium Code Reviews| Index: third_party/libaddressinput/chromium/util/json.cc |
| diff --git a/third_party/libaddressinput/chromium/util/json.cc b/third_party/libaddressinput/chromium/util/json.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..996c585c52d52bc6f6ca73c771c248165cd3e95a |
| --- /dev/null |
| +++ b/third_party/libaddressinput/chromium/util/json.cc |
| @@ -0,0 +1,50 @@ |
| +// Copyright 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/json/json_reader.h" |
| +#include "base/logging.h" |
| +#include "util/json.h" |
| + |
| +namespace i18n { |
| +namespace addressinput { |
| + |
| +Json::Json() {} |
| +Json::~Json() {} |
| + |
| +bool Json::ParseObject(const std::string& json) { |
| + dict_.reset(); |
| + |
| + // |json| is converted to a |c_str()| here because rapidjson and other parts |
| + // of the standalone library use char* rather than std::string. |
| + scoped_ptr<base::Value> parsed(base::JSONReader::Read(json.c_str())); |
| + if (parsed && parsed->IsType(base::Value::TYPE_DICTIONARY)) |
| + dict_.reset(static_cast<base::DictionaryValue*>(parsed.release())); |
| + |
| + return !!dict_; |
| +} |
| + |
| +bool Json::HasStringValueForKey(const std::string& key) const { |
| + const base::Value* val = NULL; |
| + |
| + if (dict_) |
|
please use gerrit instead
2013/11/20 00:07:58
Simpler:
DCHECK(dict_);
dict_->GetWithoutPath
Dan Beam
2013/11/20 00:58:45
scoped_ptr::operator->() has a DCHECK() so i'll ju
|
| + dict_->GetWithoutPathExpansion(key, &val); |
| + else |
| + NOTREACHED(); |
| + |
| + return val && val->IsType(base::Value::TYPE_STRING); |
| +} |
| + |
| +std::string Json::GetStringValueForKey(const std::string& key) const { |
| + std::string result; |
| + |
| + if (dict_) |
|
please use gerrit instead
2013/11/20 00:07:58
Ditto:
DCHECK(dict_);
dict_->GetStringWithout
Dan Beam
2013/11/20 00:58:45
Done.
|
| + dict_->GetStringWithoutPathExpansion(key, &result); |
| + else |
| + NOTREACHED(); |
| + |
| + return result; |
| +} |
| + |
| +} // namespace addressinput |
| +} // namespace i18n |