-
Notifications
You must be signed in to change notification settings - Fork 0
/
Comments.py
42 lines (38 loc) · 1.21 KB
/
Comments.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""
Формирование строк комментариев
"""
def create_comment(com: str = "", len_com: int = 70,
com_sim: str = "#", null_sim: str = "-"):
"""
Функция которая создает комментарии для Cmake
:param com:
:param len_com:
:param com_sim:
:param null_sim:
:return:
"""
string_com = '#'
if com == "":
for i in range(len_com - 1):
string_com += null_sim
string_com += f'{com_sim}\n'
else:
center_string = com.center(len_com)
st_sim = center_string.find(com)
end_sim = st_sim + len(com)
for i in range(len_com - 1):
if end_sim < i or i < st_sim:
string_com += null_sim
else:
string_com += center_string[i]
string_com += f'{com_sim}\n'
return string_com
if __name__ == "__main__":
string_1 = create_comment("Линковка библиотек")
string_2 = create_comment()
print(f'{string_2}{string_1}{string_2}')
if len(string_1) != len(string_2):
print(len(string_1), len(string_2), "Error")
else:
print(len(string_1), len(string_2), "all ok!")
quit(0)