mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
chore(custom): Change int conversion
This commit is contained in:
parent
11c98f13e3
commit
4698c9d2cf
@ -19,7 +19,6 @@ class Custom : public ALabel {
|
|||||||
void continuousWorker();
|
void continuousWorker();
|
||||||
void parseOutputRaw();
|
void parseOutputRaw();
|
||||||
void parseOutputJson();
|
void parseOutputJson();
|
||||||
bool isInteger(const std::string&);
|
|
||||||
|
|
||||||
const std::string name_;
|
const std::string name_;
|
||||||
std::string text_;
|
std::string text_;
|
||||||
|
@ -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()
|
void waybar::modules::Custom::parseOutputJson()
|
||||||
{
|
{
|
||||||
std::istringstream output(output_.out);
|
std::istringstream output(output_.out);
|
||||||
@ -154,8 +141,8 @@ void waybar::modules::Custom::parseOutputJson()
|
|||||||
text_ = parsed["text"].asString();
|
text_ = parsed["text"].asString();
|
||||||
tooltip_ = parsed["tooltip"].asString();
|
tooltip_ = parsed["tooltip"].asString();
|
||||||
class_ = parsed["class"].asString();
|
class_ = parsed["class"].asString();
|
||||||
if (!parsed["percentage"].asString().empty() && isInteger(parsed["percentage"].asString())) {
|
if (!parsed["percentage"].asString().empty() && parsed["percentage"].isUInt()) {
|
||||||
percentage_ = std::stoi(parsed["percentage"].asString(), nullptr);
|
percentage_ = parsed["percentage"].asUInt();
|
||||||
} else {
|
} else {
|
||||||
percentage_ = 0;
|
percentage_ = 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user