Wrap the given text in the given open and close characters. Args: text: The text to wrap. open: The open character. close: The close character. check_first: Whether to check if the text is already wrapped. num: The number of times to wrap the text. R
(
text: str,
open: str,
close: str | None = None,
check_first: bool = True,
num: int = 1,
)
| 68 | |
| 69 | |
| 70 | def wrap( |
| 71 | text: str, |
| 72 | open: str, |
| 73 | close: str | None = None, |
| 74 | check_first: bool = True, |
| 75 | num: int = 1, |
| 76 | ) -> str: |
| 77 | """Wrap the given text in the given open and close characters. |
| 78 | |
| 79 | Args: |
| 80 | text: The text to wrap. |
| 81 | open: The open character. |
| 82 | close: The close character. |
| 83 | check_first: Whether to check if the text is already wrapped. |
| 84 | num: The number of times to wrap the text. |
| 85 | |
| 86 | Returns: |
| 87 | The wrapped text. |
| 88 | """ |
| 89 | close = get_close_char(open, close) |
| 90 | |
| 91 | # If desired, check if the text is already wrapped in braces. |
| 92 | if check_first and is_wrapped(text=text, open=open, close=close): |
| 93 | return text |
| 94 | |
| 95 | # Wrap the text in braces. |
| 96 | return f"{open * num}{text}{close * num}" |
| 97 | |
| 98 | |
| 99 | def indent(text: str, indent_level: int = 2) -> str: |
no test coverage detected