mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-24 13:48:59 +00:00
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
This commit is contained in:
parent
f4f5178d4f
commit
e31e71a7a9
@ -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
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user