string: fix isNumber accepting - as valid number

This commit is contained in:
Vaxry 2024-06-15 11:36:28 +02:00
parent 8e10e0626f
commit ea8fd1d3ea
2 changed files with 2 additions and 1 deletions

View file

@ -51,7 +51,7 @@ bool Hyprutils::String::isNumber(const std::string& str, bool allowfloat) {
} }
} }
if (str.back() == '.') if (!isdigit(str.back()))
return false; return false;
return true; return true;

View file

@ -19,6 +19,7 @@ int main(int argc, char** argv, char** envp) {
EXPECT(isNumber("---3423--432s"), false); EXPECT(isNumber("---3423--432s"), false);
EXPECT(isNumber("1s"), false); EXPECT(isNumber("1s"), false);
EXPECT(isNumber(""), false); EXPECT(isNumber(""), false);
EXPECT(isNumber("-"), false);
EXPECT(isNumber("--0"), false); EXPECT(isNumber("--0"), false);
EXPECT(isNumber("abc"), false); EXPECT(isNumber("abc"), false);
EXPECT(isNumber("0.0", true), true); EXPECT(isNumber("0.0", true), true);