Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Unified Diff: third_party/libaddressinput/chromium/util/json.cc

Issue 68323005: Build libaddressinput in Chrome for requestAutocomplete(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/libaddressinput/chromium/util/json.h ('k') | third_party/libaddressinput/libaddressinput.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..604e1bda13f6e7ff729e39dcdfb059bcb0397072
--- /dev/null
+++ b/third_party/libaddressinput/chromium/util/json.cc
@@ -0,0 +1,41 @@
+// 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 "util/json.h"
+
+#include "base/json/json_reader.h"
+#include "base/logging.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 {
+ base::Value* val = NULL;
+ dict_->GetWithoutPathExpansion(key, &val);
+ return val && val->IsType(base::Value::TYPE_STRING);
+}
+
+std::string Json::GetStringValueForKey(const std::string& key) const {
+ std::string result;
+ dict_->GetStringWithoutPathExpansion(key, &result);
+ return result;
+}
+
+} // namespace addressinput
+} // namespace i18n
« no previous file with comments | « third_party/libaddressinput/chromium/util/json.h ('k') | third_party/libaddressinput/libaddressinput.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698