- if (maxlen == 0)
- maxlen = std::numeric_limits<std::size_t>::max();
- else
- LASSERT(maxlen >= 8, maxlen = TOC_ENTRY_LENGTH);
- for (size_t i = 0; i != pars_.size() && os.length() < maxlen; ++i)
- pars_[i].forOutliner(os, maxlen);
- if (shorten && os.length() >= maxlen)
- os = os.substr(0, maxlen - 3) + from_ascii("...");
+ support::truncateWithEllipsis(str, maxlen);
+ for (char_type & c : str)
+ if (c == L'\n' || c == L'\t')
+ c = L' ';
+}
+
+
+void Text::forOutliner(docstring & os, size_t const maxlen,
+ bool const shorten) const
+{
+ pit_type end = pars_.size() - 1;
+ if (0 <= end && !pars_[0].labelString().empty())
+ os += pars_[0].labelString() + ' ';
+ forOutliner(os, maxlen, 0, end, shorten);
+}
+
+
+void Text::forOutliner(docstring & os, size_t const maxlen,
+ pit_type pit_start, pit_type pit_end,
+ bool const shorten) const
+{
+ size_t tmplen = shorten ? maxlen + 1 : maxlen;
+ pit_type end = min(size_t(pit_end), pars_.size() - 1);
+ bool first = true;
+ for (pit_type i = pit_start; i <= end && os.length() < tmplen; ++i) {
+ if (!first)
+ os += ' ';
+ // This function lets the first label be treated separately
+ pars_[i].forOutliner(os, tmplen, false, !first);
+ first = false;
+ }
+ if (shorten)
+ shortenForOutliner(os, maxlen);