1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 08:34:57 +00:00

AK: Add to_{double, float} convenience functions to all string types

These are guarded with #ifndef KERNEL, since doubles (and floats) are
not allowed in KERNEL mode.
In StringUtils there is convert_to_floating_point which does have a
template parameter incase you have a templated type.
This commit is contained in:
davidot 2022-10-11 00:48:45 +02:00 committed by Linus Groh
parent 2334cd85a2
commit 6fd8e96d53
8 changed files with 68 additions and 0 deletions

View file

@ -95,6 +95,18 @@ template Optional<u16> FlyString::to_uint(TrimWhitespace) const;
template Optional<u32> FlyString::to_uint(TrimWhitespace) const;
template Optional<u64> FlyString::to_uint(TrimWhitespace) const;
#ifndef KERNEL
Optional<double> FlyString::to_double(TrimWhitespace trim_whitespace) const
{
return StringUtils::convert_to_floating_point<double>(view(), trim_whitespace);
}
Optional<float> FlyString::to_float(TrimWhitespace trim_whitespace) const
{
return StringUtils::convert_to_floating_point<float>(view(), trim_whitespace);
}
#endif
bool FlyString::equals_ignoring_case(StringView other) const
{
return StringUtils::equals_ignoring_case(view(), other);