]> git.lyx.org Git - lyx.git/blobdiff - src/dociterator.C
fix reading the author field.
[lyx.git] / src / dociterator.C
index 97630288c3e1adc8458721c18387b6d63957998a..2df577b5f4adfffe1cc6caf21a2fcc57c700a139 100644 (file)
@@ -3,8 +3,7 @@
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
- * \author unknown
- * \author Lars Gullik Bjønnes
+ * \author André Pönitz
  *
  * Full author contact details are available in file CREDITS.
  */
 using std::endl;
 
 
-//we could be able to get rid of this if only every BufferView were
-//associated to a buffer on construction
-DocIterator::DocIterator() : inset_(0)
+// We could be able to get rid of this if only every BufferView were
+// associated to a buffer on construction.
+DocIterator::DocIterator()
+       : inset_(0)
+{}
+
+
+DocIterator::DocIterator(InsetBase & inset)
+       : inset_(&inset)
 {}
 
 
@@ -47,16 +52,12 @@ DocIterator doc_iterator_end(InsetBase & inset)
 }
 
 
-DocIterator::DocIterator(InsetBase & inset) : inset_(&inset)
-{}
-
-
 InsetBase * DocIterator::nextInset()
 {
        BOOST_ASSERT(!empty());
        if (pos() == lastpos())
                return 0;
-       if (inMathed()) 
+       if (inMathed())
                return nextAtom().nucleus();
        return paragraph().isInset(pos()) ? paragraph().getInset(pos()) : 0;
 }
@@ -67,7 +68,7 @@ InsetBase * DocIterator::prevInset()
        BOOST_ASSERT(!empty());
        if (pos() == 0)
                return 0;
-       if (inMathed()) 
+       if (inMathed())
                return prevAtom().nucleus();
        return paragraph().isInset(pos() - 1) ? paragraph().getInset(pos() - 1) : 0;
 }
@@ -78,7 +79,7 @@ InsetBase const * DocIterator::prevInset() const
        BOOST_ASSERT(!empty());
        if (pos() == 0)
                return 0;
-       if (inMathed()) 
+       if (inMathed())
                return prevAtom().nucleus();
        return paragraph().isInset(pos() - 1) ? paragraph().getInset(pos() - 1) : 0;
 }
@@ -103,6 +104,7 @@ MathAtom & DocIterator::prevAtom()
 MathAtom const & DocIterator::nextAtom() const
 {
        BOOST_ASSERT(!empty());
+       //lyxerr << "lastpos: " << lastpos() << " next atom:\n" << *this << endl;
        BOOST_ASSERT(pos() < lastpos());
        return cell()[pos()];
 }
@@ -111,6 +113,7 @@ MathAtom const & DocIterator::nextAtom() const
 MathAtom & DocIterator::nextAtom()
 {
        BOOST_ASSERT(!empty());
+       //lyxerr << "lastpos: " << lastpos() << " next atom:\n" << *this << endl;
        BOOST_ASSERT(pos() < lastpos());
        return cell()[pos()];
 }
@@ -339,13 +342,13 @@ void DocIterator::forwardChar()
 {
        forwardPos();
        while (size() != 0 && pos() == lastpos())
-               forwardPos(); 
+               forwardPos();
 }
 
 
 void DocIterator::forwardInset()
 {
-       forwardPos(); 
+       forwardPos();
        while (size() != 0 && (pos() == lastpos() || nextInset() == 0))
                forwardPos();
 }
@@ -355,7 +358,7 @@ void DocIterator::backwardChar()
 {
        backwardPos();
        while (size() != 0 && pos() == lastpos())
-               backwardPos(); 
+               backwardPos();
 }
 
 
@@ -390,7 +393,7 @@ void DocIterator::backwardPos()
 
        // move into an inset to the left if possible
        InsetBase * n = 0;
-       
+
        if (inMathed()) {
                n = (top.cell().begin() + top.pos())->nucleus();
        } else {
@@ -407,6 +410,17 @@ void DocIterator::backwardPos()
 }
 
 
+bool DocIterator::hasPart(DocIterator const & it) const
+{
+       // it can't be a part if it is larger
+       if (it.size() > size())
+               return false;
+
+       // as inset adresses are the 'last' level
+       return &it.back().inset() == &operator[](it.size() - 1).inset();
+}
+
+
 std::ostream & operator<<(std::ostream & os, DocIterator const & dit)
 {
        for (size_t i = 0, n = dit.size(); i != n; ++i)
@@ -449,4 +463,3 @@ std::ostream & operator<<(std::ostream & os, StableDocIterator const & dit)
                os << " " << dit.data_[i] << "\n";
        return os;
 }
-