Coverage for fpdf2_textindex/utils.py: 100.00%
12 statements
« prev ^ index » next coverage.py v7.14.1, created at 2026-06-01 14:22 +0000
« prev ^ index » next coverage.py v7.14.1, created at 2026-06-01 14:22 +0000
1"""Utils."""
3# ruff: noqa: D103
5import re
8def escape_square_brackets(text: str) -> str:
9 return text.replace("[", "\\[").replace("]", "\\]")
12def insert_at_match(
13 text: str,
14 match: re.Match[str],
15 insert: str,
16 offset: int = 0,
17) -> str:
18 return (
19 text[: match.start() + offset] + insert + text[match.end() + offset :]
20 )
23def md_link(link_text: str | None, link: str) -> str:
24 link_text = escape_square_brackets(link_text or "")
25 return f"[{link_text:s}]({link:s})"
28def remove_match_from_str(
29 text: str,
30 match: re.Match[str],
31 offset: int = 0,
32) -> str:
33 return text[: match.start() + offset] + text[match.end() + offset :]
36def remove_quotes(text: str) -> str:
37 return text.strip(" '\"")