From 7a9c6be76c582676b8b37bc79929b66a0f4b5e09 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 27 Apr 2016 17:04:25 -0700 Subject: [PATCH] [mtiLib] Warn if trailing tabs are found --- Lib/fontTools/mtiLib/__init__.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Lib/fontTools/mtiLib/__init__.py b/Lib/fontTools/mtiLib/__init__.py index 706e491f2..cea8a0d5d 100644 --- a/Lib/fontTools/mtiLib/__init__.py +++ b/Lib/fontTools/mtiLib/__init__.py @@ -16,6 +16,7 @@ from fontTools.otlLib import builder as otl from contextlib import contextmanager from operator import setitem import logging +import warnings class MtiLibError(Exception): pass class ReferenceNotFoundError(MtiLibError): pass @@ -1009,14 +1010,20 @@ class Tokenizer(object): def _next_line(self): self.lineno += 1 line = self.line = next(self.lines) - return [s.strip() for s in line.rstrip().split('\t')] - + line = [s.strip() for s in line.split('\t')] + if len(line) == 1 and not line[0]: + del line[0] + if line and not line[-1]: + warnings.warn('trailing tab found on line %d: %s' % (self.lineno, self.line)) + while line and not line[-1]: + del line[-1] + return line def _next_nonempty(self): while True: line = self._next_line() # Skip comments and empty lines - if line[0] and (line[0][0] != '%' or line[0] == '% subtable'): + if line and line[0] and (line[0][0] != '%' or line[0] == '% subtable'): return line def _next_buffered(self):