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

Unified Diff: tools/json_schema_compiler/cc_generator.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
« no previous file with comments | « no previous file | tools/json_schema_compiler/idl_schema.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/json_schema_compiler/cc_generator.py
diff --git a/tools/json_schema_compiler/cc_generator.py b/tools/json_schema_compiler/cc_generator.py
index aefae686cd245335494a69c6c71803664a4c8ad5..f0ed3da115662a50f79e9b97ceb296016ef08c65 100644
--- a/tools/json_schema_compiler/cc_generator.py
+++ b/tools/json_schema_compiler/cc_generator.py
@@ -890,8 +890,22 @@ class _Generator(object):
(maybe_namespace, classname))
c.Sblock('switch (enum_param) {')
for enum_value in self._type_helper.FollowRef(type_).enum_values:
+ name = enum_value.name
+ if 'camel_case_enum_to_string' in self._namespace.compiler_options:
not at google - send to devlin 2014/05/13 20:18:22 you might want to move this camel-casing logic her
David Tseng 2014/05/13 23:16:14 Done.
+ # Convert to camel case.
+ snake = name
+ camel = ""
+ i = 0
+ while i < len(snake):
+ if snake[i] == "_" and (i + 1) < len(snake):
+ camel += snake[i + 1].upper()
not at google - send to devlin 2014/05/13 20:18:22 += on strings is expensive because it creates a ne
David Tseng 2014/05/13 23:16:14 Done.
+ i = i + 2
+ else:
+ camel += snake[i]
+ i = i + 1
+ name = camel
(c.Append('case %s: ' % self._type_helper.GetEnumValue(type_, enum_value))
- .Append(' return "%s";' % enum_value.name))
+ .Append(' return "%s";' % name))
(c.Append('case %s:' % self._type_helper.GetEnumNoneValue(type_))
.Append(' return "";')
.Eblock('}')
« no previous file with comments | « no previous file | tools/json_schema_compiler/idl_schema.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698