X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fmathed%2Farray.C;h=48deaf73ab7066e3b125c9b91b8cb0d7bb11a3bb;hb=dff2911bda426ad439e6475f62183cedd7044801;hp=482d1c8d8519ce038e1c047310b00c5f9b8957ec;hpb=4253792bd609d0ff130766693e292507dafcf631;p=features.git diff --git a/src/mathed/array.C b/src/mathed/array.C index 482d1c8d85..48deaf73ab 100644 --- a/src/mathed/array.C +++ b/src/mathed/array.C @@ -5,9 +5,11 @@ #include "math_inset.h" #include "math_charinset.h" #include "math_scriptinset.h" +#include "math_stringinset.h" #include "debug.h" #include "array.h" #include "mathed/support.h" +#include "support/LAssert.h" using std::ostream; using std::endl; @@ -25,28 +27,38 @@ MathArray::MathArray(MathArray const & array, size_type from, size_type to) void MathArray::substitute(MathMacro const & m) { for (iterator it = begin(); it != end(); ++it) - it->substitute(m); + it->nucleus()->substitute(m); } -MathAtom * MathArray::at(size_type pos) +MathScriptInset const * MathArray::asScript(const_iterator it) const { - return pos < size() ? &bf_[pos] : 0; + if (it->nucleus()->asScriptInset()) + return 0; + const_iterator jt = it + 1; + if (jt == end()) + return 0; + return jt->nucleus()->asScriptInset(); } -MathAtom const * MathArray::at(size_type pos) const +MathAtom & MathArray::at(size_type pos) { - return pos < size() ? &bf_[pos] : 0; + lyx::Assert(pos < size()); + return bf_[pos]; } -void MathArray::insert(size_type pos, MathInset * p) +MathAtom const & MathArray::at(size_type pos) const { - //cerr << "\n 1: "; p->write(cerr, true); cerr << p << "\n"; - // inserting here invalidates the pointer! - bf_.insert(begin() + pos, MathAtom(p)); - //cerr << "\n 2: "; p->write(cerr, true); cerr << p << "\n"; + lyx::Assert(pos < size()); + return bf_[pos]; +} + + +void MathArray::insert(size_type pos, MathAtom const & t) +{ + bf_.insert(begin() + pos, t); } @@ -62,12 +74,6 @@ void MathArray::push_back(MathAtom const & t) } -void MathArray::push_back(MathInset * p) -{ - bf_.push_back(MathAtom(p)); -} - - void MathArray::push_back(MathArray const & array) { insert(size(), array); @@ -91,7 +97,7 @@ bool MathArray::empty() const { return bf_.empty(); } - + MathArray::size_type MathArray::size() const { @@ -127,14 +133,14 @@ MathAtom & MathArray::back() void MathArray::dump2(ostream & os) const { for (const_iterator it = begin(); it != end(); ++it) - os << *it << ' '; + os << it->nucleus() << ' '; } void MathArray::dump(ostream & os) const { for (const_iterator it = begin(); it != end(); ++it) - os << "<" << *it << ">"; + os << "<" << it->nucleus() << ">"; } @@ -158,7 +164,7 @@ string charSequence(MathArray::const_iterator it, MathArray::const_iterator end) if (!it->nucleus()) break; p = it->nucleus()->asCharInset(); - if (!p || it->up() || it->down() || p->code() != c) + if (!p || p->code() != c) break; s += p->getChar(); } @@ -166,41 +172,67 @@ string charSequence(MathArray::const_iterator it, MathArray::const_iterator end) } -void MathArray::write(ostream & os, bool fragile) const +MathArray MathArray::glueChars() const { - for (const_iterator it = begin(); it != end(); ++it) { - if (it->nucleus() && it->nucleus()->asCharInset() - && !it->up() && !it->down()) - { - MathCharInset const * p = it->nucleus()->asCharInset(); - // special handling for character sequences with the same code + MathArray ar; + const_iterator it = begin(); + while (it != end()) { + if (it->nucleus() && it->nucleus()->asCharInset()) { string s = charSequence(it, end()); - p->writeHeader(os); - os << s; - p->writeTrailer(os); - it += s.size() - 1; + MathTextCodes c = it->nucleus()->asCharInset()->code(); + ar.push_back(MathAtom(new MathStringInset(s, c))); + it += s.size(); } else { - it->write(os, fragile); + ar.push_back(*it); + ++it; } } + return ar; } -void MathArray::writeNormal(ostream & os) const +void MathArray::write(MathWriteInfo & wi) const { - if (empty()) { - os << "[par] "; - return; + glueChars().write1(wi); +} + + +void MathArray::write1(MathWriteInfo & wi) const +{ + for (const_iterator it = begin(); it != end(); ++it) { + MathInset * p = it->nucleus(); + if (!p) + continue; + if (MathScriptInset const * q = asScript(it)) { + q->write(p, wi); + ++it; + } else { + p->write(wi); + } } +} - write(os, true); + +void MathArray::writeNormal(ostream & os) const +{ + for (const_iterator it = begin(); it != end(); ++it) { + MathInset * p = it->nucleus(); + if (!p) + continue; + if (MathScriptInset const * q = asScript(it)) { + q->writeNormal(p, os); + ++it; + } else { + p->writeNormal(os); + } + } } void MathArray::validate(LaTeXFeatures & features) const { for (const_iterator it = begin(); it != end(); ++it) - it->validate(features); + it->nucleus()->validate(features); }