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

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: Address feedback 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
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..58fe5b9d37b0be59ac942ea238ee1a586b384b76 100644
--- a/tools/json_schema_compiler/model.py
+++ b/tools/json_schema_compiler/model.py
@@ -410,6 +410,10 @@ class EnumValue(object):
self.name = json
self.description = None
+
not at google - send to devlin 2014/05/14 16:18:14 no blank line
David Tseng 2014/05/14 18:11:31 Done.
+ 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.
@@ -483,6 +487,20 @@ def UnixName(name):
unix_name.append(c.lower())
return ''.join(unix_name)
not at google - send to devlin 2014/05/14 16:18:14 extra blank line (the pep8 rule is 2 blank lines
David Tseng 2014/05/14 18:11:31 Done.
+@memoize
+def CamelName(snake):
+ ''' Converts a snake_cased_string to a camelCasedOne. '''
+ camel = []
+ i = 0
+ while i < len(snake):
+ if snake[i] == '_' and (i + 1) < len(snake):
+ camel.append(snake[i + 1].upper())
+ i += 2
+ else:
+ camel.append(snake[i])
+ i += 1
+ return ''.join(camel)
+
def _StripNamespace(name, namespace):
if name.startswith(namespace.name + '.'):

Powered by Google App Engine
This is Rietveld 408576698