1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 01:37:35 +00:00

Calculator: Construct KeypadValue precisely from the Clipboard contents

Previously, we would use lossy strtod() conversion. This was bad,
especially since we switched from internally storing Calculator
state in a double to storing it in the KeypadValue class
some time ago. This commit adds a constructor for the KeypadValue
class that is not lossy by using strtoll(). It handles numbers
with and without decimal points as well as negative numbers
correctly.
This commit is contained in:
creator1creeper1 2021-12-19 19:07:53 +01:00 committed by Brian Gianforcaro
parent 7ea3d40e19
commit cacac7927b
3 changed files with 22 additions and 2 deletions

View file

@ -51,8 +51,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto clipboard = GUI::Clipboard::the().fetch_data_and_type();
if (clipboard.mime_type == "text/plain") {
if (!clipboard.data.is_empty()) {
auto data = atof(StringView(clipboard.data).to_string().characters());
widget.set_entry(KeypadValue { data });
widget.set_entry(KeypadValue(StringView(clipboard.data)));
}
}
}));