From 08686b4117ae8b0f8dc3711e169e3da3fa1fe8fc Mon Sep 17 00:00:00 2001 From: Dimitri van Heesch Date: Thu, 16 Jul 2020 19:16:19 +0200 Subject: Restructured the split_and_keep function --- testing/runtests.py | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/testing/runtests.py b/testing/runtests.py index 129a781..6b3e54e 100755 --- a/testing/runtests.py +++ b/testing/runtests.py @@ -474,26 +474,13 @@ class TestManager: shutil.rmtree("dtd",ignore_errors=True) shutil.copytree(self.args.inputdir+"/dtd", "dtd") -def split_and_keep(s, sep): - if not s: return [] - - # Find replacement character that is not used in string - # i.e. just use the highest available character plus one - # Note: This fails if ord(max(s)) = 0x10FFFF (ValueError) - p=chr(ord(max(s))+1) - - retVal = [] - for val in s.replace(sep, p+sep).split(p): - vv = val.split(" ",1) - if ((len(vv) == 1) and not vv[0] == ''): - retVal += vv - if (len(vv) == 2): - vv[1] = vv[1].strip() - if ((len(vv) == 2) and not vv[1] == ''): - retVal += vv - if ((len(vv) == 2) and vv[1] == ''): - retVal += [vv[0]] - return retVal +def split_and_keep(s,sep): + s = s.replace(sep,'\0'+sep) # add token separator + s = s.split('\0') # split by null delimiter + s = [x.strip() for x in filter(None,s)] # strip and remove empty elements + s = [z.split(' ',1) for z in s] # split by first space + s = [i for ss in s for i in ss] # flatten the list + return s def main(): # argument handling -- cgit v0.12