From d17f1a298a30633a8376dfd729c3ada9f1a6a5a2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=BCrgen=20Spitzm=C3=BCller?= Date: Mon, 15 Sep 2008 14:19:00 +0000 Subject: [PATCH] * src/InsetIndex.cpp: - fix LaTeX output with unrepresentable characters in current encoding (bug 5022). git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@26412 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/insets/InsetIndex.cpp | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/insets/InsetIndex.cpp b/src/insets/InsetIndex.cpp index 00da6df8be..fa13bdc0f5 100644 --- a/src/insets/InsetIndex.cpp +++ b/src/insets/InsetIndex.cpp @@ -13,6 +13,7 @@ #include "Buffer.h" #include "DispatchResult.h" +#include "Encoding.h" #include "FuncRequest.h" #include "FuncStatus.h" #include "LaTeXFeatures.h" @@ -25,6 +26,8 @@ #include "support/gettext.h" #include "support/lstrings.h" +#include "frontends/alert.h" + #include using namespace std; @@ -106,10 +109,31 @@ int InsetIndex::latex(odocstream & os, if (contains(*it, '\\') && !contains(*it, '@')) { // Plaintext might return nothing (e.g. for ERTs) docstring const spart = - (it2 < levels_plain.end() && !(*it2).empty()) ? *it2 : *it; + (it2 < levels_plain.end() && !(*it2).empty()) + ? *it2 : *it; + // Now we need to validate that all characters in + // the sorting part are representable in the current + // encoding. If not try the LaTeX macro which might + // or might not be a good choice, and issue a warning. + docstring spart2; + for (int n = 0; n < spart.size(); ++n) { + try { + spart2 += runparams.encoding->latexChar(spart[n]); + } catch (EncodingException & /* e */) { + LYXERR0("Uncodable character in index entry. Sorting might be wrong!"); + } + } + if (spart != spart2 && !runparams.dryrun) { + // FIXME: warning should be passed to the error dialog + frontend::Alert::warning(_("Index sorting failed"), + bformat(_("LyX's automatic index sorting algorithm faced\n" + "problems with the entry '%1$s'.\n" + "Please specify the sorting of this entry manually, as\n" + "explained in the User Guide."), spart)); + } // remove remaining \'s for the sorting part docstring const ppart = - subst(spart, from_ascii("\\"), docstring()); + subst(spart2, from_ascii("\\"), docstring()); os << ppart; os << '@'; i += ppart.size() + 1; -- 2.39.2