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"
24 InsetCommandParams::InsetCommandParams()
28 InsetCommandParams::InsetCommandParams(string const & n,
31 : cmdname(n), contents(c), options(o), preview_(false)
35 void InsetCommandParams::scanCommand(string const & cmd)
37 string tcmdname, toptions, tcontents;
39 if (cmd.empty()) return;
41 enum { WS, CMDNAME, OPTION, CONTENT } state = WS;
43 // Used to handle things like \command[foo[bar]]{foo{bar}}
46 for (string::size_type i = 0; i < cmd.length(); ++i) {
48 if ((state == CMDNAME && c == ' ') ||
49 (state == CMDNAME && c == '[') ||
50 (state == CMDNAME && c == '{')) {
53 if ((state == OPTION && c == ']') ||
54 (state == CONTENT && c == '}')) {
61 if ((state == OPTION && c == '[') ||
62 (state == CONTENT && c == '{')) {
66 case CMDNAME: tcmdname += c; break;
67 case OPTION: toptions += c; break;
68 case CONTENT: tcontents += c; break;
72 } else if (c == '[') {
74 nestdepth = 0; // Just to be sure
75 } else if (c == '{') {
77 nestdepth = 0; // Just to be sure
83 // Don't mess with this.
84 if (!tcmdname.empty()) setCmdName(tcmdname);
85 if (!toptions.empty()) setOptions(toptions);
86 if (!tcontents.empty()) setContents(tcontents);
88 if (lyxerr.debugging(Debug::PARSER))
89 lyxerr << "Command <" << cmd
90 << "> == <" << getCommand()
91 << "> == <" << getCmdName()
92 << '|' << getContents()
93 << '|' << getOptions() << '>' << endl;
97 void InsetCommandParams::read(LyXLex & lex)
102 token = lex.getString();
105 lex.printError("InsetCommand: Parse error: `$$Token'");
110 token = lex.getString();
111 if (token == "\\end_inset")
113 if (token == "preview") {
115 preview_ = lex.getBool();
118 if (token != "\\end_inset") {
119 lex.printError("Missing \\end_inset at this point. "
125 void InsetCommandParams::write(ostream & os) const
127 os << "LatexCommand " << getCommand() << "\n";
131 string const InsetCommandParams::getCommand() const
134 if (!getCmdName().empty()) s += '\\' + getCmdName();
135 if (!getOptions().empty()) s += '[' + getOptions() + ']';
136 s += '{' + getContents() + '}';
141 bool operator==(InsetCommandParams const & o1,
142 InsetCommandParams const & o2)
144 return o1.getCmdName() == o2.getCmdName()
145 && o1.getContents() == o2.getContents()
146 && o1.getOptions() == o2.getOptions()
147 && o1.preview() == o2.preview();
151 bool operator!=(InsetCommandParams const & o1,
152 InsetCommandParams const & o2)