X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Flyxfind.cpp;h=70de6c96a816164aadd5da2ddb6fa88b1243a71a;hb=f758894c2fc78f33be0c8bd60c2fd0a1f470056e;hp=f98f525cbe7f072404e5301771b1aaeca37dcd11;hpb=c506f304bc522ea91ad5a7e97cd4e3c7d54376b0;p=lyx.git diff --git a/src/lyxfind.cpp b/src/lyxfind.cpp index f98f525cbe..70de6c96a8 100644 --- a/src/lyxfind.cpp +++ b/src/lyxfind.cpp @@ -968,9 +968,9 @@ static size_t identifyLeading(string const & s) // + allow to search for colored text too while (regex_replace(t, t, REGEX_BOS "\\\\(((footnotesize|tiny|scriptsize|small|large|Large|LARGE|huge|Huge|emph|noun|minisec|text(bf|md|sl|sf|it|tt))|((textcolor|foreignlanguage|latexenvironment)\\{[a-z]+\\*?\\})|(u|uu)line|(s|x)out|uwave)|((sub)?(((sub)?section)|paragraph)|part|chapter)\\*?)\\{", "") || regex_replace(t, t, REGEX_BOS "\\$", "") - || regex_replace(t, t, REGEX_BOS "\\\\\\[ ", "") + || regex_replace(t, t, REGEX_BOS "\\\\\\[", "") || regex_replace(t, t, REGEX_BOS " ?\\\\item\\{[a-z]+\\}", "") - || regex_replace(t, t, REGEX_BOS "\\\\begin\\{[a-zA-Z_]*\\*?\\} ", "")) + || regex_replace(t, t, REGEX_BOS "\\\\begin\\{[a-zA-Z_]*\\*?\\}", "")) ; LYXERR(Debug::FIND, " after removing leading $, \\[ , \\emph{, \\textbf{, etc.: '" << t << "'"); return s.find(t); @@ -1182,12 +1182,12 @@ static void checkDepthIndex(int val) static int maxdepthidx = MAXOPENED-2; static int lastmaxdepth = 0; if (val > lastmaxdepth) { - LYXERR0("Depth reached " << val); + LYXERR(Debug::INFO, "Depth reached " << val); lastmaxdepth = val; } if (val > maxdepthidx) { maxdepthidx = val; - LYXERR0("maxdepthidx now " << val); + LYXERR(Debug::INFO, "maxdepthidx now " << val); } } @@ -1197,7 +1197,7 @@ static void checkIgnoreIdx(int val) { static int lastmaxignore = -1; if ((lastmaxignore < val) && (size_t(val+1) >= borders.size())) { - LYXERR0("IgnoreIdx reached " << val); + LYXERR(Debug::INFO, "IgnoreIdx reached " << val); lastmaxignore = val; } } @@ -1293,7 +1293,7 @@ static void buildaccent(string n, string param, string values) if ((values[start] & 0x80) == 0) { // is ascii accents[key] = values.substr(start, 1); - // LYXERR0("" << key << "=" << accents[key]); + // LYXERR(Debug::INFO, "" << key << "=" << accents[key]); } start++; continue; @@ -1308,7 +1308,7 @@ static void buildaccent(string n, string param, string values) // This is the first byte of following utf8 char accents[key] = values.substr(start, j); start += j; - // LYXERR0("" << key << "=" << accents[key]); + // LYXERR(Debug::INFO, "" << key << "=" << accents[key]); break; } } @@ -1404,7 +1404,7 @@ void Intervall::removeAccents() } } else { - LYXERR0("Not added accent for \"" << key << "\""); + LYXERR(Debug::INFO, "Not added accent for \"" << key << "\""); } } } @@ -2354,7 +2354,9 @@ int LatexInfo::dispatch(ostringstream &os, int previousStart, KeyInfo &actual) int numpars = 0; int spaces = 0; while (actual._tokenstart > numpars) { - if (interval_.par[pos+numpars] == ']' && interval_.par[actual._tokenstart-numpars-1] == '[') + if (pos+numpars >= interval_.par.size()) + break; + else if (interval_.par[pos+numpars] == ']' && interval_.par[actual._tokenstart-numpars-1] == '[') numpars++; else if (interval_.par[pos+numpars] == '}' && interval_.par[actual._tokenstart-numpars-1] == '{') numpars++; @@ -2432,7 +2434,7 @@ int LatexInfo::dispatch(ostringstream &os, int previousStart, KeyInfo &actual) int val = actual._tokenstart; for (count = 0; count < actual._tokenstart;) { val = interval_.previousNotIgnored(val-1); - if (interval_.par[val] != ' ') + if (val < 0 || interval_.par[val] != ' ') break; else { count = actual._tokenstart - val; @@ -2495,7 +2497,7 @@ int LatexInfo::dispatch(ostringstream &os, int previousStart, KeyInfo &actual) // This cannot happen, already handled // fall through default: { - // LYXERR0("Unhandled keytype"); + // LYXERR(Debug::INFO, "Unhandled keytype"); nextKeyIdx = getNextKey(); break; } @@ -2535,7 +2537,7 @@ int LatexInfo::process(ostringstream &os, KeyInfo &actual ) if (oldStart <= end) { processRegion(oldStart, end); } - if (interval_.par[end] == '}') { + if (interval_.par.size() > (size_t) end && interval_.par[end] == '}') { end += 1; // This is the normal case. // But if using the firstlanguage, the closing may be missing @@ -2567,7 +2569,7 @@ string splitOnKnownMacros(string par, bool isPatternString) { ostringstream os; LatexInfo li(par, isPatternString); - // LYXERR0("Berfore split: " << par); + // LYXERR(Debug::INFO, "Berfore split: " << par); KeyInfo DummyKey = KeyInfo(KeyInfo::KeyType::isMain, 2, true); DummyKey.head = ""; DummyKey._tokensize = 0; @@ -2634,7 +2636,7 @@ string splitOnKnownMacros(string par, bool isPatternString) } else s = par; /* no known macros found */ - // LYXERR0("After split: " << s); + // LYXERR(Debug::INFO, "After split: " << s); return s; } @@ -2677,7 +2679,7 @@ static string correctlanguagesetting(string par, bool isPatternString, bool with string a = it->first; regex_with_format = true; features += " " + a; - // LYXERR0("Identified regex format:" << a); + // LYXERR(Debug::INFO, "Identified regex format:" << a); } LYXERR(Debug::FIND, "Identified Features" << features); @@ -2695,7 +2697,7 @@ static string correctlanguagesetting(string par, bool isPatternString, bool with } } else { - // LYXERR0("No regex formats"); + // LYXERR(Debug::INFO, "No regex formats"); } return result; } @@ -2709,9 +2711,9 @@ static int identifyClosing(string & t) LYXERR(Debug::FIND, "identifyClosing(): t now is '" << t << "'"); if (regex_replace(t, t, "(.*[^\\\\])\\$" REGEX_EOS, "$1")) continue; - if (regex_replace(t, t, "(.*[^\\\\]) \\\\\\]" REGEX_EOS, "$1")) + if (regex_replace(t, t, "(.*[^\\\\])\\\\\\]" REGEX_EOS, "$1")) continue; - if (regex_replace(t, t, "(.*[^\\\\]) \\\\end\\{[a-zA-Z_]*\\*?\\}" REGEX_EOS, "$1")) + if (regex_replace(t, t, "(.*[^\\\\])\\\\end\\{[a-zA-Z_]*\\*?\\}" REGEX_EOS, "$1")) continue; if (regex_replace(t, t, "(.*[^\\\\])\\}" REGEX_EOS, "$1")) { ++open_braces; @@ -2804,9 +2806,9 @@ MatchStringAdv::MatchStringAdv(lyx::Buffer & buf, FindAndReplaceOptions const & lng -= 2; open_braces++; } - else + else break; - } +} if (lng < par_as_string.size()) par_as_string = par_as_string.substr(0,lng); /* @@ -3038,9 +3040,14 @@ MatchResult MatchStringAdv::operator()(DocIterator const & cur, int len, bool at bool ws_left = (cur.pos() > 0) ? par.isWordSeparator(cur.pos() - 1) : true; - bool ws_right = (cur.pos() + len < par.size()) + bool ws_right; + if (len < 0) + ws_right = true; + else { + ws_right = (cur.pos() + len < par.size()) ? par.isWordSeparator(cur.pos() + len) : true; + } LYXERR(Debug::FIND, "cur.pos()=" << cur.pos() << ", res=" << res << ", separ: " << ws_left << ", " << ws_right @@ -3313,7 +3320,7 @@ int findAdvFinalize(DocIterator & cur, MatchStringAdv const & match) } while (cur.depth() > old_cur.depth()); /* Skip inner insets */ if (cur.depth() < old_cur.depth()) { // Outer inset? - LYXERR0("cur.depth() < old_cur.depth(), this should never happen"); + LYXERR(Debug::INFO, "cur.depth() < old_cur.depth(), this should never happen"); break; } if (cur.pos() != old_cur.pos()) { @@ -3331,7 +3338,7 @@ int findAdvFinalize(DocIterator & cur, MatchStringAdv const & match) } } else { - LYXERR0("cur.pos() == old_cur.pos(), this should never happen"); + LYXERR(Debug::INFO, "cur.pos() == old_cur.pos(), this should never happen"); actual_match = match(cur, len).match_len; if (actual_match == max_match) old_cur = cur; @@ -3353,7 +3360,7 @@ int findForwardAdv(DocIterator & cur, MatchStringAdv & match) int match_len = mres.match_len; LYXERR(Debug::FIND, "match_len: " << match_len); if ((mres.pos > 100000) || (mres.match2end > 100000) || (match_len > 100000)) { - LYXERR0("BIG LENGTHS: " << mres.pos << ", " << match_len << ", " << mres.match2end); + LYXERR(Debug::INFO, "BIG LENGTHS: " << mres.pos << ", " << match_len << ", " << mres.match2end); match_len = 0; } if (match_len > 0) {