X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Flyxfind.cpp;h=c8fc40947e75643cb281589fc41b62b30508858c;hb=3c488c22e1d86da021750e04b0c8e85a8d8630ab;hp=025b2bc39909d7338065166520a9ecb0c73badfa;hpb=0d6e3bcdc373a99d93e6bb09d8c55b6a87b6be8c;p=features.git diff --git a/src/lyxfind.cpp b/src/lyxfind.cpp index 025b2bc399..c8fc40947e 100644 --- a/src/lyxfind.cpp +++ b/src/lyxfind.cpp @@ -1111,7 +1111,7 @@ private: ** @todo Normalization should also expand macros, if the corresponding ** search option was checked. **/ - string normalize(docstring const & s, bool ignore_fomat) const; + string convertLF2Space(docstring const & s, bool ignore_fomat) const; // normalized string to search string par_as_string; // regular expression to use for searching @@ -2424,7 +2424,7 @@ void LatexInfo::buildEntries(bool isPatternString) } // Ignore language if there is math somewhere in pattern-string if (isPatternString) { - for (auto s: usedText) { + for (auto const & s: usedText) { // Remove entries created in previous search runs keys.erase(s); } @@ -3669,7 +3669,7 @@ MatchStringAdv::MatchStringAdv(lyx::Buffer & buf, FindAndReplaceOptions & opt) previous_single_replace = true; } // When using regexp, braces are hacked already by escape_for_regex() - par_as_string = normalize(ds, opt.ignoreformat); + par_as_string = convertLF2Space(ds, opt.ignoreformat); open_braces = 0; close_wildcards = 0; @@ -3794,7 +3794,7 @@ MatchResult MatchStringAdv::findAux(DocIterator const & cur, int len, MatchStrin docstring docstr = stringifyFromForSearch(opt, cur, len); string str; - str = normalize(docstr, opt.ignoreformat); + str = convertLF2Space(docstr, opt.ignoreformat); if (!opt.ignoreformat) { str = correctlanguagesetting(str, false, !opt.ignoreformat); // remove closing '}' and '\n' to allow for use of '$' in regex @@ -3988,8 +3988,7 @@ static bool simple_replace(string &t, string from, string to) } #endif -#if 1 -static string convertLF2Space(docstring const &s, bool ignore_format) +string MatchStringAdv::convertLF2Space(docstring const &s, bool ignore_format) const { // Using original docstring to handle '\n' @@ -4056,77 +4055,6 @@ static string convertLF2Space(docstring const &s, bool ignore_format) return(t.str()); } -#else -static string convertLF2Space(docstring const & s, bool ignore_format) -{ - // Using utf8-converted string to handle '\n' - - string t; - t = lyx::to_utf8(s); - // Remove \n at begin - while (!t.empty() && t[0] == '\n') - t = t.substr(1); - // Remove \n* at end - while (!t.empty() && t[t.size() - 1] == '\n') { - t = t.substr(0, t.size() - 1); - } - size_t pos; - // Handle all other '\n' - while ((pos = t.find("\n")) != string::npos) { - if (pos > 1 && t[pos-1] == '\\' && t[pos-2] == '\\' ) { - // Handle '\\\n' - if (isPrintableNonspace(t[pos+1]) && ((pos < 3) || isPrintableNonspace(t[pos-3]))) { - t.replace(pos-2, 3, " "); - } - else { - // Already a space there - t.replace(pos-2, 3, ""); - } - } - else { - if (!isAlnumASCII(t[pos+1]) || !isAlnumASCII(t[pos-1])) { - // '\n' adjacent to non-alpha-numerics, discard - t.replace(pos, 1, ""); - } - else { - // Replace all other \n with spaces - t.replace(pos, 1, " "); - } - if (!ignore_format) { - size_t count = 0; - while ((pos > count + 1) && (t[pos - 1 -count] == '%')) { - count++; - } - if (count > 0) { - t.replace(pos - count, count, ""); - } - } - } - } - return(t); - -} -#endif - -string MatchStringAdv::normalize(docstring const & s, bool ignore_format) const -{ - string t = convertLF2Space(s, ignore_format); - - // The following replaces are not appropriate in non-format-search mode - if (!ignore_format) { - // Remove stale empty \emph{}, \textbf{} and similar blocks from latexify - // Kornel: Added textsl, textsf, textit, texttt and noun - // + allow to seach for colored text too - LYXERR(Debug::FINDVERBOSE, "Removing stale empty macros from: " << t); - while (regex_replace(t, t, "\\\\(emph|noun|text(bf|sl|sf|it|tt)|(u|uu)line|(s|x)out|uwave)(\\{(\\{\\})?\\})+", "")) - LYXERR(Debug::FINDVERBOSE, " further removing stale empty \\emph{}, \\textbf{} macros from: " << t); - while (regex_replace(t, t, "\\\\((sub)?(((sub)?section)|paragraph)|part)\\*?(\\{(\\{\\})?\\})+", "")) - LYXERR(Debug::FINDVERBOSE, " further removing stale empty \\section{}, \\part{}, \\paragraph{} macros from: " << t); - while (regex_replace(t, t, "\\\\(foreignlanguage|textcolor|item)\\{[a-z]+\\}(\\{(\\{\\})?\\})+", "")); - } - return t; -} - docstring stringifyFromCursor(DocIterator const & cur, int len) { LYXERR(Debug::FINDVERBOSE, "Stringifying with len=" << len << " from cursor at pos: " << cur); @@ -4833,7 +4761,7 @@ static int findAdvReplace(BufferView * bv, FindAndReplaceOptions const & opt, Ma static bool isWordChar(char_type c) { - return isLetterChar(c) || isDigitASCII(c); + return isLetterChar(c) || isNumberChar(c); } /// Perform a FindAdv operation. @@ -4864,14 +4792,17 @@ bool findAdv(BufferView * bv, FindAndReplaceOptions & opt) if (opt.matchword && cur.pos() > 0) { // Skip word-characters if we are in the mid of a word if (cur.inTexted()) { Paragraph const & par = cur.paragraph(); - if (!par.isWordSeparator(cur.pos() -1, true)) { - class Text *t = cur.text(); - CursorSlice to; - CursorSlice from = cur.top(); - t->getWord(from, to, WHOLE_WORD); - cur.pos() = to.pos(); - cur.pit() = to.pit(); + int len_limit, new_pos; + if (cur.lastpos() < par.size()) + len_limit = cur.lastpos(); + else + len_limit = par.size(); + for (new_pos = cur.pos() - 1; new_pos < len_limit; new_pos++) { + if (!isWordChar(par.getChar(new_pos))) + break; } + if (new_pos > cur.pos()) + cur.pos() = new_pos; } else if (cur.inMathed()) { // Check if 'cur.pos()-1' and 'cur.pos()' both point to a letter, @@ -4888,15 +4819,9 @@ bool findAdv(BufferView * bv, FindAndReplaceOptions & opt) it != it_end; ++it) md2.push_back(*it); docstring inp = asString(md2); - LYXERR0("Got \"" << inp << "\""); - char_type prev = inp[0]; for (len = 0; (unsigned) len < inp.size() && len + cur.pos() <= cur.lastpos(); len++) { - char_type c = inp[len]; - if (isLetterChar(c)) - continue; - if (isDigitASCII(c)) - continue; - break; + if (!isWordChar(inp[len])) + break; } // len == 0 means previous char was a word separator // len == 1 search starts with a word separator @@ -4904,7 +4829,6 @@ bool findAdv(BufferView * bv, FindAndReplaceOptions & opt) if (len > 1) cur.pos() = cur.pos() + len - 1; } - } opt.matchword = false; }