Skip to content

Commit e8b4ae9

Browse files
Merge pull request #38 from Mbed-TLS/dev/minos/minor/code_wrappers_fix_identation
c_wrapper_generator: Increased robustness of whitespace capture.
2 parents 33d7886 + c801fc7 commit e8b4ae9

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

scripts/mbedtls_framework/c_wrapper_generator.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,18 @@ def strip_indentation(in_str: str, new_lines: int = 1, indent_lv: int = 0) -> st
3434
"""Return a whitespace stripped str, with configurable whitespace in output.
3535
3636
The method will remove space-character indentation from input string.
37-
It will also remove all new-lines around the text-block.
37+
It will also remove all new-lines around the text-block as well as
38+
trailing whitespace.
3839
The output indentation can be configured by indent_lv, and will use blocks
3940
of 4 spaces.
4041
At the end of the string a `new_lines` amount of empty lines will be added.
4142
"""
4243

43-
_ret_string = in_str.strip('\n')
44-
44+
_ret_string = in_str.lstrip('\n').rstrip()
4545
# Count empty spaces in beggining of each line. The smallest non-zero entry
4646
# will be used to clean up input indentation.
47-
indents = [len(n) for n in re.findall(r'(?m)^ +', in_str)]
47+
indents = [len(n)-1 for n in re.findall(r'(?m)^ +\S', in_str)]
48+
4849
if indents:
4950
_ret_string = re.sub(r'(?m)^ {{{indent}}}'.format(indent=min(indents)),
5051
'', _ret_string)

0 commit comments

Comments
 (0)