Skip to content

Commit 13404c8

Browse files
committed
BF: retain a possible (single) space after a number
Should avoid collapsing numbers in a date together
1 parent b1fabc9 commit 13404c8

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

heudiconv/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ def json_dumps_pretty(j, indent=2, sort_keys=True):
200200
# uniform no spaces before ]
201201
js_ = re.sub(" *\]", "]", js_)
202202
# uniform spacing before numbers
203-
js_ = re.sub(' *("?[-+.0-9e]+"?)[ \n]*', r' \1', js_)
203+
js_ = re.sub(' *("?[-+.0-9e]+"?)(?P<space> ?)[ \n]*',
204+
r' \1\g<space>', js_)
204205
# no spaces after [
205206
js_ = re.sub('\[ ', '[', js_)
206207
# the load from the original dump and reload from tuned up

tests/test_utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ def test_load_heuristic():
4545

4646
def test_json_dumps_pretty():
4747
pretty = json_dumps_pretty
48+
assert pretty({"SeriesDescription": "Trace:Nov 13 2017 14-36-14 EST"}) \
49+
== '{\n "SeriesDescription": "Trace:Nov 13 2017 14-36-14 EST"\n}'
4850
assert pretty({}) == "{}"
4951
assert pretty({"a": -1, "b": "123", "c": [1, 2, 3], "d": ["1.0", "2.0"]}) \
5052
== '{\n "a": -1,\n "b": "123",\n "c": [1, 2, 3],\n "d": ["1.0", "2.0"]\n}'
5153
assert pretty({'a': ["0.3", "-1.9128906358217845e-12", "0.2"]}) \
52-
== '{\n "a": ["0.3", "-1.9128906358217845e-12", "0.2"]\n}'
54+
== '{\n "a": ["0.3", "-1.9128906358217845e-12", "0.2"]\n}'

0 commit comments

Comments
 (0)