mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
Fix thinko in Buffer::makeLaTeXFile
* src/encoding.[Ch] (getEncoding): rename to getFromLyXName (getFromLaTeXName): new, it does what the name says * src/buffer.C (Buffer::makeLaTeXFile): Fix crash by using getFromLaTeXName instead of getFromLyXName. Avoid crash for unknown encodings. * src/language.C (Languages::read): Adjust to name change above git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15703 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
4416bb3609
commit
b67e933869
17
src/buffer.C
17
src/buffer.C
@ -817,9 +817,20 @@ bool Buffer::makeLaTeXFile(string const & fname,
|
|||||||
OutputParams const & runparams,
|
OutputParams const & runparams,
|
||||||
bool output_preamble, bool output_body)
|
bool output_preamble, bool output_body)
|
||||||
{
|
{
|
||||||
string const encoding = (params().inputenc == "auto") ?
|
string encoding;
|
||||||
params().language->encoding()->iconvName() :
|
if (params().inputenc == "auto")
|
||||||
encodings.getEncoding(params().inputenc)->iconvName();
|
encoding = params().language->encoding()->iconvName();
|
||||||
|
else {
|
||||||
|
Encoding const * enc = encodings.getFromLaTeXName(params().inputenc);
|
||||||
|
if (enc)
|
||||||
|
encoding = enc->iconvName();
|
||||||
|
else {
|
||||||
|
lyxerr << "Unknown inputenc value `"
|
||||||
|
<< params().inputenc
|
||||||
|
<< "'. Using `auto' instead." << endl;
|
||||||
|
encoding = params().language->encoding()->iconvName();
|
||||||
|
}
|
||||||
|
}
|
||||||
lyxerr[Debug::LATEX] << "makeLaTeXFile encoding: "
|
lyxerr[Debug::LATEX] << "makeLaTeXFile encoding: "
|
||||||
<< encoding << "..." << endl;
|
<< encoding << "..." << endl;
|
||||||
|
|
||||||
|
@ -224,15 +224,45 @@ char_type Encodings::transformChar(char_type c,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Encoding const * Encodings::getEncoding(string const & encoding) const
|
Encoding const * Encodings::getFromLyXName(string const & name) const
|
||||||
{
|
{
|
||||||
EncodingList::const_iterator it = encodinglist.find(encoding);
|
EncodingList::const_iterator it = encodinglist.find(name);
|
||||||
if (it != encodinglist.end())
|
if (it != encodinglist.end())
|
||||||
return &it->second;
|
return &it->second;
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
class LaTeXNamesEqual : public std::unary_function<std::pair<std::string, Encoding>, bool> {
|
||||||
|
public:
|
||||||
|
LaTeXNamesEqual(string const & LaTeXName)
|
||||||
|
: LaTeXName_(LaTeXName) {}
|
||||||
|
bool operator()(std::pair<std::string, Encoding> const & encoding) const
|
||||||
|
{
|
||||||
|
return encoding.second.latexName() == LaTeXName_;
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
string LaTeXName_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace anon
|
||||||
|
|
||||||
|
|
||||||
|
Encoding const * Encodings::getFromLaTeXName(string const & name) const
|
||||||
|
{
|
||||||
|
EncodingList::const_iterator const it =
|
||||||
|
std::find_if(encodinglist.begin(), encodinglist.end(),
|
||||||
|
LaTeXNamesEqual(name));
|
||||||
|
if (it != encodinglist.end())
|
||||||
|
return &it->second;
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Encodings::Encodings()
|
Encodings::Encodings()
|
||||||
{
|
{
|
||||||
symbol_encoding_ = Encoding("symbol", "", "");
|
symbol_encoding_ = Encoding("symbol", "", "");
|
||||||
|
@ -56,8 +56,10 @@ public:
|
|||||||
Encodings();
|
Encodings();
|
||||||
///
|
///
|
||||||
void read(std::string const & filename);
|
void read(std::string const & filename);
|
||||||
///
|
/// Get encoding from LyX name \p name
|
||||||
Encoding const * getEncoding(std::string const & encoding) const;
|
Encoding const * getFromLyXName(std::string const & name) const;
|
||||||
|
/// Get encoding from LaTeX name \p name
|
||||||
|
Encoding const * getFromLaTeXName(std::string const & name) const;
|
||||||
///
|
///
|
||||||
Encoding const * symbol_encoding() { return &symbol_encoding_; }
|
Encoding const * symbol_encoding() { return &symbol_encoding_; }
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ void Languages::read(string const & filename)
|
|||||||
{
|
{
|
||||||
// We need to set the encoding of latex_lang
|
// We need to set the encoding of latex_lang
|
||||||
latex_lang = Language("latex", "latex", "Latex", false, "iso8859-1",
|
latex_lang = Language("latex", "latex", "Latex", false, "iso8859-1",
|
||||||
encodings.getEncoding("iso8859-1"),
|
encodings.getFromLyXName("iso8859-1"),
|
||||||
"latex", "");
|
"latex", "");
|
||||||
|
|
||||||
LyXLex lex(0, 0);
|
LyXLex lex(0, 0);
|
||||||
@ -72,9 +72,9 @@ void Languages::read(string const & filename)
|
|||||||
if (lex.next())
|
if (lex.next())
|
||||||
latex_options = lex.getString();
|
latex_options = lex.getString();
|
||||||
|
|
||||||
Encoding const * encoding = encodings.getEncoding(encoding_str);
|
Encoding const * encoding = encodings.getFromLyXName(encoding_str);
|
||||||
if (!encoding) {
|
if (!encoding) {
|
||||||
encoding = encodings.getEncoding("iso8859-1");
|
encoding = encodings.getFromLyXName("iso8859-1");
|
||||||
lyxerr << "Unknown encoding " << encoding_str << endl;
|
lyxerr << "Unknown encoding " << encoding_str << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user