|
|
@ -23,6 +23,7 @@ TEMPLATE_VARIABLE_CLOSING_TAG = '___TEMPLATE_VARIABLE_CLOSING_TAG___'
|
|
|
|
TEMPLATE_BRACKET_OPENING_TAG = '___TEMPLATE_BRACKET_OPENING_TAG___'
|
|
|
|
TEMPLATE_BRACKET_OPENING_TAG = '___TEMPLATE_BRACKET_OPENING_TAG___'
|
|
|
|
TEMPLATE_BRACKET_CLOSING_TAG = '___TEMPLATE_BRACKET_CLOSING_TAG___'
|
|
|
|
TEMPLATE_BRACKET_CLOSING_TAG = '___TEMPLATE_BRACKET_CLOSING_TAG___'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def strip_line(single_line):
|
|
|
|
def strip_line(single_line):
|
|
|
|
"""Strips the line and replaces neighbouring whitespaces with single space (except when within quotation marks)."""
|
|
|
|
"""Strips the line and replaces neighbouring whitespaces with single space (except when within quotation marks)."""
|
|
|
|
single_line = single_line.strip()
|
|
|
|
single_line = single_line.strip()
|
|
|
@ -39,6 +40,7 @@ def strip_line(single_line):
|
|
|
|
within_quotes = not within_quotes
|
|
|
|
within_quotes = not within_quotes
|
|
|
|
return '"'.join(parts)
|
|
|
|
return '"'.join(parts)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def count_multi_semicolon(single_line):
|
|
|
|
def count_multi_semicolon(single_line):
|
|
|
|
"""count multi_semicolon (except when within quotation marks)."""
|
|
|
|
"""count multi_semicolon (except when within quotation marks)."""
|
|
|
|
single_line = single_line.strip()
|
|
|
|
single_line = single_line.strip()
|
|
|
@ -56,6 +58,7 @@ def count_multi_semicolon(single_line):
|
|
|
|
within_quotes = not within_quotes
|
|
|
|
within_quotes = not within_quotes
|
|
|
|
return q, c
|
|
|
|
return q, c
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def multi_semicolon(single_line):
|
|
|
|
def multi_semicolon(single_line):
|
|
|
|
"""break multi_semicolon into multiline (except when within quotation marks)."""
|
|
|
|
"""break multi_semicolon into multiline (except when within quotation marks)."""
|
|
|
|
single_line = single_line.strip()
|
|
|
|
single_line = single_line.strip()
|
|
|
@ -72,6 +75,7 @@ def multi_semicolon(single_line):
|
|
|
|
within_quotes = not within_quotes
|
|
|
|
within_quotes = not within_quotes
|
|
|
|
return '"'.join(parts)
|
|
|
|
return '"'.join(parts)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def apply_variable_template_tags(line: str) -> str:
|
|
|
|
def apply_variable_template_tags(line: str) -> str:
|
|
|
|
"""Replaces variable indicators ${ and } with tags, so subsequent formatting is easier."""
|
|
|
|
"""Replaces variable indicators ${ and } with tags, so subsequent formatting is easier."""
|
|
|
|
return re.sub(r'\${\s*(\w+)\s*}',
|
|
|
|
return re.sub(r'\${\s*(\w+)\s*}',
|
|
|
@ -87,6 +91,7 @@ def strip_variable_template_tags(line: str) -> str:
|
|
|
|
line,
|
|
|
|
line,
|
|
|
|
flags=re.UNICODE)
|
|
|
|
flags=re.UNICODE)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def apply_bracket_template_tags(content: str) -> str:
|
|
|
|
def apply_bracket_template_tags(content: str) -> str:
|
|
|
|
""" Replaces bracket { and } with tags, so subsequent formatting is easier."""
|
|
|
|
""" Replaces bracket { and } with tags, so subsequent formatting is easier."""
|
|
|
|
result = ""
|
|
|
|
result = ""
|
|
|
@ -108,17 +113,20 @@ def apply_bracket_template_tags(content: str) -> str:
|
|
|
|
last_c = c
|
|
|
|
last_c = c
|
|
|
|
return result
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def reverse_in_quotes_status(status: bool) -> bool:
|
|
|
|
def reverse_in_quotes_status(status: bool) -> bool:
|
|
|
|
if status:
|
|
|
|
if status:
|
|
|
|
return False
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def strip_bracket_template_tags(content: str) -> str:
|
|
|
|
def strip_bracket_template_tags(content: str) -> str:
|
|
|
|
""" Replaces tags back with { and } respectively."""
|
|
|
|
""" Replaces tags back with { and } respectively."""
|
|
|
|
content = content.replace(TEMPLATE_BRACKET_OPENING_TAG, "{", -1)
|
|
|
|
content = content.replace(TEMPLATE_BRACKET_OPENING_TAG, "{", -1)
|
|
|
|
content = content.replace(TEMPLATE_BRACKET_CLOSING_TAG, "}", -1)
|
|
|
|
content = content.replace(TEMPLATE_BRACKET_CLOSING_TAG, "}", -1)
|
|
|
|
return content
|
|
|
|
return content
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def clean_lines(orig_lines) -> list:
|
|
|
|
def clean_lines(orig_lines) -> list:
|
|
|
|
"""Strips the lines and splits them if they contain curly brackets."""
|
|
|
|
"""Strips the lines and splits them if they contain curly brackets."""
|
|
|
|
cleaned_lines = []
|
|
|
|
cleaned_lines = []
|
|
|
|