]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_data.C
fix typo that put too many include paths for most people
[lyx.git] / src / mathed / math_data.C
index 017742014fa77dafbd317433ed45dc51ac4990e3..7ef98e0589ddb92a862920e69aea94428a522d62 100644 (file)
@@ -1,7 +1,10 @@
+#include <config.h>
+
 #ifdef __GNUG__
 #pragma implementation
 #endif
 
+#include "math_data.h"
 #include "math_inset.h"
 #include "math_deliminset.h"
 #include "math_charinset.h"
@@ -10,7 +13,7 @@
 #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"
 
@@ -63,7 +66,7 @@ void MathArray::insert(size_type pos, MathArray const & ar)
 
 
 void MathArray::push_back(MathAtom const & t)
-{      
+{
        bf_.push_back(t);
 }
 
@@ -82,7 +85,7 @@ void MathArray::clear()
 
 void MathArray::swap(MathArray & ar)
 {
-       if (this != &ar) 
+       if (this != &ar)
                bf_.swap(ar.bf_);
 }
 
@@ -173,7 +176,7 @@ void MathArray::validate(LaTeXFeatures & features) const
 
 
 void MathArray::pop_back()
-{      
+{
        if (!size()) {
                lyxerr << "pop_back from empty array!\n";
                return;
@@ -208,10 +211,60 @@ MathArray::iterator MathArray::end()
 
 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;
 }
+
+
+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);
+}
+
+
+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;
+}