X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FLexer.cpp;h=e99875b28660286882eea04638e53b0848df2b3a;hb=4b7f1b3c3918cd32070c72b6d8e95a888981c7a2;hp=9061d7c0b3ab0ac7a23a25681900a720baa3f452;hpb=7382c55fd7295031928a31bed35e26c08bf343d4;p=lyx.git diff --git a/src/Lexer.cpp b/src/Lexer.cpp index 9061d7c0b3..e99875b286 100644 --- a/src/Lexer.cpp +++ b/src/Lexer.cpp @@ -4,7 +4,7 @@ * Licence details can be found in the file COPYING. * * \author Alejandro Aguilar Sierra - * \author Lars Gullik Bjønnes + * \author Lars Gullik Bjønnes * \author Jean-Marc Lasgouttes * \author John Levon * @@ -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; } @@ -901,6 +916,18 @@ string Lexer::quoteString(string const & arg) } +// same for docstring +docstring Lexer::quoteString(docstring const & arg) +{ + docstring res; + res += '"'; + res += subst(subst(arg, from_ascii("\\"), from_ascii("\\\\")), + from_ascii("\""), from_ascii("\\\"")); + res += '"'; + return res; +} + + Lexer & Lexer::operator>>(char const * required) { string token;