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

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: Cap funciton names 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..5c1247075ba95517cf34e81e6d2460062ad6b513 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/13 23:45:47 only 1 blank line
David Tseng 2014/05/14 02:16:14 Done.
+ def CamelName(self):
+ return SnakeToCamel(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 +488,20 @@ def UnixName(name):
return ''.join(unix_name)
+def SnakeToCamel(snake):
not at google - send to devlin 2014/05/13 23:45:47 could you write some unit tests? see model_test.py
David Tseng 2014/05/14 02:16:14 Done.
+ ''' Converts a snake_cased_string to a camelCasedOne. '''
+ camel = []
+ i = 0
+ while i < len(snake):
+ if snake[i] == "_" and (i + 1) < len(snake):
not at google - send to devlin 2014/05/13 23:45:47 single quotes
David Tseng 2014/05/14 02:16:14 Done.
+ camel.append(snake[i + 1].upper())
+ i = i + 2
not at google - send to devlin 2014/05/13 23:45:47 += 2
David Tseng 2014/05/14 02:16:14 Done.
+ else:
+ camel.append(snake[i])
+ i = i + 1
not at google - send to devlin 2014/05/13 23:45:47 += 1
David Tseng 2014/05/14 02:16:14 Done.
+ return ''.join(camel)
not at google - send to devlin 2014/05/13 23:45:47 the above said, it might be simpler (and more effi
David Tseng 2014/05/14 02:16:14 Sounds like you'd still end up with some kind of l
not at google - send to devlin 2014/05/14 16:18:14 Actually split is likely to be much faster. Iterat
David Tseng 2014/05/14 18:11:31 Thanks; good to know.
+
+
def _StripNamespace(name, namespace):
if name.startswith(namespace.name + '.'):
return name[len(namespace.name + '.'):]

Powered by Google App Engine
This is Rietveld 408576698