From bf31f642b08a8d8ca796a1b713285f2580805c2f Mon Sep 17 00:00:00 2001 From: "Mr. Myxa" Date: Sun, 22 Mar 2026 00:40:52 +0100 Subject: internal: rewrite deviceNameToInternalString using a single range pipeline (#13806) --- src/helpers/MiscFunctions.cpp | 18 ++++++++++++------ src/helpers/MiscFunctions.hpp | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp index f79cad31..2a200f1e 100644 --- a/src/helpers/MiscFunctions.cpp +++ b/src/helpers/MiscFunctions.cpp @@ -927,12 +927,18 @@ std::expected binaryNameForPid(pid_t pid) { return fullPath; } -std::string deviceNameToInternalString(std::string in) { - std::ranges::replace(in, ' ', '-'); - std::ranges::replace(in, '\n', '-'); - std::ranges::replace(in, ',', '-'); - std::ranges::transform(in, in.begin(), ::tolower); - return in; +std::string deviceNameToInternalString(const std::string& in) { + auto result = in | std::views::transform([](unsigned char ch) -> char { + switch (ch) { + case ' ': + case '\n': + case ',': return '-'; + + default: return static_cast(std::tolower(ch)); + } + }); + + return result | std::ranges::to(); } static const std::vector PKGCONF_PATHS = {"/usr/lib/pkgconfig", "/usr/local/lib/pkgconfig"}; diff --git a/src/helpers/MiscFunctions.hpp b/src/helpers/MiscFunctions.hpp index b01c2bb8..26c5c7ad 100644 --- a/src/helpers/MiscFunctions.hpp +++ b/src/helpers/MiscFunctions.hpp @@ -42,7 +42,7 @@ float stringToPercentage(const std::string& VA bool isNvidiaDriverVersionAtLeast(int threshold); std::expected binaryNameForWlClient(wl_client* client); std::expected binaryNameForPid(pid_t pid); -std::string deviceNameToInternalString(std::string in); +std::string deviceNameToInternalString(const std::string& in); std::string getSystemLibraryVersion(const std::string& name); std::string getBuiltSystemLibraryNames(); bool truthy(const std::string& str); -- cgit v1.2.3