mirror of
https://github.com/hyprwm/hyprutils.git
synced 2024-11-16 23:05:58 +01:00
parent
0252fd13e7
commit
aadf9a27dd
2 changed files with 8 additions and 1 deletions
|
@ -26,6 +26,8 @@ bool Hyprutils::String::isNumber(const std::string& str, bool allowfloat) {
|
|||
if (str.empty())
|
||||
return false;
|
||||
|
||||
bool decimalParsed = false;
|
||||
|
||||
for (size_t i = 0; i < str.length(); ++i) {
|
||||
const char& c = str.at(i);
|
||||
|
||||
|
@ -44,9 +46,11 @@ bool Hyprutils::String::isNumber(const std::string& str, bool allowfloat) {
|
|||
if (i == 0)
|
||||
return false;
|
||||
|
||||
if (str.at(0) == '-')
|
||||
if (decimalParsed)
|
||||
return false;
|
||||
|
||||
decimalParsed = true;
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,6 +30,9 @@ int main(int argc, char** argv, char** envp) {
|
|||
EXPECT(isNumber("vvss", true), false);
|
||||
EXPECT(isNumber("0.9999s", true), false);
|
||||
EXPECT(isNumber("s0.9999", true), false);
|
||||
EXPECT(isNumber("-1.0", true), true);
|
||||
EXPECT(isNumber("-1..0", true), false);
|
||||
EXPECT(isNumber("-10.0000000001", true), true);
|
||||
|
||||
CVarList list("hello world!", 0, 's', true);
|
||||
EXPECT(list[0], "hello");
|
||||
|
|
Loading…
Reference in a new issue