Mercurial > hg > TextShaper
changeset 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 | 5ffa0dbcb7fe |
children | 8cf9a26b9aaa |
files | textshaper/main.py textshaper/whitespace.py |
diffstat | 2 files changed, 14 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/textshaper/main.py Thu Mar 13 13:53:41 2014 -0700 +++ b/textshaper/main.py Sat May 03 14:47:16 2014 -0700 @@ -12,6 +12,7 @@ import time from .commands import Commands from .indent import deindent, indent +from .whitespace import underscore from which import which HR = '--' @@ -39,8 +40,10 @@ commands = Commands() commands.add(indent, 'i') commands.add(deindent, 'd') + commands.add(underscore, 'u') return commands + def add_options(parser): """add options to the parser instance"""
--- a/textshaper/whitespace.py Thu Mar 13 13:53:41 2014 -0700 +++ b/textshaper/whitespace.py Sat May 03 14:47:16 2014 -0700 @@ -5,8 +5,9 @@ """ import os +from .decorator import lines -__all__ = ['normalize'] +__all__ = ['normalize', 'underscore', 'filename2name'] def normalize(text, separator=None, joiner=None): """ @@ -18,6 +19,15 @@ return joiner.join(text.strip().split(separator)) +@lines +def underscore(text, replacement='_', split=None, strip=str.rstrip): + retval = [] + for line in text: + if strip: + strip(line) + retval.append(replacement.join(line.split(split))) + return retval + def filename2name(text, whitespace=('_',), replacement=' '): """ convert filename to name