From e31e71a7a9d978778b9c1f39b71a2491c1e31498 Mon Sep 17 00:00:00 2001 From: Enrico Forestieri Date: Sun, 21 Jun 2009 18:23:10 +0000 Subject: [PATCH] Fix bug #6030: LyX does not take into account BOM in user layout files. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@30213 a592a061-630c-0410-9148-cb99ea01b6c8 --- lib/scripts/layout2layout.py | 12 ++++++++++++ src/Lexer.cpp | 19 +++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/lib/scripts/layout2layout.py b/lib/scripts/layout2layout.py index e5b0da9674..4680c1f1be 100644 --- a/lib/scripts/layout2layout.py +++ b/lib/scripts/layout2layout.py @@ -91,13 +91,25 @@ def trim_eol(line): 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 diff --git a/src/Lexer.cpp b/src/Lexer.cpp index 546ae0e9e9..e99875b286 100644 --- a/src/Lexer.cpp +++ b/src/Lexer.cpp @@ -20,6 +20,7 @@ #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" @@ -251,7 +252,8 @@ bool Lexer::Pimpl::setFile(FileName const & filename) 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"); @@ -266,8 +268,21 @@ bool Lexer::Pimpl::setFile(FileName const & filename) 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; } -- 2.39.2