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 |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..583801ee3db055fe6411c2e9cdf793b49422e906 |
| --- /dev/null |
| +++ b/tools/json_schema_compiler/util.cc |
| @@ -0,0 +1,94 @@ |
| +// 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 extensions { |
| +namespace api_util { |
| + |
| +bool GetStrings( |
| + const base::DictionaryValue& from, |
| + const std::string& name, |
| + std::vector<std::string>* out) { |
| + base::ListValue* list = NULL; |
| + //TODO(calamity): need to check is list? |
|
not at google - send to devlin
2012/01/12 06:01:05
nah, not unnecessary here.
calamity
2012/01/16 04:01:06
Removed.
|
| + 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; |
| + 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); |
|
not at google - send to devlin
2012/01/12 06:01:05
explain why you're doing this.
calamity
2012/01/16 04:01:06
Done.
|
| + } |
| + |
| + 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; |
| + |
| + 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)); |
| + } |
|
not at google - send to devlin
2012/01/12 06:01:05
all of this can be
SetStrings(*from, name, out);
calamity
2012/01/12 22:59:20
Done.
|
| +} |
| + |
| +template<class T> |
| +bool GetTypes( |
| + const base::DictionaryValue& from, |
| + const std::string& name, |
| + std::vector<T>* out) { |
| + |
|
not at google - send to devlin
2012/01/12 06:01:05
..?
you probably want to remove this method
calamity
2012/01/12 22:59:20
Done.
|
| +} |
| + |
| +} // namespace api_util |
| +} // namespace extensions |