Mercurial > hg > TextShaper
comparison textshaper/whitespace.py @ 36:55e0579e2143
STUB: textshaper/main.py textshaper/whitespace.py
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Sat, 03 May 2014 14:47:16 -0700 |
parents | c23782a7b7ba |
children |
comparison
equal
deleted
inserted
replaced
35:5ffa0dbcb7fe | 36:55e0579e2143 |
---|---|
3 """ | 3 """ |
4 text shaping functionality having to do with whitespace | 4 text shaping functionality having to do with whitespace |
5 """ | 5 """ |
6 | 6 |
7 import os | 7 import os |
8 from .decorator import lines | |
8 | 9 |
9 __all__ = ['normalize'] | 10 __all__ = ['normalize', 'underscore', 'filename2name'] |
10 | 11 |
11 def normalize(text, separator=None, joiner=None): | 12 def normalize(text, separator=None, joiner=None): |
12 """ | 13 """ |
13 strips text and | 14 strips text and |
14 replace multiple whitespace occurance with single occurance | 15 replace multiple whitespace occurance with single occurance |
16 if joiner is None: | 17 if joiner is None: |
17 joiner = ' ' if separator is None else separator | 18 joiner = ' ' if separator is None else separator |
18 return joiner.join(text.strip().split(separator)) | 19 return joiner.join(text.strip().split(separator)) |
19 | 20 |
20 | 21 |
22 @lines | |
23 def underscore(text, replacement='_', split=None, strip=str.rstrip): | |
24 retval = [] | |
25 for line in text: | |
26 if strip: | |
27 strip(line) | |
28 retval.append(replacement.join(line.split(split))) | |
29 return retval | |
30 | |
21 def filename2name(text, whitespace=('_',), replacement=' '): | 31 def filename2name(text, whitespace=('_',), replacement=' '): |
22 """ | 32 """ |
23 convert filename to name | 33 convert filename to name |
24 """ | 34 """ |
25 | 35 |