Cleanup in order to better understand bug 3043 and 3561.

* switchEncoding(): simplify return logic (transform 'and -> do' to 'or ->return')


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18224 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2007-05-07 17:10:10 +00:00
parent 93bca90c8e
commit b5ff27fdd1

View File

@ -603,46 +603,54 @@ int switchEncoding(odocstream & os, BufferParams const & bparams,
bool moving_arg, Encoding const & oldEnc, bool moving_arg, Encoding const & oldEnc,
Encoding const & newEnc) Encoding const & newEnc)
{ {
if ((bparams.inputenc != "auto" || moving_arg)
&& bparams.inputenc != "default")
return 0;
// Do nothing if the encoding is unchanged.
if (oldEnc.name() == newEnc.name())
return 0;
// FIXME We ignore encoding switches from/to encodings that do // FIXME We ignore encoding switches from/to encodings that do
// neither support the inputenc package nor the CJK package here. // neither support the inputenc package nor the CJK package here.
// This does of course only work in special cases (e.g. switch from // This does of course only work in special cases (e.g. switch from
// tis620-0 to latin1, but the text in latin1 contains ASCII only, // tis620-0 to latin1, but the text in latin1 contains ASCII only,
// but it is the best we can do // but it is the best we can do
if (((bparams.inputenc == "auto" && !moving_arg) || if (oldEnc.package() == Encoding::none
bparams.inputenc == "default") && || newEnc.package() == Encoding::none)
oldEnc.name() != newEnc.name() && return 0;
oldEnc.package() != Encoding::none &&
newEnc.package() != Encoding::none) { LYXERR(Debug::LATEX) << "Changing LaTeX encoding from "
LYXERR(Debug::LATEX) << "Changing LaTeX encoding from " << oldEnc.name() << " to "
<< oldEnc.name() << " to " << newEnc.name() << endl;
<< newEnc.name() << endl; os << setEncoding(newEnc.iconvName());
os << setEncoding(newEnc.iconvName()); if (bparams.inputenc == "default")
if (bparams.inputenc != "default") { return 0;
docstring const inputenc(from_ascii(newEnc.latexName()));
switch (newEnc.package()) { docstring const inputenc(from_ascii(newEnc.latexName()));
case Encoding::none: switch (newEnc.package()) {
break; case Encoding::none:
case Encoding::inputenc: { return 0;
int count = inputenc.length(); case Encoding::inputenc: {
if (oldEnc.package() == Encoding::CJK) { int count = inputenc.length();
os << "\\end{CJK}"; if (oldEnc.package() == Encoding::CJK) {
count += 9; os << "\\end{CJK}";
} count += 9;
os << "\\inputencoding{" << inputenc << '}';
return count + 16;
}
case Encoding::CJK: {
int count = inputenc.length();
if (oldEnc.package() == Encoding::CJK) {
os << "\\end{CJK}";
count += 9;
}
os << "\\begin{CJK}{" << inputenc << "}{}";
return count + 15;
}
} }
os << "\\inputencoding{" << inputenc << '}';
return count + 16;
}
case Encoding::CJK: {
int count = inputenc.length();
if (oldEnc.package() == Encoding::CJK) {
os << "\\end{CJK}";
count += 9;
}
os << "\\begin{CJK}{" << inputenc << "}{}";
return count + 15;
} }
} }
// Dead code to avoid a warning:
return 0; return 0;
} }