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

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: simplify gyp 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
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

Powered by Google App Engine
This is Rietveld 408576698