Mercurial > hg > TextShaper
annotate textshaper/whitespace.py @ 7:2693d9f8ed8c
add file for dealing with whitespace
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Sat, 05 Oct 2013 09:50:34 -0700 |
parents | |
children | 22c830449604 |
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 |
2693d9f8ed8c
add file for dealing with whitespace
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
7 __all__ = ['normalize'] |
2693d9f8ed8c
add file for dealing with whitespace
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
8 |
2693d9f8ed8c
add file for dealing with whitespace
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
9 def normalize(text, separator=None, joiner=None): |
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 strips text and |
2693d9f8ed8c
add file for dealing with whitespace
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
12 replace multiple whitespace occurance with single occurance |
2693d9f8ed8c
add file for dealing with whitespace
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
13 """ |
2693d9f8ed8c
add file for dealing with whitespace
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
14 if joiner is None: |
2693d9f8ed8c
add file for dealing with whitespace
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
15 joiner = ' ' if separator is None else separator |
2693d9f8ed8c
add file for dealing with whitespace
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
16 return joiner.join(text.strip().split(separator)) |