Replaced escaped_split() logic with regex

This commit is contained in:
Azim Khan 2018-07-05 17:53:11 +01:00 committed by Mohammad Azim Khan
parent fcdf685302
commit 630281349e
2 changed files with 8 additions and 24 deletions

View file

@ -632,18 +632,10 @@ def escaped_split(inp_str, split_char):
""" """
if len(split_char) > 1: if len(split_char) > 1:
raise ValueError('Expected split character. Found string!') raise ValueError('Expected split character. Found string!')
out = [] out = re.sub(r'(\\.)|' + split_char,
part = '' lambda m: m.group(1) or '\n', inp_str,
escape = False len(inp_str)).split('\n')
for character in inp_str: out = filter(lambda x: x or False, out)
if not escape and character == split_char:
out.append(part)
part = ''
else:
part += character
escape = not escape and character == '\\'
if part:
out.append(part)
return out return out

View file

@ -77,18 +77,10 @@ class TestDataParser(object):
""" """
if len(split_char) > 1: if len(split_char) > 1:
raise ValueError('Expected split character. Found string!') raise ValueError('Expected split character. Found string!')
out = [] out = re.sub(r'(\\.)|' + split_char,
part = '' lambda m: m.group(1) or '\n', inp_str,
escape = False len(inp_str)).split('\n')
for character in inp_str: out = filter(lambda x: x or False, out)
if not escape and character == split_char:
out.append(part)
part = ''
else:
part += character
escape = not escape and character == '\\'
if part:
out.append(part)
return out return out
def __parse(self, data_f): def __parse(self, data_f):