Skip to content

Commit fb2a61a

Browse files
committedNov 24, 2021
regex to implement remove prefix for python versions < 3.9
1 parent 4edd74f commit fb2a61a

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed
 

‎scripts/message_hdr.py

+13-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
#! /usr/bin/env python3
22

33
import sys
4+
import re
45

56
FILE_HEADER = '''#pragma once
67
//This File is autogenerated an may be overridden, do not change
78
//If you need to change the content of the file please change the file
89
//sources/message_hdr.py'''
910

10-
1111
prefix = sys.argv[1] + '/'
12-
with open(sys.argv[2], 'w') as output:
13-
output.write(f"{FILE_HEADER}\n")
14-
for i in range(3, len(sys.argv)):
15-
for include in sys.argv[i].split(';'):
16-
include = include.removeprefix(prefix)
17-
output.write(f"#include <{include}>\n")
12+
13+
def remove_prefix(text, prefix):
14+
return re.sub(r'^{0}'.format(re.escape(prefix)), '', text)
15+
16+
17+
if __name__ == "__main__":
18+
with open(sys.argv[2], 'w') as output:
19+
output.write(f"{FILE_HEADER}\n")
20+
for i in range(3, len(sys.argv)):
21+
for include in sys.argv[i].split(';'):
22+
include = remove_prefix(include, prefix)
23+
output.write(f"#include <{include}>\n")

0 commit comments

Comments
 (0)
Please sign in to comment.