Rename function name
This commit is contained in:
parent
473eb0982b
commit
63525ec956
|
@ -4,5 +4,5 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace waybar::util {
|
namespace waybar::util {
|
||||||
std::string rewriteTitle(const std::string&, const Json::Value&);
|
std::string rewriteString(const std::string&, const Json::Value&);
|
||||||
}
|
}
|
|
@ -172,7 +172,7 @@ src_files = files(
|
||||||
'src/group.cpp',
|
'src/group.cpp',
|
||||||
'src/util/ustring_clen.cpp',
|
'src/util/ustring_clen.cpp',
|
||||||
'src/util/sanitize_str.cpp',
|
'src/util/sanitize_str.cpp',
|
||||||
'src/util/rewrite_title.cpp'
|
'src/util/rewrite_string.cpp'
|
||||||
)
|
)
|
||||||
|
|
||||||
if is_linux
|
if is_linux
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
#include "modules/hyprland/backend.hpp"
|
#include "modules/hyprland/backend.hpp"
|
||||||
#include "util/command.hpp"
|
#include "util/command.hpp"
|
||||||
#include "util/json.hpp"
|
#include "util/json.hpp"
|
||||||
#include "util/rewrite_title.hpp"
|
#include "util/rewrite_string.hpp"
|
||||||
|
|
||||||
namespace waybar::modules::hyprland {
|
namespace waybar::modules::hyprland {
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ auto Window::update() -> void {
|
||||||
if (!format_.empty()) {
|
if (!format_.empty()) {
|
||||||
label_.show();
|
label_.show();
|
||||||
label_.set_markup(fmt::format(fmt::runtime(format_),
|
label_.set_markup(fmt::format(fmt::runtime(format_),
|
||||||
waybar::util::rewriteTitle(lastView, config_["rewrite"])));
|
waybar::util::rewriteString(lastView, config_["rewrite"])));
|
||||||
} else {
|
} else {
|
||||||
label_.hide();
|
label_.hide();
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
#include <regex>
|
#include <regex>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "util/rewrite_title.hpp"
|
#include "util/rewrite_string.hpp"
|
||||||
|
|
||||||
namespace waybar::modules::sway {
|
namespace waybar::modules::sway {
|
||||||
|
|
||||||
|
@ -206,7 +206,7 @@ auto Window::update() -> void {
|
||||||
|
|
||||||
label_.set_markup(
|
label_.set_markup(
|
||||||
fmt::format(fmt::runtime(format_),
|
fmt::format(fmt::runtime(format_),
|
||||||
fmt::arg("title", waybar::util::rewriteTitle(window_, config_["rewrite"])),
|
fmt::arg("title", waybar::util::rewriteString(window_, config_["rewrite"])),
|
||||||
fmt::arg("app_id", app_id_), fmt::arg("shell", shell_)));
|
fmt::arg("app_id", app_id_), fmt::arg("shell", shell_)));
|
||||||
if (tooltipEnabled()) {
|
if (tooltipEnabled()) {
|
||||||
label_.set_tooltip_text(window_);
|
label_.set_tooltip_text(window_);
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
#include "util/rewrite_title.hpp"
|
#include "util/rewrite_string.hpp"
|
||||||
|
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
|
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
|
||||||
namespace waybar::util {
|
namespace waybar::util {
|
||||||
std::string rewriteTitle(const std::string& title, const Json::Value& rules) {
|
std::string rewriteString(const std::string& value, const Json::Value& rules) {
|
||||||
if (!rules.isObject()) {
|
if (!rules.isObject()) {
|
||||||
return title;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string res = title;
|
std::string res = value;
|
||||||
|
|
||||||
for (auto it = rules.begin(); it != rules.end(); ++it) {
|
for (auto it = rules.begin(); it != rules.end(); ++it) {
|
||||||
if (it.key().isString() && it->isString()) {
|
if (it.key().isString() && it->isString()) {
|
||||||
|
@ -18,7 +18,7 @@ std::string rewriteTitle(const std::string& title, const Json::Value& rules) {
|
||||||
// malformated regexes will cause an exception.
|
// malformated regexes will cause an exception.
|
||||||
// in this case, log error and try the next rule.
|
// in this case, log error and try the next rule.
|
||||||
const std::regex rule{it.key().asString()};
|
const std::regex rule{it.key().asString()};
|
||||||
if (std::regex_match(title, rule)) {
|
if (std::regex_match(value, rule)) {
|
||||||
res = std::regex_replace(res, rule, it->asString());
|
res = std::regex_replace(res, rule, it->asString());
|
||||||
}
|
}
|
||||||
} catch (const std::regex_error& e) {
|
} catch (const std::regex_error& e) {
|
Loading…
Reference in New Issue