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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tools/json_schema_compiler/idl_schema.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 from code import Code 5 from code import Code
6 from model import PropertyType 6 from model import PropertyType
7 import cpp_util 7 import cpp_util
8 import schema_util 8 import schema_util
9 import util_cc_helper 9 import util_cc_helper
10 10
(...skipping 872 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 classname = cpp_util.Classname(schema_util.StripNamespace(type_.name)) 883 classname = cpp_util.Classname(schema_util.StripNamespace(type_.name))
884 884
885 if cpp_namespace is not None: 885 if cpp_namespace is not None:
886 c.Append('// static') 886 c.Append('// static')
887 maybe_namespace = '' if cpp_namespace is None else '%s::' % cpp_namespace 887 maybe_namespace = '' if cpp_namespace is None else '%s::' % cpp_namespace
888 888
889 c.Sblock('std::string %sToString(%s enum_param) {' % 889 c.Sblock('std::string %sToString(%s enum_param) {' %
890 (maybe_namespace, classname)) 890 (maybe_namespace, classname))
891 c.Sblock('switch (enum_param) {') 891 c.Sblock('switch (enum_param) {')
892 for enum_value in self._type_helper.FollowRef(type_).enum_values: 892 for enum_value in self._type_helper.FollowRef(type_).enum_values:
893 name = enum_value.name
894 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.
895 # Convert to camel case.
896 snake = name
897 camel = ""
898 i = 0
899 while i < len(snake):
900 if snake[i] == "_" and (i + 1) < len(snake):
901 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.
902 i = i + 2
903 else:
904 camel += snake[i]
905 i = i + 1
906 name = camel
893 (c.Append('case %s: ' % self._type_helper.GetEnumValue(type_, enum_value)) 907 (c.Append('case %s: ' % self._type_helper.GetEnumValue(type_, enum_value))
894 .Append(' return "%s";' % enum_value.name)) 908 .Append(' return "%s";' % name))
895 (c.Append('case %s:' % self._type_helper.GetEnumNoneValue(type_)) 909 (c.Append('case %s:' % self._type_helper.GetEnumNoneValue(type_))
896 .Append(' return "";') 910 .Append(' return "";')
897 .Eblock('}') 911 .Eblock('}')
898 .Append('NOTREACHED();') 912 .Append('NOTREACHED();')
899 .Append('return "";') 913 .Append('return "";')
900 .Eblock('}') 914 .Eblock('}')
901 ) 915 )
902 return c 916 return c
903 917
904 def _GenerateEnumFromString(self, cpp_namespace, type_): 918 def _GenerateEnumFromString(self, cpp_namespace, type_):
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1010 if self._generate_error_messages: 1024 if self._generate_error_messages:
1011 params = list(params) + ['base::string16* error'] 1025 params = list(params) + ['base::string16* error']
1012 return ', '.join(str(p) for p in params) 1026 return ', '.join(str(p) for p in params)
1013 1027
1014 def _GenerateArgs(self, args): 1028 def _GenerateArgs(self, args):
1015 """Builds the argument list for a function, given an array of arguments. 1029 """Builds the argument list for a function, given an array of arguments.
1016 """ 1030 """
1017 if self._generate_error_messages: 1031 if self._generate_error_messages:
1018 args = list(args) + ['error'] 1032 args = list(args) + ['error']
1019 return ', '.join(str(a) for a in args) 1033 return ', '.join(str(a) for a in args)
OLDNEW
« 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