]> git.lyx.org Git - features.git/commitdiff
InsetListings: Rewrite C-ism in C++ and fix terminator bug.
authorJuergen Spitzmueller <spitz@lyx.org>
Sat, 22 Mar 2014 11:02:21 +0000 (12:02 +0100)
committerRichard Heck <rgheck@lyx.org>
Fri, 18 Apr 2014 14:52:46 +0000 (10:52 -0400)
The rewriting is completely done by JMarc. The terminator bug fix has been added to that by me.

Fixes: #8985
src/insets/InsetListings.cpp
status.21x

index 3ed00d4682ef242ccd54dfa77c98bc9da208249e..3d8225e08af4c95bad4e59025f55c568acc34917 100644 (file)
@@ -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 && !runparams.silent) {
                                // 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;
index beb8f74aaba4ebc1f541dedd6a51690926779eaf..2e8a172783ffeae916e7ac68892264ea797a7545 100644 (file)
@@ -51,6 +51,9 @@ What's new
 
 * DOCUMENT INPUT/OUTPUT
 
+- Fix LaTeX error with alphabetic delimiters in inline Listings (part of bug
+  8985).
+
 
 
 * USER INTERFACE
@@ -79,3 +82,5 @@ What's new
 
 * BUILD/INSTALLATION
 
+- Fix bad compare of pointer vs. character (part of bug 8985).
+