From 5bd46d0943903b75c72244707e8b426d797c3065 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20K=C3=BCng?= Date: Sat, 2 Nov 2024 15:37:34 +0100 Subject: [PATCH] code cleanup --- src/LexStyles.cpp | 46 +++++++++++++++++++++++----------------------- src/LexStyles.h | 8 ++++---- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/LexStyles.cpp b/src/LexStyles.cpp index 595dc34c..70f7a230 100644 --- a/src/LexStyles.cpp +++ b/src/LexStyles.cpp @@ -33,8 +33,8 @@ const std::unordered_map emptyUnorderedMap; const std::string emptyString; const std::vector emptyStringVector; -constexpr COLORREF fgColor = RGB(0, 0, 0); -constexpr COLORREF bgColor = RGB(255, 255, 255); +constexpr COLORREF fgColor = RGB(0, 0, 0); +constexpr COLORREF bgColor = RGB(255, 255, 255); }; // namespace struct LexDetectStrings @@ -99,7 +99,7 @@ void CLexStyles::ParseStyle( LPCWSTR styleName, LPCWSTR styleString, const std::unordered_map& variables, - StyleData& style) const + StyleData& style) { std::wstring v = styleString; ReplaceVariables(v, variables); @@ -289,7 +289,7 @@ void CLexStyles::Load() auto num = _wtoi(it + 3); if (_wcsicmp(it + 6, L"regex") == 0) { - assert(annotations.find(num) == annotations.end()); + assert(!annotations.contains(num)); annotations[num].sRegex = CUnicodeUtils::StdGetUTF8(ini->GetValue(lexerName.c_str(), it, L"")); } if (_wcsicmp(it + 6, L"text") == 0) @@ -384,8 +384,8 @@ void CLexStyles::Load() if (!filters.empty()) { auto sKey = std::wstring(langKey) + TEXT(" file"); - auto foundIt = std::find_if(m_fileTypes.begin(), m_fileTypes.end(), - [&](const auto& item) { return (std::get<0>(item) == sKey); }); + auto foundIt = std::ranges::find_if(m_fileTypes, + [&](const auto& item) { return (std::get<0>(item) == sKey); }); if (foundIt != m_fileTypes.end()) m_fileTypes.erase(foundIt); m_fileTypes.push_back(std::make_pair(sKey, std::move(filters))); @@ -556,7 +556,7 @@ bool CLexStyles::AddUserFunctionForLang(const std::string& lang, const std::stri return false; } -void CLexStyles::GenerateUserKeywords(LanguageData& ld) const +void CLexStyles::GenerateUserKeywords(LanguageData& ld) { if (!ld.userKeyWordsUpdated) return; @@ -624,7 +624,7 @@ const std::string& CLexStyles::GetLanguageForLexer(int lexer) const std::string CLexStyles::GetLanguageForPath(const std::wstring& path) { - auto it = std::find_if(m_pathsLang.begin(), m_pathsLang.end(), [&](const auto& toFind) { + auto it = std::ranges::find_if(m_pathsLang, [&](const auto& toFind) { return _wcsicmp(toFind.first.c_str(), path.c_str()) == 0; }); if (it != m_pathsLang.end()) @@ -643,7 +643,7 @@ std::string CLexStyles::GetLanguageForPath(const std::wstring& path) } auto pathA = CUnicodeUtils::StdGetUTF8(CPathUtils::GetFileName(path)); - auto fit = std::find_if(m_fileLang.begin(), m_fileLang.end(), [&](const auto& toFind) { + auto fit = std::ranges::find_if(m_fileLang, [&](const auto& toFind) { return _stricmp(toFind.first.c_str(), pathA.c_str()) == 0; }); @@ -653,7 +653,7 @@ std::string CLexStyles::GetLanguageForPath(const std::wstring& path) } auto ext = CUnicodeUtils::StdGetUTF8(CPathUtils::GetFileExtension(path)); - auto eit = std::find_if(m_extLang.begin(), m_extLang.end(), [&](const auto& toFind) { + auto eit = std::ranges::find_if(m_extLang, [&](const auto& toFind) { return _stricmp(toFind.first.c_str(), ext.c_str()) == 0; }); if (eit != m_extLang.end()) @@ -661,7 +661,7 @@ std::string CLexStyles::GetLanguageForPath(const std::wstring& path) return eit->second; } - auto ait = std::find_if(m_autoExtLang.begin(), m_autoExtLang.end(), [&](const auto& toFind) { + auto ait = std::ranges::find_if(m_autoExtLang, [&](const auto& toFind) { return _stricmp(toFind.first.c_str(), ext.c_str()) == 0; }); if (ait != m_autoExtLang.end()) @@ -671,7 +671,7 @@ std::string CLexStyles::GetLanguageForPath(const std::wstring& path) return ""; } -std::string CLexStyles::GetLanguageForDocument(const CDocument& doc, CScintillaWnd& edit) +std::string CLexStyles::GetLanguageForDocument(const CDocument& doc, const CScintillaWnd& edit) { if (doc.m_path.empty()) return "Text"; @@ -766,7 +766,7 @@ bool CLexStyles::GetDefaultExtensionForLanguage(const std::string& lang, std::ws bool CLexStyles::IsLanguageHidden(const std::wstring& lang) const { - return m_hiddenLangs.find(lang) != m_hiddenLangs.end(); + return m_hiddenLangs.contains(lang); } size_t CLexStyles::GetFilterSpecCount() const @@ -817,7 +817,7 @@ void CLexStyles::ReplaceVariables(std::wstring& s, const std::unordered_mapsecond.compare(lang) == 0) iter = m_userExtLang.erase(iter); @@ -1162,7 +1162,7 @@ void CLexStyles::SetLangForPath(const std::wstring& path, const std::string& lan // extension has a different language set than the user selected // only add this if the extension is set in m_autoExtLang std::string e = CUnicodeUtils::StdGetUTF8(sExt); - auto it = std::find_if(m_extLang.begin(), m_extLang.end(), [&](const auto& toFind) { + auto it = std::ranges::find_if(m_extLang, [&](const auto& toFind) { return _stricmp(toFind.first.c_str(), e.c_str()) == 0; }); if (it == m_extLang.end()) diff --git a/src/LexStyles.h b/src/LexStyles.h index 5eac6694..b3ae5e64 100644 --- a/src/LexStyles.h +++ b/src/LexStyles.h @@ -97,7 +97,7 @@ class CLexStyles std::vector GetLanguages() const; std::map& GetLanguageDataMap(); - std::string GetLanguageForDocument(const CDocument& doc, CScintillaWnd& edit); + std::string GetLanguageForDocument(const CDocument& doc, const CScintillaWnd& edit); std::wstring GetUserExtensionsForLanguage(const std::wstring& lang) const; bool GetDefaultExtensionForLanguage(const std::string& lang, std::wstring& ext, UINT& index) const; bool IsLanguageHidden(const std::wstring& lang) const; @@ -135,7 +135,7 @@ class CLexStyles void SaveUserData(); bool AddUserFunctionForLang(const std::string& lang, const std::string& fnc); std::string GetLanguageForPath(const std::wstring& path); - void GenerateUserKeywords(LanguageData& ld) const; + static void GenerateUserKeywords(LanguageData& ld); void Reload(); private: @@ -144,10 +144,10 @@ class CLexStyles void Load(); static void ReplaceVariables(std::wstring& s, const std::unordered_map& vars); - void ParseStyle(LPCWSTR styleName, + static void ParseStyle(LPCWSTR styleName, LPCWSTR styleString, const std::unordered_map& variables, - StyleData& style) const; + StyleData& style); private: bool m_bLoaded;