chore(custom): Change int conversion

This commit is contained in:
Robinhuett 2018-12-26 11:35:58 +01:00
parent 11c98f13e3
commit 4698c9d2cf
2 changed files with 2 additions and 16 deletions

View File

@ -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_;

View File

@ -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;
}