rDrama/files/helpers/strings.py
TLSM 9953c5763c
Port get.py improvements from upstream.
Generally standardizes the get_* helpers:
 - Adds type hinting.
 - Deduplicates block property addition.
 - Respects `graceful` in more contexts.
 - More resilient to invalid user input / less boilerplate necessary
   at call-sites.
2022-11-28 12:36:04 -05:00

17 lines
497 B
Python

import typing
# clean strings for searching
def sql_ilike_clean(my_str):
if my_str is None:
return None
return my_str.replace(r'\\', '').replace('_', r'\_').replace('%', '').strip()
# this will also just return a bool verbatim
def bool_from_string(input: typing.Union[str, bool]) -> bool:
if isinstance(input, bool):
return input
if input.lower() in ("yes", "true", "t", "on", "1"):
return True
if input.lower() in ("no", "false", "f", "off", "0"):
return False
raise ValueError()