Hi,

please, find attached a patch that lets the math-searching capability
work again (it is made against the advsearch trunk), plus an encapsulation
of search-related debugging messages (that helped me track down the
issue) within the Debug::DEBUG logging level.

If you search along the patch, the "math" fix is just the two places where
asString() is invoked, the others are the "debugging" fix.

Bye,

   T.

Pavel Sanda ha scritto:
Konrad Hofbauer wrote:
You do not think this could make it into 1.6.x (with x>0) ???

because i don't see anybody working hard on finishing it...
pavel

Index: src/lyxfindadv.cpp
===================================================================
--- src/lyxfindadv.cpp	(revisione 27078)
+++ src/lyxfindadv.cpp	(copia locale)
@@ -100,19 +100,19 @@
  ** the found occurrence were escaped.
  **/
 std::string apply_escapes(std::string s, Escapes const & escape_map) {
-	lyxerr << "Escaping: '" << s << "'" << std::endl;
+	LYXERR(Debug::DEBUG, "Escaping: '" << s << "'" << std::endl);
 	Escapes::const_iterator it;
 	for (it = escape_map.begin(); it != escape_map.end(); ++it) {
-//		lyxerr << "Escaping " << it->first << " as " << it->second << std::endl;
+//		LYXERR(Debug::DEBUG, "Escaping " << it->first << " as " << it->second << std::endl);
 		unsigned int pos = 0;
 		while (pos < s.length() && (pos = s.find(it->first, pos)) < s.length()) {
 			s.replace(pos, it->first.length(), it->second);
-//			lyxerr << "After escape: " << s << std::endl;
+//			LYXERR(Debug::DEBUG, "After escape: " << s << std::endl);
 			pos += it->second.length();
-//			lyxerr << "pos: " << pos << std::endl;
+//			LYXERR(Debug::DEBUG, "pos: " << pos << std::endl);
 		}
 	}
-	lyxerr << "Escaped : '" << s << "'" << std::endl;
+	LYXERR(Debug::DEBUG, "Escaped : '" << s << "'" << std::endl);
 	return s;
 }
 
@@ -143,30 +143,30 @@
 		size_t new_pos = s.find("\\regexp{", pos);
 		if (new_pos == std::string::npos)
 			new_pos = s.size();
-		lyxerr << "new_pos: " << new_pos << std::endl;
+		LYXERR(Debug::DEBUG, "new_pos: " << new_pos << std::endl);
 		std::string t = apply_escapes(s.substr(pos, new_pos - pos), get_lyx_unescapes());
-		lyxerr << "t      : " << t << std::endl;
+		LYXERR(Debug::DEBUG, "t      : " << t << std::endl);
 		t = apply_escapes(t, get_regexp_escapes());
 		s.replace(pos, new_pos - pos, t);
 		new_pos = pos + t.size();
-		lyxerr << "Regexp after escaping: " << s << std::endl;
-		lyxerr << "new_pos: " << new_pos << std::endl;
+		LYXERR(Debug::DEBUG, "Regexp after escaping: " << s << std::endl);
+		LYXERR(Debug::DEBUG, "new_pos: " << new_pos << std::endl);
 		if (new_pos == s.size())
 			break;
 		size_t end_pos = find_matching_brace(s, new_pos + 7);
-		lyxerr << "end_pos: " << end_pos << std::endl;
+		LYXERR(Debug::DEBUG, "end_pos: " << end_pos << std::endl);
 		t = apply_escapes(s.substr(new_pos + 8, end_pos - (new_pos + 8)), get_lyx_unescapes());
-		lyxerr << "t      : " << t << std::endl;
+		LYXERR(Debug::DEBUG, "t      : " << t << std::endl);
 		if (end_pos == s.size()) {
 			s.replace(new_pos, end_pos - new_pos, t);
 			pos = s.size();
-			lyxerr << "Regexp after \\regexp{} removal: " << s << std::endl;
+			LYXERR(Debug::DEBUG, "Regexp after \\regexp{} removal: " << s << std::endl);
 			break;
 		}
 		s.replace(new_pos, end_pos + 1 - new_pos, t);
-		lyxerr << "Regexp after \\regexp{} removal: " << s << std::endl;
+		LYXERR(Debug::DEBUG, "Regexp after \\regexp{} removal: " << s << std::endl);
 		pos = new_pos + t.size();
-		lyxerr << "pos: " << pos << std::endl;
+		LYXERR(Debug::DEBUG, "pos: " << pos << std::endl);
 	}
 	return s;
 }
@@ -194,7 +194,7 @@
 bool braces_match(std::string::const_iterator const & beg, std::string::const_iterator const & end, int unmatched = 0) {
 	int open_pars = 0;
 	std::string::const_iterator it = beg;
-	lyxerr << "Checking " << unmatched << " unmatched braces in '" << std::string(beg, end) << "'" << std::endl;
+	LYXERR(Debug::DEBUG, "Checking " << unmatched << " unmatched braces in '" << std::string(beg, end) << "'" << std::endl);
 	for (; it != end; ++it) {
 		// Skip escaped braces in the count
 		if (*it == '\\') {
@@ -205,17 +205,17 @@
 			++open_pars;
 		} else if (*it == '}') {
 			if (open_pars == 0) {
-				lyxerr << "Found unmatched closed brace" << std::endl;
+				LYXERR(Debug::DEBUG, "Found unmatched closed brace" << std::endl);
 				return false;
 			} else
 				--open_pars;
 		}
 	}
 	if (open_pars != unmatched) {
-		lyxerr << "Found " << open_pars << " instead of " << unmatched << " unmatched open braces at the end of count" << std::endl;
+	  LYXERR(Debug::DEBUG, "Found " << open_pars << " instead of " << unmatched << " unmatched open braces at the end of count" << std::endl);
 		return false;
 	}
-	lyxerr << "Braces match as expected" << std::endl;
+	LYXERR(Debug::DEBUG, "Braces match as expected" << std::endl);
 	return true;
 }
 
@@ -236,7 +236,7 @@
 		if (! opt.regexp) {
 			// Remove trailing closure of math, macros and environments, so to catch parts of them.
 			do {
-				lyxerr << "par_as_string now is '" << par_as_string << "'" << std::endl;
+				LYXERR(Debug::DEBUG, "par_as_string now is '" << par_as_string << "'" << std::endl);
 				if (regex_replace(par_as_string, par_as_string, "(.*)[[:blank:]]\\'", "$1"))
 					continue;
 				if (regex_replace(par_as_string, par_as_string, "(.*[^\\\\]) ?\\$\\'", "$1"))
@@ -252,13 +252,13 @@
 				}
 				break;
 			} while (true);
-			lyxerr << "Open braces: " << open_braces << std::endl;
+			LYXERR(Debug::DEBUG, "Open braces: " << open_braces << std::endl);
 			BOOST_ASSERT(braces_match(par_as_string.begin(), par_as_string.end(), open_braces));
-			lyxerr << "Built MatchStringAdv object: par_as_string = " << par_as_string << std::endl;
+			LYXERR(Debug::DEBUG, "Built MatchStringAdv object: par_as_string = '" << par_as_string << "'" << std::endl);
 		} else {
 			par_as_string = escape_for_regex(par_as_string);
 			// Insert (.*?) before trailing closure of math, macros and environments, so to catch parts of them.
-			lyxerr << "par_as_string now is '" << par_as_string << "'" << std::endl;
+			LYXERR(Debug::DEBUG, "par_as_string now is '" << par_as_string << "'" << std::endl);
 			if (
 					// Insert .* before trailing '\$' ('$' has been escaped by escape_for_regex)
 					regex_replace(par_as_string, par_as_string, "(.*[^\\\\])(\\\\\\$)\\'", "$1(.*?)$2")
@@ -271,13 +271,13 @@
 			) {
 				++close_wildcards;
 			}
-			lyxerr << "par_as_string now is '" << par_as_string << "'" << std::endl;
-			lyxerr << "Open braces: " << open_braces << std::endl;
-			lyxerr << "Close .*?  : " << close_wildcards << std::endl;
+			LYXERR(Debug::DEBUG, "par_as_string now is '" << par_as_string << "'" << std::endl);
+			LYXERR(Debug::DEBUG, "Open braces: " << open_braces << std::endl);
+			LYXERR(Debug::DEBUG, "Close .*?  : " << close_wildcards << std::endl);
 			BOOST_ASSERT(braces_match(par_as_string.begin(), par_as_string.end(), open_braces));
 			// Entered regexp must match at begin of searched string buffer
 			par_as_string = std::string("\\`") + par_as_string;
-			lyxerr << "Replaced text (to be used as regex): " << par_as_string << std::endl;
+			LYXERR(Debug::DEBUG, "Replaced text (to be used as regex): " << par_as_string << std::endl);
 			regexp = boost::regex(par_as_string);
 		}
 	}
@@ -290,9 +290,9 @@
 	 **/
 	int operator()(DocIterator const & cur, int len = -1) const {
 		docstring docstr = stringifyFromForSearch(opt, buf, cur, len);
-//		lyxerr << "Matching against     '" << lyx::to_utf8(docstr) << "'" << std::endl;
+		LYXERR(Debug::DEBUG, "Matching against     '" << lyx::to_utf8(docstr) << "'" << std::endl);
 		std::string str = normalize(docstr);
-		lyxerr << "After normalization: '" << str << "'" << std::endl;
+		LYXERR(Debug::DEBUG, "After normalization: '" << str << "'" << std::endl);
 		if (! opt.regexp) {
 			if (str.substr(0, par_as_string.size()) == par_as_string)
 				return par_as_string.size();
@@ -342,7 +342,7 @@
 	 **
 	 ** @todo Normalization should also expand macros, if the corresponding search option was checked.
 	 **/
-	std::string normalize(docstring s) const {
+	std::string normalize(docstring const & s) const {
 		std::string t;
 		if (! opt.casesensitive)
 			t = lyx::to_utf8(lowercase(s));
@@ -377,12 +377,12 @@
  ** if len is positive, or at the paragraph or innermost inset end if len is -1.
  **/
 docstring stringifyFromCursor(Buffer const & buf, DocIterator const & cur, int len) {
-	lyxerr << "Stringifying with len=" << len << " from cursor at pos: " << cur;
+  LYXERR(Debug::DEBUG, "Stringifying with len=" << len << " from cursor at pos: " << cur);
 	if (cur.inTexted()) {
 		Paragraph par = cur.paragraph();
 		// TODO what about searching beyond/across paragraph breaks ?
 		// TODO Try adding a AS_STR_INSERTS as last arg
-		return par.asString(cur.pos(), ( len == -1 || cur.pos() + len > int(par.size()) ) ? int(par.size()) : cur.pos() + len);
+		return par.asString(cur.pos(), ( len == -1 || cur.pos() + len > int(par.size()) ) ? int(par.size()) : cur.pos() + len, AS_STR_INSETS);
 	} else if (cur.inMathed()) {
 		odocstringstream os;
 		CursorSlice cs = cur.top();
@@ -392,7 +392,7 @@
 			os << *it;
 		return os.str();
 	}
-	lyxerr << "Don't know how to stringify from here: " << cur;
+	LYXERR(Debug::DEBUG, "Don't know how to stringify from here: " << cur);
 	return docstring();
 }
 
@@ -400,8 +400,8 @@
  ** if len is positive, or at the paragraph or innermost inset end if len is -1.
  **/
 docstring latexifyFromCursor(Buffer const & buf, DocIterator const & cur, int len) {
-	lyxerr << "Latexifying with len=" << len << " from cursor at pos: " << cur;
-	lyxerr << "  with cur.lastpost=" << cur.lastpos() << ", cur.lastrow=" << cur.lastrow() << ", cur.lastcol=" << cur.lastcol() << std::endl;
+  LYXERR(Debug::DEBUG, "Latexifying with len=" << len << " from cursor at pos: " << cur);
+  LYXERR(Debug::DEBUG, "  with cur.lastpost=" << cur.lastpos() << ", cur.lastrow=" << cur.lastrow() << ", cur.lastcol=" << cur.lastcol() << std::endl);
 	BOOST_ASSERT(buf.isLatex());
 
 	TexRow texrow;
@@ -423,7 +423,7 @@
 //		lyx::latexParagraphs(buf, cur.innerText()->paragraphs(), ods, texrow, runparams, std::string(), pit, pit_end);
 		lyx::TeXOnePar(buf, *cur.innerText(), pit, ods, texrow, runparams, std::string(),
 				cur.pos(), ( len == -1 || cur.pos() + len > int(pit->size()) ) ? -1 : cur.pos() + len);
-		lyxerr << "Latexified text: '" << lyx::to_utf8(ods.str()) << "'" << std::endl;
+		LYXERR(Debug::DEBUG, "Latexified text: '" << lyx::to_utf8(ods.str()) << "'" << std::endl);
 	} else if (cur.inMathed()) {
 		// Retrieve the math environment type, and add '$' or '$[' or others (\begin{equation}) accordingly
 		for (int s = cur.depth() - 1; s >= 0; --s) {
@@ -457,9 +457,9 @@
 				break;
 			}
 		}
-		lyxerr << "Latexified math: '" << lyx::to_utf8(ods.str()) << "'" << std::endl;
+		LYXERR(Debug::DEBUG, "Latexified math: '" << lyx::to_utf8(ods.str()) << "'" << std::endl);
 	} else {
-		lyxerr << "Don't know how to stringify from here: " << cur;
+		LYXERR(Debug::DEBUG, "Don't know how to stringify from here: " << cur);
 	}
 	return ods.str();
 }
@@ -473,28 +473,28 @@
 	size_t d;
 	DocIterator old_cur;
 	do {
-		lyxerr << "Forwarding one step (searching for innermost match)" << std::endl;
+	  LYXERR(Debug::DEBUG, "Forwarding one step (searching for innermost match)" << std::endl);
 		d = cur.depth();
 		old_cur = cur;
 		cur.forwardPos();
 	} while (cur && cur.depth() > d && match(cur) > 0);
 	if (! cur.empty()) {
-		lyxerr << "Backwarding one step" << std::endl;
+		LYXERR(Debug::DEBUG, "Backwarding one step" << std::endl);
 		cur.backwardPos();
 	}
 	BOOST_ASSERT(match(cur) > 0);
 //	if (! match(cur)) {
-//		lyxerr << "Ignoring assert !" << std::endl;
+//		LYXERR(Debug::DEBUG, "Ignoring assert !" << std::endl);
 //		//
 //	} else
-	lyxerr << "Ok" << std::endl;
+	LYXERR(Debug::DEBUG, "Ok" << std::endl);
 
 	// Compute the match length
 	int len = 1;
-	lyxerr << "verifying unmatch with len = " << len << std::endl;
+	LYXERR(Debug::DEBUG, "verifying unmatch with len = " << len << std::endl);
 	while (cur.pos() + len <= cur.lastpos() && match(cur, len) == 0) {
 		++len;
-		lyxerr << "verifying unmatch with len = " << len << std::endl;
+		LYXERR(Debug::DEBUG, "verifying unmatch with len = " << len << std::endl);
 	}
 	int old_len = match(cur, len);		// Length of matched text (different from len param)
 	int new_len;
@@ -502,7 +502,7 @@
 	while ((new_len = match(cur, len + 1)) > old_len) {
 		++len;
 		old_len = new_len;
-		lyxerr << "verifying   match with len = " << len << std::endl;
+		LYXERR(Debug::DEBUG, "verifying   match with len = " << len << std::endl);
 	}
 	return len;
 }
@@ -544,9 +544,9 @@
 			cur.setCursor(old_cur);
 			DocIterator cur_foremost(cur);
 			int len = findAdvFinalize(cur_foremost, match);
-			lyxerr << "cur_orig    : " << cur_orig;
-			lyxerr << "cur_foremost: " << cur_foremost;
-			lyxerr << "cur         : " << cur;
+			LYXERR(Debug::DEBUG, "cur_orig    : " << cur_orig);
+			LYXERR(Debug::DEBUG, "cur_foremost: " << cur_foremost);
+			LYXERR(Debug::DEBUG, "cur         : " << cur);
 			if (cur_foremost != cur_orig) {
 				((DocIterator &) cur) = cur_foremost;
 				return len;
@@ -614,7 +614,7 @@
 		return false;
 	}
 
-	lyxerr << "Setting selection with len: " << match_len << std::endl;
+	LYXERR(Debug::DEBUG, "Setting selection with len: " << match_len << std::endl);
 	bv->putSelectionAt(cur, match_len, ! opt.forward);
 	bv->message(_("Match found !"));
 	//bv->update();
@@ -645,14 +645,14 @@
 	   << opt.ignoreformat << ' '
 	   << opt.regexp;
 
-	lyxerr << "built: " << os.str() << std::endl;
+	LYXERR(Debug::DEBUG, "built: " << os.str() << std::endl);
 
 	return os;
 }
 
 /// Read a FindAdvOptions instance from a stringstream
 std::istringstream & operator>>(std::istringstream & is, lyx::FindAdvOptions & opt) {
-	lyxerr << "parsing" << std::endl;
+	LYXERR(Debug::DEBUG, "parsing" << std::endl);
 	std::string s;
 	std::string line;
 	getline(is, line);
@@ -664,11 +664,11 @@
 			break;
 		getline(is, line);
 	}
-	lyxerr << "searching for: '" << s << "'" << std::endl;
+	LYXERR(Debug::DEBUG, "searching for: '" << s << "'" << std::endl);
 	opt.search = from_utf8(s);
 	is >> opt.casesensitive >> opt.matchword >> opt.forward >> opt.expandmacros >> opt.ignoreformat >> opt.regexp;
-	lyxerr << "parsed: " << opt.casesensitive << ' ' << opt.matchword << ' ' << opt.forward << ' '
-			<< opt.expandmacros << ' ' << opt.ignoreformat << ' ' << opt.regexp << std::endl;
+	LYXERR(Debug::DEBUG, "parsed: " << opt.casesensitive << ' ' << opt.matchword << ' ' << opt.forward << ' '
+	       << opt.expandmacros << ' ' << opt.ignoreformat << ' ' << opt.regexp << std::endl);
 	return is;
 }
 

Proprietà modificate su: src/frontends/qt4
___________________________________________________________________
Modified: svn:ignore
   - Makefile
Makefile.in
libqt4.la
.deps
.libs
*_moc.cpp
*.lo
pch.h.gch.dep
pch.h.gch

   + Makefile
Makefile.in
libqt4.la
.deps
.libs
*_moc.cpp
*.lo
pch.h.gch.dep
pch.h.gch

ui_*Ui.h


Index: src/frontends/qt4/ControlSearchAdv.cpp
===================================================================
--- src/frontends/qt4/ControlSearchAdv.cpp	(revisione 27078)
+++ src/frontends/qt4/ControlSearchAdv.cpp	(copia locale)
@@ -72,7 +72,7 @@
 	} else {
 		for (ParIterator it = searchBuffer_.par_iterator_begin(); it != searchBuffer_.par_iterator_end(); ++it) {
 			lyxerr << "Adding to search string: '" << lyx::to_utf8(it->asString(false)) << "'" << std::endl;
-			searchString += it->asString(false);
+			searchString += it->asString(AS_STR_INSETS);
 		}
 	}
 //	lyxerr << "Searching for '" << lyx::to_utf8(searchString) << "'" << std::endl;

Reply via email to