]> git.lyx.org Git - features.git/blobdiff - src/Encoding.cpp
Encodings::fromLaTeXCommand: properly set needsTermination on early exit
[features.git] / src / Encoding.cpp
index 4e47daef8b0dc6d5967ece778a3d7c31423d8a90..a4c706bd3b409b30a68e46ef4b3ca3f96fe2630e 100644 (file)
@@ -381,6 +381,32 @@ docstring Encodings::fromLaTeXCommand(docstring const & cmd, int cmdtype,
        rem = empty_docstring();
        bool const mathmode = cmdtype & MATH_CMD;
        bool const textmode = cmdtype & TEXT_CMD;
+
+       // Easy case: the command is a complete entry of unicodesymbols.
+       for (const auto & unicodeSymbol : unicodesymbols) {
+               if (mathmode) {
+                       for (const auto & command : unicodeSymbol.second.mathCommands()) {
+                               if (command == cmd) {
+                                       docstring value;
+                                       value += unicodeSymbol.first;
+                                       needsTermination = !unicodeSymbol.second.mathNoTermination();
+                                       return value;
+                               }
+                       }
+               }
+               if (textmode) {
+                       for (const auto & command : unicodeSymbol.second.textCommands()) {
+                               if (command == cmd) {
+                                       docstring value;
+                                       value += unicodeSymbol.first;
+                                       needsTermination = !unicodeSymbol.second.textNoTermination();
+                                       return value;
+                               }
+                       }
+               }
+       }
+
+       // Otherwise, try to map as many commands as possible, matching prefixes of the command.
        docstring symbols;
        size_t const cmdend = cmd.size();
        size_t prefix = 0;
@@ -727,7 +753,7 @@ void Encodings::read(FileName const & encfile, FileName const & symbolsfile)
                symbol = tmp;
 
                // Special case: more than one entry for one character (to add other LaTeX commands).
-               if (unicodesymbols.contains(symbol)) {
+               if (unicodesymbols.find(symbol) != unicodesymbols.end()) {
                        if (!symbolsLex.next(true))
                                break;
                        docstring textCommand = symbolsLex.getDocString();