From 0331b763ffa845f3cb7b9651ca70ab8b407eb67e Mon Sep 17 00:00:00 2001 From: jesopo Date: Thu, 10 Oct 2019 10:32:47 +0100 Subject: refactor multi-line-to-line normalisation to utils.parse.line_normalise(), use it in rss.py closes #174 --- src/utils/parse.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/utils') diff --git a/src/utils/parse.py b/src/utils/parse.py index 65d0552b..b53b9595 100644 --- a/src/utils/parse.py +++ b/src/utils/parse.py @@ -1,4 +1,5 @@ import io, typing +from src import utils COMMENT_TYPES = ["#", "//"] def hashflags(filename: str @@ -79,3 +80,7 @@ def try_int(s: str) -> typing.Optional[int]: return int(s) except ValueError: return None + +def line_normalise(s: str) -> str: + lines = list(filter(None, [line.strip() for line in s.split("\n")])) + return " ".join(line.replace(" ", " ") for line in lines) -- cgit v1.3.1-10-gc9f91