forward port rev 24877. Even if trunk is not affected by 4857, it is safer to only display printable characters in the toc items and not go inside insets.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@24878 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2008-05-22 10:14:20 +00:00
parent 956b2cd11d
commit 5398dce8ae
4 changed files with 25 additions and 5 deletions

View File

@ -2302,6 +2302,21 @@ bool Paragraph::isMultiLingual(BufferParams const & bparams) const
}
docstring const Paragraph::printableString(bool label) const
{
odocstringstream os;
if (label && !params().labelString().empty())
os << params().labelString() << ' ';
pos_type end = size();
for (pos_type i = 0; i < end; ++i) {
char_type const c = d->text_[i];
if (isPrintable(c))
os.put(c);
}
return os.str();
}
docstring Paragraph::asString(bool label) const
{
return asString(0, size(), label);

View File

@ -98,7 +98,12 @@ public:
bool isMultiLingual(BufferParams const &) const;
/// Convert the paragraph to a string.
/// This method doesn't go inside insets, only printable characters in this
/// paragraph are used.
/// Used for building the table of contents
docstring const printableString(bool label) const;
/// Convert the paragraph to a string.
docstring asString(bool label) const;
///
docstring asString(pos_type beg, pos_type end, bool label) const;

View File

@ -134,7 +134,7 @@ void TocBackend::updateItem(DocIterator const & dit)
*static_cast<InsetOptArg&>(inset).paragraphs().begin();
if (!par.labelString().empty())
tocstring = par.labelString() + ' ';
tocstring += inset_par.asString(false);
tocstring += inset_par.printableString(false);
break;
}
}
@ -142,7 +142,7 @@ void TocBackend::updateItem(DocIterator const & dit)
int const toclevel = par.layout().toclevel;
if (toclevel != Layout::NOT_IN_TOC && toclevel >= min_toclevel
&& tocstring.empty())
tocstring = par.asString(true);
tocstring = par.printableString(true);
const_cast<TocItem &>(*toc_item).str_ = tocstring;
}
@ -181,7 +181,7 @@ void TocBackend::update()
*static_cast<InsetOptArg&>(inset).paragraphs().begin();
if (!pit->labelString().empty())
tocstring = pit->labelString() + ' ';
tocstring += par.asString(false);
tocstring += par.printableString(false);
break;
}
default:
@ -196,7 +196,7 @@ void TocBackend::update()
pit.pos() = 0;
// insert this into the table of contents
if (tocstring.empty())
tocstring = pit->asString(true);
tocstring = pit->printableString(true);
toc.push_back(TocItem(pit, toclevel - min_toclevel,
tocstring));
}

View File

@ -111,7 +111,7 @@ void InsetCaption::addToToc(DocIterator const & cpit)
pit.push_back(CursorSlice(*this));
Toc & toc = buffer().tocBackend().toc(type_);
docstring const str = full_label_ + ". " + text_.getPar(0).asString(false);
docstring const str = full_label_ + ". " + text_.getPar(0).printableString(false);
toc.push_back(TocItem(pit, 0, str));
}