# HG changeset patch # User Jeff Hammel # Date 1382317626 25200 # Node ID 22c83044960438c1a83adba644d216b85a500a84 # Parent 2693d9f8ed8c5040952ab33fa1f52b7fb7608fec textshaper/whitespace.py diff -r 2693d9f8ed8c -r 22c830449604 textshaper/whitespace.py --- a/textshaper/whitespace.py Sat Oct 05 09:50:34 2013 -0700 +++ b/textshaper/whitespace.py Sun Oct 20 18:07:06 2013 -0700 @@ -4,6 +4,8 @@ text shaping functionality having to do with whitespace """ +import os + __all__ = ['normalize'] def normalize(text, separator=None, joiner=None): @@ -14,3 +16,13 @@ if joiner is None: joiner = ' ' if separator is None else separator return joiner.join(text.strip().split(separator)) + +def filename2name(text, whitespace=('_',), replacement=' '): + """ + convert filename to name + """ + + name = os.path.splitext(os.path.basenmae(text))[0] + for string in whitespace: + name = name.replace(string, replace) + return name