]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetCommandParams.cpp
Split pdf format as discussed on the list
[lyx.git] / src / insets / InsetCommandParams.cpp
index 31ea514a79549aa9a835d2dfb338be258e5d3e05..dfa0705decbfaa00d38f25d5b5cdc4f7f780c3db 100644 (file)
@@ -84,7 +84,7 @@ static ParamInfo const & findInfo(InsetCode code, string const & cmdName)
        default:
                LASSERT(false, /**/);
        }
-       static const ParamInfo pi;
+       static ParamInfo pi;
        return pi; // to silence the warning
 }
 
@@ -365,48 +365,33 @@ bool InsetCommandParams::writeEmptyOptional(ParamInfo::const_iterator ci) const
 }
 
 
-
 docstring InsetCommandParams::prepareCommand(OutputParams const & runparams,
                                             docstring const & command,
                                             ParamInfo::ParamHandling handling) const
 {
        docstring result;
-       if (handling == ParamInfo::HANDLING_LATEXIFY) {
-               docstring uncodable;
-               for (size_t n = 0; n < command.size(); ++n) {
-                       try {
-                               char_type const c = command[n];
-                               docstring const latex = runparams.encoding->latexChar(c);
-                               result += latex;
-                               if (latex.length() > 1 && latex[latex.length() - 1] != '}') {
-                                       // Prevent eating of a following
-                                       // space or command corruption by
-                                       // following characters
-                                       result +=  "{}";
-                               }
-                       } catch (EncodingException & /* e */) {
-                               LYXERR0("Uncodable character in command inset!");
-                               if (runparams.dryrun) {
-                                       result += "<" + _("LyX Warning: ")
-                                               + _("uncodable character") + " '";
-                                       result += docstring(1, command[n]);
-                                       result += "'>";
-                               } else
-                                       uncodable += command[n];
-                       }
-               }
-               if (!uncodable.empty()) {
+       switch (handling) {
+       case ParamInfo::HANDLING_LATEXIFY: {
+               pair<docstring, docstring> command_latexed =
+                       runparams.encoding->latexString(command, runparams.dryrun);
+               result = command_latexed.first;
+               if (!command_latexed.second.empty()) {
                        // issue a warning about omitted characters
                        // FIXME: should be passed to the error dialog
                        frontend::Alert::warning(_("Uncodable characters"),
                                bformat(_("The following characters that are used in the inset %1$s are not\n"
                                          "representable in the current encoding and therefore have been omitted:\n%2$s."),
-                                       from_utf8(insetType()), uncodable));
+                                       from_utf8(insetType()), command_latexed.second));
                }
-       } else if (handling == ParamInfo::HANDLING_ESCAPE)
+               break;
+       } 
+       case ParamInfo::HANDLING_ESCAPE:
                result = escape(command);
-       else
+               break;
+       case ParamInfo::HANDLING_NONE:
                result = command;
+               break;
+       } // switch
 
        return result;
 }
@@ -425,14 +410,14 @@ docstring InsetCommandParams::getCommand(OutputParams const & runparams) const
                        break;
 
                case ParamInfo::LATEX_REQUIRED: {
-                       docstring const data =
+                       docstring const data =
                                prepareCommand(runparams, (*this)[name], it->handling());
                        s += '{' + data + '}';
                        noparam = false;
                        break;
                }
                case ParamInfo::LATEX_OPTIONAL: {
-                       docstring const data =
+                       docstring const data =
                                prepareCommand(runparams, (*this)[name], it->handling());
                        if (!data.empty()) {
                                s += '[' + data + ']';