]> git.lyx.org Git - features.git/commitdiff
Implement ParamInfo::HANDLING_LTRIM and use it to ltrim InsetBibitem
authorJuergen Spitzmueller <spitz@lyx.org>
Mon, 23 Oct 2017 06:20:58 +0000 (08:20 +0200)
committerJuergen Spitzmueller <spitz@lyx.org>
Mon, 23 Oct 2017 06:20:58 +0000 (08:20 +0200)
output

See #9847.

src/insets/InsetBibitem.cpp
src/insets/InsetCommandParams.cpp
src/insets/InsetCommandParams.h

index d5ebaf7640c723422952e0c602f2d05343a983ae..08e8c7666549cfa82e2686601fc0ab259ad77e62 100644 (file)
@@ -112,7 +112,8 @@ ParamInfo const & InsetBibitem::findInfo(string const & /* cmdName */)
                param_info_.add("label", ParamInfo::LATEX_OPTIONAL,
                                ParamInfo::HANDLING_LATEXIFY);
                param_info_.add("key", ParamInfo::LATEX_REQUIRED,
-                               ParamInfo::HANDLING_ESCAPE);
+                               ParamInfo::ParamHandling(ParamInfo::HANDLING_ESCAPE
+                                                        | ParamInfo::HANDLING_LTRIM));
                param_info_.add("literal", ParamInfo::LYX_INTERNAL);
        }
        return param_info_;
index 9d34808d415c668f81ef81e32b60d1f46dfb69d3..aa2458ce87100d2e16f614210f7f1f45f3c6caba 100644 (file)
@@ -432,12 +432,21 @@ docstring InsetCommandParams::prepareCommand(OutputParams const & runparams,
                                             docstring const & command,
                                             ParamInfo::ParamHandling handling) const
 {
-       if (handling == ParamInfo::HANDLING_LATEXIFY)
+       docstring result;
+       bool ltrimmed = false;
+       // Trimming can be done on top of any of the other handlings
+       // We check this here since handling might be changed below.
+       if (handling & ParamInfo::HANDLING_LTRIM) {
+               // this is used if no other handling is done
+               result = command;
+               ltrimmed = true;
+       }
+       if (handling & ParamInfo::HANDLING_LATEXIFY)
                if ((*this)["literal"] == "true")
                        handling = ParamInfo::HANDLING_NONE;
-       docstring result;
-       switch (handling) {
-       case ParamInfo::HANDLING_LATEXIFY: {
+
+       // LATEXIFY, ESCAPE and NONE are mutually exclusive
+       if (handling & ParamInfo::HANDLING_LATEXIFY) {
                // First handle backslash
                result = subst(command, from_ascii("\\"), from_ascii("\\textbackslash{}"));
                // Then get LaTeX macros
@@ -476,17 +485,13 @@ docstring InsetCommandParams::prepareCommand(OutputParams const & runparams,
                                                        result.replace(pos, 1, backslash + chars_escape[k] + term);
                                }
                }
-               break;
        }
-       case ParamInfo::HANDLING_ESCAPE:
+       else if (handling & ParamInfo::HANDLING_ESCAPE)
                result = escape(command);
-               break;
-       case ParamInfo::HANDLING_NONE:
+       else if (handling & ParamInfo::HANDLING_NONE)
                result = command;
-               break;
-       } // switch
 
-       return result;
+       return ltrimmed ? ltrim(result) : result;
 }
 
 
index 121fdac176c2af197643aa7b57fbf30f13b0892a..e82320583fc4a39856bc4a3de62387ed2af3038b 100644 (file)
@@ -42,9 +42,10 @@ public:
        };
        /// Special handling on output
        enum ParamHandling {
-               HANDLING_NONE,    /// no special handling
-               HANDLING_ESCAPE,  /// escape special characters
-               HANDLING_LATEXIFY /// transform special characters to LaTeX macros
+               HANDLING_NONE = 1,    /// no special handling
+               HANDLING_ESCAPE = 2,  /// escape special characters
+               HANDLING_LATEXIFY = 4, /// transform special characters to LaTeX macros
+               HANDLING_LTRIM = 8 /// trim blanks on the left
        };
        ///
        class ParamData {