summaryrefslogtreecommitdiffstats
path: root/tools/json_schema_compiler/model.py
diff options
context:
space:
mode:
authordtseng@chromium.org <dtseng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-15 08:04:00 +0000
committerdtseng@chromium.org <dtseng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-15 08:04:00 +0000
commitfad5da26587e70751a16b3495ac2a3e136e97f04 (patch)
tree62bd4f618fbbe79f01e5fa96004b95f29500ea2d /tools/json_schema_compiler/model.py
parent29bf8f4e29de59621652339a1a39bbf7bfb0d6b1 (diff)
downloadchromium_src-fad5da26587e70751a16b3495ac2a3e136e97f04.zip
chromium_src-fad5da26587e70751a16b3495ac2a3e136e97f04.tar.gz
chromium_src-fad5da26587e70751a16b3495ac2a3e136e97f04.tar.bz2
Convert snakecase enum names to camelcase when stringified.
This cl adds a new attribute to the namespace node "camel_case_enum_to_string". This addresses the need for: - native enums to use snake case (e.g. LOAD_COMPLETE) - stringified values (used in js) to be camel cased (e.g. loadComplete). BUG=309681 Review URL: https://codereview.chromium.org/273323002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@270623 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/json_schema_compiler/model.py')
-rw-r--r--tools/json_schema_compiler/model.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/tools/json_schema_compiler/model.py b/tools/json_schema_compiler/model.py
index 967e9ab..ed8a2ec 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 + '.'):]