3 * This file is part of LyX, the document processor.
4 * License details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
9 * \author Alfredo Braunstein
10 * \author Tommaso Cucinotta
12 * Full author contact details are available in file CREDITS.
20 #include "buffer_funcs.h"
21 #include "BufferList.h"
22 #include "BufferParams.h"
23 #include "BufferView.h"
26 #include "CutAndPaste.h"
27 #include "FuncRequest.h"
29 #include "output_latex.h"
30 #include "OutputParams.h"
31 #include "Paragraph.h"
32 #include "ParIterator.h"
36 #include "frontends/Application.h"
37 #include "frontends/alert.h"
39 #include "mathed/InsetMath.h"
40 #include "mathed/InsetMathGrid.h"
41 #include "mathed/InsetMathHull.h"
42 #include "mathed/MathStream.h"
43 #include "mathed/MathSupport.h"
45 #include "support/convert.h"
46 #include "support/debug.h"
47 #include "support/docstream.h"
48 #include "support/FileName.h"
49 #include "support/gettext.h"
50 #include "support/lassert.h"
51 #include "support/lstrings.h"
53 #include "support/regex.h"
56 using namespace lyx::support;
62 bool parse_bool(docstring & howto)
67 howto = split(howto, var, ' ');
72 class MatchString : public binary_function<Paragraph, pos_type, int>
75 MatchString(docstring const & str, bool cs, bool mw)
76 : str(str), case_sens(cs), whole_words(mw)
79 // returns true if the specified string is at the specified position
80 // del specifies whether deleted strings in ct mode will be considered
81 int operator()(Paragraph const & par, pos_type pos, bool del = true) const
83 return par.find(str, case_sens, whole_words, pos, del);
91 // match whole words only
96 int findForward(DocIterator & cur, MatchString const & match,
99 for (; cur; cur.forwardChar())
100 if (cur.inTexted()) {
101 int len = match(cur.paragraph(), cur.pos(), find_del);
109 int findBackwards(DocIterator & cur, MatchString const & match,
110 bool find_del = true)
114 if (cur.inTexted()) {
115 int len = match(cur.paragraph(), cur.pos(), find_del);
124 bool searchAllowed(docstring const & str)
127 frontend::Alert::error(_("Search error"), _("Search string is empty"));
134 bool findOne(BufferView * bv, docstring const & searchstr,
135 bool case_sens, bool whole, bool forward, bool find_del = true)
137 if (!searchAllowed(searchstr))
140 DocIterator cur = forward
141 ? bv->cursor().selectionEnd()
142 : bv->cursor().selectionBegin();
144 MatchString const match(searchstr, case_sens, whole);
146 int match_len = forward
147 ? findForward(cur, match, find_del)
148 : findBackwards(cur, match, find_del);
151 bv->putSelectionAt(cur, match_len, !forward);
153 return match_len > 0;
157 int replaceAll(BufferView * bv,
158 docstring const & searchstr, docstring const & replacestr,
159 bool case_sens, bool whole)
161 Buffer & buf = bv->buffer();
163 if (!searchAllowed(searchstr) || buf.isReadonly())
166 DocIterator cur_orig(bv->cursor());
168 MatchString const match(searchstr, case_sens, whole);
171 int const rsize = replacestr.size();
172 int const ssize = searchstr.size();
175 cur.setCursor(doc_iterator_begin(&buf));
176 int match_len = findForward(cur, match, false);
177 while (match_len > 0) {
178 // Backup current cursor position and font.
179 pos_type const pos = cur.pos();
180 Font const font = cur.paragraph().getFontSettings(buf.params(), pos);
182 int striked = ssize -
183 cur.paragraph().eraseChars(pos, pos + match_len,
184 buf.params().track_changes);
185 cur.paragraph().insert(pos, replacestr, font,
186 Change(buf.params().track_changes
188 : Change::UNCHANGED));
189 for (int i = 0; i < rsize + striked; ++i)
192 match_len = findForward(cur, match, false);
195 bv->putSelectionAt(doc_iterator_begin(&buf), 0, false);
197 cur_orig.fixIfBroken();
198 bv->setCursor(cur_orig);
204 // the idea here is that we are going to replace the string that
205 // is selected IF it is the search string.
206 // if there is a selection, but it is not the search string, then
207 // we basically ignore it. (FIXME We ought to replace only within
209 // if there is no selection, then:
210 // (i) if some search string has been provided, then we find it.
211 // (think of how the dialog works when you hit "replace" the
213 // (ii) if no search string has been provided, then we treat the
214 // word the cursor is in as the search string. (why? i have no
215 // idea.) but this only works in text?
217 // returns the number of replacements made (one, if any) and
218 // whether anything at all was done.
219 pair<bool, int> replaceOne(BufferView * bv, docstring searchstr,
220 docstring const & replacestr, bool case_sens,
221 bool whole, bool forward, bool findnext)
223 Cursor & cur = bv->cursor();
224 if (!cur.selection()) {
225 // no selection, non-empty search string: find it
226 if (!searchstr.empty()) {
227 findOne(bv, searchstr, case_sens, whole, forward);
228 return make_pair(true, 0);
230 // empty search string
233 return make_pair(false, 0);
234 // select current word and treat it as the search string.
235 // This causes a minor bug as undo will restore this selection,
236 // which the user did not create (#8986).
237 cur.innerText()->selectWord(cur, WHOLE_WORD);
238 searchstr = cur.selectionAsString(false);
241 // if we still don't have a search string, report the error
243 if (!searchAllowed(searchstr))
244 return make_pair(false, 0);
246 bool have_selection = cur.selection();
247 docstring const selected = cur.selectionAsString(false);
250 ? searchstr == selected
251 : compare_no_case(searchstr, selected) == 0;
253 // no selection or current selection is not search word:
254 // just find the search word
255 if (!have_selection || !match) {
256 findOne(bv, searchstr, case_sens, whole, forward);
257 return make_pair(true, 0);
260 // we're now actually ready to replace. if the buffer is
261 // read-only, we can't, though.
262 if (bv->buffer().isReadonly())
263 return make_pair(false, 0);
265 cap::replaceSelectionWithString(cur, replacestr);
267 cur.pos() += replacestr.length();
268 LASSERT(cur.pos() <= cur.lastpos(),
269 cur.pos() = cur.lastpos());
272 findOne(bv, searchstr, case_sens, whole, forward, false);
274 return make_pair(true, 1);
280 docstring const find2string(docstring const & search,
281 bool casesensitive, bool matchword, bool forward)
285 << int(casesensitive) << ' '
286 << int(matchword) << ' '
292 docstring const replace2string(docstring const & replace,
293 docstring const & search,
294 bool casesensitive, bool matchword,
295 bool all, bool forward, bool findnext)
298 ss << replace << '\n'
300 << int(casesensitive) << ' '
301 << int(matchword) << ' '
303 << int(forward) << ' '
309 bool lyxfind(BufferView * bv, FuncRequest const & ev)
311 if (!bv || ev.action() != LFUN_WORD_FIND)
314 //lyxerr << "find called, cmd: " << ev << endl;
316 // data is of the form
318 // <casesensitive> <matchword> <forward>"
320 docstring howto = split(ev.argument(), search, '\n');
322 bool casesensitive = parse_bool(howto);
323 bool matchword = parse_bool(howto);
324 bool forward = parse_bool(howto);
326 return findOne(bv, search, casesensitive, matchword, forward);
330 bool lyxreplace(BufferView * bv,
331 FuncRequest const & ev, bool has_deleted)
333 if (!bv || ev.action() != LFUN_WORD_REPLACE)
336 // data is of the form
339 // <casesensitive> <matchword> <all> <forward> <findnext>"
342 docstring howto = split(ev.argument(), rplc, '\n');
343 howto = split(howto, search, '\n');
345 bool casesensitive = parse_bool(howto);
346 bool matchword = parse_bool(howto);
347 bool all = parse_bool(howto);
348 bool forward = parse_bool(howto);
349 bool findnext = howto.empty() ? true : parse_bool(howto);
354 int replace_count = 0;
356 replace_count = replaceAll(bv, search, rplc, casesensitive, matchword);
357 update = replace_count > 0;
360 replaceOne(bv, search, rplc, casesensitive, matchword, forward, findnext);
362 replace_count = rv.second;
365 Buffer const & buf = bv->buffer();
367 // emit message signal.
368 buf.message(_("String not found."));
370 if (replace_count == 0) {
371 buf.message(_("String found."));
372 } else if (replace_count == 1) {
373 buf.message(_("String has been replaced."));
375 docstring const str =
376 bformat(_("%1$d strings have been replaced."), replace_count);
380 } else if (findnext) {
381 // if we have deleted characters, we do not replace at all, but
382 // rather search for the next occurence
383 if (findOne(bv, search, casesensitive, matchword, forward))
386 bv->message(_("String not found."));
392 bool findNextChange(DocIterator & cur)
394 for (; cur; cur.forwardPos())
395 if (cur.inTexted() && cur.paragraph().isChanged(cur.pos()))
401 bool findPreviousChange(DocIterator & cur)
403 for (cur.backwardPos(); cur; cur.backwardPos()) {
404 if (cur.inTexted() && cur.paragraph().isChanged(cur.pos()))
411 bool selectChange(Cursor & cur, bool forward)
413 if (!cur.inTexted() || !cur.paragraph().isChanged(cur.pos()))
415 Change ch = cur.paragraph().lookupChange(cur.pos());
417 CursorSlice tip1 = cur.top();
418 for (; tip1.pit() < tip1.lastpit() || tip1.pos() < tip1.lastpos(); tip1.forwardPos()) {
419 Change ch2 = tip1.paragraph().lookupChange(tip1.pos());
420 if (!ch2.isSimilarTo(ch))
423 CursorSlice tip2 = cur.top();
424 for (; tip2.pit() > 0 || tip2.pos() > 0;) {
426 Change ch2 = tip2.paragraph().lookupChange(tip2.pos());
427 if (!ch2.isSimilarTo(ch)) {
428 // take a step forward to correctly set the selection
436 cur.bv().mouseSetCursor(cur, false);
438 cur.bv().mouseSetCursor(cur, true);
446 bool findChange(BufferView * bv, bool forward)
449 cur.setCursor(forward ? bv->cursor().selectionEnd()
450 : bv->cursor().selectionBegin());
451 forward ? findNextChange(cur) : findPreviousChange(cur);
452 return selectChange(cur, forward);
457 bool findNextChange(BufferView * bv)
459 return findChange(bv, true);
463 bool findPreviousChange(BufferView * bv)
465 return findChange(bv, false);
472 typedef vector<pair<string, string> > Escapes;
474 /// A map of symbols and their escaped equivalent needed within a regex.
475 /// @note Beware of order
476 Escapes const & get_regexp_escapes()
478 typedef std::pair<std::string, std::string> P;
480 static Escapes escape_map;
481 if (escape_map.empty()) {
482 escape_map.push_back(P("$", "_x_$"));
483 escape_map.push_back(P("{", "_x_{"));
484 escape_map.push_back(P("}", "_x_}"));
485 escape_map.push_back(P("[", "_x_["));
486 escape_map.push_back(P("]", "_x_]"));
487 escape_map.push_back(P("(", "_x_("));
488 escape_map.push_back(P(")", "_x_)"));
489 escape_map.push_back(P("+", "_x_+"));
490 escape_map.push_back(P("*", "_x_*"));
491 escape_map.push_back(P(".", "_x_."));
492 escape_map.push_back(P("\\", "(?:\\\\|\\\\backslash)"));
493 escape_map.push_back(P("~", "(?:\\\\textasciitilde|\\\\sim)"));
494 escape_map.push_back(P("^", "(?:\\^|\\\\textasciicircum\\{\\}|\\\\mathcircumflex)"));
495 escape_map.push_back(P("_x_", "\\"));
500 /// A map of lyx escaped strings and their unescaped equivalent.
501 Escapes const & get_lyx_unescapes()
503 typedef std::pair<std::string, std::string> P;
505 static Escapes escape_map;
506 if (escape_map.empty()) {
507 escape_map.push_back(P("\\%", "%"));
508 escape_map.push_back(P("\\mathcircumflex ", "^"));
509 escape_map.push_back(P("\\mathcircumflex", "^"));
510 escape_map.push_back(P("\\backslash ", "\\"));
511 escape_map.push_back(P("\\backslash", "\\"));
512 escape_map.push_back(P("\\\\{", "_x_<"));
513 escape_map.push_back(P("\\\\}", "_x_>"));
514 escape_map.push_back(P("\\sim ", "~"));
515 escape_map.push_back(P("\\sim", "~"));
520 /// A map of escapes turning a regexp matching text to one matching latex.
521 Escapes const & get_regexp_latex_escapes()
523 typedef std::pair<std::string, std::string> P;
525 static Escapes escape_map;
526 if (escape_map.empty()) {
527 escape_map.push_back(P("\\\\", "(?:\\\\\\\\|\\\\backslash|\\\\textbackslash\\{\\})"));
528 escape_map.push_back(P("(<?!\\\\\\\\textbackslash)\\{", "\\\\\\{"));
529 escape_map.push_back(P("(<?!\\\\\\\\textbackslash\\\\\\{)\\}", "\\\\\\}"));
530 escape_map.push_back(P("\\[", "\\{\\[\\}"));
531 escape_map.push_back(P("\\]", "\\{\\]\\}"));
532 escape_map.push_back(P("\\^", "(?:\\^|\\\\textasciicircum\\{\\}|\\\\mathcircumflex)"));
533 escape_map.push_back(P("%", "\\\\\\%"));
538 /** @todo Probably the maps need to be migrated to regexps, in order to distinguish if
539 ** the found occurrence were escaped.
541 string apply_escapes(string s, Escapes const & escape_map)
543 LYXERR(Debug::FIND, "Escaping: '" << s << "'");
544 Escapes::const_iterator it;
545 for (it = escape_map.begin(); it != escape_map.end(); ++it) {
546 // LYXERR(Debug::FIND, "Escaping " << it->first << " as " << it->second);
547 unsigned int pos = 0;
548 while (pos < s.length() && (pos = s.find(it->first, pos)) < s.length()) {
549 s.replace(pos, it->first.length(), it->second);
550 LYXERR(Debug::FIND, "After escape: " << s);
551 pos += it->second.length();
552 // LYXERR(Debug::FIND, "pos: " << pos);
555 LYXERR(Debug::FIND, "Escaped : '" << s << "'");
560 /// Within \regexp{} apply get_lyx_unescapes() only (i.e., preserve regexp semantics of the string),
561 /// while outside apply get_lyx_unescapes()+get_regexp_escapes().
562 /// If match_latex is true, then apply regexp_latex_escapes() to \regexp{} contents as well.
563 string escape_for_regex(string s, bool match_latex)
566 while (pos < s.size()) {
567 size_t new_pos = s.find("\\regexp{", pos);
568 if (new_pos == string::npos)
570 LYXERR(Debug::FIND, "new_pos: " << new_pos);
571 string t = apply_escapes(s.substr(pos, new_pos - pos), get_lyx_unescapes());
572 LYXERR(Debug::FIND, "t [lyx]: " << t);
573 t = apply_escapes(t, get_regexp_escapes());
574 LYXERR(Debug::FIND, "t [rxp]: " << t);
575 s.replace(pos, new_pos - pos, t);
576 new_pos = pos + t.size();
577 LYXERR(Debug::FIND, "Regexp after escaping: " << s);
578 LYXERR(Debug::FIND, "new_pos: " << new_pos);
579 if (new_pos == s.size())
581 // Might fail if \\endregexp{} is preceeded by unexpected stuff (weird escapes)
582 size_t end_pos = s.find("\\endregexp{}}", new_pos + 8);
583 LYXERR(Debug::FIND, "end_pos: " << end_pos);
584 t = s.substr(new_pos + 8, end_pos - (new_pos + 8));
585 LYXERR(Debug::FIND, "t in regexp : " << t);
586 t = apply_escapes(t, get_lyx_unescapes());
587 LYXERR(Debug::FIND, "t in regexp [lyx]: " << t);
589 t = apply_escapes(t, get_regexp_latex_escapes());
590 LYXERR(Debug::FIND, "t in regexp [ltx]: " << t);
592 if (end_pos == s.size()) {
593 s.replace(new_pos, end_pos - new_pos, t);
594 LYXERR(Debug::FIND, "Regexp after \\regexp{} removal: " << s);
597 s.replace(new_pos, end_pos + 13 - new_pos, t);
598 LYXERR(Debug::FIND, "Regexp after \\regexp{...\\endregexp{}} removal: " << s);
599 pos = new_pos + t.size();
600 LYXERR(Debug::FIND, "pos: " << pos);
606 /// Wrapper for lyx::regex_replace with simpler interface
607 bool regex_replace(string const & s, string & t, string const & searchstr,
608 string const & replacestr)
610 lyx::regex e(searchstr);
612 ostream_iterator<char, char> it(oss);
613 lyx::regex_replace(it, s.begin(), s.end(), e, replacestr);
614 // tolerate t and s be references to the same variable
615 bool rv = (s != oss.str());
621 /** Checks if supplied string segment is well-formed from the standpoint of matching open-closed braces.
623 ** Verify that closed braces exactly match open braces. This avoids that, for example,
624 ** \frac{.*}{x} matches \frac{x+\frac{y}{x}}{z} with .* being 'x+\frac{y'.
627 ** Number of open braces that must remain open at the end for the verification to succeed.
629 bool braces_match(string::const_iterator const & beg,
630 string::const_iterator const & end,
634 string::const_iterator it = beg;
635 LYXERR(Debug::FIND, "Checking " << unmatched << " unmatched braces in '" << string(beg, end) << "'");
636 for (; it != end; ++it) {
637 // Skip escaped braces in the count
642 } else if (*it == '{') {
644 } else if (*it == '}') {
645 if (open_pars == 0) {
646 LYXERR(Debug::FIND, "Found unmatched closed brace");
652 if (open_pars != unmatched) {
653 LYXERR(Debug::FIND, "Found " << open_pars
654 << " instead of " << unmatched
655 << " unmatched open braces at the end of count");
658 LYXERR(Debug::FIND, "Braces match as expected");
663 /** The class performing a match between a position in the document and the FindAdvOptions.
665 class MatchStringAdv {
667 MatchStringAdv(lyx::Buffer & buf, FindAndReplaceOptions const & opt);
669 /** Tests if text starting at the supplied position matches with the one provided to the MatchStringAdv
670 ** constructor as opt.search, under the opt.* options settings.
673 ** If set, then match is searched only against beginning of text starting at cur.
674 ** If unset, then match is searched anywhere in text starting at cur.
677 ** The length of the matching text, or zero if no match was found.
679 int operator()(DocIterator const & cur, int len = -1, bool at_begin = true) const;
684 /// first buffer on which search was started
685 lyx::Buffer * const p_first_buf;
687 FindAndReplaceOptions const & opt;
690 /// Auxiliary find method (does not account for opt.matchword)
691 int findAux(DocIterator const & cur, int len = -1, bool at_begin = true) const;
693 /** Normalize a stringified or latexified LyX paragraph.
697 ** <li>if search is not casesensitive, then lowercase the string;
698 ** <li>remove any newline at begin or end of the string;
699 ** <li>replace any newline in the middle of the string with a simple space;
700 ** <li>remove stale empty styles and environments, like \emph{} and \textbf{}.
703 ** @todo Normalization should also expand macros, if the corresponding
704 ** search option was checked.
706 string normalize(docstring const & s, bool hack_braces) const;
707 // normalized string to search
708 string par_as_string;
709 // regular expression to use for searching
711 // same as regexp, but prefixed with a ".*"
713 // leading format material as string
714 string lead_as_string;
715 // par_as_string after removal of lead_as_string
716 string par_as_string_nolead;
717 // unmatched open braces in the search string/regexp
719 // number of (.*?) subexpressions added at end of search regexp for closing
720 // environments, math mode, styles, etc...
722 // Are we searching with regular expressions ?
727 static docstring buffer_to_latex(Buffer & buffer)
729 OutputParams runparams(&buffer.params().encoding());
730 odocstringstream ods;
731 otexstream os(ods, false);
732 runparams.nice = true;
733 runparams.flavor = OutputParams::LATEX;
734 runparams.linelen = 80; //lyxrc.plaintext_linelen;
735 // No side effect of file copying and image conversion
736 runparams.dryrun = true;
737 pit_type const endpit = buffer.paragraphs().size();
738 for (pit_type pit = 0; pit != endpit; ++pit) {
739 TeXOnePar(buffer, buffer.text(), pit, os, runparams);
740 LYXERR(Debug::FIND, "searchString up to here: " << ods.str());
746 static docstring stringifySearchBuffer(Buffer & buffer, FindAndReplaceOptions const & opt)
749 if (!opt.ignoreformat) {
750 str = buffer_to_latex(buffer);
752 OutputParams runparams(&buffer.params().encoding());
753 runparams.nice = true;
754 runparams.flavor = OutputParams::LATEX;
755 runparams.linelen = 100000; //lyxrc.plaintext_linelen;
756 runparams.dryrun = true;
757 runparams.for_search = true;
758 for (pos_type pit = pos_type(0); pit < (pos_type)buffer.paragraphs().size(); ++pit) {
759 Paragraph const & par = buffer.paragraphs().at(pit);
760 LYXERR(Debug::FIND, "Adding to search string: '"
761 << par.asString(pos_type(0), par.size(),
762 AS_STR_INSETS | AS_STR_SKIPDELETE | AS_STR_PLAINTEXT,
765 str += par.asString(pos_type(0), par.size(),
766 AS_STR_INSETS | AS_STR_SKIPDELETE | AS_STR_PLAINTEXT,
774 /// Return separation pos between the leading material and the rest
775 static size_t identifyLeading(string const & s)
778 // @TODO Support \item[text]
779 while (regex_replace(t, t, "^\\\\(emph|textbf|subsubsection|subsection|section|subparagraph|paragraph|part)\\*?\\{", "")
780 || regex_replace(t, t, "^\\$", "")
781 || regex_replace(t, t, "^\\\\\\[ ", "")
782 || regex_replace(t, t, "^\\\\item ", "")
783 || regex_replace(t, t, "^\\\\begin\\{[a-zA-Z_]*\\*?\\} ", ""))
784 LYXERR(Debug::FIND, " after removing leading $, \\[ , \\emph{, \\textbf{, etc.: '" << t << "'");
789 // Remove trailing closure of math, macros and environments, so to catch parts of them.
790 static int identifyClosing(string & t)
794 LYXERR(Debug::FIND, "identifyClosing(): t now is '" << t << "'");
795 if (regex_replace(t, t, "(.*[^\\\\])\\$\\'", "$1"))
797 if (regex_replace(t, t, "(.*[^\\\\]) \\\\\\]\\'", "$1"))
799 if (regex_replace(t, t, "(.*[^\\\\]) \\\\end\\{[a-zA-Z_]*\\*?\\}\\'", "$1"))
801 if (regex_replace(t, t, "(.*[^\\\\])\\}\\'", "$1")) {
811 MatchStringAdv::MatchStringAdv(lyx::Buffer & buf, FindAndReplaceOptions const & opt)
812 : p_buf(&buf), p_first_buf(&buf), opt(opt)
814 Buffer & find_buf = *theBufferList().getBuffer(FileName(to_utf8(opt.find_buf_name)), true);
815 docstring const & ds = stringifySearchBuffer(find_buf, opt);
816 use_regexp = lyx::to_utf8(ds).find("\\regexp{") != std::string::npos;
817 // When using regexp, braces are hacked already by escape_for_regex()
818 par_as_string = normalize(ds, !use_regexp);
822 size_t lead_size = 0;
823 if (opt.ignoreformat) {
825 // if par_as_string_nolead were emty,
826 // the following call to findAux will always *find* the string
827 // in the checked data, and thus always using the slow
828 // examining of the current text part.
829 par_as_string_nolead = par_as_string;
832 lead_size = identifyLeading(par_as_string);
833 lead_as_string = par_as_string.substr(0, lead_size);
834 par_as_string_nolead = par_as_string.substr(lead_size, par_as_string.size() - lead_size);
838 open_braces = identifyClosing(par_as_string);
839 identifyClosing(par_as_string_nolead);
840 LYXERR(Debug::FIND, "Open braces: " << open_braces);
841 LYXERR(Debug::FIND, "Built MatchStringAdv object: par_as_string = '" << par_as_string << "'");
843 string lead_as_regexp;
845 // @todo No need to search for \regexp{} insets in leading material
846 lead_as_regexp = escape_for_regex(par_as_string.substr(0, lead_size), !opt.ignoreformat);
847 par_as_string = par_as_string_nolead;
848 LYXERR(Debug::FIND, "lead_as_regexp is '" << lead_as_regexp << "'");
849 LYXERR(Debug::FIND, "par_as_string now is '" << par_as_string << "'");
851 par_as_string = escape_for_regex(par_as_string, !opt.ignoreformat);
852 // Insert (.*?) before trailing closure of math, macros and environments, so to catch parts of them.
853 LYXERR(Debug::FIND, "par_as_string now is '" << par_as_string << "'");
855 // Insert .* before trailing '\$' ('$' has been escaped by escape_for_regex)
856 regex_replace(par_as_string, par_as_string, "(.*[^\\\\])(\\\\\\$)\\'", "$1(.*?)$2")
857 // Insert .* before trailing '\\\]' ('\]' has been escaped by escape_for_regex)
858 || regex_replace(par_as_string, par_as_string, "(.*[^\\\\])( \\\\\\\\\\\\\\])\\'", "$1(.*?)$2")
859 // Insert .* before trailing '\\end\{...}' ('\end{...}' has been escaped by escape_for_regex)
860 || regex_replace(par_as_string, par_as_string,
861 "(.*[^\\\\])( \\\\\\\\end\\\\\\{[a-zA-Z_]*)(\\\\\\*)?(\\\\\\})\\'", "$1(.*?)$2$3$4")
862 // Insert .* before trailing '\}' ('}' has been escaped by escape_for_regex)
863 || regex_replace(par_as_string, par_as_string, "(.*[^\\\\])(\\\\\\})\\'", "$1(.*?)$2")
867 LYXERR(Debug::FIND, "par_as_string now is '" << par_as_string << "'");
868 LYXERR(Debug::FIND, "Open braces: " << open_braces);
869 LYXERR(Debug::FIND, "Close .*? : " << close_wildcards);
870 LYXERR(Debug::FIND, "Replaced text (to be used as regex): " << par_as_string);
871 // If entered regexp must match at begin of searched string buffer
872 string regexp_str = string("\\`") + lead_as_regexp + par_as_string;
873 LYXERR(Debug::FIND, "Setting regexp to : '" << regexp_str << "'");
874 regexp = lyx::regex(regexp_str);
876 // If entered regexp may match wherever in searched string buffer
877 string regexp2_str = string("\\`.*") + lead_as_regexp + ".*" + par_as_string;
878 LYXERR(Debug::FIND, "Setting regexp2 to: '" << regexp2_str << "'");
879 regexp2 = lyx::regex(regexp2_str);
884 int MatchStringAdv::findAux(DocIterator const & cur, int len, bool at_begin) const
887 (opt.restr == FindAndReplaceOptions::R_ONLY_MATHS && !cur.inMathed()) )
889 docstring docstr = stringifyFromForSearch(opt, cur, len);
890 LYXERR(Debug::FIND, "Matching against '" << lyx::to_utf8(docstr) << "'");
891 string str = normalize(docstr, true);
892 LYXERR(Debug::FIND, "After normalization: '" << str << "'");
894 LYXERR(Debug::FIND, "Searching in normal mode: par_as_string='" << par_as_string << "', str='" << str << "'");
895 LYXERR(Debug::FIND, "Searching in normal mode: lead_as_string='" << lead_as_string << "', par_as_string_nolead='" << par_as_string_nolead << "'");
897 LYXERR(Debug::FIND, "size=" << par_as_string.size() << ", substr='" << str.substr(0, par_as_string.size()) << "'");
898 if (str.substr(0, par_as_string.size()) == par_as_string)
899 return par_as_string.size();
901 size_t pos = str.find(par_as_string_nolead);
902 if (pos != string::npos)
903 return par_as_string.size();
906 LYXERR(Debug::FIND, "Searching in regexp mode: at_begin=" << at_begin);
907 // Try all possible regexp matches,
908 //until one that verifies the braces match test is found
909 regex const *p_regexp = at_begin ? ®exp : ®exp2;
910 sregex_iterator re_it(str.begin(), str.end(), *p_regexp);
911 sregex_iterator re_it_end;
912 for (; re_it != re_it_end; ++re_it) {
913 match_results<string::const_iterator> const & m = *re_it;
914 // Check braces on the segment that matched the entire regexp expression,
915 // plus the last subexpression, if a (.*?) was inserted in the constructor.
916 if (!braces_match(m[0].first, m[0].second, open_braces))
918 // Check braces on segments that matched all (.*?) subexpressions,
919 // except the last "padding" one inserted by lyx.
920 for (size_t i = 1; i < m.size() - 1; ++i)
921 if (!braces_match(m[i].first, m[i].second))
923 // Exclude from the returned match length any length
924 // due to close wildcards added at end of regexp
925 if (close_wildcards == 0)
926 return m[0].second - m[0].first;
928 return m[m.size() - close_wildcards].first - m[0].first;
935 int MatchStringAdv::operator()(DocIterator const & cur, int len, bool at_begin) const
937 int res = findAux(cur, len, at_begin);
939 "res=" << res << ", at_begin=" << at_begin
940 << ", matchword=" << opt.matchword
941 << ", inTexted=" << cur.inTexted());
942 if (res == 0 || !at_begin || !opt.matchword || !cur.inTexted())
944 Paragraph const & par = cur.paragraph();
945 bool ws_left = (cur.pos() > 0)
946 ? par.isWordSeparator(cur.pos() - 1)
948 bool ws_right = (cur.pos() + res < par.size())
949 ? par.isWordSeparator(cur.pos() + res)
952 "cur.pos()=" << cur.pos() << ", res=" << res
953 << ", separ: " << ws_left << ", " << ws_right
955 if (ws_left && ws_right)
961 string MatchStringAdv::normalize(docstring const & s, bool hack_braces) const
964 if (! opt.casesensitive)
965 t = lyx::to_utf8(lowercase(s));
968 // Remove \n at begin
969 while (!t.empty() && t[0] == '\n')
972 while (!t.empty() && t[t.size() - 1] == '\n')
973 t = t.substr(0, t.size() - 1);
975 // Replace all other \n with spaces
976 while ((pos = t.find("\n")) != string::npos)
977 t.replace(pos, 1, " ");
978 // Remove stale empty \emph{}, \textbf{} and similar blocks from latexify
979 LYXERR(Debug::FIND, "Removing stale empty \\emph{}, \\textbf{}, \\*section{} macros from: " << t);
980 while (regex_replace(t, t, "\\\\(emph|textbf|subsubsection|subsection|section|subparagraph|paragraph|part)(\\{\\})+", ""))
981 LYXERR(Debug::FIND, " further removing stale empty \\emph{}, \\textbf{} macros from: " << t);
983 // FIXME - check what preceeds the brace
985 if (opt.ignoreformat)
986 while (regex_replace(t, t, "\\{", "_x_<")
987 || regex_replace(t, t, "\\}", "_x_>"))
988 LYXERR(Debug::FIND, "After {} replacement: '" << t << "'");
990 while (regex_replace(t, t, "\\\\\\{", "_x_<")
991 || regex_replace(t, t, "\\\\\\}", "_x_>"))
992 LYXERR(Debug::FIND, "After {} replacement: '" << t << "'");
999 docstring stringifyFromCursor(DocIterator const & cur, int len)
1001 LYXERR(Debug::FIND, "Stringifying with len=" << len << " from cursor at pos: " << cur);
1002 if (cur.inTexted()) {
1003 Paragraph const & par = cur.paragraph();
1004 // TODO what about searching beyond/across paragraph breaks ?
1005 // TODO Try adding a AS_STR_INSERTS as last arg
1006 pos_type end = ( len == -1 || cur.pos() + len > int(par.size()) ) ?
1007 int(par.size()) : cur.pos() + len;
1008 OutputParams runparams(&cur.buffer()->params().encoding());
1009 runparams.nice = true;
1010 runparams.flavor = OutputParams::LATEX;
1011 runparams.linelen = 100000; //lyxrc.plaintext_linelen;
1012 // No side effect of file copying and image conversion
1013 runparams.dryrun = true;
1014 LYXERR(Debug::FIND, "Stringifying with cur: "
1015 << cur << ", from pos: " << cur.pos() << ", end: " << end);
1016 return par.asString(cur.pos(), end,
1017 AS_STR_INSETS | AS_STR_SKIPDELETE | AS_STR_PLAINTEXT,
1019 } else if (cur.inMathed()) {
1021 CursorSlice cs = cur.top();
1022 MathData md = cs.cell();
1023 MathData::const_iterator it_end =
1024 (( len == -1 || cs.pos() + len > int(md.size()))
1026 : md.begin() + cs.pos() + len );
1027 for (MathData::const_iterator it = md.begin() + cs.pos();
1029 s = s + asString(*it);
1030 LYXERR(Debug::FIND, "Stringified math: '" << s << "'");
1033 LYXERR(Debug::FIND, "Don't know how to stringify from here: " << cur);
1038 /** Computes the LaTeX export of buf starting from cur and ending len positions
1039 * after cur, if len is positive, or at the paragraph or innermost inset end
1042 docstring latexifyFromCursor(DocIterator const & cur, int len)
1044 LYXERR(Debug::FIND, "Latexifying with len=" << len << " from cursor at pos: " << cur);
1045 LYXERR(Debug::FIND, " with cur.lastpost=" << cur.lastpos() << ", cur.lastrow="
1046 << cur.lastrow() << ", cur.lastcol=" << cur.lastcol());
1047 Buffer const & buf = *cur.buffer();
1048 LBUFERR(buf.params().isLatex());
1050 odocstringstream ods;
1051 otexstream os(ods, false);
1052 OutputParams runparams(&buf.params().encoding());
1053 runparams.nice = false;
1054 runparams.flavor = OutputParams::LATEX;
1055 runparams.linelen = 8000; //lyxrc.plaintext_linelen;
1056 // No side effect of file copying and image conversion
1057 runparams.dryrun = true;
1059 if (cur.inTexted()) {
1060 // @TODO what about searching beyond/across paragraph breaks ?
1061 pos_type endpos = cur.paragraph().size();
1062 if (len != -1 && endpos > cur.pos() + len)
1063 endpos = cur.pos() + len;
1064 TeXOnePar(buf, *cur.innerText(), cur.pit(), os, runparams,
1065 string(), cur.pos(), endpos);
1066 LYXERR(Debug::FIND, "Latexified text: '" << lyx::to_utf8(ods.str()) << "'");
1067 } else if (cur.inMathed()) {
1068 // Retrieve the math environment type, and add '$' or '$[' or others (\begin{equation}) accordingly
1069 for (int s = cur.depth() - 1; s >= 0; --s) {
1070 CursorSlice const & cs = cur[s];
1071 if (cs.asInsetMath() && cs.asInsetMath()->asHullInset()) {
1073 cs.asInsetMath()->asHullInset()->header_write(ws);
1078 CursorSlice const & cs = cur.top();
1079 MathData md = cs.cell();
1080 MathData::const_iterator it_end =
1081 ((len == -1 || cs.pos() + len > int(md.size()))
1083 : md.begin() + cs.pos() + len);
1084 for (MathData::const_iterator it = md.begin() + cs.pos();
1086 ods << asString(*it);
1088 // Retrieve the math environment type, and add '$' or '$]'
1089 // or others (\end{equation}) accordingly
1090 for (int s = cur.depth() - 1; s >= 0; --s) {
1091 CursorSlice const & cs = cur[s];
1092 InsetMath * inset = cs.asInsetMath();
1093 if (inset && inset->asHullInset()) {
1095 inset->asHullInset()->footer_write(ws);
1099 LYXERR(Debug::FIND, "Latexified math: '" << lyx::to_utf8(ods.str()) << "'");
1101 LYXERR(Debug::FIND, "Don't know how to stringify from here: " << cur);
1107 /** Finalize an advanced find operation, advancing the cursor to the innermost
1108 ** position that matches, plus computing the length of the matching text to
1111 int findAdvFinalize(DocIterator & cur, MatchStringAdv const & match)
1113 // Search the foremost position that matches (avoids find of entire math
1114 // inset when match at start of it)
1116 DocIterator old_cur(cur.buffer());
1118 LYXERR(Debug::FIND, "Forwarding one step (searching for innermost match)");
1122 } while (cur && cur.depth() > d && match(cur) > 0);
1124 LASSERT(match(cur) > 0, return 0);
1125 LYXERR(Debug::FIND, "Ok");
1127 // Compute the match length
1129 if (cur.pos() + len > cur.lastpos())
1131 LYXERR(Debug::FIND, "verifying unmatch with len = " << len);
1132 while (cur.pos() + len <= cur.lastpos() && match(cur, len) == 0) {
1134 LYXERR(Debug::FIND, "verifying unmatch with len = " << len);
1136 // Length of matched text (different from len param)
1137 int old_len = match(cur, len);
1139 // Greedy behaviour while matching regexps
1140 while ((new_len = match(cur, len + 1)) > old_len) {
1143 LYXERR(Debug::FIND, "verifying match with len = " << len);
1150 int findForwardAdv(DocIterator & cur, MatchStringAdv & match)
1154 while (!theApp()->longOperationCancelled() && cur) {
1155 LYXERR(Debug::FIND, "findForwardAdv() cur: " << cur);
1156 int match_len = match(cur, -1, false);
1157 LYXERR(Debug::FIND, "match_len: " << match_len);
1159 for (; !theApp()->longOperationCancelled() && cur; cur.forwardPos()) {
1160 LYXERR(Debug::FIND, "Advancing cur: " << cur);
1161 int match_len = match(cur);
1162 LYXERR(Debug::FIND, "match_len: " << match_len);
1164 // Sometimes in finalize we understand it wasn't a match
1165 // and we need to continue the outest loop
1166 int len = findAdvFinalize(cur, match);
1174 if (cur.pit() < cur.lastpit()) {
1175 LYXERR(Debug::FIND, "Advancing par: cur=" << cur);
1178 // This should exit nested insets, if any, or otherwise undefine the currsor.
1179 cur.pos() = cur.lastpos();
1180 LYXERR(Debug::FIND, "Advancing pos: cur=" << cur);
1188 /// Find the most backward consecutive match within same paragraph while searching backwards.
1189 int findMostBackwards(DocIterator & cur, MatchStringAdv const & match)
1191 DocIterator cur_begin = doc_iterator_begin(cur.buffer());
1192 DocIterator tmp_cur = cur;
1193 int len = findAdvFinalize(tmp_cur, match);
1194 Inset & inset = cur.inset();
1195 for (; cur != cur_begin; cur.backwardPos()) {
1196 LYXERR(Debug::FIND, "findMostBackwards(): cur=" << cur);
1197 DocIterator new_cur = cur;
1198 new_cur.backwardPos();
1199 if (new_cur == cur || &new_cur.inset() != &inset || !match(new_cur))
1201 int new_len = findAdvFinalize(new_cur, match);
1206 LYXERR(Debug::FIND, "findMostBackwards(): exiting with cur=" << cur);
1212 int findBackwardsAdv(DocIterator & cur, MatchStringAdv & match)
1216 // Backup of original position
1217 DocIterator cur_begin = doc_iterator_begin(cur.buffer());
1218 if (cur == cur_begin)
1221 DocIterator cur_orig(cur);
1222 bool pit_changed = false;
1225 bool found_match = match(cur, -1, false);
1229 cur.pos() = cur.lastpos();
1231 cur.pos() = cur_orig.pos();
1232 LYXERR(Debug::FIND, "findBackAdv2: cur: " << cur);
1233 DocIterator cur_prev_iter;
1235 found_match = match(cur);
1236 LYXERR(Debug::FIND, "findBackAdv3: found_match="
1237 << found_match << ", cur: " << cur);
1239 return findMostBackwards(cur, match);
1241 // Stop if begin of document reached
1242 if (cur == cur_begin)
1244 cur_prev_iter = cur;
1248 if (cur == cur_begin)
1255 } while (!theApp()->longOperationCancelled());
1260 } // anonym namespace
1263 docstring stringifyFromForSearch(FindAndReplaceOptions const & opt,
1264 DocIterator const & cur, int len)
1266 LASSERT(cur.pos() >= 0 && cur.pos() <= cur.lastpos(),
1267 return docstring());
1268 if (!opt.ignoreformat)
1269 return latexifyFromCursor(cur, len);
1271 return stringifyFromCursor(cur, len);
1275 FindAndReplaceOptions::FindAndReplaceOptions(
1276 docstring const & find_buf_name, bool casesensitive,
1277 bool matchword, bool forward, bool expandmacros, bool ignoreformat,
1278 docstring const & repl_buf_name, bool keep_case,
1279 SearchScope scope, SearchRestriction restr)
1280 : find_buf_name(find_buf_name), casesensitive(casesensitive), matchword(matchword),
1281 forward(forward), expandmacros(expandmacros), ignoreformat(ignoreformat),
1282 repl_buf_name(repl_buf_name), keep_case(keep_case), scope(scope), restr(restr)
1290 /** Check if 'len' letters following cursor are all non-lowercase */
1291 static bool allNonLowercase(Cursor const & cur, int len)
1293 pos_type beg_pos = cur.selectionBegin().pos();
1294 pos_type end_pos = cur.selectionBegin().pos() + len;
1295 if (len > cur.lastpos() + 1 - beg_pos) {
1296 LYXERR(Debug::FIND, "This should not happen, more debug needed");
1297 len = cur.lastpos() + 1 - beg_pos;
1298 end_pos = beg_pos + len;
1300 for (pos_type pos = beg_pos; pos != end_pos; ++pos)
1301 if (isLowerCase(cur.paragraph().getChar(pos)))
1307 /** Check if first letter is upper case and second one is lower case */
1308 static bool firstUppercase(Cursor const & cur)
1311 pos_type pos = cur.selectionBegin().pos();
1312 if (pos >= cur.lastpos() - 1) {
1313 LYXERR(Debug::FIND, "No upper-case at cur: " << cur);
1316 ch1 = cur.paragraph().getChar(pos);
1317 ch2 = cur.paragraph().getChar(pos + 1);
1318 bool result = isUpperCase(ch1) && isLowerCase(ch2);
1319 LYXERR(Debug::FIND, "firstUppercase(): "
1320 << "ch1=" << ch1 << "(" << char(ch1) << "), ch2="
1321 << ch2 << "(" << char(ch2) << ")"
1322 << ", result=" << result << ", cur=" << cur);
1327 /** Make first letter of supplied buffer upper-case, and the rest lower-case.
1329 ** \fixme What to do with possible further paragraphs in replace buffer ?
1331 static void changeFirstCase(Buffer & buffer, TextCase first_case, TextCase others_case)
1333 ParagraphList::iterator pit = buffer.paragraphs().begin();
1334 LASSERT(pit->size() >= 1, /**/);
1335 pos_type right = pos_type(1);
1336 pit->changeCase(buffer.params(), pos_type(0), right, first_case);
1337 right = pit->size();
1338 pit->changeCase(buffer.params(), pos_type(1), right, others_case);
1344 static void findAdvReplace(BufferView * bv, FindAndReplaceOptions const & opt, MatchStringAdv & matchAdv)
1346 Cursor & cur = bv->cursor();
1347 if (opt.repl_buf_name == docstring())
1350 DocIterator sel_beg = cur.selectionBegin();
1351 DocIterator sel_end = cur.selectionEnd();
1352 if (&sel_beg.inset() != &sel_end.inset()
1353 || sel_beg.pit() != sel_end.pit()
1354 || sel_beg.idx() != sel_end.idx())
1356 int sel_len = sel_end.pos() - sel_beg.pos();
1357 LYXERR(Debug::FIND, "sel_beg: " << sel_beg << ", sel_end: " << sel_end
1358 << ", sel_len: " << sel_len << endl);
1361 LASSERT(sel_len > 0, return);
1363 if (!matchAdv(sel_beg, sel_len))
1366 // Build a copy of the replace buffer, adapted to the KeepCase option
1367 Buffer & repl_buffer_orig = *theBufferList().getBuffer(FileName(to_utf8(opt.repl_buf_name)), true);
1369 repl_buffer_orig.write(oss);
1370 string lyx = oss.str();
1371 Buffer repl_buffer("", false);
1372 repl_buffer.setUnnamed(true);
1373 LASSERT(repl_buffer.readString(lyx), return);
1374 if (opt.keep_case && sel_len >= 2) {
1375 LYXERR(Debug::FIND, "keep_case true: cur.pos()=" << cur.pos() << ", sel_len=" << sel_len);
1376 if (cur.inTexted()) {
1377 if (firstUppercase(cur))
1378 changeFirstCase(repl_buffer, text_uppercase, text_lowercase);
1379 else if (allNonLowercase(cur, sel_len))
1380 changeFirstCase(repl_buffer, text_uppercase, text_uppercase);
1383 cap::cutSelection(cur, false, false);
1384 if (cur.inTexted()) {
1385 repl_buffer.changeLanguage(
1386 repl_buffer.language(),
1387 cur.getFont().language());
1388 LYXERR(Debug::FIND, "Replacing by pasteParagraphList()ing repl_buffer");
1389 LYXERR(Debug::FIND, "Before pasteParagraphList() cur=" << cur << endl);
1390 cap::pasteParagraphList(cur, repl_buffer.paragraphs(),
1391 repl_buffer.params().documentClassPtr(),
1392 bv->buffer().errorList("Paste"));
1393 LYXERR(Debug::FIND, "After pasteParagraphList() cur=" << cur << endl);
1394 sel_len = repl_buffer.paragraphs().begin()->size();
1395 } else if (cur.inMathed()) {
1396 odocstringstream ods;
1397 otexstream os(ods, false);
1398 OutputParams runparams(&repl_buffer.params().encoding());
1399 runparams.nice = false;
1400 runparams.flavor = OutputParams::LATEX;
1401 runparams.linelen = 8000; //lyxrc.plaintext_linelen;
1402 runparams.dryrun = true;
1403 TeXOnePar(repl_buffer, repl_buffer.text(), 0, os, runparams);
1404 //repl_buffer.getSourceCode(ods, 0, repl_buffer.paragraphs().size(), false);
1405 docstring repl_latex = ods.str();
1406 LYXERR(Debug::FIND, "Latexified replace_buffer: '" << repl_latex << "'");
1408 // false positive from coverity
1409 // coverity[CHECKED_RETURN]
1410 regex_replace(to_utf8(repl_latex), s, "\\$(.*)\\$", "$1");
1411 regex_replace(s, s, "\\\\\\[(.*)\\\\\\]", "$1");
1412 repl_latex = from_utf8(s);
1413 LYXERR(Debug::FIND, "Replacing by insert()ing latex: '" << repl_latex << "' cur=" << cur << " with depth=" << cur.depth());
1414 MathData ar(cur.buffer());
1415 asArray(repl_latex, ar, Parse::NORMAL);
1417 sel_len = ar.size();
1418 LYXERR(Debug::FIND, "After insert() cur=" << cur << " with depth: " << cur.depth() << " and len: " << sel_len);
1420 if (cur.pos() >= sel_len)
1421 cur.pos() -= sel_len;
1424 LYXERR(Debug::FIND, "After pos adj cur=" << cur << " with depth: " << cur.depth() << " and len: " << sel_len);
1425 bv->putSelectionAt(DocIterator(cur), sel_len, !opt.forward);
1426 bv->processUpdateFlags(Update::Force);
1430 /// Perform a FindAdv operation.
1431 bool findAdv(BufferView * bv, FindAndReplaceOptions const & opt)
1437 MatchStringAdv matchAdv(bv->buffer(), opt);
1438 int length = bv->cursor().selectionEnd().pos() - bv->cursor().selectionBegin().pos();
1440 bv->putSelectionAt(bv->cursor().selectionBegin(), length, !opt.forward);
1441 findAdvReplace(bv, opt, matchAdv);
1444 match_len = findForwardAdv(cur, matchAdv);
1446 match_len = findBackwardsAdv(cur, matchAdv);
1448 // This may only be raised by lyx::regex()
1449 bv->message(_("Invalid regular expression!"));
1453 if (match_len == 0) {
1454 bv->message(_("Match not found!"));
1458 bv->message(_("Match found!"));
1460 LYXERR(Debug::FIND, "Putting selection at cur=" << cur << " with len: " << match_len);
1461 bv->putSelectionAt(cur, match_len, !opt.forward);
1467 ostringstream & operator<<(ostringstream & os, FindAndReplaceOptions const & opt)
1469 os << to_utf8(opt.find_buf_name) << "\nEOSS\n"
1470 << opt.casesensitive << ' '
1471 << opt.matchword << ' '
1472 << opt.forward << ' '
1473 << opt.expandmacros << ' '
1474 << opt.ignoreformat << ' '
1475 << to_utf8(opt.repl_buf_name) << "\nEOSS\n"
1476 << opt.keep_case << ' '
1477 << int(opt.scope) << ' '
1480 LYXERR(Debug::FIND, "built: " << os.str());
1486 istringstream & operator>>(istringstream & is, FindAndReplaceOptions & opt)
1488 LYXERR(Debug::FIND, "parsing");
1492 while (line != "EOSS") {
1496 if (is.eof()) // Tolerate malformed request
1500 LYXERR(Debug::FIND, "file_buf_name: '" << s << "'");
1501 opt.find_buf_name = from_utf8(s);
1502 is >> opt.casesensitive >> opt.matchword >> opt.forward >> opt.expandmacros >> opt.ignoreformat;
1503 is.get(); // Waste space before replace string
1506 while (line != "EOSS") {
1510 if (is.eof()) // Tolerate malformed request
1514 LYXERR(Debug::FIND, "repl_buf_name: '" << s << "'");
1515 opt.repl_buf_name = from_utf8(s);
1516 is >> opt.keep_case;
1519 opt.scope = FindAndReplaceOptions::SearchScope(i);
1521 opt.restr = FindAndReplaceOptions::SearchRestriction(i);
1523 LYXERR(Debug::FIND, "parsed: " << opt.casesensitive << ' ' << opt.matchword << ' ' << opt.forward << ' '
1524 << opt.expandmacros << ' ' << opt.ignoreformat << ' ' << opt.keep_case << ' '
1525 << opt.scope << ' ' << opt.restr);