Skip to content

Commit 942f2a8

Browse files
committed
Simplify parsing with regular expressions
1 parent a6bfcfe commit 942f2a8

File tree

1 file changed

+3
-15
lines changed

1 file changed

+3
-15
lines changed

lib/matplotlib/dviread.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from matplotlib.compat import subprocess
3232
from matplotlib import rcParams
3333
import numpy as np
34+
import re
3435
import struct
3536
import sys
3637
import textwrap
@@ -876,21 +877,8 @@ def _parse(self, file):
876877
line = line.strip()
877878
if line == b'' or line.startswith(b'%'):
878879
continue
879-
words, pos = [], 0
880-
while pos < len(line):
881-
if line[pos:pos+1] == b'"': # double quoted word
882-
pos += 1
883-
end = line.index(b'"', pos)
884-
words.append(line[pos:end])
885-
pos = end + 1
886-
else: # ordinary word
887-
end = line.find(b' ', pos+1)
888-
if end == -1:
889-
end = len(line)
890-
words.append(line[pos:end])
891-
pos = end
892-
while pos < len(line) and line[pos:pos+1] == b' ':
893-
pos += 1
880+
words = [word.strip(b'"') for word in
881+
re.findall(b'("[^"]*"|[^ ]+)', line)]
894882
self._register(words)
895883

896884
def _register(self, words):

0 commit comments

Comments
 (0)