From 442209942fdedbdded6362cafed736c327da0e1c Mon Sep 17 00:00:00 2001 From: Philip Damianik <39028343+pdamianik@users.noreply.github.com> Date: Sun, 15 Oct 2023 20:07:23 +0200 Subject: cleanup: Replace find() with C++20 starts_with(), ends_with() and contains() (#3572) * Replace find() with C++20 starts_with() and ends_with() * Replace find() with C++20 contains() --- src/Compositor.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/Compositor.cpp') diff --git a/src/Compositor.cpp b/src/Compositor.cpp index b9be9f18..f02f7c66 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -554,7 +554,7 @@ CMonitor* CCompositor::getMonitorFromName(const std::string& name) { CMonitor* CCompositor::getMonitorFromDesc(const std::string& desc) { for (auto& m : m_vMonitors) { - if (m->output->description && std::string(m->output->description).find(desc) == 0) + if (m->output->description && std::string(m->output->description).starts_with(desc)) return m.get(); } return nullptr; @@ -1617,7 +1617,7 @@ CWorkspace* CCompositor::getWorkspaceByName(const std::string& name) { } CWorkspace* CCompositor::getWorkspaceByString(const std::string& str) { - if (str.find("name:") == 0) { + if (str.starts_with("name:")) { return getWorkspaceByName(str.substr(str.find_first_of(':') + 1)); } @@ -1976,14 +1976,14 @@ CMonitor* CCompositor::getMonitorFromString(const std::string& name) { Debug::log(ERR, "Error in getMonitorFromString: invalid arg 1"); return nullptr; } - } else if (name.find("desc:") == 0) { + } else if (name.starts_with("desc:")) { const auto DESCRIPTION = name.substr(5); for (auto& m : m_vMonitors) { if (!m->output) continue; - if (m->output->description && std::string(m->output->description).find(DESCRIPTION) == 0) { + if (m->output->description && std::string(m->output->description).starts_with(DESCRIPTION)) { return m.get(); } } @@ -2245,13 +2245,13 @@ CWindow* CCompositor::getWindowByRegex(const std::string& regexp) { std::regex regexCheck(regexp); std::string matchCheck; - if (regexp.find("title:") == 0) { + if (regexp.starts_with("title:")) { mode = MODE_TITLE_REGEX; regexCheck = std::regex(regexp.substr(6)); - } else if (regexp.find("address:") == 0) { + } else if (regexp.starts_with("address:")) { mode = MODE_ADDRESS; matchCheck = regexp.substr(8); - } else if (regexp.find("pid:") == 0) { + } else if (regexp.starts_with("pid:")) { mode = MODE_PID; matchCheck = regexp.substr(4); } -- cgit v1.2.3