#include "support/filetools.h"
#include "support/lstrings.h"
+#include <boost/assert.hpp>
+
+#include <algorithm>
#include <iostream>
#include <map>
#include <sstream>
}
-class isLayout : public unary_function<LayoutPtr, bool> {
-public:
- isLayout(string const name) : name_(name) {}
- bool operator()(LayoutPtr const & ptr) const {
- return ptr->latexname() == name_;
- }
-private:
- string const name_;
-};
-
-
-LayoutPtr findLayout(TextClass const & textclass,
- string const & name)
+LayoutPtr findLayout(TextClass const & textclass, string const & name)
{
- TextClass::const_iterator beg = textclass.begin();
- TextClass::const_iterator end = textclass.end();
-
- TextClass::const_iterator
- it = find_if(beg, end, isLayout(name));
-
- return (it == end) ? LayoutPtr() : *it;
+ DocumentClass::const_iterator lit = textclass.begin();
+ DocumentClass::const_iterator len = textclass.end();
+ for (; lit != len; ++lit)
+ if (lit->latexname() == name)
+ return &*lit;
+ return LayoutPtr();
}
}
// The single '=' is meant here.
- else if ((newlayout = findLayout(parent_context.textclass, name)).get() &&
+ else if ((newlayout = findLayout(parent_context.textclass, name)) &&
newlayout->isEnvironment()) {
eat_whitespace(p, os, parent_context, false);
Context context(true, parent_context.textclass, newlayout,
// always must be in an own paragraph.
context.new_paragraph(os);
Context newcontext(true, context.textclass,
- context.textclass[from_ascii("Scrap")]);
+ &context.textclass[from_ascii("Scrap")]);
newcontext.check_layout(os);
os << name;
while (p.good()) {
else if ((p.next_token().asInput() == "*") &&
context.new_layout_allowed &&
// The single '=' is meant here.
- (newlayout = findLayout(context.textclass,
- t.cs() + '*')).get() &&
- newlayout->isCommand()) {
+ (newlayout = findLayout(context.textclass, t.cs() + '*')) &&
+ newlayout->isCommand()) {
p.get_token();
output_command_layout(os, p, outer, context, newlayout);
p.skip_spaces();
// The single '=' is meant here.
else if (context.new_layout_allowed &&
- (newlayout = findLayout(context.textclass, t.cs())).get() &&
+ (newlayout = findLayout(context.textclass, t.cs())) &&
newlayout->isCommand()) {
output_command_layout(os, p, outer, context, newlayout);
p.skip_spaces();
}
else if (t.cs() == "newcommand" ||
- t.cs() == "providecommand" ||
- t.cs() == "renewcommand" ||
- t.cs() == "newlyxcommand") {
+ t.cs() == "providecommand" ||
+ t.cs() == "renewcommand" ||
+ t.cs() == "newlyxcommand") {
// these could be handled by parse_command(), but
// we need to call add_known_command() here.
string name = t.asInput();
}
string const command = p.verbatim_item();
string const opt1 = p.getOpt();
- string const opt2 = p.getFullOpt();
- add_known_command(command, opt1, !opt2.empty());
- string const ert = name + '{' + command + '}' +
- opt1 + opt2 +
- '{' + p.verbatim_item() + '}';
+ string optionals;
+ unsigned optionalsNum = 0;
+ while (true) {
+ string const opt = p.getFullOpt();
+ if (opt.empty())
+ break;
+ optionalsNum++;
+ optionals += opt;
+ }
+ add_known_command(command, opt1, optionalsNum);
+ string const ert = name + '{' + command + '}' + opt1
+ + optionals + '{' + p.verbatim_item() + '}';
context.check_layout(os);
begin_inset(os, "FormulaMacro");