view pcombinators/util.py @ 82:27fb2e50dad2 draft

Only run coverage in test.sh; it is enough
author Lewin Bormann <lbo@spheniscida.de>
date Sat, 25 May 2019 23:48:44 +0200
parents 40f9e05d8f06
children
line wrap: on
line source

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu May 23 22:34:33 2019

@author: lbo
"""

import time

def time_it(f):
    def f_(*args, **kwargs):
        before = time.time()
        r = f(*args, **kwargs)
        print(f, time.time()-before)
        return r
    return f_

def remove_unused_whitespace(s):
    acc = []
    lvl = 0
    ws = set(' \n\t\r')
    for c in s:
        if c == '"':
            lvl += 1 if lvl == 0 else -1
        if lvl == 0 and c in ws:
            continue
        acc.append(c)
    return ''.join(acc)