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

Unified Diff: tools/json_schema_compiler/model.py

Issue 273323002: Convert snakecase enum names to camelcase when stringified. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: final changes Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/json_schema_compiler/idl_schema.py ('k') | tools/json_schema_compiler/model_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/json_schema_compiler/model.py
diff --git a/tools/json_schema_compiler/model.py b/tools/json_schema_compiler/model.py
index 967e9abec0041ef9d2d7c7de6378d7abbd7ee1e3..ed8a2ec404edef066279720ad422c3ee7a6c4a43 100644
--- a/tools/json_schema_compiler/model.py
+++ b/tools/json_schema_compiler/model.py
@@ -190,7 +190,7 @@ class Type(object):
elif 'enum' in json and json_type == 'string':
self.property_type = PropertyType.ENUM
self.enum_values = [EnumValue(value) for value in json['enum']]
- self.cpp_omit_enum_type = 'cpp_omit_enum_type' in json
+ self.cpp_enum_prefix_override = json.get('cpp_enum_prefix_override', None)
elif json_type == 'any':
self.property_type = PropertyType.ANY
elif json_type == 'binary':
@@ -410,6 +410,9 @@ class EnumValue(object):
self.name = json
self.description = None
+ def CamelName(self):
+ return CamelName(self.name)
+
class _Enum(object):
"""Superclass for enum types with a "name" field, setting up repr/eq/ne.
Enums need to do this so that equality/non-equality work over pickling.
@@ -484,6 +487,19 @@ def UnixName(name):
return ''.join(unix_name)
+@memoize
+def CamelName(snake):
+ ''' Converts a snake_cased_string to a camelCasedOne. '''
+ pieces = snake.split('_')
+ camel = []
+ for i, piece in enumerate(pieces):
+ if i == 0:
+ camel.append(piece)
+ else:
+ camel.append(piece.capitalize())
+ return ''.join(camel)
+
+
def _StripNamespace(name, namespace):
if name.startswith(namespace.name + '.'):
return name[len(namespace.name + '.'):]
« no previous file with comments | « tools/json_schema_compiler/idl_schema.py ('k') | tools/json_schema_compiler/model_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698