]> git.lyx.org Git - lyx.git/blobdiff - src/lyxfind.cpp
Merge branch 'master' of git.lyx.org:lyx
[lyx.git] / src / lyxfind.cpp
index 674dc1fdc4eb2faf33340b67c9bd3e1c4271d2a0..69a9b80883c37eaeb7bc14084484fa94e2b6920d 100644 (file)
@@ -348,10 +348,10 @@ bool lyxreplace(BufferView * bv,
        bool forward       = parse_bool(howto);
        bool findnext      = howto.empty() ? true : parse_bool(howto);
 
-       int replace_count = 0;
        bool update = false;
 
        if (!has_deleted) {
+               int replace_count = 0;
                if (all) {
                        replace_count = replaceAll(bv, search, rplc, casesensitive, matchword);
                        update = replace_count > 0;
@@ -385,7 +385,6 @@ bool lyxreplace(BufferView * bv,
                else
                        bv->message(_("String not found."));
        }
-       bv->buffer().updatePreviews();
        return update;
 }
 
@@ -592,7 +591,6 @@ string escape_for_regex(string s, bool match_latex)
                }
                if (end_pos == s.size()) {
                        s.replace(new_pos, end_pos - new_pos, t);
-                       pos = s.size();
                        LYXERR(Debug::FIND, "Regexp after \\regexp{} removal: " << s);
                        break;
                }
@@ -729,7 +727,7 @@ private:
 static docstring buffer_to_latex(Buffer & buffer)
 {
        OutputParams runparams(&buffer.params().encoding());
-       TexRow texrow;
+       TexRow texrow(false);
        odocstringstream ods;
        otexstream os(ods, texrow);
        runparams.nice = true;
@@ -1009,7 +1007,6 @@ docstring stringifyFromCursor(DocIterator const & cur, int len)
                pos_type end = ( len == -1 || cur.pos() + len > int(par.size()) ) ?
                        int(par.size()) : cur.pos() + len;
                OutputParams runparams(&cur.buffer()->params().encoding());
-               odocstringstream os;
                runparams.nice = true;
                runparams.flavor = OutputParams::LATEX;
                runparams.linelen = 100000; //lyxrc.plaintext_linelen;
@@ -1051,7 +1048,7 @@ docstring latexifyFromCursor(DocIterator const & cur, int len)
        Buffer const & buf = *cur.buffer();
        LBUFERR(buf.params().isLatex());
 
-       TexRow texrow;
+       TexRow texrow(false);
        odocstringstream ods;
        otexstream os(ods, texrow);
        OutputParams runparams(&buf.params().encoding());
@@ -1073,8 +1070,8 @@ docstring latexifyFromCursor(DocIterator const & cur, int len)
                // Retrieve the math environment type, and add '$' or '$[' or others (\begin{equation}) accordingly
                for (int s = cur.depth() - 1; s >= 0; --s) {
                        CursorSlice const & cs = cur[s];
-                       if (cs.asInsetMath() && cs.asInsetMath() && cs.asInsetMath()->asHullInset()) {
-                               WriteStream ws(ods);
+                       if (cs.asInsetMath() && cs.asInsetMath()->asHullInset()) {
+                               WriteStream ws(os);
                                cs.asInsetMath()->asHullInset()->header_write(ws);
                                break;
                        }
@@ -1096,7 +1093,7 @@ docstring latexifyFromCursor(DocIterator const & cur, int len)
                        CursorSlice const & cs = cur[s];
                        InsetMath * inset = cs.asInsetMath();
                        if (inset && inset->asHullInset()) {
-                               WriteStream ws(ods);
+                               WriteStream ws(os);
                                inset->asHullInset()->footer_write(ws);
                                break;
                        }
@@ -1224,12 +1221,10 @@ int findBackwardsAdv(DocIterator & cur, MatchStringAdv & match)
                return 0;
        cur.backwardPos();
        DocIterator cur_orig(cur);
-       bool found_match;
        bool pit_changed = false;
-       found_match = false;
        do {
                cur.pos() = 0;
-               found_match = match(cur, -1, false);
+               bool found_match = match(cur, -1, false);
 
                if (found_match) {
                        if (pit_changed)
@@ -1302,6 +1297,7 @@ static bool allNonLowercase(Cursor const & cur, int len)
        if (len > cur.lastpos() + 1 - beg_pos) {
                LYXERR(Debug::FIND, "This should not happen, more debug needed");
                len = cur.lastpos() + 1 - beg_pos;
+               end_pos = beg_pos + len;
        }
        for (pos_type pos = beg_pos; pos != end_pos; ++pos)
                if (isLowerCase(cur.paragraph().getChar(pos)))
@@ -1399,7 +1395,7 @@ static void findAdvReplace(BufferView * bv, FindAndReplaceOptions const & opt, M
                LYXERR(Debug::FIND, "After pasteParagraphList() cur=" << cur << endl);
                sel_len = repl_buffer.paragraphs().begin()->size();
        } else if (cur.inMathed()) {
-               TexRow texrow;
+               TexRow texrow(false);
                odocstringstream ods;
                otexstream os(ods, texrow);
                OutputParams runparams(&repl_buffer.params().encoding());
@@ -1412,6 +1408,8 @@ static void findAdvReplace(BufferView * bv, FindAndReplaceOptions const & opt, M
                docstring repl_latex = ods.str();
                LYXERR(Debug::FIND, "Latexified replace_buffer: '" << repl_latex << "'");
                string s;
+               // false positive from coverity
+               // coverity[CHECKED_RETURN]
                regex_replace(to_utf8(repl_latex), s, "\\$(.*)\\$", "$1");
                regex_replace(s, s, "\\\\\\[(.*)\\\\\\]", "$1");
                repl_latex = from_utf8(s);
@@ -1429,7 +1427,6 @@ static void findAdvReplace(BufferView * bv, FindAndReplaceOptions const & opt, M
        LYXERR(Debug::FIND, "After pos adj cur=" << cur << " with depth: " << cur.depth() << " and len: " << sel_len);
        bv->putSelectionAt(DocIterator(cur), sel_len, !opt.forward);
        bv->processUpdateFlags(Update::Force);
-       bv->buffer().updatePreviews();
 }