Mercurial > hg > TextShaper
comparison textshaper/whitespace.py @ 8:22c830449604
textshaper/whitespace.py
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Sun, 20 Oct 2013 18:07:06 -0700 |
parents | 2693d9f8ed8c |
children | c23782a7b7ba |
comparison
equal
deleted
inserted
replaced
7:2693d9f8ed8c | 8:22c830449604 |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 | 2 |
3 """ | 3 """ |
4 text shaping functionality having to do with whitespace | 4 text shaping functionality having to do with whitespace |
5 """ | 5 """ |
6 | |
7 import os | |
6 | 8 |
7 __all__ = ['normalize'] | 9 __all__ = ['normalize'] |
8 | 10 |
9 def normalize(text, separator=None, joiner=None): | 11 def normalize(text, separator=None, joiner=None): |
10 """ | 12 """ |
12 replace multiple whitespace occurance with single occurance | 14 replace multiple whitespace occurance with single occurance |
13 """ | 15 """ |
14 if joiner is None: | 16 if joiner is None: |
15 joiner = ' ' if separator is None else separator | 17 joiner = ' ' if separator is None else separator |
16 return joiner.join(text.strip().split(separator)) | 18 return joiner.join(text.strip().split(separator)) |
19 | |
20 def filename2name(text, whitespace=('_',), replacement=' '): | |
21 """ | |
22 convert filename to name | |
23 """ | |
24 | |
25 name = os.path.splitext(os.path.basenmae(text))[0] | |
26 for string in whitespace: | |
27 name = name.replace(string, replace) | |
28 return name |