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 |