| Index: third_party/libaddressinput/chromium/json.cc
|
| diff --git a/third_party/libaddressinput/chromium/util/json.h b/third_party/libaddressinput/chromium/json.cc
|
| similarity index 26%
|
| rename from third_party/libaddressinput/chromium/util/json.h
|
| rename to third_party/libaddressinput/chromium/json.cc
|
| index 43be272d3361cd047be32362140c03e8a16d5652..096f9ae95addf045eec299860204a5dbe87d0500 100644
|
| --- a/third_party/libaddressinput/chromium/util/json.h
|
| +++ b/third_party/libaddressinput/chromium/json.cc
|
| @@ -1,41 +1,66 @@
|
| // 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.
|
| -//
|
| -// This class provides the same interface as ../src/cpp/src/util/json.h but with
|
| -// a Chromium-specific JSON parser. This is because it didn't make much sense to
|
| -// have 2 JSON parsers in Chrome's code base, and the standalone library opted
|
| -// to use rapidjson instead of jsoncpp. See the other file for an explanation of
|
| -// what this class does.
|
|
|
| -#ifndef THIRD_PARTY_LIBADDRESSINPUT_CHROMIUM_UTIL_JSON_H_
|
| -#define THIRD_PARTY_LIBADDRESSINPUT_CHROMIUM_UTIL_JSON_H_
|
| -
|
| -#include <string>
|
| +#include "cpp/src/util/json.h"
|
|
|
| #include "base/basictypes.h"
|
| +#include "base/json/json_reader.h"
|
| +#include "base/logging.h"
|
| #include "base/memory/scoped_ptr.h"
|
| #include "base/values.h"
|
|
|
| namespace i18n {
|
| namespace addressinput {
|
|
|
| -class Json {
|
| +namespace {
|
| +
|
| +class ChromeJson : public Json {
|
| public:
|
| - Json();
|
| - ~Json();
|
| + ChromeJson() {}
|
| +
|
| + virtual ~ChromeJson() {}
|
| +
|
| + virtual bool 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 ParseObject(const std::string& json);
|
| - bool HasStringValueForKey(const std::string& key) const;
|
| - std::string GetStringValueForKey(const std::string& key) const;
|
| + virtual bool HasStringValueForKey(const std::string& key) const {
|
| + base::Value* val = NULL;
|
| + dict_->GetWithoutPathExpansion(key, &val);
|
| + return val && val->IsType(base::Value::TYPE_STRING);
|
| + }
|
| +
|
| + virtual std::string GetStringValueForKey(const std::string& key) const {
|
| + std::string result;
|
| + dict_->GetStringWithoutPathExpansion(key, &result);
|
| + return result;
|
| + }
|
|
|
| private:
|
| scoped_ptr<base::DictionaryValue> dict_;
|
|
|
| - DISALLOW_COPY_AND_ASSIGN(Json);
|
| + DISALLOW_COPY_AND_ASSIGN(ChromeJson);
|
| };
|
|
|
| +} // namespace
|
| +
|
| +Json::~Json() {}
|
| +
|
| +// static
|
| +Json* Json::Build() {
|
| + return new ChromeJson;
|
| +}
|
| +
|
| +Json::Json() {}
|
| +
|
| } // namespace addressinput
|
| } // namespace i18n
|
| -
|
| -#endif // THIRD_PARTY_LIBADDRESSINPUT_CHROMIUM_UTIL_JSON_H_
|
|
|