diff options
Diffstat (limited to 'SQLiteStudio3/coreSQLiteStudio/common/utils.h')
| -rw-r--r-- | SQLiteStudio3/coreSQLiteStudio/common/utils.h | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/SQLiteStudio3/coreSQLiteStudio/common/utils.h b/SQLiteStudio3/coreSQLiteStudio/common/utils.h index 90d2d62..934e70a 100644 --- a/SQLiteStudio3/coreSQLiteStudio/common/utils.h +++ b/SQLiteStudio3/coreSQLiteStudio/common/utils.h @@ -57,7 +57,7 @@ API_EXPORT QString randStr(int length, bool numChars = true, bool whiteSpaces = API_EXPORT QString randStr(int length, const QString& charCollection); API_EXPORT QString randBinStr(int length); API_EXPORT QString randStrNotIn(int length, const QSet<QString> set, bool numChars = true, bool whiteSpaces = false); -API_EXPORT QString generateUniqueName(const QString& prefix, const QStringList& existingNames); +API_EXPORT QString generateUniqueName(const QString& prefix, const QStringList& existingNames, Qt::CaseSensitivity cs = Qt::CaseSensitive); API_EXPORT bool isNumeric(const QVariant& value); API_EXPORT QString rStrip(const QString& str); API_EXPORT QStringList tokenizeArgs(const QString& str); @@ -73,6 +73,20 @@ API_EXPORT QHash<QString,QVariant> bytesToHash(const QByteArray& bytes); API_EXPORT int indexOf(const QStringList& list, const QString& value, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive); API_EXPORT int indexOf(const QStringList& list, const QString& value, Qt::CaseSensitivity cs = Qt::CaseSensitive); +template <class T> +int indexOf(const QList<T>& list, std::function<bool(const T&)> predicate) +{ + int i = 0; + for (const T& item : list) + { + if (predicate(item)) + return i; + + ++i; + } + return -1; +} + /** * @brief Returns only those elements from the list, which passed the filter. * @tparam T type for which the filter will be applied for. It should match the type in the list and in the function argument. @@ -103,6 +117,18 @@ bool contains(const QList<T>& list, std::function<bool(const T& value)> testFunc return false; } +template <class T> +QList<T> concat(const QList<QList<T>>& list) +{ + QList<T> result; + for (const QList<T>& item : list) + result.append(item); + + return result; +} + +API_EXPORT QStringList concat(const QList<QStringList>& list); + /** * @brief Appends or prepends characters to the string to make it of specified length. * @param str Input string to work with. @@ -205,6 +231,18 @@ API_EXPORT bool renameBetweenPartitions(const QString& src, const QString& dst); API_EXPORT bool isWritableRecursively(const QString& dir); API_EXPORT QString encryptRsa(const QString& input, const QString& modulus, const QString& exponent); API_EXPORT QString decryptRsa(const QString& input, const QString& modulus, const QString& exponent); +API_EXPORT QString doubleToString(double val); + +/** + * @brief Sorts string list using reference list for ordering. + * @param listToSort This list will be sorted. + * @param referenceList Should contain all elements from list to sort - it tells the order. + * @param cs Case sensitivity of the string comparision. + * + * Sorts \p listToSort using \p referenceList as a reference of what is the order. + * If any element from \p listToSort is not on the list of \p referenceList, then the element will be placed at the end. + */ +API_EXPORT void sortWithReferenceList(QList<QString>& listToSort, const QList<QString>& referenceList, Qt::CaseSensitivity cs = Qt::CaseSensitive); enum class DistributionType { |
