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
}
// delete the next paragraph
+ LyXParagraph *prev = the_next->previous;
delete the_next;
+ prev->next = 0;
}
}
-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);
}
}
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;
+}