emmental/emmental/format.py

22 lines
523 B
Python
Raw Normal View History

# Copyright 2022 (c) Anna Schumaker
"""Helper functions for formatting strings."""
def search(input: str) -> str | None:
"""Translate the input string into a sqlite3 GLOB statement."""
input = input.strip().casefold()
if len(input) == 0:
return None
if input[0] == "^":
input = input[1:] if len(input) > 1 else "*"
elif input[0] != "*":
input = "*" + input
if input[-1] == "$":
input = input[:-1]
elif input[-1] != "*":
input += "*"
return input