Skip to content

Commit 764b6b1

Browse files
committed
added surround func
1 parent 47f5ac8 commit 764b6b1

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

string_py/string_py.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,22 @@ def remove(self, chars: str) -> str:
187187

188188
class Format:
189189
"""Format texts"""
190+
191+
@staticmethod
192+
def surround(values: str, char: str = "*") -> str:
193+
"""Surround a text with chars
194+
195+
Parameters
196+
----------
197+
:param values:`str`
198+
Text to surround
199+
:param char:`*`
200+
Char to surround with
201+
:return:
202+
Returns a string with the text surrounded with chars
203+
"""
204+
return f"{char * (len(values) + 4)}\n{char} {values} {char}\n{char * (len(values) + 4)}"
205+
190206
@staticmethod
191207
def align(values: dict[str, str]):
192208
"""Algin a text
@@ -210,6 +226,8 @@ def align(values: dict[str, str]):
210226
aligned_text += key + " " * ((length + 3) - len(key)) + values[key] + "\n"
211227
return aligned_text
212228

229+
230+
213231
@staticmethod
214232
def table(values: list[list[str]], border: bool = True) -> str:
215233
"""Create a table
@@ -246,3 +264,5 @@ def table(values: list[list[str]], border: bool = True) -> str:
246264
if index != len(values) - 1:
247265
table += "\n"
248266
return table
267+
268+

0 commit comments

Comments
 (0)