20 lines
827 B
Python

import re
from fledermaus_formatter.table_handler.Entry import Entry
from copy import deepcopy
class FindAndReplace:
def __init__(self, map: dict[str, list[str]], reqire_full_match: bool = False):
self.map = map
self.require_full_match = reqire_full_match
def execute_on_cell(self, entry) -> str:
res = deepcopy(entry.value)
for correct_name, bad_names in self.map.items():
for bad_name in bad_names:
if self.require_full_match and bad_name == res:
# Todo remove random leading/trailing spaces before if
res = correct_name
elif not self.require_full_match:
res = res.replace(bad_name, correct_name)
return Entry(value=res, fg_color=entry.fg_color, bg_color=entry.bg_color)