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

Unified Diff: tools/json_schema_compiler/util.cc

Issue 9114036: Code generation for extensions api (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: windows path fix Created 8 years, 11 months 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 | « tools/json_schema_compiler/util.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/json_schema_compiler/util.cc
diff --git a/tools/json_schema_compiler/util.cc b/tools/json_schema_compiler/util.cc
new file mode 100644
index 0000000000000000000000000000000000000000..38e6b30674e75bb39bdae1d90314390fb1d32d94
--- /dev/null
+++ b/tools/json_schema_compiler/util.cc
@@ -0,0 +1,82 @@
+// Copyright (c) 2012 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 "tools/json_schema_compiler/util.h"
+
+#include "base/values.h"
+
+namespace json_schema_compiler {
+namespace util {
+
+bool GetStrings(
+ const base::DictionaryValue& from,
+ const std::string& name,
+ std::vector<std::string>* out) {
+ base::ListValue* list = NULL;
+ if (!from.GetListWithoutPathExpansion(name, &list))
+ return false;
+
+ std::string string;
+ for (size_t i = 0; i < list->GetSize(); ++i) {
+ if (!list->GetString(i, &string))
+ return false;
+ out->push_back(string);
+ }
+
+ return true;
+}
+
+bool GetOptionalStrings(
+ const base::DictionaryValue& from,
+ const std::string& name,
+ scoped_ptr<std::vector<std::string> >* out) {
+ base::ListValue* list = NULL;
+ {
+ base::Value* maybe_list = NULL;
+ // Since |name| is optional, its absence is acceptable. However, anything
+ // other than a ListValue is not.
+ if (!from.GetWithoutPathExpansion(name, &maybe_list))
+ return true;
+ if (!maybe_list->IsType(base::Value::TYPE_LIST))
+ return false;
+ list = static_cast<base::ListValue*>(maybe_list);
+ }
+
+ out->reset(new std::vector<std::string>());
+ std::string string;
+ for (size_t i = 0; i < list->GetSize(); ++i) {
+ if (!list->GetString(i, &string)) {
+ out->reset();
+ return false;
+ }
+ (*out)->push_back(string);
+ }
+
+ return true;
+}
+
+void SetStrings(
+ const std::vector<std::string>& from,
+ const std::string& name,
+ base::DictionaryValue* out) {
+ base::ListValue* list = new base::ListValue();
+ out->SetWithoutPathExpansion(name, list);
+ for (std::vector<std::string>::const_iterator it = from.begin();
+ it != from.end(); ++it) {
+ list->Append(base::Value::CreateStringValue(*it));
+ }
+}
+
+void SetOptionalStrings(
+ const scoped_ptr<std::vector<std::string> >& from,
+ const std::string& name,
+ base::DictionaryValue* out) {
+ if (!from.get())
+ return;
+
+ SetStrings(*from, name, out);
+}
+
+} // namespace api_util
+} // namespace extensions
« no previous file with comments | « tools/json_schema_compiler/util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698