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

Unified Diff: tools/json_schema_compiler/util.cc

Issue 9309044: Supporting more APIs with json_schema_compiler (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: support for choices Created 8 years, 10 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
Index: tools/json_schema_compiler/util.cc
diff --git a/tools/json_schema_compiler/util.cc b/tools/json_schema_compiler/util.cc
index 38e6b30674e75bb39bdae1d90314390fb1d32d94..b0e98f64477c3fe840ec7ea682a1b1cc42c0b45e 100644
--- a/tools/json_schema_compiler/util.cc
+++ b/tools/json_schema_compiler/util.cc
@@ -9,73 +9,47 @@
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;
+bool GetItemFromList(const ListValue& from, int index, int* out) {
+ return from.GetInteger(index, out);
+}
- std::string string;
- for (size_t i = 0; i < list->GetSize(); ++i) {
- if (!list->GetString(i, &string))
- return false;
- out->push_back(string);
- }
+bool GetItemFromList(const ListValue& from, int index, bool* out) {
+ return from.GetBoolean(index, out);
+}
- return true;
+bool GetItemFromList(const ListValue& from, int index, double* out) {
+ return from.GetDouble(index, out);
}
-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);
- }
+bool GetItemFromList(const ListValue& from, int index, std::string* out) {
+ return from.GetString(index, out);
+}
- 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);
+bool GetItemFromList(const ListValue& from, int index,
+ linked_ptr<base::DictionaryValue>* out) {
+ DictionaryValue* dict = NULL;
+ if (!from.GetDictionary(index, &dict)) {
+ return false;
}
-
+ *out = linked_ptr<DictionaryValue>(dict->DeepCopy());
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 AddItemToList(const int from, base::ListValue* out) {
+ out->Append(base::Value::CreateIntegerValue(from));
}
-
-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);
+void AddItemToList(const bool from, base::ListValue* out) {
+ out->Append(base::Value::CreateBooleanValue(from));
+}
+void AddItemToList(const double from, base::ListValue* out) {
+ out->Append(base::Value::CreateDoubleValue(from));
+}
+void AddItemToList(const std::string& from, base::ListValue* out) {
+ out->Append(base::Value::CreateStringValue(from));
+}
+void AddItemToList(const linked_ptr<base::DictionaryValue> from,
+ base::ListValue* out) {
+ out->Append(static_cast<Value*>(from->DeepCopy()));
}
} // namespace api_util

Powered by Google App Engine
This is Rietveld 408576698