return line
+def trim_bom(line):
+ " Remove byte order mark."
+ if line[0:3] == "\357\273\277":
+ return line[3:]
+ else:
+ return line
+
+
def read(input):
" Read input file and strip lineendings."
lines = list()
+ first_line = 1
while 1:
line = input.readline()
if not line:
break
+ if (first_line):
+ line = trim_bom(line)
+ first_line = 0
lines.append(trim_eol(line))
return lines
#include "support/FileName.h"
#include "support/filetools.h"
#include "support/gzstream.h"
+#include "support/lassert.h"
#include "support/lstrings.h"
#include "support/lyxalgo.h"
#include "support/types.h"
is.rdbuf(&gz_);
name = filename.absFilename();
lineno = 0;
- return gz_.is_open() && is.good();
+ if (!gz_.is_open() || !is.good())
+ return false;
} else {
LYXERR(Debug::LYXLEX, "lyxlex: UNcompressed");
is.rdbuf(&fb_);
name = filename.absFilename();
lineno = 0;
- return fb_.is_open() && is.good();
+ if (!fb_.is_open() || !is.good())
+ return false;
}
+
+ // Skip byte order mark.
+ if (is.peek() == 0xef) {
+ int c = is.get();
+ if (is.peek() == 0xbb) {
+ c = is.get();
+ LASSERT(is.get() == 0xbf, /**/);
+ } else
+ is.unget();
+ }
+
+ return true;
}