Skip to content

Commit

Permalink
Merge pull request #85 from Geson-anko/name_tools/clean_all_sep
Browse files Browse the repository at this point in the history
Name tools/clean all sep
  • Loading branch information
Geson-anko committed May 7, 2022
2 parents b633429 + f05e3ef commit a3ead10
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
11 changes: 8 additions & 3 deletions JarvisEngine/core/name.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
SEP = "."

def clean(name:str) -> str:
"""clean name."""
"""clean name.
Erase all SEP's at the head and tail of name.
Ex:
"..a.b.c.." -> "a.b.c"
".d.e" -> "d.e"
"""
if name[0] == SEP:
start = 1
start = count_head_sep(name)
else:
start = 0

if name[-1] == SEP:
end = -1
end = -count_head_sep(name[::-1])
else:
end = len(name)

Expand Down
4 changes: 4 additions & 0 deletions tests/core/test_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ def test_clean():
assert name.clean("d.e.") == "d.e"
assert name.clean(".f.") == "f"
assert name.clean(".g.h") == "g.h"

assert name.clean("..a.b.c..") == "a.b.c"
assert name.clean("..d.e") == "d.e"
assert name.clean("f....") == "f"

def test_join():
assert name.join("a","b") == "a.b"
Expand Down

0 comments on commit a3ead10

Please sign in to comment.