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(const_iterator from, const_iterator to)
26 void MathArray::substitute(MathMacro const & m)
28 for (iterator it = begin(); it != end(); ++it)
29 it->nucleus()->substitute(m);
33 MathAtom & MathArray::operator[](size_type pos)
35 lyx::Assert(pos < size());
36 return base_type::operator[](pos);
40 MathAtom const & MathArray::operator[](size_type pos) const
42 lyx::Assert(pos < size());
43 return base_type::operator[](pos);
47 void MathArray::insert(size_type pos, MathAtom const & t)
49 base_type::insert(begin() + pos, t);
53 void MathArray::insert(size_type pos, MathArray const & ar)
55 base_type::insert(begin() + pos, ar.begin(), ar.end());
59 void MathArray::append(MathArray const & ar)
65 void MathArray::erase(size_type pos)
72 void MathArray::erase(iterator pos1, iterator pos2)
74 base_type::erase(pos1, pos2);
78 void MathArray::erase(iterator pos)
80 base_type::erase(pos);
84 void MathArray::erase(size_type pos1, size_type pos2)
86 base_type::erase(begin() + pos1, begin() + pos2);
90 void MathArray::dump2() const
92 NormalStream ns(lyxerr);
93 for (const_iterator it = begin(); it != end(); ++it)
94 ns << it->nucleus() << ' ';
98 void MathArray::dump() const
100 NormalStream ns(lyxerr);
101 for (const_iterator it = begin(); it != end(); ++it)
102 ns << "<" << it->nucleus() << ">";
106 void MathArray::validate(LaTeXFeatures & features) const
108 for (const_iterator it = begin(); it != end(); ++it)
110 it->nucleus()->validate(features);
114 bool MathArray::match(MathArray const & ar) const
116 return size() == ar.size() && matchpart(ar, 0);
120 bool MathArray::matchpart(MathArray const & ar, pos_type pos) const
122 if (size() < ar.size() + pos)
124 const_iterator it = begin() + pos;
125 for (const_iterator jt = ar.begin(); jt != ar.end(); ++jt, ++it)
126 if (!jt->nucleus()->match(it->nucleus()))
132 void MathArray::replace(ReplaceData & rep)
134 for (size_type i = 0; i < size(); ++i) {
135 if (find1(rep.from, i)) {
137 lyxerr << "match found!\n";
138 erase(i, i + rep.from.size());
143 for (const_iterator it = begin(); it != end(); ++it)
144 it->nucleus()->replace(rep);
148 bool MathArray::find1(MathArray const & ar, size_type pos) const
150 //lyxerr << "finding '" << ar << "' in '" << *this << "'\n";
151 for (size_type i = 0, n = ar.size(); i < n; ++i)
152 if (!operator[](pos + i)->match(ar[i].nucleus()))
158 MathArray::size_type MathArray::find(MathArray const & ar) const
160 for (int i = 0, last = size() - ar.size(); i < last; ++i)
167 MathArray::size_type MathArray::find_last(MathArray const & ar) const
169 for (int i = size() - ar.size(); i >= 0; --i)
176 bool MathArray::contains(MathArray const & ar) const
178 if (find(ar) != size())
180 for (const_iterator it = begin(); it != end(); ++it)
181 if (it->nucleus()->contains(ar))