annotate textshaper/whitespace.py @ 23:7ffe000f6f42

removing stub
author Jeff Hammel <k0scist@gmail.com>
date Sun, 23 Feb 2014 10:14:06 -0800
parents 22c830449604
children c23782a7b7ba
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
2693d9f8ed8c add file for dealing with whitespace
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
1 #!/usr/bin/env python
2693d9f8ed8c add file for dealing with whitespace
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
2
2693d9f8ed8c add file for dealing with whitespace
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
3 """
2693d9f8ed8c add file for dealing with whitespace
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
4 text shaping functionality having to do with whitespace
2693d9f8ed8c add file for dealing with whitespace
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
5 """
2693d9f8ed8c add file for dealing with whitespace
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
6
8
22c830449604 textshaper/whitespace.py
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
7 import os
22c830449604 textshaper/whitespace.py
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
8
7
2693d9f8ed8c add file for dealing with whitespace
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
9 __all__ = ['normalize']
2693d9f8ed8c add file for dealing with whitespace
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
10
2693d9f8ed8c add file for dealing with whitespace
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
11 def normalize(text, separator=None, joiner=None):
2693d9f8ed8c add file for dealing with whitespace
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
12 """
2693d9f8ed8c add file for dealing with whitespace
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
13 strips text and
2693d9f8ed8c add file for dealing with whitespace
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
14 replace multiple whitespace occurance with single occurance
2693d9f8ed8c add file for dealing with whitespace
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
15 """
2693d9f8ed8c add file for dealing with whitespace
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
16 if joiner is None:
2693d9f8ed8c add file for dealing with whitespace
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
17 joiner = ' ' if separator is None else separator
2693d9f8ed8c add file for dealing with whitespace
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
18 return joiner.join(text.strip().split(separator))
8
22c830449604 textshaper/whitespace.py
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
19
22c830449604 textshaper/whitespace.py
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
20 def filename2name(text, whitespace=('_',), replacement=' '):
22c830449604 textshaper/whitespace.py
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
21 """
22c830449604 textshaper/whitespace.py
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
22 convert filename to name
22c830449604 textshaper/whitespace.py
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
23 """
22c830449604 textshaper/whitespace.py
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
24
22c830449604 textshaper/whitespace.py
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
25 name = os.path.splitext(os.path.basenmae(text))[0]
22c830449604 textshaper/whitespace.py
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
26 for string in whitespace:
22c830449604 textshaper/whitespace.py
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
27 name = name.replace(string, replace)
22c830449604 textshaper/whitespace.py
Jeff Hammel <jhammel@mozilla.com>
parents: 7
diff changeset
28 return name