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

AK: Implement StringView::to_number<T> from String::to_number<T>

Do exactly what String does, then use StringView's implementation as
String's new one. This should allow us to call to_number on a
StringView.
This commit is contained in:
Shannon Booth 2023-12-23 11:35:03 +13:00 committed by Andreas Kling
parent b63eb4a4dd
commit cdf84a3e36
2 changed files with 14 additions and 8 deletions

View file

@ -353,6 +353,19 @@ public:
}());
}
template<Arithmetic T>
Optional<T> to_number(TrimWhitespace trim_whitespace = TrimWhitespace::Yes) const
{
#ifndef KERNEL
if constexpr (IsFloatingPoint<T>)
return StringUtils::convert_to_floating_point<T>(*this, trim_whitespace);
#endif
if constexpr (IsSigned<T>)
return StringUtils::convert_to_int<T>(*this, trim_whitespace);
else
return StringUtils::convert_to_uint<T>(*this, trim_whitespace);
}
private:
friend class ByteString;
char const* m_characters { nullptr };