From 78ae1511849bf0b6d792eb42582aeccf3b0b4063 Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Sun, 10 Jan 2016 11:18:38 +0100 Subject: start collecting useful bits here --- akonadish/CMakeLists.txt | 3 ++- akonadish/utils.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ akonadish/utils.h | 30 ++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 akonadish/utils.cpp create mode 100644 akonadish/utils.h diff --git a/akonadish/CMakeLists.txt b/akonadish/CMakeLists.txt index 6761a32..eaedf9a 100644 --- a/akonadish/CMakeLists.txt +++ b/akonadish/CMakeLists.txt @@ -18,7 +18,8 @@ set(akonadi2_cli_SRCS akonadish_utils.cpp repl/repl.cpp repl/replStates.cpp - state.cpp) + state.cpp + utils.cpp) include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/akonadish/utils.cpp b/akonadish/utils.cpp new file mode 100644 index 0000000..d2a28ed --- /dev/null +++ b/akonadish/utils.cpp @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2016 Aaron Seigo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "utils.h" + +namespace Utils +{ + +QStringList filteredCompletions(const QStringList &possibleCompletions, const QString &commandFragment, Qt::CaseSensitivity cs) +{ + if (commandFragment.isEmpty()) { + return possibleCompletions; + } + + QStringList filtered; + for (auto item: possibleCompletions) { + if (item.startsWith(commandFragment, cs)) { + filtered << item; + } + } + + return filtered; +} + +} // namespace Utils + diff --git a/akonadish/utils.h b/akonadish/utils.h new file mode 100644 index 0000000..82be8d5 --- /dev/null +++ b/akonadish/utils.h @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2016 Aaron Seigo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#pragma once + +#include + +namespace Utils +{ + +QStringList filteredCompletions(const QStringList &possibleCompletions, const QString &commandFragment, Qt::CaseSensitivity cs = Qt::CaseSensitive); + +} // namespace Utils + -- cgit v1.2.3