8 #include "math_inset.h"
9 #include "math_deliminset.h"
10 #include "math_charinset.h"
11 #include "math_scriptinset.h"
12 #include "math_stringinset.h"
13 #include "math_matrixinset.h"
14 #include "math_mathmlstream.h"
15 #include "math_support.h"
16 #include "math_replace.h"
18 #include "support/LAssert.h"
21 MathArray::MathArray()
25 MathArray::MathArray(MathArray const & ar, size_type from, size_type to)
26 : bf_(ar.begin() + from, ar.begin() + to)
30 MathArray::MathArray(iterator from, iterator to)
35 void MathArray::substitute(MathMacro const & m)
37 for (iterator it = begin(); it != end(); ++it)
38 it->nucleus()->substitute(m);
42 MathAtom & MathArray::at(size_type pos)
44 lyx::Assert(pos < size());
49 MathAtom const & MathArray::at(size_type pos) const
51 lyx::Assert(pos < size());
56 void MathArray::insert(size_type pos, MathAtom const & t)
58 bf_.insert(begin() + pos, t);
62 void MathArray::insert(size_type pos, MathArray const & ar)
64 bf_.insert(begin() + pos, ar.begin(), ar.end());
68 void MathArray::push_back(MathAtom const & t)
74 void MathArray::push_back(MathArray const & ar)
80 void MathArray::clear()
86 void MathArray::swap(MathArray & ar)
93 bool MathArray::empty() const
99 MathArray::size_type MathArray::size() const
105 void MathArray::erase()
107 bf_.erase(begin(), end());
111 void MathArray::erase(size_type pos)
118 void MathArray::erase(iterator pos1, iterator pos2)
120 bf_.erase(pos1, pos2);
124 void MathArray::erase(iterator pos)
130 void MathArray::erase(size_type pos1, size_type pos2)
132 bf_.erase(begin() + pos1, begin() + pos2);
136 MathAtom & MathArray::back()
142 MathAtom & MathArray::front()
148 MathAtom const & MathArray::front() const
154 void MathArray::dump2() const
156 NormalStream ns(lyxerr);
157 for (const_iterator it = begin(); it != end(); ++it)
158 ns << it->nucleus() << ' ';
162 void MathArray::dump() const
164 NormalStream ns(lyxerr);
165 for (const_iterator it = begin(); it != end(); ++it)
166 ns << "<" << it->nucleus() << ">";
170 void MathArray::validate(LaTeXFeatures & features) const
172 for (const_iterator it = begin(); it != end(); ++it)
174 it->nucleus()->validate(features);
178 void MathArray::pop_back()
181 lyxerr << "pop_back from empty array!\n";
188 MathArray::const_iterator MathArray::begin() const
194 MathArray::const_iterator MathArray::end() const
200 MathArray::iterator MathArray::begin()
206 MathArray::iterator MathArray::end()
212 bool MathArray::match(MathArray const & ar) const
214 return size() == ar.size() && matchpart(ar, 0);
218 bool MathArray::matchpart(MathArray const & ar, pos_type pos) const
220 if (size() < ar.size() + pos)
222 const_iterator it = begin() + pos;
223 for (const_iterator jt = ar.begin(); jt != ar.end(); ++jt, ++it)
224 if (!jt->nucleus()->match(it->nucleus()))
230 void MathArray::replace(ReplaceData & rep)
232 for (size_type i = 0; i < size(); ++i) {
233 if (find1(rep.from, i)) {
235 lyxerr << "match found!\n";
236 erase(i, i + rep.from.size());
241 for (const_iterator it = begin(); it != end(); ++it)
242 it->nucleus()->replace(rep);
246 bool MathArray::find1(MathArray const & ar, size_type pos) const
248 //lyxerr << "finding '" << ar << "' in '" << *this << "'\n";
249 for (size_type i = 0, n = ar.size(); i < n; ++i)
250 if (!at(pos + i)->match(ar[i].nucleus()))
256 MathArray::size_type MathArray::find(MathArray const & ar) const
258 for (int i = 0, last = size() - ar.size(); i < last; ++i)
265 MathArray::size_type MathArray::find_last(MathArray const & ar) const
267 for (int i = size() - ar.size(); i >= 0; --i)
274 bool MathArray::contains(MathArray const & ar) const
276 if (find(ar) != size())
278 for (const_iterator it = begin(); it != end(); ++it)
279 if (it->nucleus()->contains(ar))