]> git.lyx.org Git - lyx.git/blobdiff - src/paragraph.C
Hopefully fixed another free-memory bug.
[lyx.git] / src / paragraph.C
index 6cf88c4815038ba3e75b4e3629751cb94cd09876..01ea6b6331c54c94b561606724c9d208548011d8 100644 (file)
@@ -40,6 +40,7 @@ using std::fstream;
 using std::ios;
 using std::lower_bound;
 using std::upper_bound;
+using std::reverse;
 
 int tex_code_break_column = 72;  // needs non-zero initialization. set later.
 // this is a bad idea, but how can LyXParagraph find its buffer to get
@@ -1622,7 +1623,9 @@ void LyXParagraph::PasteParagraph()
        }
    
        // delete the next paragraph
+       LyXParagraph *prev = the_next->previous;
        delete the_next;
+       prev->next = 0;
 }
 
 
@@ -1930,16 +1933,12 @@ int LyXParagraph::AutoDeleteInsets()
 }
 
 
-Inset * LyXParagraph::ReturnNextInsetPointer(LyXParagraph::size_type & pos)
+LyXParagraph::inset_iterator LyXParagraph::InsetIterator(LyXParagraph::size_type pos)
 {
        InsetList::iterator it = lower_bound(insetlist.begin(),
                                             insetlist.end(),
                                             pos, matchIT());
-       if (it != insetlist.end()) {
-               pos = (*it).pos;
-               return (*it).inset;
-       }
-       return 0;
+       return inset_iterator(it);
 }
 
 
@@ -4261,3 +4260,74 @@ bool LyXParagraph::isMultiLingual()
        }
        return false;
 }
+
+
+// Convert the paragraph to a string.
+// Used for building the table of contents
+string LyXParagraph::String(bool label)
+{
+       string s;
+       if (label && !IsDummy())
+               s += labelstring + ' ';
+       string::size_type len = s.size();
+
+       for (LyXParagraph::size_type i = 0; i < size(); ++i) {
+               unsigned char c = GetChar(i);
+               if (IsPrintable(c))
+                       s += c;
+               else if (c == META_INSET &&
+                        GetInset(i)->LyxCode() == Inset::MATH_CODE) {
+#ifdef HAVE_SSTREAM
+                       std::ostringstream ost;
+                       GetInset(i)->Ascii(ost);
+#else
+                       ostrstream ost;
+                       GetInset(i)->Ascii(ost);
+                       ost << '\0';
+#endif
+                       s += subst(ost.str(),'\n',' ');
+               }
+       }
+
+       if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
+               s += NextAfterFootnote()->String(false);
+
+       if (!IsDummy()) {
+               if (isRightToLeftPar())
+                       reverse(s.begin() + len,s.end());
+       }
+       return s;
+}
+
+
+string LyXParagraph::String(LyXParagraph::size_type beg,
+                           LyXParagraph::size_type end)
+{
+       string s;
+
+       for (LyXParagraph::size_type i = beg; i < end; ++i) {
+               unsigned char c = GetChar(i);
+               if (IsPrintable(c))
+                       s += c;
+               else if (c == META_INSET) {
+#ifdef HAVE_SSTREAM
+                       std::ostringstream ost;
+                       GetInset(i)->Ascii(ost);
+#else
+                       ostrstream ost;
+                       GetInset(i)->Ascii(ost);
+                       ost << '\0';
+#endif
+                       s += subst(ost.str(),'\n',' ');
+               }
+       }
+
+       if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
+               s += NextAfterFootnote()->String(false);
+
+       if (!IsDummy()) {
+               if (isRightToLeftPar())
+                       reverse(s.begin(), s.end());
+       }
+       return s;
+}