Source code for LOGS_solutions.Utils.csv_utils
# common/csv_utils.py
import re
from typing import Optional
_UNWANTED = re.compile(r"[\n\r\t\x00-\x1F]")
[docs]
def clean_csv_text(value: Optional[str]) -> str:
"""Remove control characters and escape double quotes for CSV fields.
Removes ASCII control characters (0–31, including \n, \r, \t)
from CSV fields and escapes double quotes according to the CSV convention.
"""
if value is None:
return ""
cleaned = _UNWANTED.sub("", value)
return cleaned.replace('"', '""')