Sanitize /* */ inside .proto file comment
Otherwise ends up as a nested C comment, which does not compile.
diff --git a/generator/nanopb_generator.py b/generator/nanopb_generator.py
index f4b8a22..cf0642a 100755
--- a/generator/nanopb_generator.py
+++ b/generator/nanopb_generator.py
@@ -368,6 +368,13 @@
'''Get comments for a member of enum or message.'''
return self.get_comments((ProtoElement.FIELD, index), leading_indent = True)
+ def format_comment(self, comment):
+ '''Put comment inside /* */ and sanitize comment contents'''
+ comment = comment.strip()
+ comment = comment.replace('/*', '/ *')
+ comment = comment.replace('*/', '* /')
+ return "/* %s */" % comment
+
def get_comments(self, member_path = (), leading_indent = False):
'''Get leading & trailing comments for a protobuf element.
@@ -388,10 +395,10 @@
if comment.leading_comments:
leading_comment = " " if leading_indent else ""
- leading_comment += "/* %s */" % comment.leading_comments.strip()
+ leading_comment += self.format_comment(comment.leading_comments)
if comment.trailing_comments:
- trailing_comment = "/* %s */" % comment.trailing_comments.strip()
+ trailing_comment = self.format_comment(comment.trailing_comments)
return leading_comment, trailing_comment