Skip to content

Commit aadcb6b

Browse files
committed
Replaced string manipulation utility functions with their standard library implementations
Signed-off-by: jakub-nt <175944085+jakub-nt@users.noreply.github.com>
1 parent e88e936 commit aadcb6b

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

cfbs/utils.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,12 @@ def cp(src, dst):
7979
sh("rsync -r %s/ %s" % (src, dst))
8080

8181

82-
def pad_left(s, n) -> int:
83-
return s if len(s) >= n else " " * (n - len(s)) + s
82+
def pad_left(s, n):
83+
return s.rjust(n)
8484

8585

86-
def pad_right(s, n) -> int:
87-
return s if len(s) >= n else s + " " * (n - len(s))
86+
def pad_right(s, n):
87+
return s.ljust(n)
8888

8989

9090
def split_command(command) -> Tuple[str, List[str]]:
@@ -137,12 +137,14 @@ def item_index(iterable, item, extra_at_end=True):
137137

138138

139139
def strip_right(string, ending):
140+
# can be replaced with str.removesuffix from Python 3.9 onwards
140141
if not string.endswith(ending):
141142
return string
142143
return string[0 : -len(ending)]
143144

144145

145146
def strip_left(string, beginning):
147+
# can be replaced with str.removeprefix from Python 3.9 onwards
146148
if not string.startswith(beginning):
147149
return string
148150
return string[len(beginning) :]

0 commit comments

Comments
 (0)