OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import code | 5 import code |
6 import cpp_util | 6 import cpp_util |
7 from model import Platforms | 7 from model import Platforms |
8 from schema_util import CapitalizeFirstLetter | 8 from schema_util import CapitalizeFirstLetter |
9 from schema_util import JsFunctionNameToClassName | 9 from schema_util import JsFunctionNameToClassName |
10 | 10 |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 class _SchemasHGenerator(object): | 202 class _SchemasHGenerator(object): |
203 """Generates a code.Code object for the generated schemas .h file""" | 203 """Generates a code.Code object for the generated schemas .h file""" |
204 def __init__(self, cpp_bundle): | 204 def __init__(self, cpp_bundle): |
205 self._bundle = cpp_bundle | 205 self._bundle = cpp_bundle |
206 | 206 |
207 def Generate(self, namespace): | 207 def Generate(self, namespace): |
208 c = code.Code() | 208 c = code.Code() |
209 c.Append('#include <map>') | 209 c.Append('#include <map>') |
210 c.Append('#include <string>') | 210 c.Append('#include <string>') |
211 c.Append(); | 211 c.Append(); |
212 c.Append('#include "base/string_piece.h"') | 212 c.Append('#include "base/strings/string_piece.h"') |
213 c.Append() | 213 c.Append() |
214 c.Concat(cpp_util.OpenNamespace(self._bundle._cpp_namespace)) | 214 c.Concat(cpp_util.OpenNamespace(self._bundle._cpp_namespace)) |
215 c.Append() | 215 c.Append() |
216 c.Append('class GeneratedSchemas {') | 216 c.Append('class GeneratedSchemas {') |
217 c.Sblock(' public:') | 217 c.Sblock(' public:') |
218 c.Append('// Puts all API schemas in |schemas|.') | 218 c.Append('// Puts all API schemas in |schemas|.') |
219 c.Append('static void Get(' | 219 c.Append('static void Get(' |
220 'std::map<std::string, base::StringPiece>* schemas);') | 220 'std::map<std::string, base::StringPiece>* schemas);') |
221 c.Eblock('};'); | 221 c.Eblock('};'); |
222 c.Append() | 222 c.Append() |
(...skipping 25 matching lines...) Expand all Loading... |
248 separators=(',', ':')) | 248 separators=(',', ':')) |
249 # Escape all double-quotes and backslashes. For this to output a valid | 249 # Escape all double-quotes and backslashes. For this to output a valid |
250 # JSON C string, we need to escape \ and ". | 250 # JSON C string, we need to escape \ and ". |
251 json_content = json_content.replace('\\', '\\\\').replace('"', '\\"') | 251 json_content = json_content.replace('\\', '\\\\').replace('"', '\\"') |
252 c.Append('(*schemas)["%s"] = "%s";' % (namespace.name, json_content)) | 252 c.Append('(*schemas)["%s"] = "%s";' % (namespace.name, json_content)) |
253 c.Eblock('}') | 253 c.Eblock('}') |
254 c.Append() | 254 c.Append() |
255 c.Concat(cpp_util.CloseNamespace(self._bundle._cpp_namespace)) | 255 c.Concat(cpp_util.CloseNamespace(self._bundle._cpp_namespace)) |
256 c.Append() | 256 c.Append() |
257 return c | 257 return c |
OLD | NEW |