Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nanopb/nanopb.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>2022-11-23 15:01:05 +0300
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>2022-11-23 15:13:07 +0300
commiteeda15ed4e899cd3d404abf74c1d60e50eb6f790 (patch)
tree1a1039b01a07863ca1cd08e1d5b20a3859d9926a
parentd7b2747d946376ec29886eca2ecc6a4ae1fda4fe (diff)
Sanitize /* */ inside .proto file comment
Otherwise ends up as a nested C comment, which does not compile.
-rwxr-xr-xgenerator/nanopb_generator.py11
1 files changed, 9 insertions, 2 deletions
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 @@ class ProtoElement(object):
'''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 @@ class ProtoElement(object):
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