]> git.lyx.org Git - lyx.git/blobdiff - src/Encoding.cpp
Fix scale parameter for fonts.
[lyx.git] / src / Encoding.cpp
index a231106d245a7cfc1d0e6901b08295b406a9967e..dcf65d7f66ea1f318c23d6e242d8415192750239 100644 (file)
@@ -25,6 +25,7 @@
 #include <boost/cstdint.hpp>
 
 #include <sstream>
+#include <algorithm>
 
 using namespace std;
 using namespace lyx::support;
@@ -256,9 +257,9 @@ const char * EncodingException::what() const throw()
 
 
 CharInfo::CharInfo(
-       docstring const textcommand, docstring const mathcommand,
-       std::string const textpreamble, std::string const mathpreamble,
-       std::string const tipashortcut, unsigned int flags)
+       docstring const & textcommand, docstring const & mathcommand,
+       std::string const & textpreamble, std::string const & mathpreamble,
+       std::string const tipashortcut, unsigned int flags)
        : textcommand_(textcommand), mathcommand_(mathcommand),
          textpreamble_(textpreamble), mathpreamble_(mathpreamble),
          tipashortcut_(tipashortcut), flags_(flags)
@@ -379,7 +380,7 @@ pair<docstring, bool> Encoding::latexChar(char_type c) const
 }
 
 
-pair<docstring, docstring> Encoding::latexString(docstring const input, bool dryrun) const
+pair<docstring, docstring> Encoding::latexString(docstring const input, bool dryrun) const
 {
        docstring result;
        docstring uncodable;
@@ -537,8 +538,11 @@ docstring Encodings::fromLaTeXCommand(docstring const & cmd, int cmdtype,
                if (j + 1 < cmdend && cmd[j + 1] == '{') {
                        size_t k = j + 1;
                        int count = 1;
-                       while (k < cmdend && count && k != docstring::npos) {
+                       while (k < cmdend && count) {
                                k = cmd.find_first_of(from_ascii("{}"), k + 1);
+                               // braces may not be balanced
+                               if (k == docstring::npos)
+                                       break;
                                if (cmd[k] == '{')
                                        ++count;
                                else
@@ -603,8 +607,11 @@ docstring Encodings::fromLaTeXCommand(docstring const & cmd, int cmdtype,
                            k < cmdend && cmd[k] == '{') {
                                size_t l = k;
                                int count = 1;
-                               while (l < cmdend && count && l != docstring::npos) {
+                               while (l < cmdend && count) {
                                        l = cmd.find_first_of(from_ascii("{}"), l + 1);
+                                       // braces may not be balanced
+                                       if (l == docstring::npos)
+                                               break;
                                        if (cmd[l] == '{')
                                                ++count;
                                        else