mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 20:15:17 +00:00
AK: Pass correct length to StringUtils::convert_to_floating_point()
Fixed the issue in StringUtils::convert_to_floating_point() where the end pointer of the trimmed string was not being passed, causing the function to consistently return 'None' when given strings with trailing whitespaces.
This commit is contained in:
parent
f0be812fc2
commit
54e1470467
Notes:
sideshowbarker
2024-07-16 21:34:08 +09:00
Author: https://github.com/hanaa12G 🔰 Commit: https://github.com/SerenityOS/serenity/commit/54e1470467 Pull-request: https://github.com/SerenityOS/serenity/pull/21441 Issue: https://github.com/SerenityOS/serenity/issues/21428 Reviewed-by: https://github.com/tcl3 Reviewed-by: https://github.com/timschumi ✅ Reviewed-by: https://github.com/trflynn89
2 changed files with 8 additions and 1 deletions
|
@ -247,7 +247,7 @@ Optional<T> convert_to_floating_point(StringView str, TrimWhitespace trim_whites
|
|||
: str;
|
||||
|
||||
char const* start = string.characters_without_null_termination();
|
||||
return parse_floating_point_completely<T>(start, start + str.length());
|
||||
return parse_floating_point_completely<T>(start, start + string.length());
|
||||
}
|
||||
|
||||
template Optional<double> convert_to_floating_point(StringView str, TrimWhitespace);
|
||||
|
|
|
@ -319,6 +319,13 @@ TEST_CASE(convert_to_uint_from_octal)
|
|||
EXPECT_EQ(actual.value(), 0177777u);
|
||||
}
|
||||
|
||||
TEST_CASE(convert_to_floating_point)
|
||||
{
|
||||
auto number_string = " 123.45 "sv;
|
||||
auto maybe_number = AK::StringUtils::convert_to_floating_point<float>(number_string, TrimWhitespace::Yes);
|
||||
EXPECT_APPROXIMATE(maybe_number.value(), 123.45f);
|
||||
}
|
||||
|
||||
TEST_CASE(ends_with)
|
||||
{
|
||||
DeprecatedString test_string = "ABCDEF";
|
||||
|
|
Loading…
Add table
Reference in a new issue