Skip to content

Commit

Permalink
Small indentation and naming fixes to enum_to_string functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
PetteriAimonen committed Nov 22, 2016
1 parent ad6d660 commit 3a01eea
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions generator/nanopb_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,21 +208,21 @@ def __str__(self):
result += '\n#define %s %s' % (self.value_longnames[i], x[0])

if self.options.enum_to_string:
result += '\nconst char *%s_Name(%s v);\n' % (self.names, self.names)
result += '\nconst char *%s_name(%s v);\n' % (self.names, self.names)

return result

def enum_definition(self):
def enum_to_string_definition(self):
if not self.options.enum_to_string:
return ""

result = 'const char *%s_Name(%s v) {\n' % (self.names, self.names)
result = 'const char *%s_name(%s v) {\n' % (self.names, self.names)
result += ' switch (v) {\n'

for ((enumname, _), strname) in zip(self.values, self.value_longnames):
# Strip off the leading type name from the string value.
strval = str(strname)[len(str(self.names)) + 1:]
result += ' case %s: return "%s";\n' % (enumname, strval)
result += ' case %s: return "%s";\n' % (enumname, strval)

result += ' }\n'
result += ' return "unknown";\n'
Expand Down Expand Up @@ -1242,7 +1242,7 @@ def generate_source(self, headername, options):
yield ext.extension_def() + '\n'

for enum in self.enums:
yield enum.enum_definition() + '\n'
yield enum.enum_to_string_definition() + '\n'

# Add checks for numeric limits
if self.messages:
Expand Down

0 comments on commit 3a01eea

Please sign in to comment.