+#include <config.h>
+
#ifdef __GNUG__
#pragma implementation
#endif
+#include "math_data.h"
#include "math_inset.h"
#include "math_deliminset.h"
#include "math_charinset.h"
#include "math_matrixinset.h"
#include "math_mathmlstream.h"
#include "math_support.h"
-#include "math_data.h"
+#include "math_replace.h"
#include "debug.h"
#include "support/LAssert.h"
{}
+MathArray::MathArray(iterator from, iterator to)
+ : bf_(from, to)
+{}
+
+
void MathArray::substitute(MathMacro const & m)
{
for (iterator it = begin(); it != end(); ++it)
void MathArray::erase()
{
- erase(0, size());
+ bf_.erase(begin(), end());
}
}
+void MathArray::erase(iterator pos1, iterator pos2)
+{
+ bf_.erase(pos1, pos2);
+}
+
+
+void MathArray::erase(iterator pos)
+{
+ bf_.erase(pos);
+}
+
+
void MathArray::erase(size_type pos1, size_type pos2)
{
bf_.erase(begin() + pos1, begin() + pos2);
}
+MathAtom & MathArray::front()
+{
+ return bf_.front();
+}
+
+
+MathAtom const & MathArray::front() const
+{
+ return bf_.front();
+}
+
+
void MathArray::dump2() const
{
NormalStream ns(lyxerr);
{
return bf_.end();
}
+
+
+bool MathArray::match(MathArray const & ar) const
+{
+ return size() == ar.size() && matchpart(ar, 0);
+}
+
+
+bool MathArray::matchpart(MathArray const & ar, pos_type pos) const
+{
+ if (size() < ar.size() + pos)
+ return false;
+ 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;
+}
+
+
+void MathArray::replace(ReplaceData & rep)
+{
+ for (size_type i = 0; i < size(); ++i) {
+ iterator it = begin() + i;
+ const_iterator rt = rep.from.begin();
+ const_iterator et = rep.from.end();
+ for (const_iterator jt = it; jt != end() && rt != et; ++jt, ++rt)
+ if (!jt->nucleus()->match(rt->nucleus()))
+ break;
+ if (rt == et) {
+ // match found
+ lyxerr << "match found!\n";
+ erase(it, it + rep.from.size());
+ insert(i, rep.to);
+ }
+ }
+
+ for (const_iterator it = begin(); it != end(); ++it)
+ it->nucleus()->replace(rep);
+}