From 4698c9d2cf1ead77df77e4b4d74a62eb4df79e89 Mon Sep 17 00:00:00 2001 From: Robinhuett <5955614+Robinhuett@users.noreply.github.com> Date: Wed, 26 Dec 2018 11:35:58 +0100 Subject: [PATCH] chore(custom): Change int conversion --- include/modules/custom.hpp | 1 - src/modules/custom.cpp | 17 ++--------------- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/include/modules/custom.hpp b/include/modules/custom.hpp index b429a84..074ed04 100644 --- a/include/modules/custom.hpp +++ b/include/modules/custom.hpp @@ -19,7 +19,6 @@ class Custom : public ALabel { void continuousWorker(); void parseOutputRaw(); void parseOutputJson(); - bool isInteger(const std::string&); const std::string name_; std::string text_; diff --git a/src/modules/custom.cpp b/src/modules/custom.cpp index 2bcb35b..c75760d 100644 --- a/src/modules/custom.cpp +++ b/src/modules/custom.cpp @@ -132,19 +132,6 @@ void waybar::modules::Custom::parseOutputRaw() } } -bool waybar::modules::Custom::isInteger(const std::string& n) -{ - if (std::isdigit(n[0]) || (n.size() > 1 && (n[0] == '-' || n[0] == '+'))) { - for (std::string::size_type i{ 1 }; i < n.size(); ++i) { - if (!std::isdigit(n[i])) { - return false; - } - } - return true; - } - return false; -} - void waybar::modules::Custom::parseOutputJson() { std::istringstream output(output_.out); @@ -154,8 +141,8 @@ void waybar::modules::Custom::parseOutputJson() text_ = parsed["text"].asString(); tooltip_ = parsed["tooltip"].asString(); class_ = parsed["class"].asString(); - if (!parsed["percentage"].asString().empty() && isInteger(parsed["percentage"].asString())) { - percentage_ = std::stoi(parsed["percentage"].asString(), nullptr); + if (!parsed["percentage"].asString().empty() && parsed["percentage"].isUInt()) { + percentage_ = parsed["percentage"].asUInt(); } else { percentage_ = 0; }