Skip to content

Commit

Permalink
Merge pull request #65 from IDEMSInternational/cell-trim-spaces
Browse files Browse the repository at this point in the history
CellParser: Trim starting/trailing whitespace
  • Loading branch information
geoo89 authored Feb 8, 2023
2 parents a5195a2 + 54c6622 commit 0f4359c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion parsers/common/cellparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ def split_into_lists(self, string):
def cleanse(self, nested_list):
# Unescape escaped characters (\, |, ;)
if type(nested_list) == str:
return nested_list.replace('\\\\', '\1') \
return nested_list.strip() \
.replace('\\\\', '\1') \
.replace('\\|', '|') \
.replace('\\;', ';') \
.replace('\1', '\\')
Expand Down
8 changes: 7 additions & 1 deletion parsers/common/tests/test_cellparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def test_cleanse(self):
self.compare_cleanse('a\\\\', 'a\\')
self.compare_cleanse('a\\\\;', 'a\\;')
self.compare_cleanse([[['a\\;']]], [[['a;']]])
self.compare_cleanse(['\\\\', '\n\\;\n'], ['\\', '\n;\n'])
self.compare_cleanse(['\\\\', '\\;'], ['\\', ';'])

def test_split_into_lists(self):
self.compare_split_into_lists('1', '1')
Expand All @@ -69,6 +69,12 @@ def test_split_into_lists(self):
self.compare_split_into_lists('1;2|3;4\\|', [['1', '2'], ['3', '4|']])
self.compare_split_into_lists(CellParser.escape_string('|;;|\\;\\\\\\|'), '|;;|\\;\\\\\\|')

def test_string_stripping(self):
self.compare_cleanse(' a;\n', 'a;')
self.compare_cleanse([' a;\n'], ['a;'])
self.compare_split_into_lists(' a\n|\nb ', ['a', 'b'])
self.compare_split_into_lists('1; 2\n|\n3; 4', [['1', '2'], ['3', '4']])


class TestCellParser(unittest.TestCase):

Expand Down

0 comments on commit 0f4359c

Please sign in to comment.