}
-class MatchString : public binary_function<Paragraph, pos_type, bool>
+class MatchString : public binary_function<Paragraph, pos_type, int>
{
public:
MatchString(docstring const & str, bool cs, bool mw)
// returns true if the specified string is at the specified position
// del specifies whether deleted strings in ct mode will be considered
- bool operator()(Paragraph const & par, pos_type pos, bool del = true) const
+ int operator()(Paragraph const & par, pos_type pos, bool del = true) const
{
return par.find(str, case_sens, whole_words, pos, del);
}
};
-bool findForward(DocIterator & cur, MatchString const & match,
+int findForward(DocIterator & cur, MatchString const & match,
bool find_del = true)
{
for (; cur; cur.forwardChar())
- if (cur.inTexted() &&
- match(cur.paragraph(), cur.pos(), find_del))
- return true;
- return false;
+ if (cur.inTexted()) {
+ int len = match(cur.paragraph(), cur.pos(), find_del);
+ if (len > 0)
+ return len;
+ }
+ return 0;
}
-bool findBackwards(DocIterator & cur, MatchString const & match,
+int findBackwards(DocIterator & cur, MatchString const & match,
bool find_del = true)
{
while (cur) {
cur.backwardChar();
- if (cur.inTexted() &&
- match(cur.paragraph(), cur.pos(), find_del))
- return true;
+ if (cur.inTexted()) {
+ int len = match(cur.paragraph(), cur.pos(), find_del);
+ if (len > 0)
+ return len;
+ }
}
- return false;
+ return 0;
}
MatchString const match(searchstr, case_sens, whole);
- bool found = forward ? findForward(cur, match, find_del) :
+ int match_len = forward ? findForward(cur, match, find_del) :
findBackwards(cur, match, find_del);
- if (found)
- bv->putSelectionAt(cur, searchstr.length(), !forward);
+ if (match_len > 0)
+ bv->putSelectionAt(cur, match_len, !forward);
- return found;
+ return match_len > 0;
}
Cursor cur(*bv);
cur.setCursor(doc_iterator_begin(&buf));
- while (findForward(cur, match, false)) {
+ int match_len = findForward(cur, match, false);
+ while (match_len > 0) {
// Backup current cursor position and font.
pos_type const pos = cur.pos();
Font const font = cur.paragraph().getFontSettings(buf.params(), pos);
cur.recordUndo();
- int striked = ssize - cur.paragraph().eraseChars(pos, pos + ssize,
+ int striked = ssize - cur.paragraph().eraseChars(pos, pos + match_len,
buf.params().trackChanges);
cur.paragraph().insert(pos, replacestr, font,
Change(buf.params().trackChanges ?
for (int i = 0; i < rsize + striked; ++i)
cur.forwardChar();
++num;
+ match_len = findForward(cur, match, false);
}
bv->putSelectionAt(doc_iterator_begin(&buf), 0, false);
if (str.substr(0, par_as_string.size()) == par_as_string)
return par_as_string.size();
} else {
- size_t pos = str.find(par_as_string);
+ string t = par_as_string;
+ while (regex_replace(t, t, "\\\\(emph|textbf|subsubsection|subsection|section|subparagraph|paragraph|part)\\{", "")
+ || regex_replace(t, t, "^\\$", "")
+ || regex_replace(t, t, "^\\\\\\[ ", ""))
+ LYXERR(Debug::FIND, " after removing leading $, \\[ , \\emph{, \\textbf{, etc.: " << t);
+ size_t pos = str.find(t);
if (pos != string::npos)
return par_as_string.size();
}
match_results<string::const_iterator> const & m = *re_it;
// Check braces on the segment that matched the entire regexp expression,
// plus the last subexpression, if a (.*?) was inserted in the constructor.
- if (! braces_match(m[0].first, m[0].second, open_braces))
+ if (!braces_match(m[0].first, m[0].second, open_braces))
return 0;
// Check braces on segments that matched all (.*?) subexpressions.
for (size_t i = 1; i < m.size(); ++i)
- if (! braces_match(m[i].first, m[i].second))
+ if (!braces_match(m[i].first, m[i].second))
return false;
// Exclude from the returned match length any length
// due to close wildcards added at end of regexp
t.replace(pos, 1, " ");
// Remove stale empty \emph{}, \textbf{} and similar blocks from latexify
LYXERR(Debug::FIND, "Removing stale empty \\emph{}, \\textbf{}, \\*section{} macros from: " << t);
- while (regex_replace(t, t, "\\\\(emph|textbf|subsubsection|subsection|section|subparagraph|paragraph)(\\{\\})+", ""))
+ while (regex_replace(t, t, "\\\\(emph|textbf|subsubsection|subsection|section|subparagraph|paragraph|part)(\\{\\})+", ""))
LYXERR(Debug::FIND, " further removing stale empty \\emph{}, \\textbf{} macros from: " << t);
return t;
}