summaryrefslogtreecommitdiff
path: root/src/helpers/MiscFunctions.cpp
diff options
context:
space:
mode:
authorMr. Myxa <thisisandrew0110@gmail.com>2026-03-22 00:40:52 +0100
committerGitHub <noreply@github.com>2026-03-21 23:40:52 +0000
commitbf31f642b08a8d8ca796a1b713285f2580805c2f (patch)
treec58482bb0f0be3889b1c8c8c56bf017d3a03582f /src/helpers/MiscFunctions.cpp
parent635abdd1c22cbb71216a6d9bf03d93c8d9a30184 (diff)
internal: rewrite deviceNameToInternalString using a single range pipeline (#13806)
Diffstat (limited to 'src/helpers/MiscFunctions.cpp')
-rw-r--r--src/helpers/MiscFunctions.cpp18
1 files changed, 12 insertions, 6 deletions
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<std::string, std::string> 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<char>(std::tolower(ch));
+ }
+ });
+
+ return result | std::ranges::to<std::string>();
}
static const std::vector<const char*> PKGCONF_PATHS = {"/usr/lib/pkgconfig", "/usr/local/lib/pkgconfig"};