On Fri, Mar 28, 2014 at 12:37 AM, Tommaso Cucinotta <tomm...@lyx.org> wrote:
> commit cb351665f432671eb263eec76164aa546abd7151 > Author: Tommaso Cucinotta <tomm...@lyx.org> > Date: Thu Mar 27 23:12:56 2014 +0000 > > First of all. Master is closed because we are between rc1 and final release. Please commit to the 2.2-staging branch. > Fixing #7987: deleted text in change-tracking mode is not found in > Advanced F&R any more. > > Merged Paragraph::stringify into asString(). > Added ignore of deleted text to Advanced F&R. > It would be better to split this into two commits. One commit does the cleanup and has no change in functionality, the other one fixes the bug. > > diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp > index d32c0be..6487095 100644 > --- a/src/Paragraph.cpp > +++ b/src/Paragraph.cpp > @@ -3347,7 +3347,7 @@ docstring Paragraph::asString(int options) const > } > > > -docstring Paragraph::asString(pos_type beg, pos_type end, int options) > const > +docstring Paragraph::asString(pos_type beg, pos_type end, int options, > const OutputParams *p_runparams) const > - almost everywhere else we pass around const ref OutputParams - we usually do not consitfy pointers - we usually do not use p_ prefixes > { > odocstringstream os; > > @@ -3364,9 +3364,14 @@ docstring Paragraph::asString(pos_type beg, > pos_type end, int options) const > || (c == '\n' && (options & AS_STR_NEWLINES))) > os.put(c); > else if (c == META_INSET && (options & AS_STR_INSETS)) { > - getInset(i)->toString(os); > - if (getInset(i)->asInsetMath()) > - os << " "; > + if (options & AS_STR_PLAINTEXT) { > + LASSERT(p_runparams != 0, return > docstring()); > + getInset(i)->plaintext(os, *p_runparams); > + } else { > + getInset(i)->toString(os); > + if (getInset(i)->asInsetMath()) > + os << " "; > + } > } > } > > LASSERT is not meant to force your API on the caller. > @@ -3392,33 +3397,6 @@ void Paragraph::forToc(docstring & os, size_t > maxlen) const > } > > > -docstring Paragraph::stringify(pos_type beg, pos_type end, int options, > - OutputParams const & runparams) const > -{ > - odocstringstream os; > - > - if (beg == 0 > - && options & AS_STR_LABEL > - && !d->params_.labelString().empty()) > - os << d->params_.labelString() << ' '; > - > - OutputParams op = runparams; > - op.for_search = true; > - > - for (pos_type i = beg; i < end; ++i) { > - char_type const c = d->text_[i]; > - if (isPrintable(c) || c == '\t' > - || (c == '\n' && (options & AS_STR_NEWLINES))) > - os.put(c); > - else if (c == META_INSET && (options & AS_STR_INSETS)) { > - getInset(i)->plaintext(os, op); > - } > - } > - > - return os.str(); > -} > - > - > void Paragraph::setInsetOwner(Inset const * inset) > { > d->inset_owner_ = inset; > diff --git a/src/Paragraph.h b/src/Paragraph.h > index 9558048..97d36dc 100644 > --- a/src/Paragraph.h > +++ b/src/Paragraph.h > @@ -127,7 +127,8 @@ enum AsStringParameter > AS_STR_LABEL = 1, ///< Prefix with paragraph label. > AS_STR_INSETS = 2, ///< Go into insets. > AS_STR_NEWLINES = 4, ///< Get also newline characters. > - AS_STR_SKIPDELETE = 8 ///< Skip deleted text in change tracking. > + AS_STR_SKIPDELETE = 8, ///< Skip deleted text in change tracking. > + AS_STR_PLAINTEXT = 16 ///< Extract only the explicitly visible > text (without any formatting), when descending into insets > }; > > > @@ -175,15 +176,11 @@ public: > docstring asString(int options = AS_STR_NONE) const; > /// > docstring asString(pos_type beg, pos_type end, > - int options = AS_STR_NONE) const; > + int options = AS_STR_NONE, > + const OutputParams *p_runparams = 0) const; > This is not a proper use of default values. How can your fellow developer know whether the default is ok, or whether he should supply an OutputParams object without looking into the implementation and figure out himself. Even worse, the parameter feels optional, but if he does it wrong, he will get an assert... This is some kind of guessing game. Always think of using a separate function when introducing optional arguments. And, if you do so, think of self-explanatory function names. Vincent