diff options
author | Yuqian Yang <crupest@crupest.life> | 2025-10-17 14:06:48 +0800 |
---|---|---|
committer | Yuqian Yang <crupest@crupest.life> | 2025-10-17 14:06:48 +0800 |
commit | 5c5c496b605886b286d1b99e0f9e28ec02117ad5 (patch) | |
tree | c22b07e81ba179d7cc8790656abddbcc56b5d704 /src/ui/components | |
parent | 32aa6f116acc6e3e20a1ec76cef45b29f7005ad7 (diff) | |
download | cru-5c5c496b605886b286d1b99e0f9e28ec02117ad5.tar.gz cru-5c5c496b605886b286d1b99e0f9e28ec02117ad5.tar.bz2 cru-5c5c496b605886b286d1b99e0f9e28ec02117ad5.zip |
Use std::from_chars.
Diffstat (limited to 'src/ui/components')
-rw-r--r-- | src/ui/components/Input.cpp | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/src/ui/components/Input.cpp b/src/ui/components/Input.cpp index e75eccc5..0a14c7b8 100644 --- a/src/ui/components/Input.cpp +++ b/src/ui/components/Input.cpp @@ -1,8 +1,7 @@ #include "cru/ui/components/Input.h" -#include "cru/base/StringToNumberConverter.h" +#include "cru/base/StringUtil.h" #include "cru/ui/controls/Control.h" -#include <cmath> #include <optional> #include <string> @@ -44,18 +43,18 @@ InputValidateResult Input::GetLastValidateResult() const { } InputValidateResult FloatInputValidator::Validate(std::string_view text) const { - auto result = String::FromUtf8(text).ParseToFloat( - nullptr, StringToNumberFlags::kAllowLeadingSpaces & - StringToNumberFlags::kAllowTrailingSpaces); - if (std::isnan(result)) { + auto result = cru::string::ParseToNumber<float>( + text, cru::string::ParseToNumberFlags::AllowLeadingSpaces | + cru::string::ParseToNumberFlags::AllowTrailingSpaces); + if (!result.valid) { return InputValidateResult{false, "Invalid number."}; } - if (min && result < *min) { + if (min && result.value < *min) { return InputValidateResult{false, "Value is less than minimum."}; } - if (max && result > *max) { + if (max && result.value > *max) { return InputValidateResult{false, "Value is greater than maximum."}; } @@ -67,9 +66,11 @@ FloatInput::FloatInput() { ChangeEvent()->AddHandler([this](const InputChangeEventArgs& args) { if (args.valid) { - value_ = String::FromUtf8(args.text).ParseToFloat( - nullptr, StringToNumberFlags::kAllowLeadingSpaces & - StringToNumberFlags::kAllowTrailingSpaces); + value_ = cru::string::ParseToNumber<float>( + args.text, + cru::string::ParseToNumberFlags::AllowLeadingSpaces | + cru::string::ParseToNumberFlags::AllowTrailingSpaces) + .value; } }); } |