view textshaper/whitespace.py @ 14:30f1781024a4

add splitline functionality
author Jeff Hammel <k0scist@gmail.com>
date Tue, 04 Feb 2014 14:44:47 -0800
parents 22c830449604
children c23782a7b7ba
line wrap: on
line source

#!/usr/bin/env python

"""
text shaping functionality having to do with whitespace
"""

import os

__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))

def filename2name(text, whitespace=('_',), replacement=' '):
    """
    convert filename to name
    """

    name = os.path.splitext(os.path.basenmae(text))[0]
    for string in whitespace:
        name = name.replace(string, replace)
    return name