diff options
author | Daniel Wilhelm <daniel@wili.li> | 2014-04-18 17:29:28 +0200 |
---|---|---|
committer | Daniel Wilhelm <daniel@wili.li> | 2014-04-18 17:29:28 +0200 |
commit | 75c07011b7c4d06acd7b45dabdcd60ab9d80f385 (patch) | |
tree | 8853c3978dd152ef377e652239448b1352320206 /ui/search.cpp | |
parent | 5.22 (diff) | |
download | FreeFileSync-75c07011b7c4d06acd7b45dabdcd60ab9d80f385.tar.gz FreeFileSync-75c07011b7c4d06acd7b45dabdcd60ab9d80f385.tar.bz2 FreeFileSync-75c07011b7c4d06acd7b45dabdcd60ab9d80f385.zip |
5.23
Diffstat (limited to 'ui/search.cpp')
-rw-r--r-- | ui/search.cpp | 100 |
1 files changed, 0 insertions, 100 deletions
diff --git a/ui/search.cpp b/ui/search.cpp deleted file mode 100644 index c834b934..00000000 --- a/ui/search.cpp +++ /dev/null @@ -1,100 +0,0 @@ -// ************************************************************************** -// * This file is part of the FreeFileSync project. It is distributed under * -// * GNU General Public License: http://www.gnu.org/licenses/gpl.html * -// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved * -// ************************************************************************** - -#include "search.h" -#include <zen/string_tools.h> - - -using namespace zen; - -namespace -{ -template <bool respectCase> -class ContainsMatch -{ -public: - ContainsMatch(const wxString& textToFind) : textToFind_(textToFind) {} - bool operator()(const wxString& phrase) const { return contains(phrase, textToFind_); } - -private: - wxString textToFind_; -}; - - -template <> -class ContainsMatch<false> -{ -public: - ContainsMatch(const wxString& textToFind) : textToFind_(textToFind) { textToFind_.MakeUpper(); } - bool operator()(wxString&& phrase) const - { - //wxWidgets::MakeUpper() is inefficient! But performance is not THAT important for this high-level search functionality - phrase.MakeUpper(); - return contains(phrase, textToFind_); - } - -private: - wxString textToFind_; -}; - -//########################################################################################### - -template <bool respectCase> -ptrdiff_t findRow(const Grid& grid, //return -1 if no matching row found - const wxString& searchString, - size_t rowFirst, //specify area to search: - size_t rowLast) // [rowFirst, rowLast) -{ - if (auto prov = grid.getDataProvider()) - { - std::vector<Grid::ColumnAttribute> colAttr = grid.getColumnConfig(); - vector_remove_if(colAttr, [](const Grid::ColumnAttribute& ca) { return !ca.visible_; }); - if (!colAttr.empty()) - { - const ContainsMatch<respectCase> containsMatch(searchString); - - for (size_t row = rowFirst; row < rowLast; ++row) - for (auto iterCol = colAttr.begin(); iterCol != colAttr.end(); ++iterCol) - if (containsMatch(prov->getValue(row, iterCol->type_))) - return row; - } - } - return -1; -} -} - - -std::pair<const Grid*, ptrdiff_t> zen::findGridMatch(const Grid& grid1, const Grid& grid2, const wxString& searchString, bool respectCase) -{ - const size_t rowCountL = grid1.getRowCount(); - const size_t rowCountR = grid2.getRowCount(); - auto cursorPos = grid1.getGridCursor(); //(row, component pos) - - std::pair<const Grid*, ptrdiff_t> result(nullptr, -1); - - size_t cursorRowL = cursorPos.first; - if (cursorRowL >= rowCountL) - cursorRowL = 0; - { - auto finishSearch = [&](const Grid& grid, size_t rowFirst, size_t rowLast) -> bool - { - const ptrdiff_t targetRow = respectCase ? - findRow<true>( grid, searchString, rowFirst, rowLast) : - findRow<false>(grid, searchString, rowFirst, rowLast); - if (targetRow >= 0) - { - result = std::make_pair(&grid, targetRow); - return true; - } - return false; - }; - - if (!finishSearch(grid1, cursorRowL + 1, rowCountL)) - if (!finishSearch(grid2, 0, rowCountR)) - finishSearch(grid1, 0, cursorRowL + 1); - } - return result; -}
\ No newline at end of file |