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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « tools/json_schema_compiler/util.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "tools/json_schema_compiler/util.h"
6
7 #include "base/values.h"
8
9 namespace json_schema_compiler {
10 namespace util {
11
12 bool GetStrings(
13 const base::DictionaryValue& from,
14 const std::string& name,
15 std::vector<std::string>* out) {
16 base::ListValue* list = NULL;
17 if (!from.GetListWithoutPathExpansion(name, &list))
18 return false;
19
20 std::string string;
21 for (size_t i = 0; i < list->GetSize(); ++i) {
22 if (!list->GetString(i, &string))
23 return false;
24 out->push_back(string);
25 }
26
27 return true;
28 }
29
30 bool GetOptionalStrings(
31 const base::DictionaryValue& from,
32 const std::string& name,
33 scoped_ptr<std::vector<std::string> >* out) {
34 base::ListValue* list = NULL;
35 {
36 base::Value* maybe_list = NULL;
37 // Since |name| is optional, its absence is acceptable. However, anything
38 // other than a ListValue is not.
39 if (!from.GetWithoutPathExpansion(name, &maybe_list))
40 return true;
41 if (!maybe_list->IsType(base::Value::TYPE_LIST))
42 return false;
43 list = static_cast<base::ListValue*>(maybe_list);
44 }
45
46 out->reset(new std::vector<std::string>());
47 std::string string;
48 for (size_t i = 0; i < list->GetSize(); ++i) {
49 if (!list->GetString(i, &string)) {
50 out->reset();
51 return false;
52 }
53 (*out)->push_back(string);
54 }
55
56 return true;
57 }
58
59 void SetStrings(
60 const std::vector<std::string>& from,
61 const std::string& name,
62 base::DictionaryValue* out) {
63 base::ListValue* list = new base::ListValue();
64 out->SetWithoutPathExpansion(name, list);
65 for (std::vector<std::string>::const_iterator it = from.begin();
66 it != from.end(); ++it) {
67 list->Append(base::Value::CreateStringValue(*it));
68 }
69 }
70
71 void SetOptionalStrings(
72 const scoped_ptr<std::vector<std::string> >& from,
73 const std::string& name,
74 base::DictionaryValue* out) {
75 if (!from.get())
76 return;
77
78 SetStrings(*from, name, out);
79 }
80
81 } // namespace api_util
82 } // namespace extensions
OLDNEW
« 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