Skip to content

Commit 3ab602a

Browse files
authored
[FileFormats.MPS] allow any whitespace as a separator between fields (#2798)
1 parent 5d2196c commit 3ab602a

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/FileFormats/MPS/MPS.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1160,7 +1160,14 @@ function Headers(s::AbstractString)
11601160
end
11611161

11621162
function line_to_items(line)
1163-
items = split(line, " "; keepempty = false)
1163+
# Split on any whitespace characters. We can't split only on `' '` because
1164+
# at least one models in MIPLIB has `\t` as a separator.
1165+
#
1166+
# This decision assumes that we are parsing a free MPS file, where
1167+
# whitespace is disallowed in names. If this ever becomes a problem, we
1168+
# could change to the fixed MPS format, where the files are split at the
1169+
# usual offsets.
1170+
items = split(line, r"\s"; keepempty = false)
11641171
return String.(items)
11651172
end
11661173

test/FileFormats/MPS/MPS.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1703,6 +1703,16 @@ function test_issue_2792()
17031703
return
17041704
end
17051705

1706+
function test_issue_2797_tab()
1707+
@test MPS.line_to_items("a b") == ["a", "b"]
1708+
@test MPS.line_to_items(" a b") == ["a", "b"]
1709+
@test MPS.line_to_items("a\tb") == ["a", "b"]
1710+
@test MPS.line_to_items("a\tb") == ["a", "b"]
1711+
@test MPS.line_to_items("a\t b") == ["a", "b"]
1712+
@test MPS.line_to_items(" a \t b c ") == ["a", "b", "c"]
1713+
return
1714+
end
1715+
17061716
end # TestMPS
17071717

17081718
TestMPS.runtests()

0 commit comments

Comments
 (0)