diff --git a/include/util/string.hpp b/include/util/string.hpp index d644b4c..24a9b2b 100644 --- a/include/util/string.hpp +++ b/include/util/string.hpp @@ -1,15 +1,17 @@ +#pragma once + #include const std::string WHITESPACE = " \n\r\t\f\v"; -std::string ltrim(const std::string s) { +inline std::string ltrim(const std::string& s) { size_t begin = s.find_first_not_of(WHITESPACE); return (begin == std::string::npos) ? "" : s.substr(begin); } -std::string rtrim(const std::string s) { +inline std::string rtrim(const std::string& s) { size_t end = s.find_last_not_of(WHITESPACE); return (end == std::string::npos) ? "" : s.substr(0, end + 1); } -std::string trim(const std::string& s) { return rtrim(ltrim(s)); } +inline std::string trim(const std::string& s) { return rtrim(ltrim(s)); } diff --git a/src/modules/wlr/taskbar.cpp b/src/modules/wlr/taskbar.cpp index ddc360b..55c9431 100644 --- a/src/modules/wlr/taskbar.cpp +++ b/src/modules/wlr/taskbar.cpp @@ -4,6 +4,7 @@ #include "glibmm/fileutils.h" #include "glibmm/refptr.h" #include "util/format.hpp" +#include "util/string.hpp" #include #include @@ -26,27 +27,6 @@ namespace waybar::modules::wlr { -/* String manipulation methods */ -const std::string WHITESPACE = " \n\r\t\f\v"; - -static std::string ltrim(const std::string& s) -{ - size_t start = s.find_first_not_of(WHITESPACE); - return (start == std::string::npos) ? "" : s.substr(start); -} - -static std::string rtrim(const std::string& s) -{ - size_t end = s.find_last_not_of(WHITESPACE); - return (end == std::string::npos) ? "" : s.substr(0, end + 1); -} - -static std::string trim(const std::string& s) -{ - return rtrim(ltrim(s)); -} - - /* Icon loading functions */ static std::vector search_prefix() {