From e6af49a9f57028474e95f6ae162e93995d20f28e Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Sat, 22 Mar 2014 12:02:21 +0100 Subject: [PATCH] InsetListings: Rewrite C-ism in C++ and fix terminator bug. The rewriting is completely done by JMarc. The terminator bug fix has been added to that by me. Fixes: #8985 Conflicts: src/insets/InsetListings.cpp --- src/insets/InsetListings.cpp | 30 +++++++++++++++--------------- status.20x | 6 ++++++ 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/insets/InsetListings.cpp b/src/insets/InsetListings.cpp index f45bde4d4b..1398ccad15 100644 --- a/src/insets/InsetListings.cpp +++ b/src/insets/InsetListings.cpp @@ -50,9 +50,6 @@ using namespace lyx::support; namespace lyx { -char const lstinline_delimiters[] = - "!*()-=+|;:'\"`,<.>/?QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm"; - InsetListings::InsetListings(Buffer * buf, InsetListingsParams const & par) : InsetCollapsable(buf) { @@ -202,17 +199,18 @@ void InsetListings::latex(otexstream & os, OutputParams const & runparams) const code += "\n"; } if (isInline) { - char const * delimiter = lstinline_delimiters; - for (; delimiter != '\0'; ++delimiter) - if (!contains(code, *delimiter)) - break; + static const docstring delimiters = + from_utf8("!*()-=+|;:'\"`,<.>/?QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm"); + + size_t pos = delimiters.find_first_not_of(code); + // This code piece contains all possible special character? !!! // Replace ! with a warning message and use ! as delimiter. - if (*delimiter == '\0') { + if (pos == string::npos) { docstring delim_error = "<" + _("LyX Warning: ") + _("no more lstline delimiters available") + ">"; code = subst(code, from_ascii("!"), delim_error); - delimiter = lstinline_delimiters; + pos = 0; if (!runparams.dryrun) { // FIXME: warning should be passed to the error dialog frontend::Alert::warning(_("Running out of delimiters"), @@ -223,12 +221,14 @@ void InsetListings::latex(otexstream & os, OutputParams const & runparams) const "must investigate!")); } } - if (param_string.empty()) - os << "\\lstinline" << *delimiter; - else - os << "\\lstinline[" << from_utf8(param_string) << "]" << *delimiter; - os << code - << *delimiter; + docstring const delim(1, delimiters[pos]); + os << "\\lstinline"; + if (!param_string.empty()) + os << "[" << from_utf8(param_string) << "]"; + else if (pos >= delimiters.find('Q')) + // We need to terminate the command before the delimiter + os << " "; + os << delim << code << delim; } else { OutputParams rp = runparams; rp.moving_arg = true; diff --git a/status.20x b/status.20x index 8435f8de42..07118ef610 100644 --- a/status.20x +++ b/status.20x @@ -70,6 +70,9 @@ What's new - Fix problem with export of LyX archive when bibtotoc is used (bug 9044). +- Fix LaTeX error with alphabetic delimiters in inline Listings (part of bug + 8985). + * USER INTERFACE @@ -144,4 +147,7 @@ What's new - Improve detection of Qt via pkg-config, especially on Mac OS. +- Fix bad compare of pointer vs. character (part of bug 8985). + - Fix a couple of compilation warnings. +