Merge pull request #1422 from technic/fixes

minor string utils methods refactoring
pull/1459/head
Alex 2022-03-06 14:50:02 +01:00 committed by GitHub
commit be1d2a02ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 24 deletions

View File

@ -1,15 +1,17 @@
#pragma once
#include <string> #include <string>
const std::string WHITESPACE = " \n\r\t\f\v"; 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); size_t begin = s.find_first_not_of(WHITESPACE);
return (begin == std::string::npos) ? "" : s.substr(begin); 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); size_t end = s.find_last_not_of(WHITESPACE);
return (end == std::string::npos) ? "" : s.substr(0, end + 1); 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)); }

View File

@ -4,6 +4,7 @@
#include "glibmm/fileutils.h" #include "glibmm/fileutils.h"
#include "glibmm/refptr.h" #include "glibmm/refptr.h"
#include "util/format.hpp" #include "util/format.hpp"
#include "util/string.hpp"
#include <algorithm> #include <algorithm>
#include <cctype> #include <cctype>
@ -26,27 +27,6 @@
namespace waybar::modules::wlr { 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 */ /* Icon loading functions */
static std::vector<std::string> search_prefix() static std::vector<std::string> search_prefix()
{ {