* 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
*
#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"
"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");
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;
}
is.get(cc);
c = cc;
//LYXERR(Debug::LYXLEX, "Lexer::EatLine read char: `" << c << '\'');
- if (c != '\r')
+ if (c != '\r' && is)
buff.push_back(c);
}
}
+// 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;