From 672674186eea4ccfa0a0a33f79412fd0ca62b45f Mon Sep 17 00:00:00 2001 From: Yann Roth Date: Wed, 31 Aug 2022 13:53:46 +0200 Subject: [PATCH] match expression on complete words only --- proto2cpp.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/proto2cpp.py b/proto2cpp.py index 96506aa..1bf9c83 100644 --- a/proto2cpp.py +++ b/proto2cpp.py @@ -138,7 +138,7 @@ def parseFile(self, inputFile): # Search for "enum" and if one is found before comment, # start changing all semicolons (";") to commas (","). - matchEnum = re.search("enum", line) + matchEnum = re.search(r'\benum\b', line) if matchEnum is not None and (matchComment is None or matchEnum.start() < matchComment.start()): isEnum = True # Search again for semicolon if we have detected an enum, and replace semicolon with comma. @@ -155,7 +155,7 @@ def parseFile(self, inputFile): # be a proper C(++) struct and Doxygen will handle it correctly. line = line[:matchClosingBrace.start()] + "};" + line[matchClosingBrace.end():] # Search for 'message' and replace it with 'struct' unless 'message' is behind a comment. - matchMsg = re.search("message", line) + matchMsg = re.search(r'\bmessage\b', line) if matchMsg is not None and (matchComment is None or matchMsg.start() < matchComment.start()): output = "struct" + line[:matchMsg.start()] + line[matchMsg.end():] theOutput += output