[Aptitude-svn-commit] r4359 - in branches/aptitude-0.3/aptitude: .
src/vscreen
Daniel Burrows
dburrows at costa.debian.org
Fri Sep 30 15:44:31 UTC 2005
Author: dburrows
Date: Fri Sep 30 15:44:28 2005
New Revision: 4359
Modified:
branches/aptitude-0.3/aptitude/ChangeLog
branches/aptitude-0.3/aptitude/src/vscreen/vs_text_layout.cc
branches/aptitude-0.3/aptitude/src/vscreen/vs_text_layout.h
Log:
Backend support for searching in a vs_text_layout.
Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog (original)
+++ branches/aptitude-0.3/aptitude/ChangeLog Fri Sep 30 15:44:28 2005
@@ -1,3 +1,9 @@
+2005-09-30 Daniel Burrows <dburrows at debian.org>
+
+ * src/vscreen/vs_text_layout.cc, src/vscreen/vs_text_layout.h:
+
+ Write basic code for searching in a vs_text_layout.
+
2005-09-29 Daniel Burrows <dburrows at debian.org>
* doc/en/aptitude.xml, src/Makefile.am, src/changelog_parse.cc, src/changelog_parse.h, src/defaults.cc, src/generic/util/temp.h, src/view_changelog.cc:
Modified: branches/aptitude-0.3/aptitude/src/vscreen/vs_text_layout.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/vs_text_layout.cc (original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/vs_text_layout.cc Fri Sep 30 15:44:28 2005
@@ -240,6 +240,62 @@
location_changed(start, contents.size()-getmaxy());
}
+void vs_text_layout::search_for(const wstring &s, bool search_forward)
+{
+ freshen_contents(lastst);
+
+ if(getmaxy() == 0)
+ return;
+
+ // Very simplistic routine. Could be made quicker by incorporating
+ // a more sophisticated search algorithm.
+ size_t new_start = search_forward ? start + 1 : start - 1;
+
+ // Look for the first character of the string.
+ while(new_start > 0 && new_start < contents.size())
+ {
+ fragment_line &line(contents[new_start]);
+
+ // Search this line and the following lines (if there's an
+ // overrun) for our string.
+ for(fragment_line::const_iterator i = line.begin();
+ i != line.end(); ++i)
+ {
+ if(i->ch == s[0])
+ {
+ size_t tmp = new_start;
+ fragment_line::const_iterator j = i;
+ wstring::const_iterator loc = s.begin();
+
+ while(tmp < contents.size() && loc != s.end() &&
+ j->ch == *loc)
+ {
+ ++loc;
+ ++j;
+
+ if(j == contents[tmp].end())
+ {
+ ++tmp;
+ if(tmp < contents.size())
+ j = contents[tmp].begin();
+ }
+ }
+
+ if(loc == s.end()) // success
+ {
+ set_start(new_start);
+ return;
+ }
+ }
+ }
+
+ if(search_forward)
+ ++new_start;
+ else
+ --new_start;
+ }
+}
+
void vs_text_layout::scroll(bool dir)
{
if(dir)
Modified: branches/aptitude-0.3/aptitude/src/vscreen/vs_text_layout.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/vs_text_layout.h (original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/vs_text_layout.h Fri Sep 30 15:44:28 2005
@@ -131,6 +131,13 @@
/** Move a page back. */
void page_up();
+ /** Search either forwards or backwards for the string s. The
+ * search will start on either the next or the previous line
+ * from the top of the screen.
+ */
+ void search_for(const std::wstring &s,
+ bool search_forwards);
+
/** Page based on a scrollbar signal.
*
* \param dir the direction to page: if \b true, call page_up();
More information about the Aptitude-svn-commit
mailing list