diff options
author | Přemysl Eric Janouch <p@janouch.name> | 2021-07-17 07:54:03 +0200 |
---|---|---|
committer | Přemysl Eric Janouch <p@janouch.name> | 2021-07-17 07:54:03 +0200 |
commit | 0adbac2066d35c7341329766893a3b1b90008d33 (patch) | |
tree | 8d90b047bf81636f0e0a9ee39562bbe8d2f264bf | |
parent | 2238db5a4ebc2928e5e0b18ad6dd18ab2e40b977 (diff) | |
download | sdn-0adbac2066d35c7341329766893a3b1b90008d33.tar.gz sdn-0adbac2066d35c7341329766893a3b1b90008d33.tar.xz sdn-0adbac2066d35c7341329766893a3b1b90008d33.zip |
Make search() return the number of matches
-rw-r--r-- | sdn.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
@@ -989,17 +989,19 @@ fun show_help () { fclose (contents); } -fun search (const wstring &needle) { - int best = g.cursor, best_n = 0; +fun search (const wstring &needle) -> int { + int best = g.cursor, best_n = 0, matches = 0; for (int i = 0; i < int (g.entries.size ()); i++) { auto o = (i + g.cursor) % g.entries.size (); int n = prefix_length (to_wide (g.entries[o].filename), needle); + matches += n == needle.size (); if (n > best_n) { best = o; best_n = n; } } g.cursor = best; + return matches; } fun fix_cursor_and_offset () { |