Chromium Code Reviews| 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..33faaa57f4e4e3473a2ed3e2e784ee02b7f9a697 100644 |
| --- a/tools/json_schema_compiler/util.cc |
| +++ b/tools/json_schema_compiler/util.cc |
| @@ -9,73 +9,45 @@ |
| 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) { |
|
not at google - send to devlin
2012/02/05 23:42:12
fix line length
calamity
2012/02/06 11:51:18
Done.
|
| + 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::CreateBooleanValue(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) { |
|
not at google - send to devlin
2012/02/05 23:42:12
line length
|
| + out->Append(static_cast<Value*>(from->DeepCopy())); |
| } |
| } // namespace api_util |