mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 08:04: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:
parent
2334cd85a2
commit
6fd8e96d53
8 changed files with 68 additions and 0 deletions
|
@ -236,6 +236,16 @@ template Optional<long> StringView::to_uint() const;
|
|||
template Optional<long long> StringView::to_uint() const;
|
||||
|
||||
#ifndef KERNEL
|
||||
Optional<double> StringView::to_double(TrimWhitespace trim_whitespace) const
|
||||
{
|
||||
return StringUtils::convert_to_floating_point<double>(*this, trim_whitespace);
|
||||
}
|
||||
|
||||
Optional<float> StringView::to_float(TrimWhitespace trim_whitespace) const
|
||||
{
|
||||
return StringUtils::convert_to_floating_point<float>(*this, trim_whitespace);
|
||||
}
|
||||
|
||||
bool StringView::operator==(String const& string) const
|
||||
{
|
||||
return *this == string.view();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue