add slash_join helper and tests

This commit is contained in:
Jimmy Zelinskie 2015-12-22 14:55:13 -05:00 committed by Jimmy Zelinskie
parent 0dcfcebe34
commit bf477b6b9c
2 changed files with 29 additions and 0 deletions

13
util/string.py Normal file
View file

@ -0,0 +1,13 @@
def slash_join(*args):
"""
Joins together strings and guarantees there is only one '/' in between the
each string joined. Double slashes ('//') are assumed to be intentional and
are not deduplicated.
"""
def rmslash(path):
path = path[1:] if path[0] == '/' else path
path = path[:-1] if path[-1] == '/' else path
return path
args = [rmslash(path) for path in args]
return '/'.join(args)