+#include <config.h>
+
#ifdef __GNUG__
#pragma implementation
#endif
void MathArray::push_back(MathAtom const & t)
-{
+{
bf_.push_back(t);
}
void MathArray::swap(MathArray & ar)
{
- if (this != &ar)
+ if (this != &ar)
bf_.swap(ar.bf_);
}
void MathArray::pop_back()
-{
+{
if (!size()) {
lyxerr << "pop_back from empty array!\n";
return;
bool MathArray::match(MathArray const & ar) const
{
- if (size() != ar.size())
+ return size() == ar.size() && matchpart(ar, 0);
+}
+
+
+bool MathArray::matchpart(MathArray const & ar, pos_type pos) const
+{
+ if (size() < ar.size() + pos)
return false;
- for (const_iterator it = begin(), jt = ar.begin(); it != end(); ++it, ++jt)
- if (!it->nucleus()->match(jt->nucleus()))
+ const_iterator it = begin() + pos;
+ for (const_iterator jt = ar.begin(); jt != ar.end(); ++jt, ++it)
+ if (!jt->nucleus()->match(it->nucleus()))
return false;
return true;
}
for (const_iterator it = begin(); it != end(); ++it)
it->nucleus()->replace(rep);
}
+
+
+bool MathArray::contains(MathArray const & ar) const
+{
+ for (size_type i = 0; i + ar.size() <= size(); ++i) {
+ const_iterator it = begin() + i;
+ const_iterator rt = ar.begin();
+ const_iterator et = ar.end();
+ for (const_iterator jt = it; rt != et; ++jt, ++rt)
+ if (!jt->nucleus()->match(rt->nucleus()))
+ break;
+ if (rt == et)
+ return true;
+ }
+
+ for (const_iterator it = begin(); it != end(); ++it)
+ if (it->nucleus()->contains(ar))
+ return true;
+
+ return false;
+}