Mercurial > octave
changeset 23161:6edad6ad4da9
Use BOLD to identify text that matched in documentation search results.
Identify one match pattern per line of returned text.
* parser.cc (replace): Delete function
* parser.cc (global_search): Mark up search result text with "<b>text</b>".
Incorporate trivial replace function directly into global_search function.
author | Rik <rik@octave.org> |
---|---|
date | Tue, 07 Feb 2017 10:30:31 -0800 |
parents | a0eae3977ea6 |
children | af64b6b61db9 |
files | libgui/src/qtinfo/parser.cc |
diffstat | 1 files changed, 17 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/qtinfo/parser.cc Mon Feb 06 16:50:01 2017 +0100 +++ b/libgui/src/qtinfo/parser.cc Tue Feb 07 10:30:31 2017 -0800 @@ -537,22 +537,6 @@ } } -static void -replace (QString& text, const QRegExp& re, const QString& after) -{ - int pos = 0; - - while ((pos = re.indexIn (text, pos)) != -1) - { - QString cap = text.mid (pos, re.matchedLength ()); - QString a (after); - a = a.arg (cap); - text.remove (pos, re.matchedLength ()); - text.insert (pos, a); - pos += a.size (); - } -} - QString parser::global_search (const QString& text, int max_founds) { @@ -603,13 +587,6 @@ while ((pos = re.indexIn (node_text, pos)) != -1 && founds < max_founds) { - int line_start, line_end; - line_start = node_text.lastIndexOf ("\n", pos); - line_end = node_text.indexOf ("\n", pos); - QString line = node_text.mid (line_start, - line_end - line_start).trimmed (); - pos += re.matchedLength (); - if (founds == 0) { results.append( @@ -620,10 +597,26 @@ results.append ("</a><br>\n"); } - replace (line, re, "<i>%1</i>"); + // Replace text found with BOLD TEXT in search results + int line_start, line_end; + line_start = node_text.lastIndexOf ("\n", pos); + line_end = node_text.indexOf ("\n", pos); + QString line = node_text.mid (line_start, + line_end - line_start); + + int pos2 = pos - line_start; + int len = re.matchedLength (); + + QString ptn = line.mid (pos2, len); + QString repl ("<b>%1</b>"); + repl = repl.arg (ptn); + line.remove (pos2, len); + line.insert (pos2, repl); + line = line.trimmed (); results.append (line); results.append ("<br>\n"); + pos += len; founds++; } }