2 * \file insetcommandparams.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Angus Leeming
8 * Full author contact details are available in file CREDITS.
13 #include "insetcommandparams.h"
22 InsetCommandParams::InsetCommandParams()
26 InsetCommandParams::InsetCommandParams(string const & n,
29 : cmdname(n), contents(c), options(o), preview_(false)
33 void InsetCommandParams::scanCommand(string const & cmd)
35 string tcmdname, toptions, tcontents;
37 if (cmd.empty()) return;
39 enum { WS, CMDNAME, OPTION, CONTENT } state = WS;
41 // Used to handle things like \command[foo[bar]]{foo{bar}}
44 for (string::size_type i = 0; i < cmd.length(); ++i) {
46 if ((state == CMDNAME && c == ' ') ||
47 (state == CMDNAME && c == '[') ||
48 (state == CMDNAME && c == '{')) {
51 if ((state == OPTION && c == ']') ||
52 (state == CONTENT && c == '}')) {
59 if ((state == OPTION && c == '[') ||
60 (state == CONTENT && c == '{')) {
64 case CMDNAME: tcmdname += c; break;
65 case OPTION: toptions += c; break;
66 case CONTENT: tcontents += c; break;
70 } else if (c == '[') {
72 nestdepth = 0; // Just to be sure
73 } else if (c == '{') {
75 nestdepth = 0; // Just to be sure
81 // Don't mess with this.
82 if (!tcmdname.empty()) setCmdName(tcmdname);
83 if (!toptions.empty()) setOptions(toptions);
84 if (!tcontents.empty()) setContents(tcontents);
86 if (lyxerr.debugging(Debug::PARSER))
87 lyxerr << "Command <" << cmd
88 << "> == <" << getCommand()
89 << "> == <" << getCmdName()
90 << '|' << getContents()
91 << '|' << getOptions() << '>' << endl;
95 void InsetCommandParams::read(LyXLex & lex)
100 token = lex.getString();
103 lex.printError("InsetCommand: Parse error: `$$Token'");
108 token = lex.getString();
109 if (token == "\\end_inset")
111 if (token == "preview") {
113 preview_ = lex.getBool();
116 if (token != "\\end_inset") {
117 lex.printError("Missing \\end_inset at this point. "
123 void InsetCommandParams::write(ostream & os) const
125 os << "LatexCommand " << getCommand() << "\n";
129 string const InsetCommandParams::getCommand() const
132 if (!getCmdName().empty()) s += '\\' + getCmdName();
133 if (!getOptions().empty()) s += '[' + getOptions() + ']';
134 s += '{' + getContents() + '}';
139 bool operator==(InsetCommandParams const & o1,
140 InsetCommandParams const & o2)
142 return o1.getCmdName() == o2.getCmdName()
143 && o1.getContents() == o2.getContents()
144 && o1.getOptions() == o2.getOptions()
145 && o1.preview() == o2.preview();
149 bool operator!=(InsetCommandParams const & o1,
150 InsetCommandParams const & o2)