-bool find(BufferView * bv,
- string const & searchstr, bool cs, bool mw, bool fw);
-
-
-int replace(BufferView * bv,
- string const & searchstr, string const & replacestr,
- bool cs, bool mw, bool fw);
-
-
-int replaceAll(BufferView * bv,
- string const & searchstr, string const & replacestr,
- bool cs, bool mw);
-
-
-bool findChange(PosIterator & cur, PosIterator const & end);
-
-} // namespace anon
-
-
-namespace lyx {
-namespace find {
-
-string const find2string(string const & search,
- bool casesensitive, bool matchword, bool forward)
-{
- ostringstream ss;
- ss << search << '\n'
- << int(casesensitive) << ' '
- << int(matchword) << ' '
- << int(forward);
-
- return ss.str();
-}
-
-
-string const replace2string(string const & search, string const & replace,
- bool casesensitive, bool matchword,
- bool all, bool forward)
-{
- ostringstream ss;
- ss << search << '\n'
- << replace << '\n'
- << int(casesensitive) << ' '
- << int(matchword) << ' '
- << int(all) << ' '
- << int(forward);
-
- return ss.str();
-}
-
-
-void find(BufferView * bv, FuncRequest const & ev)
-{
- if (!bv || ev.action != LFUN_WORD_FIND)
- return;
-
- // data is of the form
- // "<search>
- // <casesensitive> <matchword> <forward>"
- string search;
- string howto = split(ev.argument, search, '\n');
-
- bool casesensitive = parse_bool(howto);
- bool matchword = parse_bool(howto);
- bool forward = parse_bool(howto);
-
- bool const found = ::find(bv, search,
- forward, casesensitive, matchword);
-
- if (!found)
- bv->owner()->message(_("String not found!"));
-}
-
-
-void replace(BufferView * bv, FuncRequest const & ev)
-{
- if (!bv || ev.action != LFUN_WORD_REPLACE)
- return;
-
- // data is of the form
- // "<search>
- // <replace>
- // <casesensitive> <matchword> <all> <forward>"
- string search;
- string replace;
- string howto = split(ev.argument, search, '\n');
- howto = split(howto, replace, '\n');
-
- bool casesensitive = parse_bool(howto);
- bool matchword = parse_bool(howto);
- bool all = parse_bool(howto);
- bool forward = parse_bool(howto);
-
- LyXView * lv = bv->owner();
-
- int const replace_count = all ?
- ::replaceAll(bv, search, replace,
- casesensitive, matchword) :
- ::replace(bv, search, replace,
- casesensitive, matchword, forward);
-
- if (replace_count == 0) {
- lv->message(_("String not found!"));
- } else {
- if (replace_count == 1) {
- lv->message(_("String has been replaced."));
- } else {
- string str = tostr(replace_count);
- str += _(" strings have been replaced.");
- lv->message(str);
- }
- }
-}
-
-
-bool findNextChange(BufferView * bv)
-{
- if (!bv->available())
- return false;
-
- PosIterator cur = PosIterator(*bv);
- PosIterator const endit = bv->buffer()->pos_iterator_end();
-
- if (!findChange(cur, endit))
- return false;
-
- ParagraphList::iterator pit = cur.pit();
- pos_type pos = cur.pos();
-
- Change orig_change = pit->lookupChangeFull(pos);
- pos_type parsize = pit->size();
- pos_type end = pos;
-
- for (; end != parsize; ++end) {
- Change change = pit->lookupChangeFull(end);
- if (change != orig_change) {
- // slight UI optimisation: for replacements, we get
- // text like : _old_new. Consider that as one change.
- if (!(orig_change.type == Change::DELETED &&
- change.type == Change::INSERTED))
- break;
- }
- }
- pos_type length = end - pos;
- bv->putSelectionAt(cur, length, true);
- return true;
-}
-
-} // find namespace
-} // lyx namespace
-
-
-namespace {
-
-class MatchString