]> git.lyx.org Git - lyx.git/blobdiff - src/Lexer.cpp
GuiBox.cpp: fix this issue: horizontal box alignment is only possible without inner...
[lyx.git] / src / Lexer.cpp
index 546ae0e9e9e865cd7834ebe667421abc30db618b..778a0f2218338df5e781a6feacb35da599752eee 100644 (file)
@@ -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"
@@ -249,9 +250,10 @@ bool Lexer::Pimpl::setFile(FileName const & filename)
                                "file or stream already set.");
                gz_.open(filename.toFilesystemEncoding().c_str(), ios::in);
                is.rdbuf(&gz_);
-               name = filename.absFilename();
+               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");
 
@@ -262,12 +264,25 @@ bool Lexer::Pimpl::setFile(FileName const & filename)
                        LYXERR(Debug::LYXLEX, "Error in Lexer::setFile: "
                                "file or stream already set.");
                }
-               fb_.open(filename.toFilesystemEncoding().c_str(), ios::in);
+               fb_.open(filename.toSafeFilesystemEncoding().c_str(), ios::in);
                is.rdbuf(&fb_);
-               name = filename.absFilename();
+               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;
 }