From 57d713065545ac53a62a641d12a8b8c2c62c22fc Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Wed, 24 Apr 2024 12:04:23 +0200 Subject: [PATCH] Force a Buffer * argument to MathData constructor In order to ensure that MathData objects have a valid buffer, the default MathData() constructor is deleted. This means that a buffer shall be specified for each MathData object created. This is fairly mechanical, actually. In particular, in most InsetMathXxx cases, in MathData and in MathParser, the available buffer_ member is used. More specific cases: - lyxfind.cpp takes the buffer from the Cursor - calls to vector::resize take an additional MathData(buffer_) parameter. There are cases where resize actually remove cells, and in this case clear() or even erase() have been used. - in InsetMathMacroTemplate, the optional parameters of the constructors cannot be allowed anymore (a default value cannot depend on another parameter). Therefore there a now two constructors instead. - in MathAutoCorrect.cpp, the MathData objects are not bound to a buffer, so that std::nullptr is used instead. - in MathExtern, use a buffer when one is specified, std::nulptr instead. --- src/lyxfind.cpp | 6 +-- src/mathed/InsetMath.cpp | 2 +- src/mathed/InsetMathGrid.cpp | 2 +- src/mathed/InsetMathHull.cpp | 8 ++-- src/mathed/InsetMathMacro.cpp | 22 +++++------ src/mathed/InsetMathMacroTemplate.cpp | 12 +++++- src/mathed/InsetMathMacroTemplate.h | 8 ++-- src/mathed/InsetMathNest.cpp | 10 ++--- src/mathed/InsetMathRef.cpp | 6 +-- src/mathed/InsetMathScript.cpp | 4 +- src/mathed/InsetMathSpace.cpp | 2 +- src/mathed/MathAutoCorrect.cpp | 4 +- src/mathed/MathData.cpp | 8 ++-- src/mathed/MathData.h | 2 +- src/mathed/MathExtern.cpp | 20 +++++----- src/mathed/MathParser.cpp | 54 +++++++++++++-------------- 16 files changed, 90 insertions(+), 80 deletions(-) diff --git a/src/lyxfind.cpp b/src/lyxfind.cpp index 6e3b324bfa..ea2f669e13 100644 --- a/src/lyxfind.cpp +++ b/src/lyxfind.cpp @@ -4131,7 +4131,7 @@ docstring stringifyFromCursor(DocIterator const & cur, int len) (( len == -1 || cs.pos() + len > int(md.size())) ? md.end() : md.begin() + cs.pos() + len ); - MathData md2; + MathData md2(cur.buffer()); for (MathData::const_iterator it = md.begin() + cs.pos(); it != it_end; ++it) md2.push_back(*it); docstring res = from_utf8(latexNamesToUtf8(asString(md2), false)); @@ -4197,7 +4197,7 @@ docstring latexifyFromCursor(DocIterator const & cur, int len) ((len == -1 || cs.pos() + len > int(md.size())) ? md.end() : md.begin() + cs.pos() + len); - MathData md2; + MathData md2(cur.buffer()); for (MathData::const_iterator it = md.begin() + cs.pos(); it != it_end; ++it) md2.push_back(*it); @@ -4861,7 +4861,7 @@ bool findAdv(BufferView * bv, FindAndReplaceOptions & opt) MathData md = cs.cell(); int len = -1; MathData::const_iterator it_end = md.end(); - MathData md2; + MathData md2(cur.buffer()); // Start the check with one character before actual cursor position for (MathData::const_iterator it = md.begin() + cs.pos() - 1; it != it_end; ++it) diff --git a/src/mathed/InsetMath.cpp b/src/mathed/InsetMath.cpp index e072b487a0..5aea5716ce 100644 --- a/src/mathed/InsetMath.cpp +++ b/src/mathed/InsetMath.cpp @@ -88,7 +88,7 @@ MathData & InsetMath::cell(idx_type) MathData const & InsetMath::cell(idx_type) const { - static MathData dummyCell; + static MathData dummyCell(const_cast(&buffer())); LYXERR0("I don't have any cell"); return dummyCell; } diff --git a/src/mathed/InsetMathGrid.cpp b/src/mathed/InsetMathGrid.cpp index 3adec0ca2b..05242aca00 100644 --- a/src/mathed/InsetMathGrid.cpp +++ b/src/mathed/InsetMathGrid.cpp @@ -835,7 +835,7 @@ void InsetMathGrid::addCol(col_type newcol) { const col_type nc = ncols(); const row_type nr = nrows(); - cells_type new_cells((nc + 1) * nr); + cells_type new_cells((nc + 1) * nr, MathData(buffer_)); vector new_cellinfo((nc + 1) * nr); for (row_type row = 0; row < nr; ++row) diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp index 34c319ea5c..9c93f89f21 100644 --- a/src/mathed/InsetMathHull.cpp +++ b/src/mathed/InsetMathHull.cpp @@ -1405,7 +1405,7 @@ docstring InsetMathHull::nicelabel(row_type row) const void InsetMathHull::glueall(HullType type) { - MathData ar; + MathData ar(buffer_); for (idx_type i = 0; i < nargs(); ++i) ar.append(cell(i)); InsetLabel * label = nullptr; @@ -1771,7 +1771,7 @@ void InsetMathHull::doExtern(Cursor & cur, FuncRequest & func) // replace selection with result of computation if (reduceSelectionToOneCell(cur)) { - MathData ar; + MathData ar(buffer_); asArray(grabAndEraseSelection(cur), ar); lyxerr << "use selection: " << ar << endl; cur.insert(pipeThroughExtern(lang, extra, ar)); @@ -1792,7 +1792,7 @@ void InsetMathHull::doExtern(Cursor & cur, FuncRequest & func) return; } - MathData eq; + MathData eq(buffer_); eq.push_back(MathAtom(new InsetMathChar('='))); // go to first item in line @@ -1801,7 +1801,7 @@ void InsetMathHull::doExtern(Cursor & cur, FuncRequest & func) if (getType() == hullSimple) { size_type pos = cur.cell().find_last(eq); - MathData ar; + MathData ar(buffer_); if (pos == cur.cell().size()) { ar = cur.cell(); lyxerr << "use whole cell: " << ar << endl; diff --git a/src/mathed/InsetMathMacro.cpp b/src/mathed/InsetMathMacro.cpp index a90bf87f5e..6a5f504661 100644 --- a/src/mathed/InsetMathMacro.cpp +++ b/src/mathed/InsetMathMacro.cpp @@ -59,10 +59,10 @@ class InsetArgumentProxy : public InsetMath { public: /// InsetArgumentProxy(InsetMathMacro * mathMacro, size_t idx) - : mathMacro_(mathMacro), idx_(idx) {} + : mathMacro_(mathMacro), idx_(idx), def_(&mathMacro->buffer()) {} /// InsetArgumentProxy(InsetMathMacro * mathMacro, size_t idx, docstring const & def) - : mathMacro_(mathMacro), idx_(idx) + : mathMacro_(mathMacro), idx_(idx), def_(&mathMacro->buffer()) { asArray(def, def_); } @@ -714,7 +714,7 @@ void InsetMathMacro::updateRepresentation(Cursor * cur, MacroContext const & mc, vector const & defaults = d->macro_->defaults(); // create MathMacroArgumentValue objects pointing to the cells of the macro - vector values(nargs()); + vector values(nargs(), MathData(buffer_)); for (size_t i = 0; i < nargs(); ++i) { InsetArgumentProxy * proxy; if (i < defaults.size()) @@ -826,11 +826,11 @@ void InsetMathMacro::setDisplayMode(InsetMathMacro::DisplayMode mode, int appeti if (d->displayMode_ != mode) { // transfer name if changing from or to DISPLAY_UNFOLDED if (mode == DISPLAY_UNFOLDED) { - cells_.resize(1); + cells_.resize(1, MathData(buffer_)); asArray(d->name_, cell(0)); } else if (d->displayMode_ == DISPLAY_UNFOLDED) { d->name_ = asString(cell(0)); - cells_.resize(0); + cells_.clear(); } d->displayMode_ = mode; @@ -1042,7 +1042,7 @@ void InsetMathMacro::removeArgument(pos_type pos) { void InsetMathMacro::insertArgument(pos_type pos) { if (d->displayMode_ == DISPLAY_NORMAL) { LASSERT(size_t(pos) <= cells_.size(), return); - cells_.insert(cells_.begin() + pos, MathData()); + cells_.insert(cells_.begin() + pos, MathData(buffer_)); if (size_t(pos) < d->attachedArgsNum_) ++d->attachedArgsNum_; if (size_t(pos) < d->optionals_) @@ -1063,12 +1063,12 @@ void InsetMathMacro::detachArguments(vector & args, bool strip) size_t i; for (i = cells_.size(); i > d->attachedArgsNum_; --i) if (!cell(i - 1).empty()) break; - args.resize(i); + args.erase(args.begin() + i, args.end()); } d->attachedArgsNum_ = 0; - d->expanded_ = MathData(); - cells_.resize(0); + d->expanded_ = MathData(buffer_); + cells_.clear(); d->needsUpdate_ = true; } @@ -1079,8 +1079,8 @@ void InsetMathMacro::attachArguments(vector const & args, size_t arity LASSERT(d->displayMode_ == DISPLAY_NORMAL, return); cells_ = args; d->attachedArgsNum_ = args.size(); - cells_.resize(arity); - d->expanded_ = MathData(); + cells_.resize(arity, MathData(buffer_)); + d->expanded_ = MathData(buffer_); d->optionals_ = optionals; d->needsUpdate_ = true; diff --git a/src/mathed/InsetMathMacroTemplate.cpp b/src/mathed/InsetMathMacroTemplate.cpp index c28c0d100f..3dbc08c02c 100644 --- a/src/mathed/InsetMathMacroTemplate.cpp +++ b/src/mathed/InsetMathMacroTemplate.cpp @@ -402,6 +402,14 @@ InsetMathMacroTemplate::InsetMathMacroTemplate(Buffer * buf) } +InsetMathMacroTemplate::InsetMathMacroTemplate(Buffer * buf, docstring const & name, int numargs, + int optionals, MacroType type) + : InsetMathMacroTemplate(buf, name, numargs, optionals, type, + vector(), MathData(buf), MathData(buf)) +{ +} + + InsetMathMacroTemplate::InsetMathMacroTemplate(Buffer * buf, docstring const & name, int numargs, int optionals, MacroType type, vector const & optionalValues, MathData const & def, MathData const & display) @@ -417,7 +425,7 @@ InsetMathMacroTemplate::InsetMathMacroTemplate(Buffer * buf, docstring const & n << numargs_ << endl; asArray(name, cell(0)); - optionalValues_.resize(9); + optionalValues_.resize(9, MathData(buffer_)); for (int i = 0; i < optionals_; ++i) cell(optIdx(i)) = optionalValues_[i]; cell(defIdx()) = def; @@ -516,7 +524,7 @@ void InsetMathMacroTemplate::createLook(int args) const look_.push_back(MathAtom(new InsetMathBrace(arg))); } for (; i < argsInLook_; ++i) { - MathData arg; + MathData arg(buffer_); arg.push_back(MathAtom(new InsetMathMacroArgument(i + 1))); look_.push_back(MathAtom(new InsetColoredCell(buffer_, Color_mathmacronewarg, diff --git a/src/mathed/InsetMathMacroTemplate.h b/src/mathed/InsetMathMacroTemplate.h index 105dcfb7ff..1fa6d00989 100644 --- a/src/mathed/InsetMathMacroTemplate.h +++ b/src/mathed/InsetMathMacroTemplate.h @@ -29,11 +29,13 @@ public: /// explicit InsetMathMacroTemplate(Buffer * buf); /// + InsetMathMacroTemplate(Buffer * buf, docstring const & name, int numargs, + int optionals, MacroType type); + /// InsetMathMacroTemplate(Buffer * buf, docstring const & name, int numargs, int optionals, MacroType type, - std::vector const & optionalValues = std::vector(), - MathData const & def = MathData(), - MathData const & display = MathData()); + std::vector const & optionalValues, + MathData const & def, MathData const & display); /// parses from string, returns false if failed bool fromString (const docstring & str); /// diff --git a/src/mathed/InsetMathNest.cpp b/src/mathed/InsetMathNest.cpp index 37bbd40008..844496d111 100644 --- a/src/mathed/InsetMathNest.cpp +++ b/src/mathed/InsetMathNest.cpp @@ -84,7 +84,7 @@ using cap::selClearOrDel; InsetMathNest::InsetMathNest(Buffer * buf, idx_type nargs) - : InsetMath(buf), cells_(nargs), lock_(false) + : InsetMath(buf), cells_(nargs, MathData(buffer_)), lock_(false) { // FIXME This should not really be necessary, but when we are // initializing the table of global macros, we create macros @@ -321,7 +321,7 @@ bool InsetMathNest::isActive() const MathData InsetMathNest::glue() const { - MathData ar; + MathData ar(buffer_); for (size_t i = 0; i < nargs(); ++i) ar.append(cell(i)); return ar; @@ -715,7 +715,7 @@ void InsetMathNest::handleFont2(Cursor & cur, docstring const & arg) cur.mathForward(false); cur.setSelection(); cutSelection(cur, false); - MathData ar; + MathData ar(buffer_); if (!sel1.empty()) { mathed_parse_cell(ar, beg + sel1 + end); cur.insert(ar); @@ -1565,7 +1565,7 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd) } case LFUN_INSET_INSERT: { - MathData ar; + MathData ar(buffer_); if (createInsetMath_fromDialogStr(cmd.argument(), ar)) { cur.recordUndoSelection(); cur.insert(ar); @@ -1942,7 +1942,7 @@ void InsetMathNest::lfunMousePress(Cursor & cur, FuncRequest & cmd) cmd = FuncRequest(LFUN_PASTE, "0"); doDispatch(bv.cursor(), cmd); } else { - MathData ar; + MathData ar(buffer_); asArray(theSelection().get(), ar); bv.cursor().insert(ar); } diff --git a/src/mathed/InsetMathRef.cpp b/src/mathed/InsetMathRef.cpp index 082a341cf4..e6d246fbb0 100644 --- a/src/mathed/InsetMathRef.cpp +++ b/src/mathed/InsetMathRef.cpp @@ -87,7 +87,7 @@ void InsetMathRef::doDispatch(Cursor & cur, FuncRequest & cmd) cur.forceBufferUpdate(); break; } - MathData ar; + MathData ar(buffer_); if (createInsetMath_fromDialogStr(cmd.argument(), ar)) { cur.recordUndo(); Buffer & buf = buffer(); @@ -97,7 +97,7 @@ void InsetMathRef::doDispatch(Cursor & cur, FuncRequest & cmd) } } else if (arg0 == "changetype") { docstring const data = from_ascii(createDialogStr(arg1)); - MathData ar; + MathData ar(buffer_); if (createInsetMath_fromDialogStr(data, ar)) { cur.recordUndo(); Buffer & buf = buffer(); @@ -276,7 +276,7 @@ void InsetMathRef::changeTarget(docstring const & target) icp["reference"] = target; if (!cell(1).empty()) icp["name"] = asString(cell(1)); - MathData ar; + MathData ar(buffer_); Buffer & buf = buffer(); if (createInsetMath_fromDialogStr( from_utf8(InsetCommand::params2string(icp)), ar)) { diff --git a/src/mathed/InsetMathScript.cpp b/src/mathed/InsetMathScript.cpp index 73e1ef9d91..6ccaaaa840 100644 --- a/src/mathed/InsetMathScript.cpp +++ b/src/mathed/InsetMathScript.cpp @@ -104,14 +104,14 @@ void InsetMathScript::ensure(bool up) { if (nargs() == 1) { // just nucleus so far - cells_.push_back(MathData()); + cells_.push_back(MathData(buffer_)); cell_1_is_up_ = up; } else if (nargs() == 2 && !has(up)) { if (up) { cells_.push_back(cell(1)); cell(1).clear(); } else { - cells_.push_back(MathData()); + cells_.push_back(MathData(buffer_)); } } } diff --git a/src/mathed/InsetMathSpace.cpp b/src/mathed/InsetMathSpace.cpp index 140e97e06b..b5f03881bf 100644 --- a/src/mathed/InsetMathSpace.cpp +++ b/src/mathed/InsetMathSpace.cpp @@ -317,7 +317,7 @@ void InsetMathSpace::doDispatch(Cursor & cur, FuncRequest & cmd) switch (cmd.action()) { case LFUN_INSET_MODIFY: if (cmd.getArg(0) == "mathspace") { - MathData ar; + MathData ar(buffer_); if (createInsetMath_fromDialogStr(cmd.argument(), ar)) { Buffer * buf = buffer_; cur.recordUndo(); diff --git a/src/mathed/MathAutoCorrect.cpp b/src/mathed/MathAutoCorrect.cpp index 5d5a7d098c..c57ff44fe7 100644 --- a/src/mathed/MathAutoCorrect.cpp +++ b/src/mathed/MathAutoCorrect.cpp @@ -38,7 +38,7 @@ class Correction { public: /// /// \brief Correction - Correction() : from2_(0) {} + Correction() : from1_(nullptr), from2_(0), to_(nullptr) {} /// bool correct(Cursor & cur, char_type c) const; /// @@ -63,7 +63,7 @@ bool Correction::read(idocstream & is) return false; if (s2.size() != 1) return false; - MathData ar1, ar3; + MathData ar1(nullptr), ar3(nullptr); mathed_parse_cell(ar1, s1); mathed_parse_cell(ar3, s3); from1_ = ar1; diff --git a/src/mathed/MathData.cpp b/src/mathed/MathData.cpp index 4c33934828..9677fddb97 100644 --- a/src/mathed/MathData.cpp +++ b/src/mathed/MathData.cpp @@ -595,7 +595,7 @@ void MathData::detachMacroParameters(DocIterator * cur, const size_type macroPos } // Otherwise we don't drop an empty optional, put it back normally - MathData optarg; + MathData optarg(buffer_); asArray(from_ascii("[]"), optarg); MathData & arg = detachedArgs[j]; @@ -709,7 +709,7 @@ void MathData::attachMacroParameters(Cursor * cur, // In the math parser we remove empty braces in the base // of a script inset, but we have to restore them here. if (scriptInset->nuc().empty()) { - MathData ar; + MathData ar(buffer_); scriptInset->nuc().push_back( MathAtom(new InsetMathBrace(ar))); } @@ -829,7 +829,7 @@ void MathData::collectOptionalParameters(Cursor * cur, // fill up empty optional parameters while (params.size() < numOptionalParams) - params.push_back(MathData()); + params.push_back(MathData(buffer_)); } @@ -889,7 +889,7 @@ void MathData::collectParameters(Cursor * cur, } } else { // the simplest case: plain inset - MathData array; + MathData array(buffer_); array.insert(0, cell); params.push_back(array); } diff --git a/src/mathed/MathData.h b/src/mathed/MathData.h index c2d731efcb..6ff477f592 100644 --- a/src/mathed/MathData.h +++ b/src/mathed/MathData.h @@ -68,7 +68,7 @@ public: public: /// - MathData() = default; + MathData() = delete; /// explicit MathData(Buffer * buf) : buffer_(buf) {} /// diff --git a/src/mathed/MathExtern.cpp b/src/mathed/MathExtern.cpp index 610878455e..0f7ad7cb0e 100644 --- a/src/mathed/MathExtern.cpp +++ b/src/mathed/MathExtern.cpp @@ -648,7 +648,7 @@ void extractFunctions(MathData & ar, ExternalMath kind) // do we have an exponent like in // 'sin' '^2' 'x' -> 'sin(x)' '^2' - MathData exp; + MathData exp(buf); extractScript(exp, jt, ar.end(), true); // create a proper inset as replacement @@ -1000,7 +1000,7 @@ void extractLims(MathData & ar) MathData x0 = MathData(buf, st + 1, s.end()); // use something behind the script as core - MathData f; + MathData f(buf); MathData::iterator tt = extractTerm(f, it + 1, ar.end()); // cleanup @@ -1155,7 +1155,7 @@ namespace { vector tmp = getVectorFromString(out, "$$"); if (tmp.size() < 2) - return MathData(); + return MathData(nullptr); out = subst(subst(tmp[1], "\\>", string()), "{\\it ", "\\mathit{"); lyxerr << "output: '" << out << "'" << endl; @@ -1193,7 +1193,7 @@ namespace { //lyxerr << "output: " << out << endl; i = out.find("\\over", i + 4); } - MathData res; + MathData res(nullptr); mathed_parse_cell(res, from_utf8(out)); return res; } @@ -1271,7 +1271,7 @@ namespace { // change \_ into _ // - MathData res; + MathData res(nullptr); mathed_parse_cell(res, from_utf8(out)); return res; } @@ -1331,7 +1331,7 @@ namespace { // ansi control sequence before, such as '\033[?1034hans = ' size_t i = out.find("ans = "); if (i == string::npos) - return MathData(); + return MathData(nullptr); out = out.substr(i + 6); // parse output as matrix or single number @@ -1416,7 +1416,7 @@ namespace { size_t pos2 = out.find("In[2]:="); if (pos1 == string::npos || pos2 == string::npos) - return MathData(); + return MathData(nullptr); // get everything from pos1+17 to pos2 out = out.substr(pos1 + 17, pos2 - pos1 - 17); @@ -1427,7 +1427,7 @@ namespace { prettifyMathematicaOutput(out, "Muserfunction", true, false); prettifyMathematicaOutput(out, "Mvariable", false, false); - MathData res; + MathData res(nullptr); mathed_parse_cell(res, from_utf8(out)); return res; } @@ -1718,12 +1718,12 @@ MathData pipeThroughExtern(string const & lang, docstring const & extra, FileName const file = libFileSearch("mathed", "extern_" + lang); if (file.empty()) { lyxerr << "converter to '" << lang << "' not found" << endl; - return MathData(); + return MathData(nullptr); } // run external sript string out = captureOutput(file.absFileName(), data); - MathData res; + MathData res(nullptr); mathed_parse_cell(res, from_utf8(out)); return res; } diff --git a/src/mathed/MathParser.cpp b/src/mathed/MathParser.cpp index 9b43da8cdd..a7791d1482 100644 --- a/src/mathed/MathParser.cpp +++ b/src/mathed/MathParser.cpp @@ -728,7 +728,7 @@ bool Parser::parse(MathAtom & at) lyxerr << "unusual contents found: " << ar << endl; at = MathAtom(new InsetMathPar(buffer_, ar)); //if (at->nargs() > 0) - // at.nucleus()->cell(0) = ar; + // at.nucleus()->cell(0) = ar(buffer_); //else // lyxerr << "unusual contents found: " << ar << endl; success_ = false; @@ -850,7 +850,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, if (flags & FLAG_OPTION) { if (t.cat() == catOther && t.character() == '[') { - MathData ar; + MathData ar(buf); parse(ar, FLAG_BRACK_LAST, mode); cell->append(ar); } else { @@ -942,7 +942,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, cell->push_back(MathAtom(new InsetMathSpace(string(1, t.character()), ""))); else if (t.cat() == catBegin) { - MathData ar; + MathData ar(buf); parse(ar, FLAG_BRACE_LAST, mode); // do not create a BraceInset if they were written by LyX // this helps to keep the annoyance of "a choose b" to a minimum @@ -1069,12 +1069,12 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, nargs /= 2; // read definition - MathData def; + MathData def(buf); parse(def, FLAG_ITEM, InsetMath::UNDECIDED_MODE); // is a version for display attached? skipSpaces(); - MathData display; + MathData display(buf); if (nextToken().cat() == catBegin) parse(display, FLAG_ITEM, InsetMath::MATH_MODE); @@ -1112,17 +1112,17 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, vector optionalValues; while (nextToken().character() == '[') { getToken(); - optionalValues.push_back(MathData()); + optionalValues.push_back(MathData(buf)); parse(optionalValues[optionals], FLAG_BRACK_LAST, mode); ++optionals; } - MathData def; + MathData def(buf); parse(def, FLAG_ITEM, InsetMath::UNDECIDED_MODE); // is a version for display attached? skipSpaces(); - MathData display; + MathData display(buf); if (nextToken().cat() == catBegin) parse(display, FLAG_ITEM, InsetMath::MATH_MODE); @@ -1186,11 +1186,11 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, // get value int optNum = max(size_t(n), optionalValues.size()); - optionalValues.resize(optNum); + optionalValues.resize(optNum, MathData(buf)); optionalValues[n - 1].clear(); while (nextToken().character() != ']' && nextToken().character() != ',') { - MathData data; + MathData data(buf); parse(data, FLAG_ITEM, InsetMath::UNDECIDED_MODE); optionalValues[n - 1].append(data); } @@ -1206,7 +1206,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, // value? skipSpaces(); - MathData value; + MathData value(buf); if (nextToken().character() == '=') { getToken(); while (nextToken().character() != ']' @@ -1238,12 +1238,12 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, } // get definition - MathData def; + MathData def(buf); parse(def, FLAG_ITEM, InsetMath::UNDECIDED_MODE); // is a version for display attached? skipSpaces(); - MathData display; + MathData display(buf); if (nextToken().cat() == catBegin) parse(display, FLAG_ITEM, InsetMath::MATH_MODE); @@ -1367,7 +1367,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, // if the columns are specified numerically, // extract column count and insert dummy cells, // otherwise parse it as an user macro - MathData count; + MathData count(buf); parse(count, FLAG_ITEM, mode); int cols = 0; // limit arbitrarily to 100 columns @@ -1388,7 +1388,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, InsetMathGrid::CELL_BEGIN_OF_MULTICOLUMN; // read special alignment - MathData align; + MathData align(buf); parse(align, FLAG_ITEM, mode); grid.cellinfo(first).align = asString(align); @@ -1423,7 +1423,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, } else if (t.cs() == "sqrt") { - MathData ar; + MathData ar(buf); parse(ar, FLAG_OPTION, mode); if (!ar.empty()) { cell->push_back(MathAtom(new InsetMathRoot(buf))); @@ -1434,7 +1434,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, } else if (t.cs() == "cancelto") { - MathData ar; + MathData ar(buf); parse(ar, FLAG_ITEM, mode); cell->push_back(MathAtom(new InsetMathCancelto(buf))); cell->back().nucleus()->cell(1) = ar; @@ -1443,7 +1443,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, else if (t.cs() == "unit") { // Allowed formats \unit[val]{unit} - MathData ar; + MathData ar(buf); parse(ar, FLAG_OPTION, mode); if (!ar.empty()) { cell->push_back(MathAtom(new InsetMathFrac(buf, InsetMathFrac::UNIT))); @@ -1457,7 +1457,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, else if (t.cs() == "unitfrac") { // Here allowed formats are \unitfrac[val]{num}{denom} - MathData ar; + MathData ar(buf); parse(ar, FLAG_OPTION, mode); if (!ar.empty()) { cell->push_back(MathAtom(new InsetMathFrac(buf, InsetMathFrac::UNITFRAC, 3))); @@ -1489,7 +1489,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, else if (t.cs() == "sideset") { // Here allowed formats are \sideset{_{bl}^{tl}}{_{br}^{tr}}{operator} - MathData ar[2]; + MathData ar[2]= { MathData(buf), MathData(buf) }; InsetMathScript * script[2] = {0, 0}; for (int i = 0; i < 2; ++i) { parse(ar[i], FLAG_ITEM, mode); @@ -1517,7 +1517,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, else if (t.cs() == "stackrel") { // Here allowed formats are \stackrel[subscript]{superscript}{operator} - MathData ar; + MathData ar(buf); parse(ar, FLAG_OPTION, mode); cell->push_back(MathAtom(new InsetMathStackrel(buf, !ar.empty()))); if (!ar.empty()) @@ -1566,7 +1566,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, // can't handle \| // FIXME: fix this in InsetMathDelim itself! docstring const l = tl.cs() == "|" ? from_ascii("Vert") : tl.asString(); - MathData ar; + MathData ar(buf); parse(ar, FLAG_RIGHT, mode); if (!good()) break; @@ -1790,7 +1790,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, else if (t.cs() == "label") { // FIXME: This is swallowed in inline formulas docstring label = parse_verbatim_item(); - MathData ar; + MathData ar(buf); asArray(label, ar); if (grid.asHullInset()) { grid.asHullInset()->label(cellrow, label); @@ -1892,7 +1892,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, // Since the Length class cannot use length variables // we must not create an InsetMathSpace. cell->push_back(MathAtom(new InsetMathMacro(buf, name))); - MathData ar; + MathData ar(buf); mathed_parse_cell(ar, '{' + arg + '}', mode_); cell->append(ar); } @@ -1911,10 +1911,10 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, } else { docstring const arg = parse_verbatim_item(); cell->push_back(MathAtom(new InsetMathMacro(buf, t.cs()))); - MathData ar; + MathData ar(buf); mathed_parse_cell(ar, '[' + opt + ']', mode_); cell->append(ar); - ar = MathData(); + ar = MathData(buf); mathed_parse_cell(ar, '{' + arg + '}', mode_); cell->append(ar); } @@ -1927,7 +1927,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, #if 0 else if (t.cs() == "infer") { - MathData ar; + MathData ar(buf); parse(ar, FLAG_OPTION, mode); cell->push_back(createInsetMath(t.cs(), buf)); parse2(cell->back(), FLAG_ITEM, mode, false); -- 2.39.5