#include <boost/cstdint.hpp>
#include <sstream>
+#include <algorithm>
using namespace std;
using namespace lyx::support;
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)
}
-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;
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
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