Commit 7c846283 authored by Christoph Jüngling's avatar Christoph Jüngling

Refactoring replacing command

parent 39ae2b33
......@@ -57,8 +57,8 @@ def patch_content(content, declarations):
for line in content.split('\n'):
for decl in declarations:
newline = re.sub(
'\\b' + decl + '\\b', decl, line, flags=re.IGNORECASE)
newline = safe_replace(line, decl)
new_content.append(newline)
if line != newline:
......@@ -68,3 +68,24 @@ def patch_content(content, declarations):
if count > 0:
logger.info('%i lines would have changed', count)
return '\n'.join(new_content)
def safe_replace(line, decl):
'''
Replace only part of the Visual Basic line that is outside literal string and is not a comment.
:param line: Original code line
:type line: String
:param decl: Variable declaration in correct writing anc casing
:type decl: String
'''
# Idea:
# 1. Split string via regex in areas with "..." and without.
# 2. Process only areas without "..."
# 3. Join the parts again
newline = re.sub(
'\\b' + decl + '\\b', decl, line, flags=re.IGNORECASE)
return newline
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment