diff --git a/src/document/katedocument.cpp b/src/document/katedocument.cpp --- a/src/document/katedocument.cpp +++ b/src/document/katedocument.cpp @@ -102,6 +102,13 @@ #define EDIT_DEBUG if (0) qCDebug(LOG_KTE) #endif +template +static int indexOf(const E& entry, const std::initializer_list & list) +{ + auto it = std::find(list.begin(), list.end(), entry); + return it == list.end() ? -1 : std::distance(it, list.end()); +} + static inline QChar matchingStartBracket(QChar c, bool withQuotes) { switch (c.toLatin1()) { @@ -4515,7 +4522,7 @@ } // view variable names - static const QStringList vvl { + static const auto vvl = { QStringLiteral("dynamic-word-wrap") , QStringLiteral("dynamic-word-wrap-indicators") , QStringLiteral("line-numbers") @@ -4551,7 +4558,7 @@ // only apply view & renderer config stuff if (onlyViewAndRenderer) { - if (vvl.contains(var)) { // FIXME define above + if (indexOf(var, vvl) >= 0) { // FIXME define above setViewVariable(var, val); } } else { @@ -4610,8 +4617,8 @@ // STRING SETTINGS else if (var == QLatin1String("eol") || var == QLatin1String("end-of-line")) { - const QStringList l{ QStringLiteral("unix"), QStringLiteral("dos"), QStringLiteral("mac") }; - if ((n = l.indexOf(val.toLower())) != -1) { + const auto l{ QStringLiteral("unix"), QStringLiteral("dos"), QStringLiteral("mac") }; + if ((n = indexOf(val.toLower(), l)) != -1) { /** * set eol + avoid that it is overwritten by auto-detection again! * this fixes e.g. .kateconfig files with // kate: eol dos; to work, bug 365705 @@ -4645,7 +4652,7 @@ } // VIEW SETTINGS - else if (vvl.contains(var)) { + else if (indexOf(var, vvl) >= 0) { setViewVariable(var, val); } else { m_storedVariables.insert(var, val); @@ -4730,14 +4737,14 @@ bool KTextEditor::DocumentPrivate::checkBoolValue(QString val, bool *result) { val = val.trimmed().toLower(); - static const QStringList trueValues{ QStringLiteral("1"), QStringLiteral("on"), QStringLiteral("true") }; - if (trueValues.contains(val)) { + static const auto trueValues{ QStringLiteral("1"), QStringLiteral("on"), QStringLiteral("true") }; + if (indexOf(val, trueValues) >= 0) { *result = true; return true; } - static const QStringList falseValues{ QStringLiteral("0"), QStringLiteral("off"), QStringLiteral("false") }; - if (falseValues.contains(val)) { + static const auto falseValues{ QStringLiteral("0"), QStringLiteral("off"), QStringLiteral("false") }; + if (indexOf(val, falseValues) >= 0) { *result = false; return true; } diff --git a/src/script/katescriptmanager.cpp b/src/script/katescriptmanager.cpp --- a/src/script/katescriptmanager.cpp +++ b/src/script/katescriptmanager.cpp @@ -116,7 +116,7 @@ /** * now, we search all kinds of known scripts */ - for (const QString type : { QLatin1String("indentation"), QLatin1String("commands") }) { + for (const auto &type : { QLatin1String("indentation"), QLatin1String("commands") }) { // basedir for filesystem lookup const QString basedir = QLatin1String("/katepart5/script/") + type; diff --git a/src/view/kateview.cpp b/src/view/kateview.cpp --- a/src/view/kateview.cpp +++ b/src/view/kateview.cpp @@ -1382,7 +1382,7 @@ m_pasteMenu->setEnabled(m_doc->isReadWrite() && !KTextEditor::EditorPrivate::self()->clipboardHistory().isEmpty()); m_setEndOfLine->setEnabled(m_doc->isReadWrite()); - static const QStringList l { + static const auto l { QStringLiteral("edit_replace") , QStringLiteral("tools_spelling") , QStringLiteral("tools_indent") @@ -1401,7 +1401,7 @@ , QStringLiteral("tools_spelling_selection") }; - foreach (const QString &action, l) { + foreach (const auto &action, l) { QAction *a = actionCollection()->action(action); if (a) { a->setEnabled(m_doc->isReadWrite());