Add new utilisty

This commit is contained in:
Saifeddine ALOUI 2023-12-30 22:39:13 +01:00
parent a2cf0dbf50
commit 6d11899206

View File

@ -72,6 +72,27 @@ def expand2square(pil_img, background_color):
return result
def add_period(text):
"""
Adds a period at the end of each line in the given text, except for empty lines.
Args:
text (str): The input text.
Returns:
str: The preprocessed text with a period added at the end of each line that doesn't already have one.
"""
lines = text.split('\n')
processed_lines = []
for line in lines:
if line.strip(): # Check if line is not empty
if line[-1] != '.':
line += '.'
processed_lines.append(line)
processed_text = '\n'.join(processed_lines)
return processed_text
def find_first_available_file_index(folder_path, prefix, extension=""):