Mercurial > hg > TextShaper
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/textshaper/whitespace.py Sat Oct 05 09:50:34 2013 -0700 @@ -0,0 +1,16 @@ +#!/usr/bin/env python + +""" +text shaping functionality having to do with whitespace +""" + +__all__ = ['normalize'] + +def normalize(text, separator=None, joiner=None): + """ + strips text and + replace multiple whitespace occurance with single occurance + """ + if joiner is None: + joiner = ' ' if separator is None else separator + return joiner.join(text.strip().split(separator))